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 void set_cu_language (unsigned int, struct dwarf2_cu
*);
1178 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1179 struct dwarf2_cu
*);
1181 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1182 struct dwarf2_cu
*cu
);
1184 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1186 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1187 struct dwarf2_cu
*cu
);
1189 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1191 static struct die_info
*die_specification (struct die_info
*die
,
1192 struct dwarf2_cu
**);
1194 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1195 struct dwarf2_cu
*cu
);
1197 static void dwarf_decode_lines (struct line_header
*, const char *,
1198 struct dwarf2_cu
*, dwarf2_psymtab
*,
1199 CORE_ADDR
, int decode_mapping
);
1201 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1204 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1205 struct dwarf2_cu
*, struct symbol
* = NULL
);
1207 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1208 struct dwarf2_cu
*);
1210 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1213 struct obstack
*obstack
,
1214 struct dwarf2_cu
*cu
, LONGEST
*value
,
1215 const gdb_byte
**bytes
,
1216 struct dwarf2_locexpr_baton
**baton
);
1218 static struct type
*read_subrange_index_type (struct die_info
*die
,
1219 struct dwarf2_cu
*cu
);
1221 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1223 static int need_gnat_info (struct dwarf2_cu
*);
1225 static struct type
*die_descriptive_type (struct die_info
*,
1226 struct dwarf2_cu
*);
1228 static void set_descriptive_type (struct type
*, struct die_info
*,
1229 struct dwarf2_cu
*);
1231 static struct type
*die_containing_type (struct die_info
*,
1232 struct dwarf2_cu
*);
1234 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1235 struct dwarf2_cu
*);
1237 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1239 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1241 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1243 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1244 const char *suffix
, int physname
,
1245 struct dwarf2_cu
*cu
);
1247 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1249 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1251 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1253 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1255 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1257 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1259 /* Return the .debug_loclists section to use for cu. */
1260 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1262 /* Return the .debug_rnglists section to use for cu. */
1263 static struct dwarf2_section_info
*cu_debug_rnglists_section
1264 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1266 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1267 values. Keep the items ordered with increasing constraints compliance. */
1270 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1271 PC_BOUNDS_NOT_PRESENT
,
1273 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1274 were present but they do not form a valid range of PC addresses. */
1277 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1280 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1284 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1285 CORE_ADDR
*, CORE_ADDR
*,
1289 static void get_scope_pc_bounds (struct die_info
*,
1290 CORE_ADDR
*, CORE_ADDR
*,
1291 struct dwarf2_cu
*);
1293 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1294 CORE_ADDR
, struct dwarf2_cu
*);
1296 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1297 struct dwarf2_cu
*);
1299 static void dwarf2_attach_fields_to_type (struct field_info
*,
1300 struct type
*, struct dwarf2_cu
*);
1302 static void dwarf2_add_member_fn (struct field_info
*,
1303 struct die_info
*, struct type
*,
1304 struct dwarf2_cu
*);
1306 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1308 struct dwarf2_cu
*);
1310 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1312 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1314 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1316 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1318 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1320 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1322 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1324 static struct type
*read_module_type (struct die_info
*die
,
1325 struct dwarf2_cu
*cu
);
1327 static const char *namespace_name (struct die_info
*die
,
1328 int *is_anonymous
, struct dwarf2_cu
*);
1330 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1332 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1335 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1336 struct dwarf2_cu
*);
1338 static struct die_info
*read_die_and_siblings_1
1339 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1342 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1343 const gdb_byte
*info_ptr
,
1344 const gdb_byte
**new_info_ptr
,
1345 struct die_info
*parent
);
1347 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1348 struct die_info
**, const gdb_byte
*,
1351 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1352 struct die_info
**, const gdb_byte
*);
1354 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1356 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1359 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1361 static const char *dwarf2_full_name (const char *name
,
1362 struct die_info
*die
,
1363 struct dwarf2_cu
*cu
);
1365 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1366 struct dwarf2_cu
*cu
);
1368 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1369 struct dwarf2_cu
**);
1371 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1373 static void dump_die_for_error (struct die_info
*);
1375 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1378 /*static*/ void dump_die (struct die_info
*, int max_level
);
1380 static void store_in_ref_table (struct die_info
*,
1381 struct dwarf2_cu
*);
1383 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1384 const struct attribute
*,
1385 struct dwarf2_cu
**);
1387 static struct die_info
*follow_die_ref (struct die_info
*,
1388 const struct attribute
*,
1389 struct dwarf2_cu
**);
1391 static struct die_info
*follow_die_sig (struct die_info
*,
1392 const struct attribute
*,
1393 struct dwarf2_cu
**);
1395 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1396 struct dwarf2_cu
*);
1398 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1399 const struct attribute
*,
1400 struct dwarf2_cu
*);
1402 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1403 dwarf2_per_objfile
*per_objfile
);
1405 static void read_signatured_type (signatured_type
*sig_type
,
1406 dwarf2_per_objfile
*per_objfile
);
1408 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1409 struct die_info
*die
, struct dwarf2_cu
*cu
,
1410 struct dynamic_prop
*prop
, struct type
*type
);
1412 /* memory allocation interface */
1414 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1416 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1418 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1420 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1421 struct dwarf2_loclist_baton
*baton
,
1422 const struct attribute
*attr
);
1424 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1426 struct dwarf2_cu
*cu
,
1429 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1430 const gdb_byte
*info_ptr
,
1431 const struct abbrev_info
*abbrev
);
1433 static hashval_t
partial_die_hash (const void *item
);
1435 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1437 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1438 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1439 dwarf2_per_objfile
*per_objfile
);
1441 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1442 struct die_info
*comp_unit_die
,
1443 enum language pretend_language
);
1445 static struct type
*set_die_type (struct die_info
*, struct type
*,
1446 struct dwarf2_cu
*, bool = false);
1448 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1450 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1451 dwarf2_per_objfile
*per_objfile
,
1452 dwarf2_cu
*existing_cu
,
1454 enum language pretend_language
);
1456 static void process_full_comp_unit (dwarf2_cu
*cu
,
1457 enum language pretend_language
);
1459 static void process_full_type_unit (dwarf2_cu
*cu
,
1460 enum language pretend_language
);
1462 static struct type
*get_die_type_at_offset (sect_offset
,
1463 dwarf2_per_cu_data
*per_cu
,
1464 dwarf2_per_objfile
*per_objfile
);
1466 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1468 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1469 dwarf2_per_objfile
*per_objfile
,
1470 enum language pretend_language
);
1472 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1474 /* Class, the destructor of which frees all allocated queue entries. This
1475 will only have work to do if an error was thrown while processing the
1476 dwarf. If no error was thrown then the queue entries should have all
1477 been processed, and freed, as we went along. */
1479 class dwarf2_queue_guard
1482 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1483 : m_per_objfile (per_objfile
)
1485 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1487 m_per_objfile
->per_bfd
->queue
.emplace ();
1490 /* Free any entries remaining on the queue. There should only be
1491 entries left if we hit an error while processing the dwarf. */
1492 ~dwarf2_queue_guard ()
1494 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1496 m_per_objfile
->per_bfd
->queue
.reset ();
1499 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1502 dwarf2_per_objfile
*m_per_objfile
;
1505 dwarf2_queue_item::~dwarf2_queue_item ()
1507 /* Anything still marked queued is likely to be in an
1508 inconsistent state, so discard it. */
1511 per_objfile
->remove_cu (per_cu
);
1516 /* See dwarf2/read.h. */
1519 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1521 if (data
->is_debug_types
)
1522 delete static_cast<signatured_type
*> (data
);
1527 /* The return type of find_file_and_directory. Note, the enclosed
1528 string pointers are only valid while this object is valid. */
1530 struct file_and_directory
1532 /* The filename. This is never NULL. */
1535 /* The compilation directory. NULL if not known. If we needed to
1536 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1537 points directly to the DW_AT_comp_dir string attribute owned by
1538 the obstack that owns the DIE. */
1539 const char *comp_dir
;
1541 /* If we needed to build a new string for comp_dir, this is what
1542 owns the storage. */
1543 std::string comp_dir_storage
;
1546 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1547 struct dwarf2_cu
*cu
);
1549 static htab_up
allocate_signatured_type_table ();
1551 static htab_up
allocate_dwo_unit_table ();
1553 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1554 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1555 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1557 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1559 static struct dwo_unit
*lookup_dwo_comp_unit
1560 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1561 ULONGEST signature
);
1563 static struct dwo_unit
*lookup_dwo_type_unit
1564 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1566 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1568 /* A unique pointer to a dwo_file. */
1570 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1572 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1574 static void check_producer (struct dwarf2_cu
*cu
);
1576 /* Various complaints about symbol reading that don't abort the process. */
1579 dwarf2_debug_line_missing_file_complaint (void)
1581 complaint (_(".debug_line section has line data without a file"));
1585 dwarf2_debug_line_missing_end_sequence_complaint (void)
1587 complaint (_(".debug_line section has line "
1588 "program sequence without an end"));
1592 dwarf2_complex_location_expr_complaint (void)
1594 complaint (_("location expression too complex"));
1598 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1601 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1606 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1608 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1612 /* Hash function for line_header_hash. */
1615 line_header_hash (const struct line_header
*ofs
)
1617 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1620 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1623 line_header_hash_voidp (const void *item
)
1625 const struct line_header
*ofs
= (const struct line_header
*) item
;
1627 return line_header_hash (ofs
);
1630 /* Equality function for line_header_hash. */
1633 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1635 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1636 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1638 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1639 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1644 /* See declaration. */
1646 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1649 can_copy (can_copy_
)
1652 names
= &dwarf2_elf_names
;
1654 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1655 locate_sections (obfd
, sec
, *names
);
1658 dwarf2_per_bfd::~dwarf2_per_bfd ()
1660 for (auto &per_cu
: all_comp_units
)
1661 per_cu
->imported_symtabs_free ();
1663 /* Everything else should be on this->obstack. */
1669 dwarf2_per_objfile::remove_all_cus ()
1671 gdb_assert (!this->per_bfd
->queue
.has_value ());
1673 for (auto pair
: m_dwarf2_cus
)
1676 m_dwarf2_cus
.clear ();
1679 /* A helper class that calls free_cached_comp_units on
1682 class free_cached_comp_units
1686 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1687 : m_per_objfile (per_objfile
)
1691 ~free_cached_comp_units ()
1693 m_per_objfile
->remove_all_cus ();
1696 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1700 dwarf2_per_objfile
*m_per_objfile
;
1706 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1708 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1710 return this->m_symtabs
[per_cu
->index
] != nullptr;
1716 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1718 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1720 return this->m_symtabs
[per_cu
->index
];
1726 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1727 compunit_symtab
*symtab
)
1729 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1730 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1732 this->m_symtabs
[per_cu
->index
] = symtab
;
1735 /* Try to locate the sections we need for DWARF 2 debugging
1736 information and return true if we have enough to do something.
1737 NAMES points to the dwarf2 section names, or is NULL if the standard
1738 ELF names are used. CAN_COPY is true for formats where symbol
1739 interposition is possible and so symbol values must follow copy
1740 relocation rules. */
1743 dwarf2_has_info (struct objfile
*objfile
,
1744 const struct dwarf2_debug_sections
*names
,
1747 if (objfile
->flags
& OBJF_READNEVER
)
1750 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1752 if (per_objfile
== NULL
)
1754 dwarf2_per_bfd
*per_bfd
;
1756 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1757 BFD doesn't require relocations.
1759 We don't share with objfiles for which -readnow was requested,
1760 because it would complicate things when loading the same BFD with
1761 -readnow and then without -readnow. */
1762 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1763 && (objfile
->flags
& OBJF_READNOW
) == 0)
1765 /* See if one has been created for this BFD yet. */
1766 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1768 if (per_bfd
== nullptr)
1770 /* No, create it now. */
1771 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1772 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1777 /* No sharing possible, create one specifically for this objfile. */
1778 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1779 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1782 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1785 return (!per_objfile
->per_bfd
->info
.is_virtual
1786 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1787 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1788 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1791 /* See declaration. */
1794 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1795 const dwarf2_debug_sections
&names
)
1797 flagword aflag
= bfd_section_flags (sectp
);
1799 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1802 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1803 > bfd_get_file_size (abfd
))
1805 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1806 warning (_("Discarding section %s which has a section size (%s"
1807 ") larger than the file size [in module %s]"),
1808 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1809 bfd_get_filename (abfd
));
1811 else if (names
.info
.matches (sectp
->name
))
1813 this->info
.s
.section
= sectp
;
1814 this->info
.size
= bfd_section_size (sectp
);
1816 else if (names
.abbrev
.matches (sectp
->name
))
1818 this->abbrev
.s
.section
= sectp
;
1819 this->abbrev
.size
= bfd_section_size (sectp
);
1821 else if (names
.line
.matches (sectp
->name
))
1823 this->line
.s
.section
= sectp
;
1824 this->line
.size
= bfd_section_size (sectp
);
1826 else if (names
.loc
.matches (sectp
->name
))
1828 this->loc
.s
.section
= sectp
;
1829 this->loc
.size
= bfd_section_size (sectp
);
1831 else if (names
.loclists
.matches (sectp
->name
))
1833 this->loclists
.s
.section
= sectp
;
1834 this->loclists
.size
= bfd_section_size (sectp
);
1836 else if (names
.macinfo
.matches (sectp
->name
))
1838 this->macinfo
.s
.section
= sectp
;
1839 this->macinfo
.size
= bfd_section_size (sectp
);
1841 else if (names
.macro
.matches (sectp
->name
))
1843 this->macro
.s
.section
= sectp
;
1844 this->macro
.size
= bfd_section_size (sectp
);
1846 else if (names
.str
.matches (sectp
->name
))
1848 this->str
.s
.section
= sectp
;
1849 this->str
.size
= bfd_section_size (sectp
);
1851 else if (names
.str_offsets
.matches (sectp
->name
))
1853 this->str_offsets
.s
.section
= sectp
;
1854 this->str_offsets
.size
= bfd_section_size (sectp
);
1856 else if (names
.line_str
.matches (sectp
->name
))
1858 this->line_str
.s
.section
= sectp
;
1859 this->line_str
.size
= bfd_section_size (sectp
);
1861 else if (names
.addr
.matches (sectp
->name
))
1863 this->addr
.s
.section
= sectp
;
1864 this->addr
.size
= bfd_section_size (sectp
);
1866 else if (names
.frame
.matches (sectp
->name
))
1868 this->frame
.s
.section
= sectp
;
1869 this->frame
.size
= bfd_section_size (sectp
);
1871 else if (names
.eh_frame
.matches (sectp
->name
))
1873 this->eh_frame
.s
.section
= sectp
;
1874 this->eh_frame
.size
= bfd_section_size (sectp
);
1876 else if (names
.ranges
.matches (sectp
->name
))
1878 this->ranges
.s
.section
= sectp
;
1879 this->ranges
.size
= bfd_section_size (sectp
);
1881 else if (names
.rnglists
.matches (sectp
->name
))
1883 this->rnglists
.s
.section
= sectp
;
1884 this->rnglists
.size
= bfd_section_size (sectp
);
1886 else if (names
.types
.matches (sectp
->name
))
1888 struct dwarf2_section_info type_section
;
1890 memset (&type_section
, 0, sizeof (type_section
));
1891 type_section
.s
.section
= sectp
;
1892 type_section
.size
= bfd_section_size (sectp
);
1894 this->types
.push_back (type_section
);
1896 else if (names
.gdb_index
.matches (sectp
->name
))
1898 this->gdb_index
.s
.section
= sectp
;
1899 this->gdb_index
.size
= bfd_section_size (sectp
);
1901 else if (names
.debug_names
.matches (sectp
->name
))
1903 this->debug_names
.s
.section
= sectp
;
1904 this->debug_names
.size
= bfd_section_size (sectp
);
1906 else if (names
.debug_aranges
.matches (sectp
->name
))
1908 this->debug_aranges
.s
.section
= sectp
;
1909 this->debug_aranges
.size
= bfd_section_size (sectp
);
1912 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1913 && bfd_section_vma (sectp
) == 0)
1914 this->has_section_at_zero
= true;
1917 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1921 dwarf2_get_section_info (struct objfile
*objfile
,
1922 enum dwarf2_section_enum sect
,
1923 asection
**sectp
, const gdb_byte
**bufp
,
1924 bfd_size_type
*sizep
)
1926 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1927 struct dwarf2_section_info
*info
;
1929 /* We may see an objfile without any DWARF, in which case we just
1931 if (per_objfile
== NULL
)
1940 case DWARF2_DEBUG_FRAME
:
1941 info
= &per_objfile
->per_bfd
->frame
;
1943 case DWARF2_EH_FRAME
:
1944 info
= &per_objfile
->per_bfd
->eh_frame
;
1947 gdb_assert_not_reached ("unexpected section");
1950 info
->read (objfile
);
1952 *sectp
= info
->get_bfd_section ();
1953 *bufp
= info
->buffer
;
1954 *sizep
= info
->size
;
1958 /* DWARF quick_symbol_functions support. */
1960 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1961 unique line tables, so we maintain a separate table of all .debug_line
1962 derived entries to support the sharing.
1963 All the quick functions need is the list of file names. We discard the
1964 line_header when we're done and don't need to record it here. */
1965 struct quick_file_names
1967 /* The data used to construct the hash key. */
1968 struct stmt_list_hash hash
;
1970 /* The number of entries in file_names, real_names. */
1971 unsigned int num_file_names
;
1973 /* The file names from the line table, after being run through
1975 const char **file_names
;
1977 /* The file names from the line table after being run through
1978 gdb_realpath. These are computed lazily. */
1979 const char **real_names
;
1982 /* When using the index (and thus not using psymtabs), each CU has an
1983 object of this type. This is used to hold information needed by
1984 the various "quick" methods. */
1985 struct dwarf2_per_cu_quick_data
1987 /* The file table. This can be NULL if there was no file table
1988 or it's currently not read in.
1989 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
1990 struct quick_file_names
*file_names
;
1992 /* A temporary mark bit used when iterating over all CUs in
1993 expand_symtabs_matching. */
1994 unsigned int mark
: 1;
1996 /* True if we've tried to read the file table and found there isn't one.
1997 There will be no point in trying to read it again next time. */
1998 unsigned int no_file_data
: 1;
2001 /* A subclass of psymbol_functions that arranges to read the DWARF
2002 partial symbols when needed. */
2003 struct lazy_dwarf_reader
: public psymbol_functions
2005 using psymbol_functions::psymbol_functions
;
2007 bool can_lazily_read_symbols () override
2012 void read_partial_symbols (struct objfile
*objfile
) override
2014 if (dwarf2_has_info (objfile
, nullptr))
2015 dwarf2_build_psymtabs (objfile
, this);
2019 static quick_symbol_functions_up
2020 make_lazy_dwarf_reader ()
2022 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2025 struct dwarf2_base_index_functions
: public quick_symbol_functions
2027 bool has_symbols (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
2643 for (size_t padding
= ((-(addr
- section
->buffer
))
2644 & (2 * address_size
- 1));
2645 padding
> 0; padding
--)
2648 warning (_("Section .debug_aranges in %s entry at offset %s "
2649 "padding is not zero, ignoring .debug_aranges."),
2650 objfile_name (objfile
),
2651 plongest (entry_addr
- section
->buffer
));
2657 if (addr
+ 2 * address_size
> entry_end
)
2659 warning (_("Section .debug_aranges in %s entry at offset %s "
2660 "address list is not properly terminated, "
2661 "ignoring .debug_aranges."),
2662 objfile_name (objfile
),
2663 plongest (entry_addr
- section
->buffer
));
2666 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2668 addr
+= address_size
;
2669 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2671 addr
+= address_size
;
2672 if (start
== 0 && length
== 0)
2674 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2676 /* Symbol was eliminated due to a COMDAT group. */
2679 ULONGEST end
= start
+ length
;
2680 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2682 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2684 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2688 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2692 /* A helper function that reads the .gdb_index from BUFFER and fills
2693 in MAP. FILENAME is the name of the file containing the data;
2694 it is used for error reporting. DEPRECATED_OK is true if it is
2695 ok to use deprecated sections.
2697 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2698 out parameters that are filled in with information about the CU and
2699 TU lists in the section.
2701 Returns true if all went well, false otherwise. */
2704 read_gdb_index_from_buffer (const char *filename
,
2706 gdb::array_view
<const gdb_byte
> buffer
,
2707 struct mapped_index
*map
,
2708 const gdb_byte
**cu_list
,
2709 offset_type
*cu_list_elements
,
2710 const gdb_byte
**types_list
,
2711 offset_type
*types_list_elements
)
2713 const gdb_byte
*addr
= &buffer
[0];
2714 offset_view
metadata (buffer
);
2716 /* Version check. */
2717 offset_type version
= metadata
[0];
2718 /* Versions earlier than 3 emitted every copy of a psymbol. This
2719 causes the index to behave very poorly for certain requests. Version 3
2720 contained incomplete addrmap. So, it seems better to just ignore such
2724 static int warning_printed
= 0;
2725 if (!warning_printed
)
2727 warning (_("Skipping obsolete .gdb_index section in %s."),
2729 warning_printed
= 1;
2733 /* Index version 4 uses a different hash function than index version
2736 Versions earlier than 6 did not emit psymbols for inlined
2737 functions. Using these files will cause GDB not to be able to
2738 set breakpoints on inlined functions by name, so we ignore these
2739 indices unless the user has done
2740 "set use-deprecated-index-sections on". */
2741 if (version
< 6 && !deprecated_ok
)
2743 static int warning_printed
= 0;
2744 if (!warning_printed
)
2747 Skipping deprecated .gdb_index section in %s.\n\
2748 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2749 to use the section anyway."),
2751 warning_printed
= 1;
2755 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2756 of the TU (for symbols coming from TUs),
2757 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2758 Plus gold-generated indices can have duplicate entries for global symbols,
2759 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2760 These are just performance bugs, and we can't distinguish gdb-generated
2761 indices from gold-generated ones, so issue no warning here. */
2763 /* Indexes with higher version than the one supported by GDB may be no
2764 longer backward compatible. */
2768 map
->version
= version
;
2771 *cu_list
= addr
+ metadata
[i
];
2772 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2775 *types_list
= addr
+ metadata
[i
];
2776 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2779 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2780 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2782 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2785 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2786 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2788 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2792 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2797 /* Callback types for dwarf2_read_gdb_index. */
2799 typedef gdb::function_view
2800 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2801 get_gdb_index_contents_ftype
;
2802 typedef gdb::function_view
2803 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2804 get_gdb_index_contents_dwz_ftype
;
2806 /* Read .gdb_index. If everything went ok, initialize the "quick"
2807 elements of all the CUs and return 1. Otherwise, return 0. */
2810 dwarf2_read_gdb_index
2811 (dwarf2_per_objfile
*per_objfile
,
2812 get_gdb_index_contents_ftype get_gdb_index_contents
,
2813 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2815 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2816 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2817 struct dwz_file
*dwz
;
2818 struct objfile
*objfile
= per_objfile
->objfile
;
2819 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2821 gdb::array_view
<const gdb_byte
> main_index_contents
2822 = get_gdb_index_contents (objfile
, per_bfd
);
2824 if (main_index_contents
.empty ())
2827 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2828 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2829 use_deprecated_index_sections
,
2830 main_index_contents
, map
.get (), &cu_list
,
2831 &cu_list_elements
, &types_list
,
2832 &types_list_elements
))
2835 /* Don't use the index if it's empty. */
2836 if (map
->symbol_table
.empty ())
2839 /* If there is a .dwz file, read it so we can get its CU list as
2841 dwz
= dwarf2_get_dwz_file (per_bfd
);
2844 struct mapped_index dwz_map
;
2845 const gdb_byte
*dwz_types_ignore
;
2846 offset_type dwz_types_elements_ignore
;
2848 gdb::array_view
<const gdb_byte
> dwz_index_content
2849 = get_gdb_index_contents_dwz (objfile
, dwz
);
2851 if (dwz_index_content
.empty ())
2854 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2855 1, dwz_index_content
, &dwz_map
,
2856 &dwz_list
, &dwz_list_elements
,
2858 &dwz_types_elements_ignore
))
2860 warning (_("could not read '.gdb_index' section from %s; skipping"),
2861 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2866 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2869 if (types_list_elements
)
2871 /* We can only handle a single .debug_types when we have an
2873 if (per_bfd
->types
.size () != 1)
2876 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2878 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2879 types_list_elements
);
2882 create_addrmap_from_index (per_objfile
, map
.get ());
2884 per_bfd
->index_table
= std::move (map
);
2885 per_bfd
->using_index
= 1;
2886 per_bfd
->quick_file_names_table
=
2887 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2892 /* die_reader_func for dw2_get_file_names. */
2895 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2896 struct die_info
*comp_unit_die
)
2898 struct dwarf2_cu
*cu
= reader
->cu
;
2899 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2900 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2901 struct dwarf2_per_cu_data
*lh_cu
;
2902 struct attribute
*attr
;
2904 struct quick_file_names
*qfn
;
2906 gdb_assert (! this_cu
->is_debug_types
);
2908 /* Our callers never want to match partial units -- instead they
2909 will match the enclosing full CU. */
2910 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2912 this_cu
->v
.quick
->no_file_data
= 1;
2920 sect_offset line_offset
{};
2922 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2923 if (attr
!= nullptr && attr
->form_is_unsigned ())
2925 struct quick_file_names find_entry
;
2927 line_offset
= (sect_offset
) attr
->as_unsigned ();
2929 /* We may have already read in this line header (TU line header sharing).
2930 If we have we're done. */
2931 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2932 find_entry
.hash
.line_sect_off
= line_offset
;
2933 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2934 &find_entry
, INSERT
);
2937 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
2941 lh
= dwarf_decode_line_header (line_offset
, cu
);
2945 lh_cu
->v
.quick
->no_file_data
= 1;
2949 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
2950 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2951 qfn
->hash
.line_sect_off
= line_offset
;
2952 gdb_assert (slot
!= NULL
);
2955 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
2958 if (strcmp (fnd
.name
, "<unknown>") != 0)
2961 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
2963 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
2964 qfn
->num_file_names
);
2966 qfn
->file_names
[0] = xstrdup (fnd
.name
);
2967 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
2968 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
2969 fnd
.comp_dir
).release ();
2970 qfn
->real_names
= NULL
;
2972 lh_cu
->v
.quick
->file_names
= qfn
;
2975 /* A helper for the "quick" functions which attempts to read the line
2976 table for THIS_CU. */
2978 static struct quick_file_names
*
2979 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
2980 dwarf2_per_objfile
*per_objfile
)
2982 /* This should never be called for TUs. */
2983 gdb_assert (! this_cu
->is_debug_types
);
2984 /* Nor type unit groups. */
2985 gdb_assert (! this_cu
->type_unit_group_p ());
2987 if (this_cu
->v
.quick
->file_names
!= NULL
)
2988 return this_cu
->v
.quick
->file_names
;
2989 /* If we know there is no line data, no point in looking again. */
2990 if (this_cu
->v
.quick
->no_file_data
)
2993 cutu_reader
reader (this_cu
, per_objfile
);
2994 if (!reader
.dummy_p
)
2995 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
2997 if (this_cu
->v
.quick
->no_file_data
)
2999 return this_cu
->v
.quick
->file_names
;
3002 /* A helper for the "quick" functions which computes and caches the
3003 real path for a given file name from the line table. */
3006 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3007 struct quick_file_names
*qfn
, int index
)
3009 if (qfn
->real_names
== NULL
)
3010 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3011 qfn
->num_file_names
, const char *);
3013 if (qfn
->real_names
[index
] == NULL
)
3014 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3016 return qfn
->real_names
[index
];
3020 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3022 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3023 dwarf2_per_cu_data
*dwarf_cu
3024 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3025 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3030 return compunit_primary_filetab (cust
);
3033 /* Traversal function for dw2_forget_cached_source_info. */
3036 dw2_free_cached_file_names (void **slot
, void *info
)
3038 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3040 if (file_data
->real_names
)
3044 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3046 xfree ((void*) file_data
->real_names
[i
]);
3047 file_data
->real_names
[i
] = NULL
;
3055 dwarf2_base_index_functions::forget_cached_source_info
3056 (struct objfile
*objfile
)
3058 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3060 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3061 dw2_free_cached_file_names
, NULL
);
3064 /* Struct used to manage iterating over all CUs looking for a symbol. */
3066 struct dw2_symtab_iterator
3068 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3069 dwarf2_per_objfile
*per_objfile
;
3070 /* If set, only look for symbols that match that block. Valid values are
3071 GLOBAL_BLOCK and STATIC_BLOCK. */
3072 gdb::optional
<block_enum
> block_index
;
3073 /* The kind of symbol we're looking for. */
3075 /* The list of CUs from the index entry of the symbol,
3076 or NULL if not found. */
3078 /* The next element in VEC to look at. */
3080 /* The number of elements in VEC, or zero if there is no match. */
3082 /* Have we seen a global version of the symbol?
3083 If so we can ignore all further global instances.
3084 This is to work around gold/15646, inefficient gold-generated
3089 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3092 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3093 dwarf2_per_objfile
*per_objfile
,
3094 gdb::optional
<block_enum
> block_index
,
3095 domain_enum domain
, offset_type namei
)
3097 iter
->per_objfile
= per_objfile
;
3098 iter
->block_index
= block_index
;
3099 iter
->domain
= domain
;
3101 iter
->global_seen
= 0;
3105 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3106 /* index is NULL if OBJF_READNOW. */
3110 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3111 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3113 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3114 iter
->length
= iter
->vec
[0];
3117 /* Return the next matching CU or NULL if there are no more. */
3119 static struct dwarf2_per_cu_data
*
3120 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3122 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3124 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3126 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3127 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3128 gdb_index_symbol_kind symbol_kind
=
3129 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3130 /* Only check the symbol attributes if they're present.
3131 Indices prior to version 7 don't record them,
3132 and indices >= 7 may elide them for certain symbols
3133 (gold does this). */
3135 (per_objfile
->per_bfd
->index_table
->version
>= 7
3136 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3138 /* Don't crash on bad data. */
3139 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3141 complaint (_(".gdb_index entry has bad CU index"
3142 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3146 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3148 /* Skip if already read in. */
3149 if (per_objfile
->symtab_set_p (per_cu
))
3152 /* Check static vs global. */
3155 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3157 if (iter
->block_index
.has_value ())
3159 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3161 if (is_static
!= want_static
)
3165 /* Work around gold/15646. */
3167 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3169 if (iter
->global_seen
)
3172 iter
->global_seen
= 1;
3176 /* Only check the symbol's kind if it has one. */
3179 switch (iter
->domain
)
3182 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3183 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3184 /* Some types are also in VAR_DOMAIN. */
3185 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3189 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3193 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3197 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3213 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3219 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3220 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3223 for (int i
= 0; i
< total
; ++i
)
3225 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3227 if (!per_objfile
->symtab_set_p (per_cu
))
3230 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3231 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3234 /* This dumps minimal information about the index.
3235 It is called via "mt print objfiles".
3236 One use is to verify .gdb_index has been loaded by the
3237 gdb.dwarf2/gdb-index.exp testcase. */
3240 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3242 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3244 gdb_assert (per_objfile
->per_bfd
->using_index
);
3245 printf_filtered (".gdb_index:");
3246 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3248 printf_filtered (" version %d\n",
3249 per_objfile
->per_bfd
->index_table
->version
);
3252 printf_filtered (" faked for \"readnow\"\n");
3253 printf_filtered ("\n");
3257 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3259 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3260 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3262 for (int i
= 0; i
< total_units
; ++i
)
3264 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3266 /* We don't want to directly expand a partial CU, because if we
3267 read it with the wrong language, then assertion failures can
3268 be triggered later on. See PR symtab/23010. So, tell
3269 dw2_instantiate_symtab to skip partial CUs -- any important
3270 partial CU will be read via DW_TAG_imported_unit anyway. */
3271 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3276 dw2_expand_symtabs_matching_symbol
3277 (mapped_index_base
&index
,
3278 const lookup_name_info
&lookup_name_in
,
3279 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3280 gdb::function_view
<bool (offset_type
)> match_callback
,
3281 dwarf2_per_objfile
*per_objfile
);
3284 dw2_expand_symtabs_matching_one
3285 (dwarf2_per_cu_data
*per_cu
,
3286 dwarf2_per_objfile
*per_objfile
,
3287 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3288 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3291 dwarf2_gdb_index::expand_matching_symbols
3292 (struct objfile
*objfile
,
3293 const lookup_name_info
&name
, domain_enum domain
,
3295 symbol_compare_ftype
*ordered_compare
)
3298 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3300 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3302 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3304 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3306 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3307 auto matcher
= [&] (const char *symname
)
3309 if (ordered_compare
== nullptr)
3311 return ordered_compare (symname
, match_name
) == 0;
3314 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3315 [&] (offset_type namei
)
3317 struct dw2_symtab_iterator iter
;
3318 struct dwarf2_per_cu_data
*per_cu
;
3320 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3322 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3323 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3330 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3331 proceed assuming all symtabs have been read in. */
3335 /* Starting from a search name, return the string that finds the upper
3336 bound of all strings that start with SEARCH_NAME in a sorted name
3337 list. Returns the empty string to indicate that the upper bound is
3338 the end of the list. */
3341 make_sort_after_prefix_name (const char *search_name
)
3343 /* When looking to complete "func", we find the upper bound of all
3344 symbols that start with "func" by looking for where we'd insert
3345 the closest string that would follow "func" in lexicographical
3346 order. Usually, that's "func"-with-last-character-incremented,
3347 i.e. "fund". Mind non-ASCII characters, though. Usually those
3348 will be UTF-8 multi-byte sequences, but we can't be certain.
3349 Especially mind the 0xff character, which is a valid character in
3350 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3351 rule out compilers allowing it in identifiers. Note that
3352 conveniently, strcmp/strcasecmp are specified to compare
3353 characters interpreted as unsigned char. So what we do is treat
3354 the whole string as a base 256 number composed of a sequence of
3355 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3356 to 0, and carries 1 to the following more-significant position.
3357 If the very first character in SEARCH_NAME ends up incremented
3358 and carries/overflows, then the upper bound is the end of the
3359 list. The string after the empty string is also the empty
3362 Some examples of this operation:
3364 SEARCH_NAME => "+1" RESULT
3368 "\xff" "a" "\xff" => "\xff" "b"
3373 Then, with these symbols for example:
3379 completing "func" looks for symbols between "func" and
3380 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3381 which finds "func" and "func1", but not "fund".
3385 funcÿ (Latin1 'ÿ' [0xff])
3389 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3390 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3394 ÿÿ (Latin1 'ÿ' [0xff])
3397 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3398 the end of the list.
3400 std::string after
= search_name
;
3401 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3403 if (!after
.empty ())
3404 after
.back () = (unsigned char) after
.back () + 1;
3408 /* See declaration. */
3410 std::pair
<std::vector
<name_component
>::const_iterator
,
3411 std::vector
<name_component
>::const_iterator
>
3412 mapped_index_base::find_name_components_bounds
3413 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3414 dwarf2_per_objfile
*per_objfile
) const
3417 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3419 const char *lang_name
3420 = lookup_name_without_params
.language_lookup_name (lang
);
3422 /* Comparison function object for lower_bound that matches against a
3423 given symbol name. */
3424 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3427 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3428 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3429 return name_cmp (elem_name
, name
) < 0;
3432 /* Comparison function object for upper_bound that matches against a
3433 given symbol name. */
3434 auto lookup_compare_upper
= [&] (const char *name
,
3435 const name_component
&elem
)
3437 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3438 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3439 return name_cmp (name
, elem_name
) < 0;
3442 auto begin
= this->name_components
.begin ();
3443 auto end
= this->name_components
.end ();
3445 /* Find the lower bound. */
3448 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3451 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3454 /* Find the upper bound. */
3457 if (lookup_name_without_params
.completion_mode ())
3459 /* In completion mode, we want UPPER to point past all
3460 symbols names that have the same prefix. I.e., with
3461 these symbols, and completing "func":
3463 function << lower bound
3465 other_function << upper bound
3467 We find the upper bound by looking for the insertion
3468 point of "func"-with-last-character-incremented,
3470 std::string after
= make_sort_after_prefix_name (lang_name
);
3473 return std::lower_bound (lower
, end
, after
.c_str (),
3474 lookup_compare_lower
);
3477 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3480 return {lower
, upper
};
3483 /* See declaration. */
3486 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3488 if (!this->name_components
.empty ())
3491 this->name_components_casing
= case_sensitivity
;
3493 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3495 /* The code below only knows how to break apart components of C++
3496 symbol names (and other languages that use '::' as
3497 namespace/module separator) and Ada symbol names. */
3498 auto count
= this->symbol_name_count ();
3499 for (offset_type idx
= 0; idx
< count
; idx
++)
3501 if (this->symbol_name_slot_invalid (idx
))
3504 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3506 /* Add each name component to the name component table. */
3507 unsigned int previous_len
= 0;
3509 if (strstr (name
, "::") != nullptr)
3511 for (unsigned int current_len
= cp_find_first_component (name
);
3512 name
[current_len
] != '\0';
3513 current_len
+= cp_find_first_component (name
+ current_len
))
3515 gdb_assert (name
[current_len
] == ':');
3516 this->name_components
.push_back ({previous_len
, idx
});
3517 /* Skip the '::'. */
3519 previous_len
= current_len
;
3524 /* Handle the Ada encoded (aka mangled) form here. */
3525 for (const char *iter
= strstr (name
, "__");
3527 iter
= strstr (iter
, "__"))
3529 this->name_components
.push_back ({previous_len
, idx
});
3531 previous_len
= iter
- name
;
3535 this->name_components
.push_back ({previous_len
, idx
});
3538 /* Sort name_components elements by name. */
3539 auto name_comp_compare
= [&] (const name_component
&left
,
3540 const name_component
&right
)
3542 const char *left_qualified
3543 = this->symbol_name_at (left
.idx
, per_objfile
);
3544 const char *right_qualified
3545 = this->symbol_name_at (right
.idx
, per_objfile
);
3547 const char *left_name
= left_qualified
+ left
.name_offset
;
3548 const char *right_name
= right_qualified
+ right
.name_offset
;
3550 return name_cmp (left_name
, right_name
) < 0;
3553 std::sort (this->name_components
.begin (),
3554 this->name_components
.end (),
3558 /* Helper for dw2_expand_symtabs_matching that works with a
3559 mapped_index_base instead of the containing objfile. This is split
3560 to a separate function in order to be able to unit test the
3561 name_components matching using a mock mapped_index_base. For each
3562 symbol name that matches, calls MATCH_CALLBACK, passing it the
3563 symbol's index in the mapped_index_base symbol table. */
3566 dw2_expand_symtabs_matching_symbol
3567 (mapped_index_base
&index
,
3568 const lookup_name_info
&lookup_name_in
,
3569 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3570 gdb::function_view
<bool (offset_type
)> match_callback
,
3571 dwarf2_per_objfile
*per_objfile
)
3573 lookup_name_info lookup_name_without_params
3574 = lookup_name_in
.make_ignore_params ();
3576 /* Build the symbol name component sorted vector, if we haven't
3578 index
.build_name_components (per_objfile
);
3580 /* The same symbol may appear more than once in the range though.
3581 E.g., if we're looking for symbols that complete "w", and we have
3582 a symbol named "w1::w2", we'll find the two name components for
3583 that same symbol in the range. To be sure we only call the
3584 callback once per symbol, we first collect the symbol name
3585 indexes that matched in a temporary vector and ignore
3587 std::vector
<offset_type
> matches
;
3589 struct name_and_matcher
3591 symbol_name_matcher_ftype
*matcher
;
3594 bool operator== (const name_and_matcher
&other
) const
3596 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3600 /* A vector holding all the different symbol name matchers, for all
3602 std::vector
<name_and_matcher
> matchers
;
3604 for (int i
= 0; i
< nr_languages
; i
++)
3606 enum language lang_e
= (enum language
) i
;
3608 const language_defn
*lang
= language_def (lang_e
);
3609 symbol_name_matcher_ftype
*name_matcher
3610 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3612 name_and_matcher key
{
3614 lookup_name_without_params
.language_lookup_name (lang_e
)
3617 /* Don't insert the same comparison routine more than once.
3618 Note that we do this linear walk. This is not a problem in
3619 practice because the number of supported languages is
3621 if (std::find (matchers
.begin (), matchers
.end (), key
)
3624 matchers
.push_back (std::move (key
));
3627 = index
.find_name_components_bounds (lookup_name_without_params
,
3628 lang_e
, per_objfile
);
3630 /* Now for each symbol name in range, check to see if we have a name
3631 match, and if so, call the MATCH_CALLBACK callback. */
3633 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3635 const char *qualified
3636 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3638 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3639 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3642 matches
.push_back (bounds
.first
->idx
);
3646 std::sort (matches
.begin (), matches
.end ());
3648 /* Finally call the callback, once per match. */
3651 for (offset_type idx
: matches
)
3655 if (!match_callback (idx
))
3664 /* Above we use a type wider than idx's for 'prev', since 0 and
3665 (offset_type)-1 are both possible values. */
3666 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3673 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3675 /* A mock .gdb_index/.debug_names-like name index table, enough to
3676 exercise dw2_expand_symtabs_matching_symbol, which works with the
3677 mapped_index_base interface. Builds an index from the symbol list
3678 passed as parameter to the constructor. */
3679 class mock_mapped_index
: public mapped_index_base
3682 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3683 : m_symbol_table (symbols
)
3686 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3688 /* Return the number of names in the symbol table. */
3689 size_t symbol_name_count () const override
3691 return m_symbol_table
.size ();
3694 /* Get the name of the symbol at IDX in the symbol table. */
3695 const char *symbol_name_at
3696 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3698 return m_symbol_table
[idx
];
3702 gdb::array_view
<const char *> m_symbol_table
;
3705 /* Convenience function that converts a NULL pointer to a "<null>"
3706 string, to pass to print routines. */
3709 string_or_null (const char *str
)
3711 return str
!= NULL
? str
: "<null>";
3714 /* Check if a lookup_name_info built from
3715 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3716 index. EXPECTED_LIST is the list of expected matches, in expected
3717 matching order. If no match expected, then an empty list is
3718 specified. Returns true on success. On failure prints a warning
3719 indicating the file:line that failed, and returns false. */
3722 check_match (const char *file
, int line
,
3723 mock_mapped_index
&mock_index
,
3724 const char *name
, symbol_name_match_type match_type
,
3725 bool completion_mode
,
3726 std::initializer_list
<const char *> expected_list
,
3727 dwarf2_per_objfile
*per_objfile
)
3729 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3731 bool matched
= true;
3733 auto mismatch
= [&] (const char *expected_str
,
3736 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3737 "expected=\"%s\", got=\"%s\"\n"),
3739 (match_type
== symbol_name_match_type::FULL
3741 name
, string_or_null (expected_str
), string_or_null (got
));
3745 auto expected_it
= expected_list
.begin ();
3746 auto expected_end
= expected_list
.end ();
3748 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3750 [&] (offset_type idx
)
3752 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3753 const char *expected_str
3754 = expected_it
== expected_end
? NULL
: *expected_it
++;
3756 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3757 mismatch (expected_str
, matched_name
);
3761 const char *expected_str
3762 = expected_it
== expected_end
? NULL
: *expected_it
++;
3763 if (expected_str
!= NULL
)
3764 mismatch (expected_str
, NULL
);
3769 /* The symbols added to the mock mapped_index for testing (in
3771 static const char *test_symbols
[] = {
3780 "ns2::tmpl<int>::foo2",
3781 "(anonymous namespace)::A::B::C",
3783 /* These are used to check that the increment-last-char in the
3784 matching algorithm for completion doesn't match "t1_fund" when
3785 completing "t1_func". */
3791 /* A UTF-8 name with multi-byte sequences to make sure that
3792 cp-name-parser understands this as a single identifier ("função"
3793 is "function" in PT). */
3796 /* \377 (0xff) is Latin1 'ÿ'. */
3799 /* \377 (0xff) is Latin1 'ÿ'. */
3803 /* A name with all sorts of complications. Starts with "z" to make
3804 it easier for the completion tests below. */
3805 #define Z_SYM_NAME \
3806 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3807 "::tuple<(anonymous namespace)::ui*, " \
3808 "std::default_delete<(anonymous namespace)::ui>, void>"
3813 /* Returns true if the mapped_index_base::find_name_component_bounds
3814 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3815 in completion mode. */
3818 check_find_bounds_finds (mapped_index_base
&index
,
3819 const char *search_name
,
3820 gdb::array_view
<const char *> expected_syms
,
3821 dwarf2_per_objfile
*per_objfile
)
3823 lookup_name_info
lookup_name (search_name
,
3824 symbol_name_match_type::FULL
, true);
3826 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3830 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3831 if (distance
!= expected_syms
.size ())
3834 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3836 auto nc_elem
= bounds
.first
+ exp_elem
;
3837 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3838 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3845 /* Test the lower-level mapped_index::find_name_component_bounds
3849 test_mapped_index_find_name_component_bounds ()
3851 mock_mapped_index
mock_index (test_symbols
);
3853 mock_index
.build_name_components (NULL
/* per_objfile */);
3855 /* Test the lower-level mapped_index::find_name_component_bounds
3856 method in completion mode. */
3858 static const char *expected_syms
[] = {
3863 SELF_CHECK (check_find_bounds_finds
3864 (mock_index
, "t1_func", expected_syms
,
3865 NULL
/* per_objfile */));
3868 /* Check that the increment-last-char in the name matching algorithm
3869 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3871 static const char *expected_syms1
[] = {
3875 SELF_CHECK (check_find_bounds_finds
3876 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3878 static const char *expected_syms2
[] = {
3881 SELF_CHECK (check_find_bounds_finds
3882 (mock_index
, "\377\377", expected_syms2
,
3883 NULL
/* per_objfile */));
3887 /* Test dw2_expand_symtabs_matching_symbol. */
3890 test_dw2_expand_symtabs_matching_symbol ()
3892 mock_mapped_index
mock_index (test_symbols
);
3894 /* We let all tests run until the end even if some fails, for debug
3896 bool any_mismatch
= false;
3898 /* Create the expected symbols list (an initializer_list). Needed
3899 because lists have commas, and we need to pass them to CHECK,
3900 which is a macro. */
3901 #define EXPECT(...) { __VA_ARGS__ }
3903 /* Wrapper for check_match that passes down the current
3904 __FILE__/__LINE__. */
3905 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
3906 any_mismatch |= !check_match (__FILE__, __LINE__, \
3908 NAME, MATCH_TYPE, COMPLETION_MODE, \
3909 EXPECTED_LIST, NULL)
3911 /* Identity checks. */
3912 for (const char *sym
: test_symbols
)
3914 /* Should be able to match all existing symbols. */
3915 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
3918 /* Should be able to match all existing symbols with
3920 std::string with_params
= std::string (sym
) + "(int)";
3921 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3924 /* Should be able to match all existing symbols with
3925 parameters and qualifiers. */
3926 with_params
= std::string (sym
) + " ( int ) const";
3927 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3930 /* This should really find sym, but cp-name-parser.y doesn't
3931 know about lvalue/rvalue qualifiers yet. */
3932 with_params
= std::string (sym
) + " ( int ) &&";
3933 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3937 /* Check that the name matching algorithm for completion doesn't get
3938 confused with Latin1 'ÿ' / 0xff. */
3940 static const char str
[] = "\377";
3941 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3942 EXPECT ("\377", "\377\377123"));
3945 /* Check that the increment-last-char in the matching algorithm for
3946 completion doesn't match "t1_fund" when completing "t1_func". */
3948 static const char str
[] = "t1_func";
3949 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3950 EXPECT ("t1_func", "t1_func1"));
3953 /* Check that completion mode works at each prefix of the expected
3956 static const char str
[] = "function(int)";
3957 size_t len
= strlen (str
);
3960 for (size_t i
= 1; i
< len
; i
++)
3962 lookup
.assign (str
, i
);
3963 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3964 EXPECT ("function"));
3968 /* While "w" is a prefix of both components, the match function
3969 should still only be called once. */
3971 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
3973 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
3977 /* Same, with a "complicated" symbol. */
3979 static const char str
[] = Z_SYM_NAME
;
3980 size_t len
= strlen (str
);
3983 for (size_t i
= 1; i
< len
; i
++)
3985 lookup
.assign (str
, i
);
3986 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3987 EXPECT (Z_SYM_NAME
));
3991 /* In FULL mode, an incomplete symbol doesn't match. */
3993 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
3997 /* A complete symbol with parameters matches any overload, since the
3998 index has no overload info. */
4000 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4001 EXPECT ("std::zfunction", "std::zfunction2"));
4002 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4003 EXPECT ("std::zfunction", "std::zfunction2"));
4004 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4005 EXPECT ("std::zfunction", "std::zfunction2"));
4008 /* Check that whitespace is ignored appropriately. A symbol with a
4009 template argument list. */
4011 static const char expected
[] = "ns::foo<int>";
4012 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4014 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4018 /* Check that whitespace is ignored appropriately. A symbol with a
4019 template argument list that includes a pointer. */
4021 static const char expected
[] = "ns::foo<char*>";
4022 /* Try both completion and non-completion modes. */
4023 static const bool completion_mode
[2] = {false, true};
4024 for (size_t i
= 0; i
< 2; i
++)
4026 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4027 completion_mode
[i
], EXPECT (expected
));
4028 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4029 completion_mode
[i
], EXPECT (expected
));
4031 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4032 completion_mode
[i
], EXPECT (expected
));
4033 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4034 completion_mode
[i
], EXPECT (expected
));
4039 /* Check method qualifiers are ignored. */
4040 static const char expected
[] = "ns::foo<char*>";
4041 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4042 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4043 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4044 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4045 CHECK_MATCH ("foo < char * > ( int ) const",
4046 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4047 CHECK_MATCH ("foo < char * > ( int ) &&",
4048 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4051 /* Test lookup names that don't match anything. */
4053 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4056 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4060 /* Some wild matching tests, exercising "(anonymous namespace)",
4061 which should not be confused with a parameter list. */
4063 static const char *syms
[] = {
4067 "A :: B :: C ( int )",
4072 for (const char *s
: syms
)
4074 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4075 EXPECT ("(anonymous namespace)::A::B::C"));
4080 static const char expected
[] = "ns2::tmpl<int>::foo2";
4081 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4083 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4087 SELF_CHECK (!any_mismatch
);
4096 test_mapped_index_find_name_component_bounds ();
4097 test_dw2_expand_symtabs_matching_symbol ();
4100 }} // namespace selftests::dw2_expand_symtabs_matching
4102 #endif /* GDB_SELF_TEST */
4104 /* If FILE_MATCHER is NULL or if PER_CU has
4105 dwarf2_per_cu_quick_data::MARK set (see
4106 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4107 EXPANSION_NOTIFY on it. */
4110 dw2_expand_symtabs_matching_one
4111 (dwarf2_per_cu_data
*per_cu
,
4112 dwarf2_per_objfile
*per_objfile
,
4113 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4114 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4116 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4118 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4120 compunit_symtab
*symtab
4121 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4122 gdb_assert (symtab
!= nullptr);
4124 if (expansion_notify
!= NULL
&& symtab_was_null
)
4125 return expansion_notify (symtab
);
4130 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4131 matched, to expand corresponding CUs that were marked. IDX is the
4132 index of the symbol name that matched. */
4135 dw2_expand_marked_cus
4136 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4137 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4138 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4139 block_search_flags search_flags
,
4142 offset_type vec_len
, vec_idx
;
4143 bool global_seen
= false;
4144 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4146 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4148 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4150 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4151 /* This value is only valid for index versions >= 7. */
4152 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4153 gdb_index_symbol_kind symbol_kind
=
4154 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4155 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4156 /* Only check the symbol attributes if they're present.
4157 Indices prior to version 7 don't record them,
4158 and indices >= 7 may elide them for certain symbols
4159 (gold does this). */
4162 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4164 /* Work around gold/15646. */
4167 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4175 /* Only check the symbol's kind if it has one. */
4180 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4185 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4191 case VARIABLES_DOMAIN
:
4192 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4195 case FUNCTIONS_DOMAIN
:
4196 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4200 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4203 case MODULES_DOMAIN
:
4204 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4212 /* Don't crash on bad data. */
4213 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4215 complaint (_(".gdb_index entry has bad CU index"
4216 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4220 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4221 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4229 /* If FILE_MATCHER is non-NULL, set all the
4230 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4231 that match FILE_MATCHER. */
4234 dw_expand_symtabs_matching_file_matcher
4235 (dwarf2_per_objfile
*per_objfile
,
4236 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4238 if (file_matcher
== NULL
)
4241 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4243 NULL
, xcalloc
, xfree
));
4244 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4246 NULL
, xcalloc
, xfree
));
4248 /* The rule is CUs specify all the files, including those used by
4249 any TU, so there's no need to scan TUs here. */
4251 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4255 if (per_cu
->is_debug_types
)
4257 per_cu
->v
.quick
->mark
= 0;
4259 /* We only need to look at symtabs not already expanded. */
4260 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4263 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4265 if (file_data
== NULL
)
4268 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4270 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4272 per_cu
->v
.quick
->mark
= 1;
4276 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4278 const char *this_real_name
;
4280 if (file_matcher (file_data
->file_names
[j
], false))
4282 per_cu
->v
.quick
->mark
= 1;
4286 /* Before we invoke realpath, which can get expensive when many
4287 files are involved, do a quick comparison of the basenames. */
4288 if (!basenames_may_differ
4289 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4293 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4294 if (file_matcher (this_real_name
, false))
4296 per_cu
->v
.quick
->mark
= 1;
4301 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4302 ? visited_found
.get ()
4303 : visited_not_found
.get (),
4310 dwarf2_gdb_index::expand_symtabs_matching
4311 (struct objfile
*objfile
,
4312 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4313 const lookup_name_info
*lookup_name
,
4314 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4315 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4316 block_search_flags search_flags
,
4318 enum search_domain kind
)
4320 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4322 /* index_table is NULL if OBJF_READNOW. */
4323 if (!per_objfile
->per_bfd
->index_table
)
4326 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4328 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4330 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4334 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
4342 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4345 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4347 [&] (offset_type idx
)
4349 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4350 expansion_notify
, search_flags
, kind
))
4358 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4361 static struct compunit_symtab
*
4362 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4367 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4368 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4371 if (cust
->includes
== NULL
)
4374 for (i
= 0; cust
->includes
[i
]; ++i
)
4376 struct compunit_symtab
*s
= cust
->includes
[i
];
4378 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4386 struct compunit_symtab
*
4387 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4388 (struct objfile
*objfile
,
4389 struct bound_minimal_symbol msymbol
,
4391 struct obj_section
*section
,
4394 struct dwarf2_per_cu_data
*data
;
4395 struct compunit_symtab
*result
;
4397 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4398 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4401 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4402 data
= ((struct dwarf2_per_cu_data
*)
4403 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4408 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4409 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4410 paddress (objfile
->arch (), pc
));
4412 result
= recursively_find_pc_sect_compunit_symtab
4413 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4415 gdb_assert (result
!= NULL
);
4420 dwarf2_base_index_functions::map_symbol_filenames
4421 (struct objfile
*objfile
,
4422 gdb::function_view
<symbol_filename_ftype
> fun
,
4425 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4427 /* Use caches to ensure we only call FUN once for each filename. */
4428 filename_seen_cache filenames_cache
;
4429 std::unordered_set
<quick_file_names
*> qfn_cache
;
4431 /* The rule is CUs specify all the files, including those used by any TU,
4432 so there's no need to scan TUs here. We can ignore file names coming
4433 from already-expanded CUs. It is possible that an expanded CU might
4434 reuse the file names data from a currently unexpanded CU, in this
4435 case we don't want to report the files from the unexpanded CU. */
4437 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4439 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4441 if (per_cu
->v
.quick
->file_names
!= nullptr)
4442 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4446 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4448 /* We only need to look at symtabs not already expanded. */
4449 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4452 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4454 if (file_data
== nullptr
4455 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4458 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4460 const char *filename
= file_data
->file_names
[j
];
4461 filenames_cache
.seen (filename
);
4465 filenames_cache
.traverse ([&] (const char *filename
)
4467 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4470 this_real_name
= gdb_realpath (filename
);
4471 fun (filename
, this_real_name
.get ());
4476 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4481 /* DWARF-5 debug_names reader. */
4483 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4484 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4486 /* A helper function that reads the .debug_names section in SECTION
4487 and fills in MAP. FILENAME is the name of the file containing the
4488 section; it is used for error reporting.
4490 Returns true if all went well, false otherwise. */
4493 read_debug_names_from_section (struct objfile
*objfile
,
4494 const char *filename
,
4495 struct dwarf2_section_info
*section
,
4496 mapped_debug_names
&map
)
4498 if (section
->empty ())
4501 /* Older elfutils strip versions could keep the section in the main
4502 executable while splitting it for the separate debug info file. */
4503 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4506 section
->read (objfile
);
4508 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4510 const gdb_byte
*addr
= section
->buffer
;
4512 bfd
*const abfd
= section
->get_bfd_owner ();
4514 unsigned int bytes_read
;
4515 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4518 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4519 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4520 if (bytes_read
+ length
!= section
->size
)
4522 /* There may be multiple per-CU indices. */
4523 warning (_("Section .debug_names in %s length %s does not match "
4524 "section length %s, ignoring .debug_names."),
4525 filename
, plongest (bytes_read
+ length
),
4526 pulongest (section
->size
));
4530 /* The version number. */
4531 uint16_t version
= read_2_bytes (abfd
, addr
);
4535 warning (_("Section .debug_names in %s has unsupported version %d, "
4536 "ignoring .debug_names."),
4542 uint16_t padding
= read_2_bytes (abfd
, addr
);
4546 warning (_("Section .debug_names in %s has unsupported padding %d, "
4547 "ignoring .debug_names."),
4552 /* comp_unit_count - The number of CUs in the CU list. */
4553 map
.cu_count
= read_4_bytes (abfd
, addr
);
4556 /* local_type_unit_count - The number of TUs in the local TU
4558 map
.tu_count
= read_4_bytes (abfd
, addr
);
4561 /* foreign_type_unit_count - The number of TUs in the foreign TU
4563 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4565 if (foreign_tu_count
!= 0)
4567 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4568 "ignoring .debug_names."),
4569 filename
, static_cast<unsigned long> (foreign_tu_count
));
4573 /* bucket_count - The number of hash buckets in the hash lookup
4575 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4578 /* name_count - The number of unique names in the index. */
4579 map
.name_count
= read_4_bytes (abfd
, addr
);
4582 /* abbrev_table_size - The size in bytes of the abbreviations
4584 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4587 /* augmentation_string_size - The size in bytes of the augmentation
4588 string. This value is rounded up to a multiple of 4. */
4589 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4591 map
.augmentation_is_gdb
= ((augmentation_string_size
4592 == sizeof (dwarf5_augmentation
))
4593 && memcmp (addr
, dwarf5_augmentation
,
4594 sizeof (dwarf5_augmentation
)) == 0);
4595 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4596 addr
+= augmentation_string_size
;
4599 map
.cu_table_reordered
= addr
;
4600 addr
+= map
.cu_count
* map
.offset_size
;
4602 /* List of Local TUs */
4603 map
.tu_table_reordered
= addr
;
4604 addr
+= map
.tu_count
* map
.offset_size
;
4606 /* Hash Lookup Table */
4607 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4608 addr
+= map
.bucket_count
* 4;
4609 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4610 addr
+= map
.name_count
* 4;
4613 map
.name_table_string_offs_reordered
= addr
;
4614 addr
+= map
.name_count
* map
.offset_size
;
4615 map
.name_table_entry_offs_reordered
= addr
;
4616 addr
+= map
.name_count
* map
.offset_size
;
4618 const gdb_byte
*abbrev_table_start
= addr
;
4621 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4626 const auto insertpair
4627 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4628 if (!insertpair
.second
)
4630 warning (_("Section .debug_names in %s has duplicate index %s, "
4631 "ignoring .debug_names."),
4632 filename
, pulongest (index_num
));
4635 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4636 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4641 mapped_debug_names::index_val::attr attr
;
4642 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4644 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4646 if (attr
.form
== DW_FORM_implicit_const
)
4648 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4652 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4654 indexval
.attr_vec
.push_back (std::move (attr
));
4657 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4659 warning (_("Section .debug_names in %s has abbreviation_table "
4660 "of size %s vs. written as %u, ignoring .debug_names."),
4661 filename
, plongest (addr
- abbrev_table_start
),
4665 map
.entry_pool
= addr
;
4670 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4674 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4675 const mapped_debug_names
&map
,
4676 dwarf2_section_info
§ion
,
4679 if (!map
.augmentation_is_gdb
)
4681 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4683 sect_offset sect_off
4684 = (sect_offset
) (extract_unsigned_integer
4685 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4687 map
.dwarf5_byte_order
));
4688 /* We don't know the length of the CU, because the CU list in a
4689 .debug_names index can be incomplete, so we can't use the start
4690 of the next CU as end of this CU. We create the CUs here with
4691 length 0, and in cutu_reader::cutu_reader we'll fill in the
4693 dwarf2_per_cu_data_up per_cu
4694 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4696 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4701 sect_offset sect_off_prev
;
4702 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4704 sect_offset sect_off_next
;
4705 if (i
< map
.cu_count
)
4708 = (sect_offset
) (extract_unsigned_integer
4709 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4711 map
.dwarf5_byte_order
));
4714 sect_off_next
= (sect_offset
) section
.size
;
4717 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4718 dwarf2_per_cu_data_up per_cu
4719 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4720 sect_off_prev
, length
);
4721 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4723 sect_off_prev
= sect_off_next
;
4727 /* Read the CU list from the mapped index, and use it to create all
4728 the CU objects for this dwarf2_per_objfile. */
4731 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4732 const mapped_debug_names
&map
,
4733 const mapped_debug_names
&dwz_map
)
4735 gdb_assert (per_bfd
->all_comp_units
.empty ());
4736 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4738 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4739 false /* is_dwz */);
4741 if (dwz_map
.cu_count
== 0)
4744 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4745 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4749 /* Read .debug_names. If everything went ok, initialize the "quick"
4750 elements of all the CUs and return true. Otherwise, return false. */
4753 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4755 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4756 mapped_debug_names dwz_map
;
4757 struct objfile
*objfile
= per_objfile
->objfile
;
4758 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4760 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4761 &per_bfd
->debug_names
, *map
))
4764 /* Don't use the index if it's empty. */
4765 if (map
->name_count
== 0)
4768 /* If there is a .dwz file, read it so we can get its CU list as
4770 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4773 if (!read_debug_names_from_section (objfile
,
4774 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4775 &dwz
->debug_names
, dwz_map
))
4777 warning (_("could not read '.debug_names' section from %s; skipping"),
4778 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4783 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4785 if (map
->tu_count
!= 0)
4787 /* We can only handle a single .debug_types when we have an
4789 if (per_bfd
->types
.size () != 1)
4792 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4794 create_signatured_type_table_from_debug_names
4795 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4798 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4800 per_bfd
->debug_names_table
= std::move (map
);
4801 per_bfd
->using_index
= 1;
4802 per_bfd
->quick_file_names_table
=
4803 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4808 /* Type used to manage iterating over all CUs looking for a symbol for
4811 class dw2_debug_names_iterator
4814 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4815 block_search_flags block_index
,
4817 const char *name
, dwarf2_per_objfile
*per_objfile
)
4818 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4819 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4820 m_per_objfile (per_objfile
)
4823 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4824 search_domain search
, uint32_t namei
,
4825 dwarf2_per_objfile
*per_objfile
,
4826 domain_enum domain
= UNDEF_DOMAIN
)
4830 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4831 m_per_objfile (per_objfile
)
4834 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4835 block_search_flags block_index
, domain_enum domain
,
4836 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4837 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4838 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4839 m_per_objfile (per_objfile
)
4842 /* Return the next matching CU or NULL if there are no more. */
4843 dwarf2_per_cu_data
*next ();
4846 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4848 dwarf2_per_objfile
*per_objfile
);
4849 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4851 dwarf2_per_objfile
*per_objfile
);
4853 /* The internalized form of .debug_names. */
4854 const mapped_debug_names
&m_map
;
4856 /* Restrict the search to these blocks. */
4857 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4858 | SEARCH_STATIC_BLOCK
);
4860 /* The kind of symbol we're looking for. */
4861 const domain_enum m_domain
= UNDEF_DOMAIN
;
4862 const search_domain m_search
= ALL_DOMAIN
;
4864 /* The list of CUs from the index entry of the symbol, or NULL if
4866 const gdb_byte
*m_addr
;
4868 dwarf2_per_objfile
*m_per_objfile
;
4872 mapped_debug_names::namei_to_name
4873 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
4875 const ULONGEST namei_string_offs
4876 = extract_unsigned_integer ((name_table_string_offs_reordered
4877 + namei
* offset_size
),
4880 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
4883 /* Find a slot in .debug_names for the object named NAME. If NAME is
4884 found, return pointer to its pool data. If NAME cannot be found,
4888 dw2_debug_names_iterator::find_vec_in_debug_names
4889 (const mapped_debug_names
&map
, const char *name
,
4890 dwarf2_per_objfile
*per_objfile
)
4892 int (*cmp
) (const char *, const char *);
4894 gdb::unique_xmalloc_ptr
<char> without_params
;
4895 if (current_language
->la_language
== language_cplus
4896 || current_language
->la_language
== language_fortran
4897 || current_language
->la_language
== language_d
)
4899 /* NAME is already canonical. Drop any qualifiers as
4900 .debug_names does not contain any. */
4902 if (strchr (name
, '(') != NULL
)
4904 without_params
= cp_remove_params (name
);
4905 if (without_params
!= NULL
)
4906 name
= without_params
.get ();
4910 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
4912 const uint32_t full_hash
= dwarf5_djb_hash (name
);
4914 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4915 (map
.bucket_table_reordered
4916 + (full_hash
% map
.bucket_count
)), 4,
4917 map
.dwarf5_byte_order
);
4921 if (namei
>= map
.name_count
)
4923 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4925 namei
, map
.name_count
,
4926 objfile_name (per_objfile
->objfile
));
4932 const uint32_t namei_full_hash
4933 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4934 (map
.hash_table_reordered
+ namei
), 4,
4935 map
.dwarf5_byte_order
);
4936 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
4939 if (full_hash
== namei_full_hash
)
4941 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
4943 #if 0 /* An expensive sanity check. */
4944 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
4946 complaint (_("Wrong .debug_names hash for string at index %u "
4948 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
4953 if (cmp (namei_string
, name
) == 0)
4955 const ULONGEST namei_entry_offs
4956 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4957 + namei
* map
.offset_size
),
4958 map
.offset_size
, map
.dwarf5_byte_order
);
4959 return map
.entry_pool
+ namei_entry_offs
;
4964 if (namei
>= map
.name_count
)
4970 dw2_debug_names_iterator::find_vec_in_debug_names
4971 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4973 if (namei
>= map
.name_count
)
4975 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4977 namei
, map
.name_count
,
4978 objfile_name (per_objfile
->objfile
));
4982 const ULONGEST namei_entry_offs
4983 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4984 + namei
* map
.offset_size
),
4985 map
.offset_size
, map
.dwarf5_byte_order
);
4986 return map
.entry_pool
+ namei_entry_offs
;
4989 /* See dw2_debug_names_iterator. */
4991 dwarf2_per_cu_data
*
4992 dw2_debug_names_iterator::next ()
4997 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
4998 struct objfile
*objfile
= m_per_objfile
->objfile
;
4999 bfd
*const abfd
= objfile
->obfd
;
5003 unsigned int bytes_read
;
5004 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5005 m_addr
+= bytes_read
;
5009 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5010 if (indexval_it
== m_map
.abbrev_map
.cend ())
5012 complaint (_("Wrong .debug_names undefined abbrev code %s "
5014 pulongest (abbrev
), objfile_name (objfile
));
5017 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5018 enum class symbol_linkage
{
5022 } symbol_linkage_
= symbol_linkage::unknown
;
5023 dwarf2_per_cu_data
*per_cu
= NULL
;
5024 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5029 case DW_FORM_implicit_const
:
5030 ull
= attr
.implicit_const
;
5032 case DW_FORM_flag_present
:
5036 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5037 m_addr
+= bytes_read
;
5040 ull
= read_4_bytes (abfd
, m_addr
);
5044 ull
= read_8_bytes (abfd
, m_addr
);
5047 case DW_FORM_ref_sig8
:
5048 ull
= read_8_bytes (abfd
, m_addr
);
5052 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5053 dwarf_form_name (attr
.form
),
5054 objfile_name (objfile
));
5057 switch (attr
.dw_idx
)
5059 case DW_IDX_compile_unit
:
5060 /* Don't crash on bad data. */
5061 if (ull
>= per_bfd
->all_comp_units
.size ())
5063 complaint (_(".debug_names entry has bad CU index %s"
5066 objfile_name (objfile
));
5069 per_cu
= per_bfd
->get_cu (ull
);
5071 case DW_IDX_type_unit
:
5072 /* Don't crash on bad data. */
5073 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5075 complaint (_(".debug_names entry has bad TU index %s"
5078 objfile_name (objfile
));
5081 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5083 case DW_IDX_die_offset
:
5084 /* In a per-CU index (as opposed to a per-module index), index
5085 entries without CU attribute implicitly refer to the single CU. */
5087 per_cu
= per_bfd
->get_cu (0);
5089 case DW_IDX_GNU_internal
:
5090 if (!m_map
.augmentation_is_gdb
)
5092 symbol_linkage_
= symbol_linkage::static_
;
5094 case DW_IDX_GNU_external
:
5095 if (!m_map
.augmentation_is_gdb
)
5097 symbol_linkage_
= symbol_linkage::extern_
;
5102 /* Skip if already read in. */
5103 if (m_per_objfile
->symtab_set_p (per_cu
))
5106 /* Check static vs global. */
5107 if (symbol_linkage_
!= symbol_linkage::unknown
)
5109 if (symbol_linkage_
== symbol_linkage::static_
)
5111 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5116 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5121 /* Match dw2_symtab_iter_next, symbol_kind
5122 and debug_names::psymbol_tag. */
5126 switch (indexval
.dwarf_tag
)
5128 case DW_TAG_variable
:
5129 case DW_TAG_subprogram
:
5130 /* Some types are also in VAR_DOMAIN. */
5131 case DW_TAG_typedef
:
5132 case DW_TAG_structure_type
:
5139 switch (indexval
.dwarf_tag
)
5141 case DW_TAG_typedef
:
5142 case DW_TAG_structure_type
:
5149 switch (indexval
.dwarf_tag
)
5152 case DW_TAG_variable
:
5159 switch (indexval
.dwarf_tag
)
5171 /* Match dw2_expand_symtabs_matching, symbol_kind and
5172 debug_names::psymbol_tag. */
5175 case VARIABLES_DOMAIN
:
5176 switch (indexval
.dwarf_tag
)
5178 case DW_TAG_variable
:
5184 case FUNCTIONS_DOMAIN
:
5185 switch (indexval
.dwarf_tag
)
5187 case DW_TAG_subprogram
:
5194 switch (indexval
.dwarf_tag
)
5196 case DW_TAG_typedef
:
5197 case DW_TAG_structure_type
:
5203 case MODULES_DOMAIN
:
5204 switch (indexval
.dwarf_tag
)
5218 /* This dumps minimal information about .debug_names. It is called
5219 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5220 uses this to verify that .debug_names has been loaded. */
5223 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5225 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5227 gdb_assert (per_objfile
->per_bfd
->using_index
);
5228 printf_filtered (".debug_names:");
5229 if (per_objfile
->per_bfd
->debug_names_table
)
5230 printf_filtered (" exists\n");
5232 printf_filtered (" faked for \"readnow\"\n");
5233 printf_filtered ("\n");
5237 dwarf2_debug_names_index::expand_matching_symbols
5238 (struct objfile
*objfile
,
5239 const lookup_name_info
&name
, domain_enum domain
,
5241 symbol_compare_ftype
*ordered_compare
)
5243 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5245 /* debug_names_table is NULL if OBJF_READNOW. */
5246 if (!per_objfile
->per_bfd
->debug_names_table
)
5249 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5250 const block_search_flags block_flags
5251 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5253 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5254 auto matcher
= [&] (const char *symname
)
5256 if (ordered_compare
== nullptr)
5258 return ordered_compare (symname
, match_name
) == 0;
5261 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5262 [&] (offset_type namei
)
5264 /* The name was matched, now expand corresponding CUs that were
5266 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5269 struct dwarf2_per_cu_data
*per_cu
;
5270 while ((per_cu
= iter
.next ()) != NULL
)
5271 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5278 dwarf2_debug_names_index::expand_symtabs_matching
5279 (struct objfile
*objfile
,
5280 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5281 const lookup_name_info
*lookup_name
,
5282 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5283 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5284 block_search_flags search_flags
,
5286 enum search_domain kind
)
5288 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5290 /* debug_names_table is NULL if OBJF_READNOW. */
5291 if (!per_objfile
->per_bfd
->debug_names_table
)
5294 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5296 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5298 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5302 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
5310 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5313 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5315 [&] (offset_type namei
)
5317 /* The name was matched, now expand corresponding CUs that were
5319 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5321 struct dwarf2_per_cu_data
*per_cu
;
5322 while ((per_cu
= iter
.next ()) != NULL
)
5323 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5333 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5334 to either a dwarf2_per_bfd or dwz_file object. */
5336 template <typename T
>
5337 static gdb::array_view
<const gdb_byte
>
5338 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5340 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5342 if (section
->empty ())
5345 /* Older elfutils strip versions could keep the section in the main
5346 executable while splitting it for the separate debug info file. */
5347 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5350 section
->read (obj
);
5352 /* dwarf2_section_info::size is a bfd_size_type, while
5353 gdb::array_view works with size_t. On 32-bit hosts, with
5354 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5355 is 32-bit. So we need an explicit narrowing conversion here.
5356 This is fine, because it's impossible to allocate or mmap an
5357 array/buffer larger than what size_t can represent. */
5358 return gdb::make_array_view (section
->buffer
, section
->size
);
5361 /* Lookup the index cache for the contents of the index associated to
5364 static gdb::array_view
<const gdb_byte
>
5365 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5367 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5368 if (build_id
== nullptr)
5371 return global_index_cache
.lookup_gdb_index (build_id
,
5372 &dwarf2_per_bfd
->index_cache_res
);
5375 /* Same as the above, but for DWZ. */
5377 static gdb::array_view
<const gdb_byte
>
5378 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5380 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5381 if (build_id
== nullptr)
5384 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5387 /* See dwarf2/public.h. */
5390 dwarf2_initialize_objfile (struct objfile
*objfile
)
5392 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5393 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5395 dwarf_read_debug_printf ("called");
5397 /* If we're about to read full symbols, don't bother with the
5398 indices. In this case we also don't care if some other debug
5399 format is making psymtabs, because they are all about to be
5401 if ((objfile
->flags
& OBJF_READNOW
))
5403 dwarf_read_debug_printf ("readnow requested");
5405 /* When using READNOW, the using_index flag (set below) indicates that
5406 PER_BFD was already initialized, when we loaded some other objfile. */
5407 if (per_bfd
->using_index
)
5409 dwarf_read_debug_printf ("using_index already set");
5410 per_objfile
->resize_symtabs ();
5411 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5415 per_bfd
->using_index
= 1;
5416 create_all_comp_units (per_objfile
);
5417 per_bfd
->quick_file_names_table
5418 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5419 per_objfile
->resize_symtabs ();
5421 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5423 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5425 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5426 struct dwarf2_per_cu_quick_data
);
5429 /* Arrange for gdb to see the "quick" functions. However, these
5430 functions will be no-ops because we will have expanded all
5432 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5436 /* Was a debug names index already read when we processed an objfile sharing
5438 if (per_bfd
->debug_names_table
!= nullptr)
5440 dwarf_read_debug_printf ("re-using shared debug names table");
5441 per_objfile
->resize_symtabs ();
5442 objfile
->qf
.push_front (make_dwarf_debug_names ());
5446 /* Was a GDB index already read when we processed an objfile sharing
5448 if (per_bfd
->index_table
!= nullptr)
5450 dwarf_read_debug_printf ("re-using shared index table");
5451 per_objfile
->resize_symtabs ();
5452 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5456 /* There might already be partial symtabs built for this BFD. This happens
5457 when loading the same binary twice with the index-cache enabled. If so,
5458 don't try to read an index. The objfile / per_objfile initialization will
5459 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5461 if (per_bfd
->partial_symtabs
!= nullptr)
5463 dwarf_read_debug_printf ("re-using shared partial symtabs");
5464 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5468 if (dwarf2_read_debug_names (per_objfile
))
5470 dwarf_read_debug_printf ("found debug names");
5471 per_objfile
->resize_symtabs ();
5472 objfile
->qf
.push_front (make_dwarf_debug_names ());
5476 if (dwarf2_read_gdb_index (per_objfile
,
5477 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5478 get_gdb_index_contents_from_section
<dwz_file
>))
5480 dwarf_read_debug_printf ("found gdb index from file");
5481 per_objfile
->resize_symtabs ();
5482 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5486 /* ... otherwise, try to find the index in the index cache. */
5487 if (dwarf2_read_gdb_index (per_objfile
,
5488 get_gdb_index_contents_from_cache
,
5489 get_gdb_index_contents_from_cache_dwz
))
5491 dwarf_read_debug_printf ("found gdb index from cache");
5492 global_index_cache
.hit ();
5493 per_objfile
->resize_symtabs ();
5494 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5498 global_index_cache
.miss ();
5499 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5504 /* Build a partial symbol table. */
5507 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5509 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5510 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5512 if (per_bfd
->partial_symtabs
!= nullptr)
5514 /* Partial symbols were already read, so now we can simply
5518 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5519 objfile
->qf
.emplace_front (psf
);
5522 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5523 per_objfile
->resize_symtabs ();
5529 psf
= new psymbol_functions
;
5530 objfile
->qf
.emplace_front (psf
);
5532 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5533 = psf
->get_partial_symtabs ();
5535 /* Set the local reference to partial symtabs, so that we don't try
5536 to read them again if reading another objfile with the same BFD.
5537 If we can't in fact share, this won't make a difference anyway as
5538 the dwarf2_per_bfd object won't be shared. */
5539 per_bfd
->partial_symtabs
= partial_symtabs
;
5543 /* This isn't really ideal: all the data we allocate on the
5544 objfile's obstack is still uselessly kept around. However,
5545 freeing it seems unsafe. */
5546 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5547 dwarf2_build_psymtabs_hard (per_objfile
);
5550 per_objfile
->resize_symtabs ();
5552 /* (maybe) store an index in the cache. */
5553 global_index_cache
.store (per_objfile
);
5555 catch (const gdb_exception_error
&except
)
5557 exception_print (gdb_stderr
, except
);
5561 /* Find the base address of the compilation unit for range lists and
5562 location lists. It will normally be specified by DW_AT_low_pc.
5563 In DWARF-3 draft 4, the base address could be overridden by
5564 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5565 compilation units with discontinuous ranges. */
5568 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5570 struct attribute
*attr
;
5572 cu
->base_address
.reset ();
5574 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5575 if (attr
!= nullptr)
5576 cu
->base_address
= attr
->as_address ();
5579 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5580 if (attr
!= nullptr)
5581 cu
->base_address
= attr
->as_address ();
5585 /* Helper function that returns the proper abbrev section for
5588 static struct dwarf2_section_info
*
5589 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5591 struct dwarf2_section_info
*abbrev
;
5592 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5594 if (this_cu
->is_dwz
)
5595 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5597 abbrev
= &per_bfd
->abbrev
;
5602 /* Fetch the abbreviation table offset from a comp or type unit header. */
5605 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5606 struct dwarf2_section_info
*section
,
5607 sect_offset sect_off
)
5609 bfd
*abfd
= section
->get_bfd_owner ();
5610 const gdb_byte
*info_ptr
;
5611 unsigned int initial_length_size
, offset_size
;
5614 section
->read (per_objfile
->objfile
);
5615 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5616 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5617 offset_size
= initial_length_size
== 4 ? 4 : 8;
5618 info_ptr
+= initial_length_size
;
5620 version
= read_2_bytes (abfd
, info_ptr
);
5624 /* Skip unit type and address size. */
5628 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5631 /* A partial symtab that is used only for include files. */
5632 struct dwarf2_include_psymtab
: public partial_symtab
5634 dwarf2_include_psymtab (const char *filename
,
5635 psymtab_storage
*partial_symtabs
,
5636 objfile_per_bfd_storage
*objfile_per_bfd
)
5637 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5641 void read_symtab (struct objfile
*objfile
) override
5643 /* It's an include file, no symbols to read for it.
5644 Everything is in the includer symtab. */
5646 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5647 expansion of the includer psymtab. We use the dependencies[0] field to
5648 model the includer. But if we go the regular route of calling
5649 expand_psymtab here, and having expand_psymtab call expand_dependencies
5650 to expand the includer, we'll only use expand_psymtab on the includer
5651 (making it a non-toplevel psymtab), while if we expand the includer via
5652 another path, we'll use read_symtab (making it a toplevel psymtab).
5653 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5654 psymtab, and trigger read_symtab on the includer here directly. */
5655 includer ()->read_symtab (objfile
);
5658 void expand_psymtab (struct objfile
*objfile
) override
5660 /* This is not called by read_symtab, and should not be called by any
5661 expand_dependencies. */
5665 bool readin_p (struct objfile
*objfile
) const override
5667 return includer ()->readin_p (objfile
);
5670 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5676 partial_symtab
*includer () const
5678 /* An include psymtab has exactly one dependency: the psymtab that
5680 gdb_assert (this->number_of_dependencies
== 1);
5681 return this->dependencies
[0];
5685 /* Allocate a new partial symtab for file named NAME and mark this new
5686 partial symtab as being an include of PST. */
5689 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5691 dwarf2_psymtab
*pst
,
5692 psymtab_storage
*partial_symtabs
,
5693 objfile_per_bfd_storage
*objfile_per_bfd
)
5695 dwarf2_include_psymtab
*subpst
5696 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5698 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5699 subpst
->dirname
= pst
->dirname
;
5701 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5702 subpst
->dependencies
[0] = pst
;
5703 subpst
->number_of_dependencies
= 1;
5706 /* Read the Line Number Program data and extract the list of files
5707 included by the source file represented by PST. Build an include
5708 partial symtab for each of these included files. */
5711 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5712 struct die_info
*die
,
5713 dwarf2_psymtab
*pst
)
5716 struct attribute
*attr
;
5718 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5719 if (attr
!= nullptr && attr
->form_is_unsigned ())
5720 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5722 return; /* No linetable, so no includes. */
5724 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5725 that we pass in the raw text_low here; that is ok because we're
5726 only decoding the line table to make include partial symtabs, and
5727 so the addresses aren't really used. */
5728 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5729 pst
->raw_text_low (), 1);
5733 hash_signatured_type (const void *item
)
5735 const struct signatured_type
*sig_type
5736 = (const struct signatured_type
*) item
;
5738 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5739 return sig_type
->signature
;
5743 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5745 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5746 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5748 return lhs
->signature
== rhs
->signature
;
5751 /* Allocate a hash table for signatured types. */
5754 allocate_signatured_type_table ()
5756 return htab_up (htab_create_alloc (41,
5757 hash_signatured_type
,
5759 NULL
, xcalloc
, xfree
));
5762 /* A helper for create_debug_types_hash_table. Read types from SECTION
5763 and fill them into TYPES_HTAB. It will process only type units,
5764 therefore DW_UT_type. */
5767 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5768 struct dwo_file
*dwo_file
,
5769 dwarf2_section_info
*section
, htab_up
&types_htab
,
5770 rcuh_kind section_kind
)
5772 struct objfile
*objfile
= per_objfile
->objfile
;
5773 struct dwarf2_section_info
*abbrev_section
;
5775 const gdb_byte
*info_ptr
, *end_ptr
;
5777 abbrev_section
= &dwo_file
->sections
.abbrev
;
5779 dwarf_read_debug_printf ("Reading %s for %s",
5780 section
->get_name (),
5781 abbrev_section
->get_file_name ());
5783 section
->read (objfile
);
5784 info_ptr
= section
->buffer
;
5786 if (info_ptr
== NULL
)
5789 /* We can't set abfd until now because the section may be empty or
5790 not present, in which case the bfd is unknown. */
5791 abfd
= section
->get_bfd_owner ();
5793 /* We don't use cutu_reader here because we don't need to read
5794 any dies: the signature is in the header. */
5796 end_ptr
= info_ptr
+ section
->size
;
5797 while (info_ptr
< end_ptr
)
5799 signatured_type_up sig_type
;
5800 struct dwo_unit
*dwo_tu
;
5802 const gdb_byte
*ptr
= info_ptr
;
5803 struct comp_unit_head header
;
5804 unsigned int length
;
5806 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5808 /* Initialize it due to a false compiler warning. */
5809 header
.signature
= -1;
5810 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5812 /* We need to read the type's signature in order to build the hash
5813 table, but we don't need anything else just yet. */
5815 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5816 abbrev_section
, ptr
, section_kind
);
5818 length
= header
.get_length ();
5820 /* Skip dummy type units. */
5821 if (ptr
>= info_ptr
+ length
5822 || peek_abbrev_code (abfd
, ptr
) == 0
5823 || (header
.unit_type
!= DW_UT_type
5824 && header
.unit_type
!= DW_UT_split_type
))
5830 if (types_htab
== NULL
)
5831 types_htab
= allocate_dwo_unit_table ();
5833 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5834 dwo_tu
->dwo_file
= dwo_file
;
5835 dwo_tu
->signature
= header
.signature
;
5836 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5837 dwo_tu
->section
= section
;
5838 dwo_tu
->sect_off
= sect_off
;
5839 dwo_tu
->length
= length
;
5841 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5842 gdb_assert (slot
!= NULL
);
5844 complaint (_("debug type entry at offset %s is duplicate to"
5845 " the entry at offset %s, signature %s"),
5846 sect_offset_str (sect_off
),
5847 sect_offset_str (dwo_tu
->sect_off
),
5848 hex_string (header
.signature
));
5851 dwarf_read_debug_printf_v (" offset %s, signature %s",
5852 sect_offset_str (sect_off
),
5853 hex_string (header
.signature
));
5859 /* Create the hash table of all entries in the .debug_types
5860 (or .debug_types.dwo) section(s).
5861 DWO_FILE is a pointer to the DWO file object.
5863 The result is a pointer to the hash table or NULL if there are no types.
5865 Note: This function processes DWO files only, not DWP files. */
5868 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5869 struct dwo_file
*dwo_file
,
5870 gdb::array_view
<dwarf2_section_info
> type_sections
,
5871 htab_up
&types_htab
)
5873 for (dwarf2_section_info
§ion
: type_sections
)
5874 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5878 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5879 If SLOT is non-NULL, it is the entry to use in the hash table.
5880 Otherwise we find one. */
5882 static struct signatured_type
*
5883 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
5885 if (per_objfile
->per_bfd
->all_comp_units
.size ()
5886 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
5887 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
5889 signatured_type_up sig_type_holder
5890 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
5891 signatured_type
*sig_type
= sig_type_holder
.get ();
5893 per_objfile
->resize_symtabs ();
5895 per_objfile
->per_bfd
->all_comp_units
.emplace_back
5896 (sig_type_holder
.release ());
5897 if (per_objfile
->per_bfd
->using_index
)
5900 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
5901 struct dwarf2_per_cu_quick_data
);
5906 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5909 gdb_assert (*slot
== NULL
);
5911 /* The rest of sig_type must be filled in by the caller. */
5915 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5916 Fill in SIG_ENTRY with DWO_ENTRY. */
5919 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
5920 struct signatured_type
*sig_entry
,
5921 struct dwo_unit
*dwo_entry
)
5923 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5925 /* Make sure we're not clobbering something we don't expect to. */
5926 gdb_assert (! sig_entry
->queued
);
5927 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
5928 if (per_bfd
->using_index
)
5930 gdb_assert (sig_entry
->v
.quick
!= NULL
);
5931 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
5934 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
5935 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5936 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5937 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5938 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5940 sig_entry
->section
= dwo_entry
->section
;
5941 sig_entry
->sect_off
= dwo_entry
->sect_off
;
5942 sig_entry
->length
= dwo_entry
->length
;
5943 sig_entry
->reading_dwo_directly
= 1;
5944 sig_entry
->per_bfd
= per_bfd
;
5945 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5946 sig_entry
->dwo_unit
= dwo_entry
;
5949 /* Subroutine of lookup_signatured_type.
5950 If we haven't read the TU yet, create the signatured_type data structure
5951 for a TU to be read in directly from a DWO file, bypassing the stub.
5952 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5953 using .gdb_index, then when reading a CU we want to stay in the DWO file
5954 containing that CU. Otherwise we could end up reading several other DWO
5955 files (due to comdat folding) to process the transitive closure of all the
5956 mentioned TUs, and that can be slow. The current DWO file will have every
5957 type signature that it needs.
5958 We only do this for .gdb_index because in the psymtab case we already have
5959 to read all the DWOs to build the type unit groups. */
5961 static struct signatured_type
*
5962 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5964 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
5965 struct dwo_file
*dwo_file
;
5966 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5969 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
5971 /* If TU skeletons have been removed then we may not have read in any
5973 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
5974 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
5976 /* We only ever need to read in one copy of a signatured type.
5977 Use the global signatured_types array to do our own comdat-folding
5978 of types. If this is the first time we're reading this TU, and
5979 the TU has an entry in .gdb_index, replace the recorded data from
5980 .gdb_index with this TU. */
5982 signatured_type
find_sig_entry (sig
);
5983 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5984 &find_sig_entry
, INSERT
);
5985 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
5987 /* We can get here with the TU already read, *or* in the process of being
5988 read. Don't reassign the global entry to point to this DWO if that's
5989 the case. Also note that if the TU is already being read, it may not
5990 have come from a DWO, the program may be a mix of Fission-compiled
5991 code and non-Fission-compiled code. */
5993 /* Have we already tried to read this TU?
5994 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5995 needn't exist in the global table yet). */
5996 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
5999 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6000 dwo_unit of the TU itself. */
6001 dwo_file
= cu
->dwo_unit
->dwo_file
;
6003 /* Ok, this is the first time we're reading this TU. */
6004 if (dwo_file
->tus
== NULL
)
6006 find_dwo_entry
.signature
= sig
;
6007 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6009 if (dwo_entry
== NULL
)
6012 /* If the global table doesn't have an entry for this TU, add one. */
6013 if (sig_entry
== NULL
)
6014 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6016 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6017 sig_entry
->tu_read
= 1;
6021 /* Subroutine of lookup_signatured_type.
6022 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6023 then try the DWP file. If the TU stub (skeleton) has been removed then
6024 it won't be in .gdb_index. */
6026 static struct signatured_type
*
6027 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6029 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6030 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6031 struct dwo_unit
*dwo_entry
;
6034 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6035 gdb_assert (dwp_file
!= NULL
);
6037 /* If TU skeletons have been removed then we may not have read in any
6039 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6040 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6042 signatured_type
find_sig_entry (sig
);
6043 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6044 &find_sig_entry
, INSERT
);
6045 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6047 /* Have we already tried to read this TU?
6048 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6049 needn't exist in the global table yet). */
6050 if (sig_entry
!= NULL
)
6053 if (dwp_file
->tus
== NULL
)
6055 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6056 1 /* is_debug_types */);
6057 if (dwo_entry
== NULL
)
6060 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6061 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6066 /* Lookup a signature based type for DW_FORM_ref_sig8.
6067 Returns NULL if signature SIG is not present in the table.
6068 It is up to the caller to complain about this. */
6070 static struct signatured_type
*
6071 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6073 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6075 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6077 /* We're in a DWO/DWP file, and we're using .gdb_index.
6078 These cases require special processing. */
6079 if (get_dwp_file (per_objfile
) == NULL
)
6080 return lookup_dwo_signatured_type (cu
, sig
);
6082 return lookup_dwp_signatured_type (cu
, sig
);
6086 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6088 signatured_type
find_entry (sig
);
6089 return ((struct signatured_type
*)
6090 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6095 /* Low level DIE reading support. */
6097 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6100 init_cu_die_reader (struct die_reader_specs
*reader
,
6101 struct dwarf2_cu
*cu
,
6102 struct dwarf2_section_info
*section
,
6103 struct dwo_file
*dwo_file
,
6104 struct abbrev_table
*abbrev_table
)
6106 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6107 reader
->abfd
= section
->get_bfd_owner ();
6109 reader
->dwo_file
= dwo_file
;
6110 reader
->die_section
= section
;
6111 reader
->buffer
= section
->buffer
;
6112 reader
->buffer_end
= section
->buffer
+ section
->size
;
6113 reader
->abbrev_table
= abbrev_table
;
6116 /* Subroutine of cutu_reader to simplify it.
6117 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6118 There's just a lot of work to do, and cutu_reader is big enough
6121 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6122 from it to the DIE in the DWO. If NULL we are skipping the stub.
6123 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6124 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6125 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6126 STUB_COMP_DIR may be non-NULL.
6127 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6128 are filled in with the info of the DIE from the DWO file.
6129 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6130 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6131 kept around for at least as long as *RESULT_READER.
6133 The result is non-zero if a valid (non-dummy) DIE was found. */
6136 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6137 struct dwo_unit
*dwo_unit
,
6138 struct die_info
*stub_comp_unit_die
,
6139 const char *stub_comp_dir
,
6140 struct die_reader_specs
*result_reader
,
6141 const gdb_byte
**result_info_ptr
,
6142 struct die_info
**result_comp_unit_die
,
6143 abbrev_table_up
*result_dwo_abbrev_table
)
6145 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6146 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6147 struct objfile
*objfile
= per_objfile
->objfile
;
6149 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6150 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6151 int i
,num_extra_attrs
;
6152 struct dwarf2_section_info
*dwo_abbrev_section
;
6153 struct die_info
*comp_unit_die
;
6155 /* At most one of these may be provided. */
6156 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6158 /* These attributes aren't processed until later:
6159 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6160 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6161 referenced later. However, these attributes are found in the stub
6162 which we won't have later. In order to not impose this complication
6163 on the rest of the code, we read them here and copy them to the
6172 if (stub_comp_unit_die
!= NULL
)
6174 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6176 if (!per_cu
->is_debug_types
)
6177 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6178 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6179 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6180 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6181 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6183 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6185 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6186 We need the value before we can process DW_AT_ranges values from the
6188 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6190 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6191 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6192 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6193 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6195 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6197 else if (stub_comp_dir
!= NULL
)
6199 /* Reconstruct the comp_dir attribute to simplify the code below. */
6200 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6201 comp_dir
->name
= DW_AT_comp_dir
;
6202 comp_dir
->form
= DW_FORM_string
;
6203 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6206 /* Set up for reading the DWO CU/TU. */
6207 cu
->dwo_unit
= dwo_unit
;
6208 dwarf2_section_info
*section
= dwo_unit
->section
;
6209 section
->read (objfile
);
6210 abfd
= section
->get_bfd_owner ();
6211 begin_info_ptr
= info_ptr
= (section
->buffer
6212 + to_underlying (dwo_unit
->sect_off
));
6213 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6215 if (per_cu
->is_debug_types
)
6217 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6219 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6220 section
, dwo_abbrev_section
,
6221 info_ptr
, rcuh_kind::TYPE
);
6222 /* This is not an assert because it can be caused by bad debug info. */
6223 if (sig_type
->signature
!= cu
->header
.signature
)
6225 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6226 " TU at offset %s [in module %s]"),
6227 hex_string (sig_type
->signature
),
6228 hex_string (cu
->header
.signature
),
6229 sect_offset_str (dwo_unit
->sect_off
),
6230 bfd_get_filename (abfd
));
6232 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6233 /* For DWOs coming from DWP files, we don't know the CU length
6234 nor the type's offset in the TU until now. */
6235 dwo_unit
->length
= cu
->header
.get_length ();
6236 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6238 /* Establish the type offset that can be used to lookup the type.
6239 For DWO files, we don't know it until now. */
6240 sig_type
->type_offset_in_section
6241 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6245 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6246 section
, dwo_abbrev_section
,
6247 info_ptr
, rcuh_kind::COMPILE
);
6248 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6249 /* For DWOs coming from DWP files, we don't know the CU length
6251 dwo_unit
->length
= cu
->header
.get_length ();
6254 dwo_abbrev_section
->read (objfile
);
6255 *result_dwo_abbrev_table
6256 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6257 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6258 result_dwo_abbrev_table
->get ());
6260 /* Read in the die, but leave space to copy over the attributes
6261 from the stub. This has the benefit of simplifying the rest of
6262 the code - all the work to maintain the illusion of a single
6263 DW_TAG_{compile,type}_unit DIE is done here. */
6264 num_extra_attrs
= ((stmt_list
!= NULL
)
6268 + (comp_dir
!= NULL
));
6269 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6272 /* Copy over the attributes from the stub to the DIE we just read in. */
6273 comp_unit_die
= *result_comp_unit_die
;
6274 i
= comp_unit_die
->num_attrs
;
6275 if (stmt_list
!= NULL
)
6276 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6278 comp_unit_die
->attrs
[i
++] = *low_pc
;
6279 if (high_pc
!= NULL
)
6280 comp_unit_die
->attrs
[i
++] = *high_pc
;
6282 comp_unit_die
->attrs
[i
++] = *ranges
;
6283 if (comp_dir
!= NULL
)
6284 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6285 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6287 if (dwarf_die_debug
)
6289 fprintf_unfiltered (gdb_stdlog
,
6290 "Read die from %s@0x%x of %s:\n",
6291 section
->get_name (),
6292 (unsigned) (begin_info_ptr
- section
->buffer
),
6293 bfd_get_filename (abfd
));
6294 dump_die (comp_unit_die
, dwarf_die_debug
);
6297 /* Skip dummy compilation units. */
6298 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6299 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6302 *result_info_ptr
= info_ptr
;
6306 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6307 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6308 signature is part of the header. */
6309 static gdb::optional
<ULONGEST
>
6310 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6312 if (cu
->header
.version
>= 5)
6313 return cu
->header
.signature
;
6314 struct attribute
*attr
;
6315 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6316 if (attr
== nullptr || !attr
->form_is_unsigned ())
6317 return gdb::optional
<ULONGEST
> ();
6318 return attr
->as_unsigned ();
6321 /* Subroutine of cutu_reader to simplify it.
6322 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6323 Returns NULL if the specified DWO unit cannot be found. */
6325 static struct dwo_unit
*
6326 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6328 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6329 struct dwo_unit
*dwo_unit
;
6330 const char *comp_dir
;
6332 gdb_assert (cu
!= NULL
);
6334 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6335 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6336 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6338 if (per_cu
->is_debug_types
)
6339 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6342 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6344 if (!signature
.has_value ())
6345 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6347 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6349 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6355 /* Subroutine of cutu_reader to simplify it.
6356 See it for a description of the parameters.
6357 Read a TU directly from a DWO file, bypassing the stub. */
6360 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6361 dwarf2_per_objfile
*per_objfile
,
6362 dwarf2_cu
*existing_cu
)
6364 struct signatured_type
*sig_type
;
6366 /* Verify we can do the following downcast, and that we have the
6368 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6369 sig_type
= (struct signatured_type
*) this_cu
;
6370 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6374 if (existing_cu
!= nullptr)
6377 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6378 /* There's no need to do the rereading_dwo_cu handling that
6379 cutu_reader does since we don't read the stub. */
6383 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6384 in per_objfile yet. */
6385 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6386 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6387 cu
= m_new_cu
.get ();
6390 /* A future optimization, if needed, would be to use an existing
6391 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6392 could share abbrev tables. */
6394 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6395 NULL
/* stub_comp_unit_die */,
6396 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6399 &m_dwo_abbrev_table
) == 0)
6406 /* Initialize a CU (or TU) and read its DIEs.
6407 If the CU defers to a DWO file, read the DWO file as well.
6409 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6410 Otherwise the table specified in the comp unit header is read in and used.
6411 This is an optimization for when we already have the abbrev table.
6413 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6416 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6417 dwarf2_per_objfile
*per_objfile
,
6418 struct abbrev_table
*abbrev_table
,
6419 dwarf2_cu
*existing_cu
,
6421 : die_reader_specs
{},
6424 struct objfile
*objfile
= per_objfile
->objfile
;
6425 struct dwarf2_section_info
*section
= this_cu
->section
;
6426 bfd
*abfd
= section
->get_bfd_owner ();
6427 const gdb_byte
*begin_info_ptr
;
6428 struct signatured_type
*sig_type
= NULL
;
6429 struct dwarf2_section_info
*abbrev_section
;
6430 /* Non-zero if CU currently points to a DWO file and we need to
6431 reread it. When this happens we need to reread the skeleton die
6432 before we can reread the DWO file (this only applies to CUs, not TUs). */
6433 int rereading_dwo_cu
= 0;
6435 if (dwarf_die_debug
)
6436 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6437 this_cu
->is_debug_types
? "type" : "comp",
6438 sect_offset_str (this_cu
->sect_off
));
6440 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6441 file (instead of going through the stub), short-circuit all of this. */
6442 if (this_cu
->reading_dwo_directly
)
6444 /* Narrow down the scope of possibilities to have to understand. */
6445 gdb_assert (this_cu
->is_debug_types
);
6446 gdb_assert (abbrev_table
== NULL
);
6447 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6451 /* This is cheap if the section is already read in. */
6452 section
->read (objfile
);
6454 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6456 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6460 if (existing_cu
!= nullptr)
6463 /* If this CU is from a DWO file we need to start over, we need to
6464 refetch the attributes from the skeleton CU.
6465 This could be optimized by retrieving those attributes from when we
6466 were here the first time: the previous comp_unit_die was stored in
6467 comp_unit_obstack. But there's no data yet that we need this
6469 if (cu
->dwo_unit
!= NULL
)
6470 rereading_dwo_cu
= 1;
6474 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6475 in per_objfile yet. */
6476 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6477 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6478 cu
= m_new_cu
.get ();
6481 /* Get the header. */
6482 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6484 /* We already have the header, there's no need to read it in again. */
6485 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6489 if (this_cu
->is_debug_types
)
6491 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6492 section
, abbrev_section
,
6493 info_ptr
, rcuh_kind::TYPE
);
6495 /* Since per_cu is the first member of struct signatured_type,
6496 we can go from a pointer to one to a pointer to the other. */
6497 sig_type
= (struct signatured_type
*) this_cu
;
6498 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6499 gdb_assert (sig_type
->type_offset_in_tu
6500 == cu
->header
.type_cu_offset_in_tu
);
6501 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6503 /* LENGTH has not been set yet for type units if we're
6504 using .gdb_index. */
6505 this_cu
->length
= cu
->header
.get_length ();
6507 /* Establish the type offset that can be used to lookup the type. */
6508 sig_type
->type_offset_in_section
=
6509 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6511 this_cu
->dwarf_version
= cu
->header
.version
;
6515 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6516 section
, abbrev_section
,
6518 rcuh_kind::COMPILE
);
6520 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6521 if (this_cu
->length
== 0)
6522 this_cu
->length
= cu
->header
.get_length ();
6524 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6525 this_cu
->dwarf_version
= cu
->header
.version
;
6529 /* Skip dummy compilation units. */
6530 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6531 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6537 /* If we don't have them yet, read the abbrevs for this compilation unit.
6538 And if we need to read them now, make sure they're freed when we're
6540 if (abbrev_table
!= NULL
)
6541 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6544 abbrev_section
->read (objfile
);
6545 m_abbrev_table_holder
6546 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6547 abbrev_table
= m_abbrev_table_holder
.get ();
6550 /* Read the top level CU/TU die. */
6551 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6552 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6554 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6560 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6561 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6562 table from the DWO file and pass the ownership over to us. It will be
6563 referenced from READER, so we must make sure to free it after we're done
6566 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6567 DWO CU, that this test will fail (the attribute will not be present). */
6568 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6569 if (dwo_name
!= nullptr)
6571 struct dwo_unit
*dwo_unit
;
6572 struct die_info
*dwo_comp_unit_die
;
6574 if (comp_unit_die
->has_children
)
6576 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6577 " has children (offset %s) [in module %s]"),
6578 sect_offset_str (this_cu
->sect_off
),
6579 bfd_get_filename (abfd
));
6581 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6582 if (dwo_unit
!= NULL
)
6584 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6585 comp_unit_die
, NULL
,
6588 &m_dwo_abbrev_table
) == 0)
6594 comp_unit_die
= dwo_comp_unit_die
;
6598 /* Yikes, we couldn't find the rest of the DIE, we only have
6599 the stub. A complaint has already been logged. There's
6600 not much more we can do except pass on the stub DIE to
6601 die_reader_func. We don't want to throw an error on bad
6608 cutu_reader::keep ()
6610 /* Done, clean up. */
6611 gdb_assert (!dummy_p
);
6612 if (m_new_cu
!= NULL
)
6614 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6616 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6617 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6621 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6622 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6623 assumed to have already done the lookup to find the DWO file).
6625 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6626 THIS_CU->is_debug_types, but nothing else.
6628 We fill in THIS_CU->length.
6630 THIS_CU->cu is always freed when done.
6631 This is done in order to not leave THIS_CU->cu in a state where we have
6632 to care whether it refers to the "main" CU or the DWO CU.
6634 When parent_cu is passed, it is used to provide a default value for
6635 str_offsets_base and addr_base from the parent. */
6637 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6638 dwarf2_per_objfile
*per_objfile
,
6639 struct dwarf2_cu
*parent_cu
,
6640 struct dwo_file
*dwo_file
)
6641 : die_reader_specs
{},
6644 struct objfile
*objfile
= per_objfile
->objfile
;
6645 struct dwarf2_section_info
*section
= this_cu
->section
;
6646 bfd
*abfd
= section
->get_bfd_owner ();
6647 struct dwarf2_section_info
*abbrev_section
;
6648 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6650 if (dwarf_die_debug
)
6651 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6652 this_cu
->is_debug_types
? "type" : "comp",
6653 sect_offset_str (this_cu
->sect_off
));
6655 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6657 abbrev_section
= (dwo_file
!= NULL
6658 ? &dwo_file
->sections
.abbrev
6659 : get_abbrev_section_for_cu (this_cu
));
6661 /* This is cheap if the section is already read in. */
6662 section
->read (objfile
);
6664 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6666 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6667 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6668 section
, abbrev_section
, info_ptr
,
6669 (this_cu
->is_debug_types
6671 : rcuh_kind::COMPILE
));
6673 if (parent_cu
!= nullptr)
6675 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6676 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6678 this_cu
->length
= m_new_cu
->header
.get_length ();
6680 /* Skip dummy compilation units. */
6681 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6682 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6688 abbrev_section
->read (objfile
);
6689 m_abbrev_table_holder
6690 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6692 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6693 m_abbrev_table_holder
.get ());
6694 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6698 /* Type Unit Groups.
6700 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6701 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6702 so that all types coming from the same compilation (.o file) are grouped
6703 together. A future step could be to put the types in the same symtab as
6704 the CU the types ultimately came from. */
6707 hash_type_unit_group (const void *item
)
6709 const struct type_unit_group
*tu_group
6710 = (const struct type_unit_group
*) item
;
6712 return hash_stmt_list_entry (&tu_group
->hash
);
6716 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6718 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6719 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6721 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6724 /* Allocate a hash table for type unit groups. */
6727 allocate_type_unit_groups_table ()
6729 return htab_up (htab_create_alloc (3,
6730 hash_type_unit_group
,
6732 htab_delete_entry
<type_unit_group
>,
6736 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6737 partial symtabs. We combine several TUs per psymtab to not let the size
6738 of any one psymtab grow too big. */
6739 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6740 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6742 /* Helper routine for get_type_unit_group.
6743 Create the type_unit_group object used to hold one or more TUs. */
6745 static std::unique_ptr
<type_unit_group
>
6746 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6748 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6749 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6751 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6752 tu_group
->per_bfd
= per_bfd
;
6754 if (per_bfd
->using_index
)
6756 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6757 struct dwarf2_per_cu_quick_data
);
6761 unsigned int line_offset
= to_underlying (line_offset_struct
);
6762 dwarf2_psymtab
*pst
;
6765 /* Give the symtab a useful name for debug purposes. */
6766 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6767 name
= string_printf ("<type_units_%d>",
6768 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6770 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6772 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6774 pst
->anonymous
= true;
6777 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6778 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6783 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6784 STMT_LIST is a DW_AT_stmt_list attribute. */
6786 static struct type_unit_group
*
6787 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6789 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6790 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6791 struct type_unit_group
*tu_group
;
6793 unsigned int line_offset
;
6794 struct type_unit_group type_unit_group_for_lookup
;
6796 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6797 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6799 /* Do we need to create a new group, or can we use an existing one? */
6801 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6803 line_offset
= stmt_list
->as_unsigned ();
6804 ++tu_stats
->nr_symtab_sharers
;
6808 /* Ugh, no stmt_list. Rare, but we have to handle it.
6809 We can do various things here like create one group per TU or
6810 spread them over multiple groups to split up the expansion work.
6811 To avoid worst case scenarios (too many groups or too large groups)
6812 we, umm, group them in bunches. */
6813 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6814 | (tu_stats
->nr_stmt_less_type_units
6815 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6816 ++tu_stats
->nr_stmt_less_type_units
;
6819 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6820 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6821 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6822 &type_unit_group_for_lookup
, INSERT
);
6823 if (*slot
== nullptr)
6825 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6826 std::unique_ptr
<type_unit_group
> grp
6827 = create_type_unit_group (cu
, line_offset_struct
);
6828 *slot
= grp
.release ();
6829 ++tu_stats
->nr_symtabs
;
6832 tu_group
= (struct type_unit_group
*) *slot
;
6833 gdb_assert (tu_group
!= nullptr);
6837 /* Partial symbol tables. */
6839 /* Create a psymtab named NAME and assign it to PER_CU.
6841 The caller must fill in the following details:
6842 dirname, textlow, texthigh. */
6844 static dwarf2_psymtab
*
6845 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6846 dwarf2_per_objfile
*per_objfile
,
6850 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6851 per_objfile
->objfile
->per_bfd
, per_cu
);
6853 pst
->psymtabs_addrmap_supported
= true;
6855 /* This is the glue that links PST into GDB's symbol API. */
6856 per_cu
->v
.psymtab
= pst
;
6861 /* DIE reader function for process_psymtab_comp_unit. */
6864 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6865 const gdb_byte
*info_ptr
,
6866 struct die_info
*comp_unit_die
,
6867 enum language pretend_language
)
6869 struct dwarf2_cu
*cu
= reader
->cu
;
6870 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6871 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6872 struct objfile
*objfile
= per_objfile
->objfile
;
6873 struct gdbarch
*gdbarch
= objfile
->arch ();
6874 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6876 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6877 dwarf2_psymtab
*pst
;
6878 enum pc_bounds_kind cu_bounds_kind
;
6879 const char *filename
;
6881 gdb_assert (! per_cu
->is_debug_types
);
6883 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
6885 /* Allocate a new partial symbol table structure. */
6886 gdb::unique_xmalloc_ptr
<char> debug_filename
;
6887 static const char artificial
[] = "<artificial>";
6888 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6889 if (filename
== NULL
)
6891 else if (strcmp (filename
, artificial
) == 0)
6893 debug_filename
.reset (concat (artificial
, "@",
6894 sect_offset_str (per_cu
->sect_off
),
6896 filename
= debug_filename
.get ();
6899 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
6901 /* This must be done before calling dwarf2_build_include_psymtabs. */
6902 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6904 baseaddr
= objfile
->text_section_offset ();
6906 dwarf2_find_base_address (comp_unit_die
, cu
);
6908 /* Possibly set the default values of LOWPC and HIGHPC from
6910 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6911 &best_highpc
, cu
, pst
);
6912 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6915 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
6918 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
6920 /* Store the contiguous range if it is not empty; it can be
6921 empty for CUs with no code. */
6922 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
6926 /* Check if comp unit has_children.
6927 If so, read the rest of the partial symbols from this comp unit.
6928 If not, there's no more debug_info for this comp unit. */
6929 if (comp_unit_die
->has_children
)
6931 struct partial_die_info
*first_die
;
6932 CORE_ADDR lowpc
, highpc
;
6934 lowpc
= ((CORE_ADDR
) -1);
6935 highpc
= ((CORE_ADDR
) 0);
6937 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6939 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6940 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6942 /* If we didn't find a lowpc, set it to highpc to avoid
6943 complaints from `maint check'. */
6944 if (lowpc
== ((CORE_ADDR
) -1))
6947 /* If the compilation unit didn't have an explicit address range,
6948 then use the information extracted from its child dies. */
6949 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6952 best_highpc
= highpc
;
6955 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
6956 best_lowpc
+ baseaddr
)
6958 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
6959 best_highpc
+ baseaddr
)
6964 if (!cu
->per_cu
->imported_symtabs_empty ())
6967 int len
= cu
->per_cu
->imported_symtabs_size ();
6969 /* Fill in 'dependencies' here; we fill in 'users' in a
6971 pst
->number_of_dependencies
= len
;
6973 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
6974 for (i
= 0; i
< len
; ++i
)
6976 pst
->dependencies
[i
]
6977 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
6980 cu
->per_cu
->imported_symtabs_free ();
6983 /* Get the list of files included in the current compilation unit,
6984 and build a psymtab for each of them. */
6985 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6987 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
6988 ", %d global, %d static syms",
6989 per_cu
->is_debug_types
? "type" : "comp",
6990 sect_offset_str (per_cu
->sect_off
),
6991 paddress (gdbarch
, pst
->text_low (objfile
)),
6992 paddress (gdbarch
, pst
->text_high (objfile
)),
6993 (int) pst
->global_psymbols
.size (),
6994 (int) pst
->static_psymbols
.size ());
6997 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6998 Process compilation unit THIS_CU for a psymtab. */
7001 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7002 dwarf2_per_objfile
*per_objfile
,
7003 bool want_partial_unit
,
7004 enum language pretend_language
)
7006 /* If this compilation unit was already read in, free the
7007 cached copy in order to read it in again. This is
7008 necessary because we skipped some symbols when we first
7009 read in the compilation unit (see load_partial_dies).
7010 This problem could be avoided, but the benefit is unclear. */
7011 per_objfile
->remove_cu (this_cu
);
7013 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7015 if (reader
.comp_unit_die
== nullptr)
7018 switch (reader
.comp_unit_die
->tag
)
7020 case DW_TAG_compile_unit
:
7021 this_cu
->unit_type
= DW_UT_compile
;
7023 case DW_TAG_partial_unit
:
7024 this_cu
->unit_type
= DW_UT_partial
;
7026 case DW_TAG_type_unit
:
7027 this_cu
->unit_type
= DW_UT_type
;
7030 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7031 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7032 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7033 objfile_name (per_objfile
->objfile
));
7040 else if (this_cu
->is_debug_types
)
7041 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7042 reader
.comp_unit_die
);
7043 else if (want_partial_unit
7044 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7045 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7046 reader
.comp_unit_die
,
7049 this_cu
->lang
= reader
.cu
->language
;
7051 /* Age out any secondary CUs. */
7052 per_objfile
->age_comp_units ();
7055 /* Reader function for build_type_psymtabs. */
7058 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7059 const gdb_byte
*info_ptr
,
7060 struct die_info
*type_unit_die
)
7062 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7063 struct dwarf2_cu
*cu
= reader
->cu
;
7064 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7065 struct signatured_type
*sig_type
;
7066 struct type_unit_group
*tu_group
;
7067 struct attribute
*attr
;
7068 struct partial_die_info
*first_die
;
7069 CORE_ADDR lowpc
, highpc
;
7070 dwarf2_psymtab
*pst
;
7072 gdb_assert (per_cu
->is_debug_types
);
7073 sig_type
= (struct signatured_type
*) per_cu
;
7075 if (! type_unit_die
->has_children
)
7078 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7079 tu_group
= get_type_unit_group (cu
, attr
);
7081 if (tu_group
->tus
== nullptr)
7082 tu_group
->tus
= new std::vector
<signatured_type
*>;
7083 tu_group
->tus
->push_back (sig_type
);
7085 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7086 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7087 pst
->anonymous
= true;
7089 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7091 lowpc
= (CORE_ADDR
) -1;
7092 highpc
= (CORE_ADDR
) 0;
7093 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7098 /* Struct used to sort TUs by their abbreviation table offset. */
7100 struct tu_abbrev_offset
7102 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7103 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7106 /* This is used when sorting. */
7107 bool operator< (const tu_abbrev_offset
&other
) const
7109 return abbrev_offset
< other
.abbrev_offset
;
7112 signatured_type
*sig_type
;
7113 sect_offset abbrev_offset
;
7116 /* Efficiently read all the type units.
7118 The efficiency is because we sort TUs by the abbrev table they use and
7119 only read each abbrev table once. In one program there are 200K TUs
7120 sharing 8K abbrev tables.
7122 The main purpose of this function is to support building the
7123 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7124 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7125 can collapse the search space by grouping them by stmt_list.
7126 The savings can be significant, in the same program from above the 200K TUs
7127 share 8K stmt_list tables.
7129 FUNC is expected to call get_type_unit_group, which will create the
7130 struct type_unit_group if necessary and add it to
7131 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7134 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7136 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7137 abbrev_table_up abbrev_table
;
7138 sect_offset abbrev_offset
;
7140 /* It's up to the caller to not call us multiple times. */
7141 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7143 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7146 /* TUs typically share abbrev tables, and there can be way more TUs than
7147 abbrev tables. Sort by abbrev table to reduce the number of times we
7148 read each abbrev table in.
7149 Alternatives are to punt or to maintain a cache of abbrev tables.
7150 This is simpler and efficient enough for now.
7152 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7153 symtab to use). Typically TUs with the same abbrev offset have the same
7154 stmt_list value too so in practice this should work well.
7156 The basic algorithm here is:
7158 sort TUs by abbrev table
7159 for each TU with same abbrev table:
7160 read abbrev table if first user
7161 read TU top level DIE
7162 [IWBN if DWO skeletons had DW_AT_stmt_list]
7165 dwarf_read_debug_printf ("Building type unit groups ...");
7167 /* Sort in a separate table to maintain the order of all_comp_units
7168 for .gdb_index: TU indices directly index all_type_units. */
7169 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7170 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7172 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7174 if (cu
->is_debug_types
)
7176 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7177 sorted_by_abbrev
.emplace_back
7178 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7179 sig_type
->sect_off
));
7183 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7185 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7187 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7189 /* Switch to the next abbrev table if necessary. */
7190 if (abbrev_table
== NULL
7191 || tu
.abbrev_offset
!= abbrev_offset
)
7193 abbrev_offset
= tu
.abbrev_offset
;
7194 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7196 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7197 ++tu_stats
->nr_uniq_abbrev_tables
;
7200 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7201 abbrev_table
.get (), nullptr, false);
7202 if (!reader
.dummy_p
)
7203 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7204 reader
.comp_unit_die
);
7208 /* Print collected type unit statistics. */
7211 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7213 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7215 dwarf_read_debug_printf ("Type unit statistics:");
7216 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7217 dwarf_read_debug_printf (" %d uniq abbrev tables",
7218 tu_stats
->nr_uniq_abbrev_tables
);
7219 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7220 tu_stats
->nr_symtabs
);
7221 dwarf_read_debug_printf (" %d symtab sharers",
7222 tu_stats
->nr_symtab_sharers
);
7223 dwarf_read_debug_printf (" %d type units without a stmt_list",
7224 tu_stats
->nr_stmt_less_type_units
);
7225 dwarf_read_debug_printf (" %d all_type_units reallocs",
7226 tu_stats
->nr_all_type_units_reallocs
);
7229 /* Traversal function for build_type_psymtabs. */
7232 build_type_psymtab_dependencies (void **slot
, void *info
)
7234 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7235 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7236 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7237 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7238 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7241 gdb_assert (len
> 0);
7242 gdb_assert (tu_group
->type_unit_group_p ());
7244 pst
->number_of_dependencies
= len
;
7245 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7246 for (i
= 0; i
< len
; ++i
)
7248 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7249 gdb_assert (iter
->is_debug_types
);
7250 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7251 iter
->type_unit_group
= tu_group
;
7254 delete tu_group
->tus
;
7255 tu_group
->tus
= nullptr;
7260 /* Traversal function for process_skeletonless_type_unit.
7261 Read a TU in a DWO file and build partial symbols for it. */
7264 process_skeletonless_type_unit (void **slot
, void *info
)
7266 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7267 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7269 /* If this TU doesn't exist in the global table, add it and read it in. */
7271 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7272 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7274 signatured_type
find_entry (dwo_unit
->signature
);
7275 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7276 &find_entry
, INSERT
);
7277 /* If we've already seen this type there's nothing to do. What's happening
7278 is we're doing our own version of comdat-folding here. */
7282 /* This does the job that create_all_comp_units would have done for
7284 signatured_type
*entry
7285 = add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7286 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7289 /* This does the job that build_type_psymtabs would have done. */
7290 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7291 if (!reader
.dummy_p
)
7292 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7293 reader
.comp_unit_die
);
7298 /* Traversal function for process_skeletonless_type_units. */
7301 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7303 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7305 if (dwo_file
->tus
!= NULL
)
7306 htab_traverse_noresize (dwo_file
->tus
.get (),
7307 process_skeletonless_type_unit
, info
);
7312 /* Scan all TUs of DWO files, verifying we've processed them.
7313 This is needed in case a TU was emitted without its skeleton.
7314 Note: This can't be done until we know what all the DWO files are. */
7317 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7319 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7320 if (get_dwp_file (per_objfile
) == NULL
7321 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7323 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7324 process_dwo_file_for_skeletonless_type_units
,
7329 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7332 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7334 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7336 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7341 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7343 /* Set the 'user' field only if it is not already set. */
7344 if (pst
->dependencies
[j
]->user
== NULL
)
7345 pst
->dependencies
[j
]->user
= pst
;
7350 /* Build the partial symbol table by doing a quick pass through the
7351 .debug_info and .debug_abbrev sections. */
7354 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7356 struct objfile
*objfile
= per_objfile
->objfile
;
7357 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7359 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7360 objfile_name (objfile
));
7362 scoped_restore restore_reading_psyms
7363 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7365 per_bfd
->info
.read (objfile
);
7367 /* Any cached compilation units will be linked by the per-objfile
7368 read_in_chain. Make sure to free them when we're done. */
7369 free_cached_comp_units
freer (per_objfile
);
7371 create_all_comp_units (per_objfile
);
7372 build_type_psymtabs (per_objfile
);
7374 /* Create a temporary address map on a temporary obstack. We later
7375 copy this to the final obstack. */
7376 auto_obstack temp_obstack
;
7378 scoped_restore save_psymtabs_addrmap
7379 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7380 addrmap_create_mutable (&temp_obstack
));
7382 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7384 if (per_cu
->v
.psymtab
!= NULL
)
7385 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7387 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7391 /* This has to wait until we read the CUs, we need the list of DWOs. */
7392 process_skeletonless_type_units (per_objfile
);
7394 /* Now that all TUs have been processed we can fill in the dependencies. */
7395 if (per_bfd
->type_unit_groups
!= NULL
)
7397 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7398 build_type_psymtab_dependencies
, per_objfile
);
7401 if (dwarf_read_debug
> 0)
7402 print_tu_stats (per_objfile
);
7404 set_partial_user (per_objfile
);
7406 per_bfd
->partial_symtabs
->psymtabs_addrmap
7407 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7408 per_bfd
->partial_symtabs
->obstack ());
7409 /* At this point we want to keep the address map. */
7410 save_psymtabs_addrmap
.release ();
7412 dwarf_read_debug_printf ("Done building psymtabs of %s",
7413 objfile_name (objfile
));
7416 /* Load the partial DIEs for a secondary CU into memory.
7417 This is also used when rereading a primary CU with load_all_dies. */
7420 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7421 dwarf2_per_objfile
*per_objfile
,
7422 dwarf2_cu
*existing_cu
)
7424 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7426 if (!reader
.dummy_p
)
7428 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7431 /* Check if comp unit has_children.
7432 If so, read the rest of the partial symbols from this comp unit.
7433 If not, there's no more debug_info for this comp unit. */
7434 if (reader
.comp_unit_die
->has_children
)
7435 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7442 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7443 struct dwarf2_section_info
*section
,
7444 struct dwarf2_section_info
*abbrev_section
,
7445 unsigned int is_dwz
,
7446 htab_up
&types_htab
,
7447 rcuh_kind section_kind
)
7449 const gdb_byte
*info_ptr
;
7450 struct objfile
*objfile
= per_objfile
->objfile
;
7452 dwarf_read_debug_printf ("Reading %s for %s",
7453 section
->get_name (),
7454 section
->get_file_name ());
7456 section
->read (objfile
);
7458 info_ptr
= section
->buffer
;
7460 while (info_ptr
< section
->buffer
+ section
->size
)
7462 dwarf2_per_cu_data_up this_cu
;
7464 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7466 comp_unit_head cu_header
;
7467 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7468 abbrev_section
, info_ptr
,
7471 /* Save the compilation unit for later lookup. */
7472 if (cu_header
.unit_type
!= DW_UT_type
)
7473 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7476 if (types_htab
== nullptr)
7477 types_htab
= allocate_signatured_type_table ();
7479 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7480 (cu_header
.signature
);
7481 signatured_type
*sig_ptr
= sig_type
.get ();
7482 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7483 this_cu
.reset (sig_type
.release ());
7485 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7486 gdb_assert (slot
!= nullptr);
7487 if (*slot
!= nullptr)
7488 complaint (_("debug type entry at offset %s is duplicate to"
7489 " the entry at offset %s, signature %s"),
7490 sect_offset_str (sect_off
),
7491 sect_offset_str (sig_ptr
->sect_off
),
7492 hex_string (sig_ptr
->signature
));
7495 this_cu
->sect_off
= sect_off
;
7496 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7497 this_cu
->is_dwz
= is_dwz
;
7498 this_cu
->section
= section
;
7500 info_ptr
= info_ptr
+ this_cu
->length
;
7501 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7505 /* Create a list of all compilation units in OBJFILE.
7506 This is only done for -readnow and building partial symtabs. */
7509 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7513 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7514 &per_objfile
->per_bfd
->abbrev
, 0,
7515 types_htab
, rcuh_kind::COMPILE
);
7516 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7517 read_comp_units_from_section (per_objfile
, §ion
,
7518 &per_objfile
->per_bfd
->abbrev
, 0,
7519 types_htab
, rcuh_kind::TYPE
);
7521 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7523 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7524 types_htab
, rcuh_kind::COMPILE
);
7526 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7529 /* Process all loaded DIEs for compilation unit CU, starting at
7530 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7531 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7532 DW_AT_ranges). See the comments of add_partial_subprogram on how
7533 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7536 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7537 CORE_ADDR
*highpc
, int set_addrmap
,
7538 struct dwarf2_cu
*cu
)
7540 struct partial_die_info
*pdi
;
7542 /* Now, march along the PDI's, descending into ones which have
7543 interesting children but skipping the children of the other ones,
7544 until we reach the end of the compilation unit. */
7552 /* Anonymous namespaces or modules have no name but have interesting
7553 children, so we need to look at them. Ditto for anonymous
7556 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7557 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7558 || pdi
->tag
== DW_TAG_imported_unit
7559 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7563 case DW_TAG_subprogram
:
7564 case DW_TAG_inlined_subroutine
:
7565 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7566 if (cu
->language
== language_cplus
)
7567 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7570 case DW_TAG_constant
:
7571 case DW_TAG_variable
:
7572 case DW_TAG_typedef
:
7573 case DW_TAG_union_type
:
7574 if (!pdi
->is_declaration
7575 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7577 add_partial_symbol (pdi
, cu
);
7580 case DW_TAG_class_type
:
7581 case DW_TAG_interface_type
:
7582 case DW_TAG_structure_type
:
7583 if (!pdi
->is_declaration
)
7585 add_partial_symbol (pdi
, cu
);
7587 if ((cu
->language
== language_rust
7588 || cu
->language
== language_cplus
) && pdi
->has_children
)
7589 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7592 case DW_TAG_enumeration_type
:
7593 if (!pdi
->is_declaration
)
7594 add_partial_enumeration (pdi
, cu
);
7596 case DW_TAG_base_type
:
7597 case DW_TAG_subrange_type
:
7598 /* File scope base type definitions are added to the partial
7600 add_partial_symbol (pdi
, cu
);
7602 case DW_TAG_namespace
:
7603 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7606 if (!pdi
->is_declaration
)
7607 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7609 case DW_TAG_imported_unit
:
7611 struct dwarf2_per_cu_data
*per_cu
;
7613 /* For now we don't handle imported units in type units. */
7614 if (cu
->per_cu
->is_debug_types
)
7616 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7617 " supported in type units [in module %s]"),
7618 objfile_name (cu
->per_objfile
->objfile
));
7621 per_cu
= dwarf2_find_containing_comp_unit
7622 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7624 /* Go read the partial unit, if needed. */
7625 if (per_cu
->v
.psymtab
== NULL
)
7626 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7629 cu
->per_cu
->imported_symtabs_push (per_cu
);
7632 case DW_TAG_imported_declaration
:
7633 add_partial_symbol (pdi
, cu
);
7640 /* If the die has a sibling, skip to the sibling. */
7642 pdi
= pdi
->die_sibling
;
7646 /* Functions used to compute the fully scoped name of a partial DIE.
7648 Normally, this is simple. For C++, the parent DIE's fully scoped
7649 name is concatenated with "::" and the partial DIE's name.
7650 Enumerators are an exception; they use the scope of their parent
7651 enumeration type, i.e. the name of the enumeration type is not
7652 prepended to the enumerator.
7654 There are two complexities. One is DW_AT_specification; in this
7655 case "parent" means the parent of the target of the specification,
7656 instead of the direct parent of the DIE. The other is compilers
7657 which do not emit DW_TAG_namespace; in this case we try to guess
7658 the fully qualified name of structure types from their members'
7659 linkage names. This must be done using the DIE's children rather
7660 than the children of any DW_AT_specification target. We only need
7661 to do this for structures at the top level, i.e. if the target of
7662 any DW_AT_specification (if any; otherwise the DIE itself) does not
7665 /* Compute the scope prefix associated with PDI's parent, in
7666 compilation unit CU. The result will be allocated on CU's
7667 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7668 field. NULL is returned if no prefix is necessary. */
7670 partial_die_parent_scope (struct partial_die_info
*pdi
,
7671 struct dwarf2_cu
*cu
)
7673 const char *grandparent_scope
;
7674 struct partial_die_info
*parent
, *real_pdi
;
7676 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7677 then this means the parent of the specification DIE. */
7680 while (real_pdi
->has_specification
)
7682 auto res
= find_partial_die (real_pdi
->spec_offset
,
7683 real_pdi
->spec_is_dwz
, cu
);
7688 parent
= real_pdi
->die_parent
;
7692 if (parent
->scope_set
)
7693 return parent
->scope
;
7697 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7699 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7700 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7701 Work around this problem here. */
7702 if (cu
->language
== language_cplus
7703 && parent
->tag
== DW_TAG_namespace
7704 && strcmp (parent
->name (cu
), "::") == 0
7705 && grandparent_scope
== NULL
)
7707 parent
->scope
= NULL
;
7708 parent
->scope_set
= 1;
7712 /* Nested subroutines in Fortran get a prefix. */
7713 if (pdi
->tag
== DW_TAG_enumerator
)
7714 /* Enumerators should not get the name of the enumeration as a prefix. */
7715 parent
->scope
= grandparent_scope
;
7716 else if (parent
->tag
== DW_TAG_namespace
7717 || parent
->tag
== DW_TAG_module
7718 || parent
->tag
== DW_TAG_structure_type
7719 || parent
->tag
== DW_TAG_class_type
7720 || parent
->tag
== DW_TAG_interface_type
7721 || parent
->tag
== DW_TAG_union_type
7722 || parent
->tag
== DW_TAG_enumeration_type
7723 || (cu
->language
== language_fortran
7724 && parent
->tag
== DW_TAG_subprogram
7725 && pdi
->tag
== DW_TAG_subprogram
))
7727 if (grandparent_scope
== NULL
)
7728 parent
->scope
= parent
->name (cu
);
7730 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7732 parent
->name (cu
), 0, cu
);
7736 /* FIXME drow/2004-04-01: What should we be doing with
7737 function-local names? For partial symbols, we should probably be
7739 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7740 dwarf_tag_name (parent
->tag
),
7741 sect_offset_str (pdi
->sect_off
));
7742 parent
->scope
= grandparent_scope
;
7745 parent
->scope_set
= 1;
7746 return parent
->scope
;
7749 /* Return the fully scoped name associated with PDI, from compilation unit
7750 CU. The result will be allocated with malloc. */
7752 static gdb::unique_xmalloc_ptr
<char>
7753 partial_die_full_name (struct partial_die_info
*pdi
,
7754 struct dwarf2_cu
*cu
)
7756 const char *parent_scope
;
7758 /* If this is a template instantiation, we can not work out the
7759 template arguments from partial DIEs. So, unfortunately, we have
7760 to go through the full DIEs. At least any work we do building
7761 types here will be reused if full symbols are loaded later. */
7762 if (pdi
->has_template_arguments
)
7766 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7768 struct die_info
*die
;
7769 struct attribute attr
;
7770 struct dwarf2_cu
*ref_cu
= cu
;
7772 /* DW_FORM_ref_addr is using section offset. */
7773 attr
.name
= (enum dwarf_attribute
) 0;
7774 attr
.form
= DW_FORM_ref_addr
;
7775 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7776 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7778 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7782 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7783 if (parent_scope
== NULL
)
7786 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7792 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7794 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7795 struct objfile
*objfile
= per_objfile
->objfile
;
7796 struct gdbarch
*gdbarch
= objfile
->arch ();
7798 const char *actual_name
= NULL
;
7801 baseaddr
= objfile
->text_section_offset ();
7803 gdb::unique_xmalloc_ptr
<char> built_actual_name
7804 = partial_die_full_name (pdi
, cu
);
7805 if (built_actual_name
!= NULL
)
7806 actual_name
= built_actual_name
.get ();
7808 if (actual_name
== NULL
)
7809 actual_name
= pdi
->name (cu
);
7811 partial_symbol psymbol
;
7812 memset (&psymbol
, 0, sizeof (psymbol
));
7813 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
7814 psymbol
.ginfo
.set_section_index (-1);
7816 /* The code below indicates that the psymbol should be installed by
7818 gdb::optional
<psymbol_placement
> where
;
7822 case DW_TAG_inlined_subroutine
:
7823 case DW_TAG_subprogram
:
7824 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7826 if (pdi
->is_external
7827 || cu
->language
== language_ada
7828 || (cu
->language
== language_fortran
7829 && pdi
->die_parent
!= NULL
7830 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7832 /* Normally, only "external" DIEs are part of the global scope.
7833 But in Ada and Fortran, we want to be able to access nested
7834 procedures globally. So all Ada and Fortran subprograms are
7835 stored in the global scope. */
7836 where
= psymbol_placement::GLOBAL
;
7839 where
= psymbol_placement::STATIC
;
7841 psymbol
.domain
= VAR_DOMAIN
;
7842 psymbol
.aclass
= LOC_BLOCK
;
7843 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7844 psymbol
.ginfo
.value
.address
= addr
;
7846 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7847 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7849 case DW_TAG_constant
:
7850 psymbol
.domain
= VAR_DOMAIN
;
7851 psymbol
.aclass
= LOC_STATIC
;
7852 where
= (pdi
->is_external
7853 ? psymbol_placement::GLOBAL
7854 : psymbol_placement::STATIC
);
7856 case DW_TAG_variable
:
7858 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7862 && !per_objfile
->per_bfd
->has_section_at_zero
)
7864 /* A global or static variable may also have been stripped
7865 out by the linker if unused, in which case its address
7866 will be nullified; do not add such variables into partial
7867 symbol table then. */
7869 else if (pdi
->is_external
)
7872 Don't enter into the minimal symbol tables as there is
7873 a minimal symbol table entry from the ELF symbols already.
7874 Enter into partial symbol table if it has a location
7875 descriptor or a type.
7876 If the location descriptor is missing, new_symbol will create
7877 a LOC_UNRESOLVED symbol, the address of the variable will then
7878 be determined from the minimal symbol table whenever the variable
7880 The address for the partial symbol table entry is not
7881 used by GDB, but it comes in handy for debugging partial symbol
7884 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7886 psymbol
.domain
= VAR_DOMAIN
;
7887 psymbol
.aclass
= LOC_STATIC
;
7888 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7889 psymbol
.ginfo
.value
.address
= addr
;
7890 where
= psymbol_placement::GLOBAL
;
7895 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7897 /* Static Variable. Skip symbols whose value we cannot know (those
7898 without location descriptors or constant values). */
7899 if (!has_loc
&& !pdi
->has_const_value
)
7902 psymbol
.domain
= VAR_DOMAIN
;
7903 psymbol
.aclass
= LOC_STATIC
;
7904 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7906 psymbol
.ginfo
.value
.address
= addr
;
7907 where
= psymbol_placement::STATIC
;
7910 case DW_TAG_array_type
:
7911 case DW_TAG_typedef
:
7912 case DW_TAG_base_type
:
7913 case DW_TAG_subrange_type
:
7914 psymbol
.domain
= VAR_DOMAIN
;
7915 psymbol
.aclass
= LOC_TYPEDEF
;
7916 where
= psymbol_placement::STATIC
;
7918 case DW_TAG_imported_declaration
:
7919 case DW_TAG_namespace
:
7920 psymbol
.domain
= VAR_DOMAIN
;
7921 psymbol
.aclass
= LOC_TYPEDEF
;
7922 where
= psymbol_placement::GLOBAL
;
7925 /* With Fortran 77 there might be a "BLOCK DATA" module
7926 available without any name. If so, we skip the module as it
7927 doesn't bring any value. */
7928 if (actual_name
!= nullptr)
7930 psymbol
.domain
= MODULE_DOMAIN
;
7931 psymbol
.aclass
= LOC_TYPEDEF
;
7932 where
= psymbol_placement::GLOBAL
;
7935 case DW_TAG_class_type
:
7936 case DW_TAG_interface_type
:
7937 case DW_TAG_structure_type
:
7938 case DW_TAG_union_type
:
7939 case DW_TAG_enumeration_type
:
7940 /* Skip external references. The DWARF standard says in the section
7941 about "Structure, Union, and Class Type Entries": "An incomplete
7942 structure, union or class type is represented by a structure,
7943 union or class entry that does not have a byte size attribute
7944 and that has a DW_AT_declaration attribute." */
7945 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7948 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7949 static vs. global. */
7950 psymbol
.domain
= STRUCT_DOMAIN
;
7951 psymbol
.aclass
= LOC_TYPEDEF
;
7952 where
= (cu
->language
== language_cplus
7953 ? psymbol_placement::GLOBAL
7954 : psymbol_placement::STATIC
);
7956 case DW_TAG_enumerator
:
7957 psymbol
.domain
= VAR_DOMAIN
;
7958 psymbol
.aclass
= LOC_CONST
;
7959 where
= (cu
->language
== language_cplus
7960 ? psymbol_placement::GLOBAL
7961 : psymbol_placement::STATIC
);
7967 if (where
.has_value ())
7969 if (built_actual_name
!= nullptr)
7970 actual_name
= objfile
->intern (actual_name
);
7971 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
7972 psymbol
.ginfo
.set_linkage_name (actual_name
);
7975 psymbol
.ginfo
.set_demangled_name (actual_name
,
7976 &objfile
->objfile_obstack
);
7977 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
7979 cu
->per_cu
->v
.psymtab
->add_psymbol
7980 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
7985 /* Read a partial die corresponding to a namespace; also, add a symbol
7986 corresponding to that namespace to the symbol table. NAMESPACE is
7987 the name of the enclosing namespace. */
7990 add_partial_namespace (struct partial_die_info
*pdi
,
7991 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7992 int set_addrmap
, struct dwarf2_cu
*cu
)
7994 /* Add a symbol for the namespace. */
7996 add_partial_symbol (pdi
, cu
);
7998 /* Now scan partial symbols in that namespace. */
8000 if (pdi
->has_children
)
8001 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8004 /* Read a partial die corresponding to a Fortran module. */
8007 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8008 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8010 /* Add a symbol for the namespace. */
8012 add_partial_symbol (pdi
, cu
);
8014 /* Now scan partial symbols in that module. */
8016 if (pdi
->has_children
)
8017 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8020 /* Read a partial die corresponding to a subprogram or an inlined
8021 subprogram and create a partial symbol for that subprogram.
8022 When the CU language allows it, this routine also defines a partial
8023 symbol for each nested subprogram that this subprogram contains.
8024 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8025 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8027 PDI may also be a lexical block, in which case we simply search
8028 recursively for subprograms defined inside that lexical block.
8029 Again, this is only performed when the CU language allows this
8030 type of definitions. */
8033 add_partial_subprogram (struct partial_die_info
*pdi
,
8034 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8035 int set_addrmap
, struct dwarf2_cu
*cu
)
8037 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8039 if (pdi
->has_pc_info
)
8041 if (pdi
->lowpc
< *lowpc
)
8042 *lowpc
= pdi
->lowpc
;
8043 if (pdi
->highpc
> *highpc
)
8044 *highpc
= pdi
->highpc
;
8047 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8048 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8049 struct gdbarch
*gdbarch
= objfile
->arch ();
8051 CORE_ADDR this_highpc
;
8052 CORE_ADDR this_lowpc
;
8054 baseaddr
= objfile
->text_section_offset ();
8056 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8057 pdi
->lowpc
+ baseaddr
)
8060 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8061 pdi
->highpc
+ baseaddr
)
8063 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8064 this_lowpc
, this_highpc
- 1,
8065 cu
->per_cu
->v
.psymtab
);
8069 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8071 if (!pdi
->is_declaration
)
8072 /* Ignore subprogram DIEs that do not have a name, they are
8073 illegal. Do not emit a complaint at this point, we will
8074 do so when we convert this psymtab into a symtab. */
8076 add_partial_symbol (pdi
, cu
);
8080 if (! pdi
->has_children
)
8083 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8085 pdi
= pdi
->die_child
;
8089 if (pdi
->tag
== DW_TAG_subprogram
8090 || pdi
->tag
== DW_TAG_inlined_subroutine
8091 || pdi
->tag
== DW_TAG_lexical_block
)
8092 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8093 pdi
= pdi
->die_sibling
;
8098 /* Read a partial die corresponding to an enumeration type. */
8101 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8102 struct dwarf2_cu
*cu
)
8104 struct partial_die_info
*pdi
;
8106 if (enum_pdi
->name (cu
) != NULL
)
8107 add_partial_symbol (enum_pdi
, cu
);
8109 pdi
= enum_pdi
->die_child
;
8112 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8113 complaint (_("malformed enumerator DIE ignored"));
8115 add_partial_symbol (pdi
, cu
);
8116 pdi
= pdi
->die_sibling
;
8120 /* Return the initial uleb128 in the die at INFO_PTR. */
8123 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8125 unsigned int bytes_read
;
8127 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8130 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8131 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8133 Return the corresponding abbrev, or NULL if the number is zero (indicating
8134 an empty DIE). In either case *BYTES_READ will be set to the length of
8135 the initial number. */
8137 static const struct abbrev_info
*
8138 peek_die_abbrev (const die_reader_specs
&reader
,
8139 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8141 dwarf2_cu
*cu
= reader
.cu
;
8142 bfd
*abfd
= reader
.abfd
;
8143 unsigned int abbrev_number
8144 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8146 if (abbrev_number
== 0)
8149 const abbrev_info
*abbrev
8150 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8153 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8154 " at offset %s [in module %s]"),
8155 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8156 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8162 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8163 Returns a pointer to the end of a series of DIEs, terminated by an empty
8164 DIE. Any children of the skipped DIEs will also be skipped. */
8166 static const gdb_byte
*
8167 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8171 unsigned int bytes_read
;
8172 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8176 return info_ptr
+ bytes_read
;
8178 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8182 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8183 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8184 abbrev corresponding to that skipped uleb128 should be passed in
8185 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8188 static const gdb_byte
*
8189 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8190 const struct abbrev_info
*abbrev
)
8192 unsigned int bytes_read
;
8193 struct attribute attr
;
8194 bfd
*abfd
= reader
->abfd
;
8195 struct dwarf2_cu
*cu
= reader
->cu
;
8196 const gdb_byte
*buffer
= reader
->buffer
;
8197 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8198 unsigned int form
, i
;
8200 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8202 /* The only abbrev we care about is DW_AT_sibling. */
8203 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8205 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8206 if (attr
.form
== DW_FORM_ref_addr
)
8207 complaint (_("ignoring absolute DW_AT_sibling"));
8210 sect_offset off
= attr
.get_ref_die_offset ();
8211 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8213 if (sibling_ptr
< info_ptr
)
8214 complaint (_("DW_AT_sibling points backwards"));
8215 else if (sibling_ptr
> reader
->buffer_end
)
8216 reader
->die_section
->overflow_complaint ();
8222 /* If it isn't DW_AT_sibling, skip this attribute. */
8223 form
= abbrev
->attrs
[i
].form
;
8227 case DW_FORM_ref_addr
:
8228 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8229 and later it is offset sized. */
8230 if (cu
->header
.version
== 2)
8231 info_ptr
+= cu
->header
.addr_size
;
8233 info_ptr
+= cu
->header
.offset_size
;
8235 case DW_FORM_GNU_ref_alt
:
8236 info_ptr
+= cu
->header
.offset_size
;
8239 info_ptr
+= cu
->header
.addr_size
;
8247 case DW_FORM_flag_present
:
8248 case DW_FORM_implicit_const
:
8265 case DW_FORM_ref_sig8
:
8268 case DW_FORM_data16
:
8271 case DW_FORM_string
:
8272 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8273 info_ptr
+= bytes_read
;
8275 case DW_FORM_sec_offset
:
8277 case DW_FORM_GNU_strp_alt
:
8278 info_ptr
+= cu
->header
.offset_size
;
8280 case DW_FORM_exprloc
:
8282 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8283 info_ptr
+= bytes_read
;
8285 case DW_FORM_block1
:
8286 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8288 case DW_FORM_block2
:
8289 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8291 case DW_FORM_block4
:
8292 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8298 case DW_FORM_ref_udata
:
8299 case DW_FORM_GNU_addr_index
:
8300 case DW_FORM_GNU_str_index
:
8301 case DW_FORM_rnglistx
:
8302 case DW_FORM_loclistx
:
8303 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8305 case DW_FORM_indirect
:
8306 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8307 info_ptr
+= bytes_read
;
8308 /* We need to continue parsing from here, so just go back to
8310 goto skip_attribute
;
8313 error (_("Dwarf Error: Cannot handle %s "
8314 "in DWARF reader [in module %s]"),
8315 dwarf_form_name (form
),
8316 bfd_get_filename (abfd
));
8320 if (abbrev
->has_children
)
8321 return skip_children (reader
, info_ptr
);
8326 /* Locate ORIG_PDI's sibling.
8327 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8329 static const gdb_byte
*
8330 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8331 struct partial_die_info
*orig_pdi
,
8332 const gdb_byte
*info_ptr
)
8334 /* Do we know the sibling already? */
8336 if (orig_pdi
->sibling
)
8337 return orig_pdi
->sibling
;
8339 /* Are there any children to deal with? */
8341 if (!orig_pdi
->has_children
)
8344 /* Skip the children the long way. */
8346 return skip_children (reader
, info_ptr
);
8349 /* Expand this partial symbol table into a full symbol table. SELF is
8353 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8355 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8357 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8359 /* If this psymtab is constructed from a debug-only objfile, the
8360 has_section_at_zero flag will not necessarily be correct. We
8361 can get the correct value for this flag by looking at the data
8362 associated with the (presumably stripped) associated objfile. */
8363 if (objfile
->separate_debug_objfile_backlink
)
8365 dwarf2_per_objfile
*per_objfile_backlink
8366 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8368 per_objfile
->per_bfd
->has_section_at_zero
8369 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8372 expand_psymtab (objfile
);
8374 process_cu_includes (per_objfile
);
8377 /* Reading in full CUs. */
8379 /* Add PER_CU to the queue. */
8382 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8383 dwarf2_per_objfile
*per_objfile
,
8384 enum language pretend_language
)
8388 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8389 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8392 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8394 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8397 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8398 DIEs, false otherwise.
8400 Explanation: there is an invariant that if a CU is queued for expansion
8401 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8402 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8403 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8404 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8405 invariant is respected.
8407 The caller is therefore not required to load the CU's DIEs (we return false)
8410 - the CU is already expanded, and therefore does not get enqueued
8411 - the CU gets enqueued for expansion, but its DIEs are already loaded
8413 Note that the caller should not use this function's return value as an
8414 indicator of whether the CU's DIEs are loaded right now, it should check
8415 that by calling `dwarf2_per_objfile::get_cu` instead. */
8418 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8419 dwarf2_per_cu_data
*per_cu
,
8420 dwarf2_per_objfile
*per_objfile
,
8421 enum language pretend_language
)
8423 /* We may arrive here during partial symbol reading, if we need full
8424 DIEs to process an unusual case (e.g. template arguments). Do
8425 not queue PER_CU, just tell our caller to load its DIEs. */
8426 if (per_cu
->per_bfd
->reading_partial_symbols
)
8428 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8430 if (cu
== NULL
|| cu
->dies
== NULL
)
8435 /* Mark the dependence relation so that we don't flush PER_CU
8437 if (dependent_cu
!= NULL
)
8438 dependent_cu
->add_dependence (per_cu
);
8440 /* If it's already on the queue, we have nothing to do. */
8443 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8445 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8447 /* If the CU is queued for expansion, it should not already be
8449 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8451 /* The DIEs are already loaded, the caller doesn't need to do it. */
8455 bool queued
= false;
8456 if (!per_objfile
->symtab_set_p (per_cu
))
8458 /* Add it to the queue. */
8459 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8463 /* If the compilation unit is already loaded, just mark it as
8465 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8469 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8470 and the DIEs are not already loaded. */
8471 return queued
&& cu
== nullptr;
8474 /* Process the queue. */
8477 process_queue (dwarf2_per_objfile
*per_objfile
)
8479 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8480 objfile_name (per_objfile
->objfile
));
8482 /* The queue starts out with one item, but following a DIE reference
8483 may load a new CU, adding it to the end of the queue. */
8484 while (!per_objfile
->per_bfd
->queue
->empty ())
8486 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8487 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8489 if (!per_objfile
->symtab_set_p (per_cu
))
8491 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8493 /* Skip dummy CUs. */
8496 unsigned int debug_print_threshold
;
8499 if (per_cu
->is_debug_types
)
8501 struct signatured_type
*sig_type
=
8502 (struct signatured_type
*) per_cu
;
8504 sprintf (buf
, "TU %s at offset %s",
8505 hex_string (sig_type
->signature
),
8506 sect_offset_str (per_cu
->sect_off
));
8507 /* There can be 100s of TUs.
8508 Only print them in verbose mode. */
8509 debug_print_threshold
= 2;
8513 sprintf (buf
, "CU at offset %s",
8514 sect_offset_str (per_cu
->sect_off
));
8515 debug_print_threshold
= 1;
8518 if (dwarf_read_debug
>= debug_print_threshold
)
8519 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8521 if (per_cu
->is_debug_types
)
8522 process_full_type_unit (cu
, item
.pretend_language
);
8524 process_full_comp_unit (cu
, item
.pretend_language
);
8526 if (dwarf_read_debug
>= debug_print_threshold
)
8527 dwarf_read_debug_printf ("Done expanding %s", buf
);
8532 per_objfile
->per_bfd
->queue
->pop ();
8535 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8536 objfile_name (per_objfile
->objfile
));
8539 /* Read in full symbols for PST, and anything it depends on. */
8542 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8544 gdb_assert (!readin_p (objfile
));
8546 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8547 free_cached_comp_units
freer (per_objfile
);
8548 expand_dependencies (objfile
);
8550 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8551 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8554 /* See psympriv.h. */
8557 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8559 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8560 return per_objfile
->symtab_set_p (per_cu_data
);
8563 /* See psympriv.h. */
8566 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8568 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8569 return per_objfile
->get_symtab (per_cu_data
);
8572 /* Trivial hash function for die_info: the hash value of a DIE
8573 is its offset in .debug_info for this objfile. */
8576 die_hash (const void *item
)
8578 const struct die_info
*die
= (const struct die_info
*) item
;
8580 return to_underlying (die
->sect_off
);
8583 /* Trivial comparison function for die_info structures: two DIEs
8584 are equal if they have the same offset. */
8587 die_eq (const void *item_lhs
, const void *item_rhs
)
8589 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8590 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8592 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8595 /* Load the DIEs associated with PER_CU into memory.
8597 In some cases, the caller, while reading partial symbols, will need to load
8598 the full symbols for the CU for some reason. It will already have a
8599 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8600 rather than creating a new one. */
8603 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8604 dwarf2_per_objfile
*per_objfile
,
8605 dwarf2_cu
*existing_cu
,
8607 enum language pretend_language
)
8609 gdb_assert (! this_cu
->is_debug_types
);
8611 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8615 struct dwarf2_cu
*cu
= reader
.cu
;
8616 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8618 gdb_assert (cu
->die_hash
== NULL
);
8620 htab_create_alloc_ex (cu
->header
.length
/ 12,
8624 &cu
->comp_unit_obstack
,
8625 hashtab_obstack_allocate
,
8626 dummy_obstack_deallocate
);
8628 if (reader
.comp_unit_die
->has_children
)
8629 reader
.comp_unit_die
->child
8630 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8631 &info_ptr
, reader
.comp_unit_die
);
8632 cu
->dies
= reader
.comp_unit_die
;
8633 /* comp_unit_die is not stored in die_hash, no need. */
8635 /* We try not to read any attributes in this function, because not
8636 all CUs needed for references have been loaded yet, and symbol
8637 table processing isn't initialized. But we have to set the CU language,
8638 or we won't be able to build types correctly.
8639 Similarly, if we do not read the producer, we can not apply
8640 producer-specific interpretation. */
8641 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8646 /* Add a DIE to the delayed physname list. */
8649 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8650 const char *name
, struct die_info
*die
,
8651 struct dwarf2_cu
*cu
)
8653 struct delayed_method_info mi
;
8655 mi
.fnfield_index
= fnfield_index
;
8659 cu
->method_list
.push_back (mi
);
8662 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8663 "const" / "volatile". If so, decrements LEN by the length of the
8664 modifier and return true. Otherwise return false. */
8668 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8670 size_t mod_len
= sizeof (mod
) - 1;
8671 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8679 /* Compute the physnames of any methods on the CU's method list.
8681 The computation of method physnames is delayed in order to avoid the
8682 (bad) condition that one of the method's formal parameters is of an as yet
8686 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8688 /* Only C++ delays computing physnames. */
8689 if (cu
->method_list
.empty ())
8691 gdb_assert (cu
->language
== language_cplus
);
8693 for (const delayed_method_info
&mi
: cu
->method_list
)
8695 const char *physname
;
8696 struct fn_fieldlist
*fn_flp
8697 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8698 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8699 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8700 = physname
? physname
: "";
8702 /* Since there's no tag to indicate whether a method is a
8703 const/volatile overload, extract that information out of the
8705 if (physname
!= NULL
)
8707 size_t len
= strlen (physname
);
8711 if (physname
[len
] == ')') /* shortcut */
8713 else if (check_modifier (physname
, len
, " const"))
8714 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8715 else if (check_modifier (physname
, len
, " volatile"))
8716 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8723 /* The list is no longer needed. */
8724 cu
->method_list
.clear ();
8727 /* Go objects should be embedded in a DW_TAG_module DIE,
8728 and it's not clear if/how imported objects will appear.
8729 To keep Go support simple until that's worked out,
8730 go back through what we've read and create something usable.
8731 We could do this while processing each DIE, and feels kinda cleaner,
8732 but that way is more invasive.
8733 This is to, for example, allow the user to type "p var" or "b main"
8734 without having to specify the package name, and allow lookups
8735 of module.object to work in contexts that use the expression
8739 fixup_go_packaging (struct dwarf2_cu
*cu
)
8741 gdb::unique_xmalloc_ptr
<char> package_name
;
8742 struct pending
*list
;
8745 for (list
= *cu
->get_builder ()->get_global_symbols ();
8749 for (i
= 0; i
< list
->nsyms
; ++i
)
8751 struct symbol
*sym
= list
->symbol
[i
];
8753 if (sym
->language () == language_go
8754 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8756 gdb::unique_xmalloc_ptr
<char> this_package_name
8757 (go_symbol_package_name (sym
));
8759 if (this_package_name
== NULL
)
8761 if (package_name
== NULL
)
8762 package_name
= std::move (this_package_name
);
8765 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8766 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8767 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8768 (symbol_symtab (sym
) != NULL
8769 ? symtab_to_filename_for_display
8770 (symbol_symtab (sym
))
8771 : objfile_name (objfile
)),
8772 this_package_name
.get (), package_name
.get ());
8778 if (package_name
!= NULL
)
8780 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8781 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8782 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8783 saved_package_name
);
8786 sym
= new (&objfile
->objfile_obstack
) symbol
;
8787 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8788 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8789 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8790 e.g., "main" finds the "main" module and not C's main(). */
8791 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8792 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8793 SYMBOL_TYPE (sym
) = type
;
8795 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8799 /* Allocate a fully-qualified name consisting of the two parts on the
8803 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8805 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8808 /* A helper that allocates a variant part to attach to a Rust enum
8809 type. OBSTACK is where the results should be allocated. TYPE is
8810 the type we're processing. DISCRIMINANT_INDEX is the index of the
8811 discriminant. It must be the index of one of the fields of TYPE,
8812 or -1 to mean there is no discriminant (univariant enum).
8813 DEFAULT_INDEX is the index of the default field; or -1 if there is
8814 no default. RANGES is indexed by "effective" field number (the
8815 field index, but omitting the discriminant and default fields) and
8816 must hold the discriminant values used by the variants. Note that
8817 RANGES must have a lifetime at least as long as OBSTACK -- either
8818 already allocated on it, or static. */
8821 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8822 int discriminant_index
, int default_index
,
8823 gdb::array_view
<discriminant_range
> ranges
)
8825 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8826 gdb_assert (discriminant_index
== -1
8827 || (discriminant_index
>= 0
8828 && discriminant_index
< type
->num_fields ()));
8829 gdb_assert (default_index
== -1
8830 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8832 /* We have one variant for each non-discriminant field. */
8833 int n_variants
= type
->num_fields ();
8834 if (discriminant_index
!= -1)
8837 variant
*variants
= new (obstack
) variant
[n_variants
];
8840 for (int i
= 0; i
< type
->num_fields (); ++i
)
8842 if (i
== discriminant_index
)
8845 variants
[var_idx
].first_field
= i
;
8846 variants
[var_idx
].last_field
= i
+ 1;
8848 /* The default field does not need a range, but other fields do.
8849 We skipped the discriminant above. */
8850 if (i
!= default_index
)
8852 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8859 gdb_assert (range_idx
== ranges
.size ());
8860 gdb_assert (var_idx
== n_variants
);
8862 variant_part
*part
= new (obstack
) variant_part
;
8863 part
->discriminant_index
= discriminant_index
;
8864 /* If there is no discriminant, then whether it is signed is of no
8867 = (discriminant_index
== -1
8869 : type
->field (discriminant_index
).type ()->is_unsigned ());
8870 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
8872 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
8873 gdb::array_view
<variant_part
> *prop_value
8874 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
8876 struct dynamic_prop prop
;
8877 prop
.set_variant_parts (prop_value
);
8879 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
8882 /* Some versions of rustc emitted enums in an unusual way.
8884 Ordinary enums were emitted as unions. The first element of each
8885 structure in the union was named "RUST$ENUM$DISR". This element
8886 held the discriminant.
8888 These versions of Rust also implemented the "non-zero"
8889 optimization. When the enum had two values, and one is empty and
8890 the other holds a pointer that cannot be zero, the pointer is used
8891 as the discriminant, with a zero value meaning the empty variant.
8892 Here, the union's first member is of the form
8893 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
8894 where the fieldnos are the indices of the fields that should be
8895 traversed in order to find the field (which may be several fields deep)
8896 and the variantname is the name of the variant of the case when the
8899 This function recognizes whether TYPE is of one of these forms,
8900 and, if so, smashes it to be a variant type. */
8903 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
8905 gdb_assert (type
->code () == TYPE_CODE_UNION
);
8907 /* We don't need to deal with empty enums. */
8908 if (type
->num_fields () == 0)
8911 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
8912 if (type
->num_fields () == 1
8913 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
8915 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
8917 /* Decode the field name to find the offset of the
8919 ULONGEST bit_offset
= 0;
8920 struct type
*field_type
= type
->field (0).type ();
8921 while (name
[0] >= '0' && name
[0] <= '9')
8924 unsigned long index
= strtoul (name
, &tail
, 10);
8927 || index
>= field_type
->num_fields ()
8928 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
8929 != FIELD_LOC_KIND_BITPOS
))
8931 complaint (_("Could not parse Rust enum encoding string \"%s\""
8933 TYPE_FIELD_NAME (type
, 0),
8934 objfile_name (objfile
));
8939 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
8940 field_type
= field_type
->field (index
).type ();
8943 /* Smash this type to be a structure type. We have to do this
8944 because the type has already been recorded. */
8945 type
->set_code (TYPE_CODE_STRUCT
);
8946 type
->set_num_fields (3);
8947 /* Save the field we care about. */
8948 struct field saved_field
= type
->field (0);
8950 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
8952 /* Put the discriminant at index 0. */
8953 type
->field (0).set_type (field_type
);
8954 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
8955 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
8956 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
8958 /* The order of fields doesn't really matter, so put the real
8959 field at index 1 and the data-less field at index 2. */
8960 type
->field (1) = saved_field
;
8961 TYPE_FIELD_NAME (type
, 1)
8962 = rust_last_path_segment (type
->field (1).type ()->name ());
8963 type
->field (1).type ()->set_name
8964 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8965 TYPE_FIELD_NAME (type
, 1)));
8967 const char *dataless_name
8968 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8970 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
8972 type
->field (2).set_type (dataless_type
);
8973 /* NAME points into the original discriminant name, which
8974 already has the correct lifetime. */
8975 TYPE_FIELD_NAME (type
, 2) = name
;
8976 SET_FIELD_BITPOS (type
->field (2), 0);
8978 /* Indicate that this is a variant type. */
8979 static discriminant_range ranges
[1] = { { 0, 0 } };
8980 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
8982 /* A union with a single anonymous field is probably an old-style
8984 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
8986 /* Smash this type to be a structure type. We have to do this
8987 because the type has already been recorded. */
8988 type
->set_code (TYPE_CODE_STRUCT
);
8990 struct type
*field_type
= type
->field (0).type ();
8991 const char *variant_name
8992 = rust_last_path_segment (field_type
->name ());
8993 TYPE_FIELD_NAME (type
, 0) = variant_name
;
8994 field_type
->set_name
8995 (rust_fully_qualify (&objfile
->objfile_obstack
,
8996 type
->name (), variant_name
));
8998 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9002 struct type
*disr_type
= nullptr;
9003 for (int i
= 0; i
< type
->num_fields (); ++i
)
9005 disr_type
= type
->field (i
).type ();
9007 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9009 /* All fields of a true enum will be structs. */
9012 else if (disr_type
->num_fields () == 0)
9014 /* Could be data-less variant, so keep going. */
9015 disr_type
= nullptr;
9017 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9018 "RUST$ENUM$DISR") != 0)
9020 /* Not a Rust enum. */
9030 /* If we got here without a discriminant, then it's probably
9032 if (disr_type
== nullptr)
9035 /* Smash this type to be a structure type. We have to do this
9036 because the type has already been recorded. */
9037 type
->set_code (TYPE_CODE_STRUCT
);
9039 /* Make space for the discriminant field. */
9040 struct field
*disr_field
= &disr_type
->field (0);
9042 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9043 * sizeof (struct field
)));
9044 memcpy (new_fields
+ 1, type
->fields (),
9045 type
->num_fields () * sizeof (struct field
));
9046 type
->set_fields (new_fields
);
9047 type
->set_num_fields (type
->num_fields () + 1);
9049 /* Install the discriminant at index 0 in the union. */
9050 type
->field (0) = *disr_field
;
9051 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9052 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9054 /* We need a way to find the correct discriminant given a
9055 variant name. For convenience we build a map here. */
9056 struct type
*enum_type
= disr_field
->type ();
9057 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9058 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9060 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9063 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9064 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9068 int n_fields
= type
->num_fields ();
9069 /* We don't need a range entry for the discriminant, but we do
9070 need one for every other field, as there is no default
9072 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9075 /* Skip the discriminant here. */
9076 for (int i
= 1; i
< n_fields
; ++i
)
9078 /* Find the final word in the name of this variant's type.
9079 That name can be used to look up the correct
9081 const char *variant_name
9082 = rust_last_path_segment (type
->field (i
).type ()->name ());
9084 auto iter
= discriminant_map
.find (variant_name
);
9085 if (iter
!= discriminant_map
.end ())
9087 ranges
[i
- 1].low
= iter
->second
;
9088 ranges
[i
- 1].high
= iter
->second
;
9091 /* In Rust, each element should have the size of the
9093 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9095 /* Remove the discriminant field, if it exists. */
9096 struct type
*sub_type
= type
->field (i
).type ();
9097 if (sub_type
->num_fields () > 0)
9099 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9100 sub_type
->set_fields (sub_type
->fields () + 1);
9102 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9104 (rust_fully_qualify (&objfile
->objfile_obstack
,
9105 type
->name (), variant_name
));
9108 /* Indicate that this is a variant type. */
9109 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9110 gdb::array_view
<discriminant_range
> (ranges
,
9115 /* Rewrite some Rust unions to be structures with variants parts. */
9118 rust_union_quirks (struct dwarf2_cu
*cu
)
9120 gdb_assert (cu
->language
== language_rust
);
9121 for (type
*type_
: cu
->rust_unions
)
9122 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9123 /* We don't need this any more. */
9124 cu
->rust_unions
.clear ();
9129 type_unit_group_unshareable
*
9130 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9132 auto iter
= this->m_type_units
.find (tu_group
);
9133 if (iter
!= this->m_type_units
.end ())
9134 return iter
->second
.get ();
9136 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9137 type_unit_group_unshareable
*result
= uniq
.get ();
9138 this->m_type_units
[tu_group
] = std::move (uniq
);
9143 dwarf2_per_objfile::get_type_for_signatured_type
9144 (signatured_type
*sig_type
) const
9146 auto iter
= this->m_type_map
.find (sig_type
);
9147 if (iter
== this->m_type_map
.end ())
9150 return iter
->second
;
9153 void dwarf2_per_objfile::set_type_for_signatured_type
9154 (signatured_type
*sig_type
, struct type
*type
)
9156 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9158 this->m_type_map
[sig_type
] = type
;
9161 /* A helper function for computing the list of all symbol tables
9162 included by PER_CU. */
9165 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9166 htab_t all_children
, htab_t all_type_symtabs
,
9167 dwarf2_per_cu_data
*per_cu
,
9168 dwarf2_per_objfile
*per_objfile
,
9169 struct compunit_symtab
*immediate_parent
)
9171 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9174 /* This inclusion and its children have been processed. */
9180 /* Only add a CU if it has a symbol table. */
9181 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9184 /* If this is a type unit only add its symbol table if we haven't
9185 seen it yet (type unit per_cu's can share symtabs). */
9186 if (per_cu
->is_debug_types
)
9188 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9192 result
->push_back (cust
);
9193 if (cust
->user
== NULL
)
9194 cust
->user
= immediate_parent
;
9199 result
->push_back (cust
);
9200 if (cust
->user
== NULL
)
9201 cust
->user
= immediate_parent
;
9205 if (!per_cu
->imported_symtabs_empty ())
9206 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9208 recursively_compute_inclusions (result
, all_children
,
9209 all_type_symtabs
, ptr
, per_objfile
,
9214 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9218 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9219 dwarf2_per_objfile
*per_objfile
)
9221 gdb_assert (! per_cu
->is_debug_types
);
9223 if (!per_cu
->imported_symtabs_empty ())
9226 std::vector
<compunit_symtab
*> result_symtabs
;
9227 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9229 /* If we don't have a symtab, we can just skip this case. */
9233 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9235 NULL
, xcalloc
, xfree
));
9236 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9238 NULL
, xcalloc
, xfree
));
9240 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9242 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9243 all_type_symtabs
.get (), ptr
,
9247 /* Now we have a transitive closure of all the included symtabs. */
9248 len
= result_symtabs
.size ();
9250 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9251 struct compunit_symtab
*, len
+ 1);
9252 memcpy (cust
->includes
, result_symtabs
.data (),
9253 len
* sizeof (compunit_symtab
*));
9254 cust
->includes
[len
] = NULL
;
9258 /* Compute the 'includes' field for the symtabs of all the CUs we just
9262 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9264 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9266 if (! iter
->is_debug_types
)
9267 compute_compunit_symtab_includes (iter
, per_objfile
);
9270 per_objfile
->per_bfd
->just_read_cus
.clear ();
9273 /* Generate full symbol information for CU, whose DIEs have
9274 already been loaded into memory. */
9277 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9279 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9280 struct objfile
*objfile
= per_objfile
->objfile
;
9281 struct gdbarch
*gdbarch
= objfile
->arch ();
9282 CORE_ADDR lowpc
, highpc
;
9283 struct compunit_symtab
*cust
;
9285 struct block
*static_block
;
9288 baseaddr
= objfile
->text_section_offset ();
9290 /* Clear the list here in case something was left over. */
9291 cu
->method_list
.clear ();
9293 cu
->language
= pretend_language
;
9294 cu
->language_defn
= language_def (cu
->language
);
9296 dwarf2_find_base_address (cu
->dies
, cu
);
9298 /* Before we start reading the top-level DIE, ensure it has a valid tag
9300 switch (cu
->dies
->tag
)
9302 case DW_TAG_compile_unit
:
9303 case DW_TAG_partial_unit
:
9304 case DW_TAG_type_unit
:
9307 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9308 dwarf_tag_name (cu
->dies
->tag
),
9309 sect_offset_str (cu
->per_cu
->sect_off
),
9310 objfile_name (per_objfile
->objfile
));
9313 /* Do line number decoding in read_file_scope () */
9314 process_die (cu
->dies
, cu
);
9316 /* For now fudge the Go package. */
9317 if (cu
->language
== language_go
)
9318 fixup_go_packaging (cu
);
9320 /* Now that we have processed all the DIEs in the CU, all the types
9321 should be complete, and it should now be safe to compute all of the
9323 compute_delayed_physnames (cu
);
9325 if (cu
->language
== language_rust
)
9326 rust_union_quirks (cu
);
9328 /* Some compilers don't define a DW_AT_high_pc attribute for the
9329 compilation unit. If the DW_AT_high_pc is missing, synthesize
9330 it, by scanning the DIE's below the compilation unit. */
9331 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9333 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9334 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9336 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9337 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9338 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9339 addrmap to help ensure it has an accurate map of pc values belonging to
9341 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9343 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9344 SECT_OFF_TEXT (objfile
),
9349 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9351 /* Set symtab language to language from DW_AT_language. If the
9352 compilation is from a C file generated by language preprocessors, do
9353 not set the language if it was already deduced by start_subfile. */
9354 if (!(cu
->language
== language_c
9355 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9356 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9358 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9359 produce DW_AT_location with location lists but it can be possibly
9360 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9361 there were bugs in prologue debug info, fixed later in GCC-4.5
9362 by "unwind info for epilogues" patch (which is not directly related).
9364 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9365 needed, it would be wrong due to missing DW_AT_producer there.
9367 Still one can confuse GDB by using non-standard GCC compilation
9368 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9370 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9371 cust
->locations_valid
= 1;
9373 if (gcc_4_minor
>= 5)
9374 cust
->epilogue_unwind_valid
= 1;
9376 cust
->call_site_htab
= cu
->call_site_htab
;
9379 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9381 /* Push it for inclusion processing later. */
9382 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9384 /* Not needed any more. */
9385 cu
->reset_builder ();
9388 /* Generate full symbol information for type unit CU, whose DIEs have
9389 already been loaded into memory. */
9392 process_full_type_unit (dwarf2_cu
*cu
,
9393 enum language pretend_language
)
9395 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9396 struct objfile
*objfile
= per_objfile
->objfile
;
9397 struct compunit_symtab
*cust
;
9398 struct signatured_type
*sig_type
;
9400 gdb_assert (cu
->per_cu
->is_debug_types
);
9401 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9403 /* Clear the list here in case something was left over. */
9404 cu
->method_list
.clear ();
9406 cu
->language
= pretend_language
;
9407 cu
->language_defn
= language_def (cu
->language
);
9409 /* The symbol tables are set up in read_type_unit_scope. */
9410 process_die (cu
->dies
, cu
);
9412 /* For now fudge the Go package. */
9413 if (cu
->language
== language_go
)
9414 fixup_go_packaging (cu
);
9416 /* Now that we have processed all the DIEs in the CU, all the types
9417 should be complete, and it should now be safe to compute all of the
9419 compute_delayed_physnames (cu
);
9421 if (cu
->language
== language_rust
)
9422 rust_union_quirks (cu
);
9424 /* TUs share symbol tables.
9425 If this is the first TU to use this symtab, complete the construction
9426 of it with end_expandable_symtab. Otherwise, complete the addition of
9427 this TU's symbols to the existing symtab. */
9428 type_unit_group_unshareable
*tug_unshare
=
9429 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9430 if (tug_unshare
->compunit_symtab
== NULL
)
9432 buildsym_compunit
*builder
= cu
->get_builder ();
9433 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9434 tug_unshare
->compunit_symtab
= cust
;
9438 /* Set symtab language to language from DW_AT_language. If the
9439 compilation is from a C file generated by language preprocessors,
9440 do not set the language if it was already deduced by
9442 if (!(cu
->language
== language_c
9443 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9444 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9449 cu
->get_builder ()->augment_type_symtab ();
9450 cust
= tug_unshare
->compunit_symtab
;
9453 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9455 /* Not needed any more. */
9456 cu
->reset_builder ();
9459 /* Process an imported unit DIE. */
9462 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9464 struct attribute
*attr
;
9466 /* For now we don't handle imported units in type units. */
9467 if (cu
->per_cu
->is_debug_types
)
9469 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9470 " supported in type units [in module %s]"),
9471 objfile_name (cu
->per_objfile
->objfile
));
9474 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9477 sect_offset sect_off
= attr
->get_ref_die_offset ();
9478 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9479 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9480 dwarf2_per_cu_data
*per_cu
9481 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9483 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9484 into another compilation unit, at root level. Regard this as a hint,
9486 if (die
->parent
&& die
->parent
->parent
== NULL
9487 && per_cu
->unit_type
== DW_UT_compile
9488 && per_cu
->lang
== language_cplus
)
9491 /* If necessary, add it to the queue and load its DIEs. */
9492 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
9493 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9494 false, cu
->language
);
9496 cu
->per_cu
->imported_symtabs_push (per_cu
);
9500 /* RAII object that represents a process_die scope: i.e.,
9501 starts/finishes processing a DIE. */
9502 class process_die_scope
9505 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9506 : m_die (die
), m_cu (cu
)
9508 /* We should only be processing DIEs not already in process. */
9509 gdb_assert (!m_die
->in_process
);
9510 m_die
->in_process
= true;
9513 ~process_die_scope ()
9515 m_die
->in_process
= false;
9517 /* If we're done processing the DIE for the CU that owns the line
9518 header, we don't need the line header anymore. */
9519 if (m_cu
->line_header_die_owner
== m_die
)
9521 delete m_cu
->line_header
;
9522 m_cu
->line_header
= NULL
;
9523 m_cu
->line_header_die_owner
= NULL
;
9532 /* Process a die and its children. */
9535 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9537 process_die_scope
scope (die
, cu
);
9541 case DW_TAG_padding
:
9543 case DW_TAG_compile_unit
:
9544 case DW_TAG_partial_unit
:
9545 read_file_scope (die
, cu
);
9547 case DW_TAG_type_unit
:
9548 read_type_unit_scope (die
, cu
);
9550 case DW_TAG_subprogram
:
9551 /* Nested subprograms in Fortran get a prefix. */
9552 if (cu
->language
== language_fortran
9553 && die
->parent
!= NULL
9554 && die
->parent
->tag
== DW_TAG_subprogram
)
9555 cu
->processing_has_namespace_info
= true;
9557 case DW_TAG_inlined_subroutine
:
9558 read_func_scope (die
, cu
);
9560 case DW_TAG_lexical_block
:
9561 case DW_TAG_try_block
:
9562 case DW_TAG_catch_block
:
9563 read_lexical_block_scope (die
, cu
);
9565 case DW_TAG_call_site
:
9566 case DW_TAG_GNU_call_site
:
9567 read_call_site_scope (die
, cu
);
9569 case DW_TAG_class_type
:
9570 case DW_TAG_interface_type
:
9571 case DW_TAG_structure_type
:
9572 case DW_TAG_union_type
:
9573 process_structure_scope (die
, cu
);
9575 case DW_TAG_enumeration_type
:
9576 process_enumeration_scope (die
, cu
);
9579 /* These dies have a type, but processing them does not create
9580 a symbol or recurse to process the children. Therefore we can
9581 read them on-demand through read_type_die. */
9582 case DW_TAG_subroutine_type
:
9583 case DW_TAG_set_type
:
9584 case DW_TAG_pointer_type
:
9585 case DW_TAG_ptr_to_member_type
:
9586 case DW_TAG_reference_type
:
9587 case DW_TAG_rvalue_reference_type
:
9588 case DW_TAG_string_type
:
9591 case DW_TAG_array_type
:
9592 /* We only need to handle this case for Ada -- in other
9593 languages, it's normal for the compiler to emit a typedef
9595 if (cu
->language
!= language_ada
)
9598 case DW_TAG_base_type
:
9599 case DW_TAG_subrange_type
:
9600 case DW_TAG_typedef
:
9601 /* Add a typedef symbol for the type definition, if it has a
9603 new_symbol (die
, read_type_die (die
, cu
), cu
);
9605 case DW_TAG_common_block
:
9606 read_common_block (die
, cu
);
9608 case DW_TAG_common_inclusion
:
9610 case DW_TAG_namespace
:
9611 cu
->processing_has_namespace_info
= true;
9612 read_namespace (die
, cu
);
9615 cu
->processing_has_namespace_info
= true;
9616 read_module (die
, cu
);
9618 case DW_TAG_imported_declaration
:
9619 cu
->processing_has_namespace_info
= true;
9620 if (read_namespace_alias (die
, cu
))
9622 /* The declaration is not a global namespace alias. */
9624 case DW_TAG_imported_module
:
9625 cu
->processing_has_namespace_info
= true;
9626 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9627 || cu
->language
!= language_fortran
))
9628 complaint (_("Tag '%s' has unexpected children"),
9629 dwarf_tag_name (die
->tag
));
9630 read_import_statement (die
, cu
);
9633 case DW_TAG_imported_unit
:
9634 process_imported_unit_die (die
, cu
);
9637 case DW_TAG_variable
:
9638 read_variable (die
, cu
);
9642 new_symbol (die
, NULL
, cu
);
9647 /* DWARF name computation. */
9649 /* A helper function for dwarf2_compute_name which determines whether DIE
9650 needs to have the name of the scope prepended to the name listed in the
9654 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9656 struct attribute
*attr
;
9660 case DW_TAG_namespace
:
9661 case DW_TAG_typedef
:
9662 case DW_TAG_class_type
:
9663 case DW_TAG_interface_type
:
9664 case DW_TAG_structure_type
:
9665 case DW_TAG_union_type
:
9666 case DW_TAG_enumeration_type
:
9667 case DW_TAG_enumerator
:
9668 case DW_TAG_subprogram
:
9669 case DW_TAG_inlined_subroutine
:
9671 case DW_TAG_imported_declaration
:
9674 case DW_TAG_variable
:
9675 case DW_TAG_constant
:
9676 /* We only need to prefix "globally" visible variables. These include
9677 any variable marked with DW_AT_external or any variable that
9678 lives in a namespace. [Variables in anonymous namespaces
9679 require prefixing, but they are not DW_AT_external.] */
9681 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9683 struct dwarf2_cu
*spec_cu
= cu
;
9685 return die_needs_namespace (die_specification (die
, &spec_cu
),
9689 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9690 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9691 && die
->parent
->tag
!= DW_TAG_module
)
9693 /* A variable in a lexical block of some kind does not need a
9694 namespace, even though in C++ such variables may be external
9695 and have a mangled name. */
9696 if (die
->parent
->tag
== DW_TAG_lexical_block
9697 || die
->parent
->tag
== DW_TAG_try_block
9698 || die
->parent
->tag
== DW_TAG_catch_block
9699 || die
->parent
->tag
== DW_TAG_subprogram
)
9708 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9709 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9710 defined for the given DIE. */
9712 static struct attribute
*
9713 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9715 struct attribute
*attr
;
9717 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9719 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9724 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9725 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9726 defined for the given DIE. */
9729 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9731 const char *linkage_name
;
9733 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9734 if (linkage_name
== NULL
)
9735 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9737 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9738 See https://github.com/rust-lang/rust/issues/32925. */
9739 if (cu
->language
== language_rust
&& linkage_name
!= NULL
9740 && strchr (linkage_name
, '{') != NULL
)
9741 linkage_name
= NULL
;
9743 return linkage_name
;
9746 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9747 compute the physname for the object, which include a method's:
9748 - formal parameters (C++),
9749 - receiver type (Go),
9751 The term "physname" is a bit confusing.
9752 For C++, for example, it is the demangled name.
9753 For Go, for example, it's the mangled name.
9755 For Ada, return the DIE's linkage name rather than the fully qualified
9756 name. PHYSNAME is ignored..
9758 The result is allocated on the objfile->per_bfd's obstack and
9762 dwarf2_compute_name (const char *name
,
9763 struct die_info
*die
, struct dwarf2_cu
*cu
,
9766 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9769 name
= dwarf2_name (die
, cu
);
9771 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9772 but otherwise compute it by typename_concat inside GDB.
9773 FIXME: Actually this is not really true, or at least not always true.
9774 It's all very confusing. compute_and_set_names doesn't try to demangle
9775 Fortran names because there is no mangling standard. So new_symbol
9776 will set the demangled name to the result of dwarf2_full_name, and it is
9777 the demangled name that GDB uses if it exists. */
9778 if (cu
->language
== language_ada
9779 || (cu
->language
== language_fortran
&& physname
))
9781 /* For Ada unit, we prefer the linkage name over the name, as
9782 the former contains the exported name, which the user expects
9783 to be able to reference. Ideally, we want the user to be able
9784 to reference this entity using either natural or linkage name,
9785 but we haven't started looking at this enhancement yet. */
9786 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9788 if (linkage_name
!= NULL
)
9789 return linkage_name
;
9792 /* These are the only languages we know how to qualify names in. */
9794 && (cu
->language
== language_cplus
9795 || cu
->language
== language_fortran
|| cu
->language
== language_d
9796 || cu
->language
== language_rust
))
9798 if (die_needs_namespace (die
, cu
))
9801 const char *canonical_name
= NULL
;
9805 prefix
= determine_prefix (die
, cu
);
9806 if (*prefix
!= '\0')
9808 gdb::unique_xmalloc_ptr
<char> prefixed_name
9809 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9811 buf
.puts (prefixed_name
.get ());
9816 /* Template parameters may be specified in the DIE's DW_AT_name, or
9817 as children with DW_TAG_template_type_param or
9818 DW_TAG_value_type_param. If the latter, add them to the name
9819 here. If the name already has template parameters, then
9820 skip this step; some versions of GCC emit both, and
9821 it is more efficient to use the pre-computed name.
9823 Something to keep in mind about this process: it is very
9824 unlikely, or in some cases downright impossible, to produce
9825 something that will match the mangled name of a function.
9826 If the definition of the function has the same debug info,
9827 we should be able to match up with it anyway. But fallbacks
9828 using the minimal symbol, for instance to find a method
9829 implemented in a stripped copy of libstdc++, will not work.
9830 If we do not have debug info for the definition, we will have to
9831 match them up some other way.
9833 When we do name matching there is a related problem with function
9834 templates; two instantiated function templates are allowed to
9835 differ only by their return types, which we do not add here. */
9837 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
9839 struct attribute
*attr
;
9840 struct die_info
*child
;
9842 const language_defn
*cplus_lang
= language_def (cu
->language
);
9844 die
->building_fullname
= 1;
9846 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9850 const gdb_byte
*bytes
;
9851 struct dwarf2_locexpr_baton
*baton
;
9854 if (child
->tag
!= DW_TAG_template_type_param
9855 && child
->tag
!= DW_TAG_template_value_param
)
9866 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9869 complaint (_("template parameter missing DW_AT_type"));
9870 buf
.puts ("UNKNOWN_TYPE");
9873 type
= die_type (child
, cu
);
9875 if (child
->tag
== DW_TAG_template_type_param
)
9877 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
9878 &type_print_raw_options
);
9882 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
9885 complaint (_("template parameter missing "
9886 "DW_AT_const_value"));
9887 buf
.puts ("UNKNOWN_VALUE");
9891 dwarf2_const_value_attr (attr
, type
, name
,
9892 &cu
->comp_unit_obstack
, cu
,
9893 &value
, &bytes
, &baton
);
9895 if (type
->has_no_signedness ())
9896 /* GDB prints characters as NUMBER 'CHAR'. If that's
9897 changed, this can use value_print instead. */
9898 cplus_lang
->printchar (value
, type
, &buf
);
9901 struct value_print_options opts
;
9904 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
9908 baton
->per_objfile
);
9909 else if (bytes
!= NULL
)
9911 v
= allocate_value (type
);
9912 memcpy (value_contents_writeable (v
), bytes
,
9913 TYPE_LENGTH (type
));
9916 v
= value_from_longest (type
, value
);
9918 /* Specify decimal so that we do not depend on
9920 get_formatted_print_options (&opts
, 'd');
9922 value_print (v
, &buf
, &opts
);
9927 die
->building_fullname
= 0;
9931 /* Close the argument list, with a space if necessary
9932 (nested templates). */
9933 if (!buf
.empty () && buf
.string ().back () == '>')
9940 /* For C++ methods, append formal parameter type
9941 information, if PHYSNAME. */
9943 if (physname
&& die
->tag
== DW_TAG_subprogram
9944 && cu
->language
== language_cplus
)
9946 struct type
*type
= read_type_die (die
, cu
);
9948 c_type_print_args (type
, &buf
, 1, cu
->language
,
9949 &type_print_raw_options
);
9951 if (cu
->language
== language_cplus
)
9953 /* Assume that an artificial first parameter is
9954 "this", but do not crash if it is not. RealView
9955 marks unnamed (and thus unused) parameters as
9956 artificial; there is no way to differentiate
9958 if (type
->num_fields () > 0
9959 && TYPE_FIELD_ARTIFICIAL (type
, 0)
9960 && type
->field (0).type ()->code () == TYPE_CODE_PTR
9961 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
9962 buf
.puts (" const");
9966 const std::string
&intermediate_name
= buf
.string ();
9968 if (cu
->language
== language_cplus
)
9970 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
9973 /* If we only computed INTERMEDIATE_NAME, or if
9974 INTERMEDIATE_NAME is already canonical, then we need to
9976 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
9977 name
= objfile
->intern (intermediate_name
);
9979 name
= canonical_name
;
9986 /* Return the fully qualified name of DIE, based on its DW_AT_name.
9987 If scope qualifiers are appropriate they will be added. The result
9988 will be allocated on the storage_obstack, or NULL if the DIE does
9989 not have a name. NAME may either be from a previous call to
9990 dwarf2_name or NULL.
9992 The output string will be canonicalized (if C++). */
9995 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
9997 return dwarf2_compute_name (name
, die
, cu
, 0);
10000 /* Construct a physname for the given DIE in CU. NAME may either be
10001 from a previous call to dwarf2_name or NULL. The result will be
10002 allocated on the objfile_objstack or NULL if the DIE does not have a
10005 The output string will be canonicalized (if C++). */
10007 static const char *
10008 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10010 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10011 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10014 /* In this case dwarf2_compute_name is just a shortcut not building anything
10016 if (!die_needs_namespace (die
, cu
))
10017 return dwarf2_compute_name (name
, die
, cu
, 1);
10019 if (cu
->language
!= language_rust
)
10020 mangled
= dw2_linkage_name (die
, cu
);
10022 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10024 gdb::unique_xmalloc_ptr
<char> demangled
;
10025 if (mangled
!= NULL
)
10028 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10030 /* Do nothing (do not demangle the symbol name). */
10034 /* Use DMGL_RET_DROP for C++ template functions to suppress
10035 their return type. It is easier for GDB users to search
10036 for such functions as `name(params)' than `long name(params)'.
10037 In such case the minimal symbol names do not match the full
10038 symbol names but for template functions there is never a need
10039 to look up their definition from their declaration so
10040 the only disadvantage remains the minimal symbol variant
10041 `long name(params)' does not have the proper inferior type. */
10042 demangled
.reset (gdb_demangle (mangled
,
10043 (DMGL_PARAMS
| DMGL_ANSI
10044 | DMGL_RET_DROP
)));
10047 canon
= demangled
.get ();
10055 if (canon
== NULL
|| check_physname
)
10057 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10059 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10061 /* It may not mean a bug in GDB. The compiler could also
10062 compute DW_AT_linkage_name incorrectly. But in such case
10063 GDB would need to be bug-to-bug compatible. */
10065 complaint (_("Computed physname <%s> does not match demangled <%s> "
10066 "(from linkage <%s>) - DIE at %s [in module %s]"),
10067 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10068 objfile_name (objfile
));
10070 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10071 is available here - over computed PHYSNAME. It is safer
10072 against both buggy GDB and buggy compilers. */
10086 retval
= objfile
->intern (retval
);
10091 /* Inspect DIE in CU for a namespace alias. If one exists, record
10092 a new symbol for it.
10094 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10097 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10099 struct attribute
*attr
;
10101 /* If the die does not have a name, this is not a namespace
10103 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10107 struct die_info
*d
= die
;
10108 struct dwarf2_cu
*imported_cu
= cu
;
10110 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10111 keep inspecting DIEs until we hit the underlying import. */
10112 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10113 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10115 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10119 d
= follow_die_ref (d
, attr
, &imported_cu
);
10120 if (d
->tag
!= DW_TAG_imported_declaration
)
10124 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10126 complaint (_("DIE at %s has too many recursively imported "
10127 "declarations"), sect_offset_str (d
->sect_off
));
10134 sect_offset sect_off
= attr
->get_ref_die_offset ();
10136 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10137 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10139 /* This declaration is a global namespace alias. Add
10140 a symbol for it whose type is the aliased namespace. */
10141 new_symbol (die
, type
, cu
);
10150 /* Return the using directives repository (global or local?) to use in the
10151 current context for CU.
10153 For Ada, imported declarations can materialize renamings, which *may* be
10154 global. However it is impossible (for now?) in DWARF to distinguish
10155 "external" imported declarations and "static" ones. As all imported
10156 declarations seem to be static in all other languages, make them all CU-wide
10157 global only in Ada. */
10159 static struct using_direct
**
10160 using_directives (struct dwarf2_cu
*cu
)
10162 if (cu
->language
== language_ada
10163 && cu
->get_builder ()->outermost_context_p ())
10164 return cu
->get_builder ()->get_global_using_directives ();
10166 return cu
->get_builder ()->get_local_using_directives ();
10169 /* Read the import statement specified by the given die and record it. */
10172 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10174 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10175 struct attribute
*import_attr
;
10176 struct die_info
*imported_die
, *child_die
;
10177 struct dwarf2_cu
*imported_cu
;
10178 const char *imported_name
;
10179 const char *imported_name_prefix
;
10180 const char *canonical_name
;
10181 const char *import_alias
;
10182 const char *imported_declaration
= NULL
;
10183 const char *import_prefix
;
10184 std::vector
<const char *> excludes
;
10186 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10187 if (import_attr
== NULL
)
10189 complaint (_("Tag '%s' has no DW_AT_import"),
10190 dwarf_tag_name (die
->tag
));
10195 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10196 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10197 if (imported_name
== NULL
)
10199 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10201 The import in the following code:
10215 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10216 <52> DW_AT_decl_file : 1
10217 <53> DW_AT_decl_line : 6
10218 <54> DW_AT_import : <0x75>
10219 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10220 <59> DW_AT_name : B
10221 <5b> DW_AT_decl_file : 1
10222 <5c> DW_AT_decl_line : 2
10223 <5d> DW_AT_type : <0x6e>
10225 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10226 <76> DW_AT_byte_size : 4
10227 <77> DW_AT_encoding : 5 (signed)
10229 imports the wrong die ( 0x75 instead of 0x58 ).
10230 This case will be ignored until the gcc bug is fixed. */
10234 /* Figure out the local name after import. */
10235 import_alias
= dwarf2_name (die
, cu
);
10237 /* Figure out where the statement is being imported to. */
10238 import_prefix
= determine_prefix (die
, cu
);
10240 /* Figure out what the scope of the imported die is and prepend it
10241 to the name of the imported die. */
10242 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10244 if (imported_die
->tag
!= DW_TAG_namespace
10245 && imported_die
->tag
!= DW_TAG_module
)
10247 imported_declaration
= imported_name
;
10248 canonical_name
= imported_name_prefix
;
10250 else if (strlen (imported_name_prefix
) > 0)
10251 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10252 imported_name_prefix
,
10253 (cu
->language
== language_d
? "." : "::"),
10254 imported_name
, (char *) NULL
);
10256 canonical_name
= imported_name
;
10258 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10259 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10260 child_die
= child_die
->sibling
)
10262 /* DWARF-4: A Fortran use statement with a “rename list” may be
10263 represented by an imported module entry with an import attribute
10264 referring to the module and owned entries corresponding to those
10265 entities that are renamed as part of being imported. */
10267 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10269 complaint (_("child DW_TAG_imported_declaration expected "
10270 "- DIE at %s [in module %s]"),
10271 sect_offset_str (child_die
->sect_off
),
10272 objfile_name (objfile
));
10276 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10277 if (import_attr
== NULL
)
10279 complaint (_("Tag '%s' has no DW_AT_import"),
10280 dwarf_tag_name (child_die
->tag
));
10285 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10287 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10288 if (imported_name
== NULL
)
10290 complaint (_("child DW_TAG_imported_declaration has unknown "
10291 "imported name - DIE at %s [in module %s]"),
10292 sect_offset_str (child_die
->sect_off
),
10293 objfile_name (objfile
));
10297 excludes
.push_back (imported_name
);
10299 process_die (child_die
, cu
);
10302 add_using_directive (using_directives (cu
),
10306 imported_declaration
,
10309 &objfile
->objfile_obstack
);
10312 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10313 types, but gives them a size of zero. Starting with version 14,
10314 ICC is compatible with GCC. */
10317 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10319 if (!cu
->checked_producer
)
10320 check_producer (cu
);
10322 return cu
->producer_is_icc_lt_14
;
10325 /* ICC generates a DW_AT_type for C void functions. This was observed on
10326 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10327 which says that void functions should not have a DW_AT_type. */
10330 producer_is_icc (struct dwarf2_cu
*cu
)
10332 if (!cu
->checked_producer
)
10333 check_producer (cu
);
10335 return cu
->producer_is_icc
;
10338 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10339 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10340 this, it was first present in GCC release 4.3.0. */
10343 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10345 if (!cu
->checked_producer
)
10346 check_producer (cu
);
10348 return cu
->producer_is_gcc_lt_4_3
;
10351 static file_and_directory
10352 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10354 file_and_directory res
;
10356 /* Find the filename. Do not use dwarf2_name here, since the filename
10357 is not a source language identifier. */
10358 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10359 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10361 if (res
.comp_dir
== NULL
10362 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10363 && IS_ABSOLUTE_PATH (res
.name
))
10365 res
.comp_dir_storage
= ldirname (res
.name
);
10366 if (!res
.comp_dir_storage
.empty ())
10367 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10369 if (res
.comp_dir
!= NULL
)
10371 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10372 directory, get rid of it. */
10373 const char *cp
= strchr (res
.comp_dir
, ':');
10375 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10376 res
.comp_dir
= cp
+ 1;
10379 if (res
.name
== NULL
)
10380 res
.name
= "<unknown>";
10385 /* Handle DW_AT_stmt_list for a compilation unit.
10386 DIE is the DW_TAG_compile_unit die for CU.
10387 COMP_DIR is the compilation directory. LOWPC is passed to
10388 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10391 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10392 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10394 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10395 struct attribute
*attr
;
10396 struct line_header line_header_local
;
10397 hashval_t line_header_local_hash
;
10399 int decode_mapping
;
10401 gdb_assert (! cu
->per_cu
->is_debug_types
);
10403 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10404 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10407 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10409 /* The line header hash table is only created if needed (it exists to
10410 prevent redundant reading of the line table for partial_units).
10411 If we're given a partial_unit, we'll need it. If we're given a
10412 compile_unit, then use the line header hash table if it's already
10413 created, but don't create one just yet. */
10415 if (per_objfile
->line_header_hash
== NULL
10416 && die
->tag
== DW_TAG_partial_unit
)
10418 per_objfile
->line_header_hash
10419 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10420 line_header_eq_voidp
,
10421 htab_delete_entry
<line_header
>,
10425 line_header_local
.sect_off
= line_offset
;
10426 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10427 line_header_local_hash
= line_header_hash (&line_header_local
);
10428 if (per_objfile
->line_header_hash
!= NULL
)
10430 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10431 &line_header_local
,
10432 line_header_local_hash
, NO_INSERT
);
10434 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10435 is not present in *SLOT (since if there is something in *SLOT then
10436 it will be for a partial_unit). */
10437 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10439 gdb_assert (*slot
!= NULL
);
10440 cu
->line_header
= (struct line_header
*) *slot
;
10445 /* dwarf_decode_line_header does not yet provide sufficient information.
10446 We always have to call also dwarf_decode_lines for it. */
10447 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10451 cu
->line_header
= lh
.release ();
10452 cu
->line_header_die_owner
= die
;
10454 if (per_objfile
->line_header_hash
== NULL
)
10458 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10459 &line_header_local
,
10460 line_header_local_hash
, INSERT
);
10461 gdb_assert (slot
!= NULL
);
10463 if (slot
!= NULL
&& *slot
== NULL
)
10465 /* This newly decoded line number information unit will be owned
10466 by line_header_hash hash table. */
10467 *slot
= cu
->line_header
;
10468 cu
->line_header_die_owner
= NULL
;
10472 /* We cannot free any current entry in (*slot) as that struct line_header
10473 may be already used by multiple CUs. Create only temporary decoded
10474 line_header for this CU - it may happen at most once for each line
10475 number information unit. And if we're not using line_header_hash
10476 then this is what we want as well. */
10477 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10479 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10480 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10485 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10488 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10490 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10491 struct objfile
*objfile
= per_objfile
->objfile
;
10492 struct gdbarch
*gdbarch
= objfile
->arch ();
10493 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10494 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10495 struct attribute
*attr
;
10496 struct die_info
*child_die
;
10497 CORE_ADDR baseaddr
;
10499 prepare_one_comp_unit (cu
, die
, cu
->language
);
10500 baseaddr
= objfile
->text_section_offset ();
10502 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10504 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10505 from finish_block. */
10506 if (lowpc
== ((CORE_ADDR
) -1))
10508 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10510 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10512 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10513 standardised yet. As a workaround for the language detection we fall
10514 back to the DW_AT_producer string. */
10515 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10516 cu
->language
= language_opencl
;
10518 /* Similar hack for Go. */
10519 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10520 set_cu_language (DW_LANG_Go
, cu
);
10522 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10524 gdb_assert (per_objfile
->sym_cu
== nullptr);
10525 scoped_restore restore_sym_cu
10526 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10528 /* Decode line number information if present. We do this before
10529 processing child DIEs, so that the line header table is available
10530 for DW_AT_decl_file. */
10531 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10533 /* Process all dies in compilation unit. */
10534 if (die
->child
!= NULL
)
10536 child_die
= die
->child
;
10537 while (child_die
&& child_die
->tag
)
10539 process_die (child_die
, cu
);
10540 child_die
= child_die
->sibling
;
10543 per_objfile
->sym_cu
= nullptr;
10545 /* Decode macro information, if present. Dwarf 2 macro information
10546 refers to information in the line number info statement program
10547 header, so we can only read it if we've read the header
10549 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10551 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10552 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10554 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10555 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10557 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10561 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10562 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10564 unsigned int macro_offset
= attr
->as_unsigned ();
10566 dwarf_decode_macros (cu
, macro_offset
, 0);
10572 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10574 struct type_unit_group
*tu_group
;
10576 struct attribute
*attr
;
10578 struct signatured_type
*sig_type
;
10580 gdb_assert (per_cu
->is_debug_types
);
10581 sig_type
= (struct signatured_type
*) per_cu
;
10583 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10585 /* If we're using .gdb_index (includes -readnow) then
10586 per_cu->type_unit_group may not have been set up yet. */
10587 if (sig_type
->type_unit_group
== NULL
)
10588 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10589 tu_group
= sig_type
->type_unit_group
;
10591 /* If we've already processed this stmt_list there's no real need to
10592 do it again, we could fake it and just recreate the part we need
10593 (file name,index -> symtab mapping). If data shows this optimization
10594 is useful we can do it then. */
10595 type_unit_group_unshareable
*tug_unshare
10596 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10597 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10599 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10602 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10604 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10605 lh
= dwarf_decode_line_header (line_offset
, this);
10610 start_symtab ("", NULL
, 0);
10613 gdb_assert (tug_unshare
->symtabs
== NULL
);
10614 gdb_assert (m_builder
== nullptr);
10615 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10616 m_builder
.reset (new struct buildsym_compunit
10617 (COMPUNIT_OBJFILE (cust
), "",
10618 COMPUNIT_DIRNAME (cust
),
10619 compunit_language (cust
),
10621 list_in_scope
= get_builder ()->get_file_symbols ();
10626 line_header
= lh
.release ();
10627 line_header_die_owner
= die
;
10631 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10633 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10634 still initializing it, and our caller (a few levels up)
10635 process_full_type_unit still needs to know if this is the first
10638 tug_unshare
->symtabs
10639 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10640 struct symtab
*, line_header
->file_names_size ());
10642 auto &file_names
= line_header
->file_names ();
10643 for (i
= 0; i
< file_names
.size (); ++i
)
10645 file_entry
&fe
= file_names
[i
];
10646 dwarf2_start_subfile (this, fe
.name
,
10647 fe
.include_dir (line_header
));
10648 buildsym_compunit
*b
= get_builder ();
10649 if (b
->get_current_subfile ()->symtab
== NULL
)
10651 /* NOTE: start_subfile will recognize when it's been
10652 passed a file it has already seen. So we can't
10653 assume there's a simple mapping from
10654 cu->line_header->file_names to subfiles, plus
10655 cu->line_header->file_names may contain dups. */
10656 b
->get_current_subfile ()->symtab
10657 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10660 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10661 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10666 gdb_assert (m_builder
== nullptr);
10667 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10668 m_builder
.reset (new struct buildsym_compunit
10669 (COMPUNIT_OBJFILE (cust
), "",
10670 COMPUNIT_DIRNAME (cust
),
10671 compunit_language (cust
),
10673 list_in_scope
= get_builder ()->get_file_symbols ();
10675 auto &file_names
= line_header
->file_names ();
10676 for (i
= 0; i
< file_names
.size (); ++i
)
10678 file_entry
&fe
= file_names
[i
];
10679 fe
.symtab
= tug_unshare
->symtabs
[i
];
10683 /* The main symtab is allocated last. Type units don't have DW_AT_name
10684 so they don't have a "real" (so to speak) symtab anyway.
10685 There is later code that will assign the main symtab to all symbols
10686 that don't have one. We need to handle the case of a symbol with a
10687 missing symtab (DW_AT_decl_file) anyway. */
10690 /* Process DW_TAG_type_unit.
10691 For TUs we want to skip the first top level sibling if it's not the
10692 actual type being defined by this TU. In this case the first top
10693 level sibling is there to provide context only. */
10696 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10698 struct die_info
*child_die
;
10700 prepare_one_comp_unit (cu
, die
, language_minimal
);
10702 /* Initialize (or reinitialize) the machinery for building symtabs.
10703 We do this before processing child DIEs, so that the line header table
10704 is available for DW_AT_decl_file. */
10705 cu
->setup_type_unit_groups (die
);
10707 if (die
->child
!= NULL
)
10709 child_die
= die
->child
;
10710 while (child_die
&& child_die
->tag
)
10712 process_die (child_die
, cu
);
10713 child_die
= child_die
->sibling
;
10720 http://gcc.gnu.org/wiki/DebugFission
10721 http://gcc.gnu.org/wiki/DebugFissionDWP
10723 To simplify handling of both DWO files ("object" files with the DWARF info)
10724 and DWP files (a file with the DWOs packaged up into one file), we treat
10725 DWP files as having a collection of virtual DWO files. */
10728 hash_dwo_file (const void *item
)
10730 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10733 hash
= htab_hash_string (dwo_file
->dwo_name
);
10734 if (dwo_file
->comp_dir
!= NULL
)
10735 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10740 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10742 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10743 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10745 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10747 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10748 return lhs
->comp_dir
== rhs
->comp_dir
;
10749 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10752 /* Allocate a hash table for DWO files. */
10755 allocate_dwo_file_hash_table ()
10757 return htab_up (htab_create_alloc (41,
10760 htab_delete_entry
<dwo_file
>,
10764 /* Lookup DWO file DWO_NAME. */
10767 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10768 const char *dwo_name
,
10769 const char *comp_dir
)
10771 struct dwo_file find_entry
;
10774 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10775 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10777 find_entry
.dwo_name
= dwo_name
;
10778 find_entry
.comp_dir
= comp_dir
;
10779 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10786 hash_dwo_unit (const void *item
)
10788 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10790 /* This drops the top 32 bits of the id, but is ok for a hash. */
10791 return dwo_unit
->signature
;
10795 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10797 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10798 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10800 /* The signature is assumed to be unique within the DWO file.
10801 So while object file CU dwo_id's always have the value zero,
10802 that's OK, assuming each object file DWO file has only one CU,
10803 and that's the rule for now. */
10804 return lhs
->signature
== rhs
->signature
;
10807 /* Allocate a hash table for DWO CUs,TUs.
10808 There is one of these tables for each of CUs,TUs for each DWO file. */
10811 allocate_dwo_unit_table ()
10813 /* Start out with a pretty small number.
10814 Generally DWO files contain only one CU and maybe some TUs. */
10815 return htab_up (htab_create_alloc (3,
10818 NULL
, xcalloc
, xfree
));
10821 /* die_reader_func for create_dwo_cu. */
10824 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10825 const gdb_byte
*info_ptr
,
10826 struct die_info
*comp_unit_die
,
10827 struct dwo_file
*dwo_file
,
10828 struct dwo_unit
*dwo_unit
)
10830 struct dwarf2_cu
*cu
= reader
->cu
;
10831 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10832 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10834 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10835 if (!signature
.has_value ())
10837 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10838 " its dwo_id [in module %s]"),
10839 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10843 dwo_unit
->dwo_file
= dwo_file
;
10844 dwo_unit
->signature
= *signature
;
10845 dwo_unit
->section
= section
;
10846 dwo_unit
->sect_off
= sect_off
;
10847 dwo_unit
->length
= cu
->per_cu
->length
;
10849 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10850 sect_offset_str (sect_off
),
10851 hex_string (dwo_unit
->signature
));
10854 /* Create the dwo_units for the CUs in a DWO_FILE.
10855 Note: This function processes DWO files only, not DWP files. */
10858 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10859 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10860 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10862 struct objfile
*objfile
= per_objfile
->objfile
;
10863 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10864 const gdb_byte
*info_ptr
, *end_ptr
;
10866 section
.read (objfile
);
10867 info_ptr
= section
.buffer
;
10869 if (info_ptr
== NULL
)
10872 dwarf_read_debug_printf ("Reading %s for %s:",
10873 section
.get_name (),
10874 section
.get_file_name ());
10876 end_ptr
= info_ptr
+ section
.size
;
10877 while (info_ptr
< end_ptr
)
10879 struct dwarf2_per_cu_data per_cu
;
10880 struct dwo_unit read_unit
{};
10881 struct dwo_unit
*dwo_unit
;
10883 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10885 per_cu
.per_bfd
= per_bfd
;
10886 per_cu
.is_debug_types
= 0;
10887 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10888 per_cu
.section
= §ion
;
10890 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
10891 if (!reader
.dummy_p
)
10892 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
10893 &dwo_file
, &read_unit
);
10894 info_ptr
+= per_cu
.length
;
10896 // If the unit could not be parsed, skip it.
10897 if (read_unit
.dwo_file
== NULL
)
10900 if (cus_htab
== NULL
)
10901 cus_htab
= allocate_dwo_unit_table ();
10903 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
10905 *dwo_unit
= read_unit
;
10906 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
10907 gdb_assert (slot
!= NULL
);
10910 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
10911 sect_offset dup_sect_off
= dup_cu
->sect_off
;
10913 complaint (_("debug cu entry at offset %s is duplicate to"
10914 " the entry at offset %s, signature %s"),
10915 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
10916 hex_string (dwo_unit
->signature
));
10918 *slot
= (void *)dwo_unit
;
10922 /* DWP file .debug_{cu,tu}_index section format:
10923 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10924 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
10926 DWP Versions 1 & 2 are older, pre-standard format versions. The first
10927 officially standard DWP format was published with DWARF v5 and is called
10928 Version 5. There are no versions 3 or 4.
10932 Both index sections have the same format, and serve to map a 64-bit
10933 signature to a set of section numbers. Each section begins with a header,
10934 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10935 indexes, and a pool of 32-bit section numbers. The index sections will be
10936 aligned at 8-byte boundaries in the file.
10938 The index section header consists of:
10940 V, 32 bit version number
10942 N, 32 bit number of compilation units or type units in the index
10943 M, 32 bit number of slots in the hash table
10945 Numbers are recorded using the byte order of the application binary.
10947 The hash table begins at offset 16 in the section, and consists of an array
10948 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
10949 order of the application binary). Unused slots in the hash table are 0.
10950 (We rely on the extreme unlikeliness of a signature being exactly 0.)
10952 The parallel table begins immediately after the hash table
10953 (at offset 16 + 8 * M from the beginning of the section), and consists of an
10954 array of 32-bit indexes (using the byte order of the application binary),
10955 corresponding 1-1 with slots in the hash table. Each entry in the parallel
10956 table contains a 32-bit index into the pool of section numbers. For unused
10957 hash table slots, the corresponding entry in the parallel table will be 0.
10959 The pool of section numbers begins immediately following the hash table
10960 (at offset 16 + 12 * M from the beginning of the section). The pool of
10961 section numbers consists of an array of 32-bit words (using the byte order
10962 of the application binary). Each item in the array is indexed starting
10963 from 0. The hash table entry provides the index of the first section
10964 number in the set. Additional section numbers in the set follow, and the
10965 set is terminated by a 0 entry (section number 0 is not used in ELF).
10967 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
10968 section must be the first entry in the set, and the .debug_abbrev.dwo must
10969 be the second entry. Other members of the set may follow in any order.
10973 DWP Versions 2 and 5:
10975 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
10976 and the entries in the index tables are now offsets into these sections.
10977 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
10980 Index Section Contents:
10982 Hash Table of Signatures dwp_hash_table.hash_table
10983 Parallel Table of Indices dwp_hash_table.unit_table
10984 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
10985 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
10987 The index section header consists of:
10989 V, 32 bit version number
10990 L, 32 bit number of columns in the table of section offsets
10991 N, 32 bit number of compilation units or type units in the index
10992 M, 32 bit number of slots in the hash table
10994 Numbers are recorded using the byte order of the application binary.
10996 The hash table has the same format as version 1.
10997 The parallel table of indices has the same format as version 1,
10998 except that the entries are origin-1 indices into the table of sections
10999 offsets and the table of section sizes.
11001 The table of offsets begins immediately following the parallel table
11002 (at offset 16 + 12 * M from the beginning of the section). The table is
11003 a two-dimensional array of 32-bit words (using the byte order of the
11004 application binary), with L columns and N+1 rows, in row-major order.
11005 Each row in the array is indexed starting from 0. The first row provides
11006 a key to the remaining rows: each column in this row provides an identifier
11007 for a debug section, and the offsets in the same column of subsequent rows
11008 refer to that section. The section identifiers for Version 2 are:
11010 DW_SECT_INFO 1 .debug_info.dwo
11011 DW_SECT_TYPES 2 .debug_types.dwo
11012 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11013 DW_SECT_LINE 4 .debug_line.dwo
11014 DW_SECT_LOC 5 .debug_loc.dwo
11015 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11016 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11017 DW_SECT_MACRO 8 .debug_macro.dwo
11019 The section identifiers for Version 5 are:
11021 DW_SECT_INFO_V5 1 .debug_info.dwo
11022 DW_SECT_RESERVED_V5 2 --
11023 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11024 DW_SECT_LINE_V5 4 .debug_line.dwo
11025 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11026 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11027 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11028 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11030 The offsets provided by the CU and TU index sections are the base offsets
11031 for the contributions made by each CU or TU to the corresponding section
11032 in the package file. Each CU and TU header contains an abbrev_offset
11033 field, used to find the abbreviations table for that CU or TU within the
11034 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11035 be interpreted as relative to the base offset given in the index section.
11036 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11037 should be interpreted as relative to the base offset for .debug_line.dwo,
11038 and offsets into other debug sections obtained from DWARF attributes should
11039 also be interpreted as relative to the corresponding base offset.
11041 The table of sizes begins immediately following the table of offsets.
11042 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11043 with L columns and N rows, in row-major order. Each row in the array is
11044 indexed starting from 1 (row 0 is shared by the two tables).
11048 Hash table lookup is handled the same in version 1 and 2:
11050 We assume that N and M will not exceed 2^32 - 1.
11051 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11053 Given a 64-bit compilation unit signature or a type signature S, an entry
11054 in the hash table is located as follows:
11056 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11057 the low-order k bits all set to 1.
11059 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11061 3) If the hash table entry at index H matches the signature, use that
11062 entry. If the hash table entry at index H is unused (all zeroes),
11063 terminate the search: the signature is not present in the table.
11065 4) Let H = (H + H') modulo M. Repeat at Step 3.
11067 Because M > N and H' and M are relatively prime, the search is guaranteed
11068 to stop at an unused slot or find the match. */
11070 /* Create a hash table to map DWO IDs to their CU/TU entry in
11071 .debug_{info,types}.dwo in DWP_FILE.
11072 Returns NULL if there isn't one.
11073 Note: This function processes DWP files only, not DWO files. */
11075 static struct dwp_hash_table
*
11076 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11077 struct dwp_file
*dwp_file
, int is_debug_types
)
11079 struct objfile
*objfile
= per_objfile
->objfile
;
11080 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11081 const gdb_byte
*index_ptr
, *index_end
;
11082 struct dwarf2_section_info
*index
;
11083 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11084 struct dwp_hash_table
*htab
;
11086 if (is_debug_types
)
11087 index
= &dwp_file
->sections
.tu_index
;
11089 index
= &dwp_file
->sections
.cu_index
;
11091 if (index
->empty ())
11093 index
->read (objfile
);
11095 index_ptr
= index
->buffer
;
11096 index_end
= index_ptr
+ index
->size
;
11098 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11099 For now it's safe to just read 4 bytes (particularly as it's difficult to
11100 tell if you're dealing with Version 5 before you've read the version). */
11101 version
= read_4_bytes (dbfd
, index_ptr
);
11103 if (version
== 2 || version
== 5)
11104 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11108 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11110 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11113 if (version
!= 1 && version
!= 2 && version
!= 5)
11115 error (_("Dwarf Error: unsupported DWP file version (%s)"
11116 " [in module %s]"),
11117 pulongest (version
), dwp_file
->name
);
11119 if (nr_slots
!= (nr_slots
& -nr_slots
))
11121 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11122 " is not power of 2 [in module %s]"),
11123 pulongest (nr_slots
), dwp_file
->name
);
11126 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11127 htab
->version
= version
;
11128 htab
->nr_columns
= nr_columns
;
11129 htab
->nr_units
= nr_units
;
11130 htab
->nr_slots
= nr_slots
;
11131 htab
->hash_table
= index_ptr
;
11132 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11134 /* Exit early if the table is empty. */
11135 if (nr_slots
== 0 || nr_units
== 0
11136 || (version
== 2 && nr_columns
== 0)
11137 || (version
== 5 && nr_columns
== 0))
11139 /* All must be zero. */
11140 if (nr_slots
!= 0 || nr_units
!= 0
11141 || (version
== 2 && nr_columns
!= 0)
11142 || (version
== 5 && nr_columns
!= 0))
11144 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11145 " all zero [in modules %s]"),
11153 htab
->section_pool
.v1
.indices
=
11154 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11155 /* It's harder to decide whether the section is too small in v1.
11156 V1 is deprecated anyway so we punt. */
11158 else if (version
== 2)
11160 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11161 int *ids
= htab
->section_pool
.v2
.section_ids
;
11162 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11163 /* Reverse map for error checking. */
11164 int ids_seen
[DW_SECT_MAX
+ 1];
11167 if (nr_columns
< 2)
11169 error (_("Dwarf Error: bad DWP hash table, too few columns"
11170 " in section table [in module %s]"),
11173 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11175 error (_("Dwarf Error: bad DWP hash table, too many columns"
11176 " in section table [in module %s]"),
11179 memset (ids
, 255, sizeof_ids
);
11180 memset (ids_seen
, 255, sizeof (ids_seen
));
11181 for (i
= 0; i
< nr_columns
; ++i
)
11183 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11185 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11187 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11188 " in section table [in module %s]"),
11189 id
, dwp_file
->name
);
11191 if (ids_seen
[id
] != -1)
11193 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11194 " id %d in section table [in module %s]"),
11195 id
, dwp_file
->name
);
11200 /* Must have exactly one info or types section. */
11201 if (((ids_seen
[DW_SECT_INFO
] != -1)
11202 + (ids_seen
[DW_SECT_TYPES
] != -1))
11205 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11206 " DWO info/types section [in module %s]"),
11209 /* Must have an abbrev section. */
11210 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11212 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11213 " section [in module %s]"),
11216 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11217 htab
->section_pool
.v2
.sizes
=
11218 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11219 * nr_units
* nr_columns
);
11220 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11221 * nr_units
* nr_columns
))
11224 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11225 " [in module %s]"),
11229 else /* version == 5 */
11231 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11232 int *ids
= htab
->section_pool
.v5
.section_ids
;
11233 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11234 /* Reverse map for error checking. */
11235 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11237 if (nr_columns
< 2)
11239 error (_("Dwarf Error: bad DWP hash table, too few columns"
11240 " in section table [in module %s]"),
11243 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11245 error (_("Dwarf Error: bad DWP hash table, too many columns"
11246 " in section table [in module %s]"),
11249 memset (ids
, 255, sizeof_ids
);
11250 memset (ids_seen
, 255, sizeof (ids_seen
));
11251 for (int i
= 0; i
< nr_columns
; ++i
)
11253 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11255 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11257 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11258 " in section table [in module %s]"),
11259 id
, dwp_file
->name
);
11261 if (ids_seen
[id
] != -1)
11263 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11264 " id %d in section table [in module %s]"),
11265 id
, dwp_file
->name
);
11270 /* Must have seen an info section. */
11271 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11273 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11274 " DWO info/types section [in module %s]"),
11277 /* Must have an abbrev section. */
11278 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11280 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11281 " section [in module %s]"),
11284 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11285 htab
->section_pool
.v5
.sizes
11286 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11287 * nr_units
* nr_columns
);
11288 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11289 * nr_units
* nr_columns
))
11292 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11293 " [in module %s]"),
11301 /* Update SECTIONS with the data from SECTP.
11303 This function is like the other "locate" section routines, but in
11304 this context the sections to read comes from the DWP V1 hash table,
11305 not the full ELF section table.
11307 The result is non-zero for success, or zero if an error was found. */
11310 locate_v1_virtual_dwo_sections (asection
*sectp
,
11311 struct virtual_v1_dwo_sections
*sections
)
11313 const struct dwop_section_names
*names
= &dwop_section_names
;
11315 if (names
->abbrev_dwo
.matches (sectp
->name
))
11317 /* There can be only one. */
11318 if (sections
->abbrev
.s
.section
!= NULL
)
11320 sections
->abbrev
.s
.section
= sectp
;
11321 sections
->abbrev
.size
= bfd_section_size (sectp
);
11323 else if (names
->info_dwo
.matches (sectp
->name
)
11324 || names
->types_dwo
.matches (sectp
->name
))
11326 /* There can be only one. */
11327 if (sections
->info_or_types
.s
.section
!= NULL
)
11329 sections
->info_or_types
.s
.section
= sectp
;
11330 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11332 else if (names
->line_dwo
.matches (sectp
->name
))
11334 /* There can be only one. */
11335 if (sections
->line
.s
.section
!= NULL
)
11337 sections
->line
.s
.section
= sectp
;
11338 sections
->line
.size
= bfd_section_size (sectp
);
11340 else if (names
->loc_dwo
.matches (sectp
->name
))
11342 /* There can be only one. */
11343 if (sections
->loc
.s
.section
!= NULL
)
11345 sections
->loc
.s
.section
= sectp
;
11346 sections
->loc
.size
= bfd_section_size (sectp
);
11348 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11350 /* There can be only one. */
11351 if (sections
->macinfo
.s
.section
!= NULL
)
11353 sections
->macinfo
.s
.section
= sectp
;
11354 sections
->macinfo
.size
= bfd_section_size (sectp
);
11356 else if (names
->macro_dwo
.matches (sectp
->name
))
11358 /* There can be only one. */
11359 if (sections
->macro
.s
.section
!= NULL
)
11361 sections
->macro
.s
.section
= sectp
;
11362 sections
->macro
.size
= bfd_section_size (sectp
);
11364 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11366 /* There can be only one. */
11367 if (sections
->str_offsets
.s
.section
!= NULL
)
11369 sections
->str_offsets
.s
.section
= sectp
;
11370 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11374 /* No other kind of section is valid. */
11381 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11382 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11383 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11384 This is for DWP version 1 files. */
11386 static struct dwo_unit
*
11387 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11388 struct dwp_file
*dwp_file
,
11389 uint32_t unit_index
,
11390 const char *comp_dir
,
11391 ULONGEST signature
, int is_debug_types
)
11393 const struct dwp_hash_table
*dwp_htab
=
11394 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11395 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11396 const char *kind
= is_debug_types
? "TU" : "CU";
11397 struct dwo_file
*dwo_file
;
11398 struct dwo_unit
*dwo_unit
;
11399 struct virtual_v1_dwo_sections sections
;
11400 void **dwo_file_slot
;
11403 gdb_assert (dwp_file
->version
== 1);
11405 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11406 kind
, pulongest (unit_index
), hex_string (signature
),
11409 /* Fetch the sections of this DWO unit.
11410 Put a limit on the number of sections we look for so that bad data
11411 doesn't cause us to loop forever. */
11413 #define MAX_NR_V1_DWO_SECTIONS \
11414 (1 /* .debug_info or .debug_types */ \
11415 + 1 /* .debug_abbrev */ \
11416 + 1 /* .debug_line */ \
11417 + 1 /* .debug_loc */ \
11418 + 1 /* .debug_str_offsets */ \
11419 + 1 /* .debug_macro or .debug_macinfo */ \
11420 + 1 /* trailing zero */)
11422 memset (§ions
, 0, sizeof (sections
));
11424 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11427 uint32_t section_nr
=
11428 read_4_bytes (dbfd
,
11429 dwp_htab
->section_pool
.v1
.indices
11430 + (unit_index
+ i
) * sizeof (uint32_t));
11432 if (section_nr
== 0)
11434 if (section_nr
>= dwp_file
->num_sections
)
11436 error (_("Dwarf Error: bad DWP hash table, section number too large"
11437 " [in module %s]"),
11441 sectp
= dwp_file
->elf_sections
[section_nr
];
11442 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11444 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11445 " [in module %s]"),
11451 || sections
.info_or_types
.empty ()
11452 || sections
.abbrev
.empty ())
11454 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11455 " [in module %s]"),
11458 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11460 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11461 " [in module %s]"),
11465 /* It's easier for the rest of the code if we fake a struct dwo_file and
11466 have dwo_unit "live" in that. At least for now.
11468 The DWP file can be made up of a random collection of CUs and TUs.
11469 However, for each CU + set of TUs that came from the same original DWO
11470 file, we can combine them back into a virtual DWO file to save space
11471 (fewer struct dwo_file objects to allocate). Remember that for really
11472 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11474 std::string virtual_dwo_name
=
11475 string_printf ("virtual-dwo/%d-%d-%d-%d",
11476 sections
.abbrev
.get_id (),
11477 sections
.line
.get_id (),
11478 sections
.loc
.get_id (),
11479 sections
.str_offsets
.get_id ());
11480 /* Can we use an existing virtual DWO file? */
11481 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11483 /* Create one if necessary. */
11484 if (*dwo_file_slot
== NULL
)
11486 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11487 virtual_dwo_name
.c_str ());
11489 dwo_file
= new struct dwo_file
;
11490 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11491 dwo_file
->comp_dir
= comp_dir
;
11492 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11493 dwo_file
->sections
.line
= sections
.line
;
11494 dwo_file
->sections
.loc
= sections
.loc
;
11495 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11496 dwo_file
->sections
.macro
= sections
.macro
;
11497 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11498 /* The "str" section is global to the entire DWP file. */
11499 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11500 /* The info or types section is assigned below to dwo_unit,
11501 there's no need to record it in dwo_file.
11502 Also, we can't simply record type sections in dwo_file because
11503 we record a pointer into the vector in dwo_unit. As we collect more
11504 types we'll grow the vector and eventually have to reallocate space
11505 for it, invalidating all copies of pointers into the previous
11507 *dwo_file_slot
= dwo_file
;
11511 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11512 virtual_dwo_name
.c_str ());
11514 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11517 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11518 dwo_unit
->dwo_file
= dwo_file
;
11519 dwo_unit
->signature
= signature
;
11520 dwo_unit
->section
=
11521 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11522 *dwo_unit
->section
= sections
.info_or_types
;
11523 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11528 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11529 simplify them. Given a pointer to the containing section SECTION, and
11530 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11531 virtual section of just that piece. */
11533 static struct dwarf2_section_info
11534 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11535 struct dwarf2_section_info
*section
,
11536 bfd_size_type offset
, bfd_size_type size
)
11538 struct dwarf2_section_info result
;
11541 gdb_assert (section
!= NULL
);
11542 gdb_assert (!section
->is_virtual
);
11544 memset (&result
, 0, sizeof (result
));
11545 result
.s
.containing_section
= section
;
11546 result
.is_virtual
= true;
11551 sectp
= section
->get_bfd_section ();
11553 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11554 bounds of the real section. This is a pretty-rare event, so just
11555 flag an error (easier) instead of a warning and trying to cope. */
11557 || offset
+ size
> bfd_section_size (sectp
))
11559 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11560 " in section %s [in module %s]"),
11561 sectp
? bfd_section_name (sectp
) : "<unknown>",
11562 objfile_name (per_objfile
->objfile
));
11565 result
.virtual_offset
= offset
;
11566 result
.size
= size
;
11570 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11571 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11572 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11573 This is for DWP version 2 files. */
11575 static struct dwo_unit
*
11576 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11577 struct dwp_file
*dwp_file
,
11578 uint32_t unit_index
,
11579 const char *comp_dir
,
11580 ULONGEST signature
, int is_debug_types
)
11582 const struct dwp_hash_table
*dwp_htab
=
11583 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11584 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11585 const char *kind
= is_debug_types
? "TU" : "CU";
11586 struct dwo_file
*dwo_file
;
11587 struct dwo_unit
*dwo_unit
;
11588 struct virtual_v2_or_v5_dwo_sections sections
;
11589 void **dwo_file_slot
;
11592 gdb_assert (dwp_file
->version
== 2);
11594 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11595 kind
, pulongest (unit_index
), hex_string (signature
),
11598 /* Fetch the section offsets of this DWO unit. */
11600 memset (§ions
, 0, sizeof (sections
));
11602 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11604 uint32_t offset
= read_4_bytes (dbfd
,
11605 dwp_htab
->section_pool
.v2
.offsets
11606 + (((unit_index
- 1) * dwp_htab
->nr_columns
11608 * sizeof (uint32_t)));
11609 uint32_t size
= read_4_bytes (dbfd
,
11610 dwp_htab
->section_pool
.v2
.sizes
11611 + (((unit_index
- 1) * dwp_htab
->nr_columns
11613 * sizeof (uint32_t)));
11615 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11618 case DW_SECT_TYPES
:
11619 sections
.info_or_types_offset
= offset
;
11620 sections
.info_or_types_size
= size
;
11622 case DW_SECT_ABBREV
:
11623 sections
.abbrev_offset
= offset
;
11624 sections
.abbrev_size
= size
;
11627 sections
.line_offset
= offset
;
11628 sections
.line_size
= size
;
11631 sections
.loc_offset
= offset
;
11632 sections
.loc_size
= size
;
11634 case DW_SECT_STR_OFFSETS
:
11635 sections
.str_offsets_offset
= offset
;
11636 sections
.str_offsets_size
= size
;
11638 case DW_SECT_MACINFO
:
11639 sections
.macinfo_offset
= offset
;
11640 sections
.macinfo_size
= size
;
11642 case DW_SECT_MACRO
:
11643 sections
.macro_offset
= offset
;
11644 sections
.macro_size
= size
;
11649 /* It's easier for the rest of the code if we fake a struct dwo_file and
11650 have dwo_unit "live" in that. At least for now.
11652 The DWP file can be made up of a random collection of CUs and TUs.
11653 However, for each CU + set of TUs that came from the same original DWO
11654 file, we can combine them back into a virtual DWO file to save space
11655 (fewer struct dwo_file objects to allocate). Remember that for really
11656 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11658 std::string virtual_dwo_name
=
11659 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11660 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11661 (long) (sections
.line_size
? sections
.line_offset
: 0),
11662 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11663 (long) (sections
.str_offsets_size
11664 ? sections
.str_offsets_offset
: 0));
11665 /* Can we use an existing virtual DWO file? */
11666 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11668 /* Create one if necessary. */
11669 if (*dwo_file_slot
== NULL
)
11671 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11672 virtual_dwo_name
.c_str ());
11674 dwo_file
= new struct dwo_file
;
11675 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11676 dwo_file
->comp_dir
= comp_dir
;
11677 dwo_file
->sections
.abbrev
=
11678 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11679 sections
.abbrev_offset
,
11680 sections
.abbrev_size
);
11681 dwo_file
->sections
.line
=
11682 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11683 sections
.line_offset
,
11684 sections
.line_size
);
11685 dwo_file
->sections
.loc
=
11686 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11687 sections
.loc_offset
, sections
.loc_size
);
11688 dwo_file
->sections
.macinfo
=
11689 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11690 sections
.macinfo_offset
,
11691 sections
.macinfo_size
);
11692 dwo_file
->sections
.macro
=
11693 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11694 sections
.macro_offset
,
11695 sections
.macro_size
);
11696 dwo_file
->sections
.str_offsets
=
11697 create_dwp_v2_or_v5_section (per_objfile
,
11698 &dwp_file
->sections
.str_offsets
,
11699 sections
.str_offsets_offset
,
11700 sections
.str_offsets_size
);
11701 /* The "str" section is global to the entire DWP file. */
11702 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11703 /* The info or types section is assigned below to dwo_unit,
11704 there's no need to record it in dwo_file.
11705 Also, we can't simply record type sections in dwo_file because
11706 we record a pointer into the vector in dwo_unit. As we collect more
11707 types we'll grow the vector and eventually have to reallocate space
11708 for it, invalidating all copies of pointers into the previous
11710 *dwo_file_slot
= dwo_file
;
11714 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11715 virtual_dwo_name
.c_str ());
11717 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11720 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11721 dwo_unit
->dwo_file
= dwo_file
;
11722 dwo_unit
->signature
= signature
;
11723 dwo_unit
->section
=
11724 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11725 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11728 ? &dwp_file
->sections
.types
11729 : &dwp_file
->sections
.info
,
11730 sections
.info_or_types_offset
,
11731 sections
.info_or_types_size
);
11732 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11737 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11738 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11739 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11740 This is for DWP version 5 files. */
11742 static struct dwo_unit
*
11743 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11744 struct dwp_file
*dwp_file
,
11745 uint32_t unit_index
,
11746 const char *comp_dir
,
11747 ULONGEST signature
, int is_debug_types
)
11749 const struct dwp_hash_table
*dwp_htab
11750 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11751 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11752 const char *kind
= is_debug_types
? "TU" : "CU";
11753 struct dwo_file
*dwo_file
;
11754 struct dwo_unit
*dwo_unit
;
11755 struct virtual_v2_or_v5_dwo_sections sections
{};
11756 void **dwo_file_slot
;
11758 gdb_assert (dwp_file
->version
== 5);
11760 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11761 kind
, pulongest (unit_index
), hex_string (signature
),
11764 /* Fetch the section offsets of this DWO unit. */
11766 /* memset (§ions, 0, sizeof (sections)); */
11768 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11770 uint32_t offset
= read_4_bytes (dbfd
,
11771 dwp_htab
->section_pool
.v5
.offsets
11772 + (((unit_index
- 1)
11773 * dwp_htab
->nr_columns
11775 * sizeof (uint32_t)));
11776 uint32_t size
= read_4_bytes (dbfd
,
11777 dwp_htab
->section_pool
.v5
.sizes
11778 + (((unit_index
- 1) * dwp_htab
->nr_columns
11780 * sizeof (uint32_t)));
11782 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11784 case DW_SECT_ABBREV_V5
:
11785 sections
.abbrev_offset
= offset
;
11786 sections
.abbrev_size
= size
;
11788 case DW_SECT_INFO_V5
:
11789 sections
.info_or_types_offset
= offset
;
11790 sections
.info_or_types_size
= size
;
11792 case DW_SECT_LINE_V5
:
11793 sections
.line_offset
= offset
;
11794 sections
.line_size
= size
;
11796 case DW_SECT_LOCLISTS_V5
:
11797 sections
.loclists_offset
= offset
;
11798 sections
.loclists_size
= size
;
11800 case DW_SECT_MACRO_V5
:
11801 sections
.macro_offset
= offset
;
11802 sections
.macro_size
= size
;
11804 case DW_SECT_RNGLISTS_V5
:
11805 sections
.rnglists_offset
= offset
;
11806 sections
.rnglists_size
= size
;
11808 case DW_SECT_STR_OFFSETS_V5
:
11809 sections
.str_offsets_offset
= offset
;
11810 sections
.str_offsets_size
= size
;
11812 case DW_SECT_RESERVED_V5
:
11818 /* It's easier for the rest of the code if we fake a struct dwo_file and
11819 have dwo_unit "live" in that. At least for now.
11821 The DWP file can be made up of a random collection of CUs and TUs.
11822 However, for each CU + set of TUs that came from the same original DWO
11823 file, we can combine them back into a virtual DWO file to save space
11824 (fewer struct dwo_file objects to allocate). Remember that for really
11825 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11827 std::string virtual_dwo_name
=
11828 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11829 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11830 (long) (sections
.line_size
? sections
.line_offset
: 0),
11831 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11832 (long) (sections
.str_offsets_size
11833 ? sections
.str_offsets_offset
: 0),
11834 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11835 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11836 /* Can we use an existing virtual DWO file? */
11837 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11838 virtual_dwo_name
.c_str (),
11840 /* Create one if necessary. */
11841 if (*dwo_file_slot
== NULL
)
11843 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11844 virtual_dwo_name
.c_str ());
11846 dwo_file
= new struct dwo_file
;
11847 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11848 dwo_file
->comp_dir
= comp_dir
;
11849 dwo_file
->sections
.abbrev
=
11850 create_dwp_v2_or_v5_section (per_objfile
,
11851 &dwp_file
->sections
.abbrev
,
11852 sections
.abbrev_offset
,
11853 sections
.abbrev_size
);
11854 dwo_file
->sections
.line
=
11855 create_dwp_v2_or_v5_section (per_objfile
,
11856 &dwp_file
->sections
.line
,
11857 sections
.line_offset
, sections
.line_size
);
11858 dwo_file
->sections
.macro
=
11859 create_dwp_v2_or_v5_section (per_objfile
,
11860 &dwp_file
->sections
.macro
,
11861 sections
.macro_offset
,
11862 sections
.macro_size
);
11863 dwo_file
->sections
.loclists
=
11864 create_dwp_v2_or_v5_section (per_objfile
,
11865 &dwp_file
->sections
.loclists
,
11866 sections
.loclists_offset
,
11867 sections
.loclists_size
);
11868 dwo_file
->sections
.rnglists
=
11869 create_dwp_v2_or_v5_section (per_objfile
,
11870 &dwp_file
->sections
.rnglists
,
11871 sections
.rnglists_offset
,
11872 sections
.rnglists_size
);
11873 dwo_file
->sections
.str_offsets
=
11874 create_dwp_v2_or_v5_section (per_objfile
,
11875 &dwp_file
->sections
.str_offsets
,
11876 sections
.str_offsets_offset
,
11877 sections
.str_offsets_size
);
11878 /* The "str" section is global to the entire DWP file. */
11879 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11880 /* The info or types section is assigned below to dwo_unit,
11881 there's no need to record it in dwo_file.
11882 Also, we can't simply record type sections in dwo_file because
11883 we record a pointer into the vector in dwo_unit. As we collect more
11884 types we'll grow the vector and eventually have to reallocate space
11885 for it, invalidating all copies of pointers into the previous
11887 *dwo_file_slot
= dwo_file
;
11891 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11892 virtual_dwo_name
.c_str ());
11894 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11897 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11898 dwo_unit
->dwo_file
= dwo_file
;
11899 dwo_unit
->signature
= signature
;
11901 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11902 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
11903 &dwp_file
->sections
.info
,
11904 sections
.info_or_types_offset
,
11905 sections
.info_or_types_size
);
11906 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11911 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11912 Returns NULL if the signature isn't found. */
11914 static struct dwo_unit
*
11915 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
11916 struct dwp_file
*dwp_file
, const char *comp_dir
,
11917 ULONGEST signature
, int is_debug_types
)
11919 const struct dwp_hash_table
*dwp_htab
=
11920 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11921 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11922 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11923 uint32_t hash
= signature
& mask
;
11924 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11927 struct dwo_unit find_dwo_cu
;
11929 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11930 find_dwo_cu
.signature
= signature
;
11931 slot
= htab_find_slot (is_debug_types
11932 ? dwp_file
->loaded_tus
.get ()
11933 : dwp_file
->loaded_cus
.get (),
11934 &find_dwo_cu
, INSERT
);
11937 return (struct dwo_unit
*) *slot
;
11939 /* Use a for loop so that we don't loop forever on bad debug info. */
11940 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11942 ULONGEST signature_in_table
;
11944 signature_in_table
=
11945 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11946 if (signature_in_table
== signature
)
11948 uint32_t unit_index
=
11949 read_4_bytes (dbfd
,
11950 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11952 if (dwp_file
->version
== 1)
11954 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
11955 unit_index
, comp_dir
,
11956 signature
, is_debug_types
);
11958 else if (dwp_file
->version
== 2)
11960 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
11961 unit_index
, comp_dir
,
11962 signature
, is_debug_types
);
11964 else /* version == 5 */
11966 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
11967 unit_index
, comp_dir
,
11968 signature
, is_debug_types
);
11970 return (struct dwo_unit
*) *slot
;
11972 if (signature_in_table
== 0)
11974 hash
= (hash
+ hash2
) & mask
;
11977 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11978 " [in module %s]"),
11982 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11983 Open the file specified by FILE_NAME and hand it off to BFD for
11984 preliminary analysis. Return a newly initialized bfd *, which
11985 includes a canonicalized copy of FILE_NAME.
11986 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11987 SEARCH_CWD is true if the current directory is to be searched.
11988 It will be searched before debug-file-directory.
11989 If successful, the file is added to the bfd include table of the
11990 objfile's bfd (see gdb_bfd_record_inclusion).
11991 If unable to find/open the file, return NULL.
11992 NOTE: This function is derived from symfile_bfd_open. */
11994 static gdb_bfd_ref_ptr
11995 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
11996 const char *file_name
, int is_dwp
, int search_cwd
)
11999 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12000 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12001 to debug_file_directory. */
12002 const char *search_path
;
12003 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12005 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12008 if (*debug_file_directory
!= '\0')
12010 search_path_holder
.reset (concat (".", dirname_separator_string
,
12011 debug_file_directory
,
12013 search_path
= search_path_holder
.get ();
12019 search_path
= debug_file_directory
;
12021 /* Add the path for the executable binary to the list of search paths. */
12022 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12023 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12024 dirname_separator_string
,
12025 search_path
, nullptr));
12026 search_path
= search_path_holder
.get ();
12028 openp_flags flags
= OPF_RETURN_REALPATH
;
12030 flags
|= OPF_SEARCH_IN_PATH
;
12032 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12033 desc
= openp (search_path
, flags
, file_name
,
12034 O_RDONLY
| O_BINARY
, &absolute_name
);
12038 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12040 if (sym_bfd
== NULL
)
12042 bfd_set_cacheable (sym_bfd
.get (), 1);
12044 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12047 /* Success. Record the bfd as having been included by the objfile's bfd.
12048 This is important because things like demangled_names_hash lives in the
12049 objfile's per_bfd space and may have references to things like symbol
12050 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12051 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12056 /* Try to open DWO file FILE_NAME.
12057 COMP_DIR is the DW_AT_comp_dir attribute.
12058 The result is the bfd handle of the file.
12059 If there is a problem finding or opening the file, return NULL.
12060 Upon success, the canonicalized path of the file is stored in the bfd,
12061 same as symfile_bfd_open. */
12063 static gdb_bfd_ref_ptr
12064 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12065 const char *file_name
, const char *comp_dir
)
12067 if (IS_ABSOLUTE_PATH (file_name
))
12068 return try_open_dwop_file (per_objfile
, file_name
,
12069 0 /*is_dwp*/, 0 /*search_cwd*/);
12071 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12073 if (comp_dir
!= NULL
)
12075 gdb::unique_xmalloc_ptr
<char> path_to_try
12076 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12078 /* NOTE: If comp_dir is a relative path, this will also try the
12079 search path, which seems useful. */
12080 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12082 1 /*search_cwd*/));
12087 /* That didn't work, try debug-file-directory, which, despite its name,
12088 is a list of paths. */
12090 if (*debug_file_directory
== '\0')
12093 return try_open_dwop_file (per_objfile
, file_name
,
12094 0 /*is_dwp*/, 1 /*search_cwd*/);
12097 /* This function is mapped across the sections and remembers the offset and
12098 size of each of the DWO debugging sections we are interested in. */
12101 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12102 dwo_sections
*dwo_sections
)
12104 const struct dwop_section_names
*names
= &dwop_section_names
;
12106 if (names
->abbrev_dwo
.matches (sectp
->name
))
12108 dwo_sections
->abbrev
.s
.section
= sectp
;
12109 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12111 else if (names
->info_dwo
.matches (sectp
->name
))
12113 dwo_sections
->info
.s
.section
= sectp
;
12114 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12116 else if (names
->line_dwo
.matches (sectp
->name
))
12118 dwo_sections
->line
.s
.section
= sectp
;
12119 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12121 else if (names
->loc_dwo
.matches (sectp
->name
))
12123 dwo_sections
->loc
.s
.section
= sectp
;
12124 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12126 else if (names
->loclists_dwo
.matches (sectp
->name
))
12128 dwo_sections
->loclists
.s
.section
= sectp
;
12129 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12131 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12133 dwo_sections
->macinfo
.s
.section
= sectp
;
12134 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12136 else if (names
->macro_dwo
.matches (sectp
->name
))
12138 dwo_sections
->macro
.s
.section
= sectp
;
12139 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12141 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12143 dwo_sections
->rnglists
.s
.section
= sectp
;
12144 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12146 else if (names
->str_dwo
.matches (sectp
->name
))
12148 dwo_sections
->str
.s
.section
= sectp
;
12149 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12151 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12153 dwo_sections
->str_offsets
.s
.section
= sectp
;
12154 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12156 else if (names
->types_dwo
.matches (sectp
->name
))
12158 struct dwarf2_section_info type_section
;
12160 memset (&type_section
, 0, sizeof (type_section
));
12161 type_section
.s
.section
= sectp
;
12162 type_section
.size
= bfd_section_size (sectp
);
12163 dwo_sections
->types
.push_back (type_section
);
12167 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12168 by PER_CU. This is for the non-DWP case.
12169 The result is NULL if DWO_NAME can't be found. */
12171 static struct dwo_file
*
12172 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12173 const char *comp_dir
)
12175 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12177 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12180 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12185 dwo_file_up
dwo_file (new struct dwo_file
);
12186 dwo_file
->dwo_name
= dwo_name
;
12187 dwo_file
->comp_dir
= comp_dir
;
12188 dwo_file
->dbfd
= std::move (dbfd
);
12190 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12191 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12192 &dwo_file
->sections
);
12194 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12197 if (cu
->per_cu
->dwarf_version
< 5)
12199 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12200 dwo_file
->sections
.types
, dwo_file
->tus
);
12204 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12205 &dwo_file
->sections
.info
, dwo_file
->tus
,
12206 rcuh_kind::COMPILE
);
12209 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12211 return dwo_file
.release ();
12214 /* This function is mapped across the sections and remembers the offset and
12215 size of each of the DWP debugging sections common to version 1 and 2 that
12216 we are interested in. */
12219 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12220 dwp_file
*dwp_file
)
12222 const struct dwop_section_names
*names
= &dwop_section_names
;
12223 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12225 /* Record the ELF section number for later lookup: this is what the
12226 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12227 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12228 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12230 /* Look for specific sections that we need. */
12231 if (names
->str_dwo
.matches (sectp
->name
))
12233 dwp_file
->sections
.str
.s
.section
= sectp
;
12234 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12236 else if (names
->cu_index
.matches (sectp
->name
))
12238 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12239 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12241 else if (names
->tu_index
.matches (sectp
->name
))
12243 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12244 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12248 /* This function is mapped across the sections and remembers the offset and
12249 size of each of the DWP version 2 debugging sections that we are interested
12250 in. This is split into a separate function because we don't know if we
12251 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12254 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12256 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12257 const struct dwop_section_names
*names
= &dwop_section_names
;
12258 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12260 /* Record the ELF section number for later lookup: this is what the
12261 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12262 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12263 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12265 /* Look for specific sections that we need. */
12266 if (names
->abbrev_dwo
.matches (sectp
->name
))
12268 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12269 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12271 else if (names
->info_dwo
.matches (sectp
->name
))
12273 dwp_file
->sections
.info
.s
.section
= sectp
;
12274 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12276 else if (names
->line_dwo
.matches (sectp
->name
))
12278 dwp_file
->sections
.line
.s
.section
= sectp
;
12279 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12281 else if (names
->loc_dwo
.matches (sectp
->name
))
12283 dwp_file
->sections
.loc
.s
.section
= sectp
;
12284 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12286 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12288 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12289 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12291 else if (names
->macro_dwo
.matches (sectp
->name
))
12293 dwp_file
->sections
.macro
.s
.section
= sectp
;
12294 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12296 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12298 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12299 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12301 else if (names
->types_dwo
.matches (sectp
->name
))
12303 dwp_file
->sections
.types
.s
.section
= sectp
;
12304 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12308 /* This function is mapped across the sections and remembers the offset and
12309 size of each of the DWP version 5 debugging sections that we are interested
12310 in. This is split into a separate function because we don't know if we
12311 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12314 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12316 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12317 const struct dwop_section_names
*names
= &dwop_section_names
;
12318 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12320 /* Record the ELF section number for later lookup: this is what the
12321 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12322 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12323 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12325 /* Look for specific sections that we need. */
12326 if (names
->abbrev_dwo
.matches (sectp
->name
))
12328 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12329 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12331 else if (names
->info_dwo
.matches (sectp
->name
))
12333 dwp_file
->sections
.info
.s
.section
= sectp
;
12334 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12336 else if (names
->line_dwo
.matches (sectp
->name
))
12338 dwp_file
->sections
.line
.s
.section
= sectp
;
12339 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12341 else if (names
->loclists_dwo
.matches (sectp
->name
))
12343 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12344 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12346 else if (names
->macro_dwo
.matches (sectp
->name
))
12348 dwp_file
->sections
.macro
.s
.section
= sectp
;
12349 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12351 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12353 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12354 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12356 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12358 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12359 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12363 /* Hash function for dwp_file loaded CUs/TUs. */
12366 hash_dwp_loaded_cutus (const void *item
)
12368 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12370 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12371 return dwo_unit
->signature
;
12374 /* Equality function for dwp_file loaded CUs/TUs. */
12377 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12379 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12380 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12382 return dua
->signature
== dub
->signature
;
12385 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12388 allocate_dwp_loaded_cutus_table ()
12390 return htab_up (htab_create_alloc (3,
12391 hash_dwp_loaded_cutus
,
12392 eq_dwp_loaded_cutus
,
12393 NULL
, xcalloc
, xfree
));
12396 /* Try to open DWP file FILE_NAME.
12397 The result is the bfd handle of the file.
12398 If there is a problem finding or opening the file, return NULL.
12399 Upon success, the canonicalized path of the file is stored in the bfd,
12400 same as symfile_bfd_open. */
12402 static gdb_bfd_ref_ptr
12403 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12405 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12407 1 /*search_cwd*/));
12411 /* Work around upstream bug 15652.
12412 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12413 [Whether that's a "bug" is debatable, but it is getting in our way.]
12414 We have no real idea where the dwp file is, because gdb's realpath-ing
12415 of the executable's path may have discarded the needed info.
12416 [IWBN if the dwp file name was recorded in the executable, akin to
12417 .gnu_debuglink, but that doesn't exist yet.]
12418 Strip the directory from FILE_NAME and search again. */
12419 if (*debug_file_directory
!= '\0')
12421 /* Don't implicitly search the current directory here.
12422 If the user wants to search "." to handle this case,
12423 it must be added to debug-file-directory. */
12424 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12432 /* Initialize the use of the DWP file for the current objfile.
12433 By convention the name of the DWP file is ${objfile}.dwp.
12434 The result is NULL if it can't be found. */
12436 static std::unique_ptr
<struct dwp_file
>
12437 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12439 struct objfile
*objfile
= per_objfile
->objfile
;
12441 /* Try to find first .dwp for the binary file before any symbolic links
12444 /* If the objfile is a debug file, find the name of the real binary
12445 file and get the name of dwp file from there. */
12446 std::string dwp_name
;
12447 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12449 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12450 const char *backlink_basename
= lbasename (backlink
->original_name
);
12452 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12455 dwp_name
= objfile
->original_name
;
12457 dwp_name
+= ".dwp";
12459 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12461 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12463 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12464 dwp_name
= objfile_name (objfile
);
12465 dwp_name
+= ".dwp";
12466 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12471 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12473 return std::unique_ptr
<dwp_file
> ();
12476 const char *name
= bfd_get_filename (dbfd
.get ());
12477 std::unique_ptr
<struct dwp_file
> dwp_file
12478 (new struct dwp_file (name
, std::move (dbfd
)));
12480 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12481 dwp_file
->elf_sections
=
12482 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12483 dwp_file
->num_sections
, asection
*);
12485 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12486 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12489 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12491 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12493 /* The DWP file version is stored in the hash table. Oh well. */
12494 if (dwp_file
->cus
&& dwp_file
->tus
12495 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12497 /* Technically speaking, we should try to limp along, but this is
12498 pretty bizarre. We use pulongest here because that's the established
12499 portability solution (e.g, we cannot use %u for uint32_t). */
12500 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12501 " TU version %s [in DWP file %s]"),
12502 pulongest (dwp_file
->cus
->version
),
12503 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12507 dwp_file
->version
= dwp_file
->cus
->version
;
12508 else if (dwp_file
->tus
)
12509 dwp_file
->version
= dwp_file
->tus
->version
;
12511 dwp_file
->version
= 2;
12513 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12515 if (dwp_file
->version
== 2)
12516 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12519 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12523 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12524 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12526 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12527 dwarf_read_debug_printf (" %s CUs, %s TUs",
12528 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12529 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12534 /* Wrapper around open_and_init_dwp_file, only open it once. */
12536 static struct dwp_file
*
12537 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12539 if (!per_objfile
->per_bfd
->dwp_checked
)
12541 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12542 per_objfile
->per_bfd
->dwp_checked
= 1;
12544 return per_objfile
->per_bfd
->dwp_file
.get ();
12547 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12548 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12549 or in the DWP file for the objfile, referenced by THIS_UNIT.
12550 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12551 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12553 This is called, for example, when wanting to read a variable with a
12554 complex location. Therefore we don't want to do file i/o for every call.
12555 Therefore we don't want to look for a DWO file on every call.
12556 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12557 then we check if we've already seen DWO_NAME, and only THEN do we check
12560 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12561 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12563 static struct dwo_unit
*
12564 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12565 ULONGEST signature
, int is_debug_types
)
12567 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12568 struct objfile
*objfile
= per_objfile
->objfile
;
12569 const char *kind
= is_debug_types
? "TU" : "CU";
12570 void **dwo_file_slot
;
12571 struct dwo_file
*dwo_file
;
12572 struct dwp_file
*dwp_file
;
12574 /* First see if there's a DWP file.
12575 If we have a DWP file but didn't find the DWO inside it, don't
12576 look for the original DWO file. It makes gdb behave differently
12577 depending on whether one is debugging in the build tree. */
12579 dwp_file
= get_dwp_file (per_objfile
);
12580 if (dwp_file
!= NULL
)
12582 const struct dwp_hash_table
*dwp_htab
=
12583 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12585 if (dwp_htab
!= NULL
)
12587 struct dwo_unit
*dwo_cutu
=
12588 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12591 if (dwo_cutu
!= NULL
)
12593 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12594 kind
, hex_string (signature
),
12595 host_address_to_string (dwo_cutu
));
12603 /* No DWP file, look for the DWO file. */
12605 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12606 if (*dwo_file_slot
== NULL
)
12608 /* Read in the file and build a table of the CUs/TUs it contains. */
12609 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12611 /* NOTE: This will be NULL if unable to open the file. */
12612 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12614 if (dwo_file
!= NULL
)
12616 struct dwo_unit
*dwo_cutu
= NULL
;
12618 if (is_debug_types
&& dwo_file
->tus
)
12620 struct dwo_unit find_dwo_cutu
;
12622 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12623 find_dwo_cutu
.signature
= signature
;
12625 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12628 else if (!is_debug_types
&& dwo_file
->cus
)
12630 struct dwo_unit find_dwo_cutu
;
12632 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12633 find_dwo_cutu
.signature
= signature
;
12634 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12638 if (dwo_cutu
!= NULL
)
12640 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12641 kind
, dwo_name
, hex_string (signature
),
12642 host_address_to_string (dwo_cutu
));
12649 /* We didn't find it. This could mean a dwo_id mismatch, or
12650 someone deleted the DWO/DWP file, or the search path isn't set up
12651 correctly to find the file. */
12653 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12654 kind
, dwo_name
, hex_string (signature
));
12656 /* This is a warning and not a complaint because it can be caused by
12657 pilot error (e.g., user accidentally deleting the DWO). */
12659 /* Print the name of the DWP file if we looked there, helps the user
12660 better diagnose the problem. */
12661 std::string dwp_text
;
12663 if (dwp_file
!= NULL
)
12664 dwp_text
= string_printf (" [in DWP file %s]",
12665 lbasename (dwp_file
->name
));
12667 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12668 " [in module %s]"),
12669 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12670 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12675 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12676 See lookup_dwo_cutu_unit for details. */
12678 static struct dwo_unit
*
12679 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12680 ULONGEST signature
)
12682 gdb_assert (!cu
->per_cu
->is_debug_types
);
12684 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12687 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12688 See lookup_dwo_cutu_unit for details. */
12690 static struct dwo_unit
*
12691 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12693 gdb_assert (cu
->per_cu
->is_debug_types
);
12695 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12697 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12700 /* Traversal function for queue_and_load_all_dwo_tus. */
12703 queue_and_load_dwo_tu (void **slot
, void *info
)
12705 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12706 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12707 ULONGEST signature
= dwo_unit
->signature
;
12708 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12710 if (sig_type
!= NULL
)
12712 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12713 a real dependency of PER_CU on SIG_TYPE. That is detected later
12714 while processing PER_CU. */
12715 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12717 load_full_type_unit (sig_type
, cu
->per_objfile
);
12718 cu
->per_cu
->imported_symtabs_push (sig_type
);
12724 /* Queue all TUs contained in the DWO of CU to be read in.
12725 The DWO may have the only definition of the type, though it may not be
12726 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12727 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12730 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12732 struct dwo_unit
*dwo_unit
;
12733 struct dwo_file
*dwo_file
;
12735 gdb_assert (cu
!= nullptr);
12736 gdb_assert (!cu
->per_cu
->is_debug_types
);
12737 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12739 dwo_unit
= cu
->dwo_unit
;
12740 gdb_assert (dwo_unit
!= NULL
);
12742 dwo_file
= dwo_unit
->dwo_file
;
12743 if (dwo_file
->tus
!= NULL
)
12744 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12747 /* Read in various DIEs. */
12749 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12750 Inherit only the children of the DW_AT_abstract_origin DIE not being
12751 already referenced by DW_AT_abstract_origin from the children of the
12755 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12757 struct die_info
*child_die
;
12758 sect_offset
*offsetp
;
12759 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12760 struct die_info
*origin_die
;
12761 /* Iterator of the ORIGIN_DIE children. */
12762 struct die_info
*origin_child_die
;
12763 struct attribute
*attr
;
12764 struct dwarf2_cu
*origin_cu
;
12765 struct pending
**origin_previous_list_in_scope
;
12767 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12771 /* Note that following die references may follow to a die in a
12775 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12777 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12779 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12780 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12782 if (die
->tag
!= origin_die
->tag
12783 && !(die
->tag
== DW_TAG_inlined_subroutine
12784 && origin_die
->tag
== DW_TAG_subprogram
))
12785 complaint (_("DIE %s and its abstract origin %s have different tags"),
12786 sect_offset_str (die
->sect_off
),
12787 sect_offset_str (origin_die
->sect_off
));
12789 /* Find if the concrete and abstract trees are structurally the
12790 same. This is a shallow traversal and it is not bullet-proof;
12791 the compiler can trick the debugger into believing that the trees
12792 are isomorphic, whereas they actually are not. However, the
12793 likelyhood of this happening is pretty low, and a full-fledged
12794 check would be an overkill. */
12795 bool are_isomorphic
= true;
12796 die_info
*concrete_child
= die
->child
;
12797 die_info
*abstract_child
= origin_die
->child
;
12798 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12800 if (concrete_child
== nullptr
12801 || abstract_child
== nullptr
12802 || concrete_child
->tag
!= abstract_child
->tag
)
12804 are_isomorphic
= false;
12808 concrete_child
= concrete_child
->sibling
;
12809 abstract_child
= abstract_child
->sibling
;
12812 /* Walk the origin's children in parallel to the concrete children.
12813 This helps match an origin child in case the debug info misses
12814 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12815 origin tree may not have the same tree structure as the concrete
12817 die_info
*corresponding_abstract_child
12818 = are_isomorphic
? origin_die
->child
: nullptr;
12820 std::vector
<sect_offset
> offsets
;
12822 for (child_die
= die
->child
;
12823 child_die
&& child_die
->tag
;
12824 child_die
= child_die
->sibling
)
12826 struct die_info
*child_origin_die
;
12827 struct dwarf2_cu
*child_origin_cu
;
12829 /* We are trying to process concrete instance entries:
12830 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12831 it's not relevant to our analysis here. i.e. detecting DIEs that are
12832 present in the abstract instance but not referenced in the concrete
12834 if (child_die
->tag
== DW_TAG_call_site
12835 || child_die
->tag
== DW_TAG_GNU_call_site
)
12837 if (are_isomorphic
)
12838 corresponding_abstract_child
12839 = corresponding_abstract_child
->sibling
;
12843 /* For each CHILD_DIE, find the corresponding child of
12844 ORIGIN_DIE. If there is more than one layer of
12845 DW_AT_abstract_origin, follow them all; there shouldn't be,
12846 but GCC versions at least through 4.4 generate this (GCC PR
12848 child_origin_die
= child_die
;
12849 child_origin_cu
= cu
;
12852 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12856 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12860 /* If missing DW_AT_abstract_origin, try the corresponding child
12861 of the origin. Clang emits such lexical scopes. */
12862 if (child_origin_die
== child_die
12863 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12865 && child_die
->tag
== DW_TAG_lexical_block
)
12866 child_origin_die
= corresponding_abstract_child
;
12868 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12869 counterpart may exist. */
12870 if (child_origin_die
!= child_die
)
12872 if (child_die
->tag
!= child_origin_die
->tag
12873 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12874 && child_origin_die
->tag
== DW_TAG_subprogram
))
12875 complaint (_("Child DIE %s and its abstract origin %s have "
12877 sect_offset_str (child_die
->sect_off
),
12878 sect_offset_str (child_origin_die
->sect_off
));
12879 if (child_origin_die
->parent
!= origin_die
)
12880 complaint (_("Child DIE %s and its abstract origin %s have "
12881 "different parents"),
12882 sect_offset_str (child_die
->sect_off
),
12883 sect_offset_str (child_origin_die
->sect_off
));
12885 offsets
.push_back (child_origin_die
->sect_off
);
12888 if (are_isomorphic
)
12889 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
12891 std::sort (offsets
.begin (), offsets
.end ());
12892 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12893 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12894 if (offsetp
[-1] == *offsetp
)
12895 complaint (_("Multiple children of DIE %s refer "
12896 "to DIE %s as their abstract origin"),
12897 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12899 offsetp
= offsets
.data ();
12900 origin_child_die
= origin_die
->child
;
12901 while (origin_child_die
&& origin_child_die
->tag
)
12903 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12904 while (offsetp
< offsets_end
12905 && *offsetp
< origin_child_die
->sect_off
)
12907 if (offsetp
>= offsets_end
12908 || *offsetp
> origin_child_die
->sect_off
)
12910 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12911 Check whether we're already processing ORIGIN_CHILD_DIE.
12912 This can happen with mutually referenced abstract_origins.
12914 if (!origin_child_die
->in_process
)
12915 process_die (origin_child_die
, origin_cu
);
12917 origin_child_die
= origin_child_die
->sibling
;
12919 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12921 if (cu
!= origin_cu
)
12922 compute_delayed_physnames (origin_cu
);
12926 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12928 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12929 struct gdbarch
*gdbarch
= objfile
->arch ();
12930 struct context_stack
*newobj
;
12933 struct die_info
*child_die
;
12934 struct attribute
*attr
, *call_line
, *call_file
;
12936 CORE_ADDR baseaddr
;
12937 struct block
*block
;
12938 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12939 std::vector
<struct symbol
*> template_args
;
12940 struct template_symbol
*templ_func
= NULL
;
12944 /* If we do not have call site information, we can't show the
12945 caller of this inlined function. That's too confusing, so
12946 only use the scope for local variables. */
12947 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12948 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12949 if (call_line
== NULL
|| call_file
== NULL
)
12951 read_lexical_block_scope (die
, cu
);
12956 baseaddr
= objfile
->text_section_offset ();
12958 name
= dwarf2_name (die
, cu
);
12960 /* Ignore functions with missing or empty names. These are actually
12961 illegal according to the DWARF standard. */
12964 complaint (_("missing name for subprogram DIE at %s"),
12965 sect_offset_str (die
->sect_off
));
12969 /* Ignore functions with missing or invalid low and high pc attributes. */
12970 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12971 <= PC_BOUNDS_INVALID
)
12973 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12974 if (attr
== nullptr || !attr
->as_boolean ())
12975 complaint (_("cannot get low and high bounds "
12976 "for subprogram DIE at %s"),
12977 sect_offset_str (die
->sect_off
));
12981 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12982 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12984 /* If we have any template arguments, then we must allocate a
12985 different sort of symbol. */
12986 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12988 if (child_die
->tag
== DW_TAG_template_type_param
12989 || child_die
->tag
== DW_TAG_template_value_param
)
12991 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
12992 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12997 gdb_assert (cu
->get_builder () != nullptr);
12998 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12999 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13000 (struct symbol
*) templ_func
);
13002 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13003 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13006 /* If there is a location expression for DW_AT_frame_base, record
13008 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13009 if (attr
!= nullptr)
13010 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13012 /* If there is a location for the static link, record it. */
13013 newobj
->static_link
= NULL
;
13014 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13015 if (attr
!= nullptr)
13017 newobj
->static_link
13018 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13019 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13023 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13025 if (die
->child
!= NULL
)
13027 child_die
= die
->child
;
13028 while (child_die
&& child_die
->tag
)
13030 if (child_die
->tag
== DW_TAG_template_type_param
13031 || child_die
->tag
== DW_TAG_template_value_param
)
13033 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13036 template_args
.push_back (arg
);
13039 process_die (child_die
, cu
);
13040 child_die
= child_die
->sibling
;
13044 inherit_abstract_dies (die
, cu
);
13046 /* If we have a DW_AT_specification, we might need to import using
13047 directives from the context of the specification DIE. See the
13048 comment in determine_prefix. */
13049 if (cu
->language
== language_cplus
13050 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13052 struct dwarf2_cu
*spec_cu
= cu
;
13053 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13057 child_die
= spec_die
->child
;
13058 while (child_die
&& child_die
->tag
)
13060 if (child_die
->tag
== DW_TAG_imported_module
)
13061 process_die (child_die
, spec_cu
);
13062 child_die
= child_die
->sibling
;
13065 /* In some cases, GCC generates specification DIEs that
13066 themselves contain DW_AT_specification attributes. */
13067 spec_die
= die_specification (spec_die
, &spec_cu
);
13071 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13072 /* Make a block for the local symbols within. */
13073 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13074 cstk
.static_link
, lowpc
, highpc
);
13076 /* For C++, set the block's scope. */
13077 if ((cu
->language
== language_cplus
13078 || cu
->language
== language_fortran
13079 || cu
->language
== language_d
13080 || cu
->language
== language_rust
)
13081 && cu
->processing_has_namespace_info
)
13082 block_set_scope (block
, determine_prefix (die
, cu
),
13083 &objfile
->objfile_obstack
);
13085 /* If we have address ranges, record them. */
13086 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13088 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13090 /* Attach template arguments to function. */
13091 if (!template_args
.empty ())
13093 gdb_assert (templ_func
!= NULL
);
13095 templ_func
->n_template_arguments
= template_args
.size ();
13096 templ_func
->template_arguments
13097 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13098 templ_func
->n_template_arguments
);
13099 memcpy (templ_func
->template_arguments
,
13100 template_args
.data (),
13101 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13103 /* Make sure that the symtab is set on the new symbols. Even
13104 though they don't appear in this symtab directly, other parts
13105 of gdb assume that symbols do, and this is reasonably
13107 for (symbol
*sym
: template_args
)
13108 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13111 /* In C++, we can have functions nested inside functions (e.g., when
13112 a function declares a class that has methods). This means that
13113 when we finish processing a function scope, we may need to go
13114 back to building a containing block's symbol lists. */
13115 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13116 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13118 /* If we've finished processing a top-level function, subsequent
13119 symbols go in the file symbol list. */
13120 if (cu
->get_builder ()->outermost_context_p ())
13121 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13124 /* Process all the DIES contained within a lexical block scope. Start
13125 a new scope, process the dies, and then close the scope. */
13128 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13130 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13131 struct gdbarch
*gdbarch
= objfile
->arch ();
13132 CORE_ADDR lowpc
, highpc
;
13133 struct die_info
*child_die
;
13134 CORE_ADDR baseaddr
;
13136 baseaddr
= objfile
->text_section_offset ();
13138 /* Ignore blocks with missing or invalid low and high pc attributes. */
13139 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13140 as multiple lexical blocks? Handling children in a sane way would
13141 be nasty. Might be easier to properly extend generic blocks to
13142 describe ranges. */
13143 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13145 case PC_BOUNDS_NOT_PRESENT
:
13146 /* DW_TAG_lexical_block has no attributes, process its children as if
13147 there was no wrapping by that DW_TAG_lexical_block.
13148 GCC does no longer produces such DWARF since GCC r224161. */
13149 for (child_die
= die
->child
;
13150 child_die
!= NULL
&& child_die
->tag
;
13151 child_die
= child_die
->sibling
)
13153 /* We might already be processing this DIE. This can happen
13154 in an unusual circumstance -- where a subroutine A
13155 appears lexically in another subroutine B, but A actually
13156 inlines B. The recursion is broken here, rather than in
13157 inherit_abstract_dies, because it seems better to simply
13158 drop concrete children here. */
13159 if (!child_die
->in_process
)
13160 process_die (child_die
, cu
);
13163 case PC_BOUNDS_INVALID
:
13166 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13167 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13169 cu
->get_builder ()->push_context (0, lowpc
);
13170 if (die
->child
!= NULL
)
13172 child_die
= die
->child
;
13173 while (child_die
&& child_die
->tag
)
13175 process_die (child_die
, cu
);
13176 child_die
= child_die
->sibling
;
13179 inherit_abstract_dies (die
, cu
);
13180 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13182 if (*cu
->get_builder ()->get_local_symbols () != NULL
13183 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13185 struct block
*block
13186 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13187 cstk
.start_addr
, highpc
);
13189 /* Note that recording ranges after traversing children, as we
13190 do here, means that recording a parent's ranges entails
13191 walking across all its children's ranges as they appear in
13192 the address map, which is quadratic behavior.
13194 It would be nicer to record the parent's ranges before
13195 traversing its children, simply overriding whatever you find
13196 there. But since we don't even decide whether to create a
13197 block until after we've traversed its children, that's hard
13199 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13201 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13202 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13205 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13208 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13210 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13211 struct objfile
*objfile
= per_objfile
->objfile
;
13212 struct gdbarch
*gdbarch
= objfile
->arch ();
13213 CORE_ADDR pc
, baseaddr
;
13214 struct attribute
*attr
;
13215 struct call_site
*call_site
, call_site_local
;
13218 struct die_info
*child_die
;
13220 baseaddr
= objfile
->text_section_offset ();
13222 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13225 /* This was a pre-DWARF-5 GNU extension alias
13226 for DW_AT_call_return_pc. */
13227 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13231 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13232 "DIE %s [in module %s]"),
13233 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13236 pc
= attr
->as_address () + baseaddr
;
13237 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13239 if (cu
->call_site_htab
== NULL
)
13240 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13241 NULL
, &objfile
->objfile_obstack
,
13242 hashtab_obstack_allocate
, NULL
);
13243 call_site_local
.pc
= pc
;
13244 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13247 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13248 "DIE %s [in module %s]"),
13249 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13250 objfile_name (objfile
));
13254 /* Count parameters at the caller. */
13257 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13258 child_die
= child_die
->sibling
)
13260 if (child_die
->tag
!= DW_TAG_call_site_parameter
13261 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13263 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13264 "DW_TAG_call_site child DIE %s [in module %s]"),
13265 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13266 objfile_name (objfile
));
13274 = ((struct call_site
*)
13275 obstack_alloc (&objfile
->objfile_obstack
,
13276 sizeof (*call_site
)
13277 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13279 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13280 call_site
->pc
= pc
;
13282 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13283 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13285 struct die_info
*func_die
;
13287 /* Skip also over DW_TAG_inlined_subroutine. */
13288 for (func_die
= die
->parent
;
13289 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13290 && func_die
->tag
!= DW_TAG_subroutine_type
;
13291 func_die
= func_die
->parent
);
13293 /* DW_AT_call_all_calls is a superset
13294 of DW_AT_call_all_tail_calls. */
13296 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13297 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13298 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13299 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13301 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13302 not complete. But keep CALL_SITE for look ups via call_site_htab,
13303 both the initial caller containing the real return address PC and
13304 the final callee containing the current PC of a chain of tail
13305 calls do not need to have the tail call list complete. But any
13306 function candidate for a virtual tail call frame searched via
13307 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13308 determined unambiguously. */
13312 struct type
*func_type
= NULL
;
13315 func_type
= get_die_type (func_die
, cu
);
13316 if (func_type
!= NULL
)
13318 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13320 /* Enlist this call site to the function. */
13321 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13322 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13325 complaint (_("Cannot find function owning DW_TAG_call_site "
13326 "DIE %s [in module %s]"),
13327 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13331 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13333 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13335 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13338 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13339 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13341 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13342 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13343 /* Keep NULL DWARF_BLOCK. */;
13344 else if (attr
->form_is_block ())
13346 struct dwarf2_locexpr_baton
*dlbaton
;
13347 struct dwarf_block
*block
= attr
->as_block ();
13349 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13350 dlbaton
->data
= block
->data
;
13351 dlbaton
->size
= block
->size
;
13352 dlbaton
->per_objfile
= per_objfile
;
13353 dlbaton
->per_cu
= cu
->per_cu
;
13355 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13357 else if (attr
->form_is_ref ())
13359 struct dwarf2_cu
*target_cu
= cu
;
13360 struct die_info
*target_die
;
13362 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13363 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13364 if (die_is_declaration (target_die
, target_cu
))
13366 const char *target_physname
;
13368 /* Prefer the mangled name; otherwise compute the demangled one. */
13369 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13370 if (target_physname
== NULL
)
13371 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13372 if (target_physname
== NULL
)
13373 complaint (_("DW_AT_call_target target DIE has invalid "
13374 "physname, for referencing DIE %s [in module %s]"),
13375 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13377 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13383 /* DW_AT_entry_pc should be preferred. */
13384 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13385 <= PC_BOUNDS_INVALID
)
13386 complaint (_("DW_AT_call_target target DIE has invalid "
13387 "low pc, for referencing DIE %s [in module %s]"),
13388 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13391 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13392 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13397 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13398 "block nor reference, for DIE %s [in module %s]"),
13399 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13401 call_site
->per_cu
= cu
->per_cu
;
13402 call_site
->per_objfile
= per_objfile
;
13404 for (child_die
= die
->child
;
13405 child_die
&& child_die
->tag
;
13406 child_die
= child_die
->sibling
)
13408 struct call_site_parameter
*parameter
;
13409 struct attribute
*loc
, *origin
;
13411 if (child_die
->tag
!= DW_TAG_call_site_parameter
13412 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13414 /* Already printed the complaint above. */
13418 gdb_assert (call_site
->parameter_count
< nparams
);
13419 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13421 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13422 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13423 register is contained in DW_AT_call_value. */
13425 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13426 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13427 if (origin
== NULL
)
13429 /* This was a pre-DWARF-5 GNU extension alias
13430 for DW_AT_call_parameter. */
13431 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13433 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13435 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13437 sect_offset sect_off
= origin
->get_ref_die_offset ();
13438 if (!cu
->header
.offset_in_cu_p (sect_off
))
13440 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13441 binding can be done only inside one CU. Such referenced DIE
13442 therefore cannot be even moved to DW_TAG_partial_unit. */
13443 complaint (_("DW_AT_call_parameter offset is not in CU for "
13444 "DW_TAG_call_site child DIE %s [in module %s]"),
13445 sect_offset_str (child_die
->sect_off
),
13446 objfile_name (objfile
));
13449 parameter
->u
.param_cu_off
13450 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13452 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13454 complaint (_("No DW_FORM_block* DW_AT_location for "
13455 "DW_TAG_call_site child DIE %s [in module %s]"),
13456 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13461 struct dwarf_block
*block
= loc
->as_block ();
13463 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13464 (block
->data
, &block
->data
[block
->size
]);
13465 if (parameter
->u
.dwarf_reg
!= -1)
13466 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13467 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13468 &block
->data
[block
->size
],
13469 ¶meter
->u
.fb_offset
))
13470 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13473 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13474 "for DW_FORM_block* DW_AT_location is supported for "
13475 "DW_TAG_call_site child DIE %s "
13477 sect_offset_str (child_die
->sect_off
),
13478 objfile_name (objfile
));
13483 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13485 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13486 if (attr
== NULL
|| !attr
->form_is_block ())
13488 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13489 "DW_TAG_call_site child DIE %s [in module %s]"),
13490 sect_offset_str (child_die
->sect_off
),
13491 objfile_name (objfile
));
13495 struct dwarf_block
*block
= attr
->as_block ();
13496 parameter
->value
= block
->data
;
13497 parameter
->value_size
= block
->size
;
13499 /* Parameters are not pre-cleared by memset above. */
13500 parameter
->data_value
= NULL
;
13501 parameter
->data_value_size
= 0;
13502 call_site
->parameter_count
++;
13504 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13506 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13507 if (attr
!= nullptr)
13509 if (!attr
->form_is_block ())
13510 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13511 "DW_TAG_call_site child DIE %s [in module %s]"),
13512 sect_offset_str (child_die
->sect_off
),
13513 objfile_name (objfile
));
13516 block
= attr
->as_block ();
13517 parameter
->data_value
= block
->data
;
13518 parameter
->data_value_size
= block
->size
;
13524 /* Helper function for read_variable. If DIE represents a virtual
13525 table, then return the type of the concrete object that is
13526 associated with the virtual table. Otherwise, return NULL. */
13528 static struct type
*
13529 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13531 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13535 /* Find the type DIE. */
13536 struct die_info
*type_die
= NULL
;
13537 struct dwarf2_cu
*type_cu
= cu
;
13539 if (attr
->form_is_ref ())
13540 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13541 if (type_die
== NULL
)
13544 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13546 return die_containing_type (type_die
, type_cu
);
13549 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13552 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13554 struct rust_vtable_symbol
*storage
= NULL
;
13556 if (cu
->language
== language_rust
)
13558 struct type
*containing_type
= rust_containing_type (die
, cu
);
13560 if (containing_type
!= NULL
)
13562 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13564 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13565 storage
->concrete_type
= containing_type
;
13566 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13570 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13571 struct attribute
*abstract_origin
13572 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13573 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13574 if (res
== NULL
&& loc
&& abstract_origin
)
13576 /* We have a variable without a name, but with a location and an abstract
13577 origin. This may be a concrete instance of an abstract variable
13578 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13580 struct dwarf2_cu
*origin_cu
= cu
;
13581 struct die_info
*origin_die
13582 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13583 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13584 per_objfile
->per_bfd
->abstract_to_concrete
13585 [origin_die
->sect_off
].push_back (die
->sect_off
);
13589 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13590 reading .debug_rnglists.
13591 Callback's type should be:
13592 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13593 Return true if the attributes are present and valid, otherwise,
13596 template <typename Callback
>
13598 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13599 dwarf_tag tag
, Callback
&&callback
)
13601 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13602 struct objfile
*objfile
= per_objfile
->objfile
;
13603 bfd
*obfd
= objfile
->obfd
;
13604 /* Base address selection entry. */
13605 gdb::optional
<CORE_ADDR
> base
;
13606 const gdb_byte
*buffer
;
13607 CORE_ADDR baseaddr
;
13608 bool overflow
= false;
13609 ULONGEST addr_index
;
13610 struct dwarf2_section_info
*rnglists_section
;
13612 base
= cu
->base_address
;
13613 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13614 rnglists_section
->read (objfile
);
13616 if (offset
>= rnglists_section
->size
)
13618 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13622 buffer
= rnglists_section
->buffer
+ offset
;
13624 baseaddr
= objfile
->text_section_offset ();
13628 /* Initialize it due to a false compiler warning. */
13629 CORE_ADDR range_beginning
= 0, range_end
= 0;
13630 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13631 + rnglists_section
->size
);
13632 unsigned int bytes_read
;
13634 if (buffer
== buf_end
)
13639 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13642 case DW_RLE_end_of_list
:
13644 case DW_RLE_base_address
:
13645 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13650 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13651 buffer
+= bytes_read
;
13653 case DW_RLE_base_addressx
:
13654 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13655 buffer
+= bytes_read
;
13656 base
= read_addr_index (cu
, addr_index
);
13658 case DW_RLE_start_length
:
13659 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13664 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13666 buffer
+= bytes_read
;
13667 range_end
= (range_beginning
13668 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13669 buffer
+= bytes_read
;
13670 if (buffer
> buf_end
)
13676 case DW_RLE_startx_length
:
13677 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13678 buffer
+= bytes_read
;
13679 range_beginning
= read_addr_index (cu
, addr_index
);
13680 if (buffer
> buf_end
)
13685 range_end
= (range_beginning
13686 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13687 buffer
+= bytes_read
;
13689 case DW_RLE_offset_pair
:
13690 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13691 buffer
+= bytes_read
;
13692 if (buffer
> buf_end
)
13697 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13698 buffer
+= bytes_read
;
13699 if (buffer
> buf_end
)
13705 case DW_RLE_start_end
:
13706 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13711 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13713 buffer
+= bytes_read
;
13714 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13715 buffer
+= bytes_read
;
13717 case DW_RLE_startx_endx
:
13718 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13719 buffer
+= bytes_read
;
13720 range_beginning
= read_addr_index (cu
, addr_index
);
13721 if (buffer
> buf_end
)
13726 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13727 buffer
+= bytes_read
;
13728 range_end
= read_addr_index (cu
, addr_index
);
13731 complaint (_("Invalid .debug_rnglists data (no base address)"));
13734 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13736 if (rlet
== DW_RLE_base_address
)
13739 if (range_beginning
> range_end
)
13741 /* Inverted range entries are invalid. */
13742 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13746 /* Empty range entries have no effect. */
13747 if (range_beginning
== range_end
)
13750 /* Only DW_RLE_offset_pair needs the base address added. */
13751 if (rlet
== DW_RLE_offset_pair
)
13753 if (!base
.has_value ())
13755 /* We have no valid base address for the DW_RLE_offset_pair. */
13756 complaint (_("Invalid .debug_rnglists data (no base address for "
13757 "DW_RLE_offset_pair)"));
13761 range_beginning
+= *base
;
13762 range_end
+= *base
;
13765 /* A not-uncommon case of bad debug info.
13766 Don't pollute the addrmap with bad data. */
13767 if (range_beginning
+ baseaddr
== 0
13768 && !per_objfile
->per_bfd
->has_section_at_zero
)
13770 complaint (_(".debug_rnglists entry has start address of zero"
13771 " [in module %s]"), objfile_name (objfile
));
13775 callback (range_beginning
, range_end
);
13780 complaint (_("Offset %d is not terminated "
13781 "for DW_AT_ranges attribute"),
13789 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13790 Callback's type should be:
13791 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13792 Return 1 if the attributes are present and valid, otherwise, return 0. */
13794 template <typename Callback
>
13796 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13797 Callback
&&callback
)
13799 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13800 struct objfile
*objfile
= per_objfile
->objfile
;
13801 struct comp_unit_head
*cu_header
= &cu
->header
;
13802 bfd
*obfd
= objfile
->obfd
;
13803 unsigned int addr_size
= cu_header
->addr_size
;
13804 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13805 /* Base address selection entry. */
13806 gdb::optional
<CORE_ADDR
> base
;
13807 unsigned int dummy
;
13808 const gdb_byte
*buffer
;
13809 CORE_ADDR baseaddr
;
13811 if (cu_header
->version
>= 5)
13812 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13814 base
= cu
->base_address
;
13816 per_objfile
->per_bfd
->ranges
.read (objfile
);
13817 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13819 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13823 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13825 baseaddr
= objfile
->text_section_offset ();
13829 CORE_ADDR range_beginning
, range_end
;
13831 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13832 buffer
+= addr_size
;
13833 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13834 buffer
+= addr_size
;
13835 offset
+= 2 * addr_size
;
13837 /* An end of list marker is a pair of zero addresses. */
13838 if (range_beginning
== 0 && range_end
== 0)
13839 /* Found the end of list entry. */
13842 /* Each base address selection entry is a pair of 2 values.
13843 The first is the largest possible address, the second is
13844 the base address. Check for a base address here. */
13845 if ((range_beginning
& mask
) == mask
)
13847 /* If we found the largest possible address, then we already
13848 have the base address in range_end. */
13853 if (!base
.has_value ())
13855 /* We have no valid base address for the ranges
13857 complaint (_("Invalid .debug_ranges data (no base address)"));
13861 if (range_beginning
> range_end
)
13863 /* Inverted range entries are invalid. */
13864 complaint (_("Invalid .debug_ranges data (inverted range)"));
13868 /* Empty range entries have no effect. */
13869 if (range_beginning
== range_end
)
13872 range_beginning
+= *base
;
13873 range_end
+= *base
;
13875 /* A not-uncommon case of bad debug info.
13876 Don't pollute the addrmap with bad data. */
13877 if (range_beginning
+ baseaddr
== 0
13878 && !per_objfile
->per_bfd
->has_section_at_zero
)
13880 complaint (_(".debug_ranges entry has start address of zero"
13881 " [in module %s]"), objfile_name (objfile
));
13885 callback (range_beginning
, range_end
);
13891 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13892 Return 1 if the attributes are present and valid, otherwise, return 0.
13893 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
13896 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13897 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13898 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
13900 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13901 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
13902 struct gdbarch
*gdbarch
= objfile
->arch ();
13903 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13906 CORE_ADDR high
= 0;
13909 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
13910 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13912 if (ranges_pst
!= NULL
)
13917 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13918 range_beginning
+ baseaddr
)
13920 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13921 range_end
+ baseaddr
)
13923 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
13924 lowpc
, highpc
- 1, ranges_pst
);
13927 /* FIXME: This is recording everything as a low-high
13928 segment of consecutive addresses. We should have a
13929 data structure for discontiguous block ranges
13933 low
= range_beginning
;
13939 if (range_beginning
< low
)
13940 low
= range_beginning
;
13941 if (range_end
> high
)
13949 /* If the first entry is an end-of-list marker, the range
13950 describes an empty scope, i.e. no instructions. */
13956 *high_return
= high
;
13960 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13961 definition for the return value. *LOWPC and *HIGHPC are set iff
13962 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13964 static enum pc_bounds_kind
13965 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13966 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13967 dwarf2_psymtab
*pst
)
13969 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13970 struct attribute
*attr
;
13971 struct attribute
*attr_high
;
13973 CORE_ADDR high
= 0;
13974 enum pc_bounds_kind ret
;
13976 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13979 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13980 if (attr
!= nullptr)
13982 low
= attr
->as_address ();
13983 high
= attr_high
->as_address ();
13984 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13988 /* Found high w/o low attribute. */
13989 return PC_BOUNDS_INVALID
;
13991 /* Found consecutive range of addresses. */
13992 ret
= PC_BOUNDS_HIGH_LOW
;
13996 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13997 if (attr
!= nullptr && attr
->form_is_unsigned ())
13999 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14000 on DWARF version). */
14001 ULONGEST ranges_offset
= attr
->as_unsigned ();
14003 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14005 if (die
->tag
!= DW_TAG_compile_unit
)
14006 ranges_offset
+= cu
->gnu_ranges_base
;
14008 /* Value of the DW_AT_ranges attribute is the offset in the
14009 .debug_ranges section. */
14010 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14012 return PC_BOUNDS_INVALID
;
14013 /* Found discontinuous range of addresses. */
14014 ret
= PC_BOUNDS_RANGES
;
14017 return PC_BOUNDS_NOT_PRESENT
;
14020 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14022 return PC_BOUNDS_INVALID
;
14024 /* When using the GNU linker, .gnu.linkonce. sections are used to
14025 eliminate duplicate copies of functions and vtables and such.
14026 The linker will arbitrarily choose one and discard the others.
14027 The AT_*_pc values for such functions refer to local labels in
14028 these sections. If the section from that file was discarded, the
14029 labels are not in the output, so the relocs get a value of 0.
14030 If this is a discarded function, mark the pc bounds as invalid,
14031 so that GDB will ignore it. */
14032 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14033 return PC_BOUNDS_INVALID
;
14041 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14042 its low and high PC addresses. Do nothing if these addresses could not
14043 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14044 and HIGHPC to the high address if greater than HIGHPC. */
14047 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14048 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14049 struct dwarf2_cu
*cu
)
14051 CORE_ADDR low
, high
;
14052 struct die_info
*child
= die
->child
;
14054 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14056 *lowpc
= std::min (*lowpc
, low
);
14057 *highpc
= std::max (*highpc
, high
);
14060 /* If the language does not allow nested subprograms (either inside
14061 subprograms or lexical blocks), we're done. */
14062 if (cu
->language
!= language_ada
)
14065 /* Check all the children of the given DIE. If it contains nested
14066 subprograms, then check their pc bounds. Likewise, we need to
14067 check lexical blocks as well, as they may also contain subprogram
14069 while (child
&& child
->tag
)
14071 if (child
->tag
== DW_TAG_subprogram
14072 || child
->tag
== DW_TAG_lexical_block
)
14073 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14074 child
= child
->sibling
;
14078 /* Get the low and high pc's represented by the scope DIE, and store
14079 them in *LOWPC and *HIGHPC. If the correct values can't be
14080 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14083 get_scope_pc_bounds (struct die_info
*die
,
14084 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14085 struct dwarf2_cu
*cu
)
14087 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14088 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14089 CORE_ADDR current_low
, current_high
;
14091 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14092 >= PC_BOUNDS_RANGES
)
14094 best_low
= current_low
;
14095 best_high
= current_high
;
14099 struct die_info
*child
= die
->child
;
14101 while (child
&& child
->tag
)
14103 switch (child
->tag
) {
14104 case DW_TAG_subprogram
:
14105 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14107 case DW_TAG_namespace
:
14108 case DW_TAG_module
:
14109 /* FIXME: carlton/2004-01-16: Should we do this for
14110 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14111 that current GCC's always emit the DIEs corresponding
14112 to definitions of methods of classes as children of a
14113 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14114 the DIEs giving the declarations, which could be
14115 anywhere). But I don't see any reason why the
14116 standards says that they have to be there. */
14117 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14119 if (current_low
!= ((CORE_ADDR
) -1))
14121 best_low
= std::min (best_low
, current_low
);
14122 best_high
= std::max (best_high
, current_high
);
14130 child
= child
->sibling
;
14135 *highpc
= best_high
;
14138 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14142 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14143 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14145 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14146 struct gdbarch
*gdbarch
= objfile
->arch ();
14147 struct attribute
*attr
;
14148 struct attribute
*attr_high
;
14150 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14153 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14154 if (attr
!= nullptr)
14156 CORE_ADDR low
= attr
->as_address ();
14157 CORE_ADDR high
= attr_high
->as_address ();
14159 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14162 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14163 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14164 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14168 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14169 if (attr
!= nullptr && attr
->form_is_unsigned ())
14171 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14172 on DWARF version). */
14173 ULONGEST ranges_offset
= attr
->as_unsigned ();
14175 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14177 if (die
->tag
!= DW_TAG_compile_unit
)
14178 ranges_offset
+= cu
->gnu_ranges_base
;
14180 std::vector
<blockrange
> blockvec
;
14181 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14182 [&] (CORE_ADDR start
, CORE_ADDR end
)
14186 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14187 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14188 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14189 blockvec
.emplace_back (start
, end
);
14192 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14196 /* Check whether the producer field indicates either of GCC < 4.6, or the
14197 Intel C/C++ compiler, and cache the result in CU. */
14200 check_producer (struct dwarf2_cu
*cu
)
14204 if (cu
->producer
== NULL
)
14206 /* For unknown compilers expect their behavior is DWARF version
14209 GCC started to support .debug_types sections by -gdwarf-4 since
14210 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14211 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14212 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14213 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14215 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14217 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14218 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14220 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14222 cu
->producer_is_icc
= true;
14223 cu
->producer_is_icc_lt_14
= major
< 14;
14225 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14226 cu
->producer_is_codewarrior
= true;
14229 /* For other non-GCC compilers, expect their behavior is DWARF version
14233 cu
->checked_producer
= true;
14236 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14237 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14238 during 4.6.0 experimental. */
14241 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14243 if (!cu
->checked_producer
)
14244 check_producer (cu
);
14246 return cu
->producer_is_gxx_lt_4_6
;
14250 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14251 with incorrect is_stmt attributes. */
14254 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14256 if (!cu
->checked_producer
)
14257 check_producer (cu
);
14259 return cu
->producer_is_codewarrior
;
14262 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14263 If that attribute is not available, return the appropriate
14266 static enum dwarf_access_attribute
14267 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14269 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14270 if (attr
!= nullptr)
14272 LONGEST value
= attr
->constant_value (-1);
14273 if (value
== DW_ACCESS_public
14274 || value
== DW_ACCESS_protected
14275 || value
== DW_ACCESS_private
)
14276 return (dwarf_access_attribute
) value
;
14277 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14281 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14283 /* The default DWARF 2 accessibility for members is public, the default
14284 accessibility for inheritance is private. */
14286 if (die
->tag
!= DW_TAG_inheritance
)
14287 return DW_ACCESS_public
;
14289 return DW_ACCESS_private
;
14293 /* DWARF 3+ defines the default accessibility a different way. The same
14294 rules apply now for DW_TAG_inheritance as for the members and it only
14295 depends on the container kind. */
14297 if (die
->parent
->tag
== DW_TAG_class_type
)
14298 return DW_ACCESS_private
;
14300 return DW_ACCESS_public
;
14304 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14305 offset. If the attribute was not found return 0, otherwise return
14306 1. If it was found but could not properly be handled, set *OFFSET
14310 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14313 struct attribute
*attr
;
14315 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14320 /* Note that we do not check for a section offset first here.
14321 This is because DW_AT_data_member_location is new in DWARF 4,
14322 so if we see it, we can assume that a constant form is really
14323 a constant and not a section offset. */
14324 if (attr
->form_is_constant ())
14325 *offset
= attr
->constant_value (0);
14326 else if (attr
->form_is_section_offset ())
14327 dwarf2_complex_location_expr_complaint ();
14328 else if (attr
->form_is_block ())
14329 *offset
= decode_locdesc (attr
->as_block (), cu
);
14331 dwarf2_complex_location_expr_complaint ();
14339 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14342 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14343 struct field
*field
)
14345 struct attribute
*attr
;
14347 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14350 if (attr
->form_is_constant ())
14352 LONGEST offset
= attr
->constant_value (0);
14353 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14355 else if (attr
->form_is_section_offset ())
14356 dwarf2_complex_location_expr_complaint ();
14357 else if (attr
->form_is_block ())
14360 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14362 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14365 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14366 struct objfile
*objfile
= per_objfile
->objfile
;
14367 struct dwarf2_locexpr_baton
*dlbaton
14368 = XOBNEW (&objfile
->objfile_obstack
,
14369 struct dwarf2_locexpr_baton
);
14370 dlbaton
->data
= attr
->as_block ()->data
;
14371 dlbaton
->size
= attr
->as_block ()->size
;
14372 /* When using this baton, we want to compute the address
14373 of the field, not the value. This is why
14374 is_reference is set to false here. */
14375 dlbaton
->is_reference
= false;
14376 dlbaton
->per_objfile
= per_objfile
;
14377 dlbaton
->per_cu
= cu
->per_cu
;
14379 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14383 dwarf2_complex_location_expr_complaint ();
14387 /* Add an aggregate field to the field list. */
14390 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14391 struct dwarf2_cu
*cu
)
14393 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14394 struct gdbarch
*gdbarch
= objfile
->arch ();
14395 struct nextfield
*new_field
;
14396 struct attribute
*attr
;
14398 const char *fieldname
= "";
14400 if (die
->tag
== DW_TAG_inheritance
)
14402 fip
->baseclasses
.emplace_back ();
14403 new_field
= &fip
->baseclasses
.back ();
14407 fip
->fields
.emplace_back ();
14408 new_field
= &fip
->fields
.back ();
14411 new_field
->offset
= die
->sect_off
;
14413 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14414 if (new_field
->accessibility
!= DW_ACCESS_public
)
14415 fip
->non_public_fields
= true;
14417 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14418 if (attr
!= nullptr)
14419 new_field
->virtuality
= attr
->as_virtuality ();
14421 new_field
->virtuality
= DW_VIRTUALITY_none
;
14423 fp
= &new_field
->field
;
14425 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14427 /* Data member other than a C++ static data member. */
14429 /* Get type of field. */
14430 fp
->set_type (die_type (die
, cu
));
14432 SET_FIELD_BITPOS (*fp
, 0);
14434 /* Get bit size of field (zero if none). */
14435 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14436 if (attr
!= nullptr)
14438 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14442 FIELD_BITSIZE (*fp
) = 0;
14445 /* Get bit offset of field. */
14446 handle_data_member_location (die
, cu
, fp
);
14447 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14448 if (attr
!= nullptr && attr
->form_is_constant ())
14450 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14452 /* For big endian bits, the DW_AT_bit_offset gives the
14453 additional bit offset from the MSB of the containing
14454 anonymous object to the MSB of the field. We don't
14455 have to do anything special since we don't need to
14456 know the size of the anonymous object. */
14457 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14458 + attr
->constant_value (0)));
14462 /* For little endian bits, compute the bit offset to the
14463 MSB of the anonymous object, subtract off the number of
14464 bits from the MSB of the field to the MSB of the
14465 object, and then subtract off the number of bits of
14466 the field itself. The result is the bit offset of
14467 the LSB of the field. */
14468 int anonymous_size
;
14469 int bit_offset
= attr
->constant_value (0);
14471 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14472 if (attr
!= nullptr && attr
->form_is_constant ())
14474 /* The size of the anonymous object containing
14475 the bit field is explicit, so use the
14476 indicated size (in bytes). */
14477 anonymous_size
= attr
->constant_value (0);
14481 /* The size of the anonymous object containing
14482 the bit field must be inferred from the type
14483 attribute of the data member containing the
14485 anonymous_size
= TYPE_LENGTH (fp
->type ());
14487 SET_FIELD_BITPOS (*fp
,
14488 (FIELD_BITPOS (*fp
)
14489 + anonymous_size
* bits_per_byte
14490 - bit_offset
- FIELD_BITSIZE (*fp
)));
14493 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14495 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14496 + attr
->constant_value (0)));
14498 /* Get name of field. */
14499 fieldname
= dwarf2_name (die
, cu
);
14500 if (fieldname
== NULL
)
14503 /* The name is already allocated along with this objfile, so we don't
14504 need to duplicate it for the type. */
14505 fp
->name
= fieldname
;
14507 /* Change accessibility for artificial fields (e.g. virtual table
14508 pointer or virtual base class pointer) to private. */
14509 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14511 FIELD_ARTIFICIAL (*fp
) = 1;
14512 new_field
->accessibility
= DW_ACCESS_private
;
14513 fip
->non_public_fields
= true;
14516 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14518 /* C++ static member. */
14520 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14521 is a declaration, but all versions of G++ as of this writing
14522 (so through at least 3.2.1) incorrectly generate
14523 DW_TAG_variable tags. */
14525 const char *physname
;
14527 /* Get name of field. */
14528 fieldname
= dwarf2_name (die
, cu
);
14529 if (fieldname
== NULL
)
14532 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14534 /* Only create a symbol if this is an external value.
14535 new_symbol checks this and puts the value in the global symbol
14536 table, which we want. If it is not external, new_symbol
14537 will try to put the value in cu->list_in_scope which is wrong. */
14538 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14540 /* A static const member, not much different than an enum as far as
14541 we're concerned, except that we can support more types. */
14542 new_symbol (die
, NULL
, cu
);
14545 /* Get physical name. */
14546 physname
= dwarf2_physname (fieldname
, die
, cu
);
14548 /* The name is already allocated along with this objfile, so we don't
14549 need to duplicate it for the type. */
14550 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14551 fp
->set_type (die_type (die
, cu
));
14552 FIELD_NAME (*fp
) = fieldname
;
14554 else if (die
->tag
== DW_TAG_inheritance
)
14556 /* C++ base class field. */
14557 handle_data_member_location (die
, cu
, fp
);
14558 FIELD_BITSIZE (*fp
) = 0;
14559 fp
->set_type (die_type (die
, cu
));
14560 FIELD_NAME (*fp
) = fp
->type ()->name ();
14563 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14566 /* Can the type given by DIE define another type? */
14569 type_can_define_types (const struct die_info
*die
)
14573 case DW_TAG_typedef
:
14574 case DW_TAG_class_type
:
14575 case DW_TAG_structure_type
:
14576 case DW_TAG_union_type
:
14577 case DW_TAG_enumeration_type
:
14585 /* Add a type definition defined in the scope of the FIP's class. */
14588 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14589 struct dwarf2_cu
*cu
)
14591 struct decl_field fp
;
14592 memset (&fp
, 0, sizeof (fp
));
14594 gdb_assert (type_can_define_types (die
));
14596 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14597 fp
.name
= dwarf2_name (die
, cu
);
14598 fp
.type
= read_type_die (die
, cu
);
14600 /* Save accessibility. */
14601 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14602 switch (accessibility
)
14604 case DW_ACCESS_public
:
14605 /* The assumed value if neither private nor protected. */
14607 case DW_ACCESS_private
:
14610 case DW_ACCESS_protected
:
14611 fp
.is_protected
= 1;
14615 if (die
->tag
== DW_TAG_typedef
)
14616 fip
->typedef_field_list
.push_back (fp
);
14618 fip
->nested_types_list
.push_back (fp
);
14621 /* A convenience typedef that's used when finding the discriminant
14622 field for a variant part. */
14623 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14626 /* Compute the discriminant range for a given variant. OBSTACK is
14627 where the results will be stored. VARIANT is the variant to
14628 process. IS_UNSIGNED indicates whether the discriminant is signed
14631 static const gdb::array_view
<discriminant_range
>
14632 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14635 std::vector
<discriminant_range
> ranges
;
14637 if (variant
.default_branch
)
14640 if (variant
.discr_list_data
== nullptr)
14642 discriminant_range r
14643 = {variant
.discriminant_value
, variant
.discriminant_value
};
14644 ranges
.push_back (r
);
14648 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14649 variant
.discr_list_data
->size
);
14650 while (!data
.empty ())
14652 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14654 complaint (_("invalid discriminant marker: %d"), data
[0]);
14657 bool is_range
= data
[0] == DW_DSC_range
;
14658 data
= data
.slice (1);
14660 ULONGEST low
, high
;
14661 unsigned int bytes_read
;
14665 complaint (_("DW_AT_discr_list missing low value"));
14669 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14671 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14673 data
= data
.slice (bytes_read
);
14679 complaint (_("DW_AT_discr_list missing high value"));
14683 high
= read_unsigned_leb128 (nullptr, data
.data (),
14686 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14688 data
= data
.slice (bytes_read
);
14693 ranges
.push_back ({ low
, high
});
14697 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14699 std::copy (ranges
.begin (), ranges
.end (), result
);
14700 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14703 static const gdb::array_view
<variant_part
> create_variant_parts
14704 (struct obstack
*obstack
,
14705 const offset_map_type
&offset_map
,
14706 struct field_info
*fi
,
14707 const std::vector
<variant_part_builder
> &variant_parts
);
14709 /* Fill in a "struct variant" for a given variant field. RESULT is
14710 the variant to fill in. OBSTACK is where any needed allocations
14711 will be done. OFFSET_MAP holds the mapping from section offsets to
14712 fields for the type. FI describes the fields of the type we're
14713 processing. FIELD is the variant field we're converting. */
14716 create_one_variant (variant
&result
, struct obstack
*obstack
,
14717 const offset_map_type
&offset_map
,
14718 struct field_info
*fi
, const variant_field
&field
)
14720 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14721 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14722 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14723 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14724 field
.variant_parts
);
14727 /* Fill in a "struct variant_part" for a given variant part. RESULT
14728 is the variant part to fill in. OBSTACK is where any needed
14729 allocations will be done. OFFSET_MAP holds the mapping from
14730 section offsets to fields for the type. FI describes the fields of
14731 the type we're processing. BUILDER is the variant part to be
14735 create_one_variant_part (variant_part
&result
,
14736 struct obstack
*obstack
,
14737 const offset_map_type
&offset_map
,
14738 struct field_info
*fi
,
14739 const variant_part_builder
&builder
)
14741 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14742 if (iter
== offset_map
.end ())
14744 result
.discriminant_index
= -1;
14745 /* Doesn't matter. */
14746 result
.is_unsigned
= false;
14750 result
.discriminant_index
= iter
->second
;
14752 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14755 size_t n
= builder
.variants
.size ();
14756 variant
*output
= new (obstack
) variant
[n
];
14757 for (size_t i
= 0; i
< n
; ++i
)
14758 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14759 builder
.variants
[i
]);
14761 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14764 /* Create a vector of variant parts that can be attached to a type.
14765 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14766 holds the mapping from section offsets to fields for the type. FI
14767 describes the fields of the type we're processing. VARIANT_PARTS
14768 is the vector to convert. */
14770 static const gdb::array_view
<variant_part
>
14771 create_variant_parts (struct obstack
*obstack
,
14772 const offset_map_type
&offset_map
,
14773 struct field_info
*fi
,
14774 const std::vector
<variant_part_builder
> &variant_parts
)
14776 if (variant_parts
.empty ())
14779 size_t n
= variant_parts
.size ();
14780 variant_part
*result
= new (obstack
) variant_part
[n
];
14781 for (size_t i
= 0; i
< n
; ++i
)
14782 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14785 return gdb::array_view
<variant_part
> (result
, n
);
14788 /* Compute the variant part vector for FIP, attaching it to TYPE when
14792 add_variant_property (struct field_info
*fip
, struct type
*type
,
14793 struct dwarf2_cu
*cu
)
14795 /* Map section offsets of fields to their field index. Note the
14796 field index here does not take the number of baseclasses into
14798 offset_map_type offset_map
;
14799 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14800 offset_map
[fip
->fields
[i
].offset
] = i
;
14802 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14803 gdb::array_view
<variant_part
> parts
14804 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14805 fip
->variant_parts
);
14807 struct dynamic_prop prop
;
14808 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14809 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14812 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14815 /* Create the vector of fields, and attach it to the type. */
14818 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14819 struct dwarf2_cu
*cu
)
14821 int nfields
= fip
->nfields ();
14823 /* Record the field count, allocate space for the array of fields,
14824 and create blank accessibility bitfields if necessary. */
14825 type
->set_num_fields (nfields
);
14827 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14829 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14831 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14833 TYPE_FIELD_PRIVATE_BITS (type
) =
14834 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14835 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14837 TYPE_FIELD_PROTECTED_BITS (type
) =
14838 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14839 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14841 TYPE_FIELD_IGNORE_BITS (type
) =
14842 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14843 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14846 /* If the type has baseclasses, allocate and clear a bit vector for
14847 TYPE_FIELD_VIRTUAL_BITS. */
14848 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14850 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14851 unsigned char *pointer
;
14853 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14854 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14855 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14856 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14857 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14860 if (!fip
->variant_parts
.empty ())
14861 add_variant_property (fip
, type
, cu
);
14863 /* Copy the saved-up fields into the field vector. */
14864 for (int i
= 0; i
< nfields
; ++i
)
14866 struct nextfield
&field
14867 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14868 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14870 type
->field (i
) = field
.field
;
14871 switch (field
.accessibility
)
14873 case DW_ACCESS_private
:
14874 if (cu
->language
!= language_ada
)
14875 SET_TYPE_FIELD_PRIVATE (type
, i
);
14878 case DW_ACCESS_protected
:
14879 if (cu
->language
!= language_ada
)
14880 SET_TYPE_FIELD_PROTECTED (type
, i
);
14883 case DW_ACCESS_public
:
14887 /* Unknown accessibility. Complain and treat it as public. */
14889 complaint (_("unsupported accessibility %d"),
14890 field
.accessibility
);
14894 if (i
< fip
->baseclasses
.size ())
14896 switch (field
.virtuality
)
14898 case DW_VIRTUALITY_virtual
:
14899 case DW_VIRTUALITY_pure_virtual
:
14900 if (cu
->language
== language_ada
)
14901 error (_("unexpected virtuality in component of Ada type"));
14902 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14909 /* Return true if this member function is a constructor, false
14913 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14915 const char *fieldname
;
14916 const char *type_name
;
14919 if (die
->parent
== NULL
)
14922 if (die
->parent
->tag
!= DW_TAG_structure_type
14923 && die
->parent
->tag
!= DW_TAG_union_type
14924 && die
->parent
->tag
!= DW_TAG_class_type
)
14927 fieldname
= dwarf2_name (die
, cu
);
14928 type_name
= dwarf2_name (die
->parent
, cu
);
14929 if (fieldname
== NULL
|| type_name
== NULL
)
14932 len
= strlen (fieldname
);
14933 return (strncmp (fieldname
, type_name
, len
) == 0
14934 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14937 /* Add a member function to the proper fieldlist. */
14940 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14941 struct type
*type
, struct dwarf2_cu
*cu
)
14943 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14944 struct attribute
*attr
;
14946 struct fnfieldlist
*flp
= nullptr;
14947 struct fn_field
*fnp
;
14948 const char *fieldname
;
14949 struct type
*this_type
;
14951 if (cu
->language
== language_ada
)
14952 error (_("unexpected member function in Ada type"));
14954 /* Get name of member function. */
14955 fieldname
= dwarf2_name (die
, cu
);
14956 if (fieldname
== NULL
)
14959 /* Look up member function name in fieldlist. */
14960 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14962 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14964 flp
= &fip
->fnfieldlists
[i
];
14969 /* Create a new fnfieldlist if necessary. */
14970 if (flp
== nullptr)
14972 fip
->fnfieldlists
.emplace_back ();
14973 flp
= &fip
->fnfieldlists
.back ();
14974 flp
->name
= fieldname
;
14975 i
= fip
->fnfieldlists
.size () - 1;
14978 /* Create a new member function field and add it to the vector of
14980 flp
->fnfields
.emplace_back ();
14981 fnp
= &flp
->fnfields
.back ();
14983 /* Delay processing of the physname until later. */
14984 if (cu
->language
== language_cplus
)
14985 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14989 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14990 fnp
->physname
= physname
? physname
: "";
14993 fnp
->type
= alloc_type (objfile
);
14994 this_type
= read_type_die (die
, cu
);
14995 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
14997 int nparams
= this_type
->num_fields ();
14999 /* TYPE is the domain of this method, and THIS_TYPE is the type
15000 of the method itself (TYPE_CODE_METHOD). */
15001 smash_to_method_type (fnp
->type
, type
,
15002 TYPE_TARGET_TYPE (this_type
),
15003 this_type
->fields (),
15004 this_type
->num_fields (),
15005 this_type
->has_varargs ());
15007 /* Handle static member functions.
15008 Dwarf2 has no clean way to discern C++ static and non-static
15009 member functions. G++ helps GDB by marking the first
15010 parameter for non-static member functions (which is the this
15011 pointer) as artificial. We obtain this information from
15012 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15013 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15014 fnp
->voffset
= VOFFSET_STATIC
;
15017 complaint (_("member function type missing for '%s'"),
15018 dwarf2_full_name (fieldname
, die
, cu
));
15020 /* Get fcontext from DW_AT_containing_type if present. */
15021 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15022 fnp
->fcontext
= die_containing_type (die
, cu
);
15024 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15025 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15027 /* Get accessibility. */
15028 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15029 switch (accessibility
)
15031 case DW_ACCESS_private
:
15032 fnp
->is_private
= 1;
15034 case DW_ACCESS_protected
:
15035 fnp
->is_protected
= 1;
15039 /* Check for artificial methods. */
15040 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15041 if (attr
&& attr
->as_boolean ())
15042 fnp
->is_artificial
= 1;
15044 /* Check for defaulted methods. */
15045 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15046 if (attr
!= nullptr)
15047 fnp
->defaulted
= attr
->defaulted ();
15049 /* Check for deleted methods. */
15050 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15051 if (attr
!= nullptr && attr
->as_boolean ())
15052 fnp
->is_deleted
= 1;
15054 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15056 /* Get index in virtual function table if it is a virtual member
15057 function. For older versions of GCC, this is an offset in the
15058 appropriate virtual table, as specified by DW_AT_containing_type.
15059 For everyone else, it is an expression to be evaluated relative
15060 to the object address. */
15062 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15063 if (attr
!= nullptr)
15065 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15067 struct dwarf_block
*block
= attr
->as_block ();
15069 if (block
->data
[0] == DW_OP_constu
)
15071 /* Old-style GCC. */
15072 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15074 else if (block
->data
[0] == DW_OP_deref
15075 || (block
->size
> 1
15076 && block
->data
[0] == DW_OP_deref_size
15077 && block
->data
[1] == cu
->header
.addr_size
))
15079 fnp
->voffset
= decode_locdesc (block
, cu
);
15080 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15081 dwarf2_complex_location_expr_complaint ();
15083 fnp
->voffset
/= cu
->header
.addr_size
;
15087 dwarf2_complex_location_expr_complaint ();
15089 if (!fnp
->fcontext
)
15091 /* If there is no `this' field and no DW_AT_containing_type,
15092 we cannot actually find a base class context for the
15094 if (this_type
->num_fields () == 0
15095 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15097 complaint (_("cannot determine context for virtual member "
15098 "function \"%s\" (offset %s)"),
15099 fieldname
, sect_offset_str (die
->sect_off
));
15104 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15108 else if (attr
->form_is_section_offset ())
15110 dwarf2_complex_location_expr_complaint ();
15114 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15120 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15121 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15123 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15124 complaint (_("Member function \"%s\" (offset %s) is virtual "
15125 "but the vtable offset is not specified"),
15126 fieldname
, sect_offset_str (die
->sect_off
));
15127 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15128 TYPE_CPLUS_DYNAMIC (type
) = 1;
15133 /* Create the vector of member function fields, and attach it to the type. */
15136 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15137 struct dwarf2_cu
*cu
)
15139 if (cu
->language
== language_ada
)
15140 error (_("unexpected member functions in Ada type"));
15142 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15143 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15145 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15147 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15149 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15150 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15152 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15153 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15154 fn_flp
->fn_fields
= (struct fn_field
*)
15155 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15157 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15158 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15161 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15164 /* Returns non-zero if NAME is the name of a vtable member in CU's
15165 language, zero otherwise. */
15167 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15169 static const char vptr
[] = "_vptr";
15171 /* Look for the C++ form of the vtable. */
15172 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15178 /* GCC outputs unnamed structures that are really pointers to member
15179 functions, with the ABI-specified layout. If TYPE describes
15180 such a structure, smash it into a member function type.
15182 GCC shouldn't do this; it should just output pointer to member DIEs.
15183 This is GCC PR debug/28767. */
15186 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15188 struct type
*pfn_type
, *self_type
, *new_type
;
15190 /* Check for a structure with no name and two children. */
15191 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15194 /* Check for __pfn and __delta members. */
15195 if (TYPE_FIELD_NAME (type
, 0) == NULL
15196 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15197 || TYPE_FIELD_NAME (type
, 1) == NULL
15198 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15201 /* Find the type of the method. */
15202 pfn_type
= type
->field (0).type ();
15203 if (pfn_type
== NULL
15204 || pfn_type
->code () != TYPE_CODE_PTR
15205 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15208 /* Look for the "this" argument. */
15209 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15210 if (pfn_type
->num_fields () == 0
15211 /* || pfn_type->field (0).type () == NULL */
15212 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15215 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15216 new_type
= alloc_type (objfile
);
15217 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15218 pfn_type
->fields (), pfn_type
->num_fields (),
15219 pfn_type
->has_varargs ());
15220 smash_to_methodptr_type (type
, new_type
);
15223 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15224 requires rewriting, then copy it and return the updated copy.
15225 Otherwise return nullptr. */
15227 static struct type
*
15228 rewrite_array_type (struct type
*type
)
15230 if (type
->code () != TYPE_CODE_ARRAY
)
15233 struct type
*index_type
= type
->index_type ();
15234 range_bounds
*current_bounds
= index_type
->bounds ();
15236 /* Handle multi-dimensional arrays. */
15237 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15238 if (new_target
== nullptr)
15240 /* Maybe we don't need to rewrite this array. */
15241 if (current_bounds
->low
.kind () == PROP_CONST
15242 && current_bounds
->high
.kind () == PROP_CONST
)
15246 /* Either the target type was rewritten, or the bounds have to be
15247 updated. Either way we want to copy the type and update
15249 struct type
*copy
= copy_type (type
);
15250 int nfields
= copy
->num_fields ();
15252 = ((struct field
*) TYPE_ZALLOC (copy
,
15253 nfields
* sizeof (struct field
)));
15254 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15255 copy
->set_fields (new_fields
);
15256 if (new_target
!= nullptr)
15257 TYPE_TARGET_TYPE (copy
) = new_target
;
15259 struct type
*index_copy
= copy_type (index_type
);
15260 range_bounds
*bounds
15261 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15262 sizeof (range_bounds
));
15263 *bounds
= *current_bounds
;
15264 bounds
->low
.set_const_val (1);
15265 bounds
->high
.set_const_val (0);
15266 index_copy
->set_bounds (bounds
);
15267 copy
->set_index_type (index_copy
);
15272 /* While some versions of GCC will generate complicated DWARF for an
15273 array (see quirk_ada_thick_pointer), more recent versions were
15274 modified to emit an explicit thick pointer structure. However, in
15275 this case, the array still has DWARF expressions for its ranges,
15276 and these must be ignored. */
15279 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15282 gdb_assert (cu
->language
== language_ada
);
15284 /* Check for a structure with two children. */
15285 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15288 /* Check for P_ARRAY and P_BOUNDS members. */
15289 if (TYPE_FIELD_NAME (type
, 0) == NULL
15290 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15291 || TYPE_FIELD_NAME (type
, 1) == NULL
15292 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15295 /* Make sure we're looking at a pointer to an array. */
15296 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15299 /* The Ada code already knows how to handle these types, so all that
15300 we need to do is turn the bounds into static bounds. However, we
15301 don't want to rewrite existing array or index types in-place,
15302 because those may be referenced in other contexts where this
15303 rewriting is undesirable. */
15304 struct type
*new_ary_type
15305 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15306 if (new_ary_type
!= nullptr)
15307 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15310 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15311 appropriate error checking and issuing complaints if there is a
15315 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15317 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15319 if (attr
== nullptr)
15322 if (!attr
->form_is_constant ())
15324 complaint (_("DW_AT_alignment must have constant form"
15325 " - DIE at %s [in module %s]"),
15326 sect_offset_str (die
->sect_off
),
15327 objfile_name (cu
->per_objfile
->objfile
));
15331 LONGEST val
= attr
->constant_value (0);
15334 complaint (_("DW_AT_alignment value must not be negative"
15335 " - DIE at %s [in module %s]"),
15336 sect_offset_str (die
->sect_off
),
15337 objfile_name (cu
->per_objfile
->objfile
));
15340 ULONGEST align
= val
;
15344 complaint (_("DW_AT_alignment value must not be zero"
15345 " - DIE at %s [in module %s]"),
15346 sect_offset_str (die
->sect_off
),
15347 objfile_name (cu
->per_objfile
->objfile
));
15350 if ((align
& (align
- 1)) != 0)
15352 complaint (_("DW_AT_alignment value must be a power of 2"
15353 " - DIE at %s [in module %s]"),
15354 sect_offset_str (die
->sect_off
),
15355 objfile_name (cu
->per_objfile
->objfile
));
15362 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15363 the alignment for TYPE. */
15366 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15369 if (!set_type_align (type
, get_alignment (cu
, die
)))
15370 complaint (_("DW_AT_alignment value too large"
15371 " - DIE at %s [in module %s]"),
15372 sect_offset_str (die
->sect_off
),
15373 objfile_name (cu
->per_objfile
->objfile
));
15376 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15377 constant for a type, according to DWARF5 spec, Table 5.5. */
15380 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15385 case DW_CC_pass_by_reference
:
15386 case DW_CC_pass_by_value
:
15390 complaint (_("unrecognized DW_AT_calling_convention value "
15391 "(%s) for a type"), pulongest (value
));
15396 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15397 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15398 also according to GNU-specific values (see include/dwarf2.h). */
15401 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15406 case DW_CC_program
:
15410 case DW_CC_GNU_renesas_sh
:
15411 case DW_CC_GNU_borland_fastcall_i386
:
15412 case DW_CC_GDB_IBM_OpenCL
:
15416 complaint (_("unrecognized DW_AT_calling_convention value "
15417 "(%s) for a subroutine"), pulongest (value
));
15422 /* Called when we find the DIE that starts a structure or union scope
15423 (definition) to create a type for the structure or union. Fill in
15424 the type's name and general properties; the members will not be
15425 processed until process_structure_scope. A symbol table entry for
15426 the type will also not be done until process_structure_scope (assuming
15427 the type has a name).
15429 NOTE: we need to call these functions regardless of whether or not the
15430 DIE has a DW_AT_name attribute, since it might be an anonymous
15431 structure or union. This gets the type entered into our set of
15432 user defined types. */
15434 static struct type
*
15435 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15437 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15439 struct attribute
*attr
;
15442 /* If the definition of this type lives in .debug_types, read that type.
15443 Don't follow DW_AT_specification though, that will take us back up
15444 the chain and we want to go down. */
15445 attr
= die
->attr (DW_AT_signature
);
15446 if (attr
!= nullptr)
15448 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15450 /* The type's CU may not be the same as CU.
15451 Ensure TYPE is recorded with CU in die_type_hash. */
15452 return set_die_type (die
, type
, cu
);
15455 type
= alloc_type (objfile
);
15456 INIT_CPLUS_SPECIFIC (type
);
15458 name
= dwarf2_name (die
, cu
);
15461 if (cu
->language
== language_cplus
15462 || cu
->language
== language_d
15463 || cu
->language
== language_rust
)
15465 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15467 /* dwarf2_full_name might have already finished building the DIE's
15468 type. If so, there is no need to continue. */
15469 if (get_die_type (die
, cu
) != NULL
)
15470 return get_die_type (die
, cu
);
15472 type
->set_name (full_name
);
15476 /* The name is already allocated along with this objfile, so
15477 we don't need to duplicate it for the type. */
15478 type
->set_name (name
);
15482 if (die
->tag
== DW_TAG_structure_type
)
15484 type
->set_code (TYPE_CODE_STRUCT
);
15486 else if (die
->tag
== DW_TAG_union_type
)
15488 type
->set_code (TYPE_CODE_UNION
);
15492 type
->set_code (TYPE_CODE_STRUCT
);
15495 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15496 type
->set_is_declared_class (true);
15498 /* Store the calling convention in the type if it's available in
15499 the die. Otherwise the calling convention remains set to
15500 the default value DW_CC_normal. */
15501 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15502 if (attr
!= nullptr
15503 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15505 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15506 TYPE_CPLUS_CALLING_CONVENTION (type
)
15507 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15510 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15511 if (attr
!= nullptr)
15513 if (attr
->form_is_constant ())
15514 TYPE_LENGTH (type
) = attr
->constant_value (0);
15517 struct dynamic_prop prop
;
15518 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15519 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15520 TYPE_LENGTH (type
) = 0;
15525 TYPE_LENGTH (type
) = 0;
15528 maybe_set_alignment (cu
, die
, type
);
15530 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15532 /* ICC<14 does not output the required DW_AT_declaration on
15533 incomplete types, but gives them a size of zero. */
15534 type
->set_is_stub (true);
15537 type
->set_stub_is_supported (true);
15539 if (die_is_declaration (die
, cu
))
15540 type
->set_is_stub (true);
15541 else if (attr
== NULL
&& die
->child
== NULL
15542 && producer_is_realview (cu
->producer
))
15543 /* RealView does not output the required DW_AT_declaration
15544 on incomplete types. */
15545 type
->set_is_stub (true);
15547 /* We need to add the type field to the die immediately so we don't
15548 infinitely recurse when dealing with pointers to the structure
15549 type within the structure itself. */
15550 set_die_type (die
, type
, cu
);
15552 /* set_die_type should be already done. */
15553 set_descriptive_type (type
, die
, cu
);
15558 static void handle_struct_member_die
15559 (struct die_info
*child_die
,
15561 struct field_info
*fi
,
15562 std::vector
<struct symbol
*> *template_args
,
15563 struct dwarf2_cu
*cu
);
15565 /* A helper for handle_struct_member_die that handles
15566 DW_TAG_variant_part. */
15569 handle_variant_part (struct die_info
*die
, struct type
*type
,
15570 struct field_info
*fi
,
15571 std::vector
<struct symbol
*> *template_args
,
15572 struct dwarf2_cu
*cu
)
15574 variant_part_builder
*new_part
;
15575 if (fi
->current_variant_part
== nullptr)
15577 fi
->variant_parts
.emplace_back ();
15578 new_part
= &fi
->variant_parts
.back ();
15580 else if (!fi
->current_variant_part
->processing_variant
)
15582 complaint (_("nested DW_TAG_variant_part seen "
15583 "- DIE at %s [in module %s]"),
15584 sect_offset_str (die
->sect_off
),
15585 objfile_name (cu
->per_objfile
->objfile
));
15590 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15591 current
.variant_parts
.emplace_back ();
15592 new_part
= ¤t
.variant_parts
.back ();
15595 /* When we recurse, we want callees to add to this new variant
15597 scoped_restore save_current_variant_part
15598 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15600 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15603 /* It's a univariant form, an extension we support. */
15605 else if (discr
->form_is_ref ())
15607 struct dwarf2_cu
*target_cu
= cu
;
15608 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15610 new_part
->discriminant_offset
= target_die
->sect_off
;
15614 complaint (_("DW_AT_discr does not have DIE reference form"
15615 " - DIE at %s [in module %s]"),
15616 sect_offset_str (die
->sect_off
),
15617 objfile_name (cu
->per_objfile
->objfile
));
15620 for (die_info
*child_die
= die
->child
;
15622 child_die
= child_die
->sibling
)
15623 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15626 /* A helper for handle_struct_member_die that handles
15630 handle_variant (struct die_info
*die
, struct type
*type
,
15631 struct field_info
*fi
,
15632 std::vector
<struct symbol
*> *template_args
,
15633 struct dwarf2_cu
*cu
)
15635 if (fi
->current_variant_part
== nullptr)
15637 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15638 "- DIE at %s [in module %s]"),
15639 sect_offset_str (die
->sect_off
),
15640 objfile_name (cu
->per_objfile
->objfile
));
15643 if (fi
->current_variant_part
->processing_variant
)
15645 complaint (_("nested DW_TAG_variant seen "
15646 "- DIE at %s [in module %s]"),
15647 sect_offset_str (die
->sect_off
),
15648 objfile_name (cu
->per_objfile
->objfile
));
15652 scoped_restore save_processing_variant
15653 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15656 fi
->current_variant_part
->variants
.emplace_back ();
15657 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15658 variant
.first_field
= fi
->fields
.size ();
15660 /* In a variant we want to get the discriminant and also add a
15661 field for our sole member child. */
15662 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15663 if (discr
== nullptr || !discr
->form_is_constant ())
15665 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15666 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15667 variant
.default_branch
= true;
15669 variant
.discr_list_data
= discr
->as_block ();
15672 variant
.discriminant_value
= discr
->constant_value (0);
15674 for (die_info
*variant_child
= die
->child
;
15675 variant_child
!= NULL
;
15676 variant_child
= variant_child
->sibling
)
15677 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15679 variant
.last_field
= fi
->fields
.size ();
15682 /* A helper for process_structure_scope that handles a single member
15686 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15687 struct field_info
*fi
,
15688 std::vector
<struct symbol
*> *template_args
,
15689 struct dwarf2_cu
*cu
)
15691 if (child_die
->tag
== DW_TAG_member
15692 || child_die
->tag
== DW_TAG_variable
)
15694 /* NOTE: carlton/2002-11-05: A C++ static data member
15695 should be a DW_TAG_member that is a declaration, but
15696 all versions of G++ as of this writing (so through at
15697 least 3.2.1) incorrectly generate DW_TAG_variable
15698 tags for them instead. */
15699 dwarf2_add_field (fi
, child_die
, cu
);
15701 else if (child_die
->tag
== DW_TAG_subprogram
)
15703 /* Rust doesn't have member functions in the C++ sense.
15704 However, it does emit ordinary functions as children
15705 of a struct DIE. */
15706 if (cu
->language
== language_rust
)
15707 read_func_scope (child_die
, cu
);
15710 /* C++ member function. */
15711 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15714 else if (child_die
->tag
== DW_TAG_inheritance
)
15716 /* C++ base class field. */
15717 dwarf2_add_field (fi
, child_die
, cu
);
15719 else if (type_can_define_types (child_die
))
15720 dwarf2_add_type_defn (fi
, child_die
, cu
);
15721 else if (child_die
->tag
== DW_TAG_template_type_param
15722 || child_die
->tag
== DW_TAG_template_value_param
)
15724 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15727 template_args
->push_back (arg
);
15729 else if (child_die
->tag
== DW_TAG_variant_part
)
15730 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15731 else if (child_die
->tag
== DW_TAG_variant
)
15732 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15735 /* Finish creating a structure or union type, including filling in
15736 its members and creating a symbol for it. */
15739 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15741 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15742 struct die_info
*child_die
;
15745 type
= get_die_type (die
, cu
);
15747 type
= read_structure_type (die
, cu
);
15749 bool has_template_parameters
= false;
15750 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15752 struct field_info fi
;
15753 std::vector
<struct symbol
*> template_args
;
15755 child_die
= die
->child
;
15757 while (child_die
&& child_die
->tag
)
15759 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15760 child_die
= child_die
->sibling
;
15763 /* Attach template arguments to type. */
15764 if (!template_args
.empty ())
15766 has_template_parameters
= true;
15767 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15768 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15769 TYPE_TEMPLATE_ARGUMENTS (type
)
15770 = XOBNEWVEC (&objfile
->objfile_obstack
,
15772 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15773 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15774 template_args
.data (),
15775 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15776 * sizeof (struct symbol
*)));
15779 /* Attach fields and member functions to the type. */
15780 if (fi
.nfields () > 0)
15781 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15782 if (!fi
.fnfieldlists
.empty ())
15784 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15786 /* Get the type which refers to the base class (possibly this
15787 class itself) which contains the vtable pointer for the current
15788 class from the DW_AT_containing_type attribute. This use of
15789 DW_AT_containing_type is a GNU extension. */
15791 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15793 struct type
*t
= die_containing_type (die
, cu
);
15795 set_type_vptr_basetype (type
, t
);
15800 /* Our own class provides vtbl ptr. */
15801 for (i
= t
->num_fields () - 1;
15802 i
>= TYPE_N_BASECLASSES (t
);
15805 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15807 if (is_vtable_name (fieldname
, cu
))
15809 set_type_vptr_fieldno (type
, i
);
15814 /* Complain if virtual function table field not found. */
15815 if (i
< TYPE_N_BASECLASSES (t
))
15816 complaint (_("virtual function table pointer "
15817 "not found when defining class '%s'"),
15818 type
->name () ? type
->name () : "");
15822 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15825 else if (cu
->producer
15826 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15828 /* The IBM XLC compiler does not provide direct indication
15829 of the containing type, but the vtable pointer is
15830 always named __vfp. */
15834 for (i
= type
->num_fields () - 1;
15835 i
>= TYPE_N_BASECLASSES (type
);
15838 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15840 set_type_vptr_fieldno (type
, i
);
15841 set_type_vptr_basetype (type
, type
);
15848 /* Copy fi.typedef_field_list linked list elements content into the
15849 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15850 if (!fi
.typedef_field_list
.empty ())
15852 int count
= fi
.typedef_field_list
.size ();
15854 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15855 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15856 = ((struct decl_field
*)
15858 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15859 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15861 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15862 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15865 /* Copy fi.nested_types_list linked list elements content into the
15866 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15867 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15869 int count
= fi
.nested_types_list
.size ();
15871 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15872 TYPE_NESTED_TYPES_ARRAY (type
)
15873 = ((struct decl_field
*)
15874 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15875 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15877 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15878 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15882 quirk_gcc_member_function_pointer (type
, objfile
);
15883 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15884 cu
->rust_unions
.push_back (type
);
15885 else if (cu
->language
== language_ada
)
15886 quirk_ada_thick_pointer_struct (die
, cu
, type
);
15888 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15889 snapshots) has been known to create a die giving a declaration
15890 for a class that has, as a child, a die giving a definition for a
15891 nested class. So we have to process our children even if the
15892 current die is a declaration. Normally, of course, a declaration
15893 won't have any children at all. */
15895 child_die
= die
->child
;
15897 while (child_die
!= NULL
&& child_die
->tag
)
15899 if (child_die
->tag
== DW_TAG_member
15900 || child_die
->tag
== DW_TAG_variable
15901 || child_die
->tag
== DW_TAG_inheritance
15902 || child_die
->tag
== DW_TAG_template_value_param
15903 || child_die
->tag
== DW_TAG_template_type_param
)
15908 process_die (child_die
, cu
);
15910 child_die
= child_die
->sibling
;
15913 /* Do not consider external references. According to the DWARF standard,
15914 these DIEs are identified by the fact that they have no byte_size
15915 attribute, and a declaration attribute. */
15916 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15917 || !die_is_declaration (die
, cu
)
15918 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15920 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15922 if (has_template_parameters
)
15924 struct symtab
*symtab
;
15925 if (sym
!= nullptr)
15926 symtab
= symbol_symtab (sym
);
15927 else if (cu
->line_header
!= nullptr)
15929 /* Any related symtab will do. */
15931 = cu
->line_header
->file_names ()[0].symtab
;
15936 complaint (_("could not find suitable "
15937 "symtab for template parameter"
15938 " - DIE at %s [in module %s]"),
15939 sect_offset_str (die
->sect_off
),
15940 objfile_name (objfile
));
15943 if (symtab
!= nullptr)
15945 /* Make sure that the symtab is set on the new symbols.
15946 Even though they don't appear in this symtab directly,
15947 other parts of gdb assume that symbols do, and this is
15948 reasonably true. */
15949 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15950 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15956 /* Assuming DIE is an enumeration type, and TYPE is its associated
15957 type, update TYPE using some information only available in DIE's
15958 children. In particular, the fields are computed. */
15961 update_enumeration_type_from_children (struct die_info
*die
,
15963 struct dwarf2_cu
*cu
)
15965 struct die_info
*child_die
;
15966 int unsigned_enum
= 1;
15969 auto_obstack obstack
;
15970 std::vector
<struct field
> fields
;
15972 for (child_die
= die
->child
;
15973 child_die
!= NULL
&& child_die
->tag
;
15974 child_die
= child_die
->sibling
)
15976 struct attribute
*attr
;
15978 const gdb_byte
*bytes
;
15979 struct dwarf2_locexpr_baton
*baton
;
15982 if (child_die
->tag
!= DW_TAG_enumerator
)
15985 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15989 name
= dwarf2_name (child_die
, cu
);
15991 name
= "<anonymous enumerator>";
15993 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15994 &value
, &bytes
, &baton
);
16002 if (count_one_bits_ll (value
) >= 2)
16006 fields
.emplace_back ();
16007 struct field
&field
= fields
.back ();
16008 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16009 SET_FIELD_ENUMVAL (field
, value
);
16012 if (!fields
.empty ())
16014 type
->set_num_fields (fields
.size ());
16017 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16018 memcpy (type
->fields (), fields
.data (),
16019 sizeof (struct field
) * fields
.size ());
16023 type
->set_is_unsigned (true);
16026 type
->set_is_flag_enum (true);
16029 /* Given a DW_AT_enumeration_type die, set its type. We do not
16030 complete the type's fields yet, or create any symbols. */
16032 static struct type
*
16033 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16035 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16037 struct attribute
*attr
;
16040 /* If the definition of this type lives in .debug_types, read that type.
16041 Don't follow DW_AT_specification though, that will take us back up
16042 the chain and we want to go down. */
16043 attr
= die
->attr (DW_AT_signature
);
16044 if (attr
!= nullptr)
16046 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16048 /* The type's CU may not be the same as CU.
16049 Ensure TYPE is recorded with CU in die_type_hash. */
16050 return set_die_type (die
, type
, cu
);
16053 type
= alloc_type (objfile
);
16055 type
->set_code (TYPE_CODE_ENUM
);
16056 name
= dwarf2_full_name (NULL
, die
, cu
);
16058 type
->set_name (name
);
16060 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16063 struct type
*underlying_type
= die_type (die
, cu
);
16065 TYPE_TARGET_TYPE (type
) = underlying_type
;
16068 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16069 if (attr
!= nullptr)
16071 TYPE_LENGTH (type
) = attr
->constant_value (0);
16075 TYPE_LENGTH (type
) = 0;
16078 maybe_set_alignment (cu
, die
, type
);
16080 /* The enumeration DIE can be incomplete. In Ada, any type can be
16081 declared as private in the package spec, and then defined only
16082 inside the package body. Such types are known as Taft Amendment
16083 Types. When another package uses such a type, an incomplete DIE
16084 may be generated by the compiler. */
16085 if (die_is_declaration (die
, cu
))
16086 type
->set_is_stub (true);
16088 /* If this type has an underlying type that is not a stub, then we
16089 may use its attributes. We always use the "unsigned" attribute
16090 in this situation, because ordinarily we guess whether the type
16091 is unsigned -- but the guess can be wrong and the underlying type
16092 can tell us the reality. However, we defer to a local size
16093 attribute if one exists, because this lets the compiler override
16094 the underlying type if needed. */
16095 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16097 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16098 underlying_type
= check_typedef (underlying_type
);
16100 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16102 if (TYPE_LENGTH (type
) == 0)
16103 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16105 if (TYPE_RAW_ALIGN (type
) == 0
16106 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16107 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16110 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16112 set_die_type (die
, type
, cu
);
16114 /* Finish the creation of this type by using the enum's children.
16115 Note that, as usual, this must come after set_die_type to avoid
16116 infinite recursion when trying to compute the names of the
16118 update_enumeration_type_from_children (die
, type
, cu
);
16123 /* Given a pointer to a die which begins an enumeration, process all
16124 the dies that define the members of the enumeration, and create the
16125 symbol for the enumeration type.
16127 NOTE: We reverse the order of the element list. */
16130 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16132 struct type
*this_type
;
16134 this_type
= get_die_type (die
, cu
);
16135 if (this_type
== NULL
)
16136 this_type
= read_enumeration_type (die
, cu
);
16138 if (die
->child
!= NULL
)
16140 struct die_info
*child_die
;
16143 child_die
= die
->child
;
16144 while (child_die
&& child_die
->tag
)
16146 if (child_die
->tag
!= DW_TAG_enumerator
)
16148 process_die (child_die
, cu
);
16152 name
= dwarf2_name (child_die
, cu
);
16154 new_symbol (child_die
, this_type
, cu
);
16157 child_die
= child_die
->sibling
;
16161 /* If we are reading an enum from a .debug_types unit, and the enum
16162 is a declaration, and the enum is not the signatured type in the
16163 unit, then we do not want to add a symbol for it. Adding a
16164 symbol would in some cases obscure the true definition of the
16165 enum, giving users an incomplete type when the definition is
16166 actually available. Note that we do not want to do this for all
16167 enums which are just declarations, because C++0x allows forward
16168 enum declarations. */
16169 if (cu
->per_cu
->is_debug_types
16170 && die_is_declaration (die
, cu
))
16172 struct signatured_type
*sig_type
;
16174 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16175 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16176 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16180 new_symbol (die
, this_type
, cu
);
16183 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16184 expression for an index type and finds the corresponding field
16185 offset in the hidden "P_BOUNDS" structure. Returns true on success
16186 and updates *FIELD, false if it fails to recognize an
16190 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16191 int *bounds_offset
, struct field
*field
,
16192 struct dwarf2_cu
*cu
)
16194 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16195 if (attr
== nullptr || !attr
->form_is_block ())
16198 const struct dwarf_block
*block
= attr
->as_block ();
16199 const gdb_byte
*start
= block
->data
;
16200 const gdb_byte
*end
= block
->data
+ block
->size
;
16202 /* The expression to recognize generally looks like:
16204 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16205 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16207 However, the second "plus_uconst" may be missing:
16209 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16210 DW_OP_deref_size: 4)
16212 This happens when the field is at the start of the structure.
16214 Also, the final deref may not be sized:
16216 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16219 This happens when the size of the index type happens to be the
16220 same as the architecture's word size. This can occur with or
16221 without the second plus_uconst. */
16223 if (end
- start
< 2)
16225 if (*start
++ != DW_OP_push_object_address
)
16227 if (*start
++ != DW_OP_plus_uconst
)
16230 uint64_t this_bound_off
;
16231 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16232 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16234 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16235 is consistent among all bounds. */
16236 if (*bounds_offset
== -1)
16237 *bounds_offset
= this_bound_off
;
16238 else if (*bounds_offset
!= this_bound_off
)
16241 if (start
== end
|| *start
++ != DW_OP_deref
)
16247 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16249 /* This means an offset of 0. */
16251 else if (*start
++ != DW_OP_plus_uconst
)
16255 /* The size is the parameter to DW_OP_plus_uconst. */
16257 start
= gdb_read_uleb128 (start
, end
, &val
);
16258 if (start
== nullptr)
16260 if ((int) val
!= val
)
16269 if (*start
== DW_OP_deref_size
)
16271 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16272 if (start
== nullptr)
16275 else if (*start
== DW_OP_deref
)
16277 size
= cu
->header
.addr_size
;
16283 SET_FIELD_BITPOS (*field
, 8 * offset
);
16284 if (size
!= TYPE_LENGTH (field
->type ()))
16285 FIELD_BITSIZE (*field
) = 8 * size
;
16290 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16291 some kinds of Ada arrays:
16293 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16294 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16295 <11e0> DW_AT_data_location: 2 byte block: 97 6
16296 (DW_OP_push_object_address; DW_OP_deref)
16297 <11e3> DW_AT_type : <0x1173>
16298 <11e7> DW_AT_sibling : <0x1201>
16299 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16300 <11ec> DW_AT_type : <0x1206>
16301 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16302 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16303 DW_OP_deref_size: 4)
16304 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16305 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16306 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16308 This actually represents a "thick pointer", which is a structure
16309 with two elements: one that is a pointer to the array data, and one
16310 that is a pointer to another structure; this second structure holds
16313 This returns a new type on success, or nullptr if this didn't
16314 recognize the type. */
16316 static struct type
*
16317 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16320 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16321 /* So far we've only seen this with block form. */
16322 if (attr
== nullptr || !attr
->form_is_block ())
16325 /* Note that this will fail if the structure layout is changed by
16326 the compiler. However, we have no good way to recognize some
16327 other layout, because we don't know what expression the compiler
16328 might choose to emit should this happen. */
16329 struct dwarf_block
*blk
= attr
->as_block ();
16331 || blk
->data
[0] != DW_OP_push_object_address
16332 || blk
->data
[1] != DW_OP_deref
)
16335 int bounds_offset
= -1;
16336 int max_align
= -1;
16337 std::vector
<struct field
> range_fields
;
16338 for (struct die_info
*child_die
= die
->child
;
16340 child_die
= child_die
->sibling
)
16342 if (child_die
->tag
== DW_TAG_subrange_type
)
16344 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16346 int this_align
= type_align (underlying
);
16347 if (this_align
> max_align
)
16348 max_align
= this_align
;
16350 range_fields
.emplace_back ();
16351 range_fields
.emplace_back ();
16353 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16354 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16356 lower
.set_type (underlying
);
16357 FIELD_ARTIFICIAL (lower
) = 1;
16359 upper
.set_type (underlying
);
16360 FIELD_ARTIFICIAL (upper
) = 1;
16362 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16363 &bounds_offset
, &lower
, cu
)
16364 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16365 &bounds_offset
, &upper
, cu
))
16370 /* This shouldn't really happen, but double-check that we found
16371 where the bounds are stored. */
16372 if (bounds_offset
== -1)
16375 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16376 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16380 /* Set the name of each field in the bounds. */
16381 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16382 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16383 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16384 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16387 struct type
*bounds
= alloc_type (objfile
);
16388 bounds
->set_code (TYPE_CODE_STRUCT
);
16390 bounds
->set_num_fields (range_fields
.size ());
16392 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16393 * sizeof (struct field
))));
16394 memcpy (bounds
->fields (), range_fields
.data (),
16395 bounds
->num_fields () * sizeof (struct field
));
16397 int last_fieldno
= range_fields
.size () - 1;
16398 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16399 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16400 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16402 /* Rewrite the existing array type in place. Specifically, we
16403 remove any dynamic properties we might have read, and we replace
16404 the index types. */
16405 struct type
*iter
= type
;
16406 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16408 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16409 iter
->main_type
->dyn_prop_list
= nullptr;
16410 iter
->set_index_type
16411 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16412 iter
= TYPE_TARGET_TYPE (iter
);
16415 struct type
*result
= alloc_type (objfile
);
16416 result
->set_code (TYPE_CODE_STRUCT
);
16418 result
->set_num_fields (2);
16420 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16421 * sizeof (struct field
))));
16423 /* The names are chosen to coincide with what the compiler does with
16424 -fgnat-encodings=all, which the Ada code in gdb already
16426 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16427 result
->field (0).set_type (lookup_pointer_type (type
));
16429 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16430 result
->field (1).set_type (lookup_pointer_type (bounds
));
16431 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16433 result
->set_name (type
->name ());
16434 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16435 + TYPE_LENGTH (result
->field (1).type ()));
16440 /* Extract all information from a DW_TAG_array_type DIE and put it in
16441 the DIE's type field. For now, this only handles one dimensional
16444 static struct type
*
16445 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16447 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16448 struct die_info
*child_die
;
16450 struct type
*element_type
, *range_type
, *index_type
;
16451 struct attribute
*attr
;
16453 struct dynamic_prop
*byte_stride_prop
= NULL
;
16454 unsigned int bit_stride
= 0;
16456 element_type
= die_type (die
, cu
);
16458 /* The die_type call above may have already set the type for this DIE. */
16459 type
= get_die_type (die
, cu
);
16463 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16467 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16470 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16471 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16475 complaint (_("unable to read array DW_AT_byte_stride "
16476 " - DIE at %s [in module %s]"),
16477 sect_offset_str (die
->sect_off
),
16478 objfile_name (cu
->per_objfile
->objfile
));
16479 /* Ignore this attribute. We will likely not be able to print
16480 arrays of this type correctly, but there is little we can do
16481 to help if we cannot read the attribute's value. */
16482 byte_stride_prop
= NULL
;
16486 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16488 bit_stride
= attr
->constant_value (0);
16490 /* Irix 6.2 native cc creates array types without children for
16491 arrays with unspecified length. */
16492 if (die
->child
== NULL
)
16494 index_type
= objfile_type (objfile
)->builtin_int
;
16495 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16496 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16497 byte_stride_prop
, bit_stride
);
16498 return set_die_type (die
, type
, cu
);
16501 std::vector
<struct type
*> range_types
;
16502 child_die
= die
->child
;
16503 while (child_die
&& child_die
->tag
)
16505 if (child_die
->tag
== DW_TAG_subrange_type
)
16507 struct type
*child_type
= read_type_die (child_die
, cu
);
16509 if (child_type
!= NULL
)
16511 /* The range type was succesfully read. Save it for the
16512 array type creation. */
16513 range_types
.push_back (child_type
);
16516 child_die
= child_die
->sibling
;
16519 if (range_types
.empty ())
16521 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16522 sect_offset_str (die
->sect_off
),
16523 objfile_name (cu
->per_objfile
->objfile
));
16527 /* Dwarf2 dimensions are output from left to right, create the
16528 necessary array types in backwards order. */
16530 type
= element_type
;
16532 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16536 while (i
< range_types
.size ())
16538 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16539 byte_stride_prop
, bit_stride
);
16541 byte_stride_prop
= nullptr;
16546 size_t ndim
= range_types
.size ();
16549 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16550 byte_stride_prop
, bit_stride
);
16552 byte_stride_prop
= nullptr;
16556 gdb_assert (type
!= element_type
);
16558 /* Understand Dwarf2 support for vector types (like they occur on
16559 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16560 array type. This is not part of the Dwarf2/3 standard yet, but a
16561 custom vendor extension. The main difference between a regular
16562 array and the vector variant is that vectors are passed by value
16564 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16565 if (attr
!= nullptr)
16566 make_vector_type (type
);
16568 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16569 implementation may choose to implement triple vectors using this
16571 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16572 if (attr
!= nullptr && attr
->form_is_unsigned ())
16574 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16575 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16577 complaint (_("DW_AT_byte_size for array type smaller "
16578 "than the total size of elements"));
16581 name
= dwarf2_name (die
, cu
);
16583 type
->set_name (name
);
16585 maybe_set_alignment (cu
, die
, type
);
16587 struct type
*replacement_type
= nullptr;
16588 if (cu
->language
== language_ada
)
16590 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16591 if (replacement_type
!= nullptr)
16592 type
= replacement_type
;
16595 /* Install the type in the die. */
16596 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16598 /* set_die_type should be already done. */
16599 set_descriptive_type (type
, die
, cu
);
16604 static enum dwarf_array_dim_ordering
16605 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16607 struct attribute
*attr
;
16609 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16611 if (attr
!= nullptr)
16613 LONGEST val
= attr
->constant_value (-1);
16614 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16615 return (enum dwarf_array_dim_ordering
) val
;
16618 /* GNU F77 is a special case, as at 08/2004 array type info is the
16619 opposite order to the dwarf2 specification, but data is still
16620 laid out as per normal fortran.
16622 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16623 version checking. */
16625 if (cu
->language
== language_fortran
16626 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16628 return DW_ORD_row_major
;
16631 switch (cu
->language_defn
->array_ordering ())
16633 case array_column_major
:
16634 return DW_ORD_col_major
;
16635 case array_row_major
:
16637 return DW_ORD_row_major
;
16641 /* Extract all information from a DW_TAG_set_type DIE and put it in
16642 the DIE's type field. */
16644 static struct type
*
16645 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16647 struct type
*domain_type
, *set_type
;
16648 struct attribute
*attr
;
16650 domain_type
= die_type (die
, cu
);
16652 /* The die_type call above may have already set the type for this DIE. */
16653 set_type
= get_die_type (die
, cu
);
16657 set_type
= create_set_type (NULL
, domain_type
);
16659 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16660 if (attr
!= nullptr && attr
->form_is_unsigned ())
16661 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16663 maybe_set_alignment (cu
, die
, set_type
);
16665 return set_die_type (die
, set_type
, cu
);
16668 /* A helper for read_common_block that creates a locexpr baton.
16669 SYM is the symbol which we are marking as computed.
16670 COMMON_DIE is the DIE for the common block.
16671 COMMON_LOC is the location expression attribute for the common
16673 MEMBER_LOC is the location expression attribute for the particular
16674 member of the common block that we are processing.
16675 CU is the CU from which the above come. */
16678 mark_common_block_symbol_computed (struct symbol
*sym
,
16679 struct die_info
*common_die
,
16680 struct attribute
*common_loc
,
16681 struct attribute
*member_loc
,
16682 struct dwarf2_cu
*cu
)
16684 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16685 struct objfile
*objfile
= per_objfile
->objfile
;
16686 struct dwarf2_locexpr_baton
*baton
;
16688 unsigned int cu_off
;
16689 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16690 LONGEST offset
= 0;
16692 gdb_assert (common_loc
&& member_loc
);
16693 gdb_assert (common_loc
->form_is_block ());
16694 gdb_assert (member_loc
->form_is_block ()
16695 || member_loc
->form_is_constant ());
16697 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16698 baton
->per_objfile
= per_objfile
;
16699 baton
->per_cu
= cu
->per_cu
;
16700 gdb_assert (baton
->per_cu
);
16702 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16704 if (member_loc
->form_is_constant ())
16706 offset
= member_loc
->constant_value (0);
16707 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16710 baton
->size
+= member_loc
->as_block ()->size
;
16712 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16715 *ptr
++ = DW_OP_call4
;
16716 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16717 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16720 if (member_loc
->form_is_constant ())
16722 *ptr
++ = DW_OP_addr
;
16723 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16724 ptr
+= cu
->header
.addr_size
;
16728 /* We have to copy the data here, because DW_OP_call4 will only
16729 use a DW_AT_location attribute. */
16730 struct dwarf_block
*block
= member_loc
->as_block ();
16731 memcpy (ptr
, block
->data
, block
->size
);
16732 ptr
+= block
->size
;
16735 *ptr
++ = DW_OP_plus
;
16736 gdb_assert (ptr
- baton
->data
== baton
->size
);
16738 SYMBOL_LOCATION_BATON (sym
) = baton
;
16739 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16742 /* Create appropriate locally-scoped variables for all the
16743 DW_TAG_common_block entries. Also create a struct common_block
16744 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16745 is used to separate the common blocks name namespace from regular
16749 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16751 struct attribute
*attr
;
16753 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16754 if (attr
!= nullptr)
16756 /* Support the .debug_loc offsets. */
16757 if (attr
->form_is_block ())
16761 else if (attr
->form_is_section_offset ())
16763 dwarf2_complex_location_expr_complaint ();
16768 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16769 "common block member");
16774 if (die
->child
!= NULL
)
16776 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16777 struct die_info
*child_die
;
16778 size_t n_entries
= 0, size
;
16779 struct common_block
*common_block
;
16780 struct symbol
*sym
;
16782 for (child_die
= die
->child
;
16783 child_die
&& child_die
->tag
;
16784 child_die
= child_die
->sibling
)
16787 size
= (sizeof (struct common_block
)
16788 + (n_entries
- 1) * sizeof (struct symbol
*));
16790 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16792 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16793 common_block
->n_entries
= 0;
16795 for (child_die
= die
->child
;
16796 child_die
&& child_die
->tag
;
16797 child_die
= child_die
->sibling
)
16799 /* Create the symbol in the DW_TAG_common_block block in the current
16801 sym
= new_symbol (child_die
, NULL
, cu
);
16804 struct attribute
*member_loc
;
16806 common_block
->contents
[common_block
->n_entries
++] = sym
;
16808 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16812 /* GDB has handled this for a long time, but it is
16813 not specified by DWARF. It seems to have been
16814 emitted by gfortran at least as recently as:
16815 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16816 complaint (_("Variable in common block has "
16817 "DW_AT_data_member_location "
16818 "- DIE at %s [in module %s]"),
16819 sect_offset_str (child_die
->sect_off
),
16820 objfile_name (objfile
));
16822 if (member_loc
->form_is_section_offset ())
16823 dwarf2_complex_location_expr_complaint ();
16824 else if (member_loc
->form_is_constant ()
16825 || member_loc
->form_is_block ())
16827 if (attr
!= nullptr)
16828 mark_common_block_symbol_computed (sym
, die
, attr
,
16832 dwarf2_complex_location_expr_complaint ();
16837 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16838 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16842 /* Create a type for a C++ namespace. */
16844 static struct type
*
16845 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16847 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16848 const char *previous_prefix
, *name
;
16852 /* For extensions, reuse the type of the original namespace. */
16853 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16855 struct die_info
*ext_die
;
16856 struct dwarf2_cu
*ext_cu
= cu
;
16858 ext_die
= dwarf2_extension (die
, &ext_cu
);
16859 type
= read_type_die (ext_die
, ext_cu
);
16861 /* EXT_CU may not be the same as CU.
16862 Ensure TYPE is recorded with CU in die_type_hash. */
16863 return set_die_type (die
, type
, cu
);
16866 name
= namespace_name (die
, &is_anonymous
, cu
);
16868 /* Now build the name of the current namespace. */
16870 previous_prefix
= determine_prefix (die
, cu
);
16871 if (previous_prefix
[0] != '\0')
16872 name
= typename_concat (&objfile
->objfile_obstack
,
16873 previous_prefix
, name
, 0, cu
);
16875 /* Create the type. */
16876 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16878 return set_die_type (die
, type
, cu
);
16881 /* Read a namespace scope. */
16884 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16886 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16889 /* Add a symbol associated to this if we haven't seen the namespace
16890 before. Also, add a using directive if it's an anonymous
16893 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16897 type
= read_type_die (die
, cu
);
16898 new_symbol (die
, type
, cu
);
16900 namespace_name (die
, &is_anonymous
, cu
);
16903 const char *previous_prefix
= determine_prefix (die
, cu
);
16905 std::vector
<const char *> excludes
;
16906 add_using_directive (using_directives (cu
),
16907 previous_prefix
, type
->name (), NULL
,
16908 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16912 if (die
->child
!= NULL
)
16914 struct die_info
*child_die
= die
->child
;
16916 while (child_die
&& child_die
->tag
)
16918 process_die (child_die
, cu
);
16919 child_die
= child_die
->sibling
;
16924 /* Read a Fortran module as type. This DIE can be only a declaration used for
16925 imported module. Still we need that type as local Fortran "use ... only"
16926 declaration imports depend on the created type in determine_prefix. */
16928 static struct type
*
16929 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16931 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16932 const char *module_name
;
16935 module_name
= dwarf2_name (die
, cu
);
16936 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16938 return set_die_type (die
, type
, cu
);
16941 /* Read a Fortran module. */
16944 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16946 struct die_info
*child_die
= die
->child
;
16949 type
= read_type_die (die
, cu
);
16950 new_symbol (die
, type
, cu
);
16952 while (child_die
&& child_die
->tag
)
16954 process_die (child_die
, cu
);
16955 child_die
= child_die
->sibling
;
16959 /* Return the name of the namespace represented by DIE. Set
16960 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16963 static const char *
16964 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16966 struct die_info
*current_die
;
16967 const char *name
= NULL
;
16969 /* Loop through the extensions until we find a name. */
16971 for (current_die
= die
;
16972 current_die
!= NULL
;
16973 current_die
= dwarf2_extension (die
, &cu
))
16975 /* We don't use dwarf2_name here so that we can detect the absence
16976 of a name -> anonymous namespace. */
16977 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16983 /* Is it an anonymous namespace? */
16985 *is_anonymous
= (name
== NULL
);
16987 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16992 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16993 the user defined type vector. */
16995 static struct type
*
16996 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16998 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16999 struct comp_unit_head
*cu_header
= &cu
->header
;
17001 struct attribute
*attr_byte_size
;
17002 struct attribute
*attr_address_class
;
17003 int byte_size
, addr_class
;
17004 struct type
*target_type
;
17006 target_type
= die_type (die
, cu
);
17008 /* The die_type call above may have already set the type for this DIE. */
17009 type
= get_die_type (die
, cu
);
17013 type
= lookup_pointer_type (target_type
);
17015 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17016 if (attr_byte_size
)
17017 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17019 byte_size
= cu_header
->addr_size
;
17021 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17022 if (attr_address_class
)
17023 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17025 addr_class
= DW_ADDR_none
;
17027 ULONGEST alignment
= get_alignment (cu
, die
);
17029 /* If the pointer size, alignment, or address class is different
17030 than the default, create a type variant marked as such and set
17031 the length accordingly. */
17032 if (TYPE_LENGTH (type
) != byte_size
17033 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17034 && alignment
!= TYPE_RAW_ALIGN (type
))
17035 || addr_class
!= DW_ADDR_none
)
17037 if (gdbarch_address_class_type_flags_p (gdbarch
))
17039 type_instance_flags type_flags
17040 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17042 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17044 type
= make_type_with_address_space (type
, type_flags
);
17046 else if (TYPE_LENGTH (type
) != byte_size
)
17048 complaint (_("invalid pointer size %d"), byte_size
);
17050 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17052 complaint (_("Invalid DW_AT_alignment"
17053 " - DIE at %s [in module %s]"),
17054 sect_offset_str (die
->sect_off
),
17055 objfile_name (cu
->per_objfile
->objfile
));
17059 /* Should we also complain about unhandled address classes? */
17063 TYPE_LENGTH (type
) = byte_size
;
17064 set_type_align (type
, alignment
);
17065 return set_die_type (die
, type
, cu
);
17068 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17069 the user defined type vector. */
17071 static struct type
*
17072 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17075 struct type
*to_type
;
17076 struct type
*domain
;
17078 to_type
= die_type (die
, cu
);
17079 domain
= die_containing_type (die
, cu
);
17081 /* The calls above may have already set the type for this DIE. */
17082 type
= get_die_type (die
, cu
);
17086 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17087 type
= lookup_methodptr_type (to_type
);
17088 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17090 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17092 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17093 to_type
->fields (), to_type
->num_fields (),
17094 to_type
->has_varargs ());
17095 type
= lookup_methodptr_type (new_type
);
17098 type
= lookup_memberptr_type (to_type
, domain
);
17100 return set_die_type (die
, type
, cu
);
17103 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17104 the user defined type vector. */
17106 static struct type
*
17107 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17108 enum type_code refcode
)
17110 struct comp_unit_head
*cu_header
= &cu
->header
;
17111 struct type
*type
, *target_type
;
17112 struct attribute
*attr
;
17114 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17116 target_type
= die_type (die
, cu
);
17118 /* The die_type call above may have already set the type for this DIE. */
17119 type
= get_die_type (die
, cu
);
17123 type
= lookup_reference_type (target_type
, refcode
);
17124 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17125 if (attr
!= nullptr)
17127 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17131 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17133 maybe_set_alignment (cu
, die
, type
);
17134 return set_die_type (die
, type
, cu
);
17137 /* Add the given cv-qualifiers to the element type of the array. GCC
17138 outputs DWARF type qualifiers that apply to an array, not the
17139 element type. But GDB relies on the array element type to carry
17140 the cv-qualifiers. This mimics section 6.7.3 of the C99
17143 static struct type
*
17144 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17145 struct type
*base_type
, int cnst
, int voltl
)
17147 struct type
*el_type
, *inner_array
;
17149 base_type
= copy_type (base_type
);
17150 inner_array
= base_type
;
17152 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17154 TYPE_TARGET_TYPE (inner_array
) =
17155 copy_type (TYPE_TARGET_TYPE (inner_array
));
17156 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17159 el_type
= TYPE_TARGET_TYPE (inner_array
);
17160 cnst
|= TYPE_CONST (el_type
);
17161 voltl
|= TYPE_VOLATILE (el_type
);
17162 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17164 return set_die_type (die
, base_type
, cu
);
17167 static struct type
*
17168 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17170 struct type
*base_type
, *cv_type
;
17172 base_type
= die_type (die
, cu
);
17174 /* The die_type call above may have already set the type for this DIE. */
17175 cv_type
= get_die_type (die
, cu
);
17179 /* In case the const qualifier is applied to an array type, the element type
17180 is so qualified, not the array type (section 6.7.3 of C99). */
17181 if (base_type
->code () == TYPE_CODE_ARRAY
)
17182 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17184 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17185 return set_die_type (die
, cv_type
, cu
);
17188 static struct type
*
17189 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17191 struct type
*base_type
, *cv_type
;
17193 base_type
= die_type (die
, cu
);
17195 /* The die_type call above may have already set the type for this DIE. */
17196 cv_type
= get_die_type (die
, cu
);
17200 /* In case the volatile qualifier is applied to an array type, the
17201 element type is so qualified, not the array type (section 6.7.3
17203 if (base_type
->code () == TYPE_CODE_ARRAY
)
17204 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17206 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17207 return set_die_type (die
, cv_type
, cu
);
17210 /* Handle DW_TAG_restrict_type. */
17212 static struct type
*
17213 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17215 struct type
*base_type
, *cv_type
;
17217 base_type
= die_type (die
, cu
);
17219 /* The die_type call above may have already set the type for this DIE. */
17220 cv_type
= get_die_type (die
, cu
);
17224 cv_type
= make_restrict_type (base_type
);
17225 return set_die_type (die
, cv_type
, cu
);
17228 /* Handle DW_TAG_atomic_type. */
17230 static struct type
*
17231 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17233 struct type
*base_type
, *cv_type
;
17235 base_type
= die_type (die
, cu
);
17237 /* The die_type call above may have already set the type for this DIE. */
17238 cv_type
= get_die_type (die
, cu
);
17242 cv_type
= make_atomic_type (base_type
);
17243 return set_die_type (die
, cv_type
, cu
);
17246 /* Extract all information from a DW_TAG_string_type DIE and add to
17247 the user defined type vector. It isn't really a user defined type,
17248 but it behaves like one, with other DIE's using an AT_user_def_type
17249 attribute to reference it. */
17251 static struct type
*
17252 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17254 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17255 struct gdbarch
*gdbarch
= objfile
->arch ();
17256 struct type
*type
, *range_type
, *index_type
, *char_type
;
17257 struct attribute
*attr
;
17258 struct dynamic_prop prop
;
17259 bool length_is_constant
= true;
17262 /* There are a couple of places where bit sizes might be made use of
17263 when parsing a DW_TAG_string_type, however, no producer that we know
17264 of make use of these. Handling bit sizes that are a multiple of the
17265 byte size is easy enough, but what about other bit sizes? Lets deal
17266 with that problem when we have to. Warn about these attributes being
17267 unsupported, then parse the type and ignore them like we always
17269 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17270 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17272 static bool warning_printed
= false;
17273 if (!warning_printed
)
17275 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17276 "currently supported on DW_TAG_string_type."));
17277 warning_printed
= true;
17281 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17282 if (attr
!= nullptr && !attr
->form_is_constant ())
17284 /* The string length describes the location at which the length of
17285 the string can be found. The size of the length field can be
17286 specified with one of the attributes below. */
17287 struct type
*prop_type
;
17288 struct attribute
*len
17289 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17290 if (len
== nullptr)
17291 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17292 if (len
!= nullptr && len
->form_is_constant ())
17294 /* Pass 0 as the default as we know this attribute is constant
17295 and the default value will not be returned. */
17296 LONGEST sz
= len
->constant_value (0);
17297 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17301 /* If the size is not specified then we assume it is the size of
17302 an address on this target. */
17303 prop_type
= cu
->addr_sized_int_type (true);
17306 /* Convert the attribute into a dynamic property. */
17307 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17310 length_is_constant
= false;
17312 else if (attr
!= nullptr)
17314 /* This DW_AT_string_length just contains the length with no
17315 indirection. There's no need to create a dynamic property in this
17316 case. Pass 0 for the default value as we know it will not be
17317 returned in this case. */
17318 length
= attr
->constant_value (0);
17320 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17322 /* We don't currently support non-constant byte sizes for strings. */
17323 length
= attr
->constant_value (1);
17327 /* Use 1 as a fallback length if we have nothing else. */
17331 index_type
= objfile_type (objfile
)->builtin_int
;
17332 if (length_is_constant
)
17333 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17336 struct dynamic_prop low_bound
;
17338 low_bound
.set_const_val (1);
17339 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17341 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17342 type
= create_string_type (NULL
, char_type
, range_type
);
17344 return set_die_type (die
, type
, cu
);
17347 /* Assuming that DIE corresponds to a function, returns nonzero
17348 if the function is prototyped. */
17351 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17353 struct attribute
*attr
;
17355 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17356 if (attr
&& attr
->as_boolean ())
17359 /* The DWARF standard implies that the DW_AT_prototyped attribute
17360 is only meaningful for C, but the concept also extends to other
17361 languages that allow unprototyped functions (Eg: Objective C).
17362 For all other languages, assume that functions are always
17364 if (cu
->language
!= language_c
17365 && cu
->language
!= language_objc
17366 && cu
->language
!= language_opencl
)
17369 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17370 prototyped and unprototyped functions; default to prototyped,
17371 since that is more common in modern code (and RealView warns
17372 about unprototyped functions). */
17373 if (producer_is_realview (cu
->producer
))
17379 /* Handle DIES due to C code like:
17383 int (*funcp)(int a, long l);
17387 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17389 static struct type
*
17390 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17392 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17393 struct type
*type
; /* Type that this function returns. */
17394 struct type
*ftype
; /* Function that returns above type. */
17395 struct attribute
*attr
;
17397 type
= die_type (die
, cu
);
17399 /* The die_type call above may have already set the type for this DIE. */
17400 ftype
= get_die_type (die
, cu
);
17404 ftype
= lookup_function_type (type
);
17406 if (prototyped_function_p (die
, cu
))
17407 ftype
->set_is_prototyped (true);
17409 /* Store the calling convention in the type if it's available in
17410 the subroutine die. Otherwise set the calling convention to
17411 the default value DW_CC_normal. */
17412 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17413 if (attr
!= nullptr
17414 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17415 TYPE_CALLING_CONVENTION (ftype
)
17416 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17417 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17418 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17420 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17422 /* Record whether the function returns normally to its caller or not
17423 if the DWARF producer set that information. */
17424 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17425 if (attr
&& attr
->as_boolean ())
17426 TYPE_NO_RETURN (ftype
) = 1;
17428 /* We need to add the subroutine type to the die immediately so
17429 we don't infinitely recurse when dealing with parameters
17430 declared as the same subroutine type. */
17431 set_die_type (die
, ftype
, cu
);
17433 if (die
->child
!= NULL
)
17435 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17436 struct die_info
*child_die
;
17437 int nparams
, iparams
;
17439 /* Count the number of parameters.
17440 FIXME: GDB currently ignores vararg functions, but knows about
17441 vararg member functions. */
17443 child_die
= die
->child
;
17444 while (child_die
&& child_die
->tag
)
17446 if (child_die
->tag
== DW_TAG_formal_parameter
)
17448 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17449 ftype
->set_has_varargs (true);
17451 child_die
= child_die
->sibling
;
17454 /* Allocate storage for parameters and fill them in. */
17455 ftype
->set_num_fields (nparams
);
17457 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17459 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17460 even if we error out during the parameters reading below. */
17461 for (iparams
= 0; iparams
< nparams
; iparams
++)
17462 ftype
->field (iparams
).set_type (void_type
);
17465 child_die
= die
->child
;
17466 while (child_die
&& child_die
->tag
)
17468 if (child_die
->tag
== DW_TAG_formal_parameter
)
17470 struct type
*arg_type
;
17472 /* DWARF version 2 has no clean way to discern C++
17473 static and non-static member functions. G++ helps
17474 GDB by marking the first parameter for non-static
17475 member functions (which is the this pointer) as
17476 artificial. We pass this information to
17477 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17479 DWARF version 3 added DW_AT_object_pointer, which GCC
17480 4.5 does not yet generate. */
17481 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17482 if (attr
!= nullptr)
17483 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17485 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17486 arg_type
= die_type (child_die
, cu
);
17488 /* RealView does not mark THIS as const, which the testsuite
17489 expects. GCC marks THIS as const in method definitions,
17490 but not in the class specifications (GCC PR 43053). */
17491 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17492 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17495 struct dwarf2_cu
*arg_cu
= cu
;
17496 const char *name
= dwarf2_name (child_die
, cu
);
17498 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17499 if (attr
!= nullptr)
17501 /* If the compiler emits this, use it. */
17502 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17505 else if (name
&& strcmp (name
, "this") == 0)
17506 /* Function definitions will have the argument names. */
17508 else if (name
== NULL
&& iparams
== 0)
17509 /* Declarations may not have the names, so like
17510 elsewhere in GDB, assume an artificial first
17511 argument is "this". */
17515 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17519 ftype
->field (iparams
).set_type (arg_type
);
17522 child_die
= child_die
->sibling
;
17529 static struct type
*
17530 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17532 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17533 const char *name
= NULL
;
17534 struct type
*this_type
, *target_type
;
17536 name
= dwarf2_full_name (NULL
, die
, cu
);
17537 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17538 this_type
->set_target_is_stub (true);
17539 set_die_type (die
, this_type
, cu
);
17540 target_type
= die_type (die
, cu
);
17541 if (target_type
!= this_type
)
17542 TYPE_TARGET_TYPE (this_type
) = target_type
;
17545 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17546 spec and cause infinite loops in GDB. */
17547 complaint (_("Self-referential DW_TAG_typedef "
17548 "- DIE at %s [in module %s]"),
17549 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17550 TYPE_TARGET_TYPE (this_type
) = NULL
;
17554 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17555 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17556 Handle these by just returning the target type, rather than
17557 constructing an anonymous typedef type and trying to handle this
17559 set_die_type (die
, target_type
, cu
);
17560 return target_type
;
17565 /* Helper for get_dwarf2_rational_constant that computes the value of
17566 a given gmp_mpz given an attribute. */
17569 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17571 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17572 location expression that pushes an implicit value. */
17573 if (attr
->form
== DW_FORM_exprloc
)
17575 dwarf_block
*blk
= attr
->as_block ();
17576 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17579 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17580 blk
->data
+ blk
->size
,
17582 if (ptr
- blk
->data
+ len
<= blk
->size
)
17584 mpz_import (value
->val
, len
,
17585 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17591 /* On failure set it to 1. */
17592 *value
= gdb_mpz (1);
17594 else if (attr
->form_is_block ())
17596 dwarf_block
*blk
= attr
->as_block ();
17597 mpz_import (value
->val
, blk
->size
,
17598 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17599 1, 0, 0, blk
->data
);
17602 *value
= gdb_mpz (attr
->constant_value (1));
17605 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17606 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17608 If the numerator and/or numerator attribute is missing,
17609 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17613 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17614 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17616 struct attribute
*num_attr
, *denom_attr
;
17618 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17619 if (num_attr
== nullptr)
17620 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17621 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17623 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17624 if (denom_attr
== nullptr)
17625 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17626 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17628 if (num_attr
== nullptr || denom_attr
== nullptr)
17631 get_mpz (cu
, numerator
, num_attr
);
17632 get_mpz (cu
, denominator
, denom_attr
);
17635 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17636 rational constant, rather than a signed one.
17638 If the rational constant has a negative value, a complaint
17639 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17642 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17643 struct dwarf2_cu
*cu
,
17644 gdb_mpz
*numerator
,
17645 gdb_mpz
*denominator
)
17650 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17651 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17653 mpz_neg (num
.val
, num
.val
);
17654 mpz_neg (denom
.val
, denom
.val
);
17656 else if (mpz_sgn (num
.val
) == -1)
17658 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17660 sect_offset_str (die
->sect_off
));
17663 else if (mpz_sgn (denom
.val
) == -1)
17665 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17667 sect_offset_str (die
->sect_off
));
17671 *numerator
= std::move (num
);
17672 *denominator
= std::move (denom
);
17675 /* Assuming that ENCODING is a string whose contents starting at the
17676 K'th character is "_nn" where "nn" is a decimal number, scan that
17677 number and set RESULT to the value. K is updated to point to the
17678 character immediately following the number.
17680 If the string does not conform to the format described above, false
17681 is returned, and K may or may not be changed. */
17684 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17686 /* The next character should be an underscore ('_') followed
17688 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17691 /* Skip the underscore. */
17695 /* Determine the number of digits for our number. */
17696 while (isdigit (encoding
[k
]))
17701 std::string
copy (&encoding
[start
], k
- start
);
17702 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17708 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17709 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17710 DENOM, update OFFSET, and return true on success. Return false on
17714 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17715 gdb_mpz
*num
, gdb_mpz
*denom
)
17717 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17719 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17722 /* Assuming DIE corresponds to a fixed point type, finish the creation
17723 of the corresponding TYPE by setting its type-specific data. CU is
17724 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17725 encodings. It is nullptr if the GNAT encoding should be
17729 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17730 struct die_info
*die
, struct dwarf2_cu
*cu
)
17732 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17733 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17735 /* If GNAT encodings are preferred, don't examine the
17737 struct attribute
*attr
= nullptr;
17738 if (suffix
== nullptr)
17740 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17741 if (attr
== nullptr)
17742 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17743 if (attr
== nullptr)
17744 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17747 /* Numerator and denominator of our fixed-point type's scaling factor.
17748 The default is a scaling factor of 1, which we use as a fallback
17749 when we are not able to decode it (problem with the debugging info,
17750 unsupported forms, bug in GDB, etc...). Using that as the default
17751 allows us to at least print the unscaled value, which might still
17752 be useful to a user. */
17753 gdb_mpz
scale_num (1);
17754 gdb_mpz
scale_denom (1);
17756 if (attr
== nullptr)
17759 if (suffix
!= nullptr
17760 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17762 /* The number might be encoded as _nn_dd_nn_dd, where the
17763 second ratio is the 'small value. In this situation, we
17764 want the second value. */
17765 && (suffix
[offset
] != '_'
17766 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17773 /* Scaling factor not found. Assume a scaling factor of 1,
17774 and hope for the best. At least the user will be able to
17775 see the encoded value. */
17778 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17779 sect_offset_str (die
->sect_off
));
17782 else if (attr
->name
== DW_AT_binary_scale
)
17784 LONGEST scale_exp
= attr
->constant_value (0);
17785 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17787 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17789 else if (attr
->name
== DW_AT_decimal_scale
)
17791 LONGEST scale_exp
= attr
->constant_value (0);
17792 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17794 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17796 else if (attr
->name
== DW_AT_small
)
17798 struct die_info
*scale_die
;
17799 struct dwarf2_cu
*scale_cu
= cu
;
17801 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17802 if (scale_die
->tag
== DW_TAG_constant
)
17803 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17804 &scale_num
, &scale_denom
);
17806 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17808 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17812 complaint (_("unsupported scale attribute %s for fixed-point type"
17814 dwarf_attr_name (attr
->name
),
17815 sect_offset_str (die
->sect_off
));
17818 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17819 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17820 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17821 mpq_canonicalize (scaling_factor
.val
);
17824 /* The gnat-encoding suffix for fixed point. */
17826 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17828 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17829 "XF" suffix of the name. The text after this is what encodes the
17830 'small and 'delta information. Otherwise, return nullptr. */
17832 static const char *
17833 gnat_encoded_fixed_point_type_info (const char *name
)
17835 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17838 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17839 (which may be different from NAME) to the architecture back-end to allow
17840 it to guess the correct format if necessary. */
17842 static struct type
*
17843 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17844 const char *name_hint
, enum bfd_endian byte_order
)
17846 struct gdbarch
*gdbarch
= objfile
->arch ();
17847 const struct floatformat
**format
;
17850 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17852 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17854 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17859 /* Allocate an integer type of size BITS and name NAME. */
17861 static struct type
*
17862 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17863 int bits
, int unsigned_p
, const char *name
)
17867 /* Versions of Intel's C Compiler generate an integer type called "void"
17868 instead of using DW_TAG_unspecified_type. This has been seen on
17869 at least versions 14, 17, and 18. */
17870 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17871 && strcmp (name
, "void") == 0)
17872 type
= objfile_type (objfile
)->builtin_void
;
17874 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17879 /* Return true if DIE has a DW_AT_small attribute whose value is
17880 a constant rational, where both the numerator and denominator
17883 CU is the DIE's Compilation Unit. */
17886 has_zero_over_zero_small_attribute (struct die_info
*die
,
17887 struct dwarf2_cu
*cu
)
17889 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17890 if (attr
== nullptr)
17893 struct dwarf2_cu
*scale_cu
= cu
;
17894 struct die_info
*scale_die
17895 = follow_die_ref (die
, attr
, &scale_cu
);
17897 if (scale_die
->tag
!= DW_TAG_constant
)
17900 gdb_mpz
num (1), denom (1);
17901 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
17902 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
17905 /* Initialise and return a floating point type of size BITS suitable for
17906 use as a component of a complex number. The NAME_HINT is passed through
17907 when initialising the floating point type and is the name of the complex
17910 As DWARF doesn't currently provide an explicit name for the components
17911 of a complex number, but it can be helpful to have these components
17912 named, we try to select a suitable name based on the size of the
17914 static struct type
*
17915 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17916 struct objfile
*objfile
,
17917 int bits
, const char *name_hint
,
17918 enum bfd_endian byte_order
)
17920 gdbarch
*gdbarch
= objfile
->arch ();
17921 struct type
*tt
= nullptr;
17923 /* Try to find a suitable floating point builtin type of size BITS.
17924 We're going to use the name of this type as the name for the complex
17925 target type that we are about to create. */
17926 switch (cu
->language
)
17928 case language_fortran
:
17932 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17935 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17937 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17939 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17947 tt
= builtin_type (gdbarch
)->builtin_float
;
17950 tt
= builtin_type (gdbarch
)->builtin_double
;
17952 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17954 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17960 /* If the type we found doesn't match the size we were looking for, then
17961 pretend we didn't find a type at all, the complex target type we
17962 create will then be nameless. */
17963 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17966 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17967 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17970 /* Find a representation of a given base type and install
17971 it in the TYPE field of the die. */
17973 static struct type
*
17974 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17976 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17978 struct attribute
*attr
;
17979 int encoding
= 0, bits
= 0;
17983 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17984 if (attr
!= nullptr && attr
->form_is_constant ())
17985 encoding
= attr
->constant_value (0);
17986 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17987 if (attr
!= nullptr)
17988 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
17989 name
= dwarf2_name (die
, cu
);
17991 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17993 arch
= objfile
->arch ();
17994 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17996 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17997 if (attr
!= nullptr && attr
->form_is_constant ())
17999 int endianity
= attr
->constant_value (0);
18004 byte_order
= BFD_ENDIAN_BIG
;
18006 case DW_END_little
:
18007 byte_order
= BFD_ENDIAN_LITTLE
;
18010 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18015 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18016 && cu
->language
== language_ada
18017 && has_zero_over_zero_small_attribute (die
, cu
))
18019 /* brobecker/2018-02-24: This is a fixed point type for which
18020 the scaling factor is represented as fraction whose value
18021 does not make sense (zero divided by zero), so we should
18022 normally never see these. However, there is a small category
18023 of fixed point types for which GNAT is unable to provide
18024 the scaling factor via the standard DWARF mechanisms, and
18025 for which the info is provided via the GNAT encodings instead.
18026 This is likely what this DIE is about. */
18027 encoding
= (encoding
== DW_ATE_signed_fixed
18029 : DW_ATE_unsigned
);
18032 /* With GNAT encodings, fixed-point information will be encoded in
18033 the type name. Note that this can also occur with the above
18034 zero-over-zero case, which is why this is a separate "if" rather
18035 than an "else if". */
18036 const char *gnat_encoding_suffix
= nullptr;
18037 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18038 && cu
->language
== language_ada
18039 && name
!= nullptr)
18041 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18042 if (gnat_encoding_suffix
!= nullptr)
18044 gdb_assert (startswith (gnat_encoding_suffix
,
18045 GNAT_FIXED_POINT_SUFFIX
));
18046 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18047 name
, gnat_encoding_suffix
- name
);
18048 /* Use -1 here so that SUFFIX points at the "_" after the
18050 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18052 encoding
= (encoding
== DW_ATE_signed
18053 ? DW_ATE_signed_fixed
18054 : DW_ATE_unsigned_fixed
);
18060 case DW_ATE_address
:
18061 /* Turn DW_ATE_address into a void * pointer. */
18062 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18063 type
= init_pointer_type (objfile
, bits
, name
, type
);
18065 case DW_ATE_boolean
:
18066 type
= init_boolean_type (objfile
, bits
, 1, name
);
18068 case DW_ATE_complex_float
:
18069 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18071 if (type
->code () == TYPE_CODE_ERROR
)
18073 if (name
== nullptr)
18075 struct obstack
*obstack
18076 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18077 name
= obconcat (obstack
, "_Complex ", type
->name (),
18080 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18083 type
= init_complex_type (name
, type
);
18085 case DW_ATE_decimal_float
:
18086 type
= init_decfloat_type (objfile
, bits
, name
);
18089 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18091 case DW_ATE_signed
:
18092 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18094 case DW_ATE_unsigned
:
18095 if (cu
->language
== language_fortran
18097 && startswith (name
, "character("))
18098 type
= init_character_type (objfile
, bits
, 1, name
);
18100 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18102 case DW_ATE_signed_char
:
18103 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18104 || cu
->language
== language_pascal
18105 || cu
->language
== language_fortran
)
18106 type
= init_character_type (objfile
, bits
, 0, name
);
18108 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18110 case DW_ATE_unsigned_char
:
18111 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18112 || cu
->language
== language_pascal
18113 || cu
->language
== language_fortran
18114 || cu
->language
== language_rust
)
18115 type
= init_character_type (objfile
, bits
, 1, name
);
18117 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18122 type
= builtin_type (arch
)->builtin_char16
;
18123 else if (bits
== 32)
18124 type
= builtin_type (arch
)->builtin_char32
;
18127 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18129 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18131 return set_die_type (die
, type
, cu
);
18134 case DW_ATE_signed_fixed
:
18135 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18136 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18138 case DW_ATE_unsigned_fixed
:
18139 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18140 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18144 complaint (_("unsupported DW_AT_encoding: '%s'"),
18145 dwarf_type_encoding_name (encoding
));
18146 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18150 if (name
&& strcmp (name
, "char") == 0)
18151 type
->set_has_no_signedness (true);
18153 maybe_set_alignment (cu
, die
, type
);
18155 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18157 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18159 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18160 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18162 unsigned real_bit_size
= attr
->as_unsigned ();
18163 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18164 /* Only use the attributes if they make sense together. */
18165 if (attr
== nullptr
18166 || (attr
->as_unsigned () + real_bit_size
18167 <= 8 * TYPE_LENGTH (type
)))
18169 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18171 if (attr
!= nullptr)
18172 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18173 = attr
->as_unsigned ();
18178 return set_die_type (die
, type
, cu
);
18181 /* A helper function that returns the name of DIE, if it refers to a
18182 variable declaration. */
18184 static const char *
18185 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18187 if (die
->tag
!= DW_TAG_variable
)
18190 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18191 if (attr
== nullptr || !attr
->as_boolean ())
18194 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18195 if (attr
== nullptr)
18197 return attr
->as_string ();
18200 /* Parse dwarf attribute if it's a block, reference or constant and put the
18201 resulting value of the attribute into struct bound_prop.
18202 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18205 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18206 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18207 struct type
*default_type
)
18209 struct dwarf2_property_baton
*baton
;
18210 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18211 struct objfile
*objfile
= per_objfile
->objfile
;
18212 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18214 gdb_assert (default_type
!= NULL
);
18216 if (attr
== NULL
|| prop
== NULL
)
18219 if (attr
->form_is_block ())
18221 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18222 baton
->property_type
= default_type
;
18223 baton
->locexpr
.per_cu
= cu
->per_cu
;
18224 baton
->locexpr
.per_objfile
= per_objfile
;
18226 struct dwarf_block
*block
= attr
->as_block ();
18227 baton
->locexpr
.size
= block
->size
;
18228 baton
->locexpr
.data
= block
->data
;
18229 switch (attr
->name
)
18231 case DW_AT_string_length
:
18232 baton
->locexpr
.is_reference
= true;
18235 baton
->locexpr
.is_reference
= false;
18239 prop
->set_locexpr (baton
);
18240 gdb_assert (prop
->baton () != NULL
);
18242 else if (attr
->form_is_ref ())
18244 struct dwarf2_cu
*target_cu
= cu
;
18245 struct die_info
*target_die
;
18246 struct attribute
*target_attr
;
18248 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18249 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18250 if (target_attr
== NULL
)
18251 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18253 if (target_attr
== NULL
)
18255 const char *name
= var_decl_name (target_die
, target_cu
);
18256 if (name
!= nullptr)
18258 prop
->set_variable_name (name
);
18264 switch (target_attr
->name
)
18266 case DW_AT_location
:
18267 if (target_attr
->form_is_section_offset ())
18269 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18270 baton
->property_type
= die_type (target_die
, target_cu
);
18271 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18272 prop
->set_loclist (baton
);
18273 gdb_assert (prop
->baton () != NULL
);
18275 else if (target_attr
->form_is_block ())
18277 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18278 baton
->property_type
= die_type (target_die
, target_cu
);
18279 baton
->locexpr
.per_cu
= cu
->per_cu
;
18280 baton
->locexpr
.per_objfile
= per_objfile
;
18281 struct dwarf_block
*block
= target_attr
->as_block ();
18282 baton
->locexpr
.size
= block
->size
;
18283 baton
->locexpr
.data
= block
->data
;
18284 baton
->locexpr
.is_reference
= true;
18285 prop
->set_locexpr (baton
);
18286 gdb_assert (prop
->baton () != NULL
);
18290 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18291 "dynamic property");
18295 case DW_AT_data_member_location
:
18299 if (!handle_data_member_location (target_die
, target_cu
,
18303 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18304 baton
->property_type
= read_type_die (target_die
->parent
,
18306 baton
->offset_info
.offset
= offset
;
18307 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18308 prop
->set_addr_offset (baton
);
18313 else if (attr
->form_is_constant ())
18314 prop
->set_const_val (attr
->constant_value (0));
18317 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18318 dwarf2_name (die
, cu
));
18328 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18330 struct type
*int_type
;
18332 /* Helper macro to examine the various builtin types. */
18333 #define TRY_TYPE(F) \
18334 int_type = (unsigned_p \
18335 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18336 : objfile_type (objfile)->builtin_ ## F); \
18337 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18344 TRY_TYPE (long_long
);
18348 gdb_assert_not_reached ("unable to find suitable integer type");
18351 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18352 present (which is valid) then compute the default type based on the
18353 compilation units address size. */
18355 static struct type
*
18356 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18358 struct type
*index_type
= die_type (die
, cu
);
18360 /* Dwarf-2 specifications explicitly allows to create subrange types
18361 without specifying a base type.
18362 In that case, the base type must be set to the type of
18363 the lower bound, upper bound or count, in that order, if any of these
18364 three attributes references an object that has a type.
18365 If no base type is found, the Dwarf-2 specifications say that
18366 a signed integer type of size equal to the size of an address should
18368 For the following C code: `extern char gdb_int [];'
18369 GCC produces an empty range DIE.
18370 FIXME: muller/2010-05-28: Possible references to object for low bound,
18371 high bound or count are not yet handled by this code. */
18372 if (index_type
->code () == TYPE_CODE_VOID
)
18373 index_type
= cu
->addr_sized_int_type (false);
18378 /* Read the given DW_AT_subrange DIE. */
18380 static struct type
*
18381 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18383 struct type
*base_type
, *orig_base_type
;
18384 struct type
*range_type
;
18385 struct attribute
*attr
;
18386 struct dynamic_prop low
, high
;
18387 int low_default_is_valid
;
18388 int high_bound_is_count
= 0;
18390 ULONGEST negative_mask
;
18392 orig_base_type
= read_subrange_index_type (die
, cu
);
18394 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18395 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18396 creating the range type, but we use the result of check_typedef
18397 when examining properties of the type. */
18398 base_type
= check_typedef (orig_base_type
);
18400 /* The die_type call above may have already set the type for this DIE. */
18401 range_type
= get_die_type (die
, cu
);
18405 high
.set_const_val (0);
18407 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18408 omitting DW_AT_lower_bound. */
18409 switch (cu
->language
)
18412 case language_cplus
:
18413 low
.set_const_val (0);
18414 low_default_is_valid
= 1;
18416 case language_fortran
:
18417 low
.set_const_val (1);
18418 low_default_is_valid
= 1;
18421 case language_objc
:
18422 case language_rust
:
18423 low
.set_const_val (0);
18424 low_default_is_valid
= (cu
->header
.version
>= 4);
18428 case language_pascal
:
18429 low
.set_const_val (1);
18430 low_default_is_valid
= (cu
->header
.version
>= 4);
18433 low
.set_const_val (0);
18434 low_default_is_valid
= 0;
18438 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18439 if (attr
!= nullptr)
18440 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18441 else if (!low_default_is_valid
)
18442 complaint (_("Missing DW_AT_lower_bound "
18443 "- DIE at %s [in module %s]"),
18444 sect_offset_str (die
->sect_off
),
18445 objfile_name (cu
->per_objfile
->objfile
));
18447 struct attribute
*attr_ub
, *attr_count
;
18448 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18449 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18451 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18452 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18454 /* If bounds are constant do the final calculation here. */
18455 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18456 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18458 high_bound_is_count
= 1;
18462 if (attr_ub
!= NULL
)
18463 complaint (_("Unresolved DW_AT_upper_bound "
18464 "- DIE at %s [in module %s]"),
18465 sect_offset_str (die
->sect_off
),
18466 objfile_name (cu
->per_objfile
->objfile
));
18467 if (attr_count
!= NULL
)
18468 complaint (_("Unresolved DW_AT_count "
18469 "- DIE at %s [in module %s]"),
18470 sect_offset_str (die
->sect_off
),
18471 objfile_name (cu
->per_objfile
->objfile
));
18476 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18477 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18478 bias
= bias_attr
->constant_value (0);
18480 /* Normally, the DWARF producers are expected to use a signed
18481 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18482 But this is unfortunately not always the case, as witnessed
18483 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18484 is used instead. To work around that ambiguity, we treat
18485 the bounds as signed, and thus sign-extend their values, when
18486 the base type is signed. */
18488 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18489 if (low
.kind () == PROP_CONST
18490 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18491 low
.set_const_val (low
.const_val () | negative_mask
);
18492 if (high
.kind () == PROP_CONST
18493 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18494 high
.set_const_val (high
.const_val () | negative_mask
);
18496 /* Check for bit and byte strides. */
18497 struct dynamic_prop byte_stride_prop
;
18498 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18499 if (attr_byte_stride
!= nullptr)
18501 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18502 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18506 struct dynamic_prop bit_stride_prop
;
18507 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18508 if (attr_bit_stride
!= nullptr)
18510 /* It only makes sense to have either a bit or byte stride. */
18511 if (attr_byte_stride
!= nullptr)
18513 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18514 "- DIE at %s [in module %s]"),
18515 sect_offset_str (die
->sect_off
),
18516 objfile_name (cu
->per_objfile
->objfile
));
18517 attr_bit_stride
= nullptr;
18521 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18522 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18527 if (attr_byte_stride
!= nullptr
18528 || attr_bit_stride
!= nullptr)
18530 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18531 struct dynamic_prop
*stride
18532 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18535 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18536 &high
, bias
, stride
, byte_stride_p
);
18539 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18541 if (high_bound_is_count
)
18542 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18544 /* Ada expects an empty array on no boundary attributes. */
18545 if (attr
== NULL
&& cu
->language
!= language_ada
)
18546 range_type
->bounds ()->high
.set_undefined ();
18548 name
= dwarf2_name (die
, cu
);
18550 range_type
->set_name (name
);
18552 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18553 if (attr
!= nullptr)
18554 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18556 maybe_set_alignment (cu
, die
, range_type
);
18558 set_die_type (die
, range_type
, cu
);
18560 /* set_die_type should be already done. */
18561 set_descriptive_type (range_type
, die
, cu
);
18566 static struct type
*
18567 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18571 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18572 type
->set_name (dwarf2_name (die
, cu
));
18574 /* In Ada, an unspecified type is typically used when the description
18575 of the type is deferred to a different unit. When encountering
18576 such a type, we treat it as a stub, and try to resolve it later on,
18578 if (cu
->language
== language_ada
)
18579 type
->set_is_stub (true);
18581 return set_die_type (die
, type
, cu
);
18584 /* Read a single die and all its descendents. Set the die's sibling
18585 field to NULL; set other fields in the die correctly, and set all
18586 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18587 location of the info_ptr after reading all of those dies. PARENT
18588 is the parent of the die in question. */
18590 static struct die_info
*
18591 read_die_and_children (const struct die_reader_specs
*reader
,
18592 const gdb_byte
*info_ptr
,
18593 const gdb_byte
**new_info_ptr
,
18594 struct die_info
*parent
)
18596 struct die_info
*die
;
18597 const gdb_byte
*cur_ptr
;
18599 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18602 *new_info_ptr
= cur_ptr
;
18605 store_in_ref_table (die
, reader
->cu
);
18607 if (die
->has_children
)
18608 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18612 *new_info_ptr
= cur_ptr
;
18615 die
->sibling
= NULL
;
18616 die
->parent
= parent
;
18620 /* Read a die, all of its descendents, and all of its siblings; set
18621 all of the fields of all of the dies correctly. Arguments are as
18622 in read_die_and_children. */
18624 static struct die_info
*
18625 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18626 const gdb_byte
*info_ptr
,
18627 const gdb_byte
**new_info_ptr
,
18628 struct die_info
*parent
)
18630 struct die_info
*first_die
, *last_sibling
;
18631 const gdb_byte
*cur_ptr
;
18633 cur_ptr
= info_ptr
;
18634 first_die
= last_sibling
= NULL
;
18638 struct die_info
*die
18639 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18643 *new_info_ptr
= cur_ptr
;
18650 last_sibling
->sibling
= die
;
18652 last_sibling
= die
;
18656 /* Read a die, all of its descendents, and all of its siblings; set
18657 all of the fields of all of the dies correctly. Arguments are as
18658 in read_die_and_children.
18659 This the main entry point for reading a DIE and all its children. */
18661 static struct die_info
*
18662 read_die_and_siblings (const struct die_reader_specs
*reader
,
18663 const gdb_byte
*info_ptr
,
18664 const gdb_byte
**new_info_ptr
,
18665 struct die_info
*parent
)
18667 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18668 new_info_ptr
, parent
);
18670 if (dwarf_die_debug
)
18672 fprintf_unfiltered (gdb_stdlog
,
18673 "Read die from %s@0x%x of %s:\n",
18674 reader
->die_section
->get_name (),
18675 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18676 bfd_get_filename (reader
->abfd
));
18677 dump_die (die
, dwarf_die_debug
);
18683 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18685 The caller is responsible for filling in the extra attributes
18686 and updating (*DIEP)->num_attrs.
18687 Set DIEP to point to a newly allocated die with its information,
18688 except for its child, sibling, and parent fields. */
18690 static const gdb_byte
*
18691 read_full_die_1 (const struct die_reader_specs
*reader
,
18692 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18693 int num_extra_attrs
)
18695 unsigned int abbrev_number
, bytes_read
, i
;
18696 const struct abbrev_info
*abbrev
;
18697 struct die_info
*die
;
18698 struct dwarf2_cu
*cu
= reader
->cu
;
18699 bfd
*abfd
= reader
->abfd
;
18701 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18702 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18703 info_ptr
+= bytes_read
;
18704 if (!abbrev_number
)
18710 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18712 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18714 bfd_get_filename (abfd
));
18716 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18717 die
->sect_off
= sect_off
;
18718 die
->tag
= abbrev
->tag
;
18719 die
->abbrev
= abbrev_number
;
18720 die
->has_children
= abbrev
->has_children
;
18722 /* Make the result usable.
18723 The caller needs to update num_attrs after adding the extra
18725 die
->num_attrs
= abbrev
->num_attrs
;
18727 bool any_need_reprocess
= false;
18728 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18730 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18732 if (die
->attrs
[i
].requires_reprocessing_p ())
18733 any_need_reprocess
= true;
18736 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18737 if (attr
!= nullptr && attr
->form_is_unsigned ())
18738 cu
->str_offsets_base
= attr
->as_unsigned ();
18740 attr
= die
->attr (DW_AT_loclists_base
);
18741 if (attr
!= nullptr)
18742 cu
->loclist_base
= attr
->as_unsigned ();
18744 auto maybe_addr_base
= die
->addr_base ();
18745 if (maybe_addr_base
.has_value ())
18746 cu
->addr_base
= *maybe_addr_base
;
18748 attr
= die
->attr (DW_AT_rnglists_base
);
18749 if (attr
!= nullptr)
18750 cu
->rnglists_base
= attr
->as_unsigned ();
18752 if (any_need_reprocess
)
18754 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18756 if (die
->attrs
[i
].requires_reprocessing_p ())
18757 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18764 /* Read a die and all its attributes.
18765 Set DIEP to point to a newly allocated die with its information,
18766 except for its child, sibling, and parent fields. */
18768 static const gdb_byte
*
18769 read_full_die (const struct die_reader_specs
*reader
,
18770 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18772 const gdb_byte
*result
;
18774 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18776 if (dwarf_die_debug
)
18778 fprintf_unfiltered (gdb_stdlog
,
18779 "Read die from %s@0x%x of %s:\n",
18780 reader
->die_section
->get_name (),
18781 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18782 bfd_get_filename (reader
->abfd
));
18783 dump_die (*diep
, dwarf_die_debug
);
18790 /* Returns nonzero if TAG represents a type that we might generate a partial
18794 is_type_tag_for_partial (int tag
, enum language lang
)
18799 /* Some types that would be reasonable to generate partial symbols for,
18800 that we don't at present. Note that normally this does not
18801 matter, mainly because C compilers don't give names to these
18802 types, but instead emit DW_TAG_typedef. */
18803 case DW_TAG_file_type
:
18804 case DW_TAG_ptr_to_member_type
:
18805 case DW_TAG_set_type
:
18806 case DW_TAG_string_type
:
18807 case DW_TAG_subroutine_type
:
18810 /* GNAT may emit an array with a name, but no typedef, so we
18811 need to make a symbol in this case. */
18812 case DW_TAG_array_type
:
18813 return lang
== language_ada
;
18815 case DW_TAG_base_type
:
18816 case DW_TAG_class_type
:
18817 case DW_TAG_interface_type
:
18818 case DW_TAG_enumeration_type
:
18819 case DW_TAG_structure_type
:
18820 case DW_TAG_subrange_type
:
18821 case DW_TAG_typedef
:
18822 case DW_TAG_union_type
:
18829 /* Load all DIEs that are interesting for partial symbols into memory. */
18831 static struct partial_die_info
*
18832 load_partial_dies (const struct die_reader_specs
*reader
,
18833 const gdb_byte
*info_ptr
, int building_psymtab
)
18835 struct dwarf2_cu
*cu
= reader
->cu
;
18836 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18837 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18838 unsigned int bytes_read
;
18839 unsigned int load_all
= 0;
18840 int nesting_level
= 1;
18845 gdb_assert (cu
->per_cu
!= NULL
);
18846 if (cu
->load_all_dies
)
18850 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18854 &cu
->comp_unit_obstack
,
18855 hashtab_obstack_allocate
,
18856 dummy_obstack_deallocate
);
18860 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
18863 /* A NULL abbrev means the end of a series of children. */
18864 if (abbrev
== NULL
)
18866 if (--nesting_level
== 0)
18869 info_ptr
+= bytes_read
;
18870 last_die
= parent_die
;
18871 parent_die
= parent_die
->die_parent
;
18875 /* Check for template arguments. We never save these; if
18876 they're seen, we just mark the parent, and go on our way. */
18877 if (parent_die
!= NULL
18878 && cu
->language
== language_cplus
18879 && (abbrev
->tag
== DW_TAG_template_type_param
18880 || abbrev
->tag
== DW_TAG_template_value_param
))
18882 parent_die
->has_template_arguments
= 1;
18886 /* We don't need a partial DIE for the template argument. */
18887 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18892 /* We only recurse into c++ subprograms looking for template arguments.
18893 Skip their other children. */
18895 && cu
->language
== language_cplus
18896 && parent_die
!= NULL
18897 && parent_die
->tag
== DW_TAG_subprogram
18898 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18900 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18904 /* Check whether this DIE is interesting enough to save. Normally
18905 we would not be interested in members here, but there may be
18906 later variables referencing them via DW_AT_specification (for
18907 static members). */
18909 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
18910 && abbrev
->tag
!= DW_TAG_constant
18911 && abbrev
->tag
!= DW_TAG_enumerator
18912 && abbrev
->tag
!= DW_TAG_subprogram
18913 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18914 && abbrev
->tag
!= DW_TAG_lexical_block
18915 && abbrev
->tag
!= DW_TAG_variable
18916 && abbrev
->tag
!= DW_TAG_namespace
18917 && abbrev
->tag
!= DW_TAG_module
18918 && abbrev
->tag
!= DW_TAG_member
18919 && abbrev
->tag
!= DW_TAG_imported_unit
18920 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18922 /* Otherwise we skip to the next sibling, if any. */
18923 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18927 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18930 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18932 /* This two-pass algorithm for processing partial symbols has a
18933 high cost in cache pressure. Thus, handle some simple cases
18934 here which cover the majority of C partial symbols. DIEs
18935 which neither have specification tags in them, nor could have
18936 specification tags elsewhere pointing at them, can simply be
18937 processed and discarded.
18939 This segment is also optional; scan_partial_symbols and
18940 add_partial_symbol will handle these DIEs if we chain
18941 them in normally. When compilers which do not emit large
18942 quantities of duplicate debug information are more common,
18943 this code can probably be removed. */
18945 /* Any complete simple types at the top level (pretty much all
18946 of them, for a language without namespaces), can be processed
18948 if (parent_die
== NULL
18949 && pdi
.has_specification
== 0
18950 && pdi
.is_declaration
== 0
18951 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18952 || pdi
.tag
== DW_TAG_base_type
18953 || pdi
.tag
== DW_TAG_array_type
18954 || pdi
.tag
== DW_TAG_subrange_type
))
18956 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18957 add_partial_symbol (&pdi
, cu
);
18959 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18963 /* The exception for DW_TAG_typedef with has_children above is
18964 a workaround of GCC PR debug/47510. In the case of this complaint
18965 type_name_or_error will error on such types later.
18967 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18968 it could not find the child DIEs referenced later, this is checked
18969 above. In correct DWARF DW_TAG_typedef should have no children. */
18971 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18972 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18973 "- DIE at %s [in module %s]"),
18974 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18976 /* If we're at the second level, and we're an enumerator, and
18977 our parent has no specification (meaning possibly lives in a
18978 namespace elsewhere), then we can add the partial symbol now
18979 instead of queueing it. */
18980 if (pdi
.tag
== DW_TAG_enumerator
18981 && parent_die
!= NULL
18982 && parent_die
->die_parent
== NULL
18983 && parent_die
->tag
== DW_TAG_enumeration_type
18984 && parent_die
->has_specification
== 0)
18986 if (pdi
.raw_name
== NULL
)
18987 complaint (_("malformed enumerator DIE ignored"));
18988 else if (building_psymtab
)
18989 add_partial_symbol (&pdi
, cu
);
18991 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18995 struct partial_die_info
*part_die
18996 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18998 /* We'll save this DIE so link it in. */
18999 part_die
->die_parent
= parent_die
;
19000 part_die
->die_sibling
= NULL
;
19001 part_die
->die_child
= NULL
;
19003 if (last_die
&& last_die
== parent_die
)
19004 last_die
->die_child
= part_die
;
19006 last_die
->die_sibling
= part_die
;
19008 last_die
= part_die
;
19010 if (first_die
== NULL
)
19011 first_die
= part_die
;
19013 /* Maybe add the DIE to the hash table. Not all DIEs that we
19014 find interesting need to be in the hash table, because we
19015 also have the parent/sibling/child chains; only those that we
19016 might refer to by offset later during partial symbol reading.
19018 For now this means things that might have be the target of a
19019 DW_AT_specification, DW_AT_abstract_origin, or
19020 DW_AT_extension. DW_AT_extension will refer only to
19021 namespaces; DW_AT_abstract_origin refers to functions (and
19022 many things under the function DIE, but we do not recurse
19023 into function DIEs during partial symbol reading) and
19024 possibly variables as well; DW_AT_specification refers to
19025 declarations. Declarations ought to have the DW_AT_declaration
19026 flag. It happens that GCC forgets to put it in sometimes, but
19027 only for functions, not for types.
19029 Adding more things than necessary to the hash table is harmless
19030 except for the performance cost. Adding too few will result in
19031 wasted time in find_partial_die, when we reread the compilation
19032 unit with load_all_dies set. */
19035 || abbrev
->tag
== DW_TAG_constant
19036 || abbrev
->tag
== DW_TAG_subprogram
19037 || abbrev
->tag
== DW_TAG_variable
19038 || abbrev
->tag
== DW_TAG_namespace
19039 || part_die
->is_declaration
)
19043 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19044 to_underlying (part_die
->sect_off
),
19049 /* For some DIEs we want to follow their children (if any). For C
19050 we have no reason to follow the children of structures; for other
19051 languages we have to, so that we can get at method physnames
19052 to infer fully qualified class names, for DW_AT_specification,
19053 and for C++ template arguments. For C++, we also look one level
19054 inside functions to find template arguments (if the name of the
19055 function does not already contain the template arguments).
19057 For Ada and Fortran, we need to scan the children of subprograms
19058 and lexical blocks as well because these languages allow the
19059 definition of nested entities that could be interesting for the
19060 debugger, such as nested subprograms for instance. */
19061 if (last_die
->has_children
19063 || last_die
->tag
== DW_TAG_namespace
19064 || last_die
->tag
== DW_TAG_module
19065 || last_die
->tag
== DW_TAG_enumeration_type
19066 || (cu
->language
== language_cplus
19067 && last_die
->tag
== DW_TAG_subprogram
19068 && (last_die
->raw_name
== NULL
19069 || strchr (last_die
->raw_name
, '<') == NULL
))
19070 || (cu
->language
!= language_c
19071 && (last_die
->tag
== DW_TAG_class_type
19072 || last_die
->tag
== DW_TAG_interface_type
19073 || last_die
->tag
== DW_TAG_structure_type
19074 || last_die
->tag
== DW_TAG_union_type
))
19075 || ((cu
->language
== language_ada
19076 || cu
->language
== language_fortran
)
19077 && (last_die
->tag
== DW_TAG_subprogram
19078 || last_die
->tag
== DW_TAG_lexical_block
))))
19081 parent_die
= last_die
;
19085 /* Otherwise we skip to the next sibling, if any. */
19086 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19088 /* Back to the top, do it again. */
19092 partial_die_info::partial_die_info (sect_offset sect_off_
,
19093 const struct abbrev_info
*abbrev
)
19094 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19098 /* See class definition. */
19101 partial_die_info::name (dwarf2_cu
*cu
)
19103 if (!canonical_name
&& raw_name
!= nullptr)
19105 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19106 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19107 canonical_name
= 1;
19113 /* Read a minimal amount of information into the minimal die structure.
19114 INFO_PTR should point just after the initial uleb128 of a DIE. */
19117 partial_die_info::read (const struct die_reader_specs
*reader
,
19118 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19120 struct dwarf2_cu
*cu
= reader
->cu
;
19121 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19123 int has_low_pc_attr
= 0;
19124 int has_high_pc_attr
= 0;
19125 int high_pc_relative
= 0;
19127 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19130 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19131 /* String and address offsets that need to do the reprocessing have
19132 already been read at this point, so there is no need to wait until
19133 the loop terminates to do the reprocessing. */
19134 if (attr
.requires_reprocessing_p ())
19135 read_attribute_reprocess (reader
, &attr
, tag
);
19136 /* Store the data if it is of an attribute we want to keep in a
19137 partial symbol table. */
19143 case DW_TAG_compile_unit
:
19144 case DW_TAG_partial_unit
:
19145 case DW_TAG_type_unit
:
19146 /* Compilation units have a DW_AT_name that is a filename, not
19147 a source language identifier. */
19148 case DW_TAG_enumeration_type
:
19149 case DW_TAG_enumerator
:
19150 /* These tags always have simple identifiers already; no need
19151 to canonicalize them. */
19152 canonical_name
= 1;
19153 raw_name
= attr
.as_string ();
19156 canonical_name
= 0;
19157 raw_name
= attr
.as_string ();
19161 case DW_AT_linkage_name
:
19162 case DW_AT_MIPS_linkage_name
:
19163 /* Note that both forms of linkage name might appear. We
19164 assume they will be the same, and we only store the last
19166 linkage_name
= attr
.as_string ();
19169 has_low_pc_attr
= 1;
19170 lowpc
= attr
.as_address ();
19172 case DW_AT_high_pc
:
19173 has_high_pc_attr
= 1;
19174 highpc
= attr
.as_address ();
19175 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19176 high_pc_relative
= 1;
19178 case DW_AT_location
:
19179 /* Support the .debug_loc offsets. */
19180 if (attr
.form_is_block ())
19182 d
.locdesc
= attr
.as_block ();
19184 else if (attr
.form_is_section_offset ())
19186 dwarf2_complex_location_expr_complaint ();
19190 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19191 "partial symbol information");
19194 case DW_AT_external
:
19195 is_external
= attr
.as_boolean ();
19197 case DW_AT_declaration
:
19198 is_declaration
= attr
.as_boolean ();
19203 case DW_AT_abstract_origin
:
19204 case DW_AT_specification
:
19205 case DW_AT_extension
:
19206 has_specification
= 1;
19207 spec_offset
= attr
.get_ref_die_offset ();
19208 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19209 || cu
->per_cu
->is_dwz
);
19211 case DW_AT_sibling
:
19212 /* Ignore absolute siblings, they might point outside of
19213 the current compile unit. */
19214 if (attr
.form
== DW_FORM_ref_addr
)
19215 complaint (_("ignoring absolute DW_AT_sibling"));
19218 const gdb_byte
*buffer
= reader
->buffer
;
19219 sect_offset off
= attr
.get_ref_die_offset ();
19220 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19222 if (sibling_ptr
< info_ptr
)
19223 complaint (_("DW_AT_sibling points backwards"));
19224 else if (sibling_ptr
> reader
->buffer_end
)
19225 reader
->die_section
->overflow_complaint ();
19227 sibling
= sibling_ptr
;
19230 case DW_AT_byte_size
:
19233 case DW_AT_const_value
:
19234 has_const_value
= 1;
19236 case DW_AT_calling_convention
:
19237 /* DWARF doesn't provide a way to identify a program's source-level
19238 entry point. DW_AT_calling_convention attributes are only meant
19239 to describe functions' calling conventions.
19241 However, because it's a necessary piece of information in
19242 Fortran, and before DWARF 4 DW_CC_program was the only
19243 piece of debugging information whose definition refers to
19244 a 'main program' at all, several compilers marked Fortran
19245 main programs with DW_CC_program --- even when those
19246 functions use the standard calling conventions.
19248 Although DWARF now specifies a way to provide this
19249 information, we support this practice for backward
19251 if (attr
.constant_value (0) == DW_CC_program
19252 && cu
->language
== language_fortran
)
19253 main_subprogram
= 1;
19257 LONGEST value
= attr
.constant_value (-1);
19258 if (value
== DW_INL_inlined
19259 || value
== DW_INL_declared_inlined
)
19260 may_be_inlined
= 1;
19265 if (tag
== DW_TAG_imported_unit
)
19267 d
.sect_off
= attr
.get_ref_die_offset ();
19268 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19269 || cu
->per_cu
->is_dwz
);
19273 case DW_AT_main_subprogram
:
19274 main_subprogram
= attr
.as_boolean ();
19279 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19280 on DWARF version). */
19281 ULONGEST ranges_offset
= attr
.as_unsigned ();
19283 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19285 if (tag
!= DW_TAG_compile_unit
)
19286 ranges_offset
+= cu
->gnu_ranges_base
;
19288 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19299 /* For Ada, if both the name and the linkage name appear, we prefer
19300 the latter. This lets "catch exception" work better, regardless
19301 of the order in which the name and linkage name were emitted.
19302 Really, though, this is just a workaround for the fact that gdb
19303 doesn't store both the name and the linkage name. */
19304 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19305 raw_name
= linkage_name
;
19307 if (high_pc_relative
)
19310 if (has_low_pc_attr
&& has_high_pc_attr
)
19312 /* When using the GNU linker, .gnu.linkonce. sections are used to
19313 eliminate duplicate copies of functions and vtables and such.
19314 The linker will arbitrarily choose one and discard the others.
19315 The AT_*_pc values for such functions refer to local labels in
19316 these sections. If the section from that file was discarded, the
19317 labels are not in the output, so the relocs get a value of 0.
19318 If this is a discarded function, mark the pc bounds as invalid,
19319 so that GDB will ignore it. */
19320 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19322 struct objfile
*objfile
= per_objfile
->objfile
;
19323 struct gdbarch
*gdbarch
= objfile
->arch ();
19325 complaint (_("DW_AT_low_pc %s is zero "
19326 "for DIE at %s [in module %s]"),
19327 paddress (gdbarch
, lowpc
),
19328 sect_offset_str (sect_off
),
19329 objfile_name (objfile
));
19331 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19332 else if (lowpc
>= highpc
)
19334 struct objfile
*objfile
= per_objfile
->objfile
;
19335 struct gdbarch
*gdbarch
= objfile
->arch ();
19337 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19338 "for DIE at %s [in module %s]"),
19339 paddress (gdbarch
, lowpc
),
19340 paddress (gdbarch
, highpc
),
19341 sect_offset_str (sect_off
),
19342 objfile_name (objfile
));
19351 /* Find a cached partial DIE at OFFSET in CU. */
19353 struct partial_die_info
*
19354 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19356 struct partial_die_info
*lookup_die
= NULL
;
19357 struct partial_die_info
part_die (sect_off
);
19359 lookup_die
= ((struct partial_die_info
*)
19360 htab_find_with_hash (partial_dies
, &part_die
,
19361 to_underlying (sect_off
)));
19366 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19367 except in the case of .debug_types DIEs which do not reference
19368 outside their CU (they do however referencing other types via
19369 DW_FORM_ref_sig8). */
19371 static const struct cu_partial_die_info
19372 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19374 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19375 struct objfile
*objfile
= per_objfile
->objfile
;
19376 struct partial_die_info
*pd
= NULL
;
19378 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19379 && cu
->header
.offset_in_cu_p (sect_off
))
19381 pd
= cu
->find_partial_die (sect_off
);
19384 /* We missed recording what we needed.
19385 Load all dies and try again. */
19389 /* TUs don't reference other CUs/TUs (except via type signatures). */
19390 if (cu
->per_cu
->is_debug_types
)
19392 error (_("Dwarf Error: Type Unit at offset %s contains"
19393 " external reference to offset %s [in module %s].\n"),
19394 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19395 bfd_get_filename (objfile
->obfd
));
19397 dwarf2_per_cu_data
*per_cu
19398 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19401 cu
= per_objfile
->get_cu (per_cu
);
19402 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19403 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19405 cu
= per_objfile
->get_cu (per_cu
);
19408 pd
= cu
->find_partial_die (sect_off
);
19411 /* If we didn't find it, and not all dies have been loaded,
19412 load them all and try again. */
19414 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19416 cu
->load_all_dies
= 1;
19418 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19419 THIS_CU->cu may already be in use. So we can't just free it and
19420 replace its DIEs with the ones we read in. Instead, we leave those
19421 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19422 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19424 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19426 pd
= cu
->find_partial_die (sect_off
);
19430 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19431 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19435 /* See if we can figure out if the class lives in a namespace. We do
19436 this by looking for a member function; its demangled name will
19437 contain namespace info, if there is any. */
19440 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19441 struct dwarf2_cu
*cu
)
19443 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19444 what template types look like, because the demangler
19445 frequently doesn't give the same name as the debug info. We
19446 could fix this by only using the demangled name to get the
19447 prefix (but see comment in read_structure_type). */
19449 struct partial_die_info
*real_pdi
;
19450 struct partial_die_info
*child_pdi
;
19452 /* If this DIE (this DIE's specification, if any) has a parent, then
19453 we should not do this. We'll prepend the parent's fully qualified
19454 name when we create the partial symbol. */
19456 real_pdi
= struct_pdi
;
19457 while (real_pdi
->has_specification
)
19459 auto res
= find_partial_die (real_pdi
->spec_offset
,
19460 real_pdi
->spec_is_dwz
, cu
);
19461 real_pdi
= res
.pdi
;
19465 if (real_pdi
->die_parent
!= NULL
)
19468 for (child_pdi
= struct_pdi
->die_child
;
19470 child_pdi
= child_pdi
->die_sibling
)
19472 if (child_pdi
->tag
== DW_TAG_subprogram
19473 && child_pdi
->linkage_name
!= NULL
)
19475 gdb::unique_xmalloc_ptr
<char> actual_class_name
19476 (cu
->language_defn
->class_name_from_physname
19477 (child_pdi
->linkage_name
));
19478 if (actual_class_name
!= NULL
)
19480 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19481 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19482 struct_pdi
->canonical_name
= 1;
19489 /* Return true if a DIE with TAG may have the DW_AT_const_value
19493 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19497 case DW_TAG_constant
:
19498 case DW_TAG_enumerator
:
19499 case DW_TAG_formal_parameter
:
19500 case DW_TAG_template_value_param
:
19501 case DW_TAG_variable
:
19509 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19511 /* Once we've fixed up a die, there's no point in doing so again.
19512 This also avoids a memory leak if we were to call
19513 guess_partial_die_structure_name multiple times. */
19517 /* If we found a reference attribute and the DIE has no name, try
19518 to find a name in the referred to DIE. */
19520 if (raw_name
== NULL
&& has_specification
)
19522 struct partial_die_info
*spec_die
;
19524 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19525 spec_die
= res
.pdi
;
19528 spec_die
->fixup (cu
);
19530 if (spec_die
->raw_name
)
19532 raw_name
= spec_die
->raw_name
;
19533 canonical_name
= spec_die
->canonical_name
;
19535 /* Copy DW_AT_external attribute if it is set. */
19536 if (spec_die
->is_external
)
19537 is_external
= spec_die
->is_external
;
19541 if (!has_const_value
&& has_specification
19542 && can_have_DW_AT_const_value_p (tag
))
19544 struct partial_die_info
*spec_die
;
19546 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19547 spec_die
= res
.pdi
;
19550 spec_die
->fixup (cu
);
19552 if (spec_die
->has_const_value
)
19554 /* Copy DW_AT_const_value attribute if it is set. */
19555 has_const_value
= spec_die
->has_const_value
;
19559 /* Set default names for some unnamed DIEs. */
19561 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19563 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19564 canonical_name
= 1;
19567 /* If there is no parent die to provide a namespace, and there are
19568 children, see if we can determine the namespace from their linkage
19570 if (cu
->language
== language_cplus
19571 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19572 && die_parent
== NULL
19574 && (tag
== DW_TAG_class_type
19575 || tag
== DW_TAG_structure_type
19576 || tag
== DW_TAG_union_type
))
19577 guess_partial_die_structure_name (this, cu
);
19579 /* GCC might emit a nameless struct or union that has a linkage
19580 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19581 if (raw_name
== NULL
19582 && (tag
== DW_TAG_class_type
19583 || tag
== DW_TAG_interface_type
19584 || tag
== DW_TAG_structure_type
19585 || tag
== DW_TAG_union_type
)
19586 && linkage_name
!= NULL
)
19588 gdb::unique_xmalloc_ptr
<char> demangled
19589 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19590 if (demangled
!= nullptr)
19594 /* Strip any leading namespaces/classes, keep only the base name.
19595 DW_AT_name for named DIEs does not contain the prefixes. */
19596 base
= strrchr (demangled
.get (), ':');
19597 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19600 base
= demangled
.get ();
19602 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19603 raw_name
= objfile
->intern (base
);
19604 canonical_name
= 1;
19611 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19612 contents from the given SECTION in the HEADER.
19614 HEADER_OFFSET is the offset of the header in the section. */
19616 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19617 struct dwarf2_section_info
*section
,
19618 sect_offset header_offset
)
19620 unsigned int bytes_read
;
19621 bfd
*abfd
= section
->get_bfd_owner ();
19622 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19624 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19625 info_ptr
+= bytes_read
;
19627 header
->version
= read_2_bytes (abfd
, info_ptr
);
19630 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19633 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19636 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19639 /* Return the DW_AT_loclists_base value for the CU. */
19641 lookup_loclist_base (struct dwarf2_cu
*cu
)
19643 /* For the .dwo unit, the loclist_base points to the first offset following
19644 the header. The header consists of the following entities-
19645 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19647 2. version (2 bytes)
19648 3. address size (1 byte)
19649 4. segment selector size (1 byte)
19650 5. offset entry count (4 bytes)
19651 These sizes are derived as per the DWARFv5 standard. */
19652 if (cu
->dwo_unit
!= nullptr)
19654 if (cu
->header
.initial_length_size
== 4)
19655 return LOCLIST_HEADER_SIZE32
;
19656 return LOCLIST_HEADER_SIZE64
;
19658 return cu
->loclist_base
;
19661 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19662 array of offsets in the .debug_loclists section. */
19665 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19667 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19668 struct objfile
*objfile
= per_objfile
->objfile
;
19669 bfd
*abfd
= objfile
->obfd
;
19670 ULONGEST loclist_header_size
=
19671 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19672 : LOCLIST_HEADER_SIZE64
);
19673 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19675 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19676 ULONGEST start_offset
=
19677 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19679 /* Get loclists section. */
19680 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19682 /* Read the loclists section content. */
19683 section
->read (objfile
);
19684 if (section
->buffer
== NULL
)
19685 error (_("DW_FORM_loclistx used without .debug_loclists "
19686 "section [in module %s]"), objfile_name (objfile
));
19688 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19689 so if loclist_base is smaller than the header size, we have a problem. */
19690 if (loclist_base
< loclist_header_size
)
19691 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19692 objfile_name (objfile
));
19694 /* Read the header of the loclists contribution. */
19695 struct loclists_rnglists_header header
;
19696 read_loclists_rnglists_header (&header
, section
,
19697 (sect_offset
) (loclist_base
- loclist_header_size
));
19699 /* Verify the loclist index is valid. */
19700 if (loclist_index
>= header
.offset_entry_count
)
19701 error (_("DW_FORM_loclistx pointing outside of "
19702 ".debug_loclists offset array [in module %s]"),
19703 objfile_name (objfile
));
19705 /* Validate that reading won't go beyond the end of the section. */
19706 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19707 error (_("Reading DW_FORM_loclistx index beyond end of"
19708 ".debug_loclists section [in module %s]"),
19709 objfile_name (objfile
));
19711 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19713 if (cu
->header
.offset_size
== 4)
19714 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19716 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19719 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19720 array of offsets in the .debug_rnglists section. */
19723 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19726 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19727 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19728 bfd
*abfd
= objfile
->obfd
;
19729 ULONGEST rnglist_header_size
=
19730 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19731 : RNGLIST_HEADER_SIZE64
);
19733 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19734 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19736 ULONGEST rnglist_base
=
19737 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19739 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19740 ULONGEST start_offset
=
19741 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19743 /* Get rnglists section. */
19744 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19746 /* Read the rnglists section content. */
19747 section
->read (objfile
);
19748 if (section
->buffer
== nullptr)
19749 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19751 objfile_name (objfile
));
19753 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19754 so if rnglist_base is smaller than the header size, we have a problem. */
19755 if (rnglist_base
< rnglist_header_size
)
19756 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19757 objfile_name (objfile
));
19759 /* Read the header of the rnglists contribution. */
19760 struct loclists_rnglists_header header
;
19761 read_loclists_rnglists_header (&header
, section
,
19762 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19764 /* Verify the rnglist index is valid. */
19765 if (rnglist_index
>= header
.offset_entry_count
)
19766 error (_("DW_FORM_rnglistx index pointing outside of "
19767 ".debug_rnglists offset array [in module %s]"),
19768 objfile_name (objfile
));
19770 /* Validate that reading won't go beyond the end of the section. */
19771 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19772 error (_("Reading DW_FORM_rnglistx index beyond end of"
19773 ".debug_rnglists section [in module %s]"),
19774 objfile_name (objfile
));
19776 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19778 if (cu
->header
.offset_size
== 4)
19779 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19781 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19784 /* Process the attributes that had to be skipped in the first round. These
19785 attributes are the ones that need str_offsets_base or addr_base attributes.
19786 They could not have been processed in the first round, because at the time
19787 the values of str_offsets_base or addr_base may not have been known. */
19789 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19790 struct attribute
*attr
, dwarf_tag tag
)
19792 struct dwarf2_cu
*cu
= reader
->cu
;
19793 switch (attr
->form
)
19795 case DW_FORM_addrx
:
19796 case DW_FORM_GNU_addr_index
:
19797 attr
->set_address (read_addr_index (cu
,
19798 attr
->as_unsigned_reprocess ()));
19800 case DW_FORM_loclistx
:
19802 sect_offset loclists_sect_off
19803 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19805 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19808 case DW_FORM_rnglistx
:
19810 sect_offset rnglists_sect_off
19811 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19813 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19817 case DW_FORM_strx1
:
19818 case DW_FORM_strx2
:
19819 case DW_FORM_strx3
:
19820 case DW_FORM_strx4
:
19821 case DW_FORM_GNU_str_index
:
19823 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19824 gdb_assert (!attr
->canonical_string_p ());
19825 if (reader
->dwo_file
!= NULL
)
19826 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19829 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19834 gdb_assert_not_reached (_("Unexpected DWARF form."));
19838 /* Read an attribute value described by an attribute form. */
19840 static const gdb_byte
*
19841 read_attribute_value (const struct die_reader_specs
*reader
,
19842 struct attribute
*attr
, unsigned form
,
19843 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19845 struct dwarf2_cu
*cu
= reader
->cu
;
19846 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19847 struct objfile
*objfile
= per_objfile
->objfile
;
19848 bfd
*abfd
= reader
->abfd
;
19849 struct comp_unit_head
*cu_header
= &cu
->header
;
19850 unsigned int bytes_read
;
19851 struct dwarf_block
*blk
;
19853 attr
->form
= (enum dwarf_form
) form
;
19856 case DW_FORM_ref_addr
:
19857 if (cu_header
->version
== 2)
19858 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
19861 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19863 info_ptr
+= bytes_read
;
19865 case DW_FORM_GNU_ref_alt
:
19866 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19868 info_ptr
+= bytes_read
;
19872 struct gdbarch
*gdbarch
= objfile
->arch ();
19873 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
19874 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19875 attr
->set_address (addr
);
19876 info_ptr
+= bytes_read
;
19879 case DW_FORM_block2
:
19880 blk
= dwarf_alloc_block (cu
);
19881 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19883 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19884 info_ptr
+= blk
->size
;
19885 attr
->set_block (blk
);
19887 case DW_FORM_block4
:
19888 blk
= dwarf_alloc_block (cu
);
19889 blk
->size
= read_4_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_data2
:
19896 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
19899 case DW_FORM_data4
:
19900 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
19903 case DW_FORM_data8
:
19904 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
19907 case DW_FORM_data16
:
19908 blk
= dwarf_alloc_block (cu
);
19910 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19912 attr
->set_block (blk
);
19914 case DW_FORM_sec_offset
:
19915 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19917 info_ptr
+= bytes_read
;
19919 case DW_FORM_loclistx
:
19921 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19923 info_ptr
+= bytes_read
;
19926 case DW_FORM_string
:
19927 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
19929 info_ptr
+= bytes_read
;
19932 if (!cu
->per_cu
->is_dwz
)
19934 attr
->set_string_noncanonical
19935 (read_indirect_string (per_objfile
,
19936 abfd
, info_ptr
, cu_header
,
19938 info_ptr
+= bytes_read
;
19942 case DW_FORM_line_strp
:
19943 if (!cu
->per_cu
->is_dwz
)
19945 attr
->set_string_noncanonical
19946 (per_objfile
->read_line_string (info_ptr
, cu_header
,
19948 info_ptr
+= bytes_read
;
19952 case DW_FORM_GNU_strp_alt
:
19954 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
19955 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19958 attr
->set_string_noncanonical
19959 (dwz
->read_string (objfile
, str_offset
));
19960 info_ptr
+= bytes_read
;
19963 case DW_FORM_exprloc
:
19964 case DW_FORM_block
:
19965 blk
= dwarf_alloc_block (cu
);
19966 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19967 info_ptr
+= bytes_read
;
19968 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19969 info_ptr
+= blk
->size
;
19970 attr
->set_block (blk
);
19972 case DW_FORM_block1
:
19973 blk
= dwarf_alloc_block (cu
);
19974 blk
->size
= read_1_byte (abfd
, info_ptr
);
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_data1
:
19982 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
19985 case DW_FORM_flag_present
:
19986 attr
->set_unsigned (1);
19988 case DW_FORM_sdata
:
19989 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
19990 info_ptr
+= bytes_read
;
19992 case DW_FORM_rnglistx
:
19994 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19996 info_ptr
+= bytes_read
;
19999 case DW_FORM_udata
:
20000 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20001 info_ptr
+= bytes_read
;
20004 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20005 + read_1_byte (abfd
, info_ptr
)));
20009 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20010 + read_2_bytes (abfd
, info_ptr
)));
20014 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20015 + read_4_bytes (abfd
, info_ptr
)));
20019 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20020 + read_8_bytes (abfd
, info_ptr
)));
20023 case DW_FORM_ref_sig8
:
20024 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20027 case DW_FORM_ref_udata
:
20028 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20029 + read_unsigned_leb128 (abfd
, info_ptr
,
20031 info_ptr
+= bytes_read
;
20033 case DW_FORM_indirect
:
20034 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20035 info_ptr
+= bytes_read
;
20036 if (form
== DW_FORM_implicit_const
)
20038 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20039 info_ptr
+= bytes_read
;
20041 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20044 case DW_FORM_implicit_const
:
20045 attr
->set_signed (implicit_const
);
20047 case DW_FORM_addrx
:
20048 case DW_FORM_GNU_addr_index
:
20049 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20051 info_ptr
+= bytes_read
;
20054 case DW_FORM_strx1
:
20055 case DW_FORM_strx2
:
20056 case DW_FORM_strx3
:
20057 case DW_FORM_strx4
:
20058 case DW_FORM_GNU_str_index
:
20060 ULONGEST str_index
;
20061 if (form
== DW_FORM_strx1
)
20063 str_index
= read_1_byte (abfd
, info_ptr
);
20066 else if (form
== DW_FORM_strx2
)
20068 str_index
= read_2_bytes (abfd
, info_ptr
);
20071 else if (form
== DW_FORM_strx3
)
20073 str_index
= read_3_bytes (abfd
, info_ptr
);
20076 else if (form
== DW_FORM_strx4
)
20078 str_index
= read_4_bytes (abfd
, info_ptr
);
20083 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20084 info_ptr
+= bytes_read
;
20086 attr
->set_unsigned_reprocess (str_index
);
20090 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20091 dwarf_form_name (form
),
20092 bfd_get_filename (abfd
));
20096 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20097 attr
->form
= DW_FORM_GNU_ref_alt
;
20099 /* We have seen instances where the compiler tried to emit a byte
20100 size attribute of -1 which ended up being encoded as an unsigned
20101 0xffffffff. Although 0xffffffff is technically a valid size value,
20102 an object of this size seems pretty unlikely so we can relatively
20103 safely treat these cases as if the size attribute was invalid and
20104 treat them as zero by default. */
20105 if (attr
->name
== DW_AT_byte_size
20106 && form
== DW_FORM_data4
20107 && attr
->as_unsigned () >= 0xffffffff)
20110 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20111 hex_string (attr
->as_unsigned ()));
20112 attr
->set_unsigned (0);
20118 /* Read an attribute described by an abbreviated attribute. */
20120 static const gdb_byte
*
20121 read_attribute (const struct die_reader_specs
*reader
,
20122 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20123 const gdb_byte
*info_ptr
)
20125 attr
->name
= abbrev
->name
;
20126 attr
->string_is_canonical
= 0;
20127 attr
->requires_reprocessing
= 0;
20128 return read_attribute_value (reader
, attr
, abbrev
->form
,
20129 abbrev
->implicit_const
, info_ptr
);
20132 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20134 static const char *
20135 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20136 LONGEST str_offset
)
20138 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20139 str_offset
, "DW_FORM_strp");
20142 /* Return pointer to string at .debug_str offset as read from BUF.
20143 BUF is assumed to be in a compilation unit described by CU_HEADER.
20144 Return *BYTES_READ_PTR count of bytes read from BUF. */
20146 static const char *
20147 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20148 const gdb_byte
*buf
,
20149 const struct comp_unit_head
*cu_header
,
20150 unsigned int *bytes_read_ptr
)
20152 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20154 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20160 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20161 const struct comp_unit_head
*cu_header
,
20162 unsigned int *bytes_read_ptr
)
20164 bfd
*abfd
= objfile
->obfd
;
20165 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20167 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20170 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20171 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20172 ADDR_SIZE is the size of addresses from the CU header. */
20175 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20176 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20178 struct objfile
*objfile
= per_objfile
->objfile
;
20179 bfd
*abfd
= objfile
->obfd
;
20180 const gdb_byte
*info_ptr
;
20181 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20183 per_objfile
->per_bfd
->addr
.read (objfile
);
20184 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20185 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20186 objfile_name (objfile
));
20187 if (addr_base_or_zero
+ addr_index
* addr_size
20188 >= per_objfile
->per_bfd
->addr
.size
)
20189 error (_("DW_FORM_addr_index pointing outside of "
20190 ".debug_addr section [in module %s]"),
20191 objfile_name (objfile
));
20192 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20193 + addr_index
* addr_size
);
20194 if (addr_size
== 4)
20195 return bfd_get_32 (abfd
, info_ptr
);
20197 return bfd_get_64 (abfd
, info_ptr
);
20200 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20203 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20205 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20206 cu
->addr_base
, cu
->header
.addr_size
);
20209 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20212 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20213 unsigned int *bytes_read
)
20215 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20216 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20218 return read_addr_index (cu
, addr_index
);
20224 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20225 dwarf2_per_objfile
*per_objfile
,
20226 unsigned int addr_index
)
20228 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20229 gdb::optional
<ULONGEST
> addr_base
;
20232 /* We need addr_base and addr_size.
20233 If we don't have PER_CU->cu, we have to get it.
20234 Nasty, but the alternative is storing the needed info in PER_CU,
20235 which at this point doesn't seem justified: it's not clear how frequently
20236 it would get used and it would increase the size of every PER_CU.
20237 Entry points like dwarf2_per_cu_addr_size do a similar thing
20238 so we're not in uncharted territory here.
20239 Alas we need to be a bit more complicated as addr_base is contained
20242 We don't need to read the entire CU(/TU).
20243 We just need the header and top level die.
20245 IWBN to use the aging mechanism to let us lazily later discard the CU.
20246 For now we skip this optimization. */
20250 addr_base
= cu
->addr_base
;
20251 addr_size
= cu
->header
.addr_size
;
20255 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20256 addr_base
= reader
.cu
->addr_base
;
20257 addr_size
= reader
.cu
->header
.addr_size
;
20260 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20263 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20264 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20267 static const char *
20268 read_str_index (struct dwarf2_cu
*cu
,
20269 struct dwarf2_section_info
*str_section
,
20270 struct dwarf2_section_info
*str_offsets_section
,
20271 ULONGEST str_offsets_base
, ULONGEST str_index
)
20273 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20274 struct objfile
*objfile
= per_objfile
->objfile
;
20275 const char *objf_name
= objfile_name (objfile
);
20276 bfd
*abfd
= objfile
->obfd
;
20277 const gdb_byte
*info_ptr
;
20278 ULONGEST str_offset
;
20279 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20281 str_section
->read (objfile
);
20282 str_offsets_section
->read (objfile
);
20283 if (str_section
->buffer
== NULL
)
20284 error (_("%s used without %s section"
20285 " in CU at offset %s [in module %s]"),
20286 form_name
, str_section
->get_name (),
20287 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20288 if (str_offsets_section
->buffer
== NULL
)
20289 error (_("%s used without %s section"
20290 " in CU at offset %s [in module %s]"),
20291 form_name
, str_section
->get_name (),
20292 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20293 info_ptr
= (str_offsets_section
->buffer
20295 + str_index
* cu
->header
.offset_size
);
20296 if (cu
->header
.offset_size
== 4)
20297 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20299 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20300 if (str_offset
>= str_section
->size
)
20301 error (_("Offset from %s pointing outside of"
20302 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20303 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20304 return (const char *) (str_section
->buffer
+ str_offset
);
20307 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20309 static const char *
20310 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20312 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20313 ? reader
->cu
->header
.addr_size
: 0;
20314 return read_str_index (reader
->cu
,
20315 &reader
->dwo_file
->sections
.str
,
20316 &reader
->dwo_file
->sections
.str_offsets
,
20317 str_offsets_base
, str_index
);
20320 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20322 static const char *
20323 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20325 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20326 const char *objf_name
= objfile_name (objfile
);
20327 static const char form_name
[] = "DW_FORM_GNU_str_index";
20328 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20330 if (!cu
->str_offsets_base
.has_value ())
20331 error (_("%s used in Fission stub without %s"
20332 " in CU at offset 0x%lx [in module %s]"),
20333 form_name
, str_offsets_attr_name
,
20334 (long) cu
->header
.offset_size
, objf_name
);
20336 return read_str_index (cu
,
20337 &cu
->per_objfile
->per_bfd
->str
,
20338 &cu
->per_objfile
->per_bfd
->str_offsets
,
20339 *cu
->str_offsets_base
, str_index
);
20342 /* Return the length of an LEB128 number in BUF. */
20345 leb128_size (const gdb_byte
*buf
)
20347 const gdb_byte
*begin
= buf
;
20353 if ((byte
& 128) == 0)
20354 return buf
- begin
;
20359 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20368 cu
->language
= language_c
;
20371 case DW_LANG_C_plus_plus
:
20372 case DW_LANG_C_plus_plus_11
:
20373 case DW_LANG_C_plus_plus_14
:
20374 cu
->language
= language_cplus
;
20377 cu
->language
= language_d
;
20379 case DW_LANG_Fortran77
:
20380 case DW_LANG_Fortran90
:
20381 case DW_LANG_Fortran95
:
20382 case DW_LANG_Fortran03
:
20383 case DW_LANG_Fortran08
:
20384 cu
->language
= language_fortran
;
20387 cu
->language
= language_go
;
20389 case DW_LANG_Mips_Assembler
:
20390 cu
->language
= language_asm
;
20392 case DW_LANG_Ada83
:
20393 case DW_LANG_Ada95
:
20394 cu
->language
= language_ada
;
20396 case DW_LANG_Modula2
:
20397 cu
->language
= language_m2
;
20399 case DW_LANG_Pascal83
:
20400 cu
->language
= language_pascal
;
20403 cu
->language
= language_objc
;
20406 case DW_LANG_Rust_old
:
20407 cu
->language
= language_rust
;
20409 case DW_LANG_Cobol74
:
20410 case DW_LANG_Cobol85
:
20412 cu
->language
= language_minimal
;
20415 cu
->language_defn
= language_def (cu
->language
);
20418 /* Return the named attribute or NULL if not there. */
20420 static struct attribute
*
20421 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20426 struct attribute
*spec
= NULL
;
20428 for (i
= 0; i
< die
->num_attrs
; ++i
)
20430 if (die
->attrs
[i
].name
== name
)
20431 return &die
->attrs
[i
];
20432 if (die
->attrs
[i
].name
== DW_AT_specification
20433 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20434 spec
= &die
->attrs
[i
];
20440 die
= follow_die_ref (die
, spec
, &cu
);
20446 /* Return the string associated with a string-typed attribute, or NULL if it
20447 is either not found or is of an incorrect type. */
20449 static const char *
20450 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20452 struct attribute
*attr
;
20453 const char *str
= NULL
;
20455 attr
= dwarf2_attr (die
, name
, cu
);
20459 str
= attr
->as_string ();
20460 if (str
== nullptr)
20461 complaint (_("string type expected for attribute %s for "
20462 "DIE at %s in module %s"),
20463 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20464 objfile_name (cu
->per_objfile
->objfile
));
20470 /* Return the dwo name or NULL if not present. If present, it is in either
20471 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20472 static const char *
20473 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20475 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20476 if (dwo_name
== nullptr)
20477 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20481 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20482 and holds a non-zero value. This function should only be used for
20483 DW_FORM_flag or DW_FORM_flag_present attributes. */
20486 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20488 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20490 return attr
!= nullptr && attr
->as_boolean ();
20494 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20496 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20497 which value is non-zero. However, we have to be careful with
20498 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20499 (via dwarf2_flag_true_p) follows this attribute. So we may
20500 end up accidently finding a declaration attribute that belongs
20501 to a different DIE referenced by the specification attribute,
20502 even though the given DIE does not have a declaration attribute. */
20503 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20504 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20507 /* Return the die giving the specification for DIE, if there is
20508 one. *SPEC_CU is the CU containing DIE on input, and the CU
20509 containing the return value on output. If there is no
20510 specification, but there is an abstract origin, that is
20513 static struct die_info
*
20514 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20516 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20519 if (spec_attr
== NULL
)
20520 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20522 if (spec_attr
== NULL
)
20525 return follow_die_ref (die
, spec_attr
, spec_cu
);
20528 /* A convenience function to find the proper .debug_line section for a CU. */
20530 static struct dwarf2_section_info
*
20531 get_debug_line_section (struct dwarf2_cu
*cu
)
20533 struct dwarf2_section_info
*section
;
20534 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20536 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20538 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20539 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20540 else if (cu
->per_cu
->is_dwz
)
20542 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20544 section
= &dwz
->line
;
20547 section
= &per_objfile
->per_bfd
->line
;
20552 /* Read the statement program header starting at OFFSET in
20553 .debug_line, or .debug_line.dwo. Return a pointer
20554 to a struct line_header, allocated using xmalloc.
20555 Returns NULL if there is a problem reading the header, e.g., if it
20556 has a version we don't understand.
20558 NOTE: the strings in the include directory and file name tables of
20559 the returned object point into the dwarf line section buffer,
20560 and must not be freed. */
20562 static line_header_up
20563 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20565 struct dwarf2_section_info
*section
;
20566 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20568 section
= get_debug_line_section (cu
);
20569 section
->read (per_objfile
->objfile
);
20570 if (section
->buffer
== NULL
)
20572 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20573 complaint (_("missing .debug_line.dwo section"));
20575 complaint (_("missing .debug_line section"));
20579 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20580 per_objfile
, section
, &cu
->header
);
20583 /* Subroutine of dwarf_decode_lines to simplify it.
20584 Return the file name of the psymtab for the given file_entry.
20585 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20586 If space for the result is malloc'd, *NAME_HOLDER will be set.
20587 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20589 static const char *
20590 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20591 const dwarf2_psymtab
*pst
,
20592 const char *comp_dir
,
20593 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20595 const char *include_name
= fe
.name
;
20596 const char *include_name_to_compare
= include_name
;
20597 const char *pst_filename
;
20600 const char *dir_name
= fe
.include_dir (lh
);
20602 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20603 if (!IS_ABSOLUTE_PATH (include_name
)
20604 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20606 /* Avoid creating a duplicate psymtab for PST.
20607 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20608 Before we do the comparison, however, we need to account
20609 for DIR_NAME and COMP_DIR.
20610 First prepend dir_name (if non-NULL). If we still don't
20611 have an absolute path prepend comp_dir (if non-NULL).
20612 However, the directory we record in the include-file's
20613 psymtab does not contain COMP_DIR (to match the
20614 corresponding symtab(s)).
20619 bash$ gcc -g ./hello.c
20620 include_name = "hello.c"
20622 DW_AT_comp_dir = comp_dir = "/tmp"
20623 DW_AT_name = "./hello.c"
20627 if (dir_name
!= NULL
)
20629 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20630 include_name
, (char *) NULL
));
20631 include_name
= name_holder
->get ();
20632 include_name_to_compare
= include_name
;
20634 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20636 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20637 include_name
, (char *) NULL
));
20638 include_name_to_compare
= hold_compare
.get ();
20642 pst_filename
= pst
->filename
;
20643 gdb::unique_xmalloc_ptr
<char> copied_name
;
20644 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20646 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20647 pst_filename
, (char *) NULL
));
20648 pst_filename
= copied_name
.get ();
20651 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20655 return include_name
;
20658 /* State machine to track the state of the line number program. */
20660 class lnp_state_machine
20663 /* Initialize a machine state for the start of a line number
20665 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20666 bool record_lines_p
);
20668 file_entry
*current_file ()
20670 /* lh->file_names is 0-based, but the file name numbers in the
20671 statement program are 1-based. */
20672 return m_line_header
->file_name_at (m_file
);
20675 /* Record the line in the state machine. END_SEQUENCE is true if
20676 we're processing the end of a sequence. */
20677 void record_line (bool end_sequence
);
20679 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20680 nop-out rest of the lines in this sequence. */
20681 void check_line_address (struct dwarf2_cu
*cu
,
20682 const gdb_byte
*line_ptr
,
20683 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20685 void handle_set_discriminator (unsigned int discriminator
)
20687 m_discriminator
= discriminator
;
20688 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20691 /* Handle DW_LNE_set_address. */
20692 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20695 address
+= baseaddr
;
20696 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20699 /* Handle DW_LNS_advance_pc. */
20700 void handle_advance_pc (CORE_ADDR adjust
);
20702 /* Handle a special opcode. */
20703 void handle_special_opcode (unsigned char op_code
);
20705 /* Handle DW_LNS_advance_line. */
20706 void handle_advance_line (int line_delta
)
20708 advance_line (line_delta
);
20711 /* Handle DW_LNS_set_file. */
20712 void handle_set_file (file_name_index file
);
20714 /* Handle DW_LNS_negate_stmt. */
20715 void handle_negate_stmt ()
20717 m_is_stmt
= !m_is_stmt
;
20720 /* Handle DW_LNS_const_add_pc. */
20721 void handle_const_add_pc ();
20723 /* Handle DW_LNS_fixed_advance_pc. */
20724 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20726 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20730 /* Handle DW_LNS_copy. */
20731 void handle_copy ()
20733 record_line (false);
20734 m_discriminator
= 0;
20737 /* Handle DW_LNE_end_sequence. */
20738 void handle_end_sequence ()
20740 m_currently_recording_lines
= true;
20744 /* Advance the line by LINE_DELTA. */
20745 void advance_line (int line_delta
)
20747 m_line
+= line_delta
;
20749 if (line_delta
!= 0)
20750 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20753 struct dwarf2_cu
*m_cu
;
20755 gdbarch
*m_gdbarch
;
20757 /* True if we're recording lines.
20758 Otherwise we're building partial symtabs and are just interested in
20759 finding include files mentioned by the line number program. */
20760 bool m_record_lines_p
;
20762 /* The line number header. */
20763 line_header
*m_line_header
;
20765 /* These are part of the standard DWARF line number state machine,
20766 and initialized according to the DWARF spec. */
20768 unsigned char m_op_index
= 0;
20769 /* The line table index of the current file. */
20770 file_name_index m_file
= 1;
20771 unsigned int m_line
= 1;
20773 /* These are initialized in the constructor. */
20775 CORE_ADDR m_address
;
20777 unsigned int m_discriminator
;
20779 /* Additional bits of state we need to track. */
20781 /* The last file that we called dwarf2_start_subfile for.
20782 This is only used for TLLs. */
20783 unsigned int m_last_file
= 0;
20784 /* The last file a line number was recorded for. */
20785 struct subfile
*m_last_subfile
= NULL
;
20787 /* The address of the last line entry. */
20788 CORE_ADDR m_last_address
;
20790 /* Set to true when a previous line at the same address (using
20791 m_last_address) had m_is_stmt true. This is reset to false when a
20792 line entry at a new address (m_address different to m_last_address) is
20794 bool m_stmt_at_address
= false;
20796 /* When true, record the lines we decode. */
20797 bool m_currently_recording_lines
= false;
20799 /* The last line number that was recorded, used to coalesce
20800 consecutive entries for the same line. This can happen, for
20801 example, when discriminators are present. PR 17276. */
20802 unsigned int m_last_line
= 0;
20803 bool m_line_has_non_zero_discriminator
= false;
20807 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20809 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20810 / m_line_header
->maximum_ops_per_instruction
)
20811 * m_line_header
->minimum_instruction_length
);
20812 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20813 m_op_index
= ((m_op_index
+ adjust
)
20814 % m_line_header
->maximum_ops_per_instruction
);
20818 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20820 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20821 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20822 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20823 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
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
+ adj_opcode_d
)
20828 % m_line_header
->maximum_ops_per_instruction
);
20830 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20831 advance_line (line_delta
);
20832 record_line (false);
20833 m_discriminator
= 0;
20837 lnp_state_machine::handle_set_file (file_name_index file
)
20841 const file_entry
*fe
= current_file ();
20843 dwarf2_debug_line_missing_file_complaint ();
20844 else if (m_record_lines_p
)
20846 const char *dir
= fe
->include_dir (m_line_header
);
20848 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20849 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20850 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20855 lnp_state_machine::handle_const_add_pc ()
20858 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20861 = (((m_op_index
+ adjust
)
20862 / m_line_header
->maximum_ops_per_instruction
)
20863 * m_line_header
->minimum_instruction_length
);
20865 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20866 m_op_index
= ((m_op_index
+ adjust
)
20867 % m_line_header
->maximum_ops_per_instruction
);
20870 /* Return non-zero if we should add LINE to the line number table.
20871 LINE is the line to add, LAST_LINE is the last line that was added,
20872 LAST_SUBFILE is the subfile for LAST_LINE.
20873 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20874 had a non-zero discriminator.
20876 We have to be careful in the presence of discriminators.
20877 E.g., for this line:
20879 for (i = 0; i < 100000; i++);
20881 clang can emit four line number entries for that one line,
20882 each with a different discriminator.
20883 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20885 However, we want gdb to coalesce all four entries into one.
20886 Otherwise the user could stepi into the middle of the line and
20887 gdb would get confused about whether the pc really was in the
20888 middle of the line.
20890 Things are further complicated by the fact that two consecutive
20891 line number entries for the same line is a heuristic used by gcc
20892 to denote the end of the prologue. So we can't just discard duplicate
20893 entries, we have to be selective about it. The heuristic we use is
20894 that we only collapse consecutive entries for the same line if at least
20895 one of those entries has a non-zero discriminator. PR 17276.
20897 Note: Addresses in the line number state machine can never go backwards
20898 within one sequence, thus this coalescing is ok. */
20901 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20902 unsigned int line
, unsigned int last_line
,
20903 int line_has_non_zero_discriminator
,
20904 struct subfile
*last_subfile
)
20906 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20908 if (line
!= last_line
)
20910 /* Same line for the same file that we've seen already.
20911 As a last check, for pr 17276, only record the line if the line
20912 has never had a non-zero discriminator. */
20913 if (!line_has_non_zero_discriminator
)
20918 /* Use the CU's builder to record line number LINE beginning at
20919 address ADDRESS in the line table of subfile SUBFILE. */
20922 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20923 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20924 struct dwarf2_cu
*cu
)
20926 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20928 if (dwarf_line_debug
)
20930 fprintf_unfiltered (gdb_stdlog
,
20931 "Recording line %u, file %s, address %s\n",
20932 line
, lbasename (subfile
->name
),
20933 paddress (gdbarch
, address
));
20937 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20940 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20941 Mark the end of a set of line number records.
20942 The arguments are the same as for dwarf_record_line_1.
20943 If SUBFILE is NULL the request is ignored. */
20946 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20947 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20949 if (subfile
== NULL
)
20952 if (dwarf_line_debug
)
20954 fprintf_unfiltered (gdb_stdlog
,
20955 "Finishing current line, file %s, address %s\n",
20956 lbasename (subfile
->name
),
20957 paddress (gdbarch
, address
));
20960 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20964 lnp_state_machine::record_line (bool end_sequence
)
20966 if (dwarf_line_debug
)
20968 fprintf_unfiltered (gdb_stdlog
,
20969 "Processing actual line %u: file %u,"
20970 " address %s, is_stmt %u, discrim %u%s\n",
20972 paddress (m_gdbarch
, m_address
),
20973 m_is_stmt
, m_discriminator
,
20974 (end_sequence
? "\t(end sequence)" : ""));
20977 file_entry
*fe
= current_file ();
20980 dwarf2_debug_line_missing_file_complaint ();
20981 /* For now we ignore lines not starting on an instruction boundary.
20982 But not when processing end_sequence for compatibility with the
20983 previous version of the code. */
20984 else if (m_op_index
== 0 || end_sequence
)
20986 fe
->included_p
= 1;
20987 if (m_record_lines_p
)
20989 /* When we switch files we insert an end maker in the first file,
20990 switch to the second file and add a new line entry. The
20991 problem is that the end marker inserted in the first file will
20992 discard any previous line entries at the same address. If the
20993 line entries in the first file are marked as is-stmt, while
20994 the new line in the second file is non-stmt, then this means
20995 the end marker will discard is-stmt lines so we can have a
20996 non-stmt line. This means that there are less addresses at
20997 which the user can insert a breakpoint.
20999 To improve this we track the last address in m_last_address,
21000 and whether we have seen an is-stmt at this address. Then
21001 when switching files, if we have seen a stmt at the current
21002 address, and we are switching to create a non-stmt line, then
21003 discard the new line. */
21005 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21006 bool ignore_this_line
21007 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21008 && !m_is_stmt
&& m_stmt_at_address
)
21009 || (!end_sequence
&& m_line
== 0));
21011 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21013 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21014 m_currently_recording_lines
? m_cu
: nullptr);
21017 if (!end_sequence
&& !ignore_this_line
)
21019 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21021 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21022 m_line_has_non_zero_discriminator
,
21025 buildsym_compunit
*builder
= m_cu
->get_builder ();
21026 dwarf_record_line_1 (m_gdbarch
,
21027 builder
->get_current_subfile (),
21028 m_line
, m_address
, is_stmt
,
21029 m_currently_recording_lines
? m_cu
: nullptr);
21031 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21032 m_last_line
= m_line
;
21037 /* Track whether we have seen any m_is_stmt true at m_address in case we
21038 have multiple line table entries all at m_address. */
21039 if (m_last_address
!= m_address
)
21041 m_stmt_at_address
= false;
21042 m_last_address
= m_address
;
21044 m_stmt_at_address
|= m_is_stmt
;
21047 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21048 line_header
*lh
, bool record_lines_p
)
21052 m_record_lines_p
= record_lines_p
;
21053 m_line_header
= lh
;
21055 m_currently_recording_lines
= true;
21057 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21058 was a line entry for it so that the backend has a chance to adjust it
21059 and also record it in case it needs it. This is currently used by MIPS
21060 code, cf. `mips_adjust_dwarf2_line'. */
21061 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21062 m_is_stmt
= lh
->default_is_stmt
;
21063 m_discriminator
= 0;
21065 m_last_address
= m_address
;
21066 m_stmt_at_address
= false;
21070 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21071 const gdb_byte
*line_ptr
,
21072 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21074 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21075 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21076 located at 0x0. In this case, additionally check that if
21077 ADDRESS < UNRELOCATED_LOWPC. */
21079 if ((address
== 0 && address
< unrelocated_lowpc
)
21080 || address
== (CORE_ADDR
) -1)
21082 /* This line table is for a function which has been
21083 GCd by the linker. Ignore it. PR gdb/12528 */
21085 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21086 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21088 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21089 line_offset
, objfile_name (objfile
));
21090 m_currently_recording_lines
= false;
21091 /* Note: m_currently_recording_lines is left as false until we see
21092 DW_LNE_end_sequence. */
21096 /* Subroutine of dwarf_decode_lines to simplify it.
21097 Process the line number information in LH.
21098 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21099 program in order to set included_p for every referenced header. */
21102 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21103 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21105 const gdb_byte
*line_ptr
, *extended_end
;
21106 const gdb_byte
*line_end
;
21107 unsigned int bytes_read
, extended_len
;
21108 unsigned char op_code
, extended_op
;
21109 CORE_ADDR baseaddr
;
21110 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21111 bfd
*abfd
= objfile
->obfd
;
21112 struct gdbarch
*gdbarch
= objfile
->arch ();
21113 /* True if we're recording line info (as opposed to building partial
21114 symtabs and just interested in finding include files mentioned by
21115 the line number program). */
21116 bool record_lines_p
= !decode_for_pst_p
;
21118 baseaddr
= objfile
->text_section_offset ();
21120 line_ptr
= lh
->statement_program_start
;
21121 line_end
= lh
->statement_program_end
;
21123 /* Read the statement sequences until there's nothing left. */
21124 while (line_ptr
< line_end
)
21126 /* The DWARF line number program state machine. Reset the state
21127 machine at the start of each sequence. */
21128 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21129 bool end_sequence
= false;
21131 if (record_lines_p
)
21133 /* Start a subfile for the current file of the state
21135 const file_entry
*fe
= state_machine
.current_file ();
21138 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21141 /* Decode the table. */
21142 while (line_ptr
< line_end
&& !end_sequence
)
21144 op_code
= read_1_byte (abfd
, line_ptr
);
21147 if (op_code
>= lh
->opcode_base
)
21149 /* Special opcode. */
21150 state_machine
.handle_special_opcode (op_code
);
21152 else switch (op_code
)
21154 case DW_LNS_extended_op
:
21155 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21157 line_ptr
+= bytes_read
;
21158 extended_end
= line_ptr
+ extended_len
;
21159 extended_op
= read_1_byte (abfd
, line_ptr
);
21161 if (DW_LNE_lo_user
<= extended_op
21162 && extended_op
<= DW_LNE_hi_user
)
21164 /* Vendor extension, ignore. */
21165 line_ptr
= extended_end
;
21168 switch (extended_op
)
21170 case DW_LNE_end_sequence
:
21171 state_machine
.handle_end_sequence ();
21172 end_sequence
= true;
21174 case DW_LNE_set_address
:
21177 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21178 line_ptr
+= bytes_read
;
21180 state_machine
.check_line_address (cu
, line_ptr
,
21181 lowpc
- baseaddr
, address
);
21182 state_machine
.handle_set_address (baseaddr
, address
);
21185 case DW_LNE_define_file
:
21187 const char *cur_file
;
21188 unsigned int mod_time
, length
;
21191 cur_file
= read_direct_string (abfd
, line_ptr
,
21193 line_ptr
+= bytes_read
;
21194 dindex
= (dir_index
)
21195 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21196 line_ptr
+= bytes_read
;
21198 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21199 line_ptr
+= bytes_read
;
21201 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21202 line_ptr
+= bytes_read
;
21203 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21206 case DW_LNE_set_discriminator
:
21208 /* The discriminator is not interesting to the
21209 debugger; just ignore it. We still need to
21210 check its value though:
21211 if there are consecutive entries for the same
21212 (non-prologue) line we want to coalesce them.
21215 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21216 line_ptr
+= bytes_read
;
21218 state_machine
.handle_set_discriminator (discr
);
21222 complaint (_("mangled .debug_line section"));
21225 /* Make sure that we parsed the extended op correctly. If e.g.
21226 we expected a different address size than the producer used,
21227 we may have read the wrong number of bytes. */
21228 if (line_ptr
!= extended_end
)
21230 complaint (_("mangled .debug_line section"));
21235 state_machine
.handle_copy ();
21237 case DW_LNS_advance_pc
:
21240 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21241 line_ptr
+= bytes_read
;
21243 state_machine
.handle_advance_pc (adjust
);
21246 case DW_LNS_advance_line
:
21249 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21250 line_ptr
+= bytes_read
;
21252 state_machine
.handle_advance_line (line_delta
);
21255 case DW_LNS_set_file
:
21257 file_name_index file
21258 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21260 line_ptr
+= bytes_read
;
21262 state_machine
.handle_set_file (file
);
21265 case DW_LNS_set_column
:
21266 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21267 line_ptr
+= bytes_read
;
21269 case DW_LNS_negate_stmt
:
21270 state_machine
.handle_negate_stmt ();
21272 case DW_LNS_set_basic_block
:
21274 /* Add to the address register of the state machine the
21275 address increment value corresponding to special opcode
21276 255. I.e., this value is scaled by the minimum
21277 instruction length since special opcode 255 would have
21278 scaled the increment. */
21279 case DW_LNS_const_add_pc
:
21280 state_machine
.handle_const_add_pc ();
21282 case DW_LNS_fixed_advance_pc
:
21284 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21287 state_machine
.handle_fixed_advance_pc (addr_adj
);
21292 /* Unknown standard opcode, ignore it. */
21295 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21297 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21298 line_ptr
+= bytes_read
;
21305 dwarf2_debug_line_missing_end_sequence_complaint ();
21307 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21308 in which case we still finish recording the last line). */
21309 state_machine
.record_line (true);
21313 /* Decode the Line Number Program (LNP) for the given line_header
21314 structure and CU. The actual information extracted and the type
21315 of structures created from the LNP depends on the value of PST.
21317 1. If PST is NULL, then this procedure uses the data from the program
21318 to create all necessary symbol tables, and their linetables.
21320 2. If PST is not NULL, this procedure reads the program to determine
21321 the list of files included by the unit represented by PST, and
21322 builds all the associated partial symbol tables.
21324 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21325 It is used for relative paths in the line table.
21326 NOTE: When processing partial symtabs (pst != NULL),
21327 comp_dir == pst->dirname.
21329 NOTE: It is important that psymtabs have the same file name (via strcmp)
21330 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21331 symtab we don't use it in the name of the psymtabs we create.
21332 E.g. expand_line_sal requires this when finding psymtabs to expand.
21333 A good testcase for this is mb-inline.exp.
21335 LOWPC is the lowest address in CU (or 0 if not known).
21337 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21338 for its PC<->lines mapping information. Otherwise only the filename
21339 table is read in. */
21342 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21343 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21344 CORE_ADDR lowpc
, int decode_mapping
)
21346 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21347 const int decode_for_pst_p
= (pst
!= NULL
);
21349 if (decode_mapping
)
21350 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21352 if (decode_for_pst_p
)
21354 /* Now that we're done scanning the Line Header Program, we can
21355 create the psymtab of each included file. */
21356 for (auto &file_entry
: lh
->file_names ())
21357 if (file_entry
.included_p
== 1)
21359 gdb::unique_xmalloc_ptr
<char> name_holder
;
21360 const char *include_name
=
21361 psymtab_include_file_name (lh
, file_entry
, pst
,
21362 comp_dir
, &name_holder
);
21363 if (include_name
!= NULL
)
21364 dwarf2_create_include_psymtab
21365 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21366 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21372 /* Make sure a symtab is created for every file, even files
21373 which contain only variables (i.e. no code with associated
21375 buildsym_compunit
*builder
= cu
->get_builder ();
21376 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21378 for (auto &fe
: lh
->file_names ())
21380 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21381 if (builder
->get_current_subfile ()->symtab
== NULL
)
21383 builder
->get_current_subfile ()->symtab
21384 = allocate_symtab (cust
,
21385 builder
->get_current_subfile ()->name
);
21387 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21392 /* Start a subfile for DWARF. FILENAME is the name of the file and
21393 DIRNAME the name of the source directory which contains FILENAME
21394 or NULL if not known.
21395 This routine tries to keep line numbers from identical absolute and
21396 relative file names in a common subfile.
21398 Using the `list' example from the GDB testsuite, which resides in
21399 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21400 of /srcdir/list0.c yields the following debugging information for list0.c:
21402 DW_AT_name: /srcdir/list0.c
21403 DW_AT_comp_dir: /compdir
21404 files.files[0].name: list0.h
21405 files.files[0].dir: /srcdir
21406 files.files[1].name: list0.c
21407 files.files[1].dir: /srcdir
21409 The line number information for list0.c has to end up in a single
21410 subfile, so that `break /srcdir/list0.c:1' works as expected.
21411 start_subfile will ensure that this happens provided that we pass the
21412 concatenation of files.files[1].dir and files.files[1].name as the
21416 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21417 const char *dirname
)
21419 gdb::unique_xmalloc_ptr
<char> copy
;
21421 /* In order not to lose the line information directory,
21422 we concatenate it to the filename when it makes sense.
21423 Note that the Dwarf3 standard says (speaking of filenames in line
21424 information): ``The directory index is ignored for file names
21425 that represent full path names''. Thus ignoring dirname in the
21426 `else' branch below isn't an issue. */
21428 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21430 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21431 filename
= copy
.get ();
21434 cu
->get_builder ()->start_subfile (filename
);
21438 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21439 struct dwarf2_cu
*cu
)
21441 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21442 struct comp_unit_head
*cu_header
= &cu
->header
;
21444 /* NOTE drow/2003-01-30: There used to be a comment and some special
21445 code here to turn a symbol with DW_AT_external and a
21446 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21447 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21448 with some versions of binutils) where shared libraries could have
21449 relocations against symbols in their debug information - the
21450 minimal symbol would have the right address, but the debug info
21451 would not. It's no longer necessary, because we will explicitly
21452 apply relocations when we read in the debug information now. */
21454 /* A DW_AT_location attribute with no contents indicates that a
21455 variable has been optimized away. */
21456 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21458 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21462 /* Handle one degenerate form of location expression specially, to
21463 preserve GDB's previous behavior when section offsets are
21464 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21465 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21467 if (attr
->form_is_block ())
21469 struct dwarf_block
*block
= attr
->as_block ();
21471 if ((block
->data
[0] == DW_OP_addr
21472 && block
->size
== 1 + cu_header
->addr_size
)
21473 || ((block
->data
[0] == DW_OP_GNU_addr_index
21474 || block
->data
[0] == DW_OP_addrx
)
21476 == 1 + leb128_size (&block
->data
[1]))))
21478 unsigned int dummy
;
21480 if (block
->data
[0] == DW_OP_addr
)
21481 SET_SYMBOL_VALUE_ADDRESS
21482 (sym
, cu
->header
.read_address (objfile
->obfd
,
21486 SET_SYMBOL_VALUE_ADDRESS
21487 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21489 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21490 fixup_symbol_section (sym
, objfile
);
21491 SET_SYMBOL_VALUE_ADDRESS
21493 SYMBOL_VALUE_ADDRESS (sym
)
21494 + objfile
->section_offsets
[sym
->section_index ()]);
21499 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21500 expression evaluator, and use LOC_COMPUTED only when necessary
21501 (i.e. when the value of a register or memory location is
21502 referenced, or a thread-local block, etc.). Then again, it might
21503 not be worthwhile. I'm assuming that it isn't unless performance
21504 or memory numbers show me otherwise. */
21506 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21508 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21509 cu
->has_loclist
= true;
21512 /* Given a pointer to a DWARF information entry, figure out if we need
21513 to make a symbol table entry for it, and if so, create a new entry
21514 and return a pointer to it.
21515 If TYPE is NULL, determine symbol type from the die, otherwise
21516 used the passed type.
21517 If SPACE is not NULL, use it to hold the new symbol. If it is
21518 NULL, allocate a new symbol on the objfile's obstack. */
21520 static struct symbol
*
21521 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21522 struct symbol
*space
)
21524 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21525 struct objfile
*objfile
= per_objfile
->objfile
;
21526 struct gdbarch
*gdbarch
= objfile
->arch ();
21527 struct symbol
*sym
= NULL
;
21529 struct attribute
*attr
= NULL
;
21530 struct attribute
*attr2
= NULL
;
21531 CORE_ADDR baseaddr
;
21532 struct pending
**list_to_add
= NULL
;
21534 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21536 baseaddr
= objfile
->text_section_offset ();
21538 name
= dwarf2_name (die
, cu
);
21541 int suppress_add
= 0;
21546 sym
= new (&objfile
->objfile_obstack
) symbol
;
21547 OBJSTAT (objfile
, n_syms
++);
21549 /* Cache this symbol's name and the name's demangled form (if any). */
21550 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21551 /* Fortran does not have mangling standard and the mangling does differ
21552 between gfortran, iFort etc. */
21553 const char *physname
21554 = (cu
->language
== language_fortran
21555 ? dwarf2_full_name (name
, die
, cu
)
21556 : dwarf2_physname (name
, die
, cu
));
21557 const char *linkagename
= dw2_linkage_name (die
, cu
);
21559 if (linkagename
== nullptr || cu
->language
== language_ada
)
21560 sym
->set_linkage_name (physname
);
21563 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21564 sym
->set_linkage_name (linkagename
);
21567 /* Default assumptions.
21568 Use the passed type or decode it from the die. */
21569 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21570 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21572 SYMBOL_TYPE (sym
) = type
;
21574 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21575 attr
= dwarf2_attr (die
,
21576 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21578 if (attr
!= nullptr)
21579 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21581 attr
= dwarf2_attr (die
,
21582 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21584 if (attr
!= nullptr && attr
->is_nonnegative ())
21586 file_name_index file_index
21587 = (file_name_index
) attr
->as_nonnegative ();
21588 struct file_entry
*fe
;
21590 if (cu
->line_header
!= NULL
)
21591 fe
= cu
->line_header
->file_name_at (file_index
);
21596 complaint (_("file index out of range"));
21598 symbol_set_symtab (sym
, fe
->symtab
);
21604 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21605 if (attr
!= nullptr)
21609 addr
= attr
->as_address ();
21610 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21611 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21612 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21615 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21616 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21617 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21618 add_symbol_to_list (sym
, cu
->list_in_scope
);
21620 case DW_TAG_subprogram
:
21621 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21623 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21624 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21625 if ((attr2
!= nullptr && attr2
->as_boolean ())
21626 || cu
->language
== language_ada
21627 || cu
->language
== language_fortran
)
21629 /* Subprograms marked external are stored as a global symbol.
21630 Ada and Fortran subprograms, whether marked external or
21631 not, are always stored as a global symbol, because we want
21632 to be able to access them globally. For instance, we want
21633 to be able to break on a nested subprogram without having
21634 to specify the context. */
21635 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21639 list_to_add
= cu
->list_in_scope
;
21642 case DW_TAG_inlined_subroutine
:
21643 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21645 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21646 SYMBOL_INLINED (sym
) = 1;
21647 list_to_add
= cu
->list_in_scope
;
21649 case DW_TAG_template_value_param
:
21651 /* Fall through. */
21652 case DW_TAG_constant
:
21653 case DW_TAG_variable
:
21654 case DW_TAG_member
:
21655 /* Compilation with minimal debug info may result in
21656 variables with missing type entries. Change the
21657 misleading `void' type to something sensible. */
21658 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21659 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21661 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21662 /* In the case of DW_TAG_member, we should only be called for
21663 static const members. */
21664 if (die
->tag
== DW_TAG_member
)
21666 /* dwarf2_add_field uses die_is_declaration,
21667 so we do the same. */
21668 gdb_assert (die_is_declaration (die
, cu
));
21671 if (attr
!= nullptr)
21673 dwarf2_const_value (attr
, sym
, cu
);
21674 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21677 if (attr2
!= nullptr && attr2
->as_boolean ())
21678 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21680 list_to_add
= cu
->list_in_scope
;
21684 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21685 if (attr
!= nullptr)
21687 var_decode_location (attr
, sym
, cu
);
21688 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21690 /* Fortran explicitly imports any global symbols to the local
21691 scope by DW_TAG_common_block. */
21692 if (cu
->language
== language_fortran
&& die
->parent
21693 && die
->parent
->tag
== DW_TAG_common_block
)
21696 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21697 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21698 && !per_objfile
->per_bfd
->has_section_at_zero
)
21700 /* When a static variable is eliminated by the linker,
21701 the corresponding debug information is not stripped
21702 out, but the variable address is set to null;
21703 do not add such variables into symbol table. */
21705 else if (attr2
!= nullptr && attr2
->as_boolean ())
21707 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21708 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21709 && per_objfile
->per_bfd
->can_copy
)
21711 /* A global static variable might be subject to
21712 copy relocation. We first check for a local
21713 minsym, though, because maybe the symbol was
21714 marked hidden, in which case this would not
21716 bound_minimal_symbol found
21717 = (lookup_minimal_symbol_linkage
21718 (sym
->linkage_name (), objfile
));
21719 if (found
.minsym
!= nullptr)
21720 sym
->maybe_copied
= 1;
21723 /* A variable with DW_AT_external is never static,
21724 but it may be block-scoped. */
21726 = ((cu
->list_in_scope
21727 == cu
->get_builder ()->get_file_symbols ())
21728 ? cu
->get_builder ()->get_global_symbols ()
21729 : cu
->list_in_scope
);
21732 list_to_add
= cu
->list_in_scope
;
21736 /* We do not know the address of this symbol.
21737 If it is an external symbol and we have type information
21738 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21739 The address of the variable will then be determined from
21740 the minimal symbol table whenever the variable is
21742 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21744 /* Fortran explicitly imports any global symbols to the local
21745 scope by DW_TAG_common_block. */
21746 if (cu
->language
== language_fortran
&& die
->parent
21747 && die
->parent
->tag
== DW_TAG_common_block
)
21749 /* SYMBOL_CLASS doesn't matter here because
21750 read_common_block is going to reset it. */
21752 list_to_add
= cu
->list_in_scope
;
21754 else if (attr2
!= nullptr && attr2
->as_boolean ()
21755 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21757 /* A variable with DW_AT_external is never static, but it
21758 may be block-scoped. */
21760 = ((cu
->list_in_scope
21761 == cu
->get_builder ()->get_file_symbols ())
21762 ? cu
->get_builder ()->get_global_symbols ()
21763 : cu
->list_in_scope
);
21765 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21767 else if (!die_is_declaration (die
, cu
))
21769 /* Use the default LOC_OPTIMIZED_OUT class. */
21770 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21772 list_to_add
= cu
->list_in_scope
;
21776 case DW_TAG_formal_parameter
:
21778 /* If we are inside a function, mark this as an argument. If
21779 not, we might be looking at an argument to an inlined function
21780 when we do not have enough information to show inlined frames;
21781 pretend it's a local variable in that case so that the user can
21783 struct context_stack
*curr
21784 = cu
->get_builder ()->get_current_context_stack ();
21785 if (curr
!= nullptr && curr
->name
!= nullptr)
21786 SYMBOL_IS_ARGUMENT (sym
) = 1;
21787 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21788 if (attr
!= nullptr)
21790 var_decode_location (attr
, sym
, cu
);
21792 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21793 if (attr
!= nullptr)
21795 dwarf2_const_value (attr
, sym
, cu
);
21798 list_to_add
= cu
->list_in_scope
;
21801 case DW_TAG_unspecified_parameters
:
21802 /* From varargs functions; gdb doesn't seem to have any
21803 interest in this information, so just ignore it for now.
21806 case DW_TAG_template_type_param
:
21808 /* Fall through. */
21809 case DW_TAG_class_type
:
21810 case DW_TAG_interface_type
:
21811 case DW_TAG_structure_type
:
21812 case DW_TAG_union_type
:
21813 case DW_TAG_set_type
:
21814 case DW_TAG_enumeration_type
:
21815 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21816 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21819 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21820 really ever be static objects: otherwise, if you try
21821 to, say, break of a class's method and you're in a file
21822 which doesn't mention that class, it won't work unless
21823 the check for all static symbols in lookup_symbol_aux
21824 saves you. See the OtherFileClass tests in
21825 gdb.c++/namespace.exp. */
21829 buildsym_compunit
*builder
= cu
->get_builder ();
21831 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21832 && cu
->language
== language_cplus
21833 ? builder
->get_global_symbols ()
21834 : cu
->list_in_scope
);
21836 /* The semantics of C++ state that "struct foo {
21837 ... }" also defines a typedef for "foo". */
21838 if (cu
->language
== language_cplus
21839 || cu
->language
== language_ada
21840 || cu
->language
== language_d
21841 || cu
->language
== language_rust
)
21843 /* The symbol's name is already allocated along
21844 with this objfile, so we don't need to
21845 duplicate it for the type. */
21846 if (SYMBOL_TYPE (sym
)->name () == 0)
21847 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21852 case DW_TAG_typedef
:
21853 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21854 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21855 list_to_add
= cu
->list_in_scope
;
21857 case DW_TAG_array_type
:
21858 case DW_TAG_base_type
:
21859 case DW_TAG_subrange_type
:
21860 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21861 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21862 list_to_add
= cu
->list_in_scope
;
21864 case DW_TAG_enumerator
:
21865 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21866 if (attr
!= nullptr)
21868 dwarf2_const_value (attr
, sym
, cu
);
21871 /* NOTE: carlton/2003-11-10: See comment above in the
21872 DW_TAG_class_type, etc. block. */
21875 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21876 && cu
->language
== language_cplus
21877 ? cu
->get_builder ()->get_global_symbols ()
21878 : cu
->list_in_scope
);
21881 case DW_TAG_imported_declaration
:
21882 case DW_TAG_namespace
:
21883 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21884 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21886 case DW_TAG_module
:
21887 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21888 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21889 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21891 case DW_TAG_common_block
:
21892 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21893 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21894 add_symbol_to_list (sym
, cu
->list_in_scope
);
21897 /* Not a tag we recognize. Hopefully we aren't processing
21898 trash data, but since we must specifically ignore things
21899 we don't recognize, there is nothing else we should do at
21901 complaint (_("unsupported tag: '%s'"),
21902 dwarf_tag_name (die
->tag
));
21908 sym
->hash_next
= objfile
->template_symbols
;
21909 objfile
->template_symbols
= sym
;
21910 list_to_add
= NULL
;
21913 if (list_to_add
!= NULL
)
21914 add_symbol_to_list (sym
, list_to_add
);
21916 /* For the benefit of old versions of GCC, check for anonymous
21917 namespaces based on the demangled name. */
21918 if (!cu
->processing_has_namespace_info
21919 && cu
->language
== language_cplus
)
21920 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21925 /* Given an attr with a DW_FORM_dataN value in host byte order,
21926 zero-extend it as appropriate for the symbol's type. The DWARF
21927 standard (v4) is not entirely clear about the meaning of using
21928 DW_FORM_dataN for a constant with a signed type, where the type is
21929 wider than the data. The conclusion of a discussion on the DWARF
21930 list was that this is unspecified. We choose to always zero-extend
21931 because that is the interpretation long in use by GCC. */
21934 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21935 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21937 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21938 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21939 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21940 LONGEST l
= attr
->constant_value (0);
21942 if (bits
< sizeof (*value
) * 8)
21944 l
&= ((LONGEST
) 1 << bits
) - 1;
21947 else if (bits
== sizeof (*value
) * 8)
21951 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21952 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21959 /* Read a constant value from an attribute. Either set *VALUE, or if
21960 the value does not fit in *VALUE, set *BYTES - either already
21961 allocated on the objfile obstack, or newly allocated on OBSTACK,
21962 or, set *BATON, if we translated the constant to a location
21966 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21967 const char *name
, struct obstack
*obstack
,
21968 struct dwarf2_cu
*cu
,
21969 LONGEST
*value
, const gdb_byte
**bytes
,
21970 struct dwarf2_locexpr_baton
**baton
)
21972 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21973 struct objfile
*objfile
= per_objfile
->objfile
;
21974 struct comp_unit_head
*cu_header
= &cu
->header
;
21975 struct dwarf_block
*blk
;
21976 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21977 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21983 switch (attr
->form
)
21986 case DW_FORM_addrx
:
21987 case DW_FORM_GNU_addr_index
:
21991 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21992 dwarf2_const_value_length_mismatch_complaint (name
,
21993 cu_header
->addr_size
,
21994 TYPE_LENGTH (type
));
21995 /* Symbols of this form are reasonably rare, so we just
21996 piggyback on the existing location code rather than writing
21997 a new implementation of symbol_computed_ops. */
21998 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21999 (*baton
)->per_objfile
= per_objfile
;
22000 (*baton
)->per_cu
= cu
->per_cu
;
22001 gdb_assert ((*baton
)->per_cu
);
22003 (*baton
)->size
= 2 + cu_header
->addr_size
;
22004 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22005 (*baton
)->data
= data
;
22007 data
[0] = DW_OP_addr
;
22008 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22009 byte_order
, attr
->as_address ());
22010 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22013 case DW_FORM_string
:
22016 case DW_FORM_GNU_str_index
:
22017 case DW_FORM_GNU_strp_alt
:
22018 /* The string is already allocated on the objfile obstack, point
22020 *bytes
= (const gdb_byte
*) attr
->as_string ();
22022 case DW_FORM_block1
:
22023 case DW_FORM_block2
:
22024 case DW_FORM_block4
:
22025 case DW_FORM_block
:
22026 case DW_FORM_exprloc
:
22027 case DW_FORM_data16
:
22028 blk
= attr
->as_block ();
22029 if (TYPE_LENGTH (type
) != blk
->size
)
22030 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22031 TYPE_LENGTH (type
));
22032 *bytes
= blk
->data
;
22035 /* The DW_AT_const_value attributes are supposed to carry the
22036 symbol's value "represented as it would be on the target
22037 architecture." By the time we get here, it's already been
22038 converted to host endianness, so we just need to sign- or
22039 zero-extend it as appropriate. */
22040 case DW_FORM_data1
:
22041 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22043 case DW_FORM_data2
:
22044 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22046 case DW_FORM_data4
:
22047 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22049 case DW_FORM_data8
:
22050 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22053 case DW_FORM_sdata
:
22054 case DW_FORM_implicit_const
:
22055 *value
= attr
->as_signed ();
22058 case DW_FORM_udata
:
22059 *value
= attr
->as_unsigned ();
22063 complaint (_("unsupported const value attribute form: '%s'"),
22064 dwarf_form_name (attr
->form
));
22071 /* Copy constant value from an attribute to a symbol. */
22074 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22075 struct dwarf2_cu
*cu
)
22077 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22079 const gdb_byte
*bytes
;
22080 struct dwarf2_locexpr_baton
*baton
;
22082 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22083 sym
->print_name (),
22084 &objfile
->objfile_obstack
, cu
,
22085 &value
, &bytes
, &baton
);
22089 SYMBOL_LOCATION_BATON (sym
) = baton
;
22090 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22092 else if (bytes
!= NULL
)
22094 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22095 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22099 SYMBOL_VALUE (sym
) = value
;
22100 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22104 /* Return the type of the die in question using its DW_AT_type attribute. */
22106 static struct type
*
22107 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22109 struct attribute
*type_attr
;
22111 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22114 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22115 /* A missing DW_AT_type represents a void type. */
22116 return objfile_type (objfile
)->builtin_void
;
22119 return lookup_die_type (die
, type_attr
, cu
);
22122 /* True iff CU's producer generates GNAT Ada auxiliary information
22123 that allows to find parallel types through that information instead
22124 of having to do expensive parallel lookups by type name. */
22127 need_gnat_info (struct dwarf2_cu
*cu
)
22129 /* Assume that the Ada compiler was GNAT, which always produces
22130 the auxiliary information. */
22131 return (cu
->language
== language_ada
);
22134 /* Return the auxiliary type of the die in question using its
22135 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22136 attribute is not present. */
22138 static struct type
*
22139 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22141 struct attribute
*type_attr
;
22143 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22147 return lookup_die_type (die
, type_attr
, cu
);
22150 /* If DIE has a descriptive_type attribute, then set the TYPE's
22151 descriptive type accordingly. */
22154 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22155 struct dwarf2_cu
*cu
)
22157 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22159 if (descriptive_type
)
22161 ALLOCATE_GNAT_AUX_TYPE (type
);
22162 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22166 /* Return the containing type of the die in question using its
22167 DW_AT_containing_type attribute. */
22169 static struct type
*
22170 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22172 struct attribute
*type_attr
;
22173 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22175 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22177 error (_("Dwarf Error: Problem turning containing type into gdb type "
22178 "[in module %s]"), objfile_name (objfile
));
22180 return lookup_die_type (die
, type_attr
, cu
);
22183 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22185 static struct type
*
22186 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22188 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22189 struct objfile
*objfile
= per_objfile
->objfile
;
22192 std::string message
22193 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22194 objfile_name (objfile
),
22195 sect_offset_str (cu
->header
.sect_off
),
22196 sect_offset_str (die
->sect_off
));
22197 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22199 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22202 /* Look up the type of DIE in CU using its type attribute ATTR.
22203 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22204 DW_AT_containing_type.
22205 If there is no type substitute an error marker. */
22207 static struct type
*
22208 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22209 struct dwarf2_cu
*cu
)
22211 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22212 struct objfile
*objfile
= per_objfile
->objfile
;
22213 struct type
*this_type
;
22215 gdb_assert (attr
->name
== DW_AT_type
22216 || attr
->name
== DW_AT_GNAT_descriptive_type
22217 || attr
->name
== DW_AT_containing_type
);
22219 /* First see if we have it cached. */
22221 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22223 struct dwarf2_per_cu_data
*per_cu
;
22224 sect_offset sect_off
= attr
->get_ref_die_offset ();
22226 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22227 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22229 else if (attr
->form_is_ref ())
22231 sect_offset sect_off
= attr
->get_ref_die_offset ();
22233 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22235 else if (attr
->form
== DW_FORM_ref_sig8
)
22237 ULONGEST signature
= attr
->as_signature ();
22239 return get_signatured_type (die
, signature
, cu
);
22243 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22244 " at %s [in module %s]"),
22245 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22246 objfile_name (objfile
));
22247 return build_error_marker_type (cu
, die
);
22250 /* If not cached we need to read it in. */
22252 if (this_type
== NULL
)
22254 struct die_info
*type_die
= NULL
;
22255 struct dwarf2_cu
*type_cu
= cu
;
22257 if (attr
->form_is_ref ())
22258 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22259 if (type_die
== NULL
)
22260 return build_error_marker_type (cu
, die
);
22261 /* If we find the type now, it's probably because the type came
22262 from an inter-CU reference and the type's CU got expanded before
22264 this_type
= read_type_die (type_die
, type_cu
);
22267 /* If we still don't have a type use an error marker. */
22269 if (this_type
== NULL
)
22270 return build_error_marker_type (cu
, die
);
22275 /* Return the type in DIE, CU.
22276 Returns NULL for invalid types.
22278 This first does a lookup in die_type_hash,
22279 and only reads the die in if necessary.
22281 NOTE: This can be called when reading in partial or full symbols. */
22283 static struct type
*
22284 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22286 struct type
*this_type
;
22288 this_type
= get_die_type (die
, cu
);
22292 return read_type_die_1 (die
, cu
);
22295 /* Read the type in DIE, CU.
22296 Returns NULL for invalid types. */
22298 static struct type
*
22299 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22301 struct type
*this_type
= NULL
;
22305 case DW_TAG_class_type
:
22306 case DW_TAG_interface_type
:
22307 case DW_TAG_structure_type
:
22308 case DW_TAG_union_type
:
22309 this_type
= read_structure_type (die
, cu
);
22311 case DW_TAG_enumeration_type
:
22312 this_type
= read_enumeration_type (die
, cu
);
22314 case DW_TAG_subprogram
:
22315 case DW_TAG_subroutine_type
:
22316 case DW_TAG_inlined_subroutine
:
22317 this_type
= read_subroutine_type (die
, cu
);
22319 case DW_TAG_array_type
:
22320 this_type
= read_array_type (die
, cu
);
22322 case DW_TAG_set_type
:
22323 this_type
= read_set_type (die
, cu
);
22325 case DW_TAG_pointer_type
:
22326 this_type
= read_tag_pointer_type (die
, cu
);
22328 case DW_TAG_ptr_to_member_type
:
22329 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22331 case DW_TAG_reference_type
:
22332 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22334 case DW_TAG_rvalue_reference_type
:
22335 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22337 case DW_TAG_const_type
:
22338 this_type
= read_tag_const_type (die
, cu
);
22340 case DW_TAG_volatile_type
:
22341 this_type
= read_tag_volatile_type (die
, cu
);
22343 case DW_TAG_restrict_type
:
22344 this_type
= read_tag_restrict_type (die
, cu
);
22346 case DW_TAG_string_type
:
22347 this_type
= read_tag_string_type (die
, cu
);
22349 case DW_TAG_typedef
:
22350 this_type
= read_typedef (die
, cu
);
22352 case DW_TAG_subrange_type
:
22353 this_type
= read_subrange_type (die
, cu
);
22355 case DW_TAG_base_type
:
22356 this_type
= read_base_type (die
, cu
);
22358 case DW_TAG_unspecified_type
:
22359 this_type
= read_unspecified_type (die
, cu
);
22361 case DW_TAG_namespace
:
22362 this_type
= read_namespace_type (die
, cu
);
22364 case DW_TAG_module
:
22365 this_type
= read_module_type (die
, cu
);
22367 case DW_TAG_atomic_type
:
22368 this_type
= read_tag_atomic_type (die
, cu
);
22371 complaint (_("unexpected tag in read_type_die: '%s'"),
22372 dwarf_tag_name (die
->tag
));
22379 /* See if we can figure out if the class lives in a namespace. We do
22380 this by looking for a member function; its demangled name will
22381 contain namespace info, if there is any.
22382 Return the computed name or NULL.
22383 Space for the result is allocated on the objfile's obstack.
22384 This is the full-die version of guess_partial_die_structure_name.
22385 In this case we know DIE has no useful parent. */
22387 static const char *
22388 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22390 struct die_info
*spec_die
;
22391 struct dwarf2_cu
*spec_cu
;
22392 struct die_info
*child
;
22393 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22396 spec_die
= die_specification (die
, &spec_cu
);
22397 if (spec_die
!= NULL
)
22403 for (child
= die
->child
;
22405 child
= child
->sibling
)
22407 if (child
->tag
== DW_TAG_subprogram
)
22409 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22411 if (linkage_name
!= NULL
)
22413 gdb::unique_xmalloc_ptr
<char> actual_name
22414 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22415 const char *name
= NULL
;
22417 if (actual_name
!= NULL
)
22419 const char *die_name
= dwarf2_name (die
, cu
);
22421 if (die_name
!= NULL
22422 && strcmp (die_name
, actual_name
.get ()) != 0)
22424 /* Strip off the class name from the full name.
22425 We want the prefix. */
22426 int die_name_len
= strlen (die_name
);
22427 int actual_name_len
= strlen (actual_name
.get ());
22428 const char *ptr
= actual_name
.get ();
22430 /* Test for '::' as a sanity check. */
22431 if (actual_name_len
> die_name_len
+ 2
22432 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22433 name
= obstack_strndup (
22434 &objfile
->per_bfd
->storage_obstack
,
22435 ptr
, actual_name_len
- die_name_len
- 2);
22446 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22447 prefix part in such case. See
22448 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22450 static const char *
22451 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22453 struct attribute
*attr
;
22456 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22457 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22460 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22463 attr
= dw2_linkage_name_attr (die
, cu
);
22464 const char *attr_name
= attr
->as_string ();
22465 if (attr
== NULL
|| attr_name
== NULL
)
22468 /* dwarf2_name had to be already called. */
22469 gdb_assert (attr
->canonical_string_p ());
22471 /* Strip the base name, keep any leading namespaces/classes. */
22472 base
= strrchr (attr_name
, ':');
22473 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22476 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22477 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22479 &base
[-1] - attr_name
);
22482 /* Return the name of the namespace/class that DIE is defined within,
22483 or "" if we can't tell. The caller should not xfree the result.
22485 For example, if we're within the method foo() in the following
22495 then determine_prefix on foo's die will return "N::C". */
22497 static const char *
22498 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22500 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22501 struct die_info
*parent
, *spec_die
;
22502 struct dwarf2_cu
*spec_cu
;
22503 struct type
*parent_type
;
22504 const char *retval
;
22506 if (cu
->language
!= language_cplus
22507 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22508 && cu
->language
!= language_rust
)
22511 retval
= anonymous_struct_prefix (die
, cu
);
22515 /* We have to be careful in the presence of DW_AT_specification.
22516 For example, with GCC 3.4, given the code
22520 // Definition of N::foo.
22524 then we'll have a tree of DIEs like this:
22526 1: DW_TAG_compile_unit
22527 2: DW_TAG_namespace // N
22528 3: DW_TAG_subprogram // declaration of N::foo
22529 4: DW_TAG_subprogram // definition of N::foo
22530 DW_AT_specification // refers to die #3
22532 Thus, when processing die #4, we have to pretend that we're in
22533 the context of its DW_AT_specification, namely the contex of die
22536 spec_die
= die_specification (die
, &spec_cu
);
22537 if (spec_die
== NULL
)
22538 parent
= die
->parent
;
22541 parent
= spec_die
->parent
;
22545 if (parent
== NULL
)
22547 else if (parent
->building_fullname
)
22550 const char *parent_name
;
22552 /* It has been seen on RealView 2.2 built binaries,
22553 DW_TAG_template_type_param types actually _defined_ as
22554 children of the parent class:
22557 template class <class Enum> Class{};
22558 Class<enum E> class_e;
22560 1: DW_TAG_class_type (Class)
22561 2: DW_TAG_enumeration_type (E)
22562 3: DW_TAG_enumerator (enum1:0)
22563 3: DW_TAG_enumerator (enum2:1)
22565 2: DW_TAG_template_type_param
22566 DW_AT_type DW_FORM_ref_udata (E)
22568 Besides being broken debug info, it can put GDB into an
22569 infinite loop. Consider:
22571 When we're building the full name for Class<E>, we'll start
22572 at Class, and go look over its template type parameters,
22573 finding E. We'll then try to build the full name of E, and
22574 reach here. We're now trying to build the full name of E,
22575 and look over the parent DIE for containing scope. In the
22576 broken case, if we followed the parent DIE of E, we'd again
22577 find Class, and once again go look at its template type
22578 arguments, etc., etc. Simply don't consider such parent die
22579 as source-level parent of this die (it can't be, the language
22580 doesn't allow it), and break the loop here. */
22581 name
= dwarf2_name (die
, cu
);
22582 parent_name
= dwarf2_name (parent
, cu
);
22583 complaint (_("template param type '%s' defined within parent '%s'"),
22584 name
? name
: "<unknown>",
22585 parent_name
? parent_name
: "<unknown>");
22589 switch (parent
->tag
)
22591 case DW_TAG_namespace
:
22592 parent_type
= read_type_die (parent
, cu
);
22593 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22594 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22595 Work around this problem here. */
22596 if (cu
->language
== language_cplus
22597 && strcmp (parent_type
->name (), "::") == 0)
22599 /* We give a name to even anonymous namespaces. */
22600 return parent_type
->name ();
22601 case DW_TAG_class_type
:
22602 case DW_TAG_interface_type
:
22603 case DW_TAG_structure_type
:
22604 case DW_TAG_union_type
:
22605 case DW_TAG_module
:
22606 parent_type
= read_type_die (parent
, cu
);
22607 if (parent_type
->name () != NULL
)
22608 return parent_type
->name ();
22610 /* An anonymous structure is only allowed non-static data
22611 members; no typedefs, no member functions, et cetera.
22612 So it does not need a prefix. */
22614 case DW_TAG_compile_unit
:
22615 case DW_TAG_partial_unit
:
22616 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22617 if (cu
->language
== language_cplus
22618 && !per_objfile
->per_bfd
->types
.empty ()
22619 && die
->child
!= NULL
22620 && (die
->tag
== DW_TAG_class_type
22621 || die
->tag
== DW_TAG_structure_type
22622 || die
->tag
== DW_TAG_union_type
))
22624 const char *name
= guess_full_die_structure_name (die
, cu
);
22629 case DW_TAG_subprogram
:
22630 /* Nested subroutines in Fortran get a prefix with the name
22631 of the parent's subroutine. */
22632 if (cu
->language
== language_fortran
)
22634 if ((die
->tag
== DW_TAG_subprogram
)
22635 && (dwarf2_name (parent
, cu
) != NULL
))
22636 return dwarf2_name (parent
, cu
);
22638 return determine_prefix (parent
, cu
);
22639 case DW_TAG_enumeration_type
:
22640 parent_type
= read_type_die (parent
, cu
);
22641 if (parent_type
->is_declared_class ())
22643 if (parent_type
->name () != NULL
)
22644 return parent_type
->name ();
22647 /* Fall through. */
22649 return determine_prefix (parent
, cu
);
22653 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22654 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22655 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22656 an obconcat, otherwise allocate storage for the result. The CU argument is
22657 used to determine the language and hence, the appropriate separator. */
22659 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22662 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22663 int physname
, struct dwarf2_cu
*cu
)
22665 const char *lead
= "";
22668 if (suffix
== NULL
|| suffix
[0] == '\0'
22669 || prefix
== NULL
|| prefix
[0] == '\0')
22671 else if (cu
->language
== language_d
)
22673 /* For D, the 'main' function could be defined in any module, but it
22674 should never be prefixed. */
22675 if (strcmp (suffix
, "D main") == 0)
22683 else if (cu
->language
== language_fortran
&& physname
)
22685 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22686 DW_AT_MIPS_linkage_name is preferred and used instead. */
22694 if (prefix
== NULL
)
22696 if (suffix
== NULL
)
22703 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22705 strcpy (retval
, lead
);
22706 strcat (retval
, prefix
);
22707 strcat (retval
, sep
);
22708 strcat (retval
, suffix
);
22713 /* We have an obstack. */
22714 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22718 /* Get name of a die, return NULL if not found. */
22720 static const char *
22721 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22722 struct objfile
*objfile
)
22724 if (name
&& cu
->language
== language_cplus
)
22726 gdb::unique_xmalloc_ptr
<char> canon_name
22727 = cp_canonicalize_string (name
);
22729 if (canon_name
!= nullptr)
22730 name
= objfile
->intern (canon_name
.get ());
22736 /* Get name of a die, return NULL if not found.
22737 Anonymous namespaces are converted to their magic string. */
22739 static const char *
22740 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22742 struct attribute
*attr
;
22743 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22745 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22746 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22747 if (attr_name
== nullptr
22748 && die
->tag
!= DW_TAG_namespace
22749 && die
->tag
!= DW_TAG_class_type
22750 && die
->tag
!= DW_TAG_interface_type
22751 && die
->tag
!= DW_TAG_structure_type
22752 && die
->tag
!= DW_TAG_union_type
)
22757 case DW_TAG_compile_unit
:
22758 case DW_TAG_partial_unit
:
22759 /* Compilation units have a DW_AT_name that is a filename, not
22760 a source language identifier. */
22761 case DW_TAG_enumeration_type
:
22762 case DW_TAG_enumerator
:
22763 /* These tags always have simple identifiers already; no need
22764 to canonicalize them. */
22767 case DW_TAG_namespace
:
22768 if (attr_name
!= nullptr)
22770 return CP_ANONYMOUS_NAMESPACE_STR
;
22772 case DW_TAG_class_type
:
22773 case DW_TAG_interface_type
:
22774 case DW_TAG_structure_type
:
22775 case DW_TAG_union_type
:
22776 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22777 structures or unions. These were of the form "._%d" in GCC 4.1,
22778 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22779 and GCC 4.4. We work around this problem by ignoring these. */
22780 if (attr_name
!= nullptr
22781 && (startswith (attr_name
, "._")
22782 || startswith (attr_name
, "<anonymous")))
22785 /* GCC might emit a nameless typedef that has a linkage name. See
22786 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22787 if (!attr
|| attr_name
== NULL
)
22789 attr
= dw2_linkage_name_attr (die
, cu
);
22790 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22791 if (attr
== NULL
|| attr_name
== NULL
)
22794 /* Avoid demangling attr_name the second time on a second
22795 call for the same DIE. */
22796 if (!attr
->canonical_string_p ())
22798 gdb::unique_xmalloc_ptr
<char> demangled
22799 (gdb_demangle (attr_name
, DMGL_TYPES
));
22800 if (demangled
== nullptr)
22803 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22804 attr_name
= attr
->as_string ();
22807 /* Strip any leading namespaces/classes, keep only the
22808 base name. DW_AT_name for named DIEs does not
22809 contain the prefixes. */
22810 const char *base
= strrchr (attr_name
, ':');
22811 if (base
&& base
> attr_name
&& base
[-1] == ':')
22822 if (!attr
->canonical_string_p ())
22823 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22825 return attr
->as_string ();
22828 /* Return the die that this die in an extension of, or NULL if there
22829 is none. *EXT_CU is the CU containing DIE on input, and the CU
22830 containing the return value on output. */
22832 static struct die_info
*
22833 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22835 struct attribute
*attr
;
22837 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22841 return follow_die_ref (die
, attr
, ext_cu
);
22845 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22849 print_spaces (indent
, f
);
22850 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22851 dwarf_tag_name (die
->tag
), die
->abbrev
,
22852 sect_offset_str (die
->sect_off
));
22854 if (die
->parent
!= NULL
)
22856 print_spaces (indent
, f
);
22857 fprintf_unfiltered (f
, " parent at offset: %s\n",
22858 sect_offset_str (die
->parent
->sect_off
));
22861 print_spaces (indent
, f
);
22862 fprintf_unfiltered (f
, " has children: %s\n",
22863 dwarf_bool_name (die
->child
!= NULL
));
22865 print_spaces (indent
, f
);
22866 fprintf_unfiltered (f
, " attributes:\n");
22868 for (i
= 0; i
< die
->num_attrs
; ++i
)
22870 print_spaces (indent
, f
);
22871 fprintf_unfiltered (f
, " %s (%s) ",
22872 dwarf_attr_name (die
->attrs
[i
].name
),
22873 dwarf_form_name (die
->attrs
[i
].form
));
22875 switch (die
->attrs
[i
].form
)
22878 case DW_FORM_addrx
:
22879 case DW_FORM_GNU_addr_index
:
22880 fprintf_unfiltered (f
, "address: ");
22881 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
22883 case DW_FORM_block2
:
22884 case DW_FORM_block4
:
22885 case DW_FORM_block
:
22886 case DW_FORM_block1
:
22887 fprintf_unfiltered (f
, "block: size %s",
22888 pulongest (die
->attrs
[i
].as_block ()->size
));
22890 case DW_FORM_exprloc
:
22891 fprintf_unfiltered (f
, "expression: size %s",
22892 pulongest (die
->attrs
[i
].as_block ()->size
));
22894 case DW_FORM_data16
:
22895 fprintf_unfiltered (f
, "constant of 16 bytes");
22897 case DW_FORM_ref_addr
:
22898 fprintf_unfiltered (f
, "ref address: ");
22899 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22901 case DW_FORM_GNU_ref_alt
:
22902 fprintf_unfiltered (f
, "alt ref address: ");
22903 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22909 case DW_FORM_ref_udata
:
22910 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22911 (long) (die
->attrs
[i
].as_unsigned ()));
22913 case DW_FORM_data1
:
22914 case DW_FORM_data2
:
22915 case DW_FORM_data4
:
22916 case DW_FORM_data8
:
22917 case DW_FORM_udata
:
22918 fprintf_unfiltered (f
, "constant: %s",
22919 pulongest (die
->attrs
[i
].as_unsigned ()));
22921 case DW_FORM_sec_offset
:
22922 fprintf_unfiltered (f
, "section offset: %s",
22923 pulongest (die
->attrs
[i
].as_unsigned ()));
22925 case DW_FORM_ref_sig8
:
22926 fprintf_unfiltered (f
, "signature: %s",
22927 hex_string (die
->attrs
[i
].as_signature ()));
22929 case DW_FORM_string
:
22931 case DW_FORM_line_strp
:
22933 case DW_FORM_GNU_str_index
:
22934 case DW_FORM_GNU_strp_alt
:
22935 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22936 die
->attrs
[i
].as_string ()
22937 ? die
->attrs
[i
].as_string () : "",
22938 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
22941 if (die
->attrs
[i
].as_boolean ())
22942 fprintf_unfiltered (f
, "flag: TRUE");
22944 fprintf_unfiltered (f
, "flag: FALSE");
22946 case DW_FORM_flag_present
:
22947 fprintf_unfiltered (f
, "flag: TRUE");
22949 case DW_FORM_indirect
:
22950 /* The reader will have reduced the indirect form to
22951 the "base form" so this form should not occur. */
22952 fprintf_unfiltered (f
,
22953 "unexpected attribute form: DW_FORM_indirect");
22955 case DW_FORM_sdata
:
22956 case DW_FORM_implicit_const
:
22957 fprintf_unfiltered (f
, "constant: %s",
22958 plongest (die
->attrs
[i
].as_signed ()));
22961 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22962 die
->attrs
[i
].form
);
22965 fprintf_unfiltered (f
, "\n");
22970 dump_die_for_error (struct die_info
*die
)
22972 dump_die_shallow (gdb_stderr
, 0, die
);
22976 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22978 int indent
= level
* 4;
22980 gdb_assert (die
!= NULL
);
22982 if (level
>= max_level
)
22985 dump_die_shallow (f
, indent
, die
);
22987 if (die
->child
!= NULL
)
22989 print_spaces (indent
, f
);
22990 fprintf_unfiltered (f
, " Children:");
22991 if (level
+ 1 < max_level
)
22993 fprintf_unfiltered (f
, "\n");
22994 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22998 fprintf_unfiltered (f
,
22999 " [not printed, max nesting level reached]\n");
23003 if (die
->sibling
!= NULL
&& level
> 0)
23005 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23009 /* This is called from the pdie macro in gdbinit.in.
23010 It's not static so gcc will keep a copy callable from gdb. */
23013 dump_die (struct die_info
*die
, int max_level
)
23015 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23019 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23023 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23024 to_underlying (die
->sect_off
),
23030 /* Follow reference or signature attribute ATTR of SRC_DIE.
23031 On entry *REF_CU is the CU of SRC_DIE.
23032 On exit *REF_CU is the CU of the result. */
23034 static struct die_info
*
23035 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23036 struct dwarf2_cu
**ref_cu
)
23038 struct die_info
*die
;
23040 if (attr
->form_is_ref ())
23041 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23042 else if (attr
->form
== DW_FORM_ref_sig8
)
23043 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23046 dump_die_for_error (src_die
);
23047 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23048 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23054 /* Follow reference OFFSET.
23055 On entry *REF_CU is the CU of the source die referencing OFFSET.
23056 On exit *REF_CU is the CU of the result.
23057 Returns NULL if OFFSET is invalid. */
23059 static struct die_info
*
23060 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23061 struct dwarf2_cu
**ref_cu
)
23063 struct die_info temp_die
;
23064 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23065 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23067 gdb_assert (cu
->per_cu
!= NULL
);
23071 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23072 "source CU contains target offset: %d",
23073 sect_offset_str (cu
->per_cu
->sect_off
),
23074 sect_offset_str (sect_off
),
23075 cu
->header
.offset_in_cu_p (sect_off
));
23077 if (cu
->per_cu
->is_debug_types
)
23079 /* .debug_types CUs cannot reference anything outside their CU.
23080 If they need to, they have to reference a signatured type via
23081 DW_FORM_ref_sig8. */
23082 if (!cu
->header
.offset_in_cu_p (sect_off
))
23085 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23086 || !cu
->header
.offset_in_cu_p (sect_off
))
23088 struct dwarf2_per_cu_data
*per_cu
;
23090 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23093 dwarf_read_debug_printf_v ("target CU offset: %s, "
23094 "target CU DIEs loaded: %d",
23095 sect_offset_str (per_cu
->sect_off
),
23096 per_objfile
->get_cu (per_cu
) != nullptr);
23098 /* If necessary, add it to the queue and load its DIEs.
23100 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23101 it doesn't mean they are currently loaded. Since we require them
23102 to be loaded, we must check for ourselves. */
23103 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23104 || per_objfile
->get_cu (per_cu
) == nullptr)
23105 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23106 false, cu
->language
);
23108 target_cu
= per_objfile
->get_cu (per_cu
);
23109 gdb_assert (target_cu
!= nullptr);
23111 else if (cu
->dies
== NULL
)
23113 /* We're loading full DIEs during partial symbol reading. */
23114 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23115 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23119 *ref_cu
= target_cu
;
23120 temp_die
.sect_off
= sect_off
;
23122 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23124 to_underlying (sect_off
));
23127 /* Follow reference attribute ATTR of SRC_DIE.
23128 On entry *REF_CU is the CU of SRC_DIE.
23129 On exit *REF_CU is the CU of the result. */
23131 static struct die_info
*
23132 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23133 struct dwarf2_cu
**ref_cu
)
23135 sect_offset sect_off
= attr
->get_ref_die_offset ();
23136 struct dwarf2_cu
*cu
= *ref_cu
;
23137 struct die_info
*die
;
23139 die
= follow_die_offset (sect_off
,
23140 (attr
->form
== DW_FORM_GNU_ref_alt
23141 || cu
->per_cu
->is_dwz
),
23144 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23145 "at %s [in module %s]"),
23146 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23147 objfile_name (cu
->per_objfile
->objfile
));
23154 struct dwarf2_locexpr_baton
23155 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23156 dwarf2_per_cu_data
*per_cu
,
23157 dwarf2_per_objfile
*per_objfile
,
23158 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23159 bool resolve_abstract_p
)
23161 struct die_info
*die
;
23162 struct attribute
*attr
;
23163 struct dwarf2_locexpr_baton retval
;
23164 struct objfile
*objfile
= per_objfile
->objfile
;
23166 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23168 cu
= load_cu (per_cu
, per_objfile
, false);
23172 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23173 Instead just throw an error, not much else we can do. */
23174 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23175 sect_offset_str (sect_off
), objfile_name (objfile
));
23178 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23180 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23181 sect_offset_str (sect_off
), objfile_name (objfile
));
23183 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23184 if (!attr
&& resolve_abstract_p
23185 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23186 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23188 CORE_ADDR pc
= get_frame_pc ();
23189 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23190 struct gdbarch
*gdbarch
= objfile
->arch ();
23192 for (const auto &cand_off
23193 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23195 struct dwarf2_cu
*cand_cu
= cu
;
23196 struct die_info
*cand
23197 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23200 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23203 CORE_ADDR pc_low
, pc_high
;
23204 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23205 if (pc_low
== ((CORE_ADDR
) -1))
23207 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23208 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23209 if (!(pc_low
<= pc
&& pc
< pc_high
))
23213 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23220 /* DWARF: "If there is no such attribute, then there is no effect.".
23221 DATA is ignored if SIZE is 0. */
23223 retval
.data
= NULL
;
23226 else if (attr
->form_is_section_offset ())
23228 struct dwarf2_loclist_baton loclist_baton
;
23229 CORE_ADDR pc
= get_frame_pc ();
23232 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23234 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23236 retval
.size
= size
;
23240 if (!attr
->form_is_block ())
23241 error (_("Dwarf Error: DIE at %s referenced in module %s "
23242 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23243 sect_offset_str (sect_off
), objfile_name (objfile
));
23245 struct dwarf_block
*block
= attr
->as_block ();
23246 retval
.data
= block
->data
;
23247 retval
.size
= block
->size
;
23249 retval
.per_objfile
= per_objfile
;
23250 retval
.per_cu
= cu
->per_cu
;
23252 per_objfile
->age_comp_units ();
23259 struct dwarf2_locexpr_baton
23260 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23261 dwarf2_per_cu_data
*per_cu
,
23262 dwarf2_per_objfile
*per_objfile
,
23263 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23265 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23267 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23271 /* Write a constant of a given type as target-ordered bytes into
23274 static const gdb_byte
*
23275 write_constant_as_bytes (struct obstack
*obstack
,
23276 enum bfd_endian byte_order
,
23283 *len
= TYPE_LENGTH (type
);
23284 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23285 store_unsigned_integer (result
, *len
, byte_order
, value
);
23293 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23294 dwarf2_per_cu_data
*per_cu
,
23295 dwarf2_per_objfile
*per_objfile
,
23299 struct die_info
*die
;
23300 struct attribute
*attr
;
23301 const gdb_byte
*result
= NULL
;
23304 enum bfd_endian byte_order
;
23305 struct objfile
*objfile
= per_objfile
->objfile
;
23307 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23309 cu
= load_cu (per_cu
, per_objfile
, false);
23313 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23314 Instead just throw an error, not much else we can do. */
23315 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23316 sect_offset_str (sect_off
), objfile_name (objfile
));
23319 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23321 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23322 sect_offset_str (sect_off
), objfile_name (objfile
));
23324 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23328 byte_order
= (bfd_big_endian (objfile
->obfd
)
23329 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23331 switch (attr
->form
)
23334 case DW_FORM_addrx
:
23335 case DW_FORM_GNU_addr_index
:
23339 *len
= cu
->header
.addr_size
;
23340 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23341 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23345 case DW_FORM_string
:
23348 case DW_FORM_GNU_str_index
:
23349 case DW_FORM_GNU_strp_alt
:
23350 /* The string is already allocated on the objfile obstack, point
23353 const char *attr_name
= attr
->as_string ();
23354 result
= (const gdb_byte
*) attr_name
;
23355 *len
= strlen (attr_name
);
23358 case DW_FORM_block1
:
23359 case DW_FORM_block2
:
23360 case DW_FORM_block4
:
23361 case DW_FORM_block
:
23362 case DW_FORM_exprloc
:
23363 case DW_FORM_data16
:
23365 struct dwarf_block
*block
= attr
->as_block ();
23366 result
= block
->data
;
23367 *len
= block
->size
;
23371 /* The DW_AT_const_value attributes are supposed to carry the
23372 symbol's value "represented as it would be on the target
23373 architecture." By the time we get here, it's already been
23374 converted to host endianness, so we just need to sign- or
23375 zero-extend it as appropriate. */
23376 case DW_FORM_data1
:
23377 type
= die_type (die
, cu
);
23378 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23379 if (result
== NULL
)
23380 result
= write_constant_as_bytes (obstack
, byte_order
,
23383 case DW_FORM_data2
:
23384 type
= die_type (die
, cu
);
23385 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23386 if (result
== NULL
)
23387 result
= write_constant_as_bytes (obstack
, byte_order
,
23390 case DW_FORM_data4
:
23391 type
= die_type (die
, cu
);
23392 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23393 if (result
== NULL
)
23394 result
= write_constant_as_bytes (obstack
, byte_order
,
23397 case DW_FORM_data8
:
23398 type
= die_type (die
, cu
);
23399 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23400 if (result
== NULL
)
23401 result
= write_constant_as_bytes (obstack
, byte_order
,
23405 case DW_FORM_sdata
:
23406 case DW_FORM_implicit_const
:
23407 type
= die_type (die
, cu
);
23408 result
= write_constant_as_bytes (obstack
, byte_order
,
23409 type
, attr
->as_signed (), len
);
23412 case DW_FORM_udata
:
23413 type
= die_type (die
, cu
);
23414 result
= write_constant_as_bytes (obstack
, byte_order
,
23415 type
, attr
->as_unsigned (), len
);
23419 complaint (_("unsupported const value attribute form: '%s'"),
23420 dwarf_form_name (attr
->form
));
23430 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23431 dwarf2_per_cu_data
*per_cu
,
23432 dwarf2_per_objfile
*per_objfile
,
23433 const char **var_name
)
23435 struct die_info
*die
;
23437 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23439 cu
= load_cu (per_cu
, per_objfile
, false);
23444 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23448 if (var_name
!= nullptr)
23449 *var_name
= var_decl_name (die
, cu
);
23450 return die_type (die
, cu
);
23456 dwarf2_get_die_type (cu_offset die_offset
,
23457 dwarf2_per_cu_data
*per_cu
,
23458 dwarf2_per_objfile
*per_objfile
)
23460 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23461 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23464 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23465 On entry *REF_CU is the CU of SRC_DIE.
23466 On exit *REF_CU is the CU of the result.
23467 Returns NULL if the referenced DIE isn't found. */
23469 static struct die_info
*
23470 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23471 struct dwarf2_cu
**ref_cu
)
23473 struct die_info temp_die
;
23474 struct dwarf2_cu
*sig_cu
;
23475 struct die_info
*die
;
23476 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23479 /* While it might be nice to assert sig_type->type == NULL here,
23480 we can get here for DW_AT_imported_declaration where we need
23481 the DIE not the type. */
23483 /* If necessary, add it to the queue and load its DIEs.
23485 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23486 it doesn't mean they are currently loaded. Since we require them
23487 to be loaded, we must check for ourselves. */
23488 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23490 || per_objfile
->get_cu (sig_type
) == nullptr)
23491 read_signatured_type (sig_type
, per_objfile
);
23493 sig_cu
= per_objfile
->get_cu (sig_type
);
23494 gdb_assert (sig_cu
!= NULL
);
23495 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23496 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23497 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23498 to_underlying (temp_die
.sect_off
));
23501 /* For .gdb_index version 7 keep track of included TUs.
23502 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23503 if (per_objfile
->per_bfd
->index_table
!= NULL
23504 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23506 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23516 /* Follow signatured type referenced by ATTR in SRC_DIE.
23517 On entry *REF_CU is the CU of SRC_DIE.
23518 On exit *REF_CU is the CU of the result.
23519 The result is the DIE of the type.
23520 If the referenced type cannot be found an error is thrown. */
23522 static struct die_info
*
23523 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23524 struct dwarf2_cu
**ref_cu
)
23526 ULONGEST signature
= attr
->as_signature ();
23527 struct signatured_type
*sig_type
;
23528 struct die_info
*die
;
23530 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23532 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23533 /* sig_type will be NULL if the signatured type is missing from
23535 if (sig_type
== NULL
)
23537 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23538 " from DIE at %s [in module %s]"),
23539 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23540 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23543 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23546 dump_die_for_error (src_die
);
23547 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23548 " from DIE at %s [in module %s]"),
23549 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23550 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23556 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23557 reading in and processing the type unit if necessary. */
23559 static struct type
*
23560 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23561 struct dwarf2_cu
*cu
)
23563 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23564 struct signatured_type
*sig_type
;
23565 struct dwarf2_cu
*type_cu
;
23566 struct die_info
*type_die
;
23569 sig_type
= lookup_signatured_type (cu
, signature
);
23570 /* sig_type will be NULL if the signatured type is missing from
23572 if (sig_type
== NULL
)
23574 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23575 " from DIE at %s [in module %s]"),
23576 hex_string (signature
), sect_offset_str (die
->sect_off
),
23577 objfile_name (per_objfile
->objfile
));
23578 return build_error_marker_type (cu
, die
);
23581 /* If we already know the type we're done. */
23582 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23583 if (type
!= nullptr)
23587 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23588 if (type_die
!= NULL
)
23590 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23591 is created. This is important, for example, because for c++ classes
23592 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23593 type
= read_type_die (type_die
, type_cu
);
23596 complaint (_("Dwarf Error: Cannot build signatured type %s"
23597 " referenced from DIE at %s [in module %s]"),
23598 hex_string (signature
), sect_offset_str (die
->sect_off
),
23599 objfile_name (per_objfile
->objfile
));
23600 type
= build_error_marker_type (cu
, die
);
23605 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23606 " from DIE at %s [in module %s]"),
23607 hex_string (signature
), sect_offset_str (die
->sect_off
),
23608 objfile_name (per_objfile
->objfile
));
23609 type
= build_error_marker_type (cu
, die
);
23612 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23617 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23618 reading in and processing the type unit if necessary. */
23620 static struct type
*
23621 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23622 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23624 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23625 if (attr
->form_is_ref ())
23627 struct dwarf2_cu
*type_cu
= cu
;
23628 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23630 return read_type_die (type_die
, type_cu
);
23632 else if (attr
->form
== DW_FORM_ref_sig8
)
23634 return get_signatured_type (die
, attr
->as_signature (), cu
);
23638 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23640 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23641 " at %s [in module %s]"),
23642 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23643 objfile_name (per_objfile
->objfile
));
23644 return build_error_marker_type (cu
, die
);
23648 /* Load the DIEs associated with type unit PER_CU into memory. */
23651 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23652 dwarf2_per_objfile
*per_objfile
)
23654 struct signatured_type
*sig_type
;
23656 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23657 gdb_assert (! per_cu
->type_unit_group_p ());
23659 /* We have the per_cu, but we need the signatured_type.
23660 Fortunately this is an easy translation. */
23661 gdb_assert (per_cu
->is_debug_types
);
23662 sig_type
= (struct signatured_type
*) per_cu
;
23664 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23666 read_signatured_type (sig_type
, per_objfile
);
23668 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23671 /* Read in a signatured type and build its CU and DIEs.
23672 If the type is a stub for the real type in a DWO file,
23673 read in the real type from the DWO file as well. */
23676 read_signatured_type (signatured_type
*sig_type
,
23677 dwarf2_per_objfile
*per_objfile
)
23679 gdb_assert (sig_type
->is_debug_types
);
23680 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23682 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23684 if (!reader
.dummy_p
)
23686 struct dwarf2_cu
*cu
= reader
.cu
;
23687 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23689 gdb_assert (cu
->die_hash
== NULL
);
23691 htab_create_alloc_ex (cu
->header
.length
/ 12,
23695 &cu
->comp_unit_obstack
,
23696 hashtab_obstack_allocate
,
23697 dummy_obstack_deallocate
);
23699 if (reader
.comp_unit_die
->has_children
)
23700 reader
.comp_unit_die
->child
23701 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23702 reader
.comp_unit_die
);
23703 cu
->dies
= reader
.comp_unit_die
;
23704 /* comp_unit_die is not stored in die_hash, no need. */
23706 /* We try not to read any attributes in this function, because
23707 not all CUs needed for references have been loaded yet, and
23708 symbol table processing isn't initialized. But we have to
23709 set the CU language, or we won't be able to build types
23710 correctly. Similarly, if we do not read the producer, we can
23711 not apply producer-specific interpretation. */
23712 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23717 sig_type
->tu_read
= 1;
23720 /* Decode simple location descriptions.
23721 Given a pointer to a dwarf block that defines a location, compute
23722 the location and return the value. If COMPUTED is non-null, it is
23723 set to true to indicate that decoding was successful, and false
23724 otherwise. If COMPUTED is null, then this function may emit a
23728 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23730 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23732 size_t size
= blk
->size
;
23733 const gdb_byte
*data
= blk
->data
;
23734 CORE_ADDR stack
[64];
23736 unsigned int bytes_read
, unsnd
;
23739 if (computed
!= nullptr)
23745 stack
[++stacki
] = 0;
23784 stack
[++stacki
] = op
- DW_OP_lit0
;
23819 stack
[++stacki
] = op
- DW_OP_reg0
;
23822 if (computed
== nullptr)
23823 dwarf2_complex_location_expr_complaint ();
23830 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23832 stack
[++stacki
] = unsnd
;
23835 if (computed
== nullptr)
23836 dwarf2_complex_location_expr_complaint ();
23843 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23848 case DW_OP_const1u
:
23849 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23853 case DW_OP_const1s
:
23854 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23858 case DW_OP_const2u
:
23859 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23863 case DW_OP_const2s
:
23864 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23868 case DW_OP_const4u
:
23869 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23873 case DW_OP_const4s
:
23874 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23878 case DW_OP_const8u
:
23879 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23884 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23890 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23895 stack
[stacki
+ 1] = stack
[stacki
];
23900 stack
[stacki
- 1] += stack
[stacki
];
23904 case DW_OP_plus_uconst
:
23905 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23911 stack
[stacki
- 1] -= stack
[stacki
];
23916 /* If we're not the last op, then we definitely can't encode
23917 this using GDB's address_class enum. This is valid for partial
23918 global symbols, although the variable's address will be bogus
23922 if (computed
== nullptr)
23923 dwarf2_complex_location_expr_complaint ();
23929 case DW_OP_GNU_push_tls_address
:
23930 case DW_OP_form_tls_address
:
23931 /* The top of the stack has the offset from the beginning
23932 of the thread control block at which the variable is located. */
23933 /* Nothing should follow this operator, so the top of stack would
23935 /* This is valid for partial global symbols, but the variable's
23936 address will be bogus in the psymtab. Make it always at least
23937 non-zero to not look as a variable garbage collected by linker
23938 which have DW_OP_addr 0. */
23941 if (computed
== nullptr)
23942 dwarf2_complex_location_expr_complaint ();
23949 case DW_OP_GNU_uninit
:
23950 if (computed
!= nullptr)
23955 case DW_OP_GNU_addr_index
:
23956 case DW_OP_GNU_const_index
:
23957 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23963 if (computed
== nullptr)
23965 const char *name
= get_DW_OP_name (op
);
23968 complaint (_("unsupported stack op: '%s'"),
23971 complaint (_("unsupported stack op: '%02x'"),
23975 return (stack
[stacki
]);
23978 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23979 outside of the allocated space. Also enforce minimum>0. */
23980 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23982 if (computed
== nullptr)
23983 complaint (_("location description stack overflow"));
23989 if (computed
== nullptr)
23990 complaint (_("location description stack underflow"));
23995 if (computed
!= nullptr)
23997 return (stack
[stacki
]);
24000 /* memory allocation interface */
24002 static struct dwarf_block
*
24003 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24005 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24008 static struct die_info
*
24009 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24011 struct die_info
*die
;
24012 size_t size
= sizeof (struct die_info
);
24015 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24017 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24018 memset (die
, 0, sizeof (struct die_info
));
24024 /* Macro support. */
24026 /* An overload of dwarf_decode_macros that finds the correct section
24027 and ensures it is read in before calling the other overload. */
24030 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24031 int section_is_gnu
)
24033 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24034 struct objfile
*objfile
= per_objfile
->objfile
;
24035 const struct line_header
*lh
= cu
->line_header
;
24036 unsigned int offset_size
= cu
->header
.offset_size
;
24037 struct dwarf2_section_info
*section
;
24038 const char *section_name
;
24040 if (cu
->dwo_unit
!= nullptr)
24042 if (section_is_gnu
)
24044 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24045 section_name
= ".debug_macro.dwo";
24049 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24050 section_name
= ".debug_macinfo.dwo";
24055 if (section_is_gnu
)
24057 section
= &per_objfile
->per_bfd
->macro
;
24058 section_name
= ".debug_macro";
24062 section
= &per_objfile
->per_bfd
->macinfo
;
24063 section_name
= ".debug_macinfo";
24067 section
->read (objfile
);
24068 if (section
->buffer
== nullptr)
24070 complaint (_("missing %s section"), section_name
);
24074 buildsym_compunit
*builder
= cu
->get_builder ();
24076 struct dwarf2_section_info
*str_offsets_section
;
24077 struct dwarf2_section_info
*str_section
;
24078 ULONGEST str_offsets_base
;
24080 if (cu
->dwo_unit
!= nullptr)
24082 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24083 ->sections
.str_offsets
;
24084 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24085 str_offsets_base
= cu
->header
.addr_size
;
24089 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24090 str_section
= &per_objfile
->per_bfd
->str
;
24091 str_offsets_base
= *cu
->str_offsets_base
;
24094 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24095 offset_size
, offset
, str_section
, str_offsets_section
,
24096 str_offsets_base
, section_is_gnu
);
24099 /* Return the .debug_loc section to use for CU.
24100 For DWO files use .debug_loc.dwo. */
24102 static struct dwarf2_section_info
*
24103 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24105 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24109 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24111 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24113 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24114 : &per_objfile
->per_bfd
->loc
);
24117 /* Return the .debug_rnglists section to use for CU. */
24118 static struct dwarf2_section_info
*
24119 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24121 if (cu
->header
.version
< 5)
24122 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24123 cu
->header
.version
);
24124 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24126 /* Make sure we read the .debug_rnglists section from the file that
24127 contains the DW_AT_ranges attribute we are reading. Normally that
24128 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24129 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24131 if (cu
->dwo_unit
!= nullptr
24132 && tag
!= DW_TAG_compile_unit
24133 && tag
!= DW_TAG_skeleton_unit
)
24135 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24137 if (sections
->rnglists
.size
> 0)
24138 return §ions
->rnglists
;
24140 error (_(".debug_rnglists section is missing from .dwo file."));
24142 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24145 /* A helper function that fills in a dwarf2_loclist_baton. */
24148 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24149 struct dwarf2_loclist_baton
*baton
,
24150 const struct attribute
*attr
)
24152 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24153 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24155 section
->read (per_objfile
->objfile
);
24157 baton
->per_objfile
= per_objfile
;
24158 baton
->per_cu
= cu
->per_cu
;
24159 gdb_assert (baton
->per_cu
);
24160 /* We don't know how long the location list is, but make sure we
24161 don't run off the edge of the section. */
24162 baton
->size
= section
->size
- attr
->as_unsigned ();
24163 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24164 if (cu
->base_address
.has_value ())
24165 baton
->base_address
= *cu
->base_address
;
24167 baton
->base_address
= 0;
24168 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24172 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24173 struct dwarf2_cu
*cu
, int is_block
)
24175 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24176 struct objfile
*objfile
= per_objfile
->objfile
;
24177 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24179 if (attr
->form_is_section_offset ()
24180 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24181 the section. If so, fall through to the complaint in the
24183 && attr
->as_unsigned () < section
->get_size (objfile
))
24185 struct dwarf2_loclist_baton
*baton
;
24187 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24189 fill_in_loclist_baton (cu
, baton
, attr
);
24191 if (!cu
->base_address
.has_value ())
24192 complaint (_("Location list used without "
24193 "specifying the CU base address."));
24195 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24196 ? dwarf2_loclist_block_index
24197 : dwarf2_loclist_index
);
24198 SYMBOL_LOCATION_BATON (sym
) = baton
;
24202 struct dwarf2_locexpr_baton
*baton
;
24204 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24205 baton
->per_objfile
= per_objfile
;
24206 baton
->per_cu
= cu
->per_cu
;
24207 gdb_assert (baton
->per_cu
);
24209 if (attr
->form_is_block ())
24211 /* Note that we're just copying the block's data pointer
24212 here, not the actual data. We're still pointing into the
24213 info_buffer for SYM's objfile; right now we never release
24214 that buffer, but when we do clean up properly this may
24216 struct dwarf_block
*block
= attr
->as_block ();
24217 baton
->size
= block
->size
;
24218 baton
->data
= block
->data
;
24222 dwarf2_invalid_attrib_class_complaint ("location description",
24223 sym
->natural_name ());
24227 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24228 ? dwarf2_locexpr_block_index
24229 : dwarf2_locexpr_index
);
24230 SYMBOL_LOCATION_BATON (sym
) = baton
;
24236 const comp_unit_head
*
24237 dwarf2_per_cu_data::get_header () const
24239 if (!m_header_read_in
)
24241 const gdb_byte
*info_ptr
24242 = this->section
->buffer
+ to_underlying (this->sect_off
);
24244 memset (&m_header
, 0, sizeof (m_header
));
24246 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24247 rcuh_kind::COMPILE
);
24249 m_header_read_in
= true;
24258 dwarf2_per_cu_data::addr_size () const
24260 return this->get_header ()->addr_size
;
24266 dwarf2_per_cu_data::offset_size () const
24268 return this->get_header ()->offset_size
;
24274 dwarf2_per_cu_data::ref_addr_size () const
24276 const comp_unit_head
*header
= this->get_header ();
24278 if (header
->version
== 2)
24279 return header
->addr_size
;
24281 return header
->offset_size
;
24284 /* A helper function for dwarf2_find_containing_comp_unit that returns
24285 the index of the result, and that searches a vector. It will
24286 return a result even if the offset in question does not actually
24287 occur in any CU. This is separate so that it can be unit
24291 dwarf2_find_containing_comp_unit
24292 (sect_offset sect_off
,
24293 unsigned int offset_in_dwz
,
24294 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24299 high
= all_comp_units
.size () - 1;
24302 struct dwarf2_per_cu_data
*mid_cu
;
24303 int mid
= low
+ (high
- low
) / 2;
24305 mid_cu
= all_comp_units
[mid
].get ();
24306 if (mid_cu
->is_dwz
> offset_in_dwz
24307 || (mid_cu
->is_dwz
== offset_in_dwz
24308 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24313 gdb_assert (low
== high
);
24317 /* Locate the .debug_info compilation unit from CU's objfile which contains
24318 the DIE at OFFSET. Raises an error on failure. */
24320 static struct dwarf2_per_cu_data
*
24321 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24322 unsigned int offset_in_dwz
,
24323 dwarf2_per_objfile
*per_objfile
)
24325 int low
= dwarf2_find_containing_comp_unit
24326 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24327 dwarf2_per_cu_data
*this_cu
24328 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24330 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24332 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24333 error (_("Dwarf Error: could not find partial DIE containing "
24334 "offset %s [in module %s]"),
24335 sect_offset_str (sect_off
),
24336 bfd_get_filename (per_objfile
->objfile
->obfd
));
24338 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24340 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24344 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24345 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24346 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24347 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24354 namespace selftests
{
24355 namespace find_containing_comp_unit
{
24360 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24361 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24362 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24363 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24364 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24365 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24366 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24367 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24370 two
->sect_off
= sect_offset (one
->length
);
24375 four
->sect_off
= sect_offset (three
->length
);
24379 std::vector
<dwarf2_per_cu_data_up
> units
;
24380 units
.push_back (std::move (one
));
24381 units
.push_back (std::move (two
));
24382 units
.push_back (std::move (three
));
24383 units
.push_back (std::move (four
));
24387 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24388 SELF_CHECK (units
[result
].get () == one_ptr
);
24389 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24390 SELF_CHECK (units
[result
].get () == one_ptr
);
24391 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24392 SELF_CHECK (units
[result
].get () == two_ptr
);
24394 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24395 SELF_CHECK (units
[result
].get () == three_ptr
);
24396 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24397 SELF_CHECK (units
[result
].get () == three_ptr
);
24398 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24399 SELF_CHECK (units
[result
].get () == four_ptr
);
24405 #endif /* GDB_SELF_TEST */
24407 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24410 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24411 enum language pretend_language
)
24413 struct attribute
*attr
;
24415 /* Set the language we're debugging. */
24416 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24417 if (attr
!= nullptr)
24418 set_cu_language (attr
->constant_value (0), cu
);
24421 cu
->language
= pretend_language
;
24422 cu
->language_defn
= language_def (cu
->language
);
24425 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24431 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24433 auto it
= m_dwarf2_cus
.find (per_cu
);
24434 if (it
== m_dwarf2_cus
.end ())
24443 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24445 gdb_assert (this->get_cu (per_cu
) == nullptr);
24447 m_dwarf2_cus
[per_cu
] = cu
;
24453 dwarf2_per_objfile::age_comp_units ()
24455 dwarf_read_debug_printf_v ("running");
24457 /* This is not expected to be called in the middle of CU expansion. There is
24458 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24459 loaded in memory. Calling age_comp_units while the queue is in use could
24460 make us free the DIEs for a CU that is in the queue and therefore break
24462 gdb_assert (!this->per_bfd
->queue
.has_value ());
24464 /* Start by clearing all marks. */
24465 for (auto pair
: m_dwarf2_cus
)
24466 pair
.second
->clear_mark ();
24468 /* Traverse all CUs, mark them and their dependencies if used recently
24470 for (auto pair
: m_dwarf2_cus
)
24472 dwarf2_cu
*cu
= pair
.second
;
24475 if (cu
->last_used
<= dwarf_max_cache_age
)
24479 /* Delete all CUs still not marked. */
24480 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24482 dwarf2_cu
*cu
= it
->second
;
24484 if (!cu
->is_marked ())
24486 dwarf_read_debug_printf_v ("deleting old CU %s",
24487 sect_offset_str (cu
->per_cu
->sect_off
));
24489 it
= m_dwarf2_cus
.erase (it
);
24499 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24501 auto it
= m_dwarf2_cus
.find (per_cu
);
24502 if (it
== m_dwarf2_cus
.end ())
24507 m_dwarf2_cus
.erase (it
);
24510 dwarf2_per_objfile::~dwarf2_per_objfile ()
24515 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24516 We store these in a hash table separate from the DIEs, and preserve them
24517 when the DIEs are flushed out of cache.
24519 The CU "per_cu" pointer is needed because offset alone is not enough to
24520 uniquely identify the type. A file may have multiple .debug_types sections,
24521 or the type may come from a DWO file. Furthermore, while it's more logical
24522 to use per_cu->section+offset, with Fission the section with the data is in
24523 the DWO file but we don't know that section at the point we need it.
24524 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24525 because we can enter the lookup routine, get_die_type_at_offset, from
24526 outside this file, and thus won't necessarily have PER_CU->cu.
24527 Fortunately, PER_CU is stable for the life of the objfile. */
24529 struct dwarf2_per_cu_offset_and_type
24531 const struct dwarf2_per_cu_data
*per_cu
;
24532 sect_offset sect_off
;
24536 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24539 per_cu_offset_and_type_hash (const void *item
)
24541 const struct dwarf2_per_cu_offset_and_type
*ofs
24542 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24544 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24547 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24550 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24552 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24553 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24554 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24555 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24557 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24558 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24561 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24562 table if necessary. For convenience, return TYPE.
24564 The DIEs reading must have careful ordering to:
24565 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24566 reading current DIE.
24567 * Not trying to dereference contents of still incompletely read in types
24568 while reading in other DIEs.
24569 * Enable referencing still incompletely read in types just by a pointer to
24570 the type without accessing its fields.
24572 Therefore caller should follow these rules:
24573 * Try to fetch any prerequisite types we may need to build this DIE type
24574 before building the type and calling set_die_type.
24575 * After building type call set_die_type for current DIE as soon as
24576 possible before fetching more types to complete the current type.
24577 * Make the type as complete as possible before fetching more types. */
24579 static struct type
*
24580 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24581 bool skip_data_location
)
24583 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24584 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24585 struct objfile
*objfile
= per_objfile
->objfile
;
24586 struct attribute
*attr
;
24587 struct dynamic_prop prop
;
24589 /* For Ada types, make sure that the gnat-specific data is always
24590 initialized (if not already set). There are a few types where
24591 we should not be doing so, because the type-specific area is
24592 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24593 where the type-specific area is used to store the floatformat).
24594 But this is not a problem, because the gnat-specific information
24595 is actually not needed for these types. */
24596 if (need_gnat_info (cu
)
24597 && type
->code () != TYPE_CODE_FUNC
24598 && type
->code () != TYPE_CODE_FLT
24599 && type
->code () != TYPE_CODE_METHODPTR
24600 && type
->code () != TYPE_CODE_MEMBERPTR
24601 && type
->code () != TYPE_CODE_METHOD
24602 && type
->code () != TYPE_CODE_FIXED_POINT
24603 && !HAVE_GNAT_AUX_INFO (type
))
24604 INIT_GNAT_SPECIFIC (type
);
24606 /* Read DW_AT_allocated and set in type. */
24607 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24610 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24611 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24612 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24615 /* Read DW_AT_associated and set in type. */
24616 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24619 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24620 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24621 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24624 /* Read DW_AT_data_location and set in type. */
24625 if (!skip_data_location
)
24627 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24628 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24629 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24632 if (per_objfile
->die_type_hash
== NULL
)
24633 per_objfile
->die_type_hash
24634 = htab_up (htab_create_alloc (127,
24635 per_cu_offset_and_type_hash
,
24636 per_cu_offset_and_type_eq
,
24637 NULL
, xcalloc
, xfree
));
24639 ofs
.per_cu
= cu
->per_cu
;
24640 ofs
.sect_off
= die
->sect_off
;
24642 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24643 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24645 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24646 sect_offset_str (die
->sect_off
));
24647 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24648 struct dwarf2_per_cu_offset_and_type
);
24653 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24654 or return NULL if the die does not have a saved type. */
24656 static struct type
*
24657 get_die_type_at_offset (sect_offset sect_off
,
24658 dwarf2_per_cu_data
*per_cu
,
24659 dwarf2_per_objfile
*per_objfile
)
24661 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24663 if (per_objfile
->die_type_hash
== NULL
)
24666 ofs
.per_cu
= per_cu
;
24667 ofs
.sect_off
= sect_off
;
24668 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24669 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24676 /* Look up the type for DIE in CU in die_type_hash,
24677 or return NULL if DIE does not have a saved type. */
24679 static struct type
*
24680 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24682 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24685 /* Trivial hash function for partial_die_info: the hash value of a DIE
24686 is its offset in .debug_info for this objfile. */
24689 partial_die_hash (const void *item
)
24691 const struct partial_die_info
*part_die
24692 = (const struct partial_die_info
*) item
;
24694 return to_underlying (part_die
->sect_off
);
24697 /* Trivial comparison function for partial_die_info structures: two DIEs
24698 are equal if they have the same offset. */
24701 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24703 const struct partial_die_info
*part_die_lhs
24704 = (const struct partial_die_info
*) item_lhs
;
24705 const struct partial_die_info
*part_die_rhs
24706 = (const struct partial_die_info
*) item_rhs
;
24708 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24711 struct cmd_list_element
*set_dwarf_cmdlist
;
24712 struct cmd_list_element
*show_dwarf_cmdlist
;
24715 show_check_physname (struct ui_file
*file
, int from_tty
,
24716 struct cmd_list_element
*c
, const char *value
)
24718 fprintf_filtered (file
,
24719 _("Whether to check \"physname\" is %s.\n"),
24723 void _initialize_dwarf2_read ();
24725 _initialize_dwarf2_read ()
24727 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24728 Set DWARF specific variables.\n\
24729 Configure DWARF variables such as the cache size."),
24730 &set_dwarf_cmdlist
,
24731 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24733 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24734 Show DWARF specific variables.\n\
24735 Show DWARF variables such as the cache size."),
24736 &show_dwarf_cmdlist
,
24737 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24739 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24740 &dwarf_max_cache_age
, _("\
24741 Set the upper bound on the age of cached DWARF compilation units."), _("\
24742 Show the upper bound on the age of cached DWARF compilation units."), _("\
24743 A higher limit means that cached compilation units will be stored\n\
24744 in memory longer, and more total memory will be used. Zero disables\n\
24745 caching, which can slow down startup."),
24747 show_dwarf_max_cache_age
,
24748 &set_dwarf_cmdlist
,
24749 &show_dwarf_cmdlist
);
24751 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24752 Set debugging of the DWARF reader."), _("\
24753 Show debugging of the DWARF reader."), _("\
24754 When enabled (non-zero), debugging messages are printed during DWARF\n\
24755 reading and symtab expansion. A value of 1 (one) provides basic\n\
24756 information. A value greater than 1 provides more verbose information."),
24759 &setdebuglist
, &showdebuglist
);
24761 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24762 Set debugging of the DWARF DIE reader."), _("\
24763 Show debugging of the DWARF DIE reader."), _("\
24764 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24765 The value is the maximum depth to print."),
24768 &setdebuglist
, &showdebuglist
);
24770 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24771 Set debugging of the dwarf line reader."), _("\
24772 Show debugging of the dwarf line reader."), _("\
24773 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24774 A value of 1 (one) provides basic information.\n\
24775 A value greater than 1 provides more verbose information."),
24778 &setdebuglist
, &showdebuglist
);
24780 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24781 Set cross-checking of \"physname\" code against demangler."), _("\
24782 Show cross-checking of \"physname\" code against demangler."), _("\
24783 When enabled, GDB's internal \"physname\" code is checked against\n\
24785 NULL
, show_check_physname
,
24786 &setdebuglist
, &showdebuglist
);
24788 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24789 no_class
, &use_deprecated_index_sections
, _("\
24790 Set whether to use deprecated gdb_index sections."), _("\
24791 Show whether to use deprecated gdb_index sections."), _("\
24792 When enabled, deprecated .gdb_index sections are used anyway.\n\
24793 Normally they are ignored either because of a missing feature or\n\
24794 performance issue.\n\
24795 Warning: This option must be enabled before gdb reads the file."),
24798 &setlist
, &showlist
);
24800 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24801 &dwarf2_locexpr_funcs
);
24802 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24803 &dwarf2_loclist_funcs
);
24805 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24806 &dwarf2_block_frame_base_locexpr_funcs
);
24807 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24808 &dwarf2_block_frame_base_loclist_funcs
);
24811 selftests::register_test ("dw2_expand_symtabs_matching",
24812 selftests::dw2_expand_symtabs_matching::run_test
);
24813 selftests::register_test ("dwarf2_find_containing_comp_unit",
24814 selftests::find_containing_comp_unit::run_test
);