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 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
2029 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2031 void forget_cached_source_info (struct objfile
*objfile
) override
;
2033 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2036 bool *symbol_found_p
) override
2038 *symbol_found_p
= false;
2039 return language_unknown
;
2042 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2044 void expand_all_symtabs (struct objfile
*objfile
) override
;
2046 struct compunit_symtab
*find_pc_sect_compunit_symtab
2047 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2048 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2050 struct compunit_symtab
*find_compunit_symtab_by_address
2051 (struct objfile
*objfile
, CORE_ADDR address
) override
2056 void map_symbol_filenames (struct objfile
*objfile
,
2057 gdb::function_view
<symbol_filename_ftype
> fun
,
2058 bool need_fullname
) override
;
2061 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2063 void dump (struct objfile
*objfile
) override
;
2065 void expand_matching_symbols
2067 const lookup_name_info
&lookup_name
,
2070 symbol_compare_ftype
*ordered_compare
) override
;
2072 bool expand_symtabs_matching
2073 (struct objfile
*objfile
,
2074 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2075 const lookup_name_info
*lookup_name
,
2076 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2077 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2078 block_search_flags search_flags
,
2080 enum search_domain kind
) override
;
2083 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2085 void dump (struct objfile
*objfile
) override
;
2087 void expand_matching_symbols
2089 const lookup_name_info
&lookup_name
,
2092 symbol_compare_ftype
*ordered_compare
) override
;
2094 bool expand_symtabs_matching
2095 (struct objfile
*objfile
,
2096 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2097 const lookup_name_info
*lookup_name
,
2098 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2099 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2100 block_search_flags search_flags
,
2102 enum search_domain kind
) override
;
2105 static quick_symbol_functions_up
2106 make_dwarf_gdb_index ()
2108 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2111 static quick_symbol_functions_up
2112 make_dwarf_debug_names ()
2114 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2117 /* Utility hash function for a stmt_list_hash. */
2120 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2124 if (stmt_list_hash
->dwo_unit
!= NULL
)
2125 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2126 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2130 /* Utility equality function for a stmt_list_hash. */
2133 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2134 const struct stmt_list_hash
*rhs
)
2136 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2138 if (lhs
->dwo_unit
!= NULL
2139 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2142 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2145 /* Hash function for a quick_file_names. */
2148 hash_file_name_entry (const void *e
)
2150 const struct quick_file_names
*file_data
2151 = (const struct quick_file_names
*) e
;
2153 return hash_stmt_list_entry (&file_data
->hash
);
2156 /* Equality function for a quick_file_names. */
2159 eq_file_name_entry (const void *a
, const void *b
)
2161 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2162 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2164 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2167 /* Delete function for a quick_file_names. */
2170 delete_file_name_entry (void *e
)
2172 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2175 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2177 xfree ((void*) file_data
->file_names
[i
]);
2178 if (file_data
->real_names
)
2179 xfree ((void*) file_data
->real_names
[i
]);
2182 /* The space for the struct itself lives on the obstack, so we don't
2186 /* Create a quick_file_names hash table. */
2189 create_quick_file_names_table (unsigned int nr_initial_entries
)
2191 return htab_up (htab_create_alloc (nr_initial_entries
,
2192 hash_file_name_entry
, eq_file_name_entry
,
2193 delete_file_name_entry
, xcalloc
, xfree
));
2196 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2197 function is unrelated to symtabs, symtab would have to be created afterwards.
2198 You should call age_cached_comp_units after processing the CU. */
2201 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2204 if (per_cu
->is_debug_types
)
2205 load_full_type_unit (per_cu
, per_objfile
);
2207 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2208 skip_partial
, language_minimal
);
2210 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2212 return nullptr; /* Dummy CU. */
2214 dwarf2_find_base_address (cu
->dies
, cu
);
2219 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2222 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2223 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2225 /* Skip type_unit_groups, reading the type units they contain
2226 is handled elsewhere. */
2227 if (per_cu
->type_unit_group_p ())
2231 /* The destructor of dwarf2_queue_guard frees any entries left on
2232 the queue. After this point we're guaranteed to leave this function
2233 with the dwarf queue empty. */
2234 dwarf2_queue_guard
q_guard (per_objfile
);
2236 if (!per_objfile
->symtab_set_p (per_cu
))
2238 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2239 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2241 /* If we just loaded a CU from a DWO, and we're working with an index
2242 that may badly handle TUs, load all the TUs in that DWO as well.
2243 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2244 if (!per_cu
->is_debug_types
2246 && cu
->dwo_unit
!= NULL
2247 && per_objfile
->per_bfd
->index_table
!= NULL
2248 && per_objfile
->per_bfd
->index_table
->version
<= 7
2249 /* DWP files aren't supported yet. */
2250 && get_dwp_file (per_objfile
) == NULL
)
2251 queue_and_load_all_dwo_tus (cu
);
2254 process_queue (per_objfile
);
2257 /* Age the cache, releasing compilation units that have not
2258 been used recently. */
2259 per_objfile
->age_comp_units ();
2262 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2263 the per-objfile for which this symtab is instantiated.
2265 Returns the resulting symbol table. */
2267 static struct compunit_symtab
*
2268 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2269 dwarf2_per_objfile
*per_objfile
,
2272 gdb_assert (per_objfile
->per_bfd
->using_index
);
2274 if (!per_objfile
->symtab_set_p (per_cu
))
2276 free_cached_comp_units
freer (per_objfile
);
2277 scoped_restore decrementer
= increment_reading_symtab ();
2278 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2279 process_cu_includes (per_objfile
);
2282 return per_objfile
->get_symtab (per_cu
);
2287 dwarf2_per_cu_data_up
2288 dwarf2_per_bfd::allocate_per_cu ()
2290 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2291 result
->per_bfd
= this;
2292 result
->index
= all_comp_units
.size ();
2299 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2301 signatured_type_up
result (new signatured_type (signature
));
2302 result
->per_bfd
= this;
2303 result
->index
= all_comp_units
.size ();
2304 result
->is_debug_types
= true;
2309 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2310 obstack, and constructed with the specified field values. */
2312 static dwarf2_per_cu_data_up
2313 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2314 struct dwarf2_section_info
*section
,
2316 sect_offset sect_off
, ULONGEST length
)
2318 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2319 the_cu
->sect_off
= sect_off
;
2320 the_cu
->length
= length
;
2321 the_cu
->section
= section
;
2322 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2323 struct dwarf2_per_cu_quick_data
);
2324 the_cu
->is_dwz
= is_dwz
;
2328 /* A helper for create_cus_from_index that handles a given list of
2332 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2333 const gdb_byte
*cu_list
, offset_type n_elements
,
2334 struct dwarf2_section_info
*section
,
2337 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2339 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2341 sect_offset sect_off
2342 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2343 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2346 dwarf2_per_cu_data_up per_cu
2347 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2349 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2353 /* Read the CU list from the mapped index, and use it to create all
2354 the CU objects for PER_BFD. */
2357 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2358 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2359 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2361 gdb_assert (per_bfd
->all_comp_units
.empty ());
2362 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2364 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2367 if (dwz_elements
== 0)
2370 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2371 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2375 /* Create the signatured type hash table from the index. */
2378 create_signatured_type_table_from_index
2379 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2380 const gdb_byte
*bytes
, offset_type elements
)
2382 htab_up sig_types_hash
= allocate_signatured_type_table ();
2384 for (offset_type i
= 0; i
< elements
; i
+= 3)
2386 signatured_type_up sig_type
;
2389 cu_offset type_offset_in_tu
;
2391 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2392 sect_offset sect_off
2393 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2395 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2397 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2400 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2401 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2402 sig_type
->section
= section
;
2403 sig_type
->sect_off
= sect_off
;
2405 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2406 struct dwarf2_per_cu_quick_data
);
2408 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2409 *slot
= sig_type
.get ();
2411 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2414 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2417 /* Create the signatured type hash table from .debug_names. */
2420 create_signatured_type_table_from_debug_names
2421 (dwarf2_per_objfile
*per_objfile
,
2422 const mapped_debug_names
&map
,
2423 struct dwarf2_section_info
*section
,
2424 struct dwarf2_section_info
*abbrev_section
)
2426 struct objfile
*objfile
= per_objfile
->objfile
;
2428 section
->read (objfile
);
2429 abbrev_section
->read (objfile
);
2431 htab_up sig_types_hash
= allocate_signatured_type_table ();
2433 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2435 signatured_type_up sig_type
;
2438 sect_offset sect_off
2439 = (sect_offset
) (extract_unsigned_integer
2440 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2442 map
.dwarf5_byte_order
));
2444 comp_unit_head cu_header
;
2445 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2447 section
->buffer
+ to_underlying (sect_off
),
2450 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2451 (cu_header
.signature
);
2452 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2453 sig_type
->section
= section
;
2454 sig_type
->sect_off
= sect_off
;
2456 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2457 struct dwarf2_per_cu_quick_data
);
2459 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2460 *slot
= sig_type
.get ();
2462 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2465 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2468 /* Read the address map data from the mapped index, and use it to
2469 populate the psymtabs_addrmap. */
2472 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2473 struct mapped_index
*index
)
2475 struct objfile
*objfile
= per_objfile
->objfile
;
2476 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2477 struct gdbarch
*gdbarch
= objfile
->arch ();
2478 const gdb_byte
*iter
, *end
;
2479 struct addrmap
*mutable_map
;
2482 auto_obstack temp_obstack
;
2484 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2486 iter
= index
->address_table
.data ();
2487 end
= iter
+ index
->address_table
.size ();
2489 baseaddr
= objfile
->text_section_offset ();
2493 ULONGEST hi
, lo
, cu_index
;
2494 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2496 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2498 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2503 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2504 hex_string (lo
), hex_string (hi
));
2508 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2510 complaint (_(".gdb_index address table has invalid CU number %u"),
2511 (unsigned) cu_index
);
2515 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2516 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2517 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2518 per_bfd
->get_cu (cu_index
));
2521 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2525 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2526 populate the psymtabs_addrmap. */
2529 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2530 struct dwarf2_section_info
*section
)
2532 struct objfile
*objfile
= per_objfile
->objfile
;
2533 bfd
*abfd
= objfile
->obfd
;
2534 struct gdbarch
*gdbarch
= objfile
->arch ();
2535 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2536 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2538 auto_obstack temp_obstack
;
2539 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2541 std::unordered_map
<sect_offset
,
2542 dwarf2_per_cu_data
*,
2543 gdb::hash_enum
<sect_offset
>>
2544 debug_info_offset_to_per_cu
;
2545 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2547 const auto insertpair
2548 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2550 if (!insertpair
.second
)
2552 warning (_("Section .debug_aranges in %s has duplicate "
2553 "debug_info_offset %s, ignoring .debug_aranges."),
2554 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2559 section
->read (objfile
);
2561 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2563 const gdb_byte
*addr
= section
->buffer
;
2565 while (addr
< section
->buffer
+ section
->size
)
2567 const gdb_byte
*const entry_addr
= addr
;
2568 unsigned int bytes_read
;
2570 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2574 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2575 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2576 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2577 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2579 warning (_("Section .debug_aranges in %s entry at offset %s "
2580 "length %s exceeds section length %s, "
2581 "ignoring .debug_aranges."),
2582 objfile_name (objfile
),
2583 plongest (entry_addr
- section
->buffer
),
2584 plongest (bytes_read
+ entry_length
),
2585 pulongest (section
->size
));
2589 /* The version number. */
2590 const uint16_t version
= read_2_bytes (abfd
, addr
);
2594 warning (_("Section .debug_aranges in %s entry at offset %s "
2595 "has unsupported version %d, ignoring .debug_aranges."),
2596 objfile_name (objfile
),
2597 plongest (entry_addr
- section
->buffer
), version
);
2601 const uint64_t debug_info_offset
2602 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2603 addr
+= offset_size
;
2604 const auto per_cu_it
2605 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2606 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2608 warning (_("Section .debug_aranges in %s entry at offset %s "
2609 "debug_info_offset %s does not exists, "
2610 "ignoring .debug_aranges."),
2611 objfile_name (objfile
),
2612 plongest (entry_addr
- section
->buffer
),
2613 pulongest (debug_info_offset
));
2616 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2618 const uint8_t address_size
= *addr
++;
2619 if (address_size
< 1 || address_size
> 8)
2621 warning (_("Section .debug_aranges in %s entry at offset %s "
2622 "address_size %u is invalid, ignoring .debug_aranges."),
2623 objfile_name (objfile
),
2624 plongest (entry_addr
- section
->buffer
), address_size
);
2628 const uint8_t segment_selector_size
= *addr
++;
2629 if (segment_selector_size
!= 0)
2631 warning (_("Section .debug_aranges in %s entry at offset %s "
2632 "segment_selector_size %u is not supported, "
2633 "ignoring .debug_aranges."),
2634 objfile_name (objfile
),
2635 plongest (entry_addr
- section
->buffer
),
2636 segment_selector_size
);
2640 /* Must pad to an alignment boundary that is twice the address
2641 size. It is undocumented by the DWARF standard but GCC does
2642 use it. However, not every compiler does this. We can see
2643 whether it has happened by looking at the total length of the
2644 contents of the aranges for this CU -- it if isn't a multiple
2645 of twice the address size, then we skip any leftover
2647 addr
+= (entry_end
- addr
) % (2 * address_size
);
2651 if (addr
+ 2 * address_size
> entry_end
)
2653 warning (_("Section .debug_aranges in %s entry at offset %s "
2654 "address list is not properly terminated, "
2655 "ignoring .debug_aranges."),
2656 objfile_name (objfile
),
2657 plongest (entry_addr
- section
->buffer
));
2660 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2662 addr
+= address_size
;
2663 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2665 addr
+= address_size
;
2666 if (start
== 0 && length
== 0)
2668 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2670 /* Symbol was eliminated due to a COMDAT group. */
2673 ULONGEST end
= start
+ length
;
2674 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2676 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2678 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2682 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2686 /* A helper function that reads the .gdb_index from BUFFER and fills
2687 in MAP. FILENAME is the name of the file containing the data;
2688 it is used for error reporting. DEPRECATED_OK is true if it is
2689 ok to use deprecated sections.
2691 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2692 out parameters that are filled in with information about the CU and
2693 TU lists in the section.
2695 Returns true if all went well, false otherwise. */
2698 read_gdb_index_from_buffer (const char *filename
,
2700 gdb::array_view
<const gdb_byte
> buffer
,
2701 struct mapped_index
*map
,
2702 const gdb_byte
**cu_list
,
2703 offset_type
*cu_list_elements
,
2704 const gdb_byte
**types_list
,
2705 offset_type
*types_list_elements
)
2707 const gdb_byte
*addr
= &buffer
[0];
2708 offset_view
metadata (buffer
);
2710 /* Version check. */
2711 offset_type version
= metadata
[0];
2712 /* Versions earlier than 3 emitted every copy of a psymbol. This
2713 causes the index to behave very poorly for certain requests. Version 3
2714 contained incomplete addrmap. So, it seems better to just ignore such
2718 static int warning_printed
= 0;
2719 if (!warning_printed
)
2721 warning (_("Skipping obsolete .gdb_index section in %s."),
2723 warning_printed
= 1;
2727 /* Index version 4 uses a different hash function than index version
2730 Versions earlier than 6 did not emit psymbols for inlined
2731 functions. Using these files will cause GDB not to be able to
2732 set breakpoints on inlined functions by name, so we ignore these
2733 indices unless the user has done
2734 "set use-deprecated-index-sections on". */
2735 if (version
< 6 && !deprecated_ok
)
2737 static int warning_printed
= 0;
2738 if (!warning_printed
)
2741 Skipping deprecated .gdb_index section in %s.\n\
2742 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2743 to use the section anyway."),
2745 warning_printed
= 1;
2749 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2750 of the TU (for symbols coming from TUs),
2751 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2752 Plus gold-generated indices can have duplicate entries for global symbols,
2753 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2754 These are just performance bugs, and we can't distinguish gdb-generated
2755 indices from gold-generated ones, so issue no warning here. */
2757 /* Indexes with higher version than the one supported by GDB may be no
2758 longer backward compatible. */
2762 map
->version
= version
;
2765 *cu_list
= addr
+ metadata
[i
];
2766 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2769 *types_list
= addr
+ metadata
[i
];
2770 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2773 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2774 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2776 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2779 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2780 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2782 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2786 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2791 /* Callback types for dwarf2_read_gdb_index. */
2793 typedef gdb::function_view
2794 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2795 get_gdb_index_contents_ftype
;
2796 typedef gdb::function_view
2797 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2798 get_gdb_index_contents_dwz_ftype
;
2800 /* Read .gdb_index. If everything went ok, initialize the "quick"
2801 elements of all the CUs and return 1. Otherwise, return 0. */
2804 dwarf2_read_gdb_index
2805 (dwarf2_per_objfile
*per_objfile
,
2806 get_gdb_index_contents_ftype get_gdb_index_contents
,
2807 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2809 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2810 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2811 struct dwz_file
*dwz
;
2812 struct objfile
*objfile
= per_objfile
->objfile
;
2813 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2815 gdb::array_view
<const gdb_byte
> main_index_contents
2816 = get_gdb_index_contents (objfile
, per_bfd
);
2818 if (main_index_contents
.empty ())
2821 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2822 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2823 use_deprecated_index_sections
,
2824 main_index_contents
, map
.get (), &cu_list
,
2825 &cu_list_elements
, &types_list
,
2826 &types_list_elements
))
2829 /* Don't use the index if it's empty. */
2830 if (map
->symbol_table
.empty ())
2833 /* If there is a .dwz file, read it so we can get its CU list as
2835 dwz
= dwarf2_get_dwz_file (per_bfd
);
2838 struct mapped_index dwz_map
;
2839 const gdb_byte
*dwz_types_ignore
;
2840 offset_type dwz_types_elements_ignore
;
2842 gdb::array_view
<const gdb_byte
> dwz_index_content
2843 = get_gdb_index_contents_dwz (objfile
, dwz
);
2845 if (dwz_index_content
.empty ())
2848 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2849 1, dwz_index_content
, &dwz_map
,
2850 &dwz_list
, &dwz_list_elements
,
2852 &dwz_types_elements_ignore
))
2854 warning (_("could not read '.gdb_index' section from %s; skipping"),
2855 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2860 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2863 if (types_list_elements
)
2865 /* We can only handle a single .debug_types when we have an
2867 if (per_bfd
->types
.size () != 1)
2870 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2872 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2873 types_list_elements
);
2876 create_addrmap_from_index (per_objfile
, map
.get ());
2878 per_bfd
->index_table
= std::move (map
);
2879 per_bfd
->using_index
= 1;
2880 per_bfd
->quick_file_names_table
=
2881 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2886 /* die_reader_func for dw2_get_file_names. */
2889 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2890 struct die_info
*comp_unit_die
)
2892 struct dwarf2_cu
*cu
= reader
->cu
;
2893 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2894 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2895 struct dwarf2_per_cu_data
*lh_cu
;
2896 struct attribute
*attr
;
2898 struct quick_file_names
*qfn
;
2900 gdb_assert (! this_cu
->is_debug_types
);
2902 /* Our callers never want to match partial units -- instead they
2903 will match the enclosing full CU. */
2904 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2906 this_cu
->v
.quick
->no_file_data
= 1;
2914 sect_offset line_offset
{};
2916 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2917 if (attr
!= nullptr && attr
->form_is_unsigned ())
2919 struct quick_file_names find_entry
;
2921 line_offset
= (sect_offset
) attr
->as_unsigned ();
2923 /* We may have already read in this line header (TU line header sharing).
2924 If we have we're done. */
2925 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2926 find_entry
.hash
.line_sect_off
= line_offset
;
2927 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2928 &find_entry
, INSERT
);
2931 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
2935 lh
= dwarf_decode_line_header (line_offset
, cu
);
2939 lh_cu
->v
.quick
->no_file_data
= 1;
2943 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
2944 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2945 qfn
->hash
.line_sect_off
= line_offset
;
2946 gdb_assert (slot
!= NULL
);
2949 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
2952 if (strcmp (fnd
.name
, "<unknown>") != 0)
2955 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
2957 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
2958 qfn
->num_file_names
);
2960 qfn
->file_names
[0] = xstrdup (fnd
.name
);
2961 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
2962 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
2963 fnd
.comp_dir
).release ();
2964 qfn
->real_names
= NULL
;
2966 lh_cu
->v
.quick
->file_names
= qfn
;
2969 /* A helper for the "quick" functions which attempts to read the line
2970 table for THIS_CU. */
2972 static struct quick_file_names
*
2973 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
2974 dwarf2_per_objfile
*per_objfile
)
2976 /* This should never be called for TUs. */
2977 gdb_assert (! this_cu
->is_debug_types
);
2978 /* Nor type unit groups. */
2979 gdb_assert (! this_cu
->type_unit_group_p ());
2981 if (this_cu
->v
.quick
->file_names
!= NULL
)
2982 return this_cu
->v
.quick
->file_names
;
2983 /* If we know there is no line data, no point in looking again. */
2984 if (this_cu
->v
.quick
->no_file_data
)
2987 cutu_reader
reader (this_cu
, per_objfile
);
2988 if (!reader
.dummy_p
)
2989 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
2991 if (this_cu
->v
.quick
->no_file_data
)
2993 return this_cu
->v
.quick
->file_names
;
2996 /* A helper for the "quick" functions which computes and caches the
2997 real path for a given file name from the line table. */
3000 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3001 struct quick_file_names
*qfn
, int index
)
3003 if (qfn
->real_names
== NULL
)
3004 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3005 qfn
->num_file_names
, const char *);
3007 if (qfn
->real_names
[index
] == NULL
)
3008 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3010 return qfn
->real_names
[index
];
3014 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3016 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3017 dwarf2_per_cu_data
*dwarf_cu
3018 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3019 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3024 return compunit_primary_filetab (cust
);
3027 /* Traversal function for dw2_forget_cached_source_info. */
3030 dw2_free_cached_file_names (void **slot
, void *info
)
3032 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3034 if (file_data
->real_names
)
3038 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3040 xfree ((void*) file_data
->real_names
[i
]);
3041 file_data
->real_names
[i
] = NULL
;
3049 dwarf2_base_index_functions::forget_cached_source_info
3050 (struct objfile
*objfile
)
3052 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3054 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3055 dw2_free_cached_file_names
, NULL
);
3058 /* Struct used to manage iterating over all CUs looking for a symbol. */
3060 struct dw2_symtab_iterator
3062 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3063 dwarf2_per_objfile
*per_objfile
;
3064 /* If set, only look for symbols that match that block. Valid values are
3065 GLOBAL_BLOCK and STATIC_BLOCK. */
3066 gdb::optional
<block_enum
> block_index
;
3067 /* The kind of symbol we're looking for. */
3069 /* The list of CUs from the index entry of the symbol,
3070 or NULL if not found. */
3072 /* The next element in VEC to look at. */
3074 /* The number of elements in VEC, or zero if there is no match. */
3076 /* Have we seen a global version of the symbol?
3077 If so we can ignore all further global instances.
3078 This is to work around gold/15646, inefficient gold-generated
3083 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3086 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3087 dwarf2_per_objfile
*per_objfile
,
3088 gdb::optional
<block_enum
> block_index
,
3089 domain_enum domain
, offset_type namei
)
3091 iter
->per_objfile
= per_objfile
;
3092 iter
->block_index
= block_index
;
3093 iter
->domain
= domain
;
3095 iter
->global_seen
= 0;
3099 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3100 /* index is NULL if OBJF_READNOW. */
3104 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3105 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3107 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3108 iter
->length
= iter
->vec
[0];
3111 /* Return the next matching CU or NULL if there are no more. */
3113 static struct dwarf2_per_cu_data
*
3114 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3116 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3118 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3120 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3121 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3122 gdb_index_symbol_kind symbol_kind
=
3123 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3124 /* Only check the symbol attributes if they're present.
3125 Indices prior to version 7 don't record them,
3126 and indices >= 7 may elide them for certain symbols
3127 (gold does this). */
3129 (per_objfile
->per_bfd
->index_table
->version
>= 7
3130 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3132 /* Don't crash on bad data. */
3133 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3135 complaint (_(".gdb_index entry has bad CU index"
3136 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3140 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3142 /* Skip if already read in. */
3143 if (per_objfile
->symtab_set_p (per_cu
))
3146 /* Check static vs global. */
3149 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3151 if (iter
->block_index
.has_value ())
3153 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3155 if (is_static
!= want_static
)
3159 /* Work around gold/15646. */
3161 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3163 if (iter
->global_seen
)
3166 iter
->global_seen
= 1;
3170 /* Only check the symbol's kind if it has one. */
3173 switch (iter
->domain
)
3176 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3177 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3178 /* Some types are also in VAR_DOMAIN. */
3179 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3183 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3187 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3191 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3207 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3213 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3214 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3217 for (int i
= 0; i
< total
; ++i
)
3219 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3221 if (!per_objfile
->symtab_set_p (per_cu
))
3224 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3225 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3228 /* This dumps minimal information about the index.
3229 It is called via "mt print objfiles".
3230 One use is to verify .gdb_index has been loaded by the
3231 gdb.dwarf2/gdb-index.exp testcase. */
3234 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3236 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3238 gdb_assert (per_objfile
->per_bfd
->using_index
);
3239 printf_filtered (".gdb_index:");
3240 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3242 printf_filtered (" version %d\n",
3243 per_objfile
->per_bfd
->index_table
->version
);
3246 printf_filtered (" faked for \"readnow\"\n");
3247 printf_filtered ("\n");
3251 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3253 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3254 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3256 for (int i
= 0; i
< total_units
; ++i
)
3258 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3260 /* We don't want to directly expand a partial CU, because if we
3261 read it with the wrong language, then assertion failures can
3262 be triggered later on. See PR symtab/23010. So, tell
3263 dw2_instantiate_symtab to skip partial CUs -- any important
3264 partial CU will be read via DW_TAG_imported_unit anyway. */
3265 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3270 dw2_expand_symtabs_matching_symbol
3271 (mapped_index_base
&index
,
3272 const lookup_name_info
&lookup_name_in
,
3273 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3274 gdb::function_view
<bool (offset_type
)> match_callback
,
3275 dwarf2_per_objfile
*per_objfile
);
3278 dw2_expand_symtabs_matching_one
3279 (dwarf2_per_cu_data
*per_cu
,
3280 dwarf2_per_objfile
*per_objfile
,
3281 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3282 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3285 dwarf2_gdb_index::expand_matching_symbols
3286 (struct objfile
*objfile
,
3287 const lookup_name_info
&name
, domain_enum domain
,
3289 symbol_compare_ftype
*ordered_compare
)
3292 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3294 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3296 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3298 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3300 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3301 auto matcher
= [&] (const char *symname
)
3303 if (ordered_compare
== nullptr)
3305 return ordered_compare (symname
, match_name
) == 0;
3308 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3309 [&] (offset_type namei
)
3311 struct dw2_symtab_iterator iter
;
3312 struct dwarf2_per_cu_data
*per_cu
;
3314 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3316 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3317 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3324 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3325 proceed assuming all symtabs have been read in. */
3329 /* Starting from a search name, return the string that finds the upper
3330 bound of all strings that start with SEARCH_NAME in a sorted name
3331 list. Returns the empty string to indicate that the upper bound is
3332 the end of the list. */
3335 make_sort_after_prefix_name (const char *search_name
)
3337 /* When looking to complete "func", we find the upper bound of all
3338 symbols that start with "func" by looking for where we'd insert
3339 the closest string that would follow "func" in lexicographical
3340 order. Usually, that's "func"-with-last-character-incremented,
3341 i.e. "fund". Mind non-ASCII characters, though. Usually those
3342 will be UTF-8 multi-byte sequences, but we can't be certain.
3343 Especially mind the 0xff character, which is a valid character in
3344 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3345 rule out compilers allowing it in identifiers. Note that
3346 conveniently, strcmp/strcasecmp are specified to compare
3347 characters interpreted as unsigned char. So what we do is treat
3348 the whole string as a base 256 number composed of a sequence of
3349 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3350 to 0, and carries 1 to the following more-significant position.
3351 If the very first character in SEARCH_NAME ends up incremented
3352 and carries/overflows, then the upper bound is the end of the
3353 list. The string after the empty string is also the empty
3356 Some examples of this operation:
3358 SEARCH_NAME => "+1" RESULT
3362 "\xff" "a" "\xff" => "\xff" "b"
3367 Then, with these symbols for example:
3373 completing "func" looks for symbols between "func" and
3374 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3375 which finds "func" and "func1", but not "fund".
3379 funcÿ (Latin1 'ÿ' [0xff])
3383 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3384 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3388 ÿÿ (Latin1 'ÿ' [0xff])
3391 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3392 the end of the list.
3394 std::string after
= search_name
;
3395 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3397 if (!after
.empty ())
3398 after
.back () = (unsigned char) after
.back () + 1;
3402 /* See declaration. */
3404 std::pair
<std::vector
<name_component
>::const_iterator
,
3405 std::vector
<name_component
>::const_iterator
>
3406 mapped_index_base::find_name_components_bounds
3407 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3408 dwarf2_per_objfile
*per_objfile
) const
3411 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3413 const char *lang_name
3414 = lookup_name_without_params
.language_lookup_name (lang
);
3416 /* Comparison function object for lower_bound that matches against a
3417 given symbol name. */
3418 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3421 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3422 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3423 return name_cmp (elem_name
, name
) < 0;
3426 /* Comparison function object for upper_bound that matches against a
3427 given symbol name. */
3428 auto lookup_compare_upper
= [&] (const char *name
,
3429 const name_component
&elem
)
3431 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3432 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3433 return name_cmp (name
, elem_name
) < 0;
3436 auto begin
= this->name_components
.begin ();
3437 auto end
= this->name_components
.end ();
3439 /* Find the lower bound. */
3442 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3445 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3448 /* Find the upper bound. */
3451 if (lookup_name_without_params
.completion_mode ())
3453 /* In completion mode, we want UPPER to point past all
3454 symbols names that have the same prefix. I.e., with
3455 these symbols, and completing "func":
3457 function << lower bound
3459 other_function << upper bound
3461 We find the upper bound by looking for the insertion
3462 point of "func"-with-last-character-incremented,
3464 std::string after
= make_sort_after_prefix_name (lang_name
);
3467 return std::lower_bound (lower
, end
, after
.c_str (),
3468 lookup_compare_lower
);
3471 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3474 return {lower
, upper
};
3477 /* See declaration. */
3480 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3482 if (!this->name_components
.empty ())
3485 this->name_components_casing
= case_sensitivity
;
3487 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3489 /* The code below only knows how to break apart components of C++
3490 symbol names (and other languages that use '::' as
3491 namespace/module separator) and Ada symbol names. */
3492 auto count
= this->symbol_name_count ();
3493 for (offset_type idx
= 0; idx
< count
; idx
++)
3495 if (this->symbol_name_slot_invalid (idx
))
3498 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3500 /* Add each name component to the name component table. */
3501 unsigned int previous_len
= 0;
3503 if (strstr (name
, "::") != nullptr)
3505 for (unsigned int current_len
= cp_find_first_component (name
);
3506 name
[current_len
] != '\0';
3507 current_len
+= cp_find_first_component (name
+ current_len
))
3509 gdb_assert (name
[current_len
] == ':');
3510 this->name_components
.push_back ({previous_len
, idx
});
3511 /* Skip the '::'. */
3513 previous_len
= current_len
;
3518 /* Handle the Ada encoded (aka mangled) form here. */
3519 for (const char *iter
= strstr (name
, "__");
3521 iter
= strstr (iter
, "__"))
3523 this->name_components
.push_back ({previous_len
, idx
});
3525 previous_len
= iter
- name
;
3529 this->name_components
.push_back ({previous_len
, idx
});
3532 /* Sort name_components elements by name. */
3533 auto name_comp_compare
= [&] (const name_component
&left
,
3534 const name_component
&right
)
3536 const char *left_qualified
3537 = this->symbol_name_at (left
.idx
, per_objfile
);
3538 const char *right_qualified
3539 = this->symbol_name_at (right
.idx
, per_objfile
);
3541 const char *left_name
= left_qualified
+ left
.name_offset
;
3542 const char *right_name
= right_qualified
+ right
.name_offset
;
3544 return name_cmp (left_name
, right_name
) < 0;
3547 std::sort (this->name_components
.begin (),
3548 this->name_components
.end (),
3552 /* Helper for dw2_expand_symtabs_matching that works with a
3553 mapped_index_base instead of the containing objfile. This is split
3554 to a separate function in order to be able to unit test the
3555 name_components matching using a mock mapped_index_base. For each
3556 symbol name that matches, calls MATCH_CALLBACK, passing it the
3557 symbol's index in the mapped_index_base symbol table. */
3560 dw2_expand_symtabs_matching_symbol
3561 (mapped_index_base
&index
,
3562 const lookup_name_info
&lookup_name_in
,
3563 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3564 gdb::function_view
<bool (offset_type
)> match_callback
,
3565 dwarf2_per_objfile
*per_objfile
)
3567 lookup_name_info lookup_name_without_params
3568 = lookup_name_in
.make_ignore_params ();
3570 /* Build the symbol name component sorted vector, if we haven't
3572 index
.build_name_components (per_objfile
);
3574 /* The same symbol may appear more than once in the range though.
3575 E.g., if we're looking for symbols that complete "w", and we have
3576 a symbol named "w1::w2", we'll find the two name components for
3577 that same symbol in the range. To be sure we only call the
3578 callback once per symbol, we first collect the symbol name
3579 indexes that matched in a temporary vector and ignore
3581 std::vector
<offset_type
> matches
;
3583 struct name_and_matcher
3585 symbol_name_matcher_ftype
*matcher
;
3588 bool operator== (const name_and_matcher
&other
) const
3590 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3594 /* A vector holding all the different symbol name matchers, for all
3596 std::vector
<name_and_matcher
> matchers
;
3598 for (int i
= 0; i
< nr_languages
; i
++)
3600 enum language lang_e
= (enum language
) i
;
3602 const language_defn
*lang
= language_def (lang_e
);
3603 symbol_name_matcher_ftype
*name_matcher
3604 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3606 name_and_matcher key
{
3608 lookup_name_without_params
.language_lookup_name (lang_e
)
3611 /* Don't insert the same comparison routine more than once.
3612 Note that we do this linear walk. This is not a problem in
3613 practice because the number of supported languages is
3615 if (std::find (matchers
.begin (), matchers
.end (), key
)
3618 matchers
.push_back (std::move (key
));
3621 = index
.find_name_components_bounds (lookup_name_without_params
,
3622 lang_e
, per_objfile
);
3624 /* Now for each symbol name in range, check to see if we have a name
3625 match, and if so, call the MATCH_CALLBACK callback. */
3627 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3629 const char *qualified
3630 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3632 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3633 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3636 matches
.push_back (bounds
.first
->idx
);
3640 std::sort (matches
.begin (), matches
.end ());
3642 /* Finally call the callback, once per match. */
3645 for (offset_type idx
: matches
)
3649 if (!match_callback (idx
))
3658 /* Above we use a type wider than idx's for 'prev', since 0 and
3659 (offset_type)-1 are both possible values. */
3660 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3667 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3669 /* A mock .gdb_index/.debug_names-like name index table, enough to
3670 exercise dw2_expand_symtabs_matching_symbol, which works with the
3671 mapped_index_base interface. Builds an index from the symbol list
3672 passed as parameter to the constructor. */
3673 class mock_mapped_index
: public mapped_index_base
3676 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3677 : m_symbol_table (symbols
)
3680 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3682 /* Return the number of names in the symbol table. */
3683 size_t symbol_name_count () const override
3685 return m_symbol_table
.size ();
3688 /* Get the name of the symbol at IDX in the symbol table. */
3689 const char *symbol_name_at
3690 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3692 return m_symbol_table
[idx
];
3696 gdb::array_view
<const char *> m_symbol_table
;
3699 /* Convenience function that converts a NULL pointer to a "<null>"
3700 string, to pass to print routines. */
3703 string_or_null (const char *str
)
3705 return str
!= NULL
? str
: "<null>";
3708 /* Check if a lookup_name_info built from
3709 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3710 index. EXPECTED_LIST is the list of expected matches, in expected
3711 matching order. If no match expected, then an empty list is
3712 specified. Returns true on success. On failure prints a warning
3713 indicating the file:line that failed, and returns false. */
3716 check_match (const char *file
, int line
,
3717 mock_mapped_index
&mock_index
,
3718 const char *name
, symbol_name_match_type match_type
,
3719 bool completion_mode
,
3720 std::initializer_list
<const char *> expected_list
,
3721 dwarf2_per_objfile
*per_objfile
)
3723 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3725 bool matched
= true;
3727 auto mismatch
= [&] (const char *expected_str
,
3730 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3731 "expected=\"%s\", got=\"%s\"\n"),
3733 (match_type
== symbol_name_match_type::FULL
3735 name
, string_or_null (expected_str
), string_or_null (got
));
3739 auto expected_it
= expected_list
.begin ();
3740 auto expected_end
= expected_list
.end ();
3742 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3744 [&] (offset_type idx
)
3746 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3747 const char *expected_str
3748 = expected_it
== expected_end
? NULL
: *expected_it
++;
3750 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3751 mismatch (expected_str
, matched_name
);
3755 const char *expected_str
3756 = expected_it
== expected_end
? NULL
: *expected_it
++;
3757 if (expected_str
!= NULL
)
3758 mismatch (expected_str
, NULL
);
3763 /* The symbols added to the mock mapped_index for testing (in
3765 static const char *test_symbols
[] = {
3774 "ns2::tmpl<int>::foo2",
3775 "(anonymous namespace)::A::B::C",
3777 /* These are used to check that the increment-last-char in the
3778 matching algorithm for completion doesn't match "t1_fund" when
3779 completing "t1_func". */
3785 /* A UTF-8 name with multi-byte sequences to make sure that
3786 cp-name-parser understands this as a single identifier ("função"
3787 is "function" in PT). */
3790 /* \377 (0xff) is Latin1 'ÿ'. */
3793 /* \377 (0xff) is Latin1 'ÿ'. */
3797 /* A name with all sorts of complications. Starts with "z" to make
3798 it easier for the completion tests below. */
3799 #define Z_SYM_NAME \
3800 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3801 "::tuple<(anonymous namespace)::ui*, " \
3802 "std::default_delete<(anonymous namespace)::ui>, void>"
3807 /* Returns true if the mapped_index_base::find_name_component_bounds
3808 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3809 in completion mode. */
3812 check_find_bounds_finds (mapped_index_base
&index
,
3813 const char *search_name
,
3814 gdb::array_view
<const char *> expected_syms
,
3815 dwarf2_per_objfile
*per_objfile
)
3817 lookup_name_info
lookup_name (search_name
,
3818 symbol_name_match_type::FULL
, true);
3820 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3824 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3825 if (distance
!= expected_syms
.size ())
3828 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3830 auto nc_elem
= bounds
.first
+ exp_elem
;
3831 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3832 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3839 /* Test the lower-level mapped_index::find_name_component_bounds
3843 test_mapped_index_find_name_component_bounds ()
3845 mock_mapped_index
mock_index (test_symbols
);
3847 mock_index
.build_name_components (NULL
/* per_objfile */);
3849 /* Test the lower-level mapped_index::find_name_component_bounds
3850 method in completion mode. */
3852 static const char *expected_syms
[] = {
3857 SELF_CHECK (check_find_bounds_finds
3858 (mock_index
, "t1_func", expected_syms
,
3859 NULL
/* per_objfile */));
3862 /* Check that the increment-last-char in the name matching algorithm
3863 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3865 static const char *expected_syms1
[] = {
3869 SELF_CHECK (check_find_bounds_finds
3870 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3872 static const char *expected_syms2
[] = {
3875 SELF_CHECK (check_find_bounds_finds
3876 (mock_index
, "\377\377", expected_syms2
,
3877 NULL
/* per_objfile */));
3881 /* Test dw2_expand_symtabs_matching_symbol. */
3884 test_dw2_expand_symtabs_matching_symbol ()
3886 mock_mapped_index
mock_index (test_symbols
);
3888 /* We let all tests run until the end even if some fails, for debug
3890 bool any_mismatch
= false;
3892 /* Create the expected symbols list (an initializer_list). Needed
3893 because lists have commas, and we need to pass them to CHECK,
3894 which is a macro. */
3895 #define EXPECT(...) { __VA_ARGS__ }
3897 /* Wrapper for check_match that passes down the current
3898 __FILE__/__LINE__. */
3899 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
3900 any_mismatch |= !check_match (__FILE__, __LINE__, \
3902 NAME, MATCH_TYPE, COMPLETION_MODE, \
3903 EXPECTED_LIST, NULL)
3905 /* Identity checks. */
3906 for (const char *sym
: test_symbols
)
3908 /* Should be able to match all existing symbols. */
3909 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
3912 /* Should be able to match all existing symbols with
3914 std::string with_params
= std::string (sym
) + "(int)";
3915 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3918 /* Should be able to match all existing symbols with
3919 parameters and qualifiers. */
3920 with_params
= std::string (sym
) + " ( int ) const";
3921 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3924 /* This should really find sym, but cp-name-parser.y doesn't
3925 know about lvalue/rvalue qualifiers yet. */
3926 with_params
= std::string (sym
) + " ( int ) &&";
3927 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3931 /* Check that the name matching algorithm for completion doesn't get
3932 confused with Latin1 'ÿ' / 0xff. */
3934 static const char str
[] = "\377";
3935 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3936 EXPECT ("\377", "\377\377123"));
3939 /* Check that the increment-last-char in the matching algorithm for
3940 completion doesn't match "t1_fund" when completing "t1_func". */
3942 static const char str
[] = "t1_func";
3943 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3944 EXPECT ("t1_func", "t1_func1"));
3947 /* Check that completion mode works at each prefix of the expected
3950 static const char str
[] = "function(int)";
3951 size_t len
= strlen (str
);
3954 for (size_t i
= 1; i
< len
; i
++)
3956 lookup
.assign (str
, i
);
3957 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3958 EXPECT ("function"));
3962 /* While "w" is a prefix of both components, the match function
3963 should still only be called once. */
3965 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
3967 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
3971 /* Same, with a "complicated" symbol. */
3973 static const char str
[] = Z_SYM_NAME
;
3974 size_t len
= strlen (str
);
3977 for (size_t i
= 1; i
< len
; i
++)
3979 lookup
.assign (str
, i
);
3980 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3981 EXPECT (Z_SYM_NAME
));
3985 /* In FULL mode, an incomplete symbol doesn't match. */
3987 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
3991 /* A complete symbol with parameters matches any overload, since the
3992 index has no overload info. */
3994 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
3995 EXPECT ("std::zfunction", "std::zfunction2"));
3996 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
3997 EXPECT ("std::zfunction", "std::zfunction2"));
3998 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
3999 EXPECT ("std::zfunction", "std::zfunction2"));
4002 /* Check that whitespace is ignored appropriately. A symbol with a
4003 template argument list. */
4005 static const char expected
[] = "ns::foo<int>";
4006 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4008 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4012 /* Check that whitespace is ignored appropriately. A symbol with a
4013 template argument list that includes a pointer. */
4015 static const char expected
[] = "ns::foo<char*>";
4016 /* Try both completion and non-completion modes. */
4017 static const bool completion_mode
[2] = {false, true};
4018 for (size_t i
= 0; i
< 2; i
++)
4020 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4021 completion_mode
[i
], EXPECT (expected
));
4022 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4023 completion_mode
[i
], EXPECT (expected
));
4025 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4026 completion_mode
[i
], EXPECT (expected
));
4027 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4028 completion_mode
[i
], EXPECT (expected
));
4033 /* Check method qualifiers are ignored. */
4034 static const char expected
[] = "ns::foo<char*>";
4035 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4036 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4037 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4038 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4039 CHECK_MATCH ("foo < char * > ( int ) const",
4040 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4041 CHECK_MATCH ("foo < char * > ( int ) &&",
4042 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4045 /* Test lookup names that don't match anything. */
4047 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4050 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4054 /* Some wild matching tests, exercising "(anonymous namespace)",
4055 which should not be confused with a parameter list. */
4057 static const char *syms
[] = {
4061 "A :: B :: C ( int )",
4066 for (const char *s
: syms
)
4068 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4069 EXPECT ("(anonymous namespace)::A::B::C"));
4074 static const char expected
[] = "ns2::tmpl<int>::foo2";
4075 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4077 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4081 SELF_CHECK (!any_mismatch
);
4090 test_mapped_index_find_name_component_bounds ();
4091 test_dw2_expand_symtabs_matching_symbol ();
4094 }} // namespace selftests::dw2_expand_symtabs_matching
4096 #endif /* GDB_SELF_TEST */
4098 /* If FILE_MATCHER is NULL or if PER_CU has
4099 dwarf2_per_cu_quick_data::MARK set (see
4100 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4101 EXPANSION_NOTIFY on it. */
4104 dw2_expand_symtabs_matching_one
4105 (dwarf2_per_cu_data
*per_cu
,
4106 dwarf2_per_objfile
*per_objfile
,
4107 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4108 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4110 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4112 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4114 compunit_symtab
*symtab
4115 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4116 gdb_assert (symtab
!= nullptr);
4118 if (expansion_notify
!= NULL
&& symtab_was_null
)
4119 return expansion_notify (symtab
);
4124 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4125 matched, to expand corresponding CUs that were marked. IDX is the
4126 index of the symbol name that matched. */
4129 dw2_expand_marked_cus
4130 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4131 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4132 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4133 block_search_flags search_flags
,
4136 offset_type vec_len
, vec_idx
;
4137 bool global_seen
= false;
4138 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4140 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4142 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4144 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4145 /* This value is only valid for index versions >= 7. */
4146 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4147 gdb_index_symbol_kind symbol_kind
=
4148 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4149 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4150 /* Only check the symbol attributes if they're present.
4151 Indices prior to version 7 don't record them,
4152 and indices >= 7 may elide them for certain symbols
4153 (gold does this). */
4156 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4158 /* Work around gold/15646. */
4161 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4169 /* Only check the symbol's kind if it has one. */
4174 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4179 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4185 case VARIABLES_DOMAIN
:
4186 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4189 case FUNCTIONS_DOMAIN
:
4190 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4194 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4197 case MODULES_DOMAIN
:
4198 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4206 /* Don't crash on bad data. */
4207 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4209 complaint (_(".gdb_index entry has bad CU index"
4210 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4214 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4215 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4223 /* If FILE_MATCHER is non-NULL, set all the
4224 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4225 that match FILE_MATCHER. */
4228 dw_expand_symtabs_matching_file_matcher
4229 (dwarf2_per_objfile
*per_objfile
,
4230 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4232 if (file_matcher
== NULL
)
4235 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4237 NULL
, xcalloc
, xfree
));
4238 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4240 NULL
, xcalloc
, xfree
));
4242 /* The rule is CUs specify all the files, including those used by
4243 any TU, so there's no need to scan TUs here. */
4245 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4249 if (per_cu
->is_debug_types
)
4251 per_cu
->v
.quick
->mark
= 0;
4253 /* We only need to look at symtabs not already expanded. */
4254 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4257 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4259 if (file_data
== NULL
)
4262 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4264 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4266 per_cu
->v
.quick
->mark
= 1;
4270 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4272 const char *this_real_name
;
4274 if (file_matcher (file_data
->file_names
[j
], false))
4276 per_cu
->v
.quick
->mark
= 1;
4280 /* Before we invoke realpath, which can get expensive when many
4281 files are involved, do a quick comparison of the basenames. */
4282 if (!basenames_may_differ
4283 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4287 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4288 if (file_matcher (this_real_name
, false))
4290 per_cu
->v
.quick
->mark
= 1;
4295 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4296 ? visited_found
.get ()
4297 : visited_not_found
.get (),
4304 dwarf2_gdb_index::expand_symtabs_matching
4305 (struct objfile
*objfile
,
4306 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4307 const lookup_name_info
*lookup_name
,
4308 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4309 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4310 block_search_flags search_flags
,
4312 enum search_domain kind
)
4314 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4316 /* index_table is NULL if OBJF_READNOW. */
4317 if (!per_objfile
->per_bfd
->index_table
)
4320 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4322 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4324 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4328 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
4336 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4339 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4341 [&] (offset_type idx
)
4343 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4344 expansion_notify
, search_flags
, kind
))
4352 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4355 static struct compunit_symtab
*
4356 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4361 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4362 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4365 if (cust
->includes
== NULL
)
4368 for (i
= 0; cust
->includes
[i
]; ++i
)
4370 struct compunit_symtab
*s
= cust
->includes
[i
];
4372 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4380 struct compunit_symtab
*
4381 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4382 (struct objfile
*objfile
,
4383 struct bound_minimal_symbol msymbol
,
4385 struct obj_section
*section
,
4388 struct dwarf2_per_cu_data
*data
;
4389 struct compunit_symtab
*result
;
4391 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4392 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4395 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4396 data
= ((struct dwarf2_per_cu_data
*)
4397 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4402 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4403 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4404 paddress (objfile
->arch (), pc
));
4406 result
= recursively_find_pc_sect_compunit_symtab
4407 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4409 gdb_assert (result
!= NULL
);
4414 dwarf2_base_index_functions::map_symbol_filenames
4415 (struct objfile
*objfile
,
4416 gdb::function_view
<symbol_filename_ftype
> fun
,
4419 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4421 /* Use caches to ensure we only call FUN once for each filename. */
4422 filename_seen_cache filenames_cache
;
4423 std::unordered_set
<quick_file_names
*> qfn_cache
;
4425 /* The rule is CUs specify all the files, including those used by any TU,
4426 so there's no need to scan TUs here. We can ignore file names coming
4427 from already-expanded CUs. It is possible that an expanded CU might
4428 reuse the file names data from a currently unexpanded CU, in this
4429 case we don't want to report the files from the unexpanded CU. */
4431 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4433 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4435 if (per_cu
->v
.quick
->file_names
!= nullptr)
4436 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4440 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4442 /* We only need to look at symtabs not already expanded. */
4443 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4446 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4448 if (file_data
== nullptr
4449 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4452 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4454 const char *filename
= file_data
->file_names
[j
];
4455 filenames_cache
.seen (filename
);
4459 filenames_cache
.traverse ([&] (const char *filename
)
4461 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4464 this_real_name
= gdb_realpath (filename
);
4465 fun (filename
, this_real_name
.get ());
4470 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4475 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
4478 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
4480 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4482 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4484 /* Is this already expanded? */
4485 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4488 /* It has not yet been expanded. */
4495 /* DWARF-5 debug_names reader. */
4497 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4498 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4500 /* A helper function that reads the .debug_names section in SECTION
4501 and fills in MAP. FILENAME is the name of the file containing the
4502 section; it is used for error reporting.
4504 Returns true if all went well, false otherwise. */
4507 read_debug_names_from_section (struct objfile
*objfile
,
4508 const char *filename
,
4509 struct dwarf2_section_info
*section
,
4510 mapped_debug_names
&map
)
4512 if (section
->empty ())
4515 /* Older elfutils strip versions could keep the section in the main
4516 executable while splitting it for the separate debug info file. */
4517 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4520 section
->read (objfile
);
4522 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4524 const gdb_byte
*addr
= section
->buffer
;
4526 bfd
*const abfd
= section
->get_bfd_owner ();
4528 unsigned int bytes_read
;
4529 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4532 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4533 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4534 if (bytes_read
+ length
!= section
->size
)
4536 /* There may be multiple per-CU indices. */
4537 warning (_("Section .debug_names in %s length %s does not match "
4538 "section length %s, ignoring .debug_names."),
4539 filename
, plongest (bytes_read
+ length
),
4540 pulongest (section
->size
));
4544 /* The version number. */
4545 uint16_t version
= read_2_bytes (abfd
, addr
);
4549 warning (_("Section .debug_names in %s has unsupported version %d, "
4550 "ignoring .debug_names."),
4556 uint16_t padding
= read_2_bytes (abfd
, addr
);
4560 warning (_("Section .debug_names in %s has unsupported padding %d, "
4561 "ignoring .debug_names."),
4566 /* comp_unit_count - The number of CUs in the CU list. */
4567 map
.cu_count
= read_4_bytes (abfd
, addr
);
4570 /* local_type_unit_count - The number of TUs in the local TU
4572 map
.tu_count
= read_4_bytes (abfd
, addr
);
4575 /* foreign_type_unit_count - The number of TUs in the foreign TU
4577 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4579 if (foreign_tu_count
!= 0)
4581 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4582 "ignoring .debug_names."),
4583 filename
, static_cast<unsigned long> (foreign_tu_count
));
4587 /* bucket_count - The number of hash buckets in the hash lookup
4589 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4592 /* name_count - The number of unique names in the index. */
4593 map
.name_count
= read_4_bytes (abfd
, addr
);
4596 /* abbrev_table_size - The size in bytes of the abbreviations
4598 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4601 /* augmentation_string_size - The size in bytes of the augmentation
4602 string. This value is rounded up to a multiple of 4. */
4603 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4605 map
.augmentation_is_gdb
= ((augmentation_string_size
4606 == sizeof (dwarf5_augmentation
))
4607 && memcmp (addr
, dwarf5_augmentation
,
4608 sizeof (dwarf5_augmentation
)) == 0);
4609 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4610 addr
+= augmentation_string_size
;
4613 map
.cu_table_reordered
= addr
;
4614 addr
+= map
.cu_count
* map
.offset_size
;
4616 /* List of Local TUs */
4617 map
.tu_table_reordered
= addr
;
4618 addr
+= map
.tu_count
* map
.offset_size
;
4620 /* Hash Lookup Table */
4621 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4622 addr
+= map
.bucket_count
* 4;
4623 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4624 addr
+= map
.name_count
* 4;
4627 map
.name_table_string_offs_reordered
= addr
;
4628 addr
+= map
.name_count
* map
.offset_size
;
4629 map
.name_table_entry_offs_reordered
= addr
;
4630 addr
+= map
.name_count
* map
.offset_size
;
4632 const gdb_byte
*abbrev_table_start
= addr
;
4635 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4640 const auto insertpair
4641 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4642 if (!insertpair
.second
)
4644 warning (_("Section .debug_names in %s has duplicate index %s, "
4645 "ignoring .debug_names."),
4646 filename
, pulongest (index_num
));
4649 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4650 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4655 mapped_debug_names::index_val::attr attr
;
4656 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4658 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4660 if (attr
.form
== DW_FORM_implicit_const
)
4662 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4666 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4668 indexval
.attr_vec
.push_back (std::move (attr
));
4671 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4673 warning (_("Section .debug_names in %s has abbreviation_table "
4674 "of size %s vs. written as %u, ignoring .debug_names."),
4675 filename
, plongest (addr
- abbrev_table_start
),
4679 map
.entry_pool
= addr
;
4684 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4688 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4689 const mapped_debug_names
&map
,
4690 dwarf2_section_info
§ion
,
4693 if (!map
.augmentation_is_gdb
)
4695 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4697 sect_offset sect_off
4698 = (sect_offset
) (extract_unsigned_integer
4699 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4701 map
.dwarf5_byte_order
));
4702 /* We don't know the length of the CU, because the CU list in a
4703 .debug_names index can be incomplete, so we can't use the start
4704 of the next CU as end of this CU. We create the CUs here with
4705 length 0, and in cutu_reader::cutu_reader we'll fill in the
4707 dwarf2_per_cu_data_up per_cu
4708 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4710 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4715 sect_offset sect_off_prev
;
4716 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4718 sect_offset sect_off_next
;
4719 if (i
< map
.cu_count
)
4722 = (sect_offset
) (extract_unsigned_integer
4723 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4725 map
.dwarf5_byte_order
));
4728 sect_off_next
= (sect_offset
) section
.size
;
4731 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4732 dwarf2_per_cu_data_up per_cu
4733 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4734 sect_off_prev
, length
);
4735 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4737 sect_off_prev
= sect_off_next
;
4741 /* Read the CU list from the mapped index, and use it to create all
4742 the CU objects for this dwarf2_per_objfile. */
4745 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4746 const mapped_debug_names
&map
,
4747 const mapped_debug_names
&dwz_map
)
4749 gdb_assert (per_bfd
->all_comp_units
.empty ());
4750 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4752 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4753 false /* is_dwz */);
4755 if (dwz_map
.cu_count
== 0)
4758 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4759 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4763 /* Read .debug_names. If everything went ok, initialize the "quick"
4764 elements of all the CUs and return true. Otherwise, return false. */
4767 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4769 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4770 mapped_debug_names dwz_map
;
4771 struct objfile
*objfile
= per_objfile
->objfile
;
4772 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4774 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4775 &per_bfd
->debug_names
, *map
))
4778 /* Don't use the index if it's empty. */
4779 if (map
->name_count
== 0)
4782 /* If there is a .dwz file, read it so we can get its CU list as
4784 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4787 if (!read_debug_names_from_section (objfile
,
4788 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4789 &dwz
->debug_names
, dwz_map
))
4791 warning (_("could not read '.debug_names' section from %s; skipping"),
4792 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4797 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4799 if (map
->tu_count
!= 0)
4801 /* We can only handle a single .debug_types when we have an
4803 if (per_bfd
->types
.size () != 1)
4806 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4808 create_signatured_type_table_from_debug_names
4809 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4812 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4814 per_bfd
->debug_names_table
= std::move (map
);
4815 per_bfd
->using_index
= 1;
4816 per_bfd
->quick_file_names_table
=
4817 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4822 /* Type used to manage iterating over all CUs looking for a symbol for
4825 class dw2_debug_names_iterator
4828 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4829 block_search_flags block_index
,
4831 const char *name
, dwarf2_per_objfile
*per_objfile
)
4832 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4833 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4834 m_per_objfile (per_objfile
)
4837 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4838 search_domain search
, uint32_t namei
,
4839 dwarf2_per_objfile
*per_objfile
,
4840 domain_enum domain
= UNDEF_DOMAIN
)
4844 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4845 m_per_objfile (per_objfile
)
4848 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4849 block_search_flags block_index
, domain_enum domain
,
4850 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4851 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4852 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4853 m_per_objfile (per_objfile
)
4856 /* Return the next matching CU or NULL if there are no more. */
4857 dwarf2_per_cu_data
*next ();
4860 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4862 dwarf2_per_objfile
*per_objfile
);
4863 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4865 dwarf2_per_objfile
*per_objfile
);
4867 /* The internalized form of .debug_names. */
4868 const mapped_debug_names
&m_map
;
4870 /* Restrict the search to these blocks. */
4871 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4872 | SEARCH_STATIC_BLOCK
);
4874 /* The kind of symbol we're looking for. */
4875 const domain_enum m_domain
= UNDEF_DOMAIN
;
4876 const search_domain m_search
= ALL_DOMAIN
;
4878 /* The list of CUs from the index entry of the symbol, or NULL if
4880 const gdb_byte
*m_addr
;
4882 dwarf2_per_objfile
*m_per_objfile
;
4886 mapped_debug_names::namei_to_name
4887 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
4889 const ULONGEST namei_string_offs
4890 = extract_unsigned_integer ((name_table_string_offs_reordered
4891 + namei
* offset_size
),
4894 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
4897 /* Find a slot in .debug_names for the object named NAME. If NAME is
4898 found, return pointer to its pool data. If NAME cannot be found,
4902 dw2_debug_names_iterator::find_vec_in_debug_names
4903 (const mapped_debug_names
&map
, const char *name
,
4904 dwarf2_per_objfile
*per_objfile
)
4906 int (*cmp
) (const char *, const char *);
4908 gdb::unique_xmalloc_ptr
<char> without_params
;
4909 if (current_language
->la_language
== language_cplus
4910 || current_language
->la_language
== language_fortran
4911 || current_language
->la_language
== language_d
)
4913 /* NAME is already canonical. Drop any qualifiers as
4914 .debug_names does not contain any. */
4916 if (strchr (name
, '(') != NULL
)
4918 without_params
= cp_remove_params (name
);
4919 if (without_params
!= NULL
)
4920 name
= without_params
.get ();
4924 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
4926 const uint32_t full_hash
= dwarf5_djb_hash (name
);
4928 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4929 (map
.bucket_table_reordered
4930 + (full_hash
% map
.bucket_count
)), 4,
4931 map
.dwarf5_byte_order
);
4935 if (namei
>= map
.name_count
)
4937 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4939 namei
, map
.name_count
,
4940 objfile_name (per_objfile
->objfile
));
4946 const uint32_t namei_full_hash
4947 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4948 (map
.hash_table_reordered
+ namei
), 4,
4949 map
.dwarf5_byte_order
);
4950 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
4953 if (full_hash
== namei_full_hash
)
4955 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
4957 #if 0 /* An expensive sanity check. */
4958 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
4960 complaint (_("Wrong .debug_names hash for string at index %u "
4962 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
4967 if (cmp (namei_string
, name
) == 0)
4969 const ULONGEST namei_entry_offs
4970 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4971 + namei
* map
.offset_size
),
4972 map
.offset_size
, map
.dwarf5_byte_order
);
4973 return map
.entry_pool
+ namei_entry_offs
;
4978 if (namei
>= map
.name_count
)
4984 dw2_debug_names_iterator::find_vec_in_debug_names
4985 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4987 if (namei
>= map
.name_count
)
4989 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4991 namei
, map
.name_count
,
4992 objfile_name (per_objfile
->objfile
));
4996 const ULONGEST namei_entry_offs
4997 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4998 + namei
* map
.offset_size
),
4999 map
.offset_size
, map
.dwarf5_byte_order
);
5000 return map
.entry_pool
+ namei_entry_offs
;
5003 /* See dw2_debug_names_iterator. */
5005 dwarf2_per_cu_data
*
5006 dw2_debug_names_iterator::next ()
5011 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5012 struct objfile
*objfile
= m_per_objfile
->objfile
;
5013 bfd
*const abfd
= objfile
->obfd
;
5017 unsigned int bytes_read
;
5018 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5019 m_addr
+= bytes_read
;
5023 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5024 if (indexval_it
== m_map
.abbrev_map
.cend ())
5026 complaint (_("Wrong .debug_names undefined abbrev code %s "
5028 pulongest (abbrev
), objfile_name (objfile
));
5031 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5032 enum class symbol_linkage
{
5036 } symbol_linkage_
= symbol_linkage::unknown
;
5037 dwarf2_per_cu_data
*per_cu
= NULL
;
5038 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5043 case DW_FORM_implicit_const
:
5044 ull
= attr
.implicit_const
;
5046 case DW_FORM_flag_present
:
5050 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5051 m_addr
+= bytes_read
;
5054 ull
= read_4_bytes (abfd
, m_addr
);
5058 ull
= read_8_bytes (abfd
, m_addr
);
5061 case DW_FORM_ref_sig8
:
5062 ull
= read_8_bytes (abfd
, m_addr
);
5066 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5067 dwarf_form_name (attr
.form
),
5068 objfile_name (objfile
));
5071 switch (attr
.dw_idx
)
5073 case DW_IDX_compile_unit
:
5074 /* Don't crash on bad data. */
5075 if (ull
>= per_bfd
->all_comp_units
.size ())
5077 complaint (_(".debug_names entry has bad CU index %s"
5080 objfile_name (objfile
));
5083 per_cu
= per_bfd
->get_cu (ull
);
5085 case DW_IDX_type_unit
:
5086 /* Don't crash on bad data. */
5087 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5089 complaint (_(".debug_names entry has bad TU index %s"
5092 objfile_name (objfile
));
5095 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5097 case DW_IDX_die_offset
:
5098 /* In a per-CU index (as opposed to a per-module index), index
5099 entries without CU attribute implicitly refer to the single CU. */
5101 per_cu
= per_bfd
->get_cu (0);
5103 case DW_IDX_GNU_internal
:
5104 if (!m_map
.augmentation_is_gdb
)
5106 symbol_linkage_
= symbol_linkage::static_
;
5108 case DW_IDX_GNU_external
:
5109 if (!m_map
.augmentation_is_gdb
)
5111 symbol_linkage_
= symbol_linkage::extern_
;
5116 /* Skip if already read in. */
5117 if (m_per_objfile
->symtab_set_p (per_cu
))
5120 /* Check static vs global. */
5121 if (symbol_linkage_
!= symbol_linkage::unknown
)
5123 if (symbol_linkage_
== symbol_linkage::static_
)
5125 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5130 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5135 /* Match dw2_symtab_iter_next, symbol_kind
5136 and debug_names::psymbol_tag. */
5140 switch (indexval
.dwarf_tag
)
5142 case DW_TAG_variable
:
5143 case DW_TAG_subprogram
:
5144 /* Some types are also in VAR_DOMAIN. */
5145 case DW_TAG_typedef
:
5146 case DW_TAG_structure_type
:
5153 switch (indexval
.dwarf_tag
)
5155 case DW_TAG_typedef
:
5156 case DW_TAG_structure_type
:
5163 switch (indexval
.dwarf_tag
)
5166 case DW_TAG_variable
:
5173 switch (indexval
.dwarf_tag
)
5185 /* Match dw2_expand_symtabs_matching, symbol_kind and
5186 debug_names::psymbol_tag. */
5189 case VARIABLES_DOMAIN
:
5190 switch (indexval
.dwarf_tag
)
5192 case DW_TAG_variable
:
5198 case FUNCTIONS_DOMAIN
:
5199 switch (indexval
.dwarf_tag
)
5201 case DW_TAG_subprogram
:
5208 switch (indexval
.dwarf_tag
)
5210 case DW_TAG_typedef
:
5211 case DW_TAG_structure_type
:
5217 case MODULES_DOMAIN
:
5218 switch (indexval
.dwarf_tag
)
5232 /* This dumps minimal information about .debug_names. It is called
5233 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5234 uses this to verify that .debug_names has been loaded. */
5237 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5239 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5241 gdb_assert (per_objfile
->per_bfd
->using_index
);
5242 printf_filtered (".debug_names:");
5243 if (per_objfile
->per_bfd
->debug_names_table
)
5244 printf_filtered (" exists\n");
5246 printf_filtered (" faked for \"readnow\"\n");
5247 printf_filtered ("\n");
5251 dwarf2_debug_names_index::expand_matching_symbols
5252 (struct objfile
*objfile
,
5253 const lookup_name_info
&name
, domain_enum domain
,
5255 symbol_compare_ftype
*ordered_compare
)
5257 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5259 /* debug_names_table is NULL if OBJF_READNOW. */
5260 if (!per_objfile
->per_bfd
->debug_names_table
)
5263 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5264 const block_search_flags block_flags
5265 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5267 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5268 auto matcher
= [&] (const char *symname
)
5270 if (ordered_compare
== nullptr)
5272 return ordered_compare (symname
, match_name
) == 0;
5275 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5276 [&] (offset_type namei
)
5278 /* The name was matched, now expand corresponding CUs that were
5280 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5283 struct dwarf2_per_cu_data
*per_cu
;
5284 while ((per_cu
= iter
.next ()) != NULL
)
5285 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5292 dwarf2_debug_names_index::expand_symtabs_matching
5293 (struct objfile
*objfile
,
5294 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5295 const lookup_name_info
*lookup_name
,
5296 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5297 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5298 block_search_flags search_flags
,
5300 enum search_domain kind
)
5302 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5304 /* debug_names_table is NULL if OBJF_READNOW. */
5305 if (!per_objfile
->per_bfd
->debug_names_table
)
5308 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5310 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5312 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5316 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
5324 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5327 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5329 [&] (offset_type namei
)
5331 /* The name was matched, now expand corresponding CUs that were
5333 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5335 struct dwarf2_per_cu_data
*per_cu
;
5336 while ((per_cu
= iter
.next ()) != NULL
)
5337 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5347 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5348 to either a dwarf2_per_bfd or dwz_file object. */
5350 template <typename T
>
5351 static gdb::array_view
<const gdb_byte
>
5352 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5354 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5356 if (section
->empty ())
5359 /* Older elfutils strip versions could keep the section in the main
5360 executable while splitting it for the separate debug info file. */
5361 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5364 section
->read (obj
);
5366 /* dwarf2_section_info::size is a bfd_size_type, while
5367 gdb::array_view works with size_t. On 32-bit hosts, with
5368 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5369 is 32-bit. So we need an explicit narrowing conversion here.
5370 This is fine, because it's impossible to allocate or mmap an
5371 array/buffer larger than what size_t can represent. */
5372 return gdb::make_array_view (section
->buffer
, section
->size
);
5375 /* Lookup the index cache for the contents of the index associated to
5378 static gdb::array_view
<const gdb_byte
>
5379 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5381 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5382 if (build_id
== nullptr)
5385 return global_index_cache
.lookup_gdb_index (build_id
,
5386 &dwarf2_per_bfd
->index_cache_res
);
5389 /* Same as the above, but for DWZ. */
5391 static gdb::array_view
<const gdb_byte
>
5392 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5394 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5395 if (build_id
== nullptr)
5398 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5401 /* See dwarf2/public.h. */
5404 dwarf2_initialize_objfile (struct objfile
*objfile
)
5406 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5407 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5409 dwarf_read_debug_printf ("called");
5411 /* If we're about to read full symbols, don't bother with the
5412 indices. In this case we also don't care if some other debug
5413 format is making psymtabs, because they are all about to be
5415 if ((objfile
->flags
& OBJF_READNOW
))
5417 dwarf_read_debug_printf ("readnow requested");
5419 /* When using READNOW, the using_index flag (set below) indicates that
5420 PER_BFD was already initialized, when we loaded some other objfile. */
5421 if (per_bfd
->using_index
)
5423 dwarf_read_debug_printf ("using_index already set");
5424 per_objfile
->resize_symtabs ();
5425 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5429 per_bfd
->using_index
= 1;
5430 create_all_comp_units (per_objfile
);
5431 per_bfd
->quick_file_names_table
5432 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5433 per_objfile
->resize_symtabs ();
5435 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5437 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5439 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5440 struct dwarf2_per_cu_quick_data
);
5443 /* Arrange for gdb to see the "quick" functions. However, these
5444 functions will be no-ops because we will have expanded all
5446 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5450 /* Was a debug names index already read when we processed an objfile sharing
5452 if (per_bfd
->debug_names_table
!= nullptr)
5454 dwarf_read_debug_printf ("re-using shared debug names table");
5455 per_objfile
->resize_symtabs ();
5456 objfile
->qf
.push_front (make_dwarf_debug_names ());
5460 /* Was a GDB index already read when we processed an objfile sharing
5462 if (per_bfd
->index_table
!= nullptr)
5464 dwarf_read_debug_printf ("re-using shared index table");
5465 per_objfile
->resize_symtabs ();
5466 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5470 /* There might already be partial symtabs built for this BFD. This happens
5471 when loading the same binary twice with the index-cache enabled. If so,
5472 don't try to read an index. The objfile / per_objfile initialization will
5473 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5475 if (per_bfd
->partial_symtabs
!= nullptr)
5477 dwarf_read_debug_printf ("re-using shared partial symtabs");
5478 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5482 if (dwarf2_read_debug_names (per_objfile
))
5484 dwarf_read_debug_printf ("found debug names");
5485 per_objfile
->resize_symtabs ();
5486 objfile
->qf
.push_front (make_dwarf_debug_names ());
5490 if (dwarf2_read_gdb_index (per_objfile
,
5491 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5492 get_gdb_index_contents_from_section
<dwz_file
>))
5494 dwarf_read_debug_printf ("found gdb index from file");
5495 per_objfile
->resize_symtabs ();
5496 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5500 /* ... otherwise, try to find the index in the index cache. */
5501 if (dwarf2_read_gdb_index (per_objfile
,
5502 get_gdb_index_contents_from_cache
,
5503 get_gdb_index_contents_from_cache_dwz
))
5505 dwarf_read_debug_printf ("found gdb index from cache");
5506 global_index_cache
.hit ();
5507 per_objfile
->resize_symtabs ();
5508 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5512 global_index_cache
.miss ();
5513 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5518 /* Build a partial symbol table. */
5521 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5523 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5524 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5526 if (per_bfd
->partial_symtabs
!= nullptr)
5528 /* Partial symbols were already read, so now we can simply
5532 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5533 objfile
->qf
.emplace_front (psf
);
5536 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5537 per_objfile
->resize_symtabs ();
5543 psf
= new psymbol_functions
;
5544 objfile
->qf
.emplace_front (psf
);
5546 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5547 = psf
->get_partial_symtabs ();
5549 /* Set the local reference to partial symtabs, so that we don't try
5550 to read them again if reading another objfile with the same BFD.
5551 If we can't in fact share, this won't make a difference anyway as
5552 the dwarf2_per_bfd object won't be shared. */
5553 per_bfd
->partial_symtabs
= partial_symtabs
;
5557 /* This isn't really ideal: all the data we allocate on the
5558 objfile's obstack is still uselessly kept around. However,
5559 freeing it seems unsafe. */
5560 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5561 dwarf2_build_psymtabs_hard (per_objfile
);
5564 per_objfile
->resize_symtabs ();
5566 /* (maybe) store an index in the cache. */
5567 global_index_cache
.store (per_objfile
);
5569 catch (const gdb_exception_error
&except
)
5571 exception_print (gdb_stderr
, except
);
5575 /* Find the base address of the compilation unit for range lists and
5576 location lists. It will normally be specified by DW_AT_low_pc.
5577 In DWARF-3 draft 4, the base address could be overridden by
5578 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5579 compilation units with discontinuous ranges. */
5582 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5584 struct attribute
*attr
;
5586 cu
->base_address
.reset ();
5588 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5589 if (attr
!= nullptr)
5590 cu
->base_address
= attr
->as_address ();
5593 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5594 if (attr
!= nullptr)
5595 cu
->base_address
= attr
->as_address ();
5599 /* Helper function that returns the proper abbrev section for
5602 static struct dwarf2_section_info
*
5603 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5605 struct dwarf2_section_info
*abbrev
;
5606 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5608 if (this_cu
->is_dwz
)
5609 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5611 abbrev
= &per_bfd
->abbrev
;
5616 /* Fetch the abbreviation table offset from a comp or type unit header. */
5619 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5620 struct dwarf2_section_info
*section
,
5621 sect_offset sect_off
)
5623 bfd
*abfd
= section
->get_bfd_owner ();
5624 const gdb_byte
*info_ptr
;
5625 unsigned int initial_length_size
, offset_size
;
5628 section
->read (per_objfile
->objfile
);
5629 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5630 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5631 offset_size
= initial_length_size
== 4 ? 4 : 8;
5632 info_ptr
+= initial_length_size
;
5634 version
= read_2_bytes (abfd
, info_ptr
);
5638 /* Skip unit type and address size. */
5642 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5645 /* A partial symtab that is used only for include files. */
5646 struct dwarf2_include_psymtab
: public partial_symtab
5648 dwarf2_include_psymtab (const char *filename
,
5649 psymtab_storage
*partial_symtabs
,
5650 objfile_per_bfd_storage
*objfile_per_bfd
)
5651 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5655 void read_symtab (struct objfile
*objfile
) override
5657 /* It's an include file, no symbols to read for it.
5658 Everything is in the includer symtab. */
5660 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5661 expansion of the includer psymtab. We use the dependencies[0] field to
5662 model the includer. But if we go the regular route of calling
5663 expand_psymtab here, and having expand_psymtab call expand_dependencies
5664 to expand the includer, we'll only use expand_psymtab on the includer
5665 (making it a non-toplevel psymtab), while if we expand the includer via
5666 another path, we'll use read_symtab (making it a toplevel psymtab).
5667 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5668 psymtab, and trigger read_symtab on the includer here directly. */
5669 includer ()->read_symtab (objfile
);
5672 void expand_psymtab (struct objfile
*objfile
) override
5674 /* This is not called by read_symtab, and should not be called by any
5675 expand_dependencies. */
5679 bool readin_p (struct objfile
*objfile
) const override
5681 return includer ()->readin_p (objfile
);
5684 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5690 partial_symtab
*includer () const
5692 /* An include psymtab has exactly one dependency: the psymtab that
5694 gdb_assert (this->number_of_dependencies
== 1);
5695 return this->dependencies
[0];
5699 /* Allocate a new partial symtab for file named NAME and mark this new
5700 partial symtab as being an include of PST. */
5703 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5705 dwarf2_psymtab
*pst
,
5706 psymtab_storage
*partial_symtabs
,
5707 objfile_per_bfd_storage
*objfile_per_bfd
)
5709 dwarf2_include_psymtab
*subpst
5710 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5712 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5713 subpst
->dirname
= pst
->dirname
;
5715 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5716 subpst
->dependencies
[0] = pst
;
5717 subpst
->number_of_dependencies
= 1;
5720 /* Read the Line Number Program data and extract the list of files
5721 included by the source file represented by PST. Build an include
5722 partial symtab for each of these included files. */
5725 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5726 struct die_info
*die
,
5727 dwarf2_psymtab
*pst
)
5730 struct attribute
*attr
;
5732 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5733 if (attr
!= nullptr && attr
->form_is_unsigned ())
5734 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5736 return; /* No linetable, so no includes. */
5738 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5739 that we pass in the raw text_low here; that is ok because we're
5740 only decoding the line table to make include partial symtabs, and
5741 so the addresses aren't really used. */
5742 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5743 pst
->raw_text_low (), 1);
5747 hash_signatured_type (const void *item
)
5749 const struct signatured_type
*sig_type
5750 = (const struct signatured_type
*) item
;
5752 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5753 return sig_type
->signature
;
5757 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5759 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5760 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5762 return lhs
->signature
== rhs
->signature
;
5765 /* Allocate a hash table for signatured types. */
5768 allocate_signatured_type_table ()
5770 return htab_up (htab_create_alloc (41,
5771 hash_signatured_type
,
5773 NULL
, xcalloc
, xfree
));
5776 /* A helper for create_debug_types_hash_table. Read types from SECTION
5777 and fill them into TYPES_HTAB. It will process only type units,
5778 therefore DW_UT_type. */
5781 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5782 struct dwo_file
*dwo_file
,
5783 dwarf2_section_info
*section
, htab_up
&types_htab
,
5784 rcuh_kind section_kind
)
5786 struct objfile
*objfile
= per_objfile
->objfile
;
5787 struct dwarf2_section_info
*abbrev_section
;
5789 const gdb_byte
*info_ptr
, *end_ptr
;
5791 abbrev_section
= &dwo_file
->sections
.abbrev
;
5793 dwarf_read_debug_printf ("Reading %s for %s",
5794 section
->get_name (),
5795 abbrev_section
->get_file_name ());
5797 section
->read (objfile
);
5798 info_ptr
= section
->buffer
;
5800 if (info_ptr
== NULL
)
5803 /* We can't set abfd until now because the section may be empty or
5804 not present, in which case the bfd is unknown. */
5805 abfd
= section
->get_bfd_owner ();
5807 /* We don't use cutu_reader here because we don't need to read
5808 any dies: the signature is in the header. */
5810 end_ptr
= info_ptr
+ section
->size
;
5811 while (info_ptr
< end_ptr
)
5813 signatured_type_up sig_type
;
5814 struct dwo_unit
*dwo_tu
;
5816 const gdb_byte
*ptr
= info_ptr
;
5817 struct comp_unit_head header
;
5818 unsigned int length
;
5820 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5822 /* Initialize it due to a false compiler warning. */
5823 header
.signature
= -1;
5824 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5826 /* We need to read the type's signature in order to build the hash
5827 table, but we don't need anything else just yet. */
5829 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5830 abbrev_section
, ptr
, section_kind
);
5832 length
= header
.get_length ();
5834 /* Skip dummy type units. */
5835 if (ptr
>= info_ptr
+ length
5836 || peek_abbrev_code (abfd
, ptr
) == 0
5837 || (header
.unit_type
!= DW_UT_type
5838 && header
.unit_type
!= DW_UT_split_type
))
5844 if (types_htab
== NULL
)
5845 types_htab
= allocate_dwo_unit_table ();
5847 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5848 dwo_tu
->dwo_file
= dwo_file
;
5849 dwo_tu
->signature
= header
.signature
;
5850 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5851 dwo_tu
->section
= section
;
5852 dwo_tu
->sect_off
= sect_off
;
5853 dwo_tu
->length
= length
;
5855 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5856 gdb_assert (slot
!= NULL
);
5858 complaint (_("debug type entry at offset %s is duplicate to"
5859 " the entry at offset %s, signature %s"),
5860 sect_offset_str (sect_off
),
5861 sect_offset_str (dwo_tu
->sect_off
),
5862 hex_string (header
.signature
));
5865 dwarf_read_debug_printf_v (" offset %s, signature %s",
5866 sect_offset_str (sect_off
),
5867 hex_string (header
.signature
));
5873 /* Create the hash table of all entries in the .debug_types
5874 (or .debug_types.dwo) section(s).
5875 DWO_FILE is a pointer to the DWO file object.
5877 The result is a pointer to the hash table or NULL if there are no types.
5879 Note: This function processes DWO files only, not DWP files. */
5882 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5883 struct dwo_file
*dwo_file
,
5884 gdb::array_view
<dwarf2_section_info
> type_sections
,
5885 htab_up
&types_htab
)
5887 for (dwarf2_section_info
§ion
: type_sections
)
5888 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5892 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5893 If SLOT is non-NULL, it is the entry to use in the hash table.
5894 Otherwise we find one. */
5896 static struct signatured_type
*
5897 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
5899 if (per_objfile
->per_bfd
->all_comp_units
.size ()
5900 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
5901 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
5903 signatured_type_up sig_type_holder
5904 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
5905 signatured_type
*sig_type
= sig_type_holder
.get ();
5907 per_objfile
->resize_symtabs ();
5909 per_objfile
->per_bfd
->all_comp_units
.emplace_back
5910 (sig_type_holder
.release ());
5911 if (per_objfile
->per_bfd
->using_index
)
5914 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
5915 struct dwarf2_per_cu_quick_data
);
5920 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5923 gdb_assert (*slot
== NULL
);
5925 /* The rest of sig_type must be filled in by the caller. */
5929 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5930 Fill in SIG_ENTRY with DWO_ENTRY. */
5933 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
5934 struct signatured_type
*sig_entry
,
5935 struct dwo_unit
*dwo_entry
)
5937 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5939 /* Make sure we're not clobbering something we don't expect to. */
5940 gdb_assert (! sig_entry
->queued
);
5941 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
5942 if (per_bfd
->using_index
)
5944 gdb_assert (sig_entry
->v
.quick
!= NULL
);
5945 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
5948 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
5949 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5950 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5951 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5952 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5954 sig_entry
->section
= dwo_entry
->section
;
5955 sig_entry
->sect_off
= dwo_entry
->sect_off
;
5956 sig_entry
->length
= dwo_entry
->length
;
5957 sig_entry
->reading_dwo_directly
= 1;
5958 sig_entry
->per_bfd
= per_bfd
;
5959 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5960 sig_entry
->dwo_unit
= dwo_entry
;
5963 /* Subroutine of lookup_signatured_type.
5964 If we haven't read the TU yet, create the signatured_type data structure
5965 for a TU to be read in directly from a DWO file, bypassing the stub.
5966 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5967 using .gdb_index, then when reading a CU we want to stay in the DWO file
5968 containing that CU. Otherwise we could end up reading several other DWO
5969 files (due to comdat folding) to process the transitive closure of all the
5970 mentioned TUs, and that can be slow. The current DWO file will have every
5971 type signature that it needs.
5972 We only do this for .gdb_index because in the psymtab case we already have
5973 to read all the DWOs to build the type unit groups. */
5975 static struct signatured_type
*
5976 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5978 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
5979 struct dwo_file
*dwo_file
;
5980 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5983 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
5985 /* If TU skeletons have been removed then we may not have read in any
5987 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
5988 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
5990 /* We only ever need to read in one copy of a signatured type.
5991 Use the global signatured_types array to do our own comdat-folding
5992 of types. If this is the first time we're reading this TU, and
5993 the TU has an entry in .gdb_index, replace the recorded data from
5994 .gdb_index with this TU. */
5996 signatured_type
find_sig_entry (sig
);
5997 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5998 &find_sig_entry
, INSERT
);
5999 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6001 /* We can get here with the TU already read, *or* in the process of being
6002 read. Don't reassign the global entry to point to this DWO if that's
6003 the case. Also note that if the TU is already being read, it may not
6004 have come from a DWO, the program may be a mix of Fission-compiled
6005 code and non-Fission-compiled code. */
6007 /* Have we already tried to read this TU?
6008 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6009 needn't exist in the global table yet). */
6010 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6013 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6014 dwo_unit of the TU itself. */
6015 dwo_file
= cu
->dwo_unit
->dwo_file
;
6017 /* Ok, this is the first time we're reading this TU. */
6018 if (dwo_file
->tus
== NULL
)
6020 find_dwo_entry
.signature
= sig
;
6021 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6023 if (dwo_entry
== NULL
)
6026 /* If the global table doesn't have an entry for this TU, add one. */
6027 if (sig_entry
== NULL
)
6028 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6030 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6031 sig_entry
->tu_read
= 1;
6035 /* Subroutine of lookup_signatured_type.
6036 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6037 then try the DWP file. If the TU stub (skeleton) has been removed then
6038 it won't be in .gdb_index. */
6040 static struct signatured_type
*
6041 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6043 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6044 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6045 struct dwo_unit
*dwo_entry
;
6048 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6049 gdb_assert (dwp_file
!= NULL
);
6051 /* If TU skeletons have been removed then we may not have read in any
6053 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6054 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6056 signatured_type
find_sig_entry (sig
);
6057 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6058 &find_sig_entry
, INSERT
);
6059 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6061 /* Have we already tried to read this TU?
6062 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6063 needn't exist in the global table yet). */
6064 if (sig_entry
!= NULL
)
6067 if (dwp_file
->tus
== NULL
)
6069 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6070 1 /* is_debug_types */);
6071 if (dwo_entry
== NULL
)
6074 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6075 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6080 /* Lookup a signature based type for DW_FORM_ref_sig8.
6081 Returns NULL if signature SIG is not present in the table.
6082 It is up to the caller to complain about this. */
6084 static struct signatured_type
*
6085 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6087 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6089 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6091 /* We're in a DWO/DWP file, and we're using .gdb_index.
6092 These cases require special processing. */
6093 if (get_dwp_file (per_objfile
) == NULL
)
6094 return lookup_dwo_signatured_type (cu
, sig
);
6096 return lookup_dwp_signatured_type (cu
, sig
);
6100 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6102 signatured_type
find_entry (sig
);
6103 return ((struct signatured_type
*)
6104 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6109 /* Low level DIE reading support. */
6111 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6114 init_cu_die_reader (struct die_reader_specs
*reader
,
6115 struct dwarf2_cu
*cu
,
6116 struct dwarf2_section_info
*section
,
6117 struct dwo_file
*dwo_file
,
6118 struct abbrev_table
*abbrev_table
)
6120 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6121 reader
->abfd
= section
->get_bfd_owner ();
6123 reader
->dwo_file
= dwo_file
;
6124 reader
->die_section
= section
;
6125 reader
->buffer
= section
->buffer
;
6126 reader
->buffer_end
= section
->buffer
+ section
->size
;
6127 reader
->abbrev_table
= abbrev_table
;
6130 /* Subroutine of cutu_reader to simplify it.
6131 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6132 There's just a lot of work to do, and cutu_reader is big enough
6135 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6136 from it to the DIE in the DWO. If NULL we are skipping the stub.
6137 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6138 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6139 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6140 STUB_COMP_DIR may be non-NULL.
6141 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6142 are filled in with the info of the DIE from the DWO file.
6143 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6144 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6145 kept around for at least as long as *RESULT_READER.
6147 The result is non-zero if a valid (non-dummy) DIE was found. */
6150 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6151 struct dwo_unit
*dwo_unit
,
6152 struct die_info
*stub_comp_unit_die
,
6153 const char *stub_comp_dir
,
6154 struct die_reader_specs
*result_reader
,
6155 const gdb_byte
**result_info_ptr
,
6156 struct die_info
**result_comp_unit_die
,
6157 abbrev_table_up
*result_dwo_abbrev_table
)
6159 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6160 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6161 struct objfile
*objfile
= per_objfile
->objfile
;
6163 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6164 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6165 int i
,num_extra_attrs
;
6166 struct dwarf2_section_info
*dwo_abbrev_section
;
6167 struct die_info
*comp_unit_die
;
6169 /* At most one of these may be provided. */
6170 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6172 /* These attributes aren't processed until later:
6173 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6174 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6175 referenced later. However, these attributes are found in the stub
6176 which we won't have later. In order to not impose this complication
6177 on the rest of the code, we read them here and copy them to the
6186 if (stub_comp_unit_die
!= NULL
)
6188 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6190 if (!per_cu
->is_debug_types
)
6191 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6192 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6193 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6194 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6195 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6197 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6199 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6200 We need the value before we can process DW_AT_ranges values from the
6202 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6204 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6205 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6206 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6207 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6209 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6211 else if (stub_comp_dir
!= NULL
)
6213 /* Reconstruct the comp_dir attribute to simplify the code below. */
6214 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6215 comp_dir
->name
= DW_AT_comp_dir
;
6216 comp_dir
->form
= DW_FORM_string
;
6217 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6220 /* Set up for reading the DWO CU/TU. */
6221 cu
->dwo_unit
= dwo_unit
;
6222 dwarf2_section_info
*section
= dwo_unit
->section
;
6223 section
->read (objfile
);
6224 abfd
= section
->get_bfd_owner ();
6225 begin_info_ptr
= info_ptr
= (section
->buffer
6226 + to_underlying (dwo_unit
->sect_off
));
6227 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6229 if (per_cu
->is_debug_types
)
6231 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6233 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6234 section
, dwo_abbrev_section
,
6235 info_ptr
, rcuh_kind::TYPE
);
6236 /* This is not an assert because it can be caused by bad debug info. */
6237 if (sig_type
->signature
!= cu
->header
.signature
)
6239 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6240 " TU at offset %s [in module %s]"),
6241 hex_string (sig_type
->signature
),
6242 hex_string (cu
->header
.signature
),
6243 sect_offset_str (dwo_unit
->sect_off
),
6244 bfd_get_filename (abfd
));
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
6248 nor the type's offset in the TU until now. */
6249 dwo_unit
->length
= cu
->header
.get_length ();
6250 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6252 /* Establish the type offset that can be used to lookup the type.
6253 For DWO files, we don't know it until now. */
6254 sig_type
->type_offset_in_section
6255 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6259 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6260 section
, dwo_abbrev_section
,
6261 info_ptr
, rcuh_kind::COMPILE
);
6262 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6263 /* For DWOs coming from DWP files, we don't know the CU length
6265 dwo_unit
->length
= cu
->header
.get_length ();
6268 dwo_abbrev_section
->read (objfile
);
6269 *result_dwo_abbrev_table
6270 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6271 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6272 result_dwo_abbrev_table
->get ());
6274 /* Read in the die, but leave space to copy over the attributes
6275 from the stub. This has the benefit of simplifying the rest of
6276 the code - all the work to maintain the illusion of a single
6277 DW_TAG_{compile,type}_unit DIE is done here. */
6278 num_extra_attrs
= ((stmt_list
!= NULL
)
6282 + (comp_dir
!= NULL
));
6283 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6286 /* Copy over the attributes from the stub to the DIE we just read in. */
6287 comp_unit_die
= *result_comp_unit_die
;
6288 i
= comp_unit_die
->num_attrs
;
6289 if (stmt_list
!= NULL
)
6290 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6292 comp_unit_die
->attrs
[i
++] = *low_pc
;
6293 if (high_pc
!= NULL
)
6294 comp_unit_die
->attrs
[i
++] = *high_pc
;
6296 comp_unit_die
->attrs
[i
++] = *ranges
;
6297 if (comp_dir
!= NULL
)
6298 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6299 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6301 if (dwarf_die_debug
)
6303 fprintf_unfiltered (gdb_stdlog
,
6304 "Read die from %s@0x%x of %s:\n",
6305 section
->get_name (),
6306 (unsigned) (begin_info_ptr
- section
->buffer
),
6307 bfd_get_filename (abfd
));
6308 dump_die (comp_unit_die
, dwarf_die_debug
);
6311 /* Skip dummy compilation units. */
6312 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6313 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6316 *result_info_ptr
= info_ptr
;
6320 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6321 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6322 signature is part of the header. */
6323 static gdb::optional
<ULONGEST
>
6324 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6326 if (cu
->header
.version
>= 5)
6327 return cu
->header
.signature
;
6328 struct attribute
*attr
;
6329 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6330 if (attr
== nullptr || !attr
->form_is_unsigned ())
6331 return gdb::optional
<ULONGEST
> ();
6332 return attr
->as_unsigned ();
6335 /* Subroutine of cutu_reader to simplify it.
6336 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6337 Returns NULL if the specified DWO unit cannot be found. */
6339 static struct dwo_unit
*
6340 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6342 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6343 struct dwo_unit
*dwo_unit
;
6344 const char *comp_dir
;
6346 gdb_assert (cu
!= NULL
);
6348 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6349 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6350 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6352 if (per_cu
->is_debug_types
)
6353 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6356 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6358 if (!signature
.has_value ())
6359 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6361 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6363 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6369 /* Subroutine of cutu_reader to simplify it.
6370 See it for a description of the parameters.
6371 Read a TU directly from a DWO file, bypassing the stub. */
6374 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6375 dwarf2_per_objfile
*per_objfile
,
6376 dwarf2_cu
*existing_cu
)
6378 struct signatured_type
*sig_type
;
6380 /* Verify we can do the following downcast, and that we have the
6382 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6383 sig_type
= (struct signatured_type
*) this_cu
;
6384 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6388 if (existing_cu
!= nullptr)
6391 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6392 /* There's no need to do the rereading_dwo_cu handling that
6393 cutu_reader does since we don't read the stub. */
6397 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6398 in per_objfile yet. */
6399 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6400 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6401 cu
= m_new_cu
.get ();
6404 /* A future optimization, if needed, would be to use an existing
6405 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6406 could share abbrev tables. */
6408 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6409 NULL
/* stub_comp_unit_die */,
6410 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6413 &m_dwo_abbrev_table
) == 0)
6420 /* Initialize a CU (or TU) and read its DIEs.
6421 If the CU defers to a DWO file, read the DWO file as well.
6423 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6424 Otherwise the table specified in the comp unit header is read in and used.
6425 This is an optimization for when we already have the abbrev table.
6427 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6430 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6431 dwarf2_per_objfile
*per_objfile
,
6432 struct abbrev_table
*abbrev_table
,
6433 dwarf2_cu
*existing_cu
,
6435 : die_reader_specs
{},
6438 struct objfile
*objfile
= per_objfile
->objfile
;
6439 struct dwarf2_section_info
*section
= this_cu
->section
;
6440 bfd
*abfd
= section
->get_bfd_owner ();
6441 const gdb_byte
*begin_info_ptr
;
6442 struct signatured_type
*sig_type
= NULL
;
6443 struct dwarf2_section_info
*abbrev_section
;
6444 /* Non-zero if CU currently points to a DWO file and we need to
6445 reread it. When this happens we need to reread the skeleton die
6446 before we can reread the DWO file (this only applies to CUs, not TUs). */
6447 int rereading_dwo_cu
= 0;
6449 if (dwarf_die_debug
)
6450 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6451 this_cu
->is_debug_types
? "type" : "comp",
6452 sect_offset_str (this_cu
->sect_off
));
6454 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6455 file (instead of going through the stub), short-circuit all of this. */
6456 if (this_cu
->reading_dwo_directly
)
6458 /* Narrow down the scope of possibilities to have to understand. */
6459 gdb_assert (this_cu
->is_debug_types
);
6460 gdb_assert (abbrev_table
== NULL
);
6461 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6465 /* This is cheap if the section is already read in. */
6466 section
->read (objfile
);
6468 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6470 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6474 if (existing_cu
!= nullptr)
6477 /* If this CU is from a DWO file we need to start over, we need to
6478 refetch the attributes from the skeleton CU.
6479 This could be optimized by retrieving those attributes from when we
6480 were here the first time: the previous comp_unit_die was stored in
6481 comp_unit_obstack. But there's no data yet that we need this
6483 if (cu
->dwo_unit
!= NULL
)
6484 rereading_dwo_cu
= 1;
6488 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6489 in per_objfile yet. */
6490 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6491 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6492 cu
= m_new_cu
.get ();
6495 /* Get the header. */
6496 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6498 /* We already have the header, there's no need to read it in again. */
6499 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6503 if (this_cu
->is_debug_types
)
6505 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6506 section
, abbrev_section
,
6507 info_ptr
, rcuh_kind::TYPE
);
6509 /* Since per_cu is the first member of struct signatured_type,
6510 we can go from a pointer to one to a pointer to the other. */
6511 sig_type
= (struct signatured_type
*) this_cu
;
6512 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6513 gdb_assert (sig_type
->type_offset_in_tu
6514 == cu
->header
.type_cu_offset_in_tu
);
6515 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6517 /* LENGTH has not been set yet for type units if we're
6518 using .gdb_index. */
6519 this_cu
->length
= cu
->header
.get_length ();
6521 /* Establish the type offset that can be used to lookup the type. */
6522 sig_type
->type_offset_in_section
=
6523 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6525 this_cu
->dwarf_version
= cu
->header
.version
;
6529 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6530 section
, abbrev_section
,
6532 rcuh_kind::COMPILE
);
6534 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6535 if (this_cu
->length
== 0)
6536 this_cu
->length
= cu
->header
.get_length ();
6538 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6539 this_cu
->dwarf_version
= cu
->header
.version
;
6543 /* Skip dummy compilation units. */
6544 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6545 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6551 /* If we don't have them yet, read the abbrevs for this compilation unit.
6552 And if we need to read them now, make sure they're freed when we're
6554 if (abbrev_table
!= NULL
)
6555 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6558 abbrev_section
->read (objfile
);
6559 m_abbrev_table_holder
6560 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6561 abbrev_table
= m_abbrev_table_holder
.get ();
6564 /* Read the top level CU/TU die. */
6565 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6566 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6568 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6574 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6575 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6576 table from the DWO file and pass the ownership over to us. It will be
6577 referenced from READER, so we must make sure to free it after we're done
6580 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6581 DWO CU, that this test will fail (the attribute will not be present). */
6582 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6583 if (dwo_name
!= nullptr)
6585 struct dwo_unit
*dwo_unit
;
6586 struct die_info
*dwo_comp_unit_die
;
6588 if (comp_unit_die
->has_children
)
6590 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6591 " has children (offset %s) [in module %s]"),
6592 sect_offset_str (this_cu
->sect_off
),
6593 bfd_get_filename (abfd
));
6595 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6596 if (dwo_unit
!= NULL
)
6598 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6599 comp_unit_die
, NULL
,
6602 &m_dwo_abbrev_table
) == 0)
6608 comp_unit_die
= dwo_comp_unit_die
;
6612 /* Yikes, we couldn't find the rest of the DIE, we only have
6613 the stub. A complaint has already been logged. There's
6614 not much more we can do except pass on the stub DIE to
6615 die_reader_func. We don't want to throw an error on bad
6622 cutu_reader::keep ()
6624 /* Done, clean up. */
6625 gdb_assert (!dummy_p
);
6626 if (m_new_cu
!= NULL
)
6628 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6630 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6631 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6635 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6636 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6637 assumed to have already done the lookup to find the DWO file).
6639 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6640 THIS_CU->is_debug_types, but nothing else.
6642 We fill in THIS_CU->length.
6644 THIS_CU->cu is always freed when done.
6645 This is done in order to not leave THIS_CU->cu in a state where we have
6646 to care whether it refers to the "main" CU or the DWO CU.
6648 When parent_cu is passed, it is used to provide a default value for
6649 str_offsets_base and addr_base from the parent. */
6651 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6652 dwarf2_per_objfile
*per_objfile
,
6653 struct dwarf2_cu
*parent_cu
,
6654 struct dwo_file
*dwo_file
)
6655 : die_reader_specs
{},
6658 struct objfile
*objfile
= per_objfile
->objfile
;
6659 struct dwarf2_section_info
*section
= this_cu
->section
;
6660 bfd
*abfd
= section
->get_bfd_owner ();
6661 struct dwarf2_section_info
*abbrev_section
;
6662 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6664 if (dwarf_die_debug
)
6665 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6666 this_cu
->is_debug_types
? "type" : "comp",
6667 sect_offset_str (this_cu
->sect_off
));
6669 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6671 abbrev_section
= (dwo_file
!= NULL
6672 ? &dwo_file
->sections
.abbrev
6673 : get_abbrev_section_for_cu (this_cu
));
6675 /* This is cheap if the section is already read in. */
6676 section
->read (objfile
);
6678 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6680 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6681 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6682 section
, abbrev_section
, info_ptr
,
6683 (this_cu
->is_debug_types
6685 : rcuh_kind::COMPILE
));
6687 if (parent_cu
!= nullptr)
6689 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6690 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6692 this_cu
->length
= m_new_cu
->header
.get_length ();
6694 /* Skip dummy compilation units. */
6695 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6696 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6702 abbrev_section
->read (objfile
);
6703 m_abbrev_table_holder
6704 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6706 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6707 m_abbrev_table_holder
.get ());
6708 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6712 /* Type Unit Groups.
6714 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6715 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6716 so that all types coming from the same compilation (.o file) are grouped
6717 together. A future step could be to put the types in the same symtab as
6718 the CU the types ultimately came from. */
6721 hash_type_unit_group (const void *item
)
6723 const struct type_unit_group
*tu_group
6724 = (const struct type_unit_group
*) item
;
6726 return hash_stmt_list_entry (&tu_group
->hash
);
6730 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6732 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6733 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6735 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6738 /* Allocate a hash table for type unit groups. */
6741 allocate_type_unit_groups_table ()
6743 return htab_up (htab_create_alloc (3,
6744 hash_type_unit_group
,
6746 htab_delete_entry
<type_unit_group
>,
6750 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6751 partial symtabs. We combine several TUs per psymtab to not let the size
6752 of any one psymtab grow too big. */
6753 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6754 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6756 /* Helper routine for get_type_unit_group.
6757 Create the type_unit_group object used to hold one or more TUs. */
6759 static std::unique_ptr
<type_unit_group
>
6760 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6762 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6763 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6765 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6766 tu_group
->per_bfd
= per_bfd
;
6768 if (per_bfd
->using_index
)
6770 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6771 struct dwarf2_per_cu_quick_data
);
6775 unsigned int line_offset
= to_underlying (line_offset_struct
);
6776 dwarf2_psymtab
*pst
;
6779 /* Give the symtab a useful name for debug purposes. */
6780 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6781 name
= string_printf ("<type_units_%d>",
6782 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6784 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6786 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6788 pst
->anonymous
= true;
6791 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6792 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6797 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6798 STMT_LIST is a DW_AT_stmt_list attribute. */
6800 static struct type_unit_group
*
6801 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6803 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6804 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6805 struct type_unit_group
*tu_group
;
6807 unsigned int line_offset
;
6808 struct type_unit_group type_unit_group_for_lookup
;
6810 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6811 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6813 /* Do we need to create a new group, or can we use an existing one? */
6815 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6817 line_offset
= stmt_list
->as_unsigned ();
6818 ++tu_stats
->nr_symtab_sharers
;
6822 /* Ugh, no stmt_list. Rare, but we have to handle it.
6823 We can do various things here like create one group per TU or
6824 spread them over multiple groups to split up the expansion work.
6825 To avoid worst case scenarios (too many groups or too large groups)
6826 we, umm, group them in bunches. */
6827 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6828 | (tu_stats
->nr_stmt_less_type_units
6829 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6830 ++tu_stats
->nr_stmt_less_type_units
;
6833 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6834 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6835 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6836 &type_unit_group_for_lookup
, INSERT
);
6837 if (*slot
== nullptr)
6839 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6840 std::unique_ptr
<type_unit_group
> grp
6841 = create_type_unit_group (cu
, line_offset_struct
);
6842 *slot
= grp
.release ();
6843 ++tu_stats
->nr_symtabs
;
6846 tu_group
= (struct type_unit_group
*) *slot
;
6847 gdb_assert (tu_group
!= nullptr);
6851 /* Partial symbol tables. */
6853 /* Create a psymtab named NAME and assign it to PER_CU.
6855 The caller must fill in the following details:
6856 dirname, textlow, texthigh. */
6858 static dwarf2_psymtab
*
6859 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6860 dwarf2_per_objfile
*per_objfile
,
6864 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6865 per_objfile
->objfile
->per_bfd
, per_cu
);
6867 pst
->psymtabs_addrmap_supported
= true;
6869 /* This is the glue that links PST into GDB's symbol API. */
6870 per_cu
->v
.psymtab
= pst
;
6875 /* DIE reader function for process_psymtab_comp_unit. */
6878 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6879 const gdb_byte
*info_ptr
,
6880 struct die_info
*comp_unit_die
,
6881 enum language pretend_language
)
6883 struct dwarf2_cu
*cu
= reader
->cu
;
6884 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6885 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6886 struct objfile
*objfile
= per_objfile
->objfile
;
6887 struct gdbarch
*gdbarch
= objfile
->arch ();
6888 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6890 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6891 dwarf2_psymtab
*pst
;
6892 enum pc_bounds_kind cu_bounds_kind
;
6893 const char *filename
;
6895 gdb_assert (! per_cu
->is_debug_types
);
6897 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
6899 /* Allocate a new partial symbol table structure. */
6900 gdb::unique_xmalloc_ptr
<char> debug_filename
;
6901 static const char artificial
[] = "<artificial>";
6902 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6903 if (filename
== NULL
)
6905 else if (strcmp (filename
, artificial
) == 0)
6907 debug_filename
.reset (concat (artificial
, "@",
6908 sect_offset_str (per_cu
->sect_off
),
6910 filename
= debug_filename
.get ();
6913 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
6915 /* This must be done before calling dwarf2_build_include_psymtabs. */
6916 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6918 baseaddr
= objfile
->text_section_offset ();
6920 dwarf2_find_base_address (comp_unit_die
, cu
);
6922 /* Possibly set the default values of LOWPC and HIGHPC from
6924 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6925 &best_highpc
, cu
, pst
);
6926 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6929 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
6932 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
6934 /* Store the contiguous range if it is not empty; it can be
6935 empty for CUs with no code. */
6936 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
6940 /* Check if comp unit has_children.
6941 If so, read the rest of the partial symbols from this comp unit.
6942 If not, there's no more debug_info for this comp unit. */
6943 if (comp_unit_die
->has_children
)
6945 struct partial_die_info
*first_die
;
6946 CORE_ADDR lowpc
, highpc
;
6948 lowpc
= ((CORE_ADDR
) -1);
6949 highpc
= ((CORE_ADDR
) 0);
6951 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6953 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6954 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6956 /* If we didn't find a lowpc, set it to highpc to avoid
6957 complaints from `maint check'. */
6958 if (lowpc
== ((CORE_ADDR
) -1))
6961 /* If the compilation unit didn't have an explicit address range,
6962 then use the information extracted from its child dies. */
6963 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6966 best_highpc
= highpc
;
6969 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
6970 best_lowpc
+ baseaddr
)
6972 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
6973 best_highpc
+ baseaddr
)
6978 if (!cu
->per_cu
->imported_symtabs_empty ())
6981 int len
= cu
->per_cu
->imported_symtabs_size ();
6983 /* Fill in 'dependencies' here; we fill in 'users' in a
6985 pst
->number_of_dependencies
= len
;
6987 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
6988 for (i
= 0; i
< len
; ++i
)
6990 pst
->dependencies
[i
]
6991 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
6994 cu
->per_cu
->imported_symtabs_free ();
6997 /* Get the list of files included in the current compilation unit,
6998 and build a psymtab for each of them. */
6999 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7001 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7002 ", %d global, %d static syms",
7003 per_cu
->is_debug_types
? "type" : "comp",
7004 sect_offset_str (per_cu
->sect_off
),
7005 paddress (gdbarch
, pst
->text_low (objfile
)),
7006 paddress (gdbarch
, pst
->text_high (objfile
)),
7007 (int) pst
->global_psymbols
.size (),
7008 (int) pst
->static_psymbols
.size ());
7011 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7012 Process compilation unit THIS_CU for a psymtab. */
7015 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7016 dwarf2_per_objfile
*per_objfile
,
7017 bool want_partial_unit
,
7018 enum language pretend_language
)
7020 /* If this compilation unit was already read in, free the
7021 cached copy in order to read it in again. This is
7022 necessary because we skipped some symbols when we first
7023 read in the compilation unit (see load_partial_dies).
7024 This problem could be avoided, but the benefit is unclear. */
7025 per_objfile
->remove_cu (this_cu
);
7027 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7029 if (reader
.comp_unit_die
== nullptr)
7032 switch (reader
.comp_unit_die
->tag
)
7034 case DW_TAG_compile_unit
:
7035 this_cu
->unit_type
= DW_UT_compile
;
7037 case DW_TAG_partial_unit
:
7038 this_cu
->unit_type
= DW_UT_partial
;
7040 case DW_TAG_type_unit
:
7041 this_cu
->unit_type
= DW_UT_type
;
7044 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7045 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7046 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7047 objfile_name (per_objfile
->objfile
));
7054 else if (this_cu
->is_debug_types
)
7055 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7056 reader
.comp_unit_die
);
7057 else if (want_partial_unit
7058 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7059 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7060 reader
.comp_unit_die
,
7063 /* Age out any secondary CUs. */
7064 per_objfile
->age_comp_units ();
7067 /* Reader function for build_type_psymtabs. */
7070 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7071 const gdb_byte
*info_ptr
,
7072 struct die_info
*type_unit_die
)
7074 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7075 struct dwarf2_cu
*cu
= reader
->cu
;
7076 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7077 struct signatured_type
*sig_type
;
7078 struct type_unit_group
*tu_group
;
7079 struct attribute
*attr
;
7080 struct partial_die_info
*first_die
;
7081 CORE_ADDR lowpc
, highpc
;
7082 dwarf2_psymtab
*pst
;
7084 gdb_assert (per_cu
->is_debug_types
);
7085 sig_type
= (struct signatured_type
*) per_cu
;
7087 if (! type_unit_die
->has_children
)
7090 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7091 tu_group
= get_type_unit_group (cu
, attr
);
7093 if (tu_group
->tus
== nullptr)
7094 tu_group
->tus
= new std::vector
<signatured_type
*>;
7095 tu_group
->tus
->push_back (sig_type
);
7097 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7098 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7099 pst
->anonymous
= true;
7101 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7103 lowpc
= (CORE_ADDR
) -1;
7104 highpc
= (CORE_ADDR
) 0;
7105 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7110 /* Struct used to sort TUs by their abbreviation table offset. */
7112 struct tu_abbrev_offset
7114 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7115 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7118 /* This is used when sorting. */
7119 bool operator< (const tu_abbrev_offset
&other
) const
7121 return abbrev_offset
< other
.abbrev_offset
;
7124 signatured_type
*sig_type
;
7125 sect_offset abbrev_offset
;
7128 /* Efficiently read all the type units.
7130 The efficiency is because we sort TUs by the abbrev table they use and
7131 only read each abbrev table once. In one program there are 200K TUs
7132 sharing 8K abbrev tables.
7134 The main purpose of this function is to support building the
7135 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7136 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7137 can collapse the search space by grouping them by stmt_list.
7138 The savings can be significant, in the same program from above the 200K TUs
7139 share 8K stmt_list tables.
7141 FUNC is expected to call get_type_unit_group, which will create the
7142 struct type_unit_group if necessary and add it to
7143 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7146 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7148 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7149 abbrev_table_up abbrev_table
;
7150 sect_offset abbrev_offset
;
7152 /* It's up to the caller to not call us multiple times. */
7153 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7155 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7158 /* TUs typically share abbrev tables, and there can be way more TUs than
7159 abbrev tables. Sort by abbrev table to reduce the number of times we
7160 read each abbrev table in.
7161 Alternatives are to punt or to maintain a cache of abbrev tables.
7162 This is simpler and efficient enough for now.
7164 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7165 symtab to use). Typically TUs with the same abbrev offset have the same
7166 stmt_list value too so in practice this should work well.
7168 The basic algorithm here is:
7170 sort TUs by abbrev table
7171 for each TU with same abbrev table:
7172 read abbrev table if first user
7173 read TU top level DIE
7174 [IWBN if DWO skeletons had DW_AT_stmt_list]
7177 dwarf_read_debug_printf ("Building type unit groups ...");
7179 /* Sort in a separate table to maintain the order of all_comp_units
7180 for .gdb_index: TU indices directly index all_type_units. */
7181 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7182 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7184 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7186 if (cu
->is_debug_types
)
7188 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7189 sorted_by_abbrev
.emplace_back
7190 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7191 sig_type
->sect_off
));
7195 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7197 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7199 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7201 /* Switch to the next abbrev table if necessary. */
7202 if (abbrev_table
== NULL
7203 || tu
.abbrev_offset
!= abbrev_offset
)
7205 abbrev_offset
= tu
.abbrev_offset
;
7206 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7208 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7209 ++tu_stats
->nr_uniq_abbrev_tables
;
7212 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7213 abbrev_table
.get (), nullptr, false);
7214 if (!reader
.dummy_p
)
7215 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7216 reader
.comp_unit_die
);
7220 /* Print collected type unit statistics. */
7223 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7225 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7227 dwarf_read_debug_printf ("Type unit statistics:");
7228 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7229 dwarf_read_debug_printf (" %d uniq abbrev tables",
7230 tu_stats
->nr_uniq_abbrev_tables
);
7231 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7232 tu_stats
->nr_symtabs
);
7233 dwarf_read_debug_printf (" %d symtab sharers",
7234 tu_stats
->nr_symtab_sharers
);
7235 dwarf_read_debug_printf (" %d type units without a stmt_list",
7236 tu_stats
->nr_stmt_less_type_units
);
7237 dwarf_read_debug_printf (" %d all_type_units reallocs",
7238 tu_stats
->nr_all_type_units_reallocs
);
7241 /* Traversal function for build_type_psymtabs. */
7244 build_type_psymtab_dependencies (void **slot
, void *info
)
7246 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7247 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7248 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7249 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7250 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7253 gdb_assert (len
> 0);
7254 gdb_assert (tu_group
->type_unit_group_p ());
7256 pst
->number_of_dependencies
= len
;
7257 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7258 for (i
= 0; i
< len
; ++i
)
7260 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7261 gdb_assert (iter
->is_debug_types
);
7262 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7263 iter
->type_unit_group
= tu_group
;
7266 delete tu_group
->tus
;
7267 tu_group
->tus
= nullptr;
7272 /* Traversal function for process_skeletonless_type_unit.
7273 Read a TU in a DWO file and build partial symbols for it. */
7276 process_skeletonless_type_unit (void **slot
, void *info
)
7278 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7279 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7281 /* If this TU doesn't exist in the global table, add it and read it in. */
7283 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7284 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7286 signatured_type
find_entry (dwo_unit
->signature
);
7287 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7288 &find_entry
, INSERT
);
7289 /* If we've already seen this type there's nothing to do. What's happening
7290 is we're doing our own version of comdat-folding here. */
7294 /* This does the job that create_all_comp_units would have done for
7296 signatured_type
*entry
7297 = add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7298 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7301 /* This does the job that build_type_psymtabs would have done. */
7302 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7303 if (!reader
.dummy_p
)
7304 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7305 reader
.comp_unit_die
);
7310 /* Traversal function for process_skeletonless_type_units. */
7313 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7315 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7317 if (dwo_file
->tus
!= NULL
)
7318 htab_traverse_noresize (dwo_file
->tus
.get (),
7319 process_skeletonless_type_unit
, info
);
7324 /* Scan all TUs of DWO files, verifying we've processed them.
7325 This is needed in case a TU was emitted without its skeleton.
7326 Note: This can't be done until we know what all the DWO files are. */
7329 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7331 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7332 if (get_dwp_file (per_objfile
) == NULL
7333 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7335 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7336 process_dwo_file_for_skeletonless_type_units
,
7341 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7344 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7346 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7348 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7353 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7355 /* Set the 'user' field only if it is not already set. */
7356 if (pst
->dependencies
[j
]->user
== NULL
)
7357 pst
->dependencies
[j
]->user
= pst
;
7362 /* Build the partial symbol table by doing a quick pass through the
7363 .debug_info and .debug_abbrev sections. */
7366 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7368 struct objfile
*objfile
= per_objfile
->objfile
;
7369 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7371 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7372 objfile_name (objfile
));
7374 scoped_restore restore_reading_psyms
7375 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7377 per_bfd
->info
.read (objfile
);
7379 /* Any cached compilation units will be linked by the per-objfile
7380 read_in_chain. Make sure to free them when we're done. */
7381 free_cached_comp_units
freer (per_objfile
);
7383 create_all_comp_units (per_objfile
);
7384 build_type_psymtabs (per_objfile
);
7386 /* Create a temporary address map on a temporary obstack. We later
7387 copy this to the final obstack. */
7388 auto_obstack temp_obstack
;
7390 scoped_restore save_psymtabs_addrmap
7391 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7392 addrmap_create_mutable (&temp_obstack
));
7394 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7396 if (per_cu
->v
.psymtab
!= NULL
)
7397 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7399 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7403 /* This has to wait until we read the CUs, we need the list of DWOs. */
7404 process_skeletonless_type_units (per_objfile
);
7406 /* Now that all TUs have been processed we can fill in the dependencies. */
7407 if (per_bfd
->type_unit_groups
!= NULL
)
7409 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7410 build_type_psymtab_dependencies
, per_objfile
);
7413 if (dwarf_read_debug
> 0)
7414 print_tu_stats (per_objfile
);
7416 set_partial_user (per_objfile
);
7418 per_bfd
->partial_symtabs
->psymtabs_addrmap
7419 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7420 per_bfd
->partial_symtabs
->obstack ());
7421 /* At this point we want to keep the address map. */
7422 save_psymtabs_addrmap
.release ();
7424 dwarf_read_debug_printf ("Done building psymtabs of %s",
7425 objfile_name (objfile
));
7428 /* Load the partial DIEs for a secondary CU into memory.
7429 This is also used when rereading a primary CU with load_all_dies. */
7432 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7433 dwarf2_per_objfile
*per_objfile
,
7434 dwarf2_cu
*existing_cu
)
7436 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7438 if (!reader
.dummy_p
)
7440 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7443 /* Check if comp unit has_children.
7444 If so, read the rest of the partial symbols from this comp unit.
7445 If not, there's no more debug_info for this comp unit. */
7446 if (reader
.comp_unit_die
->has_children
)
7447 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7454 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7455 struct dwarf2_section_info
*section
,
7456 struct dwarf2_section_info
*abbrev_section
,
7457 unsigned int is_dwz
,
7458 htab_up
&types_htab
,
7459 rcuh_kind section_kind
)
7461 const gdb_byte
*info_ptr
;
7462 struct objfile
*objfile
= per_objfile
->objfile
;
7464 dwarf_read_debug_printf ("Reading %s for %s",
7465 section
->get_name (),
7466 section
->get_file_name ());
7468 section
->read (objfile
);
7470 info_ptr
= section
->buffer
;
7472 while (info_ptr
< section
->buffer
+ section
->size
)
7474 dwarf2_per_cu_data_up this_cu
;
7476 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7478 comp_unit_head cu_header
;
7479 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7480 abbrev_section
, info_ptr
,
7483 /* Save the compilation unit for later lookup. */
7484 if (cu_header
.unit_type
!= DW_UT_type
)
7485 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7488 if (types_htab
== nullptr)
7489 types_htab
= allocate_signatured_type_table ();
7491 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7492 (cu_header
.signature
);
7493 signatured_type
*sig_ptr
= sig_type
.get ();
7494 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7495 this_cu
.reset (sig_type
.release ());
7497 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7498 gdb_assert (slot
!= nullptr);
7499 if (*slot
!= nullptr)
7500 complaint (_("debug type entry at offset %s is duplicate to"
7501 " the entry at offset %s, signature %s"),
7502 sect_offset_str (sect_off
),
7503 sect_offset_str (sig_ptr
->sect_off
),
7504 hex_string (sig_ptr
->signature
));
7507 this_cu
->sect_off
= sect_off
;
7508 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7509 this_cu
->is_dwz
= is_dwz
;
7510 this_cu
->section
= section
;
7512 info_ptr
= info_ptr
+ this_cu
->length
;
7513 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7517 /* Create a list of all compilation units in OBJFILE.
7518 This is only done for -readnow and building partial symtabs. */
7521 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7525 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7526 &per_objfile
->per_bfd
->abbrev
, 0,
7527 types_htab
, rcuh_kind::COMPILE
);
7528 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7529 read_comp_units_from_section (per_objfile
, §ion
,
7530 &per_objfile
->per_bfd
->abbrev
, 0,
7531 types_htab
, rcuh_kind::TYPE
);
7533 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7535 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7536 types_htab
, rcuh_kind::COMPILE
);
7538 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7541 /* Process all loaded DIEs for compilation unit CU, starting at
7542 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7543 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7544 DW_AT_ranges). See the comments of add_partial_subprogram on how
7545 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7548 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7549 CORE_ADDR
*highpc
, int set_addrmap
,
7550 struct dwarf2_cu
*cu
)
7552 struct partial_die_info
*pdi
;
7554 /* Now, march along the PDI's, descending into ones which have
7555 interesting children but skipping the children of the other ones,
7556 until we reach the end of the compilation unit. */
7564 /* Anonymous namespaces or modules have no name but have interesting
7565 children, so we need to look at them. Ditto for anonymous
7568 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7569 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7570 || pdi
->tag
== DW_TAG_imported_unit
7571 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7575 case DW_TAG_subprogram
:
7576 case DW_TAG_inlined_subroutine
:
7577 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7578 if (cu
->per_cu
->lang
== language_cplus
)
7579 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7582 case DW_TAG_constant
:
7583 case DW_TAG_variable
:
7584 case DW_TAG_typedef
:
7585 case DW_TAG_union_type
:
7586 if (!pdi
->is_declaration
7587 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7589 add_partial_symbol (pdi
, cu
);
7592 case DW_TAG_class_type
:
7593 case DW_TAG_interface_type
:
7594 case DW_TAG_structure_type
:
7595 if (!pdi
->is_declaration
)
7597 add_partial_symbol (pdi
, cu
);
7599 if ((cu
->per_cu
->lang
== language_rust
7600 || cu
->per_cu
->lang
== language_cplus
)
7601 && pdi
->has_children
)
7602 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7605 case DW_TAG_enumeration_type
:
7606 if (!pdi
->is_declaration
)
7607 add_partial_enumeration (pdi
, cu
);
7609 case DW_TAG_base_type
:
7610 case DW_TAG_subrange_type
:
7611 /* File scope base type definitions are added to the partial
7613 add_partial_symbol (pdi
, cu
);
7615 case DW_TAG_namespace
:
7616 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7619 if (!pdi
->is_declaration
)
7620 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7622 case DW_TAG_imported_unit
:
7624 struct dwarf2_per_cu_data
*per_cu
;
7626 /* For now we don't handle imported units in type units. */
7627 if (cu
->per_cu
->is_debug_types
)
7629 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7630 " supported in type units [in module %s]"),
7631 objfile_name (cu
->per_objfile
->objfile
));
7634 per_cu
= dwarf2_find_containing_comp_unit
7635 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7637 /* Go read the partial unit, if needed. */
7638 if (per_cu
->v
.psymtab
== NULL
)
7639 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7642 cu
->per_cu
->imported_symtabs_push (per_cu
);
7645 case DW_TAG_imported_declaration
:
7646 add_partial_symbol (pdi
, cu
);
7653 /* If the die has a sibling, skip to the sibling. */
7655 pdi
= pdi
->die_sibling
;
7659 /* Functions used to compute the fully scoped name of a partial DIE.
7661 Normally, this is simple. For C++, the parent DIE's fully scoped
7662 name is concatenated with "::" and the partial DIE's name.
7663 Enumerators are an exception; they use the scope of their parent
7664 enumeration type, i.e. the name of the enumeration type is not
7665 prepended to the enumerator.
7667 There are two complexities. One is DW_AT_specification; in this
7668 case "parent" means the parent of the target of the specification,
7669 instead of the direct parent of the DIE. The other is compilers
7670 which do not emit DW_TAG_namespace; in this case we try to guess
7671 the fully qualified name of structure types from their members'
7672 linkage names. This must be done using the DIE's children rather
7673 than the children of any DW_AT_specification target. We only need
7674 to do this for structures at the top level, i.e. if the target of
7675 any DW_AT_specification (if any; otherwise the DIE itself) does not
7678 /* Compute the scope prefix associated with PDI's parent, in
7679 compilation unit CU. The result will be allocated on CU's
7680 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7681 field. NULL is returned if no prefix is necessary. */
7683 partial_die_parent_scope (struct partial_die_info
*pdi
,
7684 struct dwarf2_cu
*cu
)
7686 const char *grandparent_scope
;
7687 struct partial_die_info
*parent
, *real_pdi
;
7689 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7690 then this means the parent of the specification DIE. */
7693 while (real_pdi
->has_specification
)
7695 auto res
= find_partial_die (real_pdi
->spec_offset
,
7696 real_pdi
->spec_is_dwz
, cu
);
7701 parent
= real_pdi
->die_parent
;
7705 if (parent
->scope_set
)
7706 return parent
->scope
;
7710 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7712 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7713 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7714 Work around this problem here. */
7715 if (cu
->per_cu
->lang
== language_cplus
7716 && parent
->tag
== DW_TAG_namespace
7717 && strcmp (parent
->name (cu
), "::") == 0
7718 && grandparent_scope
== NULL
)
7720 parent
->scope
= NULL
;
7721 parent
->scope_set
= 1;
7725 /* Nested subroutines in Fortran get a prefix. */
7726 if (pdi
->tag
== DW_TAG_enumerator
)
7727 /* Enumerators should not get the name of the enumeration as a prefix. */
7728 parent
->scope
= grandparent_scope
;
7729 else if (parent
->tag
== DW_TAG_namespace
7730 || parent
->tag
== DW_TAG_module
7731 || parent
->tag
== DW_TAG_structure_type
7732 || parent
->tag
== DW_TAG_class_type
7733 || parent
->tag
== DW_TAG_interface_type
7734 || parent
->tag
== DW_TAG_union_type
7735 || parent
->tag
== DW_TAG_enumeration_type
7736 || (cu
->per_cu
->lang
== language_fortran
7737 && parent
->tag
== DW_TAG_subprogram
7738 && pdi
->tag
== DW_TAG_subprogram
))
7740 if (grandparent_scope
== NULL
)
7741 parent
->scope
= parent
->name (cu
);
7743 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7745 parent
->name (cu
), 0, cu
);
7749 /* FIXME drow/2004-04-01: What should we be doing with
7750 function-local names? For partial symbols, we should probably be
7752 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7753 dwarf_tag_name (parent
->tag
),
7754 sect_offset_str (pdi
->sect_off
));
7755 parent
->scope
= grandparent_scope
;
7758 parent
->scope_set
= 1;
7759 return parent
->scope
;
7762 /* Return the fully scoped name associated with PDI, from compilation unit
7763 CU. The result will be allocated with malloc. */
7765 static gdb::unique_xmalloc_ptr
<char>
7766 partial_die_full_name (struct partial_die_info
*pdi
,
7767 struct dwarf2_cu
*cu
)
7769 const char *parent_scope
;
7771 /* If this is a template instantiation, we can not work out the
7772 template arguments from partial DIEs. So, unfortunately, we have
7773 to go through the full DIEs. At least any work we do building
7774 types here will be reused if full symbols are loaded later. */
7775 if (pdi
->has_template_arguments
)
7779 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7781 struct die_info
*die
;
7782 struct attribute attr
;
7783 struct dwarf2_cu
*ref_cu
= cu
;
7785 /* DW_FORM_ref_addr is using section offset. */
7786 attr
.name
= (enum dwarf_attribute
) 0;
7787 attr
.form
= DW_FORM_ref_addr
;
7788 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7789 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7791 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7795 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7796 if (parent_scope
== NULL
)
7799 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7805 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7807 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7808 struct objfile
*objfile
= per_objfile
->objfile
;
7809 struct gdbarch
*gdbarch
= objfile
->arch ();
7811 const char *actual_name
= NULL
;
7814 baseaddr
= objfile
->text_section_offset ();
7816 gdb::unique_xmalloc_ptr
<char> built_actual_name
7817 = partial_die_full_name (pdi
, cu
);
7818 if (built_actual_name
!= NULL
)
7819 actual_name
= built_actual_name
.get ();
7821 if (actual_name
== NULL
)
7822 actual_name
= pdi
->name (cu
);
7824 partial_symbol psymbol
;
7825 memset (&psymbol
, 0, sizeof (psymbol
));
7826 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
7827 &objfile
->objfile_obstack
);
7828 psymbol
.ginfo
.set_section_index (-1);
7830 /* The code below indicates that the psymbol should be installed by
7832 gdb::optional
<psymbol_placement
> where
;
7836 case DW_TAG_inlined_subroutine
:
7837 case DW_TAG_subprogram
:
7838 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7840 if (pdi
->is_external
7841 || cu
->per_cu
->lang
== language_ada
7842 || (cu
->per_cu
->lang
== language_fortran
7843 && pdi
->die_parent
!= NULL
7844 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7846 /* Normally, only "external" DIEs are part of the global scope.
7847 But in Ada and Fortran, we want to be able to access nested
7848 procedures globally. So all Ada and Fortran subprograms are
7849 stored in the global scope. */
7850 where
= psymbol_placement::GLOBAL
;
7853 where
= psymbol_placement::STATIC
;
7855 psymbol
.domain
= VAR_DOMAIN
;
7856 psymbol
.aclass
= LOC_BLOCK
;
7857 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7858 psymbol
.ginfo
.value
.address
= addr
;
7860 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7861 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
7863 case DW_TAG_constant
:
7864 psymbol
.domain
= VAR_DOMAIN
;
7865 psymbol
.aclass
= LOC_STATIC
;
7866 where
= (pdi
->is_external
7867 ? psymbol_placement::GLOBAL
7868 : psymbol_placement::STATIC
);
7870 case DW_TAG_variable
:
7872 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7876 && !per_objfile
->per_bfd
->has_section_at_zero
)
7878 /* A global or static variable may also have been stripped
7879 out by the linker if unused, in which case its address
7880 will be nullified; do not add such variables into partial
7881 symbol table then. */
7883 else if (pdi
->is_external
)
7886 Don't enter into the minimal symbol tables as there is
7887 a minimal symbol table entry from the ELF symbols already.
7888 Enter into partial symbol table if it has a location
7889 descriptor or a type.
7890 If the location descriptor is missing, new_symbol will create
7891 a LOC_UNRESOLVED symbol, the address of the variable will then
7892 be determined from the minimal symbol table whenever the variable
7894 The address for the partial symbol table entry is not
7895 used by GDB, but it comes in handy for debugging partial symbol
7898 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7900 psymbol
.domain
= VAR_DOMAIN
;
7901 psymbol
.aclass
= LOC_STATIC
;
7902 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7903 psymbol
.ginfo
.value
.address
= addr
;
7904 where
= psymbol_placement::GLOBAL
;
7909 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7911 /* Static Variable. Skip symbols whose value we cannot know (those
7912 without location descriptors or constant values). */
7913 if (!has_loc
&& !pdi
->has_const_value
)
7916 psymbol
.domain
= VAR_DOMAIN
;
7917 psymbol
.aclass
= LOC_STATIC
;
7918 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7920 psymbol
.ginfo
.value
.address
= addr
;
7921 where
= psymbol_placement::STATIC
;
7924 case DW_TAG_array_type
:
7925 case DW_TAG_typedef
:
7926 case DW_TAG_base_type
:
7927 case DW_TAG_subrange_type
:
7928 psymbol
.domain
= VAR_DOMAIN
;
7929 psymbol
.aclass
= LOC_TYPEDEF
;
7930 where
= psymbol_placement::STATIC
;
7932 case DW_TAG_imported_declaration
:
7933 case DW_TAG_namespace
:
7934 psymbol
.domain
= VAR_DOMAIN
;
7935 psymbol
.aclass
= LOC_TYPEDEF
;
7936 where
= psymbol_placement::GLOBAL
;
7939 /* With Fortran 77 there might be a "BLOCK DATA" module
7940 available without any name. If so, we skip the module as it
7941 doesn't bring any value. */
7942 if (actual_name
!= nullptr)
7944 psymbol
.domain
= MODULE_DOMAIN
;
7945 psymbol
.aclass
= LOC_TYPEDEF
;
7946 where
= psymbol_placement::GLOBAL
;
7949 case DW_TAG_class_type
:
7950 case DW_TAG_interface_type
:
7951 case DW_TAG_structure_type
:
7952 case DW_TAG_union_type
:
7953 case DW_TAG_enumeration_type
:
7954 /* Skip external references. The DWARF standard says in the section
7955 about "Structure, Union, and Class Type Entries": "An incomplete
7956 structure, union or class type is represented by a structure,
7957 union or class entry that does not have a byte size attribute
7958 and that has a DW_AT_declaration attribute." */
7959 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7962 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7963 static vs. global. */
7964 psymbol
.domain
= STRUCT_DOMAIN
;
7965 psymbol
.aclass
= LOC_TYPEDEF
;
7966 where
= (cu
->per_cu
->lang
== language_cplus
7967 ? psymbol_placement::GLOBAL
7968 : psymbol_placement::STATIC
);
7970 case DW_TAG_enumerator
:
7971 psymbol
.domain
= VAR_DOMAIN
;
7972 psymbol
.aclass
= LOC_CONST
;
7973 where
= (cu
->per_cu
->lang
== language_cplus
7974 ? psymbol_placement::GLOBAL
7975 : psymbol_placement::STATIC
);
7981 if (where
.has_value ())
7983 if (built_actual_name
!= nullptr)
7984 actual_name
= objfile
->intern (actual_name
);
7985 if (pdi
->linkage_name
== nullptr
7986 || cu
->per_cu
->lang
== language_ada
)
7987 psymbol
.ginfo
.set_linkage_name (actual_name
);
7990 psymbol
.ginfo
.set_demangled_name (actual_name
,
7991 &objfile
->objfile_obstack
);
7992 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
7994 cu
->per_cu
->v
.psymtab
->add_psymbol
7995 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8000 /* Read a partial die corresponding to a namespace; also, add a symbol
8001 corresponding to that namespace to the symbol table. NAMESPACE is
8002 the name of the enclosing namespace. */
8005 add_partial_namespace (struct partial_die_info
*pdi
,
8006 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8007 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 namespace. */
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 Fortran module. */
8022 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8023 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8025 /* Add a symbol for the namespace. */
8027 add_partial_symbol (pdi
, cu
);
8029 /* Now scan partial symbols in that module. */
8031 if (pdi
->has_children
)
8032 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8035 /* Read a partial die corresponding to a subprogram or an inlined
8036 subprogram and create a partial symbol for that subprogram.
8037 When the CU language allows it, this routine also defines a partial
8038 symbol for each nested subprogram that this subprogram contains.
8039 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8040 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8042 PDI may also be a lexical block, in which case we simply search
8043 recursively for subprograms defined inside that lexical block.
8044 Again, this is only performed when the CU language allows this
8045 type of definitions. */
8048 add_partial_subprogram (struct partial_die_info
*pdi
,
8049 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8050 int set_addrmap
, struct dwarf2_cu
*cu
)
8052 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8054 if (pdi
->has_pc_info
)
8056 if (pdi
->lowpc
< *lowpc
)
8057 *lowpc
= pdi
->lowpc
;
8058 if (pdi
->highpc
> *highpc
)
8059 *highpc
= pdi
->highpc
;
8062 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8063 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8064 struct gdbarch
*gdbarch
= objfile
->arch ();
8066 CORE_ADDR this_highpc
;
8067 CORE_ADDR this_lowpc
;
8069 baseaddr
= objfile
->text_section_offset ();
8071 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8072 pdi
->lowpc
+ baseaddr
)
8075 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8076 pdi
->highpc
+ baseaddr
)
8078 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8079 this_lowpc
, this_highpc
- 1,
8080 cu
->per_cu
->v
.psymtab
);
8084 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8086 if (!pdi
->is_declaration
)
8087 /* Ignore subprogram DIEs that do not have a name, they are
8088 illegal. Do not emit a complaint at this point, we will
8089 do so when we convert this psymtab into a symtab. */
8091 add_partial_symbol (pdi
, cu
);
8095 if (! pdi
->has_children
)
8098 if (cu
->per_cu
->lang
== language_ada
8099 || cu
->per_cu
->lang
== language_fortran
)
8101 pdi
= pdi
->die_child
;
8105 if (pdi
->tag
== DW_TAG_subprogram
8106 || pdi
->tag
== DW_TAG_inlined_subroutine
8107 || pdi
->tag
== DW_TAG_lexical_block
)
8108 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8109 pdi
= pdi
->die_sibling
;
8114 /* Read a partial die corresponding to an enumeration type. */
8117 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8118 struct dwarf2_cu
*cu
)
8120 struct partial_die_info
*pdi
;
8122 if (enum_pdi
->name (cu
) != NULL
)
8123 add_partial_symbol (enum_pdi
, cu
);
8125 pdi
= enum_pdi
->die_child
;
8128 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8129 complaint (_("malformed enumerator DIE ignored"));
8131 add_partial_symbol (pdi
, cu
);
8132 pdi
= pdi
->die_sibling
;
8136 /* Return the initial uleb128 in the die at INFO_PTR. */
8139 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8141 unsigned int bytes_read
;
8143 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8146 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8147 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8149 Return the corresponding abbrev, or NULL if the number is zero (indicating
8150 an empty DIE). In either case *BYTES_READ will be set to the length of
8151 the initial number. */
8153 static const struct abbrev_info
*
8154 peek_die_abbrev (const die_reader_specs
&reader
,
8155 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8157 dwarf2_cu
*cu
= reader
.cu
;
8158 bfd
*abfd
= reader
.abfd
;
8159 unsigned int abbrev_number
8160 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8162 if (abbrev_number
== 0)
8165 const abbrev_info
*abbrev
8166 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8169 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8170 " at offset %s [in module %s]"),
8171 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8172 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8178 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8179 Returns a pointer to the end of a series of DIEs, terminated by an empty
8180 DIE. Any children of the skipped DIEs will also be skipped. */
8182 static const gdb_byte
*
8183 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8187 unsigned int bytes_read
;
8188 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8192 return info_ptr
+ bytes_read
;
8194 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8198 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8199 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8200 abbrev corresponding to that skipped uleb128 should be passed in
8201 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8204 static const gdb_byte
*
8205 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8206 const struct abbrev_info
*abbrev
)
8208 unsigned int bytes_read
;
8209 struct attribute attr
;
8210 bfd
*abfd
= reader
->abfd
;
8211 struct dwarf2_cu
*cu
= reader
->cu
;
8212 const gdb_byte
*buffer
= reader
->buffer
;
8213 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8214 unsigned int form
, i
;
8216 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8218 /* The only abbrev we care about is DW_AT_sibling. */
8219 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8221 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8222 if (attr
.form
== DW_FORM_ref_addr
)
8223 complaint (_("ignoring absolute DW_AT_sibling"));
8226 sect_offset off
= attr
.get_ref_die_offset ();
8227 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8229 if (sibling_ptr
< info_ptr
)
8230 complaint (_("DW_AT_sibling points backwards"));
8231 else if (sibling_ptr
> reader
->buffer_end
)
8232 reader
->die_section
->overflow_complaint ();
8238 /* If it isn't DW_AT_sibling, skip this attribute. */
8239 form
= abbrev
->attrs
[i
].form
;
8243 case DW_FORM_ref_addr
:
8244 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8245 and later it is offset sized. */
8246 if (cu
->header
.version
== 2)
8247 info_ptr
+= cu
->header
.addr_size
;
8249 info_ptr
+= cu
->header
.offset_size
;
8251 case DW_FORM_GNU_ref_alt
:
8252 info_ptr
+= cu
->header
.offset_size
;
8255 info_ptr
+= cu
->header
.addr_size
;
8263 case DW_FORM_flag_present
:
8264 case DW_FORM_implicit_const
:
8281 case DW_FORM_ref_sig8
:
8284 case DW_FORM_data16
:
8287 case DW_FORM_string
:
8288 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8289 info_ptr
+= bytes_read
;
8291 case DW_FORM_sec_offset
:
8293 case DW_FORM_GNU_strp_alt
:
8294 info_ptr
+= cu
->header
.offset_size
;
8296 case DW_FORM_exprloc
:
8298 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8299 info_ptr
+= bytes_read
;
8301 case DW_FORM_block1
:
8302 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8304 case DW_FORM_block2
:
8305 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8307 case DW_FORM_block4
:
8308 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8314 case DW_FORM_ref_udata
:
8315 case DW_FORM_GNU_addr_index
:
8316 case DW_FORM_GNU_str_index
:
8317 case DW_FORM_rnglistx
:
8318 case DW_FORM_loclistx
:
8319 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8321 case DW_FORM_indirect
:
8322 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8323 info_ptr
+= bytes_read
;
8324 /* We need to continue parsing from here, so just go back to
8326 goto skip_attribute
;
8329 error (_("Dwarf Error: Cannot handle %s "
8330 "in DWARF reader [in module %s]"),
8331 dwarf_form_name (form
),
8332 bfd_get_filename (abfd
));
8336 if (abbrev
->has_children
)
8337 return skip_children (reader
, info_ptr
);
8342 /* Locate ORIG_PDI's sibling.
8343 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8345 static const gdb_byte
*
8346 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8347 struct partial_die_info
*orig_pdi
,
8348 const gdb_byte
*info_ptr
)
8350 /* Do we know the sibling already? */
8352 if (orig_pdi
->sibling
)
8353 return orig_pdi
->sibling
;
8355 /* Are there any children to deal with? */
8357 if (!orig_pdi
->has_children
)
8360 /* Skip the children the long way. */
8362 return skip_children (reader
, info_ptr
);
8365 /* Expand this partial symbol table into a full symbol table. SELF is
8369 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8371 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8373 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8375 /* If this psymtab is constructed from a debug-only objfile, the
8376 has_section_at_zero flag will not necessarily be correct. We
8377 can get the correct value for this flag by looking at the data
8378 associated with the (presumably stripped) associated objfile. */
8379 if (objfile
->separate_debug_objfile_backlink
)
8381 dwarf2_per_objfile
*per_objfile_backlink
8382 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8384 per_objfile
->per_bfd
->has_section_at_zero
8385 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8388 expand_psymtab (objfile
);
8390 process_cu_includes (per_objfile
);
8393 /* Reading in full CUs. */
8395 /* Add PER_CU to the queue. */
8398 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8399 dwarf2_per_objfile
*per_objfile
,
8400 enum language pretend_language
)
8404 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8405 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8408 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8410 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8413 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8414 DIEs, false otherwise.
8416 Explanation: there is an invariant that if a CU is queued for expansion
8417 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8418 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8419 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8420 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8421 invariant is respected.
8423 The caller is therefore not required to load the CU's DIEs (we return false)
8426 - the CU is already expanded, and therefore does not get enqueued
8427 - the CU gets enqueued for expansion, but its DIEs are already loaded
8429 Note that the caller should not use this function's return value as an
8430 indicator of whether the CU's DIEs are loaded right now, it should check
8431 that by calling `dwarf2_per_objfile::get_cu` instead. */
8434 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8435 dwarf2_per_cu_data
*per_cu
,
8436 dwarf2_per_objfile
*per_objfile
,
8437 enum language pretend_language
)
8439 /* We may arrive here during partial symbol reading, if we need full
8440 DIEs to process an unusual case (e.g. template arguments). Do
8441 not queue PER_CU, just tell our caller to load its DIEs. */
8442 if (per_cu
->per_bfd
->reading_partial_symbols
)
8444 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8446 if (cu
== NULL
|| cu
->dies
== NULL
)
8451 /* Mark the dependence relation so that we don't flush PER_CU
8453 if (dependent_cu
!= NULL
)
8454 dependent_cu
->add_dependence (per_cu
);
8456 /* If it's already on the queue, we have nothing to do. */
8459 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8461 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8463 /* If the CU is queued for expansion, it should not already be
8465 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8467 /* The DIEs are already loaded, the caller doesn't need to do it. */
8471 bool queued
= false;
8472 if (!per_objfile
->symtab_set_p (per_cu
))
8474 /* Add it to the queue. */
8475 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8479 /* If the compilation unit is already loaded, just mark it as
8481 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8485 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8486 and the DIEs are not already loaded. */
8487 return queued
&& cu
== nullptr;
8490 /* Process the queue. */
8493 process_queue (dwarf2_per_objfile
*per_objfile
)
8495 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8496 objfile_name (per_objfile
->objfile
));
8498 /* The queue starts out with one item, but following a DIE reference
8499 may load a new CU, adding it to the end of the queue. */
8500 while (!per_objfile
->per_bfd
->queue
->empty ())
8502 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8503 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8505 if (!per_objfile
->symtab_set_p (per_cu
))
8507 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8509 /* Skip dummy CUs. */
8512 unsigned int debug_print_threshold
;
8515 if (per_cu
->is_debug_types
)
8517 struct signatured_type
*sig_type
=
8518 (struct signatured_type
*) per_cu
;
8520 sprintf (buf
, "TU %s at offset %s",
8521 hex_string (sig_type
->signature
),
8522 sect_offset_str (per_cu
->sect_off
));
8523 /* There can be 100s of TUs.
8524 Only print them in verbose mode. */
8525 debug_print_threshold
= 2;
8529 sprintf (buf
, "CU at offset %s",
8530 sect_offset_str (per_cu
->sect_off
));
8531 debug_print_threshold
= 1;
8534 if (dwarf_read_debug
>= debug_print_threshold
)
8535 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8537 if (per_cu
->is_debug_types
)
8538 process_full_type_unit (cu
, item
.pretend_language
);
8540 process_full_comp_unit (cu
, item
.pretend_language
);
8542 if (dwarf_read_debug
>= debug_print_threshold
)
8543 dwarf_read_debug_printf ("Done expanding %s", buf
);
8548 per_objfile
->per_bfd
->queue
->pop ();
8551 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8552 objfile_name (per_objfile
->objfile
));
8555 /* Read in full symbols for PST, and anything it depends on. */
8558 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8560 gdb_assert (!readin_p (objfile
));
8562 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8563 free_cached_comp_units
freer (per_objfile
);
8564 expand_dependencies (objfile
);
8566 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8567 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8570 /* See psympriv.h. */
8573 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8575 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8576 return per_objfile
->symtab_set_p (per_cu_data
);
8579 /* See psympriv.h. */
8582 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8584 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8585 return per_objfile
->get_symtab (per_cu_data
);
8588 /* Trivial hash function for die_info: the hash value of a DIE
8589 is its offset in .debug_info for this objfile. */
8592 die_hash (const void *item
)
8594 const struct die_info
*die
= (const struct die_info
*) item
;
8596 return to_underlying (die
->sect_off
);
8599 /* Trivial comparison function for die_info structures: two DIEs
8600 are equal if they have the same offset. */
8603 die_eq (const void *item_lhs
, const void *item_rhs
)
8605 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8606 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8608 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8611 /* Load the DIEs associated with PER_CU into memory.
8613 In some cases, the caller, while reading partial symbols, will need to load
8614 the full symbols for the CU for some reason. It will already have a
8615 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8616 rather than creating a new one. */
8619 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8620 dwarf2_per_objfile
*per_objfile
,
8621 dwarf2_cu
*existing_cu
,
8623 enum language pretend_language
)
8625 gdb_assert (! this_cu
->is_debug_types
);
8627 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8631 struct dwarf2_cu
*cu
= reader
.cu
;
8632 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8634 gdb_assert (cu
->die_hash
== NULL
);
8636 htab_create_alloc_ex (cu
->header
.length
/ 12,
8640 &cu
->comp_unit_obstack
,
8641 hashtab_obstack_allocate
,
8642 dummy_obstack_deallocate
);
8644 if (reader
.comp_unit_die
->has_children
)
8645 reader
.comp_unit_die
->child
8646 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8647 &info_ptr
, reader
.comp_unit_die
);
8648 cu
->dies
= reader
.comp_unit_die
;
8649 /* comp_unit_die is not stored in die_hash, no need. */
8651 /* We try not to read any attributes in this function, because not
8652 all CUs needed for references have been loaded yet, and symbol
8653 table processing isn't initialized. But we have to set the CU language,
8654 or we won't be able to build types correctly.
8655 Similarly, if we do not read the producer, we can not apply
8656 producer-specific interpretation. */
8657 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8662 /* Add a DIE to the delayed physname list. */
8665 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8666 const char *name
, struct die_info
*die
,
8667 struct dwarf2_cu
*cu
)
8669 struct delayed_method_info mi
;
8671 mi
.fnfield_index
= fnfield_index
;
8675 cu
->method_list
.push_back (mi
);
8678 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8679 "const" / "volatile". If so, decrements LEN by the length of the
8680 modifier and return true. Otherwise return false. */
8684 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8686 size_t mod_len
= sizeof (mod
) - 1;
8687 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8695 /* Compute the physnames of any methods on the CU's method list.
8697 The computation of method physnames is delayed in order to avoid the
8698 (bad) condition that one of the method's formal parameters is of an as yet
8702 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8704 /* Only C++ delays computing physnames. */
8705 if (cu
->method_list
.empty ())
8707 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
8709 for (const delayed_method_info
&mi
: cu
->method_list
)
8711 const char *physname
;
8712 struct fn_fieldlist
*fn_flp
8713 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8714 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8715 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8716 = physname
? physname
: "";
8718 /* Since there's no tag to indicate whether a method is a
8719 const/volatile overload, extract that information out of the
8721 if (physname
!= NULL
)
8723 size_t len
= strlen (physname
);
8727 if (physname
[len
] == ')') /* shortcut */
8729 else if (check_modifier (physname
, len
, " const"))
8730 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8731 else if (check_modifier (physname
, len
, " volatile"))
8732 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8739 /* The list is no longer needed. */
8740 cu
->method_list
.clear ();
8743 /* Go objects should be embedded in a DW_TAG_module DIE,
8744 and it's not clear if/how imported objects will appear.
8745 To keep Go support simple until that's worked out,
8746 go back through what we've read and create something usable.
8747 We could do this while processing each DIE, and feels kinda cleaner,
8748 but that way is more invasive.
8749 This is to, for example, allow the user to type "p var" or "b main"
8750 without having to specify the package name, and allow lookups
8751 of module.object to work in contexts that use the expression
8755 fixup_go_packaging (struct dwarf2_cu
*cu
)
8757 gdb::unique_xmalloc_ptr
<char> package_name
;
8758 struct pending
*list
;
8761 for (list
= *cu
->get_builder ()->get_global_symbols ();
8765 for (i
= 0; i
< list
->nsyms
; ++i
)
8767 struct symbol
*sym
= list
->symbol
[i
];
8769 if (sym
->language () == language_go
8770 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8772 gdb::unique_xmalloc_ptr
<char> this_package_name
8773 (go_symbol_package_name (sym
));
8775 if (this_package_name
== NULL
)
8777 if (package_name
== NULL
)
8778 package_name
= std::move (this_package_name
);
8781 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8782 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8783 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8784 (symbol_symtab (sym
) != NULL
8785 ? symtab_to_filename_for_display
8786 (symbol_symtab (sym
))
8787 : objfile_name (objfile
)),
8788 this_package_name
.get (), package_name
.get ());
8794 if (package_name
!= NULL
)
8796 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8797 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8798 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8799 saved_package_name
);
8802 sym
= new (&objfile
->objfile_obstack
) symbol
;
8803 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8804 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8805 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8806 e.g., "main" finds the "main" module and not C's main(). */
8807 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8808 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8809 SYMBOL_TYPE (sym
) = type
;
8811 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8815 /* Allocate a fully-qualified name consisting of the two parts on the
8819 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8821 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8824 /* A helper that allocates a variant part to attach to a Rust enum
8825 type. OBSTACK is where the results should be allocated. TYPE is
8826 the type we're processing. DISCRIMINANT_INDEX is the index of the
8827 discriminant. It must be the index of one of the fields of TYPE,
8828 or -1 to mean there is no discriminant (univariant enum).
8829 DEFAULT_INDEX is the index of the default field; or -1 if there is
8830 no default. RANGES is indexed by "effective" field number (the
8831 field index, but omitting the discriminant and default fields) and
8832 must hold the discriminant values used by the variants. Note that
8833 RANGES must have a lifetime at least as long as OBSTACK -- either
8834 already allocated on it, or static. */
8837 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8838 int discriminant_index
, int default_index
,
8839 gdb::array_view
<discriminant_range
> ranges
)
8841 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8842 gdb_assert (discriminant_index
== -1
8843 || (discriminant_index
>= 0
8844 && discriminant_index
< type
->num_fields ()));
8845 gdb_assert (default_index
== -1
8846 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8848 /* We have one variant for each non-discriminant field. */
8849 int n_variants
= type
->num_fields ();
8850 if (discriminant_index
!= -1)
8853 variant
*variants
= new (obstack
) variant
[n_variants
];
8856 for (int i
= 0; i
< type
->num_fields (); ++i
)
8858 if (i
== discriminant_index
)
8861 variants
[var_idx
].first_field
= i
;
8862 variants
[var_idx
].last_field
= i
+ 1;
8864 /* The default field does not need a range, but other fields do.
8865 We skipped the discriminant above. */
8866 if (i
!= default_index
)
8868 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8875 gdb_assert (range_idx
== ranges
.size ());
8876 gdb_assert (var_idx
== n_variants
);
8878 variant_part
*part
= new (obstack
) variant_part
;
8879 part
->discriminant_index
= discriminant_index
;
8880 /* If there is no discriminant, then whether it is signed is of no
8883 = (discriminant_index
== -1
8885 : type
->field (discriminant_index
).type ()->is_unsigned ());
8886 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
8888 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
8889 gdb::array_view
<variant_part
> *prop_value
8890 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
8892 struct dynamic_prop prop
;
8893 prop
.set_variant_parts (prop_value
);
8895 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
8898 /* Some versions of rustc emitted enums in an unusual way.
8900 Ordinary enums were emitted as unions. The first element of each
8901 structure in the union was named "RUST$ENUM$DISR". This element
8902 held the discriminant.
8904 These versions of Rust also implemented the "non-zero"
8905 optimization. When the enum had two values, and one is empty and
8906 the other holds a pointer that cannot be zero, the pointer is used
8907 as the discriminant, with a zero value meaning the empty variant.
8908 Here, the union's first member is of the form
8909 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
8910 where the fieldnos are the indices of the fields that should be
8911 traversed in order to find the field (which may be several fields deep)
8912 and the variantname is the name of the variant of the case when the
8915 This function recognizes whether TYPE is of one of these forms,
8916 and, if so, smashes it to be a variant type. */
8919 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
8921 gdb_assert (type
->code () == TYPE_CODE_UNION
);
8923 /* We don't need to deal with empty enums. */
8924 if (type
->num_fields () == 0)
8927 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
8928 if (type
->num_fields () == 1
8929 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
8931 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
8933 /* Decode the field name to find the offset of the
8935 ULONGEST bit_offset
= 0;
8936 struct type
*field_type
= type
->field (0).type ();
8937 while (name
[0] >= '0' && name
[0] <= '9')
8940 unsigned long index
= strtoul (name
, &tail
, 10);
8943 || index
>= field_type
->num_fields ()
8944 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
8945 != FIELD_LOC_KIND_BITPOS
))
8947 complaint (_("Could not parse Rust enum encoding string \"%s\""
8949 TYPE_FIELD_NAME (type
, 0),
8950 objfile_name (objfile
));
8955 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
8956 field_type
= field_type
->field (index
).type ();
8959 /* Smash this type to be a structure type. We have to do this
8960 because the type has already been recorded. */
8961 type
->set_code (TYPE_CODE_STRUCT
);
8962 type
->set_num_fields (3);
8963 /* Save the field we care about. */
8964 struct field saved_field
= type
->field (0);
8966 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
8968 /* Put the discriminant at index 0. */
8969 type
->field (0).set_type (field_type
);
8970 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
8971 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
8972 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
8974 /* The order of fields doesn't really matter, so put the real
8975 field at index 1 and the data-less field at index 2. */
8976 type
->field (1) = saved_field
;
8977 TYPE_FIELD_NAME (type
, 1)
8978 = rust_last_path_segment (type
->field (1).type ()->name ());
8979 type
->field (1).type ()->set_name
8980 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8981 TYPE_FIELD_NAME (type
, 1)));
8983 const char *dataless_name
8984 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8986 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
8988 type
->field (2).set_type (dataless_type
);
8989 /* NAME points into the original discriminant name, which
8990 already has the correct lifetime. */
8991 TYPE_FIELD_NAME (type
, 2) = name
;
8992 SET_FIELD_BITPOS (type
->field (2), 0);
8994 /* Indicate that this is a variant type. */
8995 static discriminant_range ranges
[1] = { { 0, 0 } };
8996 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
8998 /* A union with a single anonymous field is probably an old-style
9000 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9002 /* Smash this type to be a structure type. We have to do this
9003 because the type has already been recorded. */
9004 type
->set_code (TYPE_CODE_STRUCT
);
9006 struct type
*field_type
= type
->field (0).type ();
9007 const char *variant_name
9008 = rust_last_path_segment (field_type
->name ());
9009 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9010 field_type
->set_name
9011 (rust_fully_qualify (&objfile
->objfile_obstack
,
9012 type
->name (), variant_name
));
9014 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9018 struct type
*disr_type
= nullptr;
9019 for (int i
= 0; i
< type
->num_fields (); ++i
)
9021 disr_type
= type
->field (i
).type ();
9023 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9025 /* All fields of a true enum will be structs. */
9028 else if (disr_type
->num_fields () == 0)
9030 /* Could be data-less variant, so keep going. */
9031 disr_type
= nullptr;
9033 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9034 "RUST$ENUM$DISR") != 0)
9036 /* Not a Rust enum. */
9046 /* If we got here without a discriminant, then it's probably
9048 if (disr_type
== nullptr)
9051 /* Smash this type to be a structure type. We have to do this
9052 because the type has already been recorded. */
9053 type
->set_code (TYPE_CODE_STRUCT
);
9055 /* Make space for the discriminant field. */
9056 struct field
*disr_field
= &disr_type
->field (0);
9058 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9059 * sizeof (struct field
)));
9060 memcpy (new_fields
+ 1, type
->fields (),
9061 type
->num_fields () * sizeof (struct field
));
9062 type
->set_fields (new_fields
);
9063 type
->set_num_fields (type
->num_fields () + 1);
9065 /* Install the discriminant at index 0 in the union. */
9066 type
->field (0) = *disr_field
;
9067 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9068 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9070 /* We need a way to find the correct discriminant given a
9071 variant name. For convenience we build a map here. */
9072 struct type
*enum_type
= disr_field
->type ();
9073 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9074 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9076 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9079 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9080 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9084 int n_fields
= type
->num_fields ();
9085 /* We don't need a range entry for the discriminant, but we do
9086 need one for every other field, as there is no default
9088 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9091 /* Skip the discriminant here. */
9092 for (int i
= 1; i
< n_fields
; ++i
)
9094 /* Find the final word in the name of this variant's type.
9095 That name can be used to look up the correct
9097 const char *variant_name
9098 = rust_last_path_segment (type
->field (i
).type ()->name ());
9100 auto iter
= discriminant_map
.find (variant_name
);
9101 if (iter
!= discriminant_map
.end ())
9103 ranges
[i
- 1].low
= iter
->second
;
9104 ranges
[i
- 1].high
= iter
->second
;
9107 /* In Rust, each element should have the size of the
9109 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9111 /* Remove the discriminant field, if it exists. */
9112 struct type
*sub_type
= type
->field (i
).type ();
9113 if (sub_type
->num_fields () > 0)
9115 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9116 sub_type
->set_fields (sub_type
->fields () + 1);
9118 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9120 (rust_fully_qualify (&objfile
->objfile_obstack
,
9121 type
->name (), variant_name
));
9124 /* Indicate that this is a variant type. */
9125 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9126 gdb::array_view
<discriminant_range
> (ranges
,
9131 /* Rewrite some Rust unions to be structures with variants parts. */
9134 rust_union_quirks (struct dwarf2_cu
*cu
)
9136 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9137 for (type
*type_
: cu
->rust_unions
)
9138 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9139 /* We don't need this any more. */
9140 cu
->rust_unions
.clear ();
9145 type_unit_group_unshareable
*
9146 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9148 auto iter
= this->m_type_units
.find (tu_group
);
9149 if (iter
!= this->m_type_units
.end ())
9150 return iter
->second
.get ();
9152 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9153 type_unit_group_unshareable
*result
= uniq
.get ();
9154 this->m_type_units
[tu_group
] = std::move (uniq
);
9159 dwarf2_per_objfile::get_type_for_signatured_type
9160 (signatured_type
*sig_type
) const
9162 auto iter
= this->m_type_map
.find (sig_type
);
9163 if (iter
== this->m_type_map
.end ())
9166 return iter
->second
;
9169 void dwarf2_per_objfile::set_type_for_signatured_type
9170 (signatured_type
*sig_type
, struct type
*type
)
9172 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9174 this->m_type_map
[sig_type
] = type
;
9177 /* A helper function for computing the list of all symbol tables
9178 included by PER_CU. */
9181 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9182 htab_t all_children
, htab_t all_type_symtabs
,
9183 dwarf2_per_cu_data
*per_cu
,
9184 dwarf2_per_objfile
*per_objfile
,
9185 struct compunit_symtab
*immediate_parent
)
9187 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9190 /* This inclusion and its children have been processed. */
9196 /* Only add a CU if it has a symbol table. */
9197 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9200 /* If this is a type unit only add its symbol table if we haven't
9201 seen it yet (type unit per_cu's can share symtabs). */
9202 if (per_cu
->is_debug_types
)
9204 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9208 result
->push_back (cust
);
9209 if (cust
->user
== NULL
)
9210 cust
->user
= immediate_parent
;
9215 result
->push_back (cust
);
9216 if (cust
->user
== NULL
)
9217 cust
->user
= immediate_parent
;
9221 if (!per_cu
->imported_symtabs_empty ())
9222 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9224 recursively_compute_inclusions (result
, all_children
,
9225 all_type_symtabs
, ptr
, per_objfile
,
9230 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9234 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9235 dwarf2_per_objfile
*per_objfile
)
9237 gdb_assert (! per_cu
->is_debug_types
);
9239 if (!per_cu
->imported_symtabs_empty ())
9242 std::vector
<compunit_symtab
*> result_symtabs
;
9243 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9245 /* If we don't have a symtab, we can just skip this case. */
9249 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9251 NULL
, xcalloc
, xfree
));
9252 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9254 NULL
, xcalloc
, xfree
));
9256 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9258 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9259 all_type_symtabs
.get (), ptr
,
9263 /* Now we have a transitive closure of all the included symtabs. */
9264 len
= result_symtabs
.size ();
9266 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9267 struct compunit_symtab
*, len
+ 1);
9268 memcpy (cust
->includes
, result_symtabs
.data (),
9269 len
* sizeof (compunit_symtab
*));
9270 cust
->includes
[len
] = NULL
;
9274 /* Compute the 'includes' field for the symtabs of all the CUs we just
9278 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9280 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9282 if (! iter
->is_debug_types
)
9283 compute_compunit_symtab_includes (iter
, per_objfile
);
9286 per_objfile
->per_bfd
->just_read_cus
.clear ();
9289 /* Generate full symbol information for CU, whose DIEs have
9290 already been loaded into memory. */
9293 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9295 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9296 struct objfile
*objfile
= per_objfile
->objfile
;
9297 struct gdbarch
*gdbarch
= objfile
->arch ();
9298 CORE_ADDR lowpc
, highpc
;
9299 struct compunit_symtab
*cust
;
9301 struct block
*static_block
;
9304 baseaddr
= objfile
->text_section_offset ();
9306 /* Clear the list here in case something was left over. */
9307 cu
->method_list
.clear ();
9309 dwarf2_find_base_address (cu
->dies
, cu
);
9311 /* Before we start reading the top-level DIE, ensure it has a valid tag
9313 switch (cu
->dies
->tag
)
9315 case DW_TAG_compile_unit
:
9316 case DW_TAG_partial_unit
:
9317 case DW_TAG_type_unit
:
9320 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9321 dwarf_tag_name (cu
->dies
->tag
),
9322 sect_offset_str (cu
->per_cu
->sect_off
),
9323 objfile_name (per_objfile
->objfile
));
9326 /* Do line number decoding in read_file_scope () */
9327 process_die (cu
->dies
, cu
);
9329 /* For now fudge the Go package. */
9330 if (cu
->per_cu
->lang
== language_go
)
9331 fixup_go_packaging (cu
);
9333 /* Now that we have processed all the DIEs in the CU, all the types
9334 should be complete, and it should now be safe to compute all of the
9336 compute_delayed_physnames (cu
);
9338 if (cu
->per_cu
->lang
== language_rust
)
9339 rust_union_quirks (cu
);
9341 /* Some compilers don't define a DW_AT_high_pc attribute for the
9342 compilation unit. If the DW_AT_high_pc is missing, synthesize
9343 it, by scanning the DIE's below the compilation unit. */
9344 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9346 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9347 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9349 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9350 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9351 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9352 addrmap to help ensure it has an accurate map of pc values belonging to
9354 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9356 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9357 SECT_OFF_TEXT (objfile
),
9362 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9364 /* Set symtab language to language from DW_AT_language. If the
9365 compilation is from a C file generated by language preprocessors, do
9366 not set the language if it was already deduced by start_subfile. */
9367 if (!(cu
->per_cu
->lang
== language_c
9368 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9369 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9371 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9372 produce DW_AT_location with location lists but it can be possibly
9373 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9374 there were bugs in prologue debug info, fixed later in GCC-4.5
9375 by "unwind info for epilogues" patch (which is not directly related).
9377 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9378 needed, it would be wrong due to missing DW_AT_producer there.
9380 Still one can confuse GDB by using non-standard GCC compilation
9381 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9383 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9384 cust
->locations_valid
= 1;
9386 if (gcc_4_minor
>= 5)
9387 cust
->epilogue_unwind_valid
= 1;
9389 cust
->call_site_htab
= cu
->call_site_htab
;
9392 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9394 /* Push it for inclusion processing later. */
9395 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9397 /* Not needed any more. */
9398 cu
->reset_builder ();
9401 /* Generate full symbol information for type unit CU, whose DIEs have
9402 already been loaded into memory. */
9405 process_full_type_unit (dwarf2_cu
*cu
,
9406 enum language pretend_language
)
9408 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9409 struct objfile
*objfile
= per_objfile
->objfile
;
9410 struct compunit_symtab
*cust
;
9411 struct signatured_type
*sig_type
;
9413 gdb_assert (cu
->per_cu
->is_debug_types
);
9414 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9416 /* Clear the list here in case something was left over. */
9417 cu
->method_list
.clear ();
9419 /* The symbol tables are set up in read_type_unit_scope. */
9420 process_die (cu
->dies
, cu
);
9422 /* For now fudge the Go package. */
9423 if (cu
->per_cu
->lang
== language_go
)
9424 fixup_go_packaging (cu
);
9426 /* Now that we have processed all the DIEs in the CU, all the types
9427 should be complete, and it should now be safe to compute all of the
9429 compute_delayed_physnames (cu
);
9431 if (cu
->per_cu
->lang
== language_rust
)
9432 rust_union_quirks (cu
);
9434 /* TUs share symbol tables.
9435 If this is the first TU to use this symtab, complete the construction
9436 of it with end_expandable_symtab. Otherwise, complete the addition of
9437 this TU's symbols to the existing symtab. */
9438 type_unit_group_unshareable
*tug_unshare
=
9439 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9440 if (tug_unshare
->compunit_symtab
== NULL
)
9442 buildsym_compunit
*builder
= cu
->get_builder ();
9443 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9444 tug_unshare
->compunit_symtab
= cust
;
9448 /* Set symtab language to language from DW_AT_language. If the
9449 compilation is from a C file generated by language preprocessors,
9450 do not set the language if it was already deduced by
9452 if (!(cu
->per_cu
->lang
== language_c
9453 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9454 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9459 cu
->get_builder ()->augment_type_symtab ();
9460 cust
= tug_unshare
->compunit_symtab
;
9463 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9465 /* Not needed any more. */
9466 cu
->reset_builder ();
9469 /* Process an imported unit DIE. */
9472 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9474 struct attribute
*attr
;
9476 /* For now we don't handle imported units in type units. */
9477 if (cu
->per_cu
->is_debug_types
)
9479 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9480 " supported in type units [in module %s]"),
9481 objfile_name (cu
->per_objfile
->objfile
));
9484 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9487 sect_offset sect_off
= attr
->get_ref_die_offset ();
9488 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9489 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9490 dwarf2_per_cu_data
*per_cu
9491 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9493 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9494 into another compilation unit, at root level. Regard this as a hint,
9496 if (die
->parent
&& die
->parent
->parent
== NULL
9497 && per_cu
->unit_type
== DW_UT_compile
9498 && per_cu
->lang
== language_cplus
)
9501 /* If necessary, add it to the queue and load its DIEs. */
9502 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
9504 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9505 false, cu
->per_cu
->lang
);
9507 cu
->per_cu
->imported_symtabs_push (per_cu
);
9511 /* RAII object that represents a process_die scope: i.e.,
9512 starts/finishes processing a DIE. */
9513 class process_die_scope
9516 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9517 : m_die (die
), m_cu (cu
)
9519 /* We should only be processing DIEs not already in process. */
9520 gdb_assert (!m_die
->in_process
);
9521 m_die
->in_process
= true;
9524 ~process_die_scope ()
9526 m_die
->in_process
= false;
9528 /* If we're done processing the DIE for the CU that owns the line
9529 header, we don't need the line header anymore. */
9530 if (m_cu
->line_header_die_owner
== m_die
)
9532 delete m_cu
->line_header
;
9533 m_cu
->line_header
= NULL
;
9534 m_cu
->line_header_die_owner
= NULL
;
9543 /* Process a die and its children. */
9546 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9548 process_die_scope
scope (die
, cu
);
9552 case DW_TAG_padding
:
9554 case DW_TAG_compile_unit
:
9555 case DW_TAG_partial_unit
:
9556 read_file_scope (die
, cu
);
9558 case DW_TAG_type_unit
:
9559 read_type_unit_scope (die
, cu
);
9561 case DW_TAG_subprogram
:
9562 /* Nested subprograms in Fortran get a prefix. */
9563 if (cu
->per_cu
->lang
== language_fortran
9564 && die
->parent
!= NULL
9565 && die
->parent
->tag
== DW_TAG_subprogram
)
9566 cu
->processing_has_namespace_info
= true;
9568 case DW_TAG_inlined_subroutine
:
9569 read_func_scope (die
, cu
);
9571 case DW_TAG_lexical_block
:
9572 case DW_TAG_try_block
:
9573 case DW_TAG_catch_block
:
9574 read_lexical_block_scope (die
, cu
);
9576 case DW_TAG_call_site
:
9577 case DW_TAG_GNU_call_site
:
9578 read_call_site_scope (die
, cu
);
9580 case DW_TAG_class_type
:
9581 case DW_TAG_interface_type
:
9582 case DW_TAG_structure_type
:
9583 case DW_TAG_union_type
:
9584 process_structure_scope (die
, cu
);
9586 case DW_TAG_enumeration_type
:
9587 process_enumeration_scope (die
, cu
);
9590 /* These dies have a type, but processing them does not create
9591 a symbol or recurse to process the children. Therefore we can
9592 read them on-demand through read_type_die. */
9593 case DW_TAG_subroutine_type
:
9594 case DW_TAG_set_type
:
9595 case DW_TAG_pointer_type
:
9596 case DW_TAG_ptr_to_member_type
:
9597 case DW_TAG_reference_type
:
9598 case DW_TAG_rvalue_reference_type
:
9599 case DW_TAG_string_type
:
9602 case DW_TAG_array_type
:
9603 /* We only need to handle this case for Ada -- in other
9604 languages, it's normal for the compiler to emit a typedef
9606 if (cu
->per_cu
->lang
!= language_ada
)
9609 case DW_TAG_base_type
:
9610 case DW_TAG_subrange_type
:
9611 case DW_TAG_typedef
:
9612 /* Add a typedef symbol for the type definition, if it has a
9614 new_symbol (die
, read_type_die (die
, cu
), cu
);
9616 case DW_TAG_common_block
:
9617 read_common_block (die
, cu
);
9619 case DW_TAG_common_inclusion
:
9621 case DW_TAG_namespace
:
9622 cu
->processing_has_namespace_info
= true;
9623 read_namespace (die
, cu
);
9626 cu
->processing_has_namespace_info
= true;
9627 read_module (die
, cu
);
9629 case DW_TAG_imported_declaration
:
9630 cu
->processing_has_namespace_info
= true;
9631 if (read_namespace_alias (die
, cu
))
9633 /* The declaration is not a global namespace alias. */
9635 case DW_TAG_imported_module
:
9636 cu
->processing_has_namespace_info
= true;
9637 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9638 || cu
->per_cu
->lang
!= language_fortran
))
9639 complaint (_("Tag '%s' has unexpected children"),
9640 dwarf_tag_name (die
->tag
));
9641 read_import_statement (die
, cu
);
9644 case DW_TAG_imported_unit
:
9645 process_imported_unit_die (die
, cu
);
9648 case DW_TAG_variable
:
9649 read_variable (die
, cu
);
9653 new_symbol (die
, NULL
, cu
);
9658 /* DWARF name computation. */
9660 /* A helper function for dwarf2_compute_name which determines whether DIE
9661 needs to have the name of the scope prepended to the name listed in the
9665 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9667 struct attribute
*attr
;
9671 case DW_TAG_namespace
:
9672 case DW_TAG_typedef
:
9673 case DW_TAG_class_type
:
9674 case DW_TAG_interface_type
:
9675 case DW_TAG_structure_type
:
9676 case DW_TAG_union_type
:
9677 case DW_TAG_enumeration_type
:
9678 case DW_TAG_enumerator
:
9679 case DW_TAG_subprogram
:
9680 case DW_TAG_inlined_subroutine
:
9682 case DW_TAG_imported_declaration
:
9685 case DW_TAG_variable
:
9686 case DW_TAG_constant
:
9687 /* We only need to prefix "globally" visible variables. These include
9688 any variable marked with DW_AT_external or any variable that
9689 lives in a namespace. [Variables in anonymous namespaces
9690 require prefixing, but they are not DW_AT_external.] */
9692 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9694 struct dwarf2_cu
*spec_cu
= cu
;
9696 return die_needs_namespace (die_specification (die
, &spec_cu
),
9700 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9701 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9702 && die
->parent
->tag
!= DW_TAG_module
)
9704 /* A variable in a lexical block of some kind does not need a
9705 namespace, even though in C++ such variables may be external
9706 and have a mangled name. */
9707 if (die
->parent
->tag
== DW_TAG_lexical_block
9708 || die
->parent
->tag
== DW_TAG_try_block
9709 || die
->parent
->tag
== DW_TAG_catch_block
9710 || die
->parent
->tag
== DW_TAG_subprogram
)
9719 /* Return the DIE's linkage name attribute, 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. */
9723 static struct attribute
*
9724 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9726 struct attribute
*attr
;
9728 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9730 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9735 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9736 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9737 defined for the given DIE. */
9740 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9742 const char *linkage_name
;
9744 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9745 if (linkage_name
== NULL
)
9746 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9748 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9749 See https://github.com/rust-lang/rust/issues/32925. */
9750 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
9751 && strchr (linkage_name
, '{') != NULL
)
9752 linkage_name
= NULL
;
9754 return linkage_name
;
9757 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9758 compute the physname for the object, which include a method's:
9759 - formal parameters (C++),
9760 - receiver type (Go),
9762 The term "physname" is a bit confusing.
9763 For C++, for example, it is the demangled name.
9764 For Go, for example, it's the mangled name.
9766 For Ada, return the DIE's linkage name rather than the fully qualified
9767 name. PHYSNAME is ignored..
9769 The result is allocated on the objfile->per_bfd's obstack and
9773 dwarf2_compute_name (const char *name
,
9774 struct die_info
*die
, struct dwarf2_cu
*cu
,
9777 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9780 name
= dwarf2_name (die
, cu
);
9782 enum language lang
= cu
->per_cu
->lang
;
9784 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9785 but otherwise compute it by typename_concat inside GDB.
9786 FIXME: Actually this is not really true, or at least not always true.
9787 It's all very confusing. compute_and_set_names doesn't try to demangle
9788 Fortran names because there is no mangling standard. So new_symbol
9789 will set the demangled name to the result of dwarf2_full_name, and it is
9790 the demangled name that GDB uses if it exists. */
9791 if (lang
== language_ada
9792 || (lang
== language_fortran
&& physname
))
9794 /* For Ada unit, we prefer the linkage name over the name, as
9795 the former contains the exported name, which the user expects
9796 to be able to reference. Ideally, we want the user to be able
9797 to reference this entity using either natural or linkage name,
9798 but we haven't started looking at this enhancement yet. */
9799 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9801 if (linkage_name
!= NULL
)
9802 return linkage_name
;
9805 /* These are the only languages we know how to qualify names in. */
9807 && (lang
== language_cplus
9808 || lang
== language_fortran
|| lang
== language_d
9809 || lang
== language_rust
))
9811 if (die_needs_namespace (die
, cu
))
9814 const char *canonical_name
= NULL
;
9818 prefix
= determine_prefix (die
, cu
);
9819 if (*prefix
!= '\0')
9821 gdb::unique_xmalloc_ptr
<char> prefixed_name
9822 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9824 buf
.puts (prefixed_name
.get ());
9829 /* Template parameters may be specified in the DIE's DW_AT_name, or
9830 as children with DW_TAG_template_type_param or
9831 DW_TAG_value_type_param. If the latter, add them to the name
9832 here. If the name already has template parameters, then
9833 skip this step; some versions of GCC emit both, and
9834 it is more efficient to use the pre-computed name.
9836 Something to keep in mind about this process: it is very
9837 unlikely, or in some cases downright impossible, to produce
9838 something that will match the mangled name of a function.
9839 If the definition of the function has the same debug info,
9840 we should be able to match up with it anyway. But fallbacks
9841 using the minimal symbol, for instance to find a method
9842 implemented in a stripped copy of libstdc++, will not work.
9843 If we do not have debug info for the definition, we will have to
9844 match them up some other way.
9846 When we do name matching there is a related problem with function
9847 templates; two instantiated function templates are allowed to
9848 differ only by their return types, which we do not add here. */
9850 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
9852 struct attribute
*attr
;
9853 struct die_info
*child
;
9856 die
->building_fullname
= 1;
9858 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9862 const gdb_byte
*bytes
;
9863 struct dwarf2_locexpr_baton
*baton
;
9866 if (child
->tag
!= DW_TAG_template_type_param
9867 && child
->tag
!= DW_TAG_template_value_param
)
9878 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9881 complaint (_("template parameter missing DW_AT_type"));
9882 buf
.puts ("UNKNOWN_TYPE");
9885 type
= die_type (child
, cu
);
9887 if (child
->tag
== DW_TAG_template_type_param
)
9889 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
9890 &type_print_raw_options
);
9894 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
9897 complaint (_("template parameter missing "
9898 "DW_AT_const_value"));
9899 buf
.puts ("UNKNOWN_VALUE");
9903 dwarf2_const_value_attr (attr
, type
, name
,
9904 &cu
->comp_unit_obstack
, cu
,
9905 &value
, &bytes
, &baton
);
9907 if (type
->has_no_signedness ())
9908 /* GDB prints characters as NUMBER 'CHAR'. If that's
9909 changed, this can use value_print instead. */
9910 cu
->language_defn
->printchar (value
, type
, &buf
);
9913 struct value_print_options opts
;
9916 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
9920 baton
->per_objfile
);
9921 else if (bytes
!= NULL
)
9923 v
= allocate_value (type
);
9924 memcpy (value_contents_writeable (v
), bytes
,
9925 TYPE_LENGTH (type
));
9928 v
= value_from_longest (type
, value
);
9930 /* Specify decimal so that we do not depend on
9932 get_formatted_print_options (&opts
, 'd');
9934 value_print (v
, &buf
, &opts
);
9939 die
->building_fullname
= 0;
9943 /* Close the argument list, with a space if necessary
9944 (nested templates). */
9945 if (!buf
.empty () && buf
.string ().back () == '>')
9952 /* For C++ methods, append formal parameter type
9953 information, if PHYSNAME. */
9955 if (physname
&& die
->tag
== DW_TAG_subprogram
9956 && lang
== language_cplus
)
9958 struct type
*type
= read_type_die (die
, cu
);
9960 c_type_print_args (type
, &buf
, 1, lang
,
9961 &type_print_raw_options
);
9963 if (lang
== language_cplus
)
9965 /* Assume that an artificial first parameter is
9966 "this", but do not crash if it is not. RealView
9967 marks unnamed (and thus unused) parameters as
9968 artificial; there is no way to differentiate
9970 if (type
->num_fields () > 0
9971 && TYPE_FIELD_ARTIFICIAL (type
, 0)
9972 && type
->field (0).type ()->code () == TYPE_CODE_PTR
9973 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
9974 buf
.puts (" const");
9978 const std::string
&intermediate_name
= buf
.string ();
9980 if (lang
== language_cplus
)
9982 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
9985 /* If we only computed INTERMEDIATE_NAME, or if
9986 INTERMEDIATE_NAME is already canonical, then we need to
9988 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
9989 name
= objfile
->intern (intermediate_name
);
9991 name
= canonical_name
;
9998 /* Return the fully qualified name of DIE, based on its DW_AT_name.
9999 If scope qualifiers are appropriate they will be added. The result
10000 will be allocated on the storage_obstack, or NULL if the DIE does
10001 not have a name. NAME may either be from a previous call to
10002 dwarf2_name or NULL.
10004 The output string will be canonicalized (if C++). */
10006 static const char *
10007 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10009 return dwarf2_compute_name (name
, die
, cu
, 0);
10012 /* Construct a physname for the given DIE in CU. NAME may either be
10013 from a previous call to dwarf2_name or NULL. The result will be
10014 allocated on the objfile_objstack or NULL if the DIE does not have a
10017 The output string will be canonicalized (if C++). */
10019 static const char *
10020 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10022 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10023 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10026 /* In this case dwarf2_compute_name is just a shortcut not building anything
10028 if (!die_needs_namespace (die
, cu
))
10029 return dwarf2_compute_name (name
, die
, cu
, 1);
10031 if (cu
->per_cu
->lang
!= language_rust
)
10032 mangled
= dw2_linkage_name (die
, cu
);
10034 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10036 gdb::unique_xmalloc_ptr
<char> demangled
;
10037 if (mangled
!= NULL
)
10039 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10041 /* Do nothing (do not demangle the symbol name). */
10045 /* Use DMGL_RET_DROP for C++ template functions to suppress
10046 their return type. It is easier for GDB users to search
10047 for such functions as `name(params)' than `long name(params)'.
10048 In such case the minimal symbol names do not match the full
10049 symbol names but for template functions there is never a need
10050 to look up their definition from their declaration so
10051 the only disadvantage remains the minimal symbol variant
10052 `long name(params)' does not have the proper inferior type. */
10053 demangled
.reset (gdb_demangle (mangled
,
10054 (DMGL_PARAMS
| DMGL_ANSI
10055 | DMGL_RET_DROP
)));
10058 canon
= demangled
.get ();
10066 if (canon
== NULL
|| check_physname
)
10068 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10070 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10072 /* It may not mean a bug in GDB. The compiler could also
10073 compute DW_AT_linkage_name incorrectly. But in such case
10074 GDB would need to be bug-to-bug compatible. */
10076 complaint (_("Computed physname <%s> does not match demangled <%s> "
10077 "(from linkage <%s>) - DIE at %s [in module %s]"),
10078 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10079 objfile_name (objfile
));
10081 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10082 is available here - over computed PHYSNAME. It is safer
10083 against both buggy GDB and buggy compilers. */
10097 retval
= objfile
->intern (retval
);
10102 /* Inspect DIE in CU for a namespace alias. If one exists, record
10103 a new symbol for it.
10105 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10108 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10110 struct attribute
*attr
;
10112 /* If the die does not have a name, this is not a namespace
10114 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10118 struct die_info
*d
= die
;
10119 struct dwarf2_cu
*imported_cu
= cu
;
10121 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10122 keep inspecting DIEs until we hit the underlying import. */
10123 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10124 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10126 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10130 d
= follow_die_ref (d
, attr
, &imported_cu
);
10131 if (d
->tag
!= DW_TAG_imported_declaration
)
10135 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10137 complaint (_("DIE at %s has too many recursively imported "
10138 "declarations"), sect_offset_str (d
->sect_off
));
10145 sect_offset sect_off
= attr
->get_ref_die_offset ();
10147 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10148 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10150 /* This declaration is a global namespace alias. Add
10151 a symbol for it whose type is the aliased namespace. */
10152 new_symbol (die
, type
, cu
);
10161 /* Return the using directives repository (global or local?) to use in the
10162 current context for CU.
10164 For Ada, imported declarations can materialize renamings, which *may* be
10165 global. However it is impossible (for now?) in DWARF to distinguish
10166 "external" imported declarations and "static" ones. As all imported
10167 declarations seem to be static in all other languages, make them all CU-wide
10168 global only in Ada. */
10170 static struct using_direct
**
10171 using_directives (struct dwarf2_cu
*cu
)
10173 if (cu
->per_cu
->lang
== language_ada
10174 && cu
->get_builder ()->outermost_context_p ())
10175 return cu
->get_builder ()->get_global_using_directives ();
10177 return cu
->get_builder ()->get_local_using_directives ();
10180 /* Read the import statement specified by the given die and record it. */
10183 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10185 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10186 struct attribute
*import_attr
;
10187 struct die_info
*imported_die
, *child_die
;
10188 struct dwarf2_cu
*imported_cu
;
10189 const char *imported_name
;
10190 const char *imported_name_prefix
;
10191 const char *canonical_name
;
10192 const char *import_alias
;
10193 const char *imported_declaration
= NULL
;
10194 const char *import_prefix
;
10195 std::vector
<const char *> excludes
;
10197 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10198 if (import_attr
== NULL
)
10200 complaint (_("Tag '%s' has no DW_AT_import"),
10201 dwarf_tag_name (die
->tag
));
10206 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10207 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10208 if (imported_name
== NULL
)
10210 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10212 The import in the following code:
10226 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10227 <52> DW_AT_decl_file : 1
10228 <53> DW_AT_decl_line : 6
10229 <54> DW_AT_import : <0x75>
10230 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10231 <59> DW_AT_name : B
10232 <5b> DW_AT_decl_file : 1
10233 <5c> DW_AT_decl_line : 2
10234 <5d> DW_AT_type : <0x6e>
10236 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10237 <76> DW_AT_byte_size : 4
10238 <77> DW_AT_encoding : 5 (signed)
10240 imports the wrong die ( 0x75 instead of 0x58 ).
10241 This case will be ignored until the gcc bug is fixed. */
10245 /* Figure out the local name after import. */
10246 import_alias
= dwarf2_name (die
, cu
);
10248 /* Figure out where the statement is being imported to. */
10249 import_prefix
= determine_prefix (die
, cu
);
10251 /* Figure out what the scope of the imported die is and prepend it
10252 to the name of the imported die. */
10253 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10255 if (imported_die
->tag
!= DW_TAG_namespace
10256 && imported_die
->tag
!= DW_TAG_module
)
10258 imported_declaration
= imported_name
;
10259 canonical_name
= imported_name_prefix
;
10261 else if (strlen (imported_name_prefix
) > 0)
10262 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10263 imported_name_prefix
,
10264 (cu
->per_cu
->lang
== language_d
10267 imported_name
, (char *) NULL
);
10269 canonical_name
= imported_name
;
10271 if (die
->tag
== DW_TAG_imported_module
10272 && cu
->per_cu
->lang
== language_fortran
)
10273 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10274 child_die
= child_die
->sibling
)
10276 /* DWARF-4: A Fortran use statement with a “rename list” may be
10277 represented by an imported module entry with an import attribute
10278 referring to the module and owned entries corresponding to those
10279 entities that are renamed as part of being imported. */
10281 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10283 complaint (_("child DW_TAG_imported_declaration expected "
10284 "- DIE at %s [in module %s]"),
10285 sect_offset_str (child_die
->sect_off
),
10286 objfile_name (objfile
));
10290 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10291 if (import_attr
== NULL
)
10293 complaint (_("Tag '%s' has no DW_AT_import"),
10294 dwarf_tag_name (child_die
->tag
));
10299 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10301 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10302 if (imported_name
== NULL
)
10304 complaint (_("child DW_TAG_imported_declaration has unknown "
10305 "imported name - DIE at %s [in module %s]"),
10306 sect_offset_str (child_die
->sect_off
),
10307 objfile_name (objfile
));
10311 excludes
.push_back (imported_name
);
10313 process_die (child_die
, cu
);
10316 add_using_directive (using_directives (cu
),
10320 imported_declaration
,
10323 &objfile
->objfile_obstack
);
10326 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10327 types, but gives them a size of zero. Starting with version 14,
10328 ICC is compatible with GCC. */
10331 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10333 if (!cu
->checked_producer
)
10334 check_producer (cu
);
10336 return cu
->producer_is_icc_lt_14
;
10339 /* ICC generates a DW_AT_type for C void functions. This was observed on
10340 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10341 which says that void functions should not have a DW_AT_type. */
10344 producer_is_icc (struct dwarf2_cu
*cu
)
10346 if (!cu
->checked_producer
)
10347 check_producer (cu
);
10349 return cu
->producer_is_icc
;
10352 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10353 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10354 this, it was first present in GCC release 4.3.0. */
10357 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10359 if (!cu
->checked_producer
)
10360 check_producer (cu
);
10362 return cu
->producer_is_gcc_lt_4_3
;
10365 static file_and_directory
10366 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10368 file_and_directory res
;
10370 /* Find the filename. Do not use dwarf2_name here, since the filename
10371 is not a source language identifier. */
10372 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10373 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10375 if (res
.comp_dir
== NULL
10376 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10377 && IS_ABSOLUTE_PATH (res
.name
))
10379 res
.comp_dir_storage
= ldirname (res
.name
);
10380 if (!res
.comp_dir_storage
.empty ())
10381 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10383 if (res
.comp_dir
!= NULL
)
10385 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10386 directory, get rid of it. */
10387 const char *cp
= strchr (res
.comp_dir
, ':');
10389 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10390 res
.comp_dir
= cp
+ 1;
10393 if (res
.name
== NULL
)
10394 res
.name
= "<unknown>";
10399 /* Handle DW_AT_stmt_list for a compilation unit.
10400 DIE is the DW_TAG_compile_unit die for CU.
10401 COMP_DIR is the compilation directory. LOWPC is passed to
10402 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10405 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10406 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10408 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10409 struct attribute
*attr
;
10410 struct line_header line_header_local
;
10411 hashval_t line_header_local_hash
;
10413 int decode_mapping
;
10415 gdb_assert (! cu
->per_cu
->is_debug_types
);
10417 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10418 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10421 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10423 /* The line header hash table is only created if needed (it exists to
10424 prevent redundant reading of the line table for partial_units).
10425 If we're given a partial_unit, we'll need it. If we're given a
10426 compile_unit, then use the line header hash table if it's already
10427 created, but don't create one just yet. */
10429 if (per_objfile
->line_header_hash
== NULL
10430 && die
->tag
== DW_TAG_partial_unit
)
10432 per_objfile
->line_header_hash
10433 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10434 line_header_eq_voidp
,
10435 htab_delete_entry
<line_header
>,
10439 line_header_local
.sect_off
= line_offset
;
10440 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10441 line_header_local_hash
= line_header_hash (&line_header_local
);
10442 if (per_objfile
->line_header_hash
!= NULL
)
10444 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10445 &line_header_local
,
10446 line_header_local_hash
, NO_INSERT
);
10448 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10449 is not present in *SLOT (since if there is something in *SLOT then
10450 it will be for a partial_unit). */
10451 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10453 gdb_assert (*slot
!= NULL
);
10454 cu
->line_header
= (struct line_header
*) *slot
;
10459 /* dwarf_decode_line_header does not yet provide sufficient information.
10460 We always have to call also dwarf_decode_lines for it. */
10461 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10465 cu
->line_header
= lh
.release ();
10466 cu
->line_header_die_owner
= die
;
10468 if (per_objfile
->line_header_hash
== NULL
)
10472 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10473 &line_header_local
,
10474 line_header_local_hash
, INSERT
);
10475 gdb_assert (slot
!= NULL
);
10477 if (slot
!= NULL
&& *slot
== NULL
)
10479 /* This newly decoded line number information unit will be owned
10480 by line_header_hash hash table. */
10481 *slot
= cu
->line_header
;
10482 cu
->line_header_die_owner
= NULL
;
10486 /* We cannot free any current entry in (*slot) as that struct line_header
10487 may be already used by multiple CUs. Create only temporary decoded
10488 line_header for this CU - it may happen at most once for each line
10489 number information unit. And if we're not using line_header_hash
10490 then this is what we want as well. */
10491 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10493 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10494 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10499 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10502 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10504 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10505 struct objfile
*objfile
= per_objfile
->objfile
;
10506 struct gdbarch
*gdbarch
= objfile
->arch ();
10507 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10508 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10509 struct attribute
*attr
;
10510 struct die_info
*child_die
;
10511 CORE_ADDR baseaddr
;
10513 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
10514 baseaddr
= objfile
->text_section_offset ();
10516 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10518 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10519 from finish_block. */
10520 if (lowpc
== ((CORE_ADDR
) -1))
10522 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10524 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10526 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10528 gdb_assert (per_objfile
->sym_cu
== nullptr);
10529 scoped_restore restore_sym_cu
10530 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10532 /* Decode line number information if present. We do this before
10533 processing child DIEs, so that the line header table is available
10534 for DW_AT_decl_file. */
10535 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10537 /* Process all dies in compilation unit. */
10538 if (die
->child
!= NULL
)
10540 child_die
= die
->child
;
10541 while (child_die
&& child_die
->tag
)
10543 process_die (child_die
, cu
);
10544 child_die
= child_die
->sibling
;
10547 per_objfile
->sym_cu
= nullptr;
10549 /* Decode macro information, if present. Dwarf 2 macro information
10550 refers to information in the line number info statement program
10551 header, so we can only read it if we've read the header
10553 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10555 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10556 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10558 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10559 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10561 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10565 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10566 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10568 unsigned int macro_offset
= attr
->as_unsigned ();
10570 dwarf_decode_macros (cu
, macro_offset
, 0);
10576 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10578 struct type_unit_group
*tu_group
;
10580 struct attribute
*attr
;
10582 struct signatured_type
*sig_type
;
10584 gdb_assert (per_cu
->is_debug_types
);
10585 sig_type
= (struct signatured_type
*) per_cu
;
10587 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10589 /* If we're using .gdb_index (includes -readnow) then
10590 per_cu->type_unit_group may not have been set up yet. */
10591 if (sig_type
->type_unit_group
== NULL
)
10592 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10593 tu_group
= sig_type
->type_unit_group
;
10595 /* If we've already processed this stmt_list there's no real need to
10596 do it again, we could fake it and just recreate the part we need
10597 (file name,index -> symtab mapping). If data shows this optimization
10598 is useful we can do it then. */
10599 type_unit_group_unshareable
*tug_unshare
10600 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10601 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10603 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10606 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10608 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10609 lh
= dwarf_decode_line_header (line_offset
, this);
10614 start_symtab ("", NULL
, 0);
10617 gdb_assert (tug_unshare
->symtabs
== NULL
);
10618 gdb_assert (m_builder
== nullptr);
10619 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10620 m_builder
.reset (new struct buildsym_compunit
10621 (COMPUNIT_OBJFILE (cust
), "",
10622 COMPUNIT_DIRNAME (cust
),
10623 compunit_language (cust
),
10625 list_in_scope
= get_builder ()->get_file_symbols ();
10630 line_header
= lh
.release ();
10631 line_header_die_owner
= die
;
10635 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10637 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10638 still initializing it, and our caller (a few levels up)
10639 process_full_type_unit still needs to know if this is the first
10642 tug_unshare
->symtabs
10643 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10644 struct symtab
*, line_header
->file_names_size ());
10646 auto &file_names
= line_header
->file_names ();
10647 for (i
= 0; i
< file_names
.size (); ++i
)
10649 file_entry
&fe
= file_names
[i
];
10650 dwarf2_start_subfile (this, fe
.name
,
10651 fe
.include_dir (line_header
));
10652 buildsym_compunit
*b
= get_builder ();
10653 if (b
->get_current_subfile ()->symtab
== NULL
)
10655 /* NOTE: start_subfile will recognize when it's been
10656 passed a file it has already seen. So we can't
10657 assume there's a simple mapping from
10658 cu->line_header->file_names to subfiles, plus
10659 cu->line_header->file_names may contain dups. */
10660 b
->get_current_subfile ()->symtab
10661 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10664 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10665 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10670 gdb_assert (m_builder
== nullptr);
10671 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10672 m_builder
.reset (new struct buildsym_compunit
10673 (COMPUNIT_OBJFILE (cust
), "",
10674 COMPUNIT_DIRNAME (cust
),
10675 compunit_language (cust
),
10677 list_in_scope
= get_builder ()->get_file_symbols ();
10679 auto &file_names
= line_header
->file_names ();
10680 for (i
= 0; i
< file_names
.size (); ++i
)
10682 file_entry
&fe
= file_names
[i
];
10683 fe
.symtab
= tug_unshare
->symtabs
[i
];
10687 /* The main symtab is allocated last. Type units don't have DW_AT_name
10688 so they don't have a "real" (so to speak) symtab anyway.
10689 There is later code that will assign the main symtab to all symbols
10690 that don't have one. We need to handle the case of a symbol with a
10691 missing symtab (DW_AT_decl_file) anyway. */
10694 /* Process DW_TAG_type_unit.
10695 For TUs we want to skip the first top level sibling if it's not the
10696 actual type being defined by this TU. In this case the first top
10697 level sibling is there to provide context only. */
10700 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10702 struct die_info
*child_die
;
10704 prepare_one_comp_unit (cu
, die
, language_minimal
);
10706 /* Initialize (or reinitialize) the machinery for building symtabs.
10707 We do this before processing child DIEs, so that the line header table
10708 is available for DW_AT_decl_file. */
10709 cu
->setup_type_unit_groups (die
);
10711 if (die
->child
!= NULL
)
10713 child_die
= die
->child
;
10714 while (child_die
&& child_die
->tag
)
10716 process_die (child_die
, cu
);
10717 child_die
= child_die
->sibling
;
10724 http://gcc.gnu.org/wiki/DebugFission
10725 http://gcc.gnu.org/wiki/DebugFissionDWP
10727 To simplify handling of both DWO files ("object" files with the DWARF info)
10728 and DWP files (a file with the DWOs packaged up into one file), we treat
10729 DWP files as having a collection of virtual DWO files. */
10732 hash_dwo_file (const void *item
)
10734 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10737 hash
= htab_hash_string (dwo_file
->dwo_name
);
10738 if (dwo_file
->comp_dir
!= NULL
)
10739 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10744 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10746 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10747 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10749 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10751 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10752 return lhs
->comp_dir
== rhs
->comp_dir
;
10753 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10756 /* Allocate a hash table for DWO files. */
10759 allocate_dwo_file_hash_table ()
10761 return htab_up (htab_create_alloc (41,
10764 htab_delete_entry
<dwo_file
>,
10768 /* Lookup DWO file DWO_NAME. */
10771 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10772 const char *dwo_name
,
10773 const char *comp_dir
)
10775 struct dwo_file find_entry
;
10778 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10779 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10781 find_entry
.dwo_name
= dwo_name
;
10782 find_entry
.comp_dir
= comp_dir
;
10783 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10790 hash_dwo_unit (const void *item
)
10792 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10794 /* This drops the top 32 bits of the id, but is ok for a hash. */
10795 return dwo_unit
->signature
;
10799 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10801 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10802 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10804 /* The signature is assumed to be unique within the DWO file.
10805 So while object file CU dwo_id's always have the value zero,
10806 that's OK, assuming each object file DWO file has only one CU,
10807 and that's the rule for now. */
10808 return lhs
->signature
== rhs
->signature
;
10811 /* Allocate a hash table for DWO CUs,TUs.
10812 There is one of these tables for each of CUs,TUs for each DWO file. */
10815 allocate_dwo_unit_table ()
10817 /* Start out with a pretty small number.
10818 Generally DWO files contain only one CU and maybe some TUs. */
10819 return htab_up (htab_create_alloc (3,
10822 NULL
, xcalloc
, xfree
));
10825 /* die_reader_func for create_dwo_cu. */
10828 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10829 const gdb_byte
*info_ptr
,
10830 struct die_info
*comp_unit_die
,
10831 struct dwo_file
*dwo_file
,
10832 struct dwo_unit
*dwo_unit
)
10834 struct dwarf2_cu
*cu
= reader
->cu
;
10835 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10836 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10838 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10839 if (!signature
.has_value ())
10841 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10842 " its dwo_id [in module %s]"),
10843 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10847 dwo_unit
->dwo_file
= dwo_file
;
10848 dwo_unit
->signature
= *signature
;
10849 dwo_unit
->section
= section
;
10850 dwo_unit
->sect_off
= sect_off
;
10851 dwo_unit
->length
= cu
->per_cu
->length
;
10853 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10854 sect_offset_str (sect_off
),
10855 hex_string (dwo_unit
->signature
));
10858 /* Create the dwo_units for the CUs in a DWO_FILE.
10859 Note: This function processes DWO files only, not DWP files. */
10862 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10863 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10864 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10866 struct objfile
*objfile
= per_objfile
->objfile
;
10867 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10868 const gdb_byte
*info_ptr
, *end_ptr
;
10870 section
.read (objfile
);
10871 info_ptr
= section
.buffer
;
10873 if (info_ptr
== NULL
)
10876 dwarf_read_debug_printf ("Reading %s for %s:",
10877 section
.get_name (),
10878 section
.get_file_name ());
10880 end_ptr
= info_ptr
+ section
.size
;
10881 while (info_ptr
< end_ptr
)
10883 struct dwarf2_per_cu_data per_cu
;
10884 struct dwo_unit read_unit
{};
10885 struct dwo_unit
*dwo_unit
;
10887 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10889 per_cu
.per_bfd
= per_bfd
;
10890 per_cu
.is_debug_types
= 0;
10891 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10892 per_cu
.section
= §ion
;
10894 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
10895 if (!reader
.dummy_p
)
10896 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
10897 &dwo_file
, &read_unit
);
10898 info_ptr
+= per_cu
.length
;
10900 // If the unit could not be parsed, skip it.
10901 if (read_unit
.dwo_file
== NULL
)
10904 if (cus_htab
== NULL
)
10905 cus_htab
= allocate_dwo_unit_table ();
10907 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
10909 *dwo_unit
= read_unit
;
10910 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
10911 gdb_assert (slot
!= NULL
);
10914 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
10915 sect_offset dup_sect_off
= dup_cu
->sect_off
;
10917 complaint (_("debug cu entry at offset %s is duplicate to"
10918 " the entry at offset %s, signature %s"),
10919 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
10920 hex_string (dwo_unit
->signature
));
10922 *slot
= (void *)dwo_unit
;
10926 /* DWP file .debug_{cu,tu}_index section format:
10927 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10928 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
10930 DWP Versions 1 & 2 are older, pre-standard format versions. The first
10931 officially standard DWP format was published with DWARF v5 and is called
10932 Version 5. There are no versions 3 or 4.
10936 Both index sections have the same format, and serve to map a 64-bit
10937 signature to a set of section numbers. Each section begins with a header,
10938 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10939 indexes, and a pool of 32-bit section numbers. The index sections will be
10940 aligned at 8-byte boundaries in the file.
10942 The index section header consists of:
10944 V, 32 bit version number
10946 N, 32 bit number of compilation units or type units in the index
10947 M, 32 bit number of slots in the hash table
10949 Numbers are recorded using the byte order of the application binary.
10951 The hash table begins at offset 16 in the section, and consists of an array
10952 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
10953 order of the application binary). Unused slots in the hash table are 0.
10954 (We rely on the extreme unlikeliness of a signature being exactly 0.)
10956 The parallel table begins immediately after the hash table
10957 (at offset 16 + 8 * M from the beginning of the section), and consists of an
10958 array of 32-bit indexes (using the byte order of the application binary),
10959 corresponding 1-1 with slots in the hash table. Each entry in the parallel
10960 table contains a 32-bit index into the pool of section numbers. For unused
10961 hash table slots, the corresponding entry in the parallel table will be 0.
10963 The pool of section numbers begins immediately following the hash table
10964 (at offset 16 + 12 * M from the beginning of the section). The pool of
10965 section numbers consists of an array of 32-bit words (using the byte order
10966 of the application binary). Each item in the array is indexed starting
10967 from 0. The hash table entry provides the index of the first section
10968 number in the set. Additional section numbers in the set follow, and the
10969 set is terminated by a 0 entry (section number 0 is not used in ELF).
10971 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
10972 section must be the first entry in the set, and the .debug_abbrev.dwo must
10973 be the second entry. Other members of the set may follow in any order.
10977 DWP Versions 2 and 5:
10979 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
10980 and the entries in the index tables are now offsets into these sections.
10981 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
10984 Index Section Contents:
10986 Hash Table of Signatures dwp_hash_table.hash_table
10987 Parallel Table of Indices dwp_hash_table.unit_table
10988 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
10989 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
10991 The index section header consists of:
10993 V, 32 bit version number
10994 L, 32 bit number of columns in the table of section offsets
10995 N, 32 bit number of compilation units or type units in the index
10996 M, 32 bit number of slots in the hash table
10998 Numbers are recorded using the byte order of the application binary.
11000 The hash table has the same format as version 1.
11001 The parallel table of indices has the same format as version 1,
11002 except that the entries are origin-1 indices into the table of sections
11003 offsets and the table of section sizes.
11005 The table of offsets begins immediately following the parallel table
11006 (at offset 16 + 12 * M from the beginning of the section). The table is
11007 a two-dimensional array of 32-bit words (using the byte order of the
11008 application binary), with L columns and N+1 rows, in row-major order.
11009 Each row in the array is indexed starting from 0. The first row provides
11010 a key to the remaining rows: each column in this row provides an identifier
11011 for a debug section, and the offsets in the same column of subsequent rows
11012 refer to that section. The section identifiers for Version 2 are:
11014 DW_SECT_INFO 1 .debug_info.dwo
11015 DW_SECT_TYPES 2 .debug_types.dwo
11016 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11017 DW_SECT_LINE 4 .debug_line.dwo
11018 DW_SECT_LOC 5 .debug_loc.dwo
11019 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11020 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11021 DW_SECT_MACRO 8 .debug_macro.dwo
11023 The section identifiers for Version 5 are:
11025 DW_SECT_INFO_V5 1 .debug_info.dwo
11026 DW_SECT_RESERVED_V5 2 --
11027 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11028 DW_SECT_LINE_V5 4 .debug_line.dwo
11029 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11030 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11031 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11032 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11034 The offsets provided by the CU and TU index sections are the base offsets
11035 for the contributions made by each CU or TU to the corresponding section
11036 in the package file. Each CU and TU header contains an abbrev_offset
11037 field, used to find the abbreviations table for that CU or TU within the
11038 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11039 be interpreted as relative to the base offset given in the index section.
11040 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11041 should be interpreted as relative to the base offset for .debug_line.dwo,
11042 and offsets into other debug sections obtained from DWARF attributes should
11043 also be interpreted as relative to the corresponding base offset.
11045 The table of sizes begins immediately following the table of offsets.
11046 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11047 with L columns and N rows, in row-major order. Each row in the array is
11048 indexed starting from 1 (row 0 is shared by the two tables).
11052 Hash table lookup is handled the same in version 1 and 2:
11054 We assume that N and M will not exceed 2^32 - 1.
11055 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11057 Given a 64-bit compilation unit signature or a type signature S, an entry
11058 in the hash table is located as follows:
11060 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11061 the low-order k bits all set to 1.
11063 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11065 3) If the hash table entry at index H matches the signature, use that
11066 entry. If the hash table entry at index H is unused (all zeroes),
11067 terminate the search: the signature is not present in the table.
11069 4) Let H = (H + H') modulo M. Repeat at Step 3.
11071 Because M > N and H' and M are relatively prime, the search is guaranteed
11072 to stop at an unused slot or find the match. */
11074 /* Create a hash table to map DWO IDs to their CU/TU entry in
11075 .debug_{info,types}.dwo in DWP_FILE.
11076 Returns NULL if there isn't one.
11077 Note: This function processes DWP files only, not DWO files. */
11079 static struct dwp_hash_table
*
11080 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11081 struct dwp_file
*dwp_file
, int is_debug_types
)
11083 struct objfile
*objfile
= per_objfile
->objfile
;
11084 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11085 const gdb_byte
*index_ptr
, *index_end
;
11086 struct dwarf2_section_info
*index
;
11087 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11088 struct dwp_hash_table
*htab
;
11090 if (is_debug_types
)
11091 index
= &dwp_file
->sections
.tu_index
;
11093 index
= &dwp_file
->sections
.cu_index
;
11095 if (index
->empty ())
11097 index
->read (objfile
);
11099 index_ptr
= index
->buffer
;
11100 index_end
= index_ptr
+ index
->size
;
11102 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11103 For now it's safe to just read 4 bytes (particularly as it's difficult to
11104 tell if you're dealing with Version 5 before you've read the version). */
11105 version
= read_4_bytes (dbfd
, index_ptr
);
11107 if (version
== 2 || version
== 5)
11108 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11112 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11114 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11117 if (version
!= 1 && version
!= 2 && version
!= 5)
11119 error (_("Dwarf Error: unsupported DWP file version (%s)"
11120 " [in module %s]"),
11121 pulongest (version
), dwp_file
->name
);
11123 if (nr_slots
!= (nr_slots
& -nr_slots
))
11125 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11126 " is not power of 2 [in module %s]"),
11127 pulongest (nr_slots
), dwp_file
->name
);
11130 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11131 htab
->version
= version
;
11132 htab
->nr_columns
= nr_columns
;
11133 htab
->nr_units
= nr_units
;
11134 htab
->nr_slots
= nr_slots
;
11135 htab
->hash_table
= index_ptr
;
11136 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11138 /* Exit early if the table is empty. */
11139 if (nr_slots
== 0 || nr_units
== 0
11140 || (version
== 2 && nr_columns
== 0)
11141 || (version
== 5 && nr_columns
== 0))
11143 /* All must be zero. */
11144 if (nr_slots
!= 0 || nr_units
!= 0
11145 || (version
== 2 && nr_columns
!= 0)
11146 || (version
== 5 && nr_columns
!= 0))
11148 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11149 " all zero [in modules %s]"),
11157 htab
->section_pool
.v1
.indices
=
11158 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11159 /* It's harder to decide whether the section is too small in v1.
11160 V1 is deprecated anyway so we punt. */
11162 else if (version
== 2)
11164 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11165 int *ids
= htab
->section_pool
.v2
.section_ids
;
11166 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11167 /* Reverse map for error checking. */
11168 int ids_seen
[DW_SECT_MAX
+ 1];
11171 if (nr_columns
< 2)
11173 error (_("Dwarf Error: bad DWP hash table, too few columns"
11174 " in section table [in module %s]"),
11177 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11179 error (_("Dwarf Error: bad DWP hash table, too many columns"
11180 " in section table [in module %s]"),
11183 memset (ids
, 255, sizeof_ids
);
11184 memset (ids_seen
, 255, sizeof (ids_seen
));
11185 for (i
= 0; i
< nr_columns
; ++i
)
11187 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11189 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11191 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11192 " in section table [in module %s]"),
11193 id
, dwp_file
->name
);
11195 if (ids_seen
[id
] != -1)
11197 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11198 " id %d in section table [in module %s]"),
11199 id
, dwp_file
->name
);
11204 /* Must have exactly one info or types section. */
11205 if (((ids_seen
[DW_SECT_INFO
] != -1)
11206 + (ids_seen
[DW_SECT_TYPES
] != -1))
11209 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11210 " DWO info/types section [in module %s]"),
11213 /* Must have an abbrev section. */
11214 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11216 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11217 " section [in module %s]"),
11220 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11221 htab
->section_pool
.v2
.sizes
=
11222 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11223 * nr_units
* nr_columns
);
11224 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11225 * nr_units
* nr_columns
))
11228 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11229 " [in module %s]"),
11233 else /* version == 5 */
11235 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11236 int *ids
= htab
->section_pool
.v5
.section_ids
;
11237 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11238 /* Reverse map for error checking. */
11239 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11241 if (nr_columns
< 2)
11243 error (_("Dwarf Error: bad DWP hash table, too few columns"
11244 " in section table [in module %s]"),
11247 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11249 error (_("Dwarf Error: bad DWP hash table, too many columns"
11250 " in section table [in module %s]"),
11253 memset (ids
, 255, sizeof_ids
);
11254 memset (ids_seen
, 255, sizeof (ids_seen
));
11255 for (int i
= 0; i
< nr_columns
; ++i
)
11257 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11259 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11261 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11262 " in section table [in module %s]"),
11263 id
, dwp_file
->name
);
11265 if (ids_seen
[id
] != -1)
11267 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11268 " id %d in section table [in module %s]"),
11269 id
, dwp_file
->name
);
11274 /* Must have seen an info section. */
11275 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11277 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11278 " DWO info/types section [in module %s]"),
11281 /* Must have an abbrev section. */
11282 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11284 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11285 " section [in module %s]"),
11288 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11289 htab
->section_pool
.v5
.sizes
11290 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11291 * nr_units
* nr_columns
);
11292 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11293 * nr_units
* nr_columns
))
11296 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11297 " [in module %s]"),
11305 /* Update SECTIONS with the data from SECTP.
11307 This function is like the other "locate" section routines, but in
11308 this context the sections to read comes from the DWP V1 hash table,
11309 not the full ELF section table.
11311 The result is non-zero for success, or zero if an error was found. */
11314 locate_v1_virtual_dwo_sections (asection
*sectp
,
11315 struct virtual_v1_dwo_sections
*sections
)
11317 const struct dwop_section_names
*names
= &dwop_section_names
;
11319 if (names
->abbrev_dwo
.matches (sectp
->name
))
11321 /* There can be only one. */
11322 if (sections
->abbrev
.s
.section
!= NULL
)
11324 sections
->abbrev
.s
.section
= sectp
;
11325 sections
->abbrev
.size
= bfd_section_size (sectp
);
11327 else if (names
->info_dwo
.matches (sectp
->name
)
11328 || names
->types_dwo
.matches (sectp
->name
))
11330 /* There can be only one. */
11331 if (sections
->info_or_types
.s
.section
!= NULL
)
11333 sections
->info_or_types
.s
.section
= sectp
;
11334 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11336 else if (names
->line_dwo
.matches (sectp
->name
))
11338 /* There can be only one. */
11339 if (sections
->line
.s
.section
!= NULL
)
11341 sections
->line
.s
.section
= sectp
;
11342 sections
->line
.size
= bfd_section_size (sectp
);
11344 else if (names
->loc_dwo
.matches (sectp
->name
))
11346 /* There can be only one. */
11347 if (sections
->loc
.s
.section
!= NULL
)
11349 sections
->loc
.s
.section
= sectp
;
11350 sections
->loc
.size
= bfd_section_size (sectp
);
11352 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11354 /* There can be only one. */
11355 if (sections
->macinfo
.s
.section
!= NULL
)
11357 sections
->macinfo
.s
.section
= sectp
;
11358 sections
->macinfo
.size
= bfd_section_size (sectp
);
11360 else if (names
->macro_dwo
.matches (sectp
->name
))
11362 /* There can be only one. */
11363 if (sections
->macro
.s
.section
!= NULL
)
11365 sections
->macro
.s
.section
= sectp
;
11366 sections
->macro
.size
= bfd_section_size (sectp
);
11368 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11370 /* There can be only one. */
11371 if (sections
->str_offsets
.s
.section
!= NULL
)
11373 sections
->str_offsets
.s
.section
= sectp
;
11374 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11378 /* No other kind of section is valid. */
11385 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11386 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11387 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11388 This is for DWP version 1 files. */
11390 static struct dwo_unit
*
11391 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11392 struct dwp_file
*dwp_file
,
11393 uint32_t unit_index
,
11394 const char *comp_dir
,
11395 ULONGEST signature
, int is_debug_types
)
11397 const struct dwp_hash_table
*dwp_htab
=
11398 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11399 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11400 const char *kind
= is_debug_types
? "TU" : "CU";
11401 struct dwo_file
*dwo_file
;
11402 struct dwo_unit
*dwo_unit
;
11403 struct virtual_v1_dwo_sections sections
;
11404 void **dwo_file_slot
;
11407 gdb_assert (dwp_file
->version
== 1);
11409 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11410 kind
, pulongest (unit_index
), hex_string (signature
),
11413 /* Fetch the sections of this DWO unit.
11414 Put a limit on the number of sections we look for so that bad data
11415 doesn't cause us to loop forever. */
11417 #define MAX_NR_V1_DWO_SECTIONS \
11418 (1 /* .debug_info or .debug_types */ \
11419 + 1 /* .debug_abbrev */ \
11420 + 1 /* .debug_line */ \
11421 + 1 /* .debug_loc */ \
11422 + 1 /* .debug_str_offsets */ \
11423 + 1 /* .debug_macro or .debug_macinfo */ \
11424 + 1 /* trailing zero */)
11426 memset (§ions
, 0, sizeof (sections
));
11428 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11431 uint32_t section_nr
=
11432 read_4_bytes (dbfd
,
11433 dwp_htab
->section_pool
.v1
.indices
11434 + (unit_index
+ i
) * sizeof (uint32_t));
11436 if (section_nr
== 0)
11438 if (section_nr
>= dwp_file
->num_sections
)
11440 error (_("Dwarf Error: bad DWP hash table, section number too large"
11441 " [in module %s]"),
11445 sectp
= dwp_file
->elf_sections
[section_nr
];
11446 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11448 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11449 " [in module %s]"),
11455 || sections
.info_or_types
.empty ()
11456 || sections
.abbrev
.empty ())
11458 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11459 " [in module %s]"),
11462 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11464 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11465 " [in module %s]"),
11469 /* It's easier for the rest of the code if we fake a struct dwo_file and
11470 have dwo_unit "live" in that. At least for now.
11472 The DWP file can be made up of a random collection of CUs and TUs.
11473 However, for each CU + set of TUs that came from the same original DWO
11474 file, we can combine them back into a virtual DWO file to save space
11475 (fewer struct dwo_file objects to allocate). Remember that for really
11476 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11478 std::string virtual_dwo_name
=
11479 string_printf ("virtual-dwo/%d-%d-%d-%d",
11480 sections
.abbrev
.get_id (),
11481 sections
.line
.get_id (),
11482 sections
.loc
.get_id (),
11483 sections
.str_offsets
.get_id ());
11484 /* Can we use an existing virtual DWO file? */
11485 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11487 /* Create one if necessary. */
11488 if (*dwo_file_slot
== NULL
)
11490 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11491 virtual_dwo_name
.c_str ());
11493 dwo_file
= new struct dwo_file
;
11494 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11495 dwo_file
->comp_dir
= comp_dir
;
11496 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11497 dwo_file
->sections
.line
= sections
.line
;
11498 dwo_file
->sections
.loc
= sections
.loc
;
11499 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11500 dwo_file
->sections
.macro
= sections
.macro
;
11501 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11502 /* The "str" section is global to the entire DWP file. */
11503 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11504 /* The info or types section is assigned below to dwo_unit,
11505 there's no need to record it in dwo_file.
11506 Also, we can't simply record type sections in dwo_file because
11507 we record a pointer into the vector in dwo_unit. As we collect more
11508 types we'll grow the vector and eventually have to reallocate space
11509 for it, invalidating all copies of pointers into the previous
11511 *dwo_file_slot
= dwo_file
;
11515 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11516 virtual_dwo_name
.c_str ());
11518 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11521 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11522 dwo_unit
->dwo_file
= dwo_file
;
11523 dwo_unit
->signature
= signature
;
11524 dwo_unit
->section
=
11525 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11526 *dwo_unit
->section
= sections
.info_or_types
;
11527 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11532 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11533 simplify them. Given a pointer to the containing section SECTION, and
11534 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11535 virtual section of just that piece. */
11537 static struct dwarf2_section_info
11538 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11539 struct dwarf2_section_info
*section
,
11540 bfd_size_type offset
, bfd_size_type size
)
11542 struct dwarf2_section_info result
;
11545 gdb_assert (section
!= NULL
);
11546 gdb_assert (!section
->is_virtual
);
11548 memset (&result
, 0, sizeof (result
));
11549 result
.s
.containing_section
= section
;
11550 result
.is_virtual
= true;
11555 sectp
= section
->get_bfd_section ();
11557 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11558 bounds of the real section. This is a pretty-rare event, so just
11559 flag an error (easier) instead of a warning and trying to cope. */
11561 || offset
+ size
> bfd_section_size (sectp
))
11563 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11564 " in section %s [in module %s]"),
11565 sectp
? bfd_section_name (sectp
) : "<unknown>",
11566 objfile_name (per_objfile
->objfile
));
11569 result
.virtual_offset
= offset
;
11570 result
.size
= size
;
11574 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11575 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11576 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11577 This is for DWP version 2 files. */
11579 static struct dwo_unit
*
11580 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11581 struct dwp_file
*dwp_file
,
11582 uint32_t unit_index
,
11583 const char *comp_dir
,
11584 ULONGEST signature
, int is_debug_types
)
11586 const struct dwp_hash_table
*dwp_htab
=
11587 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11588 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11589 const char *kind
= is_debug_types
? "TU" : "CU";
11590 struct dwo_file
*dwo_file
;
11591 struct dwo_unit
*dwo_unit
;
11592 struct virtual_v2_or_v5_dwo_sections sections
;
11593 void **dwo_file_slot
;
11596 gdb_assert (dwp_file
->version
== 2);
11598 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11599 kind
, pulongest (unit_index
), hex_string (signature
),
11602 /* Fetch the section offsets of this DWO unit. */
11604 memset (§ions
, 0, sizeof (sections
));
11606 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11608 uint32_t offset
= read_4_bytes (dbfd
,
11609 dwp_htab
->section_pool
.v2
.offsets
11610 + (((unit_index
- 1) * dwp_htab
->nr_columns
11612 * sizeof (uint32_t)));
11613 uint32_t size
= read_4_bytes (dbfd
,
11614 dwp_htab
->section_pool
.v2
.sizes
11615 + (((unit_index
- 1) * dwp_htab
->nr_columns
11617 * sizeof (uint32_t)));
11619 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11622 case DW_SECT_TYPES
:
11623 sections
.info_or_types_offset
= offset
;
11624 sections
.info_or_types_size
= size
;
11626 case DW_SECT_ABBREV
:
11627 sections
.abbrev_offset
= offset
;
11628 sections
.abbrev_size
= size
;
11631 sections
.line_offset
= offset
;
11632 sections
.line_size
= size
;
11635 sections
.loc_offset
= offset
;
11636 sections
.loc_size
= size
;
11638 case DW_SECT_STR_OFFSETS
:
11639 sections
.str_offsets_offset
= offset
;
11640 sections
.str_offsets_size
= size
;
11642 case DW_SECT_MACINFO
:
11643 sections
.macinfo_offset
= offset
;
11644 sections
.macinfo_size
= size
;
11646 case DW_SECT_MACRO
:
11647 sections
.macro_offset
= offset
;
11648 sections
.macro_size
= size
;
11653 /* It's easier for the rest of the code if we fake a struct dwo_file and
11654 have dwo_unit "live" in that. At least for now.
11656 The DWP file can be made up of a random collection of CUs and TUs.
11657 However, for each CU + set of TUs that came from the same original DWO
11658 file, we can combine them back into a virtual DWO file to save space
11659 (fewer struct dwo_file objects to allocate). Remember that for really
11660 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11662 std::string virtual_dwo_name
=
11663 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11664 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11665 (long) (sections
.line_size
? sections
.line_offset
: 0),
11666 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11667 (long) (sections
.str_offsets_size
11668 ? sections
.str_offsets_offset
: 0));
11669 /* Can we use an existing virtual DWO file? */
11670 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11672 /* Create one if necessary. */
11673 if (*dwo_file_slot
== NULL
)
11675 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11676 virtual_dwo_name
.c_str ());
11678 dwo_file
= new struct dwo_file
;
11679 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11680 dwo_file
->comp_dir
= comp_dir
;
11681 dwo_file
->sections
.abbrev
=
11682 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11683 sections
.abbrev_offset
,
11684 sections
.abbrev_size
);
11685 dwo_file
->sections
.line
=
11686 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11687 sections
.line_offset
,
11688 sections
.line_size
);
11689 dwo_file
->sections
.loc
=
11690 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11691 sections
.loc_offset
, sections
.loc_size
);
11692 dwo_file
->sections
.macinfo
=
11693 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11694 sections
.macinfo_offset
,
11695 sections
.macinfo_size
);
11696 dwo_file
->sections
.macro
=
11697 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11698 sections
.macro_offset
,
11699 sections
.macro_size
);
11700 dwo_file
->sections
.str_offsets
=
11701 create_dwp_v2_or_v5_section (per_objfile
,
11702 &dwp_file
->sections
.str_offsets
,
11703 sections
.str_offsets_offset
,
11704 sections
.str_offsets_size
);
11705 /* The "str" section is global to the entire DWP file. */
11706 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11707 /* The info or types section is assigned below to dwo_unit,
11708 there's no need to record it in dwo_file.
11709 Also, we can't simply record type sections in dwo_file because
11710 we record a pointer into the vector in dwo_unit. As we collect more
11711 types we'll grow the vector and eventually have to reallocate space
11712 for it, invalidating all copies of pointers into the previous
11714 *dwo_file_slot
= dwo_file
;
11718 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11719 virtual_dwo_name
.c_str ());
11721 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11724 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11725 dwo_unit
->dwo_file
= dwo_file
;
11726 dwo_unit
->signature
= signature
;
11727 dwo_unit
->section
=
11728 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11729 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11732 ? &dwp_file
->sections
.types
11733 : &dwp_file
->sections
.info
,
11734 sections
.info_or_types_offset
,
11735 sections
.info_or_types_size
);
11736 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11741 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11742 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11743 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11744 This is for DWP version 5 files. */
11746 static struct dwo_unit
*
11747 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11748 struct dwp_file
*dwp_file
,
11749 uint32_t unit_index
,
11750 const char *comp_dir
,
11751 ULONGEST signature
, int is_debug_types
)
11753 const struct dwp_hash_table
*dwp_htab
11754 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11755 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11756 const char *kind
= is_debug_types
? "TU" : "CU";
11757 struct dwo_file
*dwo_file
;
11758 struct dwo_unit
*dwo_unit
;
11759 struct virtual_v2_or_v5_dwo_sections sections
{};
11760 void **dwo_file_slot
;
11762 gdb_assert (dwp_file
->version
== 5);
11764 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11765 kind
, pulongest (unit_index
), hex_string (signature
),
11768 /* Fetch the section offsets of this DWO unit. */
11770 /* memset (§ions, 0, sizeof (sections)); */
11772 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11774 uint32_t offset
= read_4_bytes (dbfd
,
11775 dwp_htab
->section_pool
.v5
.offsets
11776 + (((unit_index
- 1)
11777 * dwp_htab
->nr_columns
11779 * sizeof (uint32_t)));
11780 uint32_t size
= read_4_bytes (dbfd
,
11781 dwp_htab
->section_pool
.v5
.sizes
11782 + (((unit_index
- 1) * dwp_htab
->nr_columns
11784 * sizeof (uint32_t)));
11786 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11788 case DW_SECT_ABBREV_V5
:
11789 sections
.abbrev_offset
= offset
;
11790 sections
.abbrev_size
= size
;
11792 case DW_SECT_INFO_V5
:
11793 sections
.info_or_types_offset
= offset
;
11794 sections
.info_or_types_size
= size
;
11796 case DW_SECT_LINE_V5
:
11797 sections
.line_offset
= offset
;
11798 sections
.line_size
= size
;
11800 case DW_SECT_LOCLISTS_V5
:
11801 sections
.loclists_offset
= offset
;
11802 sections
.loclists_size
= size
;
11804 case DW_SECT_MACRO_V5
:
11805 sections
.macro_offset
= offset
;
11806 sections
.macro_size
= size
;
11808 case DW_SECT_RNGLISTS_V5
:
11809 sections
.rnglists_offset
= offset
;
11810 sections
.rnglists_size
= size
;
11812 case DW_SECT_STR_OFFSETS_V5
:
11813 sections
.str_offsets_offset
= offset
;
11814 sections
.str_offsets_size
= size
;
11816 case DW_SECT_RESERVED_V5
:
11822 /* It's easier for the rest of the code if we fake a struct dwo_file and
11823 have dwo_unit "live" in that. At least for now.
11825 The DWP file can be made up of a random collection of CUs and TUs.
11826 However, for each CU + set of TUs that came from the same original DWO
11827 file, we can combine them back into a virtual DWO file to save space
11828 (fewer struct dwo_file objects to allocate). Remember that for really
11829 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11831 std::string virtual_dwo_name
=
11832 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11833 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11834 (long) (sections
.line_size
? sections
.line_offset
: 0),
11835 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11836 (long) (sections
.str_offsets_size
11837 ? sections
.str_offsets_offset
: 0),
11838 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11839 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11840 /* Can we use an existing virtual DWO file? */
11841 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11842 virtual_dwo_name
.c_str (),
11844 /* Create one if necessary. */
11845 if (*dwo_file_slot
== NULL
)
11847 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11848 virtual_dwo_name
.c_str ());
11850 dwo_file
= new struct dwo_file
;
11851 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11852 dwo_file
->comp_dir
= comp_dir
;
11853 dwo_file
->sections
.abbrev
=
11854 create_dwp_v2_or_v5_section (per_objfile
,
11855 &dwp_file
->sections
.abbrev
,
11856 sections
.abbrev_offset
,
11857 sections
.abbrev_size
);
11858 dwo_file
->sections
.line
=
11859 create_dwp_v2_or_v5_section (per_objfile
,
11860 &dwp_file
->sections
.line
,
11861 sections
.line_offset
, sections
.line_size
);
11862 dwo_file
->sections
.macro
=
11863 create_dwp_v2_or_v5_section (per_objfile
,
11864 &dwp_file
->sections
.macro
,
11865 sections
.macro_offset
,
11866 sections
.macro_size
);
11867 dwo_file
->sections
.loclists
=
11868 create_dwp_v2_or_v5_section (per_objfile
,
11869 &dwp_file
->sections
.loclists
,
11870 sections
.loclists_offset
,
11871 sections
.loclists_size
);
11872 dwo_file
->sections
.rnglists
=
11873 create_dwp_v2_or_v5_section (per_objfile
,
11874 &dwp_file
->sections
.rnglists
,
11875 sections
.rnglists_offset
,
11876 sections
.rnglists_size
);
11877 dwo_file
->sections
.str_offsets
=
11878 create_dwp_v2_or_v5_section (per_objfile
,
11879 &dwp_file
->sections
.str_offsets
,
11880 sections
.str_offsets_offset
,
11881 sections
.str_offsets_size
);
11882 /* The "str" section is global to the entire DWP file. */
11883 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11884 /* The info or types section is assigned below to dwo_unit,
11885 there's no need to record it in dwo_file.
11886 Also, we can't simply record type sections in dwo_file because
11887 we record a pointer into the vector in dwo_unit. As we collect more
11888 types we'll grow the vector and eventually have to reallocate space
11889 for it, invalidating all copies of pointers into the previous
11891 *dwo_file_slot
= dwo_file
;
11895 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11896 virtual_dwo_name
.c_str ());
11898 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11901 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11902 dwo_unit
->dwo_file
= dwo_file
;
11903 dwo_unit
->signature
= signature
;
11905 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11906 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
11907 &dwp_file
->sections
.info
,
11908 sections
.info_or_types_offset
,
11909 sections
.info_or_types_size
);
11910 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11915 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11916 Returns NULL if the signature isn't found. */
11918 static struct dwo_unit
*
11919 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
11920 struct dwp_file
*dwp_file
, const char *comp_dir
,
11921 ULONGEST signature
, int is_debug_types
)
11923 const struct dwp_hash_table
*dwp_htab
=
11924 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11925 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11926 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11927 uint32_t hash
= signature
& mask
;
11928 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11931 struct dwo_unit find_dwo_cu
;
11933 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11934 find_dwo_cu
.signature
= signature
;
11935 slot
= htab_find_slot (is_debug_types
11936 ? dwp_file
->loaded_tus
.get ()
11937 : dwp_file
->loaded_cus
.get (),
11938 &find_dwo_cu
, INSERT
);
11941 return (struct dwo_unit
*) *slot
;
11943 /* Use a for loop so that we don't loop forever on bad debug info. */
11944 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11946 ULONGEST signature_in_table
;
11948 signature_in_table
=
11949 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11950 if (signature_in_table
== signature
)
11952 uint32_t unit_index
=
11953 read_4_bytes (dbfd
,
11954 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11956 if (dwp_file
->version
== 1)
11958 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
11959 unit_index
, comp_dir
,
11960 signature
, is_debug_types
);
11962 else if (dwp_file
->version
== 2)
11964 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
11965 unit_index
, comp_dir
,
11966 signature
, is_debug_types
);
11968 else /* version == 5 */
11970 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
11971 unit_index
, comp_dir
,
11972 signature
, is_debug_types
);
11974 return (struct dwo_unit
*) *slot
;
11976 if (signature_in_table
== 0)
11978 hash
= (hash
+ hash2
) & mask
;
11981 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11982 " [in module %s]"),
11986 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11987 Open the file specified by FILE_NAME and hand it off to BFD for
11988 preliminary analysis. Return a newly initialized bfd *, which
11989 includes a canonicalized copy of FILE_NAME.
11990 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11991 SEARCH_CWD is true if the current directory is to be searched.
11992 It will be searched before debug-file-directory.
11993 If successful, the file is added to the bfd include table of the
11994 objfile's bfd (see gdb_bfd_record_inclusion).
11995 If unable to find/open the file, return NULL.
11996 NOTE: This function is derived from symfile_bfd_open. */
11998 static gdb_bfd_ref_ptr
11999 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12000 const char *file_name
, int is_dwp
, int search_cwd
)
12003 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12004 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12005 to debug_file_directory. */
12006 const char *search_path
;
12007 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12009 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12012 if (*debug_file_directory
!= '\0')
12014 search_path_holder
.reset (concat (".", dirname_separator_string
,
12015 debug_file_directory
,
12017 search_path
= search_path_holder
.get ();
12023 search_path
= debug_file_directory
;
12025 /* Add the path for the executable binary to the list of search paths. */
12026 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12027 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12028 dirname_separator_string
,
12029 search_path
, nullptr));
12030 search_path
= search_path_holder
.get ();
12032 openp_flags flags
= OPF_RETURN_REALPATH
;
12034 flags
|= OPF_SEARCH_IN_PATH
;
12036 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12037 desc
= openp (search_path
, flags
, file_name
,
12038 O_RDONLY
| O_BINARY
, &absolute_name
);
12042 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12044 if (sym_bfd
== NULL
)
12046 bfd_set_cacheable (sym_bfd
.get (), 1);
12048 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12051 /* Success. Record the bfd as having been included by the objfile's bfd.
12052 This is important because things like demangled_names_hash lives in the
12053 objfile's per_bfd space and may have references to things like symbol
12054 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12055 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12060 /* Try to open DWO file FILE_NAME.
12061 COMP_DIR is the DW_AT_comp_dir attribute.
12062 The result is the bfd handle of the file.
12063 If there is a problem finding or opening the file, return NULL.
12064 Upon success, the canonicalized path of the file is stored in the bfd,
12065 same as symfile_bfd_open. */
12067 static gdb_bfd_ref_ptr
12068 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12069 const char *file_name
, const char *comp_dir
)
12071 if (IS_ABSOLUTE_PATH (file_name
))
12072 return try_open_dwop_file (per_objfile
, file_name
,
12073 0 /*is_dwp*/, 0 /*search_cwd*/);
12075 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12077 if (comp_dir
!= NULL
)
12079 gdb::unique_xmalloc_ptr
<char> path_to_try
12080 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12082 /* NOTE: If comp_dir is a relative path, this will also try the
12083 search path, which seems useful. */
12084 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12086 1 /*search_cwd*/));
12091 /* That didn't work, try debug-file-directory, which, despite its name,
12092 is a list of paths. */
12094 if (*debug_file_directory
== '\0')
12097 return try_open_dwop_file (per_objfile
, file_name
,
12098 0 /*is_dwp*/, 1 /*search_cwd*/);
12101 /* This function is mapped across the sections and remembers the offset and
12102 size of each of the DWO debugging sections we are interested in. */
12105 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12106 dwo_sections
*dwo_sections
)
12108 const struct dwop_section_names
*names
= &dwop_section_names
;
12110 if (names
->abbrev_dwo
.matches (sectp
->name
))
12112 dwo_sections
->abbrev
.s
.section
= sectp
;
12113 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12115 else if (names
->info_dwo
.matches (sectp
->name
))
12117 dwo_sections
->info
.s
.section
= sectp
;
12118 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12120 else if (names
->line_dwo
.matches (sectp
->name
))
12122 dwo_sections
->line
.s
.section
= sectp
;
12123 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12125 else if (names
->loc_dwo
.matches (sectp
->name
))
12127 dwo_sections
->loc
.s
.section
= sectp
;
12128 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12130 else if (names
->loclists_dwo
.matches (sectp
->name
))
12132 dwo_sections
->loclists
.s
.section
= sectp
;
12133 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12135 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12137 dwo_sections
->macinfo
.s
.section
= sectp
;
12138 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12140 else if (names
->macro_dwo
.matches (sectp
->name
))
12142 dwo_sections
->macro
.s
.section
= sectp
;
12143 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12145 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12147 dwo_sections
->rnglists
.s
.section
= sectp
;
12148 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12150 else if (names
->str_dwo
.matches (sectp
->name
))
12152 dwo_sections
->str
.s
.section
= sectp
;
12153 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12155 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12157 dwo_sections
->str_offsets
.s
.section
= sectp
;
12158 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12160 else if (names
->types_dwo
.matches (sectp
->name
))
12162 struct dwarf2_section_info type_section
;
12164 memset (&type_section
, 0, sizeof (type_section
));
12165 type_section
.s
.section
= sectp
;
12166 type_section
.size
= bfd_section_size (sectp
);
12167 dwo_sections
->types
.push_back (type_section
);
12171 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12172 by PER_CU. This is for the non-DWP case.
12173 The result is NULL if DWO_NAME can't be found. */
12175 static struct dwo_file
*
12176 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12177 const char *comp_dir
)
12179 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12181 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12184 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12189 dwo_file_up
dwo_file (new struct dwo_file
);
12190 dwo_file
->dwo_name
= dwo_name
;
12191 dwo_file
->comp_dir
= comp_dir
;
12192 dwo_file
->dbfd
= std::move (dbfd
);
12194 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12195 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12196 &dwo_file
->sections
);
12198 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12201 if (cu
->per_cu
->dwarf_version
< 5)
12203 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12204 dwo_file
->sections
.types
, dwo_file
->tus
);
12208 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12209 &dwo_file
->sections
.info
, dwo_file
->tus
,
12210 rcuh_kind::COMPILE
);
12213 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12215 return dwo_file
.release ();
12218 /* This function is mapped across the sections and remembers the offset and
12219 size of each of the DWP debugging sections common to version 1 and 2 that
12220 we are interested in. */
12223 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12224 dwp_file
*dwp_file
)
12226 const struct dwop_section_names
*names
= &dwop_section_names
;
12227 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12229 /* Record the ELF section number for later lookup: this is what the
12230 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12231 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12232 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12234 /* Look for specific sections that we need. */
12235 if (names
->str_dwo
.matches (sectp
->name
))
12237 dwp_file
->sections
.str
.s
.section
= sectp
;
12238 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12240 else if (names
->cu_index
.matches (sectp
->name
))
12242 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12243 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12245 else if (names
->tu_index
.matches (sectp
->name
))
12247 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12248 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12252 /* This function is mapped across the sections and remembers the offset and
12253 size of each of the DWP version 2 debugging sections that we are interested
12254 in. This is split into a separate function because we don't know if we
12255 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12258 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12260 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12261 const struct dwop_section_names
*names
= &dwop_section_names
;
12262 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12264 /* Record the ELF section number for later lookup: this is what the
12265 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12266 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12267 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12269 /* Look for specific sections that we need. */
12270 if (names
->abbrev_dwo
.matches (sectp
->name
))
12272 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12273 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12275 else if (names
->info_dwo
.matches (sectp
->name
))
12277 dwp_file
->sections
.info
.s
.section
= sectp
;
12278 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12280 else if (names
->line_dwo
.matches (sectp
->name
))
12282 dwp_file
->sections
.line
.s
.section
= sectp
;
12283 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12285 else if (names
->loc_dwo
.matches (sectp
->name
))
12287 dwp_file
->sections
.loc
.s
.section
= sectp
;
12288 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12290 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12292 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12293 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12295 else if (names
->macro_dwo
.matches (sectp
->name
))
12297 dwp_file
->sections
.macro
.s
.section
= sectp
;
12298 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12300 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12302 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12303 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12305 else if (names
->types_dwo
.matches (sectp
->name
))
12307 dwp_file
->sections
.types
.s
.section
= sectp
;
12308 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12312 /* This function is mapped across the sections and remembers the offset and
12313 size of each of the DWP version 5 debugging sections that we are interested
12314 in. This is split into a separate function because we don't know if we
12315 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12318 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12320 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12321 const struct dwop_section_names
*names
= &dwop_section_names
;
12322 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12324 /* Record the ELF section number for later lookup: this is what the
12325 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12326 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12327 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12329 /* Look for specific sections that we need. */
12330 if (names
->abbrev_dwo
.matches (sectp
->name
))
12332 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12333 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12335 else if (names
->info_dwo
.matches (sectp
->name
))
12337 dwp_file
->sections
.info
.s
.section
= sectp
;
12338 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12340 else if (names
->line_dwo
.matches (sectp
->name
))
12342 dwp_file
->sections
.line
.s
.section
= sectp
;
12343 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12345 else if (names
->loclists_dwo
.matches (sectp
->name
))
12347 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12348 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12350 else if (names
->macro_dwo
.matches (sectp
->name
))
12352 dwp_file
->sections
.macro
.s
.section
= sectp
;
12353 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12355 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12357 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12358 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12360 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12362 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12363 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12367 /* Hash function for dwp_file loaded CUs/TUs. */
12370 hash_dwp_loaded_cutus (const void *item
)
12372 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12374 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12375 return dwo_unit
->signature
;
12378 /* Equality function for dwp_file loaded CUs/TUs. */
12381 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12383 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12384 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12386 return dua
->signature
== dub
->signature
;
12389 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12392 allocate_dwp_loaded_cutus_table ()
12394 return htab_up (htab_create_alloc (3,
12395 hash_dwp_loaded_cutus
,
12396 eq_dwp_loaded_cutus
,
12397 NULL
, xcalloc
, xfree
));
12400 /* Try to open DWP file FILE_NAME.
12401 The result is the bfd handle of the file.
12402 If there is a problem finding or opening the file, return NULL.
12403 Upon success, the canonicalized path of the file is stored in the bfd,
12404 same as symfile_bfd_open. */
12406 static gdb_bfd_ref_ptr
12407 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12409 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12411 1 /*search_cwd*/));
12415 /* Work around upstream bug 15652.
12416 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12417 [Whether that's a "bug" is debatable, but it is getting in our way.]
12418 We have no real idea where the dwp file is, because gdb's realpath-ing
12419 of the executable's path may have discarded the needed info.
12420 [IWBN if the dwp file name was recorded in the executable, akin to
12421 .gnu_debuglink, but that doesn't exist yet.]
12422 Strip the directory from FILE_NAME and search again. */
12423 if (*debug_file_directory
!= '\0')
12425 /* Don't implicitly search the current directory here.
12426 If the user wants to search "." to handle this case,
12427 it must be added to debug-file-directory. */
12428 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12436 /* Initialize the use of the DWP file for the current objfile.
12437 By convention the name of the DWP file is ${objfile}.dwp.
12438 The result is NULL if it can't be found. */
12440 static std::unique_ptr
<struct dwp_file
>
12441 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12443 struct objfile
*objfile
= per_objfile
->objfile
;
12445 /* Try to find first .dwp for the binary file before any symbolic links
12448 /* If the objfile is a debug file, find the name of the real binary
12449 file and get the name of dwp file from there. */
12450 std::string dwp_name
;
12451 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12453 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12454 const char *backlink_basename
= lbasename (backlink
->original_name
);
12456 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12459 dwp_name
= objfile
->original_name
;
12461 dwp_name
+= ".dwp";
12463 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12465 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12467 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12468 dwp_name
= objfile_name (objfile
);
12469 dwp_name
+= ".dwp";
12470 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12475 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12477 return std::unique_ptr
<dwp_file
> ();
12480 const char *name
= bfd_get_filename (dbfd
.get ());
12481 std::unique_ptr
<struct dwp_file
> dwp_file
12482 (new struct dwp_file (name
, std::move (dbfd
)));
12484 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12485 dwp_file
->elf_sections
=
12486 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12487 dwp_file
->num_sections
, asection
*);
12489 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12490 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12493 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12495 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12497 /* The DWP file version is stored in the hash table. Oh well. */
12498 if (dwp_file
->cus
&& dwp_file
->tus
12499 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12501 /* Technically speaking, we should try to limp along, but this is
12502 pretty bizarre. We use pulongest here because that's the established
12503 portability solution (e.g, we cannot use %u for uint32_t). */
12504 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12505 " TU version %s [in DWP file %s]"),
12506 pulongest (dwp_file
->cus
->version
),
12507 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12511 dwp_file
->version
= dwp_file
->cus
->version
;
12512 else if (dwp_file
->tus
)
12513 dwp_file
->version
= dwp_file
->tus
->version
;
12515 dwp_file
->version
= 2;
12517 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12519 if (dwp_file
->version
== 2)
12520 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12523 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12527 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12528 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12530 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12531 dwarf_read_debug_printf (" %s CUs, %s TUs",
12532 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12533 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12538 /* Wrapper around open_and_init_dwp_file, only open it once. */
12540 static struct dwp_file
*
12541 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12543 if (!per_objfile
->per_bfd
->dwp_checked
)
12545 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12546 per_objfile
->per_bfd
->dwp_checked
= 1;
12548 return per_objfile
->per_bfd
->dwp_file
.get ();
12551 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12552 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12553 or in the DWP file for the objfile, referenced by THIS_UNIT.
12554 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12555 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12557 This is called, for example, when wanting to read a variable with a
12558 complex location. Therefore we don't want to do file i/o for every call.
12559 Therefore we don't want to look for a DWO file on every call.
12560 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12561 then we check if we've already seen DWO_NAME, and only THEN do we check
12564 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12565 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12567 static struct dwo_unit
*
12568 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12569 ULONGEST signature
, int is_debug_types
)
12571 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12572 struct objfile
*objfile
= per_objfile
->objfile
;
12573 const char *kind
= is_debug_types
? "TU" : "CU";
12574 void **dwo_file_slot
;
12575 struct dwo_file
*dwo_file
;
12576 struct dwp_file
*dwp_file
;
12578 /* First see if there's a DWP file.
12579 If we have a DWP file but didn't find the DWO inside it, don't
12580 look for the original DWO file. It makes gdb behave differently
12581 depending on whether one is debugging in the build tree. */
12583 dwp_file
= get_dwp_file (per_objfile
);
12584 if (dwp_file
!= NULL
)
12586 const struct dwp_hash_table
*dwp_htab
=
12587 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12589 if (dwp_htab
!= NULL
)
12591 struct dwo_unit
*dwo_cutu
=
12592 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12595 if (dwo_cutu
!= NULL
)
12597 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12598 kind
, hex_string (signature
),
12599 host_address_to_string (dwo_cutu
));
12607 /* No DWP file, look for the DWO file. */
12609 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12610 if (*dwo_file_slot
== NULL
)
12612 /* Read in the file and build a table of the CUs/TUs it contains. */
12613 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12615 /* NOTE: This will be NULL if unable to open the file. */
12616 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12618 if (dwo_file
!= NULL
)
12620 struct dwo_unit
*dwo_cutu
= NULL
;
12622 if (is_debug_types
&& dwo_file
->tus
)
12624 struct dwo_unit find_dwo_cutu
;
12626 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12627 find_dwo_cutu
.signature
= signature
;
12629 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12632 else if (!is_debug_types
&& dwo_file
->cus
)
12634 struct dwo_unit find_dwo_cutu
;
12636 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12637 find_dwo_cutu
.signature
= signature
;
12638 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12642 if (dwo_cutu
!= NULL
)
12644 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12645 kind
, dwo_name
, hex_string (signature
),
12646 host_address_to_string (dwo_cutu
));
12653 /* We didn't find it. This could mean a dwo_id mismatch, or
12654 someone deleted the DWO/DWP file, or the search path isn't set up
12655 correctly to find the file. */
12657 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12658 kind
, dwo_name
, hex_string (signature
));
12660 /* This is a warning and not a complaint because it can be caused by
12661 pilot error (e.g., user accidentally deleting the DWO). */
12663 /* Print the name of the DWP file if we looked there, helps the user
12664 better diagnose the problem. */
12665 std::string dwp_text
;
12667 if (dwp_file
!= NULL
)
12668 dwp_text
= string_printf (" [in DWP file %s]",
12669 lbasename (dwp_file
->name
));
12671 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12672 " [in module %s]"),
12673 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12674 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12679 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12680 See lookup_dwo_cutu_unit for details. */
12682 static struct dwo_unit
*
12683 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12684 ULONGEST signature
)
12686 gdb_assert (!cu
->per_cu
->is_debug_types
);
12688 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12691 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12692 See lookup_dwo_cutu_unit for details. */
12694 static struct dwo_unit
*
12695 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12697 gdb_assert (cu
->per_cu
->is_debug_types
);
12699 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12701 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12704 /* Traversal function for queue_and_load_all_dwo_tus. */
12707 queue_and_load_dwo_tu (void **slot
, void *info
)
12709 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12710 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12711 ULONGEST signature
= dwo_unit
->signature
;
12712 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12714 if (sig_type
!= NULL
)
12716 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12717 a real dependency of PER_CU on SIG_TYPE. That is detected later
12718 while processing PER_CU. */
12719 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12721 load_full_type_unit (sig_type
, cu
->per_objfile
);
12722 cu
->per_cu
->imported_symtabs_push (sig_type
);
12728 /* Queue all TUs contained in the DWO of CU to be read in.
12729 The DWO may have the only definition of the type, though it may not be
12730 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12731 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12734 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12736 struct dwo_unit
*dwo_unit
;
12737 struct dwo_file
*dwo_file
;
12739 gdb_assert (cu
!= nullptr);
12740 gdb_assert (!cu
->per_cu
->is_debug_types
);
12741 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12743 dwo_unit
= cu
->dwo_unit
;
12744 gdb_assert (dwo_unit
!= NULL
);
12746 dwo_file
= dwo_unit
->dwo_file
;
12747 if (dwo_file
->tus
!= NULL
)
12748 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12751 /* Read in various DIEs. */
12753 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12754 Inherit only the children of the DW_AT_abstract_origin DIE not being
12755 already referenced by DW_AT_abstract_origin from the children of the
12759 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12761 struct die_info
*child_die
;
12762 sect_offset
*offsetp
;
12763 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12764 struct die_info
*origin_die
;
12765 /* Iterator of the ORIGIN_DIE children. */
12766 struct die_info
*origin_child_die
;
12767 struct attribute
*attr
;
12768 struct dwarf2_cu
*origin_cu
;
12769 struct pending
**origin_previous_list_in_scope
;
12771 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12775 /* Note that following die references may follow to a die in a
12779 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12781 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12783 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12784 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12786 if (die
->tag
!= origin_die
->tag
12787 && !(die
->tag
== DW_TAG_inlined_subroutine
12788 && origin_die
->tag
== DW_TAG_subprogram
))
12789 complaint (_("DIE %s and its abstract origin %s have different tags"),
12790 sect_offset_str (die
->sect_off
),
12791 sect_offset_str (origin_die
->sect_off
));
12793 /* Find if the concrete and abstract trees are structurally the
12794 same. This is a shallow traversal and it is not bullet-proof;
12795 the compiler can trick the debugger into believing that the trees
12796 are isomorphic, whereas they actually are not. However, the
12797 likelyhood of this happening is pretty low, and a full-fledged
12798 check would be an overkill. */
12799 bool are_isomorphic
= true;
12800 die_info
*concrete_child
= die
->child
;
12801 die_info
*abstract_child
= origin_die
->child
;
12802 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12804 if (concrete_child
== nullptr
12805 || abstract_child
== nullptr
12806 || concrete_child
->tag
!= abstract_child
->tag
)
12808 are_isomorphic
= false;
12812 concrete_child
= concrete_child
->sibling
;
12813 abstract_child
= abstract_child
->sibling
;
12816 /* Walk the origin's children in parallel to the concrete children.
12817 This helps match an origin child in case the debug info misses
12818 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12819 origin tree may not have the same tree structure as the concrete
12821 die_info
*corresponding_abstract_child
12822 = are_isomorphic
? origin_die
->child
: nullptr;
12824 std::vector
<sect_offset
> offsets
;
12826 for (child_die
= die
->child
;
12827 child_die
&& child_die
->tag
;
12828 child_die
= child_die
->sibling
)
12830 struct die_info
*child_origin_die
;
12831 struct dwarf2_cu
*child_origin_cu
;
12833 /* We are trying to process concrete instance entries:
12834 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12835 it's not relevant to our analysis here. i.e. detecting DIEs that are
12836 present in the abstract instance but not referenced in the concrete
12838 if (child_die
->tag
== DW_TAG_call_site
12839 || child_die
->tag
== DW_TAG_GNU_call_site
)
12841 if (are_isomorphic
)
12842 corresponding_abstract_child
12843 = corresponding_abstract_child
->sibling
;
12847 /* For each CHILD_DIE, find the corresponding child of
12848 ORIGIN_DIE. If there is more than one layer of
12849 DW_AT_abstract_origin, follow them all; there shouldn't be,
12850 but GCC versions at least through 4.4 generate this (GCC PR
12852 child_origin_die
= child_die
;
12853 child_origin_cu
= cu
;
12856 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12860 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12864 /* If missing DW_AT_abstract_origin, try the corresponding child
12865 of the origin. Clang emits such lexical scopes. */
12866 if (child_origin_die
== child_die
12867 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12869 && child_die
->tag
== DW_TAG_lexical_block
)
12870 child_origin_die
= corresponding_abstract_child
;
12872 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12873 counterpart may exist. */
12874 if (child_origin_die
!= child_die
)
12876 if (child_die
->tag
!= child_origin_die
->tag
12877 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12878 && child_origin_die
->tag
== DW_TAG_subprogram
))
12879 complaint (_("Child DIE %s and its abstract origin %s have "
12881 sect_offset_str (child_die
->sect_off
),
12882 sect_offset_str (child_origin_die
->sect_off
));
12883 if (child_origin_die
->parent
!= origin_die
)
12884 complaint (_("Child DIE %s and its abstract origin %s have "
12885 "different parents"),
12886 sect_offset_str (child_die
->sect_off
),
12887 sect_offset_str (child_origin_die
->sect_off
));
12889 offsets
.push_back (child_origin_die
->sect_off
);
12892 if (are_isomorphic
)
12893 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
12895 std::sort (offsets
.begin (), offsets
.end ());
12896 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12897 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12898 if (offsetp
[-1] == *offsetp
)
12899 complaint (_("Multiple children of DIE %s refer "
12900 "to DIE %s as their abstract origin"),
12901 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12903 offsetp
= offsets
.data ();
12904 origin_child_die
= origin_die
->child
;
12905 while (origin_child_die
&& origin_child_die
->tag
)
12907 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12908 while (offsetp
< offsets_end
12909 && *offsetp
< origin_child_die
->sect_off
)
12911 if (offsetp
>= offsets_end
12912 || *offsetp
> origin_child_die
->sect_off
)
12914 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12915 Check whether we're already processing ORIGIN_CHILD_DIE.
12916 This can happen with mutually referenced abstract_origins.
12918 if (!origin_child_die
->in_process
)
12919 process_die (origin_child_die
, origin_cu
);
12921 origin_child_die
= origin_child_die
->sibling
;
12923 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12925 if (cu
!= origin_cu
)
12926 compute_delayed_physnames (origin_cu
);
12930 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12932 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12933 struct gdbarch
*gdbarch
= objfile
->arch ();
12934 struct context_stack
*newobj
;
12937 struct die_info
*child_die
;
12938 struct attribute
*attr
, *call_line
, *call_file
;
12940 CORE_ADDR baseaddr
;
12941 struct block
*block
;
12942 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12943 std::vector
<struct symbol
*> template_args
;
12944 struct template_symbol
*templ_func
= NULL
;
12948 /* If we do not have call site information, we can't show the
12949 caller of this inlined function. That's too confusing, so
12950 only use the scope for local variables. */
12951 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12952 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12953 if (call_line
== NULL
|| call_file
== NULL
)
12955 read_lexical_block_scope (die
, cu
);
12960 baseaddr
= objfile
->text_section_offset ();
12962 name
= dwarf2_name (die
, cu
);
12964 /* Ignore functions with missing or empty names. These are actually
12965 illegal according to the DWARF standard. */
12968 complaint (_("missing name for subprogram DIE at %s"),
12969 sect_offset_str (die
->sect_off
));
12973 /* Ignore functions with missing or invalid low and high pc attributes. */
12974 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12975 <= PC_BOUNDS_INVALID
)
12977 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12978 if (attr
== nullptr || !attr
->as_boolean ())
12979 complaint (_("cannot get low and high bounds "
12980 "for subprogram DIE at %s"),
12981 sect_offset_str (die
->sect_off
));
12985 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12986 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12988 /* If we have any template arguments, then we must allocate a
12989 different sort of symbol. */
12990 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12992 if (child_die
->tag
== DW_TAG_template_type_param
12993 || child_die
->tag
== DW_TAG_template_value_param
)
12995 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
12996 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13001 gdb_assert (cu
->get_builder () != nullptr);
13002 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13003 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13004 (struct symbol
*) templ_func
);
13006 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13007 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13010 /* If there is a location expression for DW_AT_frame_base, record
13012 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13013 if (attr
!= nullptr)
13014 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13016 /* If there is a location for the static link, record it. */
13017 newobj
->static_link
= NULL
;
13018 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13019 if (attr
!= nullptr)
13021 newobj
->static_link
13022 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13023 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13027 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13029 if (die
->child
!= NULL
)
13031 child_die
= die
->child
;
13032 while (child_die
&& child_die
->tag
)
13034 if (child_die
->tag
== DW_TAG_template_type_param
13035 || child_die
->tag
== DW_TAG_template_value_param
)
13037 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13040 template_args
.push_back (arg
);
13043 process_die (child_die
, cu
);
13044 child_die
= child_die
->sibling
;
13048 inherit_abstract_dies (die
, cu
);
13050 /* If we have a DW_AT_specification, we might need to import using
13051 directives from the context of the specification DIE. See the
13052 comment in determine_prefix. */
13053 if (cu
->per_cu
->lang
== language_cplus
13054 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13056 struct dwarf2_cu
*spec_cu
= cu
;
13057 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13061 child_die
= spec_die
->child
;
13062 while (child_die
&& child_die
->tag
)
13064 if (child_die
->tag
== DW_TAG_imported_module
)
13065 process_die (child_die
, spec_cu
);
13066 child_die
= child_die
->sibling
;
13069 /* In some cases, GCC generates specification DIEs that
13070 themselves contain DW_AT_specification attributes. */
13071 spec_die
= die_specification (spec_die
, &spec_cu
);
13075 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13076 /* Make a block for the local symbols within. */
13077 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13078 cstk
.static_link
, lowpc
, highpc
);
13080 /* For C++, set the block's scope. */
13081 if ((cu
->per_cu
->lang
== language_cplus
13082 || cu
->per_cu
->lang
== language_fortran
13083 || cu
->per_cu
->lang
== language_d
13084 || cu
->per_cu
->lang
== language_rust
)
13085 && cu
->processing_has_namespace_info
)
13086 block_set_scope (block
, determine_prefix (die
, cu
),
13087 &objfile
->objfile_obstack
);
13089 /* If we have address ranges, record them. */
13090 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13092 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13094 /* Attach template arguments to function. */
13095 if (!template_args
.empty ())
13097 gdb_assert (templ_func
!= NULL
);
13099 templ_func
->n_template_arguments
= template_args
.size ();
13100 templ_func
->template_arguments
13101 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13102 templ_func
->n_template_arguments
);
13103 memcpy (templ_func
->template_arguments
,
13104 template_args
.data (),
13105 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13107 /* Make sure that the symtab is set on the new symbols. Even
13108 though they don't appear in this symtab directly, other parts
13109 of gdb assume that symbols do, and this is reasonably
13111 for (symbol
*sym
: template_args
)
13112 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13115 /* In C++, we can have functions nested inside functions (e.g., when
13116 a function declares a class that has methods). This means that
13117 when we finish processing a function scope, we may need to go
13118 back to building a containing block's symbol lists. */
13119 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13120 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13122 /* If we've finished processing a top-level function, subsequent
13123 symbols go in the file symbol list. */
13124 if (cu
->get_builder ()->outermost_context_p ())
13125 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13128 /* Process all the DIES contained within a lexical block scope. Start
13129 a new scope, process the dies, and then close the scope. */
13132 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13134 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13135 struct gdbarch
*gdbarch
= objfile
->arch ();
13136 CORE_ADDR lowpc
, highpc
;
13137 struct die_info
*child_die
;
13138 CORE_ADDR baseaddr
;
13140 baseaddr
= objfile
->text_section_offset ();
13142 /* Ignore blocks with missing or invalid low and high pc attributes. */
13143 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13144 as multiple lexical blocks? Handling children in a sane way would
13145 be nasty. Might be easier to properly extend generic blocks to
13146 describe ranges. */
13147 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13149 case PC_BOUNDS_NOT_PRESENT
:
13150 /* DW_TAG_lexical_block has no attributes, process its children as if
13151 there was no wrapping by that DW_TAG_lexical_block.
13152 GCC does no longer produces such DWARF since GCC r224161. */
13153 for (child_die
= die
->child
;
13154 child_die
!= NULL
&& child_die
->tag
;
13155 child_die
= child_die
->sibling
)
13157 /* We might already be processing this DIE. This can happen
13158 in an unusual circumstance -- where a subroutine A
13159 appears lexically in another subroutine B, but A actually
13160 inlines B. The recursion is broken here, rather than in
13161 inherit_abstract_dies, because it seems better to simply
13162 drop concrete children here. */
13163 if (!child_die
->in_process
)
13164 process_die (child_die
, cu
);
13167 case PC_BOUNDS_INVALID
:
13170 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13171 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13173 cu
->get_builder ()->push_context (0, lowpc
);
13174 if (die
->child
!= NULL
)
13176 child_die
= die
->child
;
13177 while (child_die
&& child_die
->tag
)
13179 process_die (child_die
, cu
);
13180 child_die
= child_die
->sibling
;
13183 inherit_abstract_dies (die
, cu
);
13184 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13186 if (*cu
->get_builder ()->get_local_symbols () != NULL
13187 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13189 struct block
*block
13190 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13191 cstk
.start_addr
, highpc
);
13193 /* Note that recording ranges after traversing children, as we
13194 do here, means that recording a parent's ranges entails
13195 walking across all its children's ranges as they appear in
13196 the address map, which is quadratic behavior.
13198 It would be nicer to record the parent's ranges before
13199 traversing its children, simply overriding whatever you find
13200 there. But since we don't even decide whether to create a
13201 block until after we've traversed its children, that's hard
13203 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13205 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13206 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13209 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13212 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13214 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13215 struct objfile
*objfile
= per_objfile
->objfile
;
13216 struct gdbarch
*gdbarch
= objfile
->arch ();
13217 CORE_ADDR pc
, baseaddr
;
13218 struct attribute
*attr
;
13219 struct call_site
*call_site
, call_site_local
;
13222 struct die_info
*child_die
;
13224 baseaddr
= objfile
->text_section_offset ();
13226 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13229 /* This was a pre-DWARF-5 GNU extension alias
13230 for DW_AT_call_return_pc. */
13231 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13235 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13236 "DIE %s [in module %s]"),
13237 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13240 pc
= attr
->as_address () + baseaddr
;
13241 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13243 if (cu
->call_site_htab
== NULL
)
13244 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13245 NULL
, &objfile
->objfile_obstack
,
13246 hashtab_obstack_allocate
, NULL
);
13247 call_site_local
.pc
= pc
;
13248 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13251 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13252 "DIE %s [in module %s]"),
13253 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13254 objfile_name (objfile
));
13258 /* Count parameters at the caller. */
13261 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13262 child_die
= child_die
->sibling
)
13264 if (child_die
->tag
!= DW_TAG_call_site_parameter
13265 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13267 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13268 "DW_TAG_call_site child DIE %s [in module %s]"),
13269 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13270 objfile_name (objfile
));
13278 = ((struct call_site
*)
13279 obstack_alloc (&objfile
->objfile_obstack
,
13280 sizeof (*call_site
)
13281 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13283 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13284 call_site
->pc
= pc
;
13286 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13287 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13289 struct die_info
*func_die
;
13291 /* Skip also over DW_TAG_inlined_subroutine. */
13292 for (func_die
= die
->parent
;
13293 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13294 && func_die
->tag
!= DW_TAG_subroutine_type
;
13295 func_die
= func_die
->parent
);
13297 /* DW_AT_call_all_calls is a superset
13298 of DW_AT_call_all_tail_calls. */
13300 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13301 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13302 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13303 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13305 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13306 not complete. But keep CALL_SITE for look ups via call_site_htab,
13307 both the initial caller containing the real return address PC and
13308 the final callee containing the current PC of a chain of tail
13309 calls do not need to have the tail call list complete. But any
13310 function candidate for a virtual tail call frame searched via
13311 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13312 determined unambiguously. */
13316 struct type
*func_type
= NULL
;
13319 func_type
= get_die_type (func_die
, cu
);
13320 if (func_type
!= NULL
)
13322 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13324 /* Enlist this call site to the function. */
13325 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13326 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13329 complaint (_("Cannot find function owning DW_TAG_call_site "
13330 "DIE %s [in module %s]"),
13331 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13335 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13337 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13339 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13342 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13343 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13345 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13346 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13347 /* Keep NULL DWARF_BLOCK. */;
13348 else if (attr
->form_is_block ())
13350 struct dwarf2_locexpr_baton
*dlbaton
;
13351 struct dwarf_block
*block
= attr
->as_block ();
13353 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13354 dlbaton
->data
= block
->data
;
13355 dlbaton
->size
= block
->size
;
13356 dlbaton
->per_objfile
= per_objfile
;
13357 dlbaton
->per_cu
= cu
->per_cu
;
13359 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13361 else if (attr
->form_is_ref ())
13363 struct dwarf2_cu
*target_cu
= cu
;
13364 struct die_info
*target_die
;
13366 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13367 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13368 if (die_is_declaration (target_die
, target_cu
))
13370 const char *target_physname
;
13372 /* Prefer the mangled name; otherwise compute the demangled one. */
13373 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13374 if (target_physname
== NULL
)
13375 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13376 if (target_physname
== NULL
)
13377 complaint (_("DW_AT_call_target target DIE has invalid "
13378 "physname, for referencing DIE %s [in module %s]"),
13379 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13381 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13387 /* DW_AT_entry_pc should be preferred. */
13388 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13389 <= PC_BOUNDS_INVALID
)
13390 complaint (_("DW_AT_call_target target DIE has invalid "
13391 "low pc, for referencing DIE %s [in module %s]"),
13392 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13395 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13396 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13401 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13402 "block nor reference, for DIE %s [in module %s]"),
13403 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13405 call_site
->per_cu
= cu
->per_cu
;
13406 call_site
->per_objfile
= per_objfile
;
13408 for (child_die
= die
->child
;
13409 child_die
&& child_die
->tag
;
13410 child_die
= child_die
->sibling
)
13412 struct call_site_parameter
*parameter
;
13413 struct attribute
*loc
, *origin
;
13415 if (child_die
->tag
!= DW_TAG_call_site_parameter
13416 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13418 /* Already printed the complaint above. */
13422 gdb_assert (call_site
->parameter_count
< nparams
);
13423 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13425 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13426 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13427 register is contained in DW_AT_call_value. */
13429 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13430 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13431 if (origin
== NULL
)
13433 /* This was a pre-DWARF-5 GNU extension alias
13434 for DW_AT_call_parameter. */
13435 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13437 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13439 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13441 sect_offset sect_off
= origin
->get_ref_die_offset ();
13442 if (!cu
->header
.offset_in_cu_p (sect_off
))
13444 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13445 binding can be done only inside one CU. Such referenced DIE
13446 therefore cannot be even moved to DW_TAG_partial_unit. */
13447 complaint (_("DW_AT_call_parameter offset is not in CU for "
13448 "DW_TAG_call_site child DIE %s [in module %s]"),
13449 sect_offset_str (child_die
->sect_off
),
13450 objfile_name (objfile
));
13453 parameter
->u
.param_cu_off
13454 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13456 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13458 complaint (_("No DW_FORM_block* DW_AT_location for "
13459 "DW_TAG_call_site child DIE %s [in module %s]"),
13460 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13465 struct dwarf_block
*block
= loc
->as_block ();
13467 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13468 (block
->data
, &block
->data
[block
->size
]);
13469 if (parameter
->u
.dwarf_reg
!= -1)
13470 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13471 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13472 &block
->data
[block
->size
],
13473 ¶meter
->u
.fb_offset
))
13474 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13477 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13478 "for DW_FORM_block* DW_AT_location is supported for "
13479 "DW_TAG_call_site child DIE %s "
13481 sect_offset_str (child_die
->sect_off
),
13482 objfile_name (objfile
));
13487 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13489 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13490 if (attr
== NULL
|| !attr
->form_is_block ())
13492 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13493 "DW_TAG_call_site child DIE %s [in module %s]"),
13494 sect_offset_str (child_die
->sect_off
),
13495 objfile_name (objfile
));
13499 struct dwarf_block
*block
= attr
->as_block ();
13500 parameter
->value
= block
->data
;
13501 parameter
->value_size
= block
->size
;
13503 /* Parameters are not pre-cleared by memset above. */
13504 parameter
->data_value
= NULL
;
13505 parameter
->data_value_size
= 0;
13506 call_site
->parameter_count
++;
13508 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13510 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13511 if (attr
!= nullptr)
13513 if (!attr
->form_is_block ())
13514 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13515 "DW_TAG_call_site child DIE %s [in module %s]"),
13516 sect_offset_str (child_die
->sect_off
),
13517 objfile_name (objfile
));
13520 block
= attr
->as_block ();
13521 parameter
->data_value
= block
->data
;
13522 parameter
->data_value_size
= block
->size
;
13528 /* Helper function for read_variable. If DIE represents a virtual
13529 table, then return the type of the concrete object that is
13530 associated with the virtual table. Otherwise, return NULL. */
13532 static struct type
*
13533 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13535 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13539 /* Find the type DIE. */
13540 struct die_info
*type_die
= NULL
;
13541 struct dwarf2_cu
*type_cu
= cu
;
13543 if (attr
->form_is_ref ())
13544 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13545 if (type_die
== NULL
)
13548 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13550 return die_containing_type (type_die
, type_cu
);
13553 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13556 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13558 struct rust_vtable_symbol
*storage
= NULL
;
13560 if (cu
->per_cu
->lang
== language_rust
)
13562 struct type
*containing_type
= rust_containing_type (die
, cu
);
13564 if (containing_type
!= NULL
)
13566 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13568 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13569 storage
->concrete_type
= containing_type
;
13570 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13574 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13575 struct attribute
*abstract_origin
13576 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13577 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13578 if (res
== NULL
&& loc
&& abstract_origin
)
13580 /* We have a variable without a name, but with a location and an abstract
13581 origin. This may be a concrete instance of an abstract variable
13582 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13584 struct dwarf2_cu
*origin_cu
= cu
;
13585 struct die_info
*origin_die
13586 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13587 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13588 per_objfile
->per_bfd
->abstract_to_concrete
13589 [origin_die
->sect_off
].push_back (die
->sect_off
);
13593 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13594 reading .debug_rnglists.
13595 Callback's type should be:
13596 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13597 Return true if the attributes are present and valid, otherwise,
13600 template <typename Callback
>
13602 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13603 dwarf_tag tag
, Callback
&&callback
)
13605 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13606 struct objfile
*objfile
= per_objfile
->objfile
;
13607 bfd
*obfd
= objfile
->obfd
;
13608 /* Base address selection entry. */
13609 gdb::optional
<CORE_ADDR
> base
;
13610 const gdb_byte
*buffer
;
13611 CORE_ADDR baseaddr
;
13612 bool overflow
= false;
13613 ULONGEST addr_index
;
13614 struct dwarf2_section_info
*rnglists_section
;
13616 base
= cu
->base_address
;
13617 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13618 rnglists_section
->read (objfile
);
13620 if (offset
>= rnglists_section
->size
)
13622 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13626 buffer
= rnglists_section
->buffer
+ offset
;
13628 baseaddr
= objfile
->text_section_offset ();
13632 /* Initialize it due to a false compiler warning. */
13633 CORE_ADDR range_beginning
= 0, range_end
= 0;
13634 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13635 + rnglists_section
->size
);
13636 unsigned int bytes_read
;
13638 if (buffer
== buf_end
)
13643 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13646 case DW_RLE_end_of_list
:
13648 case DW_RLE_base_address
:
13649 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13654 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13655 buffer
+= bytes_read
;
13657 case DW_RLE_base_addressx
:
13658 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13659 buffer
+= bytes_read
;
13660 base
= read_addr_index (cu
, addr_index
);
13662 case DW_RLE_start_length
:
13663 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13668 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13670 buffer
+= bytes_read
;
13671 range_end
= (range_beginning
13672 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13673 buffer
+= bytes_read
;
13674 if (buffer
> buf_end
)
13680 case DW_RLE_startx_length
:
13681 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13682 buffer
+= bytes_read
;
13683 range_beginning
= read_addr_index (cu
, addr_index
);
13684 if (buffer
> buf_end
)
13689 range_end
= (range_beginning
13690 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13691 buffer
+= bytes_read
;
13693 case DW_RLE_offset_pair
:
13694 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13695 buffer
+= bytes_read
;
13696 if (buffer
> buf_end
)
13701 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13702 buffer
+= bytes_read
;
13703 if (buffer
> buf_end
)
13709 case DW_RLE_start_end
:
13710 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13715 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13717 buffer
+= bytes_read
;
13718 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13719 buffer
+= bytes_read
;
13721 case DW_RLE_startx_endx
:
13722 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13723 buffer
+= bytes_read
;
13724 range_beginning
= read_addr_index (cu
, addr_index
);
13725 if (buffer
> buf_end
)
13730 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13731 buffer
+= bytes_read
;
13732 range_end
= read_addr_index (cu
, addr_index
);
13735 complaint (_("Invalid .debug_rnglists data (no base address)"));
13738 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13740 if (rlet
== DW_RLE_base_address
)
13743 if (range_beginning
> range_end
)
13745 /* Inverted range entries are invalid. */
13746 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13750 /* Empty range entries have no effect. */
13751 if (range_beginning
== range_end
)
13754 /* Only DW_RLE_offset_pair needs the base address added. */
13755 if (rlet
== DW_RLE_offset_pair
)
13757 if (!base
.has_value ())
13759 /* We have no valid base address for the DW_RLE_offset_pair. */
13760 complaint (_("Invalid .debug_rnglists data (no base address for "
13761 "DW_RLE_offset_pair)"));
13765 range_beginning
+= *base
;
13766 range_end
+= *base
;
13769 /* A not-uncommon case of bad debug info.
13770 Don't pollute the addrmap with bad data. */
13771 if (range_beginning
+ baseaddr
== 0
13772 && !per_objfile
->per_bfd
->has_section_at_zero
)
13774 complaint (_(".debug_rnglists entry has start address of zero"
13775 " [in module %s]"), objfile_name (objfile
));
13779 callback (range_beginning
, range_end
);
13784 complaint (_("Offset %d is not terminated "
13785 "for DW_AT_ranges attribute"),
13793 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13794 Callback's type should be:
13795 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13796 Return 1 if the attributes are present and valid, otherwise, return 0. */
13798 template <typename Callback
>
13800 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13801 Callback
&&callback
)
13803 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13804 struct objfile
*objfile
= per_objfile
->objfile
;
13805 struct comp_unit_head
*cu_header
= &cu
->header
;
13806 bfd
*obfd
= objfile
->obfd
;
13807 unsigned int addr_size
= cu_header
->addr_size
;
13808 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13809 /* Base address selection entry. */
13810 gdb::optional
<CORE_ADDR
> base
;
13811 unsigned int dummy
;
13812 const gdb_byte
*buffer
;
13813 CORE_ADDR baseaddr
;
13815 if (cu_header
->version
>= 5)
13816 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13818 base
= cu
->base_address
;
13820 per_objfile
->per_bfd
->ranges
.read (objfile
);
13821 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13823 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13827 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13829 baseaddr
= objfile
->text_section_offset ();
13833 CORE_ADDR range_beginning
, range_end
;
13835 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13836 buffer
+= addr_size
;
13837 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13838 buffer
+= addr_size
;
13839 offset
+= 2 * addr_size
;
13841 /* An end of list marker is a pair of zero addresses. */
13842 if (range_beginning
== 0 && range_end
== 0)
13843 /* Found the end of list entry. */
13846 /* Each base address selection entry is a pair of 2 values.
13847 The first is the largest possible address, the second is
13848 the base address. Check for a base address here. */
13849 if ((range_beginning
& mask
) == mask
)
13851 /* If we found the largest possible address, then we already
13852 have the base address in range_end. */
13857 if (!base
.has_value ())
13859 /* We have no valid base address for the ranges
13861 complaint (_("Invalid .debug_ranges data (no base address)"));
13865 if (range_beginning
> range_end
)
13867 /* Inverted range entries are invalid. */
13868 complaint (_("Invalid .debug_ranges data (inverted range)"));
13872 /* Empty range entries have no effect. */
13873 if (range_beginning
== range_end
)
13876 range_beginning
+= *base
;
13877 range_end
+= *base
;
13879 /* A not-uncommon case of bad debug info.
13880 Don't pollute the addrmap with bad data. */
13881 if (range_beginning
+ baseaddr
== 0
13882 && !per_objfile
->per_bfd
->has_section_at_zero
)
13884 complaint (_(".debug_ranges entry has start address of zero"
13885 " [in module %s]"), objfile_name (objfile
));
13889 callback (range_beginning
, range_end
);
13895 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13896 Return 1 if the attributes are present and valid, otherwise, return 0.
13897 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
13900 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13901 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13902 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
13904 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13905 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
13906 struct gdbarch
*gdbarch
= objfile
->arch ();
13907 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13910 CORE_ADDR high
= 0;
13913 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
13914 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13916 if (ranges_pst
!= NULL
)
13921 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13922 range_beginning
+ baseaddr
)
13924 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13925 range_end
+ baseaddr
)
13927 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
13928 lowpc
, highpc
- 1, ranges_pst
);
13931 /* FIXME: This is recording everything as a low-high
13932 segment of consecutive addresses. We should have a
13933 data structure for discontiguous block ranges
13937 low
= range_beginning
;
13943 if (range_beginning
< low
)
13944 low
= range_beginning
;
13945 if (range_end
> high
)
13953 /* If the first entry is an end-of-list marker, the range
13954 describes an empty scope, i.e. no instructions. */
13960 *high_return
= high
;
13964 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13965 definition for the return value. *LOWPC and *HIGHPC are set iff
13966 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13968 static enum pc_bounds_kind
13969 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13970 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13971 dwarf2_psymtab
*pst
)
13973 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13974 struct attribute
*attr
;
13975 struct attribute
*attr_high
;
13977 CORE_ADDR high
= 0;
13978 enum pc_bounds_kind ret
;
13980 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13983 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13984 if (attr
!= nullptr)
13986 low
= attr
->as_address ();
13987 high
= attr_high
->as_address ();
13988 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13992 /* Found high w/o low attribute. */
13993 return PC_BOUNDS_INVALID
;
13995 /* Found consecutive range of addresses. */
13996 ret
= PC_BOUNDS_HIGH_LOW
;
14000 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14001 if (attr
!= nullptr && attr
->form_is_unsigned ())
14003 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14004 on DWARF version). */
14005 ULONGEST ranges_offset
= attr
->as_unsigned ();
14007 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14009 if (die
->tag
!= DW_TAG_compile_unit
)
14010 ranges_offset
+= cu
->gnu_ranges_base
;
14012 /* Value of the DW_AT_ranges attribute is the offset in the
14013 .debug_ranges section. */
14014 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14016 return PC_BOUNDS_INVALID
;
14017 /* Found discontinuous range of addresses. */
14018 ret
= PC_BOUNDS_RANGES
;
14021 return PC_BOUNDS_NOT_PRESENT
;
14024 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14026 return PC_BOUNDS_INVALID
;
14028 /* When using the GNU linker, .gnu.linkonce. sections are used to
14029 eliminate duplicate copies of functions and vtables and such.
14030 The linker will arbitrarily choose one and discard the others.
14031 The AT_*_pc values for such functions refer to local labels in
14032 these sections. If the section from that file was discarded, the
14033 labels are not in the output, so the relocs get a value of 0.
14034 If this is a discarded function, mark the pc bounds as invalid,
14035 so that GDB will ignore it. */
14036 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14037 return PC_BOUNDS_INVALID
;
14045 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14046 its low and high PC addresses. Do nothing if these addresses could not
14047 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14048 and HIGHPC to the high address if greater than HIGHPC. */
14051 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14052 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14053 struct dwarf2_cu
*cu
)
14055 CORE_ADDR low
, high
;
14056 struct die_info
*child
= die
->child
;
14058 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14060 *lowpc
= std::min (*lowpc
, low
);
14061 *highpc
= std::max (*highpc
, high
);
14064 /* If the language does not allow nested subprograms (either inside
14065 subprograms or lexical blocks), we're done. */
14066 if (cu
->per_cu
->lang
!= language_ada
)
14069 /* Check all the children of the given DIE. If it contains nested
14070 subprograms, then check their pc bounds. Likewise, we need to
14071 check lexical blocks as well, as they may also contain subprogram
14073 while (child
&& child
->tag
)
14075 if (child
->tag
== DW_TAG_subprogram
14076 || child
->tag
== DW_TAG_lexical_block
)
14077 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14078 child
= child
->sibling
;
14082 /* Get the low and high pc's represented by the scope DIE, and store
14083 them in *LOWPC and *HIGHPC. If the correct values can't be
14084 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14087 get_scope_pc_bounds (struct die_info
*die
,
14088 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14089 struct dwarf2_cu
*cu
)
14091 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14092 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14093 CORE_ADDR current_low
, current_high
;
14095 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14096 >= PC_BOUNDS_RANGES
)
14098 best_low
= current_low
;
14099 best_high
= current_high
;
14103 struct die_info
*child
= die
->child
;
14105 while (child
&& child
->tag
)
14107 switch (child
->tag
) {
14108 case DW_TAG_subprogram
:
14109 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14111 case DW_TAG_namespace
:
14112 case DW_TAG_module
:
14113 /* FIXME: carlton/2004-01-16: Should we do this for
14114 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14115 that current GCC's always emit the DIEs corresponding
14116 to definitions of methods of classes as children of a
14117 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14118 the DIEs giving the declarations, which could be
14119 anywhere). But I don't see any reason why the
14120 standards says that they have to be there. */
14121 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14123 if (current_low
!= ((CORE_ADDR
) -1))
14125 best_low
= std::min (best_low
, current_low
);
14126 best_high
= std::max (best_high
, current_high
);
14134 child
= child
->sibling
;
14139 *highpc
= best_high
;
14142 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14146 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14147 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14149 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14150 struct gdbarch
*gdbarch
= objfile
->arch ();
14151 struct attribute
*attr
;
14152 struct attribute
*attr_high
;
14154 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14157 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14158 if (attr
!= nullptr)
14160 CORE_ADDR low
= attr
->as_address ();
14161 CORE_ADDR high
= attr_high
->as_address ();
14163 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14166 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14167 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14168 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14172 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14173 if (attr
!= nullptr && attr
->form_is_unsigned ())
14175 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14176 on DWARF version). */
14177 ULONGEST ranges_offset
= attr
->as_unsigned ();
14179 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14181 if (die
->tag
!= DW_TAG_compile_unit
)
14182 ranges_offset
+= cu
->gnu_ranges_base
;
14184 std::vector
<blockrange
> blockvec
;
14185 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14186 [&] (CORE_ADDR start
, CORE_ADDR end
)
14190 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14191 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14192 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14193 blockvec
.emplace_back (start
, end
);
14196 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14200 /* Check whether the producer field indicates either of GCC < 4.6, or the
14201 Intel C/C++ compiler, and cache the result in CU. */
14204 check_producer (struct dwarf2_cu
*cu
)
14208 if (cu
->producer
== NULL
)
14210 /* For unknown compilers expect their behavior is DWARF version
14213 GCC started to support .debug_types sections by -gdwarf-4 since
14214 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14215 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14216 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14217 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14219 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14221 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14222 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14224 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14226 cu
->producer_is_icc
= true;
14227 cu
->producer_is_icc_lt_14
= major
< 14;
14229 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14230 cu
->producer_is_codewarrior
= true;
14233 /* For other non-GCC compilers, expect their behavior is DWARF version
14237 cu
->checked_producer
= true;
14240 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14241 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14242 during 4.6.0 experimental. */
14245 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14247 if (!cu
->checked_producer
)
14248 check_producer (cu
);
14250 return cu
->producer_is_gxx_lt_4_6
;
14254 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14255 with incorrect is_stmt attributes. */
14258 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14260 if (!cu
->checked_producer
)
14261 check_producer (cu
);
14263 return cu
->producer_is_codewarrior
;
14266 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14267 If that attribute is not available, return the appropriate
14270 static enum dwarf_access_attribute
14271 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14273 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14274 if (attr
!= nullptr)
14276 LONGEST value
= attr
->constant_value (-1);
14277 if (value
== DW_ACCESS_public
14278 || value
== DW_ACCESS_protected
14279 || value
== DW_ACCESS_private
)
14280 return (dwarf_access_attribute
) value
;
14281 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14285 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14287 /* The default DWARF 2 accessibility for members is public, the default
14288 accessibility for inheritance is private. */
14290 if (die
->tag
!= DW_TAG_inheritance
)
14291 return DW_ACCESS_public
;
14293 return DW_ACCESS_private
;
14297 /* DWARF 3+ defines the default accessibility a different way. The same
14298 rules apply now for DW_TAG_inheritance as for the members and it only
14299 depends on the container kind. */
14301 if (die
->parent
->tag
== DW_TAG_class_type
)
14302 return DW_ACCESS_private
;
14304 return DW_ACCESS_public
;
14308 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14309 offset. If the attribute was not found return 0, otherwise return
14310 1. If it was found but could not properly be handled, set *OFFSET
14314 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14317 struct attribute
*attr
;
14319 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14324 /* Note that we do not check for a section offset first here.
14325 This is because DW_AT_data_member_location is new in DWARF 4,
14326 so if we see it, we can assume that a constant form is really
14327 a constant and not a section offset. */
14328 if (attr
->form_is_constant ())
14329 *offset
= attr
->constant_value (0);
14330 else if (attr
->form_is_section_offset ())
14331 dwarf2_complex_location_expr_complaint ();
14332 else if (attr
->form_is_block ())
14333 *offset
= decode_locdesc (attr
->as_block (), cu
);
14335 dwarf2_complex_location_expr_complaint ();
14343 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14346 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14347 struct field
*field
)
14349 struct attribute
*attr
;
14351 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14354 if (attr
->form_is_constant ())
14356 LONGEST offset
= attr
->constant_value (0);
14357 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14359 else if (attr
->form_is_section_offset ())
14360 dwarf2_complex_location_expr_complaint ();
14361 else if (attr
->form_is_block ())
14364 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14366 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14369 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14370 struct objfile
*objfile
= per_objfile
->objfile
;
14371 struct dwarf2_locexpr_baton
*dlbaton
14372 = XOBNEW (&objfile
->objfile_obstack
,
14373 struct dwarf2_locexpr_baton
);
14374 dlbaton
->data
= attr
->as_block ()->data
;
14375 dlbaton
->size
= attr
->as_block ()->size
;
14376 /* When using this baton, we want to compute the address
14377 of the field, not the value. This is why
14378 is_reference is set to false here. */
14379 dlbaton
->is_reference
= false;
14380 dlbaton
->per_objfile
= per_objfile
;
14381 dlbaton
->per_cu
= cu
->per_cu
;
14383 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14387 dwarf2_complex_location_expr_complaint ();
14391 /* Add an aggregate field to the field list. */
14394 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14395 struct dwarf2_cu
*cu
)
14397 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14398 struct gdbarch
*gdbarch
= objfile
->arch ();
14399 struct nextfield
*new_field
;
14400 struct attribute
*attr
;
14402 const char *fieldname
= "";
14404 if (die
->tag
== DW_TAG_inheritance
)
14406 fip
->baseclasses
.emplace_back ();
14407 new_field
= &fip
->baseclasses
.back ();
14411 fip
->fields
.emplace_back ();
14412 new_field
= &fip
->fields
.back ();
14415 new_field
->offset
= die
->sect_off
;
14417 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14418 if (new_field
->accessibility
!= DW_ACCESS_public
)
14419 fip
->non_public_fields
= true;
14421 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14422 if (attr
!= nullptr)
14423 new_field
->virtuality
= attr
->as_virtuality ();
14425 new_field
->virtuality
= DW_VIRTUALITY_none
;
14427 fp
= &new_field
->field
;
14429 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14431 /* Data member other than a C++ static data member. */
14433 /* Get type of field. */
14434 fp
->set_type (die_type (die
, cu
));
14436 SET_FIELD_BITPOS (*fp
, 0);
14438 /* Get bit size of field (zero if none). */
14439 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14440 if (attr
!= nullptr)
14442 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14446 FIELD_BITSIZE (*fp
) = 0;
14449 /* Get bit offset of field. */
14450 handle_data_member_location (die
, cu
, fp
);
14451 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14452 if (attr
!= nullptr && attr
->form_is_constant ())
14454 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14456 /* For big endian bits, the DW_AT_bit_offset gives the
14457 additional bit offset from the MSB of the containing
14458 anonymous object to the MSB of the field. We don't
14459 have to do anything special since we don't need to
14460 know the size of the anonymous object. */
14461 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14462 + attr
->constant_value (0)));
14466 /* For little endian bits, compute the bit offset to the
14467 MSB of the anonymous object, subtract off the number of
14468 bits from the MSB of the field to the MSB of the
14469 object, and then subtract off the number of bits of
14470 the field itself. The result is the bit offset of
14471 the LSB of the field. */
14472 int anonymous_size
;
14473 int bit_offset
= attr
->constant_value (0);
14475 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14476 if (attr
!= nullptr && attr
->form_is_constant ())
14478 /* The size of the anonymous object containing
14479 the bit field is explicit, so use the
14480 indicated size (in bytes). */
14481 anonymous_size
= attr
->constant_value (0);
14485 /* The size of the anonymous object containing
14486 the bit field must be inferred from the type
14487 attribute of the data member containing the
14489 anonymous_size
= TYPE_LENGTH (fp
->type ());
14491 SET_FIELD_BITPOS (*fp
,
14492 (FIELD_BITPOS (*fp
)
14493 + anonymous_size
* bits_per_byte
14494 - bit_offset
- FIELD_BITSIZE (*fp
)));
14497 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14499 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14500 + attr
->constant_value (0)));
14502 /* Get name of field. */
14503 fieldname
= dwarf2_name (die
, cu
);
14504 if (fieldname
== NULL
)
14507 /* The name is already allocated along with this objfile, so we don't
14508 need to duplicate it for the type. */
14509 fp
->name
= fieldname
;
14511 /* Change accessibility for artificial fields (e.g. virtual table
14512 pointer or virtual base class pointer) to private. */
14513 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14515 FIELD_ARTIFICIAL (*fp
) = 1;
14516 new_field
->accessibility
= DW_ACCESS_private
;
14517 fip
->non_public_fields
= true;
14520 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14522 /* C++ static member. */
14524 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14525 is a declaration, but all versions of G++ as of this writing
14526 (so through at least 3.2.1) incorrectly generate
14527 DW_TAG_variable tags. */
14529 const char *physname
;
14531 /* Get name of field. */
14532 fieldname
= dwarf2_name (die
, cu
);
14533 if (fieldname
== NULL
)
14536 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14538 /* Only create a symbol if this is an external value.
14539 new_symbol checks this and puts the value in the global symbol
14540 table, which we want. If it is not external, new_symbol
14541 will try to put the value in cu->list_in_scope which is wrong. */
14542 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14544 /* A static const member, not much different than an enum as far as
14545 we're concerned, except that we can support more types. */
14546 new_symbol (die
, NULL
, cu
);
14549 /* Get physical name. */
14550 physname
= dwarf2_physname (fieldname
, die
, cu
);
14552 /* The name is already allocated along with this objfile, so we don't
14553 need to duplicate it for the type. */
14554 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14555 fp
->set_type (die_type (die
, cu
));
14556 FIELD_NAME (*fp
) = fieldname
;
14558 else if (die
->tag
== DW_TAG_inheritance
)
14560 /* C++ base class field. */
14561 handle_data_member_location (die
, cu
, fp
);
14562 FIELD_BITSIZE (*fp
) = 0;
14563 fp
->set_type (die_type (die
, cu
));
14564 FIELD_NAME (*fp
) = fp
->type ()->name ();
14567 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14570 /* Can the type given by DIE define another type? */
14573 type_can_define_types (const struct die_info
*die
)
14577 case DW_TAG_typedef
:
14578 case DW_TAG_class_type
:
14579 case DW_TAG_structure_type
:
14580 case DW_TAG_union_type
:
14581 case DW_TAG_enumeration_type
:
14589 /* Add a type definition defined in the scope of the FIP's class. */
14592 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14593 struct dwarf2_cu
*cu
)
14595 struct decl_field fp
;
14596 memset (&fp
, 0, sizeof (fp
));
14598 gdb_assert (type_can_define_types (die
));
14600 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14601 fp
.name
= dwarf2_name (die
, cu
);
14602 fp
.type
= read_type_die (die
, cu
);
14604 /* Save accessibility. */
14605 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14606 switch (accessibility
)
14608 case DW_ACCESS_public
:
14609 /* The assumed value if neither private nor protected. */
14611 case DW_ACCESS_private
:
14614 case DW_ACCESS_protected
:
14615 fp
.is_protected
= 1;
14619 if (die
->tag
== DW_TAG_typedef
)
14620 fip
->typedef_field_list
.push_back (fp
);
14622 fip
->nested_types_list
.push_back (fp
);
14625 /* A convenience typedef that's used when finding the discriminant
14626 field for a variant part. */
14627 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14630 /* Compute the discriminant range for a given variant. OBSTACK is
14631 where the results will be stored. VARIANT is the variant to
14632 process. IS_UNSIGNED indicates whether the discriminant is signed
14635 static const gdb::array_view
<discriminant_range
>
14636 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14639 std::vector
<discriminant_range
> ranges
;
14641 if (variant
.default_branch
)
14644 if (variant
.discr_list_data
== nullptr)
14646 discriminant_range r
14647 = {variant
.discriminant_value
, variant
.discriminant_value
};
14648 ranges
.push_back (r
);
14652 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14653 variant
.discr_list_data
->size
);
14654 while (!data
.empty ())
14656 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14658 complaint (_("invalid discriminant marker: %d"), data
[0]);
14661 bool is_range
= data
[0] == DW_DSC_range
;
14662 data
= data
.slice (1);
14664 ULONGEST low
, high
;
14665 unsigned int bytes_read
;
14669 complaint (_("DW_AT_discr_list missing low value"));
14673 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14675 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14677 data
= data
.slice (bytes_read
);
14683 complaint (_("DW_AT_discr_list missing high value"));
14687 high
= read_unsigned_leb128 (nullptr, data
.data (),
14690 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14692 data
= data
.slice (bytes_read
);
14697 ranges
.push_back ({ low
, high
});
14701 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14703 std::copy (ranges
.begin (), ranges
.end (), result
);
14704 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14707 static const gdb::array_view
<variant_part
> create_variant_parts
14708 (struct obstack
*obstack
,
14709 const offset_map_type
&offset_map
,
14710 struct field_info
*fi
,
14711 const std::vector
<variant_part_builder
> &variant_parts
);
14713 /* Fill in a "struct variant" for a given variant field. RESULT is
14714 the variant to fill in. OBSTACK is where any needed allocations
14715 will be done. OFFSET_MAP holds the mapping from section offsets to
14716 fields for the type. FI describes the fields of the type we're
14717 processing. FIELD is the variant field we're converting. */
14720 create_one_variant (variant
&result
, struct obstack
*obstack
,
14721 const offset_map_type
&offset_map
,
14722 struct field_info
*fi
, const variant_field
&field
)
14724 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14725 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14726 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14727 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14728 field
.variant_parts
);
14731 /* Fill in a "struct variant_part" for a given variant part. RESULT
14732 is the variant part to fill in. OBSTACK is where any needed
14733 allocations will be done. OFFSET_MAP holds the mapping from
14734 section offsets to fields for the type. FI describes the fields of
14735 the type we're processing. BUILDER is the variant part to be
14739 create_one_variant_part (variant_part
&result
,
14740 struct obstack
*obstack
,
14741 const offset_map_type
&offset_map
,
14742 struct field_info
*fi
,
14743 const variant_part_builder
&builder
)
14745 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14746 if (iter
== offset_map
.end ())
14748 result
.discriminant_index
= -1;
14749 /* Doesn't matter. */
14750 result
.is_unsigned
= false;
14754 result
.discriminant_index
= iter
->second
;
14756 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14759 size_t n
= builder
.variants
.size ();
14760 variant
*output
= new (obstack
) variant
[n
];
14761 for (size_t i
= 0; i
< n
; ++i
)
14762 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14763 builder
.variants
[i
]);
14765 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14768 /* Create a vector of variant parts that can be attached to a type.
14769 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14770 holds the mapping from section offsets to fields for the type. FI
14771 describes the fields of the type we're processing. VARIANT_PARTS
14772 is the vector to convert. */
14774 static const gdb::array_view
<variant_part
>
14775 create_variant_parts (struct obstack
*obstack
,
14776 const offset_map_type
&offset_map
,
14777 struct field_info
*fi
,
14778 const std::vector
<variant_part_builder
> &variant_parts
)
14780 if (variant_parts
.empty ())
14783 size_t n
= variant_parts
.size ();
14784 variant_part
*result
= new (obstack
) variant_part
[n
];
14785 for (size_t i
= 0; i
< n
; ++i
)
14786 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14789 return gdb::array_view
<variant_part
> (result
, n
);
14792 /* Compute the variant part vector for FIP, attaching it to TYPE when
14796 add_variant_property (struct field_info
*fip
, struct type
*type
,
14797 struct dwarf2_cu
*cu
)
14799 /* Map section offsets of fields to their field index. Note the
14800 field index here does not take the number of baseclasses into
14802 offset_map_type offset_map
;
14803 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14804 offset_map
[fip
->fields
[i
].offset
] = i
;
14806 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14807 gdb::array_view
<variant_part
> parts
14808 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14809 fip
->variant_parts
);
14811 struct dynamic_prop prop
;
14812 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14813 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14816 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14819 /* Create the vector of fields, and attach it to the type. */
14822 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14823 struct dwarf2_cu
*cu
)
14825 int nfields
= fip
->nfields ();
14827 /* Record the field count, allocate space for the array of fields,
14828 and create blank accessibility bitfields if necessary. */
14829 type
->set_num_fields (nfields
);
14831 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14833 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
14835 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14837 TYPE_FIELD_PRIVATE_BITS (type
) =
14838 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14839 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14841 TYPE_FIELD_PROTECTED_BITS (type
) =
14842 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14843 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14845 TYPE_FIELD_IGNORE_BITS (type
) =
14846 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14847 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14850 /* If the type has baseclasses, allocate and clear a bit vector for
14851 TYPE_FIELD_VIRTUAL_BITS. */
14852 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
14854 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14855 unsigned char *pointer
;
14857 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14858 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14859 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14860 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14861 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14864 if (!fip
->variant_parts
.empty ())
14865 add_variant_property (fip
, type
, cu
);
14867 /* Copy the saved-up fields into the field vector. */
14868 for (int i
= 0; i
< nfields
; ++i
)
14870 struct nextfield
&field
14871 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14872 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14874 type
->field (i
) = field
.field
;
14875 switch (field
.accessibility
)
14877 case DW_ACCESS_private
:
14878 if (cu
->per_cu
->lang
!= language_ada
)
14879 SET_TYPE_FIELD_PRIVATE (type
, i
);
14882 case DW_ACCESS_protected
:
14883 if (cu
->per_cu
->lang
!= language_ada
)
14884 SET_TYPE_FIELD_PROTECTED (type
, i
);
14887 case DW_ACCESS_public
:
14891 /* Unknown accessibility. Complain and treat it as public. */
14893 complaint (_("unsupported accessibility %d"),
14894 field
.accessibility
);
14898 if (i
< fip
->baseclasses
.size ())
14900 switch (field
.virtuality
)
14902 case DW_VIRTUALITY_virtual
:
14903 case DW_VIRTUALITY_pure_virtual
:
14904 if (cu
->per_cu
->lang
== language_ada
)
14905 error (_("unexpected virtuality in component of Ada type"));
14906 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14913 /* Return true if this member function is a constructor, false
14917 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14919 const char *fieldname
;
14920 const char *type_name
;
14923 if (die
->parent
== NULL
)
14926 if (die
->parent
->tag
!= DW_TAG_structure_type
14927 && die
->parent
->tag
!= DW_TAG_union_type
14928 && die
->parent
->tag
!= DW_TAG_class_type
)
14931 fieldname
= dwarf2_name (die
, cu
);
14932 type_name
= dwarf2_name (die
->parent
, cu
);
14933 if (fieldname
== NULL
|| type_name
== NULL
)
14936 len
= strlen (fieldname
);
14937 return (strncmp (fieldname
, type_name
, len
) == 0
14938 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14941 /* Add a member function to the proper fieldlist. */
14944 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14945 struct type
*type
, struct dwarf2_cu
*cu
)
14947 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14948 struct attribute
*attr
;
14950 struct fnfieldlist
*flp
= nullptr;
14951 struct fn_field
*fnp
;
14952 const char *fieldname
;
14953 struct type
*this_type
;
14955 if (cu
->per_cu
->lang
== language_ada
)
14956 error (_("unexpected member function in Ada type"));
14958 /* Get name of member function. */
14959 fieldname
= dwarf2_name (die
, cu
);
14960 if (fieldname
== NULL
)
14963 /* Look up member function name in fieldlist. */
14964 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14966 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14968 flp
= &fip
->fnfieldlists
[i
];
14973 /* Create a new fnfieldlist if necessary. */
14974 if (flp
== nullptr)
14976 fip
->fnfieldlists
.emplace_back ();
14977 flp
= &fip
->fnfieldlists
.back ();
14978 flp
->name
= fieldname
;
14979 i
= fip
->fnfieldlists
.size () - 1;
14982 /* Create a new member function field and add it to the vector of
14984 flp
->fnfields
.emplace_back ();
14985 fnp
= &flp
->fnfields
.back ();
14987 /* Delay processing of the physname until later. */
14988 if (cu
->per_cu
->lang
== language_cplus
)
14989 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14993 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14994 fnp
->physname
= physname
? physname
: "";
14997 fnp
->type
= alloc_type (objfile
);
14998 this_type
= read_type_die (die
, cu
);
14999 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15001 int nparams
= this_type
->num_fields ();
15003 /* TYPE is the domain of this method, and THIS_TYPE is the type
15004 of the method itself (TYPE_CODE_METHOD). */
15005 smash_to_method_type (fnp
->type
, type
,
15006 TYPE_TARGET_TYPE (this_type
),
15007 this_type
->fields (),
15008 this_type
->num_fields (),
15009 this_type
->has_varargs ());
15011 /* Handle static member functions.
15012 Dwarf2 has no clean way to discern C++ static and non-static
15013 member functions. G++ helps GDB by marking the first
15014 parameter for non-static member functions (which is the this
15015 pointer) as artificial. We obtain this information from
15016 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15017 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15018 fnp
->voffset
= VOFFSET_STATIC
;
15021 complaint (_("member function type missing for '%s'"),
15022 dwarf2_full_name (fieldname
, die
, cu
));
15024 /* Get fcontext from DW_AT_containing_type if present. */
15025 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15026 fnp
->fcontext
= die_containing_type (die
, cu
);
15028 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15029 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15031 /* Get accessibility. */
15032 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15033 switch (accessibility
)
15035 case DW_ACCESS_private
:
15036 fnp
->is_private
= 1;
15038 case DW_ACCESS_protected
:
15039 fnp
->is_protected
= 1;
15043 /* Check for artificial methods. */
15044 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15045 if (attr
&& attr
->as_boolean ())
15046 fnp
->is_artificial
= 1;
15048 /* Check for defaulted methods. */
15049 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15050 if (attr
!= nullptr)
15051 fnp
->defaulted
= attr
->defaulted ();
15053 /* Check for deleted methods. */
15054 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15055 if (attr
!= nullptr && attr
->as_boolean ())
15056 fnp
->is_deleted
= 1;
15058 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15060 /* Get index in virtual function table if it is a virtual member
15061 function. For older versions of GCC, this is an offset in the
15062 appropriate virtual table, as specified by DW_AT_containing_type.
15063 For everyone else, it is an expression to be evaluated relative
15064 to the object address. */
15066 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15067 if (attr
!= nullptr)
15069 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15071 struct dwarf_block
*block
= attr
->as_block ();
15073 if (block
->data
[0] == DW_OP_constu
)
15075 /* Old-style GCC. */
15076 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15078 else if (block
->data
[0] == DW_OP_deref
15079 || (block
->size
> 1
15080 && block
->data
[0] == DW_OP_deref_size
15081 && block
->data
[1] == cu
->header
.addr_size
))
15083 fnp
->voffset
= decode_locdesc (block
, cu
);
15084 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15085 dwarf2_complex_location_expr_complaint ();
15087 fnp
->voffset
/= cu
->header
.addr_size
;
15091 dwarf2_complex_location_expr_complaint ();
15093 if (!fnp
->fcontext
)
15095 /* If there is no `this' field and no DW_AT_containing_type,
15096 we cannot actually find a base class context for the
15098 if (this_type
->num_fields () == 0
15099 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15101 complaint (_("cannot determine context for virtual member "
15102 "function \"%s\" (offset %s)"),
15103 fieldname
, sect_offset_str (die
->sect_off
));
15108 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15112 else if (attr
->form_is_section_offset ())
15114 dwarf2_complex_location_expr_complaint ();
15118 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15124 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15125 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15127 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15128 complaint (_("Member function \"%s\" (offset %s) is virtual "
15129 "but the vtable offset is not specified"),
15130 fieldname
, sect_offset_str (die
->sect_off
));
15131 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15132 TYPE_CPLUS_DYNAMIC (type
) = 1;
15137 /* Create the vector of member function fields, and attach it to the type. */
15140 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15141 struct dwarf2_cu
*cu
)
15143 if (cu
->per_cu
->lang
== language_ada
)
15144 error (_("unexpected member functions in Ada type"));
15146 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15147 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15149 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15151 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15153 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15154 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15156 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15157 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15158 fn_flp
->fn_fields
= (struct fn_field
*)
15159 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15161 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15162 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15165 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15168 /* Returns non-zero if NAME is the name of a vtable member in CU's
15169 language, zero otherwise. */
15171 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15173 static const char vptr
[] = "_vptr";
15175 /* Look for the C++ form of the vtable. */
15176 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15182 /* GCC outputs unnamed structures that are really pointers to member
15183 functions, with the ABI-specified layout. If TYPE describes
15184 such a structure, smash it into a member function type.
15186 GCC shouldn't do this; it should just output pointer to member DIEs.
15187 This is GCC PR debug/28767. */
15190 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15192 struct type
*pfn_type
, *self_type
, *new_type
;
15194 /* Check for a structure with no name and two children. */
15195 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15198 /* Check for __pfn and __delta members. */
15199 if (TYPE_FIELD_NAME (type
, 0) == NULL
15200 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15201 || TYPE_FIELD_NAME (type
, 1) == NULL
15202 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15205 /* Find the type of the method. */
15206 pfn_type
= type
->field (0).type ();
15207 if (pfn_type
== NULL
15208 || pfn_type
->code () != TYPE_CODE_PTR
15209 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15212 /* Look for the "this" argument. */
15213 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15214 if (pfn_type
->num_fields () == 0
15215 /* || pfn_type->field (0).type () == NULL */
15216 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15219 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15220 new_type
= alloc_type (objfile
);
15221 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15222 pfn_type
->fields (), pfn_type
->num_fields (),
15223 pfn_type
->has_varargs ());
15224 smash_to_methodptr_type (type
, new_type
);
15227 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15228 requires rewriting, then copy it and return the updated copy.
15229 Otherwise return nullptr. */
15231 static struct type
*
15232 rewrite_array_type (struct type
*type
)
15234 if (type
->code () != TYPE_CODE_ARRAY
)
15237 struct type
*index_type
= type
->index_type ();
15238 range_bounds
*current_bounds
= index_type
->bounds ();
15240 /* Handle multi-dimensional arrays. */
15241 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15242 if (new_target
== nullptr)
15244 /* Maybe we don't need to rewrite this array. */
15245 if (current_bounds
->low
.kind () == PROP_CONST
15246 && current_bounds
->high
.kind () == PROP_CONST
)
15250 /* Either the target type was rewritten, or the bounds have to be
15251 updated. Either way we want to copy the type and update
15253 struct type
*copy
= copy_type (type
);
15254 int nfields
= copy
->num_fields ();
15256 = ((struct field
*) TYPE_ZALLOC (copy
,
15257 nfields
* sizeof (struct field
)));
15258 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15259 copy
->set_fields (new_fields
);
15260 if (new_target
!= nullptr)
15261 TYPE_TARGET_TYPE (copy
) = new_target
;
15263 struct type
*index_copy
= copy_type (index_type
);
15264 range_bounds
*bounds
15265 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15266 sizeof (range_bounds
));
15267 *bounds
= *current_bounds
;
15268 bounds
->low
.set_const_val (1);
15269 bounds
->high
.set_const_val (0);
15270 index_copy
->set_bounds (bounds
);
15271 copy
->set_index_type (index_copy
);
15276 /* While some versions of GCC will generate complicated DWARF for an
15277 array (see quirk_ada_thick_pointer), more recent versions were
15278 modified to emit an explicit thick pointer structure. However, in
15279 this case, the array still has DWARF expressions for its ranges,
15280 and these must be ignored. */
15283 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15286 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15288 /* Check for a structure with two children. */
15289 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15292 /* Check for P_ARRAY and P_BOUNDS members. */
15293 if (TYPE_FIELD_NAME (type
, 0) == NULL
15294 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15295 || TYPE_FIELD_NAME (type
, 1) == NULL
15296 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15299 /* Make sure we're looking at a pointer to an array. */
15300 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15303 /* The Ada code already knows how to handle these types, so all that
15304 we need to do is turn the bounds into static bounds. However, we
15305 don't want to rewrite existing array or index types in-place,
15306 because those may be referenced in other contexts where this
15307 rewriting is undesirable. */
15308 struct type
*new_ary_type
15309 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15310 if (new_ary_type
!= nullptr)
15311 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15314 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15315 appropriate error checking and issuing complaints if there is a
15319 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15321 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15323 if (attr
== nullptr)
15326 if (!attr
->form_is_constant ())
15328 complaint (_("DW_AT_alignment must have constant form"
15329 " - DIE at %s [in module %s]"),
15330 sect_offset_str (die
->sect_off
),
15331 objfile_name (cu
->per_objfile
->objfile
));
15335 LONGEST val
= attr
->constant_value (0);
15338 complaint (_("DW_AT_alignment value must not be negative"
15339 " - DIE at %s [in module %s]"),
15340 sect_offset_str (die
->sect_off
),
15341 objfile_name (cu
->per_objfile
->objfile
));
15344 ULONGEST align
= val
;
15348 complaint (_("DW_AT_alignment value must not be zero"
15349 " - DIE at %s [in module %s]"),
15350 sect_offset_str (die
->sect_off
),
15351 objfile_name (cu
->per_objfile
->objfile
));
15354 if ((align
& (align
- 1)) != 0)
15356 complaint (_("DW_AT_alignment value must be a power of 2"
15357 " - DIE at %s [in module %s]"),
15358 sect_offset_str (die
->sect_off
),
15359 objfile_name (cu
->per_objfile
->objfile
));
15366 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15367 the alignment for TYPE. */
15370 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15373 if (!set_type_align (type
, get_alignment (cu
, die
)))
15374 complaint (_("DW_AT_alignment value too large"
15375 " - DIE at %s [in module %s]"),
15376 sect_offset_str (die
->sect_off
),
15377 objfile_name (cu
->per_objfile
->objfile
));
15380 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15381 constant for a type, according to DWARF5 spec, Table 5.5. */
15384 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15389 case DW_CC_pass_by_reference
:
15390 case DW_CC_pass_by_value
:
15394 complaint (_("unrecognized DW_AT_calling_convention value "
15395 "(%s) for a type"), pulongest (value
));
15400 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15401 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15402 also according to GNU-specific values (see include/dwarf2.h). */
15405 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15410 case DW_CC_program
:
15414 case DW_CC_GNU_renesas_sh
:
15415 case DW_CC_GNU_borland_fastcall_i386
:
15416 case DW_CC_GDB_IBM_OpenCL
:
15420 complaint (_("unrecognized DW_AT_calling_convention value "
15421 "(%s) for a subroutine"), pulongest (value
));
15426 /* Called when we find the DIE that starts a structure or union scope
15427 (definition) to create a type for the structure or union. Fill in
15428 the type's name and general properties; the members will not be
15429 processed until process_structure_scope. A symbol table entry for
15430 the type will also not be done until process_structure_scope (assuming
15431 the type has a name).
15433 NOTE: we need to call these functions regardless of whether or not the
15434 DIE has a DW_AT_name attribute, since it might be an anonymous
15435 structure or union. This gets the type entered into our set of
15436 user defined types. */
15438 static struct type
*
15439 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15441 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15443 struct attribute
*attr
;
15446 /* If the definition of this type lives in .debug_types, read that type.
15447 Don't follow DW_AT_specification though, that will take us back up
15448 the chain and we want to go down. */
15449 attr
= die
->attr (DW_AT_signature
);
15450 if (attr
!= nullptr)
15452 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15454 /* The type's CU may not be the same as CU.
15455 Ensure TYPE is recorded with CU in die_type_hash. */
15456 return set_die_type (die
, type
, cu
);
15459 type
= alloc_type (objfile
);
15460 INIT_CPLUS_SPECIFIC (type
);
15462 name
= dwarf2_name (die
, cu
);
15465 if (cu
->per_cu
->lang
== language_cplus
15466 || cu
->per_cu
->lang
== language_d
15467 || cu
->per_cu
->lang
== language_rust
)
15469 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15471 /* dwarf2_full_name might have already finished building the DIE's
15472 type. If so, there is no need to continue. */
15473 if (get_die_type (die
, cu
) != NULL
)
15474 return get_die_type (die
, cu
);
15476 type
->set_name (full_name
);
15480 /* The name is already allocated along with this objfile, so
15481 we don't need to duplicate it for the type. */
15482 type
->set_name (name
);
15486 if (die
->tag
== DW_TAG_structure_type
)
15488 type
->set_code (TYPE_CODE_STRUCT
);
15490 else if (die
->tag
== DW_TAG_union_type
)
15492 type
->set_code (TYPE_CODE_UNION
);
15496 type
->set_code (TYPE_CODE_STRUCT
);
15499 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15500 type
->set_is_declared_class (true);
15502 /* Store the calling convention in the type if it's available in
15503 the die. Otherwise the calling convention remains set to
15504 the default value DW_CC_normal. */
15505 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15506 if (attr
!= nullptr
15507 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15509 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15510 TYPE_CPLUS_CALLING_CONVENTION (type
)
15511 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15514 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15515 if (attr
!= nullptr)
15517 if (attr
->form_is_constant ())
15518 TYPE_LENGTH (type
) = attr
->constant_value (0);
15521 struct dynamic_prop prop
;
15522 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15523 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15524 TYPE_LENGTH (type
) = 0;
15529 TYPE_LENGTH (type
) = 0;
15532 maybe_set_alignment (cu
, die
, type
);
15534 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15536 /* ICC<14 does not output the required DW_AT_declaration on
15537 incomplete types, but gives them a size of zero. */
15538 type
->set_is_stub (true);
15541 type
->set_stub_is_supported (true);
15543 if (die_is_declaration (die
, cu
))
15544 type
->set_is_stub (true);
15545 else if (attr
== NULL
&& die
->child
== NULL
15546 && producer_is_realview (cu
->producer
))
15547 /* RealView does not output the required DW_AT_declaration
15548 on incomplete types. */
15549 type
->set_is_stub (true);
15551 /* We need to add the type field to the die immediately so we don't
15552 infinitely recurse when dealing with pointers to the structure
15553 type within the structure itself. */
15554 set_die_type (die
, type
, cu
);
15556 /* set_die_type should be already done. */
15557 set_descriptive_type (type
, die
, cu
);
15562 static void handle_struct_member_die
15563 (struct die_info
*child_die
,
15565 struct field_info
*fi
,
15566 std::vector
<struct symbol
*> *template_args
,
15567 struct dwarf2_cu
*cu
);
15569 /* A helper for handle_struct_member_die that handles
15570 DW_TAG_variant_part. */
15573 handle_variant_part (struct die_info
*die
, struct type
*type
,
15574 struct field_info
*fi
,
15575 std::vector
<struct symbol
*> *template_args
,
15576 struct dwarf2_cu
*cu
)
15578 variant_part_builder
*new_part
;
15579 if (fi
->current_variant_part
== nullptr)
15581 fi
->variant_parts
.emplace_back ();
15582 new_part
= &fi
->variant_parts
.back ();
15584 else if (!fi
->current_variant_part
->processing_variant
)
15586 complaint (_("nested DW_TAG_variant_part seen "
15587 "- DIE at %s [in module %s]"),
15588 sect_offset_str (die
->sect_off
),
15589 objfile_name (cu
->per_objfile
->objfile
));
15594 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15595 current
.variant_parts
.emplace_back ();
15596 new_part
= ¤t
.variant_parts
.back ();
15599 /* When we recurse, we want callees to add to this new variant
15601 scoped_restore save_current_variant_part
15602 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15604 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15607 /* It's a univariant form, an extension we support. */
15609 else if (discr
->form_is_ref ())
15611 struct dwarf2_cu
*target_cu
= cu
;
15612 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15614 new_part
->discriminant_offset
= target_die
->sect_off
;
15618 complaint (_("DW_AT_discr does not have DIE reference form"
15619 " - DIE at %s [in module %s]"),
15620 sect_offset_str (die
->sect_off
),
15621 objfile_name (cu
->per_objfile
->objfile
));
15624 for (die_info
*child_die
= die
->child
;
15626 child_die
= child_die
->sibling
)
15627 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15630 /* A helper for handle_struct_member_die that handles
15634 handle_variant (struct die_info
*die
, struct type
*type
,
15635 struct field_info
*fi
,
15636 std::vector
<struct symbol
*> *template_args
,
15637 struct dwarf2_cu
*cu
)
15639 if (fi
->current_variant_part
== nullptr)
15641 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15642 "- DIE at %s [in module %s]"),
15643 sect_offset_str (die
->sect_off
),
15644 objfile_name (cu
->per_objfile
->objfile
));
15647 if (fi
->current_variant_part
->processing_variant
)
15649 complaint (_("nested DW_TAG_variant seen "
15650 "- DIE at %s [in module %s]"),
15651 sect_offset_str (die
->sect_off
),
15652 objfile_name (cu
->per_objfile
->objfile
));
15656 scoped_restore save_processing_variant
15657 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15660 fi
->current_variant_part
->variants
.emplace_back ();
15661 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15662 variant
.first_field
= fi
->fields
.size ();
15664 /* In a variant we want to get the discriminant and also add a
15665 field for our sole member child. */
15666 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15667 if (discr
== nullptr || !discr
->form_is_constant ())
15669 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15670 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15671 variant
.default_branch
= true;
15673 variant
.discr_list_data
= discr
->as_block ();
15676 variant
.discriminant_value
= discr
->constant_value (0);
15678 for (die_info
*variant_child
= die
->child
;
15679 variant_child
!= NULL
;
15680 variant_child
= variant_child
->sibling
)
15681 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15683 variant
.last_field
= fi
->fields
.size ();
15686 /* A helper for process_structure_scope that handles a single member
15690 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15691 struct field_info
*fi
,
15692 std::vector
<struct symbol
*> *template_args
,
15693 struct dwarf2_cu
*cu
)
15695 if (child_die
->tag
== DW_TAG_member
15696 || child_die
->tag
== DW_TAG_variable
)
15698 /* NOTE: carlton/2002-11-05: A C++ static data member
15699 should be a DW_TAG_member that is a declaration, but
15700 all versions of G++ as of this writing (so through at
15701 least 3.2.1) incorrectly generate DW_TAG_variable
15702 tags for them instead. */
15703 dwarf2_add_field (fi
, child_die
, cu
);
15705 else if (child_die
->tag
== DW_TAG_subprogram
)
15707 /* Rust doesn't have member functions in the C++ sense.
15708 However, it does emit ordinary functions as children
15709 of a struct DIE. */
15710 if (cu
->per_cu
->lang
== language_rust
)
15711 read_func_scope (child_die
, cu
);
15714 /* C++ member function. */
15715 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15718 else if (child_die
->tag
== DW_TAG_inheritance
)
15720 /* C++ base class field. */
15721 dwarf2_add_field (fi
, child_die
, cu
);
15723 else if (type_can_define_types (child_die
))
15724 dwarf2_add_type_defn (fi
, child_die
, cu
);
15725 else if (child_die
->tag
== DW_TAG_template_type_param
15726 || child_die
->tag
== DW_TAG_template_value_param
)
15728 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15731 template_args
->push_back (arg
);
15733 else if (child_die
->tag
== DW_TAG_variant_part
)
15734 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15735 else if (child_die
->tag
== DW_TAG_variant
)
15736 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15739 /* Finish creating a structure or union type, including filling in
15740 its members and creating a symbol for it. */
15743 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15745 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15746 struct die_info
*child_die
;
15749 type
= get_die_type (die
, cu
);
15751 type
= read_structure_type (die
, cu
);
15753 bool has_template_parameters
= false;
15754 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15756 struct field_info fi
;
15757 std::vector
<struct symbol
*> template_args
;
15759 child_die
= die
->child
;
15761 while (child_die
&& child_die
->tag
)
15763 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15764 child_die
= child_die
->sibling
;
15767 /* Attach template arguments to type. */
15768 if (!template_args
.empty ())
15770 has_template_parameters
= true;
15771 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15772 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15773 TYPE_TEMPLATE_ARGUMENTS (type
)
15774 = XOBNEWVEC (&objfile
->objfile_obstack
,
15776 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15777 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15778 template_args
.data (),
15779 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15780 * sizeof (struct symbol
*)));
15783 /* Attach fields and member functions to the type. */
15784 if (fi
.nfields () > 0)
15785 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15786 if (!fi
.fnfieldlists
.empty ())
15788 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15790 /* Get the type which refers to the base class (possibly this
15791 class itself) which contains the vtable pointer for the current
15792 class from the DW_AT_containing_type attribute. This use of
15793 DW_AT_containing_type is a GNU extension. */
15795 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15797 struct type
*t
= die_containing_type (die
, cu
);
15799 set_type_vptr_basetype (type
, t
);
15804 /* Our own class provides vtbl ptr. */
15805 for (i
= t
->num_fields () - 1;
15806 i
>= TYPE_N_BASECLASSES (t
);
15809 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15811 if (is_vtable_name (fieldname
, cu
))
15813 set_type_vptr_fieldno (type
, i
);
15818 /* Complain if virtual function table field not found. */
15819 if (i
< TYPE_N_BASECLASSES (t
))
15820 complaint (_("virtual function table pointer "
15821 "not found when defining class '%s'"),
15822 type
->name () ? type
->name () : "");
15826 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15829 else if (cu
->producer
15830 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15832 /* The IBM XLC compiler does not provide direct indication
15833 of the containing type, but the vtable pointer is
15834 always named __vfp. */
15838 for (i
= type
->num_fields () - 1;
15839 i
>= TYPE_N_BASECLASSES (type
);
15842 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15844 set_type_vptr_fieldno (type
, i
);
15845 set_type_vptr_basetype (type
, type
);
15852 /* Copy fi.typedef_field_list linked list elements content into the
15853 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15854 if (!fi
.typedef_field_list
.empty ())
15856 int count
= fi
.typedef_field_list
.size ();
15858 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15859 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15860 = ((struct decl_field
*)
15862 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15863 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15865 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15866 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15869 /* Copy fi.nested_types_list linked list elements content into the
15870 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15871 if (!fi
.nested_types_list
.empty ()
15872 && cu
->per_cu
->lang
!= language_ada
)
15874 int count
= fi
.nested_types_list
.size ();
15876 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15877 TYPE_NESTED_TYPES_ARRAY (type
)
15878 = ((struct decl_field
*)
15879 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15880 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15882 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15883 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15887 quirk_gcc_member_function_pointer (type
, objfile
);
15888 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15889 cu
->rust_unions
.push_back (type
);
15890 else if (cu
->per_cu
->lang
== language_ada
)
15891 quirk_ada_thick_pointer_struct (die
, cu
, type
);
15893 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15894 snapshots) has been known to create a die giving a declaration
15895 for a class that has, as a child, a die giving a definition for a
15896 nested class. So we have to process our children even if the
15897 current die is a declaration. Normally, of course, a declaration
15898 won't have any children at all. */
15900 child_die
= die
->child
;
15902 while (child_die
!= NULL
&& child_die
->tag
)
15904 if (child_die
->tag
== DW_TAG_member
15905 || child_die
->tag
== DW_TAG_variable
15906 || child_die
->tag
== DW_TAG_inheritance
15907 || child_die
->tag
== DW_TAG_template_value_param
15908 || child_die
->tag
== DW_TAG_template_type_param
)
15913 process_die (child_die
, cu
);
15915 child_die
= child_die
->sibling
;
15918 /* Do not consider external references. According to the DWARF standard,
15919 these DIEs are identified by the fact that they have no byte_size
15920 attribute, and a declaration attribute. */
15921 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15922 || !die_is_declaration (die
, cu
)
15923 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15925 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15927 if (has_template_parameters
)
15929 struct symtab
*symtab
;
15930 if (sym
!= nullptr)
15931 symtab
= symbol_symtab (sym
);
15932 else if (cu
->line_header
!= nullptr)
15934 /* Any related symtab will do. */
15936 = cu
->line_header
->file_names ()[0].symtab
;
15941 complaint (_("could not find suitable "
15942 "symtab for template parameter"
15943 " - DIE at %s [in module %s]"),
15944 sect_offset_str (die
->sect_off
),
15945 objfile_name (objfile
));
15948 if (symtab
!= nullptr)
15950 /* Make sure that the symtab is set on the new symbols.
15951 Even though they don't appear in this symtab directly,
15952 other parts of gdb assume that symbols do, and this is
15953 reasonably true. */
15954 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15955 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15961 /* Assuming DIE is an enumeration type, and TYPE is its associated
15962 type, update TYPE using some information only available in DIE's
15963 children. In particular, the fields are computed. */
15966 update_enumeration_type_from_children (struct die_info
*die
,
15968 struct dwarf2_cu
*cu
)
15970 struct die_info
*child_die
;
15971 int unsigned_enum
= 1;
15974 auto_obstack obstack
;
15975 std::vector
<struct field
> fields
;
15977 for (child_die
= die
->child
;
15978 child_die
!= NULL
&& child_die
->tag
;
15979 child_die
= child_die
->sibling
)
15981 struct attribute
*attr
;
15983 const gdb_byte
*bytes
;
15984 struct dwarf2_locexpr_baton
*baton
;
15987 if (child_die
->tag
!= DW_TAG_enumerator
)
15990 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15994 name
= dwarf2_name (child_die
, cu
);
15996 name
= "<anonymous enumerator>";
15998 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15999 &value
, &bytes
, &baton
);
16007 if (count_one_bits_ll (value
) >= 2)
16011 fields
.emplace_back ();
16012 struct field
&field
= fields
.back ();
16013 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16014 SET_FIELD_ENUMVAL (field
, value
);
16017 if (!fields
.empty ())
16019 type
->set_num_fields (fields
.size ());
16022 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16023 memcpy (type
->fields (), fields
.data (),
16024 sizeof (struct field
) * fields
.size ());
16028 type
->set_is_unsigned (true);
16031 type
->set_is_flag_enum (true);
16034 /* Given a DW_AT_enumeration_type die, set its type. We do not
16035 complete the type's fields yet, or create any symbols. */
16037 static struct type
*
16038 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16040 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16042 struct attribute
*attr
;
16045 /* If the definition of this type lives in .debug_types, read that type.
16046 Don't follow DW_AT_specification though, that will take us back up
16047 the chain and we want to go down. */
16048 attr
= die
->attr (DW_AT_signature
);
16049 if (attr
!= nullptr)
16051 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16053 /* The type's CU may not be the same as CU.
16054 Ensure TYPE is recorded with CU in die_type_hash. */
16055 return set_die_type (die
, type
, cu
);
16058 type
= alloc_type (objfile
);
16060 type
->set_code (TYPE_CODE_ENUM
);
16061 name
= dwarf2_full_name (NULL
, die
, cu
);
16063 type
->set_name (name
);
16065 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16068 struct type
*underlying_type
= die_type (die
, cu
);
16070 TYPE_TARGET_TYPE (type
) = underlying_type
;
16073 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16074 if (attr
!= nullptr)
16076 TYPE_LENGTH (type
) = attr
->constant_value (0);
16080 TYPE_LENGTH (type
) = 0;
16083 maybe_set_alignment (cu
, die
, type
);
16085 /* The enumeration DIE can be incomplete. In Ada, any type can be
16086 declared as private in the package spec, and then defined only
16087 inside the package body. Such types are known as Taft Amendment
16088 Types. When another package uses such a type, an incomplete DIE
16089 may be generated by the compiler. */
16090 if (die_is_declaration (die
, cu
))
16091 type
->set_is_stub (true);
16093 /* If this type has an underlying type that is not a stub, then we
16094 may use its attributes. We always use the "unsigned" attribute
16095 in this situation, because ordinarily we guess whether the type
16096 is unsigned -- but the guess can be wrong and the underlying type
16097 can tell us the reality. However, we defer to a local size
16098 attribute if one exists, because this lets the compiler override
16099 the underlying type if needed. */
16100 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16102 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16103 underlying_type
= check_typedef (underlying_type
);
16105 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16107 if (TYPE_LENGTH (type
) == 0)
16108 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16110 if (TYPE_RAW_ALIGN (type
) == 0
16111 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16112 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16115 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16117 set_die_type (die
, type
, cu
);
16119 /* Finish the creation of this type by using the enum's children.
16120 Note that, as usual, this must come after set_die_type to avoid
16121 infinite recursion when trying to compute the names of the
16123 update_enumeration_type_from_children (die
, type
, cu
);
16128 /* Given a pointer to a die which begins an enumeration, process all
16129 the dies that define the members of the enumeration, and create the
16130 symbol for the enumeration type.
16132 NOTE: We reverse the order of the element list. */
16135 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16137 struct type
*this_type
;
16139 this_type
= get_die_type (die
, cu
);
16140 if (this_type
== NULL
)
16141 this_type
= read_enumeration_type (die
, cu
);
16143 if (die
->child
!= NULL
)
16145 struct die_info
*child_die
;
16148 child_die
= die
->child
;
16149 while (child_die
&& child_die
->tag
)
16151 if (child_die
->tag
!= DW_TAG_enumerator
)
16153 process_die (child_die
, cu
);
16157 name
= dwarf2_name (child_die
, cu
);
16159 new_symbol (child_die
, this_type
, cu
);
16162 child_die
= child_die
->sibling
;
16166 /* If we are reading an enum from a .debug_types unit, and the enum
16167 is a declaration, and the enum is not the signatured type in the
16168 unit, then we do not want to add a symbol for it. Adding a
16169 symbol would in some cases obscure the true definition of the
16170 enum, giving users an incomplete type when the definition is
16171 actually available. Note that we do not want to do this for all
16172 enums which are just declarations, because C++0x allows forward
16173 enum declarations. */
16174 if (cu
->per_cu
->is_debug_types
16175 && die_is_declaration (die
, cu
))
16177 struct signatured_type
*sig_type
;
16179 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16180 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16181 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16185 new_symbol (die
, this_type
, cu
);
16188 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16189 expression for an index type and finds the corresponding field
16190 offset in the hidden "P_BOUNDS" structure. Returns true on success
16191 and updates *FIELD, false if it fails to recognize an
16195 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16196 int *bounds_offset
, struct field
*field
,
16197 struct dwarf2_cu
*cu
)
16199 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16200 if (attr
== nullptr || !attr
->form_is_block ())
16203 const struct dwarf_block
*block
= attr
->as_block ();
16204 const gdb_byte
*start
= block
->data
;
16205 const gdb_byte
*end
= block
->data
+ block
->size
;
16207 /* The expression to recognize generally looks like:
16209 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16210 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16212 However, the second "plus_uconst" may be missing:
16214 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16215 DW_OP_deref_size: 4)
16217 This happens when the field is at the start of the structure.
16219 Also, the final deref may not be sized:
16221 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16224 This happens when the size of the index type happens to be the
16225 same as the architecture's word size. This can occur with or
16226 without the second plus_uconst. */
16228 if (end
- start
< 2)
16230 if (*start
++ != DW_OP_push_object_address
)
16232 if (*start
++ != DW_OP_plus_uconst
)
16235 uint64_t this_bound_off
;
16236 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16237 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16239 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16240 is consistent among all bounds. */
16241 if (*bounds_offset
== -1)
16242 *bounds_offset
= this_bound_off
;
16243 else if (*bounds_offset
!= this_bound_off
)
16246 if (start
== end
|| *start
++ != DW_OP_deref
)
16252 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16254 /* This means an offset of 0. */
16256 else if (*start
++ != DW_OP_plus_uconst
)
16260 /* The size is the parameter to DW_OP_plus_uconst. */
16262 start
= gdb_read_uleb128 (start
, end
, &val
);
16263 if (start
== nullptr)
16265 if ((int) val
!= val
)
16274 if (*start
== DW_OP_deref_size
)
16276 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16277 if (start
== nullptr)
16280 else if (*start
== DW_OP_deref
)
16282 size
= cu
->header
.addr_size
;
16288 SET_FIELD_BITPOS (*field
, 8 * offset
);
16289 if (size
!= TYPE_LENGTH (field
->type ()))
16290 FIELD_BITSIZE (*field
) = 8 * size
;
16295 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16296 some kinds of Ada arrays:
16298 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16299 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16300 <11e0> DW_AT_data_location: 2 byte block: 97 6
16301 (DW_OP_push_object_address; DW_OP_deref)
16302 <11e3> DW_AT_type : <0x1173>
16303 <11e7> DW_AT_sibling : <0x1201>
16304 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16305 <11ec> DW_AT_type : <0x1206>
16306 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16307 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16308 DW_OP_deref_size: 4)
16309 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16310 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16311 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16313 This actually represents a "thick pointer", which is a structure
16314 with two elements: one that is a pointer to the array data, and one
16315 that is a pointer to another structure; this second structure holds
16318 This returns a new type on success, or nullptr if this didn't
16319 recognize the type. */
16321 static struct type
*
16322 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16325 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16326 /* So far we've only seen this with block form. */
16327 if (attr
== nullptr || !attr
->form_is_block ())
16330 /* Note that this will fail if the structure layout is changed by
16331 the compiler. However, we have no good way to recognize some
16332 other layout, because we don't know what expression the compiler
16333 might choose to emit should this happen. */
16334 struct dwarf_block
*blk
= attr
->as_block ();
16336 || blk
->data
[0] != DW_OP_push_object_address
16337 || blk
->data
[1] != DW_OP_deref
)
16340 int bounds_offset
= -1;
16341 int max_align
= -1;
16342 std::vector
<struct field
> range_fields
;
16343 for (struct die_info
*child_die
= die
->child
;
16345 child_die
= child_die
->sibling
)
16347 if (child_die
->tag
== DW_TAG_subrange_type
)
16349 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16351 int this_align
= type_align (underlying
);
16352 if (this_align
> max_align
)
16353 max_align
= this_align
;
16355 range_fields
.emplace_back ();
16356 range_fields
.emplace_back ();
16358 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16359 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16361 lower
.set_type (underlying
);
16362 FIELD_ARTIFICIAL (lower
) = 1;
16364 upper
.set_type (underlying
);
16365 FIELD_ARTIFICIAL (upper
) = 1;
16367 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16368 &bounds_offset
, &lower
, cu
)
16369 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16370 &bounds_offset
, &upper
, cu
))
16375 /* This shouldn't really happen, but double-check that we found
16376 where the bounds are stored. */
16377 if (bounds_offset
== -1)
16380 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16381 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16385 /* Set the name of each field in the bounds. */
16386 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16387 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16388 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16389 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16392 struct type
*bounds
= alloc_type (objfile
);
16393 bounds
->set_code (TYPE_CODE_STRUCT
);
16395 bounds
->set_num_fields (range_fields
.size ());
16397 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16398 * sizeof (struct field
))));
16399 memcpy (bounds
->fields (), range_fields
.data (),
16400 bounds
->num_fields () * sizeof (struct field
));
16402 int last_fieldno
= range_fields
.size () - 1;
16403 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16404 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16405 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16407 /* Rewrite the existing array type in place. Specifically, we
16408 remove any dynamic properties we might have read, and we replace
16409 the index types. */
16410 struct type
*iter
= type
;
16411 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16413 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16414 iter
->main_type
->dyn_prop_list
= nullptr;
16415 iter
->set_index_type
16416 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16417 iter
= TYPE_TARGET_TYPE (iter
);
16420 struct type
*result
= alloc_type (objfile
);
16421 result
->set_code (TYPE_CODE_STRUCT
);
16423 result
->set_num_fields (2);
16425 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16426 * sizeof (struct field
))));
16428 /* The names are chosen to coincide with what the compiler does with
16429 -fgnat-encodings=all, which the Ada code in gdb already
16431 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16432 result
->field (0).set_type (lookup_pointer_type (type
));
16434 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16435 result
->field (1).set_type (lookup_pointer_type (bounds
));
16436 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16438 result
->set_name (type
->name ());
16439 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16440 + TYPE_LENGTH (result
->field (1).type ()));
16445 /* Extract all information from a DW_TAG_array_type DIE and put it in
16446 the DIE's type field. For now, this only handles one dimensional
16449 static struct type
*
16450 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16452 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16453 struct die_info
*child_die
;
16455 struct type
*element_type
, *range_type
, *index_type
;
16456 struct attribute
*attr
;
16458 struct dynamic_prop
*byte_stride_prop
= NULL
;
16459 unsigned int bit_stride
= 0;
16461 element_type
= die_type (die
, cu
);
16463 /* The die_type call above may have already set the type for this DIE. */
16464 type
= get_die_type (die
, cu
);
16468 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16472 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16475 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16476 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16480 complaint (_("unable to read array DW_AT_byte_stride "
16481 " - DIE at %s [in module %s]"),
16482 sect_offset_str (die
->sect_off
),
16483 objfile_name (cu
->per_objfile
->objfile
));
16484 /* Ignore this attribute. We will likely not be able to print
16485 arrays of this type correctly, but there is little we can do
16486 to help if we cannot read the attribute's value. */
16487 byte_stride_prop
= NULL
;
16491 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16493 bit_stride
= attr
->constant_value (0);
16495 /* Irix 6.2 native cc creates array types without children for
16496 arrays with unspecified length. */
16497 if (die
->child
== NULL
)
16499 index_type
= objfile_type (objfile
)->builtin_int
;
16500 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16501 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16502 byte_stride_prop
, bit_stride
);
16503 return set_die_type (die
, type
, cu
);
16506 std::vector
<struct type
*> range_types
;
16507 child_die
= die
->child
;
16508 while (child_die
&& child_die
->tag
)
16510 if (child_die
->tag
== DW_TAG_subrange_type
)
16512 struct type
*child_type
= read_type_die (child_die
, cu
);
16514 if (child_type
!= NULL
)
16516 /* The range type was succesfully read. Save it for the
16517 array type creation. */
16518 range_types
.push_back (child_type
);
16521 child_die
= child_die
->sibling
;
16524 if (range_types
.empty ())
16526 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16527 sect_offset_str (die
->sect_off
),
16528 objfile_name (cu
->per_objfile
->objfile
));
16532 /* Dwarf2 dimensions are output from left to right, create the
16533 necessary array types in backwards order. */
16535 type
= element_type
;
16537 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16541 while (i
< range_types
.size ())
16543 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16544 byte_stride_prop
, bit_stride
);
16546 byte_stride_prop
= nullptr;
16551 size_t ndim
= range_types
.size ();
16554 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16555 byte_stride_prop
, bit_stride
);
16557 byte_stride_prop
= nullptr;
16561 gdb_assert (type
!= element_type
);
16563 /* Understand Dwarf2 support for vector types (like they occur on
16564 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16565 array type. This is not part of the Dwarf2/3 standard yet, but a
16566 custom vendor extension. The main difference between a regular
16567 array and the vector variant is that vectors are passed by value
16569 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16570 if (attr
!= nullptr)
16571 make_vector_type (type
);
16573 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16574 implementation may choose to implement triple vectors using this
16576 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16577 if (attr
!= nullptr && attr
->form_is_unsigned ())
16579 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16580 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16582 complaint (_("DW_AT_byte_size for array type smaller "
16583 "than the total size of elements"));
16586 name
= dwarf2_name (die
, cu
);
16588 type
->set_name (name
);
16590 maybe_set_alignment (cu
, die
, type
);
16592 struct type
*replacement_type
= nullptr;
16593 if (cu
->per_cu
->lang
== language_ada
)
16595 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16596 if (replacement_type
!= nullptr)
16597 type
= replacement_type
;
16600 /* Install the type in the die. */
16601 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16603 /* set_die_type should be already done. */
16604 set_descriptive_type (type
, die
, cu
);
16609 static enum dwarf_array_dim_ordering
16610 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16612 struct attribute
*attr
;
16614 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16616 if (attr
!= nullptr)
16618 LONGEST val
= attr
->constant_value (-1);
16619 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16620 return (enum dwarf_array_dim_ordering
) val
;
16623 /* GNU F77 is a special case, as at 08/2004 array type info is the
16624 opposite order to the dwarf2 specification, but data is still
16625 laid out as per normal fortran.
16627 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16628 version checking. */
16630 if (cu
->per_cu
->lang
== language_fortran
16631 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16633 return DW_ORD_row_major
;
16636 switch (cu
->language_defn
->array_ordering ())
16638 case array_column_major
:
16639 return DW_ORD_col_major
;
16640 case array_row_major
:
16642 return DW_ORD_row_major
;
16646 /* Extract all information from a DW_TAG_set_type DIE and put it in
16647 the DIE's type field. */
16649 static struct type
*
16650 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16652 struct type
*domain_type
, *set_type
;
16653 struct attribute
*attr
;
16655 domain_type
= die_type (die
, cu
);
16657 /* The die_type call above may have already set the type for this DIE. */
16658 set_type
= get_die_type (die
, cu
);
16662 set_type
= create_set_type (NULL
, domain_type
);
16664 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16665 if (attr
!= nullptr && attr
->form_is_unsigned ())
16666 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16668 maybe_set_alignment (cu
, die
, set_type
);
16670 return set_die_type (die
, set_type
, cu
);
16673 /* A helper for read_common_block that creates a locexpr baton.
16674 SYM is the symbol which we are marking as computed.
16675 COMMON_DIE is the DIE for the common block.
16676 COMMON_LOC is the location expression attribute for the common
16678 MEMBER_LOC is the location expression attribute for the particular
16679 member of the common block that we are processing.
16680 CU is the CU from which the above come. */
16683 mark_common_block_symbol_computed (struct symbol
*sym
,
16684 struct die_info
*common_die
,
16685 struct attribute
*common_loc
,
16686 struct attribute
*member_loc
,
16687 struct dwarf2_cu
*cu
)
16689 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16690 struct objfile
*objfile
= per_objfile
->objfile
;
16691 struct dwarf2_locexpr_baton
*baton
;
16693 unsigned int cu_off
;
16694 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16695 LONGEST offset
= 0;
16697 gdb_assert (common_loc
&& member_loc
);
16698 gdb_assert (common_loc
->form_is_block ());
16699 gdb_assert (member_loc
->form_is_block ()
16700 || member_loc
->form_is_constant ());
16702 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16703 baton
->per_objfile
= per_objfile
;
16704 baton
->per_cu
= cu
->per_cu
;
16705 gdb_assert (baton
->per_cu
);
16707 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16709 if (member_loc
->form_is_constant ())
16711 offset
= member_loc
->constant_value (0);
16712 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16715 baton
->size
+= member_loc
->as_block ()->size
;
16717 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16720 *ptr
++ = DW_OP_call4
;
16721 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16722 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16725 if (member_loc
->form_is_constant ())
16727 *ptr
++ = DW_OP_addr
;
16728 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16729 ptr
+= cu
->header
.addr_size
;
16733 /* We have to copy the data here, because DW_OP_call4 will only
16734 use a DW_AT_location attribute. */
16735 struct dwarf_block
*block
= member_loc
->as_block ();
16736 memcpy (ptr
, block
->data
, block
->size
);
16737 ptr
+= block
->size
;
16740 *ptr
++ = DW_OP_plus
;
16741 gdb_assert (ptr
- baton
->data
== baton
->size
);
16743 SYMBOL_LOCATION_BATON (sym
) = baton
;
16744 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16747 /* Create appropriate locally-scoped variables for all the
16748 DW_TAG_common_block entries. Also create a struct common_block
16749 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16750 is used to separate the common blocks name namespace from regular
16754 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16756 struct attribute
*attr
;
16758 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16759 if (attr
!= nullptr)
16761 /* Support the .debug_loc offsets. */
16762 if (attr
->form_is_block ())
16766 else if (attr
->form_is_section_offset ())
16768 dwarf2_complex_location_expr_complaint ();
16773 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16774 "common block member");
16779 if (die
->child
!= NULL
)
16781 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16782 struct die_info
*child_die
;
16783 size_t n_entries
= 0, size
;
16784 struct common_block
*common_block
;
16785 struct symbol
*sym
;
16787 for (child_die
= die
->child
;
16788 child_die
&& child_die
->tag
;
16789 child_die
= child_die
->sibling
)
16792 size
= (sizeof (struct common_block
)
16793 + (n_entries
- 1) * sizeof (struct symbol
*));
16795 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16797 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16798 common_block
->n_entries
= 0;
16800 for (child_die
= die
->child
;
16801 child_die
&& child_die
->tag
;
16802 child_die
= child_die
->sibling
)
16804 /* Create the symbol in the DW_TAG_common_block block in the current
16806 sym
= new_symbol (child_die
, NULL
, cu
);
16809 struct attribute
*member_loc
;
16811 common_block
->contents
[common_block
->n_entries
++] = sym
;
16813 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16817 /* GDB has handled this for a long time, but it is
16818 not specified by DWARF. It seems to have been
16819 emitted by gfortran at least as recently as:
16820 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16821 complaint (_("Variable in common block has "
16822 "DW_AT_data_member_location "
16823 "- DIE at %s [in module %s]"),
16824 sect_offset_str (child_die
->sect_off
),
16825 objfile_name (objfile
));
16827 if (member_loc
->form_is_section_offset ())
16828 dwarf2_complex_location_expr_complaint ();
16829 else if (member_loc
->form_is_constant ()
16830 || member_loc
->form_is_block ())
16832 if (attr
!= nullptr)
16833 mark_common_block_symbol_computed (sym
, die
, attr
,
16837 dwarf2_complex_location_expr_complaint ();
16842 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16843 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16847 /* Create a type for a C++ namespace. */
16849 static struct type
*
16850 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16852 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16853 const char *previous_prefix
, *name
;
16857 /* For extensions, reuse the type of the original namespace. */
16858 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16860 struct die_info
*ext_die
;
16861 struct dwarf2_cu
*ext_cu
= cu
;
16863 ext_die
= dwarf2_extension (die
, &ext_cu
);
16864 type
= read_type_die (ext_die
, ext_cu
);
16866 /* EXT_CU may not be the same as CU.
16867 Ensure TYPE is recorded with CU in die_type_hash. */
16868 return set_die_type (die
, type
, cu
);
16871 name
= namespace_name (die
, &is_anonymous
, cu
);
16873 /* Now build the name of the current namespace. */
16875 previous_prefix
= determine_prefix (die
, cu
);
16876 if (previous_prefix
[0] != '\0')
16877 name
= typename_concat (&objfile
->objfile_obstack
,
16878 previous_prefix
, name
, 0, cu
);
16880 /* Create the type. */
16881 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16883 return set_die_type (die
, type
, cu
);
16886 /* Read a namespace scope. */
16889 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16891 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16894 /* Add a symbol associated to this if we haven't seen the namespace
16895 before. Also, add a using directive if it's an anonymous
16898 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16902 type
= read_type_die (die
, cu
);
16903 new_symbol (die
, type
, cu
);
16905 namespace_name (die
, &is_anonymous
, cu
);
16908 const char *previous_prefix
= determine_prefix (die
, cu
);
16910 std::vector
<const char *> excludes
;
16911 add_using_directive (using_directives (cu
),
16912 previous_prefix
, type
->name (), NULL
,
16913 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16917 if (die
->child
!= NULL
)
16919 struct die_info
*child_die
= die
->child
;
16921 while (child_die
&& child_die
->tag
)
16923 process_die (child_die
, cu
);
16924 child_die
= child_die
->sibling
;
16929 /* Read a Fortran module as type. This DIE can be only a declaration used for
16930 imported module. Still we need that type as local Fortran "use ... only"
16931 declaration imports depend on the created type in determine_prefix. */
16933 static struct type
*
16934 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16936 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16937 const char *module_name
;
16940 module_name
= dwarf2_name (die
, cu
);
16941 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16943 return set_die_type (die
, type
, cu
);
16946 /* Read a Fortran module. */
16949 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16951 struct die_info
*child_die
= die
->child
;
16954 type
= read_type_die (die
, cu
);
16955 new_symbol (die
, type
, cu
);
16957 while (child_die
&& child_die
->tag
)
16959 process_die (child_die
, cu
);
16960 child_die
= child_die
->sibling
;
16964 /* Return the name of the namespace represented by DIE. Set
16965 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16968 static const char *
16969 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16971 struct die_info
*current_die
;
16972 const char *name
= NULL
;
16974 /* Loop through the extensions until we find a name. */
16976 for (current_die
= die
;
16977 current_die
!= NULL
;
16978 current_die
= dwarf2_extension (die
, &cu
))
16980 /* We don't use dwarf2_name here so that we can detect the absence
16981 of a name -> anonymous namespace. */
16982 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16988 /* Is it an anonymous namespace? */
16990 *is_anonymous
= (name
== NULL
);
16992 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16997 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16998 the user defined type vector. */
17000 static struct type
*
17001 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17003 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17004 struct comp_unit_head
*cu_header
= &cu
->header
;
17006 struct attribute
*attr_byte_size
;
17007 struct attribute
*attr_address_class
;
17008 int byte_size
, addr_class
;
17009 struct type
*target_type
;
17011 target_type
= die_type (die
, cu
);
17013 /* The die_type call above may have already set the type for this DIE. */
17014 type
= get_die_type (die
, cu
);
17018 type
= lookup_pointer_type (target_type
);
17020 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17021 if (attr_byte_size
)
17022 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17024 byte_size
= cu_header
->addr_size
;
17026 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17027 if (attr_address_class
)
17028 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17030 addr_class
= DW_ADDR_none
;
17032 ULONGEST alignment
= get_alignment (cu
, die
);
17034 /* If the pointer size, alignment, or address class is different
17035 than the default, create a type variant marked as such and set
17036 the length accordingly. */
17037 if (TYPE_LENGTH (type
) != byte_size
17038 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17039 && alignment
!= TYPE_RAW_ALIGN (type
))
17040 || addr_class
!= DW_ADDR_none
)
17042 if (gdbarch_address_class_type_flags_p (gdbarch
))
17044 type_instance_flags type_flags
17045 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17047 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17049 type
= make_type_with_address_space (type
, type_flags
);
17051 else if (TYPE_LENGTH (type
) != byte_size
)
17053 complaint (_("invalid pointer size %d"), byte_size
);
17055 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17057 complaint (_("Invalid DW_AT_alignment"
17058 " - DIE at %s [in module %s]"),
17059 sect_offset_str (die
->sect_off
),
17060 objfile_name (cu
->per_objfile
->objfile
));
17064 /* Should we also complain about unhandled address classes? */
17068 TYPE_LENGTH (type
) = byte_size
;
17069 set_type_align (type
, alignment
);
17070 return set_die_type (die
, type
, cu
);
17073 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17074 the user defined type vector. */
17076 static struct type
*
17077 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17080 struct type
*to_type
;
17081 struct type
*domain
;
17083 to_type
= die_type (die
, cu
);
17084 domain
= die_containing_type (die
, cu
);
17086 /* The calls above may have already set the type for this DIE. */
17087 type
= get_die_type (die
, cu
);
17091 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17092 type
= lookup_methodptr_type (to_type
);
17093 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17095 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17097 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17098 to_type
->fields (), to_type
->num_fields (),
17099 to_type
->has_varargs ());
17100 type
= lookup_methodptr_type (new_type
);
17103 type
= lookup_memberptr_type (to_type
, domain
);
17105 return set_die_type (die
, type
, cu
);
17108 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17109 the user defined type vector. */
17111 static struct type
*
17112 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17113 enum type_code refcode
)
17115 struct comp_unit_head
*cu_header
= &cu
->header
;
17116 struct type
*type
, *target_type
;
17117 struct attribute
*attr
;
17119 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17121 target_type
= die_type (die
, cu
);
17123 /* The die_type call above may have already set the type for this DIE. */
17124 type
= get_die_type (die
, cu
);
17128 type
= lookup_reference_type (target_type
, refcode
);
17129 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17130 if (attr
!= nullptr)
17132 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17136 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17138 maybe_set_alignment (cu
, die
, type
);
17139 return set_die_type (die
, type
, cu
);
17142 /* Add the given cv-qualifiers to the element type of the array. GCC
17143 outputs DWARF type qualifiers that apply to an array, not the
17144 element type. But GDB relies on the array element type to carry
17145 the cv-qualifiers. This mimics section 6.7.3 of the C99
17148 static struct type
*
17149 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17150 struct type
*base_type
, int cnst
, int voltl
)
17152 struct type
*el_type
, *inner_array
;
17154 base_type
= copy_type (base_type
);
17155 inner_array
= base_type
;
17157 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17159 TYPE_TARGET_TYPE (inner_array
) =
17160 copy_type (TYPE_TARGET_TYPE (inner_array
));
17161 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17164 el_type
= TYPE_TARGET_TYPE (inner_array
);
17165 cnst
|= TYPE_CONST (el_type
);
17166 voltl
|= TYPE_VOLATILE (el_type
);
17167 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17169 return set_die_type (die
, base_type
, cu
);
17172 static struct type
*
17173 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17175 struct type
*base_type
, *cv_type
;
17177 base_type
= die_type (die
, cu
);
17179 /* The die_type call above may have already set the type for this DIE. */
17180 cv_type
= get_die_type (die
, cu
);
17184 /* In case the const qualifier is applied to an array type, the element type
17185 is so qualified, not the array type (section 6.7.3 of C99). */
17186 if (base_type
->code () == TYPE_CODE_ARRAY
)
17187 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17189 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17190 return set_die_type (die
, cv_type
, cu
);
17193 static struct type
*
17194 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17196 struct type
*base_type
, *cv_type
;
17198 base_type
= die_type (die
, cu
);
17200 /* The die_type call above may have already set the type for this DIE. */
17201 cv_type
= get_die_type (die
, cu
);
17205 /* In case the volatile qualifier is applied to an array type, the
17206 element type is so qualified, not the array type (section 6.7.3
17208 if (base_type
->code () == TYPE_CODE_ARRAY
)
17209 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17211 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17212 return set_die_type (die
, cv_type
, cu
);
17215 /* Handle DW_TAG_restrict_type. */
17217 static struct type
*
17218 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17220 struct type
*base_type
, *cv_type
;
17222 base_type
= die_type (die
, cu
);
17224 /* The die_type call above may have already set the type for this DIE. */
17225 cv_type
= get_die_type (die
, cu
);
17229 cv_type
= make_restrict_type (base_type
);
17230 return set_die_type (die
, cv_type
, cu
);
17233 /* Handle DW_TAG_atomic_type. */
17235 static struct type
*
17236 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17238 struct type
*base_type
, *cv_type
;
17240 base_type
= die_type (die
, cu
);
17242 /* The die_type call above may have already set the type for this DIE. */
17243 cv_type
= get_die_type (die
, cu
);
17247 cv_type
= make_atomic_type (base_type
);
17248 return set_die_type (die
, cv_type
, cu
);
17251 /* Extract all information from a DW_TAG_string_type DIE and add to
17252 the user defined type vector. It isn't really a user defined type,
17253 but it behaves like one, with other DIE's using an AT_user_def_type
17254 attribute to reference it. */
17256 static struct type
*
17257 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17259 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17260 struct gdbarch
*gdbarch
= objfile
->arch ();
17261 struct type
*type
, *range_type
, *index_type
, *char_type
;
17262 struct attribute
*attr
;
17263 struct dynamic_prop prop
;
17264 bool length_is_constant
= true;
17267 /* There are a couple of places where bit sizes might be made use of
17268 when parsing a DW_TAG_string_type, however, no producer that we know
17269 of make use of these. Handling bit sizes that are a multiple of the
17270 byte size is easy enough, but what about other bit sizes? Lets deal
17271 with that problem when we have to. Warn about these attributes being
17272 unsupported, then parse the type and ignore them like we always
17274 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17275 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17277 static bool warning_printed
= false;
17278 if (!warning_printed
)
17280 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17281 "currently supported on DW_TAG_string_type."));
17282 warning_printed
= true;
17286 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17287 if (attr
!= nullptr && !attr
->form_is_constant ())
17289 /* The string length describes the location at which the length of
17290 the string can be found. The size of the length field can be
17291 specified with one of the attributes below. */
17292 struct type
*prop_type
;
17293 struct attribute
*len
17294 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17295 if (len
== nullptr)
17296 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17297 if (len
!= nullptr && len
->form_is_constant ())
17299 /* Pass 0 as the default as we know this attribute is constant
17300 and the default value will not be returned. */
17301 LONGEST sz
= len
->constant_value (0);
17302 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17306 /* If the size is not specified then we assume it is the size of
17307 an address on this target. */
17308 prop_type
= cu
->addr_sized_int_type (true);
17311 /* Convert the attribute into a dynamic property. */
17312 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17315 length_is_constant
= false;
17317 else if (attr
!= nullptr)
17319 /* This DW_AT_string_length just contains the length with no
17320 indirection. There's no need to create a dynamic property in this
17321 case. Pass 0 for the default value as we know it will not be
17322 returned in this case. */
17323 length
= attr
->constant_value (0);
17325 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17327 /* We don't currently support non-constant byte sizes for strings. */
17328 length
= attr
->constant_value (1);
17332 /* Use 1 as a fallback length if we have nothing else. */
17336 index_type
= objfile_type (objfile
)->builtin_int
;
17337 if (length_is_constant
)
17338 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17341 struct dynamic_prop low_bound
;
17343 low_bound
.set_const_val (1);
17344 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17346 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17347 type
= create_string_type (NULL
, char_type
, range_type
);
17349 return set_die_type (die
, type
, cu
);
17352 /* Assuming that DIE corresponds to a function, returns nonzero
17353 if the function is prototyped. */
17356 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17358 struct attribute
*attr
;
17360 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17361 if (attr
&& attr
->as_boolean ())
17364 /* The DWARF standard implies that the DW_AT_prototyped attribute
17365 is only meaningful for C, but the concept also extends to other
17366 languages that allow unprototyped functions (Eg: Objective C).
17367 For all other languages, assume that functions are always
17369 if (cu
->per_cu
->lang
!= language_c
17370 && cu
->per_cu
->lang
!= language_objc
17371 && cu
->per_cu
->lang
!= language_opencl
)
17374 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17375 prototyped and unprototyped functions; default to prototyped,
17376 since that is more common in modern code (and RealView warns
17377 about unprototyped functions). */
17378 if (producer_is_realview (cu
->producer
))
17384 /* Handle DIES due to C code like:
17388 int (*funcp)(int a, long l);
17392 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17394 static struct type
*
17395 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17397 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17398 struct type
*type
; /* Type that this function returns. */
17399 struct type
*ftype
; /* Function that returns above type. */
17400 struct attribute
*attr
;
17402 type
= die_type (die
, cu
);
17404 /* The die_type call above may have already set the type for this DIE. */
17405 ftype
= get_die_type (die
, cu
);
17409 ftype
= lookup_function_type (type
);
17411 if (prototyped_function_p (die
, cu
))
17412 ftype
->set_is_prototyped (true);
17414 /* Store the calling convention in the type if it's available in
17415 the subroutine die. Otherwise set the calling convention to
17416 the default value DW_CC_normal. */
17417 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17418 if (attr
!= nullptr
17419 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17420 TYPE_CALLING_CONVENTION (ftype
)
17421 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17422 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17423 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17425 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17427 /* Record whether the function returns normally to its caller or not
17428 if the DWARF producer set that information. */
17429 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17430 if (attr
&& attr
->as_boolean ())
17431 TYPE_NO_RETURN (ftype
) = 1;
17433 /* We need to add the subroutine type to the die immediately so
17434 we don't infinitely recurse when dealing with parameters
17435 declared as the same subroutine type. */
17436 set_die_type (die
, ftype
, cu
);
17438 if (die
->child
!= NULL
)
17440 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17441 struct die_info
*child_die
;
17442 int nparams
, iparams
;
17444 /* Count the number of parameters.
17445 FIXME: GDB currently ignores vararg functions, but knows about
17446 vararg member functions. */
17448 child_die
= die
->child
;
17449 while (child_die
&& child_die
->tag
)
17451 if (child_die
->tag
== DW_TAG_formal_parameter
)
17453 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17454 ftype
->set_has_varargs (true);
17456 child_die
= child_die
->sibling
;
17459 /* Allocate storage for parameters and fill them in. */
17460 ftype
->set_num_fields (nparams
);
17462 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17464 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17465 even if we error out during the parameters reading below. */
17466 for (iparams
= 0; iparams
< nparams
; iparams
++)
17467 ftype
->field (iparams
).set_type (void_type
);
17470 child_die
= die
->child
;
17471 while (child_die
&& child_die
->tag
)
17473 if (child_die
->tag
== DW_TAG_formal_parameter
)
17475 struct type
*arg_type
;
17477 /* DWARF version 2 has no clean way to discern C++
17478 static and non-static member functions. G++ helps
17479 GDB by marking the first parameter for non-static
17480 member functions (which is the this pointer) as
17481 artificial. We pass this information to
17482 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17484 DWARF version 3 added DW_AT_object_pointer, which GCC
17485 4.5 does not yet generate. */
17486 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17487 if (attr
!= nullptr)
17488 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17490 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17491 arg_type
= die_type (child_die
, cu
);
17493 /* RealView does not mark THIS as const, which the testsuite
17494 expects. GCC marks THIS as const in method definitions,
17495 but not in the class specifications (GCC PR 43053). */
17496 if (cu
->per_cu
->lang
== language_cplus
17497 && !TYPE_CONST (arg_type
)
17498 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17501 struct dwarf2_cu
*arg_cu
= cu
;
17502 const char *name
= dwarf2_name (child_die
, cu
);
17504 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17505 if (attr
!= nullptr)
17507 /* If the compiler emits this, use it. */
17508 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17511 else if (name
&& strcmp (name
, "this") == 0)
17512 /* Function definitions will have the argument names. */
17514 else if (name
== NULL
&& iparams
== 0)
17515 /* Declarations may not have the names, so like
17516 elsewhere in GDB, assume an artificial first
17517 argument is "this". */
17521 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17525 ftype
->field (iparams
).set_type (arg_type
);
17528 child_die
= child_die
->sibling
;
17535 static struct type
*
17536 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17538 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17539 const char *name
= NULL
;
17540 struct type
*this_type
, *target_type
;
17542 name
= dwarf2_full_name (NULL
, die
, cu
);
17543 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17544 this_type
->set_target_is_stub (true);
17545 set_die_type (die
, this_type
, cu
);
17546 target_type
= die_type (die
, cu
);
17547 if (target_type
!= this_type
)
17548 TYPE_TARGET_TYPE (this_type
) = target_type
;
17551 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17552 spec and cause infinite loops in GDB. */
17553 complaint (_("Self-referential DW_TAG_typedef "
17554 "- DIE at %s [in module %s]"),
17555 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17556 TYPE_TARGET_TYPE (this_type
) = NULL
;
17560 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17561 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17562 Handle these by just returning the target type, rather than
17563 constructing an anonymous typedef type and trying to handle this
17565 set_die_type (die
, target_type
, cu
);
17566 return target_type
;
17571 /* Helper for get_dwarf2_rational_constant that computes the value of
17572 a given gmp_mpz given an attribute. */
17575 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17577 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17578 location expression that pushes an implicit value. */
17579 if (attr
->form
== DW_FORM_exprloc
)
17581 dwarf_block
*blk
= attr
->as_block ();
17582 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17585 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17586 blk
->data
+ blk
->size
,
17588 if (ptr
- blk
->data
+ len
<= blk
->size
)
17590 mpz_import (value
->val
, len
,
17591 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17597 /* On failure set it to 1. */
17598 *value
= gdb_mpz (1);
17600 else if (attr
->form_is_block ())
17602 dwarf_block
*blk
= attr
->as_block ();
17603 mpz_import (value
->val
, blk
->size
,
17604 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17605 1, 0, 0, blk
->data
);
17608 *value
= gdb_mpz (attr
->constant_value (1));
17611 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17612 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17614 If the numerator and/or numerator attribute is missing,
17615 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17619 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17620 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17622 struct attribute
*num_attr
, *denom_attr
;
17624 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17625 if (num_attr
== nullptr)
17626 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17627 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17629 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17630 if (denom_attr
== nullptr)
17631 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17632 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17634 if (num_attr
== nullptr || denom_attr
== nullptr)
17637 get_mpz (cu
, numerator
, num_attr
);
17638 get_mpz (cu
, denominator
, denom_attr
);
17641 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17642 rational constant, rather than a signed one.
17644 If the rational constant has a negative value, a complaint
17645 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17648 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17649 struct dwarf2_cu
*cu
,
17650 gdb_mpz
*numerator
,
17651 gdb_mpz
*denominator
)
17656 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17657 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17659 mpz_neg (num
.val
, num
.val
);
17660 mpz_neg (denom
.val
, denom
.val
);
17662 else if (mpz_sgn (num
.val
) == -1)
17664 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17666 sect_offset_str (die
->sect_off
));
17669 else if (mpz_sgn (denom
.val
) == -1)
17671 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17673 sect_offset_str (die
->sect_off
));
17677 *numerator
= std::move (num
);
17678 *denominator
= std::move (denom
);
17681 /* Assuming that ENCODING is a string whose contents starting at the
17682 K'th character is "_nn" where "nn" is a decimal number, scan that
17683 number and set RESULT to the value. K is updated to point to the
17684 character immediately following the number.
17686 If the string does not conform to the format described above, false
17687 is returned, and K may or may not be changed. */
17690 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17692 /* The next character should be an underscore ('_') followed
17694 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17697 /* Skip the underscore. */
17701 /* Determine the number of digits for our number. */
17702 while (isdigit (encoding
[k
]))
17707 std::string
copy (&encoding
[start
], k
- start
);
17708 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17714 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17715 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17716 DENOM, update OFFSET, and return true on success. Return false on
17720 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17721 gdb_mpz
*num
, gdb_mpz
*denom
)
17723 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17725 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17728 /* Assuming DIE corresponds to a fixed point type, finish the creation
17729 of the corresponding TYPE by setting its type-specific data. CU is
17730 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17731 encodings. It is nullptr if the GNAT encoding should be
17735 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17736 struct die_info
*die
, struct dwarf2_cu
*cu
)
17738 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17739 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17741 /* If GNAT encodings are preferred, don't examine the
17743 struct attribute
*attr
= nullptr;
17744 if (suffix
== nullptr)
17746 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17747 if (attr
== nullptr)
17748 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17749 if (attr
== nullptr)
17750 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17753 /* Numerator and denominator of our fixed-point type's scaling factor.
17754 The default is a scaling factor of 1, which we use as a fallback
17755 when we are not able to decode it (problem with the debugging info,
17756 unsupported forms, bug in GDB, etc...). Using that as the default
17757 allows us to at least print the unscaled value, which might still
17758 be useful to a user. */
17759 gdb_mpz
scale_num (1);
17760 gdb_mpz
scale_denom (1);
17762 if (attr
== nullptr)
17765 if (suffix
!= nullptr
17766 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17768 /* The number might be encoded as _nn_dd_nn_dd, where the
17769 second ratio is the 'small value. In this situation, we
17770 want the second value. */
17771 && (suffix
[offset
] != '_'
17772 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17779 /* Scaling factor not found. Assume a scaling factor of 1,
17780 and hope for the best. At least the user will be able to
17781 see the encoded value. */
17784 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17785 sect_offset_str (die
->sect_off
));
17788 else if (attr
->name
== DW_AT_binary_scale
)
17790 LONGEST scale_exp
= attr
->constant_value (0);
17791 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17793 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17795 else if (attr
->name
== DW_AT_decimal_scale
)
17797 LONGEST scale_exp
= attr
->constant_value (0);
17798 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17800 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17802 else if (attr
->name
== DW_AT_small
)
17804 struct die_info
*scale_die
;
17805 struct dwarf2_cu
*scale_cu
= cu
;
17807 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17808 if (scale_die
->tag
== DW_TAG_constant
)
17809 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17810 &scale_num
, &scale_denom
);
17812 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17814 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17818 complaint (_("unsupported scale attribute %s for fixed-point type"
17820 dwarf_attr_name (attr
->name
),
17821 sect_offset_str (die
->sect_off
));
17824 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17825 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17826 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17827 mpq_canonicalize (scaling_factor
.val
);
17830 /* The gnat-encoding suffix for fixed point. */
17832 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17834 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17835 "XF" suffix of the name. The text after this is what encodes the
17836 'small and 'delta information. Otherwise, return nullptr. */
17838 static const char *
17839 gnat_encoded_fixed_point_type_info (const char *name
)
17841 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17844 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17845 (which may be different from NAME) to the architecture back-end to allow
17846 it to guess the correct format if necessary. */
17848 static struct type
*
17849 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17850 const char *name_hint
, enum bfd_endian byte_order
)
17852 struct gdbarch
*gdbarch
= objfile
->arch ();
17853 const struct floatformat
**format
;
17856 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17858 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17860 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17865 /* Allocate an integer type of size BITS and name NAME. */
17867 static struct type
*
17868 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17869 int bits
, int unsigned_p
, const char *name
)
17873 /* Versions of Intel's C Compiler generate an integer type called "void"
17874 instead of using DW_TAG_unspecified_type. This has been seen on
17875 at least versions 14, 17, and 18. */
17876 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17877 && strcmp (name
, "void") == 0)
17878 type
= objfile_type (objfile
)->builtin_void
;
17880 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17885 /* Return true if DIE has a DW_AT_small attribute whose value is
17886 a constant rational, where both the numerator and denominator
17889 CU is the DIE's Compilation Unit. */
17892 has_zero_over_zero_small_attribute (struct die_info
*die
,
17893 struct dwarf2_cu
*cu
)
17895 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17896 if (attr
== nullptr)
17899 struct dwarf2_cu
*scale_cu
= cu
;
17900 struct die_info
*scale_die
17901 = follow_die_ref (die
, attr
, &scale_cu
);
17903 if (scale_die
->tag
!= DW_TAG_constant
)
17906 gdb_mpz
num (1), denom (1);
17907 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
17908 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
17911 /* Initialise and return a floating point type of size BITS suitable for
17912 use as a component of a complex number. The NAME_HINT is passed through
17913 when initialising the floating point type and is the name of the complex
17916 As DWARF doesn't currently provide an explicit name for the components
17917 of a complex number, but it can be helpful to have these components
17918 named, we try to select a suitable name based on the size of the
17920 static struct type
*
17921 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17922 struct objfile
*objfile
,
17923 int bits
, const char *name_hint
,
17924 enum bfd_endian byte_order
)
17926 gdbarch
*gdbarch
= objfile
->arch ();
17927 struct type
*tt
= nullptr;
17929 /* Try to find a suitable floating point builtin type of size BITS.
17930 We're going to use the name of this type as the name for the complex
17931 target type that we are about to create. */
17932 switch (cu
->per_cu
->lang
)
17934 case language_fortran
:
17938 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17941 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17943 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17945 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17953 tt
= builtin_type (gdbarch
)->builtin_float
;
17956 tt
= builtin_type (gdbarch
)->builtin_double
;
17958 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17960 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17966 /* If the type we found doesn't match the size we were looking for, then
17967 pretend we didn't find a type at all, the complex target type we
17968 create will then be nameless. */
17969 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17972 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17973 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17976 /* Find a representation of a given base type and install
17977 it in the TYPE field of the die. */
17979 static struct type
*
17980 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17982 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17984 struct attribute
*attr
;
17985 int encoding
= 0, bits
= 0;
17989 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17990 if (attr
!= nullptr && attr
->form_is_constant ())
17991 encoding
= attr
->constant_value (0);
17992 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17993 if (attr
!= nullptr)
17994 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
17995 name
= dwarf2_name (die
, cu
);
17997 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17999 arch
= objfile
->arch ();
18000 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18002 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18003 if (attr
!= nullptr && attr
->form_is_constant ())
18005 int endianity
= attr
->constant_value (0);
18010 byte_order
= BFD_ENDIAN_BIG
;
18012 case DW_END_little
:
18013 byte_order
= BFD_ENDIAN_LITTLE
;
18016 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18021 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18022 && cu
->per_cu
->lang
== language_ada
18023 && has_zero_over_zero_small_attribute (die
, cu
))
18025 /* brobecker/2018-02-24: This is a fixed point type for which
18026 the scaling factor is represented as fraction whose value
18027 does not make sense (zero divided by zero), so we should
18028 normally never see these. However, there is a small category
18029 of fixed point types for which GNAT is unable to provide
18030 the scaling factor via the standard DWARF mechanisms, and
18031 for which the info is provided via the GNAT encodings instead.
18032 This is likely what this DIE is about. */
18033 encoding
= (encoding
== DW_ATE_signed_fixed
18035 : DW_ATE_unsigned
);
18038 /* With GNAT encodings, fixed-point information will be encoded in
18039 the type name. Note that this can also occur with the above
18040 zero-over-zero case, which is why this is a separate "if" rather
18041 than an "else if". */
18042 const char *gnat_encoding_suffix
= nullptr;
18043 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18044 && cu
->per_cu
->lang
== language_ada
18045 && name
!= nullptr)
18047 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18048 if (gnat_encoding_suffix
!= nullptr)
18050 gdb_assert (startswith (gnat_encoding_suffix
,
18051 GNAT_FIXED_POINT_SUFFIX
));
18052 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18053 name
, gnat_encoding_suffix
- name
);
18054 /* Use -1 here so that SUFFIX points at the "_" after the
18056 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18058 encoding
= (encoding
== DW_ATE_signed
18059 ? DW_ATE_signed_fixed
18060 : DW_ATE_unsigned_fixed
);
18066 case DW_ATE_address
:
18067 /* Turn DW_ATE_address into a void * pointer. */
18068 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18069 type
= init_pointer_type (objfile
, bits
, name
, type
);
18071 case DW_ATE_boolean
:
18072 type
= init_boolean_type (objfile
, bits
, 1, name
);
18074 case DW_ATE_complex_float
:
18075 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18077 if (type
->code () == TYPE_CODE_ERROR
)
18079 if (name
== nullptr)
18081 struct obstack
*obstack
18082 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18083 name
= obconcat (obstack
, "_Complex ", type
->name (),
18086 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18089 type
= init_complex_type (name
, type
);
18091 case DW_ATE_decimal_float
:
18092 type
= init_decfloat_type (objfile
, bits
, name
);
18095 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18097 case DW_ATE_signed
:
18098 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18100 case DW_ATE_unsigned
:
18101 if (cu
->per_cu
->lang
== language_fortran
18103 && startswith (name
, "character("))
18104 type
= init_character_type (objfile
, bits
, 1, name
);
18106 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18108 case DW_ATE_signed_char
:
18109 if (cu
->per_cu
->lang
== language_ada
18110 || cu
->per_cu
->lang
== language_m2
18111 || cu
->per_cu
->lang
== language_pascal
18112 || cu
->per_cu
->lang
== language_fortran
)
18113 type
= init_character_type (objfile
, bits
, 0, name
);
18115 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18117 case DW_ATE_unsigned_char
:
18118 if (cu
->per_cu
->lang
== language_ada
18119 || cu
->per_cu
->lang
== language_m2
18120 || cu
->per_cu
->lang
== language_pascal
18121 || cu
->per_cu
->lang
== language_fortran
18122 || cu
->per_cu
->lang
== language_rust
)
18123 type
= init_character_type (objfile
, bits
, 1, name
);
18125 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18130 type
= builtin_type (arch
)->builtin_char16
;
18131 else if (bits
== 32)
18132 type
= builtin_type (arch
)->builtin_char32
;
18135 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18137 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18139 return set_die_type (die
, type
, cu
);
18142 case DW_ATE_signed_fixed
:
18143 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18144 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18146 case DW_ATE_unsigned_fixed
:
18147 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18148 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18152 complaint (_("unsupported DW_AT_encoding: '%s'"),
18153 dwarf_type_encoding_name (encoding
));
18154 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18158 if (name
&& strcmp (name
, "char") == 0)
18159 type
->set_has_no_signedness (true);
18161 maybe_set_alignment (cu
, die
, type
);
18163 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18165 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18167 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18168 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18170 unsigned real_bit_size
= attr
->as_unsigned ();
18171 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18172 /* Only use the attributes if they make sense together. */
18173 if (attr
== nullptr
18174 || (attr
->as_unsigned () + real_bit_size
18175 <= 8 * TYPE_LENGTH (type
)))
18177 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18179 if (attr
!= nullptr)
18180 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18181 = attr
->as_unsigned ();
18186 return set_die_type (die
, type
, cu
);
18189 /* A helper function that returns the name of DIE, if it refers to a
18190 variable declaration. */
18192 static const char *
18193 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18195 if (die
->tag
!= DW_TAG_variable
)
18198 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18199 if (attr
== nullptr || !attr
->as_boolean ())
18202 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18203 if (attr
== nullptr)
18205 return attr
->as_string ();
18208 /* Parse dwarf attribute if it's a block, reference or constant and put the
18209 resulting value of the attribute into struct bound_prop.
18210 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18213 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18214 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18215 struct type
*default_type
)
18217 struct dwarf2_property_baton
*baton
;
18218 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18219 struct objfile
*objfile
= per_objfile
->objfile
;
18220 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18222 gdb_assert (default_type
!= NULL
);
18224 if (attr
== NULL
|| prop
== NULL
)
18227 if (attr
->form_is_block ())
18229 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18230 baton
->property_type
= default_type
;
18231 baton
->locexpr
.per_cu
= cu
->per_cu
;
18232 baton
->locexpr
.per_objfile
= per_objfile
;
18234 struct dwarf_block
*block
= attr
->as_block ();
18235 baton
->locexpr
.size
= block
->size
;
18236 baton
->locexpr
.data
= block
->data
;
18237 switch (attr
->name
)
18239 case DW_AT_string_length
:
18240 baton
->locexpr
.is_reference
= true;
18243 baton
->locexpr
.is_reference
= false;
18247 prop
->set_locexpr (baton
);
18248 gdb_assert (prop
->baton () != NULL
);
18250 else if (attr
->form_is_ref ())
18252 struct dwarf2_cu
*target_cu
= cu
;
18253 struct die_info
*target_die
;
18254 struct attribute
*target_attr
;
18256 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18257 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18258 if (target_attr
== NULL
)
18259 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18261 if (target_attr
== NULL
)
18263 const char *name
= var_decl_name (target_die
, target_cu
);
18264 if (name
!= nullptr)
18266 prop
->set_variable_name (name
);
18272 switch (target_attr
->name
)
18274 case DW_AT_location
:
18275 if (target_attr
->form_is_section_offset ())
18277 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18278 baton
->property_type
= die_type (target_die
, target_cu
);
18279 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18280 prop
->set_loclist (baton
);
18281 gdb_assert (prop
->baton () != NULL
);
18283 else if (target_attr
->form_is_block ())
18285 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18286 baton
->property_type
= die_type (target_die
, target_cu
);
18287 baton
->locexpr
.per_cu
= cu
->per_cu
;
18288 baton
->locexpr
.per_objfile
= per_objfile
;
18289 struct dwarf_block
*block
= target_attr
->as_block ();
18290 baton
->locexpr
.size
= block
->size
;
18291 baton
->locexpr
.data
= block
->data
;
18292 baton
->locexpr
.is_reference
= true;
18293 prop
->set_locexpr (baton
);
18294 gdb_assert (prop
->baton () != NULL
);
18298 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18299 "dynamic property");
18303 case DW_AT_data_member_location
:
18307 if (!handle_data_member_location (target_die
, target_cu
,
18311 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18312 baton
->property_type
= read_type_die (target_die
->parent
,
18314 baton
->offset_info
.offset
= offset
;
18315 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18316 prop
->set_addr_offset (baton
);
18321 else if (attr
->form_is_constant ())
18322 prop
->set_const_val (attr
->constant_value (0));
18325 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18326 dwarf2_name (die
, cu
));
18336 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18338 struct type
*int_type
;
18340 /* Helper macro to examine the various builtin types. */
18341 #define TRY_TYPE(F) \
18342 int_type = (unsigned_p \
18343 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18344 : objfile_type (objfile)->builtin_ ## F); \
18345 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18352 TRY_TYPE (long_long
);
18356 gdb_assert_not_reached ("unable to find suitable integer type");
18359 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18360 present (which is valid) then compute the default type based on the
18361 compilation units address size. */
18363 static struct type
*
18364 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18366 struct type
*index_type
= die_type (die
, cu
);
18368 /* Dwarf-2 specifications explicitly allows to create subrange types
18369 without specifying a base type.
18370 In that case, the base type must be set to the type of
18371 the lower bound, upper bound or count, in that order, if any of these
18372 three attributes references an object that has a type.
18373 If no base type is found, the Dwarf-2 specifications say that
18374 a signed integer type of size equal to the size of an address should
18376 For the following C code: `extern char gdb_int [];'
18377 GCC produces an empty range DIE.
18378 FIXME: muller/2010-05-28: Possible references to object for low bound,
18379 high bound or count are not yet handled by this code. */
18380 if (index_type
->code () == TYPE_CODE_VOID
)
18381 index_type
= cu
->addr_sized_int_type (false);
18386 /* Read the given DW_AT_subrange DIE. */
18388 static struct type
*
18389 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18391 struct type
*base_type
, *orig_base_type
;
18392 struct type
*range_type
;
18393 struct attribute
*attr
;
18394 struct dynamic_prop low
, high
;
18395 int low_default_is_valid
;
18396 int high_bound_is_count
= 0;
18398 ULONGEST negative_mask
;
18400 orig_base_type
= read_subrange_index_type (die
, cu
);
18402 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18403 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18404 creating the range type, but we use the result of check_typedef
18405 when examining properties of the type. */
18406 base_type
= check_typedef (orig_base_type
);
18408 /* The die_type call above may have already set the type for this DIE. */
18409 range_type
= get_die_type (die
, cu
);
18413 high
.set_const_val (0);
18415 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18416 omitting DW_AT_lower_bound. */
18417 switch (cu
->per_cu
->lang
)
18420 case language_cplus
:
18421 low
.set_const_val (0);
18422 low_default_is_valid
= 1;
18424 case language_fortran
:
18425 low
.set_const_val (1);
18426 low_default_is_valid
= 1;
18429 case language_objc
:
18430 case language_rust
:
18431 low
.set_const_val (0);
18432 low_default_is_valid
= (cu
->header
.version
>= 4);
18436 case language_pascal
:
18437 low
.set_const_val (1);
18438 low_default_is_valid
= (cu
->header
.version
>= 4);
18441 low
.set_const_val (0);
18442 low_default_is_valid
= 0;
18446 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18447 if (attr
!= nullptr)
18448 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18449 else if (!low_default_is_valid
)
18450 complaint (_("Missing DW_AT_lower_bound "
18451 "- DIE at %s [in module %s]"),
18452 sect_offset_str (die
->sect_off
),
18453 objfile_name (cu
->per_objfile
->objfile
));
18455 struct attribute
*attr_ub
, *attr_count
;
18456 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18457 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18459 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18460 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18462 /* If bounds are constant do the final calculation here. */
18463 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18464 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18466 high_bound_is_count
= 1;
18470 if (attr_ub
!= NULL
)
18471 complaint (_("Unresolved DW_AT_upper_bound "
18472 "- DIE at %s [in module %s]"),
18473 sect_offset_str (die
->sect_off
),
18474 objfile_name (cu
->per_objfile
->objfile
));
18475 if (attr_count
!= NULL
)
18476 complaint (_("Unresolved DW_AT_count "
18477 "- DIE at %s [in module %s]"),
18478 sect_offset_str (die
->sect_off
),
18479 objfile_name (cu
->per_objfile
->objfile
));
18484 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18485 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18486 bias
= bias_attr
->constant_value (0);
18488 /* Normally, the DWARF producers are expected to use a signed
18489 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18490 But this is unfortunately not always the case, as witnessed
18491 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18492 is used instead. To work around that ambiguity, we treat
18493 the bounds as signed, and thus sign-extend their values, when
18494 the base type is signed. */
18496 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18497 if (low
.kind () == PROP_CONST
18498 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18499 low
.set_const_val (low
.const_val () | negative_mask
);
18500 if (high
.kind () == PROP_CONST
18501 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18502 high
.set_const_val (high
.const_val () | negative_mask
);
18504 /* Check for bit and byte strides. */
18505 struct dynamic_prop byte_stride_prop
;
18506 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18507 if (attr_byte_stride
!= nullptr)
18509 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18510 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18514 struct dynamic_prop bit_stride_prop
;
18515 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18516 if (attr_bit_stride
!= nullptr)
18518 /* It only makes sense to have either a bit or byte stride. */
18519 if (attr_byte_stride
!= nullptr)
18521 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18522 "- DIE at %s [in module %s]"),
18523 sect_offset_str (die
->sect_off
),
18524 objfile_name (cu
->per_objfile
->objfile
));
18525 attr_bit_stride
= nullptr;
18529 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18530 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18535 if (attr_byte_stride
!= nullptr
18536 || attr_bit_stride
!= nullptr)
18538 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18539 struct dynamic_prop
*stride
18540 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18543 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18544 &high
, bias
, stride
, byte_stride_p
);
18547 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18549 if (high_bound_is_count
)
18550 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18552 /* Ada expects an empty array on no boundary attributes. */
18553 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
18554 range_type
->bounds ()->high
.set_undefined ();
18556 name
= dwarf2_name (die
, cu
);
18558 range_type
->set_name (name
);
18560 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18561 if (attr
!= nullptr)
18562 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18564 maybe_set_alignment (cu
, die
, range_type
);
18566 set_die_type (die
, range_type
, cu
);
18568 /* set_die_type should be already done. */
18569 set_descriptive_type (range_type
, die
, cu
);
18574 static struct type
*
18575 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18579 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18580 type
->set_name (dwarf2_name (die
, cu
));
18582 /* In Ada, an unspecified type is typically used when the description
18583 of the type is deferred to a different unit. When encountering
18584 such a type, we treat it as a stub, and try to resolve it later on,
18586 if (cu
->per_cu
->lang
== language_ada
)
18587 type
->set_is_stub (true);
18589 return set_die_type (die
, type
, cu
);
18592 /* Read a single die and all its descendents. Set the die's sibling
18593 field to NULL; set other fields in the die correctly, and set all
18594 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18595 location of the info_ptr after reading all of those dies. PARENT
18596 is the parent of the die in question. */
18598 static struct die_info
*
18599 read_die_and_children (const struct die_reader_specs
*reader
,
18600 const gdb_byte
*info_ptr
,
18601 const gdb_byte
**new_info_ptr
,
18602 struct die_info
*parent
)
18604 struct die_info
*die
;
18605 const gdb_byte
*cur_ptr
;
18607 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18610 *new_info_ptr
= cur_ptr
;
18613 store_in_ref_table (die
, reader
->cu
);
18615 if (die
->has_children
)
18616 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18620 *new_info_ptr
= cur_ptr
;
18623 die
->sibling
= NULL
;
18624 die
->parent
= parent
;
18628 /* Read a die, all of its descendents, and all of its siblings; set
18629 all of the fields of all of the dies correctly. Arguments are as
18630 in read_die_and_children. */
18632 static struct die_info
*
18633 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18634 const gdb_byte
*info_ptr
,
18635 const gdb_byte
**new_info_ptr
,
18636 struct die_info
*parent
)
18638 struct die_info
*first_die
, *last_sibling
;
18639 const gdb_byte
*cur_ptr
;
18641 cur_ptr
= info_ptr
;
18642 first_die
= last_sibling
= NULL
;
18646 struct die_info
*die
18647 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18651 *new_info_ptr
= cur_ptr
;
18658 last_sibling
->sibling
= die
;
18660 last_sibling
= die
;
18664 /* Read a die, all of its descendents, and all of its siblings; set
18665 all of the fields of all of the dies correctly. Arguments are as
18666 in read_die_and_children.
18667 This the main entry point for reading a DIE and all its children. */
18669 static struct die_info
*
18670 read_die_and_siblings (const struct die_reader_specs
*reader
,
18671 const gdb_byte
*info_ptr
,
18672 const gdb_byte
**new_info_ptr
,
18673 struct die_info
*parent
)
18675 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18676 new_info_ptr
, parent
);
18678 if (dwarf_die_debug
)
18680 fprintf_unfiltered (gdb_stdlog
,
18681 "Read die from %s@0x%x of %s:\n",
18682 reader
->die_section
->get_name (),
18683 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18684 bfd_get_filename (reader
->abfd
));
18685 dump_die (die
, dwarf_die_debug
);
18691 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18693 The caller is responsible for filling in the extra attributes
18694 and updating (*DIEP)->num_attrs.
18695 Set DIEP to point to a newly allocated die with its information,
18696 except for its child, sibling, and parent fields. */
18698 static const gdb_byte
*
18699 read_full_die_1 (const struct die_reader_specs
*reader
,
18700 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18701 int num_extra_attrs
)
18703 unsigned int abbrev_number
, bytes_read
, i
;
18704 const struct abbrev_info
*abbrev
;
18705 struct die_info
*die
;
18706 struct dwarf2_cu
*cu
= reader
->cu
;
18707 bfd
*abfd
= reader
->abfd
;
18709 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18710 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18711 info_ptr
+= bytes_read
;
18712 if (!abbrev_number
)
18718 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18720 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18722 bfd_get_filename (abfd
));
18724 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18725 die
->sect_off
= sect_off
;
18726 die
->tag
= abbrev
->tag
;
18727 die
->abbrev
= abbrev_number
;
18728 die
->has_children
= abbrev
->has_children
;
18730 /* Make the result usable.
18731 The caller needs to update num_attrs after adding the extra
18733 die
->num_attrs
= abbrev
->num_attrs
;
18735 bool any_need_reprocess
= false;
18736 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18738 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18740 if (die
->attrs
[i
].requires_reprocessing_p ())
18741 any_need_reprocess
= true;
18744 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18745 if (attr
!= nullptr && attr
->form_is_unsigned ())
18746 cu
->str_offsets_base
= attr
->as_unsigned ();
18748 attr
= die
->attr (DW_AT_loclists_base
);
18749 if (attr
!= nullptr)
18750 cu
->loclist_base
= attr
->as_unsigned ();
18752 auto maybe_addr_base
= die
->addr_base ();
18753 if (maybe_addr_base
.has_value ())
18754 cu
->addr_base
= *maybe_addr_base
;
18756 attr
= die
->attr (DW_AT_rnglists_base
);
18757 if (attr
!= nullptr)
18758 cu
->rnglists_base
= attr
->as_unsigned ();
18760 if (any_need_reprocess
)
18762 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18764 if (die
->attrs
[i
].requires_reprocessing_p ())
18765 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18772 /* Read a die and all its attributes.
18773 Set DIEP to point to a newly allocated die with its information,
18774 except for its child, sibling, and parent fields. */
18776 static const gdb_byte
*
18777 read_full_die (const struct die_reader_specs
*reader
,
18778 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18780 const gdb_byte
*result
;
18782 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18784 if (dwarf_die_debug
)
18786 fprintf_unfiltered (gdb_stdlog
,
18787 "Read die from %s@0x%x of %s:\n",
18788 reader
->die_section
->get_name (),
18789 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18790 bfd_get_filename (reader
->abfd
));
18791 dump_die (*diep
, dwarf_die_debug
);
18798 /* Returns nonzero if TAG represents a type that we might generate a partial
18802 is_type_tag_for_partial (int tag
, enum language lang
)
18807 /* Some types that would be reasonable to generate partial symbols for,
18808 that we don't at present. Note that normally this does not
18809 matter, mainly because C compilers don't give names to these
18810 types, but instead emit DW_TAG_typedef. */
18811 case DW_TAG_file_type
:
18812 case DW_TAG_ptr_to_member_type
:
18813 case DW_TAG_set_type
:
18814 case DW_TAG_string_type
:
18815 case DW_TAG_subroutine_type
:
18818 /* GNAT may emit an array with a name, but no typedef, so we
18819 need to make a symbol in this case. */
18820 case DW_TAG_array_type
:
18821 return lang
== language_ada
;
18823 case DW_TAG_base_type
:
18824 case DW_TAG_class_type
:
18825 case DW_TAG_interface_type
:
18826 case DW_TAG_enumeration_type
:
18827 case DW_TAG_structure_type
:
18828 case DW_TAG_subrange_type
:
18829 case DW_TAG_typedef
:
18830 case DW_TAG_union_type
:
18837 /* Load all DIEs that are interesting for partial symbols into memory. */
18839 static struct partial_die_info
*
18840 load_partial_dies (const struct die_reader_specs
*reader
,
18841 const gdb_byte
*info_ptr
, int building_psymtab
)
18843 struct dwarf2_cu
*cu
= reader
->cu
;
18844 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18845 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18846 unsigned int bytes_read
;
18847 unsigned int load_all
= 0;
18848 int nesting_level
= 1;
18853 gdb_assert (cu
->per_cu
!= NULL
);
18854 if (cu
->load_all_dies
)
18858 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18862 &cu
->comp_unit_obstack
,
18863 hashtab_obstack_allocate
,
18864 dummy_obstack_deallocate
);
18868 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
18871 /* A NULL abbrev means the end of a series of children. */
18872 if (abbrev
== NULL
)
18874 if (--nesting_level
== 0)
18877 info_ptr
+= bytes_read
;
18878 last_die
= parent_die
;
18879 parent_die
= parent_die
->die_parent
;
18883 /* Check for template arguments. We never save these; if
18884 they're seen, we just mark the parent, and go on our way. */
18885 if (parent_die
!= NULL
18886 && cu
->per_cu
->lang
== language_cplus
18887 && (abbrev
->tag
== DW_TAG_template_type_param
18888 || abbrev
->tag
== DW_TAG_template_value_param
))
18890 parent_die
->has_template_arguments
= 1;
18894 /* We don't need a partial DIE for the template argument. */
18895 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18900 /* We only recurse into c++ subprograms looking for template arguments.
18901 Skip their other children. */
18903 && cu
->per_cu
->lang
== language_cplus
18904 && parent_die
!= NULL
18905 && parent_die
->tag
== DW_TAG_subprogram
18906 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18908 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18912 /* Check whether this DIE is interesting enough to save. Normally
18913 we would not be interested in members here, but there may be
18914 later variables referencing them via DW_AT_specification (for
18915 static members). */
18917 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
18918 && abbrev
->tag
!= DW_TAG_constant
18919 && abbrev
->tag
!= DW_TAG_enumerator
18920 && abbrev
->tag
!= DW_TAG_subprogram
18921 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18922 && abbrev
->tag
!= DW_TAG_lexical_block
18923 && abbrev
->tag
!= DW_TAG_variable
18924 && abbrev
->tag
!= DW_TAG_namespace
18925 && abbrev
->tag
!= DW_TAG_module
18926 && abbrev
->tag
!= DW_TAG_member
18927 && abbrev
->tag
!= DW_TAG_imported_unit
18928 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18930 /* Otherwise we skip to the next sibling, if any. */
18931 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18935 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18938 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18940 /* This two-pass algorithm for processing partial symbols has a
18941 high cost in cache pressure. Thus, handle some simple cases
18942 here which cover the majority of C partial symbols. DIEs
18943 which neither have specification tags in them, nor could have
18944 specification tags elsewhere pointing at them, can simply be
18945 processed and discarded.
18947 This segment is also optional; scan_partial_symbols and
18948 add_partial_symbol will handle these DIEs if we chain
18949 them in normally. When compilers which do not emit large
18950 quantities of duplicate debug information are more common,
18951 this code can probably be removed. */
18953 /* Any complete simple types at the top level (pretty much all
18954 of them, for a language without namespaces), can be processed
18956 if (parent_die
== NULL
18957 && pdi
.has_specification
== 0
18958 && pdi
.is_declaration
== 0
18959 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18960 || pdi
.tag
== DW_TAG_base_type
18961 || pdi
.tag
== DW_TAG_array_type
18962 || pdi
.tag
== DW_TAG_subrange_type
))
18964 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18965 add_partial_symbol (&pdi
, cu
);
18967 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18971 /* The exception for DW_TAG_typedef with has_children above is
18972 a workaround of GCC PR debug/47510. In the case of this complaint
18973 type_name_or_error will error on such types later.
18975 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18976 it could not find the child DIEs referenced later, this is checked
18977 above. In correct DWARF DW_TAG_typedef should have no children. */
18979 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18980 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18981 "- DIE at %s [in module %s]"),
18982 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18984 /* If we're at the second level, and we're an enumerator, and
18985 our parent has no specification (meaning possibly lives in a
18986 namespace elsewhere), then we can add the partial symbol now
18987 instead of queueing it. */
18988 if (pdi
.tag
== DW_TAG_enumerator
18989 && parent_die
!= NULL
18990 && parent_die
->die_parent
== NULL
18991 && parent_die
->tag
== DW_TAG_enumeration_type
18992 && parent_die
->has_specification
== 0)
18994 if (pdi
.raw_name
== NULL
)
18995 complaint (_("malformed enumerator DIE ignored"));
18996 else if (building_psymtab
)
18997 add_partial_symbol (&pdi
, cu
);
18999 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19003 struct partial_die_info
*part_die
19004 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19006 /* We'll save this DIE so link it in. */
19007 part_die
->die_parent
= parent_die
;
19008 part_die
->die_sibling
= NULL
;
19009 part_die
->die_child
= NULL
;
19011 if (last_die
&& last_die
== parent_die
)
19012 last_die
->die_child
= part_die
;
19014 last_die
->die_sibling
= part_die
;
19016 last_die
= part_die
;
19018 if (first_die
== NULL
)
19019 first_die
= part_die
;
19021 /* Maybe add the DIE to the hash table. Not all DIEs that we
19022 find interesting need to be in the hash table, because we
19023 also have the parent/sibling/child chains; only those that we
19024 might refer to by offset later during partial symbol reading.
19026 For now this means things that might have be the target of a
19027 DW_AT_specification, DW_AT_abstract_origin, or
19028 DW_AT_extension. DW_AT_extension will refer only to
19029 namespaces; DW_AT_abstract_origin refers to functions (and
19030 many things under the function DIE, but we do not recurse
19031 into function DIEs during partial symbol reading) and
19032 possibly variables as well; DW_AT_specification refers to
19033 declarations. Declarations ought to have the DW_AT_declaration
19034 flag. It happens that GCC forgets to put it in sometimes, but
19035 only for functions, not for types.
19037 Adding more things than necessary to the hash table is harmless
19038 except for the performance cost. Adding too few will result in
19039 wasted time in find_partial_die, when we reread the compilation
19040 unit with load_all_dies set. */
19043 || abbrev
->tag
== DW_TAG_constant
19044 || abbrev
->tag
== DW_TAG_subprogram
19045 || abbrev
->tag
== DW_TAG_variable
19046 || abbrev
->tag
== DW_TAG_namespace
19047 || part_die
->is_declaration
)
19051 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19052 to_underlying (part_die
->sect_off
),
19057 /* For some DIEs we want to follow their children (if any). For C
19058 we have no reason to follow the children of structures; for other
19059 languages we have to, so that we can get at method physnames
19060 to infer fully qualified class names, for DW_AT_specification,
19061 and for C++ template arguments. For C++, we also look one level
19062 inside functions to find template arguments (if the name of the
19063 function does not already contain the template arguments).
19065 For Ada and Fortran, we need to scan the children of subprograms
19066 and lexical blocks as well because these languages allow the
19067 definition of nested entities that could be interesting for the
19068 debugger, such as nested subprograms for instance. */
19069 if (last_die
->has_children
19071 || last_die
->tag
== DW_TAG_namespace
19072 || last_die
->tag
== DW_TAG_module
19073 || last_die
->tag
== DW_TAG_enumeration_type
19074 || (cu
->per_cu
->lang
== language_cplus
19075 && last_die
->tag
== DW_TAG_subprogram
19076 && (last_die
->raw_name
== NULL
19077 || strchr (last_die
->raw_name
, '<') == NULL
))
19078 || (cu
->per_cu
->lang
!= language_c
19079 && (last_die
->tag
== DW_TAG_class_type
19080 || last_die
->tag
== DW_TAG_interface_type
19081 || last_die
->tag
== DW_TAG_structure_type
19082 || last_die
->tag
== DW_TAG_union_type
))
19083 || ((cu
->per_cu
->lang
== language_ada
19084 || cu
->per_cu
->lang
== language_fortran
)
19085 && (last_die
->tag
== DW_TAG_subprogram
19086 || last_die
->tag
== DW_TAG_lexical_block
))))
19089 parent_die
= last_die
;
19093 /* Otherwise we skip to the next sibling, if any. */
19094 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19096 /* Back to the top, do it again. */
19100 partial_die_info::partial_die_info (sect_offset sect_off_
,
19101 const struct abbrev_info
*abbrev
)
19102 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19106 /* See class definition. */
19109 partial_die_info::name (dwarf2_cu
*cu
)
19111 if (!canonical_name
&& raw_name
!= nullptr)
19113 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19114 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19115 canonical_name
= 1;
19121 /* Read a minimal amount of information into the minimal die structure.
19122 INFO_PTR should point just after the initial uleb128 of a DIE. */
19125 partial_die_info::read (const struct die_reader_specs
*reader
,
19126 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19128 struct dwarf2_cu
*cu
= reader
->cu
;
19129 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19131 int has_low_pc_attr
= 0;
19132 int has_high_pc_attr
= 0;
19133 int high_pc_relative
= 0;
19135 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19138 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19139 /* String and address offsets that need to do the reprocessing have
19140 already been read at this point, so there is no need to wait until
19141 the loop terminates to do the reprocessing. */
19142 if (attr
.requires_reprocessing_p ())
19143 read_attribute_reprocess (reader
, &attr
, tag
);
19144 /* Store the data if it is of an attribute we want to keep in a
19145 partial symbol table. */
19151 case DW_TAG_compile_unit
:
19152 case DW_TAG_partial_unit
:
19153 case DW_TAG_type_unit
:
19154 /* Compilation units have a DW_AT_name that is a filename, not
19155 a source language identifier. */
19156 case DW_TAG_enumeration_type
:
19157 case DW_TAG_enumerator
:
19158 /* These tags always have simple identifiers already; no need
19159 to canonicalize them. */
19160 canonical_name
= 1;
19161 raw_name
= attr
.as_string ();
19164 canonical_name
= 0;
19165 raw_name
= attr
.as_string ();
19169 case DW_AT_linkage_name
:
19170 case DW_AT_MIPS_linkage_name
:
19171 /* Note that both forms of linkage name might appear. We
19172 assume they will be the same, and we only store the last
19174 linkage_name
= attr
.as_string ();
19177 has_low_pc_attr
= 1;
19178 lowpc
= attr
.as_address ();
19180 case DW_AT_high_pc
:
19181 has_high_pc_attr
= 1;
19182 highpc
= attr
.as_address ();
19183 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19184 high_pc_relative
= 1;
19186 case DW_AT_location
:
19187 /* Support the .debug_loc offsets. */
19188 if (attr
.form_is_block ())
19190 d
.locdesc
= attr
.as_block ();
19192 else if (attr
.form_is_section_offset ())
19194 dwarf2_complex_location_expr_complaint ();
19198 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19199 "partial symbol information");
19202 case DW_AT_external
:
19203 is_external
= attr
.as_boolean ();
19205 case DW_AT_declaration
:
19206 is_declaration
= attr
.as_boolean ();
19211 case DW_AT_abstract_origin
:
19212 case DW_AT_specification
:
19213 case DW_AT_extension
:
19214 has_specification
= 1;
19215 spec_offset
= attr
.get_ref_die_offset ();
19216 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19217 || cu
->per_cu
->is_dwz
);
19219 case DW_AT_sibling
:
19220 /* Ignore absolute siblings, they might point outside of
19221 the current compile unit. */
19222 if (attr
.form
== DW_FORM_ref_addr
)
19223 complaint (_("ignoring absolute DW_AT_sibling"));
19226 const gdb_byte
*buffer
= reader
->buffer
;
19227 sect_offset off
= attr
.get_ref_die_offset ();
19228 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19230 if (sibling_ptr
< info_ptr
)
19231 complaint (_("DW_AT_sibling points backwards"));
19232 else if (sibling_ptr
> reader
->buffer_end
)
19233 reader
->die_section
->overflow_complaint ();
19235 sibling
= sibling_ptr
;
19238 case DW_AT_byte_size
:
19241 case DW_AT_const_value
:
19242 has_const_value
= 1;
19244 case DW_AT_calling_convention
:
19245 /* DWARF doesn't provide a way to identify a program's source-level
19246 entry point. DW_AT_calling_convention attributes are only meant
19247 to describe functions' calling conventions.
19249 However, because it's a necessary piece of information in
19250 Fortran, and before DWARF 4 DW_CC_program was the only
19251 piece of debugging information whose definition refers to
19252 a 'main program' at all, several compilers marked Fortran
19253 main programs with DW_CC_program --- even when those
19254 functions use the standard calling conventions.
19256 Although DWARF now specifies a way to provide this
19257 information, we support this practice for backward
19259 if (attr
.constant_value (0) == DW_CC_program
19260 && cu
->per_cu
->lang
== language_fortran
)
19261 main_subprogram
= 1;
19265 LONGEST value
= attr
.constant_value (-1);
19266 if (value
== DW_INL_inlined
19267 || value
== DW_INL_declared_inlined
)
19268 may_be_inlined
= 1;
19273 if (tag
== DW_TAG_imported_unit
)
19275 d
.sect_off
= attr
.get_ref_die_offset ();
19276 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19277 || cu
->per_cu
->is_dwz
);
19281 case DW_AT_main_subprogram
:
19282 main_subprogram
= attr
.as_boolean ();
19287 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19288 on DWARF version). */
19289 ULONGEST ranges_offset
= attr
.as_unsigned ();
19291 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19293 if (tag
!= DW_TAG_compile_unit
)
19294 ranges_offset
+= cu
->gnu_ranges_base
;
19296 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19307 /* For Ada, if both the name and the linkage name appear, we prefer
19308 the latter. This lets "catch exception" work better, regardless
19309 of the order in which the name and linkage name were emitted.
19310 Really, though, this is just a workaround for the fact that gdb
19311 doesn't store both the name and the linkage name. */
19312 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
19313 raw_name
= linkage_name
;
19315 if (high_pc_relative
)
19318 if (has_low_pc_attr
&& has_high_pc_attr
)
19320 /* When using the GNU linker, .gnu.linkonce. sections are used to
19321 eliminate duplicate copies of functions and vtables and such.
19322 The linker will arbitrarily choose one and discard the others.
19323 The AT_*_pc values for such functions refer to local labels in
19324 these sections. If the section from that file was discarded, the
19325 labels are not in the output, so the relocs get a value of 0.
19326 If this is a discarded function, mark the pc bounds as invalid,
19327 so that GDB will ignore it. */
19328 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19330 struct objfile
*objfile
= per_objfile
->objfile
;
19331 struct gdbarch
*gdbarch
= objfile
->arch ();
19333 complaint (_("DW_AT_low_pc %s is zero "
19334 "for DIE at %s [in module %s]"),
19335 paddress (gdbarch
, lowpc
),
19336 sect_offset_str (sect_off
),
19337 objfile_name (objfile
));
19339 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19340 else if (lowpc
>= highpc
)
19342 struct objfile
*objfile
= per_objfile
->objfile
;
19343 struct gdbarch
*gdbarch
= objfile
->arch ();
19345 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19346 "for DIE at %s [in module %s]"),
19347 paddress (gdbarch
, lowpc
),
19348 paddress (gdbarch
, highpc
),
19349 sect_offset_str (sect_off
),
19350 objfile_name (objfile
));
19359 /* Find a cached partial DIE at OFFSET in CU. */
19361 struct partial_die_info
*
19362 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19364 struct partial_die_info
*lookup_die
= NULL
;
19365 struct partial_die_info
part_die (sect_off
);
19367 lookup_die
= ((struct partial_die_info
*)
19368 htab_find_with_hash (partial_dies
, &part_die
,
19369 to_underlying (sect_off
)));
19374 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19375 except in the case of .debug_types DIEs which do not reference
19376 outside their CU (they do however referencing other types via
19377 DW_FORM_ref_sig8). */
19379 static const struct cu_partial_die_info
19380 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19382 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19383 struct objfile
*objfile
= per_objfile
->objfile
;
19384 struct partial_die_info
*pd
= NULL
;
19386 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19387 && cu
->header
.offset_in_cu_p (sect_off
))
19389 pd
= cu
->find_partial_die (sect_off
);
19392 /* We missed recording what we needed.
19393 Load all dies and try again. */
19397 /* TUs don't reference other CUs/TUs (except via type signatures). */
19398 if (cu
->per_cu
->is_debug_types
)
19400 error (_("Dwarf Error: Type Unit at offset %s contains"
19401 " external reference to offset %s [in module %s].\n"),
19402 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19403 bfd_get_filename (objfile
->obfd
));
19405 dwarf2_per_cu_data
*per_cu
19406 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19409 cu
= per_objfile
->get_cu (per_cu
);
19410 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19411 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19413 cu
= per_objfile
->get_cu (per_cu
);
19416 pd
= cu
->find_partial_die (sect_off
);
19419 /* If we didn't find it, and not all dies have been loaded,
19420 load them all and try again. */
19422 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19424 cu
->load_all_dies
= 1;
19426 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19427 THIS_CU->cu may already be in use. So we can't just free it and
19428 replace its DIEs with the ones we read in. Instead, we leave those
19429 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19430 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19432 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19434 pd
= cu
->find_partial_die (sect_off
);
19438 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19439 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19443 /* See if we can figure out if the class lives in a namespace. We do
19444 this by looking for a member function; its demangled name will
19445 contain namespace info, if there is any. */
19448 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19449 struct dwarf2_cu
*cu
)
19451 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19452 what template types look like, because the demangler
19453 frequently doesn't give the same name as the debug info. We
19454 could fix this by only using the demangled name to get the
19455 prefix (but see comment in read_structure_type). */
19457 struct partial_die_info
*real_pdi
;
19458 struct partial_die_info
*child_pdi
;
19460 /* If this DIE (this DIE's specification, if any) has a parent, then
19461 we should not do this. We'll prepend the parent's fully qualified
19462 name when we create the partial symbol. */
19464 real_pdi
= struct_pdi
;
19465 while (real_pdi
->has_specification
)
19467 auto res
= find_partial_die (real_pdi
->spec_offset
,
19468 real_pdi
->spec_is_dwz
, cu
);
19469 real_pdi
= res
.pdi
;
19473 if (real_pdi
->die_parent
!= NULL
)
19476 for (child_pdi
= struct_pdi
->die_child
;
19478 child_pdi
= child_pdi
->die_sibling
)
19480 if (child_pdi
->tag
== DW_TAG_subprogram
19481 && child_pdi
->linkage_name
!= NULL
)
19483 gdb::unique_xmalloc_ptr
<char> actual_class_name
19484 (cu
->language_defn
->class_name_from_physname
19485 (child_pdi
->linkage_name
));
19486 if (actual_class_name
!= NULL
)
19488 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19489 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19490 struct_pdi
->canonical_name
= 1;
19497 /* Return true if a DIE with TAG may have the DW_AT_const_value
19501 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19505 case DW_TAG_constant
:
19506 case DW_TAG_enumerator
:
19507 case DW_TAG_formal_parameter
:
19508 case DW_TAG_template_value_param
:
19509 case DW_TAG_variable
:
19517 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19519 /* Once we've fixed up a die, there's no point in doing so again.
19520 This also avoids a memory leak if we were to call
19521 guess_partial_die_structure_name multiple times. */
19525 /* If we found a reference attribute and the DIE has no name, try
19526 to find a name in the referred to DIE. */
19528 if (raw_name
== NULL
&& has_specification
)
19530 struct partial_die_info
*spec_die
;
19532 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19533 spec_die
= res
.pdi
;
19536 spec_die
->fixup (cu
);
19538 if (spec_die
->raw_name
)
19540 raw_name
= spec_die
->raw_name
;
19541 canonical_name
= spec_die
->canonical_name
;
19543 /* Copy DW_AT_external attribute if it is set. */
19544 if (spec_die
->is_external
)
19545 is_external
= spec_die
->is_external
;
19549 if (!has_const_value
&& has_specification
19550 && can_have_DW_AT_const_value_p (tag
))
19552 struct partial_die_info
*spec_die
;
19554 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19555 spec_die
= res
.pdi
;
19558 spec_die
->fixup (cu
);
19560 if (spec_die
->has_const_value
)
19562 /* Copy DW_AT_const_value attribute if it is set. */
19563 has_const_value
= spec_die
->has_const_value
;
19567 /* Set default names for some unnamed DIEs. */
19569 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19571 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19572 canonical_name
= 1;
19575 /* If there is no parent die to provide a namespace, and there are
19576 children, see if we can determine the namespace from their linkage
19578 if (cu
->per_cu
->lang
== language_cplus
19579 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19580 && die_parent
== NULL
19582 && (tag
== DW_TAG_class_type
19583 || tag
== DW_TAG_structure_type
19584 || tag
== DW_TAG_union_type
))
19585 guess_partial_die_structure_name (this, cu
);
19587 /* GCC might emit a nameless struct or union that has a linkage
19588 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19589 if (raw_name
== NULL
19590 && (tag
== DW_TAG_class_type
19591 || tag
== DW_TAG_interface_type
19592 || tag
== DW_TAG_structure_type
19593 || tag
== DW_TAG_union_type
)
19594 && linkage_name
!= NULL
)
19596 gdb::unique_xmalloc_ptr
<char> demangled
19597 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19598 if (demangled
!= nullptr)
19602 /* Strip any leading namespaces/classes, keep only the base name.
19603 DW_AT_name for named DIEs does not contain the prefixes. */
19604 base
= strrchr (demangled
.get (), ':');
19605 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19608 base
= demangled
.get ();
19610 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19611 raw_name
= objfile
->intern (base
);
19612 canonical_name
= 1;
19619 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19620 contents from the given SECTION in the HEADER.
19622 HEADER_OFFSET is the offset of the header in the section. */
19624 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19625 struct dwarf2_section_info
*section
,
19626 sect_offset header_offset
)
19628 unsigned int bytes_read
;
19629 bfd
*abfd
= section
->get_bfd_owner ();
19630 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19632 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19633 info_ptr
+= bytes_read
;
19635 header
->version
= read_2_bytes (abfd
, info_ptr
);
19638 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19641 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19644 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19647 /* Return the DW_AT_loclists_base value for the CU. */
19649 lookup_loclist_base (struct dwarf2_cu
*cu
)
19651 /* For the .dwo unit, the loclist_base points to the first offset following
19652 the header. The header consists of the following entities-
19653 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19655 2. version (2 bytes)
19656 3. address size (1 byte)
19657 4. segment selector size (1 byte)
19658 5. offset entry count (4 bytes)
19659 These sizes are derived as per the DWARFv5 standard. */
19660 if (cu
->dwo_unit
!= nullptr)
19662 if (cu
->header
.initial_length_size
== 4)
19663 return LOCLIST_HEADER_SIZE32
;
19664 return LOCLIST_HEADER_SIZE64
;
19666 return cu
->loclist_base
;
19669 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19670 array of offsets in the .debug_loclists section. */
19673 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19675 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19676 struct objfile
*objfile
= per_objfile
->objfile
;
19677 bfd
*abfd
= objfile
->obfd
;
19678 ULONGEST loclist_header_size
=
19679 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19680 : LOCLIST_HEADER_SIZE64
);
19681 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19683 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19684 ULONGEST start_offset
=
19685 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19687 /* Get loclists section. */
19688 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19690 /* Read the loclists section content. */
19691 section
->read (objfile
);
19692 if (section
->buffer
== NULL
)
19693 error (_("DW_FORM_loclistx used without .debug_loclists "
19694 "section [in module %s]"), objfile_name (objfile
));
19696 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19697 so if loclist_base is smaller than the header size, we have a problem. */
19698 if (loclist_base
< loclist_header_size
)
19699 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19700 objfile_name (objfile
));
19702 /* Read the header of the loclists contribution. */
19703 struct loclists_rnglists_header header
;
19704 read_loclists_rnglists_header (&header
, section
,
19705 (sect_offset
) (loclist_base
- loclist_header_size
));
19707 /* Verify the loclist index is valid. */
19708 if (loclist_index
>= header
.offset_entry_count
)
19709 error (_("DW_FORM_loclistx pointing outside of "
19710 ".debug_loclists offset array [in module %s]"),
19711 objfile_name (objfile
));
19713 /* Validate that reading won't go beyond the end of the section. */
19714 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19715 error (_("Reading DW_FORM_loclistx index beyond end of"
19716 ".debug_loclists section [in module %s]"),
19717 objfile_name (objfile
));
19719 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19721 if (cu
->header
.offset_size
== 4)
19722 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19724 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19727 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19728 array of offsets in the .debug_rnglists section. */
19731 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19734 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19735 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19736 bfd
*abfd
= objfile
->obfd
;
19737 ULONGEST rnglist_header_size
=
19738 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19739 : RNGLIST_HEADER_SIZE64
);
19741 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19742 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19744 ULONGEST rnglist_base
=
19745 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19747 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19748 ULONGEST start_offset
=
19749 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19751 /* Get rnglists section. */
19752 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19754 /* Read the rnglists section content. */
19755 section
->read (objfile
);
19756 if (section
->buffer
== nullptr)
19757 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19759 objfile_name (objfile
));
19761 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19762 so if rnglist_base is smaller than the header size, we have a problem. */
19763 if (rnglist_base
< rnglist_header_size
)
19764 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19765 objfile_name (objfile
));
19767 /* Read the header of the rnglists contribution. */
19768 struct loclists_rnglists_header header
;
19769 read_loclists_rnglists_header (&header
, section
,
19770 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19772 /* Verify the rnglist index is valid. */
19773 if (rnglist_index
>= header
.offset_entry_count
)
19774 error (_("DW_FORM_rnglistx index pointing outside of "
19775 ".debug_rnglists offset array [in module %s]"),
19776 objfile_name (objfile
));
19778 /* Validate that reading won't go beyond the end of the section. */
19779 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19780 error (_("Reading DW_FORM_rnglistx index beyond end of"
19781 ".debug_rnglists section [in module %s]"),
19782 objfile_name (objfile
));
19784 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19786 if (cu
->header
.offset_size
== 4)
19787 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19789 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19792 /* Process the attributes that had to be skipped in the first round. These
19793 attributes are the ones that need str_offsets_base or addr_base attributes.
19794 They could not have been processed in the first round, because at the time
19795 the values of str_offsets_base or addr_base may not have been known. */
19797 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19798 struct attribute
*attr
, dwarf_tag tag
)
19800 struct dwarf2_cu
*cu
= reader
->cu
;
19801 switch (attr
->form
)
19803 case DW_FORM_addrx
:
19804 case DW_FORM_GNU_addr_index
:
19805 attr
->set_address (read_addr_index (cu
,
19806 attr
->as_unsigned_reprocess ()));
19808 case DW_FORM_loclistx
:
19810 sect_offset loclists_sect_off
19811 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19813 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19816 case DW_FORM_rnglistx
:
19818 sect_offset rnglists_sect_off
19819 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19821 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19825 case DW_FORM_strx1
:
19826 case DW_FORM_strx2
:
19827 case DW_FORM_strx3
:
19828 case DW_FORM_strx4
:
19829 case DW_FORM_GNU_str_index
:
19831 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19832 gdb_assert (!attr
->canonical_string_p ());
19833 if (reader
->dwo_file
!= NULL
)
19834 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19837 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19842 gdb_assert_not_reached (_("Unexpected DWARF form."));
19846 /* Read an attribute value described by an attribute form. */
19848 static const gdb_byte
*
19849 read_attribute_value (const struct die_reader_specs
*reader
,
19850 struct attribute
*attr
, unsigned form
,
19851 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19853 struct dwarf2_cu
*cu
= reader
->cu
;
19854 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19855 struct objfile
*objfile
= per_objfile
->objfile
;
19856 bfd
*abfd
= reader
->abfd
;
19857 struct comp_unit_head
*cu_header
= &cu
->header
;
19858 unsigned int bytes_read
;
19859 struct dwarf_block
*blk
;
19861 attr
->form
= (enum dwarf_form
) form
;
19864 case DW_FORM_ref_addr
:
19865 if (cu_header
->version
== 2)
19866 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
19869 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19871 info_ptr
+= bytes_read
;
19873 case DW_FORM_GNU_ref_alt
:
19874 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19876 info_ptr
+= bytes_read
;
19880 struct gdbarch
*gdbarch
= objfile
->arch ();
19881 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
19882 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19883 attr
->set_address (addr
);
19884 info_ptr
+= bytes_read
;
19887 case DW_FORM_block2
:
19888 blk
= dwarf_alloc_block (cu
);
19889 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19891 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19892 info_ptr
+= blk
->size
;
19893 attr
->set_block (blk
);
19895 case DW_FORM_block4
:
19896 blk
= dwarf_alloc_block (cu
);
19897 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19899 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19900 info_ptr
+= blk
->size
;
19901 attr
->set_block (blk
);
19903 case DW_FORM_data2
:
19904 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
19907 case DW_FORM_data4
:
19908 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
19911 case DW_FORM_data8
:
19912 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
19915 case DW_FORM_data16
:
19916 blk
= dwarf_alloc_block (cu
);
19918 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19920 attr
->set_block (blk
);
19922 case DW_FORM_sec_offset
:
19923 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19925 info_ptr
+= bytes_read
;
19927 case DW_FORM_loclistx
:
19929 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19931 info_ptr
+= bytes_read
;
19934 case DW_FORM_string
:
19935 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
19937 info_ptr
+= bytes_read
;
19940 if (!cu
->per_cu
->is_dwz
)
19942 attr
->set_string_noncanonical
19943 (read_indirect_string (per_objfile
,
19944 abfd
, info_ptr
, cu_header
,
19946 info_ptr
+= bytes_read
;
19950 case DW_FORM_line_strp
:
19951 if (!cu
->per_cu
->is_dwz
)
19953 attr
->set_string_noncanonical
19954 (per_objfile
->read_line_string (info_ptr
, cu_header
,
19956 info_ptr
+= bytes_read
;
19960 case DW_FORM_GNU_strp_alt
:
19962 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
19963 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19966 attr
->set_string_noncanonical
19967 (dwz
->read_string (objfile
, str_offset
));
19968 info_ptr
+= bytes_read
;
19971 case DW_FORM_exprloc
:
19972 case DW_FORM_block
:
19973 blk
= dwarf_alloc_block (cu
);
19974 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19975 info_ptr
+= bytes_read
;
19976 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19977 info_ptr
+= blk
->size
;
19978 attr
->set_block (blk
);
19980 case DW_FORM_block1
:
19981 blk
= dwarf_alloc_block (cu
);
19982 blk
->size
= read_1_byte (abfd
, info_ptr
);
19984 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19985 info_ptr
+= blk
->size
;
19986 attr
->set_block (blk
);
19988 case DW_FORM_data1
:
19990 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
19993 case DW_FORM_flag_present
:
19994 attr
->set_unsigned (1);
19996 case DW_FORM_sdata
:
19997 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
19998 info_ptr
+= bytes_read
;
20000 case DW_FORM_rnglistx
:
20002 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20004 info_ptr
+= bytes_read
;
20007 case DW_FORM_udata
:
20008 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20009 info_ptr
+= bytes_read
;
20012 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20013 + read_1_byte (abfd
, info_ptr
)));
20017 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20018 + read_2_bytes (abfd
, info_ptr
)));
20022 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20023 + read_4_bytes (abfd
, info_ptr
)));
20027 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20028 + read_8_bytes (abfd
, info_ptr
)));
20031 case DW_FORM_ref_sig8
:
20032 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20035 case DW_FORM_ref_udata
:
20036 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20037 + read_unsigned_leb128 (abfd
, info_ptr
,
20039 info_ptr
+= bytes_read
;
20041 case DW_FORM_indirect
:
20042 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20043 info_ptr
+= bytes_read
;
20044 if (form
== DW_FORM_implicit_const
)
20046 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20047 info_ptr
+= bytes_read
;
20049 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20052 case DW_FORM_implicit_const
:
20053 attr
->set_signed (implicit_const
);
20055 case DW_FORM_addrx
:
20056 case DW_FORM_GNU_addr_index
:
20057 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20059 info_ptr
+= bytes_read
;
20062 case DW_FORM_strx1
:
20063 case DW_FORM_strx2
:
20064 case DW_FORM_strx3
:
20065 case DW_FORM_strx4
:
20066 case DW_FORM_GNU_str_index
:
20068 ULONGEST str_index
;
20069 if (form
== DW_FORM_strx1
)
20071 str_index
= read_1_byte (abfd
, info_ptr
);
20074 else if (form
== DW_FORM_strx2
)
20076 str_index
= read_2_bytes (abfd
, info_ptr
);
20079 else if (form
== DW_FORM_strx3
)
20081 str_index
= read_3_bytes (abfd
, info_ptr
);
20084 else if (form
== DW_FORM_strx4
)
20086 str_index
= read_4_bytes (abfd
, info_ptr
);
20091 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20092 info_ptr
+= bytes_read
;
20094 attr
->set_unsigned_reprocess (str_index
);
20098 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20099 dwarf_form_name (form
),
20100 bfd_get_filename (abfd
));
20104 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20105 attr
->form
= DW_FORM_GNU_ref_alt
;
20107 /* We have seen instances where the compiler tried to emit a byte
20108 size attribute of -1 which ended up being encoded as an unsigned
20109 0xffffffff. Although 0xffffffff is technically a valid size value,
20110 an object of this size seems pretty unlikely so we can relatively
20111 safely treat these cases as if the size attribute was invalid and
20112 treat them as zero by default. */
20113 if (attr
->name
== DW_AT_byte_size
20114 && form
== DW_FORM_data4
20115 && attr
->as_unsigned () >= 0xffffffff)
20118 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20119 hex_string (attr
->as_unsigned ()));
20120 attr
->set_unsigned (0);
20126 /* Read an attribute described by an abbreviated attribute. */
20128 static const gdb_byte
*
20129 read_attribute (const struct die_reader_specs
*reader
,
20130 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20131 const gdb_byte
*info_ptr
)
20133 attr
->name
= abbrev
->name
;
20134 attr
->string_is_canonical
= 0;
20135 attr
->requires_reprocessing
= 0;
20136 return read_attribute_value (reader
, attr
, abbrev
->form
,
20137 abbrev
->implicit_const
, info_ptr
);
20140 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20142 static const char *
20143 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20144 LONGEST str_offset
)
20146 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20147 str_offset
, "DW_FORM_strp");
20150 /* Return pointer to string at .debug_str offset as read from BUF.
20151 BUF is assumed to be in a compilation unit described by CU_HEADER.
20152 Return *BYTES_READ_PTR count of bytes read from BUF. */
20154 static const char *
20155 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20156 const gdb_byte
*buf
,
20157 const struct comp_unit_head
*cu_header
,
20158 unsigned int *bytes_read_ptr
)
20160 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20162 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20168 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20169 const struct comp_unit_head
*cu_header
,
20170 unsigned int *bytes_read_ptr
)
20172 bfd
*abfd
= objfile
->obfd
;
20173 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20175 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20178 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20179 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20180 ADDR_SIZE is the size of addresses from the CU header. */
20183 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20184 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20186 struct objfile
*objfile
= per_objfile
->objfile
;
20187 bfd
*abfd
= objfile
->obfd
;
20188 const gdb_byte
*info_ptr
;
20189 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20191 per_objfile
->per_bfd
->addr
.read (objfile
);
20192 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20193 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20194 objfile_name (objfile
));
20195 if (addr_base_or_zero
+ addr_index
* addr_size
20196 >= per_objfile
->per_bfd
->addr
.size
)
20197 error (_("DW_FORM_addr_index pointing outside of "
20198 ".debug_addr section [in module %s]"),
20199 objfile_name (objfile
));
20200 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20201 + addr_index
* addr_size
);
20202 if (addr_size
== 4)
20203 return bfd_get_32 (abfd
, info_ptr
);
20205 return bfd_get_64 (abfd
, info_ptr
);
20208 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20211 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20213 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20214 cu
->addr_base
, cu
->header
.addr_size
);
20217 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20220 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20221 unsigned int *bytes_read
)
20223 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20224 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20226 return read_addr_index (cu
, addr_index
);
20232 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20233 dwarf2_per_objfile
*per_objfile
,
20234 unsigned int addr_index
)
20236 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20237 gdb::optional
<ULONGEST
> addr_base
;
20240 /* We need addr_base and addr_size.
20241 If we don't have PER_CU->cu, we have to get it.
20242 Nasty, but the alternative is storing the needed info in PER_CU,
20243 which at this point doesn't seem justified: it's not clear how frequently
20244 it would get used and it would increase the size of every PER_CU.
20245 Entry points like dwarf2_per_cu_addr_size do a similar thing
20246 so we're not in uncharted territory here.
20247 Alas we need to be a bit more complicated as addr_base is contained
20250 We don't need to read the entire CU(/TU).
20251 We just need the header and top level die.
20253 IWBN to use the aging mechanism to let us lazily later discard the CU.
20254 For now we skip this optimization. */
20258 addr_base
= cu
->addr_base
;
20259 addr_size
= cu
->header
.addr_size
;
20263 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20264 addr_base
= reader
.cu
->addr_base
;
20265 addr_size
= reader
.cu
->header
.addr_size
;
20268 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20271 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20272 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20275 static const char *
20276 read_str_index (struct dwarf2_cu
*cu
,
20277 struct dwarf2_section_info
*str_section
,
20278 struct dwarf2_section_info
*str_offsets_section
,
20279 ULONGEST str_offsets_base
, ULONGEST str_index
)
20281 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20282 struct objfile
*objfile
= per_objfile
->objfile
;
20283 const char *objf_name
= objfile_name (objfile
);
20284 bfd
*abfd
= objfile
->obfd
;
20285 const gdb_byte
*info_ptr
;
20286 ULONGEST str_offset
;
20287 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20289 str_section
->read (objfile
);
20290 str_offsets_section
->read (objfile
);
20291 if (str_section
->buffer
== NULL
)
20292 error (_("%s used without %s section"
20293 " in CU at offset %s [in module %s]"),
20294 form_name
, str_section
->get_name (),
20295 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20296 if (str_offsets_section
->buffer
== NULL
)
20297 error (_("%s used without %s section"
20298 " in CU at offset %s [in module %s]"),
20299 form_name
, str_section
->get_name (),
20300 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20301 info_ptr
= (str_offsets_section
->buffer
20303 + str_index
* cu
->header
.offset_size
);
20304 if (cu
->header
.offset_size
== 4)
20305 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20307 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20308 if (str_offset
>= str_section
->size
)
20309 error (_("Offset from %s pointing outside of"
20310 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20311 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20312 return (const char *) (str_section
->buffer
+ str_offset
);
20315 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20317 static const char *
20318 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20320 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20321 ? reader
->cu
->header
.addr_size
: 0;
20322 return read_str_index (reader
->cu
,
20323 &reader
->dwo_file
->sections
.str
,
20324 &reader
->dwo_file
->sections
.str_offsets
,
20325 str_offsets_base
, str_index
);
20328 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20330 static const char *
20331 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20333 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20334 const char *objf_name
= objfile_name (objfile
);
20335 static const char form_name
[] = "DW_FORM_GNU_str_index";
20336 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20338 if (!cu
->str_offsets_base
.has_value ())
20339 error (_("%s used in Fission stub without %s"
20340 " in CU at offset 0x%lx [in module %s]"),
20341 form_name
, str_offsets_attr_name
,
20342 (long) cu
->header
.offset_size
, objf_name
);
20344 return read_str_index (cu
,
20345 &cu
->per_objfile
->per_bfd
->str
,
20346 &cu
->per_objfile
->per_bfd
->str_offsets
,
20347 *cu
->str_offsets_base
, str_index
);
20350 /* Return the length of an LEB128 number in BUF. */
20353 leb128_size (const gdb_byte
*buf
)
20355 const gdb_byte
*begin
= buf
;
20361 if ((byte
& 128) == 0)
20362 return buf
- begin
;
20366 static enum language
20367 dwarf_lang_to_enum_language (unsigned int lang
)
20369 enum language language
;
20378 language
= language_c
;
20381 case DW_LANG_C_plus_plus
:
20382 case DW_LANG_C_plus_plus_11
:
20383 case DW_LANG_C_plus_plus_14
:
20384 language
= language_cplus
;
20387 language
= language_d
;
20389 case DW_LANG_Fortran77
:
20390 case DW_LANG_Fortran90
:
20391 case DW_LANG_Fortran95
:
20392 case DW_LANG_Fortran03
:
20393 case DW_LANG_Fortran08
:
20394 language
= language_fortran
;
20397 language
= language_go
;
20399 case DW_LANG_Mips_Assembler
:
20400 language
= language_asm
;
20402 case DW_LANG_Ada83
:
20403 case DW_LANG_Ada95
:
20404 language
= language_ada
;
20406 case DW_LANG_Modula2
:
20407 language
= language_m2
;
20409 case DW_LANG_Pascal83
:
20410 language
= language_pascal
;
20413 language
= language_objc
;
20416 case DW_LANG_Rust_old
:
20417 language
= language_rust
;
20419 case DW_LANG_OpenCL
:
20420 language
= language_opencl
;
20422 case DW_LANG_Cobol74
:
20423 case DW_LANG_Cobol85
:
20425 language
= language_minimal
;
20432 /* Return the named attribute or NULL if not there. */
20434 static struct attribute
*
20435 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20440 struct attribute
*spec
= NULL
;
20442 for (i
= 0; i
< die
->num_attrs
; ++i
)
20444 if (die
->attrs
[i
].name
== name
)
20445 return &die
->attrs
[i
];
20446 if (die
->attrs
[i
].name
== DW_AT_specification
20447 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20448 spec
= &die
->attrs
[i
];
20454 die
= follow_die_ref (die
, spec
, &cu
);
20460 /* Return the string associated with a string-typed attribute, or NULL if it
20461 is either not found or is of an incorrect type. */
20463 static const char *
20464 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20466 struct attribute
*attr
;
20467 const char *str
= NULL
;
20469 attr
= dwarf2_attr (die
, name
, cu
);
20473 str
= attr
->as_string ();
20474 if (str
== nullptr)
20475 complaint (_("string type expected for attribute %s for "
20476 "DIE at %s in module %s"),
20477 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20478 objfile_name (cu
->per_objfile
->objfile
));
20484 /* Return the dwo name or NULL if not present. If present, it is in either
20485 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20486 static const char *
20487 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20489 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20490 if (dwo_name
== nullptr)
20491 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20495 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20496 and holds a non-zero value. This function should only be used for
20497 DW_FORM_flag or DW_FORM_flag_present attributes. */
20500 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20502 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20504 return attr
!= nullptr && attr
->as_boolean ();
20508 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20510 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20511 which value is non-zero. However, we have to be careful with
20512 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20513 (via dwarf2_flag_true_p) follows this attribute. So we may
20514 end up accidently finding a declaration attribute that belongs
20515 to a different DIE referenced by the specification attribute,
20516 even though the given DIE does not have a declaration attribute. */
20517 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20518 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20521 /* Return the die giving the specification for DIE, if there is
20522 one. *SPEC_CU is the CU containing DIE on input, and the CU
20523 containing the return value on output. If there is no
20524 specification, but there is an abstract origin, that is
20527 static struct die_info
*
20528 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20530 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20533 if (spec_attr
== NULL
)
20534 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20536 if (spec_attr
== NULL
)
20539 return follow_die_ref (die
, spec_attr
, spec_cu
);
20542 /* A convenience function to find the proper .debug_line section for a CU. */
20544 static struct dwarf2_section_info
*
20545 get_debug_line_section (struct dwarf2_cu
*cu
)
20547 struct dwarf2_section_info
*section
;
20548 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20550 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20552 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20553 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20554 else if (cu
->per_cu
->is_dwz
)
20556 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20558 section
= &dwz
->line
;
20561 section
= &per_objfile
->per_bfd
->line
;
20566 /* Read the statement program header starting at OFFSET in
20567 .debug_line, or .debug_line.dwo. Return a pointer
20568 to a struct line_header, allocated using xmalloc.
20569 Returns NULL if there is a problem reading the header, e.g., if it
20570 has a version we don't understand.
20572 NOTE: the strings in the include directory and file name tables of
20573 the returned object point into the dwarf line section buffer,
20574 and must not be freed. */
20576 static line_header_up
20577 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20579 struct dwarf2_section_info
*section
;
20580 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20582 section
= get_debug_line_section (cu
);
20583 section
->read (per_objfile
->objfile
);
20584 if (section
->buffer
== NULL
)
20586 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20587 complaint (_("missing .debug_line.dwo section"));
20589 complaint (_("missing .debug_line section"));
20593 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20594 per_objfile
, section
, &cu
->header
);
20597 /* Subroutine of dwarf_decode_lines to simplify it.
20598 Return the file name of the psymtab for the given file_entry.
20599 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20600 If space for the result is malloc'd, *NAME_HOLDER will be set.
20601 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20603 static const char *
20604 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20605 const dwarf2_psymtab
*pst
,
20606 const char *comp_dir
,
20607 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20609 const char *include_name
= fe
.name
;
20610 const char *include_name_to_compare
= include_name
;
20611 const char *pst_filename
;
20614 const char *dir_name
= fe
.include_dir (lh
);
20616 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20617 if (!IS_ABSOLUTE_PATH (include_name
)
20618 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20620 /* Avoid creating a duplicate psymtab for PST.
20621 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20622 Before we do the comparison, however, we need to account
20623 for DIR_NAME and COMP_DIR.
20624 First prepend dir_name (if non-NULL). If we still don't
20625 have an absolute path prepend comp_dir (if non-NULL).
20626 However, the directory we record in the include-file's
20627 psymtab does not contain COMP_DIR (to match the
20628 corresponding symtab(s)).
20633 bash$ gcc -g ./hello.c
20634 include_name = "hello.c"
20636 DW_AT_comp_dir = comp_dir = "/tmp"
20637 DW_AT_name = "./hello.c"
20641 if (dir_name
!= NULL
)
20643 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20644 include_name
, (char *) NULL
));
20645 include_name
= name_holder
->get ();
20646 include_name_to_compare
= include_name
;
20648 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20650 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20651 include_name
, (char *) NULL
));
20652 include_name_to_compare
= hold_compare
.get ();
20656 pst_filename
= pst
->filename
;
20657 gdb::unique_xmalloc_ptr
<char> copied_name
;
20658 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20660 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20661 pst_filename
, (char *) NULL
));
20662 pst_filename
= copied_name
.get ();
20665 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20669 return include_name
;
20672 /* State machine to track the state of the line number program. */
20674 class lnp_state_machine
20677 /* Initialize a machine state for the start of a line number
20679 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20680 bool record_lines_p
);
20682 file_entry
*current_file ()
20684 /* lh->file_names is 0-based, but the file name numbers in the
20685 statement program are 1-based. */
20686 return m_line_header
->file_name_at (m_file
);
20689 /* Record the line in the state machine. END_SEQUENCE is true if
20690 we're processing the end of a sequence. */
20691 void record_line (bool end_sequence
);
20693 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20694 nop-out rest of the lines in this sequence. */
20695 void check_line_address (struct dwarf2_cu
*cu
,
20696 const gdb_byte
*line_ptr
,
20697 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20699 void handle_set_discriminator (unsigned int discriminator
)
20701 m_discriminator
= discriminator
;
20702 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20705 /* Handle DW_LNE_set_address. */
20706 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20709 address
+= baseaddr
;
20710 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20713 /* Handle DW_LNS_advance_pc. */
20714 void handle_advance_pc (CORE_ADDR adjust
);
20716 /* Handle a special opcode. */
20717 void handle_special_opcode (unsigned char op_code
);
20719 /* Handle DW_LNS_advance_line. */
20720 void handle_advance_line (int line_delta
)
20722 advance_line (line_delta
);
20725 /* Handle DW_LNS_set_file. */
20726 void handle_set_file (file_name_index file
);
20728 /* Handle DW_LNS_negate_stmt. */
20729 void handle_negate_stmt ()
20731 m_is_stmt
= !m_is_stmt
;
20734 /* Handle DW_LNS_const_add_pc. */
20735 void handle_const_add_pc ();
20737 /* Handle DW_LNS_fixed_advance_pc. */
20738 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20740 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20744 /* Handle DW_LNS_copy. */
20745 void handle_copy ()
20747 record_line (false);
20748 m_discriminator
= 0;
20751 /* Handle DW_LNE_end_sequence. */
20752 void handle_end_sequence ()
20754 m_currently_recording_lines
= true;
20758 /* Advance the line by LINE_DELTA. */
20759 void advance_line (int line_delta
)
20761 m_line
+= line_delta
;
20763 if (line_delta
!= 0)
20764 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20767 struct dwarf2_cu
*m_cu
;
20769 gdbarch
*m_gdbarch
;
20771 /* True if we're recording lines.
20772 Otherwise we're building partial symtabs and are just interested in
20773 finding include files mentioned by the line number program. */
20774 bool m_record_lines_p
;
20776 /* The line number header. */
20777 line_header
*m_line_header
;
20779 /* These are part of the standard DWARF line number state machine,
20780 and initialized according to the DWARF spec. */
20782 unsigned char m_op_index
= 0;
20783 /* The line table index of the current file. */
20784 file_name_index m_file
= 1;
20785 unsigned int m_line
= 1;
20787 /* These are initialized in the constructor. */
20789 CORE_ADDR m_address
;
20791 unsigned int m_discriminator
;
20793 /* Additional bits of state we need to track. */
20795 /* The last file that we called dwarf2_start_subfile for.
20796 This is only used for TLLs. */
20797 unsigned int m_last_file
= 0;
20798 /* The last file a line number was recorded for. */
20799 struct subfile
*m_last_subfile
= NULL
;
20801 /* The address of the last line entry. */
20802 CORE_ADDR m_last_address
;
20804 /* Set to true when a previous line at the same address (using
20805 m_last_address) had m_is_stmt true. This is reset to false when a
20806 line entry at a new address (m_address different to m_last_address) is
20808 bool m_stmt_at_address
= false;
20810 /* When true, record the lines we decode. */
20811 bool m_currently_recording_lines
= false;
20813 /* The last line number that was recorded, used to coalesce
20814 consecutive entries for the same line. This can happen, for
20815 example, when discriminators are present. PR 17276. */
20816 unsigned int m_last_line
= 0;
20817 bool m_line_has_non_zero_discriminator
= false;
20821 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20823 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20824 / m_line_header
->maximum_ops_per_instruction
)
20825 * m_line_header
->minimum_instruction_length
);
20826 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20827 m_op_index
= ((m_op_index
+ adjust
)
20828 % m_line_header
->maximum_ops_per_instruction
);
20832 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20834 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20835 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20836 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20837 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20838 / m_line_header
->maximum_ops_per_instruction
)
20839 * m_line_header
->minimum_instruction_length
);
20840 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20841 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20842 % m_line_header
->maximum_ops_per_instruction
);
20844 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20845 advance_line (line_delta
);
20846 record_line (false);
20847 m_discriminator
= 0;
20851 lnp_state_machine::handle_set_file (file_name_index file
)
20855 const file_entry
*fe
= current_file ();
20857 dwarf2_debug_line_missing_file_complaint ();
20858 else if (m_record_lines_p
)
20860 const char *dir
= fe
->include_dir (m_line_header
);
20862 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20863 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20864 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20869 lnp_state_machine::handle_const_add_pc ()
20872 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20875 = (((m_op_index
+ adjust
)
20876 / m_line_header
->maximum_ops_per_instruction
)
20877 * m_line_header
->minimum_instruction_length
);
20879 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20880 m_op_index
= ((m_op_index
+ adjust
)
20881 % m_line_header
->maximum_ops_per_instruction
);
20884 /* Return non-zero if we should add LINE to the line number table.
20885 LINE is the line to add, LAST_LINE is the last line that was added,
20886 LAST_SUBFILE is the subfile for LAST_LINE.
20887 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20888 had a non-zero discriminator.
20890 We have to be careful in the presence of discriminators.
20891 E.g., for this line:
20893 for (i = 0; i < 100000; i++);
20895 clang can emit four line number entries for that one line,
20896 each with a different discriminator.
20897 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20899 However, we want gdb to coalesce all four entries into one.
20900 Otherwise the user could stepi into the middle of the line and
20901 gdb would get confused about whether the pc really was in the
20902 middle of the line.
20904 Things are further complicated by the fact that two consecutive
20905 line number entries for the same line is a heuristic used by gcc
20906 to denote the end of the prologue. So we can't just discard duplicate
20907 entries, we have to be selective about it. The heuristic we use is
20908 that we only collapse consecutive entries for the same line if at least
20909 one of those entries has a non-zero discriminator. PR 17276.
20911 Note: Addresses in the line number state machine can never go backwards
20912 within one sequence, thus this coalescing is ok. */
20915 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20916 unsigned int line
, unsigned int last_line
,
20917 int line_has_non_zero_discriminator
,
20918 struct subfile
*last_subfile
)
20920 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20922 if (line
!= last_line
)
20924 /* Same line for the same file that we've seen already.
20925 As a last check, for pr 17276, only record the line if the line
20926 has never had a non-zero discriminator. */
20927 if (!line_has_non_zero_discriminator
)
20932 /* Use the CU's builder to record line number LINE beginning at
20933 address ADDRESS in the line table of subfile SUBFILE. */
20936 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20937 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20938 struct dwarf2_cu
*cu
)
20940 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20942 if (dwarf_line_debug
)
20944 fprintf_unfiltered (gdb_stdlog
,
20945 "Recording line %u, file %s, address %s\n",
20946 line
, lbasename (subfile
->name
),
20947 paddress (gdbarch
, address
));
20951 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20954 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20955 Mark the end of a set of line number records.
20956 The arguments are the same as for dwarf_record_line_1.
20957 If SUBFILE is NULL the request is ignored. */
20960 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20961 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20963 if (subfile
== NULL
)
20966 if (dwarf_line_debug
)
20968 fprintf_unfiltered (gdb_stdlog
,
20969 "Finishing current line, file %s, address %s\n",
20970 lbasename (subfile
->name
),
20971 paddress (gdbarch
, address
));
20974 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20978 lnp_state_machine::record_line (bool end_sequence
)
20980 if (dwarf_line_debug
)
20982 fprintf_unfiltered (gdb_stdlog
,
20983 "Processing actual line %u: file %u,"
20984 " address %s, is_stmt %u, discrim %u%s\n",
20986 paddress (m_gdbarch
, m_address
),
20987 m_is_stmt
, m_discriminator
,
20988 (end_sequence
? "\t(end sequence)" : ""));
20991 file_entry
*fe
= current_file ();
20994 dwarf2_debug_line_missing_file_complaint ();
20995 /* For now we ignore lines not starting on an instruction boundary.
20996 But not when processing end_sequence for compatibility with the
20997 previous version of the code. */
20998 else if (m_op_index
== 0 || end_sequence
)
21000 fe
->included_p
= 1;
21001 if (m_record_lines_p
)
21003 /* When we switch files we insert an end maker in the first file,
21004 switch to the second file and add a new line entry. The
21005 problem is that the end marker inserted in the first file will
21006 discard any previous line entries at the same address. If the
21007 line entries in the first file are marked as is-stmt, while
21008 the new line in the second file is non-stmt, then this means
21009 the end marker will discard is-stmt lines so we can have a
21010 non-stmt line. This means that there are less addresses at
21011 which the user can insert a breakpoint.
21013 To improve this we track the last address in m_last_address,
21014 and whether we have seen an is-stmt at this address. Then
21015 when switching files, if we have seen a stmt at the current
21016 address, and we are switching to create a non-stmt line, then
21017 discard the new line. */
21019 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21020 bool ignore_this_line
21021 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21022 && !m_is_stmt
&& m_stmt_at_address
)
21023 || (!end_sequence
&& m_line
== 0));
21025 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21027 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21028 m_currently_recording_lines
? m_cu
: nullptr);
21031 if (!end_sequence
&& !ignore_this_line
)
21033 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21035 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21036 m_line_has_non_zero_discriminator
,
21039 buildsym_compunit
*builder
= m_cu
->get_builder ();
21040 dwarf_record_line_1 (m_gdbarch
,
21041 builder
->get_current_subfile (),
21042 m_line
, m_address
, is_stmt
,
21043 m_currently_recording_lines
? m_cu
: nullptr);
21045 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21046 m_last_line
= m_line
;
21051 /* Track whether we have seen any m_is_stmt true at m_address in case we
21052 have multiple line table entries all at m_address. */
21053 if (m_last_address
!= m_address
)
21055 m_stmt_at_address
= false;
21056 m_last_address
= m_address
;
21058 m_stmt_at_address
|= m_is_stmt
;
21061 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21062 line_header
*lh
, bool record_lines_p
)
21066 m_record_lines_p
= record_lines_p
;
21067 m_line_header
= lh
;
21069 m_currently_recording_lines
= true;
21071 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21072 was a line entry for it so that the backend has a chance to adjust it
21073 and also record it in case it needs it. This is currently used by MIPS
21074 code, cf. `mips_adjust_dwarf2_line'. */
21075 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21076 m_is_stmt
= lh
->default_is_stmt
;
21077 m_discriminator
= 0;
21079 m_last_address
= m_address
;
21080 m_stmt_at_address
= false;
21084 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21085 const gdb_byte
*line_ptr
,
21086 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21088 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21089 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21090 located at 0x0. In this case, additionally check that if
21091 ADDRESS < UNRELOCATED_LOWPC. */
21093 if ((address
== 0 && address
< unrelocated_lowpc
)
21094 || address
== (CORE_ADDR
) -1)
21096 /* This line table is for a function which has been
21097 GCd by the linker. Ignore it. PR gdb/12528 */
21099 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21100 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21102 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21103 line_offset
, objfile_name (objfile
));
21104 m_currently_recording_lines
= false;
21105 /* Note: m_currently_recording_lines is left as false until we see
21106 DW_LNE_end_sequence. */
21110 /* Subroutine of dwarf_decode_lines to simplify it.
21111 Process the line number information in LH.
21112 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21113 program in order to set included_p for every referenced header. */
21116 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21117 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21119 const gdb_byte
*line_ptr
, *extended_end
;
21120 const gdb_byte
*line_end
;
21121 unsigned int bytes_read
, extended_len
;
21122 unsigned char op_code
, extended_op
;
21123 CORE_ADDR baseaddr
;
21124 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21125 bfd
*abfd
= objfile
->obfd
;
21126 struct gdbarch
*gdbarch
= objfile
->arch ();
21127 /* True if we're recording line info (as opposed to building partial
21128 symtabs and just interested in finding include files mentioned by
21129 the line number program). */
21130 bool record_lines_p
= !decode_for_pst_p
;
21132 baseaddr
= objfile
->text_section_offset ();
21134 line_ptr
= lh
->statement_program_start
;
21135 line_end
= lh
->statement_program_end
;
21137 /* Read the statement sequences until there's nothing left. */
21138 while (line_ptr
< line_end
)
21140 /* The DWARF line number program state machine. Reset the state
21141 machine at the start of each sequence. */
21142 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21143 bool end_sequence
= false;
21145 if (record_lines_p
)
21147 /* Start a subfile for the current file of the state
21149 const file_entry
*fe
= state_machine
.current_file ();
21152 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21155 /* Decode the table. */
21156 while (line_ptr
< line_end
&& !end_sequence
)
21158 op_code
= read_1_byte (abfd
, line_ptr
);
21161 if (op_code
>= lh
->opcode_base
)
21163 /* Special opcode. */
21164 state_machine
.handle_special_opcode (op_code
);
21166 else switch (op_code
)
21168 case DW_LNS_extended_op
:
21169 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21171 line_ptr
+= bytes_read
;
21172 extended_end
= line_ptr
+ extended_len
;
21173 extended_op
= read_1_byte (abfd
, line_ptr
);
21175 if (DW_LNE_lo_user
<= extended_op
21176 && extended_op
<= DW_LNE_hi_user
)
21178 /* Vendor extension, ignore. */
21179 line_ptr
= extended_end
;
21182 switch (extended_op
)
21184 case DW_LNE_end_sequence
:
21185 state_machine
.handle_end_sequence ();
21186 end_sequence
= true;
21188 case DW_LNE_set_address
:
21191 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21192 line_ptr
+= bytes_read
;
21194 state_machine
.check_line_address (cu
, line_ptr
,
21195 lowpc
- baseaddr
, address
);
21196 state_machine
.handle_set_address (baseaddr
, address
);
21199 case DW_LNE_define_file
:
21201 const char *cur_file
;
21202 unsigned int mod_time
, length
;
21205 cur_file
= read_direct_string (abfd
, line_ptr
,
21207 line_ptr
+= bytes_read
;
21208 dindex
= (dir_index
)
21209 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21210 line_ptr
+= bytes_read
;
21212 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21213 line_ptr
+= bytes_read
;
21215 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21216 line_ptr
+= bytes_read
;
21217 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21220 case DW_LNE_set_discriminator
:
21222 /* The discriminator is not interesting to the
21223 debugger; just ignore it. We still need to
21224 check its value though:
21225 if there are consecutive entries for the same
21226 (non-prologue) line we want to coalesce them.
21229 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21230 line_ptr
+= bytes_read
;
21232 state_machine
.handle_set_discriminator (discr
);
21236 complaint (_("mangled .debug_line section"));
21239 /* Make sure that we parsed the extended op correctly. If e.g.
21240 we expected a different address size than the producer used,
21241 we may have read the wrong number of bytes. */
21242 if (line_ptr
!= extended_end
)
21244 complaint (_("mangled .debug_line section"));
21249 state_machine
.handle_copy ();
21251 case DW_LNS_advance_pc
:
21254 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21255 line_ptr
+= bytes_read
;
21257 state_machine
.handle_advance_pc (adjust
);
21260 case DW_LNS_advance_line
:
21263 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21264 line_ptr
+= bytes_read
;
21266 state_machine
.handle_advance_line (line_delta
);
21269 case DW_LNS_set_file
:
21271 file_name_index file
21272 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21274 line_ptr
+= bytes_read
;
21276 state_machine
.handle_set_file (file
);
21279 case DW_LNS_set_column
:
21280 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21281 line_ptr
+= bytes_read
;
21283 case DW_LNS_negate_stmt
:
21284 state_machine
.handle_negate_stmt ();
21286 case DW_LNS_set_basic_block
:
21288 /* Add to the address register of the state machine the
21289 address increment value corresponding to special opcode
21290 255. I.e., this value is scaled by the minimum
21291 instruction length since special opcode 255 would have
21292 scaled the increment. */
21293 case DW_LNS_const_add_pc
:
21294 state_machine
.handle_const_add_pc ();
21296 case DW_LNS_fixed_advance_pc
:
21298 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21301 state_machine
.handle_fixed_advance_pc (addr_adj
);
21306 /* Unknown standard opcode, ignore it. */
21309 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21311 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21312 line_ptr
+= bytes_read
;
21319 dwarf2_debug_line_missing_end_sequence_complaint ();
21321 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21322 in which case we still finish recording the last line). */
21323 state_machine
.record_line (true);
21327 /* Decode the Line Number Program (LNP) for the given line_header
21328 structure and CU. The actual information extracted and the type
21329 of structures created from the LNP depends on the value of PST.
21331 1. If PST is NULL, then this procedure uses the data from the program
21332 to create all necessary symbol tables, and their linetables.
21334 2. If PST is not NULL, this procedure reads the program to determine
21335 the list of files included by the unit represented by PST, and
21336 builds all the associated partial symbol tables.
21338 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21339 It is used for relative paths in the line table.
21340 NOTE: When processing partial symtabs (pst != NULL),
21341 comp_dir == pst->dirname.
21343 NOTE: It is important that psymtabs have the same file name (via strcmp)
21344 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21345 symtab we don't use it in the name of the psymtabs we create.
21346 E.g. expand_line_sal requires this when finding psymtabs to expand.
21347 A good testcase for this is mb-inline.exp.
21349 LOWPC is the lowest address in CU (or 0 if not known).
21351 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21352 for its PC<->lines mapping information. Otherwise only the filename
21353 table is read in. */
21356 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21357 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21358 CORE_ADDR lowpc
, int decode_mapping
)
21360 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21361 const int decode_for_pst_p
= (pst
!= NULL
);
21363 if (decode_mapping
)
21364 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21366 if (decode_for_pst_p
)
21368 /* Now that we're done scanning the Line Header Program, we can
21369 create the psymtab of each included file. */
21370 for (auto &file_entry
: lh
->file_names ())
21371 if (file_entry
.included_p
== 1)
21373 gdb::unique_xmalloc_ptr
<char> name_holder
;
21374 const char *include_name
=
21375 psymtab_include_file_name (lh
, file_entry
, pst
,
21376 comp_dir
, &name_holder
);
21377 if (include_name
!= NULL
)
21378 dwarf2_create_include_psymtab
21379 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21380 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21386 /* Make sure a symtab is created for every file, even files
21387 which contain only variables (i.e. no code with associated
21389 buildsym_compunit
*builder
= cu
->get_builder ();
21390 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21392 for (auto &fe
: lh
->file_names ())
21394 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21395 if (builder
->get_current_subfile ()->symtab
== NULL
)
21397 builder
->get_current_subfile ()->symtab
21398 = allocate_symtab (cust
,
21399 builder
->get_current_subfile ()->name
);
21401 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21406 /* Start a subfile for DWARF. FILENAME is the name of the file and
21407 DIRNAME the name of the source directory which contains FILENAME
21408 or NULL if not known.
21409 This routine tries to keep line numbers from identical absolute and
21410 relative file names in a common subfile.
21412 Using the `list' example from the GDB testsuite, which resides in
21413 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21414 of /srcdir/list0.c yields the following debugging information for list0.c:
21416 DW_AT_name: /srcdir/list0.c
21417 DW_AT_comp_dir: /compdir
21418 files.files[0].name: list0.h
21419 files.files[0].dir: /srcdir
21420 files.files[1].name: list0.c
21421 files.files[1].dir: /srcdir
21423 The line number information for list0.c has to end up in a single
21424 subfile, so that `break /srcdir/list0.c:1' works as expected.
21425 start_subfile will ensure that this happens provided that we pass the
21426 concatenation of files.files[1].dir and files.files[1].name as the
21430 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21431 const char *dirname
)
21433 gdb::unique_xmalloc_ptr
<char> copy
;
21435 /* In order not to lose the line information directory,
21436 we concatenate it to the filename when it makes sense.
21437 Note that the Dwarf3 standard says (speaking of filenames in line
21438 information): ``The directory index is ignored for file names
21439 that represent full path names''. Thus ignoring dirname in the
21440 `else' branch below isn't an issue. */
21442 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21444 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21445 filename
= copy
.get ();
21448 cu
->get_builder ()->start_subfile (filename
);
21452 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21453 struct dwarf2_cu
*cu
)
21455 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21456 struct comp_unit_head
*cu_header
= &cu
->header
;
21458 /* NOTE drow/2003-01-30: There used to be a comment and some special
21459 code here to turn a symbol with DW_AT_external and a
21460 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21461 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21462 with some versions of binutils) where shared libraries could have
21463 relocations against symbols in their debug information - the
21464 minimal symbol would have the right address, but the debug info
21465 would not. It's no longer necessary, because we will explicitly
21466 apply relocations when we read in the debug information now. */
21468 /* A DW_AT_location attribute with no contents indicates that a
21469 variable has been optimized away. */
21470 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21472 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21476 /* Handle one degenerate form of location expression specially, to
21477 preserve GDB's previous behavior when section offsets are
21478 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21479 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21481 if (attr
->form_is_block ())
21483 struct dwarf_block
*block
= attr
->as_block ();
21485 if ((block
->data
[0] == DW_OP_addr
21486 && block
->size
== 1 + cu_header
->addr_size
)
21487 || ((block
->data
[0] == DW_OP_GNU_addr_index
21488 || block
->data
[0] == DW_OP_addrx
)
21490 == 1 + leb128_size (&block
->data
[1]))))
21492 unsigned int dummy
;
21494 if (block
->data
[0] == DW_OP_addr
)
21495 SET_SYMBOL_VALUE_ADDRESS
21496 (sym
, cu
->header
.read_address (objfile
->obfd
,
21500 SET_SYMBOL_VALUE_ADDRESS
21501 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21503 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21504 fixup_symbol_section (sym
, objfile
);
21505 SET_SYMBOL_VALUE_ADDRESS
21507 SYMBOL_VALUE_ADDRESS (sym
)
21508 + objfile
->section_offsets
[sym
->section_index ()]);
21513 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21514 expression evaluator, and use LOC_COMPUTED only when necessary
21515 (i.e. when the value of a register or memory location is
21516 referenced, or a thread-local block, etc.). Then again, it might
21517 not be worthwhile. I'm assuming that it isn't unless performance
21518 or memory numbers show me otherwise. */
21520 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21522 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21523 cu
->has_loclist
= true;
21526 /* Given a pointer to a DWARF information entry, figure out if we need
21527 to make a symbol table entry for it, and if so, create a new entry
21528 and return a pointer to it.
21529 If TYPE is NULL, determine symbol type from the die, otherwise
21530 used the passed type.
21531 If SPACE is not NULL, use it to hold the new symbol. If it is
21532 NULL, allocate a new symbol on the objfile's obstack. */
21534 static struct symbol
*
21535 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21536 struct symbol
*space
)
21538 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21539 struct objfile
*objfile
= per_objfile
->objfile
;
21540 struct gdbarch
*gdbarch
= objfile
->arch ();
21541 struct symbol
*sym
= NULL
;
21543 struct attribute
*attr
= NULL
;
21544 struct attribute
*attr2
= NULL
;
21545 CORE_ADDR baseaddr
;
21546 struct pending
**list_to_add
= NULL
;
21548 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21550 baseaddr
= objfile
->text_section_offset ();
21552 name
= dwarf2_name (die
, cu
);
21555 int suppress_add
= 0;
21560 sym
= new (&objfile
->objfile_obstack
) symbol
;
21561 OBJSTAT (objfile
, n_syms
++);
21563 /* Cache this symbol's name and the name's demangled form (if any). */
21564 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
21565 /* Fortran does not have mangling standard and the mangling does differ
21566 between gfortran, iFort etc. */
21567 const char *physname
21568 = (cu
->per_cu
->lang
== language_fortran
21569 ? dwarf2_full_name (name
, die
, cu
)
21570 : dwarf2_physname (name
, die
, cu
));
21571 const char *linkagename
= dw2_linkage_name (die
, cu
);
21573 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
21574 sym
->set_linkage_name (physname
);
21577 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21578 sym
->set_linkage_name (linkagename
);
21581 /* Default assumptions.
21582 Use the passed type or decode it from the die. */
21583 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21584 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21586 SYMBOL_TYPE (sym
) = type
;
21588 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21589 attr
= dwarf2_attr (die
,
21590 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21592 if (attr
!= nullptr)
21593 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21595 attr
= dwarf2_attr (die
,
21596 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21598 if (attr
!= nullptr && attr
->is_nonnegative ())
21600 file_name_index file_index
21601 = (file_name_index
) attr
->as_nonnegative ();
21602 struct file_entry
*fe
;
21604 if (cu
->line_header
!= NULL
)
21605 fe
= cu
->line_header
->file_name_at (file_index
);
21610 complaint (_("file index out of range"));
21612 symbol_set_symtab (sym
, fe
->symtab
);
21618 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21619 if (attr
!= nullptr)
21623 addr
= attr
->as_address ();
21624 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21625 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21626 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21629 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21630 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21631 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21632 add_symbol_to_list (sym
, cu
->list_in_scope
);
21634 case DW_TAG_subprogram
:
21635 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21637 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21638 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21639 if ((attr2
!= nullptr && attr2
->as_boolean ())
21640 || cu
->per_cu
->lang
== language_ada
21641 || cu
->per_cu
->lang
== language_fortran
)
21643 /* Subprograms marked external are stored as a global symbol.
21644 Ada and Fortran subprograms, whether marked external or
21645 not, are always stored as a global symbol, because we want
21646 to be able to access them globally. For instance, we want
21647 to be able to break on a nested subprogram without having
21648 to specify the context. */
21649 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21653 list_to_add
= cu
->list_in_scope
;
21656 case DW_TAG_inlined_subroutine
:
21657 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21659 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21660 SYMBOL_INLINED (sym
) = 1;
21661 list_to_add
= cu
->list_in_scope
;
21663 case DW_TAG_template_value_param
:
21665 /* Fall through. */
21666 case DW_TAG_constant
:
21667 case DW_TAG_variable
:
21668 case DW_TAG_member
:
21669 /* Compilation with minimal debug info may result in
21670 variables with missing type entries. Change the
21671 misleading `void' type to something sensible. */
21672 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21673 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21675 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21676 /* In the case of DW_TAG_member, we should only be called for
21677 static const members. */
21678 if (die
->tag
== DW_TAG_member
)
21680 /* dwarf2_add_field uses die_is_declaration,
21681 so we do the same. */
21682 gdb_assert (die_is_declaration (die
, cu
));
21685 if (attr
!= nullptr)
21687 dwarf2_const_value (attr
, sym
, cu
);
21688 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21691 if (attr2
!= nullptr && attr2
->as_boolean ())
21692 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21694 list_to_add
= cu
->list_in_scope
;
21698 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21699 if (attr
!= nullptr)
21701 var_decode_location (attr
, sym
, cu
);
21702 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21704 /* Fortran explicitly imports any global symbols to the local
21705 scope by DW_TAG_common_block. */
21706 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21707 && die
->parent
->tag
== DW_TAG_common_block
)
21710 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21711 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21712 && !per_objfile
->per_bfd
->has_section_at_zero
)
21714 /* When a static variable is eliminated by the linker,
21715 the corresponding debug information is not stripped
21716 out, but the variable address is set to null;
21717 do not add such variables into symbol table. */
21719 else if (attr2
!= nullptr && attr2
->as_boolean ())
21721 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21722 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21723 && per_objfile
->per_bfd
->can_copy
)
21725 /* A global static variable might be subject to
21726 copy relocation. We first check for a local
21727 minsym, though, because maybe the symbol was
21728 marked hidden, in which case this would not
21730 bound_minimal_symbol found
21731 = (lookup_minimal_symbol_linkage
21732 (sym
->linkage_name (), objfile
));
21733 if (found
.minsym
!= nullptr)
21734 sym
->maybe_copied
= 1;
21737 /* A variable with DW_AT_external is never static,
21738 but it may be block-scoped. */
21740 = ((cu
->list_in_scope
21741 == cu
->get_builder ()->get_file_symbols ())
21742 ? cu
->get_builder ()->get_global_symbols ()
21743 : cu
->list_in_scope
);
21746 list_to_add
= cu
->list_in_scope
;
21750 /* We do not know the address of this symbol.
21751 If it is an external symbol and we have type information
21752 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21753 The address of the variable will then be determined from
21754 the minimal symbol table whenever the variable is
21756 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21758 /* Fortran explicitly imports any global symbols to the local
21759 scope by DW_TAG_common_block. */
21760 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21761 && die
->parent
->tag
== DW_TAG_common_block
)
21763 /* SYMBOL_CLASS doesn't matter here because
21764 read_common_block is going to reset it. */
21766 list_to_add
= cu
->list_in_scope
;
21768 else if (attr2
!= nullptr && attr2
->as_boolean ()
21769 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21771 /* A variable with DW_AT_external is never static, but it
21772 may be block-scoped. */
21774 = ((cu
->list_in_scope
21775 == cu
->get_builder ()->get_file_symbols ())
21776 ? cu
->get_builder ()->get_global_symbols ()
21777 : cu
->list_in_scope
);
21779 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21781 else if (!die_is_declaration (die
, cu
))
21783 /* Use the default LOC_OPTIMIZED_OUT class. */
21784 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21786 list_to_add
= cu
->list_in_scope
;
21790 case DW_TAG_formal_parameter
:
21792 /* If we are inside a function, mark this as an argument. If
21793 not, we might be looking at an argument to an inlined function
21794 when we do not have enough information to show inlined frames;
21795 pretend it's a local variable in that case so that the user can
21797 struct context_stack
*curr
21798 = cu
->get_builder ()->get_current_context_stack ();
21799 if (curr
!= nullptr && curr
->name
!= nullptr)
21800 SYMBOL_IS_ARGUMENT (sym
) = 1;
21801 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21802 if (attr
!= nullptr)
21804 var_decode_location (attr
, sym
, cu
);
21806 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21807 if (attr
!= nullptr)
21809 dwarf2_const_value (attr
, sym
, cu
);
21812 list_to_add
= cu
->list_in_scope
;
21815 case DW_TAG_unspecified_parameters
:
21816 /* From varargs functions; gdb doesn't seem to have any
21817 interest in this information, so just ignore it for now.
21820 case DW_TAG_template_type_param
:
21822 /* Fall through. */
21823 case DW_TAG_class_type
:
21824 case DW_TAG_interface_type
:
21825 case DW_TAG_structure_type
:
21826 case DW_TAG_union_type
:
21827 case DW_TAG_set_type
:
21828 case DW_TAG_enumeration_type
:
21829 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21830 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21833 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21834 really ever be static objects: otherwise, if you try
21835 to, say, break of a class's method and you're in a file
21836 which doesn't mention that class, it won't work unless
21837 the check for all static symbols in lookup_symbol_aux
21838 saves you. See the OtherFileClass tests in
21839 gdb.c++/namespace.exp. */
21843 buildsym_compunit
*builder
= cu
->get_builder ();
21845 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21846 && cu
->per_cu
->lang
== language_cplus
21847 ? builder
->get_global_symbols ()
21848 : cu
->list_in_scope
);
21850 /* The semantics of C++ state that "struct foo {
21851 ... }" also defines a typedef for "foo". */
21852 if (cu
->per_cu
->lang
== language_cplus
21853 || cu
->per_cu
->lang
== language_ada
21854 || cu
->per_cu
->lang
== language_d
21855 || cu
->per_cu
->lang
== language_rust
)
21857 /* The symbol's name is already allocated along
21858 with this objfile, so we don't need to
21859 duplicate it for the type. */
21860 if (SYMBOL_TYPE (sym
)->name () == 0)
21861 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21866 case DW_TAG_typedef
:
21867 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21868 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21869 list_to_add
= cu
->list_in_scope
;
21871 case DW_TAG_array_type
:
21872 case DW_TAG_base_type
:
21873 case DW_TAG_subrange_type
:
21874 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21875 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21876 list_to_add
= cu
->list_in_scope
;
21878 case DW_TAG_enumerator
:
21879 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21880 if (attr
!= nullptr)
21882 dwarf2_const_value (attr
, sym
, cu
);
21885 /* NOTE: carlton/2003-11-10: See comment above in the
21886 DW_TAG_class_type, etc. block. */
21889 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21890 && cu
->per_cu
->lang
== language_cplus
21891 ? cu
->get_builder ()->get_global_symbols ()
21892 : cu
->list_in_scope
);
21895 case DW_TAG_imported_declaration
:
21896 case DW_TAG_namespace
:
21897 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21898 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21900 case DW_TAG_module
:
21901 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21902 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21903 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21905 case DW_TAG_common_block
:
21906 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21907 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21908 add_symbol_to_list (sym
, cu
->list_in_scope
);
21911 /* Not a tag we recognize. Hopefully we aren't processing
21912 trash data, but since we must specifically ignore things
21913 we don't recognize, there is nothing else we should do at
21915 complaint (_("unsupported tag: '%s'"),
21916 dwarf_tag_name (die
->tag
));
21922 sym
->hash_next
= objfile
->template_symbols
;
21923 objfile
->template_symbols
= sym
;
21924 list_to_add
= NULL
;
21927 if (list_to_add
!= NULL
)
21928 add_symbol_to_list (sym
, list_to_add
);
21930 /* For the benefit of old versions of GCC, check for anonymous
21931 namespaces based on the demangled name. */
21932 if (!cu
->processing_has_namespace_info
21933 && cu
->per_cu
->lang
== language_cplus
)
21934 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21939 /* Given an attr with a DW_FORM_dataN value in host byte order,
21940 zero-extend it as appropriate for the symbol's type. The DWARF
21941 standard (v4) is not entirely clear about the meaning of using
21942 DW_FORM_dataN for a constant with a signed type, where the type is
21943 wider than the data. The conclusion of a discussion on the DWARF
21944 list was that this is unspecified. We choose to always zero-extend
21945 because that is the interpretation long in use by GCC. */
21948 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21949 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21951 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21952 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21953 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21954 LONGEST l
= attr
->constant_value (0);
21956 if (bits
< sizeof (*value
) * 8)
21958 l
&= ((LONGEST
) 1 << bits
) - 1;
21961 else if (bits
== sizeof (*value
) * 8)
21965 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21966 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21973 /* Read a constant value from an attribute. Either set *VALUE, or if
21974 the value does not fit in *VALUE, set *BYTES - either already
21975 allocated on the objfile obstack, or newly allocated on OBSTACK,
21976 or, set *BATON, if we translated the constant to a location
21980 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21981 const char *name
, struct obstack
*obstack
,
21982 struct dwarf2_cu
*cu
,
21983 LONGEST
*value
, const gdb_byte
**bytes
,
21984 struct dwarf2_locexpr_baton
**baton
)
21986 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21987 struct objfile
*objfile
= per_objfile
->objfile
;
21988 struct comp_unit_head
*cu_header
= &cu
->header
;
21989 struct dwarf_block
*blk
;
21990 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21991 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21997 switch (attr
->form
)
22000 case DW_FORM_addrx
:
22001 case DW_FORM_GNU_addr_index
:
22005 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22006 dwarf2_const_value_length_mismatch_complaint (name
,
22007 cu_header
->addr_size
,
22008 TYPE_LENGTH (type
));
22009 /* Symbols of this form are reasonably rare, so we just
22010 piggyback on the existing location code rather than writing
22011 a new implementation of symbol_computed_ops. */
22012 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22013 (*baton
)->per_objfile
= per_objfile
;
22014 (*baton
)->per_cu
= cu
->per_cu
;
22015 gdb_assert ((*baton
)->per_cu
);
22017 (*baton
)->size
= 2 + cu_header
->addr_size
;
22018 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22019 (*baton
)->data
= data
;
22021 data
[0] = DW_OP_addr
;
22022 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22023 byte_order
, attr
->as_address ());
22024 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22027 case DW_FORM_string
:
22030 case DW_FORM_GNU_str_index
:
22031 case DW_FORM_GNU_strp_alt
:
22032 /* The string is already allocated on the objfile obstack, point
22034 *bytes
= (const gdb_byte
*) attr
->as_string ();
22036 case DW_FORM_block1
:
22037 case DW_FORM_block2
:
22038 case DW_FORM_block4
:
22039 case DW_FORM_block
:
22040 case DW_FORM_exprloc
:
22041 case DW_FORM_data16
:
22042 blk
= attr
->as_block ();
22043 if (TYPE_LENGTH (type
) != blk
->size
)
22044 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22045 TYPE_LENGTH (type
));
22046 *bytes
= blk
->data
;
22049 /* The DW_AT_const_value attributes are supposed to carry the
22050 symbol's value "represented as it would be on the target
22051 architecture." By the time we get here, it's already been
22052 converted to host endianness, so we just need to sign- or
22053 zero-extend it as appropriate. */
22054 case DW_FORM_data1
:
22055 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22057 case DW_FORM_data2
:
22058 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22060 case DW_FORM_data4
:
22061 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22063 case DW_FORM_data8
:
22064 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22067 case DW_FORM_sdata
:
22068 case DW_FORM_implicit_const
:
22069 *value
= attr
->as_signed ();
22072 case DW_FORM_udata
:
22073 *value
= attr
->as_unsigned ();
22077 complaint (_("unsupported const value attribute form: '%s'"),
22078 dwarf_form_name (attr
->form
));
22085 /* Copy constant value from an attribute to a symbol. */
22088 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22089 struct dwarf2_cu
*cu
)
22091 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22093 const gdb_byte
*bytes
;
22094 struct dwarf2_locexpr_baton
*baton
;
22096 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22097 sym
->print_name (),
22098 &objfile
->objfile_obstack
, cu
,
22099 &value
, &bytes
, &baton
);
22103 SYMBOL_LOCATION_BATON (sym
) = baton
;
22104 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22106 else if (bytes
!= NULL
)
22108 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22109 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22113 SYMBOL_VALUE (sym
) = value
;
22114 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22118 /* Return the type of the die in question using its DW_AT_type attribute. */
22120 static struct type
*
22121 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22123 struct attribute
*type_attr
;
22125 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22128 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22129 /* A missing DW_AT_type represents a void type. */
22130 return objfile_type (objfile
)->builtin_void
;
22133 return lookup_die_type (die
, type_attr
, cu
);
22136 /* True iff CU's producer generates GNAT Ada auxiliary information
22137 that allows to find parallel types through that information instead
22138 of having to do expensive parallel lookups by type name. */
22141 need_gnat_info (struct dwarf2_cu
*cu
)
22143 /* Assume that the Ada compiler was GNAT, which always produces
22144 the auxiliary information. */
22145 return (cu
->per_cu
->lang
== language_ada
);
22148 /* Return the auxiliary type of the die in question using its
22149 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22150 attribute is not present. */
22152 static struct type
*
22153 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22155 struct attribute
*type_attr
;
22157 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22161 return lookup_die_type (die
, type_attr
, cu
);
22164 /* If DIE has a descriptive_type attribute, then set the TYPE's
22165 descriptive type accordingly. */
22168 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22169 struct dwarf2_cu
*cu
)
22171 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22173 if (descriptive_type
)
22175 ALLOCATE_GNAT_AUX_TYPE (type
);
22176 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22180 /* Return the containing type of the die in question using its
22181 DW_AT_containing_type attribute. */
22183 static struct type
*
22184 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22186 struct attribute
*type_attr
;
22187 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22189 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22191 error (_("Dwarf Error: Problem turning containing type into gdb type "
22192 "[in module %s]"), objfile_name (objfile
));
22194 return lookup_die_type (die
, type_attr
, cu
);
22197 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22199 static struct type
*
22200 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22202 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22203 struct objfile
*objfile
= per_objfile
->objfile
;
22206 std::string message
22207 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22208 objfile_name (objfile
),
22209 sect_offset_str (cu
->header
.sect_off
),
22210 sect_offset_str (die
->sect_off
));
22211 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22213 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22216 /* Look up the type of DIE in CU using its type attribute ATTR.
22217 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22218 DW_AT_containing_type.
22219 If there is no type substitute an error marker. */
22221 static struct type
*
22222 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22223 struct dwarf2_cu
*cu
)
22225 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22226 struct objfile
*objfile
= per_objfile
->objfile
;
22227 struct type
*this_type
;
22229 gdb_assert (attr
->name
== DW_AT_type
22230 || attr
->name
== DW_AT_GNAT_descriptive_type
22231 || attr
->name
== DW_AT_containing_type
);
22233 /* First see if we have it cached. */
22235 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22237 struct dwarf2_per_cu_data
*per_cu
;
22238 sect_offset sect_off
= attr
->get_ref_die_offset ();
22240 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22241 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22243 else if (attr
->form_is_ref ())
22245 sect_offset sect_off
= attr
->get_ref_die_offset ();
22247 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22249 else if (attr
->form
== DW_FORM_ref_sig8
)
22251 ULONGEST signature
= attr
->as_signature ();
22253 return get_signatured_type (die
, signature
, cu
);
22257 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22258 " at %s [in module %s]"),
22259 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22260 objfile_name (objfile
));
22261 return build_error_marker_type (cu
, die
);
22264 /* If not cached we need to read it in. */
22266 if (this_type
== NULL
)
22268 struct die_info
*type_die
= NULL
;
22269 struct dwarf2_cu
*type_cu
= cu
;
22271 if (attr
->form_is_ref ())
22272 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22273 if (type_die
== NULL
)
22274 return build_error_marker_type (cu
, die
);
22275 /* If we find the type now, it's probably because the type came
22276 from an inter-CU reference and the type's CU got expanded before
22278 this_type
= read_type_die (type_die
, type_cu
);
22281 /* If we still don't have a type use an error marker. */
22283 if (this_type
== NULL
)
22284 return build_error_marker_type (cu
, die
);
22289 /* Return the type in DIE, CU.
22290 Returns NULL for invalid types.
22292 This first does a lookup in die_type_hash,
22293 and only reads the die in if necessary.
22295 NOTE: This can be called when reading in partial or full symbols. */
22297 static struct type
*
22298 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22300 struct type
*this_type
;
22302 this_type
= get_die_type (die
, cu
);
22306 return read_type_die_1 (die
, cu
);
22309 /* Read the type in DIE, CU.
22310 Returns NULL for invalid types. */
22312 static struct type
*
22313 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22315 struct type
*this_type
= NULL
;
22319 case DW_TAG_class_type
:
22320 case DW_TAG_interface_type
:
22321 case DW_TAG_structure_type
:
22322 case DW_TAG_union_type
:
22323 this_type
= read_structure_type (die
, cu
);
22325 case DW_TAG_enumeration_type
:
22326 this_type
= read_enumeration_type (die
, cu
);
22328 case DW_TAG_subprogram
:
22329 case DW_TAG_subroutine_type
:
22330 case DW_TAG_inlined_subroutine
:
22331 this_type
= read_subroutine_type (die
, cu
);
22333 case DW_TAG_array_type
:
22334 this_type
= read_array_type (die
, cu
);
22336 case DW_TAG_set_type
:
22337 this_type
= read_set_type (die
, cu
);
22339 case DW_TAG_pointer_type
:
22340 this_type
= read_tag_pointer_type (die
, cu
);
22342 case DW_TAG_ptr_to_member_type
:
22343 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22345 case DW_TAG_reference_type
:
22346 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22348 case DW_TAG_rvalue_reference_type
:
22349 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22351 case DW_TAG_const_type
:
22352 this_type
= read_tag_const_type (die
, cu
);
22354 case DW_TAG_volatile_type
:
22355 this_type
= read_tag_volatile_type (die
, cu
);
22357 case DW_TAG_restrict_type
:
22358 this_type
= read_tag_restrict_type (die
, cu
);
22360 case DW_TAG_string_type
:
22361 this_type
= read_tag_string_type (die
, cu
);
22363 case DW_TAG_typedef
:
22364 this_type
= read_typedef (die
, cu
);
22366 case DW_TAG_subrange_type
:
22367 this_type
= read_subrange_type (die
, cu
);
22369 case DW_TAG_base_type
:
22370 this_type
= read_base_type (die
, cu
);
22372 case DW_TAG_unspecified_type
:
22373 this_type
= read_unspecified_type (die
, cu
);
22375 case DW_TAG_namespace
:
22376 this_type
= read_namespace_type (die
, cu
);
22378 case DW_TAG_module
:
22379 this_type
= read_module_type (die
, cu
);
22381 case DW_TAG_atomic_type
:
22382 this_type
= read_tag_atomic_type (die
, cu
);
22385 complaint (_("unexpected tag in read_type_die: '%s'"),
22386 dwarf_tag_name (die
->tag
));
22393 /* See if we can figure out if the class lives in a namespace. We do
22394 this by looking for a member function; its demangled name will
22395 contain namespace info, if there is any.
22396 Return the computed name or NULL.
22397 Space for the result is allocated on the objfile's obstack.
22398 This is the full-die version of guess_partial_die_structure_name.
22399 In this case we know DIE has no useful parent. */
22401 static const char *
22402 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22404 struct die_info
*spec_die
;
22405 struct dwarf2_cu
*spec_cu
;
22406 struct die_info
*child
;
22407 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22410 spec_die
= die_specification (die
, &spec_cu
);
22411 if (spec_die
!= NULL
)
22417 for (child
= die
->child
;
22419 child
= child
->sibling
)
22421 if (child
->tag
== DW_TAG_subprogram
)
22423 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22425 if (linkage_name
!= NULL
)
22427 gdb::unique_xmalloc_ptr
<char> actual_name
22428 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22429 const char *name
= NULL
;
22431 if (actual_name
!= NULL
)
22433 const char *die_name
= dwarf2_name (die
, cu
);
22435 if (die_name
!= NULL
22436 && strcmp (die_name
, actual_name
.get ()) != 0)
22438 /* Strip off the class name from the full name.
22439 We want the prefix. */
22440 int die_name_len
= strlen (die_name
);
22441 int actual_name_len
= strlen (actual_name
.get ());
22442 const char *ptr
= actual_name
.get ();
22444 /* Test for '::' as a sanity check. */
22445 if (actual_name_len
> die_name_len
+ 2
22446 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22447 name
= obstack_strndup (
22448 &objfile
->per_bfd
->storage_obstack
,
22449 ptr
, actual_name_len
- die_name_len
- 2);
22460 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22461 prefix part in such case. See
22462 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22464 static const char *
22465 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22467 struct attribute
*attr
;
22470 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22471 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22474 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22477 attr
= dw2_linkage_name_attr (die
, cu
);
22478 const char *attr_name
= attr
->as_string ();
22479 if (attr
== NULL
|| attr_name
== NULL
)
22482 /* dwarf2_name had to be already called. */
22483 gdb_assert (attr
->canonical_string_p ());
22485 /* Strip the base name, keep any leading namespaces/classes. */
22486 base
= strrchr (attr_name
, ':');
22487 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22490 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22491 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22493 &base
[-1] - attr_name
);
22496 /* Return the name of the namespace/class that DIE is defined within,
22497 or "" if we can't tell. The caller should not xfree the result.
22499 For example, if we're within the method foo() in the following
22509 then determine_prefix on foo's die will return "N::C". */
22511 static const char *
22512 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22514 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22515 struct die_info
*parent
, *spec_die
;
22516 struct dwarf2_cu
*spec_cu
;
22517 struct type
*parent_type
;
22518 const char *retval
;
22520 if (cu
->per_cu
->lang
!= language_cplus
22521 && cu
->per_cu
->lang
!= language_fortran
22522 && cu
->per_cu
->lang
!= language_d
22523 && cu
->per_cu
->lang
!= language_rust
)
22526 retval
= anonymous_struct_prefix (die
, cu
);
22530 /* We have to be careful in the presence of DW_AT_specification.
22531 For example, with GCC 3.4, given the code
22535 // Definition of N::foo.
22539 then we'll have a tree of DIEs like this:
22541 1: DW_TAG_compile_unit
22542 2: DW_TAG_namespace // N
22543 3: DW_TAG_subprogram // declaration of N::foo
22544 4: DW_TAG_subprogram // definition of N::foo
22545 DW_AT_specification // refers to die #3
22547 Thus, when processing die #4, we have to pretend that we're in
22548 the context of its DW_AT_specification, namely the contex of die
22551 spec_die
= die_specification (die
, &spec_cu
);
22552 if (spec_die
== NULL
)
22553 parent
= die
->parent
;
22556 parent
= spec_die
->parent
;
22560 if (parent
== NULL
)
22562 else if (parent
->building_fullname
)
22565 const char *parent_name
;
22567 /* It has been seen on RealView 2.2 built binaries,
22568 DW_TAG_template_type_param types actually _defined_ as
22569 children of the parent class:
22572 template class <class Enum> Class{};
22573 Class<enum E> class_e;
22575 1: DW_TAG_class_type (Class)
22576 2: DW_TAG_enumeration_type (E)
22577 3: DW_TAG_enumerator (enum1:0)
22578 3: DW_TAG_enumerator (enum2:1)
22580 2: DW_TAG_template_type_param
22581 DW_AT_type DW_FORM_ref_udata (E)
22583 Besides being broken debug info, it can put GDB into an
22584 infinite loop. Consider:
22586 When we're building the full name for Class<E>, we'll start
22587 at Class, and go look over its template type parameters,
22588 finding E. We'll then try to build the full name of E, and
22589 reach here. We're now trying to build the full name of E,
22590 and look over the parent DIE for containing scope. In the
22591 broken case, if we followed the parent DIE of E, we'd again
22592 find Class, and once again go look at its template type
22593 arguments, etc., etc. Simply don't consider such parent die
22594 as source-level parent of this die (it can't be, the language
22595 doesn't allow it), and break the loop here. */
22596 name
= dwarf2_name (die
, cu
);
22597 parent_name
= dwarf2_name (parent
, cu
);
22598 complaint (_("template param type '%s' defined within parent '%s'"),
22599 name
? name
: "<unknown>",
22600 parent_name
? parent_name
: "<unknown>");
22604 switch (parent
->tag
)
22606 case DW_TAG_namespace
:
22607 parent_type
= read_type_die (parent
, cu
);
22608 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22609 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22610 Work around this problem here. */
22611 if (cu
->per_cu
->lang
== language_cplus
22612 && strcmp (parent_type
->name (), "::") == 0)
22614 /* We give a name to even anonymous namespaces. */
22615 return parent_type
->name ();
22616 case DW_TAG_class_type
:
22617 case DW_TAG_interface_type
:
22618 case DW_TAG_structure_type
:
22619 case DW_TAG_union_type
:
22620 case DW_TAG_module
:
22621 parent_type
= read_type_die (parent
, cu
);
22622 if (parent_type
->name () != NULL
)
22623 return parent_type
->name ();
22625 /* An anonymous structure is only allowed non-static data
22626 members; no typedefs, no member functions, et cetera.
22627 So it does not need a prefix. */
22629 case DW_TAG_compile_unit
:
22630 case DW_TAG_partial_unit
:
22631 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22632 if (cu
->per_cu
->lang
== language_cplus
22633 && !per_objfile
->per_bfd
->types
.empty ()
22634 && die
->child
!= NULL
22635 && (die
->tag
== DW_TAG_class_type
22636 || die
->tag
== DW_TAG_structure_type
22637 || die
->tag
== DW_TAG_union_type
))
22639 const char *name
= guess_full_die_structure_name (die
, cu
);
22644 case DW_TAG_subprogram
:
22645 /* Nested subroutines in Fortran get a prefix with the name
22646 of the parent's subroutine. */
22647 if (cu
->per_cu
->lang
== language_fortran
)
22649 if ((die
->tag
== DW_TAG_subprogram
)
22650 && (dwarf2_name (parent
, cu
) != NULL
))
22651 return dwarf2_name (parent
, cu
);
22653 return determine_prefix (parent
, cu
);
22654 case DW_TAG_enumeration_type
:
22655 parent_type
= read_type_die (parent
, cu
);
22656 if (parent_type
->is_declared_class ())
22658 if (parent_type
->name () != NULL
)
22659 return parent_type
->name ();
22662 /* Fall through. */
22664 return determine_prefix (parent
, cu
);
22668 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22669 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22670 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22671 an obconcat, otherwise allocate storage for the result. The CU argument is
22672 used to determine the language and hence, the appropriate separator. */
22674 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22677 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22678 int physname
, struct dwarf2_cu
*cu
)
22680 const char *lead
= "";
22683 if (suffix
== NULL
|| suffix
[0] == '\0'
22684 || prefix
== NULL
|| prefix
[0] == '\0')
22686 else if (cu
->per_cu
->lang
== language_d
)
22688 /* For D, the 'main' function could be defined in any module, but it
22689 should never be prefixed. */
22690 if (strcmp (suffix
, "D main") == 0)
22698 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
22700 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22701 DW_AT_MIPS_linkage_name is preferred and used instead. */
22709 if (prefix
== NULL
)
22711 if (suffix
== NULL
)
22718 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22720 strcpy (retval
, lead
);
22721 strcat (retval
, prefix
);
22722 strcat (retval
, sep
);
22723 strcat (retval
, suffix
);
22728 /* We have an obstack. */
22729 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22733 /* Get name of a die, return NULL if not found. */
22735 static const char *
22736 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22737 struct objfile
*objfile
)
22739 if (name
&& cu
->per_cu
->lang
== language_cplus
)
22741 gdb::unique_xmalloc_ptr
<char> canon_name
22742 = cp_canonicalize_string (name
);
22744 if (canon_name
!= nullptr)
22745 name
= objfile
->intern (canon_name
.get ());
22751 /* Get name of a die, return NULL if not found.
22752 Anonymous namespaces are converted to their magic string. */
22754 static const char *
22755 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22757 struct attribute
*attr
;
22758 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22760 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22761 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22762 if (attr_name
== nullptr
22763 && die
->tag
!= DW_TAG_namespace
22764 && die
->tag
!= DW_TAG_class_type
22765 && die
->tag
!= DW_TAG_interface_type
22766 && die
->tag
!= DW_TAG_structure_type
22767 && die
->tag
!= DW_TAG_union_type
)
22772 case DW_TAG_compile_unit
:
22773 case DW_TAG_partial_unit
:
22774 /* Compilation units have a DW_AT_name that is a filename, not
22775 a source language identifier. */
22776 case DW_TAG_enumeration_type
:
22777 case DW_TAG_enumerator
:
22778 /* These tags always have simple identifiers already; no need
22779 to canonicalize them. */
22782 case DW_TAG_namespace
:
22783 if (attr_name
!= nullptr)
22785 return CP_ANONYMOUS_NAMESPACE_STR
;
22787 case DW_TAG_class_type
:
22788 case DW_TAG_interface_type
:
22789 case DW_TAG_structure_type
:
22790 case DW_TAG_union_type
:
22791 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22792 structures or unions. These were of the form "._%d" in GCC 4.1,
22793 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22794 and GCC 4.4. We work around this problem by ignoring these. */
22795 if (attr_name
!= nullptr
22796 && (startswith (attr_name
, "._")
22797 || startswith (attr_name
, "<anonymous")))
22800 /* GCC might emit a nameless typedef that has a linkage name. See
22801 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22802 if (!attr
|| attr_name
== NULL
)
22804 attr
= dw2_linkage_name_attr (die
, cu
);
22805 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22806 if (attr
== NULL
|| attr_name
== NULL
)
22809 /* Avoid demangling attr_name the second time on a second
22810 call for the same DIE. */
22811 if (!attr
->canonical_string_p ())
22813 gdb::unique_xmalloc_ptr
<char> demangled
22814 (gdb_demangle (attr_name
, DMGL_TYPES
));
22815 if (demangled
== nullptr)
22818 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22819 attr_name
= attr
->as_string ();
22822 /* Strip any leading namespaces/classes, keep only the
22823 base name. DW_AT_name for named DIEs does not
22824 contain the prefixes. */
22825 const char *base
= strrchr (attr_name
, ':');
22826 if (base
&& base
> attr_name
&& base
[-1] == ':')
22837 if (!attr
->canonical_string_p ())
22838 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22840 return attr
->as_string ();
22843 /* Return the die that this die in an extension of, or NULL if there
22844 is none. *EXT_CU is the CU containing DIE on input, and the CU
22845 containing the return value on output. */
22847 static struct die_info
*
22848 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22850 struct attribute
*attr
;
22852 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22856 return follow_die_ref (die
, attr
, ext_cu
);
22860 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22864 print_spaces (indent
, f
);
22865 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22866 dwarf_tag_name (die
->tag
), die
->abbrev
,
22867 sect_offset_str (die
->sect_off
));
22869 if (die
->parent
!= NULL
)
22871 print_spaces (indent
, f
);
22872 fprintf_unfiltered (f
, " parent at offset: %s\n",
22873 sect_offset_str (die
->parent
->sect_off
));
22876 print_spaces (indent
, f
);
22877 fprintf_unfiltered (f
, " has children: %s\n",
22878 dwarf_bool_name (die
->child
!= NULL
));
22880 print_spaces (indent
, f
);
22881 fprintf_unfiltered (f
, " attributes:\n");
22883 for (i
= 0; i
< die
->num_attrs
; ++i
)
22885 print_spaces (indent
, f
);
22886 fprintf_unfiltered (f
, " %s (%s) ",
22887 dwarf_attr_name (die
->attrs
[i
].name
),
22888 dwarf_form_name (die
->attrs
[i
].form
));
22890 switch (die
->attrs
[i
].form
)
22893 case DW_FORM_addrx
:
22894 case DW_FORM_GNU_addr_index
:
22895 fprintf_unfiltered (f
, "address: ");
22896 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
22898 case DW_FORM_block2
:
22899 case DW_FORM_block4
:
22900 case DW_FORM_block
:
22901 case DW_FORM_block1
:
22902 fprintf_unfiltered (f
, "block: size %s",
22903 pulongest (die
->attrs
[i
].as_block ()->size
));
22905 case DW_FORM_exprloc
:
22906 fprintf_unfiltered (f
, "expression: size %s",
22907 pulongest (die
->attrs
[i
].as_block ()->size
));
22909 case DW_FORM_data16
:
22910 fprintf_unfiltered (f
, "constant of 16 bytes");
22912 case DW_FORM_ref_addr
:
22913 fprintf_unfiltered (f
, "ref address: ");
22914 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22916 case DW_FORM_GNU_ref_alt
:
22917 fprintf_unfiltered (f
, "alt ref address: ");
22918 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22924 case DW_FORM_ref_udata
:
22925 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22926 (long) (die
->attrs
[i
].as_unsigned ()));
22928 case DW_FORM_data1
:
22929 case DW_FORM_data2
:
22930 case DW_FORM_data4
:
22931 case DW_FORM_data8
:
22932 case DW_FORM_udata
:
22933 fprintf_unfiltered (f
, "constant: %s",
22934 pulongest (die
->attrs
[i
].as_unsigned ()));
22936 case DW_FORM_sec_offset
:
22937 fprintf_unfiltered (f
, "section offset: %s",
22938 pulongest (die
->attrs
[i
].as_unsigned ()));
22940 case DW_FORM_ref_sig8
:
22941 fprintf_unfiltered (f
, "signature: %s",
22942 hex_string (die
->attrs
[i
].as_signature ()));
22944 case DW_FORM_string
:
22946 case DW_FORM_line_strp
:
22948 case DW_FORM_GNU_str_index
:
22949 case DW_FORM_GNU_strp_alt
:
22950 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22951 die
->attrs
[i
].as_string ()
22952 ? die
->attrs
[i
].as_string () : "",
22953 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
22956 if (die
->attrs
[i
].as_boolean ())
22957 fprintf_unfiltered (f
, "flag: TRUE");
22959 fprintf_unfiltered (f
, "flag: FALSE");
22961 case DW_FORM_flag_present
:
22962 fprintf_unfiltered (f
, "flag: TRUE");
22964 case DW_FORM_indirect
:
22965 /* The reader will have reduced the indirect form to
22966 the "base form" so this form should not occur. */
22967 fprintf_unfiltered (f
,
22968 "unexpected attribute form: DW_FORM_indirect");
22970 case DW_FORM_sdata
:
22971 case DW_FORM_implicit_const
:
22972 fprintf_unfiltered (f
, "constant: %s",
22973 plongest (die
->attrs
[i
].as_signed ()));
22976 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22977 die
->attrs
[i
].form
);
22980 fprintf_unfiltered (f
, "\n");
22985 dump_die_for_error (struct die_info
*die
)
22987 dump_die_shallow (gdb_stderr
, 0, die
);
22991 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22993 int indent
= level
* 4;
22995 gdb_assert (die
!= NULL
);
22997 if (level
>= max_level
)
23000 dump_die_shallow (f
, indent
, die
);
23002 if (die
->child
!= NULL
)
23004 print_spaces (indent
, f
);
23005 fprintf_unfiltered (f
, " Children:");
23006 if (level
+ 1 < max_level
)
23008 fprintf_unfiltered (f
, "\n");
23009 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23013 fprintf_unfiltered (f
,
23014 " [not printed, max nesting level reached]\n");
23018 if (die
->sibling
!= NULL
&& level
> 0)
23020 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23024 /* This is called from the pdie macro in gdbinit.in.
23025 It's not static so gcc will keep a copy callable from gdb. */
23028 dump_die (struct die_info
*die
, int max_level
)
23030 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23034 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23038 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23039 to_underlying (die
->sect_off
),
23045 /* Follow reference or signature attribute ATTR of SRC_DIE.
23046 On entry *REF_CU is the CU of SRC_DIE.
23047 On exit *REF_CU is the CU of the result. */
23049 static struct die_info
*
23050 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23051 struct dwarf2_cu
**ref_cu
)
23053 struct die_info
*die
;
23055 if (attr
->form_is_ref ())
23056 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23057 else if (attr
->form
== DW_FORM_ref_sig8
)
23058 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23061 dump_die_for_error (src_die
);
23062 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23063 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23069 /* Follow reference OFFSET.
23070 On entry *REF_CU is the CU of the source die referencing OFFSET.
23071 On exit *REF_CU is the CU of the result.
23072 Returns NULL if OFFSET is invalid. */
23074 static struct die_info
*
23075 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23076 struct dwarf2_cu
**ref_cu
)
23078 struct die_info temp_die
;
23079 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23080 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23082 gdb_assert (cu
->per_cu
!= NULL
);
23086 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23087 "source CU contains target offset: %d",
23088 sect_offset_str (cu
->per_cu
->sect_off
),
23089 sect_offset_str (sect_off
),
23090 cu
->header
.offset_in_cu_p (sect_off
));
23092 if (cu
->per_cu
->is_debug_types
)
23094 /* .debug_types CUs cannot reference anything outside their CU.
23095 If they need to, they have to reference a signatured type via
23096 DW_FORM_ref_sig8. */
23097 if (!cu
->header
.offset_in_cu_p (sect_off
))
23100 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23101 || !cu
->header
.offset_in_cu_p (sect_off
))
23103 struct dwarf2_per_cu_data
*per_cu
;
23105 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23108 dwarf_read_debug_printf_v ("target CU offset: %s, "
23109 "target CU DIEs loaded: %d",
23110 sect_offset_str (per_cu
->sect_off
),
23111 per_objfile
->get_cu (per_cu
) != nullptr);
23113 /* If necessary, add it to the queue and load its DIEs.
23115 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23116 it doesn't mean they are currently loaded. Since we require them
23117 to be loaded, we must check for ourselves. */
23118 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
23119 || per_objfile
->get_cu (per_cu
) == nullptr)
23120 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23121 false, cu
->per_cu
->lang
);
23123 target_cu
= per_objfile
->get_cu (per_cu
);
23124 gdb_assert (target_cu
!= nullptr);
23126 else if (cu
->dies
== NULL
)
23128 /* We're loading full DIEs during partial symbol reading. */
23129 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23130 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23134 *ref_cu
= target_cu
;
23135 temp_die
.sect_off
= sect_off
;
23137 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23139 to_underlying (sect_off
));
23142 /* Follow reference attribute ATTR of SRC_DIE.
23143 On entry *REF_CU is the CU of SRC_DIE.
23144 On exit *REF_CU is the CU of the result. */
23146 static struct die_info
*
23147 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23148 struct dwarf2_cu
**ref_cu
)
23150 sect_offset sect_off
= attr
->get_ref_die_offset ();
23151 struct dwarf2_cu
*cu
= *ref_cu
;
23152 struct die_info
*die
;
23154 die
= follow_die_offset (sect_off
,
23155 (attr
->form
== DW_FORM_GNU_ref_alt
23156 || cu
->per_cu
->is_dwz
),
23159 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23160 "at %s [in module %s]"),
23161 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23162 objfile_name (cu
->per_objfile
->objfile
));
23169 struct dwarf2_locexpr_baton
23170 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23171 dwarf2_per_cu_data
*per_cu
,
23172 dwarf2_per_objfile
*per_objfile
,
23173 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23174 bool resolve_abstract_p
)
23176 struct die_info
*die
;
23177 struct attribute
*attr
;
23178 struct dwarf2_locexpr_baton retval
;
23179 struct objfile
*objfile
= per_objfile
->objfile
;
23181 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23183 cu
= load_cu (per_cu
, per_objfile
, false);
23187 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23188 Instead just throw an error, not much else we can do. */
23189 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23190 sect_offset_str (sect_off
), objfile_name (objfile
));
23193 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23195 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23196 sect_offset_str (sect_off
), objfile_name (objfile
));
23198 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23199 if (!attr
&& resolve_abstract_p
23200 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23201 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23203 CORE_ADDR pc
= get_frame_pc ();
23204 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23205 struct gdbarch
*gdbarch
= objfile
->arch ();
23207 for (const auto &cand_off
23208 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23210 struct dwarf2_cu
*cand_cu
= cu
;
23211 struct die_info
*cand
23212 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23215 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23218 CORE_ADDR pc_low
, pc_high
;
23219 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23220 if (pc_low
== ((CORE_ADDR
) -1))
23222 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23223 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23224 if (!(pc_low
<= pc
&& pc
< pc_high
))
23228 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23235 /* DWARF: "If there is no such attribute, then there is no effect.".
23236 DATA is ignored if SIZE is 0. */
23238 retval
.data
= NULL
;
23241 else if (attr
->form_is_section_offset ())
23243 struct dwarf2_loclist_baton loclist_baton
;
23244 CORE_ADDR pc
= get_frame_pc ();
23247 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23249 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23251 retval
.size
= size
;
23255 if (!attr
->form_is_block ())
23256 error (_("Dwarf Error: DIE at %s referenced in module %s "
23257 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23258 sect_offset_str (sect_off
), objfile_name (objfile
));
23260 struct dwarf_block
*block
= attr
->as_block ();
23261 retval
.data
= block
->data
;
23262 retval
.size
= block
->size
;
23264 retval
.per_objfile
= per_objfile
;
23265 retval
.per_cu
= cu
->per_cu
;
23267 per_objfile
->age_comp_units ();
23274 struct dwarf2_locexpr_baton
23275 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23276 dwarf2_per_cu_data
*per_cu
,
23277 dwarf2_per_objfile
*per_objfile
,
23278 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23280 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23282 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23286 /* Write a constant of a given type as target-ordered bytes into
23289 static const gdb_byte
*
23290 write_constant_as_bytes (struct obstack
*obstack
,
23291 enum bfd_endian byte_order
,
23298 *len
= TYPE_LENGTH (type
);
23299 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23300 store_unsigned_integer (result
, *len
, byte_order
, value
);
23308 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23309 dwarf2_per_cu_data
*per_cu
,
23310 dwarf2_per_objfile
*per_objfile
,
23314 struct die_info
*die
;
23315 struct attribute
*attr
;
23316 const gdb_byte
*result
= NULL
;
23319 enum bfd_endian byte_order
;
23320 struct objfile
*objfile
= per_objfile
->objfile
;
23322 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23324 cu
= load_cu (per_cu
, per_objfile
, false);
23328 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23329 Instead just throw an error, not much else we can do. */
23330 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23331 sect_offset_str (sect_off
), objfile_name (objfile
));
23334 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23336 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23337 sect_offset_str (sect_off
), objfile_name (objfile
));
23339 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23343 byte_order
= (bfd_big_endian (objfile
->obfd
)
23344 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23346 switch (attr
->form
)
23349 case DW_FORM_addrx
:
23350 case DW_FORM_GNU_addr_index
:
23354 *len
= cu
->header
.addr_size
;
23355 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23356 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23360 case DW_FORM_string
:
23363 case DW_FORM_GNU_str_index
:
23364 case DW_FORM_GNU_strp_alt
:
23365 /* The string is already allocated on the objfile obstack, point
23368 const char *attr_name
= attr
->as_string ();
23369 result
= (const gdb_byte
*) attr_name
;
23370 *len
= strlen (attr_name
);
23373 case DW_FORM_block1
:
23374 case DW_FORM_block2
:
23375 case DW_FORM_block4
:
23376 case DW_FORM_block
:
23377 case DW_FORM_exprloc
:
23378 case DW_FORM_data16
:
23380 struct dwarf_block
*block
= attr
->as_block ();
23381 result
= block
->data
;
23382 *len
= block
->size
;
23386 /* The DW_AT_const_value attributes are supposed to carry the
23387 symbol's value "represented as it would be on the target
23388 architecture." By the time we get here, it's already been
23389 converted to host endianness, so we just need to sign- or
23390 zero-extend it as appropriate. */
23391 case DW_FORM_data1
:
23392 type
= die_type (die
, cu
);
23393 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23394 if (result
== NULL
)
23395 result
= write_constant_as_bytes (obstack
, byte_order
,
23398 case DW_FORM_data2
:
23399 type
= die_type (die
, cu
);
23400 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23401 if (result
== NULL
)
23402 result
= write_constant_as_bytes (obstack
, byte_order
,
23405 case DW_FORM_data4
:
23406 type
= die_type (die
, cu
);
23407 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23408 if (result
== NULL
)
23409 result
= write_constant_as_bytes (obstack
, byte_order
,
23412 case DW_FORM_data8
:
23413 type
= die_type (die
, cu
);
23414 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23415 if (result
== NULL
)
23416 result
= write_constant_as_bytes (obstack
, byte_order
,
23420 case DW_FORM_sdata
:
23421 case DW_FORM_implicit_const
:
23422 type
= die_type (die
, cu
);
23423 result
= write_constant_as_bytes (obstack
, byte_order
,
23424 type
, attr
->as_signed (), len
);
23427 case DW_FORM_udata
:
23428 type
= die_type (die
, cu
);
23429 result
= write_constant_as_bytes (obstack
, byte_order
,
23430 type
, attr
->as_unsigned (), len
);
23434 complaint (_("unsupported const value attribute form: '%s'"),
23435 dwarf_form_name (attr
->form
));
23445 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23446 dwarf2_per_cu_data
*per_cu
,
23447 dwarf2_per_objfile
*per_objfile
,
23448 const char **var_name
)
23450 struct die_info
*die
;
23452 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23454 cu
= load_cu (per_cu
, per_objfile
, false);
23459 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23463 if (var_name
!= nullptr)
23464 *var_name
= var_decl_name (die
, cu
);
23465 return die_type (die
, cu
);
23471 dwarf2_get_die_type (cu_offset die_offset
,
23472 dwarf2_per_cu_data
*per_cu
,
23473 dwarf2_per_objfile
*per_objfile
)
23475 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23476 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23479 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23480 On entry *REF_CU is the CU of SRC_DIE.
23481 On exit *REF_CU is the CU of the result.
23482 Returns NULL if the referenced DIE isn't found. */
23484 static struct die_info
*
23485 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23486 struct dwarf2_cu
**ref_cu
)
23488 struct die_info temp_die
;
23489 struct dwarf2_cu
*sig_cu
;
23490 struct die_info
*die
;
23491 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23494 /* While it might be nice to assert sig_type->type == NULL here,
23495 we can get here for DW_AT_imported_declaration where we need
23496 the DIE not the type. */
23498 /* If necessary, add it to the queue and load its DIEs.
23500 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23501 it doesn't mean they are currently loaded. Since we require them
23502 to be loaded, we must check for ourselves. */
23503 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23505 || per_objfile
->get_cu (sig_type
) == nullptr)
23506 read_signatured_type (sig_type
, per_objfile
);
23508 sig_cu
= per_objfile
->get_cu (sig_type
);
23509 gdb_assert (sig_cu
!= NULL
);
23510 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23511 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23512 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23513 to_underlying (temp_die
.sect_off
));
23516 /* For .gdb_index version 7 keep track of included TUs.
23517 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23518 if (per_objfile
->per_bfd
->index_table
!= NULL
23519 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23521 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23531 /* Follow signatured type referenced by ATTR in SRC_DIE.
23532 On entry *REF_CU is the CU of SRC_DIE.
23533 On exit *REF_CU is the CU of the result.
23534 The result is the DIE of the type.
23535 If the referenced type cannot be found an error is thrown. */
23537 static struct die_info
*
23538 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23539 struct dwarf2_cu
**ref_cu
)
23541 ULONGEST signature
= attr
->as_signature ();
23542 struct signatured_type
*sig_type
;
23543 struct die_info
*die
;
23545 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23547 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23548 /* sig_type will be NULL if the signatured type is missing from
23550 if (sig_type
== NULL
)
23552 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23553 " from DIE at %s [in module %s]"),
23554 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23555 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23558 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23561 dump_die_for_error (src_die
);
23562 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23563 " from DIE at %s [in module %s]"),
23564 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23565 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23571 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23572 reading in and processing the type unit if necessary. */
23574 static struct type
*
23575 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23576 struct dwarf2_cu
*cu
)
23578 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23579 struct signatured_type
*sig_type
;
23580 struct dwarf2_cu
*type_cu
;
23581 struct die_info
*type_die
;
23584 sig_type
= lookup_signatured_type (cu
, signature
);
23585 /* sig_type will be NULL if the signatured type is missing from
23587 if (sig_type
== NULL
)
23589 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23590 " from DIE at %s [in module %s]"),
23591 hex_string (signature
), sect_offset_str (die
->sect_off
),
23592 objfile_name (per_objfile
->objfile
));
23593 return build_error_marker_type (cu
, die
);
23596 /* If we already know the type we're done. */
23597 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23598 if (type
!= nullptr)
23602 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23603 if (type_die
!= NULL
)
23605 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23606 is created. This is important, for example, because for c++ classes
23607 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23608 type
= read_type_die (type_die
, type_cu
);
23611 complaint (_("Dwarf Error: Cannot build signatured type %s"
23612 " referenced from DIE at %s [in module %s]"),
23613 hex_string (signature
), sect_offset_str (die
->sect_off
),
23614 objfile_name (per_objfile
->objfile
));
23615 type
= build_error_marker_type (cu
, die
);
23620 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23621 " from DIE at %s [in module %s]"),
23622 hex_string (signature
), sect_offset_str (die
->sect_off
),
23623 objfile_name (per_objfile
->objfile
));
23624 type
= build_error_marker_type (cu
, die
);
23627 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23632 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23633 reading in and processing the type unit if necessary. */
23635 static struct type
*
23636 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23637 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23639 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23640 if (attr
->form_is_ref ())
23642 struct dwarf2_cu
*type_cu
= cu
;
23643 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23645 return read_type_die (type_die
, type_cu
);
23647 else if (attr
->form
== DW_FORM_ref_sig8
)
23649 return get_signatured_type (die
, attr
->as_signature (), cu
);
23653 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23655 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23656 " at %s [in module %s]"),
23657 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23658 objfile_name (per_objfile
->objfile
));
23659 return build_error_marker_type (cu
, die
);
23663 /* Load the DIEs associated with type unit PER_CU into memory. */
23666 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23667 dwarf2_per_objfile
*per_objfile
)
23669 struct signatured_type
*sig_type
;
23671 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23672 gdb_assert (! per_cu
->type_unit_group_p ());
23674 /* We have the per_cu, but we need the signatured_type.
23675 Fortunately this is an easy translation. */
23676 gdb_assert (per_cu
->is_debug_types
);
23677 sig_type
= (struct signatured_type
*) per_cu
;
23679 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23681 read_signatured_type (sig_type
, per_objfile
);
23683 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23686 /* Read in a signatured type and build its CU and DIEs.
23687 If the type is a stub for the real type in a DWO file,
23688 read in the real type from the DWO file as well. */
23691 read_signatured_type (signatured_type
*sig_type
,
23692 dwarf2_per_objfile
*per_objfile
)
23694 gdb_assert (sig_type
->is_debug_types
);
23695 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23697 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23699 if (!reader
.dummy_p
)
23701 struct dwarf2_cu
*cu
= reader
.cu
;
23702 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23704 gdb_assert (cu
->die_hash
== NULL
);
23706 htab_create_alloc_ex (cu
->header
.length
/ 12,
23710 &cu
->comp_unit_obstack
,
23711 hashtab_obstack_allocate
,
23712 dummy_obstack_deallocate
);
23714 if (reader
.comp_unit_die
->has_children
)
23715 reader
.comp_unit_die
->child
23716 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23717 reader
.comp_unit_die
);
23718 cu
->dies
= reader
.comp_unit_die
;
23719 /* comp_unit_die is not stored in die_hash, no need. */
23721 /* We try not to read any attributes in this function, because
23722 not all CUs needed for references have been loaded yet, and
23723 symbol table processing isn't initialized. But we have to
23724 set the CU language, or we won't be able to build types
23725 correctly. Similarly, if we do not read the producer, we can
23726 not apply producer-specific interpretation. */
23727 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23732 sig_type
->tu_read
= 1;
23735 /* Decode simple location descriptions.
23736 Given a pointer to a dwarf block that defines a location, compute
23737 the location and return the value. If COMPUTED is non-null, it is
23738 set to true to indicate that decoding was successful, and false
23739 otherwise. If COMPUTED is null, then this function may emit a
23743 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23745 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23747 size_t size
= blk
->size
;
23748 const gdb_byte
*data
= blk
->data
;
23749 CORE_ADDR stack
[64];
23751 unsigned int bytes_read
, unsnd
;
23754 if (computed
!= nullptr)
23760 stack
[++stacki
] = 0;
23799 stack
[++stacki
] = op
- DW_OP_lit0
;
23834 stack
[++stacki
] = op
- DW_OP_reg0
;
23837 if (computed
== nullptr)
23838 dwarf2_complex_location_expr_complaint ();
23845 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23847 stack
[++stacki
] = unsnd
;
23850 if (computed
== nullptr)
23851 dwarf2_complex_location_expr_complaint ();
23858 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23863 case DW_OP_const1u
:
23864 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23868 case DW_OP_const1s
:
23869 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23873 case DW_OP_const2u
:
23874 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23878 case DW_OP_const2s
:
23879 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23883 case DW_OP_const4u
:
23884 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23888 case DW_OP_const4s
:
23889 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23893 case DW_OP_const8u
:
23894 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23899 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23905 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23910 stack
[stacki
+ 1] = stack
[stacki
];
23915 stack
[stacki
- 1] += stack
[stacki
];
23919 case DW_OP_plus_uconst
:
23920 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23926 stack
[stacki
- 1] -= stack
[stacki
];
23931 /* If we're not the last op, then we definitely can't encode
23932 this using GDB's address_class enum. This is valid for partial
23933 global symbols, although the variable's address will be bogus
23937 if (computed
== nullptr)
23938 dwarf2_complex_location_expr_complaint ();
23944 case DW_OP_GNU_push_tls_address
:
23945 case DW_OP_form_tls_address
:
23946 /* The top of the stack has the offset from the beginning
23947 of the thread control block at which the variable is located. */
23948 /* Nothing should follow this operator, so the top of stack would
23950 /* This is valid for partial global symbols, but the variable's
23951 address will be bogus in the psymtab. Make it always at least
23952 non-zero to not look as a variable garbage collected by linker
23953 which have DW_OP_addr 0. */
23956 if (computed
== nullptr)
23957 dwarf2_complex_location_expr_complaint ();
23964 case DW_OP_GNU_uninit
:
23965 if (computed
!= nullptr)
23970 case DW_OP_GNU_addr_index
:
23971 case DW_OP_GNU_const_index
:
23972 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23978 if (computed
== nullptr)
23980 const char *name
= get_DW_OP_name (op
);
23983 complaint (_("unsupported stack op: '%s'"),
23986 complaint (_("unsupported stack op: '%02x'"),
23990 return (stack
[stacki
]);
23993 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23994 outside of the allocated space. Also enforce minimum>0. */
23995 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23997 if (computed
== nullptr)
23998 complaint (_("location description stack overflow"));
24004 if (computed
== nullptr)
24005 complaint (_("location description stack underflow"));
24010 if (computed
!= nullptr)
24012 return (stack
[stacki
]);
24015 /* memory allocation interface */
24017 static struct dwarf_block
*
24018 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24020 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24023 static struct die_info
*
24024 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24026 struct die_info
*die
;
24027 size_t size
= sizeof (struct die_info
);
24030 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24032 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24033 memset (die
, 0, sizeof (struct die_info
));
24039 /* Macro support. */
24041 /* An overload of dwarf_decode_macros that finds the correct section
24042 and ensures it is read in before calling the other overload. */
24045 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24046 int section_is_gnu
)
24048 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24049 struct objfile
*objfile
= per_objfile
->objfile
;
24050 const struct line_header
*lh
= cu
->line_header
;
24051 unsigned int offset_size
= cu
->header
.offset_size
;
24052 struct dwarf2_section_info
*section
;
24053 const char *section_name
;
24055 if (cu
->dwo_unit
!= nullptr)
24057 if (section_is_gnu
)
24059 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24060 section_name
= ".debug_macro.dwo";
24064 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24065 section_name
= ".debug_macinfo.dwo";
24070 if (section_is_gnu
)
24072 section
= &per_objfile
->per_bfd
->macro
;
24073 section_name
= ".debug_macro";
24077 section
= &per_objfile
->per_bfd
->macinfo
;
24078 section_name
= ".debug_macinfo";
24082 section
->read (objfile
);
24083 if (section
->buffer
== nullptr)
24085 complaint (_("missing %s section"), section_name
);
24089 buildsym_compunit
*builder
= cu
->get_builder ();
24091 struct dwarf2_section_info
*str_offsets_section
;
24092 struct dwarf2_section_info
*str_section
;
24093 ULONGEST str_offsets_base
;
24095 if (cu
->dwo_unit
!= nullptr)
24097 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24098 ->sections
.str_offsets
;
24099 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24100 str_offsets_base
= cu
->header
.addr_size
;
24104 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24105 str_section
= &per_objfile
->per_bfd
->str
;
24106 str_offsets_base
= *cu
->str_offsets_base
;
24109 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24110 offset_size
, offset
, str_section
, str_offsets_section
,
24111 str_offsets_base
, section_is_gnu
);
24114 /* Return the .debug_loc section to use for CU.
24115 For DWO files use .debug_loc.dwo. */
24117 static struct dwarf2_section_info
*
24118 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24120 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24124 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24126 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24128 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24129 : &per_objfile
->per_bfd
->loc
);
24132 /* Return the .debug_rnglists section to use for CU. */
24133 static struct dwarf2_section_info
*
24134 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24136 if (cu
->header
.version
< 5)
24137 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24138 cu
->header
.version
);
24139 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24141 /* Make sure we read the .debug_rnglists section from the file that
24142 contains the DW_AT_ranges attribute we are reading. Normally that
24143 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24144 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24146 if (cu
->dwo_unit
!= nullptr
24147 && tag
!= DW_TAG_compile_unit
24148 && tag
!= DW_TAG_skeleton_unit
)
24150 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24152 if (sections
->rnglists
.size
> 0)
24153 return §ions
->rnglists
;
24155 error (_(".debug_rnglists section is missing from .dwo file."));
24157 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24160 /* A helper function that fills in a dwarf2_loclist_baton. */
24163 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24164 struct dwarf2_loclist_baton
*baton
,
24165 const struct attribute
*attr
)
24167 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24168 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24170 section
->read (per_objfile
->objfile
);
24172 baton
->per_objfile
= per_objfile
;
24173 baton
->per_cu
= cu
->per_cu
;
24174 gdb_assert (baton
->per_cu
);
24175 /* We don't know how long the location list is, but make sure we
24176 don't run off the edge of the section. */
24177 baton
->size
= section
->size
- attr
->as_unsigned ();
24178 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24179 if (cu
->base_address
.has_value ())
24180 baton
->base_address
= *cu
->base_address
;
24182 baton
->base_address
= 0;
24183 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24187 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24188 struct dwarf2_cu
*cu
, int is_block
)
24190 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24191 struct objfile
*objfile
= per_objfile
->objfile
;
24192 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24194 if (attr
->form_is_section_offset ()
24195 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24196 the section. If so, fall through to the complaint in the
24198 && attr
->as_unsigned () < section
->get_size (objfile
))
24200 struct dwarf2_loclist_baton
*baton
;
24202 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24204 fill_in_loclist_baton (cu
, baton
, attr
);
24206 if (!cu
->base_address
.has_value ())
24207 complaint (_("Location list used without "
24208 "specifying the CU base address."));
24210 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24211 ? dwarf2_loclist_block_index
24212 : dwarf2_loclist_index
);
24213 SYMBOL_LOCATION_BATON (sym
) = baton
;
24217 struct dwarf2_locexpr_baton
*baton
;
24219 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24220 baton
->per_objfile
= per_objfile
;
24221 baton
->per_cu
= cu
->per_cu
;
24222 gdb_assert (baton
->per_cu
);
24224 if (attr
->form_is_block ())
24226 /* Note that we're just copying the block's data pointer
24227 here, not the actual data. We're still pointing into the
24228 info_buffer for SYM's objfile; right now we never release
24229 that buffer, but when we do clean up properly this may
24231 struct dwarf_block
*block
= attr
->as_block ();
24232 baton
->size
= block
->size
;
24233 baton
->data
= block
->data
;
24237 dwarf2_invalid_attrib_class_complaint ("location description",
24238 sym
->natural_name ());
24242 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24243 ? dwarf2_locexpr_block_index
24244 : dwarf2_locexpr_index
);
24245 SYMBOL_LOCATION_BATON (sym
) = baton
;
24251 const comp_unit_head
*
24252 dwarf2_per_cu_data::get_header () const
24254 if (!m_header_read_in
)
24256 const gdb_byte
*info_ptr
24257 = this->section
->buffer
+ to_underlying (this->sect_off
);
24259 memset (&m_header
, 0, sizeof (m_header
));
24261 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24262 rcuh_kind::COMPILE
);
24264 m_header_read_in
= true;
24273 dwarf2_per_cu_data::addr_size () const
24275 return this->get_header ()->addr_size
;
24281 dwarf2_per_cu_data::offset_size () const
24283 return this->get_header ()->offset_size
;
24289 dwarf2_per_cu_data::ref_addr_size () const
24291 const comp_unit_head
*header
= this->get_header ();
24293 if (header
->version
== 2)
24294 return header
->addr_size
;
24296 return header
->offset_size
;
24299 /* A helper function for dwarf2_find_containing_comp_unit that returns
24300 the index of the result, and that searches a vector. It will
24301 return a result even if the offset in question does not actually
24302 occur in any CU. This is separate so that it can be unit
24306 dwarf2_find_containing_comp_unit
24307 (sect_offset sect_off
,
24308 unsigned int offset_in_dwz
,
24309 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24314 high
= all_comp_units
.size () - 1;
24317 struct dwarf2_per_cu_data
*mid_cu
;
24318 int mid
= low
+ (high
- low
) / 2;
24320 mid_cu
= all_comp_units
[mid
].get ();
24321 if (mid_cu
->is_dwz
> offset_in_dwz
24322 || (mid_cu
->is_dwz
== offset_in_dwz
24323 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24328 gdb_assert (low
== high
);
24332 /* Locate the .debug_info compilation unit from CU's objfile which contains
24333 the DIE at OFFSET. Raises an error on failure. */
24335 static struct dwarf2_per_cu_data
*
24336 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24337 unsigned int offset_in_dwz
,
24338 dwarf2_per_objfile
*per_objfile
)
24340 int low
= dwarf2_find_containing_comp_unit
24341 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24342 dwarf2_per_cu_data
*this_cu
24343 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24345 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24347 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24348 error (_("Dwarf Error: could not find partial DIE containing "
24349 "offset %s [in module %s]"),
24350 sect_offset_str (sect_off
),
24351 bfd_get_filename (per_objfile
->objfile
->obfd
));
24353 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24355 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24359 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24360 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24361 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24362 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24369 namespace selftests
{
24370 namespace find_containing_comp_unit
{
24375 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24376 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24377 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24378 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24379 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24380 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24381 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24382 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24385 two
->sect_off
= sect_offset (one
->length
);
24390 four
->sect_off
= sect_offset (three
->length
);
24394 std::vector
<dwarf2_per_cu_data_up
> units
;
24395 units
.push_back (std::move (one
));
24396 units
.push_back (std::move (two
));
24397 units
.push_back (std::move (three
));
24398 units
.push_back (std::move (four
));
24402 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24403 SELF_CHECK (units
[result
].get () == one_ptr
);
24404 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24405 SELF_CHECK (units
[result
].get () == one_ptr
);
24406 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24407 SELF_CHECK (units
[result
].get () == two_ptr
);
24409 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24410 SELF_CHECK (units
[result
].get () == three_ptr
);
24411 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24412 SELF_CHECK (units
[result
].get () == three_ptr
);
24413 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24414 SELF_CHECK (units
[result
].get () == four_ptr
);
24420 #endif /* GDB_SELF_TEST */
24422 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24425 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24426 enum language pretend_language
)
24428 struct attribute
*attr
;
24430 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24432 /* Set the language we're debugging. */
24433 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24434 if (cu
->producer
!= nullptr
24435 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
24437 /* The XLCL doesn't generate DW_LANG_OpenCL because this
24438 attribute is not standardised yet. As a workaround for the
24439 language detection we fall back to the DW_AT_producer
24441 cu
->per_cu
->lang
= language_opencl
;
24443 else if (cu
->producer
!= nullptr
24444 && strstr (cu
->producer
, "GNU Go ") != NULL
)
24446 /* Similar hack for Go. */
24447 cu
->per_cu
->lang
= language_go
;
24449 else if (attr
!= nullptr)
24450 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
24452 cu
->per_cu
->lang
= pretend_language
;
24453 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
24459 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24461 auto it
= m_dwarf2_cus
.find (per_cu
);
24462 if (it
== m_dwarf2_cus
.end ())
24471 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24473 gdb_assert (this->get_cu (per_cu
) == nullptr);
24475 m_dwarf2_cus
[per_cu
] = cu
;
24481 dwarf2_per_objfile::age_comp_units ()
24483 dwarf_read_debug_printf_v ("running");
24485 /* This is not expected to be called in the middle of CU expansion. There is
24486 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24487 loaded in memory. Calling age_comp_units while the queue is in use could
24488 make us free the DIEs for a CU that is in the queue and therefore break
24490 gdb_assert (!this->per_bfd
->queue
.has_value ());
24492 /* Start by clearing all marks. */
24493 for (auto pair
: m_dwarf2_cus
)
24494 pair
.second
->clear_mark ();
24496 /* Traverse all CUs, mark them and their dependencies if used recently
24498 for (auto pair
: m_dwarf2_cus
)
24500 dwarf2_cu
*cu
= pair
.second
;
24503 if (cu
->last_used
<= dwarf_max_cache_age
)
24507 /* Delete all CUs still not marked. */
24508 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24510 dwarf2_cu
*cu
= it
->second
;
24512 if (!cu
->is_marked ())
24514 dwarf_read_debug_printf_v ("deleting old CU %s",
24515 sect_offset_str (cu
->per_cu
->sect_off
));
24517 it
= m_dwarf2_cus
.erase (it
);
24527 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24529 auto it
= m_dwarf2_cus
.find (per_cu
);
24530 if (it
== m_dwarf2_cus
.end ())
24535 m_dwarf2_cus
.erase (it
);
24538 dwarf2_per_objfile::~dwarf2_per_objfile ()
24543 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24544 We store these in a hash table separate from the DIEs, and preserve them
24545 when the DIEs are flushed out of cache.
24547 The CU "per_cu" pointer is needed because offset alone is not enough to
24548 uniquely identify the type. A file may have multiple .debug_types sections,
24549 or the type may come from a DWO file. Furthermore, while it's more logical
24550 to use per_cu->section+offset, with Fission the section with the data is in
24551 the DWO file but we don't know that section at the point we need it.
24552 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24553 because we can enter the lookup routine, get_die_type_at_offset, from
24554 outside this file, and thus won't necessarily have PER_CU->cu.
24555 Fortunately, PER_CU is stable for the life of the objfile. */
24557 struct dwarf2_per_cu_offset_and_type
24559 const struct dwarf2_per_cu_data
*per_cu
;
24560 sect_offset sect_off
;
24564 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24567 per_cu_offset_and_type_hash (const void *item
)
24569 const struct dwarf2_per_cu_offset_and_type
*ofs
24570 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24572 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24575 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24578 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24580 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24581 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24582 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24583 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24585 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24586 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24589 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24590 table if necessary. For convenience, return TYPE.
24592 The DIEs reading must have careful ordering to:
24593 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24594 reading current DIE.
24595 * Not trying to dereference contents of still incompletely read in types
24596 while reading in other DIEs.
24597 * Enable referencing still incompletely read in types just by a pointer to
24598 the type without accessing its fields.
24600 Therefore caller should follow these rules:
24601 * Try to fetch any prerequisite types we may need to build this DIE type
24602 before building the type and calling set_die_type.
24603 * After building type call set_die_type for current DIE as soon as
24604 possible before fetching more types to complete the current type.
24605 * Make the type as complete as possible before fetching more types. */
24607 static struct type
*
24608 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24609 bool skip_data_location
)
24611 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24612 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24613 struct objfile
*objfile
= per_objfile
->objfile
;
24614 struct attribute
*attr
;
24615 struct dynamic_prop prop
;
24617 /* For Ada types, make sure that the gnat-specific data is always
24618 initialized (if not already set). There are a few types where
24619 we should not be doing so, because the type-specific area is
24620 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24621 where the type-specific area is used to store the floatformat).
24622 But this is not a problem, because the gnat-specific information
24623 is actually not needed for these types. */
24624 if (need_gnat_info (cu
)
24625 && type
->code () != TYPE_CODE_FUNC
24626 && type
->code () != TYPE_CODE_FLT
24627 && type
->code () != TYPE_CODE_METHODPTR
24628 && type
->code () != TYPE_CODE_MEMBERPTR
24629 && type
->code () != TYPE_CODE_METHOD
24630 && type
->code () != TYPE_CODE_FIXED_POINT
24631 && !HAVE_GNAT_AUX_INFO (type
))
24632 INIT_GNAT_SPECIFIC (type
);
24634 /* Read DW_AT_allocated and set in type. */
24635 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24638 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24639 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24640 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24643 /* Read DW_AT_associated and set in type. */
24644 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24647 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24648 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24649 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24652 /* Read DW_AT_data_location and set in type. */
24653 if (!skip_data_location
)
24655 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24656 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24657 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24660 if (per_objfile
->die_type_hash
== NULL
)
24661 per_objfile
->die_type_hash
24662 = htab_up (htab_create_alloc (127,
24663 per_cu_offset_and_type_hash
,
24664 per_cu_offset_and_type_eq
,
24665 NULL
, xcalloc
, xfree
));
24667 ofs
.per_cu
= cu
->per_cu
;
24668 ofs
.sect_off
= die
->sect_off
;
24670 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24671 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24673 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24674 sect_offset_str (die
->sect_off
));
24675 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24676 struct dwarf2_per_cu_offset_and_type
);
24681 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24682 or return NULL if the die does not have a saved type. */
24684 static struct type
*
24685 get_die_type_at_offset (sect_offset sect_off
,
24686 dwarf2_per_cu_data
*per_cu
,
24687 dwarf2_per_objfile
*per_objfile
)
24689 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24691 if (per_objfile
->die_type_hash
== NULL
)
24694 ofs
.per_cu
= per_cu
;
24695 ofs
.sect_off
= sect_off
;
24696 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24697 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24704 /* Look up the type for DIE in CU in die_type_hash,
24705 or return NULL if DIE does not have a saved type. */
24707 static struct type
*
24708 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24710 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24713 /* Trivial hash function for partial_die_info: the hash value of a DIE
24714 is its offset in .debug_info for this objfile. */
24717 partial_die_hash (const void *item
)
24719 const struct partial_die_info
*part_die
24720 = (const struct partial_die_info
*) item
;
24722 return to_underlying (part_die
->sect_off
);
24725 /* Trivial comparison function for partial_die_info structures: two DIEs
24726 are equal if they have the same offset. */
24729 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24731 const struct partial_die_info
*part_die_lhs
24732 = (const struct partial_die_info
*) item_lhs
;
24733 const struct partial_die_info
*part_die_rhs
24734 = (const struct partial_die_info
*) item_rhs
;
24736 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24739 struct cmd_list_element
*set_dwarf_cmdlist
;
24740 struct cmd_list_element
*show_dwarf_cmdlist
;
24743 show_check_physname (struct ui_file
*file
, int from_tty
,
24744 struct cmd_list_element
*c
, const char *value
)
24746 fprintf_filtered (file
,
24747 _("Whether to check \"physname\" is %s.\n"),
24751 void _initialize_dwarf2_read ();
24753 _initialize_dwarf2_read ()
24755 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24756 Set DWARF specific variables.\n\
24757 Configure DWARF variables such as the cache size."),
24758 &set_dwarf_cmdlist
,
24759 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24761 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24762 Show DWARF specific variables.\n\
24763 Show DWARF variables such as the cache size."),
24764 &show_dwarf_cmdlist
,
24765 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24767 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24768 &dwarf_max_cache_age
, _("\
24769 Set the upper bound on the age of cached DWARF compilation units."), _("\
24770 Show the upper bound on the age of cached DWARF compilation units."), _("\
24771 A higher limit means that cached compilation units will be stored\n\
24772 in memory longer, and more total memory will be used. Zero disables\n\
24773 caching, which can slow down startup."),
24775 show_dwarf_max_cache_age
,
24776 &set_dwarf_cmdlist
,
24777 &show_dwarf_cmdlist
);
24779 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24780 Set debugging of the DWARF reader."), _("\
24781 Show debugging of the DWARF reader."), _("\
24782 When enabled (non-zero), debugging messages are printed during DWARF\n\
24783 reading and symtab expansion. A value of 1 (one) provides basic\n\
24784 information. A value greater than 1 provides more verbose information."),
24787 &setdebuglist
, &showdebuglist
);
24789 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24790 Set debugging of the DWARF DIE reader."), _("\
24791 Show debugging of the DWARF DIE reader."), _("\
24792 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24793 The value is the maximum depth to print."),
24796 &setdebuglist
, &showdebuglist
);
24798 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24799 Set debugging of the dwarf line reader."), _("\
24800 Show debugging of the dwarf line reader."), _("\
24801 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24802 A value of 1 (one) provides basic information.\n\
24803 A value greater than 1 provides more verbose information."),
24806 &setdebuglist
, &showdebuglist
);
24808 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24809 Set cross-checking of \"physname\" code against demangler."), _("\
24810 Show cross-checking of \"physname\" code against demangler."), _("\
24811 When enabled, GDB's internal \"physname\" code is checked against\n\
24813 NULL
, show_check_physname
,
24814 &setdebuglist
, &showdebuglist
);
24816 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24817 no_class
, &use_deprecated_index_sections
, _("\
24818 Set whether to use deprecated gdb_index sections."), _("\
24819 Show whether to use deprecated gdb_index sections."), _("\
24820 When enabled, deprecated .gdb_index sections are used anyway.\n\
24821 Normally they are ignored either because of a missing feature or\n\
24822 performance issue.\n\
24823 Warning: This option must be enabled before gdb reads the file."),
24826 &setlist
, &showlist
);
24828 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24829 &dwarf2_locexpr_funcs
);
24830 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24831 &dwarf2_loclist_funcs
);
24833 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24834 &dwarf2_block_frame_base_locexpr_funcs
);
24835 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24836 &dwarf2_block_frame_base_loclist_funcs
);
24839 selftests::register_test ("dw2_expand_symtabs_matching",
24840 selftests::dw2_expand_symtabs_matching::run_test
);
24841 selftests::register_test ("dwarf2_find_containing_comp_unit",
24842 selftests::find_containing_comp_unit::run_test
);