1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2022 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit-head.h"
36 #include "dwarf2/cu.h"
37 #include "dwarf2/index-cache.h"
38 #include "dwarf2/index-common.h"
39 #include "dwarf2/leb.h"
40 #include "dwarf2/line-header.h"
41 #include "dwarf2/dwz.h"
42 #include "dwarf2/macro.h"
43 #include "dwarf2/die.h"
44 #include "dwarf2/sect-names.h"
45 #include "dwarf2/stringify.h"
46 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
91 #include <unordered_set>
93 /* When == 1, print basic high level tracing messages.
94 When > 1, be more verbose.
95 This is in contrast to the low level DIE reading of dwarf_die_debug. */
96 static unsigned int dwarf_read_debug
= 0;
98 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
100 #define dwarf_read_debug_printf(fmt, ...) \
101 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
104 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
106 #define dwarf_read_debug_printf_v(fmt, ...) \
107 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
110 /* When non-zero, dump DIEs after they are read in. */
111 static unsigned int dwarf_die_debug
= 0;
113 /* When non-zero, dump line number entries as they are read in. */
114 unsigned int dwarf_line_debug
= 0;
116 /* When true, cross-check physname against demangler. */
117 static bool check_physname
= false;
119 /* When true, do not reject deprecated .gdb_index sections. */
120 static bool use_deprecated_index_sections
= false;
122 /* This is used to store the data that is always per objfile. */
123 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
125 /* These are used to store the dwarf2_per_bfd objects.
127 objfiles having the same BFD, which doesn't require relocations, are going to
128 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
130 Other objfiles are not going to share a dwarf2_per_bfd with any other
131 objfiles, so they'll have their own version kept in the _objfile_data_key
133 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
134 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
136 /* The "aclass" indices for various kinds of computed DWARF symbols. */
138 static int dwarf2_locexpr_index
;
139 static int dwarf2_loclist_index
;
140 static int dwarf2_locexpr_block_index
;
141 static int dwarf2_loclist_block_index
;
143 /* Size of .debug_loclists section header for 32-bit DWARF format. */
144 #define LOCLIST_HEADER_SIZE32 12
146 /* Size of .debug_loclists section header for 64-bit DWARF format. */
147 #define LOCLIST_HEADER_SIZE64 20
149 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
150 #define RNGLIST_HEADER_SIZE32 12
152 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
153 #define RNGLIST_HEADER_SIZE64 20
155 /* An index into a (C++) symbol name component in a symbol name as
156 recorded in the mapped_index's symbol table. For each C++ symbol
157 in the symbol table, we record one entry for the start of each
158 component in the symbol in a table of name components, and then
159 sort the table, in order to be able to binary search symbol names,
160 ignoring leading namespaces, both completion and regular look up.
161 For example, for symbol "A::B::C", we'll have an entry that points
162 to "A::B::C", another that points to "B::C", and another for "C".
163 Note that function symbols in GDB index have no parameter
164 information, just the function/method names. You can convert a
165 name_component to a "const char *" using the
166 'mapped_index::symbol_name_at(offset_type)' method. */
168 struct name_component
170 /* Offset in the symbol name where the component starts. Stored as
171 a (32-bit) offset instead of a pointer to save memory and improve
172 locality on 64-bit architectures. */
173 offset_type name_offset
;
175 /* The symbol's index in the symbol and constant pool tables of a
180 /* Base class containing bits shared by both .gdb_index and
181 .debug_name indexes. */
183 struct mapped_index_base
185 mapped_index_base () = default;
186 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
188 /* The name_component table (a sorted vector). See name_component's
189 description above. */
190 std::vector
<name_component
> name_components
;
192 /* How NAME_COMPONENTS is sorted. */
193 enum case_sensitivity name_components_casing
;
195 /* Return the number of names in the symbol table. */
196 virtual size_t symbol_name_count () const = 0;
198 /* Get the name of the symbol at IDX in the symbol table. */
199 virtual const char *symbol_name_at
200 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
202 /* Return whether the name at IDX in the symbol table should be
204 virtual bool symbol_name_slot_invalid (offset_type idx
) const
209 /* Build the symbol name component sorted vector, if we haven't
211 void build_name_components (dwarf2_per_objfile
*per_objfile
);
213 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
214 possible matches for LN_NO_PARAMS in the name component
216 std::pair
<std::vector
<name_component
>::const_iterator
,
217 std::vector
<name_component
>::const_iterator
>
218 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
220 dwarf2_per_objfile
*per_objfile
) const;
222 /* Prevent deleting/destroying via a base class pointer. */
224 ~mapped_index_base() = default;
227 /* This is a view into the index that converts from bytes to an
228 offset_type, and allows indexing. Unaligned bytes are specifically
229 allowed here, and handled via unpacking. */
234 offset_view () = default;
236 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
241 /* Extract the INDEXth offset_type from the array. */
242 offset_type
operator[] (size_t index
) const
244 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
245 return (offset_type
) extract_unsigned_integer (bytes
,
246 sizeof (offset_type
),
250 /* Return the number of offset_types in this array. */
253 return m_bytes
.size () / sizeof (offset_type
);
256 /* Return true if this view is empty. */
259 return m_bytes
.empty ();
263 /* The underlying bytes. */
264 gdb::array_view
<const gdb_byte
> m_bytes
;
267 /* A description of the mapped index. The file format is described in
268 a comment by the code that writes the index. */
269 struct mapped_index final
: public mapped_index_base
271 /* Index data format version. */
274 /* The address table data. */
275 gdb::array_view
<const gdb_byte
> address_table
;
277 /* The symbol table, implemented as a hash table. */
278 offset_view symbol_table
;
280 /* A pointer to the constant pool. */
281 gdb::array_view
<const gdb_byte
> constant_pool
;
283 /* Return the index into the constant pool of the name of the IDXth
284 symbol in the symbol table. */
285 offset_type
symbol_name_index (offset_type idx
) const
287 return symbol_table
[2 * idx
];
290 /* Return the index into the constant pool of the CU vector of the
291 IDXth symbol in the symbol table. */
292 offset_type
symbol_vec_index (offset_type idx
) const
294 return symbol_table
[2 * idx
+ 1];
297 bool symbol_name_slot_invalid (offset_type idx
) const override
299 return (symbol_name_index (idx
) == 0
300 && symbol_vec_index (idx
) == 0);
303 /* Convenience method to get at the name of the symbol at IDX in the
305 const char *symbol_name_at
306 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
308 return (const char *) (this->constant_pool
.data ()
309 + symbol_name_index (idx
));
312 size_t symbol_name_count () const override
313 { return this->symbol_table
.size () / 2; }
316 /* A description of the mapped .debug_names.
317 Uninitialized map has CU_COUNT 0. */
318 struct mapped_debug_names final
: public mapped_index_base
320 bfd_endian dwarf5_byte_order
;
321 bool dwarf5_is_dwarf64
;
322 bool augmentation_is_gdb
;
324 uint32_t cu_count
= 0;
325 uint32_t tu_count
, bucket_count
, name_count
;
326 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
327 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
328 const gdb_byte
*name_table_string_offs_reordered
;
329 const gdb_byte
*name_table_entry_offs_reordered
;
330 const gdb_byte
*entry_pool
;
337 /* Attribute name DW_IDX_*. */
340 /* Attribute form DW_FORM_*. */
343 /* Value if FORM is DW_FORM_implicit_const. */
344 LONGEST implicit_const
;
346 std::vector
<attr
> attr_vec
;
349 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
351 const char *namei_to_name
352 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
354 /* Implementation of the mapped_index_base virtual interface, for
355 the name_components cache. */
357 const char *symbol_name_at
358 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
359 { return namei_to_name (idx
, per_objfile
); }
361 size_t symbol_name_count () const override
362 { return this->name_count
; }
365 /* See dwarf2/read.h. */
368 get_dwarf2_per_objfile (struct objfile
*objfile
)
370 return dwarf2_objfile_data_key
.get (objfile
);
373 /* Default names of the debugging sections. */
375 /* Note that if the debugging section has been compressed, it might
376 have a name like .zdebug_info. */
378 const struct dwarf2_debug_sections dwarf2_elf_names
=
380 { ".debug_info", ".zdebug_info" },
381 { ".debug_abbrev", ".zdebug_abbrev" },
382 { ".debug_line", ".zdebug_line" },
383 { ".debug_loc", ".zdebug_loc" },
384 { ".debug_loclists", ".zdebug_loclists" },
385 { ".debug_macinfo", ".zdebug_macinfo" },
386 { ".debug_macro", ".zdebug_macro" },
387 { ".debug_str", ".zdebug_str" },
388 { ".debug_str_offsets", ".zdebug_str_offsets" },
389 { ".debug_line_str", ".zdebug_line_str" },
390 { ".debug_ranges", ".zdebug_ranges" },
391 { ".debug_rnglists", ".zdebug_rnglists" },
392 { ".debug_types", ".zdebug_types" },
393 { ".debug_addr", ".zdebug_addr" },
394 { ".debug_frame", ".zdebug_frame" },
395 { ".eh_frame", NULL
},
396 { ".gdb_index", ".zgdb_index" },
397 { ".debug_names", ".zdebug_names" },
398 { ".debug_aranges", ".zdebug_aranges" },
402 /* List of DWO/DWP sections. */
404 static const struct dwop_section_names
406 struct dwarf2_section_names abbrev_dwo
;
407 struct dwarf2_section_names info_dwo
;
408 struct dwarf2_section_names line_dwo
;
409 struct dwarf2_section_names loc_dwo
;
410 struct dwarf2_section_names loclists_dwo
;
411 struct dwarf2_section_names macinfo_dwo
;
412 struct dwarf2_section_names macro_dwo
;
413 struct dwarf2_section_names rnglists_dwo
;
414 struct dwarf2_section_names str_dwo
;
415 struct dwarf2_section_names str_offsets_dwo
;
416 struct dwarf2_section_names types_dwo
;
417 struct dwarf2_section_names cu_index
;
418 struct dwarf2_section_names tu_index
;
422 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
423 { ".debug_info.dwo", ".zdebug_info.dwo" },
424 { ".debug_line.dwo", ".zdebug_line.dwo" },
425 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
426 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
427 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
428 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
429 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
430 { ".debug_str.dwo", ".zdebug_str.dwo" },
431 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
432 { ".debug_types.dwo", ".zdebug_types.dwo" },
433 { ".debug_cu_index", ".zdebug_cu_index" },
434 { ".debug_tu_index", ".zdebug_tu_index" },
437 /* local data types */
439 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
440 begin with a header, which contains the following information. */
441 struct loclists_rnglists_header
443 /* A 4-byte or 12-byte length containing the length of the
444 set of entries for this compilation unit, not including the
445 length field itself. */
448 /* A 2-byte version identifier. */
451 /* A 1-byte unsigned integer containing the size in bytes of an address on
452 the target system. */
453 unsigned char addr_size
;
455 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
456 on the target system. */
457 unsigned char segment_collector_size
;
459 /* A 4-byte count of the number of offsets that follow the header. */
460 unsigned int offset_entry_count
;
463 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
464 This includes type_unit_group and quick_file_names. */
466 struct stmt_list_hash
468 /* The DWO unit this table is from or NULL if there is none. */
469 struct dwo_unit
*dwo_unit
;
471 /* Offset in .debug_line or .debug_line.dwo. */
472 sect_offset line_sect_off
;
475 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
476 an object of this type. This contains elements of type unit groups
477 that can be shared across objfiles. The non-shareable parts are in
478 type_unit_group_unshareable. */
480 struct type_unit_group
: public dwarf2_per_cu_data
482 /* The TUs that share this DW_AT_stmt_list entry.
483 This is added to while parsing type units to build partial symtabs,
484 and is deleted afterwards and not used again. */
485 std::vector
<signatured_type
*> *tus
= nullptr;
487 /* The data used to construct the hash key. */
488 struct stmt_list_hash hash
{};
491 /* These sections are what may appear in a (real or virtual) DWO file. */
495 struct dwarf2_section_info abbrev
;
496 struct dwarf2_section_info line
;
497 struct dwarf2_section_info loc
;
498 struct dwarf2_section_info loclists
;
499 struct dwarf2_section_info macinfo
;
500 struct dwarf2_section_info macro
;
501 struct dwarf2_section_info rnglists
;
502 struct dwarf2_section_info str
;
503 struct dwarf2_section_info str_offsets
;
504 /* In the case of a virtual DWO file, these two are unused. */
505 struct dwarf2_section_info info
;
506 std::vector
<dwarf2_section_info
> types
;
509 /* CUs/TUs in DWP/DWO files. */
513 /* Backlink to the containing struct dwo_file. */
514 struct dwo_file
*dwo_file
;
516 /* The "id" that distinguishes this CU/TU.
517 .debug_info calls this "dwo_id", .debug_types calls this "signature".
518 Since signatures came first, we stick with it for consistency. */
521 /* The section this CU/TU lives in, in the DWO file. */
522 struct dwarf2_section_info
*section
;
524 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
525 sect_offset sect_off
;
528 /* For types, offset in the type's DIE of the type defined by this TU. */
529 cu_offset type_offset_in_tu
;
532 /* include/dwarf2.h defines the DWP section codes.
533 It defines a max value but it doesn't define a min value, which we
534 use for error checking, so provide one. */
536 enum dwp_v2_section_ids
541 /* Data for one DWO file.
543 This includes virtual DWO files (a virtual DWO file is a DWO file as it
544 appears in a DWP file). DWP files don't really have DWO files per se -
545 comdat folding of types "loses" the DWO file they came from, and from
546 a high level view DWP files appear to contain a mass of random types.
547 However, to maintain consistency with the non-DWP case we pretend DWP
548 files contain virtual DWO files, and we assign each TU with one virtual
549 DWO file (generally based on the line and abbrev section offsets -
550 a heuristic that seems to work in practice). */
554 dwo_file () = default;
555 DISABLE_COPY_AND_ASSIGN (dwo_file
);
557 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
558 For virtual DWO files the name is constructed from the section offsets
559 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
560 from related CU+TUs. */
561 const char *dwo_name
= nullptr;
563 /* The DW_AT_comp_dir attribute. */
564 const char *comp_dir
= nullptr;
566 /* The bfd, when the file is open. Otherwise this is NULL.
567 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
568 gdb_bfd_ref_ptr dbfd
;
570 /* The sections that make up this DWO file.
571 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
572 sections (for lack of a better name). */
573 struct dwo_sections sections
{};
575 /* The CUs in the file.
576 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
577 an extension to handle LLVM's Link Time Optimization output (where
578 multiple source files may be compiled into a single object/dwo pair). */
581 /* Table of TUs in the file.
582 Each element is a struct dwo_unit. */
586 /* These sections are what may appear in a DWP file. */
590 /* These are used by all DWP versions (1, 2 and 5). */
591 struct dwarf2_section_info str
;
592 struct dwarf2_section_info cu_index
;
593 struct dwarf2_section_info tu_index
;
595 /* These are only used by DWP version 2 and version 5 files.
596 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
597 sections are referenced by section number, and are not recorded here.
598 In DWP version 2 or 5 there is at most one copy of all these sections,
599 each section being (effectively) comprised of the concatenation of all of
600 the individual sections that exist in the version 1 format.
601 To keep the code simple we treat each of these concatenated pieces as a
602 section itself (a virtual section?). */
603 struct dwarf2_section_info abbrev
;
604 struct dwarf2_section_info info
;
605 struct dwarf2_section_info line
;
606 struct dwarf2_section_info loc
;
607 struct dwarf2_section_info loclists
;
608 struct dwarf2_section_info macinfo
;
609 struct dwarf2_section_info macro
;
610 struct dwarf2_section_info rnglists
;
611 struct dwarf2_section_info str_offsets
;
612 struct dwarf2_section_info types
;
615 /* These sections are what may appear in a virtual DWO file in DWP version 1.
616 A virtual DWO file is a DWO file as it appears in a DWP file. */
618 struct virtual_v1_dwo_sections
620 struct dwarf2_section_info abbrev
;
621 struct dwarf2_section_info line
;
622 struct dwarf2_section_info loc
;
623 struct dwarf2_section_info macinfo
;
624 struct dwarf2_section_info macro
;
625 struct dwarf2_section_info str_offsets
;
626 /* Each DWP hash table entry records one CU or one TU.
627 That is recorded here, and copied to dwo_unit.section. */
628 struct dwarf2_section_info info_or_types
;
631 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
632 In version 2, the sections of the DWO files are concatenated together
633 and stored in one section of that name. Thus each ELF section contains
634 several "virtual" sections. */
636 struct virtual_v2_or_v5_dwo_sections
638 bfd_size_type abbrev_offset
;
639 bfd_size_type abbrev_size
;
641 bfd_size_type line_offset
;
642 bfd_size_type line_size
;
644 bfd_size_type loc_offset
;
645 bfd_size_type loc_size
;
647 bfd_size_type loclists_offset
;
648 bfd_size_type loclists_size
;
650 bfd_size_type macinfo_offset
;
651 bfd_size_type macinfo_size
;
653 bfd_size_type macro_offset
;
654 bfd_size_type macro_size
;
656 bfd_size_type rnglists_offset
;
657 bfd_size_type rnglists_size
;
659 bfd_size_type str_offsets_offset
;
660 bfd_size_type str_offsets_size
;
662 /* Each DWP hash table entry records one CU or one TU.
663 That is recorded here, and copied to dwo_unit.section. */
664 bfd_size_type info_or_types_offset
;
665 bfd_size_type info_or_types_size
;
668 /* Contents of DWP hash tables. */
670 struct dwp_hash_table
672 uint32_t version
, nr_columns
;
673 uint32_t nr_units
, nr_slots
;
674 const gdb_byte
*hash_table
, *unit_table
;
679 const gdb_byte
*indices
;
683 /* This is indexed by column number and gives the id of the section
685 #define MAX_NR_V2_DWO_SECTIONS \
686 (1 /* .debug_info or .debug_types */ \
687 + 1 /* .debug_abbrev */ \
688 + 1 /* .debug_line */ \
689 + 1 /* .debug_loc */ \
690 + 1 /* .debug_str_offsets */ \
691 + 1 /* .debug_macro or .debug_macinfo */)
692 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
693 const gdb_byte
*offsets
;
694 const gdb_byte
*sizes
;
698 /* This is indexed by column number and gives the id of the section
700 #define MAX_NR_V5_DWO_SECTIONS \
701 (1 /* .debug_info */ \
702 + 1 /* .debug_abbrev */ \
703 + 1 /* .debug_line */ \
704 + 1 /* .debug_loclists */ \
705 + 1 /* .debug_str_offsets */ \
706 + 1 /* .debug_macro */ \
707 + 1 /* .debug_rnglists */)
708 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
709 const gdb_byte
*offsets
;
710 const gdb_byte
*sizes
;
715 /* Data for one DWP file. */
719 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
721 dbfd (std::move (abfd
))
725 /* Name of the file. */
728 /* File format version. */
732 gdb_bfd_ref_ptr dbfd
;
734 /* Section info for this file. */
735 struct dwp_sections sections
{};
737 /* Table of CUs in the file. */
738 const struct dwp_hash_table
*cus
= nullptr;
740 /* Table of TUs in the file. */
741 const struct dwp_hash_table
*tus
= nullptr;
743 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
747 /* Table to map ELF section numbers to their sections.
748 This is only needed for the DWP V1 file format. */
749 unsigned int num_sections
= 0;
750 asection
**elf_sections
= nullptr;
753 /* Struct used to pass misc. parameters to read_die_and_children, et
754 al. which are used for both .debug_info and .debug_types dies.
755 All parameters here are unchanging for the life of the call. This
756 struct exists to abstract away the constant parameters of die reading. */
758 struct die_reader_specs
760 /* The bfd of die_section. */
763 /* The CU of the DIE we are parsing. */
764 struct dwarf2_cu
*cu
;
766 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
767 struct dwo_file
*dwo_file
;
769 /* The section the die comes from.
770 This is either .debug_info or .debug_types, or the .dwo variants. */
771 struct dwarf2_section_info
*die_section
;
773 /* die_section->buffer. */
774 const gdb_byte
*buffer
;
776 /* The end of the buffer. */
777 const gdb_byte
*buffer_end
;
779 /* The abbreviation table to use when reading the DIEs. */
780 struct abbrev_table
*abbrev_table
;
783 /* A subclass of die_reader_specs that holds storage and has complex
784 constructor and destructor behavior. */
786 class cutu_reader
: public die_reader_specs
790 cutu_reader (dwarf2_per_cu_data
*this_cu
,
791 dwarf2_per_objfile
*per_objfile
,
792 struct abbrev_table
*abbrev_table
,
793 dwarf2_cu
*existing_cu
,
796 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
797 dwarf2_per_objfile
*per_objfile
,
798 struct dwarf2_cu
*parent_cu
= nullptr,
799 struct dwo_file
*dwo_file
= nullptr);
801 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
803 const gdb_byte
*info_ptr
= nullptr;
804 struct die_info
*comp_unit_die
= nullptr;
805 bool dummy_p
= false;
807 /* Release the new CU, putting it on the chain. This cannot be done
812 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
813 dwarf2_per_objfile
*per_objfile
,
814 dwarf2_cu
*existing_cu
);
816 struct dwarf2_per_cu_data
*m_this_cu
;
817 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
819 /* The ordinary abbreviation table. */
820 abbrev_table_up m_abbrev_table_holder
;
822 /* The DWO abbreviation table. */
823 abbrev_table_up m_dwo_abbrev_table
;
826 /* When we construct a partial symbol table entry we only
827 need this much information. */
828 struct partial_die_info
: public allocate_on_obstack
830 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
832 /* Disable assign but still keep copy ctor, which is needed
833 load_partial_dies. */
834 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
835 partial_die_info (const partial_die_info
&) = default;
837 /* Adjust the partial die before generating a symbol for it. This
838 function may set the is_external flag or change the DIE's
840 void fixup (struct dwarf2_cu
*cu
);
842 /* Read a minimal amount of information into the minimal die
844 const gdb_byte
*read (const struct die_reader_specs
*reader
,
845 const struct abbrev_info
&abbrev
,
846 const gdb_byte
*info_ptr
);
848 /* Compute the name of this partial DIE. This memoizes the
849 result, so it is safe to call multiple times. */
850 const char *name (dwarf2_cu
*cu
);
852 /* Offset of this DIE. */
853 const sect_offset sect_off
;
855 /* DWARF-2 tag for this DIE. */
856 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
858 /* Assorted flags describing the data found in this DIE. */
859 const unsigned int has_children
: 1;
861 unsigned int is_external
: 1;
862 unsigned int is_declaration
: 1;
863 unsigned int has_type
: 1;
864 unsigned int has_specification
: 1;
865 unsigned int has_pc_info
: 1;
866 unsigned int has_range_info
: 1;
867 unsigned int may_be_inlined
: 1;
869 /* This DIE has been marked DW_AT_main_subprogram. */
870 unsigned int main_subprogram
: 1;
872 /* Flag set if the SCOPE field of this structure has been
874 unsigned int scope_set
: 1;
876 /* Flag set if the DIE has a byte_size attribute. */
877 unsigned int has_byte_size
: 1;
879 /* Flag set if the DIE has a DW_AT_const_value attribute. */
880 unsigned int has_const_value
: 1;
882 /* Flag set if any of the DIE's children are template arguments. */
883 unsigned int has_template_arguments
: 1;
885 /* Flag set if fixup has been called on this die. */
886 unsigned int fixup_called
: 1;
888 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
889 unsigned int is_dwz
: 1;
891 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
892 unsigned int spec_is_dwz
: 1;
894 unsigned int canonical_name
: 1;
896 /* The name of this DIE. Normally the value of DW_AT_name, but
897 sometimes a default name for unnamed DIEs. */
898 const char *raw_name
= nullptr;
900 /* The linkage name, if present. */
901 const char *linkage_name
= nullptr;
903 /* The scope to prepend to our children. This is generally
904 allocated on the comp_unit_obstack, so will disappear
905 when this compilation unit leaves the cache. */
906 const char *scope
= nullptr;
908 /* Some data associated with the partial DIE. The tag determines
909 which field is live. */
912 /* The location description associated with this DIE, if any. */
913 struct dwarf_block
*locdesc
;
914 /* The offset of an import, for DW_TAG_imported_unit. */
915 sect_offset sect_off
;
920 /* If HAS_PC_INFO, the PC range associated with this DIE. */
926 /* If HAS_RANGE_INFO, the ranges offset associated with this DIE. */
927 ULONGEST ranges_offset
;
930 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
931 DW_AT_sibling, if any. */
932 /* NOTE: This member isn't strictly necessary, partial_die_info::read
933 could return DW_AT_sibling values to its caller load_partial_dies. */
934 const gdb_byte
*sibling
= nullptr;
936 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
937 DW_AT_specification (or DW_AT_abstract_origin or
939 sect_offset spec_offset
{};
941 /* Pointers to this DIE's parent, first child, and next sibling,
943 struct partial_die_info
*die_parent
= nullptr;
944 struct partial_die_info
*die_child
= nullptr;
945 struct partial_die_info
*die_sibling
= nullptr;
947 friend struct partial_die_info
*
948 dwarf2_cu::find_partial_die (sect_offset sect_off
);
951 /* Only need to do look up in dwarf2_cu::find_partial_die. */
952 partial_die_info (sect_offset sect_off
)
953 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
957 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
959 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
964 has_specification
= 0;
972 has_template_arguments
= 0;
977 /* Don't set these using NSDMI (Non-static data member initialisation),
978 because g++-4.8 will error out. */
984 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
985 but this would require a corresponding change in unpack_field_as_long
987 static int bits_per_byte
= 8;
989 struct variant_part_builder
;
991 /* When reading a variant, we track a bit more information about the
992 field, and store it in an object of this type. */
996 int first_field
= -1;
999 /* A variant can contain other variant parts. */
1000 std::vector
<variant_part_builder
> variant_parts
;
1002 /* If we see a DW_TAG_variant, then this will be set if this is the
1004 bool default_branch
= false;
1005 /* If we see a DW_AT_discr_value, then this will be the discriminant
1007 ULONGEST discriminant_value
= 0;
1008 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1010 struct dwarf_block
*discr_list_data
= nullptr;
1013 /* This represents a DW_TAG_variant_part. */
1015 struct variant_part_builder
1017 /* The offset of the discriminant field. */
1018 sect_offset discriminant_offset
{};
1020 /* Variants that are direct children of this variant part. */
1021 std::vector
<variant_field
> variants
;
1023 /* True if we're currently reading a variant. */
1024 bool processing_variant
= false;
1029 int accessibility
= 0;
1031 /* Variant parts need to find the discriminant, which is a DIE
1032 reference. We track the section offset of each field to make
1035 struct field field
{};
1040 const char *name
= nullptr;
1041 std::vector
<struct fn_field
> fnfields
;
1044 /* The routines that read and process dies for a C struct or C++ class
1045 pass lists of data member fields and lists of member function fields
1046 in an instance of a field_info structure, as defined below. */
1049 /* List of data member and baseclasses fields. */
1050 std::vector
<struct nextfield
> fields
;
1051 std::vector
<struct nextfield
> baseclasses
;
1053 /* Set if the accessibility of one of the fields is not public. */
1054 bool non_public_fields
= false;
1056 /* Member function fieldlist array, contains name of possibly overloaded
1057 member function, number of overloaded member functions and a pointer
1058 to the head of the member function field chain. */
1059 std::vector
<struct fnfieldlist
> fnfieldlists
;
1061 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1062 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1063 std::vector
<struct decl_field
> typedef_field_list
;
1065 /* Nested types defined by this class and the number of elements in this
1067 std::vector
<struct decl_field
> nested_types_list
;
1069 /* If non-null, this is the variant part we are currently
1071 variant_part_builder
*current_variant_part
= nullptr;
1072 /* This holds all the top-level variant parts attached to the type
1074 std::vector
<variant_part_builder
> variant_parts
;
1076 /* Return the total number of fields (including baseclasses). */
1077 int nfields () const
1079 return fields
.size () + baseclasses
.size ();
1083 /* Loaded secondary compilation units are kept in memory until they
1084 have not been referenced for the processing of this many
1085 compilation units. Set this to zero to disable caching. Cache
1086 sizes of up to at least twenty will improve startup time for
1087 typical inter-CU-reference binaries, at an obvious memory cost. */
1088 static int dwarf_max_cache_age
= 5;
1090 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1091 struct cmd_list_element
*c
, const char *value
)
1093 gdb_printf (file
, _("The upper bound on the age of cached "
1094 "DWARF compilation units is %s.\n"),
1098 /* local function prototypes */
1100 static void dwarf2_find_base_address (struct die_info
*die
,
1101 struct dwarf2_cu
*cu
);
1103 static dwarf2_psymtab
*create_partial_symtab
1104 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1107 static void build_type_psymtabs_reader (cutu_reader
*reader
);
1109 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1111 static void scan_partial_symbols (struct partial_die_info
*,
1112 CORE_ADDR
*, CORE_ADDR
*,
1113 int, struct dwarf2_cu
*);
1115 static void add_partial_symbol (struct partial_die_info
*,
1116 struct dwarf2_cu
*);
1118 static void add_partial_namespace (struct partial_die_info
*pdi
,
1119 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1120 int set_addrmap
, struct dwarf2_cu
*cu
);
1122 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1123 CORE_ADDR
*highpc
, int set_addrmap
,
1124 struct dwarf2_cu
*cu
);
1126 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1127 struct dwarf2_cu
*cu
);
1129 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1130 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1131 int need_pc
, struct dwarf2_cu
*cu
);
1133 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1135 static struct partial_die_info
*load_partial_dies
1136 (const struct die_reader_specs
*, const gdb_byte
*, int);
1138 /* A pair of partial_die_info and compilation unit. */
1139 struct cu_partial_die_info
1141 /* The compilation unit of the partial_die_info. */
1142 struct dwarf2_cu
*cu
;
1143 /* A partial_die_info. */
1144 struct partial_die_info
*pdi
;
1146 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1152 cu_partial_die_info () = delete;
1155 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1156 struct dwarf2_cu
*);
1158 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1160 const struct attr_abbrev
*,
1163 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1164 struct attribute
*attr
, dwarf_tag tag
);
1166 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1168 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1169 dwarf2_section_info
*, sect_offset
);
1171 static const char *read_indirect_string
1172 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1173 const struct comp_unit_head
*, unsigned int *);
1175 static const char *read_indirect_string_at_offset
1176 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1178 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1182 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1183 ULONGEST str_index
);
1185 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1186 ULONGEST str_index
);
1188 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1189 struct dwarf2_cu
*);
1191 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1192 struct dwarf2_cu
*cu
);
1194 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1196 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1197 struct dwarf2_cu
*cu
);
1199 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1201 static struct die_info
*die_specification (struct die_info
*die
,
1202 struct dwarf2_cu
**);
1204 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1205 struct dwarf2_cu
*cu
);
1207 static void dwarf_decode_lines (struct line_header
*,
1208 const file_and_directory
&,
1209 struct dwarf2_cu
*, dwarf2_psymtab
*,
1210 CORE_ADDR
, int decode_mapping
);
1212 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1215 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1216 struct dwarf2_cu
*, struct symbol
* = NULL
);
1218 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1219 struct dwarf2_cu
*);
1221 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1224 struct obstack
*obstack
,
1225 struct dwarf2_cu
*cu
, LONGEST
*value
,
1226 const gdb_byte
**bytes
,
1227 struct dwarf2_locexpr_baton
**baton
);
1229 static struct type
*read_subrange_index_type (struct die_info
*die
,
1230 struct dwarf2_cu
*cu
);
1232 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1234 static int need_gnat_info (struct dwarf2_cu
*);
1236 static struct type
*die_descriptive_type (struct die_info
*,
1237 struct dwarf2_cu
*);
1239 static void set_descriptive_type (struct type
*, struct die_info
*,
1240 struct dwarf2_cu
*);
1242 static struct type
*die_containing_type (struct die_info
*,
1243 struct dwarf2_cu
*);
1245 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1246 struct dwarf2_cu
*);
1248 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1250 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1252 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1254 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1255 const char *suffix
, int physname
,
1256 struct dwarf2_cu
*cu
);
1258 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1260 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1262 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1264 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1266 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1268 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1270 /* Return the .debug_loclists section to use for cu. */
1271 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1273 /* Return the .debug_rnglists section to use for cu. */
1274 static struct dwarf2_section_info
*cu_debug_rnglists_section
1275 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1277 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1278 values. Keep the items ordered with increasing constraints compliance. */
1281 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1282 PC_BOUNDS_NOT_PRESENT
,
1284 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1285 were present but they do not form a valid range of PC addresses. */
1288 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1291 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1295 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1296 CORE_ADDR
*, CORE_ADDR
*,
1301 static void get_scope_pc_bounds (struct die_info
*,
1302 CORE_ADDR
*, CORE_ADDR
*,
1303 struct dwarf2_cu
*);
1305 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1306 CORE_ADDR
, struct dwarf2_cu
*);
1308 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1309 struct dwarf2_cu
*);
1311 static void dwarf2_attach_fields_to_type (struct field_info
*,
1312 struct type
*, struct dwarf2_cu
*);
1314 static void dwarf2_add_member_fn (struct field_info
*,
1315 struct die_info
*, struct type
*,
1316 struct dwarf2_cu
*);
1318 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1320 struct dwarf2_cu
*);
1322 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1324 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1326 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1328 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1330 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1332 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1334 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1336 static struct type
*read_module_type (struct die_info
*die
,
1337 struct dwarf2_cu
*cu
);
1339 static const char *namespace_name (struct die_info
*die
,
1340 int *is_anonymous
, struct dwarf2_cu
*);
1342 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1344 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1347 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1348 struct dwarf2_cu
*);
1350 static struct die_info
*read_die_and_siblings_1
1351 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1354 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1355 const gdb_byte
*info_ptr
,
1356 const gdb_byte
**new_info_ptr
,
1357 struct die_info
*parent
);
1359 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1360 struct die_info
**, const gdb_byte
*,
1363 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1364 struct die_info
**, const gdb_byte
*);
1366 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1368 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1371 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1373 static const char *dwarf2_full_name (const char *name
,
1374 struct die_info
*die
,
1375 struct dwarf2_cu
*cu
);
1377 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1378 struct dwarf2_cu
*cu
);
1380 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1381 struct dwarf2_cu
**);
1383 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1385 static void dump_die_for_error (struct die_info
*);
1387 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1390 /*static*/ void dump_die (struct die_info
*, int max_level
);
1392 static void store_in_ref_table (struct die_info
*,
1393 struct dwarf2_cu
*);
1395 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1396 const struct attribute
*,
1397 struct dwarf2_cu
**);
1399 static struct die_info
*follow_die_ref (struct die_info
*,
1400 const struct attribute
*,
1401 struct dwarf2_cu
**);
1403 static struct die_info
*follow_die_sig (struct die_info
*,
1404 const struct attribute
*,
1405 struct dwarf2_cu
**);
1407 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1408 struct dwarf2_cu
*);
1410 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1411 const struct attribute
*,
1412 struct dwarf2_cu
*);
1414 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1415 dwarf2_per_objfile
*per_objfile
);
1417 static void read_signatured_type (signatured_type
*sig_type
,
1418 dwarf2_per_objfile
*per_objfile
);
1420 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1421 struct die_info
*die
, struct dwarf2_cu
*cu
,
1422 struct dynamic_prop
*prop
, struct type
*type
);
1424 /* memory allocation interface */
1426 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1428 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1430 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1432 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1433 struct dwarf2_loclist_baton
*baton
,
1434 const struct attribute
*attr
);
1436 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1438 struct dwarf2_cu
*cu
,
1441 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1442 const gdb_byte
*info_ptr
,
1443 const struct abbrev_info
*abbrev
,
1444 bool do_skip_children
= true);
1446 static hashval_t
partial_die_hash (const void *item
);
1448 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1450 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1451 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1452 dwarf2_per_bfd
*per_bfd
);
1454 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1455 struct die_info
*comp_unit_die
,
1456 enum language pretend_language
);
1458 static struct type
*set_die_type (struct die_info
*, struct type
*,
1459 struct dwarf2_cu
*, bool = false);
1461 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1463 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1464 dwarf2_per_objfile
*per_objfile
,
1465 dwarf2_cu
*existing_cu
,
1467 enum language pretend_language
);
1469 static void process_full_comp_unit (dwarf2_cu
*cu
,
1470 enum language pretend_language
);
1472 static void process_full_type_unit (dwarf2_cu
*cu
,
1473 enum language pretend_language
);
1475 static struct type
*get_die_type_at_offset (sect_offset
,
1476 dwarf2_per_cu_data
*per_cu
,
1477 dwarf2_per_objfile
*per_objfile
);
1479 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1481 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1482 dwarf2_per_objfile
*per_objfile
,
1483 enum language pretend_language
);
1485 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1487 /* Class, the destructor of which frees all allocated queue entries. This
1488 will only have work to do if an error was thrown while processing the
1489 dwarf. If no error was thrown then the queue entries should have all
1490 been processed, and freed, as we went along. */
1492 class dwarf2_queue_guard
1495 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1496 : m_per_objfile (per_objfile
)
1498 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1500 m_per_objfile
->per_bfd
->queue
.emplace ();
1503 /* Free any entries remaining on the queue. There should only be
1504 entries left if we hit an error while processing the dwarf. */
1505 ~dwarf2_queue_guard ()
1507 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1509 m_per_objfile
->per_bfd
->queue
.reset ();
1512 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1515 dwarf2_per_objfile
*m_per_objfile
;
1518 dwarf2_queue_item::~dwarf2_queue_item ()
1520 /* Anything still marked queued is likely to be in an
1521 inconsistent state, so discard it. */
1524 per_objfile
->remove_cu (per_cu
);
1529 /* See dwarf2/read.h. */
1532 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1534 if (data
->is_debug_types
)
1535 delete static_cast<signatured_type
*> (data
);
1540 static file_and_directory
&find_file_and_directory
1541 (struct die_info
*die
, struct dwarf2_cu
*cu
);
1543 static const char *compute_include_file_name
1544 (const struct line_header
*lh
,
1545 const file_entry
&fe
,
1546 const file_and_directory
&cu_info
,
1547 gdb::unique_xmalloc_ptr
<char> *name_holder
);
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 /* An iterator for all_comp_units that is based on index. This
1645 approach makes it possible to iterate over all_comp_units safely,
1646 when some caller in the loop may add new units. */
1648 class all_comp_units_iterator
1652 all_comp_units_iterator (dwarf2_per_bfd
*per_bfd
, bool start
)
1653 : m_per_bfd (per_bfd
),
1654 m_index (start
? 0 : per_bfd
->all_comp_units
.size ())
1658 all_comp_units_iterator
&operator++ ()
1664 dwarf2_per_cu_data
*operator* () const
1666 return m_per_bfd
->get_cu (m_index
);
1669 bool operator== (const all_comp_units_iterator
&other
) const
1671 return m_index
== other
.m_index
;
1675 bool operator!= (const all_comp_units_iterator
&other
) const
1677 return m_index
!= other
.m_index
;
1682 dwarf2_per_bfd
*m_per_bfd
;
1686 /* A range adapter for the all_comp_units_iterator. */
1687 class all_comp_units_range
1691 all_comp_units_range (dwarf2_per_bfd
*per_bfd
)
1692 : m_per_bfd (per_bfd
)
1696 all_comp_units_iterator
begin ()
1698 return all_comp_units_iterator (m_per_bfd
, true);
1701 all_comp_units_iterator
end ()
1703 return all_comp_units_iterator (m_per_bfd
, false);
1708 dwarf2_per_bfd
*m_per_bfd
;
1711 /* See declaration. */
1713 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1716 can_copy (can_copy_
)
1719 names
= &dwarf2_elf_names
;
1721 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1722 locate_sections (obfd
, sec
, *names
);
1725 dwarf2_per_bfd::~dwarf2_per_bfd ()
1727 for (auto &per_cu
: all_comp_units
)
1729 per_cu
->imported_symtabs_free ();
1730 per_cu
->free_cached_file_names ();
1733 /* Everything else should be on this->obstack. */
1739 dwarf2_per_objfile::remove_all_cus ()
1741 gdb_assert (!this->per_bfd
->queue
.has_value ());
1743 for (auto pair
: m_dwarf2_cus
)
1746 m_dwarf2_cus
.clear ();
1749 /* A helper class that calls free_cached_comp_units on
1752 class free_cached_comp_units
1756 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1757 : m_per_objfile (per_objfile
)
1761 ~free_cached_comp_units ()
1763 m_per_objfile
->remove_all_cus ();
1766 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1770 dwarf2_per_objfile
*m_per_objfile
;
1776 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1778 if (per_cu
->index
< this->m_symtabs
.size ())
1779 return this->m_symtabs
[per_cu
->index
] != nullptr;
1786 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1788 if (per_cu
->index
< this->m_symtabs
.size ())
1789 return this->m_symtabs
[per_cu
->index
];
1796 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1797 compunit_symtab
*symtab
)
1799 if (per_cu
->index
>= this->m_symtabs
.size ())
1800 this->m_symtabs
.resize (per_cu
->index
+ 1);
1801 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1802 this->m_symtabs
[per_cu
->index
] = symtab
;
1805 /* Try to locate the sections we need for DWARF 2 debugging
1806 information and return true if we have enough to do something.
1807 NAMES points to the dwarf2 section names, or is NULL if the standard
1808 ELF names are used. CAN_COPY is true for formats where symbol
1809 interposition is possible and so symbol values must follow copy
1810 relocation rules. */
1813 dwarf2_has_info (struct objfile
*objfile
,
1814 const struct dwarf2_debug_sections
*names
,
1817 if (objfile
->flags
& OBJF_READNEVER
)
1820 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1822 if (per_objfile
== NULL
)
1824 dwarf2_per_bfd
*per_bfd
;
1826 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1827 BFD doesn't require relocations.
1829 We don't share with objfiles for which -readnow was requested,
1830 because it would complicate things when loading the same BFD with
1831 -readnow and then without -readnow. */
1832 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1833 && (objfile
->flags
& OBJF_READNOW
) == 0)
1835 /* See if one has been created for this BFD yet. */
1836 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1838 if (per_bfd
== nullptr)
1840 /* No, create it now. */
1841 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1842 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1847 /* No sharing possible, create one specifically for this objfile. */
1848 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1849 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1852 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1855 return (!per_objfile
->per_bfd
->info
.is_virtual
1856 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1857 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1858 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1861 /* See declaration. */
1864 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1865 const dwarf2_debug_sections
&names
)
1867 flagword aflag
= bfd_section_flags (sectp
);
1869 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1872 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1873 > bfd_get_file_size (abfd
))
1875 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1876 warning (_("Discarding section %s which has a section size (%s"
1877 ") larger than the file size [in module %s]"),
1878 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1879 bfd_get_filename (abfd
));
1881 else if (names
.info
.matches (sectp
->name
))
1883 this->info
.s
.section
= sectp
;
1884 this->info
.size
= bfd_section_size (sectp
);
1886 else if (names
.abbrev
.matches (sectp
->name
))
1888 this->abbrev
.s
.section
= sectp
;
1889 this->abbrev
.size
= bfd_section_size (sectp
);
1891 else if (names
.line
.matches (sectp
->name
))
1893 this->line
.s
.section
= sectp
;
1894 this->line
.size
= bfd_section_size (sectp
);
1896 else if (names
.loc
.matches (sectp
->name
))
1898 this->loc
.s
.section
= sectp
;
1899 this->loc
.size
= bfd_section_size (sectp
);
1901 else if (names
.loclists
.matches (sectp
->name
))
1903 this->loclists
.s
.section
= sectp
;
1904 this->loclists
.size
= bfd_section_size (sectp
);
1906 else if (names
.macinfo
.matches (sectp
->name
))
1908 this->macinfo
.s
.section
= sectp
;
1909 this->macinfo
.size
= bfd_section_size (sectp
);
1911 else if (names
.macro
.matches (sectp
->name
))
1913 this->macro
.s
.section
= sectp
;
1914 this->macro
.size
= bfd_section_size (sectp
);
1916 else if (names
.str
.matches (sectp
->name
))
1918 this->str
.s
.section
= sectp
;
1919 this->str
.size
= bfd_section_size (sectp
);
1921 else if (names
.str_offsets
.matches (sectp
->name
))
1923 this->str_offsets
.s
.section
= sectp
;
1924 this->str_offsets
.size
= bfd_section_size (sectp
);
1926 else if (names
.line_str
.matches (sectp
->name
))
1928 this->line_str
.s
.section
= sectp
;
1929 this->line_str
.size
= bfd_section_size (sectp
);
1931 else if (names
.addr
.matches (sectp
->name
))
1933 this->addr
.s
.section
= sectp
;
1934 this->addr
.size
= bfd_section_size (sectp
);
1936 else if (names
.frame
.matches (sectp
->name
))
1938 this->frame
.s
.section
= sectp
;
1939 this->frame
.size
= bfd_section_size (sectp
);
1941 else if (names
.eh_frame
.matches (sectp
->name
))
1943 this->eh_frame
.s
.section
= sectp
;
1944 this->eh_frame
.size
= bfd_section_size (sectp
);
1946 else if (names
.ranges
.matches (sectp
->name
))
1948 this->ranges
.s
.section
= sectp
;
1949 this->ranges
.size
= bfd_section_size (sectp
);
1951 else if (names
.rnglists
.matches (sectp
->name
))
1953 this->rnglists
.s
.section
= sectp
;
1954 this->rnglists
.size
= bfd_section_size (sectp
);
1956 else if (names
.types
.matches (sectp
->name
))
1958 struct dwarf2_section_info type_section
;
1960 memset (&type_section
, 0, sizeof (type_section
));
1961 type_section
.s
.section
= sectp
;
1962 type_section
.size
= bfd_section_size (sectp
);
1964 this->types
.push_back (type_section
);
1966 else if (names
.gdb_index
.matches (sectp
->name
))
1968 this->gdb_index
.s
.section
= sectp
;
1969 this->gdb_index
.size
= bfd_section_size (sectp
);
1971 else if (names
.debug_names
.matches (sectp
->name
))
1973 this->debug_names
.s
.section
= sectp
;
1974 this->debug_names
.size
= bfd_section_size (sectp
);
1976 else if (names
.debug_aranges
.matches (sectp
->name
))
1978 this->debug_aranges
.s
.section
= sectp
;
1979 this->debug_aranges
.size
= bfd_section_size (sectp
);
1982 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1983 && bfd_section_vma (sectp
) == 0)
1984 this->has_section_at_zero
= true;
1987 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1991 dwarf2_get_section_info (struct objfile
*objfile
,
1992 enum dwarf2_section_enum sect
,
1993 asection
**sectp
, const gdb_byte
**bufp
,
1994 bfd_size_type
*sizep
)
1996 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1997 struct dwarf2_section_info
*info
;
1999 /* We may see an objfile without any DWARF, in which case we just
2001 if (per_objfile
== NULL
)
2010 case DWARF2_DEBUG_FRAME
:
2011 info
= &per_objfile
->per_bfd
->frame
;
2013 case DWARF2_EH_FRAME
:
2014 info
= &per_objfile
->per_bfd
->eh_frame
;
2017 gdb_assert_not_reached ("unexpected section");
2020 info
->read (objfile
);
2022 *sectp
= info
->get_bfd_section ();
2023 *bufp
= info
->buffer
;
2024 *sizep
= info
->size
;
2028 /* DWARF quick_symbol_functions support. */
2030 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2031 unique line tables, so we maintain a separate table of all .debug_line
2032 derived entries to support the sharing.
2033 All the quick functions need is the list of file names. We discard the
2034 line_header when we're done and don't need to record it here. */
2035 struct quick_file_names
2037 /* The data used to construct the hash key. */
2038 struct stmt_list_hash hash
;
2040 /* The number of entries in file_names, real_names. */
2041 unsigned int num_file_names
;
2043 /* The CU directory, as given by DW_AT_comp_dir. May be
2045 const char *comp_dir
;
2047 /* The file names from the line table, after being run through
2049 const char **file_names
;
2051 /* The file names from the line table after being run through
2052 gdb_realpath. These are computed lazily. */
2053 const char **real_names
;
2056 /* When using the index (and thus not using psymtabs), each CU has an
2057 object of this type. This is used to hold information needed by
2058 the various "quick" methods. */
2059 struct dwarf2_per_cu_quick_data
2061 /* The file table. This can be NULL if there was no file table
2062 or it's currently not read in.
2063 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2064 struct quick_file_names
*file_names
;
2066 /* A temporary mark bit used when iterating over all CUs in
2067 expand_symtabs_matching. */
2068 unsigned int mark
: 1;
2070 /* True if we've tried to read the file table. There will be no
2071 point in trying to read it again next time. */
2072 bool files_read
: 1;
2075 /* A subclass of psymbol_functions that arranges to read the DWARF
2076 partial symbols when needed. */
2077 struct lazy_dwarf_reader
: public psymbol_functions
2079 using psymbol_functions::psymbol_functions
;
2081 bool can_lazily_read_symbols () override
2086 void read_partial_symbols (struct objfile
*objfile
) override
2088 if (dwarf2_has_info (objfile
, nullptr))
2089 dwarf2_build_psymtabs (objfile
, this);
2093 static quick_symbol_functions_up
2094 make_lazy_dwarf_reader ()
2096 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2099 struct dwarf2_base_index_functions
: public quick_symbol_functions
2101 bool has_symbols (struct objfile
*objfile
) override
;
2103 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
2105 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2107 void forget_cached_source_info (struct objfile
*objfile
) override
;
2109 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2112 bool *symbol_found_p
) override
2114 *symbol_found_p
= false;
2115 return language_unknown
;
2118 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2120 void expand_all_symtabs (struct objfile
*objfile
) override
;
2122 struct compunit_symtab
*find_pc_sect_compunit_symtab
2123 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2124 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2126 struct compunit_symtab
*find_compunit_symtab_by_address
2127 (struct objfile
*objfile
, CORE_ADDR address
) override
2132 void map_symbol_filenames (struct objfile
*objfile
,
2133 gdb::function_view
<symbol_filename_ftype
> fun
,
2134 bool need_fullname
) override
;
2137 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2139 void dump (struct objfile
*objfile
) override
;
2141 void expand_matching_symbols
2143 const lookup_name_info
&lookup_name
,
2146 symbol_compare_ftype
*ordered_compare
) override
;
2148 bool expand_symtabs_matching
2149 (struct objfile
*objfile
,
2150 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2151 const lookup_name_info
*lookup_name
,
2152 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2153 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2154 block_search_flags search_flags
,
2156 enum search_domain kind
) override
;
2159 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2161 void dump (struct objfile
*objfile
) override
;
2163 void expand_matching_symbols
2165 const lookup_name_info
&lookup_name
,
2168 symbol_compare_ftype
*ordered_compare
) override
;
2170 bool expand_symtabs_matching
2171 (struct objfile
*objfile
,
2172 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2173 const lookup_name_info
*lookup_name
,
2174 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2175 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2176 block_search_flags search_flags
,
2178 enum search_domain kind
) override
;
2181 static quick_symbol_functions_up
2182 make_dwarf_gdb_index ()
2184 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2187 static quick_symbol_functions_up
2188 make_dwarf_debug_names ()
2190 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2193 /* Utility hash function for a stmt_list_hash. */
2196 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2200 if (stmt_list_hash
->dwo_unit
!= NULL
)
2201 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2202 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2206 /* Utility equality function for a stmt_list_hash. */
2209 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2210 const struct stmt_list_hash
*rhs
)
2212 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2214 if (lhs
->dwo_unit
!= NULL
2215 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2218 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2221 /* Hash function for a quick_file_names. */
2224 hash_file_name_entry (const void *e
)
2226 const struct quick_file_names
*file_data
2227 = (const struct quick_file_names
*) e
;
2229 return hash_stmt_list_entry (&file_data
->hash
);
2232 /* Equality function for a quick_file_names. */
2235 eq_file_name_entry (const void *a
, const void *b
)
2237 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2238 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2240 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2243 /* Create a quick_file_names hash table. */
2246 create_quick_file_names_table (unsigned int nr_initial_entries
)
2248 return htab_up (htab_create_alloc (nr_initial_entries
,
2249 hash_file_name_entry
, eq_file_name_entry
,
2250 nullptr, xcalloc
, xfree
));
2253 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2254 function is unrelated to symtabs, symtab would have to be created afterwards.
2255 You should call age_cached_comp_units after processing the CU. */
2258 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2261 if (per_cu
->is_debug_types
)
2262 load_full_type_unit (per_cu
, per_objfile
);
2264 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2265 skip_partial
, language_minimal
);
2267 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2269 return nullptr; /* Dummy CU. */
2271 dwarf2_find_base_address (cu
->dies
, cu
);
2276 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2279 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2280 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2282 /* Skip type_unit_groups, reading the type units they contain
2283 is handled elsewhere. */
2284 if (per_cu
->type_unit_group_p ())
2288 /* The destructor of dwarf2_queue_guard frees any entries left on
2289 the queue. After this point we're guaranteed to leave this function
2290 with the dwarf queue empty. */
2291 dwarf2_queue_guard
q_guard (per_objfile
);
2293 if (!per_objfile
->symtab_set_p (per_cu
))
2295 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2296 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2298 /* If we just loaded a CU from a DWO, and we're working with an index
2299 that may badly handle TUs, load all the TUs in that DWO as well.
2300 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2301 if (!per_cu
->is_debug_types
2303 && cu
->dwo_unit
!= NULL
2304 && per_objfile
->per_bfd
->index_table
!= NULL
2305 && per_objfile
->per_bfd
->index_table
->version
<= 7
2306 /* DWP files aren't supported yet. */
2307 && get_dwp_file (per_objfile
) == NULL
)
2308 queue_and_load_all_dwo_tus (cu
);
2311 process_queue (per_objfile
);
2314 /* Age the cache, releasing compilation units that have not
2315 been used recently. */
2316 per_objfile
->age_comp_units ();
2319 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2320 the per-objfile for which this symtab is instantiated.
2322 Returns the resulting symbol table. */
2324 static struct compunit_symtab
*
2325 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2326 dwarf2_per_objfile
*per_objfile
,
2329 gdb_assert (per_objfile
->per_bfd
->using_index
);
2331 if (!per_objfile
->symtab_set_p (per_cu
))
2333 free_cached_comp_units
freer (per_objfile
);
2334 scoped_restore decrementer
= increment_reading_symtab ();
2335 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2336 process_cu_includes (per_objfile
);
2339 return per_objfile
->get_symtab (per_cu
);
2344 dwarf2_per_cu_data_up
2345 dwarf2_per_bfd::allocate_per_cu ()
2347 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2348 result
->per_bfd
= this;
2349 result
->index
= all_comp_units
.size ();
2356 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2358 signatured_type_up
result (new signatured_type (signature
));
2359 result
->per_bfd
= this;
2360 result
->index
= all_comp_units
.size ();
2361 result
->is_debug_types
= true;
2366 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2367 obstack, and constructed with the specified field values. */
2369 static dwarf2_per_cu_data_up
2370 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2371 struct dwarf2_section_info
*section
,
2373 sect_offset sect_off
, ULONGEST length
)
2375 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2376 the_cu
->sect_off
= sect_off
;
2377 the_cu
->length
= length
;
2378 the_cu
->section
= section
;
2379 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2380 struct dwarf2_per_cu_quick_data
);
2381 the_cu
->is_dwz
= is_dwz
;
2385 /* A helper for create_cus_from_index that handles a given list of
2389 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2390 const gdb_byte
*cu_list
, offset_type n_elements
,
2391 struct dwarf2_section_info
*section
,
2394 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2396 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2398 sect_offset sect_off
2399 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2400 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2403 dwarf2_per_cu_data_up per_cu
2404 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2406 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2410 /* Read the CU list from the mapped index, and use it to create all
2411 the CU objects for PER_BFD. */
2414 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2415 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2416 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2418 gdb_assert (per_bfd
->all_comp_units
.empty ());
2419 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2421 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2424 if (dwz_elements
== 0)
2427 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2428 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2432 /* Create the signatured type hash table from the index. */
2435 create_signatured_type_table_from_index
2436 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2437 const gdb_byte
*bytes
, offset_type elements
)
2439 htab_up sig_types_hash
= allocate_signatured_type_table ();
2441 for (offset_type i
= 0; i
< elements
; i
+= 3)
2443 signatured_type_up sig_type
;
2446 cu_offset type_offset_in_tu
;
2448 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2449 sect_offset sect_off
2450 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2452 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2454 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2457 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2458 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2459 sig_type
->section
= section
;
2460 sig_type
->sect_off
= sect_off
;
2462 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2463 struct dwarf2_per_cu_quick_data
);
2465 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2466 *slot
= sig_type
.get ();
2468 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2471 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2474 /* Create the signatured type hash table from .debug_names. */
2477 create_signatured_type_table_from_debug_names
2478 (dwarf2_per_objfile
*per_objfile
,
2479 const mapped_debug_names
&map
,
2480 struct dwarf2_section_info
*section
,
2481 struct dwarf2_section_info
*abbrev_section
)
2483 struct objfile
*objfile
= per_objfile
->objfile
;
2485 section
->read (objfile
);
2486 abbrev_section
->read (objfile
);
2488 htab_up sig_types_hash
= allocate_signatured_type_table ();
2490 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2492 signatured_type_up sig_type
;
2495 sect_offset sect_off
2496 = (sect_offset
) (extract_unsigned_integer
2497 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2499 map
.dwarf5_byte_order
));
2501 comp_unit_head cu_header
;
2502 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2504 section
->buffer
+ to_underlying (sect_off
),
2507 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2508 (cu_header
.signature
);
2509 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2510 sig_type
->section
= section
;
2511 sig_type
->sect_off
= sect_off
;
2513 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2514 struct dwarf2_per_cu_quick_data
);
2516 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2517 *slot
= sig_type
.get ();
2519 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2522 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2525 /* Read the address map data from the mapped index, and use it to
2526 populate the psymtabs_addrmap. */
2529 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2530 struct mapped_index
*index
)
2532 struct objfile
*objfile
= per_objfile
->objfile
;
2533 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2534 struct gdbarch
*gdbarch
= objfile
->arch ();
2535 const gdb_byte
*iter
, *end
;
2536 struct addrmap
*mutable_map
;
2539 auto_obstack temp_obstack
;
2541 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2543 iter
= index
->address_table
.data ();
2544 end
= iter
+ index
->address_table
.size ();
2546 baseaddr
= objfile
->text_section_offset ();
2550 ULONGEST hi
, lo
, cu_index
;
2551 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2553 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2555 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2560 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2561 hex_string (lo
), hex_string (hi
));
2565 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2567 complaint (_(".gdb_index address table has invalid CU number %u"),
2568 (unsigned) cu_index
);
2572 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2573 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2574 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2575 per_bfd
->get_cu (cu_index
));
2578 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2582 /* Read the address map data from DWARF-5 .debug_aranges, and use it
2583 to populate given addrmap. Returns true on success, false on
2587 read_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2588 struct dwarf2_section_info
*section
,
2589 addrmap
*mutable_map
)
2591 struct objfile
*objfile
= per_objfile
->objfile
;
2592 bfd
*abfd
= objfile
->obfd
;
2593 struct gdbarch
*gdbarch
= objfile
->arch ();
2594 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2595 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2597 std::unordered_map
<sect_offset
,
2598 dwarf2_per_cu_data
*,
2599 gdb::hash_enum
<sect_offset
>>
2600 debug_info_offset_to_per_cu
;
2601 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2603 /* A TU will not need aranges, and skipping them here is an easy
2604 way of ignoring .debug_types -- and possibly seeing a
2605 duplicate section offset -- entirely. The same applies to
2606 units coming from a dwz file. */
2607 if (per_cu
->is_debug_types
|| per_cu
->is_dwz
)
2610 const auto insertpair
2611 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2613 if (!insertpair
.second
)
2615 warning (_("Section .debug_aranges in %s has duplicate "
2616 "debug_info_offset %s, ignoring .debug_aranges."),
2617 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2622 section
->read (objfile
);
2624 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2626 const gdb_byte
*addr
= section
->buffer
;
2628 while (addr
< section
->buffer
+ section
->size
)
2630 const gdb_byte
*const entry_addr
= addr
;
2631 unsigned int bytes_read
;
2633 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2637 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2638 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2639 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2640 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2642 warning (_("Section .debug_aranges in %s entry at offset %s "
2643 "length %s exceeds section length %s, "
2644 "ignoring .debug_aranges."),
2645 objfile_name (objfile
),
2646 plongest (entry_addr
- section
->buffer
),
2647 plongest (bytes_read
+ entry_length
),
2648 pulongest (section
->size
));
2652 /* The version number. */
2653 const uint16_t version
= read_2_bytes (abfd
, addr
);
2657 warning (_("Section .debug_aranges in %s entry at offset %s "
2658 "has unsupported version %d, ignoring .debug_aranges."),
2659 objfile_name (objfile
),
2660 plongest (entry_addr
- section
->buffer
), version
);
2664 const uint64_t debug_info_offset
2665 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2666 addr
+= offset_size
;
2667 const auto per_cu_it
2668 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2669 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2671 warning (_("Section .debug_aranges in %s entry at offset %s "
2672 "debug_info_offset %s does not exists, "
2673 "ignoring .debug_aranges."),
2674 objfile_name (objfile
),
2675 plongest (entry_addr
- section
->buffer
),
2676 pulongest (debug_info_offset
));
2679 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2681 const uint8_t address_size
= *addr
++;
2682 if (address_size
< 1 || address_size
> 8)
2684 warning (_("Section .debug_aranges in %s entry at offset %s "
2685 "address_size %u is invalid, ignoring .debug_aranges."),
2686 objfile_name (objfile
),
2687 plongest (entry_addr
- section
->buffer
), address_size
);
2691 const uint8_t segment_selector_size
= *addr
++;
2692 if (segment_selector_size
!= 0)
2694 warning (_("Section .debug_aranges in %s entry at offset %s "
2695 "segment_selector_size %u is not supported, "
2696 "ignoring .debug_aranges."),
2697 objfile_name (objfile
),
2698 plongest (entry_addr
- section
->buffer
),
2699 segment_selector_size
);
2703 /* Must pad to an alignment boundary that is twice the address
2704 size. It is undocumented by the DWARF standard but GCC does
2705 use it. However, not every compiler does this. We can see
2706 whether it has happened by looking at the total length of the
2707 contents of the aranges for this CU -- it if isn't a multiple
2708 of twice the address size, then we skip any leftover
2710 addr
+= (entry_end
- addr
) % (2 * address_size
);
2714 if (addr
+ 2 * address_size
> entry_end
)
2716 warning (_("Section .debug_aranges in %s entry at offset %s "
2717 "address list is not properly terminated, "
2718 "ignoring .debug_aranges."),
2719 objfile_name (objfile
),
2720 plongest (entry_addr
- section
->buffer
));
2723 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2725 addr
+= address_size
;
2726 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2728 addr
+= address_size
;
2729 if (start
== 0 && length
== 0)
2731 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2733 /* Symbol was eliminated due to a COMDAT group. */
2736 ULONGEST end
= start
+ length
;
2737 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2739 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2741 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2744 per_cu
->addresses_seen
= true;
2750 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2751 populate the psymtabs_addrmap. */
2754 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2755 struct dwarf2_section_info
*section
)
2757 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2759 auto_obstack temp_obstack
;
2760 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2762 if (read_addrmap_from_aranges (per_objfile
, section
, mutable_map
))
2763 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2767 /* A helper function that reads the .gdb_index from BUFFER and fills
2768 in MAP. FILENAME is the name of the file containing the data;
2769 it is used for error reporting. DEPRECATED_OK is true if it is
2770 ok to use deprecated sections.
2772 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2773 out parameters that are filled in with information about the CU and
2774 TU lists in the section.
2776 Returns true if all went well, false otherwise. */
2779 read_gdb_index_from_buffer (const char *filename
,
2781 gdb::array_view
<const gdb_byte
> buffer
,
2782 struct mapped_index
*map
,
2783 const gdb_byte
**cu_list
,
2784 offset_type
*cu_list_elements
,
2785 const gdb_byte
**types_list
,
2786 offset_type
*types_list_elements
)
2788 const gdb_byte
*addr
= &buffer
[0];
2789 offset_view
metadata (buffer
);
2791 /* Version check. */
2792 offset_type version
= metadata
[0];
2793 /* Versions earlier than 3 emitted every copy of a psymbol. This
2794 causes the index to behave very poorly for certain requests. Version 3
2795 contained incomplete addrmap. So, it seems better to just ignore such
2799 static int warning_printed
= 0;
2800 if (!warning_printed
)
2802 warning (_("Skipping obsolete .gdb_index section in %s."),
2804 warning_printed
= 1;
2808 /* Index version 4 uses a different hash function than index version
2811 Versions earlier than 6 did not emit psymbols for inlined
2812 functions. Using these files will cause GDB not to be able to
2813 set breakpoints on inlined functions by name, so we ignore these
2814 indices unless the user has done
2815 "set use-deprecated-index-sections on". */
2816 if (version
< 6 && !deprecated_ok
)
2818 static int warning_printed
= 0;
2819 if (!warning_printed
)
2822 Skipping deprecated .gdb_index section in %s.\n\
2823 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2824 to use the section anyway."),
2826 warning_printed
= 1;
2830 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2831 of the TU (for symbols coming from TUs),
2832 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2833 Plus gold-generated indices can have duplicate entries for global symbols,
2834 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2835 These are just performance bugs, and we can't distinguish gdb-generated
2836 indices from gold-generated ones, so issue no warning here. */
2838 /* Indexes with higher version than the one supported by GDB may be no
2839 longer backward compatible. */
2843 map
->version
= version
;
2846 *cu_list
= addr
+ metadata
[i
];
2847 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2850 *types_list
= addr
+ metadata
[i
];
2851 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2854 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2855 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2857 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2860 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2861 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2863 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2867 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2869 if (map
->constant_pool
.empty () && !map
->symbol_table
.empty ())
2871 /* An empty constant pool implies that all symbol table entries are
2872 empty. Make map->symbol_table.empty () == true. */
2874 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2881 /* Callback types for dwarf2_read_gdb_index. */
2883 typedef gdb::function_view
2884 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2885 get_gdb_index_contents_ftype
;
2886 typedef gdb::function_view
2887 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2888 get_gdb_index_contents_dwz_ftype
;
2890 /* Read .gdb_index. If everything went ok, initialize the "quick"
2891 elements of all the CUs and return 1. Otherwise, return 0. */
2894 dwarf2_read_gdb_index
2895 (dwarf2_per_objfile
*per_objfile
,
2896 get_gdb_index_contents_ftype get_gdb_index_contents
,
2897 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2899 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2900 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2901 struct dwz_file
*dwz
;
2902 struct objfile
*objfile
= per_objfile
->objfile
;
2903 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2905 gdb::array_view
<const gdb_byte
> main_index_contents
2906 = get_gdb_index_contents (objfile
, per_bfd
);
2908 if (main_index_contents
.empty ())
2911 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2912 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2913 use_deprecated_index_sections
,
2914 main_index_contents
, map
.get (), &cu_list
,
2915 &cu_list_elements
, &types_list
,
2916 &types_list_elements
))
2919 /* Don't use the index if it's empty. */
2920 if (map
->symbol_table
.empty ())
2923 /* If there is a .dwz file, read it so we can get its CU list as
2925 dwz
= dwarf2_get_dwz_file (per_bfd
);
2928 struct mapped_index dwz_map
;
2929 const gdb_byte
*dwz_types_ignore
;
2930 offset_type dwz_types_elements_ignore
;
2932 gdb::array_view
<const gdb_byte
> dwz_index_content
2933 = get_gdb_index_contents_dwz (objfile
, dwz
);
2935 if (dwz_index_content
.empty ())
2938 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2939 1, dwz_index_content
, &dwz_map
,
2940 &dwz_list
, &dwz_list_elements
,
2942 &dwz_types_elements_ignore
))
2944 warning (_("could not read '.gdb_index' section from %s; skipping"),
2945 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2950 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2953 if (types_list_elements
)
2955 /* We can only handle a single .debug_types when we have an
2957 if (per_bfd
->types
.size () != 1)
2960 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2962 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2963 types_list_elements
);
2966 create_addrmap_from_index (per_objfile
, map
.get ());
2968 per_bfd
->index_table
= std::move (map
);
2969 per_bfd
->using_index
= 1;
2970 per_bfd
->quick_file_names_table
=
2971 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2976 /* die_reader_func for dw2_get_file_names. */
2979 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2980 struct die_info
*comp_unit_die
)
2982 struct dwarf2_cu
*cu
= reader
->cu
;
2983 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2984 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2985 struct dwarf2_per_cu_data
*lh_cu
;
2986 struct attribute
*attr
;
2988 struct quick_file_names
*qfn
;
2990 gdb_assert (! this_cu
->is_debug_types
);
2992 this_cu
->v
.quick
->files_read
= true;
2993 /* Our callers never want to match partial units -- instead they
2994 will match the enclosing full CU. */
2995 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3002 sect_offset line_offset
{};
3004 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3005 if (attr
!= nullptr && attr
->form_is_unsigned ())
3007 struct quick_file_names find_entry
;
3009 line_offset
= (sect_offset
) attr
->as_unsigned ();
3011 /* We may have already read in this line header (TU line header sharing).
3012 If we have we're done. */
3013 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3014 find_entry
.hash
.line_sect_off
= line_offset
;
3015 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3016 &find_entry
, INSERT
);
3019 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3023 lh
= dwarf_decode_line_header (line_offset
, cu
);
3026 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
3029 if (!fnd
.is_unknown ())
3031 else if (lh
== nullptr)
3034 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3035 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3036 qfn
->hash
.line_sect_off
= line_offset
;
3037 /* There may not be a DW_AT_stmt_list. */
3038 if (slot
!= nullptr)
3041 std::vector
<const char *> include_names
;
3044 for (const auto &entry
: lh
->file_names ())
3046 gdb::unique_xmalloc_ptr
<char> name_holder
;
3047 const char *include_name
=
3048 compute_include_file_name (lh
.get (), entry
, fnd
, &name_holder
);
3049 if (include_name
!= nullptr)
3051 include_name
= per_objfile
->objfile
->intern (include_name
);
3052 include_names
.push_back (include_name
);
3057 qfn
->num_file_names
= offset
+ include_names
.size ();
3058 qfn
->comp_dir
= fnd
.intern_comp_dir (per_objfile
->objfile
);
3060 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3061 qfn
->num_file_names
);
3063 qfn
->file_names
[0] = xstrdup (fnd
.get_name ());
3065 if (!include_names
.empty ())
3066 memcpy (&qfn
->file_names
[offset
], include_names
.data (),
3067 include_names
.size () * sizeof (const char *));
3069 qfn
->real_names
= NULL
;
3071 lh_cu
->v
.quick
->file_names
= qfn
;
3074 /* A helper for the "quick" functions which attempts to read the line
3075 table for THIS_CU. */
3077 static struct quick_file_names
*
3078 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3079 dwarf2_per_objfile
*per_objfile
)
3081 /* This should never be called for TUs. */
3082 gdb_assert (! this_cu
->is_debug_types
);
3083 /* Nor type unit groups. */
3084 gdb_assert (! this_cu
->type_unit_group_p ());
3086 if (this_cu
->v
.quick
->files_read
)
3087 return this_cu
->v
.quick
->file_names
;
3089 cutu_reader
reader (this_cu
, per_objfile
);
3090 if (!reader
.dummy_p
)
3091 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3093 return this_cu
->v
.quick
->file_names
;
3096 /* A helper for the "quick" functions which computes and caches the
3097 real path for a given file name from the line table. */
3100 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3101 struct quick_file_names
*qfn
, int index
)
3103 if (qfn
->real_names
== NULL
)
3104 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3105 qfn
->num_file_names
, const char *);
3107 if (qfn
->real_names
[index
] == NULL
)
3109 const char *dirname
= nullptr;
3111 if (!IS_ABSOLUTE_PATH (qfn
->file_names
[index
]))
3112 dirname
= qfn
->comp_dir
;
3114 gdb::unique_xmalloc_ptr
<char> fullname
;
3115 fullname
= find_source_or_rewrite (qfn
->file_names
[index
], dirname
);
3117 qfn
->real_names
[index
] = fullname
.release ();
3120 return qfn
->real_names
[index
];
3124 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3126 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3127 dwarf2_per_cu_data
*dwarf_cu
3128 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3129 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3134 return cust
->primary_filetab ();
3140 dwarf2_per_cu_data::free_cached_file_names ()
3142 if (per_bfd
== nullptr || !per_bfd
->using_index
|| v
.quick
== nullptr)
3145 struct quick_file_names
*file_data
= v
.quick
->file_names
;
3146 if (file_data
!= nullptr && file_data
->real_names
!= nullptr)
3148 for (int i
= 0; i
< file_data
->num_file_names
; ++i
)
3150 xfree ((void *) file_data
->real_names
[i
]);
3151 file_data
->real_names
[i
] = nullptr;
3157 dwarf2_base_index_functions::forget_cached_source_info
3158 (struct objfile
*objfile
)
3160 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3162 for (auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3163 per_cu
->free_cached_file_names ();
3166 /* Struct used to manage iterating over all CUs looking for a symbol. */
3168 struct dw2_symtab_iterator
3170 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3171 dwarf2_per_objfile
*per_objfile
;
3172 /* If set, only look for symbols that match that block. Valid values are
3173 GLOBAL_BLOCK and STATIC_BLOCK. */
3174 gdb::optional
<block_enum
> block_index
;
3175 /* The kind of symbol we're looking for. */
3177 /* The list of CUs from the index entry of the symbol,
3178 or NULL if not found. */
3180 /* The next element in VEC to look at. */
3182 /* The number of elements in VEC, or zero if there is no match. */
3184 /* Have we seen a global version of the symbol?
3185 If so we can ignore all further global instances.
3186 This is to work around gold/15646, inefficient gold-generated
3191 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3194 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3195 dwarf2_per_objfile
*per_objfile
,
3196 gdb::optional
<block_enum
> block_index
,
3197 domain_enum domain
, offset_type namei
)
3199 iter
->per_objfile
= per_objfile
;
3200 iter
->block_index
= block_index
;
3201 iter
->domain
= domain
;
3203 iter
->global_seen
= 0;
3207 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3208 /* index is NULL if OBJF_READNOW. */
3212 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3213 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3215 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3216 iter
->length
= iter
->vec
[0];
3219 /* Return the next matching CU or NULL if there are no more. */
3221 static struct dwarf2_per_cu_data
*
3222 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3224 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3226 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3228 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3229 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3230 gdb_index_symbol_kind symbol_kind
=
3231 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3232 /* Only check the symbol attributes if they're present.
3233 Indices prior to version 7 don't record them,
3234 and indices >= 7 may elide them for certain symbols
3235 (gold does this). */
3237 (per_objfile
->per_bfd
->index_table
->version
>= 7
3238 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3240 /* Don't crash on bad data. */
3241 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3243 complaint (_(".gdb_index entry has bad CU index"
3244 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3248 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3250 /* Skip if already read in. */
3251 if (per_objfile
->symtab_set_p (per_cu
))
3254 /* Check static vs global. */
3257 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3259 if (iter
->block_index
.has_value ())
3261 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3263 if (is_static
!= want_static
)
3267 /* Work around gold/15646. */
3269 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3271 if (iter
->global_seen
)
3274 iter
->global_seen
= 1;
3278 /* Only check the symbol's kind if it has one. */
3281 switch (iter
->domain
)
3284 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3285 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3286 /* Some types are also in VAR_DOMAIN. */
3287 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3291 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3295 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3299 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3315 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3321 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3322 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3325 for (int i
= 0; i
< total
; ++i
)
3327 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3329 if (!per_objfile
->symtab_set_p (per_cu
))
3332 gdb_printf (_(" Number of read CUs: %d\n"), total
- count
);
3333 gdb_printf (_(" Number of unread CUs: %d\n"), count
);
3336 /* This dumps minimal information about the index.
3337 It is called via "mt print objfiles".
3338 One use is to verify .gdb_index has been loaded by the
3339 gdb.dwarf2/gdb-index.exp testcase. */
3342 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3344 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3346 gdb_assert (per_objfile
->per_bfd
->using_index
);
3347 gdb_printf (".gdb_index:");
3348 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3350 gdb_printf (" version %d\n",
3351 per_objfile
->per_bfd
->index_table
->version
);
3354 gdb_printf (" faked for \"readnow\"\n");
3359 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3361 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3362 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3364 for (int i
= 0; i
< total_units
; ++i
)
3366 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3368 /* We don't want to directly expand a partial CU, because if we
3369 read it with the wrong language, then assertion failures can
3370 be triggered later on. See PR symtab/23010. So, tell
3371 dw2_instantiate_symtab to skip partial CUs -- any important
3372 partial CU will be read via DW_TAG_imported_unit anyway. */
3373 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3378 dw2_expand_symtabs_matching_symbol
3379 (mapped_index_base
&index
,
3380 const lookup_name_info
&lookup_name_in
,
3381 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3382 gdb::function_view
<bool (offset_type
)> match_callback
,
3383 dwarf2_per_objfile
*per_objfile
);
3386 dw2_expand_symtabs_matching_one
3387 (dwarf2_per_cu_data
*per_cu
,
3388 dwarf2_per_objfile
*per_objfile
,
3389 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3390 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3393 dwarf2_gdb_index::expand_matching_symbols
3394 (struct objfile
*objfile
,
3395 const lookup_name_info
&name
, domain_enum domain
,
3397 symbol_compare_ftype
*ordered_compare
)
3400 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3402 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3404 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3406 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3408 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3409 auto matcher
= [&] (const char *symname
)
3411 if (ordered_compare
== nullptr)
3413 return ordered_compare (symname
, match_name
) == 0;
3416 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3417 [&] (offset_type namei
)
3419 struct dw2_symtab_iterator iter
;
3420 struct dwarf2_per_cu_data
*per_cu
;
3422 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3424 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3425 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3432 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3433 proceed assuming all symtabs have been read in. */
3437 /* Starting from a search name, return the string that finds the upper
3438 bound of all strings that start with SEARCH_NAME in a sorted name
3439 list. Returns the empty string to indicate that the upper bound is
3440 the end of the list. */
3443 make_sort_after_prefix_name (const char *search_name
)
3445 /* When looking to complete "func", we find the upper bound of all
3446 symbols that start with "func" by looking for where we'd insert
3447 the closest string that would follow "func" in lexicographical
3448 order. Usually, that's "func"-with-last-character-incremented,
3449 i.e. "fund". Mind non-ASCII characters, though. Usually those
3450 will be UTF-8 multi-byte sequences, but we can't be certain.
3451 Especially mind the 0xff character, which is a valid character in
3452 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3453 rule out compilers allowing it in identifiers. Note that
3454 conveniently, strcmp/strcasecmp are specified to compare
3455 characters interpreted as unsigned char. So what we do is treat
3456 the whole string as a base 256 number composed of a sequence of
3457 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3458 to 0, and carries 1 to the following more-significant position.
3459 If the very first character in SEARCH_NAME ends up incremented
3460 and carries/overflows, then the upper bound is the end of the
3461 list. The string after the empty string is also the empty
3464 Some examples of this operation:
3466 SEARCH_NAME => "+1" RESULT
3470 "\xff" "a" "\xff" => "\xff" "b"
3475 Then, with these symbols for example:
3481 completing "func" looks for symbols between "func" and
3482 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3483 which finds "func" and "func1", but not "fund".
3487 funcÿ (Latin1 'ÿ' [0xff])
3491 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3492 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3496 ÿÿ (Latin1 'ÿ' [0xff])
3499 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3500 the end of the list.
3502 std::string after
= search_name
;
3503 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3505 if (!after
.empty ())
3506 after
.back () = (unsigned char) after
.back () + 1;
3510 /* See declaration. */
3512 std::pair
<std::vector
<name_component
>::const_iterator
,
3513 std::vector
<name_component
>::const_iterator
>
3514 mapped_index_base::find_name_components_bounds
3515 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3516 dwarf2_per_objfile
*per_objfile
) const
3519 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3521 const char *lang_name
3522 = lookup_name_without_params
.language_lookup_name (lang
);
3524 /* Comparison function object for lower_bound that matches against a
3525 given symbol name. */
3526 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3529 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3530 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3531 return name_cmp (elem_name
, name
) < 0;
3534 /* Comparison function object for upper_bound that matches against a
3535 given symbol name. */
3536 auto lookup_compare_upper
= [&] (const char *name
,
3537 const name_component
&elem
)
3539 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3540 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3541 return name_cmp (name
, elem_name
) < 0;
3544 auto begin
= this->name_components
.begin ();
3545 auto end
= this->name_components
.end ();
3547 /* Find the lower bound. */
3550 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3553 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3556 /* Find the upper bound. */
3559 if (lookup_name_without_params
.completion_mode ())
3561 /* In completion mode, we want UPPER to point past all
3562 symbols names that have the same prefix. I.e., with
3563 these symbols, and completing "func":
3565 function << lower bound
3567 other_function << upper bound
3569 We find the upper bound by looking for the insertion
3570 point of "func"-with-last-character-incremented,
3572 std::string after
= make_sort_after_prefix_name (lang_name
);
3575 return std::lower_bound (lower
, end
, after
.c_str (),
3576 lookup_compare_lower
);
3579 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3582 return {lower
, upper
};
3585 /* See declaration. */
3588 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3590 if (!this->name_components
.empty ())
3593 this->name_components_casing
= case_sensitivity
;
3595 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3597 /* The code below only knows how to break apart components of C++
3598 symbol names (and other languages that use '::' as
3599 namespace/module separator) and Ada symbol names. */
3600 auto count
= this->symbol_name_count ();
3601 for (offset_type idx
= 0; idx
< count
; idx
++)
3603 if (this->symbol_name_slot_invalid (idx
))
3606 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3608 /* Add each name component to the name component table. */
3609 unsigned int previous_len
= 0;
3611 if (strstr (name
, "::") != nullptr)
3613 for (unsigned int current_len
= cp_find_first_component (name
);
3614 name
[current_len
] != '\0';
3615 current_len
+= cp_find_first_component (name
+ current_len
))
3617 gdb_assert (name
[current_len
] == ':');
3618 this->name_components
.push_back ({previous_len
, idx
});
3619 /* Skip the '::'. */
3621 previous_len
= current_len
;
3626 /* Handle the Ada encoded (aka mangled) form here. */
3627 for (const char *iter
= strstr (name
, "__");
3629 iter
= strstr (iter
, "__"))
3631 this->name_components
.push_back ({previous_len
, idx
});
3633 previous_len
= iter
- name
;
3637 this->name_components
.push_back ({previous_len
, idx
});
3640 /* Sort name_components elements by name. */
3641 auto name_comp_compare
= [&] (const name_component
&left
,
3642 const name_component
&right
)
3644 const char *left_qualified
3645 = this->symbol_name_at (left
.idx
, per_objfile
);
3646 const char *right_qualified
3647 = this->symbol_name_at (right
.idx
, per_objfile
);
3649 const char *left_name
= left_qualified
+ left
.name_offset
;
3650 const char *right_name
= right_qualified
+ right
.name_offset
;
3652 return name_cmp (left_name
, right_name
) < 0;
3655 std::sort (this->name_components
.begin (),
3656 this->name_components
.end (),
3660 /* Helper for dw2_expand_symtabs_matching that works with a
3661 mapped_index_base instead of the containing objfile. This is split
3662 to a separate function in order to be able to unit test the
3663 name_components matching using a mock mapped_index_base. For each
3664 symbol name that matches, calls MATCH_CALLBACK, passing it the
3665 symbol's index in the mapped_index_base symbol table. */
3668 dw2_expand_symtabs_matching_symbol
3669 (mapped_index_base
&index
,
3670 const lookup_name_info
&lookup_name_in
,
3671 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3672 gdb::function_view
<bool (offset_type
)> match_callback
,
3673 dwarf2_per_objfile
*per_objfile
)
3675 lookup_name_info lookup_name_without_params
3676 = lookup_name_in
.make_ignore_params ();
3678 /* Build the symbol name component sorted vector, if we haven't
3680 index
.build_name_components (per_objfile
);
3682 /* The same symbol may appear more than once in the range though.
3683 E.g., if we're looking for symbols that complete "w", and we have
3684 a symbol named "w1::w2", we'll find the two name components for
3685 that same symbol in the range. To be sure we only call the
3686 callback once per symbol, we first collect the symbol name
3687 indexes that matched in a temporary vector and ignore
3689 std::vector
<offset_type
> matches
;
3691 struct name_and_matcher
3693 symbol_name_matcher_ftype
*matcher
;
3696 bool operator== (const name_and_matcher
&other
) const
3698 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3702 /* A vector holding all the different symbol name matchers, for all
3704 std::vector
<name_and_matcher
> matchers
;
3706 for (int i
= 0; i
< nr_languages
; i
++)
3708 enum language lang_e
= (enum language
) i
;
3710 const language_defn
*lang
= language_def (lang_e
);
3711 symbol_name_matcher_ftype
*name_matcher
3712 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3714 name_and_matcher key
{
3716 lookup_name_without_params
.language_lookup_name (lang_e
)
3719 /* Don't insert the same comparison routine more than once.
3720 Note that we do this linear walk. This is not a problem in
3721 practice because the number of supported languages is
3723 if (std::find (matchers
.begin (), matchers
.end (), key
)
3726 matchers
.push_back (std::move (key
));
3729 = index
.find_name_components_bounds (lookup_name_without_params
,
3730 lang_e
, per_objfile
);
3732 /* Now for each symbol name in range, check to see if we have a name
3733 match, and if so, call the MATCH_CALLBACK callback. */
3735 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3737 const char *qualified
3738 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3740 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3741 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3744 matches
.push_back (bounds
.first
->idx
);
3748 std::sort (matches
.begin (), matches
.end ());
3750 /* Finally call the callback, once per match. */
3753 for (offset_type idx
: matches
)
3757 if (!match_callback (idx
))
3766 /* Above we use a type wider than idx's for 'prev', since 0 and
3767 (offset_type)-1 are both possible values. */
3768 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3775 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3777 /* A mock .gdb_index/.debug_names-like name index table, enough to
3778 exercise dw2_expand_symtabs_matching_symbol, which works with the
3779 mapped_index_base interface. Builds an index from the symbol list
3780 passed as parameter to the constructor. */
3781 class mock_mapped_index
: public mapped_index_base
3784 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3785 : m_symbol_table (symbols
)
3788 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3790 /* Return the number of names in the symbol table. */
3791 size_t symbol_name_count () const override
3793 return m_symbol_table
.size ();
3796 /* Get the name of the symbol at IDX in the symbol table. */
3797 const char *symbol_name_at
3798 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3800 return m_symbol_table
[idx
];
3804 gdb::array_view
<const char *> m_symbol_table
;
3807 /* Convenience function that converts a NULL pointer to a "<null>"
3808 string, to pass to print routines. */
3811 string_or_null (const char *str
)
3813 return str
!= NULL
? str
: "<null>";
3816 /* Check if a lookup_name_info built from
3817 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3818 index. EXPECTED_LIST is the list of expected matches, in expected
3819 matching order. If no match expected, then an empty list is
3820 specified. Returns true on success. On failure prints a warning
3821 indicating the file:line that failed, and returns false. */
3824 check_match (const char *file
, int line
,
3825 mock_mapped_index
&mock_index
,
3826 const char *name
, symbol_name_match_type match_type
,
3827 bool completion_mode
,
3828 std::initializer_list
<const char *> expected_list
,
3829 dwarf2_per_objfile
*per_objfile
)
3831 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3833 bool matched
= true;
3835 auto mismatch
= [&] (const char *expected_str
,
3838 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3839 "expected=\"%s\", got=\"%s\"\n"),
3841 (match_type
== symbol_name_match_type::FULL
3843 name
, string_or_null (expected_str
), string_or_null (got
));
3847 auto expected_it
= expected_list
.begin ();
3848 auto expected_end
= expected_list
.end ();
3850 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3852 [&] (offset_type idx
)
3854 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3855 const char *expected_str
3856 = expected_it
== expected_end
? NULL
: *expected_it
++;
3858 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3859 mismatch (expected_str
, matched_name
);
3863 const char *expected_str
3864 = expected_it
== expected_end
? NULL
: *expected_it
++;
3865 if (expected_str
!= NULL
)
3866 mismatch (expected_str
, NULL
);
3871 /* The symbols added to the mock mapped_index for testing (in
3873 static const char *test_symbols
[] = {
3882 "ns2::tmpl<int>::foo2",
3883 "(anonymous namespace)::A::B::C",
3885 /* These are used to check that the increment-last-char in the
3886 matching algorithm for completion doesn't match "t1_fund" when
3887 completing "t1_func". */
3893 /* A UTF-8 name with multi-byte sequences to make sure that
3894 cp-name-parser understands this as a single identifier ("função"
3895 is "function" in PT). */
3898 /* \377 (0xff) is Latin1 'ÿ'. */
3901 /* \377 (0xff) is Latin1 'ÿ'. */
3905 /* A name with all sorts of complications. Starts with "z" to make
3906 it easier for the completion tests below. */
3907 #define Z_SYM_NAME \
3908 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3909 "::tuple<(anonymous namespace)::ui*, " \
3910 "std::default_delete<(anonymous namespace)::ui>, void>"
3915 /* Returns true if the mapped_index_base::find_name_component_bounds
3916 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3917 in completion mode. */
3920 check_find_bounds_finds (mapped_index_base
&index
,
3921 const char *search_name
,
3922 gdb::array_view
<const char *> expected_syms
,
3923 dwarf2_per_objfile
*per_objfile
)
3925 lookup_name_info
lookup_name (search_name
,
3926 symbol_name_match_type::FULL
, true);
3928 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3932 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3933 if (distance
!= expected_syms
.size ())
3936 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3938 auto nc_elem
= bounds
.first
+ exp_elem
;
3939 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3940 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3947 /* Test the lower-level mapped_index::find_name_component_bounds
3951 test_mapped_index_find_name_component_bounds ()
3953 mock_mapped_index
mock_index (test_symbols
);
3955 mock_index
.build_name_components (NULL
/* per_objfile */);
3957 /* Test the lower-level mapped_index::find_name_component_bounds
3958 method in completion mode. */
3960 static const char *expected_syms
[] = {
3965 SELF_CHECK (check_find_bounds_finds
3966 (mock_index
, "t1_func", expected_syms
,
3967 NULL
/* per_objfile */));
3970 /* Check that the increment-last-char in the name matching algorithm
3971 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3973 static const char *expected_syms1
[] = {
3977 SELF_CHECK (check_find_bounds_finds
3978 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3980 static const char *expected_syms2
[] = {
3983 SELF_CHECK (check_find_bounds_finds
3984 (mock_index
, "\377\377", expected_syms2
,
3985 NULL
/* per_objfile */));
3989 /* Test dw2_expand_symtabs_matching_symbol. */
3992 test_dw2_expand_symtabs_matching_symbol ()
3994 mock_mapped_index
mock_index (test_symbols
);
3996 /* We let all tests run until the end even if some fails, for debug
3998 bool any_mismatch
= false;
4000 /* Create the expected symbols list (an initializer_list). Needed
4001 because lists have commas, and we need to pass them to CHECK,
4002 which is a macro. */
4003 #define EXPECT(...) { __VA_ARGS__ }
4005 /* Wrapper for check_match that passes down the current
4006 __FILE__/__LINE__. */
4007 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4008 any_mismatch |= !check_match (__FILE__, __LINE__, \
4010 NAME, MATCH_TYPE, COMPLETION_MODE, \
4011 EXPECTED_LIST, NULL)
4013 /* Identity checks. */
4014 for (const char *sym
: test_symbols
)
4016 /* Should be able to match all existing symbols. */
4017 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4020 /* Should be able to match all existing symbols with
4022 std::string with_params
= std::string (sym
) + "(int)";
4023 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4026 /* Should be able to match all existing symbols with
4027 parameters and qualifiers. */
4028 with_params
= std::string (sym
) + " ( int ) const";
4029 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4032 /* This should really find sym, but cp-name-parser.y doesn't
4033 know about lvalue/rvalue qualifiers yet. */
4034 with_params
= std::string (sym
) + " ( int ) &&";
4035 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4039 /* Check that the name matching algorithm for completion doesn't get
4040 confused with Latin1 'ÿ' / 0xff. */
4042 static const char str
[] = "\377";
4043 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4044 EXPECT ("\377", "\377\377123"));
4047 /* Check that the increment-last-char in the matching algorithm for
4048 completion doesn't match "t1_fund" when completing "t1_func". */
4050 static const char str
[] = "t1_func";
4051 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4052 EXPECT ("t1_func", "t1_func1"));
4055 /* Check that completion mode works at each prefix of the expected
4058 static const char str
[] = "function(int)";
4059 size_t len
= strlen (str
);
4062 for (size_t i
= 1; i
< len
; i
++)
4064 lookup
.assign (str
, i
);
4065 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4066 EXPECT ("function"));
4070 /* While "w" is a prefix of both components, the match function
4071 should still only be called once. */
4073 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4075 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4079 /* Same, with a "complicated" symbol. */
4081 static const char str
[] = Z_SYM_NAME
;
4082 size_t len
= strlen (str
);
4085 for (size_t i
= 1; i
< len
; i
++)
4087 lookup
.assign (str
, i
);
4088 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4089 EXPECT (Z_SYM_NAME
));
4093 /* In FULL mode, an incomplete symbol doesn't match. */
4095 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4099 /* A complete symbol with parameters matches any overload, since the
4100 index has no overload info. */
4102 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4103 EXPECT ("std::zfunction", "std::zfunction2"));
4104 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4105 EXPECT ("std::zfunction", "std::zfunction2"));
4106 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4107 EXPECT ("std::zfunction", "std::zfunction2"));
4110 /* Check that whitespace is ignored appropriately. A symbol with a
4111 template argument list. */
4113 static const char expected
[] = "ns::foo<int>";
4114 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4116 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4120 /* Check that whitespace is ignored appropriately. A symbol with a
4121 template argument list that includes a pointer. */
4123 static const char expected
[] = "ns::foo<char*>";
4124 /* Try both completion and non-completion modes. */
4125 static const bool completion_mode
[2] = {false, true};
4126 for (size_t i
= 0; i
< 2; i
++)
4128 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4129 completion_mode
[i
], EXPECT (expected
));
4130 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4131 completion_mode
[i
], EXPECT (expected
));
4133 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4134 completion_mode
[i
], EXPECT (expected
));
4135 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4136 completion_mode
[i
], EXPECT (expected
));
4141 /* Check method qualifiers are ignored. */
4142 static const char expected
[] = "ns::foo<char*>";
4143 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4144 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4145 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4146 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4147 CHECK_MATCH ("foo < char * > ( int ) const",
4148 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4149 CHECK_MATCH ("foo < char * > ( int ) &&",
4150 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4153 /* Test lookup names that don't match anything. */
4155 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4158 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4162 /* Some wild matching tests, exercising "(anonymous namespace)",
4163 which should not be confused with a parameter list. */
4165 static const char *syms
[] = {
4169 "A :: B :: C ( int )",
4174 for (const char *s
: syms
)
4176 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4177 EXPECT ("(anonymous namespace)::A::B::C"));
4182 static const char expected
[] = "ns2::tmpl<int>::foo2";
4183 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4185 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4189 SELF_CHECK (!any_mismatch
);
4198 test_mapped_index_find_name_component_bounds ();
4199 test_dw2_expand_symtabs_matching_symbol ();
4202 }} // namespace selftests::dw2_expand_symtabs_matching
4204 #endif /* GDB_SELF_TEST */
4206 /* If FILE_MATCHER is NULL or if PER_CU has
4207 dwarf2_per_cu_quick_data::MARK set (see
4208 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4209 EXPANSION_NOTIFY on it. */
4212 dw2_expand_symtabs_matching_one
4213 (dwarf2_per_cu_data
*per_cu
,
4214 dwarf2_per_objfile
*per_objfile
,
4215 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4216 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4218 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4220 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4222 compunit_symtab
*symtab
4223 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4224 gdb_assert (symtab
!= nullptr);
4226 if (expansion_notify
!= NULL
&& symtab_was_null
)
4227 return expansion_notify (symtab
);
4232 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4233 matched, to expand corresponding CUs that were marked. IDX is the
4234 index of the symbol name that matched. */
4237 dw2_expand_marked_cus
4238 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4239 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4240 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4241 block_search_flags search_flags
,
4244 offset_type vec_len
, vec_idx
;
4245 bool global_seen
= false;
4246 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4248 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4250 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4252 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4253 /* This value is only valid for index versions >= 7. */
4254 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4255 gdb_index_symbol_kind symbol_kind
=
4256 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4257 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4258 /* Only check the symbol attributes if they're present.
4259 Indices prior to version 7 don't record them,
4260 and indices >= 7 may elide them for certain symbols
4261 (gold does this). */
4264 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4266 /* Work around gold/15646. */
4269 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4277 /* Only check the symbol's kind if it has one. */
4282 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4287 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4293 case VARIABLES_DOMAIN
:
4294 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4297 case FUNCTIONS_DOMAIN
:
4298 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4302 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4305 case MODULES_DOMAIN
:
4306 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4314 /* Don't crash on bad data. */
4315 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4317 complaint (_(".gdb_index entry has bad CU index"
4318 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4322 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4323 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4331 /* If FILE_MATCHER is non-NULL, set all the
4332 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4333 that match FILE_MATCHER. */
4336 dw_expand_symtabs_matching_file_matcher
4337 (dwarf2_per_objfile
*per_objfile
,
4338 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4340 if (file_matcher
== NULL
)
4343 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4345 NULL
, xcalloc
, xfree
));
4346 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4348 NULL
, xcalloc
, xfree
));
4350 /* The rule is CUs specify all the files, including those used by
4351 any TU, so there's no need to scan TUs here. */
4353 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4357 if (per_cu
->is_debug_types
)
4359 per_cu
->v
.quick
->mark
= 0;
4361 /* We only need to look at symtabs not already expanded. */
4362 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4365 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4367 if (file_data
== NULL
)
4370 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4372 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4374 per_cu
->v
.quick
->mark
= 1;
4378 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4380 const char *this_real_name
;
4382 if (file_matcher (file_data
->file_names
[j
], false))
4384 per_cu
->v
.quick
->mark
= 1;
4388 /* Before we invoke realpath, which can get expensive when many
4389 files are involved, do a quick comparison of the basenames. */
4390 if (!basenames_may_differ
4391 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4395 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4396 if (file_matcher (this_real_name
, false))
4398 per_cu
->v
.quick
->mark
= 1;
4403 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4404 ? visited_found
.get ()
4405 : visited_not_found
.get (),
4412 dwarf2_gdb_index::expand_symtabs_matching
4413 (struct objfile
*objfile
,
4414 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4415 const lookup_name_info
*lookup_name
,
4416 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4417 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4418 block_search_flags search_flags
,
4420 enum search_domain kind
)
4422 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4424 /* index_table is NULL if OBJF_READNOW. */
4425 if (!per_objfile
->per_bfd
->index_table
)
4428 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4430 /* This invariant is documented in quick-functions.h. */
4431 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
4432 if (lookup_name
== nullptr)
4434 for (dwarf2_per_cu_data
*per_cu
4435 : all_comp_units_range (per_objfile
->per_bfd
))
4439 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4447 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4450 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4452 [&] (offset_type idx
)
4454 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4455 expansion_notify
, search_flags
, kind
))
4463 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4466 static struct compunit_symtab
*
4467 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4472 if (cust
->blockvector () != nullptr
4473 && blockvector_contains_pc (cust
->blockvector (), pc
))
4476 if (cust
->includes
== NULL
)
4479 for (i
= 0; cust
->includes
[i
]; ++i
)
4481 struct compunit_symtab
*s
= cust
->includes
[i
];
4483 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4491 struct compunit_symtab
*
4492 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4493 (struct objfile
*objfile
,
4494 struct bound_minimal_symbol msymbol
,
4496 struct obj_section
*section
,
4499 struct dwarf2_per_cu_data
*data
;
4500 struct compunit_symtab
*result
;
4502 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4503 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4506 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4507 data
= ((struct dwarf2_per_cu_data
*)
4508 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4513 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4514 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4515 paddress (objfile
->arch (), pc
));
4517 result
= recursively_find_pc_sect_compunit_symtab
4518 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4520 gdb_assert (result
!= NULL
);
4525 dwarf2_base_index_functions::map_symbol_filenames
4526 (struct objfile
*objfile
,
4527 gdb::function_view
<symbol_filename_ftype
> fun
,
4530 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4532 /* Use caches to ensure we only call FUN once for each filename. */
4533 filename_seen_cache filenames_cache
;
4534 std::unordered_set
<quick_file_names
*> qfn_cache
;
4536 /* The rule is CUs specify all the files, including those used by any TU,
4537 so there's no need to scan TUs here. We can ignore file names coming
4538 from already-expanded CUs. It is possible that an expanded CU might
4539 reuse the file names data from a currently unexpanded CU, in this
4540 case we don't want to report the files from the unexpanded CU. */
4542 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4544 if (!per_cu
->is_debug_types
4545 && per_objfile
->symtab_set_p (per_cu
.get ()))
4547 if (per_cu
->v
.quick
->file_names
!= nullptr)
4548 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4552 for (dwarf2_per_cu_data
*per_cu
4553 : all_comp_units_range (per_objfile
->per_bfd
))
4555 /* We only need to look at symtabs not already expanded. */
4556 if (per_cu
->is_debug_types
|| per_objfile
->symtab_set_p (per_cu
))
4559 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4560 if (file_data
== nullptr
4561 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4564 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4566 const char *filename
= file_data
->file_names
[j
];
4567 const char *key
= filename
;
4568 const char *fullname
= nullptr;
4572 fullname
= dw2_get_real_path (per_objfile
, file_data
, j
);
4576 if (!filenames_cache
.seen (key
))
4577 fun (filename
, fullname
);
4583 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4588 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
4591 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
4593 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4595 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4597 /* Is this already expanded? */
4598 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4601 /* It has not yet been expanded. */
4608 /* DWARF-5 debug_names reader. */
4610 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4611 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4613 /* A helper function that reads the .debug_names section in SECTION
4614 and fills in MAP. FILENAME is the name of the file containing the
4615 section; it is used for error reporting.
4617 Returns true if all went well, false otherwise. */
4620 read_debug_names_from_section (struct objfile
*objfile
,
4621 const char *filename
,
4622 struct dwarf2_section_info
*section
,
4623 mapped_debug_names
&map
)
4625 if (section
->empty ())
4628 /* Older elfutils strip versions could keep the section in the main
4629 executable while splitting it for the separate debug info file. */
4630 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4633 section
->read (objfile
);
4635 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4637 const gdb_byte
*addr
= section
->buffer
;
4639 bfd
*const abfd
= section
->get_bfd_owner ();
4641 unsigned int bytes_read
;
4642 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4645 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4646 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4647 if (bytes_read
+ length
!= section
->size
)
4649 /* There may be multiple per-CU indices. */
4650 warning (_("Section .debug_names in %s length %s does not match "
4651 "section length %s, ignoring .debug_names."),
4652 filename
, plongest (bytes_read
+ length
),
4653 pulongest (section
->size
));
4657 /* The version number. */
4658 uint16_t version
= read_2_bytes (abfd
, addr
);
4662 warning (_("Section .debug_names in %s has unsupported version %d, "
4663 "ignoring .debug_names."),
4669 uint16_t padding
= read_2_bytes (abfd
, addr
);
4673 warning (_("Section .debug_names in %s has unsupported padding %d, "
4674 "ignoring .debug_names."),
4679 /* comp_unit_count - The number of CUs in the CU list. */
4680 map
.cu_count
= read_4_bytes (abfd
, addr
);
4683 /* local_type_unit_count - The number of TUs in the local TU
4685 map
.tu_count
= read_4_bytes (abfd
, addr
);
4688 /* foreign_type_unit_count - The number of TUs in the foreign TU
4690 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4692 if (foreign_tu_count
!= 0)
4694 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4695 "ignoring .debug_names."),
4696 filename
, static_cast<unsigned long> (foreign_tu_count
));
4700 /* bucket_count - The number of hash buckets in the hash lookup
4702 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4705 /* name_count - The number of unique names in the index. */
4706 map
.name_count
= read_4_bytes (abfd
, addr
);
4709 /* abbrev_table_size - The size in bytes of the abbreviations
4711 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4714 /* augmentation_string_size - The size in bytes of the augmentation
4715 string. This value is rounded up to a multiple of 4. */
4716 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4718 map
.augmentation_is_gdb
= ((augmentation_string_size
4719 == sizeof (dwarf5_augmentation
))
4720 && memcmp (addr
, dwarf5_augmentation
,
4721 sizeof (dwarf5_augmentation
)) == 0);
4722 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4723 addr
+= augmentation_string_size
;
4726 map
.cu_table_reordered
= addr
;
4727 addr
+= map
.cu_count
* map
.offset_size
;
4729 /* List of Local TUs */
4730 map
.tu_table_reordered
= addr
;
4731 addr
+= map
.tu_count
* map
.offset_size
;
4733 /* Hash Lookup Table */
4734 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4735 addr
+= map
.bucket_count
* 4;
4736 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4737 addr
+= map
.name_count
* 4;
4740 map
.name_table_string_offs_reordered
= addr
;
4741 addr
+= map
.name_count
* map
.offset_size
;
4742 map
.name_table_entry_offs_reordered
= addr
;
4743 addr
+= map
.name_count
* map
.offset_size
;
4745 const gdb_byte
*abbrev_table_start
= addr
;
4748 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4753 const auto insertpair
4754 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4755 if (!insertpair
.second
)
4757 warning (_("Section .debug_names in %s has duplicate index %s, "
4758 "ignoring .debug_names."),
4759 filename
, pulongest (index_num
));
4762 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4763 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4768 mapped_debug_names::index_val::attr attr
;
4769 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4771 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4773 if (attr
.form
== DW_FORM_implicit_const
)
4775 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4779 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4781 indexval
.attr_vec
.push_back (std::move (attr
));
4784 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4786 warning (_("Section .debug_names in %s has abbreviation_table "
4787 "of size %s vs. written as %u, ignoring .debug_names."),
4788 filename
, plongest (addr
- abbrev_table_start
),
4792 map
.entry_pool
= addr
;
4797 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4801 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4802 const mapped_debug_names
&map
,
4803 dwarf2_section_info
§ion
,
4806 if (!map
.augmentation_is_gdb
)
4808 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4810 sect_offset sect_off
4811 = (sect_offset
) (extract_unsigned_integer
4812 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4814 map
.dwarf5_byte_order
));
4815 /* We don't know the length of the CU, because the CU list in a
4816 .debug_names index can be incomplete, so we can't use the start
4817 of the next CU as end of this CU. We create the CUs here with
4818 length 0, and in cutu_reader::cutu_reader we'll fill in the
4820 dwarf2_per_cu_data_up per_cu
4821 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4823 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4828 sect_offset sect_off_prev
;
4829 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4831 sect_offset sect_off_next
;
4832 if (i
< map
.cu_count
)
4835 = (sect_offset
) (extract_unsigned_integer
4836 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4838 map
.dwarf5_byte_order
));
4841 sect_off_next
= (sect_offset
) section
.size
;
4844 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4845 dwarf2_per_cu_data_up per_cu
4846 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4847 sect_off_prev
, length
);
4848 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4850 sect_off_prev
= sect_off_next
;
4854 /* Read the CU list from the mapped index, and use it to create all
4855 the CU objects for this dwarf2_per_objfile. */
4858 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4859 const mapped_debug_names
&map
,
4860 const mapped_debug_names
&dwz_map
)
4862 gdb_assert (per_bfd
->all_comp_units
.empty ());
4863 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4865 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4866 false /* is_dwz */);
4868 if (dwz_map
.cu_count
== 0)
4871 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4872 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4876 /* Read .debug_names. If everything went ok, initialize the "quick"
4877 elements of all the CUs and return true. Otherwise, return false. */
4880 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4882 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4883 mapped_debug_names dwz_map
;
4884 struct objfile
*objfile
= per_objfile
->objfile
;
4885 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4887 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4888 &per_bfd
->debug_names
, *map
))
4891 /* Don't use the index if it's empty. */
4892 if (map
->name_count
== 0)
4895 /* If there is a .dwz file, read it so we can get its CU list as
4897 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4900 if (!read_debug_names_from_section (objfile
,
4901 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4902 &dwz
->debug_names
, dwz_map
))
4904 warning (_("could not read '.debug_names' section from %s; skipping"),
4905 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4910 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4912 if (map
->tu_count
!= 0)
4914 /* We can only handle a single .debug_types when we have an
4916 if (per_bfd
->types
.size () != 1)
4919 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4921 create_signatured_type_table_from_debug_names
4922 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4925 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4927 per_bfd
->debug_names_table
= std::move (map
);
4928 per_bfd
->using_index
= 1;
4929 per_bfd
->quick_file_names_table
=
4930 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4935 /* Type used to manage iterating over all CUs looking for a symbol for
4938 class dw2_debug_names_iterator
4941 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4942 block_search_flags block_index
,
4944 const char *name
, dwarf2_per_objfile
*per_objfile
)
4945 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4946 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4947 m_per_objfile (per_objfile
)
4950 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4951 search_domain search
, uint32_t namei
,
4952 dwarf2_per_objfile
*per_objfile
,
4953 domain_enum domain
= UNDEF_DOMAIN
)
4957 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4958 m_per_objfile (per_objfile
)
4961 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4962 block_search_flags block_index
, domain_enum domain
,
4963 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4964 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4965 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4966 m_per_objfile (per_objfile
)
4969 /* Return the next matching CU or NULL if there are no more. */
4970 dwarf2_per_cu_data
*next ();
4973 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4975 dwarf2_per_objfile
*per_objfile
);
4976 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4978 dwarf2_per_objfile
*per_objfile
);
4980 /* The internalized form of .debug_names. */
4981 const mapped_debug_names
&m_map
;
4983 /* Restrict the search to these blocks. */
4984 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4985 | SEARCH_STATIC_BLOCK
);
4987 /* The kind of symbol we're looking for. */
4988 const domain_enum m_domain
= UNDEF_DOMAIN
;
4989 const search_domain m_search
= ALL_DOMAIN
;
4991 /* The list of CUs from the index entry of the symbol, or NULL if
4993 const gdb_byte
*m_addr
;
4995 dwarf2_per_objfile
*m_per_objfile
;
4999 mapped_debug_names::namei_to_name
5000 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5002 const ULONGEST namei_string_offs
5003 = extract_unsigned_integer ((name_table_string_offs_reordered
5004 + namei
* offset_size
),
5007 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5010 /* Find a slot in .debug_names for the object named NAME. If NAME is
5011 found, return pointer to its pool data. If NAME cannot be found,
5015 dw2_debug_names_iterator::find_vec_in_debug_names
5016 (const mapped_debug_names
&map
, const char *name
,
5017 dwarf2_per_objfile
*per_objfile
)
5019 int (*cmp
) (const char *, const char *);
5021 gdb::unique_xmalloc_ptr
<char> without_params
;
5022 if (current_language
->la_language
== language_cplus
5023 || current_language
->la_language
== language_fortran
5024 || current_language
->la_language
== language_d
)
5026 /* NAME is already canonical. Drop any qualifiers as
5027 .debug_names does not contain any. */
5029 if (strchr (name
, '(') != NULL
)
5031 without_params
= cp_remove_params (name
);
5032 if (without_params
!= NULL
)
5033 name
= without_params
.get ();
5037 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5039 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5041 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5042 (map
.bucket_table_reordered
5043 + (full_hash
% map
.bucket_count
)), 4,
5044 map
.dwarf5_byte_order
);
5048 if (namei
>= map
.name_count
)
5050 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5052 namei
, map
.name_count
,
5053 objfile_name (per_objfile
->objfile
));
5059 const uint32_t namei_full_hash
5060 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5061 (map
.hash_table_reordered
+ namei
), 4,
5062 map
.dwarf5_byte_order
);
5063 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5066 if (full_hash
== namei_full_hash
)
5068 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5070 #if 0 /* An expensive sanity check. */
5071 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5073 complaint (_("Wrong .debug_names hash for string at index %u "
5075 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5080 if (cmp (namei_string
, name
) == 0)
5082 const ULONGEST namei_entry_offs
5083 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5084 + namei
* map
.offset_size
),
5085 map
.offset_size
, map
.dwarf5_byte_order
);
5086 return map
.entry_pool
+ namei_entry_offs
;
5091 if (namei
>= map
.name_count
)
5097 dw2_debug_names_iterator::find_vec_in_debug_names
5098 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5100 if (namei
>= map
.name_count
)
5102 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5104 namei
, map
.name_count
,
5105 objfile_name (per_objfile
->objfile
));
5109 const ULONGEST namei_entry_offs
5110 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5111 + namei
* map
.offset_size
),
5112 map
.offset_size
, map
.dwarf5_byte_order
);
5113 return map
.entry_pool
+ namei_entry_offs
;
5116 /* See dw2_debug_names_iterator. */
5118 dwarf2_per_cu_data
*
5119 dw2_debug_names_iterator::next ()
5124 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5125 struct objfile
*objfile
= m_per_objfile
->objfile
;
5126 bfd
*const abfd
= objfile
->obfd
;
5130 unsigned int bytes_read
;
5131 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5132 m_addr
+= bytes_read
;
5136 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5137 if (indexval_it
== m_map
.abbrev_map
.cend ())
5139 complaint (_("Wrong .debug_names undefined abbrev code %s "
5141 pulongest (abbrev
), objfile_name (objfile
));
5144 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5145 enum class symbol_linkage
{
5149 } symbol_linkage_
= symbol_linkage::unknown
;
5150 dwarf2_per_cu_data
*per_cu
= NULL
;
5151 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5156 case DW_FORM_implicit_const
:
5157 ull
= attr
.implicit_const
;
5159 case DW_FORM_flag_present
:
5163 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5164 m_addr
+= bytes_read
;
5167 ull
= read_4_bytes (abfd
, m_addr
);
5171 ull
= read_8_bytes (abfd
, m_addr
);
5174 case DW_FORM_ref_sig8
:
5175 ull
= read_8_bytes (abfd
, m_addr
);
5179 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5180 dwarf_form_name (attr
.form
),
5181 objfile_name (objfile
));
5184 switch (attr
.dw_idx
)
5186 case DW_IDX_compile_unit
:
5187 /* Don't crash on bad data. */
5188 if (ull
>= per_bfd
->all_comp_units
.size ())
5190 complaint (_(".debug_names entry has bad CU index %s"
5193 objfile_name (objfile
));
5196 per_cu
= per_bfd
->get_cu (ull
);
5198 case DW_IDX_type_unit
:
5199 /* Don't crash on bad data. */
5200 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5202 complaint (_(".debug_names entry has bad TU index %s"
5205 objfile_name (objfile
));
5208 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5210 case DW_IDX_die_offset
:
5211 /* In a per-CU index (as opposed to a per-module index), index
5212 entries without CU attribute implicitly refer to the single CU. */
5214 per_cu
= per_bfd
->get_cu (0);
5216 case DW_IDX_GNU_internal
:
5217 if (!m_map
.augmentation_is_gdb
)
5219 symbol_linkage_
= symbol_linkage::static_
;
5221 case DW_IDX_GNU_external
:
5222 if (!m_map
.augmentation_is_gdb
)
5224 symbol_linkage_
= symbol_linkage::extern_
;
5229 /* Skip if already read in. */
5230 if (m_per_objfile
->symtab_set_p (per_cu
))
5233 /* Check static vs global. */
5234 if (symbol_linkage_
!= symbol_linkage::unknown
)
5236 if (symbol_linkage_
== symbol_linkage::static_
)
5238 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5243 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5248 /* Match dw2_symtab_iter_next, symbol_kind
5249 and debug_names::psymbol_tag. */
5253 switch (indexval
.dwarf_tag
)
5255 case DW_TAG_variable
:
5256 case DW_TAG_subprogram
:
5257 /* Some types are also in VAR_DOMAIN. */
5258 case DW_TAG_typedef
:
5259 case DW_TAG_structure_type
:
5266 switch (indexval
.dwarf_tag
)
5268 case DW_TAG_typedef
:
5269 case DW_TAG_structure_type
:
5276 switch (indexval
.dwarf_tag
)
5279 case DW_TAG_variable
:
5286 switch (indexval
.dwarf_tag
)
5298 /* Match dw2_expand_symtabs_matching, symbol_kind and
5299 debug_names::psymbol_tag. */
5302 case VARIABLES_DOMAIN
:
5303 switch (indexval
.dwarf_tag
)
5305 case DW_TAG_variable
:
5311 case FUNCTIONS_DOMAIN
:
5312 switch (indexval
.dwarf_tag
)
5314 case DW_TAG_subprogram
:
5321 switch (indexval
.dwarf_tag
)
5323 case DW_TAG_typedef
:
5324 case DW_TAG_structure_type
:
5330 case MODULES_DOMAIN
:
5331 switch (indexval
.dwarf_tag
)
5345 /* This dumps minimal information about .debug_names. It is called
5346 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5347 uses this to verify that .debug_names has been loaded. */
5350 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5352 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5354 gdb_assert (per_objfile
->per_bfd
->using_index
);
5355 gdb_printf (".debug_names:");
5356 if (per_objfile
->per_bfd
->debug_names_table
)
5357 gdb_printf (" exists\n");
5359 gdb_printf (" faked for \"readnow\"\n");
5364 dwarf2_debug_names_index::expand_matching_symbols
5365 (struct objfile
*objfile
,
5366 const lookup_name_info
&name
, domain_enum domain
,
5368 symbol_compare_ftype
*ordered_compare
)
5370 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5372 /* debug_names_table is NULL if OBJF_READNOW. */
5373 if (!per_objfile
->per_bfd
->debug_names_table
)
5376 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5377 const block_search_flags block_flags
5378 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5380 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5381 auto matcher
= [&] (const char *symname
)
5383 if (ordered_compare
== nullptr)
5385 return ordered_compare (symname
, match_name
) == 0;
5388 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5389 [&] (offset_type namei
)
5391 /* The name was matched, now expand corresponding CUs that were
5393 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5396 struct dwarf2_per_cu_data
*per_cu
;
5397 while ((per_cu
= iter
.next ()) != NULL
)
5398 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5405 dwarf2_debug_names_index::expand_symtabs_matching
5406 (struct objfile
*objfile
,
5407 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5408 const lookup_name_info
*lookup_name
,
5409 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5410 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5411 block_search_flags search_flags
,
5413 enum search_domain kind
)
5415 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5417 /* debug_names_table is NULL if OBJF_READNOW. */
5418 if (!per_objfile
->per_bfd
->debug_names_table
)
5421 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5423 /* This invariant is documented in quick-functions.h. */
5424 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
5425 if (lookup_name
== nullptr)
5427 for (dwarf2_per_cu_data
*per_cu
5428 : all_comp_units_range (per_objfile
->per_bfd
))
5432 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5440 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5443 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5445 [&] (offset_type namei
)
5447 /* The name was matched, now expand corresponding CUs that were
5449 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5451 struct dwarf2_per_cu_data
*per_cu
;
5452 while ((per_cu
= iter
.next ()) != NULL
)
5453 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5463 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5464 to either a dwarf2_per_bfd or dwz_file object. */
5466 template <typename T
>
5467 static gdb::array_view
<const gdb_byte
>
5468 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5470 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5472 if (section
->empty ())
5475 /* Older elfutils strip versions could keep the section in the main
5476 executable while splitting it for the separate debug info file. */
5477 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5480 section
->read (obj
);
5482 /* dwarf2_section_info::size is a bfd_size_type, while
5483 gdb::array_view works with size_t. On 32-bit hosts, with
5484 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5485 is 32-bit. So we need an explicit narrowing conversion here.
5486 This is fine, because it's impossible to allocate or mmap an
5487 array/buffer larger than what size_t can represent. */
5488 return gdb::make_array_view (section
->buffer
, section
->size
);
5491 /* Lookup the index cache for the contents of the index associated to
5494 static gdb::array_view
<const gdb_byte
>
5495 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5497 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5498 if (build_id
== nullptr)
5501 return global_index_cache
.lookup_gdb_index (build_id
,
5502 &dwarf2_per_bfd
->index_cache_res
);
5505 /* Same as the above, but for DWZ. */
5507 static gdb::array_view
<const gdb_byte
>
5508 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5510 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5511 if (build_id
== nullptr)
5514 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5517 /* See dwarf2/public.h. */
5520 dwarf2_initialize_objfile (struct objfile
*objfile
)
5522 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5523 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5525 dwarf_read_debug_printf ("called");
5527 /* If we're about to read full symbols, don't bother with the
5528 indices. In this case we also don't care if some other debug
5529 format is making psymtabs, because they are all about to be
5531 if ((objfile
->flags
& OBJF_READNOW
))
5533 dwarf_read_debug_printf ("readnow requested");
5535 /* When using READNOW, the using_index flag (set below) indicates that
5536 PER_BFD was already initialized, when we loaded some other objfile. */
5537 if (per_bfd
->using_index
)
5539 dwarf_read_debug_printf ("using_index already set");
5540 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5544 per_bfd
->using_index
= 1;
5545 create_all_comp_units (per_objfile
);
5546 per_bfd
->quick_file_names_table
5547 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5549 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5551 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5553 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5554 struct dwarf2_per_cu_quick_data
);
5557 /* Arrange for gdb to see the "quick" functions. However, these
5558 functions will be no-ops because we will have expanded all
5560 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5564 /* Was a debug names index already read when we processed an objfile sharing
5566 if (per_bfd
->debug_names_table
!= nullptr)
5568 dwarf_read_debug_printf ("re-using shared debug names table");
5569 objfile
->qf
.push_front (make_dwarf_debug_names ());
5573 /* Was a GDB index already read when we processed an objfile sharing
5575 if (per_bfd
->index_table
!= nullptr)
5577 dwarf_read_debug_printf ("re-using shared index table");
5578 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5582 /* There might already be partial symtabs built for this BFD. This happens
5583 when loading the same binary twice with the index-cache enabled. If so,
5584 don't try to read an index. The objfile / per_objfile initialization will
5585 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5587 if (per_bfd
->partial_symtabs
!= nullptr)
5589 dwarf_read_debug_printf ("re-using shared partial symtabs");
5590 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5594 if (dwarf2_read_debug_names (per_objfile
))
5596 dwarf_read_debug_printf ("found debug names");
5597 objfile
->qf
.push_front (make_dwarf_debug_names ());
5601 if (dwarf2_read_gdb_index (per_objfile
,
5602 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5603 get_gdb_index_contents_from_section
<dwz_file
>))
5605 dwarf_read_debug_printf ("found gdb index from file");
5606 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5610 /* ... otherwise, try to find the index in the index cache. */
5611 if (dwarf2_read_gdb_index (per_objfile
,
5612 get_gdb_index_contents_from_cache
,
5613 get_gdb_index_contents_from_cache_dwz
))
5615 dwarf_read_debug_printf ("found gdb index from cache");
5616 global_index_cache
.hit ();
5617 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5621 global_index_cache
.miss ();
5622 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5627 /* Build a partial symbol table. */
5630 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5632 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5633 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5635 if (per_bfd
->partial_symtabs
!= nullptr)
5637 /* Partial symbols were already read, so now we can simply
5641 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5642 objfile
->qf
.emplace_front (psf
);
5645 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5651 psf
= new psymbol_functions
;
5652 objfile
->qf
.emplace_front (psf
);
5654 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5655 = psf
->get_partial_symtabs ();
5657 /* Set the local reference to partial symtabs, so that we don't try
5658 to read them again if reading another objfile with the same BFD.
5659 If we can't in fact share, this won't make a difference anyway as
5660 the dwarf2_per_bfd object won't be shared. */
5661 per_bfd
->partial_symtabs
= partial_symtabs
;
5665 /* This isn't really ideal: all the data we allocate on the
5666 objfile's obstack is still uselessly kept around. However,
5667 freeing it seems unsafe. */
5668 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5669 dwarf2_build_psymtabs_hard (per_objfile
);
5672 /* (maybe) store an index in the cache. */
5673 global_index_cache
.store (per_objfile
);
5675 catch (const gdb_exception_error
&except
)
5677 exception_print (gdb_stderr
, except
);
5681 /* Find the base address of the compilation unit for range lists and
5682 location lists. It will normally be specified by DW_AT_low_pc.
5683 In DWARF-3 draft 4, the base address could be overridden by
5684 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5685 compilation units with discontinuous ranges. */
5688 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5690 struct attribute
*attr
;
5692 cu
->base_address
.reset ();
5694 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5695 if (attr
!= nullptr)
5696 cu
->base_address
= attr
->as_address ();
5699 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5700 if (attr
!= nullptr)
5701 cu
->base_address
= attr
->as_address ();
5705 /* Helper function that returns the proper abbrev section for
5708 static struct dwarf2_section_info
*
5709 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5711 struct dwarf2_section_info
*abbrev
;
5712 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5714 if (this_cu
->is_dwz
)
5715 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5717 abbrev
= &per_bfd
->abbrev
;
5722 /* Fetch the abbreviation table offset from a comp or type unit header. */
5725 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5726 struct dwarf2_section_info
*section
,
5727 sect_offset sect_off
)
5729 bfd
*abfd
= section
->get_bfd_owner ();
5730 const gdb_byte
*info_ptr
;
5731 unsigned int initial_length_size
, offset_size
;
5734 section
->read (per_objfile
->objfile
);
5735 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5736 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5737 offset_size
= initial_length_size
== 4 ? 4 : 8;
5738 info_ptr
+= initial_length_size
;
5740 version
= read_2_bytes (abfd
, info_ptr
);
5744 /* Skip unit type and address size. */
5748 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5751 /* A partial symtab that is used only for include files. */
5752 struct dwarf2_include_psymtab
: public partial_symtab
5754 dwarf2_include_psymtab (const char *filename
,
5755 psymtab_storage
*partial_symtabs
,
5756 objfile_per_bfd_storage
*objfile_per_bfd
)
5757 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5761 void read_symtab (struct objfile
*objfile
) override
5763 /* It's an include file, no symbols to read for it.
5764 Everything is in the includer symtab. */
5766 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5767 expansion of the includer psymtab. We use the dependencies[0] field to
5768 model the includer. But if we go the regular route of calling
5769 expand_psymtab here, and having expand_psymtab call expand_dependencies
5770 to expand the includer, we'll only use expand_psymtab on the includer
5771 (making it a non-toplevel psymtab), while if we expand the includer via
5772 another path, we'll use read_symtab (making it a toplevel psymtab).
5773 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5774 psymtab, and trigger read_symtab on the includer here directly. */
5775 includer ()->read_symtab (objfile
);
5778 void expand_psymtab (struct objfile
*objfile
) override
5780 /* This is not called by read_symtab, and should not be called by any
5781 expand_dependencies. */
5785 bool readin_p (struct objfile
*objfile
) const override
5787 return includer ()->readin_p (objfile
);
5790 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5792 compunit_symtab
*cust
= includer ()->get_compunit_symtab (objfile
);
5793 while (cust
!= nullptr && cust
->user
!= nullptr)
5799 partial_symtab
*includer () const
5801 /* An include psymtab has exactly one dependency: the psymtab that
5803 gdb_assert (this->number_of_dependencies
== 1);
5804 return this->dependencies
[0];
5808 /* Allocate a new partial symtab for file named NAME and mark this new
5809 partial symtab as being an include of PST. */
5812 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5814 dwarf2_psymtab
*pst
,
5815 psymtab_storage
*partial_symtabs
,
5816 objfile_per_bfd_storage
*objfile_per_bfd
)
5818 dwarf2_include_psymtab
*subpst
5819 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5821 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5822 subpst
->dirname
= pst
->dirname
;
5824 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5825 subpst
->dependencies
[0] = pst
;
5826 subpst
->number_of_dependencies
= 1;
5829 /* Read the Line Number Program data and extract the list of files
5830 included by the source file represented by PST. Build an include
5831 partial symtab for each of these included files. */
5834 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5835 struct die_info
*die
,
5836 const file_and_directory
&fnd
,
5837 dwarf2_psymtab
*pst
)
5840 struct attribute
*attr
;
5842 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5843 if (attr
!= nullptr && attr
->form_is_unsigned ())
5844 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5846 return; /* No linetable, so no includes. */
5848 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5849 that we pass in the raw text_low here; that is ok because we're
5850 only decoding the line table to make include partial symtabs, and
5851 so the addresses aren't really used. */
5852 dwarf_decode_lines (lh
.get (), fnd
, cu
, pst
,
5853 pst
->raw_text_low (), 1);
5857 hash_signatured_type (const void *item
)
5859 const struct signatured_type
*sig_type
5860 = (const struct signatured_type
*) item
;
5862 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5863 return sig_type
->signature
;
5867 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5869 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5870 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5872 return lhs
->signature
== rhs
->signature
;
5875 /* Allocate a hash table for signatured types. */
5878 allocate_signatured_type_table ()
5880 return htab_up (htab_create_alloc (41,
5881 hash_signatured_type
,
5883 NULL
, xcalloc
, xfree
));
5886 /* A helper for create_debug_types_hash_table. Read types from SECTION
5887 and fill them into TYPES_HTAB. It will process only type units,
5888 therefore DW_UT_type. */
5891 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5892 struct dwo_file
*dwo_file
,
5893 dwarf2_section_info
*section
, htab_up
&types_htab
,
5894 rcuh_kind section_kind
)
5896 struct objfile
*objfile
= per_objfile
->objfile
;
5897 struct dwarf2_section_info
*abbrev_section
;
5899 const gdb_byte
*info_ptr
, *end_ptr
;
5901 abbrev_section
= &dwo_file
->sections
.abbrev
;
5903 dwarf_read_debug_printf ("Reading %s for %s",
5904 section
->get_name (),
5905 abbrev_section
->get_file_name ());
5907 section
->read (objfile
);
5908 info_ptr
= section
->buffer
;
5910 if (info_ptr
== NULL
)
5913 /* We can't set abfd until now because the section may be empty or
5914 not present, in which case the bfd is unknown. */
5915 abfd
= section
->get_bfd_owner ();
5917 /* We don't use cutu_reader here because we don't need to read
5918 any dies: the signature is in the header. */
5920 end_ptr
= info_ptr
+ section
->size
;
5921 while (info_ptr
< end_ptr
)
5923 signatured_type_up sig_type
;
5924 struct dwo_unit
*dwo_tu
;
5926 const gdb_byte
*ptr
= info_ptr
;
5927 struct comp_unit_head header
;
5928 unsigned int length
;
5930 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5932 /* Initialize it due to a false compiler warning. */
5933 header
.signature
= -1;
5934 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5936 /* We need to read the type's signature in order to build the hash
5937 table, but we don't need anything else just yet. */
5939 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5940 abbrev_section
, ptr
, section_kind
);
5942 length
= header
.get_length ();
5944 /* Skip dummy type units. */
5945 if (ptr
>= info_ptr
+ length
5946 || peek_abbrev_code (abfd
, ptr
) == 0
5947 || (header
.unit_type
!= DW_UT_type
5948 && header
.unit_type
!= DW_UT_split_type
))
5954 if (types_htab
== NULL
)
5955 types_htab
= allocate_dwo_unit_table ();
5957 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5958 dwo_tu
->dwo_file
= dwo_file
;
5959 dwo_tu
->signature
= header
.signature
;
5960 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5961 dwo_tu
->section
= section
;
5962 dwo_tu
->sect_off
= sect_off
;
5963 dwo_tu
->length
= length
;
5965 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5966 gdb_assert (slot
!= NULL
);
5968 complaint (_("debug type entry at offset %s is duplicate to"
5969 " the entry at offset %s, signature %s"),
5970 sect_offset_str (sect_off
),
5971 sect_offset_str (dwo_tu
->sect_off
),
5972 hex_string (header
.signature
));
5975 dwarf_read_debug_printf_v (" offset %s, signature %s",
5976 sect_offset_str (sect_off
),
5977 hex_string (header
.signature
));
5983 /* Create the hash table of all entries in the .debug_types
5984 (or .debug_types.dwo) section(s).
5985 DWO_FILE is a pointer to the DWO file object.
5987 The result is a pointer to the hash table or NULL if there are no types.
5989 Note: This function processes DWO files only, not DWP files. */
5992 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5993 struct dwo_file
*dwo_file
,
5994 gdb::array_view
<dwarf2_section_info
> type_sections
,
5995 htab_up
&types_htab
)
5997 for (dwarf2_section_info
§ion
: type_sections
)
5998 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6002 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6003 If SLOT is non-NULL, it is the entry to use in the hash table.
6004 Otherwise we find one. */
6006 static struct signatured_type
*
6007 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6009 if (per_objfile
->per_bfd
->all_comp_units
.size ()
6010 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
6011 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6013 signatured_type_up sig_type_holder
6014 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
6015 signatured_type
*sig_type
= sig_type_holder
.get ();
6017 per_objfile
->per_bfd
->all_comp_units
.emplace_back
6018 (sig_type_holder
.release ());
6019 if (per_objfile
->per_bfd
->using_index
)
6022 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6023 struct dwarf2_per_cu_quick_data
);
6028 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6031 gdb_assert (*slot
== NULL
);
6033 /* The rest of sig_type must be filled in by the caller. */
6037 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6038 Fill in SIG_ENTRY with DWO_ENTRY. */
6041 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6042 struct signatured_type
*sig_entry
,
6043 struct dwo_unit
*dwo_entry
)
6045 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6047 /* Make sure we're not clobbering something we don't expect to. */
6048 gdb_assert (! sig_entry
->queued
);
6049 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
6050 if (per_bfd
->using_index
)
6052 gdb_assert (sig_entry
->v
.quick
!= NULL
);
6053 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
6056 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
6057 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6058 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6059 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6060 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6062 sig_entry
->section
= dwo_entry
->section
;
6063 sig_entry
->sect_off
= dwo_entry
->sect_off
;
6064 sig_entry
->length
= dwo_entry
->length
;
6065 sig_entry
->reading_dwo_directly
= 1;
6066 sig_entry
->per_bfd
= per_bfd
;
6067 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6068 sig_entry
->dwo_unit
= dwo_entry
;
6071 /* Subroutine of lookup_signatured_type.
6072 If we haven't read the TU yet, create the signatured_type data structure
6073 for a TU to be read in directly from a DWO file, bypassing the stub.
6074 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6075 using .gdb_index, then when reading a CU we want to stay in the DWO file
6076 containing that CU. Otherwise we could end up reading several other DWO
6077 files (due to comdat folding) to process the transitive closure of all the
6078 mentioned TUs, and that can be slow. The current DWO file will have every
6079 type signature that it needs.
6080 We only do this for .gdb_index because in the psymtab case we already have
6081 to read all the DWOs to build the type unit groups. */
6083 static struct signatured_type
*
6084 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6086 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6087 struct dwo_file
*dwo_file
;
6088 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6091 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6093 /* If TU skeletons have been removed then we may not have read in any
6095 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6096 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6098 /* We only ever need to read in one copy of a signatured type.
6099 Use the global signatured_types array to do our own comdat-folding
6100 of types. If this is the first time we're reading this TU, and
6101 the TU has an entry in .gdb_index, replace the recorded data from
6102 .gdb_index with this TU. */
6104 signatured_type
find_sig_entry (sig
);
6105 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6106 &find_sig_entry
, INSERT
);
6107 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6109 /* We can get here with the TU already read, *or* in the process of being
6110 read. Don't reassign the global entry to point to this DWO if that's
6111 the case. Also note that if the TU is already being read, it may not
6112 have come from a DWO, the program may be a mix of Fission-compiled
6113 code and non-Fission-compiled code. */
6115 /* Have we already tried to read this TU?
6116 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6117 needn't exist in the global table yet). */
6118 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6121 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6122 dwo_unit of the TU itself. */
6123 dwo_file
= cu
->dwo_unit
->dwo_file
;
6125 /* Ok, this is the first time we're reading this TU. */
6126 if (dwo_file
->tus
== NULL
)
6128 find_dwo_entry
.signature
= sig
;
6129 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6131 if (dwo_entry
== NULL
)
6134 /* If the global table doesn't have an entry for this TU, add one. */
6135 if (sig_entry
== NULL
)
6136 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6138 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6139 sig_entry
->tu_read
= 1;
6143 /* Subroutine of lookup_signatured_type.
6144 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6145 then try the DWP file. If the TU stub (skeleton) has been removed then
6146 it won't be in .gdb_index. */
6148 static struct signatured_type
*
6149 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6151 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6152 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6153 struct dwo_unit
*dwo_entry
;
6156 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6157 gdb_assert (dwp_file
!= NULL
);
6159 /* If TU skeletons have been removed then we may not have read in any
6161 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6162 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6164 signatured_type
find_sig_entry (sig
);
6165 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6166 &find_sig_entry
, INSERT
);
6167 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6169 /* Have we already tried to read this TU?
6170 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6171 needn't exist in the global table yet). */
6172 if (sig_entry
!= NULL
)
6175 if (dwp_file
->tus
== NULL
)
6177 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6178 1 /* is_debug_types */);
6179 if (dwo_entry
== NULL
)
6182 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6183 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6188 /* Lookup a signature based type for DW_FORM_ref_sig8.
6189 Returns NULL if signature SIG is not present in the table.
6190 It is up to the caller to complain about this. */
6192 static struct signatured_type
*
6193 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6195 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6197 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6199 /* We're in a DWO/DWP file, and we're using .gdb_index.
6200 These cases require special processing. */
6201 if (get_dwp_file (per_objfile
) == NULL
)
6202 return lookup_dwo_signatured_type (cu
, sig
);
6204 return lookup_dwp_signatured_type (cu
, sig
);
6208 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6210 signatured_type
find_entry (sig
);
6211 return ((struct signatured_type
*)
6212 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6217 /* Low level DIE reading support. */
6219 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6222 init_cu_die_reader (struct die_reader_specs
*reader
,
6223 struct dwarf2_cu
*cu
,
6224 struct dwarf2_section_info
*section
,
6225 struct dwo_file
*dwo_file
,
6226 struct abbrev_table
*abbrev_table
)
6228 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6229 reader
->abfd
= section
->get_bfd_owner ();
6231 reader
->dwo_file
= dwo_file
;
6232 reader
->die_section
= section
;
6233 reader
->buffer
= section
->buffer
;
6234 reader
->buffer_end
= section
->buffer
+ section
->size
;
6235 reader
->abbrev_table
= abbrev_table
;
6238 /* Subroutine of cutu_reader to simplify it.
6239 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6240 There's just a lot of work to do, and cutu_reader is big enough
6243 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6244 from it to the DIE in the DWO. If NULL we are skipping the stub.
6245 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6246 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6247 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6248 STUB_COMP_DIR may be non-NULL.
6249 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6250 are filled in with the info of the DIE from the DWO file.
6251 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6252 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6253 kept around for at least as long as *RESULT_READER.
6255 The result is non-zero if a valid (non-dummy) DIE was found. */
6258 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6259 struct dwo_unit
*dwo_unit
,
6260 struct die_info
*stub_comp_unit_die
,
6261 const char *stub_comp_dir
,
6262 struct die_reader_specs
*result_reader
,
6263 const gdb_byte
**result_info_ptr
,
6264 struct die_info
**result_comp_unit_die
,
6265 abbrev_table_up
*result_dwo_abbrev_table
)
6267 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6268 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6269 struct objfile
*objfile
= per_objfile
->objfile
;
6271 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6272 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6273 int i
,num_extra_attrs
;
6274 struct dwarf2_section_info
*dwo_abbrev_section
;
6275 struct die_info
*comp_unit_die
;
6277 /* At most one of these may be provided. */
6278 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6280 /* These attributes aren't processed until later:
6281 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6282 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6283 referenced later. However, these attributes are found in the stub
6284 which we won't have later. In order to not impose this complication
6285 on the rest of the code, we read them here and copy them to the
6294 if (stub_comp_unit_die
!= NULL
)
6296 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6298 if (!per_cu
->is_debug_types
)
6299 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6300 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6301 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6302 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6303 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6305 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6307 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6308 We need the value before we can process DW_AT_ranges values from the
6310 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6312 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6313 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6314 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6315 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6317 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6319 else if (stub_comp_dir
!= NULL
)
6321 /* Reconstruct the comp_dir attribute to simplify the code below. */
6322 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6323 comp_dir
->name
= DW_AT_comp_dir
;
6324 comp_dir
->form
= DW_FORM_string
;
6325 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6328 /* Set up for reading the DWO CU/TU. */
6329 cu
->dwo_unit
= dwo_unit
;
6330 dwarf2_section_info
*section
= dwo_unit
->section
;
6331 section
->read (objfile
);
6332 abfd
= section
->get_bfd_owner ();
6333 begin_info_ptr
= info_ptr
= (section
->buffer
6334 + to_underlying (dwo_unit
->sect_off
));
6335 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6337 if (per_cu
->is_debug_types
)
6339 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6341 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6342 section
, dwo_abbrev_section
,
6343 info_ptr
, rcuh_kind::TYPE
);
6344 /* This is not an assert because it can be caused by bad debug info. */
6345 if (sig_type
->signature
!= cu
->header
.signature
)
6347 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6348 " TU at offset %s [in module %s]"),
6349 hex_string (sig_type
->signature
),
6350 hex_string (cu
->header
.signature
),
6351 sect_offset_str (dwo_unit
->sect_off
),
6352 bfd_get_filename (abfd
));
6354 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6355 /* For DWOs coming from DWP files, we don't know the CU length
6356 nor the type's offset in the TU until now. */
6357 dwo_unit
->length
= cu
->header
.get_length ();
6358 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6360 /* Establish the type offset that can be used to lookup the type.
6361 For DWO files, we don't know it until now. */
6362 sig_type
->type_offset_in_section
6363 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6367 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6368 section
, dwo_abbrev_section
,
6369 info_ptr
, rcuh_kind::COMPILE
);
6370 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6371 /* For DWOs coming from DWP files, we don't know the CU length
6373 dwo_unit
->length
= cu
->header
.get_length ();
6376 dwo_abbrev_section
->read (objfile
);
6377 *result_dwo_abbrev_table
6378 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6379 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6380 result_dwo_abbrev_table
->get ());
6382 /* Read in the die, but leave space to copy over the attributes
6383 from the stub. This has the benefit of simplifying the rest of
6384 the code - all the work to maintain the illusion of a single
6385 DW_TAG_{compile,type}_unit DIE is done here. */
6386 num_extra_attrs
= ((stmt_list
!= NULL
)
6390 + (comp_dir
!= NULL
));
6391 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6394 /* Copy over the attributes from the stub to the DIE we just read in. */
6395 comp_unit_die
= *result_comp_unit_die
;
6396 i
= comp_unit_die
->num_attrs
;
6397 if (stmt_list
!= NULL
)
6398 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6400 comp_unit_die
->attrs
[i
++] = *low_pc
;
6401 if (high_pc
!= NULL
)
6402 comp_unit_die
->attrs
[i
++] = *high_pc
;
6404 comp_unit_die
->attrs
[i
++] = *ranges
;
6405 if (comp_dir
!= NULL
)
6406 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6407 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6409 if (dwarf_die_debug
)
6411 gdb_printf (gdb_stdlog
,
6412 "Read die from %s@0x%x of %s:\n",
6413 section
->get_name (),
6414 (unsigned) (begin_info_ptr
- section
->buffer
),
6415 bfd_get_filename (abfd
));
6416 dump_die (comp_unit_die
, dwarf_die_debug
);
6419 /* Skip dummy compilation units. */
6420 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6421 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6424 *result_info_ptr
= info_ptr
;
6428 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6429 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6430 signature is part of the header. */
6431 static gdb::optional
<ULONGEST
>
6432 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6434 if (cu
->header
.version
>= 5)
6435 return cu
->header
.signature
;
6436 struct attribute
*attr
;
6437 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6438 if (attr
== nullptr || !attr
->form_is_unsigned ())
6439 return gdb::optional
<ULONGEST
> ();
6440 return attr
->as_unsigned ();
6443 /* Subroutine of cutu_reader to simplify it.
6444 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6445 Returns NULL if the specified DWO unit cannot be found. */
6447 static struct dwo_unit
*
6448 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6450 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6451 struct dwo_unit
*dwo_unit
;
6452 const char *comp_dir
;
6454 gdb_assert (cu
!= NULL
);
6456 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6457 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6458 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6460 if (per_cu
->is_debug_types
)
6461 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6464 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6466 if (!signature
.has_value ())
6467 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6469 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6471 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6477 /* Subroutine of cutu_reader to simplify it.
6478 See it for a description of the parameters.
6479 Read a TU directly from a DWO file, bypassing the stub. */
6482 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6483 dwarf2_per_objfile
*per_objfile
,
6484 dwarf2_cu
*existing_cu
)
6486 struct signatured_type
*sig_type
;
6488 /* Verify we can do the following downcast, and that we have the
6490 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6491 sig_type
= (struct signatured_type
*) this_cu
;
6492 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6496 if (existing_cu
!= nullptr)
6499 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6500 /* There's no need to do the rereading_dwo_cu handling that
6501 cutu_reader does since we don't read the stub. */
6505 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6506 in per_objfile yet. */
6507 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6508 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6509 cu
= m_new_cu
.get ();
6512 /* A future optimization, if needed, would be to use an existing
6513 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6514 could share abbrev tables. */
6516 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6517 NULL
/* stub_comp_unit_die */,
6518 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6521 &m_dwo_abbrev_table
) == 0)
6528 /* Initialize a CU (or TU) and read its DIEs.
6529 If the CU defers to a DWO file, read the DWO file as well.
6531 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6532 Otherwise the table specified in the comp unit header is read in and used.
6533 This is an optimization for when we already have the abbrev table.
6535 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6538 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6539 dwarf2_per_objfile
*per_objfile
,
6540 struct abbrev_table
*abbrev_table
,
6541 dwarf2_cu
*existing_cu
,
6543 : die_reader_specs
{},
6546 struct objfile
*objfile
= per_objfile
->objfile
;
6547 struct dwarf2_section_info
*section
= this_cu
->section
;
6548 bfd
*abfd
= section
->get_bfd_owner ();
6549 const gdb_byte
*begin_info_ptr
;
6550 struct signatured_type
*sig_type
= NULL
;
6551 struct dwarf2_section_info
*abbrev_section
;
6552 /* Non-zero if CU currently points to a DWO file and we need to
6553 reread it. When this happens we need to reread the skeleton die
6554 before we can reread the DWO file (this only applies to CUs, not TUs). */
6555 int rereading_dwo_cu
= 0;
6557 if (dwarf_die_debug
)
6558 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
6559 this_cu
->is_debug_types
? "type" : "comp",
6560 sect_offset_str (this_cu
->sect_off
));
6562 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6563 file (instead of going through the stub), short-circuit all of this. */
6564 if (this_cu
->reading_dwo_directly
)
6566 /* Narrow down the scope of possibilities to have to understand. */
6567 gdb_assert (this_cu
->is_debug_types
);
6568 gdb_assert (abbrev_table
== NULL
);
6569 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6573 /* This is cheap if the section is already read in. */
6574 section
->read (objfile
);
6576 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6578 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6582 if (existing_cu
!= nullptr)
6585 /* If this CU is from a DWO file we need to start over, we need to
6586 refetch the attributes from the skeleton CU.
6587 This could be optimized by retrieving those attributes from when we
6588 were here the first time: the previous comp_unit_die was stored in
6589 comp_unit_obstack. But there's no data yet that we need this
6591 if (cu
->dwo_unit
!= NULL
)
6592 rereading_dwo_cu
= 1;
6596 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6597 in per_objfile yet. */
6598 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6599 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6600 cu
= m_new_cu
.get ();
6603 /* Get the header. */
6604 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6606 /* We already have the header, there's no need to read it in again. */
6607 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6611 if (this_cu
->is_debug_types
)
6613 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6614 section
, abbrev_section
,
6615 info_ptr
, rcuh_kind::TYPE
);
6617 /* Since per_cu is the first member of struct signatured_type,
6618 we can go from a pointer to one to a pointer to the other. */
6619 sig_type
= (struct signatured_type
*) this_cu
;
6620 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6621 gdb_assert (sig_type
->type_offset_in_tu
6622 == cu
->header
.type_cu_offset_in_tu
);
6623 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6625 /* LENGTH has not been set yet for type units if we're
6626 using .gdb_index. */
6627 this_cu
->length
= cu
->header
.get_length ();
6629 /* Establish the type offset that can be used to lookup the type. */
6630 sig_type
->type_offset_in_section
=
6631 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6633 this_cu
->dwarf_version
= cu
->header
.version
;
6637 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6638 section
, abbrev_section
,
6640 rcuh_kind::COMPILE
);
6642 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6643 if (this_cu
->length
== 0)
6644 this_cu
->length
= cu
->header
.get_length ();
6646 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6647 this_cu
->dwarf_version
= cu
->header
.version
;
6651 /* Skip dummy compilation units. */
6652 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6653 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6659 /* If we don't have them yet, read the abbrevs for this compilation unit.
6660 And if we need to read them now, make sure they're freed when we're
6662 if (abbrev_table
!= NULL
)
6663 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6666 abbrev_section
->read (objfile
);
6667 m_abbrev_table_holder
6668 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6669 abbrev_table
= m_abbrev_table_holder
.get ();
6672 /* Read the top level CU/TU die. */
6673 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6674 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6676 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6682 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6683 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6684 table from the DWO file and pass the ownership over to us. It will be
6685 referenced from READER, so we must make sure to free it after we're done
6688 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6689 DWO CU, that this test will fail (the attribute will not be present). */
6690 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6691 if (dwo_name
!= nullptr)
6693 struct dwo_unit
*dwo_unit
;
6694 struct die_info
*dwo_comp_unit_die
;
6696 if (comp_unit_die
->has_children
)
6698 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6699 " has children (offset %s) [in module %s]"),
6700 sect_offset_str (this_cu
->sect_off
),
6701 bfd_get_filename (abfd
));
6703 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6704 if (dwo_unit
!= NULL
)
6706 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6707 comp_unit_die
, NULL
,
6710 &m_dwo_abbrev_table
) == 0)
6716 comp_unit_die
= dwo_comp_unit_die
;
6720 /* Yikes, we couldn't find the rest of the DIE, we only have
6721 the stub. A complaint has already been logged. There's
6722 not much more we can do except pass on the stub DIE to
6723 die_reader_func. We don't want to throw an error on bad
6730 cutu_reader::keep ()
6732 /* Done, clean up. */
6733 gdb_assert (!dummy_p
);
6734 if (m_new_cu
!= NULL
)
6736 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6738 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6739 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6743 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6744 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6745 assumed to have already done the lookup to find the DWO file).
6747 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6748 THIS_CU->is_debug_types, but nothing else.
6750 We fill in THIS_CU->length.
6752 THIS_CU->cu is always freed when done.
6753 This is done in order to not leave THIS_CU->cu in a state where we have
6754 to care whether it refers to the "main" CU or the DWO CU.
6756 When parent_cu is passed, it is used to provide a default value for
6757 str_offsets_base and addr_base from the parent. */
6759 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6760 dwarf2_per_objfile
*per_objfile
,
6761 struct dwarf2_cu
*parent_cu
,
6762 struct dwo_file
*dwo_file
)
6763 : die_reader_specs
{},
6766 struct objfile
*objfile
= per_objfile
->objfile
;
6767 struct dwarf2_section_info
*section
= this_cu
->section
;
6768 bfd
*abfd
= section
->get_bfd_owner ();
6769 struct dwarf2_section_info
*abbrev_section
;
6770 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6772 if (dwarf_die_debug
)
6773 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
6774 this_cu
->is_debug_types
? "type" : "comp",
6775 sect_offset_str (this_cu
->sect_off
));
6777 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6779 abbrev_section
= (dwo_file
!= NULL
6780 ? &dwo_file
->sections
.abbrev
6781 : get_abbrev_section_for_cu (this_cu
));
6783 /* This is cheap if the section is already read in. */
6784 section
->read (objfile
);
6786 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6788 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6789 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6790 section
, abbrev_section
, info_ptr
,
6791 (this_cu
->is_debug_types
6793 : rcuh_kind::COMPILE
));
6795 if (parent_cu
!= nullptr)
6797 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6798 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6800 this_cu
->length
= m_new_cu
->header
.get_length ();
6802 /* Skip dummy compilation units. */
6803 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6804 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6810 abbrev_section
->read (objfile
);
6811 m_abbrev_table_holder
6812 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6814 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6815 m_abbrev_table_holder
.get ());
6816 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6820 /* Type Unit Groups.
6822 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6823 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6824 so that all types coming from the same compilation (.o file) are grouped
6825 together. A future step could be to put the types in the same symtab as
6826 the CU the types ultimately came from. */
6829 hash_type_unit_group (const void *item
)
6831 const struct type_unit_group
*tu_group
6832 = (const struct type_unit_group
*) item
;
6834 return hash_stmt_list_entry (&tu_group
->hash
);
6838 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6840 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6841 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6843 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6846 /* Allocate a hash table for type unit groups. */
6849 allocate_type_unit_groups_table ()
6851 return htab_up (htab_create_alloc (3,
6852 hash_type_unit_group
,
6854 htab_delete_entry
<type_unit_group
>,
6858 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6859 partial symtabs. We combine several TUs per psymtab to not let the size
6860 of any one psymtab grow too big. */
6861 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6862 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6864 /* Helper routine for get_type_unit_group.
6865 Create the type_unit_group object used to hold one or more TUs. */
6867 static std::unique_ptr
<type_unit_group
>
6868 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6870 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6871 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6873 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6874 tu_group
->per_bfd
= per_bfd
;
6876 if (per_bfd
->using_index
)
6878 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6879 struct dwarf2_per_cu_quick_data
);
6883 unsigned int line_offset
= to_underlying (line_offset_struct
);
6884 dwarf2_psymtab
*pst
;
6887 /* Give the symtab a useful name for debug purposes. */
6888 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6889 name
= string_printf ("<type_units_%d>",
6890 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6892 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6894 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6896 pst
->anonymous
= true;
6899 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6900 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6905 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6906 STMT_LIST is a DW_AT_stmt_list attribute. */
6908 static struct type_unit_group
*
6909 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6911 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6912 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6913 struct type_unit_group
*tu_group
;
6915 unsigned int line_offset
;
6916 struct type_unit_group type_unit_group_for_lookup
;
6918 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6919 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6921 /* Do we need to create a new group, or can we use an existing one? */
6923 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6925 line_offset
= stmt_list
->as_unsigned ();
6926 ++tu_stats
->nr_symtab_sharers
;
6930 /* Ugh, no stmt_list. Rare, but we have to handle it.
6931 We can do various things here like create one group per TU or
6932 spread them over multiple groups to split up the expansion work.
6933 To avoid worst case scenarios (too many groups or too large groups)
6934 we, umm, group them in bunches. */
6935 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6936 | (tu_stats
->nr_stmt_less_type_units
6937 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6938 ++tu_stats
->nr_stmt_less_type_units
;
6941 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6942 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6943 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6944 &type_unit_group_for_lookup
, INSERT
);
6945 if (*slot
== nullptr)
6947 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6948 std::unique_ptr
<type_unit_group
> grp
6949 = create_type_unit_group (cu
, line_offset_struct
);
6950 *slot
= grp
.release ();
6951 ++tu_stats
->nr_symtabs
;
6954 tu_group
= (struct type_unit_group
*) *slot
;
6955 gdb_assert (tu_group
!= nullptr);
6959 /* Partial symbol tables. */
6961 /* Create a psymtab named NAME and assign it to PER_CU.
6963 The caller must fill in the following details:
6964 dirname, textlow, texthigh. */
6966 static dwarf2_psymtab
*
6967 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6968 dwarf2_per_objfile
*per_objfile
,
6972 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6973 per_objfile
->objfile
->per_bfd
, per_cu
);
6975 pst
->psymtabs_addrmap_supported
= true;
6977 /* This is the glue that links PST into GDB's symbol API. */
6978 per_cu
->v
.psymtab
= pst
;
6983 /* DIE reader function for process_psymtab_comp_unit. */
6986 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6987 const gdb_byte
*info_ptr
,
6988 struct die_info
*comp_unit_die
,
6989 enum language pretend_language
)
6991 struct dwarf2_cu
*cu
= reader
->cu
;
6992 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6993 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6994 struct objfile
*objfile
= per_objfile
->objfile
;
6995 struct gdbarch
*gdbarch
= objfile
->arch ();
6996 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6998 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6999 dwarf2_psymtab
*pst
;
7000 enum pc_bounds_kind cu_bounds_kind
;
7002 gdb_assert (! per_cu
->is_debug_types
);
7004 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7006 /* Allocate a new partial symbol table structure. */
7007 static const char artificial
[] = "<artificial>";
7008 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
7009 if (strcmp (fnd
.get_name (), artificial
) == 0)
7011 gdb::unique_xmalloc_ptr
<char> debug_filename
7012 (concat (artificial
, "@",
7013 sect_offset_str (per_cu
->sect_off
),
7015 fnd
.set_name (std::move (debug_filename
));
7018 pst
= create_partial_symtab (per_cu
, per_objfile
, fnd
.get_name ());
7020 /* This must be done before calling dwarf2_build_include_psymtabs. */
7021 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7023 baseaddr
= objfile
->text_section_offset ();
7025 dwarf2_find_base_address (comp_unit_die
, cu
);
7027 /* Possibly set the default values of LOWPC and HIGHPC from
7030 = dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7032 per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7034 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7037 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7040 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7042 /* Store the contiguous range if it is not empty; it can be
7043 empty for CUs with no code. */
7044 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7048 /* Check if comp unit has_children.
7049 If so, read the rest of the partial symbols from this comp unit.
7050 If not, there's no more debug_info for this comp unit. */
7051 if (comp_unit_die
->has_children
)
7053 struct partial_die_info
*first_die
;
7054 CORE_ADDR lowpc
, highpc
;
7056 lowpc
= ((CORE_ADDR
) -1);
7057 highpc
= ((CORE_ADDR
) 0);
7059 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7061 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7062 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7064 /* If we didn't find a lowpc, set it to highpc to avoid
7065 complaints from `maint check'. */
7066 if (lowpc
== ((CORE_ADDR
) -1))
7069 /* If the compilation unit didn't have an explicit address range,
7070 then use the information extracted from its child dies. */
7071 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7074 best_highpc
= highpc
;
7077 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7078 best_lowpc
+ baseaddr
)
7080 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7081 best_highpc
+ baseaddr
)
7086 if (!cu
->per_cu
->imported_symtabs_empty ())
7089 int len
= cu
->per_cu
->imported_symtabs_size ();
7091 /* Fill in 'dependencies' here; we fill in 'users' in a
7093 pst
->number_of_dependencies
= len
;
7095 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7096 for (i
= 0; i
< len
; ++i
)
7098 pst
->dependencies
[i
]
7099 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7102 cu
->per_cu
->imported_symtabs_free ();
7105 /* Get the list of files included in the current compilation unit,
7106 and build a psymtab for each of them. */
7107 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, fnd
, pst
);
7109 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7110 ", %d global, %d static syms",
7111 per_cu
->is_debug_types
? "type" : "comp",
7112 sect_offset_str (per_cu
->sect_off
),
7113 paddress (gdbarch
, pst
->text_low (objfile
)),
7114 paddress (gdbarch
, pst
->text_high (objfile
)),
7115 (int) pst
->global_psymbols
.size (),
7116 (int) pst
->static_psymbols
.size ());
7119 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7120 Process compilation unit THIS_CU for a psymtab. */
7123 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7124 dwarf2_per_objfile
*per_objfile
,
7125 bool want_partial_unit
,
7126 enum language pretend_language
)
7128 /* If this compilation unit was already read in, free the
7129 cached copy in order to read it in again. This is
7130 necessary because we skipped some symbols when we first
7131 read in the compilation unit (see load_partial_dies).
7132 This problem could be avoided, but the benefit is unclear. */
7133 per_objfile
->remove_cu (this_cu
);
7135 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7137 if (reader
.comp_unit_die
== nullptr)
7140 switch (reader
.comp_unit_die
->tag
)
7142 case DW_TAG_compile_unit
:
7143 this_cu
->unit_type
= DW_UT_compile
;
7145 case DW_TAG_partial_unit
:
7146 this_cu
->unit_type
= DW_UT_partial
;
7148 case DW_TAG_type_unit
:
7149 this_cu
->unit_type
= DW_UT_type
;
7152 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7153 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7154 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7155 objfile_name (per_objfile
->objfile
));
7162 else if (this_cu
->is_debug_types
)
7163 build_type_psymtabs_reader (&reader
);
7164 else if (want_partial_unit
7165 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7166 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7167 reader
.comp_unit_die
,
7170 /* Age out any secondary CUs. */
7171 per_objfile
->age_comp_units ();
7174 /* Reader function for build_type_psymtabs. */
7177 build_type_psymtabs_reader (cutu_reader
*reader
)
7179 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7180 struct dwarf2_cu
*cu
= reader
->cu
;
7181 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7182 struct signatured_type
*sig_type
;
7183 struct type_unit_group
*tu_group
;
7184 struct attribute
*attr
;
7185 struct partial_die_info
*first_die
;
7186 CORE_ADDR lowpc
, highpc
;
7187 dwarf2_psymtab
*pst
;
7188 const gdb_byte
*info_ptr
= reader
->info_ptr
;
7189 struct die_info
*type_unit_die
= reader
->comp_unit_die
;
7191 gdb_assert (per_cu
->is_debug_types
);
7192 sig_type
= (struct signatured_type
*) per_cu
;
7194 if (! type_unit_die
->has_children
)
7197 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7198 tu_group
= get_type_unit_group (cu
, attr
);
7200 if (tu_group
->tus
== nullptr)
7201 tu_group
->tus
= new std::vector
<signatured_type
*>;
7202 tu_group
->tus
->push_back (sig_type
);
7204 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7205 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7206 pst
->anonymous
= true;
7208 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7210 lowpc
= (CORE_ADDR
) -1;
7211 highpc
= (CORE_ADDR
) 0;
7212 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7217 /* Struct used to sort TUs by their abbreviation table offset. */
7219 struct tu_abbrev_offset
7221 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7222 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7225 /* This is used when sorting. */
7226 bool operator< (const tu_abbrev_offset
&other
) const
7228 return abbrev_offset
< other
.abbrev_offset
;
7231 signatured_type
*sig_type
;
7232 sect_offset abbrev_offset
;
7235 /* Efficiently read all the type units.
7237 The efficiency is because we sort TUs by the abbrev table they use and
7238 only read each abbrev table once. In one program there are 200K TUs
7239 sharing 8K abbrev tables.
7241 The main purpose of this function is to support building the
7242 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7243 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7244 can collapse the search space by grouping them by stmt_list.
7245 The savings can be significant, in the same program from above the 200K TUs
7246 share 8K stmt_list tables.
7248 FUNC is expected to call get_type_unit_group, which will create the
7249 struct type_unit_group if necessary and add it to
7250 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7253 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7255 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7256 abbrev_table_up abbrev_table
;
7257 sect_offset abbrev_offset
;
7259 /* It's up to the caller to not call us multiple times. */
7260 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7262 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7265 /* TUs typically share abbrev tables, and there can be way more TUs than
7266 abbrev tables. Sort by abbrev table to reduce the number of times we
7267 read each abbrev table in.
7268 Alternatives are to punt or to maintain a cache of abbrev tables.
7269 This is simpler and efficient enough for now.
7271 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7272 symtab to use). Typically TUs with the same abbrev offset have the same
7273 stmt_list value too so in practice this should work well.
7275 The basic algorithm here is:
7277 sort TUs by abbrev table
7278 for each TU with same abbrev table:
7279 read abbrev table if first user
7280 read TU top level DIE
7281 [IWBN if DWO skeletons had DW_AT_stmt_list]
7284 dwarf_read_debug_printf ("Building type unit groups ...");
7286 /* Sort in a separate table to maintain the order of all_comp_units
7287 for .gdb_index: TU indices directly index all_type_units. */
7288 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7289 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7291 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7293 if (cu
->is_debug_types
)
7295 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7296 sorted_by_abbrev
.emplace_back
7297 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7298 sig_type
->sect_off
));
7302 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7304 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7306 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7308 /* Switch to the next abbrev table if necessary. */
7309 if (abbrev_table
== NULL
7310 || tu
.abbrev_offset
!= abbrev_offset
)
7312 abbrev_offset
= tu
.abbrev_offset
;
7313 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7315 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7316 ++tu_stats
->nr_uniq_abbrev_tables
;
7319 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7320 abbrev_table
.get (), nullptr, false);
7321 if (!reader
.dummy_p
)
7322 build_type_psymtabs_reader (&reader
);
7326 /* Print collected type unit statistics. */
7329 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7331 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7333 dwarf_read_debug_printf ("Type unit statistics:");
7334 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7335 dwarf_read_debug_printf (" %d uniq abbrev tables",
7336 tu_stats
->nr_uniq_abbrev_tables
);
7337 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7338 tu_stats
->nr_symtabs
);
7339 dwarf_read_debug_printf (" %d symtab sharers",
7340 tu_stats
->nr_symtab_sharers
);
7341 dwarf_read_debug_printf (" %d type units without a stmt_list",
7342 tu_stats
->nr_stmt_less_type_units
);
7343 dwarf_read_debug_printf (" %d all_type_units reallocs",
7344 tu_stats
->nr_all_type_units_reallocs
);
7347 /* Traversal function for build_type_psymtabs. */
7350 build_type_psymtab_dependencies (void **slot
, void *info
)
7352 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7353 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7354 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7355 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7356 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7359 gdb_assert (len
> 0);
7360 gdb_assert (tu_group
->type_unit_group_p ());
7362 pst
->number_of_dependencies
= len
;
7363 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7364 for (i
= 0; i
< len
; ++i
)
7366 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7367 gdb_assert (iter
->is_debug_types
);
7368 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7369 iter
->type_unit_group
= tu_group
;
7372 delete tu_group
->tus
;
7373 tu_group
->tus
= nullptr;
7378 /* Traversal function for process_skeletonless_type_unit.
7379 Read a TU in a DWO file and build partial symbols for it. */
7382 process_skeletonless_type_unit (void **slot
, void *info
)
7384 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7385 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7387 /* If this TU doesn't exist in the global table, add it and read it in. */
7389 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7390 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7392 signatured_type
find_entry (dwo_unit
->signature
);
7393 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7394 &find_entry
, INSERT
);
7395 /* If we've already seen this type there's nothing to do. What's happening
7396 is we're doing our own version of comdat-folding here. */
7400 /* This does the job that create_all_comp_units would have done for
7402 signatured_type
*entry
7403 = add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7404 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7407 /* This does the job that build_type_psymtabs would have done. */
7408 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7409 if (!reader
.dummy_p
)
7410 build_type_psymtabs_reader (&reader
);
7415 /* Traversal function for process_skeletonless_type_units. */
7418 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7420 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7422 if (dwo_file
->tus
!= NULL
)
7423 htab_traverse_noresize (dwo_file
->tus
.get (),
7424 process_skeletonless_type_unit
, info
);
7429 /* Scan all TUs of DWO files, verifying we've processed them.
7430 This is needed in case a TU was emitted without its skeleton.
7431 Note: This can't be done until we know what all the DWO files are. */
7434 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7436 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7437 if (get_dwp_file (per_objfile
) == NULL
7438 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7440 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7441 process_dwo_file_for_skeletonless_type_units
,
7446 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7449 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7451 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7453 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7458 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7460 /* Set the 'user' field only if it is not already set. */
7461 if (pst
->dependencies
[j
]->user
== NULL
)
7462 pst
->dependencies
[j
]->user
= pst
;
7467 /* Build the partial symbol table by doing a quick pass through the
7468 .debug_info and .debug_abbrev sections. */
7471 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7473 struct objfile
*objfile
= per_objfile
->objfile
;
7474 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7476 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7477 objfile_name (objfile
));
7479 scoped_restore restore_reading_psyms
7480 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7482 per_bfd
->info
.read (objfile
);
7484 /* Any cached compilation units will be linked by the per-objfile
7485 read_in_chain. Make sure to free them when we're done. */
7486 free_cached_comp_units
freer (per_objfile
);
7488 create_all_comp_units (per_objfile
);
7489 build_type_psymtabs (per_objfile
);
7491 /* Create a temporary address map on a temporary obstack. We later
7492 copy this to the final obstack. */
7493 auto_obstack temp_obstack
;
7495 scoped_restore save_psymtabs_addrmap
7496 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7497 addrmap_create_mutable (&temp_obstack
));
7499 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7501 if (per_cu
->v
.psymtab
!= NULL
)
7502 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7504 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7508 /* This has to wait until we read the CUs, we need the list of DWOs. */
7509 process_skeletonless_type_units (per_objfile
);
7511 /* Now that all TUs have been processed we can fill in the dependencies. */
7512 if (per_bfd
->type_unit_groups
!= NULL
)
7514 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7515 build_type_psymtab_dependencies
, per_objfile
);
7518 if (dwarf_read_debug
> 0)
7519 print_tu_stats (per_objfile
);
7521 set_partial_user (per_objfile
);
7523 per_bfd
->partial_symtabs
->psymtabs_addrmap
7524 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7525 per_bfd
->partial_symtabs
->obstack ());
7526 /* At this point we want to keep the address map. */
7527 save_psymtabs_addrmap
.release ();
7529 dwarf_read_debug_printf ("Done building psymtabs of %s",
7530 objfile_name (objfile
));
7533 /* Load the partial DIEs for a secondary CU into memory.
7534 This is also used when rereading a primary CU with load_all_dies. */
7537 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7538 dwarf2_per_objfile
*per_objfile
,
7539 dwarf2_cu
*existing_cu
)
7541 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7543 if (!reader
.dummy_p
)
7545 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7548 /* Check if comp unit has_children.
7549 If so, read the rest of the partial symbols from this comp unit.
7550 If not, there's no more debug_info for this comp unit. */
7551 if (reader
.comp_unit_die
->has_children
)
7552 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7559 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7560 struct dwarf2_section_info
*section
,
7561 struct dwarf2_section_info
*abbrev_section
,
7562 unsigned int is_dwz
,
7563 htab_up
&types_htab
,
7564 rcuh_kind section_kind
)
7566 const gdb_byte
*info_ptr
;
7567 struct objfile
*objfile
= per_objfile
->objfile
;
7569 dwarf_read_debug_printf ("Reading %s for %s",
7570 section
->get_name (),
7571 section
->get_file_name ());
7573 section
->read (objfile
);
7575 info_ptr
= section
->buffer
;
7577 while (info_ptr
< section
->buffer
+ section
->size
)
7579 dwarf2_per_cu_data_up this_cu
;
7581 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7583 comp_unit_head cu_header
;
7584 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7585 abbrev_section
, info_ptr
,
7588 /* Save the compilation unit for later lookup. */
7589 if (cu_header
.unit_type
!= DW_UT_type
)
7590 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7593 if (types_htab
== nullptr)
7594 types_htab
= allocate_signatured_type_table ();
7596 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7597 (cu_header
.signature
);
7598 signatured_type
*sig_ptr
= sig_type
.get ();
7599 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7600 this_cu
.reset (sig_type
.release ());
7602 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7603 gdb_assert (slot
!= nullptr);
7604 if (*slot
!= nullptr)
7605 complaint (_("debug type entry at offset %s is duplicate to"
7606 " the entry at offset %s, signature %s"),
7607 sect_offset_str (sect_off
),
7608 sect_offset_str (sig_ptr
->sect_off
),
7609 hex_string (sig_ptr
->signature
));
7612 this_cu
->sect_off
= sect_off
;
7613 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7614 this_cu
->is_dwz
= is_dwz
;
7615 this_cu
->section
= section
;
7617 info_ptr
= info_ptr
+ this_cu
->length
;
7618 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7622 /* Create a list of all compilation units in OBJFILE.
7623 This is only done for -readnow and building partial symtabs. */
7626 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7630 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7631 &per_objfile
->per_bfd
->abbrev
, 0,
7632 types_htab
, rcuh_kind::COMPILE
);
7633 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7634 read_comp_units_from_section (per_objfile
, §ion
,
7635 &per_objfile
->per_bfd
->abbrev
, 0,
7636 types_htab
, rcuh_kind::TYPE
);
7638 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7640 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7641 types_htab
, rcuh_kind::COMPILE
);
7643 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7646 /* Process all loaded DIEs for compilation unit CU, starting at
7647 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7648 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7649 DW_AT_ranges). See the comments of add_partial_subprogram on how
7650 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7653 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7654 CORE_ADDR
*highpc
, int set_addrmap
,
7655 struct dwarf2_cu
*cu
)
7657 struct partial_die_info
*pdi
;
7659 /* Now, march along the PDI's, descending into ones which have
7660 interesting children but skipping the children of the other ones,
7661 until we reach the end of the compilation unit. */
7669 /* Anonymous namespaces or modules have no name but have interesting
7670 children, so we need to look at them. Ditto for anonymous
7673 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7674 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7675 || pdi
->tag
== DW_TAG_imported_unit
7676 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7680 case DW_TAG_subprogram
:
7681 case DW_TAG_inlined_subroutine
:
7682 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7683 if (cu
->per_cu
->lang
== language_cplus
)
7684 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7687 case DW_TAG_constant
:
7688 case DW_TAG_variable
:
7689 case DW_TAG_typedef
:
7690 case DW_TAG_union_type
:
7691 if (!pdi
->is_declaration
7692 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7694 add_partial_symbol (pdi
, cu
);
7697 case DW_TAG_class_type
:
7698 case DW_TAG_interface_type
:
7699 case DW_TAG_structure_type
:
7700 if (!pdi
->is_declaration
)
7702 add_partial_symbol (pdi
, cu
);
7704 if ((cu
->per_cu
->lang
== language_rust
7705 || cu
->per_cu
->lang
== language_cplus
)
7706 && pdi
->has_children
)
7707 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7710 case DW_TAG_enumeration_type
:
7711 if (!pdi
->is_declaration
)
7712 add_partial_enumeration (pdi
, cu
);
7714 case DW_TAG_base_type
:
7715 case DW_TAG_generic_subrange
:
7716 case DW_TAG_subrange_type
:
7717 /* File scope base type definitions are added to the partial
7719 add_partial_symbol (pdi
, cu
);
7721 case DW_TAG_namespace
:
7722 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7725 if (!pdi
->is_declaration
)
7726 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7728 case DW_TAG_imported_unit
:
7730 struct dwarf2_per_cu_data
*per_cu
;
7732 /* For now we don't handle imported units in type units. */
7733 if (cu
->per_cu
->is_debug_types
)
7735 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7736 " supported in type units [in module %s]"),
7737 objfile_name (cu
->per_objfile
->objfile
));
7740 per_cu
= dwarf2_find_containing_comp_unit
7741 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7742 cu
->per_objfile
->per_bfd
);
7744 /* Go read the partial unit, if needed. */
7745 if (per_cu
->v
.psymtab
== NULL
)
7746 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7749 if (pdi
->die_parent
== nullptr
7750 && per_cu
->unit_type
== DW_UT_compile
7751 && per_cu
->lang
== language_cplus
)
7752 /* Regard import as hint. See corresponding code in
7753 process_imported_unit_die. */
7756 cu
->per_cu
->imported_symtabs_push (per_cu
);
7759 case DW_TAG_imported_declaration
:
7760 add_partial_symbol (pdi
, cu
);
7767 /* If the die has a sibling, skip to the sibling. */
7769 pdi
= pdi
->die_sibling
;
7773 /* Functions used to compute the fully scoped name of a partial DIE.
7775 Normally, this is simple. For C++, the parent DIE's fully scoped
7776 name is concatenated with "::" and the partial DIE's name.
7777 Enumerators are an exception; they use the scope of their parent
7778 enumeration type, i.e. the name of the enumeration type is not
7779 prepended to the enumerator.
7781 There are two complexities. One is DW_AT_specification; in this
7782 case "parent" means the parent of the target of the specification,
7783 instead of the direct parent of the DIE. The other is compilers
7784 which do not emit DW_TAG_namespace; in this case we try to guess
7785 the fully qualified name of structure types from their members'
7786 linkage names. This must be done using the DIE's children rather
7787 than the children of any DW_AT_specification target. We only need
7788 to do this for structures at the top level, i.e. if the target of
7789 any DW_AT_specification (if any; otherwise the DIE itself) does not
7792 /* Compute the scope prefix associated with PDI's parent, in
7793 compilation unit CU. The result will be allocated on CU's
7794 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7795 field. NULL is returned if no prefix is necessary. */
7797 partial_die_parent_scope (struct partial_die_info
*pdi
,
7798 struct dwarf2_cu
*cu
)
7800 const char *grandparent_scope
;
7801 struct partial_die_info
*parent
, *real_pdi
;
7803 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7804 then this means the parent of the specification DIE. */
7807 while (real_pdi
->has_specification
)
7809 auto res
= find_partial_die (real_pdi
->spec_offset
,
7810 real_pdi
->spec_is_dwz
, cu
);
7815 parent
= real_pdi
->die_parent
;
7819 if (parent
->scope_set
)
7820 return parent
->scope
;
7824 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7826 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7827 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7828 Work around this problem here. */
7829 if (cu
->per_cu
->lang
== language_cplus
7830 && parent
->tag
== DW_TAG_namespace
7831 && strcmp (parent
->name (cu
), "::") == 0
7832 && grandparent_scope
== NULL
)
7834 parent
->scope
= NULL
;
7835 parent
->scope_set
= 1;
7839 /* Nested subroutines in Fortran get a prefix. */
7840 if (pdi
->tag
== DW_TAG_enumerator
)
7841 /* Enumerators should not get the name of the enumeration as a prefix. */
7842 parent
->scope
= grandparent_scope
;
7843 else if (parent
->tag
== DW_TAG_namespace
7844 || parent
->tag
== DW_TAG_module
7845 || parent
->tag
== DW_TAG_structure_type
7846 || parent
->tag
== DW_TAG_class_type
7847 || parent
->tag
== DW_TAG_interface_type
7848 || parent
->tag
== DW_TAG_union_type
7849 || parent
->tag
== DW_TAG_enumeration_type
7850 || (cu
->per_cu
->lang
== language_fortran
7851 && parent
->tag
== DW_TAG_subprogram
7852 && pdi
->tag
== DW_TAG_subprogram
))
7854 if (grandparent_scope
== NULL
)
7855 parent
->scope
= parent
->name (cu
);
7857 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7859 parent
->name (cu
), 0, cu
);
7863 /* FIXME drow/2004-04-01: What should we be doing with
7864 function-local names? For partial symbols, we should probably be
7866 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7867 dwarf_tag_name (parent
->tag
),
7868 sect_offset_str (pdi
->sect_off
));
7869 parent
->scope
= grandparent_scope
;
7872 parent
->scope_set
= 1;
7873 return parent
->scope
;
7876 /* Return the fully scoped name associated with PDI, from compilation unit
7877 CU. The result will be allocated with malloc. */
7879 static gdb::unique_xmalloc_ptr
<char>
7880 partial_die_full_name (struct partial_die_info
*pdi
,
7881 struct dwarf2_cu
*cu
)
7883 const char *parent_scope
;
7885 /* If this is a template instantiation, we can not work out the
7886 template arguments from partial DIEs. So, unfortunately, we have
7887 to go through the full DIEs. At least any work we do building
7888 types here will be reused if full symbols are loaded later. */
7889 if (pdi
->has_template_arguments
)
7893 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7895 struct die_info
*die
;
7896 struct attribute attr
;
7897 struct dwarf2_cu
*ref_cu
= cu
;
7899 /* DW_FORM_ref_addr is using section offset. */
7900 attr
.name
= (enum dwarf_attribute
) 0;
7901 attr
.form
= DW_FORM_ref_addr
;
7902 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7903 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7905 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7909 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7910 if (parent_scope
== NULL
)
7913 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7919 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7921 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7922 struct objfile
*objfile
= per_objfile
->objfile
;
7923 struct gdbarch
*gdbarch
= objfile
->arch ();
7925 const char *actual_name
= NULL
;
7928 baseaddr
= objfile
->text_section_offset ();
7930 gdb::unique_xmalloc_ptr
<char> built_actual_name
7931 = partial_die_full_name (pdi
, cu
);
7932 if (built_actual_name
!= NULL
)
7933 actual_name
= built_actual_name
.get ();
7935 if (actual_name
== NULL
)
7936 actual_name
= pdi
->name (cu
);
7938 partial_symbol psymbol
;
7939 memset (&psymbol
, 0, sizeof (psymbol
));
7940 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
7941 &objfile
->objfile_obstack
);
7942 psymbol
.ginfo
.set_section_index (-1);
7944 /* The code below indicates that the psymbol should be installed by
7946 gdb::optional
<psymbol_placement
> where
;
7950 case DW_TAG_inlined_subroutine
:
7951 case DW_TAG_subprogram
:
7952 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7954 if (pdi
->is_external
7955 || cu
->per_cu
->lang
== language_ada
7956 || (cu
->per_cu
->lang
== language_fortran
7957 && pdi
->die_parent
!= NULL
7958 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7960 /* Normally, only "external" DIEs are part of the global scope.
7961 But in Ada and Fortran, we want to be able to access nested
7962 procedures globally. So all Ada and Fortran subprograms are
7963 stored in the global scope. */
7964 where
= psymbol_placement::GLOBAL
;
7967 where
= psymbol_placement::STATIC
;
7969 psymbol
.domain
= VAR_DOMAIN
;
7970 psymbol
.aclass
= LOC_BLOCK
;
7971 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7972 psymbol
.ginfo
.set_value_address (addr
);
7974 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7975 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
7977 case DW_TAG_constant
:
7978 psymbol
.domain
= VAR_DOMAIN
;
7979 psymbol
.aclass
= LOC_STATIC
;
7980 where
= (pdi
->is_external
7981 ? psymbol_placement::GLOBAL
7982 : psymbol_placement::STATIC
);
7984 case DW_TAG_variable
:
7986 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7990 && !per_objfile
->per_bfd
->has_section_at_zero
)
7992 /* A global or static variable may also have been stripped
7993 out by the linker if unused, in which case its address
7994 will be nullified; do not add such variables into partial
7995 symbol table then. */
7997 else if (pdi
->is_external
)
8000 Don't enter into the minimal symbol tables as there is
8001 a minimal symbol table entry from the ELF symbols already.
8002 Enter into partial symbol table if it has a location
8003 descriptor or a type.
8004 If the location descriptor is missing, new_symbol will create
8005 a LOC_UNRESOLVED symbol, the address of the variable will then
8006 be determined from the minimal symbol table whenever the variable
8008 The address for the partial symbol table entry is not
8009 used by GDB, but it comes in handy for debugging partial symbol
8012 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8014 psymbol
.domain
= VAR_DOMAIN
;
8015 psymbol
.aclass
= LOC_STATIC
;
8016 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8017 psymbol
.ginfo
.set_value_address (addr
);
8018 where
= psymbol_placement::GLOBAL
;
8023 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8025 /* Static Variable. Skip symbols whose value we cannot know (those
8026 without location descriptors or constant values). */
8027 if (!has_loc
&& !pdi
->has_const_value
)
8030 psymbol
.domain
= VAR_DOMAIN
;
8031 psymbol
.aclass
= LOC_STATIC
;
8032 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8034 psymbol
.ginfo
.set_value_address (addr
);
8035 where
= psymbol_placement::STATIC
;
8038 case DW_TAG_array_type
:
8039 case DW_TAG_typedef
:
8040 case DW_TAG_base_type
:
8041 case DW_TAG_subrange_type
:
8042 case DW_TAG_generic_subrange
:
8043 psymbol
.domain
= VAR_DOMAIN
;
8044 psymbol
.aclass
= LOC_TYPEDEF
;
8045 where
= psymbol_placement::STATIC
;
8047 case DW_TAG_imported_declaration
:
8048 case DW_TAG_namespace
:
8049 psymbol
.domain
= VAR_DOMAIN
;
8050 psymbol
.aclass
= LOC_TYPEDEF
;
8051 where
= psymbol_placement::GLOBAL
;
8054 /* With Fortran 77 there might be a "BLOCK DATA" module
8055 available without any name. If so, we skip the module as it
8056 doesn't bring any value. */
8057 if (actual_name
!= nullptr)
8059 psymbol
.domain
= MODULE_DOMAIN
;
8060 psymbol
.aclass
= LOC_TYPEDEF
;
8061 where
= psymbol_placement::GLOBAL
;
8064 case DW_TAG_class_type
:
8065 case DW_TAG_interface_type
:
8066 case DW_TAG_structure_type
:
8067 case DW_TAG_union_type
:
8068 case DW_TAG_enumeration_type
:
8069 /* Skip external references. The DWARF standard says in the section
8070 about "Structure, Union, and Class Type Entries": "An incomplete
8071 structure, union or class type is represented by a structure,
8072 union or class entry that does not have a byte size attribute
8073 and that has a DW_AT_declaration attribute." */
8074 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8077 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8078 static vs. global. */
8079 psymbol
.domain
= STRUCT_DOMAIN
;
8080 psymbol
.aclass
= LOC_TYPEDEF
;
8081 where
= (cu
->per_cu
->lang
== language_cplus
8082 ? psymbol_placement::GLOBAL
8083 : psymbol_placement::STATIC
);
8085 case DW_TAG_enumerator
:
8086 psymbol
.domain
= VAR_DOMAIN
;
8087 psymbol
.aclass
= LOC_CONST
;
8088 where
= (cu
->per_cu
->lang
== language_cplus
8089 ? psymbol_placement::GLOBAL
8090 : psymbol_placement::STATIC
);
8096 if (where
.has_value ())
8098 if (built_actual_name
!= nullptr)
8099 actual_name
= objfile
->intern (actual_name
);
8100 if (pdi
->linkage_name
== nullptr
8101 || cu
->per_cu
->lang
== language_ada
)
8102 psymbol
.ginfo
.set_linkage_name (actual_name
);
8105 psymbol
.ginfo
.set_demangled_name (actual_name
,
8106 &objfile
->objfile_obstack
);
8107 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8109 cu
->per_cu
->v
.psymtab
->add_psymbol
8110 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8115 /* Read a partial die corresponding to a namespace; also, add a symbol
8116 corresponding to that namespace to the symbol table. NAMESPACE is
8117 the name of the enclosing namespace. */
8120 add_partial_namespace (struct partial_die_info
*pdi
,
8121 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8122 int set_addrmap
, struct dwarf2_cu
*cu
)
8124 /* Add a symbol for the namespace. */
8126 add_partial_symbol (pdi
, cu
);
8128 /* Now scan partial symbols in that namespace. */
8130 if (pdi
->has_children
)
8131 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8134 /* Read a partial die corresponding to a Fortran module. */
8137 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8138 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8140 /* Add a symbol for the namespace. */
8142 add_partial_symbol (pdi
, cu
);
8144 /* Now scan partial symbols in that module. */
8146 if (pdi
->has_children
)
8147 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8150 static int dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
8151 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
8152 addrmap
*map
, void *datum
, dwarf_tag tag
);
8154 /* Read a partial die corresponding to a subprogram or an inlined
8155 subprogram and create a partial symbol for that subprogram.
8156 When the CU language allows it, this routine also defines a partial
8157 symbol for each nested subprogram that this subprogram contains.
8158 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8159 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8161 PDI may also be a lexical block, in which case we simply search
8162 recursively for subprograms defined inside that lexical block.
8163 Again, this is only performed when the CU language allows this
8164 type of definitions. */
8167 add_partial_subprogram (struct partial_die_info
*pdi
,
8168 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8169 int set_addrmap
, struct dwarf2_cu
*cu
)
8171 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8173 if (pdi
->has_pc_info
)
8175 if (pdi
->lowpc
< *lowpc
)
8176 *lowpc
= pdi
->lowpc
;
8177 if (pdi
->highpc
> *highpc
)
8178 *highpc
= pdi
->highpc
;
8181 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8182 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8183 struct gdbarch
*gdbarch
= objfile
->arch ();
8185 CORE_ADDR this_highpc
;
8186 CORE_ADDR this_lowpc
;
8188 baseaddr
= objfile
->text_section_offset ();
8190 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8191 pdi
->lowpc
+ baseaddr
)
8194 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8195 pdi
->highpc
+ baseaddr
)
8197 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8198 this_lowpc
, this_highpc
- 1,
8199 cu
->per_cu
->v
.psymtab
);
8203 if (pdi
->has_range_info
8204 && dwarf2_ranges_read (pdi
->ranges_offset
, &pdi
->lowpc
, &pdi
->highpc
,
8207 ? cu
->per_objfile
->per_bfd
->partial_symtabs
->psymtabs_addrmap
8209 set_addrmap
? cu
->per_cu
->v
.psymtab
: nullptr,
8212 if (pdi
->lowpc
< *lowpc
)
8213 *lowpc
= pdi
->lowpc
;
8214 if (pdi
->highpc
> *highpc
)
8215 *highpc
= pdi
->highpc
;
8218 if (pdi
->has_pc_info
|| pdi
->has_range_info
8219 || (!pdi
->is_external
&& pdi
->may_be_inlined
))
8221 if (!pdi
->is_declaration
)
8222 /* Ignore subprogram DIEs that do not have a name, they are
8223 illegal. Do not emit a complaint at this point, we will
8224 do so when we convert this psymtab into a symtab. */
8226 add_partial_symbol (pdi
, cu
);
8230 if (! pdi
->has_children
)
8233 if (cu
->per_cu
->lang
== language_ada
8234 || cu
->per_cu
->lang
== language_fortran
)
8236 pdi
= pdi
->die_child
;
8240 if (pdi
->tag
== DW_TAG_subprogram
8241 || pdi
->tag
== DW_TAG_inlined_subroutine
8242 || pdi
->tag
== DW_TAG_lexical_block
)
8243 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8244 pdi
= pdi
->die_sibling
;
8249 /* Read a partial die corresponding to an enumeration type. */
8252 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8253 struct dwarf2_cu
*cu
)
8255 struct partial_die_info
*pdi
;
8257 if (enum_pdi
->name (cu
) != NULL
)
8258 add_partial_symbol (enum_pdi
, cu
);
8260 pdi
= enum_pdi
->die_child
;
8263 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8264 complaint (_("malformed enumerator DIE ignored"));
8266 add_partial_symbol (pdi
, cu
);
8267 pdi
= pdi
->die_sibling
;
8271 /* Return the initial uleb128 in the die at INFO_PTR. */
8274 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8276 unsigned int bytes_read
;
8278 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8281 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8282 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8284 Return the corresponding abbrev, or NULL if the number is zero (indicating
8285 an empty DIE). In either case *BYTES_READ will be set to the length of
8286 the initial number. */
8288 static const struct abbrev_info
*
8289 peek_die_abbrev (const die_reader_specs
&reader
,
8290 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8292 dwarf2_cu
*cu
= reader
.cu
;
8293 bfd
*abfd
= reader
.abfd
;
8294 unsigned int abbrev_number
8295 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8297 if (abbrev_number
== 0)
8300 const abbrev_info
*abbrev
8301 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8304 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8305 " at offset %s [in module %s]"),
8306 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8307 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8313 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8314 Returns a pointer to the end of a series of DIEs, terminated by an empty
8315 DIE. Any children of the skipped DIEs will also be skipped. */
8317 static const gdb_byte
*
8318 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8322 unsigned int bytes_read
;
8323 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8327 return info_ptr
+ bytes_read
;
8329 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8333 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8334 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8335 abbrev corresponding to that skipped uleb128 should be passed in
8338 If DO_SKIP_CHILDREN is true, or if the DIE has no children, this
8339 returns a pointer to this DIE's sibling, skipping any children.
8340 Otherwise, returns a pointer to the DIE's first child. */
8342 static const gdb_byte
*
8343 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8344 const struct abbrev_info
*abbrev
, bool do_skip_children
)
8346 unsigned int bytes_read
;
8347 struct attribute attr
;
8348 bfd
*abfd
= reader
->abfd
;
8349 struct dwarf2_cu
*cu
= reader
->cu
;
8350 const gdb_byte
*buffer
= reader
->buffer
;
8351 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8352 unsigned int form
, i
;
8354 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8356 /* The only abbrev we care about is DW_AT_sibling. */
8357 if (do_skip_children
&& abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8359 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8360 if (attr
.form
== DW_FORM_ref_addr
)
8361 complaint (_("ignoring absolute DW_AT_sibling"));
8364 sect_offset off
= attr
.get_ref_die_offset ();
8365 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8367 if (sibling_ptr
< info_ptr
)
8368 complaint (_("DW_AT_sibling points backwards"));
8369 else if (sibling_ptr
> reader
->buffer_end
)
8370 reader
->die_section
->overflow_complaint ();
8376 /* If it isn't DW_AT_sibling, skip this attribute. */
8377 form
= abbrev
->attrs
[i
].form
;
8381 case DW_FORM_ref_addr
:
8382 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8383 and later it is offset sized. */
8384 if (cu
->header
.version
== 2)
8385 info_ptr
+= cu
->header
.addr_size
;
8387 info_ptr
+= cu
->header
.offset_size
;
8389 case DW_FORM_GNU_ref_alt
:
8390 info_ptr
+= cu
->header
.offset_size
;
8393 info_ptr
+= cu
->header
.addr_size
;
8401 case DW_FORM_flag_present
:
8402 case DW_FORM_implicit_const
:
8419 case DW_FORM_ref_sig8
:
8422 case DW_FORM_data16
:
8425 case DW_FORM_string
:
8426 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8427 info_ptr
+= bytes_read
;
8429 case DW_FORM_sec_offset
:
8431 case DW_FORM_GNU_strp_alt
:
8432 info_ptr
+= cu
->header
.offset_size
;
8434 case DW_FORM_exprloc
:
8436 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8437 info_ptr
+= bytes_read
;
8439 case DW_FORM_block1
:
8440 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8442 case DW_FORM_block2
:
8443 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8445 case DW_FORM_block4
:
8446 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8452 case DW_FORM_ref_udata
:
8453 case DW_FORM_GNU_addr_index
:
8454 case DW_FORM_GNU_str_index
:
8455 case DW_FORM_rnglistx
:
8456 case DW_FORM_loclistx
:
8457 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8459 case DW_FORM_indirect
:
8460 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8461 info_ptr
+= bytes_read
;
8462 /* We need to continue parsing from here, so just go back to
8464 goto skip_attribute
;
8467 error (_("Dwarf Error: Cannot handle %s "
8468 "in DWARF reader [in module %s]"),
8469 dwarf_form_name (form
),
8470 bfd_get_filename (abfd
));
8474 if (do_skip_children
&& abbrev
->has_children
)
8475 return skip_children (reader
, info_ptr
);
8480 /* Locate ORIG_PDI's sibling.
8481 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8483 static const gdb_byte
*
8484 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8485 struct partial_die_info
*orig_pdi
,
8486 const gdb_byte
*info_ptr
)
8488 /* Do we know the sibling already? */
8490 if (orig_pdi
->sibling
)
8491 return orig_pdi
->sibling
;
8493 /* Are there any children to deal with? */
8495 if (!orig_pdi
->has_children
)
8498 /* Skip the children the long way. */
8500 return skip_children (reader
, info_ptr
);
8503 /* Expand this partial symbol table into a full symbol table. SELF is
8507 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8509 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8511 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8513 /* If this psymtab is constructed from a debug-only objfile, the
8514 has_section_at_zero flag will not necessarily be correct. We
8515 can get the correct value for this flag by looking at the data
8516 associated with the (presumably stripped) associated objfile. */
8517 if (objfile
->separate_debug_objfile_backlink
)
8519 dwarf2_per_objfile
*per_objfile_backlink
8520 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8522 per_objfile
->per_bfd
->has_section_at_zero
8523 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8526 expand_psymtab (objfile
);
8528 process_cu_includes (per_objfile
);
8531 /* Reading in full CUs. */
8533 /* Add PER_CU to the queue. */
8536 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8537 dwarf2_per_objfile
*per_objfile
,
8538 enum language pretend_language
)
8542 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8543 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8546 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8548 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8551 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8552 DIEs, false otherwise.
8554 Explanation: there is an invariant that if a CU is queued for expansion
8555 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8556 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8557 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8558 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8559 invariant is respected.
8561 The caller is therefore not required to load the CU's DIEs (we return false)
8564 - the CU is already expanded, and therefore does not get enqueued
8565 - the CU gets enqueued for expansion, but its DIEs are already loaded
8567 Note that the caller should not use this function's return value as an
8568 indicator of whether the CU's DIEs are loaded right now, it should check
8569 that by calling `dwarf2_per_objfile::get_cu` instead. */
8572 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8573 dwarf2_per_cu_data
*per_cu
,
8574 dwarf2_per_objfile
*per_objfile
,
8575 enum language pretend_language
)
8577 /* We may arrive here during partial symbol reading, if we need full
8578 DIEs to process an unusual case (e.g. template arguments). Do
8579 not queue PER_CU, just tell our caller to load its DIEs. */
8580 if (per_cu
->per_bfd
->reading_partial_symbols
)
8582 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8584 if (cu
== NULL
|| cu
->dies
== NULL
)
8589 /* Mark the dependence relation so that we don't flush PER_CU
8591 if (dependent_cu
!= NULL
)
8592 dependent_cu
->add_dependence (per_cu
);
8594 /* If it's already on the queue, we have nothing to do. */
8597 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8599 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8601 /* If the CU is queued for expansion, it should not already be
8603 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8605 /* The DIEs are already loaded, the caller doesn't need to do it. */
8609 bool queued
= false;
8610 if (!per_objfile
->symtab_set_p (per_cu
))
8612 /* Add it to the queue. */
8613 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8617 /* If the compilation unit is already loaded, just mark it as
8619 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8623 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8624 and the DIEs are not already loaded. */
8625 return queued
&& cu
== nullptr;
8628 /* Process the queue. */
8631 process_queue (dwarf2_per_objfile
*per_objfile
)
8633 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8634 objfile_name (per_objfile
->objfile
));
8636 /* The queue starts out with one item, but following a DIE reference
8637 may load a new CU, adding it to the end of the queue. */
8638 while (!per_objfile
->per_bfd
->queue
->empty ())
8640 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8641 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8643 if (!per_objfile
->symtab_set_p (per_cu
))
8645 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8647 /* Skip dummy CUs. */
8650 unsigned int debug_print_threshold
;
8653 if (per_cu
->is_debug_types
)
8655 struct signatured_type
*sig_type
=
8656 (struct signatured_type
*) per_cu
;
8658 sprintf (buf
, "TU %s at offset %s",
8659 hex_string (sig_type
->signature
),
8660 sect_offset_str (per_cu
->sect_off
));
8661 /* There can be 100s of TUs.
8662 Only print them in verbose mode. */
8663 debug_print_threshold
= 2;
8667 sprintf (buf
, "CU at offset %s",
8668 sect_offset_str (per_cu
->sect_off
));
8669 debug_print_threshold
= 1;
8672 if (dwarf_read_debug
>= debug_print_threshold
)
8673 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8675 if (per_cu
->is_debug_types
)
8676 process_full_type_unit (cu
, item
.pretend_language
);
8678 process_full_comp_unit (cu
, item
.pretend_language
);
8680 if (dwarf_read_debug
>= debug_print_threshold
)
8681 dwarf_read_debug_printf ("Done expanding %s", buf
);
8686 per_objfile
->per_bfd
->queue
->pop ();
8689 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8690 objfile_name (per_objfile
->objfile
));
8693 /* Read in full symbols for PST, and anything it depends on. */
8696 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8698 gdb_assert (!readin_p (objfile
));
8700 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8701 free_cached_comp_units
freer (per_objfile
);
8702 expand_dependencies (objfile
);
8704 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8705 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8708 /* See psympriv.h. */
8711 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8713 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8714 return per_objfile
->symtab_set_p (per_cu_data
);
8717 /* See psympriv.h. */
8720 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8722 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8723 return per_objfile
->get_symtab (per_cu_data
);
8726 /* Trivial hash function for die_info: the hash value of a DIE
8727 is its offset in .debug_info for this objfile. */
8730 die_hash (const void *item
)
8732 const struct die_info
*die
= (const struct die_info
*) item
;
8734 return to_underlying (die
->sect_off
);
8737 /* Trivial comparison function for die_info structures: two DIEs
8738 are equal if they have the same offset. */
8741 die_eq (const void *item_lhs
, const void *item_rhs
)
8743 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8744 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8746 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8749 /* Load the DIEs associated with PER_CU into memory.
8751 In some cases, the caller, while reading partial symbols, will need to load
8752 the full symbols for the CU for some reason. It will already have a
8753 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8754 rather than creating a new one. */
8757 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8758 dwarf2_per_objfile
*per_objfile
,
8759 dwarf2_cu
*existing_cu
,
8761 enum language pretend_language
)
8763 gdb_assert (! this_cu
->is_debug_types
);
8765 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8769 struct dwarf2_cu
*cu
= reader
.cu
;
8770 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8772 gdb_assert (cu
->die_hash
== NULL
);
8774 htab_create_alloc_ex (cu
->header
.length
/ 12,
8778 &cu
->comp_unit_obstack
,
8779 hashtab_obstack_allocate
,
8780 dummy_obstack_deallocate
);
8782 if (reader
.comp_unit_die
->has_children
)
8783 reader
.comp_unit_die
->child
8784 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8785 &info_ptr
, reader
.comp_unit_die
);
8786 cu
->dies
= reader
.comp_unit_die
;
8787 /* comp_unit_die is not stored in die_hash, no need. */
8789 /* We try not to read any attributes in this function, because not
8790 all CUs needed for references have been loaded yet, and symbol
8791 table processing isn't initialized. But we have to set the CU language,
8792 or we won't be able to build types correctly.
8793 Similarly, if we do not read the producer, we can not apply
8794 producer-specific interpretation. */
8795 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8800 /* Add a DIE to the delayed physname list. */
8803 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8804 const char *name
, struct die_info
*die
,
8805 struct dwarf2_cu
*cu
)
8807 struct delayed_method_info mi
;
8809 mi
.fnfield_index
= fnfield_index
;
8813 cu
->method_list
.push_back (mi
);
8816 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8817 "const" / "volatile". If so, decrements LEN by the length of the
8818 modifier and return true. Otherwise return false. */
8822 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8824 size_t mod_len
= sizeof (mod
) - 1;
8825 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8833 /* Compute the physnames of any methods on the CU's method list.
8835 The computation of method physnames is delayed in order to avoid the
8836 (bad) condition that one of the method's formal parameters is of an as yet
8840 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8842 /* Only C++ delays computing physnames. */
8843 if (cu
->method_list
.empty ())
8845 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
8847 for (const delayed_method_info
&mi
: cu
->method_list
)
8849 const char *physname
;
8850 struct fn_fieldlist
*fn_flp
8851 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8852 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8853 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8854 = physname
? physname
: "";
8856 /* Since there's no tag to indicate whether a method is a
8857 const/volatile overload, extract that information out of the
8859 if (physname
!= NULL
)
8861 size_t len
= strlen (physname
);
8865 if (physname
[len
] == ')') /* shortcut */
8867 else if (check_modifier (physname
, len
, " const"))
8868 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8869 else if (check_modifier (physname
, len
, " volatile"))
8870 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8877 /* The list is no longer needed. */
8878 cu
->method_list
.clear ();
8881 /* Go objects should be embedded in a DW_TAG_module DIE,
8882 and it's not clear if/how imported objects will appear.
8883 To keep Go support simple until that's worked out,
8884 go back through what we've read and create something usable.
8885 We could do this while processing each DIE, and feels kinda cleaner,
8886 but that way is more invasive.
8887 This is to, for example, allow the user to type "p var" or "b main"
8888 without having to specify the package name, and allow lookups
8889 of module.object to work in contexts that use the expression
8893 fixup_go_packaging (struct dwarf2_cu
*cu
)
8895 gdb::unique_xmalloc_ptr
<char> package_name
;
8896 struct pending
*list
;
8899 for (list
= *cu
->get_builder ()->get_global_symbols ();
8903 for (i
= 0; i
< list
->nsyms
; ++i
)
8905 struct symbol
*sym
= list
->symbol
[i
];
8907 if (sym
->language () == language_go
8908 && sym
->aclass () == LOC_BLOCK
)
8910 gdb::unique_xmalloc_ptr
<char> this_package_name
8911 (go_symbol_package_name (sym
));
8913 if (this_package_name
== NULL
)
8915 if (package_name
== NULL
)
8916 package_name
= std::move (this_package_name
);
8919 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8920 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8921 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8922 (symbol_symtab (sym
) != NULL
8923 ? symtab_to_filename_for_display
8924 (symbol_symtab (sym
))
8925 : objfile_name (objfile
)),
8926 this_package_name
.get (), package_name
.get ());
8932 if (package_name
!= NULL
)
8934 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8935 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8936 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8937 saved_package_name
);
8940 sym
= new (&objfile
->objfile_obstack
) symbol
;
8941 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8942 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8943 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8944 e.g., "main" finds the "main" module and not C's main(). */
8945 sym
->set_domain (STRUCT_DOMAIN
);
8946 sym
->set_aclass_index (LOC_TYPEDEF
);
8947 sym
->set_type (type
);
8949 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8953 /* Allocate a fully-qualified name consisting of the two parts on the
8957 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8959 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8962 /* A helper that allocates a variant part to attach to a Rust enum
8963 type. OBSTACK is where the results should be allocated. TYPE is
8964 the type we're processing. DISCRIMINANT_INDEX is the index of the
8965 discriminant. It must be the index of one of the fields of TYPE,
8966 or -1 to mean there is no discriminant (univariant enum).
8967 DEFAULT_INDEX is the index of the default field; or -1 if there is
8968 no default. RANGES is indexed by "effective" field number (the
8969 field index, but omitting the discriminant and default fields) and
8970 must hold the discriminant values used by the variants. Note that
8971 RANGES must have a lifetime at least as long as OBSTACK -- either
8972 already allocated on it, or static. */
8975 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8976 int discriminant_index
, int default_index
,
8977 gdb::array_view
<discriminant_range
> ranges
)
8979 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8980 gdb_assert (discriminant_index
== -1
8981 || (discriminant_index
>= 0
8982 && discriminant_index
< type
->num_fields ()));
8983 gdb_assert (default_index
== -1
8984 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8986 /* We have one variant for each non-discriminant field. */
8987 int n_variants
= type
->num_fields ();
8988 if (discriminant_index
!= -1)
8991 variant
*variants
= new (obstack
) variant
[n_variants
];
8994 for (int i
= 0; i
< type
->num_fields (); ++i
)
8996 if (i
== discriminant_index
)
8999 variants
[var_idx
].first_field
= i
;
9000 variants
[var_idx
].last_field
= i
+ 1;
9002 /* The default field does not need a range, but other fields do.
9003 We skipped the discriminant above. */
9004 if (i
!= default_index
)
9006 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9013 gdb_assert (range_idx
== ranges
.size ());
9014 gdb_assert (var_idx
== n_variants
);
9016 variant_part
*part
= new (obstack
) variant_part
;
9017 part
->discriminant_index
= discriminant_index
;
9018 /* If there is no discriminant, then whether it is signed is of no
9021 = (discriminant_index
== -1
9023 : type
->field (discriminant_index
).type ()->is_unsigned ());
9024 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9026 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9027 gdb::array_view
<variant_part
> *prop_value
9028 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9030 struct dynamic_prop prop
;
9031 prop
.set_variant_parts (prop_value
);
9033 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9036 /* Some versions of rustc emitted enums in an unusual way.
9038 Ordinary enums were emitted as unions. The first element of each
9039 structure in the union was named "RUST$ENUM$DISR". This element
9040 held the discriminant.
9042 These versions of Rust also implemented the "non-zero"
9043 optimization. When the enum had two values, and one is empty and
9044 the other holds a pointer that cannot be zero, the pointer is used
9045 as the discriminant, with a zero value meaning the empty variant.
9046 Here, the union's first member is of the form
9047 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9048 where the fieldnos are the indices of the fields that should be
9049 traversed in order to find the field (which may be several fields deep)
9050 and the variantname is the name of the variant of the case when the
9053 This function recognizes whether TYPE is of one of these forms,
9054 and, if so, smashes it to be a variant type. */
9057 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9059 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9061 /* We don't need to deal with empty enums. */
9062 if (type
->num_fields () == 0)
9065 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9066 if (type
->num_fields () == 1
9067 && startswith (type
->field (0).name (), RUST_ENUM_PREFIX
))
9069 const char *name
= type
->field (0).name () + strlen (RUST_ENUM_PREFIX
);
9071 /* Decode the field name to find the offset of the
9073 ULONGEST bit_offset
= 0;
9074 struct type
*field_type
= type
->field (0).type ();
9075 while (name
[0] >= '0' && name
[0] <= '9')
9078 unsigned long index
= strtoul (name
, &tail
, 10);
9081 || index
>= field_type
->num_fields ()
9082 || (field_type
->field (index
).loc_kind ()
9083 != FIELD_LOC_KIND_BITPOS
))
9085 complaint (_("Could not parse Rust enum encoding string \"%s\""
9087 type
->field (0).name (),
9088 objfile_name (objfile
));
9093 bit_offset
+= field_type
->field (index
).loc_bitpos ();
9094 field_type
= field_type
->field (index
).type ();
9097 /* Smash this type to be a structure type. We have to do this
9098 because the type has already been recorded. */
9099 type
->set_code (TYPE_CODE_STRUCT
);
9100 type
->set_num_fields (3);
9101 /* Save the field we care about. */
9102 struct field saved_field
= type
->field (0);
9104 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9106 /* Put the discriminant at index 0. */
9107 type
->field (0).set_type (field_type
);
9108 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9109 type
->field (0).set_name ("<<discriminant>>");
9110 type
->field (0).set_loc_bitpos (bit_offset
);
9112 /* The order of fields doesn't really matter, so put the real
9113 field at index 1 and the data-less field at index 2. */
9114 type
->field (1) = saved_field
;
9115 type
->field (1).set_name
9116 (rust_last_path_segment (type
->field (1).type ()->name ()));
9117 type
->field (1).type ()->set_name
9118 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9119 type
->field (1).name ()));
9121 const char *dataless_name
9122 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9124 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9126 type
->field (2).set_type (dataless_type
);
9127 /* NAME points into the original discriminant name, which
9128 already has the correct lifetime. */
9129 type
->field (2).set_name (name
);
9130 type
->field (2).set_loc_bitpos (0);
9132 /* Indicate that this is a variant type. */
9133 static discriminant_range ranges
[1] = { { 0, 0 } };
9134 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9136 /* A union with a single anonymous field is probably an old-style
9138 else if (type
->num_fields () == 1 && streq (type
->field (0).name (), ""))
9140 /* Smash this type to be a structure type. We have to do this
9141 because the type has already been recorded. */
9142 type
->set_code (TYPE_CODE_STRUCT
);
9144 struct type
*field_type
= type
->field (0).type ();
9145 const char *variant_name
9146 = rust_last_path_segment (field_type
->name ());
9147 type
->field (0).set_name (variant_name
);
9148 field_type
->set_name
9149 (rust_fully_qualify (&objfile
->objfile_obstack
,
9150 type
->name (), variant_name
));
9152 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9156 struct type
*disr_type
= nullptr;
9157 for (int i
= 0; i
< type
->num_fields (); ++i
)
9159 disr_type
= type
->field (i
).type ();
9161 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9163 /* All fields of a true enum will be structs. */
9166 else if (disr_type
->num_fields () == 0)
9168 /* Could be data-less variant, so keep going. */
9169 disr_type
= nullptr;
9171 else if (strcmp (disr_type
->field (0).name (),
9172 "RUST$ENUM$DISR") != 0)
9174 /* Not a Rust enum. */
9184 /* If we got here without a discriminant, then it's probably
9186 if (disr_type
== nullptr)
9189 /* Smash this type to be a structure type. We have to do this
9190 because the type has already been recorded. */
9191 type
->set_code (TYPE_CODE_STRUCT
);
9193 /* Make space for the discriminant field. */
9194 struct field
*disr_field
= &disr_type
->field (0);
9196 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9197 * sizeof (struct field
)));
9198 memcpy (new_fields
+ 1, type
->fields (),
9199 type
->num_fields () * sizeof (struct field
));
9200 type
->set_fields (new_fields
);
9201 type
->set_num_fields (type
->num_fields () + 1);
9203 /* Install the discriminant at index 0 in the union. */
9204 type
->field (0) = *disr_field
;
9205 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9206 type
->field (0).set_name ("<<discriminant>>");
9208 /* We need a way to find the correct discriminant given a
9209 variant name. For convenience we build a map here. */
9210 struct type
*enum_type
= disr_field
->type ();
9211 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9212 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9214 if (enum_type
->field (i
).loc_kind () == FIELD_LOC_KIND_ENUMVAL
)
9217 = rust_last_path_segment (enum_type
->field (i
).name ());
9218 discriminant_map
[name
] = enum_type
->field (i
).loc_enumval ();
9222 int n_fields
= type
->num_fields ();
9223 /* We don't need a range entry for the discriminant, but we do
9224 need one for every other field, as there is no default
9226 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9229 /* Skip the discriminant here. */
9230 for (int i
= 1; i
< n_fields
; ++i
)
9232 /* Find the final word in the name of this variant's type.
9233 That name can be used to look up the correct
9235 const char *variant_name
9236 = rust_last_path_segment (type
->field (i
).type ()->name ());
9238 auto iter
= discriminant_map
.find (variant_name
);
9239 if (iter
!= discriminant_map
.end ())
9241 ranges
[i
- 1].low
= iter
->second
;
9242 ranges
[i
- 1].high
= iter
->second
;
9245 /* In Rust, each element should have the size of the
9247 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9249 /* Remove the discriminant field, if it exists. */
9250 struct type
*sub_type
= type
->field (i
).type ();
9251 if (sub_type
->num_fields () > 0)
9253 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9254 sub_type
->set_fields (sub_type
->fields () + 1);
9256 type
->field (i
).set_name (variant_name
);
9258 (rust_fully_qualify (&objfile
->objfile_obstack
,
9259 type
->name (), variant_name
));
9262 /* Indicate that this is a variant type. */
9263 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9264 gdb::array_view
<discriminant_range
> (ranges
,
9269 /* Rewrite some Rust unions to be structures with variants parts. */
9272 rust_union_quirks (struct dwarf2_cu
*cu
)
9274 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9275 for (type
*type_
: cu
->rust_unions
)
9276 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9277 /* We don't need this any more. */
9278 cu
->rust_unions
.clear ();
9283 type_unit_group_unshareable
*
9284 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9286 auto iter
= this->m_type_units
.find (tu_group
);
9287 if (iter
!= this->m_type_units
.end ())
9288 return iter
->second
.get ();
9290 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9291 type_unit_group_unshareable
*result
= uniq
.get ();
9292 this->m_type_units
[tu_group
] = std::move (uniq
);
9297 dwarf2_per_objfile::get_type_for_signatured_type
9298 (signatured_type
*sig_type
) const
9300 auto iter
= this->m_type_map
.find (sig_type
);
9301 if (iter
== this->m_type_map
.end ())
9304 return iter
->second
;
9307 void dwarf2_per_objfile::set_type_for_signatured_type
9308 (signatured_type
*sig_type
, struct type
*type
)
9310 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9312 this->m_type_map
[sig_type
] = type
;
9315 /* A helper function for computing the list of all symbol tables
9316 included by PER_CU. */
9319 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9320 htab_t all_children
, htab_t all_type_symtabs
,
9321 dwarf2_per_cu_data
*per_cu
,
9322 dwarf2_per_objfile
*per_objfile
,
9323 struct compunit_symtab
*immediate_parent
)
9325 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9328 /* This inclusion and its children have been processed. */
9334 /* Only add a CU if it has a symbol table. */
9335 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9338 /* If this is a type unit only add its symbol table if we haven't
9339 seen it yet (type unit per_cu's can share symtabs). */
9340 if (per_cu
->is_debug_types
)
9342 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9346 result
->push_back (cust
);
9347 if (cust
->user
== NULL
)
9348 cust
->user
= immediate_parent
;
9353 result
->push_back (cust
);
9354 if (cust
->user
== NULL
)
9355 cust
->user
= immediate_parent
;
9359 if (!per_cu
->imported_symtabs_empty ())
9360 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9362 recursively_compute_inclusions (result
, all_children
,
9363 all_type_symtabs
, ptr
, per_objfile
,
9368 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9372 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9373 dwarf2_per_objfile
*per_objfile
)
9375 gdb_assert (! per_cu
->is_debug_types
);
9377 if (!per_cu
->imported_symtabs_empty ())
9380 std::vector
<compunit_symtab
*> result_symtabs
;
9381 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9383 /* If we don't have a symtab, we can just skip this case. */
9387 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9389 NULL
, xcalloc
, xfree
));
9390 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9392 NULL
, xcalloc
, xfree
));
9394 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9396 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9397 all_type_symtabs
.get (), ptr
,
9401 /* Now we have a transitive closure of all the included symtabs. */
9402 len
= result_symtabs
.size ();
9404 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9405 struct compunit_symtab
*, len
+ 1);
9406 memcpy (cust
->includes
, result_symtabs
.data (),
9407 len
* sizeof (compunit_symtab
*));
9408 cust
->includes
[len
] = NULL
;
9412 /* Compute the 'includes' field for the symtabs of all the CUs we just
9416 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9418 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9420 if (! iter
->is_debug_types
)
9421 compute_compunit_symtab_includes (iter
, per_objfile
);
9424 per_objfile
->per_bfd
->just_read_cus
.clear ();
9427 /* Generate full symbol information for CU, whose DIEs have
9428 already been loaded into memory. */
9431 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9433 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9434 struct objfile
*objfile
= per_objfile
->objfile
;
9435 struct gdbarch
*gdbarch
= objfile
->arch ();
9436 CORE_ADDR lowpc
, highpc
;
9437 struct compunit_symtab
*cust
;
9439 struct block
*static_block
;
9442 baseaddr
= objfile
->text_section_offset ();
9444 /* Clear the list here in case something was left over. */
9445 cu
->method_list
.clear ();
9447 dwarf2_find_base_address (cu
->dies
, cu
);
9449 /* Before we start reading the top-level DIE, ensure it has a valid tag
9451 switch (cu
->dies
->tag
)
9453 case DW_TAG_compile_unit
:
9454 case DW_TAG_partial_unit
:
9455 case DW_TAG_type_unit
:
9458 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9459 dwarf_tag_name (cu
->dies
->tag
),
9460 sect_offset_str (cu
->per_cu
->sect_off
),
9461 objfile_name (per_objfile
->objfile
));
9464 /* Do line number decoding in read_file_scope () */
9465 process_die (cu
->dies
, cu
);
9467 /* For now fudge the Go package. */
9468 if (cu
->per_cu
->lang
== language_go
)
9469 fixup_go_packaging (cu
);
9471 /* Now that we have processed all the DIEs in the CU, all the types
9472 should be complete, and it should now be safe to compute all of the
9474 compute_delayed_physnames (cu
);
9476 if (cu
->per_cu
->lang
== language_rust
)
9477 rust_union_quirks (cu
);
9479 /* Some compilers don't define a DW_AT_high_pc attribute for the
9480 compilation unit. If the DW_AT_high_pc is missing, synthesize
9481 it, by scanning the DIE's below the compilation unit. */
9482 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9484 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9486 = cu
->get_builder ()->end_compunit_symtab_get_static_block (addr
, 0, 1);
9488 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9489 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9490 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9491 addrmap to help ensure it has an accurate map of pc values belonging to
9493 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9495 cust
= cu
->get_builder ()->end_compunit_symtab_from_static_block
9496 (static_block
, SECT_OFF_TEXT (objfile
), 0);
9500 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9502 /* Set symtab language to language from DW_AT_language. If the
9503 compilation is from a C file generated by language preprocessors, do
9504 not set the language if it was already deduced by start_subfile. */
9505 if (!(cu
->per_cu
->lang
== language_c
9506 && cust
->primary_filetab ()->language () != language_unknown
))
9507 cust
->primary_filetab ()->set_language (cu
->per_cu
->lang
);
9509 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9510 produce DW_AT_location with location lists but it can be possibly
9511 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9512 there were bugs in prologue debug info, fixed later in GCC-4.5
9513 by "unwind info for epilogues" patch (which is not directly related).
9515 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9516 needed, it would be wrong due to missing DW_AT_producer there.
9518 Still one can confuse GDB by using non-standard GCC compilation
9519 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9521 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9522 cust
->set_locations_valid (true);
9524 if (gcc_4_minor
>= 5)
9525 cust
->set_epilogue_unwind_valid (true);
9527 cust
->set_call_site_htab (cu
->call_site_htab
);
9530 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9532 /* Push it for inclusion processing later. */
9533 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9535 /* Not needed any more. */
9536 cu
->reset_builder ();
9539 /* Generate full symbol information for type unit CU, whose DIEs have
9540 already been loaded into memory. */
9543 process_full_type_unit (dwarf2_cu
*cu
,
9544 enum language pretend_language
)
9546 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9547 struct objfile
*objfile
= per_objfile
->objfile
;
9548 struct compunit_symtab
*cust
;
9549 struct signatured_type
*sig_type
;
9551 gdb_assert (cu
->per_cu
->is_debug_types
);
9552 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9554 /* Clear the list here in case something was left over. */
9555 cu
->method_list
.clear ();
9557 /* The symbol tables are set up in read_type_unit_scope. */
9558 process_die (cu
->dies
, cu
);
9560 /* For now fudge the Go package. */
9561 if (cu
->per_cu
->lang
== language_go
)
9562 fixup_go_packaging (cu
);
9564 /* Now that we have processed all the DIEs in the CU, all the types
9565 should be complete, and it should now be safe to compute all of the
9567 compute_delayed_physnames (cu
);
9569 if (cu
->per_cu
->lang
== language_rust
)
9570 rust_union_quirks (cu
);
9572 /* TUs share symbol tables.
9573 If this is the first TU to use this symtab, complete the construction
9574 of it with end_expandable_symtab. Otherwise, complete the addition of
9575 this TU's symbols to the existing symtab. */
9576 type_unit_group_unshareable
*tug_unshare
=
9577 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9578 if (tug_unshare
->compunit_symtab
== NULL
)
9580 buildsym_compunit
*builder
= cu
->get_builder ();
9581 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9582 tug_unshare
->compunit_symtab
= cust
;
9586 /* Set symtab language to language from DW_AT_language. If the
9587 compilation is from a C file generated by language preprocessors,
9588 do not set the language if it was already deduced by
9590 if (!(cu
->per_cu
->lang
== language_c
9591 && cust
->primary_filetab ()->language () != language_c
))
9592 cust
->primary_filetab ()->set_language (cu
->per_cu
->lang
);
9597 cu
->get_builder ()->augment_type_symtab ();
9598 cust
= tug_unshare
->compunit_symtab
;
9601 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9603 /* Not needed any more. */
9604 cu
->reset_builder ();
9607 /* Process an imported unit DIE. */
9610 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9612 struct attribute
*attr
;
9614 /* For now we don't handle imported units in type units. */
9615 if (cu
->per_cu
->is_debug_types
)
9617 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9618 " supported in type units [in module %s]"),
9619 objfile_name (cu
->per_objfile
->objfile
));
9622 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9625 sect_offset sect_off
= attr
->get_ref_die_offset ();
9626 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9627 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9628 dwarf2_per_cu_data
*per_cu
9629 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9630 per_objfile
->per_bfd
);
9632 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9633 into another compilation unit, at root level. Regard this as a hint,
9635 if (die
->parent
&& die
->parent
->parent
== NULL
9636 && per_cu
->unit_type
== DW_UT_compile
9637 && per_cu
->lang
== language_cplus
)
9640 /* If necessary, add it to the queue and load its DIEs. */
9641 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
9643 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9644 false, cu
->per_cu
->lang
);
9646 cu
->per_cu
->imported_symtabs_push (per_cu
);
9650 /* RAII object that represents a process_die scope: i.e.,
9651 starts/finishes processing a DIE. */
9652 class process_die_scope
9655 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9656 : m_die (die
), m_cu (cu
)
9658 /* We should only be processing DIEs not already in process. */
9659 gdb_assert (!m_die
->in_process
);
9660 m_die
->in_process
= true;
9663 ~process_die_scope ()
9665 m_die
->in_process
= false;
9667 /* If we're done processing the DIE for the CU that owns the line
9668 header, we don't need the line header anymore. */
9669 if (m_cu
->line_header_die_owner
== m_die
)
9671 delete m_cu
->line_header
;
9672 m_cu
->line_header
= NULL
;
9673 m_cu
->line_header_die_owner
= NULL
;
9682 /* Process a die and its children. */
9685 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9687 process_die_scope
scope (die
, cu
);
9691 case DW_TAG_padding
:
9693 case DW_TAG_compile_unit
:
9694 case DW_TAG_partial_unit
:
9695 read_file_scope (die
, cu
);
9697 case DW_TAG_type_unit
:
9698 read_type_unit_scope (die
, cu
);
9700 case DW_TAG_subprogram
:
9701 /* Nested subprograms in Fortran get a prefix. */
9702 if (cu
->per_cu
->lang
== language_fortran
9703 && die
->parent
!= NULL
9704 && die
->parent
->tag
== DW_TAG_subprogram
)
9705 cu
->processing_has_namespace_info
= true;
9707 case DW_TAG_inlined_subroutine
:
9708 read_func_scope (die
, cu
);
9710 case DW_TAG_lexical_block
:
9711 case DW_TAG_try_block
:
9712 case DW_TAG_catch_block
:
9713 read_lexical_block_scope (die
, cu
);
9715 case DW_TAG_call_site
:
9716 case DW_TAG_GNU_call_site
:
9717 read_call_site_scope (die
, cu
);
9719 case DW_TAG_class_type
:
9720 case DW_TAG_interface_type
:
9721 case DW_TAG_structure_type
:
9722 case DW_TAG_union_type
:
9723 case DW_TAG_namelist
:
9724 process_structure_scope (die
, cu
);
9726 case DW_TAG_enumeration_type
:
9727 process_enumeration_scope (die
, cu
);
9730 /* These dies have a type, but processing them does not create
9731 a symbol or recurse to process the children. Therefore we can
9732 read them on-demand through read_type_die. */
9733 case DW_TAG_subroutine_type
:
9734 case DW_TAG_set_type
:
9735 case DW_TAG_pointer_type
:
9736 case DW_TAG_ptr_to_member_type
:
9737 case DW_TAG_reference_type
:
9738 case DW_TAG_rvalue_reference_type
:
9739 case DW_TAG_string_type
:
9742 case DW_TAG_array_type
:
9743 /* We only need to handle this case for Ada -- in other
9744 languages, it's normal for the compiler to emit a typedef
9746 if (cu
->per_cu
->lang
!= language_ada
)
9749 case DW_TAG_base_type
:
9750 case DW_TAG_subrange_type
:
9751 case DW_TAG_generic_subrange
:
9752 case DW_TAG_typedef
:
9753 /* Add a typedef symbol for the type definition, if it has a
9755 new_symbol (die
, read_type_die (die
, cu
), cu
);
9757 case DW_TAG_common_block
:
9758 read_common_block (die
, cu
);
9760 case DW_TAG_common_inclusion
:
9762 case DW_TAG_namespace
:
9763 cu
->processing_has_namespace_info
= true;
9764 read_namespace (die
, cu
);
9767 cu
->processing_has_namespace_info
= true;
9768 read_module (die
, cu
);
9770 case DW_TAG_imported_declaration
:
9771 cu
->processing_has_namespace_info
= true;
9772 if (read_namespace_alias (die
, cu
))
9774 /* The declaration is not a global namespace alias. */
9776 case DW_TAG_imported_module
:
9777 cu
->processing_has_namespace_info
= true;
9778 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9779 || cu
->per_cu
->lang
!= language_fortran
))
9780 complaint (_("Tag '%s' has unexpected children"),
9781 dwarf_tag_name (die
->tag
));
9782 read_import_statement (die
, cu
);
9785 case DW_TAG_imported_unit
:
9786 process_imported_unit_die (die
, cu
);
9789 case DW_TAG_variable
:
9790 read_variable (die
, cu
);
9794 new_symbol (die
, NULL
, cu
);
9799 /* DWARF name computation. */
9801 /* A helper function for dwarf2_compute_name which determines whether DIE
9802 needs to have the name of the scope prepended to the name listed in the
9806 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9808 struct attribute
*attr
;
9812 case DW_TAG_namespace
:
9813 case DW_TAG_typedef
:
9814 case DW_TAG_class_type
:
9815 case DW_TAG_interface_type
:
9816 case DW_TAG_structure_type
:
9817 case DW_TAG_union_type
:
9818 case DW_TAG_enumeration_type
:
9819 case DW_TAG_enumerator
:
9820 case DW_TAG_subprogram
:
9821 case DW_TAG_inlined_subroutine
:
9823 case DW_TAG_imported_declaration
:
9826 case DW_TAG_variable
:
9827 case DW_TAG_constant
:
9828 /* We only need to prefix "globally" visible variables. These include
9829 any variable marked with DW_AT_external or any variable that
9830 lives in a namespace. [Variables in anonymous namespaces
9831 require prefixing, but they are not DW_AT_external.] */
9833 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9835 struct dwarf2_cu
*spec_cu
= cu
;
9837 return die_needs_namespace (die_specification (die
, &spec_cu
),
9841 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9842 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9843 && die
->parent
->tag
!= DW_TAG_module
)
9845 /* A variable in a lexical block of some kind does not need a
9846 namespace, even though in C++ such variables may be external
9847 and have a mangled name. */
9848 if (die
->parent
->tag
== DW_TAG_lexical_block
9849 || die
->parent
->tag
== DW_TAG_try_block
9850 || die
->parent
->tag
== DW_TAG_catch_block
9851 || die
->parent
->tag
== DW_TAG_subprogram
)
9860 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9861 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9862 defined for the given DIE. */
9864 static struct attribute
*
9865 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9867 struct attribute
*attr
;
9869 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9871 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9876 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9877 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9878 defined for the given DIE. */
9881 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9883 const char *linkage_name
;
9885 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9886 if (linkage_name
== NULL
)
9887 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9889 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9890 See https://github.com/rust-lang/rust/issues/32925. */
9891 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
9892 && strchr (linkage_name
, '{') != NULL
)
9893 linkage_name
= NULL
;
9895 return linkage_name
;
9898 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9899 compute the physname for the object, which include a method's:
9900 - formal parameters (C++),
9901 - receiver type (Go),
9903 The term "physname" is a bit confusing.
9904 For C++, for example, it is the demangled name.
9905 For Go, for example, it's the mangled name.
9907 For Ada, return the DIE's linkage name rather than the fully qualified
9908 name. PHYSNAME is ignored..
9910 The result is allocated on the objfile->per_bfd's obstack and
9914 dwarf2_compute_name (const char *name
,
9915 struct die_info
*die
, struct dwarf2_cu
*cu
,
9918 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9921 name
= dwarf2_name (die
, cu
);
9923 enum language lang
= cu
->per_cu
->lang
;
9925 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9926 but otherwise compute it by typename_concat inside GDB.
9927 FIXME: Actually this is not really true, or at least not always true.
9928 It's all very confusing. compute_and_set_names doesn't try to demangle
9929 Fortran names because there is no mangling standard. So new_symbol
9930 will set the demangled name to the result of dwarf2_full_name, and it is
9931 the demangled name that GDB uses if it exists. */
9932 if (lang
== language_ada
9933 || (lang
== language_fortran
&& physname
))
9935 /* For Ada unit, we prefer the linkage name over the name, as
9936 the former contains the exported name, which the user expects
9937 to be able to reference. Ideally, we want the user to be able
9938 to reference this entity using either natural or linkage name,
9939 but we haven't started looking at this enhancement yet. */
9940 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9942 if (linkage_name
!= NULL
)
9943 return linkage_name
;
9946 /* These are the only languages we know how to qualify names in. */
9948 && (lang
== language_cplus
9949 || lang
== language_fortran
|| lang
== language_d
9950 || lang
== language_rust
))
9952 if (die_needs_namespace (die
, cu
))
9955 const char *canonical_name
= NULL
;
9959 prefix
= determine_prefix (die
, cu
);
9960 if (*prefix
!= '\0')
9962 gdb::unique_xmalloc_ptr
<char> prefixed_name
9963 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9965 buf
.puts (prefixed_name
.get ());
9970 /* Template parameters may be specified in the DIE's DW_AT_name, or
9971 as children with DW_TAG_template_type_param or
9972 DW_TAG_value_type_param. If the latter, add them to the name
9973 here. If the name already has template parameters, then
9974 skip this step; some versions of GCC emit both, and
9975 it is more efficient to use the pre-computed name.
9977 Something to keep in mind about this process: it is very
9978 unlikely, or in some cases downright impossible, to produce
9979 something that will match the mangled name of a function.
9980 If the definition of the function has the same debug info,
9981 we should be able to match up with it anyway. But fallbacks
9982 using the minimal symbol, for instance to find a method
9983 implemented in a stripped copy of libstdc++, will not work.
9984 If we do not have debug info for the definition, we will have to
9985 match them up some other way.
9987 When we do name matching there is a related problem with function
9988 templates; two instantiated function templates are allowed to
9989 differ only by their return types, which we do not add here. */
9991 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
9993 struct attribute
*attr
;
9994 struct die_info
*child
;
9997 die
->building_fullname
= 1;
9999 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10003 const gdb_byte
*bytes
;
10004 struct dwarf2_locexpr_baton
*baton
;
10007 if (child
->tag
!= DW_TAG_template_type_param
10008 && child
->tag
!= DW_TAG_template_value_param
)
10019 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10022 complaint (_("template parameter missing DW_AT_type"));
10023 buf
.puts ("UNKNOWN_TYPE");
10026 type
= die_type (child
, cu
);
10028 if (child
->tag
== DW_TAG_template_type_param
)
10030 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
10031 &type_print_raw_options
);
10035 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10038 complaint (_("template parameter missing "
10039 "DW_AT_const_value"));
10040 buf
.puts ("UNKNOWN_VALUE");
10044 dwarf2_const_value_attr (attr
, type
, name
,
10045 &cu
->comp_unit_obstack
, cu
,
10046 &value
, &bytes
, &baton
);
10048 if (type
->has_no_signedness ())
10049 /* GDB prints characters as NUMBER 'CHAR'. If that's
10050 changed, this can use value_print instead. */
10051 cu
->language_defn
->printchar (value
, type
, &buf
);
10054 struct value_print_options opts
;
10057 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10061 baton
->per_objfile
);
10062 else if (bytes
!= NULL
)
10064 v
= allocate_value (type
);
10065 memcpy (value_contents_writeable (v
).data (), bytes
,
10066 TYPE_LENGTH (type
));
10069 v
= value_from_longest (type
, value
);
10071 /* Specify decimal so that we do not depend on
10073 get_formatted_print_options (&opts
, 'd');
10075 value_print (v
, &buf
, &opts
);
10080 die
->building_fullname
= 0;
10084 /* Close the argument list, with a space if necessary
10085 (nested templates). */
10086 if (!buf
.empty () && buf
.string ().back () == '>')
10093 /* For C++ methods, append formal parameter type
10094 information, if PHYSNAME. */
10096 if (physname
&& die
->tag
== DW_TAG_subprogram
10097 && lang
== language_cplus
)
10099 struct type
*type
= read_type_die (die
, cu
);
10101 c_type_print_args (type
, &buf
, 1, lang
,
10102 &type_print_raw_options
);
10104 if (lang
== language_cplus
)
10106 /* Assume that an artificial first parameter is
10107 "this", but do not crash if it is not. RealView
10108 marks unnamed (and thus unused) parameters as
10109 artificial; there is no way to differentiate
10111 if (type
->num_fields () > 0
10112 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10113 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10114 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10115 buf
.puts (" const");
10119 const std::string
&intermediate_name
= buf
.string ();
10121 if (lang
== language_cplus
)
10123 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10126 /* If we only computed INTERMEDIATE_NAME, or if
10127 INTERMEDIATE_NAME is already canonical, then we need to
10129 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10130 name
= objfile
->intern (intermediate_name
);
10132 name
= canonical_name
;
10139 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10140 If scope qualifiers are appropriate they will be added. The result
10141 will be allocated on the storage_obstack, or NULL if the DIE does
10142 not have a name. NAME may either be from a previous call to
10143 dwarf2_name or NULL.
10145 The output string will be canonicalized (if C++). */
10147 static const char *
10148 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10150 return dwarf2_compute_name (name
, die
, cu
, 0);
10153 /* Construct a physname for the given DIE in CU. NAME may either be
10154 from a previous call to dwarf2_name or NULL. The result will be
10155 allocated on the objfile_objstack or NULL if the DIE does not have a
10158 The output string will be canonicalized (if C++). */
10160 static const char *
10161 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10163 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10164 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10167 /* In this case dwarf2_compute_name is just a shortcut not building anything
10169 if (!die_needs_namespace (die
, cu
))
10170 return dwarf2_compute_name (name
, die
, cu
, 1);
10172 if (cu
->per_cu
->lang
!= language_rust
)
10173 mangled
= dw2_linkage_name (die
, cu
);
10175 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10177 gdb::unique_xmalloc_ptr
<char> demangled
;
10178 if (mangled
!= NULL
)
10180 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10182 /* Do nothing (do not demangle the symbol name). */
10186 /* Use DMGL_RET_DROP for C++ template functions to suppress
10187 their return type. It is easier for GDB users to search
10188 for such functions as `name(params)' than `long name(params)'.
10189 In such case the minimal symbol names do not match the full
10190 symbol names but for template functions there is never a need
10191 to look up their definition from their declaration so
10192 the only disadvantage remains the minimal symbol variant
10193 `long name(params)' does not have the proper inferior type. */
10194 demangled
= gdb_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
10198 canon
= demangled
.get ();
10206 if (canon
== NULL
|| check_physname
)
10208 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10210 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10212 /* It may not mean a bug in GDB. The compiler could also
10213 compute DW_AT_linkage_name incorrectly. But in such case
10214 GDB would need to be bug-to-bug compatible. */
10216 complaint (_("Computed physname <%s> does not match demangled <%s> "
10217 "(from linkage <%s>) - DIE at %s [in module %s]"),
10218 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10219 objfile_name (objfile
));
10221 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10222 is available here - over computed PHYSNAME. It is safer
10223 against both buggy GDB and buggy compilers. */
10237 retval
= objfile
->intern (retval
);
10242 /* Inspect DIE in CU for a namespace alias. If one exists, record
10243 a new symbol for it.
10245 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10248 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10250 struct attribute
*attr
;
10252 /* If the die does not have a name, this is not a namespace
10254 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10258 struct die_info
*d
= die
;
10259 struct dwarf2_cu
*imported_cu
= cu
;
10261 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10262 keep inspecting DIEs until we hit the underlying import. */
10263 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10264 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10266 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10270 d
= follow_die_ref (d
, attr
, &imported_cu
);
10271 if (d
->tag
!= DW_TAG_imported_declaration
)
10275 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10277 complaint (_("DIE at %s has too many recursively imported "
10278 "declarations"), sect_offset_str (d
->sect_off
));
10285 sect_offset sect_off
= attr
->get_ref_die_offset ();
10287 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10288 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10290 /* This declaration is a global namespace alias. Add
10291 a symbol for it whose type is the aliased namespace. */
10292 new_symbol (die
, type
, cu
);
10301 /* Return the using directives repository (global or local?) to use in the
10302 current context for CU.
10304 For Ada, imported declarations can materialize renamings, which *may* be
10305 global. However it is impossible (for now?) in DWARF to distinguish
10306 "external" imported declarations and "static" ones. As all imported
10307 declarations seem to be static in all other languages, make them all CU-wide
10308 global only in Ada. */
10310 static struct using_direct
**
10311 using_directives (struct dwarf2_cu
*cu
)
10313 if (cu
->per_cu
->lang
== language_ada
10314 && cu
->get_builder ()->outermost_context_p ())
10315 return cu
->get_builder ()->get_global_using_directives ();
10317 return cu
->get_builder ()->get_local_using_directives ();
10320 /* Read the import statement specified by the given die and record it. */
10323 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10325 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10326 struct attribute
*import_attr
;
10327 struct die_info
*imported_die
, *child_die
;
10328 struct dwarf2_cu
*imported_cu
;
10329 const char *imported_name
;
10330 const char *imported_name_prefix
;
10331 const char *canonical_name
;
10332 const char *import_alias
;
10333 const char *imported_declaration
= NULL
;
10334 const char *import_prefix
;
10335 std::vector
<const char *> excludes
;
10337 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10338 if (import_attr
== NULL
)
10340 complaint (_("Tag '%s' has no DW_AT_import"),
10341 dwarf_tag_name (die
->tag
));
10346 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10347 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10348 if (imported_name
== NULL
)
10350 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10352 The import in the following code:
10366 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10367 <52> DW_AT_decl_file : 1
10368 <53> DW_AT_decl_line : 6
10369 <54> DW_AT_import : <0x75>
10370 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10371 <59> DW_AT_name : B
10372 <5b> DW_AT_decl_file : 1
10373 <5c> DW_AT_decl_line : 2
10374 <5d> DW_AT_type : <0x6e>
10376 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10377 <76> DW_AT_byte_size : 4
10378 <77> DW_AT_encoding : 5 (signed)
10380 imports the wrong die ( 0x75 instead of 0x58 ).
10381 This case will be ignored until the gcc bug is fixed. */
10385 /* Figure out the local name after import. */
10386 import_alias
= dwarf2_name (die
, cu
);
10388 /* Figure out where the statement is being imported to. */
10389 import_prefix
= determine_prefix (die
, cu
);
10391 /* Figure out what the scope of the imported die is and prepend it
10392 to the name of the imported die. */
10393 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10395 if (imported_die
->tag
!= DW_TAG_namespace
10396 && imported_die
->tag
!= DW_TAG_module
)
10398 imported_declaration
= imported_name
;
10399 canonical_name
= imported_name_prefix
;
10401 else if (strlen (imported_name_prefix
) > 0)
10402 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10403 imported_name_prefix
,
10404 (cu
->per_cu
->lang
== language_d
10407 imported_name
, (char *) NULL
);
10409 canonical_name
= imported_name
;
10411 if (die
->tag
== DW_TAG_imported_module
10412 && cu
->per_cu
->lang
== language_fortran
)
10413 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10414 child_die
= child_die
->sibling
)
10416 /* DWARF-4: A Fortran use statement with a “rename list” may be
10417 represented by an imported module entry with an import attribute
10418 referring to the module and owned entries corresponding to those
10419 entities that are renamed as part of being imported. */
10421 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10423 complaint (_("child DW_TAG_imported_declaration expected "
10424 "- DIE at %s [in module %s]"),
10425 sect_offset_str (child_die
->sect_off
),
10426 objfile_name (objfile
));
10430 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10431 if (import_attr
== NULL
)
10433 complaint (_("Tag '%s' has no DW_AT_import"),
10434 dwarf_tag_name (child_die
->tag
));
10439 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10441 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10442 if (imported_name
== NULL
)
10444 complaint (_("child DW_TAG_imported_declaration has unknown "
10445 "imported name - DIE at %s [in module %s]"),
10446 sect_offset_str (child_die
->sect_off
),
10447 objfile_name (objfile
));
10451 excludes
.push_back (imported_name
);
10453 process_die (child_die
, cu
);
10456 add_using_directive (using_directives (cu
),
10460 imported_declaration
,
10463 &objfile
->objfile_obstack
);
10466 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10467 types, but gives them a size of zero. Starting with version 14,
10468 ICC is compatible with GCC. */
10471 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10473 if (!cu
->checked_producer
)
10474 check_producer (cu
);
10476 return cu
->producer_is_icc_lt_14
;
10479 /* ICC generates a DW_AT_type for C void functions. This was observed on
10480 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10481 which says that void functions should not have a DW_AT_type. */
10484 producer_is_icc (struct dwarf2_cu
*cu
)
10486 if (!cu
->checked_producer
)
10487 check_producer (cu
);
10489 return cu
->producer_is_icc
;
10492 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10493 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10494 this, it was first present in GCC release 4.3.0. */
10497 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10499 if (!cu
->checked_producer
)
10500 check_producer (cu
);
10502 return cu
->producer_is_gcc_lt_4_3
;
10505 static file_and_directory
&
10506 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10508 if (cu
->per_cu
->fnd
!= nullptr)
10509 return *cu
->per_cu
->fnd
;
10511 /* Find the filename. Do not use dwarf2_name here, since the filename
10512 is not a source language identifier. */
10513 file_and_directory
res (dwarf2_string_attr (die
, DW_AT_name
, cu
),
10514 dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
));
10516 if (res
.get_comp_dir () == nullptr
10517 && producer_is_gcc_lt_4_3 (cu
)
10518 && res
.get_name () != nullptr
10519 && IS_ABSOLUTE_PATH (res
.get_name ()))
10520 res
.set_comp_dir (ldirname (res
.get_name ()));
10522 cu
->per_cu
->fnd
.reset (new file_and_directory (std::move (res
)));
10523 return *cu
->per_cu
->fnd
;
10526 /* Handle DW_AT_stmt_list for a compilation unit.
10527 DIE is the DW_TAG_compile_unit die for CU.
10528 COMP_DIR is the compilation directory. LOWPC is passed to
10529 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10532 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10533 const file_and_directory
&fnd
, CORE_ADDR lowpc
) /* ARI: editCase function */
10535 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10536 struct attribute
*attr
;
10537 struct line_header line_header_local
;
10538 hashval_t line_header_local_hash
;
10540 int decode_mapping
;
10542 gdb_assert (! cu
->per_cu
->is_debug_types
);
10544 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10545 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10548 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10550 /* The line header hash table is only created if needed (it exists to
10551 prevent redundant reading of the line table for partial_units).
10552 If we're given a partial_unit, we'll need it. If we're given a
10553 compile_unit, then use the line header hash table if it's already
10554 created, but don't create one just yet. */
10556 if (per_objfile
->line_header_hash
== NULL
10557 && die
->tag
== DW_TAG_partial_unit
)
10559 per_objfile
->line_header_hash
10560 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10561 line_header_eq_voidp
,
10562 htab_delete_entry
<line_header
>,
10566 line_header_local
.sect_off
= line_offset
;
10567 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10568 line_header_local_hash
= line_header_hash (&line_header_local
);
10569 if (per_objfile
->line_header_hash
!= NULL
)
10571 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10572 &line_header_local
,
10573 line_header_local_hash
, NO_INSERT
);
10575 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10576 is not present in *SLOT (since if there is something in *SLOT then
10577 it will be for a partial_unit). */
10578 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10580 gdb_assert (*slot
!= NULL
);
10581 cu
->line_header
= (struct line_header
*) *slot
;
10586 /* dwarf_decode_line_header does not yet provide sufficient information.
10587 We always have to call also dwarf_decode_lines for it. */
10588 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10592 cu
->line_header
= lh
.release ();
10593 cu
->line_header_die_owner
= die
;
10595 if (per_objfile
->line_header_hash
== NULL
)
10599 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10600 &line_header_local
,
10601 line_header_local_hash
, INSERT
);
10602 gdb_assert (slot
!= NULL
);
10604 if (slot
!= NULL
&& *slot
== NULL
)
10606 /* This newly decoded line number information unit will be owned
10607 by line_header_hash hash table. */
10608 *slot
= cu
->line_header
;
10609 cu
->line_header_die_owner
= NULL
;
10613 /* We cannot free any current entry in (*slot) as that struct line_header
10614 may be already used by multiple CUs. Create only temporary decoded
10615 line_header for this CU - it may happen at most once for each line
10616 number information unit. And if we're not using line_header_hash
10617 then this is what we want as well. */
10618 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10620 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10621 dwarf_decode_lines (cu
->line_header
, fnd
, cu
, nullptr, lowpc
,
10626 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10629 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10631 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10632 struct objfile
*objfile
= per_objfile
->objfile
;
10633 struct gdbarch
*gdbarch
= objfile
->arch ();
10634 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10635 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10636 struct attribute
*attr
;
10637 struct die_info
*child_die
;
10638 CORE_ADDR baseaddr
;
10640 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
10641 baseaddr
= objfile
->text_section_offset ();
10643 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10645 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10646 from finish_block. */
10647 if (lowpc
== ((CORE_ADDR
) -1))
10649 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10651 file_and_directory
&fnd
= find_file_and_directory (die
, cu
);
10653 cu
->start_compunit_symtab (fnd
.get_name (), fnd
.intern_comp_dir (objfile
),
10656 gdb_assert (per_objfile
->sym_cu
== nullptr);
10657 scoped_restore restore_sym_cu
10658 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10660 /* Decode line number information if present. We do this before
10661 processing child DIEs, so that the line header table is available
10662 for DW_AT_decl_file. The PC check is here because, if LOWPC and
10663 HIGHPC are both 0x0, then there won't be any interesting code in
10664 the CU, but a check later on (in
10665 lnp_state_machine::check_line_address) will fail to properly
10666 exclude an entry that was removed via --gc-sections. */
10667 if (lowpc
!= highpc
)
10668 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
);
10670 /* Process all dies in compilation unit. */
10671 if (die
->child
!= NULL
)
10673 child_die
= die
->child
;
10674 while (child_die
&& child_die
->tag
)
10676 process_die (child_die
, cu
);
10677 child_die
= child_die
->sibling
;
10680 per_objfile
->sym_cu
= nullptr;
10682 /* Decode macro information, if present. Dwarf 2 macro information
10683 refers to information in the line number info statement program
10684 header, so we can only read it if we've read the header
10686 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10688 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10689 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10691 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10692 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10694 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10698 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10699 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10701 unsigned int macro_offset
= attr
->as_unsigned ();
10703 dwarf_decode_macros (cu
, macro_offset
, 0);
10709 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10711 struct type_unit_group
*tu_group
;
10713 struct attribute
*attr
;
10715 struct signatured_type
*sig_type
;
10717 gdb_assert (per_cu
->is_debug_types
);
10718 sig_type
= (struct signatured_type
*) per_cu
;
10720 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10722 /* If we're using .gdb_index (includes -readnow) then
10723 per_cu->type_unit_group may not have been set up yet. */
10724 if (sig_type
->type_unit_group
== NULL
)
10725 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10726 tu_group
= sig_type
->type_unit_group
;
10728 /* If we've already processed this stmt_list there's no real need to
10729 do it again, we could fake it and just recreate the part we need
10730 (file name,index -> symtab mapping). If data shows this optimization
10731 is useful we can do it then. */
10732 type_unit_group_unshareable
*tug_unshare
10733 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10734 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10736 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10739 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10741 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10742 lh
= dwarf_decode_line_header (line_offset
, this);
10747 start_compunit_symtab ("", NULL
, 0);
10750 gdb_assert (tug_unshare
->symtabs
== NULL
);
10751 gdb_assert (m_builder
== nullptr);
10752 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10753 m_builder
.reset (new struct buildsym_compunit
10754 (cust
->objfile (), "",
10756 compunit_language (cust
),
10758 list_in_scope
= get_builder ()->get_file_symbols ();
10763 line_header
= lh
.release ();
10764 line_header_die_owner
= die
;
10768 struct compunit_symtab
*cust
= start_compunit_symtab ("", NULL
, 0);
10770 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10771 still initializing it, and our caller (a few levels up)
10772 process_full_type_unit still needs to know if this is the first
10775 tug_unshare
->symtabs
10776 = XOBNEWVEC (&cust
->objfile ()->objfile_obstack
,
10777 struct symtab
*, line_header
->file_names_size ());
10779 auto &file_names
= line_header
->file_names ();
10780 for (i
= 0; i
< file_names
.size (); ++i
)
10782 file_entry
&fe
= file_names
[i
];
10783 dwarf2_start_subfile (this, fe
.name
,
10784 fe
.include_dir (line_header
));
10785 buildsym_compunit
*b
= get_builder ();
10786 if (b
->get_current_subfile ()->symtab
== NULL
)
10788 /* NOTE: start_subfile will recognize when it's been
10789 passed a file it has already seen. So we can't
10790 assume there's a simple mapping from
10791 cu->line_header->file_names to subfiles, plus
10792 cu->line_header->file_names may contain dups. */
10793 b
->get_current_subfile ()->symtab
10794 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10797 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10798 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10803 gdb_assert (m_builder
== nullptr);
10804 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10805 m_builder
.reset (new struct buildsym_compunit
10806 (cust
->objfile (), "",
10808 compunit_language (cust
),
10810 list_in_scope
= get_builder ()->get_file_symbols ();
10812 auto &file_names
= line_header
->file_names ();
10813 for (i
= 0; i
< file_names
.size (); ++i
)
10815 file_entry
&fe
= file_names
[i
];
10816 fe
.symtab
= tug_unshare
->symtabs
[i
];
10820 /* The main symtab is allocated last. Type units don't have DW_AT_name
10821 so they don't have a "real" (so to speak) symtab anyway.
10822 There is later code that will assign the main symtab to all symbols
10823 that don't have one. We need to handle the case of a symbol with a
10824 missing symtab (DW_AT_decl_file) anyway. */
10827 /* Process DW_TAG_type_unit.
10828 For TUs we want to skip the first top level sibling if it's not the
10829 actual type being defined by this TU. In this case the first top
10830 level sibling is there to provide context only. */
10833 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10835 struct die_info
*child_die
;
10837 prepare_one_comp_unit (cu
, die
, language_minimal
);
10839 /* Initialize (or reinitialize) the machinery for building symtabs.
10840 We do this before processing child DIEs, so that the line header table
10841 is available for DW_AT_decl_file. */
10842 cu
->setup_type_unit_groups (die
);
10844 if (die
->child
!= NULL
)
10846 child_die
= die
->child
;
10847 while (child_die
&& child_die
->tag
)
10849 process_die (child_die
, cu
);
10850 child_die
= child_die
->sibling
;
10857 http://gcc.gnu.org/wiki/DebugFission
10858 http://gcc.gnu.org/wiki/DebugFissionDWP
10860 To simplify handling of both DWO files ("object" files with the DWARF info)
10861 and DWP files (a file with the DWOs packaged up into one file), we treat
10862 DWP files as having a collection of virtual DWO files. */
10865 hash_dwo_file (const void *item
)
10867 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10870 hash
= htab_hash_string (dwo_file
->dwo_name
);
10871 if (dwo_file
->comp_dir
!= NULL
)
10872 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10877 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10879 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10880 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10882 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10884 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10885 return lhs
->comp_dir
== rhs
->comp_dir
;
10886 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10889 /* Allocate a hash table for DWO files. */
10892 allocate_dwo_file_hash_table ()
10894 return htab_up (htab_create_alloc (41,
10897 htab_delete_entry
<dwo_file
>,
10901 /* Lookup DWO file DWO_NAME. */
10904 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10905 const char *dwo_name
,
10906 const char *comp_dir
)
10908 struct dwo_file find_entry
;
10911 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10912 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10914 find_entry
.dwo_name
= dwo_name
;
10915 find_entry
.comp_dir
= comp_dir
;
10916 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10923 hash_dwo_unit (const void *item
)
10925 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10927 /* This drops the top 32 bits of the id, but is ok for a hash. */
10928 return dwo_unit
->signature
;
10932 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10934 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10935 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10937 /* The signature is assumed to be unique within the DWO file.
10938 So while object file CU dwo_id's always have the value zero,
10939 that's OK, assuming each object file DWO file has only one CU,
10940 and that's the rule for now. */
10941 return lhs
->signature
== rhs
->signature
;
10944 /* Allocate a hash table for DWO CUs,TUs.
10945 There is one of these tables for each of CUs,TUs for each DWO file. */
10948 allocate_dwo_unit_table ()
10950 /* Start out with a pretty small number.
10951 Generally DWO files contain only one CU and maybe some TUs. */
10952 return htab_up (htab_create_alloc (3,
10955 NULL
, xcalloc
, xfree
));
10958 /* die_reader_func for create_dwo_cu. */
10961 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10962 const gdb_byte
*info_ptr
,
10963 struct die_info
*comp_unit_die
,
10964 struct dwo_file
*dwo_file
,
10965 struct dwo_unit
*dwo_unit
)
10967 struct dwarf2_cu
*cu
= reader
->cu
;
10968 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10969 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10971 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10972 if (!signature
.has_value ())
10974 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10975 " its dwo_id [in module %s]"),
10976 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10980 dwo_unit
->dwo_file
= dwo_file
;
10981 dwo_unit
->signature
= *signature
;
10982 dwo_unit
->section
= section
;
10983 dwo_unit
->sect_off
= sect_off
;
10984 dwo_unit
->length
= cu
->per_cu
->length
;
10986 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10987 sect_offset_str (sect_off
),
10988 hex_string (dwo_unit
->signature
));
10991 /* Create the dwo_units for the CUs in a DWO_FILE.
10992 Note: This function processes DWO files only, not DWP files. */
10995 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10996 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10997 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10999 struct objfile
*objfile
= per_objfile
->objfile
;
11000 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11001 const gdb_byte
*info_ptr
, *end_ptr
;
11003 section
.read (objfile
);
11004 info_ptr
= section
.buffer
;
11006 if (info_ptr
== NULL
)
11009 dwarf_read_debug_printf ("Reading %s for %s:",
11010 section
.get_name (),
11011 section
.get_file_name ());
11013 end_ptr
= info_ptr
+ section
.size
;
11014 while (info_ptr
< end_ptr
)
11016 struct dwarf2_per_cu_data per_cu
;
11017 struct dwo_unit read_unit
{};
11018 struct dwo_unit
*dwo_unit
;
11020 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11022 per_cu
.per_bfd
= per_bfd
;
11023 per_cu
.is_debug_types
= 0;
11024 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11025 per_cu
.section
= §ion
;
11027 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11028 if (!reader
.dummy_p
)
11029 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11030 &dwo_file
, &read_unit
);
11031 info_ptr
+= per_cu
.length
;
11033 // If the unit could not be parsed, skip it.
11034 if (read_unit
.dwo_file
== NULL
)
11037 if (cus_htab
== NULL
)
11038 cus_htab
= allocate_dwo_unit_table ();
11040 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11042 *dwo_unit
= read_unit
;
11043 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11044 gdb_assert (slot
!= NULL
);
11047 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11048 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11050 complaint (_("debug cu entry at offset %s is duplicate to"
11051 " the entry at offset %s, signature %s"),
11052 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11053 hex_string (dwo_unit
->signature
));
11055 *slot
= (void *)dwo_unit
;
11059 /* DWP file .debug_{cu,tu}_index section format:
11060 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11061 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11063 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11064 officially standard DWP format was published with DWARF v5 and is called
11065 Version 5. There are no versions 3 or 4.
11069 Both index sections have the same format, and serve to map a 64-bit
11070 signature to a set of section numbers. Each section begins with a header,
11071 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11072 indexes, and a pool of 32-bit section numbers. The index sections will be
11073 aligned at 8-byte boundaries in the file.
11075 The index section header consists of:
11077 V, 32 bit version number
11079 N, 32 bit number of compilation units or type units in the index
11080 M, 32 bit number of slots in the hash table
11082 Numbers are recorded using the byte order of the application binary.
11084 The hash table begins at offset 16 in the section, and consists of an array
11085 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11086 order of the application binary). Unused slots in the hash table are 0.
11087 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11089 The parallel table begins immediately after the hash table
11090 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11091 array of 32-bit indexes (using the byte order of the application binary),
11092 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11093 table contains a 32-bit index into the pool of section numbers. For unused
11094 hash table slots, the corresponding entry in the parallel table will be 0.
11096 The pool of section numbers begins immediately following the hash table
11097 (at offset 16 + 12 * M from the beginning of the section). The pool of
11098 section numbers consists of an array of 32-bit words (using the byte order
11099 of the application binary). Each item in the array is indexed starting
11100 from 0. The hash table entry provides the index of the first section
11101 number in the set. Additional section numbers in the set follow, and the
11102 set is terminated by a 0 entry (section number 0 is not used in ELF).
11104 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11105 section must be the first entry in the set, and the .debug_abbrev.dwo must
11106 be the second entry. Other members of the set may follow in any order.
11110 DWP Versions 2 and 5:
11112 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11113 and the entries in the index tables are now offsets into these sections.
11114 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11117 Index Section Contents:
11119 Hash Table of Signatures dwp_hash_table.hash_table
11120 Parallel Table of Indices dwp_hash_table.unit_table
11121 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11122 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11124 The index section header consists of:
11126 V, 32 bit version number
11127 L, 32 bit number of columns in the table of section offsets
11128 N, 32 bit number of compilation units or type units in the index
11129 M, 32 bit number of slots in the hash table
11131 Numbers are recorded using the byte order of the application binary.
11133 The hash table has the same format as version 1.
11134 The parallel table of indices has the same format as version 1,
11135 except that the entries are origin-1 indices into the table of sections
11136 offsets and the table of section sizes.
11138 The table of offsets begins immediately following the parallel table
11139 (at offset 16 + 12 * M from the beginning of the section). The table is
11140 a two-dimensional array of 32-bit words (using the byte order of the
11141 application binary), with L columns and N+1 rows, in row-major order.
11142 Each row in the array is indexed starting from 0. The first row provides
11143 a key to the remaining rows: each column in this row provides an identifier
11144 for a debug section, and the offsets in the same column of subsequent rows
11145 refer to that section. The section identifiers for Version 2 are:
11147 DW_SECT_INFO 1 .debug_info.dwo
11148 DW_SECT_TYPES 2 .debug_types.dwo
11149 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11150 DW_SECT_LINE 4 .debug_line.dwo
11151 DW_SECT_LOC 5 .debug_loc.dwo
11152 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11153 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11154 DW_SECT_MACRO 8 .debug_macro.dwo
11156 The section identifiers for Version 5 are:
11158 DW_SECT_INFO_V5 1 .debug_info.dwo
11159 DW_SECT_RESERVED_V5 2 --
11160 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11161 DW_SECT_LINE_V5 4 .debug_line.dwo
11162 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11163 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11164 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11165 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11167 The offsets provided by the CU and TU index sections are the base offsets
11168 for the contributions made by each CU or TU to the corresponding section
11169 in the package file. Each CU and TU header contains an abbrev_offset
11170 field, used to find the abbreviations table for that CU or TU within the
11171 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11172 be interpreted as relative to the base offset given in the index section.
11173 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11174 should be interpreted as relative to the base offset for .debug_line.dwo,
11175 and offsets into other debug sections obtained from DWARF attributes should
11176 also be interpreted as relative to the corresponding base offset.
11178 The table of sizes begins immediately following the table of offsets.
11179 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11180 with L columns and N rows, in row-major order. Each row in the array is
11181 indexed starting from 1 (row 0 is shared by the two tables).
11185 Hash table lookup is handled the same in version 1 and 2:
11187 We assume that N and M will not exceed 2^32 - 1.
11188 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11190 Given a 64-bit compilation unit signature or a type signature S, an entry
11191 in the hash table is located as follows:
11193 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11194 the low-order k bits all set to 1.
11196 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11198 3) If the hash table entry at index H matches the signature, use that
11199 entry. If the hash table entry at index H is unused (all zeroes),
11200 terminate the search: the signature is not present in the table.
11202 4) Let H = (H + H') modulo M. Repeat at Step 3.
11204 Because M > N and H' and M are relatively prime, the search is guaranteed
11205 to stop at an unused slot or find the match. */
11207 /* Create a hash table to map DWO IDs to their CU/TU entry in
11208 .debug_{info,types}.dwo in DWP_FILE.
11209 Returns NULL if there isn't one.
11210 Note: This function processes DWP files only, not DWO files. */
11212 static struct dwp_hash_table
*
11213 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11214 struct dwp_file
*dwp_file
, int is_debug_types
)
11216 struct objfile
*objfile
= per_objfile
->objfile
;
11217 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11218 const gdb_byte
*index_ptr
, *index_end
;
11219 struct dwarf2_section_info
*index
;
11220 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11221 struct dwp_hash_table
*htab
;
11223 if (is_debug_types
)
11224 index
= &dwp_file
->sections
.tu_index
;
11226 index
= &dwp_file
->sections
.cu_index
;
11228 if (index
->empty ())
11230 index
->read (objfile
);
11232 index_ptr
= index
->buffer
;
11233 index_end
= index_ptr
+ index
->size
;
11235 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11236 For now it's safe to just read 4 bytes (particularly as it's difficult to
11237 tell if you're dealing with Version 5 before you've read the version). */
11238 version
= read_4_bytes (dbfd
, index_ptr
);
11240 if (version
== 2 || version
== 5)
11241 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11245 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11247 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11250 if (version
!= 1 && version
!= 2 && version
!= 5)
11252 error (_("Dwarf Error: unsupported DWP file version (%s)"
11253 " [in module %s]"),
11254 pulongest (version
), dwp_file
->name
);
11256 if (nr_slots
!= (nr_slots
& -nr_slots
))
11258 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11259 " is not power of 2 [in module %s]"),
11260 pulongest (nr_slots
), dwp_file
->name
);
11263 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11264 htab
->version
= version
;
11265 htab
->nr_columns
= nr_columns
;
11266 htab
->nr_units
= nr_units
;
11267 htab
->nr_slots
= nr_slots
;
11268 htab
->hash_table
= index_ptr
;
11269 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11271 /* Exit early if the table is empty. */
11272 if (nr_slots
== 0 || nr_units
== 0
11273 || (version
== 2 && nr_columns
== 0)
11274 || (version
== 5 && nr_columns
== 0))
11276 /* All must be zero. */
11277 if (nr_slots
!= 0 || nr_units
!= 0
11278 || (version
== 2 && nr_columns
!= 0)
11279 || (version
== 5 && nr_columns
!= 0))
11281 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11282 " all zero [in modules %s]"),
11290 htab
->section_pool
.v1
.indices
=
11291 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11292 /* It's harder to decide whether the section is too small in v1.
11293 V1 is deprecated anyway so we punt. */
11295 else if (version
== 2)
11297 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11298 int *ids
= htab
->section_pool
.v2
.section_ids
;
11299 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11300 /* Reverse map for error checking. */
11301 int ids_seen
[DW_SECT_MAX
+ 1];
11304 if (nr_columns
< 2)
11306 error (_("Dwarf Error: bad DWP hash table, too few columns"
11307 " in section table [in module %s]"),
11310 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11312 error (_("Dwarf Error: bad DWP hash table, too many columns"
11313 " in section table [in module %s]"),
11316 memset (ids
, 255, sizeof_ids
);
11317 memset (ids_seen
, 255, sizeof (ids_seen
));
11318 for (i
= 0; i
< nr_columns
; ++i
)
11320 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11322 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11324 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11325 " in section table [in module %s]"),
11326 id
, dwp_file
->name
);
11328 if (ids_seen
[id
] != -1)
11330 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11331 " id %d in section table [in module %s]"),
11332 id
, dwp_file
->name
);
11337 /* Must have exactly one info or types section. */
11338 if (((ids_seen
[DW_SECT_INFO
] != -1)
11339 + (ids_seen
[DW_SECT_TYPES
] != -1))
11342 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11343 " DWO info/types section [in module %s]"),
11346 /* Must have an abbrev section. */
11347 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11349 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11350 " section [in module %s]"),
11353 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11354 htab
->section_pool
.v2
.sizes
=
11355 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11356 * nr_units
* nr_columns
);
11357 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11358 * nr_units
* nr_columns
))
11361 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11362 " [in module %s]"),
11366 else /* version == 5 */
11368 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11369 int *ids
= htab
->section_pool
.v5
.section_ids
;
11370 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11371 /* Reverse map for error checking. */
11372 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11374 if (nr_columns
< 2)
11376 error (_("Dwarf Error: bad DWP hash table, too few columns"
11377 " in section table [in module %s]"),
11380 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11382 error (_("Dwarf Error: bad DWP hash table, too many columns"
11383 " in section table [in module %s]"),
11386 memset (ids
, 255, sizeof_ids
);
11387 memset (ids_seen
, 255, sizeof (ids_seen
));
11388 for (int i
= 0; i
< nr_columns
; ++i
)
11390 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11392 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11394 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11395 " in section table [in module %s]"),
11396 id
, dwp_file
->name
);
11398 if (ids_seen
[id
] != -1)
11400 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11401 " id %d in section table [in module %s]"),
11402 id
, dwp_file
->name
);
11407 /* Must have seen an info section. */
11408 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11410 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11411 " DWO info/types section [in module %s]"),
11414 /* Must have an abbrev section. */
11415 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11417 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11418 " section [in module %s]"),
11421 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11422 htab
->section_pool
.v5
.sizes
11423 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11424 * nr_units
* nr_columns
);
11425 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11426 * nr_units
* nr_columns
))
11429 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11430 " [in module %s]"),
11438 /* Update SECTIONS with the data from SECTP.
11440 This function is like the other "locate" section routines, but in
11441 this context the sections to read comes from the DWP V1 hash table,
11442 not the full ELF section table.
11444 The result is non-zero for success, or zero if an error was found. */
11447 locate_v1_virtual_dwo_sections (asection
*sectp
,
11448 struct virtual_v1_dwo_sections
*sections
)
11450 const struct dwop_section_names
*names
= &dwop_section_names
;
11452 if (names
->abbrev_dwo
.matches (sectp
->name
))
11454 /* There can be only one. */
11455 if (sections
->abbrev
.s
.section
!= NULL
)
11457 sections
->abbrev
.s
.section
= sectp
;
11458 sections
->abbrev
.size
= bfd_section_size (sectp
);
11460 else if (names
->info_dwo
.matches (sectp
->name
)
11461 || names
->types_dwo
.matches (sectp
->name
))
11463 /* There can be only one. */
11464 if (sections
->info_or_types
.s
.section
!= NULL
)
11466 sections
->info_or_types
.s
.section
= sectp
;
11467 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11469 else if (names
->line_dwo
.matches (sectp
->name
))
11471 /* There can be only one. */
11472 if (sections
->line
.s
.section
!= NULL
)
11474 sections
->line
.s
.section
= sectp
;
11475 sections
->line
.size
= bfd_section_size (sectp
);
11477 else if (names
->loc_dwo
.matches (sectp
->name
))
11479 /* There can be only one. */
11480 if (sections
->loc
.s
.section
!= NULL
)
11482 sections
->loc
.s
.section
= sectp
;
11483 sections
->loc
.size
= bfd_section_size (sectp
);
11485 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11487 /* There can be only one. */
11488 if (sections
->macinfo
.s
.section
!= NULL
)
11490 sections
->macinfo
.s
.section
= sectp
;
11491 sections
->macinfo
.size
= bfd_section_size (sectp
);
11493 else if (names
->macro_dwo
.matches (sectp
->name
))
11495 /* There can be only one. */
11496 if (sections
->macro
.s
.section
!= NULL
)
11498 sections
->macro
.s
.section
= sectp
;
11499 sections
->macro
.size
= bfd_section_size (sectp
);
11501 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11503 /* There can be only one. */
11504 if (sections
->str_offsets
.s
.section
!= NULL
)
11506 sections
->str_offsets
.s
.section
= sectp
;
11507 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11511 /* No other kind of section is valid. */
11518 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11519 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11520 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11521 This is for DWP version 1 files. */
11523 static struct dwo_unit
*
11524 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11525 struct dwp_file
*dwp_file
,
11526 uint32_t unit_index
,
11527 const char *comp_dir
,
11528 ULONGEST signature
, int is_debug_types
)
11530 const struct dwp_hash_table
*dwp_htab
=
11531 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11532 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11533 const char *kind
= is_debug_types
? "TU" : "CU";
11534 struct dwo_file
*dwo_file
;
11535 struct dwo_unit
*dwo_unit
;
11536 struct virtual_v1_dwo_sections sections
;
11537 void **dwo_file_slot
;
11540 gdb_assert (dwp_file
->version
== 1);
11542 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11543 kind
, pulongest (unit_index
), hex_string (signature
),
11546 /* Fetch the sections of this DWO unit.
11547 Put a limit on the number of sections we look for so that bad data
11548 doesn't cause us to loop forever. */
11550 #define MAX_NR_V1_DWO_SECTIONS \
11551 (1 /* .debug_info or .debug_types */ \
11552 + 1 /* .debug_abbrev */ \
11553 + 1 /* .debug_line */ \
11554 + 1 /* .debug_loc */ \
11555 + 1 /* .debug_str_offsets */ \
11556 + 1 /* .debug_macro or .debug_macinfo */ \
11557 + 1 /* trailing zero */)
11559 memset (§ions
, 0, sizeof (sections
));
11561 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11564 uint32_t section_nr
=
11565 read_4_bytes (dbfd
,
11566 dwp_htab
->section_pool
.v1
.indices
11567 + (unit_index
+ i
) * sizeof (uint32_t));
11569 if (section_nr
== 0)
11571 if (section_nr
>= dwp_file
->num_sections
)
11573 error (_("Dwarf Error: bad DWP hash table, section number too large"
11574 " [in module %s]"),
11578 sectp
= dwp_file
->elf_sections
[section_nr
];
11579 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11581 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11582 " [in module %s]"),
11588 || sections
.info_or_types
.empty ()
11589 || sections
.abbrev
.empty ())
11591 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11592 " [in module %s]"),
11595 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11597 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11598 " [in module %s]"),
11602 /* It's easier for the rest of the code if we fake a struct dwo_file and
11603 have dwo_unit "live" in that. At least for now.
11605 The DWP file can be made up of a random collection of CUs and TUs.
11606 However, for each CU + set of TUs that came from the same original DWO
11607 file, we can combine them back into a virtual DWO file to save space
11608 (fewer struct dwo_file objects to allocate). Remember that for really
11609 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11611 std::string virtual_dwo_name
=
11612 string_printf ("virtual-dwo/%d-%d-%d-%d",
11613 sections
.abbrev
.get_id (),
11614 sections
.line
.get_id (),
11615 sections
.loc
.get_id (),
11616 sections
.str_offsets
.get_id ());
11617 /* Can we use an existing virtual DWO file? */
11618 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11620 /* Create one if necessary. */
11621 if (*dwo_file_slot
== NULL
)
11623 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11624 virtual_dwo_name
.c_str ());
11626 dwo_file
= new struct dwo_file
;
11627 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11628 dwo_file
->comp_dir
= comp_dir
;
11629 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11630 dwo_file
->sections
.line
= sections
.line
;
11631 dwo_file
->sections
.loc
= sections
.loc
;
11632 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11633 dwo_file
->sections
.macro
= sections
.macro
;
11634 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11635 /* The "str" section is global to the entire DWP file. */
11636 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11637 /* The info or types section is assigned below to dwo_unit,
11638 there's no need to record it in dwo_file.
11639 Also, we can't simply record type sections in dwo_file because
11640 we record a pointer into the vector in dwo_unit. As we collect more
11641 types we'll grow the vector and eventually have to reallocate space
11642 for it, invalidating all copies of pointers into the previous
11644 *dwo_file_slot
= dwo_file
;
11648 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11649 virtual_dwo_name
.c_str ());
11651 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11654 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11655 dwo_unit
->dwo_file
= dwo_file
;
11656 dwo_unit
->signature
= signature
;
11657 dwo_unit
->section
=
11658 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11659 *dwo_unit
->section
= sections
.info_or_types
;
11660 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11665 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11666 simplify them. Given a pointer to the containing section SECTION, and
11667 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11668 virtual section of just that piece. */
11670 static struct dwarf2_section_info
11671 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11672 struct dwarf2_section_info
*section
,
11673 bfd_size_type offset
, bfd_size_type size
)
11675 struct dwarf2_section_info result
;
11678 gdb_assert (section
!= NULL
);
11679 gdb_assert (!section
->is_virtual
);
11681 memset (&result
, 0, sizeof (result
));
11682 result
.s
.containing_section
= section
;
11683 result
.is_virtual
= true;
11688 sectp
= section
->get_bfd_section ();
11690 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11691 bounds of the real section. This is a pretty-rare event, so just
11692 flag an error (easier) instead of a warning and trying to cope. */
11694 || offset
+ size
> bfd_section_size (sectp
))
11696 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11697 " in section %s [in module %s]"),
11698 sectp
? bfd_section_name (sectp
) : "<unknown>",
11699 objfile_name (per_objfile
->objfile
));
11702 result
.virtual_offset
= offset
;
11703 result
.size
= size
;
11707 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11708 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11709 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11710 This is for DWP version 2 files. */
11712 static struct dwo_unit
*
11713 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11714 struct dwp_file
*dwp_file
,
11715 uint32_t unit_index
,
11716 const char *comp_dir
,
11717 ULONGEST signature
, int is_debug_types
)
11719 const struct dwp_hash_table
*dwp_htab
=
11720 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11721 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11722 const char *kind
= is_debug_types
? "TU" : "CU";
11723 struct dwo_file
*dwo_file
;
11724 struct dwo_unit
*dwo_unit
;
11725 struct virtual_v2_or_v5_dwo_sections sections
;
11726 void **dwo_file_slot
;
11729 gdb_assert (dwp_file
->version
== 2);
11731 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11732 kind
, pulongest (unit_index
), hex_string (signature
),
11735 /* Fetch the section offsets of this DWO unit. */
11737 memset (§ions
, 0, sizeof (sections
));
11739 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11741 uint32_t offset
= read_4_bytes (dbfd
,
11742 dwp_htab
->section_pool
.v2
.offsets
11743 + (((unit_index
- 1) * dwp_htab
->nr_columns
11745 * sizeof (uint32_t)));
11746 uint32_t size
= read_4_bytes (dbfd
,
11747 dwp_htab
->section_pool
.v2
.sizes
11748 + (((unit_index
- 1) * dwp_htab
->nr_columns
11750 * sizeof (uint32_t)));
11752 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11755 case DW_SECT_TYPES
:
11756 sections
.info_or_types_offset
= offset
;
11757 sections
.info_or_types_size
= size
;
11759 case DW_SECT_ABBREV
:
11760 sections
.abbrev_offset
= offset
;
11761 sections
.abbrev_size
= size
;
11764 sections
.line_offset
= offset
;
11765 sections
.line_size
= size
;
11768 sections
.loc_offset
= offset
;
11769 sections
.loc_size
= size
;
11771 case DW_SECT_STR_OFFSETS
:
11772 sections
.str_offsets_offset
= offset
;
11773 sections
.str_offsets_size
= size
;
11775 case DW_SECT_MACINFO
:
11776 sections
.macinfo_offset
= offset
;
11777 sections
.macinfo_size
= size
;
11779 case DW_SECT_MACRO
:
11780 sections
.macro_offset
= offset
;
11781 sections
.macro_size
= size
;
11786 /* It's easier for the rest of the code if we fake a struct dwo_file and
11787 have dwo_unit "live" in that. At least for now.
11789 The DWP file can be made up of a random collection of CUs and TUs.
11790 However, for each CU + set of TUs that came from the same original DWO
11791 file, we can combine them back into a virtual DWO file to save space
11792 (fewer struct dwo_file objects to allocate). Remember that for really
11793 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11795 std::string virtual_dwo_name
=
11796 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11797 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11798 (long) (sections
.line_size
? sections
.line_offset
: 0),
11799 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11800 (long) (sections
.str_offsets_size
11801 ? sections
.str_offsets_offset
: 0));
11802 /* Can we use an existing virtual DWO file? */
11803 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11805 /* Create one if necessary. */
11806 if (*dwo_file_slot
== NULL
)
11808 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11809 virtual_dwo_name
.c_str ());
11811 dwo_file
= new struct dwo_file
;
11812 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11813 dwo_file
->comp_dir
= comp_dir
;
11814 dwo_file
->sections
.abbrev
=
11815 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11816 sections
.abbrev_offset
,
11817 sections
.abbrev_size
);
11818 dwo_file
->sections
.line
=
11819 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11820 sections
.line_offset
,
11821 sections
.line_size
);
11822 dwo_file
->sections
.loc
=
11823 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11824 sections
.loc_offset
, sections
.loc_size
);
11825 dwo_file
->sections
.macinfo
=
11826 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11827 sections
.macinfo_offset
,
11828 sections
.macinfo_size
);
11829 dwo_file
->sections
.macro
=
11830 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11831 sections
.macro_offset
,
11832 sections
.macro_size
);
11833 dwo_file
->sections
.str_offsets
=
11834 create_dwp_v2_or_v5_section (per_objfile
,
11835 &dwp_file
->sections
.str_offsets
,
11836 sections
.str_offsets_offset
,
11837 sections
.str_offsets_size
);
11838 /* The "str" section is global to the entire DWP file. */
11839 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11840 /* The info or types section is assigned below to dwo_unit,
11841 there's no need to record it in dwo_file.
11842 Also, we can't simply record type sections in dwo_file because
11843 we record a pointer into the vector in dwo_unit. As we collect more
11844 types we'll grow the vector and eventually have to reallocate space
11845 for it, invalidating all copies of pointers into the previous
11847 *dwo_file_slot
= dwo_file
;
11851 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11852 virtual_dwo_name
.c_str ());
11854 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11857 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11858 dwo_unit
->dwo_file
= dwo_file
;
11859 dwo_unit
->signature
= signature
;
11860 dwo_unit
->section
=
11861 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11862 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11865 ? &dwp_file
->sections
.types
11866 : &dwp_file
->sections
.info
,
11867 sections
.info_or_types_offset
,
11868 sections
.info_or_types_size
);
11869 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11874 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11875 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11876 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11877 This is for DWP version 5 files. */
11879 static struct dwo_unit
*
11880 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11881 struct dwp_file
*dwp_file
,
11882 uint32_t unit_index
,
11883 const char *comp_dir
,
11884 ULONGEST signature
, int is_debug_types
)
11886 const struct dwp_hash_table
*dwp_htab
11887 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11888 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11889 const char *kind
= is_debug_types
? "TU" : "CU";
11890 struct dwo_file
*dwo_file
;
11891 struct dwo_unit
*dwo_unit
;
11892 struct virtual_v2_or_v5_dwo_sections sections
{};
11893 void **dwo_file_slot
;
11895 gdb_assert (dwp_file
->version
== 5);
11897 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11898 kind
, pulongest (unit_index
), hex_string (signature
),
11901 /* Fetch the section offsets of this DWO unit. */
11903 /* memset (§ions, 0, sizeof (sections)); */
11905 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11907 uint32_t offset
= read_4_bytes (dbfd
,
11908 dwp_htab
->section_pool
.v5
.offsets
11909 + (((unit_index
- 1)
11910 * dwp_htab
->nr_columns
11912 * sizeof (uint32_t)));
11913 uint32_t size
= read_4_bytes (dbfd
,
11914 dwp_htab
->section_pool
.v5
.sizes
11915 + (((unit_index
- 1) * dwp_htab
->nr_columns
11917 * sizeof (uint32_t)));
11919 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11921 case DW_SECT_ABBREV_V5
:
11922 sections
.abbrev_offset
= offset
;
11923 sections
.abbrev_size
= size
;
11925 case DW_SECT_INFO_V5
:
11926 sections
.info_or_types_offset
= offset
;
11927 sections
.info_or_types_size
= size
;
11929 case DW_SECT_LINE_V5
:
11930 sections
.line_offset
= offset
;
11931 sections
.line_size
= size
;
11933 case DW_SECT_LOCLISTS_V5
:
11934 sections
.loclists_offset
= offset
;
11935 sections
.loclists_size
= size
;
11937 case DW_SECT_MACRO_V5
:
11938 sections
.macro_offset
= offset
;
11939 sections
.macro_size
= size
;
11941 case DW_SECT_RNGLISTS_V5
:
11942 sections
.rnglists_offset
= offset
;
11943 sections
.rnglists_size
= size
;
11945 case DW_SECT_STR_OFFSETS_V5
:
11946 sections
.str_offsets_offset
= offset
;
11947 sections
.str_offsets_size
= size
;
11949 case DW_SECT_RESERVED_V5
:
11955 /* It's easier for the rest of the code if we fake a struct dwo_file and
11956 have dwo_unit "live" in that. At least for now.
11958 The DWP file can be made up of a random collection of CUs and TUs.
11959 However, for each CU + set of TUs that came from the same original DWO
11960 file, we can combine them back into a virtual DWO file to save space
11961 (fewer struct dwo_file objects to allocate). Remember that for really
11962 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11964 std::string virtual_dwo_name
=
11965 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11966 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11967 (long) (sections
.line_size
? sections
.line_offset
: 0),
11968 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11969 (long) (sections
.str_offsets_size
11970 ? sections
.str_offsets_offset
: 0),
11971 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11972 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11973 /* Can we use an existing virtual DWO file? */
11974 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11975 virtual_dwo_name
.c_str (),
11977 /* Create one if necessary. */
11978 if (*dwo_file_slot
== NULL
)
11980 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11981 virtual_dwo_name
.c_str ());
11983 dwo_file
= new struct dwo_file
;
11984 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11985 dwo_file
->comp_dir
= comp_dir
;
11986 dwo_file
->sections
.abbrev
=
11987 create_dwp_v2_or_v5_section (per_objfile
,
11988 &dwp_file
->sections
.abbrev
,
11989 sections
.abbrev_offset
,
11990 sections
.abbrev_size
);
11991 dwo_file
->sections
.line
=
11992 create_dwp_v2_or_v5_section (per_objfile
,
11993 &dwp_file
->sections
.line
,
11994 sections
.line_offset
, sections
.line_size
);
11995 dwo_file
->sections
.macro
=
11996 create_dwp_v2_or_v5_section (per_objfile
,
11997 &dwp_file
->sections
.macro
,
11998 sections
.macro_offset
,
11999 sections
.macro_size
);
12000 dwo_file
->sections
.loclists
=
12001 create_dwp_v2_or_v5_section (per_objfile
,
12002 &dwp_file
->sections
.loclists
,
12003 sections
.loclists_offset
,
12004 sections
.loclists_size
);
12005 dwo_file
->sections
.rnglists
=
12006 create_dwp_v2_or_v5_section (per_objfile
,
12007 &dwp_file
->sections
.rnglists
,
12008 sections
.rnglists_offset
,
12009 sections
.rnglists_size
);
12010 dwo_file
->sections
.str_offsets
=
12011 create_dwp_v2_or_v5_section (per_objfile
,
12012 &dwp_file
->sections
.str_offsets
,
12013 sections
.str_offsets_offset
,
12014 sections
.str_offsets_size
);
12015 /* The "str" section is global to the entire DWP file. */
12016 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12017 /* The info or types section is assigned below to dwo_unit,
12018 there's no need to record it in dwo_file.
12019 Also, we can't simply record type sections in dwo_file because
12020 we record a pointer into the vector in dwo_unit. As we collect more
12021 types we'll grow the vector and eventually have to reallocate space
12022 for it, invalidating all copies of pointers into the previous
12024 *dwo_file_slot
= dwo_file
;
12028 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12029 virtual_dwo_name
.c_str ());
12031 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12034 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12035 dwo_unit
->dwo_file
= dwo_file
;
12036 dwo_unit
->signature
= signature
;
12038 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12039 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12040 &dwp_file
->sections
.info
,
12041 sections
.info_or_types_offset
,
12042 sections
.info_or_types_size
);
12043 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12048 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12049 Returns NULL if the signature isn't found. */
12051 static struct dwo_unit
*
12052 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12053 struct dwp_file
*dwp_file
, const char *comp_dir
,
12054 ULONGEST signature
, int is_debug_types
)
12056 const struct dwp_hash_table
*dwp_htab
=
12057 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12058 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12059 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12060 uint32_t hash
= signature
& mask
;
12061 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12064 struct dwo_unit find_dwo_cu
;
12066 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12067 find_dwo_cu
.signature
= signature
;
12068 slot
= htab_find_slot (is_debug_types
12069 ? dwp_file
->loaded_tus
.get ()
12070 : dwp_file
->loaded_cus
.get (),
12071 &find_dwo_cu
, INSERT
);
12074 return (struct dwo_unit
*) *slot
;
12076 /* Use a for loop so that we don't loop forever on bad debug info. */
12077 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12079 ULONGEST signature_in_table
;
12081 signature_in_table
=
12082 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12083 if (signature_in_table
== signature
)
12085 uint32_t unit_index
=
12086 read_4_bytes (dbfd
,
12087 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12089 if (dwp_file
->version
== 1)
12091 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12092 unit_index
, comp_dir
,
12093 signature
, is_debug_types
);
12095 else if (dwp_file
->version
== 2)
12097 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12098 unit_index
, comp_dir
,
12099 signature
, is_debug_types
);
12101 else /* version == 5 */
12103 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12104 unit_index
, comp_dir
,
12105 signature
, is_debug_types
);
12107 return (struct dwo_unit
*) *slot
;
12109 if (signature_in_table
== 0)
12111 hash
= (hash
+ hash2
) & mask
;
12114 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12115 " [in module %s]"),
12119 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12120 Open the file specified by FILE_NAME and hand it off to BFD for
12121 preliminary analysis. Return a newly initialized bfd *, which
12122 includes a canonicalized copy of FILE_NAME.
12123 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12124 SEARCH_CWD is true if the current directory is to be searched.
12125 It will be searched before debug-file-directory.
12126 If successful, the file is added to the bfd include table of the
12127 objfile's bfd (see gdb_bfd_record_inclusion).
12128 If unable to find/open the file, return NULL.
12129 NOTE: This function is derived from symfile_bfd_open. */
12131 static gdb_bfd_ref_ptr
12132 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12133 const char *file_name
, int is_dwp
, int search_cwd
)
12136 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12137 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12138 to debug_file_directory. */
12139 const char *search_path
;
12140 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12142 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12145 if (!debug_file_directory
.empty ())
12147 search_path_holder
.reset (concat (".", dirname_separator_string
,
12148 debug_file_directory
.c_str (),
12150 search_path
= search_path_holder
.get ();
12156 search_path
= debug_file_directory
.c_str ();
12158 /* Add the path for the executable binary to the list of search paths. */
12159 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12160 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12161 dirname_separator_string
,
12162 search_path
, nullptr));
12163 search_path
= search_path_holder
.get ();
12165 openp_flags flags
= OPF_RETURN_REALPATH
;
12167 flags
|= OPF_SEARCH_IN_PATH
;
12169 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12170 desc
= openp (search_path
, flags
, file_name
,
12171 O_RDONLY
| O_BINARY
, &absolute_name
);
12175 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12177 if (sym_bfd
== NULL
)
12179 bfd_set_cacheable (sym_bfd
.get (), 1);
12181 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12184 /* Success. Record the bfd as having been included by the objfile's bfd.
12185 This is important because things like demangled_names_hash lives in the
12186 objfile's per_bfd space and may have references to things like symbol
12187 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12188 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12193 /* Try to open DWO file FILE_NAME.
12194 COMP_DIR is the DW_AT_comp_dir attribute.
12195 The result is the bfd handle of the file.
12196 If there is a problem finding or opening the file, return NULL.
12197 Upon success, the canonicalized path of the file is stored in the bfd,
12198 same as symfile_bfd_open. */
12200 static gdb_bfd_ref_ptr
12201 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12202 const char *file_name
, const char *comp_dir
)
12204 if (IS_ABSOLUTE_PATH (file_name
))
12205 return try_open_dwop_file (per_objfile
, file_name
,
12206 0 /*is_dwp*/, 0 /*search_cwd*/);
12208 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12210 if (comp_dir
!= NULL
)
12212 gdb::unique_xmalloc_ptr
<char> path_to_try
12213 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12215 /* NOTE: If comp_dir is a relative path, this will also try the
12216 search path, which seems useful. */
12217 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12219 1 /*search_cwd*/));
12224 /* That didn't work, try debug-file-directory, which, despite its name,
12225 is a list of paths. */
12227 if (debug_file_directory
.empty ())
12230 return try_open_dwop_file (per_objfile
, file_name
,
12231 0 /*is_dwp*/, 1 /*search_cwd*/);
12234 /* This function is mapped across the sections and remembers the offset and
12235 size of each of the DWO debugging sections we are interested in. */
12238 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12239 dwo_sections
*dwo_sections
)
12241 const struct dwop_section_names
*names
= &dwop_section_names
;
12243 if (names
->abbrev_dwo
.matches (sectp
->name
))
12245 dwo_sections
->abbrev
.s
.section
= sectp
;
12246 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12248 else if (names
->info_dwo
.matches (sectp
->name
))
12250 dwo_sections
->info
.s
.section
= sectp
;
12251 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12253 else if (names
->line_dwo
.matches (sectp
->name
))
12255 dwo_sections
->line
.s
.section
= sectp
;
12256 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12258 else if (names
->loc_dwo
.matches (sectp
->name
))
12260 dwo_sections
->loc
.s
.section
= sectp
;
12261 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12263 else if (names
->loclists_dwo
.matches (sectp
->name
))
12265 dwo_sections
->loclists
.s
.section
= sectp
;
12266 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12268 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12270 dwo_sections
->macinfo
.s
.section
= sectp
;
12271 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12273 else if (names
->macro_dwo
.matches (sectp
->name
))
12275 dwo_sections
->macro
.s
.section
= sectp
;
12276 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12278 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12280 dwo_sections
->rnglists
.s
.section
= sectp
;
12281 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12283 else if (names
->str_dwo
.matches (sectp
->name
))
12285 dwo_sections
->str
.s
.section
= sectp
;
12286 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12288 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12290 dwo_sections
->str_offsets
.s
.section
= sectp
;
12291 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12293 else if (names
->types_dwo
.matches (sectp
->name
))
12295 struct dwarf2_section_info type_section
;
12297 memset (&type_section
, 0, sizeof (type_section
));
12298 type_section
.s
.section
= sectp
;
12299 type_section
.size
= bfd_section_size (sectp
);
12300 dwo_sections
->types
.push_back (type_section
);
12304 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12305 by PER_CU. This is for the non-DWP case.
12306 The result is NULL if DWO_NAME can't be found. */
12308 static struct dwo_file
*
12309 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12310 const char *comp_dir
)
12312 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12314 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12317 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12322 dwo_file_up
dwo_file (new struct dwo_file
);
12323 dwo_file
->dwo_name
= dwo_name
;
12324 dwo_file
->comp_dir
= comp_dir
;
12325 dwo_file
->dbfd
= std::move (dbfd
);
12327 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12328 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12329 &dwo_file
->sections
);
12331 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12334 if (cu
->per_cu
->dwarf_version
< 5)
12336 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12337 dwo_file
->sections
.types
, dwo_file
->tus
);
12341 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12342 &dwo_file
->sections
.info
, dwo_file
->tus
,
12343 rcuh_kind::COMPILE
);
12346 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12348 return dwo_file
.release ();
12351 /* This function is mapped across the sections and remembers the offset and
12352 size of each of the DWP debugging sections common to version 1 and 2 that
12353 we are interested in. */
12356 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12357 dwp_file
*dwp_file
)
12359 const struct dwop_section_names
*names
= &dwop_section_names
;
12360 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12362 /* Record the ELF section number for later lookup: this is what the
12363 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12364 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12365 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12367 /* Look for specific sections that we need. */
12368 if (names
->str_dwo
.matches (sectp
->name
))
12370 dwp_file
->sections
.str
.s
.section
= sectp
;
12371 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12373 else if (names
->cu_index
.matches (sectp
->name
))
12375 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12376 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12378 else if (names
->tu_index
.matches (sectp
->name
))
12380 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12381 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12385 /* This function is mapped across the sections and remembers the offset and
12386 size of each of the DWP version 2 debugging sections that we are interested
12387 in. This is split into a separate function because we don't know if we
12388 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12391 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12393 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12394 const struct dwop_section_names
*names
= &dwop_section_names
;
12395 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12397 /* Record the ELF section number for later lookup: this is what the
12398 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12399 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12400 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12402 /* Look for specific sections that we need. */
12403 if (names
->abbrev_dwo
.matches (sectp
->name
))
12405 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12406 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12408 else if (names
->info_dwo
.matches (sectp
->name
))
12410 dwp_file
->sections
.info
.s
.section
= sectp
;
12411 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12413 else if (names
->line_dwo
.matches (sectp
->name
))
12415 dwp_file
->sections
.line
.s
.section
= sectp
;
12416 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12418 else if (names
->loc_dwo
.matches (sectp
->name
))
12420 dwp_file
->sections
.loc
.s
.section
= sectp
;
12421 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12423 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12425 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12426 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12428 else if (names
->macro_dwo
.matches (sectp
->name
))
12430 dwp_file
->sections
.macro
.s
.section
= sectp
;
12431 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12433 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12435 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12436 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12438 else if (names
->types_dwo
.matches (sectp
->name
))
12440 dwp_file
->sections
.types
.s
.section
= sectp
;
12441 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12445 /* This function is mapped across the sections and remembers the offset and
12446 size of each of the DWP version 5 debugging sections that we are interested
12447 in. This is split into a separate function because we don't know if we
12448 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12451 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12453 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12454 const struct dwop_section_names
*names
= &dwop_section_names
;
12455 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12457 /* Record the ELF section number for later lookup: this is what the
12458 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12459 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12460 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12462 /* Look for specific sections that we need. */
12463 if (names
->abbrev_dwo
.matches (sectp
->name
))
12465 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12466 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12468 else if (names
->info_dwo
.matches (sectp
->name
))
12470 dwp_file
->sections
.info
.s
.section
= sectp
;
12471 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12473 else if (names
->line_dwo
.matches (sectp
->name
))
12475 dwp_file
->sections
.line
.s
.section
= sectp
;
12476 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12478 else if (names
->loclists_dwo
.matches (sectp
->name
))
12480 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12481 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12483 else if (names
->macro_dwo
.matches (sectp
->name
))
12485 dwp_file
->sections
.macro
.s
.section
= sectp
;
12486 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12488 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12490 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12491 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12493 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12495 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12496 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12500 /* Hash function for dwp_file loaded CUs/TUs. */
12503 hash_dwp_loaded_cutus (const void *item
)
12505 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12507 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12508 return dwo_unit
->signature
;
12511 /* Equality function for dwp_file loaded CUs/TUs. */
12514 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12516 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12517 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12519 return dua
->signature
== dub
->signature
;
12522 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12525 allocate_dwp_loaded_cutus_table ()
12527 return htab_up (htab_create_alloc (3,
12528 hash_dwp_loaded_cutus
,
12529 eq_dwp_loaded_cutus
,
12530 NULL
, xcalloc
, xfree
));
12533 /* Try to open DWP file FILE_NAME.
12534 The result is the bfd handle of the file.
12535 If there is a problem finding or opening the file, return NULL.
12536 Upon success, the canonicalized path of the file is stored in the bfd,
12537 same as symfile_bfd_open. */
12539 static gdb_bfd_ref_ptr
12540 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12542 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12544 1 /*search_cwd*/));
12548 /* Work around upstream bug 15652.
12549 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12550 [Whether that's a "bug" is debatable, but it is getting in our way.]
12551 We have no real idea where the dwp file is, because gdb's realpath-ing
12552 of the executable's path may have discarded the needed info.
12553 [IWBN if the dwp file name was recorded in the executable, akin to
12554 .gnu_debuglink, but that doesn't exist yet.]
12555 Strip the directory from FILE_NAME and search again. */
12556 if (!debug_file_directory
.empty ())
12558 /* Don't implicitly search the current directory here.
12559 If the user wants to search "." to handle this case,
12560 it must be added to debug-file-directory. */
12561 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12569 /* Initialize the use of the DWP file for the current objfile.
12570 By convention the name of the DWP file is ${objfile}.dwp.
12571 The result is NULL if it can't be found. */
12573 static std::unique_ptr
<struct dwp_file
>
12574 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12576 struct objfile
*objfile
= per_objfile
->objfile
;
12578 /* Try to find first .dwp for the binary file before any symbolic links
12581 /* If the objfile is a debug file, find the name of the real binary
12582 file and get the name of dwp file from there. */
12583 std::string dwp_name
;
12584 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12586 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12587 const char *backlink_basename
= lbasename (backlink
->original_name
);
12589 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12592 dwp_name
= objfile
->original_name
;
12594 dwp_name
+= ".dwp";
12596 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12598 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12600 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12601 dwp_name
= objfile_name (objfile
);
12602 dwp_name
+= ".dwp";
12603 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12608 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12610 return std::unique_ptr
<dwp_file
> ();
12613 const char *name
= bfd_get_filename (dbfd
.get ());
12614 std::unique_ptr
<struct dwp_file
> dwp_file
12615 (new struct dwp_file (name
, std::move (dbfd
)));
12617 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12618 dwp_file
->elf_sections
=
12619 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12620 dwp_file
->num_sections
, asection
*);
12622 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12623 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12626 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12628 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12630 /* The DWP file version is stored in the hash table. Oh well. */
12631 if (dwp_file
->cus
&& dwp_file
->tus
12632 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12634 /* Technically speaking, we should try to limp along, but this is
12635 pretty bizarre. We use pulongest here because that's the established
12636 portability solution (e.g, we cannot use %u for uint32_t). */
12637 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12638 " TU version %s [in DWP file %s]"),
12639 pulongest (dwp_file
->cus
->version
),
12640 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12644 dwp_file
->version
= dwp_file
->cus
->version
;
12645 else if (dwp_file
->tus
)
12646 dwp_file
->version
= dwp_file
->tus
->version
;
12648 dwp_file
->version
= 2;
12650 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12652 if (dwp_file
->version
== 2)
12653 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12656 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12660 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12661 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12663 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12664 dwarf_read_debug_printf (" %s CUs, %s TUs",
12665 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12666 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12671 /* Wrapper around open_and_init_dwp_file, only open it once. */
12673 static struct dwp_file
*
12674 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12676 if (!per_objfile
->per_bfd
->dwp_checked
)
12678 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12679 per_objfile
->per_bfd
->dwp_checked
= 1;
12681 return per_objfile
->per_bfd
->dwp_file
.get ();
12684 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12685 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12686 or in the DWP file for the objfile, referenced by THIS_UNIT.
12687 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12688 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12690 This is called, for example, when wanting to read a variable with a
12691 complex location. Therefore we don't want to do file i/o for every call.
12692 Therefore we don't want to look for a DWO file on every call.
12693 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12694 then we check if we've already seen DWO_NAME, and only THEN do we check
12697 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12698 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12700 static struct dwo_unit
*
12701 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12702 ULONGEST signature
, int is_debug_types
)
12704 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12705 struct objfile
*objfile
= per_objfile
->objfile
;
12706 const char *kind
= is_debug_types
? "TU" : "CU";
12707 void **dwo_file_slot
;
12708 struct dwo_file
*dwo_file
;
12709 struct dwp_file
*dwp_file
;
12711 /* First see if there's a DWP file.
12712 If we have a DWP file but didn't find the DWO inside it, don't
12713 look for the original DWO file. It makes gdb behave differently
12714 depending on whether one is debugging in the build tree. */
12716 dwp_file
= get_dwp_file (per_objfile
);
12717 if (dwp_file
!= NULL
)
12719 const struct dwp_hash_table
*dwp_htab
=
12720 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12722 if (dwp_htab
!= NULL
)
12724 struct dwo_unit
*dwo_cutu
=
12725 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12728 if (dwo_cutu
!= NULL
)
12730 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12731 kind
, hex_string (signature
),
12732 host_address_to_string (dwo_cutu
));
12740 /* No DWP file, look for the DWO file. */
12742 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12743 if (*dwo_file_slot
== NULL
)
12745 /* Read in the file and build a table of the CUs/TUs it contains. */
12746 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12748 /* NOTE: This will be NULL if unable to open the file. */
12749 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12751 if (dwo_file
!= NULL
)
12753 struct dwo_unit
*dwo_cutu
= NULL
;
12755 if (is_debug_types
&& dwo_file
->tus
)
12757 struct dwo_unit find_dwo_cutu
;
12759 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12760 find_dwo_cutu
.signature
= signature
;
12762 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12765 else if (!is_debug_types
&& dwo_file
->cus
)
12767 struct dwo_unit find_dwo_cutu
;
12769 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12770 find_dwo_cutu
.signature
= signature
;
12771 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12775 if (dwo_cutu
!= NULL
)
12777 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12778 kind
, dwo_name
, hex_string (signature
),
12779 host_address_to_string (dwo_cutu
));
12786 /* We didn't find it. This could mean a dwo_id mismatch, or
12787 someone deleted the DWO/DWP file, or the search path isn't set up
12788 correctly to find the file. */
12790 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12791 kind
, dwo_name
, hex_string (signature
));
12793 /* This is a warning and not a complaint because it can be caused by
12794 pilot error (e.g., user accidentally deleting the DWO). */
12796 /* Print the name of the DWP file if we looked there, helps the user
12797 better diagnose the problem. */
12798 std::string dwp_text
;
12800 if (dwp_file
!= NULL
)
12801 dwp_text
= string_printf (" [in DWP file %s]",
12802 lbasename (dwp_file
->name
));
12804 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12805 " [in module %s]"),
12806 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12807 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12812 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12813 See lookup_dwo_cutu_unit for details. */
12815 static struct dwo_unit
*
12816 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12817 ULONGEST signature
)
12819 gdb_assert (!cu
->per_cu
->is_debug_types
);
12821 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12824 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12825 See lookup_dwo_cutu_unit for details. */
12827 static struct dwo_unit
*
12828 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12830 gdb_assert (cu
->per_cu
->is_debug_types
);
12832 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12834 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12837 /* Traversal function for queue_and_load_all_dwo_tus. */
12840 queue_and_load_dwo_tu (void **slot
, void *info
)
12842 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12843 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12844 ULONGEST signature
= dwo_unit
->signature
;
12845 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12847 if (sig_type
!= NULL
)
12849 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12850 a real dependency of PER_CU on SIG_TYPE. That is detected later
12851 while processing PER_CU. */
12852 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12854 load_full_type_unit (sig_type
, cu
->per_objfile
);
12855 cu
->per_cu
->imported_symtabs_push (sig_type
);
12861 /* Queue all TUs contained in the DWO of CU to be read in.
12862 The DWO may have the only definition of the type, though it may not be
12863 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12864 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12867 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12869 struct dwo_unit
*dwo_unit
;
12870 struct dwo_file
*dwo_file
;
12872 gdb_assert (cu
!= nullptr);
12873 gdb_assert (!cu
->per_cu
->is_debug_types
);
12874 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12876 dwo_unit
= cu
->dwo_unit
;
12877 gdb_assert (dwo_unit
!= NULL
);
12879 dwo_file
= dwo_unit
->dwo_file
;
12880 if (dwo_file
->tus
!= NULL
)
12881 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12884 /* Read in various DIEs. */
12886 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12887 Inherit only the children of the DW_AT_abstract_origin DIE not being
12888 already referenced by DW_AT_abstract_origin from the children of the
12892 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12894 struct die_info
*child_die
;
12895 sect_offset
*offsetp
;
12896 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12897 struct die_info
*origin_die
;
12898 /* Iterator of the ORIGIN_DIE children. */
12899 struct die_info
*origin_child_die
;
12900 struct attribute
*attr
;
12901 struct dwarf2_cu
*origin_cu
;
12902 struct pending
**origin_previous_list_in_scope
;
12904 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12908 /* Note that following die references may follow to a die in a
12912 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12914 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12916 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12917 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12919 if (die
->tag
!= origin_die
->tag
12920 && !(die
->tag
== DW_TAG_inlined_subroutine
12921 && origin_die
->tag
== DW_TAG_subprogram
))
12922 complaint (_("DIE %s and its abstract origin %s have different tags"),
12923 sect_offset_str (die
->sect_off
),
12924 sect_offset_str (origin_die
->sect_off
));
12926 /* Find if the concrete and abstract trees are structurally the
12927 same. This is a shallow traversal and it is not bullet-proof;
12928 the compiler can trick the debugger into believing that the trees
12929 are isomorphic, whereas they actually are not. However, the
12930 likelyhood of this happening is pretty low, and a full-fledged
12931 check would be an overkill. */
12932 bool are_isomorphic
= true;
12933 die_info
*concrete_child
= die
->child
;
12934 die_info
*abstract_child
= origin_die
->child
;
12935 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12937 if (concrete_child
== nullptr
12938 || abstract_child
== nullptr
12939 || concrete_child
->tag
!= abstract_child
->tag
)
12941 are_isomorphic
= false;
12945 concrete_child
= concrete_child
->sibling
;
12946 abstract_child
= abstract_child
->sibling
;
12949 /* Walk the origin's children in parallel to the concrete children.
12950 This helps match an origin child in case the debug info misses
12951 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12952 origin tree may not have the same tree structure as the concrete
12954 die_info
*corresponding_abstract_child
12955 = are_isomorphic
? origin_die
->child
: nullptr;
12957 std::vector
<sect_offset
> offsets
;
12959 for (child_die
= die
->child
;
12960 child_die
&& child_die
->tag
;
12961 child_die
= child_die
->sibling
)
12963 struct die_info
*child_origin_die
;
12964 struct dwarf2_cu
*child_origin_cu
;
12966 /* We are trying to process concrete instance entries:
12967 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12968 it's not relevant to our analysis here. i.e. detecting DIEs that are
12969 present in the abstract instance but not referenced in the concrete
12971 if (child_die
->tag
== DW_TAG_call_site
12972 || child_die
->tag
== DW_TAG_GNU_call_site
)
12974 if (are_isomorphic
)
12975 corresponding_abstract_child
12976 = corresponding_abstract_child
->sibling
;
12980 /* For each CHILD_DIE, find the corresponding child of
12981 ORIGIN_DIE. If there is more than one layer of
12982 DW_AT_abstract_origin, follow them all; there shouldn't be,
12983 but GCC versions at least through 4.4 generate this (GCC PR
12985 child_origin_die
= child_die
;
12986 child_origin_cu
= cu
;
12989 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12993 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12997 /* If missing DW_AT_abstract_origin, try the corresponding child
12998 of the origin. Clang emits such lexical scopes. */
12999 if (child_origin_die
== child_die
13000 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
13002 && child_die
->tag
== DW_TAG_lexical_block
)
13003 child_origin_die
= corresponding_abstract_child
;
13005 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13006 counterpart may exist. */
13007 if (child_origin_die
!= child_die
)
13009 if (child_die
->tag
!= child_origin_die
->tag
13010 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13011 && child_origin_die
->tag
== DW_TAG_subprogram
))
13012 complaint (_("Child DIE %s and its abstract origin %s have "
13014 sect_offset_str (child_die
->sect_off
),
13015 sect_offset_str (child_origin_die
->sect_off
));
13016 if (child_origin_die
->parent
!= origin_die
)
13017 complaint (_("Child DIE %s and its abstract origin %s have "
13018 "different parents"),
13019 sect_offset_str (child_die
->sect_off
),
13020 sect_offset_str (child_origin_die
->sect_off
));
13022 offsets
.push_back (child_origin_die
->sect_off
);
13025 if (are_isomorphic
)
13026 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
13028 std::sort (offsets
.begin (), offsets
.end ());
13029 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13030 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13031 if (offsetp
[-1] == *offsetp
)
13032 complaint (_("Multiple children of DIE %s refer "
13033 "to DIE %s as their abstract origin"),
13034 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13036 offsetp
= offsets
.data ();
13037 origin_child_die
= origin_die
->child
;
13038 while (origin_child_die
&& origin_child_die
->tag
)
13040 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13041 while (offsetp
< offsets_end
13042 && *offsetp
< origin_child_die
->sect_off
)
13044 if (offsetp
>= offsets_end
13045 || *offsetp
> origin_child_die
->sect_off
)
13047 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13048 Check whether we're already processing ORIGIN_CHILD_DIE.
13049 This can happen with mutually referenced abstract_origins.
13051 if (!origin_child_die
->in_process
)
13052 process_die (origin_child_die
, origin_cu
);
13054 origin_child_die
= origin_child_die
->sibling
;
13056 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13058 if (cu
!= origin_cu
)
13059 compute_delayed_physnames (origin_cu
);
13063 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13065 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13066 struct gdbarch
*gdbarch
= objfile
->arch ();
13067 struct context_stack
*newobj
;
13070 struct die_info
*child_die
;
13071 struct attribute
*attr
, *call_line
, *call_file
;
13073 CORE_ADDR baseaddr
;
13074 struct block
*block
;
13075 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13076 std::vector
<struct symbol
*> template_args
;
13077 struct template_symbol
*templ_func
= NULL
;
13081 /* If we do not have call site information, we can't show the
13082 caller of this inlined function. That's too confusing, so
13083 only use the scope for local variables. */
13084 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13085 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13086 if (call_line
== NULL
|| call_file
== NULL
)
13088 read_lexical_block_scope (die
, cu
);
13093 baseaddr
= objfile
->text_section_offset ();
13095 name
= dwarf2_name (die
, cu
);
13097 /* Ignore functions with missing or empty names. These are actually
13098 illegal according to the DWARF standard. */
13101 complaint (_("missing name for subprogram DIE at %s"),
13102 sect_offset_str (die
->sect_off
));
13106 /* Ignore functions with missing or invalid low and high pc attributes. */
13107 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr)
13108 <= PC_BOUNDS_INVALID
)
13110 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13111 if (attr
== nullptr || !attr
->as_boolean ())
13112 complaint (_("cannot get low and high bounds "
13113 "for subprogram DIE at %s"),
13114 sect_offset_str (die
->sect_off
));
13118 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13119 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13121 /* If we have any template arguments, then we must allocate a
13122 different sort of symbol. */
13123 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13125 if (child_die
->tag
== DW_TAG_template_type_param
13126 || child_die
->tag
== DW_TAG_template_value_param
)
13128 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13129 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13134 gdb_assert (cu
->get_builder () != nullptr);
13135 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13136 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13137 (struct symbol
*) templ_func
);
13139 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13140 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13143 /* If there is a location expression for DW_AT_frame_base, record
13145 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13146 if (attr
!= nullptr)
13147 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13149 /* If there is a location for the static link, record it. */
13150 newobj
->static_link
= NULL
;
13151 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13152 if (attr
!= nullptr)
13154 newobj
->static_link
13155 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13156 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13160 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13162 if (die
->child
!= NULL
)
13164 child_die
= die
->child
;
13165 while (child_die
&& child_die
->tag
)
13167 if (child_die
->tag
== DW_TAG_template_type_param
13168 || child_die
->tag
== DW_TAG_template_value_param
)
13170 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13173 template_args
.push_back (arg
);
13176 process_die (child_die
, cu
);
13177 child_die
= child_die
->sibling
;
13181 inherit_abstract_dies (die
, cu
);
13183 /* If we have a DW_AT_specification, we might need to import using
13184 directives from the context of the specification DIE. See the
13185 comment in determine_prefix. */
13186 if (cu
->per_cu
->lang
== language_cplus
13187 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13189 struct dwarf2_cu
*spec_cu
= cu
;
13190 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13194 child_die
= spec_die
->child
;
13195 while (child_die
&& child_die
->tag
)
13197 if (child_die
->tag
== DW_TAG_imported_module
)
13198 process_die (child_die
, spec_cu
);
13199 child_die
= child_die
->sibling
;
13202 /* In some cases, GCC generates specification DIEs that
13203 themselves contain DW_AT_specification attributes. */
13204 spec_die
= die_specification (spec_die
, &spec_cu
);
13208 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13209 /* Make a block for the local symbols within. */
13210 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13211 cstk
.static_link
, lowpc
, highpc
);
13213 /* For C++, set the block's scope. */
13214 if ((cu
->per_cu
->lang
== language_cplus
13215 || cu
->per_cu
->lang
== language_fortran
13216 || cu
->per_cu
->lang
== language_d
13217 || cu
->per_cu
->lang
== language_rust
)
13218 && cu
->processing_has_namespace_info
)
13219 block_set_scope (block
, determine_prefix (die
, cu
),
13220 &objfile
->objfile_obstack
);
13222 /* If we have address ranges, record them. */
13223 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13225 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13227 /* Attach template arguments to function. */
13228 if (!template_args
.empty ())
13230 gdb_assert (templ_func
!= NULL
);
13232 templ_func
->n_template_arguments
= template_args
.size ();
13233 templ_func
->template_arguments
13234 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13235 templ_func
->n_template_arguments
);
13236 memcpy (templ_func
->template_arguments
,
13237 template_args
.data (),
13238 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13240 /* Make sure that the symtab is set on the new symbols. Even
13241 though they don't appear in this symtab directly, other parts
13242 of gdb assume that symbols do, and this is reasonably
13244 for (symbol
*sym
: template_args
)
13245 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13248 /* In C++, we can have functions nested inside functions (e.g., when
13249 a function declares a class that has methods). This means that
13250 when we finish processing a function scope, we may need to go
13251 back to building a containing block's symbol lists. */
13252 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13253 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13255 /* If we've finished processing a top-level function, subsequent
13256 symbols go in the file symbol list. */
13257 if (cu
->get_builder ()->outermost_context_p ())
13258 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13261 /* Process all the DIES contained within a lexical block scope. Start
13262 a new scope, process the dies, and then close the scope. */
13265 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13267 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13268 struct gdbarch
*gdbarch
= objfile
->arch ();
13269 CORE_ADDR lowpc
, highpc
;
13270 struct die_info
*child_die
;
13271 CORE_ADDR baseaddr
;
13273 baseaddr
= objfile
->text_section_offset ();
13275 /* Ignore blocks with missing or invalid low and high pc attributes. */
13276 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13277 as multiple lexical blocks? Handling children in a sane way would
13278 be nasty. Might be easier to properly extend generic blocks to
13279 describe ranges. */
13280 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr))
13282 case PC_BOUNDS_NOT_PRESENT
:
13283 /* DW_TAG_lexical_block has no attributes, process its children as if
13284 there was no wrapping by that DW_TAG_lexical_block.
13285 GCC does no longer produces such DWARF since GCC r224161. */
13286 for (child_die
= die
->child
;
13287 child_die
!= NULL
&& child_die
->tag
;
13288 child_die
= child_die
->sibling
)
13290 /* We might already be processing this DIE. This can happen
13291 in an unusual circumstance -- where a subroutine A
13292 appears lexically in another subroutine B, but A actually
13293 inlines B. The recursion is broken here, rather than in
13294 inherit_abstract_dies, because it seems better to simply
13295 drop concrete children here. */
13296 if (!child_die
->in_process
)
13297 process_die (child_die
, cu
);
13300 case PC_BOUNDS_INVALID
:
13303 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13304 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13306 cu
->get_builder ()->push_context (0, lowpc
);
13307 if (die
->child
!= NULL
)
13309 child_die
= die
->child
;
13310 while (child_die
&& child_die
->tag
)
13312 process_die (child_die
, cu
);
13313 child_die
= child_die
->sibling
;
13316 inherit_abstract_dies (die
, cu
);
13317 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13319 if (*cu
->get_builder ()->get_local_symbols () != NULL
13320 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13322 struct block
*block
13323 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13324 cstk
.start_addr
, highpc
);
13326 /* Note that recording ranges after traversing children, as we
13327 do here, means that recording a parent's ranges entails
13328 walking across all its children's ranges as they appear in
13329 the address map, which is quadratic behavior.
13331 It would be nicer to record the parent's ranges before
13332 traversing its children, simply overriding whatever you find
13333 there. But since we don't even decide whether to create a
13334 block until after we've traversed its children, that's hard
13336 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13338 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13339 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13342 static void dwarf2_ranges_read_low_addrs (unsigned offset
,
13343 struct dwarf2_cu
*cu
,
13345 std::vector
<CORE_ADDR
> &result
);
13347 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13350 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13352 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13353 struct objfile
*objfile
= per_objfile
->objfile
;
13354 struct gdbarch
*gdbarch
= objfile
->arch ();
13355 CORE_ADDR pc
, baseaddr
;
13356 struct attribute
*attr
;
13359 struct die_info
*child_die
;
13361 baseaddr
= objfile
->text_section_offset ();
13363 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13366 /* This was a pre-DWARF-5 GNU extension alias
13367 for DW_AT_call_return_pc. */
13368 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13372 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13373 "DIE %s [in module %s]"),
13374 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13377 pc
= attr
->as_address () + baseaddr
;
13378 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13381 if (cu
->call_site_htab
== NULL
)
13382 cu
->call_site_htab
= htab_create_alloc_ex (16, call_site::hash
,
13383 call_site::eq
, NULL
,
13384 &objfile
->objfile_obstack
,
13385 hashtab_obstack_allocate
, NULL
);
13386 struct call_site
call_site_local (pc
, nullptr, nullptr);
13387 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13390 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13391 "DIE %s [in module %s]"),
13392 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13393 objfile_name (objfile
));
13397 /* Count parameters at the caller. */
13400 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13401 child_die
= child_die
->sibling
)
13403 if (child_die
->tag
!= DW_TAG_call_site_parameter
13404 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13406 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13407 "DW_TAG_call_site child DIE %s [in module %s]"),
13408 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13409 objfile_name (objfile
));
13416 struct call_site
*call_site
13417 = new (XOBNEWVAR (&objfile
->objfile_obstack
,
13419 sizeof (*call_site
) + sizeof (call_site
->parameter
[0]) * nparams
))
13420 struct call_site (pc
, cu
->per_cu
, per_objfile
);
13423 /* We never call the destructor of call_site, so we must ensure it is
13424 trivially destructible. */
13425 gdb_static_assert(std::is_trivially_destructible
<struct call_site
>::value
);
13427 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13428 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13430 struct die_info
*func_die
;
13432 /* Skip also over DW_TAG_inlined_subroutine. */
13433 for (func_die
= die
->parent
;
13434 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13435 && func_die
->tag
!= DW_TAG_subroutine_type
;
13436 func_die
= func_die
->parent
);
13438 /* DW_AT_call_all_calls is a superset
13439 of DW_AT_call_all_tail_calls. */
13441 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13442 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13443 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13444 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13446 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13447 not complete. But keep CALL_SITE for look ups via call_site_htab,
13448 both the initial caller containing the real return address PC and
13449 the final callee containing the current PC of a chain of tail
13450 calls do not need to have the tail call list complete. But any
13451 function candidate for a virtual tail call frame searched via
13452 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13453 determined unambiguously. */
13457 struct type
*func_type
= NULL
;
13460 func_type
= get_die_type (func_die
, cu
);
13461 if (func_type
!= NULL
)
13463 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13465 /* Enlist this call site to the function. */
13466 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13467 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13470 complaint (_("Cannot find function owning DW_TAG_call_site "
13471 "DIE %s [in module %s]"),
13472 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13476 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13478 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13480 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13483 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13484 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13487 call_site
->target
.set_loc_dwarf_block (nullptr);
13488 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13489 /* Keep NULL DWARF_BLOCK. */;
13490 else if (attr
->form_is_block ())
13492 struct dwarf2_locexpr_baton
*dlbaton
;
13493 struct dwarf_block
*block
= attr
->as_block ();
13495 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13496 dlbaton
->data
= block
->data
;
13497 dlbaton
->size
= block
->size
;
13498 dlbaton
->per_objfile
= per_objfile
;
13499 dlbaton
->per_cu
= cu
->per_cu
;
13501 call_site
->target
.set_loc_dwarf_block (dlbaton
);
13503 else if (attr
->form_is_ref ())
13505 struct dwarf2_cu
*target_cu
= cu
;
13506 struct die_info
*target_die
;
13508 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13509 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13511 struct attribute
*ranges_attr
13512 = dwarf2_attr (target_die
, DW_AT_ranges
, target_cu
);
13514 if (die_is_declaration (target_die
, target_cu
))
13516 const char *target_physname
;
13518 /* Prefer the mangled name; otherwise compute the demangled one. */
13519 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13520 if (target_physname
== NULL
)
13521 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13522 if (target_physname
== NULL
)
13523 complaint (_("DW_AT_call_target target DIE has invalid "
13524 "physname, for referencing DIE %s [in module %s]"),
13525 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13527 call_site
->target
.set_loc_physname (target_physname
);
13529 else if (ranges_attr
!= nullptr && ranges_attr
->form_is_unsigned ())
13531 ULONGEST ranges_offset
= (ranges_attr
->as_unsigned ()
13532 + target_cu
->gnu_ranges_base
);
13533 std::vector
<CORE_ADDR
> addresses
;
13534 dwarf2_ranges_read_low_addrs (ranges_offset
, target_cu
,
13535 target_die
->tag
, addresses
);
13536 CORE_ADDR
*saved
= XOBNEWVAR (&objfile
->objfile_obstack
, CORE_ADDR
,
13537 addresses
.size ());
13538 std::copy (addresses
.begin (), addresses
.end (), saved
);
13539 call_site
->target
.set_loc_array (addresses
.size (), saved
);
13545 /* DW_AT_entry_pc should be preferred. */
13546 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
,
13548 <= PC_BOUNDS_INVALID
)
13549 complaint (_("DW_AT_call_target target DIE has invalid "
13550 "low pc, for referencing DIE %s [in module %s]"),
13551 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13554 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
)
13556 call_site
->target
.set_loc_physaddr (lowpc
);
13561 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13562 "block nor reference, for DIE %s [in module %s]"),
13563 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13565 for (child_die
= die
->child
;
13566 child_die
&& child_die
->tag
;
13567 child_die
= child_die
->sibling
)
13569 struct call_site_parameter
*parameter
;
13570 struct attribute
*loc
, *origin
;
13572 if (child_die
->tag
!= DW_TAG_call_site_parameter
13573 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13575 /* Already printed the complaint above. */
13579 gdb_assert (call_site
->parameter_count
< nparams
);
13580 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13582 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13583 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13584 register is contained in DW_AT_call_value. */
13586 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13587 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13588 if (origin
== NULL
)
13590 /* This was a pre-DWARF-5 GNU extension alias
13591 for DW_AT_call_parameter. */
13592 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13594 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13596 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13598 sect_offset sect_off
= origin
->get_ref_die_offset ();
13599 if (!cu
->header
.offset_in_cu_p (sect_off
))
13601 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13602 binding can be done only inside one CU. Such referenced DIE
13603 therefore cannot be even moved to DW_TAG_partial_unit. */
13604 complaint (_("DW_AT_call_parameter offset is not in CU for "
13605 "DW_TAG_call_site child DIE %s [in module %s]"),
13606 sect_offset_str (child_die
->sect_off
),
13607 objfile_name (objfile
));
13610 parameter
->u
.param_cu_off
13611 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13613 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13615 complaint (_("No DW_FORM_block* DW_AT_location for "
13616 "DW_TAG_call_site child DIE %s [in module %s]"),
13617 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13622 struct dwarf_block
*block
= loc
->as_block ();
13624 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13625 (block
->data
, &block
->data
[block
->size
]);
13626 if (parameter
->u
.dwarf_reg
!= -1)
13627 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13628 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13629 &block
->data
[block
->size
],
13630 ¶meter
->u
.fb_offset
))
13631 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13634 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13635 "for DW_FORM_block* DW_AT_location is supported for "
13636 "DW_TAG_call_site child DIE %s "
13638 sect_offset_str (child_die
->sect_off
),
13639 objfile_name (objfile
));
13644 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13646 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13647 if (attr
== NULL
|| !attr
->form_is_block ())
13649 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13650 "DW_TAG_call_site child DIE %s [in module %s]"),
13651 sect_offset_str (child_die
->sect_off
),
13652 objfile_name (objfile
));
13656 struct dwarf_block
*block
= attr
->as_block ();
13657 parameter
->value
= block
->data
;
13658 parameter
->value_size
= block
->size
;
13660 /* Parameters are not pre-cleared by memset above. */
13661 parameter
->data_value
= NULL
;
13662 parameter
->data_value_size
= 0;
13663 call_site
->parameter_count
++;
13665 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13667 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13668 if (attr
!= nullptr)
13670 if (!attr
->form_is_block ())
13671 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13672 "DW_TAG_call_site child DIE %s [in module %s]"),
13673 sect_offset_str (child_die
->sect_off
),
13674 objfile_name (objfile
));
13677 block
= attr
->as_block ();
13678 parameter
->data_value
= block
->data
;
13679 parameter
->data_value_size
= block
->size
;
13685 /* Helper function for read_variable. If DIE represents a virtual
13686 table, then return the type of the concrete object that is
13687 associated with the virtual table. Otherwise, return NULL. */
13689 static struct type
*
13690 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13692 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13696 /* Find the type DIE. */
13697 struct die_info
*type_die
= NULL
;
13698 struct dwarf2_cu
*type_cu
= cu
;
13700 if (attr
->form_is_ref ())
13701 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13702 if (type_die
== NULL
)
13705 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13707 return die_containing_type (type_die
, type_cu
);
13710 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13713 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13715 struct rust_vtable_symbol
*storage
= NULL
;
13717 if (cu
->per_cu
->lang
== language_rust
)
13719 struct type
*containing_type
= rust_containing_type (die
, cu
);
13721 if (containing_type
!= NULL
)
13723 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13725 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13726 storage
->concrete_type
= containing_type
;
13727 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13731 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13732 struct attribute
*abstract_origin
13733 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13734 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13735 if (res
== NULL
&& loc
&& abstract_origin
)
13737 /* We have a variable without a name, but with a location and an abstract
13738 origin. This may be a concrete instance of an abstract variable
13739 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13741 struct dwarf2_cu
*origin_cu
= cu
;
13742 struct die_info
*origin_die
13743 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13744 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13745 per_objfile
->per_bfd
->abstract_to_concrete
13746 [origin_die
->sect_off
].push_back (die
->sect_off
);
13750 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13751 reading .debug_rnglists.
13752 Callback's type should be:
13753 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13754 Return true if the attributes are present and valid, otherwise,
13757 template <typename Callback
>
13759 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13760 dwarf_tag tag
, Callback
&&callback
)
13762 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13763 struct objfile
*objfile
= per_objfile
->objfile
;
13764 bfd
*obfd
= objfile
->obfd
;
13765 /* Base address selection entry. */
13766 gdb::optional
<CORE_ADDR
> base
;
13767 const gdb_byte
*buffer
;
13768 bool overflow
= false;
13769 ULONGEST addr_index
;
13770 struct dwarf2_section_info
*rnglists_section
;
13772 base
= cu
->base_address
;
13773 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13774 rnglists_section
->read (objfile
);
13776 if (offset
>= rnglists_section
->size
)
13778 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13782 buffer
= rnglists_section
->buffer
+ offset
;
13786 /* Initialize it due to a false compiler warning. */
13787 CORE_ADDR range_beginning
= 0, range_end
= 0;
13788 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13789 + rnglists_section
->size
);
13790 unsigned int bytes_read
;
13792 if (buffer
== buf_end
)
13797 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13800 case DW_RLE_end_of_list
:
13802 case DW_RLE_base_address
:
13803 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13808 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13809 buffer
+= bytes_read
;
13811 case DW_RLE_base_addressx
:
13812 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13813 buffer
+= bytes_read
;
13814 base
= read_addr_index (cu
, addr_index
);
13816 case DW_RLE_start_length
:
13817 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13822 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13824 buffer
+= bytes_read
;
13825 range_end
= (range_beginning
13826 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13827 buffer
+= bytes_read
;
13828 if (buffer
> buf_end
)
13834 case DW_RLE_startx_length
:
13835 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13836 buffer
+= bytes_read
;
13837 range_beginning
= read_addr_index (cu
, addr_index
);
13838 if (buffer
> buf_end
)
13843 range_end
= (range_beginning
13844 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13845 buffer
+= bytes_read
;
13847 case DW_RLE_offset_pair
:
13848 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13849 buffer
+= bytes_read
;
13850 if (buffer
> buf_end
)
13855 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13856 buffer
+= bytes_read
;
13857 if (buffer
> buf_end
)
13863 case DW_RLE_start_end
:
13864 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13869 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13871 buffer
+= bytes_read
;
13872 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13873 buffer
+= bytes_read
;
13875 case DW_RLE_startx_endx
:
13876 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13877 buffer
+= bytes_read
;
13878 range_beginning
= read_addr_index (cu
, addr_index
);
13879 if (buffer
> buf_end
)
13884 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13885 buffer
+= bytes_read
;
13886 range_end
= read_addr_index (cu
, addr_index
);
13889 complaint (_("Invalid .debug_rnglists data (no base address)"));
13892 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13894 if (rlet
== DW_RLE_base_address
)
13897 if (range_beginning
> range_end
)
13899 /* Inverted range entries are invalid. */
13900 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13904 /* Empty range entries have no effect. */
13905 if (range_beginning
== range_end
)
13908 /* Only DW_RLE_offset_pair needs the base address added. */
13909 if (rlet
== DW_RLE_offset_pair
)
13911 if (!base
.has_value ())
13913 /* We have no valid base address for the DW_RLE_offset_pair. */
13914 complaint (_("Invalid .debug_rnglists data (no base address for "
13915 "DW_RLE_offset_pair)"));
13919 range_beginning
+= *base
;
13920 range_end
+= *base
;
13923 /* A not-uncommon case of bad debug info.
13924 Don't pollute the addrmap with bad data. */
13925 if (range_beginning
== 0
13926 && !per_objfile
->per_bfd
->has_section_at_zero
)
13928 complaint (_(".debug_rnglists entry has start address of zero"
13929 " [in module %s]"), objfile_name (objfile
));
13933 callback (range_beginning
, range_end
);
13938 complaint (_("Offset %d is not terminated "
13939 "for DW_AT_ranges attribute"),
13947 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13948 Callback's type should be:
13949 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13950 Return 1 if the attributes are present and valid, otherwise, return 0. */
13952 template <typename Callback
>
13954 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13955 Callback
&&callback
)
13957 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13958 struct objfile
*objfile
= per_objfile
->objfile
;
13959 struct comp_unit_head
*cu_header
= &cu
->header
;
13960 bfd
*obfd
= objfile
->obfd
;
13961 unsigned int addr_size
= cu_header
->addr_size
;
13962 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13963 /* Base address selection entry. */
13964 gdb::optional
<CORE_ADDR
> base
;
13965 unsigned int dummy
;
13966 const gdb_byte
*buffer
;
13968 if (cu_header
->version
>= 5)
13969 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13971 base
= cu
->base_address
;
13973 per_objfile
->per_bfd
->ranges
.read (objfile
);
13974 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13976 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13980 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13984 CORE_ADDR range_beginning
, range_end
;
13986 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13987 buffer
+= addr_size
;
13988 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13989 buffer
+= addr_size
;
13990 offset
+= 2 * addr_size
;
13992 /* An end of list marker is a pair of zero addresses. */
13993 if (range_beginning
== 0 && range_end
== 0)
13994 /* Found the end of list entry. */
13997 /* Each base address selection entry is a pair of 2 values.
13998 The first is the largest possible address, the second is
13999 the base address. Check for a base address here. */
14000 if ((range_beginning
& mask
) == mask
)
14002 /* If we found the largest possible address, then we already
14003 have the base address in range_end. */
14008 if (!base
.has_value ())
14010 /* We have no valid base address for the ranges
14012 complaint (_("Invalid .debug_ranges data (no base address)"));
14016 if (range_beginning
> range_end
)
14018 /* Inverted range entries are invalid. */
14019 complaint (_("Invalid .debug_ranges data (inverted range)"));
14023 /* Empty range entries have no effect. */
14024 if (range_beginning
== range_end
)
14027 range_beginning
+= *base
;
14028 range_end
+= *base
;
14030 /* A not-uncommon case of bad debug info.
14031 Don't pollute the addrmap with bad data. */
14032 if (range_beginning
== 0
14033 && !per_objfile
->per_bfd
->has_section_at_zero
)
14035 complaint (_(".debug_ranges entry has start address of zero"
14036 " [in module %s]"), objfile_name (objfile
));
14040 callback (range_beginning
, range_end
);
14046 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14047 Return 1 if the attributes are present and valid, otherwise, return 0.
14048 TAG is passed to dwarf2_ranges_process. If MAP is not NULL, then
14049 ranges in MAP are set, using DATUM as the value. */
14052 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14053 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14054 addrmap
*map
, void *datum
, dwarf_tag tag
)
14056 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14057 struct gdbarch
*gdbarch
= objfile
->arch ();
14058 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14061 CORE_ADDR high
= 0;
14064 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14065 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14067 if (map
!= nullptr)
14072 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14073 range_beginning
+ baseaddr
)
14075 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14076 range_end
+ baseaddr
)
14078 addrmap_set_empty (map
, lowpc
, highpc
- 1, datum
);
14081 /* FIXME: This is recording everything as a low-high
14082 segment of consecutive addresses. We should have a
14083 data structure for discontiguous block ranges
14087 low
= range_beginning
;
14093 if (range_beginning
< low
)
14094 low
= range_beginning
;
14095 if (range_end
> high
)
14103 /* If the first entry is an end-of-list marker, the range
14104 describes an empty scope, i.e. no instructions. */
14110 *high_return
= high
;
14114 /* Process ranges and fill in a vector of the low PC values only. */
14117 dwarf2_ranges_read_low_addrs (unsigned offset
, struct dwarf2_cu
*cu
,
14119 std::vector
<CORE_ADDR
> &result
)
14121 dwarf2_ranges_process (offset
, cu
, tag
,
14122 [&] (CORE_ADDR start
, CORE_ADDR end
)
14124 result
.push_back (start
);
14128 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14129 definition for the return value. *LOWPC and *HIGHPC are set iff
14130 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14132 static enum pc_bounds_kind
14133 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14134 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14135 addrmap
*map
, void *datum
)
14137 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14138 struct attribute
*attr
;
14139 struct attribute
*attr_high
;
14141 CORE_ADDR high
= 0;
14142 enum pc_bounds_kind ret
;
14144 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14147 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14148 if (attr
!= nullptr)
14150 low
= attr
->as_address ();
14151 high
= attr_high
->as_address ();
14152 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14156 /* Found high w/o low attribute. */
14157 return PC_BOUNDS_INVALID
;
14159 /* Found consecutive range of addresses. */
14160 ret
= PC_BOUNDS_HIGH_LOW
;
14164 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14165 if (attr
!= nullptr && attr
->form_is_unsigned ())
14167 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14168 on DWARF version). */
14169 ULONGEST ranges_offset
= attr
->as_unsigned ();
14171 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14173 if (die
->tag
!= DW_TAG_compile_unit
)
14174 ranges_offset
+= cu
->gnu_ranges_base
;
14176 /* Value of the DW_AT_ranges attribute is the offset in the
14177 .debug_ranges section. */
14178 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
,
14179 map
, datum
, die
->tag
))
14180 return PC_BOUNDS_INVALID
;
14181 /* Found discontinuous range of addresses. */
14182 ret
= PC_BOUNDS_RANGES
;
14185 return PC_BOUNDS_NOT_PRESENT
;
14188 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14190 return PC_BOUNDS_INVALID
;
14192 /* When using the GNU linker, .gnu.linkonce. sections are used to
14193 eliminate duplicate copies of functions and vtables and such.
14194 The linker will arbitrarily choose one and discard the others.
14195 The AT_*_pc values for such functions refer to local labels in
14196 these sections. If the section from that file was discarded, the
14197 labels are not in the output, so the relocs get a value of 0.
14198 If this is a discarded function, mark the pc bounds as invalid,
14199 so that GDB will ignore it. */
14200 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14201 return PC_BOUNDS_INVALID
;
14209 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14210 its low and high PC addresses. Do nothing if these addresses could not
14211 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14212 and HIGHPC to the high address if greater than HIGHPC. */
14215 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14216 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14217 struct dwarf2_cu
*cu
)
14219 CORE_ADDR low
, high
;
14220 struct die_info
*child
= die
->child
;
14222 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, nullptr, nullptr)
14223 >= PC_BOUNDS_RANGES
)
14225 *lowpc
= std::min (*lowpc
, low
);
14226 *highpc
= std::max (*highpc
, high
);
14229 /* If the language does not allow nested subprograms (either inside
14230 subprograms or lexical blocks), we're done. */
14231 if (cu
->per_cu
->lang
!= language_ada
)
14234 /* Check all the children of the given DIE. If it contains nested
14235 subprograms, then check their pc bounds. Likewise, we need to
14236 check lexical blocks as well, as they may also contain subprogram
14238 while (child
&& child
->tag
)
14240 if (child
->tag
== DW_TAG_subprogram
14241 || child
->tag
== DW_TAG_lexical_block
)
14242 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14243 child
= child
->sibling
;
14247 /* Get the low and high pc's represented by the scope DIE, and store
14248 them in *LOWPC and *HIGHPC. If the correct values can't be
14249 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14252 get_scope_pc_bounds (struct die_info
*die
,
14253 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14254 struct dwarf2_cu
*cu
)
14256 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14257 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14258 CORE_ADDR current_low
, current_high
;
14260 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
,
14262 >= PC_BOUNDS_RANGES
)
14264 best_low
= current_low
;
14265 best_high
= current_high
;
14269 struct die_info
*child
= die
->child
;
14271 while (child
&& child
->tag
)
14273 switch (child
->tag
) {
14274 case DW_TAG_subprogram
:
14275 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14277 case DW_TAG_namespace
:
14278 case DW_TAG_module
:
14279 /* FIXME: carlton/2004-01-16: Should we do this for
14280 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14281 that current GCC's always emit the DIEs corresponding
14282 to definitions of methods of classes as children of a
14283 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14284 the DIEs giving the declarations, which could be
14285 anywhere). But I don't see any reason why the
14286 standards says that they have to be there. */
14287 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14289 if (current_low
!= ((CORE_ADDR
) -1))
14291 best_low
= std::min (best_low
, current_low
);
14292 best_high
= std::max (best_high
, current_high
);
14300 child
= child
->sibling
;
14305 *highpc
= best_high
;
14308 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14312 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14313 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14315 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14316 struct gdbarch
*gdbarch
= objfile
->arch ();
14317 struct attribute
*attr
;
14318 struct attribute
*attr_high
;
14320 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14323 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14324 if (attr
!= nullptr)
14326 CORE_ADDR low
= attr
->as_address ();
14327 CORE_ADDR high
= attr_high
->as_address ();
14329 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14332 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14333 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14334 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14338 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14339 if (attr
!= nullptr && attr
->form_is_unsigned ())
14341 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14342 on DWARF version). */
14343 ULONGEST ranges_offset
= attr
->as_unsigned ();
14345 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14347 if (die
->tag
!= DW_TAG_compile_unit
)
14348 ranges_offset
+= cu
->gnu_ranges_base
;
14350 std::vector
<blockrange
> blockvec
;
14351 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14352 [&] (CORE_ADDR start
, CORE_ADDR end
)
14356 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14357 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14358 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14359 blockvec
.emplace_back (start
, end
);
14362 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14366 /* Check whether the producer field indicates either of GCC < 4.6, or the
14367 Intel C/C++ compiler, and cache the result in CU. */
14370 check_producer (struct dwarf2_cu
*cu
)
14374 if (cu
->producer
== NULL
)
14376 /* For unknown compilers expect their behavior is DWARF version
14379 GCC started to support .debug_types sections by -gdwarf-4 since
14380 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14381 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14382 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14383 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14385 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14387 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14388 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14389 cu
->producer_is_gcc_11
= major
== 11;
14391 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14393 cu
->producer_is_icc
= true;
14394 cu
->producer_is_icc_lt_14
= major
< 14;
14396 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14397 cu
->producer_is_codewarrior
= true;
14400 /* For other non-GCC compilers, expect their behavior is DWARF version
14404 cu
->checked_producer
= true;
14407 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14408 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14409 during 4.6.0 experimental. */
14412 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14414 if (!cu
->checked_producer
)
14415 check_producer (cu
);
14417 return cu
->producer_is_gxx_lt_4_6
;
14421 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14422 with incorrect is_stmt attributes. */
14425 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14427 if (!cu
->checked_producer
)
14428 check_producer (cu
);
14430 return cu
->producer_is_codewarrior
;
14433 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14434 If that attribute is not available, return the appropriate
14437 static enum dwarf_access_attribute
14438 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14440 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14441 if (attr
!= nullptr)
14443 LONGEST value
= attr
->constant_value (-1);
14444 if (value
== DW_ACCESS_public
14445 || value
== DW_ACCESS_protected
14446 || value
== DW_ACCESS_private
)
14447 return (dwarf_access_attribute
) value
;
14448 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14452 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14454 /* The default DWARF 2 accessibility for members is public, the default
14455 accessibility for inheritance is private. */
14457 if (die
->tag
!= DW_TAG_inheritance
)
14458 return DW_ACCESS_public
;
14460 return DW_ACCESS_private
;
14464 /* DWARF 3+ defines the default accessibility a different way. The same
14465 rules apply now for DW_TAG_inheritance as for the members and it only
14466 depends on the container kind. */
14468 if (die
->parent
->tag
== DW_TAG_class_type
)
14469 return DW_ACCESS_private
;
14471 return DW_ACCESS_public
;
14475 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
14476 *OFFSET to the byte offset. If the attribute was not found return
14477 0, otherwise return 1. If it was found but could not properly be
14478 handled, set *OFFSET to 0. */
14481 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14484 struct attribute
*attr
;
14486 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14491 /* Note that we do not check for a section offset first here.
14492 This is because DW_AT_data_member_location is new in DWARF 4,
14493 so if we see it, we can assume that a constant form is really
14494 a constant and not a section offset. */
14495 if (attr
->form_is_constant ())
14496 *offset
= attr
->constant_value (0);
14497 else if (attr
->form_is_section_offset ())
14498 dwarf2_complex_location_expr_complaint ();
14499 else if (attr
->form_is_block ())
14500 *offset
= decode_locdesc (attr
->as_block (), cu
);
14502 dwarf2_complex_location_expr_complaint ();
14508 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14509 if (attr
!= nullptr)
14511 *offset
= attr
->constant_value (0);
14519 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
14520 store the results in FIELD. */
14523 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14524 struct field
*field
)
14526 struct attribute
*attr
;
14528 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14531 if (attr
->form_is_constant ())
14533 LONGEST offset
= attr
->constant_value (0);
14535 /* Work around this GCC 11 bug, where it would erroneously use -1
14536 data member locations, instead of 0:
14538 Negative DW_AT_data_member_location
14539 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
14541 if (offset
== -1 && cu
->producer_is_gcc_11
)
14543 complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
14547 field
->set_loc_bitpos (offset
* bits_per_byte
);
14549 else if (attr
->form_is_section_offset ())
14550 dwarf2_complex_location_expr_complaint ();
14551 else if (attr
->form_is_block ())
14554 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14556 field
->set_loc_bitpos (offset
* bits_per_byte
);
14559 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14560 struct objfile
*objfile
= per_objfile
->objfile
;
14561 struct dwarf2_locexpr_baton
*dlbaton
14562 = XOBNEW (&objfile
->objfile_obstack
,
14563 struct dwarf2_locexpr_baton
);
14564 dlbaton
->data
= attr
->as_block ()->data
;
14565 dlbaton
->size
= attr
->as_block ()->size
;
14566 /* When using this baton, we want to compute the address
14567 of the field, not the value. This is why
14568 is_reference is set to false here. */
14569 dlbaton
->is_reference
= false;
14570 dlbaton
->per_objfile
= per_objfile
;
14571 dlbaton
->per_cu
= cu
->per_cu
;
14573 field
->set_loc_dwarf_block (dlbaton
);
14577 dwarf2_complex_location_expr_complaint ();
14581 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14582 if (attr
!= nullptr)
14583 field
->set_loc_bitpos (attr
->constant_value (0));
14587 /* Add an aggregate field to the field list. */
14590 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14591 struct dwarf2_cu
*cu
)
14593 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14594 struct gdbarch
*gdbarch
= objfile
->arch ();
14595 struct nextfield
*new_field
;
14596 struct attribute
*attr
;
14598 const char *fieldname
= "";
14600 if (die
->tag
== DW_TAG_inheritance
)
14602 fip
->baseclasses
.emplace_back ();
14603 new_field
= &fip
->baseclasses
.back ();
14607 fip
->fields
.emplace_back ();
14608 new_field
= &fip
->fields
.back ();
14611 new_field
->offset
= die
->sect_off
;
14613 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14614 if (new_field
->accessibility
!= DW_ACCESS_public
)
14615 fip
->non_public_fields
= true;
14617 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14618 if (attr
!= nullptr)
14619 new_field
->virtuality
= attr
->as_virtuality ();
14621 new_field
->virtuality
= DW_VIRTUALITY_none
;
14623 fp
= &new_field
->field
;
14625 if ((die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_namelist_item
)
14626 && !die_is_declaration (die
, cu
))
14628 if (die
->tag
== DW_TAG_namelist_item
)
14630 /* Typically, DW_TAG_namelist_item are references to namelist items.
14631 If so, follow that reference. */
14632 struct attribute
*attr1
= dwarf2_attr (die
, DW_AT_namelist_item
, cu
);
14633 struct die_info
*item_die
= nullptr;
14634 struct dwarf2_cu
*item_cu
= cu
;
14635 if (attr1
->form_is_ref ())
14636 item_die
= follow_die_ref (die
, attr1
, &item_cu
);
14637 if (item_die
!= nullptr)
14640 /* Data member other than a C++ static data member. */
14642 /* Get type of field. */
14643 fp
->set_type (die_type (die
, cu
));
14645 fp
->set_loc_bitpos (0);
14647 /* Get bit size of field (zero if none). */
14648 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14649 if (attr
!= nullptr)
14651 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14655 FIELD_BITSIZE (*fp
) = 0;
14658 /* Get bit offset of field. */
14659 handle_member_location (die
, cu
, fp
);
14660 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14661 if (attr
!= nullptr && attr
->form_is_constant ())
14663 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14665 /* For big endian bits, the DW_AT_bit_offset gives the
14666 additional bit offset from the MSB of the containing
14667 anonymous object to the MSB of the field. We don't
14668 have to do anything special since we don't need to
14669 know the size of the anonymous object. */
14670 fp
->set_loc_bitpos (fp
->loc_bitpos () + attr
->constant_value (0));
14674 /* For little endian bits, compute the bit offset to the
14675 MSB of the anonymous object, subtract off the number of
14676 bits from the MSB of the field to the MSB of the
14677 object, and then subtract off the number of bits of
14678 the field itself. The result is the bit offset of
14679 the LSB of the field. */
14680 int anonymous_size
;
14681 int bit_offset
= attr
->constant_value (0);
14683 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14684 if (attr
!= nullptr && attr
->form_is_constant ())
14686 /* The size of the anonymous object containing
14687 the bit field is explicit, so use the
14688 indicated size (in bytes). */
14689 anonymous_size
= attr
->constant_value (0);
14693 /* The size of the anonymous object containing
14694 the bit field must be inferred from the type
14695 attribute of the data member containing the
14697 anonymous_size
= TYPE_LENGTH (fp
->type ());
14699 fp
->set_loc_bitpos (fp
->loc_bitpos ()
14700 + anonymous_size
* bits_per_byte
14701 - bit_offset
- FIELD_BITSIZE (*fp
));
14705 /* Get name of field. */
14706 fieldname
= dwarf2_name (die
, cu
);
14707 if (fieldname
== NULL
)
14710 /* The name is already allocated along with this objfile, so we don't
14711 need to duplicate it for the type. */
14712 fp
->set_name (fieldname
);
14714 /* Change accessibility for artificial fields (e.g. virtual table
14715 pointer or virtual base class pointer) to private. */
14716 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14718 FIELD_ARTIFICIAL (*fp
) = 1;
14719 new_field
->accessibility
= DW_ACCESS_private
;
14720 fip
->non_public_fields
= true;
14723 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14725 /* C++ static member. */
14727 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14728 is a declaration, but all versions of G++ as of this writing
14729 (so through at least 3.2.1) incorrectly generate
14730 DW_TAG_variable tags. */
14732 const char *physname
;
14734 /* Get name of field. */
14735 fieldname
= dwarf2_name (die
, cu
);
14736 if (fieldname
== NULL
)
14739 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14741 /* Only create a symbol if this is an external value.
14742 new_symbol checks this and puts the value in the global symbol
14743 table, which we want. If it is not external, new_symbol
14744 will try to put the value in cu->list_in_scope which is wrong. */
14745 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14747 /* A static const member, not much different than an enum as far as
14748 we're concerned, except that we can support more types. */
14749 new_symbol (die
, NULL
, cu
);
14752 /* Get physical name. */
14753 physname
= dwarf2_physname (fieldname
, die
, cu
);
14755 /* The name is already allocated along with this objfile, so we don't
14756 need to duplicate it for the type. */
14757 fp
->set_loc_physname (physname
? physname
: "");
14758 fp
->set_type (die_type (die
, cu
));
14759 fp
->set_name (fieldname
);
14761 else if (die
->tag
== DW_TAG_inheritance
)
14763 /* C++ base class field. */
14764 handle_member_location (die
, cu
, fp
);
14765 FIELD_BITSIZE (*fp
) = 0;
14766 fp
->set_type (die_type (die
, cu
));
14767 fp
->set_name (fp
->type ()->name ());
14770 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14773 /* Can the type given by DIE define another type? */
14776 type_can_define_types (const struct die_info
*die
)
14780 case DW_TAG_typedef
:
14781 case DW_TAG_class_type
:
14782 case DW_TAG_structure_type
:
14783 case DW_TAG_union_type
:
14784 case DW_TAG_enumeration_type
:
14792 /* Add a type definition defined in the scope of the FIP's class. */
14795 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14796 struct dwarf2_cu
*cu
)
14798 struct decl_field fp
;
14799 memset (&fp
, 0, sizeof (fp
));
14801 gdb_assert (type_can_define_types (die
));
14803 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14804 fp
.name
= dwarf2_name (die
, cu
);
14805 fp
.type
= read_type_die (die
, cu
);
14807 /* Save accessibility. */
14808 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14809 switch (accessibility
)
14811 case DW_ACCESS_public
:
14812 /* The assumed value if neither private nor protected. */
14814 case DW_ACCESS_private
:
14817 case DW_ACCESS_protected
:
14818 fp
.is_protected
= 1;
14822 if (die
->tag
== DW_TAG_typedef
)
14823 fip
->typedef_field_list
.push_back (fp
);
14825 fip
->nested_types_list
.push_back (fp
);
14828 /* A convenience typedef that's used when finding the discriminant
14829 field for a variant part. */
14830 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14833 /* Compute the discriminant range for a given variant. OBSTACK is
14834 where the results will be stored. VARIANT is the variant to
14835 process. IS_UNSIGNED indicates whether the discriminant is signed
14838 static const gdb::array_view
<discriminant_range
>
14839 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14842 std::vector
<discriminant_range
> ranges
;
14844 if (variant
.default_branch
)
14847 if (variant
.discr_list_data
== nullptr)
14849 discriminant_range r
14850 = {variant
.discriminant_value
, variant
.discriminant_value
};
14851 ranges
.push_back (r
);
14855 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14856 variant
.discr_list_data
->size
);
14857 while (!data
.empty ())
14859 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14861 complaint (_("invalid discriminant marker: %d"), data
[0]);
14864 bool is_range
= data
[0] == DW_DSC_range
;
14865 data
= data
.slice (1);
14867 ULONGEST low
, high
;
14868 unsigned int bytes_read
;
14872 complaint (_("DW_AT_discr_list missing low value"));
14876 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14878 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14880 data
= data
.slice (bytes_read
);
14886 complaint (_("DW_AT_discr_list missing high value"));
14890 high
= read_unsigned_leb128 (nullptr, data
.data (),
14893 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14895 data
= data
.slice (bytes_read
);
14900 ranges
.push_back ({ low
, high
});
14904 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14906 std::copy (ranges
.begin (), ranges
.end (), result
);
14907 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14910 static const gdb::array_view
<variant_part
> create_variant_parts
14911 (struct obstack
*obstack
,
14912 const offset_map_type
&offset_map
,
14913 struct field_info
*fi
,
14914 const std::vector
<variant_part_builder
> &variant_parts
);
14916 /* Fill in a "struct variant" for a given variant field. RESULT is
14917 the variant to fill in. OBSTACK is where any needed allocations
14918 will be done. OFFSET_MAP holds the mapping from section offsets to
14919 fields for the type. FI describes the fields of the type we're
14920 processing. FIELD is the variant field we're converting. */
14923 create_one_variant (variant
&result
, struct obstack
*obstack
,
14924 const offset_map_type
&offset_map
,
14925 struct field_info
*fi
, const variant_field
&field
)
14927 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14928 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14929 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14930 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14931 field
.variant_parts
);
14934 /* Fill in a "struct variant_part" for a given variant part. RESULT
14935 is the variant part to fill in. OBSTACK is where any needed
14936 allocations will be done. OFFSET_MAP holds the mapping from
14937 section offsets to fields for the type. FI describes the fields of
14938 the type we're processing. BUILDER is the variant part to be
14942 create_one_variant_part (variant_part
&result
,
14943 struct obstack
*obstack
,
14944 const offset_map_type
&offset_map
,
14945 struct field_info
*fi
,
14946 const variant_part_builder
&builder
)
14948 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14949 if (iter
== offset_map
.end ())
14951 result
.discriminant_index
= -1;
14952 /* Doesn't matter. */
14953 result
.is_unsigned
= false;
14957 result
.discriminant_index
= iter
->second
;
14959 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14962 size_t n
= builder
.variants
.size ();
14963 variant
*output
= new (obstack
) variant
[n
];
14964 for (size_t i
= 0; i
< n
; ++i
)
14965 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14966 builder
.variants
[i
]);
14968 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14971 /* Create a vector of variant parts that can be attached to a type.
14972 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14973 holds the mapping from section offsets to fields for the type. FI
14974 describes the fields of the type we're processing. VARIANT_PARTS
14975 is the vector to convert. */
14977 static const gdb::array_view
<variant_part
>
14978 create_variant_parts (struct obstack
*obstack
,
14979 const offset_map_type
&offset_map
,
14980 struct field_info
*fi
,
14981 const std::vector
<variant_part_builder
> &variant_parts
)
14983 if (variant_parts
.empty ())
14986 size_t n
= variant_parts
.size ();
14987 variant_part
*result
= new (obstack
) variant_part
[n
];
14988 for (size_t i
= 0; i
< n
; ++i
)
14989 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14992 return gdb::array_view
<variant_part
> (result
, n
);
14995 /* Compute the variant part vector for FIP, attaching it to TYPE when
14999 add_variant_property (struct field_info
*fip
, struct type
*type
,
15000 struct dwarf2_cu
*cu
)
15002 /* Map section offsets of fields to their field index. Note the
15003 field index here does not take the number of baseclasses into
15005 offset_map_type offset_map
;
15006 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15007 offset_map
[fip
->fields
[i
].offset
] = i
;
15009 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15010 gdb::array_view
<const variant_part
> parts
15011 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15012 fip
->variant_parts
);
15014 struct dynamic_prop prop
;
15015 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15016 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15019 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15022 /* Create the vector of fields, and attach it to the type. */
15025 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15026 struct dwarf2_cu
*cu
)
15028 int nfields
= fip
->nfields ();
15030 /* Record the field count, allocate space for the array of fields,
15031 and create blank accessibility bitfields if necessary. */
15032 type
->set_num_fields (nfields
);
15034 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15036 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
15038 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15040 TYPE_FIELD_PRIVATE_BITS (type
) =
15041 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15042 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15044 TYPE_FIELD_PROTECTED_BITS (type
) =
15045 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15046 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15048 TYPE_FIELD_IGNORE_BITS (type
) =
15049 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15050 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15053 /* If the type has baseclasses, allocate and clear a bit vector for
15054 TYPE_FIELD_VIRTUAL_BITS. */
15055 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
15057 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15058 unsigned char *pointer
;
15060 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15061 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15062 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15063 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15064 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15067 if (!fip
->variant_parts
.empty ())
15068 add_variant_property (fip
, type
, cu
);
15070 /* Copy the saved-up fields into the field vector. */
15071 for (int i
= 0; i
< nfields
; ++i
)
15073 struct nextfield
&field
15074 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15075 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15077 type
->field (i
) = field
.field
;
15078 switch (field
.accessibility
)
15080 case DW_ACCESS_private
:
15081 if (cu
->per_cu
->lang
!= language_ada
)
15082 SET_TYPE_FIELD_PRIVATE (type
, i
);
15085 case DW_ACCESS_protected
:
15086 if (cu
->per_cu
->lang
!= language_ada
)
15087 SET_TYPE_FIELD_PROTECTED (type
, i
);
15090 case DW_ACCESS_public
:
15094 /* Unknown accessibility. Complain and treat it as public. */
15096 complaint (_("unsupported accessibility %d"),
15097 field
.accessibility
);
15101 if (i
< fip
->baseclasses
.size ())
15103 switch (field
.virtuality
)
15105 case DW_VIRTUALITY_virtual
:
15106 case DW_VIRTUALITY_pure_virtual
:
15107 if (cu
->per_cu
->lang
== language_ada
)
15108 error (_("unexpected virtuality in component of Ada type"));
15109 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15116 /* Return true if this member function is a constructor, false
15120 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15122 const char *fieldname
;
15123 const char *type_name
;
15126 if (die
->parent
== NULL
)
15129 if (die
->parent
->tag
!= DW_TAG_structure_type
15130 && die
->parent
->tag
!= DW_TAG_union_type
15131 && die
->parent
->tag
!= DW_TAG_class_type
)
15134 fieldname
= dwarf2_name (die
, cu
);
15135 type_name
= dwarf2_name (die
->parent
, cu
);
15136 if (fieldname
== NULL
|| type_name
== NULL
)
15139 len
= strlen (fieldname
);
15140 return (strncmp (fieldname
, type_name
, len
) == 0
15141 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15144 /* Add a member function to the proper fieldlist. */
15147 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15148 struct type
*type
, struct dwarf2_cu
*cu
)
15150 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15151 struct attribute
*attr
;
15153 struct fnfieldlist
*flp
= nullptr;
15154 struct fn_field
*fnp
;
15155 const char *fieldname
;
15156 struct type
*this_type
;
15158 if (cu
->per_cu
->lang
== language_ada
)
15159 error (_("unexpected member function in Ada type"));
15161 /* Get name of member function. */
15162 fieldname
= dwarf2_name (die
, cu
);
15163 if (fieldname
== NULL
)
15166 /* Look up member function name in fieldlist. */
15167 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15169 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15171 flp
= &fip
->fnfieldlists
[i
];
15176 /* Create a new fnfieldlist if necessary. */
15177 if (flp
== nullptr)
15179 fip
->fnfieldlists
.emplace_back ();
15180 flp
= &fip
->fnfieldlists
.back ();
15181 flp
->name
= fieldname
;
15182 i
= fip
->fnfieldlists
.size () - 1;
15185 /* Create a new member function field and add it to the vector of
15187 flp
->fnfields
.emplace_back ();
15188 fnp
= &flp
->fnfields
.back ();
15190 /* Delay processing of the physname until later. */
15191 if (cu
->per_cu
->lang
== language_cplus
)
15192 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15196 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15197 fnp
->physname
= physname
? physname
: "";
15200 fnp
->type
= alloc_type (objfile
);
15201 this_type
= read_type_die (die
, cu
);
15202 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15204 int nparams
= this_type
->num_fields ();
15206 /* TYPE is the domain of this method, and THIS_TYPE is the type
15207 of the method itself (TYPE_CODE_METHOD). */
15208 smash_to_method_type (fnp
->type
, type
,
15209 TYPE_TARGET_TYPE (this_type
),
15210 this_type
->fields (),
15211 this_type
->num_fields (),
15212 this_type
->has_varargs ());
15214 /* Handle static member functions.
15215 Dwarf2 has no clean way to discern C++ static and non-static
15216 member functions. G++ helps GDB by marking the first
15217 parameter for non-static member functions (which is the this
15218 pointer) as artificial. We obtain this information from
15219 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15220 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15221 fnp
->voffset
= VOFFSET_STATIC
;
15224 complaint (_("member function type missing for '%s'"),
15225 dwarf2_full_name (fieldname
, die
, cu
));
15227 /* Get fcontext from DW_AT_containing_type if present. */
15228 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15229 fnp
->fcontext
= die_containing_type (die
, cu
);
15231 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15232 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15234 /* Get accessibility. */
15235 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15236 switch (accessibility
)
15238 case DW_ACCESS_private
:
15239 fnp
->is_private
= 1;
15241 case DW_ACCESS_protected
:
15242 fnp
->is_protected
= 1;
15246 /* Check for artificial methods. */
15247 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15248 if (attr
&& attr
->as_boolean ())
15249 fnp
->is_artificial
= 1;
15251 /* Check for defaulted methods. */
15252 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15253 if (attr
!= nullptr)
15254 fnp
->defaulted
= attr
->defaulted ();
15256 /* Check for deleted methods. */
15257 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15258 if (attr
!= nullptr && attr
->as_boolean ())
15259 fnp
->is_deleted
= 1;
15261 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15263 /* Get index in virtual function table if it is a virtual member
15264 function. For older versions of GCC, this is an offset in the
15265 appropriate virtual table, as specified by DW_AT_containing_type.
15266 For everyone else, it is an expression to be evaluated relative
15267 to the object address. */
15269 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15270 if (attr
!= nullptr)
15272 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15274 struct dwarf_block
*block
= attr
->as_block ();
15276 if (block
->data
[0] == DW_OP_constu
)
15278 /* Old-style GCC. */
15279 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15281 else if (block
->data
[0] == DW_OP_deref
15282 || (block
->size
> 1
15283 && block
->data
[0] == DW_OP_deref_size
15284 && block
->data
[1] == cu
->header
.addr_size
))
15286 fnp
->voffset
= decode_locdesc (block
, cu
);
15287 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15288 dwarf2_complex_location_expr_complaint ();
15290 fnp
->voffset
/= cu
->header
.addr_size
;
15294 dwarf2_complex_location_expr_complaint ();
15296 if (!fnp
->fcontext
)
15298 /* If there is no `this' field and no DW_AT_containing_type,
15299 we cannot actually find a base class context for the
15301 if (this_type
->num_fields () == 0
15302 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15304 complaint (_("cannot determine context for virtual member "
15305 "function \"%s\" (offset %s)"),
15306 fieldname
, sect_offset_str (die
->sect_off
));
15311 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15315 else if (attr
->form_is_section_offset ())
15317 dwarf2_complex_location_expr_complaint ();
15321 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15327 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15328 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15330 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15331 complaint (_("Member function \"%s\" (offset %s) is virtual "
15332 "but the vtable offset is not specified"),
15333 fieldname
, sect_offset_str (die
->sect_off
));
15334 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15335 TYPE_CPLUS_DYNAMIC (type
) = 1;
15340 /* Create the vector of member function fields, and attach it to the type. */
15343 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15344 struct dwarf2_cu
*cu
)
15346 if (cu
->per_cu
->lang
== language_ada
)
15347 error (_("unexpected member functions in Ada type"));
15349 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15350 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15352 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15354 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15356 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15357 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15359 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15360 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15361 fn_flp
->fn_fields
= (struct fn_field
*)
15362 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15364 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15365 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15368 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15371 /* Returns non-zero if NAME is the name of a vtable member in CU's
15372 language, zero otherwise. */
15374 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15376 static const char vptr
[] = "_vptr";
15378 /* Look for the C++ form of the vtable. */
15379 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15385 /* GCC outputs unnamed structures that are really pointers to member
15386 functions, with the ABI-specified layout. If TYPE describes
15387 such a structure, smash it into a member function type.
15389 GCC shouldn't do this; it should just output pointer to member DIEs.
15390 This is GCC PR debug/28767. */
15393 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15395 struct type
*pfn_type
, *self_type
, *new_type
;
15397 /* Check for a structure with no name and two children. */
15398 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15401 /* Check for __pfn and __delta members. */
15402 if (type
->field (0).name () == NULL
15403 || strcmp (type
->field (0).name (), "__pfn") != 0
15404 || type
->field (1).name () == NULL
15405 || strcmp (type
->field (1).name (), "__delta") != 0)
15408 /* Find the type of the method. */
15409 pfn_type
= type
->field (0).type ();
15410 if (pfn_type
== NULL
15411 || pfn_type
->code () != TYPE_CODE_PTR
15412 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15415 /* Look for the "this" argument. */
15416 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15417 if (pfn_type
->num_fields () == 0
15418 /* || pfn_type->field (0).type () == NULL */
15419 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15422 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15423 new_type
= alloc_type (objfile
);
15424 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15425 pfn_type
->fields (), pfn_type
->num_fields (),
15426 pfn_type
->has_varargs ());
15427 smash_to_methodptr_type (type
, new_type
);
15430 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15431 requires rewriting, then copy it and return the updated copy.
15432 Otherwise return nullptr. */
15434 static struct type
*
15435 rewrite_array_type (struct type
*type
)
15437 if (type
->code () != TYPE_CODE_ARRAY
)
15440 struct type
*index_type
= type
->index_type ();
15441 range_bounds
*current_bounds
= index_type
->bounds ();
15443 /* Handle multi-dimensional arrays. */
15444 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15445 if (new_target
== nullptr)
15447 /* Maybe we don't need to rewrite this array. */
15448 if (current_bounds
->low
.kind () == PROP_CONST
15449 && current_bounds
->high
.kind () == PROP_CONST
)
15453 /* Either the target type was rewritten, or the bounds have to be
15454 updated. Either way we want to copy the type and update
15456 struct type
*copy
= copy_type (type
);
15457 int nfields
= copy
->num_fields ();
15459 = ((struct field
*) TYPE_ZALLOC (copy
,
15460 nfields
* sizeof (struct field
)));
15461 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15462 copy
->set_fields (new_fields
);
15463 if (new_target
!= nullptr)
15464 TYPE_TARGET_TYPE (copy
) = new_target
;
15466 struct type
*index_copy
= copy_type (index_type
);
15467 range_bounds
*bounds
15468 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15469 sizeof (range_bounds
));
15470 *bounds
= *current_bounds
;
15471 bounds
->low
.set_const_val (1);
15472 bounds
->high
.set_const_val (0);
15473 index_copy
->set_bounds (bounds
);
15474 copy
->set_index_type (index_copy
);
15479 /* While some versions of GCC will generate complicated DWARF for an
15480 array (see quirk_ada_thick_pointer), more recent versions were
15481 modified to emit an explicit thick pointer structure. However, in
15482 this case, the array still has DWARF expressions for its ranges,
15483 and these must be ignored. */
15486 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15489 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15491 /* Check for a structure with two children. */
15492 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15495 /* Check for P_ARRAY and P_BOUNDS members. */
15496 if (type
->field (0).name () == NULL
15497 || strcmp (type
->field (0).name (), "P_ARRAY") != 0
15498 || type
->field (1).name () == NULL
15499 || strcmp (type
->field (1).name (), "P_BOUNDS") != 0)
15502 /* Make sure we're looking at a pointer to an array. */
15503 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15506 /* The Ada code already knows how to handle these types, so all that
15507 we need to do is turn the bounds into static bounds. However, we
15508 don't want to rewrite existing array or index types in-place,
15509 because those may be referenced in other contexts where this
15510 rewriting is undesirable. */
15511 struct type
*new_ary_type
15512 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15513 if (new_ary_type
!= nullptr)
15514 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15517 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15518 appropriate error checking and issuing complaints if there is a
15522 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15524 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15526 if (attr
== nullptr)
15529 if (!attr
->form_is_constant ())
15531 complaint (_("DW_AT_alignment must have constant form"
15532 " - DIE at %s [in module %s]"),
15533 sect_offset_str (die
->sect_off
),
15534 objfile_name (cu
->per_objfile
->objfile
));
15538 LONGEST val
= attr
->constant_value (0);
15541 complaint (_("DW_AT_alignment value must not be negative"
15542 " - DIE at %s [in module %s]"),
15543 sect_offset_str (die
->sect_off
),
15544 objfile_name (cu
->per_objfile
->objfile
));
15547 ULONGEST align
= val
;
15551 complaint (_("DW_AT_alignment value must not be zero"
15552 " - DIE at %s [in module %s]"),
15553 sect_offset_str (die
->sect_off
),
15554 objfile_name (cu
->per_objfile
->objfile
));
15557 if ((align
& (align
- 1)) != 0)
15559 complaint (_("DW_AT_alignment value must be a power of 2"
15560 " - DIE at %s [in module %s]"),
15561 sect_offset_str (die
->sect_off
),
15562 objfile_name (cu
->per_objfile
->objfile
));
15569 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15570 the alignment for TYPE. */
15573 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15576 if (!set_type_align (type
, get_alignment (cu
, die
)))
15577 complaint (_("DW_AT_alignment value too large"
15578 " - DIE at %s [in module %s]"),
15579 sect_offset_str (die
->sect_off
),
15580 objfile_name (cu
->per_objfile
->objfile
));
15583 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15584 constant for a type, according to DWARF5 spec, Table 5.5. */
15587 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15592 case DW_CC_pass_by_reference
:
15593 case DW_CC_pass_by_value
:
15597 complaint (_("unrecognized DW_AT_calling_convention value "
15598 "(%s) for a type"), pulongest (value
));
15603 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15604 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15605 also according to GNU-specific values (see include/dwarf2.h). */
15608 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15613 case DW_CC_program
:
15617 case DW_CC_GNU_renesas_sh
:
15618 case DW_CC_GNU_borland_fastcall_i386
:
15619 case DW_CC_GDB_IBM_OpenCL
:
15623 complaint (_("unrecognized DW_AT_calling_convention value "
15624 "(%s) for a subroutine"), pulongest (value
));
15629 /* Called when we find the DIE that starts a structure or union scope
15630 (definition) to create a type for the structure or union. Fill in
15631 the type's name and general properties; the members will not be
15632 processed until process_structure_scope. A symbol table entry for
15633 the type will also not be done until process_structure_scope (assuming
15634 the type has a name).
15636 NOTE: we need to call these functions regardless of whether or not the
15637 DIE has a DW_AT_name attribute, since it might be an anonymous
15638 structure or union. This gets the type entered into our set of
15639 user defined types. */
15641 static struct type
*
15642 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15644 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15646 struct attribute
*attr
;
15649 /* If the definition of this type lives in .debug_types, read that type.
15650 Don't follow DW_AT_specification though, that will take us back up
15651 the chain and we want to go down. */
15652 attr
= die
->attr (DW_AT_signature
);
15653 if (attr
!= nullptr)
15655 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15657 /* The type's CU may not be the same as CU.
15658 Ensure TYPE is recorded with CU in die_type_hash. */
15659 return set_die_type (die
, type
, cu
);
15662 type
= alloc_type (objfile
);
15663 INIT_CPLUS_SPECIFIC (type
);
15665 name
= dwarf2_name (die
, cu
);
15668 if (cu
->per_cu
->lang
== language_cplus
15669 || cu
->per_cu
->lang
== language_d
15670 || cu
->per_cu
->lang
== language_rust
)
15672 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15674 /* dwarf2_full_name might have already finished building the DIE's
15675 type. If so, there is no need to continue. */
15676 if (get_die_type (die
, cu
) != NULL
)
15677 return get_die_type (die
, cu
);
15679 type
->set_name (full_name
);
15683 /* The name is already allocated along with this objfile, so
15684 we don't need to duplicate it for the type. */
15685 type
->set_name (name
);
15689 if (die
->tag
== DW_TAG_structure_type
)
15691 type
->set_code (TYPE_CODE_STRUCT
);
15693 else if (die
->tag
== DW_TAG_union_type
)
15695 type
->set_code (TYPE_CODE_UNION
);
15697 else if (die
->tag
== DW_TAG_namelist
)
15699 type
->set_code (TYPE_CODE_NAMELIST
);
15703 type
->set_code (TYPE_CODE_STRUCT
);
15706 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15707 type
->set_is_declared_class (true);
15709 /* Store the calling convention in the type if it's available in
15710 the die. Otherwise the calling convention remains set to
15711 the default value DW_CC_normal. */
15712 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15713 if (attr
!= nullptr
15714 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15716 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15717 TYPE_CPLUS_CALLING_CONVENTION (type
)
15718 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15721 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15722 if (attr
!= nullptr)
15724 if (attr
->form_is_constant ())
15725 TYPE_LENGTH (type
) = attr
->constant_value (0);
15728 struct dynamic_prop prop
;
15729 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15730 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15731 TYPE_LENGTH (type
) = 0;
15736 TYPE_LENGTH (type
) = 0;
15739 maybe_set_alignment (cu
, die
, type
);
15741 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15743 /* ICC<14 does not output the required DW_AT_declaration on
15744 incomplete types, but gives them a size of zero. */
15745 type
->set_is_stub (true);
15748 type
->set_stub_is_supported (true);
15750 if (die_is_declaration (die
, cu
))
15751 type
->set_is_stub (true);
15752 else if (attr
== NULL
&& die
->child
== NULL
15753 && producer_is_realview (cu
->producer
))
15754 /* RealView does not output the required DW_AT_declaration
15755 on incomplete types. */
15756 type
->set_is_stub (true);
15758 /* We need to add the type field to the die immediately so we don't
15759 infinitely recurse when dealing with pointers to the structure
15760 type within the structure itself. */
15761 set_die_type (die
, type
, cu
);
15763 /* set_die_type should be already done. */
15764 set_descriptive_type (type
, die
, cu
);
15769 static void handle_struct_member_die
15770 (struct die_info
*child_die
,
15772 struct field_info
*fi
,
15773 std::vector
<struct symbol
*> *template_args
,
15774 struct dwarf2_cu
*cu
);
15776 /* A helper for handle_struct_member_die that handles
15777 DW_TAG_variant_part. */
15780 handle_variant_part (struct die_info
*die
, struct type
*type
,
15781 struct field_info
*fi
,
15782 std::vector
<struct symbol
*> *template_args
,
15783 struct dwarf2_cu
*cu
)
15785 variant_part_builder
*new_part
;
15786 if (fi
->current_variant_part
== nullptr)
15788 fi
->variant_parts
.emplace_back ();
15789 new_part
= &fi
->variant_parts
.back ();
15791 else if (!fi
->current_variant_part
->processing_variant
)
15793 complaint (_("nested DW_TAG_variant_part seen "
15794 "- DIE at %s [in module %s]"),
15795 sect_offset_str (die
->sect_off
),
15796 objfile_name (cu
->per_objfile
->objfile
));
15801 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15802 current
.variant_parts
.emplace_back ();
15803 new_part
= ¤t
.variant_parts
.back ();
15806 /* When we recurse, we want callees to add to this new variant
15808 scoped_restore save_current_variant_part
15809 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15811 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15814 /* It's a univariant form, an extension we support. */
15816 else if (discr
->form_is_ref ())
15818 struct dwarf2_cu
*target_cu
= cu
;
15819 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15821 new_part
->discriminant_offset
= target_die
->sect_off
;
15825 complaint (_("DW_AT_discr does not have DIE reference form"
15826 " - DIE at %s [in module %s]"),
15827 sect_offset_str (die
->sect_off
),
15828 objfile_name (cu
->per_objfile
->objfile
));
15831 for (die_info
*child_die
= die
->child
;
15833 child_die
= child_die
->sibling
)
15834 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15837 /* A helper for handle_struct_member_die that handles
15841 handle_variant (struct die_info
*die
, struct type
*type
,
15842 struct field_info
*fi
,
15843 std::vector
<struct symbol
*> *template_args
,
15844 struct dwarf2_cu
*cu
)
15846 if (fi
->current_variant_part
== nullptr)
15848 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15849 "- DIE at %s [in module %s]"),
15850 sect_offset_str (die
->sect_off
),
15851 objfile_name (cu
->per_objfile
->objfile
));
15854 if (fi
->current_variant_part
->processing_variant
)
15856 complaint (_("nested DW_TAG_variant seen "
15857 "- DIE at %s [in module %s]"),
15858 sect_offset_str (die
->sect_off
),
15859 objfile_name (cu
->per_objfile
->objfile
));
15863 scoped_restore save_processing_variant
15864 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15867 fi
->current_variant_part
->variants
.emplace_back ();
15868 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15869 variant
.first_field
= fi
->fields
.size ();
15871 /* In a variant we want to get the discriminant and also add a
15872 field for our sole member child. */
15873 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15874 if (discr
== nullptr || !discr
->form_is_constant ())
15876 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15877 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15878 variant
.default_branch
= true;
15880 variant
.discr_list_data
= discr
->as_block ();
15883 variant
.discriminant_value
= discr
->constant_value (0);
15885 for (die_info
*variant_child
= die
->child
;
15886 variant_child
!= NULL
;
15887 variant_child
= variant_child
->sibling
)
15888 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15890 variant
.last_field
= fi
->fields
.size ();
15893 /* A helper for process_structure_scope that handles a single member
15897 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15898 struct field_info
*fi
,
15899 std::vector
<struct symbol
*> *template_args
,
15900 struct dwarf2_cu
*cu
)
15902 if (child_die
->tag
== DW_TAG_member
15903 || child_die
->tag
== DW_TAG_variable
15904 || child_die
->tag
== DW_TAG_namelist_item
)
15906 /* NOTE: carlton/2002-11-05: A C++ static data member
15907 should be a DW_TAG_member that is a declaration, but
15908 all versions of G++ as of this writing (so through at
15909 least 3.2.1) incorrectly generate DW_TAG_variable
15910 tags for them instead. */
15911 dwarf2_add_field (fi
, child_die
, cu
);
15913 else if (child_die
->tag
== DW_TAG_subprogram
)
15915 /* Rust doesn't have member functions in the C++ sense.
15916 However, it does emit ordinary functions as children
15917 of a struct DIE. */
15918 if (cu
->per_cu
->lang
== language_rust
)
15919 read_func_scope (child_die
, cu
);
15922 /* C++ member function. */
15923 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15926 else if (child_die
->tag
== DW_TAG_inheritance
)
15928 /* C++ base class field. */
15929 dwarf2_add_field (fi
, child_die
, cu
);
15931 else if (type_can_define_types (child_die
))
15932 dwarf2_add_type_defn (fi
, child_die
, cu
);
15933 else if (child_die
->tag
== DW_TAG_template_type_param
15934 || child_die
->tag
== DW_TAG_template_value_param
)
15936 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15939 template_args
->push_back (arg
);
15941 else if (child_die
->tag
== DW_TAG_variant_part
)
15942 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15943 else if (child_die
->tag
== DW_TAG_variant
)
15944 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15947 /* Finish creating a structure or union type, including filling in its
15948 members and creating a symbol for it. This function also handles Fortran
15949 namelist variables, their items or members and creating a symbol for
15953 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15955 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15956 struct die_info
*child_die
;
15959 type
= get_die_type (die
, cu
);
15961 type
= read_structure_type (die
, cu
);
15963 bool has_template_parameters
= false;
15964 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15966 struct field_info fi
;
15967 std::vector
<struct symbol
*> template_args
;
15969 child_die
= die
->child
;
15971 while (child_die
&& child_die
->tag
)
15973 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15974 child_die
= child_die
->sibling
;
15977 /* Attach template arguments to type. */
15978 if (!template_args
.empty ())
15980 has_template_parameters
= true;
15981 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15982 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15983 TYPE_TEMPLATE_ARGUMENTS (type
)
15984 = XOBNEWVEC (&objfile
->objfile_obstack
,
15986 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15987 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15988 template_args
.data (),
15989 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15990 * sizeof (struct symbol
*)));
15993 /* Attach fields and member functions to the type. */
15994 if (fi
.nfields () > 0)
15995 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15996 if (!fi
.fnfieldlists
.empty ())
15998 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16000 /* Get the type which refers to the base class (possibly this
16001 class itself) which contains the vtable pointer for the current
16002 class from the DW_AT_containing_type attribute. This use of
16003 DW_AT_containing_type is a GNU extension. */
16005 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16007 struct type
*t
= die_containing_type (die
, cu
);
16009 set_type_vptr_basetype (type
, t
);
16014 /* Our own class provides vtbl ptr. */
16015 for (i
= t
->num_fields () - 1;
16016 i
>= TYPE_N_BASECLASSES (t
);
16019 const char *fieldname
= t
->field (i
).name ();
16021 if (is_vtable_name (fieldname
, cu
))
16023 set_type_vptr_fieldno (type
, i
);
16028 /* Complain if virtual function table field not found. */
16029 if (i
< TYPE_N_BASECLASSES (t
))
16030 complaint (_("virtual function table pointer "
16031 "not found when defining class '%s'"),
16032 type
->name () ? type
->name () : "");
16036 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16039 else if (cu
->producer
16040 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16042 /* The IBM XLC compiler does not provide direct indication
16043 of the containing type, but the vtable pointer is
16044 always named __vfp. */
16048 for (i
= type
->num_fields () - 1;
16049 i
>= TYPE_N_BASECLASSES (type
);
16052 if (strcmp (type
->field (i
).name (), "__vfp") == 0)
16054 set_type_vptr_fieldno (type
, i
);
16055 set_type_vptr_basetype (type
, type
);
16062 /* Copy fi.typedef_field_list linked list elements content into the
16063 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16064 if (!fi
.typedef_field_list
.empty ())
16066 int count
= fi
.typedef_field_list
.size ();
16068 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16069 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16070 = ((struct decl_field
*)
16072 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16073 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16075 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16076 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16079 /* Copy fi.nested_types_list linked list elements content into the
16080 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16081 if (!fi
.nested_types_list
.empty ()
16082 && cu
->per_cu
->lang
!= language_ada
)
16084 int count
= fi
.nested_types_list
.size ();
16086 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16087 TYPE_NESTED_TYPES_ARRAY (type
)
16088 = ((struct decl_field
*)
16089 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16090 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16092 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16093 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16097 quirk_gcc_member_function_pointer (type
, objfile
);
16098 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16099 cu
->rust_unions
.push_back (type
);
16100 else if (cu
->per_cu
->lang
== language_ada
)
16101 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16103 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16104 snapshots) has been known to create a die giving a declaration
16105 for a class that has, as a child, a die giving a definition for a
16106 nested class. So we have to process our children even if the
16107 current die is a declaration. Normally, of course, a declaration
16108 won't have any children at all. */
16110 child_die
= die
->child
;
16112 while (child_die
!= NULL
&& child_die
->tag
)
16114 if (child_die
->tag
== DW_TAG_member
16115 || child_die
->tag
== DW_TAG_variable
16116 || child_die
->tag
== DW_TAG_inheritance
16117 || child_die
->tag
== DW_TAG_template_value_param
16118 || child_die
->tag
== DW_TAG_template_type_param
)
16123 process_die (child_die
, cu
);
16125 child_die
= child_die
->sibling
;
16128 /* Do not consider external references. According to the DWARF standard,
16129 these DIEs are identified by the fact that they have no byte_size
16130 attribute, and a declaration attribute. */
16131 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16132 || !die_is_declaration (die
, cu
)
16133 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16135 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16137 if (has_template_parameters
)
16139 struct symtab
*symtab
;
16140 if (sym
!= nullptr)
16141 symtab
= symbol_symtab (sym
);
16142 else if (cu
->line_header
!= nullptr)
16144 /* Any related symtab will do. */
16146 = cu
->line_header
->file_names ()[0].symtab
;
16151 complaint (_("could not find suitable "
16152 "symtab for template parameter"
16153 " - DIE at %s [in module %s]"),
16154 sect_offset_str (die
->sect_off
),
16155 objfile_name (objfile
));
16158 if (symtab
!= nullptr)
16160 /* Make sure that the symtab is set on the new symbols.
16161 Even though they don't appear in this symtab directly,
16162 other parts of gdb assume that symbols do, and this is
16163 reasonably true. */
16164 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16165 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16171 /* Assuming DIE is an enumeration type, and TYPE is its associated
16172 type, update TYPE using some information only available in DIE's
16173 children. In particular, the fields are computed. */
16176 update_enumeration_type_from_children (struct die_info
*die
,
16178 struct dwarf2_cu
*cu
)
16180 struct die_info
*child_die
;
16181 int unsigned_enum
= 1;
16184 auto_obstack obstack
;
16185 std::vector
<struct field
> fields
;
16187 for (child_die
= die
->child
;
16188 child_die
!= NULL
&& child_die
->tag
;
16189 child_die
= child_die
->sibling
)
16191 struct attribute
*attr
;
16193 const gdb_byte
*bytes
;
16194 struct dwarf2_locexpr_baton
*baton
;
16197 if (child_die
->tag
!= DW_TAG_enumerator
)
16200 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16204 name
= dwarf2_name (child_die
, cu
);
16206 name
= "<anonymous enumerator>";
16208 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16209 &value
, &bytes
, &baton
);
16217 if (count_one_bits_ll (value
) >= 2)
16221 fields
.emplace_back ();
16222 struct field
&field
= fields
.back ();
16223 field
.set_name (dwarf2_physname (name
, child_die
, cu
));
16224 field
.set_loc_enumval (value
);
16227 if (!fields
.empty ())
16229 type
->set_num_fields (fields
.size ());
16232 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16233 memcpy (type
->fields (), fields
.data (),
16234 sizeof (struct field
) * fields
.size ());
16238 type
->set_is_unsigned (true);
16241 type
->set_is_flag_enum (true);
16244 /* Given a DW_AT_enumeration_type die, set its type. We do not
16245 complete the type's fields yet, or create any symbols. */
16247 static struct type
*
16248 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16250 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16252 struct attribute
*attr
;
16255 /* If the definition of this type lives in .debug_types, read that type.
16256 Don't follow DW_AT_specification though, that will take us back up
16257 the chain and we want to go down. */
16258 attr
= die
->attr (DW_AT_signature
);
16259 if (attr
!= nullptr)
16261 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16263 /* The type's CU may not be the same as CU.
16264 Ensure TYPE is recorded with CU in die_type_hash. */
16265 return set_die_type (die
, type
, cu
);
16268 type
= alloc_type (objfile
);
16270 type
->set_code (TYPE_CODE_ENUM
);
16271 name
= dwarf2_full_name (NULL
, die
, cu
);
16273 type
->set_name (name
);
16275 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16278 struct type
*underlying_type
= die_type (die
, cu
);
16280 TYPE_TARGET_TYPE (type
) = underlying_type
;
16283 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16284 if (attr
!= nullptr)
16286 TYPE_LENGTH (type
) = attr
->constant_value (0);
16290 TYPE_LENGTH (type
) = 0;
16293 maybe_set_alignment (cu
, die
, type
);
16295 /* The enumeration DIE can be incomplete. In Ada, any type can be
16296 declared as private in the package spec, and then defined only
16297 inside the package body. Such types are known as Taft Amendment
16298 Types. When another package uses such a type, an incomplete DIE
16299 may be generated by the compiler. */
16300 if (die_is_declaration (die
, cu
))
16301 type
->set_is_stub (true);
16303 /* If this type has an underlying type that is not a stub, then we
16304 may use its attributes. We always use the "unsigned" attribute
16305 in this situation, because ordinarily we guess whether the type
16306 is unsigned -- but the guess can be wrong and the underlying type
16307 can tell us the reality. However, we defer to a local size
16308 attribute if one exists, because this lets the compiler override
16309 the underlying type if needed. */
16310 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16312 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16313 underlying_type
= check_typedef (underlying_type
);
16315 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16317 if (TYPE_LENGTH (type
) == 0)
16318 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16320 if (TYPE_RAW_ALIGN (type
) == 0
16321 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16322 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16325 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16327 set_die_type (die
, type
, cu
);
16329 /* Finish the creation of this type by using the enum's children.
16330 Note that, as usual, this must come after set_die_type to avoid
16331 infinite recursion when trying to compute the names of the
16333 update_enumeration_type_from_children (die
, type
, cu
);
16338 /* Given a pointer to a die which begins an enumeration, process all
16339 the dies that define the members of the enumeration, and create the
16340 symbol for the enumeration type.
16342 NOTE: We reverse the order of the element list. */
16345 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16347 struct type
*this_type
;
16349 this_type
= get_die_type (die
, cu
);
16350 if (this_type
== NULL
)
16351 this_type
= read_enumeration_type (die
, cu
);
16353 if (die
->child
!= NULL
)
16355 struct die_info
*child_die
;
16358 child_die
= die
->child
;
16359 while (child_die
&& child_die
->tag
)
16361 if (child_die
->tag
!= DW_TAG_enumerator
)
16363 process_die (child_die
, cu
);
16367 name
= dwarf2_name (child_die
, cu
);
16369 new_symbol (child_die
, this_type
, cu
);
16372 child_die
= child_die
->sibling
;
16376 /* If we are reading an enum from a .debug_types unit, and the enum
16377 is a declaration, and the enum is not the signatured type in the
16378 unit, then we do not want to add a symbol for it. Adding a
16379 symbol would in some cases obscure the true definition of the
16380 enum, giving users an incomplete type when the definition is
16381 actually available. Note that we do not want to do this for all
16382 enums which are just declarations, because C++0x allows forward
16383 enum declarations. */
16384 if (cu
->per_cu
->is_debug_types
16385 && die_is_declaration (die
, cu
))
16387 struct signatured_type
*sig_type
;
16389 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16390 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16391 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16395 new_symbol (die
, this_type
, cu
);
16398 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16399 expression for an index type and finds the corresponding field
16400 offset in the hidden "P_BOUNDS" structure. Returns true on success
16401 and updates *FIELD, false if it fails to recognize an
16405 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16406 int *bounds_offset
, struct field
*field
,
16407 struct dwarf2_cu
*cu
)
16409 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16410 if (attr
== nullptr || !attr
->form_is_block ())
16413 const struct dwarf_block
*block
= attr
->as_block ();
16414 const gdb_byte
*start
= block
->data
;
16415 const gdb_byte
*end
= block
->data
+ block
->size
;
16417 /* The expression to recognize generally looks like:
16419 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16420 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16422 However, the second "plus_uconst" may be missing:
16424 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16425 DW_OP_deref_size: 4)
16427 This happens when the field is at the start of the structure.
16429 Also, the final deref may not be sized:
16431 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16434 This happens when the size of the index type happens to be the
16435 same as the architecture's word size. This can occur with or
16436 without the second plus_uconst. */
16438 if (end
- start
< 2)
16440 if (*start
++ != DW_OP_push_object_address
)
16442 if (*start
++ != DW_OP_plus_uconst
)
16445 uint64_t this_bound_off
;
16446 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16447 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16449 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16450 is consistent among all bounds. */
16451 if (*bounds_offset
== -1)
16452 *bounds_offset
= this_bound_off
;
16453 else if (*bounds_offset
!= this_bound_off
)
16456 if (start
== end
|| *start
++ != DW_OP_deref
)
16462 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16464 /* This means an offset of 0. */
16466 else if (*start
++ != DW_OP_plus_uconst
)
16470 /* The size is the parameter to DW_OP_plus_uconst. */
16472 start
= gdb_read_uleb128 (start
, end
, &val
);
16473 if (start
== nullptr)
16475 if ((int) val
!= val
)
16484 if (*start
== DW_OP_deref_size
)
16486 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16487 if (start
== nullptr)
16490 else if (*start
== DW_OP_deref
)
16492 size
= cu
->header
.addr_size
;
16498 field
->set_loc_bitpos (8 * offset
);
16499 if (size
!= TYPE_LENGTH (field
->type ()))
16500 FIELD_BITSIZE (*field
) = 8 * size
;
16505 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16506 some kinds of Ada arrays:
16508 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16509 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16510 <11e0> DW_AT_data_location: 2 byte block: 97 6
16511 (DW_OP_push_object_address; DW_OP_deref)
16512 <11e3> DW_AT_type : <0x1173>
16513 <11e7> DW_AT_sibling : <0x1201>
16514 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16515 <11ec> DW_AT_type : <0x1206>
16516 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16517 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16518 DW_OP_deref_size: 4)
16519 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16520 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16521 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16523 This actually represents a "thick pointer", which is a structure
16524 with two elements: one that is a pointer to the array data, and one
16525 that is a pointer to another structure; this second structure holds
16528 This returns a new type on success, or nullptr if this didn't
16529 recognize the type. */
16531 static struct type
*
16532 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16535 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16536 /* So far we've only seen this with block form. */
16537 if (attr
== nullptr || !attr
->form_is_block ())
16540 /* Note that this will fail if the structure layout is changed by
16541 the compiler. However, we have no good way to recognize some
16542 other layout, because we don't know what expression the compiler
16543 might choose to emit should this happen. */
16544 struct dwarf_block
*blk
= attr
->as_block ();
16546 || blk
->data
[0] != DW_OP_push_object_address
16547 || blk
->data
[1] != DW_OP_deref
)
16550 int bounds_offset
= -1;
16551 int max_align
= -1;
16552 std::vector
<struct field
> range_fields
;
16553 for (struct die_info
*child_die
= die
->child
;
16555 child_die
= child_die
->sibling
)
16557 if (child_die
->tag
== DW_TAG_subrange_type
)
16559 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16561 int this_align
= type_align (underlying
);
16562 if (this_align
> max_align
)
16563 max_align
= this_align
;
16565 range_fields
.emplace_back ();
16566 range_fields
.emplace_back ();
16568 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16569 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16571 lower
.set_type (underlying
);
16572 FIELD_ARTIFICIAL (lower
) = 1;
16574 upper
.set_type (underlying
);
16575 FIELD_ARTIFICIAL (upper
) = 1;
16577 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16578 &bounds_offset
, &lower
, cu
)
16579 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16580 &bounds_offset
, &upper
, cu
))
16585 /* This shouldn't really happen, but double-check that we found
16586 where the bounds are stored. */
16587 if (bounds_offset
== -1)
16590 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16591 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16595 /* Set the name of each field in the bounds. */
16596 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16597 range_fields
[i
].set_name (objfile
->intern (name
));
16598 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16599 range_fields
[i
+ 1].set_name (objfile
->intern (name
));
16602 struct type
*bounds
= alloc_type (objfile
);
16603 bounds
->set_code (TYPE_CODE_STRUCT
);
16605 bounds
->set_num_fields (range_fields
.size ());
16607 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16608 * sizeof (struct field
))));
16609 memcpy (bounds
->fields (), range_fields
.data (),
16610 bounds
->num_fields () * sizeof (struct field
));
16612 int last_fieldno
= range_fields
.size () - 1;
16613 int bounds_size
= (bounds
->field (last_fieldno
).loc_bitpos () / 8
16614 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16615 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16617 /* Rewrite the existing array type in place. Specifically, we
16618 remove any dynamic properties we might have read, and we replace
16619 the index types. */
16620 struct type
*iter
= type
;
16621 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16623 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16624 iter
->main_type
->dyn_prop_list
= nullptr;
16625 iter
->set_index_type
16626 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16627 iter
= TYPE_TARGET_TYPE (iter
);
16630 struct type
*result
= alloc_type (objfile
);
16631 result
->set_code (TYPE_CODE_STRUCT
);
16633 result
->set_num_fields (2);
16635 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16636 * sizeof (struct field
))));
16638 /* The names are chosen to coincide with what the compiler does with
16639 -fgnat-encodings=all, which the Ada code in gdb already
16641 result
->field (0).set_name ("P_ARRAY");
16642 result
->field (0).set_type (lookup_pointer_type (type
));
16644 result
->field (1).set_name ("P_BOUNDS");
16645 result
->field (1).set_type (lookup_pointer_type (bounds
));
16646 result
->field (1).set_loc_bitpos (8 * bounds_offset
);
16648 result
->set_name (type
->name ());
16649 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16650 + TYPE_LENGTH (result
->field (1).type ()));
16655 /* Extract all information from a DW_TAG_array_type DIE and put it in
16656 the DIE's type field. For now, this only handles one dimensional
16659 static struct type
*
16660 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16662 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16663 struct die_info
*child_die
;
16665 struct type
*element_type
, *range_type
, *index_type
;
16666 struct attribute
*attr
;
16668 struct dynamic_prop
*byte_stride_prop
= NULL
;
16669 unsigned int bit_stride
= 0;
16671 element_type
= die_type (die
, cu
);
16673 /* The die_type call above may have already set the type for this DIE. */
16674 type
= get_die_type (die
, cu
);
16678 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16682 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16685 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16686 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16690 complaint (_("unable to read array DW_AT_byte_stride "
16691 " - DIE at %s [in module %s]"),
16692 sect_offset_str (die
->sect_off
),
16693 objfile_name (cu
->per_objfile
->objfile
));
16694 /* Ignore this attribute. We will likely not be able to print
16695 arrays of this type correctly, but there is little we can do
16696 to help if we cannot read the attribute's value. */
16697 byte_stride_prop
= NULL
;
16701 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16703 bit_stride
= attr
->constant_value (0);
16705 /* Irix 6.2 native cc creates array types without children for
16706 arrays with unspecified length. */
16707 if (die
->child
== NULL
)
16709 index_type
= objfile_type (objfile
)->builtin_int
;
16710 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16711 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16712 byte_stride_prop
, bit_stride
);
16713 return set_die_type (die
, type
, cu
);
16716 std::vector
<struct type
*> range_types
;
16717 child_die
= die
->child
;
16718 while (child_die
&& child_die
->tag
)
16720 if (child_die
->tag
== DW_TAG_subrange_type
16721 || child_die
->tag
== DW_TAG_generic_subrange
)
16723 struct type
*child_type
= read_type_die (child_die
, cu
);
16725 if (child_type
!= NULL
)
16727 /* The range type was succesfully read. Save it for the
16728 array type creation. */
16729 range_types
.push_back (child_type
);
16732 child_die
= child_die
->sibling
;
16735 if (range_types
.empty ())
16737 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16738 sect_offset_str (die
->sect_off
),
16739 objfile_name (cu
->per_objfile
->objfile
));
16743 /* Dwarf2 dimensions are output from left to right, create the
16744 necessary array types in backwards order. */
16746 type
= element_type
;
16748 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16752 while (i
< range_types
.size ())
16754 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16755 byte_stride_prop
, bit_stride
);
16757 byte_stride_prop
= nullptr;
16762 size_t ndim
= range_types
.size ();
16765 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16766 byte_stride_prop
, bit_stride
);
16768 byte_stride_prop
= nullptr;
16772 gdb_assert (type
!= element_type
);
16774 /* Understand Dwarf2 support for vector types (like they occur on
16775 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16776 array type. This is not part of the Dwarf2/3 standard yet, but a
16777 custom vendor extension. The main difference between a regular
16778 array and the vector variant is that vectors are passed by value
16780 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16781 if (attr
!= nullptr)
16782 make_vector_type (type
);
16784 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16785 implementation may choose to implement triple vectors using this
16787 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16788 if (attr
!= nullptr && attr
->form_is_unsigned ())
16790 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16791 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16793 complaint (_("DW_AT_byte_size for array type smaller "
16794 "than the total size of elements"));
16797 name
= dwarf2_name (die
, cu
);
16799 type
->set_name (name
);
16801 maybe_set_alignment (cu
, die
, type
);
16803 struct type
*replacement_type
= nullptr;
16804 if (cu
->per_cu
->lang
== language_ada
)
16806 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16807 if (replacement_type
!= nullptr)
16808 type
= replacement_type
;
16811 /* Install the type in the die. */
16812 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16814 /* set_die_type should be already done. */
16815 set_descriptive_type (type
, die
, cu
);
16820 static enum dwarf_array_dim_ordering
16821 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16823 struct attribute
*attr
;
16825 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16827 if (attr
!= nullptr)
16829 LONGEST val
= attr
->constant_value (-1);
16830 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16831 return (enum dwarf_array_dim_ordering
) val
;
16834 /* GNU F77 is a special case, as at 08/2004 array type info is the
16835 opposite order to the dwarf2 specification, but data is still
16836 laid out as per normal fortran.
16838 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16839 version checking. */
16841 if (cu
->per_cu
->lang
== language_fortran
16842 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16844 return DW_ORD_row_major
;
16847 switch (cu
->language_defn
->array_ordering ())
16849 case array_column_major
:
16850 return DW_ORD_col_major
;
16851 case array_row_major
:
16853 return DW_ORD_row_major
;
16857 /* Extract all information from a DW_TAG_set_type DIE and put it in
16858 the DIE's type field. */
16860 static struct type
*
16861 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16863 struct type
*domain_type
, *set_type
;
16864 struct attribute
*attr
;
16866 domain_type
= die_type (die
, cu
);
16868 /* The die_type call above may have already set the type for this DIE. */
16869 set_type
= get_die_type (die
, cu
);
16873 set_type
= create_set_type (NULL
, domain_type
);
16875 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16876 if (attr
!= nullptr && attr
->form_is_unsigned ())
16877 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16879 maybe_set_alignment (cu
, die
, set_type
);
16881 return set_die_type (die
, set_type
, cu
);
16884 /* A helper for read_common_block that creates a locexpr baton.
16885 SYM is the symbol which we are marking as computed.
16886 COMMON_DIE is the DIE for the common block.
16887 COMMON_LOC is the location expression attribute for the common
16889 MEMBER_LOC is the location expression attribute for the particular
16890 member of the common block that we are processing.
16891 CU is the CU from which the above come. */
16894 mark_common_block_symbol_computed (struct symbol
*sym
,
16895 struct die_info
*common_die
,
16896 struct attribute
*common_loc
,
16897 struct attribute
*member_loc
,
16898 struct dwarf2_cu
*cu
)
16900 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16901 struct objfile
*objfile
= per_objfile
->objfile
;
16902 struct dwarf2_locexpr_baton
*baton
;
16904 unsigned int cu_off
;
16905 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16906 LONGEST offset
= 0;
16908 gdb_assert (common_loc
&& member_loc
);
16909 gdb_assert (common_loc
->form_is_block ());
16910 gdb_assert (member_loc
->form_is_block ()
16911 || member_loc
->form_is_constant ());
16913 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16914 baton
->per_objfile
= per_objfile
;
16915 baton
->per_cu
= cu
->per_cu
;
16916 gdb_assert (baton
->per_cu
);
16918 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16920 if (member_loc
->form_is_constant ())
16922 offset
= member_loc
->constant_value (0);
16923 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16926 baton
->size
+= member_loc
->as_block ()->size
;
16928 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16931 *ptr
++ = DW_OP_call4
;
16932 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16933 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16936 if (member_loc
->form_is_constant ())
16938 *ptr
++ = DW_OP_addr
;
16939 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16940 ptr
+= cu
->header
.addr_size
;
16944 /* We have to copy the data here, because DW_OP_call4 will only
16945 use a DW_AT_location attribute. */
16946 struct dwarf_block
*block
= member_loc
->as_block ();
16947 memcpy (ptr
, block
->data
, block
->size
);
16948 ptr
+= block
->size
;
16951 *ptr
++ = DW_OP_plus
;
16952 gdb_assert (ptr
- baton
->data
== baton
->size
);
16954 SYMBOL_LOCATION_BATON (sym
) = baton
;
16955 sym
->set_aclass_index (dwarf2_locexpr_index
);
16958 /* Create appropriate locally-scoped variables for all the
16959 DW_TAG_common_block entries. Also create a struct common_block
16960 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16961 is used to separate the common blocks name namespace from regular
16965 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16967 struct attribute
*attr
;
16969 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16970 if (attr
!= nullptr)
16972 /* Support the .debug_loc offsets. */
16973 if (attr
->form_is_block ())
16977 else if (attr
->form_is_section_offset ())
16979 dwarf2_complex_location_expr_complaint ();
16984 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16985 "common block member");
16990 if (die
->child
!= NULL
)
16992 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16993 struct die_info
*child_die
;
16994 size_t n_entries
= 0, size
;
16995 struct common_block
*common_block
;
16996 struct symbol
*sym
;
16998 for (child_die
= die
->child
;
16999 child_die
&& child_die
->tag
;
17000 child_die
= child_die
->sibling
)
17003 size
= (sizeof (struct common_block
)
17004 + (n_entries
- 1) * sizeof (struct symbol
*));
17006 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17008 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17009 common_block
->n_entries
= 0;
17011 for (child_die
= die
->child
;
17012 child_die
&& child_die
->tag
;
17013 child_die
= child_die
->sibling
)
17015 /* Create the symbol in the DW_TAG_common_block block in the current
17017 sym
= new_symbol (child_die
, NULL
, cu
);
17020 struct attribute
*member_loc
;
17022 common_block
->contents
[common_block
->n_entries
++] = sym
;
17024 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17028 /* GDB has handled this for a long time, but it is
17029 not specified by DWARF. It seems to have been
17030 emitted by gfortran at least as recently as:
17031 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17032 complaint (_("Variable in common block has "
17033 "DW_AT_data_member_location "
17034 "- DIE at %s [in module %s]"),
17035 sect_offset_str (child_die
->sect_off
),
17036 objfile_name (objfile
));
17038 if (member_loc
->form_is_section_offset ())
17039 dwarf2_complex_location_expr_complaint ();
17040 else if (member_loc
->form_is_constant ()
17041 || member_loc
->form_is_block ())
17043 if (attr
!= nullptr)
17044 mark_common_block_symbol_computed (sym
, die
, attr
,
17048 dwarf2_complex_location_expr_complaint ();
17053 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17054 sym
->set_value_common_block (common_block
);
17058 /* Create a type for a C++ namespace. */
17060 static struct type
*
17061 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17063 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17064 const char *previous_prefix
, *name
;
17068 /* For extensions, reuse the type of the original namespace. */
17069 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17071 struct die_info
*ext_die
;
17072 struct dwarf2_cu
*ext_cu
= cu
;
17074 ext_die
= dwarf2_extension (die
, &ext_cu
);
17075 type
= read_type_die (ext_die
, ext_cu
);
17077 /* EXT_CU may not be the same as CU.
17078 Ensure TYPE is recorded with CU in die_type_hash. */
17079 return set_die_type (die
, type
, cu
);
17082 name
= namespace_name (die
, &is_anonymous
, cu
);
17084 /* Now build the name of the current namespace. */
17086 previous_prefix
= determine_prefix (die
, cu
);
17087 if (previous_prefix
[0] != '\0')
17088 name
= typename_concat (&objfile
->objfile_obstack
,
17089 previous_prefix
, name
, 0, cu
);
17091 /* Create the type. */
17092 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17094 return set_die_type (die
, type
, cu
);
17097 /* Read a namespace scope. */
17100 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17102 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17105 /* Add a symbol associated to this if we haven't seen the namespace
17106 before. Also, add a using directive if it's an anonymous
17109 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17113 type
= read_type_die (die
, cu
);
17114 new_symbol (die
, type
, cu
);
17116 namespace_name (die
, &is_anonymous
, cu
);
17119 const char *previous_prefix
= determine_prefix (die
, cu
);
17121 std::vector
<const char *> excludes
;
17122 add_using_directive (using_directives (cu
),
17123 previous_prefix
, type
->name (), NULL
,
17124 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17128 if (die
->child
!= NULL
)
17130 struct die_info
*child_die
= die
->child
;
17132 while (child_die
&& child_die
->tag
)
17134 process_die (child_die
, cu
);
17135 child_die
= child_die
->sibling
;
17140 /* Read a Fortran module as type. This DIE can be only a declaration used for
17141 imported module. Still we need that type as local Fortran "use ... only"
17142 declaration imports depend on the created type in determine_prefix. */
17144 static struct type
*
17145 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17147 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17148 const char *module_name
;
17151 module_name
= dwarf2_name (die
, cu
);
17152 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17154 return set_die_type (die
, type
, cu
);
17157 /* Read a Fortran module. */
17160 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17162 struct die_info
*child_die
= die
->child
;
17165 type
= read_type_die (die
, cu
);
17166 new_symbol (die
, type
, cu
);
17168 while (child_die
&& child_die
->tag
)
17170 process_die (child_die
, cu
);
17171 child_die
= child_die
->sibling
;
17175 /* Return the name of the namespace represented by DIE. Set
17176 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17179 static const char *
17180 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17182 struct die_info
*current_die
;
17183 const char *name
= NULL
;
17185 /* Loop through the extensions until we find a name. */
17187 for (current_die
= die
;
17188 current_die
!= NULL
;
17189 current_die
= dwarf2_extension (die
, &cu
))
17191 /* We don't use dwarf2_name here so that we can detect the absence
17192 of a name -> anonymous namespace. */
17193 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17199 /* Is it an anonymous namespace? */
17201 *is_anonymous
= (name
== NULL
);
17203 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17208 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17209 the user defined type vector. */
17211 static struct type
*
17212 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17214 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17215 struct comp_unit_head
*cu_header
= &cu
->header
;
17217 struct attribute
*attr_byte_size
;
17218 struct attribute
*attr_address_class
;
17219 int byte_size
, addr_class
;
17220 struct type
*target_type
;
17222 target_type
= die_type (die
, cu
);
17224 /* The die_type call above may have already set the type for this DIE. */
17225 type
= get_die_type (die
, cu
);
17229 type
= lookup_pointer_type (target_type
);
17231 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17232 if (attr_byte_size
)
17233 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17235 byte_size
= cu_header
->addr_size
;
17237 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17238 if (attr_address_class
)
17239 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17241 addr_class
= DW_ADDR_none
;
17243 ULONGEST alignment
= get_alignment (cu
, die
);
17245 /* If the pointer size, alignment, or address class is different
17246 than the default, create a type variant marked as such and set
17247 the length accordingly. */
17248 if (TYPE_LENGTH (type
) != byte_size
17249 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17250 && alignment
!= TYPE_RAW_ALIGN (type
))
17251 || addr_class
!= DW_ADDR_none
)
17253 if (gdbarch_address_class_type_flags_p (gdbarch
))
17255 type_instance_flags type_flags
17256 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17258 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17260 type
= make_type_with_address_space (type
, type_flags
);
17262 else if (TYPE_LENGTH (type
) != byte_size
)
17264 complaint (_("invalid pointer size %d"), byte_size
);
17266 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17268 complaint (_("Invalid DW_AT_alignment"
17269 " - DIE at %s [in module %s]"),
17270 sect_offset_str (die
->sect_off
),
17271 objfile_name (cu
->per_objfile
->objfile
));
17275 /* Should we also complain about unhandled address classes? */
17279 TYPE_LENGTH (type
) = byte_size
;
17280 set_type_align (type
, alignment
);
17281 return set_die_type (die
, type
, cu
);
17284 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17285 the user defined type vector. */
17287 static struct type
*
17288 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17291 struct type
*to_type
;
17292 struct type
*domain
;
17294 to_type
= die_type (die
, cu
);
17295 domain
= die_containing_type (die
, cu
);
17297 /* The calls above may have already set the type for this DIE. */
17298 type
= get_die_type (die
, cu
);
17302 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17303 type
= lookup_methodptr_type (to_type
);
17304 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17306 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17308 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17309 to_type
->fields (), to_type
->num_fields (),
17310 to_type
->has_varargs ());
17311 type
= lookup_methodptr_type (new_type
);
17314 type
= lookup_memberptr_type (to_type
, domain
);
17316 return set_die_type (die
, type
, cu
);
17319 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17320 the user defined type vector. */
17322 static struct type
*
17323 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17324 enum type_code refcode
)
17326 struct comp_unit_head
*cu_header
= &cu
->header
;
17327 struct type
*type
, *target_type
;
17328 struct attribute
*attr
;
17330 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17332 target_type
= die_type (die
, cu
);
17334 /* The die_type call above may have already set the type for this DIE. */
17335 type
= get_die_type (die
, cu
);
17339 type
= lookup_reference_type (target_type
, refcode
);
17340 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17341 if (attr
!= nullptr)
17343 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17347 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17349 maybe_set_alignment (cu
, die
, type
);
17350 return set_die_type (die
, type
, cu
);
17353 /* Add the given cv-qualifiers to the element type of the array. GCC
17354 outputs DWARF type qualifiers that apply to an array, not the
17355 element type. But GDB relies on the array element type to carry
17356 the cv-qualifiers. This mimics section 6.7.3 of the C99
17359 static struct type
*
17360 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17361 struct type
*base_type
, int cnst
, int voltl
)
17363 struct type
*el_type
, *inner_array
;
17365 base_type
= copy_type (base_type
);
17366 inner_array
= base_type
;
17368 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17370 TYPE_TARGET_TYPE (inner_array
) =
17371 copy_type (TYPE_TARGET_TYPE (inner_array
));
17372 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17375 el_type
= TYPE_TARGET_TYPE (inner_array
);
17376 cnst
|= TYPE_CONST (el_type
);
17377 voltl
|= TYPE_VOLATILE (el_type
);
17378 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17380 return set_die_type (die
, base_type
, cu
);
17383 static struct type
*
17384 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17386 struct type
*base_type
, *cv_type
;
17388 base_type
= die_type (die
, cu
);
17390 /* The die_type call above may have already set the type for this DIE. */
17391 cv_type
= get_die_type (die
, cu
);
17395 /* In case the const qualifier is applied to an array type, the element type
17396 is so qualified, not the array type (section 6.7.3 of C99). */
17397 if (base_type
->code () == TYPE_CODE_ARRAY
)
17398 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17400 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17401 return set_die_type (die
, cv_type
, cu
);
17404 static struct type
*
17405 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17407 struct type
*base_type
, *cv_type
;
17409 base_type
= die_type (die
, cu
);
17411 /* The die_type call above may have already set the type for this DIE. */
17412 cv_type
= get_die_type (die
, cu
);
17416 /* In case the volatile qualifier is applied to an array type, the
17417 element type is so qualified, not the array type (section 6.7.3
17419 if (base_type
->code () == TYPE_CODE_ARRAY
)
17420 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17422 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17423 return set_die_type (die
, cv_type
, cu
);
17426 /* Handle DW_TAG_restrict_type. */
17428 static struct type
*
17429 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17431 struct type
*base_type
, *cv_type
;
17433 base_type
= die_type (die
, cu
);
17435 /* The die_type call above may have already set the type for this DIE. */
17436 cv_type
= get_die_type (die
, cu
);
17440 cv_type
= make_restrict_type (base_type
);
17441 return set_die_type (die
, cv_type
, cu
);
17444 /* Handle DW_TAG_atomic_type. */
17446 static struct type
*
17447 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17449 struct type
*base_type
, *cv_type
;
17451 base_type
= die_type (die
, cu
);
17453 /* The die_type call above may have already set the type for this DIE. */
17454 cv_type
= get_die_type (die
, cu
);
17458 cv_type
= make_atomic_type (base_type
);
17459 return set_die_type (die
, cv_type
, cu
);
17462 /* Extract all information from a DW_TAG_string_type DIE and add to
17463 the user defined type vector. It isn't really a user defined type,
17464 but it behaves like one, with other DIE's using an AT_user_def_type
17465 attribute to reference it. */
17467 static struct type
*
17468 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17470 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17471 struct gdbarch
*gdbarch
= objfile
->arch ();
17472 struct type
*type
, *range_type
, *index_type
, *char_type
;
17473 struct attribute
*attr
;
17474 struct dynamic_prop prop
;
17475 bool length_is_constant
= true;
17478 /* There are a couple of places where bit sizes might be made use of
17479 when parsing a DW_TAG_string_type, however, no producer that we know
17480 of make use of these. Handling bit sizes that are a multiple of the
17481 byte size is easy enough, but what about other bit sizes? Lets deal
17482 with that problem when we have to. Warn about these attributes being
17483 unsupported, then parse the type and ignore them like we always
17485 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17486 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17488 static bool warning_printed
= false;
17489 if (!warning_printed
)
17491 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17492 "currently supported on DW_TAG_string_type."));
17493 warning_printed
= true;
17497 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17498 if (attr
!= nullptr && !attr
->form_is_constant ())
17500 /* The string length describes the location at which the length of
17501 the string can be found. The size of the length field can be
17502 specified with one of the attributes below. */
17503 struct type
*prop_type
;
17504 struct attribute
*len
17505 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17506 if (len
== nullptr)
17507 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17508 if (len
!= nullptr && len
->form_is_constant ())
17510 /* Pass 0 as the default as we know this attribute is constant
17511 and the default value will not be returned. */
17512 LONGEST sz
= len
->constant_value (0);
17513 prop_type
= objfile_int_type (objfile
, sz
, true);
17517 /* If the size is not specified then we assume it is the size of
17518 an address on this target. */
17519 prop_type
= cu
->addr_sized_int_type (true);
17522 /* Convert the attribute into a dynamic property. */
17523 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17526 length_is_constant
= false;
17528 else if (attr
!= nullptr)
17530 /* This DW_AT_string_length just contains the length with no
17531 indirection. There's no need to create a dynamic property in this
17532 case. Pass 0 for the default value as we know it will not be
17533 returned in this case. */
17534 length
= attr
->constant_value (0);
17536 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17538 /* We don't currently support non-constant byte sizes for strings. */
17539 length
= attr
->constant_value (1);
17543 /* Use 1 as a fallback length if we have nothing else. */
17547 index_type
= objfile_type (objfile
)->builtin_int
;
17548 if (length_is_constant
)
17549 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17552 struct dynamic_prop low_bound
;
17554 low_bound
.set_const_val (1);
17555 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17557 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17558 type
= create_string_type (NULL
, char_type
, range_type
);
17560 return set_die_type (die
, type
, cu
);
17563 /* Assuming that DIE corresponds to a function, returns nonzero
17564 if the function is prototyped. */
17567 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17569 struct attribute
*attr
;
17571 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17572 if (attr
&& attr
->as_boolean ())
17575 /* The DWARF standard implies that the DW_AT_prototyped attribute
17576 is only meaningful for C, but the concept also extends to other
17577 languages that allow unprototyped functions (Eg: Objective C).
17578 For all other languages, assume that functions are always
17580 if (cu
->per_cu
->lang
!= language_c
17581 && cu
->per_cu
->lang
!= language_objc
17582 && cu
->per_cu
->lang
!= language_opencl
)
17585 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17586 prototyped and unprototyped functions; default to prototyped,
17587 since that is more common in modern code (and RealView warns
17588 about unprototyped functions). */
17589 if (producer_is_realview (cu
->producer
))
17595 /* Handle DIES due to C code like:
17599 int (*funcp)(int a, long l);
17603 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17605 static struct type
*
17606 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17608 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17609 struct type
*type
; /* Type that this function returns. */
17610 struct type
*ftype
; /* Function that returns above type. */
17611 struct attribute
*attr
;
17613 type
= die_type (die
, cu
);
17615 /* The die_type call above may have already set the type for this DIE. */
17616 ftype
= get_die_type (die
, cu
);
17620 ftype
= lookup_function_type (type
);
17622 if (prototyped_function_p (die
, cu
))
17623 ftype
->set_is_prototyped (true);
17625 /* Store the calling convention in the type if it's available in
17626 the subroutine die. Otherwise set the calling convention to
17627 the default value DW_CC_normal. */
17628 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17629 if (attr
!= nullptr
17630 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17631 TYPE_CALLING_CONVENTION (ftype
)
17632 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17633 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17634 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17636 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17638 /* Record whether the function returns normally to its caller or not
17639 if the DWARF producer set that information. */
17640 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17641 if (attr
&& attr
->as_boolean ())
17642 TYPE_NO_RETURN (ftype
) = 1;
17644 /* We need to add the subroutine type to the die immediately so
17645 we don't infinitely recurse when dealing with parameters
17646 declared as the same subroutine type. */
17647 set_die_type (die
, ftype
, cu
);
17649 if (die
->child
!= NULL
)
17651 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17652 struct die_info
*child_die
;
17653 int nparams
, iparams
;
17655 /* Count the number of parameters.
17656 FIXME: GDB currently ignores vararg functions, but knows about
17657 vararg member functions. */
17659 child_die
= die
->child
;
17660 while (child_die
&& child_die
->tag
)
17662 if (child_die
->tag
== DW_TAG_formal_parameter
)
17664 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17665 ftype
->set_has_varargs (true);
17667 child_die
= child_die
->sibling
;
17670 /* Allocate storage for parameters and fill them in. */
17671 ftype
->set_num_fields (nparams
);
17673 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17675 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17676 even if we error out during the parameters reading below. */
17677 for (iparams
= 0; iparams
< nparams
; iparams
++)
17678 ftype
->field (iparams
).set_type (void_type
);
17681 child_die
= die
->child
;
17682 while (child_die
&& child_die
->tag
)
17684 if (child_die
->tag
== DW_TAG_formal_parameter
)
17686 struct type
*arg_type
;
17688 /* DWARF version 2 has no clean way to discern C++
17689 static and non-static member functions. G++ helps
17690 GDB by marking the first parameter for non-static
17691 member functions (which is the this pointer) as
17692 artificial. We pass this information to
17693 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17695 DWARF version 3 added DW_AT_object_pointer, which GCC
17696 4.5 does not yet generate. */
17697 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17698 if (attr
!= nullptr)
17699 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17701 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17702 arg_type
= die_type (child_die
, cu
);
17704 /* RealView does not mark THIS as const, which the testsuite
17705 expects. GCC marks THIS as const in method definitions,
17706 but not in the class specifications (GCC PR 43053). */
17707 if (cu
->per_cu
->lang
== language_cplus
17708 && !TYPE_CONST (arg_type
)
17709 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17712 struct dwarf2_cu
*arg_cu
= cu
;
17713 const char *name
= dwarf2_name (child_die
, cu
);
17715 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17716 if (attr
!= nullptr)
17718 /* If the compiler emits this, use it. */
17719 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17722 else if (name
&& strcmp (name
, "this") == 0)
17723 /* Function definitions will have the argument names. */
17725 else if (name
== NULL
&& iparams
== 0)
17726 /* Declarations may not have the names, so like
17727 elsewhere in GDB, assume an artificial first
17728 argument is "this". */
17732 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17736 ftype
->field (iparams
).set_type (arg_type
);
17739 child_die
= child_die
->sibling
;
17746 static struct type
*
17747 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17749 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17750 const char *name
= NULL
;
17751 struct type
*this_type
, *target_type
;
17753 name
= dwarf2_full_name (NULL
, die
, cu
);
17754 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17755 this_type
->set_target_is_stub (true);
17756 set_die_type (die
, this_type
, cu
);
17757 target_type
= die_type (die
, cu
);
17758 if (target_type
!= this_type
)
17759 TYPE_TARGET_TYPE (this_type
) = target_type
;
17762 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17763 spec and cause infinite loops in GDB. */
17764 complaint (_("Self-referential DW_TAG_typedef "
17765 "- DIE at %s [in module %s]"),
17766 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17767 TYPE_TARGET_TYPE (this_type
) = NULL
;
17771 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17772 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17773 Handle these by just returning the target type, rather than
17774 constructing an anonymous typedef type and trying to handle this
17776 set_die_type (die
, target_type
, cu
);
17777 return target_type
;
17782 /* Helper for get_dwarf2_rational_constant that computes the value of
17783 a given gmp_mpz given an attribute. */
17786 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17788 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17789 location expression that pushes an implicit value. */
17790 if (attr
->form
== DW_FORM_exprloc
)
17792 dwarf_block
*blk
= attr
->as_block ();
17793 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17796 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17797 blk
->data
+ blk
->size
,
17799 if (ptr
- blk
->data
+ len
<= blk
->size
)
17801 mpz_import (value
->val
, len
,
17802 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17808 /* On failure set it to 1. */
17809 *value
= gdb_mpz (1);
17811 else if (attr
->form_is_block ())
17813 dwarf_block
*blk
= attr
->as_block ();
17814 mpz_import (value
->val
, blk
->size
,
17815 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17816 1, 0, 0, blk
->data
);
17819 *value
= gdb_mpz (attr
->constant_value (1));
17822 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17823 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17825 If the numerator and/or numerator attribute is missing,
17826 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17830 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17831 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17833 struct attribute
*num_attr
, *denom_attr
;
17835 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17836 if (num_attr
== nullptr)
17837 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17838 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17840 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17841 if (denom_attr
== nullptr)
17842 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17843 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17845 if (num_attr
== nullptr || denom_attr
== nullptr)
17848 get_mpz (cu
, numerator
, num_attr
);
17849 get_mpz (cu
, denominator
, denom_attr
);
17852 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17853 rational constant, rather than a signed one.
17855 If the rational constant has a negative value, a complaint
17856 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17859 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17860 struct dwarf2_cu
*cu
,
17861 gdb_mpz
*numerator
,
17862 gdb_mpz
*denominator
)
17867 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17868 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17870 mpz_neg (num
.val
, num
.val
);
17871 mpz_neg (denom
.val
, denom
.val
);
17873 else if (mpz_sgn (num
.val
) == -1)
17875 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17877 sect_offset_str (die
->sect_off
));
17880 else if (mpz_sgn (denom
.val
) == -1)
17882 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17884 sect_offset_str (die
->sect_off
));
17888 *numerator
= std::move (num
);
17889 *denominator
= std::move (denom
);
17892 /* Assuming that ENCODING is a string whose contents starting at the
17893 K'th character is "_nn" where "nn" is a decimal number, scan that
17894 number and set RESULT to the value. K is updated to point to the
17895 character immediately following the number.
17897 If the string does not conform to the format described above, false
17898 is returned, and K may or may not be changed. */
17901 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17903 /* The next character should be an underscore ('_') followed
17905 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17908 /* Skip the underscore. */
17912 /* Determine the number of digits for our number. */
17913 while (isdigit (encoding
[k
]))
17918 std::string
copy (&encoding
[start
], k
- start
);
17919 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17925 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17926 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17927 DENOM, update OFFSET, and return true on success. Return false on
17931 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17932 gdb_mpz
*num
, gdb_mpz
*denom
)
17934 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17936 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17939 /* Assuming DIE corresponds to a fixed point type, finish the creation
17940 of the corresponding TYPE by setting its type-specific data. CU is
17941 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17942 encodings. It is nullptr if the GNAT encoding should be
17946 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17947 struct die_info
*die
, struct dwarf2_cu
*cu
)
17949 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17950 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17952 /* If GNAT encodings are preferred, don't examine the
17954 struct attribute
*attr
= nullptr;
17955 if (suffix
== nullptr)
17957 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17958 if (attr
== nullptr)
17959 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17960 if (attr
== nullptr)
17961 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17964 /* Numerator and denominator of our fixed-point type's scaling factor.
17965 The default is a scaling factor of 1, which we use as a fallback
17966 when we are not able to decode it (problem with the debugging info,
17967 unsupported forms, bug in GDB, etc...). Using that as the default
17968 allows us to at least print the unscaled value, which might still
17969 be useful to a user. */
17970 gdb_mpz
scale_num (1);
17971 gdb_mpz
scale_denom (1);
17973 if (attr
== nullptr)
17976 if (suffix
!= nullptr
17977 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17979 /* The number might be encoded as _nn_dd_nn_dd, where the
17980 second ratio is the 'small value. In this situation, we
17981 want the second value. */
17982 && (suffix
[offset
] != '_'
17983 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17990 /* Scaling factor not found. Assume a scaling factor of 1,
17991 and hope for the best. At least the user will be able to
17992 see the encoded value. */
17995 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17996 sect_offset_str (die
->sect_off
));
17999 else if (attr
->name
== DW_AT_binary_scale
)
18001 LONGEST scale_exp
= attr
->constant_value (0);
18002 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18004 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18006 else if (attr
->name
== DW_AT_decimal_scale
)
18008 LONGEST scale_exp
= attr
->constant_value (0);
18009 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18011 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18013 else if (attr
->name
== DW_AT_small
)
18015 struct die_info
*scale_die
;
18016 struct dwarf2_cu
*scale_cu
= cu
;
18018 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18019 if (scale_die
->tag
== DW_TAG_constant
)
18020 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18021 &scale_num
, &scale_denom
);
18023 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18025 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18029 complaint (_("unsupported scale attribute %s for fixed-point type"
18031 dwarf_attr_name (attr
->name
),
18032 sect_offset_str (die
->sect_off
));
18035 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18036 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18037 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18038 mpq_canonicalize (scaling_factor
.val
);
18041 /* The gnat-encoding suffix for fixed point. */
18043 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18045 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18046 "XF" suffix of the name. The text after this is what encodes the
18047 'small and 'delta information. Otherwise, return nullptr. */
18049 static const char *
18050 gnat_encoded_fixed_point_type_info (const char *name
)
18052 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18055 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18056 (which may be different from NAME) to the architecture back-end to allow
18057 it to guess the correct format if necessary. */
18059 static struct type
*
18060 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18061 const char *name_hint
, enum bfd_endian byte_order
)
18063 struct gdbarch
*gdbarch
= objfile
->arch ();
18064 const struct floatformat
**format
;
18067 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18069 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18071 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18076 /* Allocate an integer type of size BITS and name NAME. */
18078 static struct type
*
18079 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18080 int bits
, int unsigned_p
, const char *name
)
18084 /* Versions of Intel's C Compiler generate an integer type called "void"
18085 instead of using DW_TAG_unspecified_type. This has been seen on
18086 at least versions 14, 17, and 18. */
18087 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18088 && strcmp (name
, "void") == 0)
18089 type
= objfile_type (objfile
)->builtin_void
;
18091 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18096 /* Return true if DIE has a DW_AT_small attribute whose value is
18097 a constant rational, where both the numerator and denominator
18100 CU is the DIE's Compilation Unit. */
18103 has_zero_over_zero_small_attribute (struct die_info
*die
,
18104 struct dwarf2_cu
*cu
)
18106 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18107 if (attr
== nullptr)
18110 struct dwarf2_cu
*scale_cu
= cu
;
18111 struct die_info
*scale_die
18112 = follow_die_ref (die
, attr
, &scale_cu
);
18114 if (scale_die
->tag
!= DW_TAG_constant
)
18117 gdb_mpz
num (1), denom (1);
18118 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18119 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18122 /* Initialise and return a floating point type of size BITS suitable for
18123 use as a component of a complex number. The NAME_HINT is passed through
18124 when initialising the floating point type and is the name of the complex
18127 As DWARF doesn't currently provide an explicit name for the components
18128 of a complex number, but it can be helpful to have these components
18129 named, we try to select a suitable name based on the size of the
18131 static struct type
*
18132 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18133 struct objfile
*objfile
,
18134 int bits
, const char *name_hint
,
18135 enum bfd_endian byte_order
)
18137 gdbarch
*gdbarch
= objfile
->arch ();
18138 struct type
*tt
= nullptr;
18140 /* Try to find a suitable floating point builtin type of size BITS.
18141 We're going to use the name of this type as the name for the complex
18142 target type that we are about to create. */
18143 switch (cu
->per_cu
->lang
)
18145 case language_fortran
:
18149 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18152 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18154 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18156 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18164 tt
= builtin_type (gdbarch
)->builtin_float
;
18167 tt
= builtin_type (gdbarch
)->builtin_double
;
18169 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18171 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18177 /* If the type we found doesn't match the size we were looking for, then
18178 pretend we didn't find a type at all, the complex target type we
18179 create will then be nameless. */
18180 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18183 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18184 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18187 /* Find a representation of a given base type and install
18188 it in the TYPE field of the die. */
18190 static struct type
*
18191 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18193 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18195 struct attribute
*attr
;
18196 int encoding
= 0, bits
= 0;
18200 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18201 if (attr
!= nullptr && attr
->form_is_constant ())
18202 encoding
= attr
->constant_value (0);
18203 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18204 if (attr
!= nullptr)
18205 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18206 name
= dwarf2_name (die
, cu
);
18208 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18210 arch
= objfile
->arch ();
18211 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18213 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18214 if (attr
!= nullptr && attr
->form_is_constant ())
18216 int endianity
= attr
->constant_value (0);
18221 byte_order
= BFD_ENDIAN_BIG
;
18223 case DW_END_little
:
18224 byte_order
= BFD_ENDIAN_LITTLE
;
18227 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18232 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18233 && cu
->per_cu
->lang
== language_ada
18234 && has_zero_over_zero_small_attribute (die
, cu
))
18236 /* brobecker/2018-02-24: This is a fixed point type for which
18237 the scaling factor is represented as fraction whose value
18238 does not make sense (zero divided by zero), so we should
18239 normally never see these. However, there is a small category
18240 of fixed point types for which GNAT is unable to provide
18241 the scaling factor via the standard DWARF mechanisms, and
18242 for which the info is provided via the GNAT encodings instead.
18243 This is likely what this DIE is about. */
18244 encoding
= (encoding
== DW_ATE_signed_fixed
18246 : DW_ATE_unsigned
);
18249 /* With GNAT encodings, fixed-point information will be encoded in
18250 the type name. Note that this can also occur with the above
18251 zero-over-zero case, which is why this is a separate "if" rather
18252 than an "else if". */
18253 const char *gnat_encoding_suffix
= nullptr;
18254 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18255 && cu
->per_cu
->lang
== language_ada
18256 && name
!= nullptr)
18258 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18259 if (gnat_encoding_suffix
!= nullptr)
18261 gdb_assert (startswith (gnat_encoding_suffix
,
18262 GNAT_FIXED_POINT_SUFFIX
));
18263 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18264 name
, gnat_encoding_suffix
- name
);
18265 /* Use -1 here so that SUFFIX points at the "_" after the
18267 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18269 encoding
= (encoding
== DW_ATE_signed
18270 ? DW_ATE_signed_fixed
18271 : DW_ATE_unsigned_fixed
);
18277 case DW_ATE_address
:
18278 /* Turn DW_ATE_address into a void * pointer. */
18279 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18280 type
= init_pointer_type (objfile
, bits
, name
, type
);
18282 case DW_ATE_boolean
:
18283 type
= init_boolean_type (objfile
, bits
, 1, name
);
18285 case DW_ATE_complex_float
:
18286 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18288 if (type
->code () == TYPE_CODE_ERROR
)
18290 if (name
== nullptr)
18292 struct obstack
*obstack
18293 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18294 name
= obconcat (obstack
, "_Complex ", type
->name (),
18297 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18300 type
= init_complex_type (name
, type
);
18302 case DW_ATE_decimal_float
:
18303 type
= init_decfloat_type (objfile
, bits
, name
);
18306 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18308 case DW_ATE_signed
:
18309 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18311 case DW_ATE_unsigned
:
18312 if (cu
->per_cu
->lang
== language_fortran
18314 && startswith (name
, "character("))
18315 type
= init_character_type (objfile
, bits
, 1, name
);
18317 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18319 case DW_ATE_signed_char
:
18320 if (cu
->per_cu
->lang
== language_ada
18321 || cu
->per_cu
->lang
== language_m2
18322 || cu
->per_cu
->lang
== language_pascal
18323 || cu
->per_cu
->lang
== language_fortran
)
18324 type
= init_character_type (objfile
, bits
, 0, name
);
18326 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18328 case DW_ATE_unsigned_char
:
18329 if (cu
->per_cu
->lang
== language_ada
18330 || cu
->per_cu
->lang
== language_m2
18331 || cu
->per_cu
->lang
== language_pascal
18332 || cu
->per_cu
->lang
== language_fortran
18333 || cu
->per_cu
->lang
== language_rust
)
18334 type
= init_character_type (objfile
, bits
, 1, name
);
18336 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18340 type
= init_character_type (objfile
, bits
, 1, name
);
18341 return set_die_type (die
, type
, cu
);
18344 case DW_ATE_signed_fixed
:
18345 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18346 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18348 case DW_ATE_unsigned_fixed
:
18349 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18350 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18354 complaint (_("unsupported DW_AT_encoding: '%s'"),
18355 dwarf_type_encoding_name (encoding
));
18356 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18360 if (type
->code () == TYPE_CODE_INT
18362 && strcmp (name
, "char") == 0)
18363 type
->set_has_no_signedness (true);
18365 maybe_set_alignment (cu
, die
, type
);
18367 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18369 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18371 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18372 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18374 unsigned real_bit_size
= attr
->as_unsigned ();
18375 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18376 /* Only use the attributes if they make sense together. */
18377 if (attr
== nullptr
18378 || (attr
->as_unsigned () + real_bit_size
18379 <= 8 * TYPE_LENGTH (type
)))
18381 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18383 if (attr
!= nullptr)
18384 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18385 = attr
->as_unsigned ();
18390 return set_die_type (die
, type
, cu
);
18393 /* A helper function that returns the name of DIE, if it refers to a
18394 variable declaration. */
18396 static const char *
18397 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18399 if (die
->tag
!= DW_TAG_variable
)
18402 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18403 if (attr
== nullptr || !attr
->as_boolean ())
18406 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18407 if (attr
== nullptr)
18409 return attr
->as_string ();
18412 /* Parse dwarf attribute if it's a block, reference or constant and put the
18413 resulting value of the attribute into struct bound_prop.
18414 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18417 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18418 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18419 struct type
*default_type
)
18421 struct dwarf2_property_baton
*baton
;
18422 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18423 struct objfile
*objfile
= per_objfile
->objfile
;
18424 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18426 gdb_assert (default_type
!= NULL
);
18428 if (attr
== NULL
|| prop
== NULL
)
18431 if (attr
->form_is_block ())
18433 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18434 baton
->property_type
= default_type
;
18435 baton
->locexpr
.per_cu
= cu
->per_cu
;
18436 baton
->locexpr
.per_objfile
= per_objfile
;
18438 struct dwarf_block
*block
;
18439 if (attr
->form
== DW_FORM_data16
)
18441 size_t data_size
= 16;
18442 block
= XOBNEW (obstack
, struct dwarf_block
);
18443 block
->size
= (data_size
18444 + 2 /* Extra bytes for DW_OP and arg. */);
18445 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
18446 data
[0] = DW_OP_implicit_value
;
18447 data
[1] = data_size
;
18448 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
18449 block
->data
= data
;
18452 block
= attr
->as_block ();
18454 baton
->locexpr
.size
= block
->size
;
18455 baton
->locexpr
.data
= block
->data
;
18456 switch (attr
->name
)
18458 case DW_AT_string_length
:
18459 baton
->locexpr
.is_reference
= true;
18462 baton
->locexpr
.is_reference
= false;
18466 prop
->set_locexpr (baton
);
18467 gdb_assert (prop
->baton () != NULL
);
18469 else if (attr
->form_is_ref ())
18471 struct dwarf2_cu
*target_cu
= cu
;
18472 struct die_info
*target_die
;
18473 struct attribute
*target_attr
;
18475 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18476 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18477 if (target_attr
== NULL
)
18478 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18480 if (target_attr
== nullptr)
18481 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
18483 if (target_attr
== NULL
)
18485 const char *name
= var_decl_name (target_die
, target_cu
);
18486 if (name
!= nullptr)
18488 prop
->set_variable_name (name
);
18494 switch (target_attr
->name
)
18496 case DW_AT_location
:
18497 if (target_attr
->form_is_section_offset ())
18499 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18500 baton
->property_type
= die_type (target_die
, target_cu
);
18501 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18502 prop
->set_loclist (baton
);
18503 gdb_assert (prop
->baton () != NULL
);
18505 else if (target_attr
->form_is_block ())
18507 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18508 baton
->property_type
= die_type (target_die
, target_cu
);
18509 baton
->locexpr
.per_cu
= cu
->per_cu
;
18510 baton
->locexpr
.per_objfile
= per_objfile
;
18511 struct dwarf_block
*block
= target_attr
->as_block ();
18512 baton
->locexpr
.size
= block
->size
;
18513 baton
->locexpr
.data
= block
->data
;
18514 baton
->locexpr
.is_reference
= true;
18515 prop
->set_locexpr (baton
);
18516 gdb_assert (prop
->baton () != NULL
);
18520 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18521 "dynamic property");
18525 case DW_AT_data_member_location
:
18526 case DW_AT_data_bit_offset
:
18530 if (!handle_member_location (target_die
, target_cu
, &offset
))
18533 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18534 baton
->property_type
= read_type_die (target_die
->parent
,
18536 baton
->offset_info
.offset
= offset
;
18537 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18538 prop
->set_addr_offset (baton
);
18543 else if (attr
->form_is_constant ())
18544 prop
->set_const_val (attr
->constant_value (0));
18545 else if (attr
->form_is_section_offset ())
18547 switch (attr
->name
)
18549 case DW_AT_string_length
:
18550 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18551 baton
->property_type
= default_type
;
18552 fill_in_loclist_baton (cu
, &baton
->loclist
, attr
);
18553 prop
->set_loclist (baton
);
18554 gdb_assert (prop
->baton () != NULL
);
18566 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18567 dwarf2_name (die
, cu
));
18573 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18574 present (which is valid) then compute the default type based on the
18575 compilation units address size. */
18577 static struct type
*
18578 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18580 struct type
*index_type
= die_type (die
, cu
);
18582 /* Dwarf-2 specifications explicitly allows to create subrange types
18583 without specifying a base type.
18584 In that case, the base type must be set to the type of
18585 the lower bound, upper bound or count, in that order, if any of these
18586 three attributes references an object that has a type.
18587 If no base type is found, the Dwarf-2 specifications say that
18588 a signed integer type of size equal to the size of an address should
18590 For the following C code: `extern char gdb_int [];'
18591 GCC produces an empty range DIE.
18592 FIXME: muller/2010-05-28: Possible references to object for low bound,
18593 high bound or count are not yet handled by this code. */
18594 if (index_type
->code () == TYPE_CODE_VOID
)
18595 index_type
= cu
->addr_sized_int_type (false);
18600 /* Read the given DW_AT_subrange DIE. */
18602 static struct type
*
18603 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18605 struct type
*base_type
, *orig_base_type
;
18606 struct type
*range_type
;
18607 struct attribute
*attr
;
18608 struct dynamic_prop low
, high
;
18609 int low_default_is_valid
;
18610 int high_bound_is_count
= 0;
18612 ULONGEST negative_mask
;
18614 orig_base_type
= read_subrange_index_type (die
, cu
);
18616 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18617 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18618 creating the range type, but we use the result of check_typedef
18619 when examining properties of the type. */
18620 base_type
= check_typedef (orig_base_type
);
18622 /* The die_type call above may have already set the type for this DIE. */
18623 range_type
= get_die_type (die
, cu
);
18627 high
.set_const_val (0);
18629 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18630 omitting DW_AT_lower_bound. */
18631 switch (cu
->per_cu
->lang
)
18634 case language_cplus
:
18635 low
.set_const_val (0);
18636 low_default_is_valid
= 1;
18638 case language_fortran
:
18639 low
.set_const_val (1);
18640 low_default_is_valid
= 1;
18643 case language_objc
:
18644 case language_rust
:
18645 low
.set_const_val (0);
18646 low_default_is_valid
= (cu
->header
.version
>= 4);
18650 case language_pascal
:
18651 low
.set_const_val (1);
18652 low_default_is_valid
= (cu
->header
.version
>= 4);
18655 low
.set_const_val (0);
18656 low_default_is_valid
= 0;
18660 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18661 if (attr
!= nullptr)
18662 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18663 else if (!low_default_is_valid
)
18664 complaint (_("Missing DW_AT_lower_bound "
18665 "- DIE at %s [in module %s]"),
18666 sect_offset_str (die
->sect_off
),
18667 objfile_name (cu
->per_objfile
->objfile
));
18669 struct attribute
*attr_ub
, *attr_count
;
18670 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18671 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18673 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18674 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18676 /* If bounds are constant do the final calculation here. */
18677 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18678 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18680 high_bound_is_count
= 1;
18684 if (attr_ub
!= NULL
)
18685 complaint (_("Unresolved DW_AT_upper_bound "
18686 "- DIE at %s [in module %s]"),
18687 sect_offset_str (die
->sect_off
),
18688 objfile_name (cu
->per_objfile
->objfile
));
18689 if (attr_count
!= NULL
)
18690 complaint (_("Unresolved DW_AT_count "
18691 "- DIE at %s [in module %s]"),
18692 sect_offset_str (die
->sect_off
),
18693 objfile_name (cu
->per_objfile
->objfile
));
18698 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18699 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18700 bias
= bias_attr
->constant_value (0);
18702 /* Normally, the DWARF producers are expected to use a signed
18703 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18704 But this is unfortunately not always the case, as witnessed
18705 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18706 is used instead. To work around that ambiguity, we treat
18707 the bounds as signed, and thus sign-extend their values, when
18708 the base type is signed. */
18710 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18711 if (low
.kind () == PROP_CONST
18712 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18713 low
.set_const_val (low
.const_val () | negative_mask
);
18714 if (high
.kind () == PROP_CONST
18715 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18716 high
.set_const_val (high
.const_val () | negative_mask
);
18718 /* Check for bit and byte strides. */
18719 struct dynamic_prop byte_stride_prop
;
18720 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18721 if (attr_byte_stride
!= nullptr)
18723 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18724 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18728 struct dynamic_prop bit_stride_prop
;
18729 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18730 if (attr_bit_stride
!= nullptr)
18732 /* It only makes sense to have either a bit or byte stride. */
18733 if (attr_byte_stride
!= nullptr)
18735 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18736 "- DIE at %s [in module %s]"),
18737 sect_offset_str (die
->sect_off
),
18738 objfile_name (cu
->per_objfile
->objfile
));
18739 attr_bit_stride
= nullptr;
18743 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18744 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18749 if (attr_byte_stride
!= nullptr
18750 || attr_bit_stride
!= nullptr)
18752 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18753 struct dynamic_prop
*stride
18754 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18757 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18758 &high
, bias
, stride
, byte_stride_p
);
18761 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18763 if (high_bound_is_count
)
18764 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18766 /* Ada expects an empty array on no boundary attributes. */
18767 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
18768 range_type
->bounds ()->high
.set_undefined ();
18770 name
= dwarf2_name (die
, cu
);
18772 range_type
->set_name (name
);
18774 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18775 if (attr
!= nullptr)
18776 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18778 maybe_set_alignment (cu
, die
, range_type
);
18780 set_die_type (die
, range_type
, cu
);
18782 /* set_die_type should be already done. */
18783 set_descriptive_type (range_type
, die
, cu
);
18788 static struct type
*
18789 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18793 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18794 type
->set_name (dwarf2_name (die
, cu
));
18796 /* In Ada, an unspecified type is typically used when the description
18797 of the type is deferred to a different unit. When encountering
18798 such a type, we treat it as a stub, and try to resolve it later on,
18800 if (cu
->per_cu
->lang
== language_ada
)
18801 type
->set_is_stub (true);
18803 return set_die_type (die
, type
, cu
);
18806 /* Read a single die and all its descendents. Set the die's sibling
18807 field to NULL; set other fields in the die correctly, and set all
18808 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18809 location of the info_ptr after reading all of those dies. PARENT
18810 is the parent of the die in question. */
18812 static struct die_info
*
18813 read_die_and_children (const struct die_reader_specs
*reader
,
18814 const gdb_byte
*info_ptr
,
18815 const gdb_byte
**new_info_ptr
,
18816 struct die_info
*parent
)
18818 struct die_info
*die
;
18819 const gdb_byte
*cur_ptr
;
18821 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18824 *new_info_ptr
= cur_ptr
;
18827 store_in_ref_table (die
, reader
->cu
);
18829 if (die
->has_children
)
18830 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18834 *new_info_ptr
= cur_ptr
;
18837 die
->sibling
= NULL
;
18838 die
->parent
= parent
;
18842 /* Read a die, all of its descendents, and all of its siblings; set
18843 all of the fields of all of the dies correctly. Arguments are as
18844 in read_die_and_children. */
18846 static struct die_info
*
18847 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18848 const gdb_byte
*info_ptr
,
18849 const gdb_byte
**new_info_ptr
,
18850 struct die_info
*parent
)
18852 struct die_info
*first_die
, *last_sibling
;
18853 const gdb_byte
*cur_ptr
;
18855 cur_ptr
= info_ptr
;
18856 first_die
= last_sibling
= NULL
;
18860 struct die_info
*die
18861 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18865 *new_info_ptr
= cur_ptr
;
18872 last_sibling
->sibling
= die
;
18874 last_sibling
= die
;
18878 /* Read a die, all of its descendents, and all of its siblings; set
18879 all of the fields of all of the dies correctly. Arguments are as
18880 in read_die_and_children.
18881 This the main entry point for reading a DIE and all its children. */
18883 static struct die_info
*
18884 read_die_and_siblings (const struct die_reader_specs
*reader
,
18885 const gdb_byte
*info_ptr
,
18886 const gdb_byte
**new_info_ptr
,
18887 struct die_info
*parent
)
18889 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18890 new_info_ptr
, parent
);
18892 if (dwarf_die_debug
)
18894 gdb_printf (gdb_stdlog
,
18895 "Read die from %s@0x%x of %s:\n",
18896 reader
->die_section
->get_name (),
18897 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18898 bfd_get_filename (reader
->abfd
));
18899 dump_die (die
, dwarf_die_debug
);
18905 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18907 The caller is responsible for filling in the extra attributes
18908 and updating (*DIEP)->num_attrs.
18909 Set DIEP to point to a newly allocated die with its information,
18910 except for its child, sibling, and parent fields. */
18912 static const gdb_byte
*
18913 read_full_die_1 (const struct die_reader_specs
*reader
,
18914 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18915 int num_extra_attrs
)
18917 unsigned int abbrev_number
, bytes_read
, i
;
18918 const struct abbrev_info
*abbrev
;
18919 struct die_info
*die
;
18920 struct dwarf2_cu
*cu
= reader
->cu
;
18921 bfd
*abfd
= reader
->abfd
;
18923 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18924 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18925 info_ptr
+= bytes_read
;
18926 if (!abbrev_number
)
18932 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18934 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18936 bfd_get_filename (abfd
));
18938 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18939 die
->sect_off
= sect_off
;
18940 die
->tag
= abbrev
->tag
;
18941 die
->abbrev
= abbrev_number
;
18942 die
->has_children
= abbrev
->has_children
;
18944 /* Make the result usable.
18945 The caller needs to update num_attrs after adding the extra
18947 die
->num_attrs
= abbrev
->num_attrs
;
18949 bool any_need_reprocess
= false;
18950 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18952 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18954 if (die
->attrs
[i
].requires_reprocessing_p ())
18955 any_need_reprocess
= true;
18958 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18959 if (attr
!= nullptr && attr
->form_is_unsigned ())
18960 cu
->str_offsets_base
= attr
->as_unsigned ();
18962 attr
= die
->attr (DW_AT_loclists_base
);
18963 if (attr
!= nullptr)
18964 cu
->loclist_base
= attr
->as_unsigned ();
18966 auto maybe_addr_base
= die
->addr_base ();
18967 if (maybe_addr_base
.has_value ())
18968 cu
->addr_base
= *maybe_addr_base
;
18970 attr
= die
->attr (DW_AT_rnglists_base
);
18971 if (attr
!= nullptr)
18972 cu
->rnglists_base
= attr
->as_unsigned ();
18974 if (any_need_reprocess
)
18976 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18978 if (die
->attrs
[i
].requires_reprocessing_p ())
18979 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18986 /* Read a die and all its attributes.
18987 Set DIEP to point to a newly allocated die with its information,
18988 except for its child, sibling, and parent fields. */
18990 static const gdb_byte
*
18991 read_full_die (const struct die_reader_specs
*reader
,
18992 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18994 const gdb_byte
*result
;
18996 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18998 if (dwarf_die_debug
)
19000 gdb_printf (gdb_stdlog
,
19001 "Read die from %s@0x%x of %s:\n",
19002 reader
->die_section
->get_name (),
19003 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19004 bfd_get_filename (reader
->abfd
));
19005 dump_die (*diep
, dwarf_die_debug
);
19012 /* Returns nonzero if TAG represents a type that we might generate a partial
19016 is_type_tag_for_partial (int tag
, enum language lang
)
19021 /* Some types that would be reasonable to generate partial symbols for,
19022 that we don't at present. Note that normally this does not
19023 matter, mainly because C compilers don't give names to these
19024 types, but instead emit DW_TAG_typedef. */
19025 case DW_TAG_file_type
:
19026 case DW_TAG_ptr_to_member_type
:
19027 case DW_TAG_set_type
:
19028 case DW_TAG_string_type
:
19029 case DW_TAG_subroutine_type
:
19032 /* GNAT may emit an array with a name, but no typedef, so we
19033 need to make a symbol in this case. */
19034 case DW_TAG_array_type
:
19035 return lang
== language_ada
;
19037 case DW_TAG_base_type
:
19038 case DW_TAG_class_type
:
19039 case DW_TAG_interface_type
:
19040 case DW_TAG_enumeration_type
:
19041 case DW_TAG_structure_type
:
19042 case DW_TAG_subrange_type
:
19043 case DW_TAG_generic_subrange
:
19044 case DW_TAG_typedef
:
19045 case DW_TAG_union_type
:
19052 /* Load all DIEs that are interesting for partial symbols into memory. */
19054 static struct partial_die_info
*
19055 load_partial_dies (const struct die_reader_specs
*reader
,
19056 const gdb_byte
*info_ptr
, int building_psymtab
)
19058 struct dwarf2_cu
*cu
= reader
->cu
;
19059 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19060 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19061 unsigned int bytes_read
;
19062 unsigned int load_all
= 0;
19063 int nesting_level
= 1;
19068 gdb_assert (cu
->per_cu
!= NULL
);
19069 if (cu
->load_all_dies
)
19073 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19077 &cu
->comp_unit_obstack
,
19078 hashtab_obstack_allocate
,
19079 dummy_obstack_deallocate
);
19083 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19086 /* A NULL abbrev means the end of a series of children. */
19087 if (abbrev
== NULL
)
19089 if (--nesting_level
== 0)
19092 info_ptr
+= bytes_read
;
19093 last_die
= parent_die
;
19094 parent_die
= parent_die
->die_parent
;
19098 /* Check for template arguments. We never save these; if
19099 they're seen, we just mark the parent, and go on our way. */
19100 if (parent_die
!= NULL
19101 && cu
->per_cu
->lang
== language_cplus
19102 && (abbrev
->tag
== DW_TAG_template_type_param
19103 || abbrev
->tag
== DW_TAG_template_value_param
))
19105 parent_die
->has_template_arguments
= 1;
19109 /* We don't need a partial DIE for the template argument. */
19110 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19115 /* We only recurse into c++ subprograms looking for template arguments.
19116 Skip their other children. */
19118 && cu
->per_cu
->lang
== language_cplus
19119 && parent_die
!= NULL
19120 && parent_die
->tag
== DW_TAG_subprogram
19121 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19123 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19127 /* Check whether this DIE is interesting enough to save. Normally
19128 we would not be interested in members here, but there may be
19129 later variables referencing them via DW_AT_specification (for
19130 static members). */
19132 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
19133 && abbrev
->tag
!= DW_TAG_constant
19134 && abbrev
->tag
!= DW_TAG_enumerator
19135 && abbrev
->tag
!= DW_TAG_subprogram
19136 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19137 && abbrev
->tag
!= DW_TAG_lexical_block
19138 && abbrev
->tag
!= DW_TAG_variable
19139 && abbrev
->tag
!= DW_TAG_namespace
19140 && abbrev
->tag
!= DW_TAG_module
19141 && abbrev
->tag
!= DW_TAG_member
19142 && abbrev
->tag
!= DW_TAG_imported_unit
19143 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19145 /* Otherwise we skip to the next sibling, if any. */
19146 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19150 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19153 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19155 /* This two-pass algorithm for processing partial symbols has a
19156 high cost in cache pressure. Thus, handle some simple cases
19157 here which cover the majority of C partial symbols. DIEs
19158 which neither have specification tags in them, nor could have
19159 specification tags elsewhere pointing at them, can simply be
19160 processed and discarded.
19162 This segment is also optional; scan_partial_symbols and
19163 add_partial_symbol will handle these DIEs if we chain
19164 them in normally. When compilers which do not emit large
19165 quantities of duplicate debug information are more common,
19166 this code can probably be removed. */
19168 /* Any complete simple types at the top level (pretty much all
19169 of them, for a language without namespaces), can be processed
19171 if (parent_die
== NULL
19172 && pdi
.has_specification
== 0
19173 && pdi
.is_declaration
== 0
19174 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19175 || pdi
.tag
== DW_TAG_base_type
19176 || pdi
.tag
== DW_TAG_array_type
19177 || pdi
.tag
== DW_TAG_generic_subrange
19178 || pdi
.tag
== DW_TAG_subrange_type
))
19180 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19181 add_partial_symbol (&pdi
, cu
);
19183 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19187 /* The exception for DW_TAG_typedef with has_children above is
19188 a workaround of GCC PR debug/47510. In the case of this complaint
19189 type_name_or_error will error on such types later.
19191 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19192 it could not find the child DIEs referenced later, this is checked
19193 above. In correct DWARF DW_TAG_typedef should have no children. */
19195 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19196 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19197 "- DIE at %s [in module %s]"),
19198 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19200 /* If we're at the second level, and we're an enumerator, and
19201 our parent has no specification (meaning possibly lives in a
19202 namespace elsewhere), then we can add the partial symbol now
19203 instead of queueing it. */
19204 if (pdi
.tag
== DW_TAG_enumerator
19205 && parent_die
!= NULL
19206 && parent_die
->die_parent
== NULL
19207 && parent_die
->tag
== DW_TAG_enumeration_type
19208 && parent_die
->has_specification
== 0)
19210 if (pdi
.raw_name
== NULL
)
19211 complaint (_("malformed enumerator DIE ignored"));
19212 else if (building_psymtab
)
19213 add_partial_symbol (&pdi
, cu
);
19215 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19219 struct partial_die_info
*part_die
19220 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19222 /* We'll save this DIE so link it in. */
19223 part_die
->die_parent
= parent_die
;
19224 part_die
->die_sibling
= NULL
;
19225 part_die
->die_child
= NULL
;
19227 if (last_die
&& last_die
== parent_die
)
19228 last_die
->die_child
= part_die
;
19230 last_die
->die_sibling
= part_die
;
19232 last_die
= part_die
;
19234 if (first_die
== NULL
)
19235 first_die
= part_die
;
19237 /* Maybe add the DIE to the hash table. Not all DIEs that we
19238 find interesting need to be in the hash table, because we
19239 also have the parent/sibling/child chains; only those that we
19240 might refer to by offset later during partial symbol reading.
19242 For now this means things that might have be the target of a
19243 DW_AT_specification, DW_AT_abstract_origin, or
19244 DW_AT_extension. DW_AT_extension will refer only to
19245 namespaces; DW_AT_abstract_origin refers to functions (and
19246 many things under the function DIE, but we do not recurse
19247 into function DIEs during partial symbol reading) and
19248 possibly variables as well; DW_AT_specification refers to
19249 declarations. Declarations ought to have the DW_AT_declaration
19250 flag. It happens that GCC forgets to put it in sometimes, but
19251 only for functions, not for types.
19253 Adding more things than necessary to the hash table is harmless
19254 except for the performance cost. Adding too few will result in
19255 wasted time in find_partial_die, when we reread the compilation
19256 unit with load_all_dies set. */
19259 || abbrev
->tag
== DW_TAG_constant
19260 || abbrev
->tag
== DW_TAG_subprogram
19261 || abbrev
->tag
== DW_TAG_variable
19262 || abbrev
->tag
== DW_TAG_namespace
19263 || part_die
->is_declaration
)
19267 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19268 to_underlying (part_die
->sect_off
),
19273 /* For some DIEs we want to follow their children (if any). For C
19274 we have no reason to follow the children of structures; for other
19275 languages we have to, so that we can get at method physnames
19276 to infer fully qualified class names, for DW_AT_specification,
19277 and for C++ template arguments. For C++, we also look one level
19278 inside functions to find template arguments (if the name of the
19279 function does not already contain the template arguments).
19281 For Ada and Fortran, we need to scan the children of subprograms
19282 and lexical blocks as well because these languages allow the
19283 definition of nested entities that could be interesting for the
19284 debugger, such as nested subprograms for instance. */
19285 if (last_die
->has_children
19287 || last_die
->tag
== DW_TAG_namespace
19288 || last_die
->tag
== DW_TAG_module
19289 || last_die
->tag
== DW_TAG_enumeration_type
19290 || (cu
->per_cu
->lang
== language_cplus
19291 && last_die
->tag
== DW_TAG_subprogram
19292 && (last_die
->raw_name
== NULL
19293 || strchr (last_die
->raw_name
, '<') == NULL
))
19294 || (cu
->per_cu
->lang
!= language_c
19295 && (last_die
->tag
== DW_TAG_class_type
19296 || last_die
->tag
== DW_TAG_interface_type
19297 || last_die
->tag
== DW_TAG_structure_type
19298 || last_die
->tag
== DW_TAG_union_type
))
19299 || ((cu
->per_cu
->lang
== language_ada
19300 || cu
->per_cu
->lang
== language_fortran
)
19301 && (last_die
->tag
== DW_TAG_subprogram
19302 || last_die
->tag
== DW_TAG_lexical_block
))))
19305 parent_die
= last_die
;
19309 /* Otherwise we skip to the next sibling, if any. */
19310 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19312 /* Back to the top, do it again. */
19316 partial_die_info::partial_die_info (sect_offset sect_off_
,
19317 const struct abbrev_info
*abbrev
)
19318 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19322 /* See class definition. */
19325 partial_die_info::name (dwarf2_cu
*cu
)
19327 if (!canonical_name
&& raw_name
!= nullptr)
19329 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19330 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19331 canonical_name
= 1;
19337 /* Read a minimal amount of information into the minimal die structure.
19338 INFO_PTR should point just after the initial uleb128 of a DIE. */
19341 partial_die_info::read (const struct die_reader_specs
*reader
,
19342 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19344 struct dwarf2_cu
*cu
= reader
->cu
;
19345 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19347 int has_low_pc_attr
= 0;
19348 int has_high_pc_attr
= 0;
19349 int high_pc_relative
= 0;
19351 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19354 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19355 /* String and address offsets that need to do the reprocessing have
19356 already been read at this point, so there is no need to wait until
19357 the loop terminates to do the reprocessing. */
19358 if (attr
.requires_reprocessing_p ())
19359 read_attribute_reprocess (reader
, &attr
, tag
);
19360 /* Store the data if it is of an attribute we want to keep in a
19361 partial symbol table. */
19367 case DW_TAG_compile_unit
:
19368 case DW_TAG_partial_unit
:
19369 case DW_TAG_type_unit
:
19370 /* Compilation units have a DW_AT_name that is a filename, not
19371 a source language identifier. */
19372 case DW_TAG_enumeration_type
:
19373 case DW_TAG_enumerator
:
19374 /* These tags always have simple identifiers already; no need
19375 to canonicalize them. */
19376 canonical_name
= 1;
19377 raw_name
= attr
.as_string ();
19380 canonical_name
= 0;
19381 raw_name
= attr
.as_string ();
19385 case DW_AT_linkage_name
:
19386 case DW_AT_MIPS_linkage_name
:
19387 /* Note that both forms of linkage name might appear. We
19388 assume they will be the same, and we only store the last
19390 linkage_name
= attr
.as_string ();
19393 has_low_pc_attr
= 1;
19394 lowpc
= attr
.as_address ();
19396 case DW_AT_high_pc
:
19397 has_high_pc_attr
= 1;
19398 highpc
= attr
.as_address ();
19399 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19400 high_pc_relative
= 1;
19402 case DW_AT_location
:
19403 /* Support the .debug_loc offsets. */
19404 if (attr
.form_is_block ())
19406 d
.locdesc
= attr
.as_block ();
19408 else if (attr
.form_is_section_offset ())
19410 dwarf2_complex_location_expr_complaint ();
19414 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19415 "partial symbol information");
19418 case DW_AT_external
:
19419 is_external
= attr
.as_boolean ();
19421 case DW_AT_declaration
:
19422 is_declaration
= attr
.as_boolean ();
19427 case DW_AT_abstract_origin
:
19428 case DW_AT_specification
:
19429 case DW_AT_extension
:
19430 has_specification
= 1;
19431 spec_offset
= attr
.get_ref_die_offset ();
19432 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19433 || cu
->per_cu
->is_dwz
);
19435 case DW_AT_sibling
:
19436 /* Ignore absolute siblings, they might point outside of
19437 the current compile unit. */
19438 if (attr
.form
== DW_FORM_ref_addr
)
19439 complaint (_("ignoring absolute DW_AT_sibling"));
19442 const gdb_byte
*buffer
= reader
->buffer
;
19443 sect_offset off
= attr
.get_ref_die_offset ();
19444 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19446 if (sibling_ptr
< info_ptr
)
19447 complaint (_("DW_AT_sibling points backwards"));
19448 else if (sibling_ptr
> reader
->buffer_end
)
19449 reader
->die_section
->overflow_complaint ();
19451 sibling
= sibling_ptr
;
19454 case DW_AT_byte_size
:
19457 case DW_AT_const_value
:
19458 has_const_value
= 1;
19460 case DW_AT_calling_convention
:
19461 /* DWARF doesn't provide a way to identify a program's source-level
19462 entry point. DW_AT_calling_convention attributes are only meant
19463 to describe functions' calling conventions.
19465 However, because it's a necessary piece of information in
19466 Fortran, and before DWARF 4 DW_CC_program was the only
19467 piece of debugging information whose definition refers to
19468 a 'main program' at all, several compilers marked Fortran
19469 main programs with DW_CC_program --- even when those
19470 functions use the standard calling conventions.
19472 Although DWARF now specifies a way to provide this
19473 information, we support this practice for backward
19475 if (attr
.constant_value (0) == DW_CC_program
19476 && cu
->per_cu
->lang
== language_fortran
)
19477 main_subprogram
= 1;
19481 LONGEST value
= attr
.constant_value (-1);
19482 if (value
== DW_INL_inlined
19483 || value
== DW_INL_declared_inlined
)
19484 may_be_inlined
= 1;
19489 if (tag
== DW_TAG_imported_unit
)
19491 d
.sect_off
= attr
.get_ref_die_offset ();
19492 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19493 || cu
->per_cu
->is_dwz
);
19497 case DW_AT_main_subprogram
:
19498 main_subprogram
= attr
.as_boolean ();
19503 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19504 on DWARF version). */
19505 ranges_offset
= attr
.as_unsigned ();
19507 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19509 if (tag
!= DW_TAG_compile_unit
)
19510 ranges_offset
+= cu
->gnu_ranges_base
;
19512 has_range_info
= 1;
19521 /* For Ada, if both the name and the linkage name appear, we prefer
19522 the latter. This lets "catch exception" work better, regardless
19523 of the order in which the name and linkage name were emitted.
19524 Really, though, this is just a workaround for the fact that gdb
19525 doesn't store both the name and the linkage name. */
19526 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
19527 raw_name
= linkage_name
;
19529 if (high_pc_relative
)
19532 if (has_low_pc_attr
&& has_high_pc_attr
)
19534 /* When using the GNU linker, .gnu.linkonce. sections are used to
19535 eliminate duplicate copies of functions and vtables and such.
19536 The linker will arbitrarily choose one and discard the others.
19537 The AT_*_pc values for such functions refer to local labels in
19538 these sections. If the section from that file was discarded, the
19539 labels are not in the output, so the relocs get a value of 0.
19540 If this is a discarded function, mark the pc bounds as invalid,
19541 so that GDB will ignore it. */
19542 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19544 struct objfile
*objfile
= per_objfile
->objfile
;
19545 struct gdbarch
*gdbarch
= objfile
->arch ();
19547 complaint (_("DW_AT_low_pc %s is zero "
19548 "for DIE at %s [in module %s]"),
19549 paddress (gdbarch
, lowpc
),
19550 sect_offset_str (sect_off
),
19551 objfile_name (objfile
));
19553 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19554 else if (lowpc
>= highpc
)
19556 struct objfile
*objfile
= per_objfile
->objfile
;
19557 struct gdbarch
*gdbarch
= objfile
->arch ();
19559 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19560 "for DIE at %s [in module %s]"),
19561 paddress (gdbarch
, lowpc
),
19562 paddress (gdbarch
, highpc
),
19563 sect_offset_str (sect_off
),
19564 objfile_name (objfile
));
19573 /* Find a cached partial DIE at OFFSET in CU. */
19575 struct partial_die_info
*
19576 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19578 struct partial_die_info
*lookup_die
= NULL
;
19579 struct partial_die_info
part_die (sect_off
);
19581 lookup_die
= ((struct partial_die_info
*)
19582 htab_find_with_hash (partial_dies
, &part_die
,
19583 to_underlying (sect_off
)));
19588 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19589 except in the case of .debug_types DIEs which do not reference
19590 outside their CU (they do however referencing other types via
19591 DW_FORM_ref_sig8). */
19593 static const struct cu_partial_die_info
19594 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19596 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19597 struct objfile
*objfile
= per_objfile
->objfile
;
19598 struct partial_die_info
*pd
= NULL
;
19600 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19601 && cu
->header
.offset_in_cu_p (sect_off
))
19603 pd
= cu
->find_partial_die (sect_off
);
19606 /* We missed recording what we needed.
19607 Load all dies and try again. */
19611 /* TUs don't reference other CUs/TUs (except via type signatures). */
19612 if (cu
->per_cu
->is_debug_types
)
19614 error (_("Dwarf Error: Type Unit at offset %s contains"
19615 " external reference to offset %s [in module %s].\n"),
19616 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19617 bfd_get_filename (objfile
->obfd
));
19619 dwarf2_per_cu_data
*per_cu
19620 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19621 per_objfile
->per_bfd
);
19623 cu
= per_objfile
->get_cu (per_cu
);
19624 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19625 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19627 cu
= per_objfile
->get_cu (per_cu
);
19630 pd
= cu
->find_partial_die (sect_off
);
19633 /* If we didn't find it, and not all dies have been loaded,
19634 load them all and try again. */
19636 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19638 cu
->load_all_dies
= 1;
19640 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19641 THIS_CU->cu may already be in use. So we can't just free it and
19642 replace its DIEs with the ones we read in. Instead, we leave those
19643 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19644 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19646 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19648 pd
= cu
->find_partial_die (sect_off
);
19652 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19653 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19657 /* See if we can figure out if the class lives in a namespace. We do
19658 this by looking for a member function; its demangled name will
19659 contain namespace info, if there is any. */
19662 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19663 struct dwarf2_cu
*cu
)
19665 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19666 what template types look like, because the demangler
19667 frequently doesn't give the same name as the debug info. We
19668 could fix this by only using the demangled name to get the
19669 prefix (but see comment in read_structure_type). */
19671 struct partial_die_info
*real_pdi
;
19672 struct partial_die_info
*child_pdi
;
19674 /* If this DIE (this DIE's specification, if any) has a parent, then
19675 we should not do this. We'll prepend the parent's fully qualified
19676 name when we create the partial symbol. */
19678 real_pdi
= struct_pdi
;
19679 while (real_pdi
->has_specification
)
19681 auto res
= find_partial_die (real_pdi
->spec_offset
,
19682 real_pdi
->spec_is_dwz
, cu
);
19683 real_pdi
= res
.pdi
;
19687 if (real_pdi
->die_parent
!= NULL
)
19690 for (child_pdi
= struct_pdi
->die_child
;
19692 child_pdi
= child_pdi
->die_sibling
)
19694 if (child_pdi
->tag
== DW_TAG_subprogram
19695 && child_pdi
->linkage_name
!= NULL
)
19697 gdb::unique_xmalloc_ptr
<char> actual_class_name
19698 (cu
->language_defn
->class_name_from_physname
19699 (child_pdi
->linkage_name
));
19700 if (actual_class_name
!= NULL
)
19702 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19703 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19704 struct_pdi
->canonical_name
= 1;
19711 /* Return true if a DIE with TAG may have the DW_AT_const_value
19715 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19719 case DW_TAG_constant
:
19720 case DW_TAG_enumerator
:
19721 case DW_TAG_formal_parameter
:
19722 case DW_TAG_template_value_param
:
19723 case DW_TAG_variable
:
19731 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19733 /* Once we've fixed up a die, there's no point in doing so again.
19734 This also avoids a memory leak if we were to call
19735 guess_partial_die_structure_name multiple times. */
19739 /* If we found a reference attribute and the DIE has no name, try
19740 to find a name in the referred to DIE. */
19742 if (raw_name
== NULL
&& has_specification
)
19744 struct partial_die_info
*spec_die
;
19746 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19747 spec_die
= res
.pdi
;
19750 spec_die
->fixup (cu
);
19752 if (spec_die
->raw_name
)
19754 raw_name
= spec_die
->raw_name
;
19755 canonical_name
= spec_die
->canonical_name
;
19757 /* Copy DW_AT_external attribute if it is set. */
19758 if (spec_die
->is_external
)
19759 is_external
= spec_die
->is_external
;
19763 if (!has_const_value
&& has_specification
19764 && can_have_DW_AT_const_value_p (tag
))
19766 struct partial_die_info
*spec_die
;
19768 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19769 spec_die
= res
.pdi
;
19772 spec_die
->fixup (cu
);
19774 if (spec_die
->has_const_value
)
19776 /* Copy DW_AT_const_value attribute if it is set. */
19777 has_const_value
= spec_die
->has_const_value
;
19781 /* Set default names for some unnamed DIEs. */
19783 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19785 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19786 canonical_name
= 1;
19789 /* If there is no parent die to provide a namespace, and there are
19790 children, see if we can determine the namespace from their linkage
19792 if (cu
->per_cu
->lang
== language_cplus
19793 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19794 && die_parent
== NULL
19796 && (tag
== DW_TAG_class_type
19797 || tag
== DW_TAG_structure_type
19798 || tag
== DW_TAG_union_type
))
19799 guess_partial_die_structure_name (this, cu
);
19801 /* GCC might emit a nameless struct or union that has a linkage
19802 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19803 if (raw_name
== NULL
19804 && (tag
== DW_TAG_class_type
19805 || tag
== DW_TAG_interface_type
19806 || tag
== DW_TAG_structure_type
19807 || tag
== DW_TAG_union_type
)
19808 && linkage_name
!= NULL
)
19810 gdb::unique_xmalloc_ptr
<char> demangled
19811 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19812 if (demangled
!= nullptr)
19816 /* Strip any leading namespaces/classes, keep only the base name.
19817 DW_AT_name for named DIEs does not contain the prefixes. */
19818 base
= strrchr (demangled
.get (), ':');
19819 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19822 base
= demangled
.get ();
19824 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19825 raw_name
= objfile
->intern (base
);
19826 canonical_name
= 1;
19833 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19834 contents from the given SECTION in the HEADER.
19836 HEADER_OFFSET is the offset of the header in the section. */
19838 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19839 struct dwarf2_section_info
*section
,
19840 sect_offset header_offset
)
19842 unsigned int bytes_read
;
19843 bfd
*abfd
= section
->get_bfd_owner ();
19844 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19846 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19847 info_ptr
+= bytes_read
;
19849 header
->version
= read_2_bytes (abfd
, info_ptr
);
19852 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19855 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19858 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19861 /* Return the DW_AT_loclists_base value for the CU. */
19863 lookup_loclist_base (struct dwarf2_cu
*cu
)
19865 /* For the .dwo unit, the loclist_base points to the first offset following
19866 the header. The header consists of the following entities-
19867 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19869 2. version (2 bytes)
19870 3. address size (1 byte)
19871 4. segment selector size (1 byte)
19872 5. offset entry count (4 bytes)
19873 These sizes are derived as per the DWARFv5 standard. */
19874 if (cu
->dwo_unit
!= nullptr)
19876 if (cu
->header
.initial_length_size
== 4)
19877 return LOCLIST_HEADER_SIZE32
;
19878 return LOCLIST_HEADER_SIZE64
;
19880 return cu
->loclist_base
;
19883 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19884 array of offsets in the .debug_loclists section. */
19887 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19889 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19890 struct objfile
*objfile
= per_objfile
->objfile
;
19891 bfd
*abfd
= objfile
->obfd
;
19892 ULONGEST loclist_header_size
=
19893 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19894 : LOCLIST_HEADER_SIZE64
);
19895 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19897 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19898 ULONGEST start_offset
=
19899 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19901 /* Get loclists section. */
19902 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19904 /* Read the loclists section content. */
19905 section
->read (objfile
);
19906 if (section
->buffer
== NULL
)
19907 error (_("DW_FORM_loclistx used without .debug_loclists "
19908 "section [in module %s]"), objfile_name (objfile
));
19910 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19911 so if loclist_base is smaller than the header size, we have a problem. */
19912 if (loclist_base
< loclist_header_size
)
19913 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19914 objfile_name (objfile
));
19916 /* Read the header of the loclists contribution. */
19917 struct loclists_rnglists_header header
;
19918 read_loclists_rnglists_header (&header
, section
,
19919 (sect_offset
) (loclist_base
- loclist_header_size
));
19921 /* Verify the loclist index is valid. */
19922 if (loclist_index
>= header
.offset_entry_count
)
19923 error (_("DW_FORM_loclistx pointing outside of "
19924 ".debug_loclists offset array [in module %s]"),
19925 objfile_name (objfile
));
19927 /* Validate that reading won't go beyond the end of the section. */
19928 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19929 error (_("Reading DW_FORM_loclistx index beyond end of"
19930 ".debug_loclists section [in module %s]"),
19931 objfile_name (objfile
));
19933 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19935 if (cu
->header
.offset_size
== 4)
19936 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19938 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19941 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19942 array of offsets in the .debug_rnglists section. */
19945 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19948 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19949 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19950 bfd
*abfd
= objfile
->obfd
;
19951 ULONGEST rnglist_header_size
=
19952 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19953 : RNGLIST_HEADER_SIZE64
);
19955 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19956 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19958 ULONGEST rnglist_base
=
19959 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19961 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19962 ULONGEST start_offset
=
19963 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19965 /* Get rnglists section. */
19966 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19968 /* Read the rnglists section content. */
19969 section
->read (objfile
);
19970 if (section
->buffer
== nullptr)
19971 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19973 objfile_name (objfile
));
19975 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19976 so if rnglist_base is smaller than the header size, we have a problem. */
19977 if (rnglist_base
< rnglist_header_size
)
19978 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19979 objfile_name (objfile
));
19981 /* Read the header of the rnglists contribution. */
19982 struct loclists_rnglists_header header
;
19983 read_loclists_rnglists_header (&header
, section
,
19984 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19986 /* Verify the rnglist index is valid. */
19987 if (rnglist_index
>= header
.offset_entry_count
)
19988 error (_("DW_FORM_rnglistx index pointing outside of "
19989 ".debug_rnglists offset array [in module %s]"),
19990 objfile_name (objfile
));
19992 /* Validate that reading won't go beyond the end of the section. */
19993 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19994 error (_("Reading DW_FORM_rnglistx index beyond end of"
19995 ".debug_rnglists section [in module %s]"),
19996 objfile_name (objfile
));
19998 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20000 if (cu
->header
.offset_size
== 4)
20001 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
20003 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
20006 /* Process the attributes that had to be skipped in the first round. These
20007 attributes are the ones that need str_offsets_base or addr_base attributes.
20008 They could not have been processed in the first round, because at the time
20009 the values of str_offsets_base or addr_base may not have been known. */
20011 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20012 struct attribute
*attr
, dwarf_tag tag
)
20014 struct dwarf2_cu
*cu
= reader
->cu
;
20015 switch (attr
->form
)
20017 case DW_FORM_addrx
:
20018 case DW_FORM_GNU_addr_index
:
20019 attr
->set_address (read_addr_index (cu
,
20020 attr
->as_unsigned_reprocess ()));
20022 case DW_FORM_loclistx
:
20024 sect_offset loclists_sect_off
20025 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20027 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20030 case DW_FORM_rnglistx
:
20032 sect_offset rnglists_sect_off
20033 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20035 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20039 case DW_FORM_strx1
:
20040 case DW_FORM_strx2
:
20041 case DW_FORM_strx3
:
20042 case DW_FORM_strx4
:
20043 case DW_FORM_GNU_str_index
:
20045 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20046 gdb_assert (!attr
->canonical_string_p ());
20047 if (reader
->dwo_file
!= NULL
)
20048 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20051 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20056 gdb_assert_not_reached ("Unexpected DWARF form.");
20060 /* Read an attribute value described by an attribute form. */
20062 static const gdb_byte
*
20063 read_attribute_value (const struct die_reader_specs
*reader
,
20064 struct attribute
*attr
, unsigned form
,
20065 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20067 struct dwarf2_cu
*cu
= reader
->cu
;
20068 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20069 struct objfile
*objfile
= per_objfile
->objfile
;
20070 bfd
*abfd
= reader
->abfd
;
20071 struct comp_unit_head
*cu_header
= &cu
->header
;
20072 unsigned int bytes_read
;
20073 struct dwarf_block
*blk
;
20075 attr
->form
= (enum dwarf_form
) form
;
20078 case DW_FORM_ref_addr
:
20079 if (cu_header
->version
== 2)
20080 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20083 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20085 info_ptr
+= bytes_read
;
20087 case DW_FORM_GNU_ref_alt
:
20088 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20090 info_ptr
+= bytes_read
;
20094 struct gdbarch
*gdbarch
= objfile
->arch ();
20095 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20096 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20097 attr
->set_address (addr
);
20098 info_ptr
+= bytes_read
;
20101 case DW_FORM_block2
:
20102 blk
= dwarf_alloc_block (cu
);
20103 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20105 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20106 info_ptr
+= blk
->size
;
20107 attr
->set_block (blk
);
20109 case DW_FORM_block4
:
20110 blk
= dwarf_alloc_block (cu
);
20111 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20113 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20114 info_ptr
+= blk
->size
;
20115 attr
->set_block (blk
);
20117 case DW_FORM_data2
:
20118 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20121 case DW_FORM_data4
:
20122 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20125 case DW_FORM_data8
:
20126 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20129 case DW_FORM_data16
:
20130 blk
= dwarf_alloc_block (cu
);
20132 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20134 attr
->set_block (blk
);
20136 case DW_FORM_sec_offset
:
20137 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20139 info_ptr
+= bytes_read
;
20141 case DW_FORM_loclistx
:
20143 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20145 info_ptr
+= bytes_read
;
20148 case DW_FORM_string
:
20149 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20151 info_ptr
+= bytes_read
;
20154 if (!cu
->per_cu
->is_dwz
)
20156 attr
->set_string_noncanonical
20157 (read_indirect_string (per_objfile
,
20158 abfd
, info_ptr
, cu_header
,
20160 info_ptr
+= bytes_read
;
20164 case DW_FORM_line_strp
:
20165 if (!cu
->per_cu
->is_dwz
)
20167 attr
->set_string_noncanonical
20168 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20170 info_ptr
+= bytes_read
;
20174 case DW_FORM_GNU_strp_alt
:
20176 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20177 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20180 attr
->set_string_noncanonical
20181 (dwz
->read_string (objfile
, str_offset
));
20182 info_ptr
+= bytes_read
;
20185 case DW_FORM_exprloc
:
20186 case DW_FORM_block
:
20187 blk
= dwarf_alloc_block (cu
);
20188 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20189 info_ptr
+= bytes_read
;
20190 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20191 info_ptr
+= blk
->size
;
20192 attr
->set_block (blk
);
20194 case DW_FORM_block1
:
20195 blk
= dwarf_alloc_block (cu
);
20196 blk
->size
= read_1_byte (abfd
, info_ptr
);
20198 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20199 info_ptr
+= blk
->size
;
20200 attr
->set_block (blk
);
20202 case DW_FORM_data1
:
20204 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20207 case DW_FORM_flag_present
:
20208 attr
->set_unsigned (1);
20210 case DW_FORM_sdata
:
20211 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20212 info_ptr
+= bytes_read
;
20214 case DW_FORM_rnglistx
:
20216 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20218 info_ptr
+= bytes_read
;
20221 case DW_FORM_udata
:
20222 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20223 info_ptr
+= bytes_read
;
20226 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20227 + read_1_byte (abfd
, info_ptr
)));
20231 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20232 + read_2_bytes (abfd
, info_ptr
)));
20236 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20237 + read_4_bytes (abfd
, info_ptr
)));
20241 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20242 + read_8_bytes (abfd
, info_ptr
)));
20245 case DW_FORM_ref_sig8
:
20246 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20249 case DW_FORM_ref_udata
:
20250 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20251 + read_unsigned_leb128 (abfd
, info_ptr
,
20253 info_ptr
+= bytes_read
;
20255 case DW_FORM_indirect
:
20256 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20257 info_ptr
+= bytes_read
;
20258 if (form
== DW_FORM_implicit_const
)
20260 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20261 info_ptr
+= bytes_read
;
20263 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20266 case DW_FORM_implicit_const
:
20267 attr
->set_signed (implicit_const
);
20269 case DW_FORM_addrx
:
20270 case DW_FORM_GNU_addr_index
:
20271 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20273 info_ptr
+= bytes_read
;
20276 case DW_FORM_strx1
:
20277 case DW_FORM_strx2
:
20278 case DW_FORM_strx3
:
20279 case DW_FORM_strx4
:
20280 case DW_FORM_GNU_str_index
:
20282 ULONGEST str_index
;
20283 if (form
== DW_FORM_strx1
)
20285 str_index
= read_1_byte (abfd
, info_ptr
);
20288 else if (form
== DW_FORM_strx2
)
20290 str_index
= read_2_bytes (abfd
, info_ptr
);
20293 else if (form
== DW_FORM_strx3
)
20295 str_index
= read_3_bytes (abfd
, info_ptr
);
20298 else if (form
== DW_FORM_strx4
)
20300 str_index
= read_4_bytes (abfd
, info_ptr
);
20305 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20306 info_ptr
+= bytes_read
;
20308 attr
->set_unsigned_reprocess (str_index
);
20312 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20313 dwarf_form_name (form
),
20314 bfd_get_filename (abfd
));
20318 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20319 attr
->form
= DW_FORM_GNU_ref_alt
;
20321 /* We have seen instances where the compiler tried to emit a byte
20322 size attribute of -1 which ended up being encoded as an unsigned
20323 0xffffffff. Although 0xffffffff is technically a valid size value,
20324 an object of this size seems pretty unlikely so we can relatively
20325 safely treat these cases as if the size attribute was invalid and
20326 treat them as zero by default. */
20327 if (attr
->name
== DW_AT_byte_size
20328 && form
== DW_FORM_data4
20329 && attr
->as_unsigned () >= 0xffffffff)
20332 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20333 hex_string (attr
->as_unsigned ()));
20334 attr
->set_unsigned (0);
20340 /* Read an attribute described by an abbreviated attribute. */
20342 static const gdb_byte
*
20343 read_attribute (const struct die_reader_specs
*reader
,
20344 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20345 const gdb_byte
*info_ptr
)
20347 attr
->name
= abbrev
->name
;
20348 attr
->string_is_canonical
= 0;
20349 attr
->requires_reprocessing
= 0;
20350 return read_attribute_value (reader
, attr
, abbrev
->form
,
20351 abbrev
->implicit_const
, info_ptr
);
20354 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20356 static const char *
20357 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20358 LONGEST str_offset
)
20360 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20361 str_offset
, "DW_FORM_strp");
20364 /* Return pointer to string at .debug_str offset as read from BUF.
20365 BUF is assumed to be in a compilation unit described by CU_HEADER.
20366 Return *BYTES_READ_PTR count of bytes read from BUF. */
20368 static const char *
20369 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20370 const gdb_byte
*buf
,
20371 const struct comp_unit_head
*cu_header
,
20372 unsigned int *bytes_read_ptr
)
20374 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20376 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20382 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20383 unsigned int offset_size
)
20385 bfd
*abfd
= objfile
->obfd
;
20386 ULONGEST str_offset
= read_offset (abfd
, buf
, offset_size
);
20388 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20394 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20395 const struct comp_unit_head
*cu_header
,
20396 unsigned int *bytes_read_ptr
)
20398 bfd
*abfd
= objfile
->obfd
;
20399 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20401 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20404 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20405 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20406 ADDR_SIZE is the size of addresses from the CU header. */
20409 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20410 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20412 struct objfile
*objfile
= per_objfile
->objfile
;
20413 bfd
*abfd
= objfile
->obfd
;
20414 const gdb_byte
*info_ptr
;
20415 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20417 per_objfile
->per_bfd
->addr
.read (objfile
);
20418 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20419 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20420 objfile_name (objfile
));
20421 if (addr_base_or_zero
+ addr_index
* addr_size
20422 >= per_objfile
->per_bfd
->addr
.size
)
20423 error (_("DW_FORM_addr_index pointing outside of "
20424 ".debug_addr section [in module %s]"),
20425 objfile_name (objfile
));
20426 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20427 + addr_index
* addr_size
);
20428 if (addr_size
== 4)
20429 return bfd_get_32 (abfd
, info_ptr
);
20431 return bfd_get_64 (abfd
, info_ptr
);
20434 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20437 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20439 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20440 cu
->addr_base
, cu
->header
.addr_size
);
20443 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20446 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20447 unsigned int *bytes_read
)
20449 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20450 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20452 return read_addr_index (cu
, addr_index
);
20458 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20459 dwarf2_per_objfile
*per_objfile
,
20460 unsigned int addr_index
)
20462 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20463 gdb::optional
<ULONGEST
> addr_base
;
20466 /* We need addr_base and addr_size.
20467 If we don't have PER_CU->cu, we have to get it.
20468 Nasty, but the alternative is storing the needed info in PER_CU,
20469 which at this point doesn't seem justified: it's not clear how frequently
20470 it would get used and it would increase the size of every PER_CU.
20471 Entry points like dwarf2_per_cu_addr_size do a similar thing
20472 so we're not in uncharted territory here.
20473 Alas we need to be a bit more complicated as addr_base is contained
20476 We don't need to read the entire CU(/TU).
20477 We just need the header and top level die.
20479 IWBN to use the aging mechanism to let us lazily later discard the CU.
20480 For now we skip this optimization. */
20484 addr_base
= cu
->addr_base
;
20485 addr_size
= cu
->header
.addr_size
;
20489 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20490 addr_base
= reader
.cu
->addr_base
;
20491 addr_size
= reader
.cu
->header
.addr_size
;
20494 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20497 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20498 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20501 static const char *
20502 read_str_index (struct dwarf2_cu
*cu
,
20503 struct dwarf2_section_info
*str_section
,
20504 struct dwarf2_section_info
*str_offsets_section
,
20505 ULONGEST str_offsets_base
, ULONGEST str_index
)
20507 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20508 struct objfile
*objfile
= per_objfile
->objfile
;
20509 const char *objf_name
= objfile_name (objfile
);
20510 bfd
*abfd
= objfile
->obfd
;
20511 const gdb_byte
*info_ptr
;
20512 ULONGEST str_offset
;
20513 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20515 str_section
->read (objfile
);
20516 str_offsets_section
->read (objfile
);
20517 if (str_section
->buffer
== NULL
)
20518 error (_("%s used without %s section"
20519 " in CU at offset %s [in module %s]"),
20520 form_name
, str_section
->get_name (),
20521 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20522 if (str_offsets_section
->buffer
== NULL
)
20523 error (_("%s used without %s section"
20524 " in CU at offset %s [in module %s]"),
20525 form_name
, str_section
->get_name (),
20526 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20527 info_ptr
= (str_offsets_section
->buffer
20529 + str_index
* cu
->header
.offset_size
);
20530 if (cu
->header
.offset_size
== 4)
20531 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20533 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20534 if (str_offset
>= str_section
->size
)
20535 error (_("Offset from %s pointing outside of"
20536 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20537 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20538 return (const char *) (str_section
->buffer
+ str_offset
);
20541 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20543 static const char *
20544 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20546 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20547 ? reader
->cu
->header
.addr_size
: 0;
20548 return read_str_index (reader
->cu
,
20549 &reader
->dwo_file
->sections
.str
,
20550 &reader
->dwo_file
->sections
.str_offsets
,
20551 str_offsets_base
, str_index
);
20554 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20556 static const char *
20557 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20559 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20560 const char *objf_name
= objfile_name (objfile
);
20561 static const char form_name
[] = "DW_FORM_GNU_str_index";
20562 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20564 if (!cu
->str_offsets_base
.has_value ())
20565 error (_("%s used in Fission stub without %s"
20566 " in CU at offset 0x%lx [in module %s]"),
20567 form_name
, str_offsets_attr_name
,
20568 (long) cu
->header
.offset_size
, objf_name
);
20570 return read_str_index (cu
,
20571 &cu
->per_objfile
->per_bfd
->str
,
20572 &cu
->per_objfile
->per_bfd
->str_offsets
,
20573 *cu
->str_offsets_base
, str_index
);
20576 /* Return the length of an LEB128 number in BUF. */
20579 leb128_size (const gdb_byte
*buf
)
20581 const gdb_byte
*begin
= buf
;
20587 if ((byte
& 128) == 0)
20588 return buf
- begin
;
20592 static enum language
20593 dwarf_lang_to_enum_language (unsigned int lang
)
20595 enum language language
;
20604 language
= language_c
;
20607 case DW_LANG_C_plus_plus
:
20608 case DW_LANG_C_plus_plus_11
:
20609 case DW_LANG_C_plus_plus_14
:
20610 language
= language_cplus
;
20613 language
= language_d
;
20615 case DW_LANG_Fortran77
:
20616 case DW_LANG_Fortran90
:
20617 case DW_LANG_Fortran95
:
20618 case DW_LANG_Fortran03
:
20619 case DW_LANG_Fortran08
:
20620 language
= language_fortran
;
20623 language
= language_go
;
20625 case DW_LANG_Mips_Assembler
:
20626 language
= language_asm
;
20628 case DW_LANG_Ada83
:
20629 case DW_LANG_Ada95
:
20630 language
= language_ada
;
20632 case DW_LANG_Modula2
:
20633 language
= language_m2
;
20635 case DW_LANG_Pascal83
:
20636 language
= language_pascal
;
20639 language
= language_objc
;
20642 case DW_LANG_Rust_old
:
20643 language
= language_rust
;
20645 case DW_LANG_OpenCL
:
20646 language
= language_opencl
;
20648 case DW_LANG_Cobol74
:
20649 case DW_LANG_Cobol85
:
20651 language
= language_minimal
;
20658 /* Return the named attribute or NULL if not there. */
20660 static struct attribute
*
20661 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20666 struct attribute
*spec
= NULL
;
20668 for (i
= 0; i
< die
->num_attrs
; ++i
)
20670 if (die
->attrs
[i
].name
== name
)
20671 return &die
->attrs
[i
];
20672 if (die
->attrs
[i
].name
== DW_AT_specification
20673 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20674 spec
= &die
->attrs
[i
];
20680 die
= follow_die_ref (die
, spec
, &cu
);
20686 /* Return the string associated with a string-typed attribute, or NULL if it
20687 is either not found or is of an incorrect type. */
20689 static const char *
20690 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20692 struct attribute
*attr
;
20693 const char *str
= NULL
;
20695 attr
= dwarf2_attr (die
, name
, cu
);
20699 str
= attr
->as_string ();
20700 if (str
== nullptr)
20701 complaint (_("string type expected for attribute %s for "
20702 "DIE at %s in module %s"),
20703 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20704 objfile_name (cu
->per_objfile
->objfile
));
20710 /* Return the dwo name or NULL if not present. If present, it is in either
20711 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20712 static const char *
20713 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20715 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20716 if (dwo_name
== nullptr)
20717 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20721 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20722 and holds a non-zero value. This function should only be used for
20723 DW_FORM_flag or DW_FORM_flag_present attributes. */
20726 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20728 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20730 return attr
!= nullptr && attr
->as_boolean ();
20734 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20736 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20737 which value is non-zero. However, we have to be careful with
20738 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20739 (via dwarf2_flag_true_p) follows this attribute. So we may
20740 end up accidently finding a declaration attribute that belongs
20741 to a different DIE referenced by the specification attribute,
20742 even though the given DIE does not have a declaration attribute. */
20743 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20744 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20747 /* Return the die giving the specification for DIE, if there is
20748 one. *SPEC_CU is the CU containing DIE on input, and the CU
20749 containing the return value on output. If there is no
20750 specification, but there is an abstract origin, that is
20753 static struct die_info
*
20754 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20756 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20759 if (spec_attr
== NULL
)
20760 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20762 if (spec_attr
== NULL
)
20765 return follow_die_ref (die
, spec_attr
, spec_cu
);
20768 /* A convenience function to find the proper .debug_line section for a CU. */
20770 static struct dwarf2_section_info
*
20771 get_debug_line_section (struct dwarf2_cu
*cu
)
20773 struct dwarf2_section_info
*section
;
20774 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20776 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20778 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20779 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20780 else if (cu
->per_cu
->is_dwz
)
20782 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20784 section
= &dwz
->line
;
20787 section
= &per_objfile
->per_bfd
->line
;
20792 /* Read the statement program header starting at OFFSET in
20793 .debug_line, or .debug_line.dwo. Return a pointer
20794 to a struct line_header, allocated using xmalloc.
20795 Returns NULL if there is a problem reading the header, e.g., if it
20796 has a version we don't understand.
20798 NOTE: the strings in the include directory and file name tables of
20799 the returned object point into the dwarf line section buffer,
20800 and must not be freed. */
20802 static line_header_up
20803 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20805 struct dwarf2_section_info
*section
;
20806 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20808 section
= get_debug_line_section (cu
);
20809 section
->read (per_objfile
->objfile
);
20810 if (section
->buffer
== NULL
)
20812 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20813 complaint (_("missing .debug_line.dwo section"));
20815 complaint (_("missing .debug_line section"));
20819 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20820 per_objfile
, section
, &cu
->header
);
20823 /* Subroutine of dwarf_decode_lines to simplify it.
20824 Return the file name for the given file_entry.
20825 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
20826 If space for the result is malloc'd, *NAME_HOLDER will be set.
20827 Returns NULL if FILE_INDEX should be ignored, i.e., it is
20828 equivalent to CU_INFO. */
20830 static const char *
20831 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20832 const file_and_directory
&cu_info
,
20833 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20835 const char *include_name
= fe
.name
;
20836 const char *include_name_to_compare
= include_name
;
20838 const char *dir_name
= fe
.include_dir (lh
);
20840 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20841 if (!IS_ABSOLUTE_PATH (include_name
)
20842 && (dir_name
!= nullptr || cu_info
.get_comp_dir () != nullptr))
20844 /* Avoid creating a duplicate name for CU_INFO.
20845 We do this by comparing INCLUDE_NAME and CU_INFO.
20846 Before we do the comparison, however, we need to account
20847 for DIR_NAME and COMP_DIR.
20848 First prepend dir_name (if non-NULL). If we still don't
20849 have an absolute path prepend comp_dir (if non-NULL).
20850 However, the directory we record in the include-file's
20851 psymtab does not contain COMP_DIR (to match the
20852 corresponding symtab(s)).
20857 bash$ gcc -g ./hello.c
20858 include_name = "hello.c"
20860 DW_AT_comp_dir = comp_dir = "/tmp"
20861 DW_AT_name = "./hello.c"
20865 if (dir_name
!= NULL
)
20867 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20868 include_name
, (char *) NULL
));
20869 include_name
= name_holder
->get ();
20870 include_name_to_compare
= include_name
;
20872 if (!IS_ABSOLUTE_PATH (include_name
)
20873 && cu_info
.get_comp_dir () != nullptr)
20875 hold_compare
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
20876 include_name
, (char *) NULL
));
20877 include_name_to_compare
= hold_compare
.get ();
20881 gdb::unique_xmalloc_ptr
<char> copied_name
;
20882 const char *cu_filename
= cu_info
.get_name ();
20883 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.get_comp_dir () != nullptr)
20885 copied_name
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
20886 cu_filename
, (char *) NULL
));
20887 cu_filename
= copied_name
.get ();
20890 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
20892 return include_name
;
20895 /* State machine to track the state of the line number program. */
20897 class lnp_state_machine
20900 /* Initialize a machine state for the start of a line number
20902 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20903 bool record_lines_p
);
20905 file_entry
*current_file ()
20907 /* lh->file_names is 0-based, but the file name numbers in the
20908 statement program are 1-based. */
20909 return m_line_header
->file_name_at (m_file
);
20912 /* Record the line in the state machine. END_SEQUENCE is true if
20913 we're processing the end of a sequence. */
20914 void record_line (bool end_sequence
);
20916 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20917 nop-out rest of the lines in this sequence. */
20918 void check_line_address (struct dwarf2_cu
*cu
,
20919 const gdb_byte
*line_ptr
,
20920 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20922 void handle_set_discriminator (unsigned int discriminator
)
20924 m_discriminator
= discriminator
;
20925 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20928 /* Handle DW_LNE_set_address. */
20929 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20932 address
+= baseaddr
;
20933 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20936 /* Handle DW_LNS_advance_pc. */
20937 void handle_advance_pc (CORE_ADDR adjust
);
20939 /* Handle a special opcode. */
20940 void handle_special_opcode (unsigned char op_code
);
20942 /* Handle DW_LNS_advance_line. */
20943 void handle_advance_line (int line_delta
)
20945 advance_line (line_delta
);
20948 /* Handle DW_LNS_set_file. */
20949 void handle_set_file (file_name_index file
);
20951 /* Handle DW_LNS_negate_stmt. */
20952 void handle_negate_stmt ()
20954 m_flags
^= LEF_IS_STMT
;
20957 /* Handle DW_LNS_const_add_pc. */
20958 void handle_const_add_pc ();
20960 /* Handle DW_LNS_fixed_advance_pc. */
20961 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20963 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20967 /* Handle DW_LNS_copy. */
20968 void handle_copy ()
20970 record_line (false);
20971 m_discriminator
= 0;
20972 m_flags
&= ~LEF_PROLOGUE_END
;
20975 /* Handle DW_LNE_end_sequence. */
20976 void handle_end_sequence ()
20978 m_currently_recording_lines
= true;
20981 /* Handle DW_LNS_set_prologue_end. */
20982 void handle_set_prologue_end ()
20984 m_flags
|= LEF_PROLOGUE_END
;
20988 /* Advance the line by LINE_DELTA. */
20989 void advance_line (int line_delta
)
20991 m_line
+= line_delta
;
20993 if (line_delta
!= 0)
20994 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20997 struct dwarf2_cu
*m_cu
;
20999 gdbarch
*m_gdbarch
;
21001 /* True if we're recording lines.
21002 Otherwise we're building partial symtabs and are just interested in
21003 finding include files mentioned by the line number program. */
21004 bool m_record_lines_p
;
21006 /* The line number header. */
21007 line_header
*m_line_header
;
21009 /* These are part of the standard DWARF line number state machine,
21010 and initialized according to the DWARF spec. */
21012 unsigned char m_op_index
= 0;
21013 /* The line table index of the current file. */
21014 file_name_index m_file
= 1;
21015 unsigned int m_line
= 1;
21017 /* These are initialized in the constructor. */
21019 CORE_ADDR m_address
;
21020 linetable_entry_flags m_flags
;
21021 unsigned int m_discriminator
;
21023 /* Additional bits of state we need to track. */
21025 /* The last file that we called dwarf2_start_subfile for.
21026 This is only used for TLLs. */
21027 unsigned int m_last_file
= 0;
21028 /* The last file a line number was recorded for. */
21029 struct subfile
*m_last_subfile
= NULL
;
21031 /* The address of the last line entry. */
21032 CORE_ADDR m_last_address
;
21034 /* Set to true when a previous line at the same address (using
21035 m_last_address) had LEF_IS_STMT set in m_flags. This is reset to false
21036 when a line entry at a new address (m_address different to
21037 m_last_address) is processed. */
21038 bool m_stmt_at_address
= false;
21040 /* When true, record the lines we decode. */
21041 bool m_currently_recording_lines
= false;
21043 /* The last line number that was recorded, used to coalesce
21044 consecutive entries for the same line. This can happen, for
21045 example, when discriminators are present. PR 17276. */
21046 unsigned int m_last_line
= 0;
21047 bool m_line_has_non_zero_discriminator
= false;
21051 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21053 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21054 / m_line_header
->maximum_ops_per_instruction
)
21055 * m_line_header
->minimum_instruction_length
);
21056 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21057 m_op_index
= ((m_op_index
+ adjust
)
21058 % m_line_header
->maximum_ops_per_instruction
);
21062 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21064 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21065 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21066 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21067 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21068 / m_line_header
->maximum_ops_per_instruction
)
21069 * m_line_header
->minimum_instruction_length
);
21070 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21071 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21072 % m_line_header
->maximum_ops_per_instruction
);
21074 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21075 advance_line (line_delta
);
21076 record_line (false);
21077 m_discriminator
= 0;
21078 m_flags
&= ~LEF_PROLOGUE_END
;
21082 lnp_state_machine::handle_set_file (file_name_index file
)
21086 const file_entry
*fe
= current_file ();
21088 dwarf2_debug_line_missing_file_complaint ();
21089 else if (m_record_lines_p
)
21091 const char *dir
= fe
->include_dir (m_line_header
);
21093 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21094 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21095 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21100 lnp_state_machine::handle_const_add_pc ()
21103 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21106 = (((m_op_index
+ adjust
)
21107 / m_line_header
->maximum_ops_per_instruction
)
21108 * m_line_header
->minimum_instruction_length
);
21110 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21111 m_op_index
= ((m_op_index
+ adjust
)
21112 % m_line_header
->maximum_ops_per_instruction
);
21115 /* Return non-zero if we should add LINE to the line number table.
21116 LINE is the line to add, LAST_LINE is the last line that was added,
21117 LAST_SUBFILE is the subfile for LAST_LINE.
21118 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21119 had a non-zero discriminator.
21121 We have to be careful in the presence of discriminators.
21122 E.g., for this line:
21124 for (i = 0; i < 100000; i++);
21126 clang can emit four line number entries for that one line,
21127 each with a different discriminator.
21128 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21130 However, we want gdb to coalesce all four entries into one.
21131 Otherwise the user could stepi into the middle of the line and
21132 gdb would get confused about whether the pc really was in the
21133 middle of the line.
21135 Things are further complicated by the fact that two consecutive
21136 line number entries for the same line is a heuristic used by gcc
21137 to denote the end of the prologue. So we can't just discard duplicate
21138 entries, we have to be selective about it. The heuristic we use is
21139 that we only collapse consecutive entries for the same line if at least
21140 one of those entries has a non-zero discriminator. PR 17276.
21142 Note: Addresses in the line number state machine can never go backwards
21143 within one sequence, thus this coalescing is ok. */
21146 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21147 unsigned int line
, unsigned int last_line
,
21148 int line_has_non_zero_discriminator
,
21149 struct subfile
*last_subfile
)
21151 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21153 if (line
!= last_line
)
21155 /* Same line for the same file that we've seen already.
21156 As a last check, for pr 17276, only record the line if the line
21157 has never had a non-zero discriminator. */
21158 if (!line_has_non_zero_discriminator
)
21163 /* Use the CU's builder to record line number LINE beginning at
21164 address ADDRESS in the line table of subfile SUBFILE. */
21167 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21168 unsigned int line
, CORE_ADDR address
,
21169 linetable_entry_flags flags
,
21170 struct dwarf2_cu
*cu
)
21172 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21174 if (dwarf_line_debug
)
21176 gdb_printf (gdb_stdlog
,
21177 "Recording line %u, file %s, address %s\n",
21178 line
, lbasename (subfile
->name
),
21179 paddress (gdbarch
, address
));
21183 cu
->get_builder ()->record_line (subfile
, line
, addr
, flags
);
21186 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21187 Mark the end of a set of line number records.
21188 The arguments are the same as for dwarf_record_line_1.
21189 If SUBFILE is NULL the request is ignored. */
21192 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21193 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21195 if (subfile
== NULL
)
21198 if (dwarf_line_debug
)
21200 gdb_printf (gdb_stdlog
,
21201 "Finishing current line, file %s, address %s\n",
21202 lbasename (subfile
->name
),
21203 paddress (gdbarch
, address
));
21206 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, LEF_IS_STMT
, cu
);
21210 lnp_state_machine::record_line (bool end_sequence
)
21212 if (dwarf_line_debug
)
21214 gdb_printf (gdb_stdlog
,
21215 "Processing actual line %u: file %u,"
21216 " address %s, is_stmt %u, prologue_end %u, discrim %u%s\n",
21218 paddress (m_gdbarch
, m_address
),
21219 (m_flags
& LEF_IS_STMT
) != 0,
21220 (m_flags
& LEF_PROLOGUE_END
) != 0,
21222 (end_sequence
? "\t(end sequence)" : ""));
21225 file_entry
*fe
= current_file ();
21228 dwarf2_debug_line_missing_file_complaint ();
21229 /* For now we ignore lines not starting on an instruction boundary.
21230 But not when processing end_sequence for compatibility with the
21231 previous version of the code. */
21232 else if (m_op_index
== 0 || end_sequence
)
21234 fe
->included_p
= true;
21235 if (m_record_lines_p
)
21237 /* When we switch files we insert an end maker in the first file,
21238 switch to the second file and add a new line entry. The
21239 problem is that the end marker inserted in the first file will
21240 discard any previous line entries at the same address. If the
21241 line entries in the first file are marked as is-stmt, while
21242 the new line in the second file is non-stmt, then this means
21243 the end marker will discard is-stmt lines so we can have a
21244 non-stmt line. This means that there are less addresses at
21245 which the user can insert a breakpoint.
21247 To improve this we track the last address in m_last_address,
21248 and whether we have seen an is-stmt at this address. Then
21249 when switching files, if we have seen a stmt at the current
21250 address, and we are switching to create a non-stmt line, then
21251 discard the new line. */
21253 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21254 bool ignore_this_line
21255 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21256 && ((m_flags
& LEF_IS_STMT
) == 0)
21257 && m_stmt_at_address
)
21258 || (!end_sequence
&& m_line
== 0));
21260 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21262 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21263 m_currently_recording_lines
? m_cu
: nullptr);
21266 if (!end_sequence
&& !ignore_this_line
)
21268 linetable_entry_flags lte_flags
= m_flags
;
21269 if (producer_is_codewarrior (m_cu
))
21270 lte_flags
|= LEF_IS_STMT
;
21272 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21273 m_line_has_non_zero_discriminator
,
21276 buildsym_compunit
*builder
= m_cu
->get_builder ();
21277 dwarf_record_line_1 (m_gdbarch
,
21278 builder
->get_current_subfile (),
21279 m_line
, m_address
, lte_flags
,
21280 m_currently_recording_lines
? m_cu
: nullptr);
21282 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21283 m_last_line
= m_line
;
21288 /* Track whether we have seen any IS_STMT true at m_address in case we
21289 have multiple line table entries all at m_address. */
21290 if (m_last_address
!= m_address
)
21292 m_stmt_at_address
= false;
21293 m_last_address
= m_address
;
21295 m_stmt_at_address
|= (m_flags
& LEF_IS_STMT
) != 0;
21298 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21299 line_header
*lh
, bool record_lines_p
)
21303 m_record_lines_p
= record_lines_p
;
21304 m_line_header
= lh
;
21306 m_currently_recording_lines
= true;
21308 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21309 was a line entry for it so that the backend has a chance to adjust it
21310 and also record it in case it needs it. This is currently used by MIPS
21311 code, cf. `mips_adjust_dwarf2_line'. */
21312 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21314 if (lh
->default_is_stmt
)
21315 m_flags
|= LEF_IS_STMT
;
21316 m_discriminator
= 0;
21318 m_last_address
= m_address
;
21319 m_stmt_at_address
= false;
21323 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21324 const gdb_byte
*line_ptr
,
21325 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21327 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21328 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21329 located at 0x0. In this case, additionally check that if
21330 ADDRESS < UNRELOCATED_LOWPC. */
21332 if ((address
== 0 && address
< unrelocated_lowpc
)
21333 || address
== (CORE_ADDR
) -1)
21335 /* This line table is for a function which has been
21336 GCd by the linker. Ignore it. PR gdb/12528 */
21338 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21339 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21341 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21342 line_offset
, objfile_name (objfile
));
21343 m_currently_recording_lines
= false;
21344 /* Note: m_currently_recording_lines is left as false until we see
21345 DW_LNE_end_sequence. */
21349 /* Subroutine of dwarf_decode_lines to simplify it.
21350 Process the line number information in LH.
21351 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21352 program in order to set included_p for every referenced header. */
21355 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21356 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21358 const gdb_byte
*line_ptr
, *extended_end
;
21359 const gdb_byte
*line_end
;
21360 unsigned int bytes_read
, extended_len
;
21361 unsigned char op_code
, extended_op
;
21362 CORE_ADDR baseaddr
;
21363 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21364 bfd
*abfd
= objfile
->obfd
;
21365 struct gdbarch
*gdbarch
= objfile
->arch ();
21366 /* True if we're recording line info (as opposed to building partial
21367 symtabs and just interested in finding include files mentioned by
21368 the line number program). */
21369 bool record_lines_p
= !decode_for_pst_p
;
21371 baseaddr
= objfile
->text_section_offset ();
21373 line_ptr
= lh
->statement_program_start
;
21374 line_end
= lh
->statement_program_end
;
21376 /* Read the statement sequences until there's nothing left. */
21377 while (line_ptr
< line_end
)
21379 /* The DWARF line number program state machine. Reset the state
21380 machine at the start of each sequence. */
21381 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21382 bool end_sequence
= false;
21384 if (record_lines_p
)
21386 /* Start a subfile for the current file of the state
21388 const file_entry
*fe
= state_machine
.current_file ();
21391 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21394 /* Decode the table. */
21395 while (line_ptr
< line_end
&& !end_sequence
)
21397 op_code
= read_1_byte (abfd
, line_ptr
);
21400 if (op_code
>= lh
->opcode_base
)
21402 /* Special opcode. */
21403 state_machine
.handle_special_opcode (op_code
);
21405 else switch (op_code
)
21407 case DW_LNS_extended_op
:
21408 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21410 line_ptr
+= bytes_read
;
21411 extended_end
= line_ptr
+ extended_len
;
21412 extended_op
= read_1_byte (abfd
, line_ptr
);
21414 if (DW_LNE_lo_user
<= extended_op
21415 && extended_op
<= DW_LNE_hi_user
)
21417 /* Vendor extension, ignore. */
21418 line_ptr
= extended_end
;
21421 switch (extended_op
)
21423 case DW_LNE_end_sequence
:
21424 state_machine
.handle_end_sequence ();
21425 end_sequence
= true;
21427 case DW_LNE_set_address
:
21430 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21431 line_ptr
+= bytes_read
;
21433 state_machine
.check_line_address (cu
, line_ptr
,
21434 lowpc
- baseaddr
, address
);
21435 state_machine
.handle_set_address (baseaddr
, address
);
21438 case DW_LNE_define_file
:
21440 const char *cur_file
;
21441 unsigned int mod_time
, length
;
21444 cur_file
= read_direct_string (abfd
, line_ptr
,
21446 line_ptr
+= bytes_read
;
21447 dindex
= (dir_index
)
21448 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21449 line_ptr
+= bytes_read
;
21451 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21452 line_ptr
+= bytes_read
;
21454 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21455 line_ptr
+= bytes_read
;
21456 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21459 case DW_LNE_set_discriminator
:
21461 /* The discriminator is not interesting to the
21462 debugger; just ignore it. We still need to
21463 check its value though:
21464 if there are consecutive entries for the same
21465 (non-prologue) line we want to coalesce them.
21468 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21469 line_ptr
+= bytes_read
;
21471 state_machine
.handle_set_discriminator (discr
);
21475 complaint (_("mangled .debug_line section"));
21478 /* Make sure that we parsed the extended op correctly. If e.g.
21479 we expected a different address size than the producer used,
21480 we may have read the wrong number of bytes. */
21481 if (line_ptr
!= extended_end
)
21483 complaint (_("mangled .debug_line section"));
21488 state_machine
.handle_copy ();
21490 case DW_LNS_advance_pc
:
21493 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21494 line_ptr
+= bytes_read
;
21496 state_machine
.handle_advance_pc (adjust
);
21499 case DW_LNS_advance_line
:
21502 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21503 line_ptr
+= bytes_read
;
21505 state_machine
.handle_advance_line (line_delta
);
21508 case DW_LNS_set_file
:
21510 file_name_index file
21511 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21513 line_ptr
+= bytes_read
;
21515 state_machine
.handle_set_file (file
);
21518 case DW_LNS_set_column
:
21519 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21520 line_ptr
+= bytes_read
;
21522 case DW_LNS_negate_stmt
:
21523 state_machine
.handle_negate_stmt ();
21525 case DW_LNS_set_basic_block
:
21527 /* Add to the address register of the state machine the
21528 address increment value corresponding to special opcode
21529 255. I.e., this value is scaled by the minimum
21530 instruction length since special opcode 255 would have
21531 scaled the increment. */
21532 case DW_LNS_const_add_pc
:
21533 state_machine
.handle_const_add_pc ();
21535 case DW_LNS_fixed_advance_pc
:
21537 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21540 state_machine
.handle_fixed_advance_pc (addr_adj
);
21543 case DW_LNS_set_prologue_end
:
21544 state_machine
.handle_set_prologue_end ();
21548 /* Unknown standard opcode, ignore it. */
21551 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21553 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21554 line_ptr
+= bytes_read
;
21561 dwarf2_debug_line_missing_end_sequence_complaint ();
21563 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21564 in which case we still finish recording the last line). */
21565 state_machine
.record_line (true);
21569 /* Decode the Line Number Program (LNP) for the given line_header
21570 structure and CU. The actual information extracted and the type
21571 of structures created from the LNP depends on the value of PST.
21573 1. If PST is NULL, then this procedure uses the data from the program
21574 to create all necessary symbol tables, and their linetables.
21576 2. If PST is not NULL, this procedure reads the program to determine
21577 the list of files included by the unit represented by PST, and
21578 builds all the associated partial symbol tables.
21580 FND holds the CU file name and directory, if known.
21581 It is used for relative paths in the line table.
21583 NOTE: It is important that psymtabs have the same file name (via
21584 strcmp) as the corresponding symtab. Since the directory is not
21585 used in the name of the symtab we don't use it in the name of the
21586 psymtabs we create. E.g. expand_line_sal requires this when
21587 finding psymtabs to expand. A good testcase for this is
21590 LOWPC is the lowest address in CU (or 0 if not known).
21592 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21593 for its PC<->lines mapping information. Otherwise only the filename
21594 table is read in. */
21597 dwarf_decode_lines (struct line_header
*lh
, const file_and_directory
&fnd
,
21598 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21599 CORE_ADDR lowpc
, int decode_mapping
)
21601 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21602 const int decode_for_pst_p
= (pst
!= NULL
);
21604 if (decode_mapping
)
21605 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21607 if (decode_for_pst_p
)
21609 /* Now that we're done scanning the Line Header Program, we can
21610 create the psymtab of each included file. */
21611 for (auto &file_entry
: lh
->file_names ())
21612 if (file_entry
.included_p
)
21614 gdb::unique_xmalloc_ptr
<char> name_holder
;
21615 const char *include_name
=
21616 compute_include_file_name (lh
, file_entry
, fnd
, &name_holder
);
21617 if (include_name
!= NULL
)
21618 dwarf2_create_include_psymtab
21619 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21620 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21626 /* Make sure a symtab is created for every file, even files
21627 which contain only variables (i.e. no code with associated
21629 buildsym_compunit
*builder
= cu
->get_builder ();
21630 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21632 for (auto &fe
: lh
->file_names ())
21634 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21635 if (builder
->get_current_subfile ()->symtab
== NULL
)
21637 builder
->get_current_subfile ()->symtab
21638 = allocate_symtab (cust
,
21639 builder
->get_current_subfile ()->name
);
21641 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21646 /* Start a subfile for DWARF. FILENAME is the name of the file and
21647 DIRNAME the name of the source directory which contains FILENAME
21648 or NULL if not known.
21649 This routine tries to keep line numbers from identical absolute and
21650 relative file names in a common subfile.
21652 Using the `list' example from the GDB testsuite, which resides in
21653 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21654 of /srcdir/list0.c yields the following debugging information for list0.c:
21656 DW_AT_name: /srcdir/list0.c
21657 DW_AT_comp_dir: /compdir
21658 files.files[0].name: list0.h
21659 files.files[0].dir: /srcdir
21660 files.files[1].name: list0.c
21661 files.files[1].dir: /srcdir
21663 The line number information for list0.c has to end up in a single
21664 subfile, so that `break /srcdir/list0.c:1' works as expected.
21665 start_subfile will ensure that this happens provided that we pass the
21666 concatenation of files.files[1].dir and files.files[1].name as the
21670 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21671 const char *dirname
)
21673 gdb::unique_xmalloc_ptr
<char> copy
;
21675 /* In order not to lose the line information directory,
21676 we concatenate it to the filename when it makes sense.
21677 Note that the Dwarf3 standard says (speaking of filenames in line
21678 information): ``The directory index is ignored for file names
21679 that represent full path names''. Thus ignoring dirname in the
21680 `else' branch below isn't an issue. */
21682 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21684 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21685 filename
= copy
.get ();
21688 cu
->get_builder ()->start_subfile (filename
);
21692 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21693 struct dwarf2_cu
*cu
)
21695 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21696 struct comp_unit_head
*cu_header
= &cu
->header
;
21698 /* NOTE drow/2003-01-30: There used to be a comment and some special
21699 code here to turn a symbol with DW_AT_external and a
21700 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21701 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21702 with some versions of binutils) where shared libraries could have
21703 relocations against symbols in their debug information - the
21704 minimal symbol would have the right address, but the debug info
21705 would not. It's no longer necessary, because we will explicitly
21706 apply relocations when we read in the debug information now. */
21708 /* A DW_AT_location attribute with no contents indicates that a
21709 variable has been optimized away. */
21710 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21712 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
21716 /* Handle one degenerate form of location expression specially, to
21717 preserve GDB's previous behavior when section offsets are
21718 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21719 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21721 if (attr
->form_is_block ())
21723 struct dwarf_block
*block
= attr
->as_block ();
21725 if ((block
->data
[0] == DW_OP_addr
21726 && block
->size
== 1 + cu_header
->addr_size
)
21727 || ((block
->data
[0] == DW_OP_GNU_addr_index
21728 || block
->data
[0] == DW_OP_addrx
)
21730 == 1 + leb128_size (&block
->data
[1]))))
21732 unsigned int dummy
;
21734 if (block
->data
[0] == DW_OP_addr
)
21735 sym
->set_value_address
21736 (cu
->header
.read_address (objfile
->obfd
, block
->data
+ 1,
21739 sym
->set_value_address
21740 (read_addr_index_from_leb128 (cu
, block
->data
+ 1, &dummy
));
21741 sym
->set_aclass_index (LOC_STATIC
);
21742 fixup_symbol_section (sym
, objfile
);
21743 sym
->set_value_address
21744 (sym
->value_address ()
21745 + objfile
->section_offsets
[sym
->section_index ()]);
21750 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21751 expression evaluator, and use LOC_COMPUTED only when necessary
21752 (i.e. when the value of a register or memory location is
21753 referenced, or a thread-local block, etc.). Then again, it might
21754 not be worthwhile. I'm assuming that it isn't unless performance
21755 or memory numbers show me otherwise. */
21757 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21759 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21760 cu
->has_loclist
= true;
21763 /* Given a pointer to a DWARF information entry, figure out if we need
21764 to make a symbol table entry for it, and if so, create a new entry
21765 and return a pointer to it.
21766 If TYPE is NULL, determine symbol type from the die, otherwise
21767 used the passed type.
21768 If SPACE is not NULL, use it to hold the new symbol. If it is
21769 NULL, allocate a new symbol on the objfile's obstack. */
21771 static struct symbol
*
21772 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21773 struct symbol
*space
)
21775 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21776 struct objfile
*objfile
= per_objfile
->objfile
;
21777 struct gdbarch
*gdbarch
= objfile
->arch ();
21778 struct symbol
*sym
= NULL
;
21780 struct attribute
*attr
= NULL
;
21781 struct attribute
*attr2
= NULL
;
21782 CORE_ADDR baseaddr
;
21783 struct pending
**list_to_add
= NULL
;
21785 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21787 baseaddr
= objfile
->text_section_offset ();
21789 name
= dwarf2_name (die
, cu
);
21792 int suppress_add
= 0;
21797 sym
= new (&objfile
->objfile_obstack
) symbol
;
21798 OBJSTAT (objfile
, n_syms
++);
21800 /* Cache this symbol's name and the name's demangled form (if any). */
21801 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
21802 /* Fortran does not have mangling standard and the mangling does differ
21803 between gfortran, iFort etc. */
21804 const char *physname
21805 = (cu
->per_cu
->lang
== language_fortran
21806 ? dwarf2_full_name (name
, die
, cu
)
21807 : dwarf2_physname (name
, die
, cu
));
21808 const char *linkagename
= dw2_linkage_name (die
, cu
);
21810 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
21811 sym
->set_linkage_name (physname
);
21814 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21815 sym
->set_linkage_name (linkagename
);
21818 /* Handle DW_AT_artificial. */
21819 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
21820 if (attr
!= nullptr)
21821 sym
->artificial
= attr
->as_boolean ();
21823 /* Default assumptions.
21824 Use the passed type or decode it from the die. */
21825 sym
->set_domain (VAR_DOMAIN
);
21826 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
21828 sym
->set_type (type
);
21830 sym
->set_type (die_type (die
, cu
));
21831 attr
= dwarf2_attr (die
,
21832 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21834 if (attr
!= nullptr)
21835 sym
->set_line (attr
->constant_value (0));
21837 attr
= dwarf2_attr (die
,
21838 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21840 if (attr
!= nullptr && attr
->is_nonnegative ())
21842 file_name_index file_index
21843 = (file_name_index
) attr
->as_nonnegative ();
21844 struct file_entry
*fe
;
21846 if (cu
->line_header
!= NULL
)
21847 fe
= cu
->line_header
->file_name_at (file_index
);
21852 complaint (_("file index out of range"));
21854 symbol_set_symtab (sym
, fe
->symtab
);
21860 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21861 if (attr
!= nullptr)
21865 addr
= attr
->as_address ();
21866 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21867 sym
->set_value_address (addr
);
21868 sym
->set_aclass_index (LOC_LABEL
);
21871 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
21872 sym
->set_type (objfile_type (objfile
)->builtin_core_addr
);
21873 sym
->set_domain (LABEL_DOMAIN
);
21874 add_symbol_to_list (sym
, cu
->list_in_scope
);
21876 case DW_TAG_subprogram
:
21877 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21879 sym
->set_aclass_index (LOC_BLOCK
);
21880 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21881 if ((attr2
!= nullptr && attr2
->as_boolean ())
21882 || cu
->per_cu
->lang
== language_ada
21883 || cu
->per_cu
->lang
== language_fortran
)
21885 /* Subprograms marked external are stored as a global symbol.
21886 Ada and Fortran subprograms, whether marked external or
21887 not, are always stored as a global symbol, because we want
21888 to be able to access them globally. For instance, we want
21889 to be able to break on a nested subprogram without having
21890 to specify the context. */
21891 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21895 list_to_add
= cu
->list_in_scope
;
21898 case DW_TAG_inlined_subroutine
:
21899 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21901 sym
->set_aclass_index (LOC_BLOCK
);
21902 sym
->set_is_inlined (1);
21903 list_to_add
= cu
->list_in_scope
;
21905 case DW_TAG_template_value_param
:
21907 /* Fall through. */
21908 case DW_TAG_constant
:
21909 case DW_TAG_variable
:
21910 case DW_TAG_member
:
21911 /* Compilation with minimal debug info may result in
21912 variables with missing type entries. Change the
21913 misleading `void' type to something sensible. */
21914 if (sym
->type ()->code () == TYPE_CODE_VOID
)
21915 sym
->set_type (objfile_type (objfile
)->builtin_int
);
21917 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21918 /* In the case of DW_TAG_member, we should only be called for
21919 static const members. */
21920 if (die
->tag
== DW_TAG_member
)
21922 /* dwarf2_add_field uses die_is_declaration,
21923 so we do the same. */
21924 gdb_assert (die_is_declaration (die
, cu
));
21927 if (attr
!= nullptr)
21929 dwarf2_const_value (attr
, sym
, cu
);
21930 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21933 if (attr2
!= nullptr && attr2
->as_boolean ())
21934 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21936 list_to_add
= cu
->list_in_scope
;
21940 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21941 if (attr
!= nullptr)
21943 var_decode_location (attr
, sym
, cu
);
21944 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21946 /* Fortran explicitly imports any global symbols to the local
21947 scope by DW_TAG_common_block. */
21948 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21949 && die
->parent
->tag
== DW_TAG_common_block
)
21952 if (sym
->aclass () == LOC_STATIC
21953 && sym
->value_address () == 0
21954 && !per_objfile
->per_bfd
->has_section_at_zero
)
21956 /* When a static variable is eliminated by the linker,
21957 the corresponding debug information is not stripped
21958 out, but the variable address is set to null;
21959 do not add such variables into symbol table. */
21961 else if (attr2
!= nullptr && attr2
->as_boolean ())
21963 if (sym
->aclass () == LOC_STATIC
21964 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21965 && per_objfile
->per_bfd
->can_copy
)
21967 /* A global static variable might be subject to
21968 copy relocation. We first check for a local
21969 minsym, though, because maybe the symbol was
21970 marked hidden, in which case this would not
21972 bound_minimal_symbol found
21973 = (lookup_minimal_symbol_linkage
21974 (sym
->linkage_name (), objfile
));
21975 if (found
.minsym
!= nullptr)
21976 sym
->maybe_copied
= 1;
21979 /* A variable with DW_AT_external is never static,
21980 but it may be block-scoped. */
21982 = ((cu
->list_in_scope
21983 == cu
->get_builder ()->get_file_symbols ())
21984 ? cu
->get_builder ()->get_global_symbols ()
21985 : cu
->list_in_scope
);
21988 list_to_add
= cu
->list_in_scope
;
21992 /* We do not know the address of this symbol.
21993 If it is an external symbol and we have type information
21994 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21995 The address of the variable will then be determined from
21996 the minimal symbol table whenever the variable is
21998 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22000 /* Fortran explicitly imports any global symbols to the local
22001 scope by DW_TAG_common_block. */
22002 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
22003 && die
->parent
->tag
== DW_TAG_common_block
)
22005 /* SYMBOL_CLASS doesn't matter here because
22006 read_common_block is going to reset it. */
22008 list_to_add
= cu
->list_in_scope
;
22010 else if (attr2
!= nullptr && attr2
->as_boolean ()
22011 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22013 /* A variable with DW_AT_external is never static, but it
22014 may be block-scoped. */
22016 = ((cu
->list_in_scope
22017 == cu
->get_builder ()->get_file_symbols ())
22018 ? cu
->get_builder ()->get_global_symbols ()
22019 : cu
->list_in_scope
);
22021 sym
->set_aclass_index (LOC_UNRESOLVED
);
22023 else if (!die_is_declaration (die
, cu
))
22025 /* Use the default LOC_OPTIMIZED_OUT class. */
22026 gdb_assert (sym
->aclass () == LOC_OPTIMIZED_OUT
);
22028 list_to_add
= cu
->list_in_scope
;
22032 case DW_TAG_formal_parameter
:
22034 /* If we are inside a function, mark this as an argument. If
22035 not, we might be looking at an argument to an inlined function
22036 when we do not have enough information to show inlined frames;
22037 pretend it's a local variable in that case so that the user can
22039 struct context_stack
*curr
22040 = cu
->get_builder ()->get_current_context_stack ();
22041 if (curr
!= nullptr && curr
->name
!= nullptr)
22042 sym
->set_is_argument (1);
22043 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22044 if (attr
!= nullptr)
22046 var_decode_location (attr
, sym
, cu
);
22048 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22049 if (attr
!= nullptr)
22051 dwarf2_const_value (attr
, sym
, cu
);
22054 list_to_add
= cu
->list_in_scope
;
22057 case DW_TAG_unspecified_parameters
:
22058 /* From varargs functions; gdb doesn't seem to have any
22059 interest in this information, so just ignore it for now.
22062 case DW_TAG_template_type_param
:
22064 /* Fall through. */
22065 case DW_TAG_class_type
:
22066 case DW_TAG_interface_type
:
22067 case DW_TAG_structure_type
:
22068 case DW_TAG_union_type
:
22069 case DW_TAG_set_type
:
22070 case DW_TAG_enumeration_type
:
22071 case DW_TAG_namelist
:
22072 if (die
->tag
== DW_TAG_namelist
)
22074 sym
->set_aclass_index (LOC_STATIC
);
22075 sym
->set_domain (VAR_DOMAIN
);
22079 sym
->set_aclass_index (LOC_TYPEDEF
);
22080 sym
->set_domain (STRUCT_DOMAIN
);
22083 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22084 really ever be static objects: otherwise, if you try
22085 to, say, break of a class's method and you're in a file
22086 which doesn't mention that class, it won't work unless
22087 the check for all static symbols in lookup_symbol_aux
22088 saves you. See the OtherFileClass tests in
22089 gdb.c++/namespace.exp. */
22093 buildsym_compunit
*builder
= cu
->get_builder ();
22095 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22096 && cu
->per_cu
->lang
== language_cplus
22097 ? builder
->get_global_symbols ()
22098 : cu
->list_in_scope
);
22100 /* The semantics of C++ state that "struct foo {
22101 ... }" also defines a typedef for "foo". */
22102 if (cu
->per_cu
->lang
== language_cplus
22103 || cu
->per_cu
->lang
== language_ada
22104 || cu
->per_cu
->lang
== language_d
22105 || cu
->per_cu
->lang
== language_rust
)
22107 /* The symbol's name is already allocated along
22108 with this objfile, so we don't need to
22109 duplicate it for the type. */
22110 if (sym
->type ()->name () == 0)
22111 sym
->type ()->set_name (sym
->search_name ());
22116 case DW_TAG_typedef
:
22117 sym
->set_aclass_index (LOC_TYPEDEF
);
22118 sym
->set_domain (VAR_DOMAIN
);
22119 list_to_add
= cu
->list_in_scope
;
22121 case DW_TAG_array_type
:
22122 case DW_TAG_base_type
:
22123 case DW_TAG_subrange_type
:
22124 case DW_TAG_generic_subrange
:
22125 sym
->set_aclass_index (LOC_TYPEDEF
);
22126 sym
->set_domain (VAR_DOMAIN
);
22127 list_to_add
= cu
->list_in_scope
;
22129 case DW_TAG_enumerator
:
22130 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22131 if (attr
!= nullptr)
22133 dwarf2_const_value (attr
, sym
, cu
);
22136 /* NOTE: carlton/2003-11-10: See comment above in the
22137 DW_TAG_class_type, etc. block. */
22140 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22141 && cu
->per_cu
->lang
== language_cplus
22142 ? cu
->get_builder ()->get_global_symbols ()
22143 : cu
->list_in_scope
);
22146 case DW_TAG_imported_declaration
:
22147 case DW_TAG_namespace
:
22148 sym
->set_aclass_index (LOC_TYPEDEF
);
22149 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22151 case DW_TAG_module
:
22152 sym
->set_aclass_index (LOC_TYPEDEF
);
22153 sym
->set_domain (MODULE_DOMAIN
);
22154 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22156 case DW_TAG_common_block
:
22157 sym
->set_aclass_index (LOC_COMMON_BLOCK
);
22158 sym
->set_domain (COMMON_BLOCK_DOMAIN
);
22159 add_symbol_to_list (sym
, cu
->list_in_scope
);
22162 /* Not a tag we recognize. Hopefully we aren't processing
22163 trash data, but since we must specifically ignore things
22164 we don't recognize, there is nothing else we should do at
22166 complaint (_("unsupported tag: '%s'"),
22167 dwarf_tag_name (die
->tag
));
22173 sym
->hash_next
= objfile
->template_symbols
;
22174 objfile
->template_symbols
= sym
;
22175 list_to_add
= NULL
;
22178 if (list_to_add
!= NULL
)
22179 add_symbol_to_list (sym
, list_to_add
);
22181 /* For the benefit of old versions of GCC, check for anonymous
22182 namespaces based on the demangled name. */
22183 if (!cu
->processing_has_namespace_info
22184 && cu
->per_cu
->lang
== language_cplus
)
22185 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22190 /* Given an attr with a DW_FORM_dataN value in host byte order,
22191 zero-extend it as appropriate for the symbol's type. The DWARF
22192 standard (v4) is not entirely clear about the meaning of using
22193 DW_FORM_dataN for a constant with a signed type, where the type is
22194 wider than the data. The conclusion of a discussion on the DWARF
22195 list was that this is unspecified. We choose to always zero-extend
22196 because that is the interpretation long in use by GCC. */
22199 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22200 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22202 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22203 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22204 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22205 LONGEST l
= attr
->constant_value (0);
22207 if (bits
< sizeof (*value
) * 8)
22209 l
&= ((LONGEST
) 1 << bits
) - 1;
22212 else if (bits
== sizeof (*value
) * 8)
22216 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22217 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22224 /* Read a constant value from an attribute. Either set *VALUE, or if
22225 the value does not fit in *VALUE, set *BYTES - either already
22226 allocated on the objfile obstack, or newly allocated on OBSTACK,
22227 or, set *BATON, if we translated the constant to a location
22231 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22232 const char *name
, struct obstack
*obstack
,
22233 struct dwarf2_cu
*cu
,
22234 LONGEST
*value
, const gdb_byte
**bytes
,
22235 struct dwarf2_locexpr_baton
**baton
)
22237 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22238 struct objfile
*objfile
= per_objfile
->objfile
;
22239 struct comp_unit_head
*cu_header
= &cu
->header
;
22240 struct dwarf_block
*blk
;
22241 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22242 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22248 switch (attr
->form
)
22251 case DW_FORM_addrx
:
22252 case DW_FORM_GNU_addr_index
:
22256 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22257 dwarf2_const_value_length_mismatch_complaint (name
,
22258 cu_header
->addr_size
,
22259 TYPE_LENGTH (type
));
22260 /* Symbols of this form are reasonably rare, so we just
22261 piggyback on the existing location code rather than writing
22262 a new implementation of symbol_computed_ops. */
22263 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22264 (*baton
)->per_objfile
= per_objfile
;
22265 (*baton
)->per_cu
= cu
->per_cu
;
22266 gdb_assert ((*baton
)->per_cu
);
22268 (*baton
)->size
= 2 + cu_header
->addr_size
;
22269 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22270 (*baton
)->data
= data
;
22272 data
[0] = DW_OP_addr
;
22273 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22274 byte_order
, attr
->as_address ());
22275 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22278 case DW_FORM_string
:
22281 case DW_FORM_GNU_str_index
:
22282 case DW_FORM_GNU_strp_alt
:
22283 /* The string is already allocated on the objfile obstack, point
22285 *bytes
= (const gdb_byte
*) attr
->as_string ();
22287 case DW_FORM_block1
:
22288 case DW_FORM_block2
:
22289 case DW_FORM_block4
:
22290 case DW_FORM_block
:
22291 case DW_FORM_exprloc
:
22292 case DW_FORM_data16
:
22293 blk
= attr
->as_block ();
22294 if (TYPE_LENGTH (type
) != blk
->size
)
22295 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22296 TYPE_LENGTH (type
));
22297 *bytes
= blk
->data
;
22300 /* The DW_AT_const_value attributes are supposed to carry the
22301 symbol's value "represented as it would be on the target
22302 architecture." By the time we get here, it's already been
22303 converted to host endianness, so we just need to sign- or
22304 zero-extend it as appropriate. */
22305 case DW_FORM_data1
:
22306 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22308 case DW_FORM_data2
:
22309 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22311 case DW_FORM_data4
:
22312 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22314 case DW_FORM_data8
:
22315 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22318 case DW_FORM_sdata
:
22319 case DW_FORM_implicit_const
:
22320 *value
= attr
->as_signed ();
22323 case DW_FORM_udata
:
22324 *value
= attr
->as_unsigned ();
22328 complaint (_("unsupported const value attribute form: '%s'"),
22329 dwarf_form_name (attr
->form
));
22336 /* Copy constant value from an attribute to a symbol. */
22339 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22340 struct dwarf2_cu
*cu
)
22342 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22344 const gdb_byte
*bytes
;
22345 struct dwarf2_locexpr_baton
*baton
;
22347 dwarf2_const_value_attr (attr
, sym
->type (),
22348 sym
->print_name (),
22349 &objfile
->objfile_obstack
, cu
,
22350 &value
, &bytes
, &baton
);
22354 SYMBOL_LOCATION_BATON (sym
) = baton
;
22355 sym
->set_aclass_index (dwarf2_locexpr_index
);
22357 else if (bytes
!= NULL
)
22359 sym
->set_value_bytes (bytes
);
22360 sym
->set_aclass_index (LOC_CONST_BYTES
);
22364 sym
->set_value_longest (value
);
22365 sym
->set_aclass_index (LOC_CONST
);
22369 /* Return the type of the die in question using its DW_AT_type attribute. */
22371 static struct type
*
22372 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22374 struct attribute
*type_attr
;
22376 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22379 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22380 /* A missing DW_AT_type represents a void type. */
22381 return objfile_type (objfile
)->builtin_void
;
22384 return lookup_die_type (die
, type_attr
, cu
);
22387 /* True iff CU's producer generates GNAT Ada auxiliary information
22388 that allows to find parallel types through that information instead
22389 of having to do expensive parallel lookups by type name. */
22392 need_gnat_info (struct dwarf2_cu
*cu
)
22394 /* Assume that the Ada compiler was GNAT, which always produces
22395 the auxiliary information. */
22396 return (cu
->per_cu
->lang
== language_ada
);
22399 /* Return the auxiliary type of the die in question using its
22400 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22401 attribute is not present. */
22403 static struct type
*
22404 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22406 struct attribute
*type_attr
;
22408 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22412 return lookup_die_type (die
, type_attr
, cu
);
22415 /* If DIE has a descriptive_type attribute, then set the TYPE's
22416 descriptive type accordingly. */
22419 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22420 struct dwarf2_cu
*cu
)
22422 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22424 if (descriptive_type
)
22426 ALLOCATE_GNAT_AUX_TYPE (type
);
22427 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22431 /* Return the containing type of the die in question using its
22432 DW_AT_containing_type attribute. */
22434 static struct type
*
22435 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22437 struct attribute
*type_attr
;
22438 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22440 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22442 error (_("Dwarf Error: Problem turning containing type into gdb type "
22443 "[in module %s]"), objfile_name (objfile
));
22445 return lookup_die_type (die
, type_attr
, cu
);
22448 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22450 static struct type
*
22451 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22453 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22454 struct objfile
*objfile
= per_objfile
->objfile
;
22457 std::string message
22458 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22459 objfile_name (objfile
),
22460 sect_offset_str (cu
->header
.sect_off
),
22461 sect_offset_str (die
->sect_off
));
22462 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22464 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22467 /* Look up the type of DIE in CU using its type attribute ATTR.
22468 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22469 DW_AT_containing_type.
22470 If there is no type substitute an error marker. */
22472 static struct type
*
22473 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22474 struct dwarf2_cu
*cu
)
22476 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22477 struct objfile
*objfile
= per_objfile
->objfile
;
22478 struct type
*this_type
;
22480 gdb_assert (attr
->name
== DW_AT_type
22481 || attr
->name
== DW_AT_GNAT_descriptive_type
22482 || attr
->name
== DW_AT_containing_type
);
22484 /* First see if we have it cached. */
22486 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22488 struct dwarf2_per_cu_data
*per_cu
;
22489 sect_offset sect_off
= attr
->get_ref_die_offset ();
22491 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22492 per_objfile
->per_bfd
);
22493 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22495 else if (attr
->form_is_ref ())
22497 sect_offset sect_off
= attr
->get_ref_die_offset ();
22499 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22501 else if (attr
->form
== DW_FORM_ref_sig8
)
22503 ULONGEST signature
= attr
->as_signature ();
22505 return get_signatured_type (die
, signature
, cu
);
22509 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22510 " at %s [in module %s]"),
22511 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22512 objfile_name (objfile
));
22513 return build_error_marker_type (cu
, die
);
22516 /* If not cached we need to read it in. */
22518 if (this_type
== NULL
)
22520 struct die_info
*type_die
= NULL
;
22521 struct dwarf2_cu
*type_cu
= cu
;
22523 if (attr
->form_is_ref ())
22524 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22525 if (type_die
== NULL
)
22526 return build_error_marker_type (cu
, die
);
22527 /* If we find the type now, it's probably because the type came
22528 from an inter-CU reference and the type's CU got expanded before
22530 this_type
= read_type_die (type_die
, type_cu
);
22533 /* If we still don't have a type use an error marker. */
22535 if (this_type
== NULL
)
22536 return build_error_marker_type (cu
, die
);
22541 /* Return the type in DIE, CU.
22542 Returns NULL for invalid types.
22544 This first does a lookup in die_type_hash,
22545 and only reads the die in if necessary.
22547 NOTE: This can be called when reading in partial or full symbols. */
22549 static struct type
*
22550 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22552 struct type
*this_type
;
22554 this_type
= get_die_type (die
, cu
);
22558 return read_type_die_1 (die
, cu
);
22561 /* Read the type in DIE, CU.
22562 Returns NULL for invalid types. */
22564 static struct type
*
22565 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22567 struct type
*this_type
= NULL
;
22571 case DW_TAG_class_type
:
22572 case DW_TAG_interface_type
:
22573 case DW_TAG_structure_type
:
22574 case DW_TAG_union_type
:
22575 this_type
= read_structure_type (die
, cu
);
22577 case DW_TAG_enumeration_type
:
22578 this_type
= read_enumeration_type (die
, cu
);
22580 case DW_TAG_subprogram
:
22581 case DW_TAG_subroutine_type
:
22582 case DW_TAG_inlined_subroutine
:
22583 this_type
= read_subroutine_type (die
, cu
);
22585 case DW_TAG_array_type
:
22586 this_type
= read_array_type (die
, cu
);
22588 case DW_TAG_set_type
:
22589 this_type
= read_set_type (die
, cu
);
22591 case DW_TAG_pointer_type
:
22592 this_type
= read_tag_pointer_type (die
, cu
);
22594 case DW_TAG_ptr_to_member_type
:
22595 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22597 case DW_TAG_reference_type
:
22598 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22600 case DW_TAG_rvalue_reference_type
:
22601 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22603 case DW_TAG_const_type
:
22604 this_type
= read_tag_const_type (die
, cu
);
22606 case DW_TAG_volatile_type
:
22607 this_type
= read_tag_volatile_type (die
, cu
);
22609 case DW_TAG_restrict_type
:
22610 this_type
= read_tag_restrict_type (die
, cu
);
22612 case DW_TAG_string_type
:
22613 this_type
= read_tag_string_type (die
, cu
);
22615 case DW_TAG_typedef
:
22616 this_type
= read_typedef (die
, cu
);
22618 case DW_TAG_generic_subrange
:
22619 case DW_TAG_subrange_type
:
22620 this_type
= read_subrange_type (die
, cu
);
22622 case DW_TAG_base_type
:
22623 this_type
= read_base_type (die
, cu
);
22625 case DW_TAG_unspecified_type
:
22626 this_type
= read_unspecified_type (die
, cu
);
22628 case DW_TAG_namespace
:
22629 this_type
= read_namespace_type (die
, cu
);
22631 case DW_TAG_module
:
22632 this_type
= read_module_type (die
, cu
);
22634 case DW_TAG_atomic_type
:
22635 this_type
= read_tag_atomic_type (die
, cu
);
22638 complaint (_("unexpected tag in read_type_die: '%s'"),
22639 dwarf_tag_name (die
->tag
));
22646 /* See if we can figure out if the class lives in a namespace. We do
22647 this by looking for a member function; its demangled name will
22648 contain namespace info, if there is any.
22649 Return the computed name or NULL.
22650 Space for the result is allocated on the objfile's obstack.
22651 This is the full-die version of guess_partial_die_structure_name.
22652 In this case we know DIE has no useful parent. */
22654 static const char *
22655 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22657 struct die_info
*spec_die
;
22658 struct dwarf2_cu
*spec_cu
;
22659 struct die_info
*child
;
22660 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22663 spec_die
= die_specification (die
, &spec_cu
);
22664 if (spec_die
!= NULL
)
22670 for (child
= die
->child
;
22672 child
= child
->sibling
)
22674 if (child
->tag
== DW_TAG_subprogram
)
22676 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22678 if (linkage_name
!= NULL
)
22680 gdb::unique_xmalloc_ptr
<char> actual_name
22681 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22682 const char *name
= NULL
;
22684 if (actual_name
!= NULL
)
22686 const char *die_name
= dwarf2_name (die
, cu
);
22688 if (die_name
!= NULL
22689 && strcmp (die_name
, actual_name
.get ()) != 0)
22691 /* Strip off the class name from the full name.
22692 We want the prefix. */
22693 int die_name_len
= strlen (die_name
);
22694 int actual_name_len
= strlen (actual_name
.get ());
22695 const char *ptr
= actual_name
.get ();
22697 /* Test for '::' as a sanity check. */
22698 if (actual_name_len
> die_name_len
+ 2
22699 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22700 name
= obstack_strndup (
22701 &objfile
->per_bfd
->storage_obstack
,
22702 ptr
, actual_name_len
- die_name_len
- 2);
22713 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22714 prefix part in such case. See
22715 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22717 static const char *
22718 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22720 struct attribute
*attr
;
22723 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22724 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22727 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22730 attr
= dw2_linkage_name_attr (die
, cu
);
22731 const char *attr_name
= attr
->as_string ();
22732 if (attr
== NULL
|| attr_name
== NULL
)
22735 /* dwarf2_name had to be already called. */
22736 gdb_assert (attr
->canonical_string_p ());
22738 /* Strip the base name, keep any leading namespaces/classes. */
22739 base
= strrchr (attr_name
, ':');
22740 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22743 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22744 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22746 &base
[-1] - attr_name
);
22749 /* Return the name of the namespace/class that DIE is defined within,
22750 or "" if we can't tell. The caller should not xfree the result.
22752 For example, if we're within the method foo() in the following
22762 then determine_prefix on foo's die will return "N::C". */
22764 static const char *
22765 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22767 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22768 struct die_info
*parent
, *spec_die
;
22769 struct dwarf2_cu
*spec_cu
;
22770 struct type
*parent_type
;
22771 const char *retval
;
22773 if (cu
->per_cu
->lang
!= language_cplus
22774 && cu
->per_cu
->lang
!= language_fortran
22775 && cu
->per_cu
->lang
!= language_d
22776 && cu
->per_cu
->lang
!= language_rust
)
22779 retval
= anonymous_struct_prefix (die
, cu
);
22783 /* We have to be careful in the presence of DW_AT_specification.
22784 For example, with GCC 3.4, given the code
22788 // Definition of N::foo.
22792 then we'll have a tree of DIEs like this:
22794 1: DW_TAG_compile_unit
22795 2: DW_TAG_namespace // N
22796 3: DW_TAG_subprogram // declaration of N::foo
22797 4: DW_TAG_subprogram // definition of N::foo
22798 DW_AT_specification // refers to die #3
22800 Thus, when processing die #4, we have to pretend that we're in
22801 the context of its DW_AT_specification, namely the contex of die
22804 spec_die
= die_specification (die
, &spec_cu
);
22805 if (spec_die
== NULL
)
22806 parent
= die
->parent
;
22809 parent
= spec_die
->parent
;
22813 if (parent
== NULL
)
22815 else if (parent
->building_fullname
)
22818 const char *parent_name
;
22820 /* It has been seen on RealView 2.2 built binaries,
22821 DW_TAG_template_type_param types actually _defined_ as
22822 children of the parent class:
22825 template class <class Enum> Class{};
22826 Class<enum E> class_e;
22828 1: DW_TAG_class_type (Class)
22829 2: DW_TAG_enumeration_type (E)
22830 3: DW_TAG_enumerator (enum1:0)
22831 3: DW_TAG_enumerator (enum2:1)
22833 2: DW_TAG_template_type_param
22834 DW_AT_type DW_FORM_ref_udata (E)
22836 Besides being broken debug info, it can put GDB into an
22837 infinite loop. Consider:
22839 When we're building the full name for Class<E>, we'll start
22840 at Class, and go look over its template type parameters,
22841 finding E. We'll then try to build the full name of E, and
22842 reach here. We're now trying to build the full name of E,
22843 and look over the parent DIE for containing scope. In the
22844 broken case, if we followed the parent DIE of E, we'd again
22845 find Class, and once again go look at its template type
22846 arguments, etc., etc. Simply don't consider such parent die
22847 as source-level parent of this die (it can't be, the language
22848 doesn't allow it), and break the loop here. */
22849 name
= dwarf2_name (die
, cu
);
22850 parent_name
= dwarf2_name (parent
, cu
);
22851 complaint (_("template param type '%s' defined within parent '%s'"),
22852 name
? name
: "<unknown>",
22853 parent_name
? parent_name
: "<unknown>");
22857 switch (parent
->tag
)
22859 case DW_TAG_namespace
:
22860 parent_type
= read_type_die (parent
, cu
);
22861 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22862 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22863 Work around this problem here. */
22864 if (cu
->per_cu
->lang
== language_cplus
22865 && strcmp (parent_type
->name (), "::") == 0)
22867 /* We give a name to even anonymous namespaces. */
22868 return parent_type
->name ();
22869 case DW_TAG_class_type
:
22870 case DW_TAG_interface_type
:
22871 case DW_TAG_structure_type
:
22872 case DW_TAG_union_type
:
22873 case DW_TAG_module
:
22874 parent_type
= read_type_die (parent
, cu
);
22875 if (parent_type
->name () != NULL
)
22876 return parent_type
->name ();
22878 /* An anonymous structure is only allowed non-static data
22879 members; no typedefs, no member functions, et cetera.
22880 So it does not need a prefix. */
22882 case DW_TAG_compile_unit
:
22883 case DW_TAG_partial_unit
:
22884 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22885 if (cu
->per_cu
->lang
== language_cplus
22886 && !per_objfile
->per_bfd
->types
.empty ()
22887 && die
->child
!= NULL
22888 && (die
->tag
== DW_TAG_class_type
22889 || die
->tag
== DW_TAG_structure_type
22890 || die
->tag
== DW_TAG_union_type
))
22892 const char *name
= guess_full_die_structure_name (die
, cu
);
22897 case DW_TAG_subprogram
:
22898 /* Nested subroutines in Fortran get a prefix with the name
22899 of the parent's subroutine. */
22900 if (cu
->per_cu
->lang
== language_fortran
)
22902 if ((die
->tag
== DW_TAG_subprogram
)
22903 && (dwarf2_name (parent
, cu
) != NULL
))
22904 return dwarf2_name (parent
, cu
);
22907 case DW_TAG_enumeration_type
:
22908 parent_type
= read_type_die (parent
, cu
);
22909 if (parent_type
->is_declared_class ())
22911 if (parent_type
->name () != NULL
)
22912 return parent_type
->name ();
22915 /* Fall through. */
22917 return determine_prefix (parent
, cu
);
22921 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22922 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22923 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22924 an obconcat, otherwise allocate storage for the result. The CU argument is
22925 used to determine the language and hence, the appropriate separator. */
22927 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22930 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22931 int physname
, struct dwarf2_cu
*cu
)
22933 const char *lead
= "";
22936 if (suffix
== NULL
|| suffix
[0] == '\0'
22937 || prefix
== NULL
|| prefix
[0] == '\0')
22939 else if (cu
->per_cu
->lang
== language_d
)
22941 /* For D, the 'main' function could be defined in any module, but it
22942 should never be prefixed. */
22943 if (strcmp (suffix
, "D main") == 0)
22951 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
22953 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22954 DW_AT_MIPS_linkage_name is preferred and used instead. */
22962 if (prefix
== NULL
)
22964 if (suffix
== NULL
)
22971 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22973 strcpy (retval
, lead
);
22974 strcat (retval
, prefix
);
22975 strcat (retval
, sep
);
22976 strcat (retval
, suffix
);
22981 /* We have an obstack. */
22982 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22986 /* Get name of a die, return NULL if not found. */
22988 static const char *
22989 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22990 struct objfile
*objfile
)
22992 if (name
&& cu
->per_cu
->lang
== language_cplus
)
22994 gdb::unique_xmalloc_ptr
<char> canon_name
22995 = cp_canonicalize_string (name
);
22997 if (canon_name
!= nullptr)
22998 name
= objfile
->intern (canon_name
.get ());
23004 /* Get name of a die, return NULL if not found.
23005 Anonymous namespaces are converted to their magic string. */
23007 static const char *
23008 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23010 struct attribute
*attr
;
23011 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23013 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23014 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23015 if (attr_name
== nullptr
23016 && die
->tag
!= DW_TAG_namespace
23017 && die
->tag
!= DW_TAG_class_type
23018 && die
->tag
!= DW_TAG_interface_type
23019 && die
->tag
!= DW_TAG_structure_type
23020 && die
->tag
!= DW_TAG_namelist
23021 && die
->tag
!= DW_TAG_union_type
)
23026 case DW_TAG_compile_unit
:
23027 case DW_TAG_partial_unit
:
23028 /* Compilation units have a DW_AT_name that is a filename, not
23029 a source language identifier. */
23030 case DW_TAG_enumeration_type
:
23031 case DW_TAG_enumerator
:
23032 /* These tags always have simple identifiers already; no need
23033 to canonicalize them. */
23036 case DW_TAG_namespace
:
23037 if (attr_name
!= nullptr)
23039 return CP_ANONYMOUS_NAMESPACE_STR
;
23041 case DW_TAG_class_type
:
23042 case DW_TAG_interface_type
:
23043 case DW_TAG_structure_type
:
23044 case DW_TAG_union_type
:
23045 case DW_TAG_namelist
:
23046 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23047 structures or unions. These were of the form "._%d" in GCC 4.1,
23048 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23049 and GCC 4.4. We work around this problem by ignoring these. */
23050 if (attr_name
!= nullptr
23051 && (startswith (attr_name
, "._")
23052 || startswith (attr_name
, "<anonymous")))
23055 /* GCC might emit a nameless typedef that has a linkage name. See
23056 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23057 if (!attr
|| attr_name
== NULL
)
23059 attr
= dw2_linkage_name_attr (die
, cu
);
23060 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23061 if (attr
== NULL
|| attr_name
== NULL
)
23064 /* Avoid demangling attr_name the second time on a second
23065 call for the same DIE. */
23066 if (!attr
->canonical_string_p ())
23068 gdb::unique_xmalloc_ptr
<char> demangled
23069 (gdb_demangle (attr_name
, DMGL_TYPES
));
23070 if (demangled
== nullptr)
23073 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23074 attr_name
= attr
->as_string ();
23077 /* Strip any leading namespaces/classes, keep only the
23078 base name. DW_AT_name for named DIEs does not
23079 contain the prefixes. */
23080 const char *base
= strrchr (attr_name
, ':');
23081 if (base
&& base
> attr_name
&& base
[-1] == ':')
23092 if (!attr
->canonical_string_p ())
23093 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23095 return attr
->as_string ();
23098 /* Return the die that this die in an extension of, or NULL if there
23099 is none. *EXT_CU is the CU containing DIE on input, and the CU
23100 containing the return value on output. */
23102 static struct die_info
*
23103 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23105 struct attribute
*attr
;
23107 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23111 return follow_die_ref (die
, attr
, ext_cu
);
23115 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23119 gdb_printf (f
, "%*sDie: %s (abbrev %d, offset %s)\n",
23121 dwarf_tag_name (die
->tag
), die
->abbrev
,
23122 sect_offset_str (die
->sect_off
));
23124 if (die
->parent
!= NULL
)
23125 gdb_printf (f
, "%*s parent at offset: %s\n",
23127 sect_offset_str (die
->parent
->sect_off
));
23129 gdb_printf (f
, "%*s has children: %s\n",
23131 dwarf_bool_name (die
->child
!= NULL
));
23133 gdb_printf (f
, "%*s attributes:\n", indent
, "");
23135 for (i
= 0; i
< die
->num_attrs
; ++i
)
23137 gdb_printf (f
, "%*s %s (%s) ",
23139 dwarf_attr_name (die
->attrs
[i
].name
),
23140 dwarf_form_name (die
->attrs
[i
].form
));
23142 switch (die
->attrs
[i
].form
)
23145 case DW_FORM_addrx
:
23146 case DW_FORM_GNU_addr_index
:
23147 gdb_printf (f
, "address: ");
23148 gdb_puts (hex_string (die
->attrs
[i
].as_address ()), f
);
23150 case DW_FORM_block2
:
23151 case DW_FORM_block4
:
23152 case DW_FORM_block
:
23153 case DW_FORM_block1
:
23154 gdb_printf (f
, "block: size %s",
23155 pulongest (die
->attrs
[i
].as_block ()->size
));
23157 case DW_FORM_exprloc
:
23158 gdb_printf (f
, "expression: size %s",
23159 pulongest (die
->attrs
[i
].as_block ()->size
));
23161 case DW_FORM_data16
:
23162 gdb_printf (f
, "constant of 16 bytes");
23164 case DW_FORM_ref_addr
:
23165 gdb_printf (f
, "ref address: ");
23166 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23168 case DW_FORM_GNU_ref_alt
:
23169 gdb_printf (f
, "alt ref address: ");
23170 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23176 case DW_FORM_ref_udata
:
23177 gdb_printf (f
, "constant ref: 0x%lx (adjusted)",
23178 (long) (die
->attrs
[i
].as_unsigned ()));
23180 case DW_FORM_data1
:
23181 case DW_FORM_data2
:
23182 case DW_FORM_data4
:
23183 case DW_FORM_data8
:
23184 case DW_FORM_udata
:
23185 gdb_printf (f
, "constant: %s",
23186 pulongest (die
->attrs
[i
].as_unsigned ()));
23188 case DW_FORM_sec_offset
:
23189 gdb_printf (f
, "section offset: %s",
23190 pulongest (die
->attrs
[i
].as_unsigned ()));
23192 case DW_FORM_ref_sig8
:
23193 gdb_printf (f
, "signature: %s",
23194 hex_string (die
->attrs
[i
].as_signature ()));
23196 case DW_FORM_string
:
23198 case DW_FORM_line_strp
:
23200 case DW_FORM_GNU_str_index
:
23201 case DW_FORM_GNU_strp_alt
:
23202 gdb_printf (f
, "string: \"%s\" (%s canonicalized)",
23203 die
->attrs
[i
].as_string ()
23204 ? die
->attrs
[i
].as_string () : "",
23205 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23208 if (die
->attrs
[i
].as_boolean ())
23209 gdb_printf (f
, "flag: TRUE");
23211 gdb_printf (f
, "flag: FALSE");
23213 case DW_FORM_flag_present
:
23214 gdb_printf (f
, "flag: TRUE");
23216 case DW_FORM_indirect
:
23217 /* The reader will have reduced the indirect form to
23218 the "base form" so this form should not occur. */
23220 "unexpected attribute form: DW_FORM_indirect");
23222 case DW_FORM_sdata
:
23223 case DW_FORM_implicit_const
:
23224 gdb_printf (f
, "constant: %s",
23225 plongest (die
->attrs
[i
].as_signed ()));
23228 gdb_printf (f
, "unsupported attribute form: %d.",
23229 die
->attrs
[i
].form
);
23232 gdb_printf (f
, "\n");
23237 dump_die_for_error (struct die_info
*die
)
23239 dump_die_shallow (gdb_stderr
, 0, die
);
23243 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23245 int indent
= level
* 4;
23247 gdb_assert (die
!= NULL
);
23249 if (level
>= max_level
)
23252 dump_die_shallow (f
, indent
, die
);
23254 if (die
->child
!= NULL
)
23256 gdb_printf (f
, "%*s Children:", indent
, "");
23257 if (level
+ 1 < max_level
)
23259 gdb_printf (f
, "\n");
23260 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23265 " [not printed, max nesting level reached]\n");
23269 if (die
->sibling
!= NULL
&& level
> 0)
23271 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23275 /* This is called from the pdie macro in gdbinit.in.
23276 It's not static so gcc will keep a copy callable from gdb. */
23279 dump_die (struct die_info
*die
, int max_level
)
23281 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23285 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23289 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23290 to_underlying (die
->sect_off
),
23296 /* Follow reference or signature attribute ATTR of SRC_DIE.
23297 On entry *REF_CU is the CU of SRC_DIE.
23298 On exit *REF_CU is the CU of the result. */
23300 static struct die_info
*
23301 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23302 struct dwarf2_cu
**ref_cu
)
23304 struct die_info
*die
;
23306 if (attr
->form_is_ref ())
23307 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23308 else if (attr
->form
== DW_FORM_ref_sig8
)
23309 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23312 dump_die_for_error (src_die
);
23313 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23314 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23320 /* Follow reference OFFSET.
23321 On entry *REF_CU is the CU of the source die referencing OFFSET.
23322 On exit *REF_CU is the CU of the result.
23323 Returns NULL if OFFSET is invalid. */
23325 static struct die_info
*
23326 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23327 struct dwarf2_cu
**ref_cu
)
23329 struct die_info temp_die
;
23330 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23331 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23333 gdb_assert (cu
->per_cu
!= NULL
);
23337 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23338 "source CU contains target offset: %d",
23339 sect_offset_str (cu
->per_cu
->sect_off
),
23340 sect_offset_str (sect_off
),
23341 cu
->header
.offset_in_cu_p (sect_off
));
23343 if (cu
->per_cu
->is_debug_types
)
23345 /* .debug_types CUs cannot reference anything outside their CU.
23346 If they need to, they have to reference a signatured type via
23347 DW_FORM_ref_sig8. */
23348 if (!cu
->header
.offset_in_cu_p (sect_off
))
23351 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23352 || !cu
->header
.offset_in_cu_p (sect_off
))
23354 struct dwarf2_per_cu_data
*per_cu
;
23356 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23357 per_objfile
->per_bfd
);
23359 dwarf_read_debug_printf_v ("target CU offset: %s, "
23360 "target CU DIEs loaded: %d",
23361 sect_offset_str (per_cu
->sect_off
),
23362 per_objfile
->get_cu (per_cu
) != nullptr);
23364 /* If necessary, add it to the queue and load its DIEs.
23366 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23367 it doesn't mean they are currently loaded. Since we require them
23368 to be loaded, we must check for ourselves. */
23369 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
23370 || per_objfile
->get_cu (per_cu
) == nullptr)
23371 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23372 false, cu
->per_cu
->lang
);
23374 target_cu
= per_objfile
->get_cu (per_cu
);
23375 gdb_assert (target_cu
!= nullptr);
23377 else if (cu
->dies
== NULL
)
23379 /* We're loading full DIEs during partial symbol reading. */
23380 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23381 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23385 *ref_cu
= target_cu
;
23386 temp_die
.sect_off
= sect_off
;
23388 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23390 to_underlying (sect_off
));
23393 /* Follow reference attribute ATTR of SRC_DIE.
23394 On entry *REF_CU is the CU of SRC_DIE.
23395 On exit *REF_CU is the CU of the result. */
23397 static struct die_info
*
23398 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23399 struct dwarf2_cu
**ref_cu
)
23401 sect_offset sect_off
= attr
->get_ref_die_offset ();
23402 struct dwarf2_cu
*cu
= *ref_cu
;
23403 struct die_info
*die
;
23405 die
= follow_die_offset (sect_off
,
23406 (attr
->form
== DW_FORM_GNU_ref_alt
23407 || cu
->per_cu
->is_dwz
),
23410 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23411 "at %s [in module %s]"),
23412 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23413 objfile_name (cu
->per_objfile
->objfile
));
23420 struct dwarf2_locexpr_baton
23421 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23422 dwarf2_per_cu_data
*per_cu
,
23423 dwarf2_per_objfile
*per_objfile
,
23424 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23425 bool resolve_abstract_p
)
23427 struct die_info
*die
;
23428 struct attribute
*attr
;
23429 struct dwarf2_locexpr_baton retval
;
23430 struct objfile
*objfile
= per_objfile
->objfile
;
23432 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23434 cu
= load_cu (per_cu
, per_objfile
, false);
23438 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23439 Instead just throw an error, not much else we can do. */
23440 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23441 sect_offset_str (sect_off
), objfile_name (objfile
));
23444 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23446 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23447 sect_offset_str (sect_off
), objfile_name (objfile
));
23449 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23450 if (!attr
&& resolve_abstract_p
23451 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23452 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23454 CORE_ADDR pc
= get_frame_pc ();
23455 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23456 struct gdbarch
*gdbarch
= objfile
->arch ();
23458 for (const auto &cand_off
23459 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23461 struct dwarf2_cu
*cand_cu
= cu
;
23462 struct die_info
*cand
23463 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23466 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23469 CORE_ADDR pc_low
, pc_high
;
23470 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23471 if (pc_low
== ((CORE_ADDR
) -1))
23473 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23474 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23475 if (!(pc_low
<= pc
&& pc
< pc_high
))
23479 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23486 /* DWARF: "If there is no such attribute, then there is no effect.".
23487 DATA is ignored if SIZE is 0. */
23489 retval
.data
= NULL
;
23492 else if (attr
->form_is_section_offset ())
23494 struct dwarf2_loclist_baton loclist_baton
;
23495 CORE_ADDR pc
= get_frame_pc ();
23498 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23500 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23502 retval
.size
= size
;
23506 if (!attr
->form_is_block ())
23507 error (_("Dwarf Error: DIE at %s referenced in module %s "
23508 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23509 sect_offset_str (sect_off
), objfile_name (objfile
));
23511 struct dwarf_block
*block
= attr
->as_block ();
23512 retval
.data
= block
->data
;
23513 retval
.size
= block
->size
;
23515 retval
.per_objfile
= per_objfile
;
23516 retval
.per_cu
= cu
->per_cu
;
23518 per_objfile
->age_comp_units ();
23525 struct dwarf2_locexpr_baton
23526 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23527 dwarf2_per_cu_data
*per_cu
,
23528 dwarf2_per_objfile
*per_objfile
,
23529 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23531 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23533 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23537 /* Write a constant of a given type as target-ordered bytes into
23540 static const gdb_byte
*
23541 write_constant_as_bytes (struct obstack
*obstack
,
23542 enum bfd_endian byte_order
,
23549 *len
= TYPE_LENGTH (type
);
23550 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23551 store_unsigned_integer (result
, *len
, byte_order
, value
);
23559 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23560 dwarf2_per_cu_data
*per_cu
,
23561 dwarf2_per_objfile
*per_objfile
,
23565 struct die_info
*die
;
23566 struct attribute
*attr
;
23567 const gdb_byte
*result
= NULL
;
23570 enum bfd_endian byte_order
;
23571 struct objfile
*objfile
= per_objfile
->objfile
;
23573 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23575 cu
= load_cu (per_cu
, per_objfile
, false);
23579 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23580 Instead just throw an error, not much else we can do. */
23581 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23582 sect_offset_str (sect_off
), objfile_name (objfile
));
23585 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23587 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23588 sect_offset_str (sect_off
), objfile_name (objfile
));
23590 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23594 byte_order
= (bfd_big_endian (objfile
->obfd
)
23595 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23597 switch (attr
->form
)
23600 case DW_FORM_addrx
:
23601 case DW_FORM_GNU_addr_index
:
23605 *len
= cu
->header
.addr_size
;
23606 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23607 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23611 case DW_FORM_string
:
23614 case DW_FORM_GNU_str_index
:
23615 case DW_FORM_GNU_strp_alt
:
23616 /* The string is already allocated on the objfile obstack, point
23619 const char *attr_name
= attr
->as_string ();
23620 result
= (const gdb_byte
*) attr_name
;
23621 *len
= strlen (attr_name
);
23624 case DW_FORM_block1
:
23625 case DW_FORM_block2
:
23626 case DW_FORM_block4
:
23627 case DW_FORM_block
:
23628 case DW_FORM_exprloc
:
23629 case DW_FORM_data16
:
23631 struct dwarf_block
*block
= attr
->as_block ();
23632 result
= block
->data
;
23633 *len
= block
->size
;
23637 /* The DW_AT_const_value attributes are supposed to carry the
23638 symbol's value "represented as it would be on the target
23639 architecture." By the time we get here, it's already been
23640 converted to host endianness, so we just need to sign- or
23641 zero-extend it as appropriate. */
23642 case DW_FORM_data1
:
23643 type
= die_type (die
, cu
);
23644 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23645 if (result
== NULL
)
23646 result
= write_constant_as_bytes (obstack
, byte_order
,
23649 case DW_FORM_data2
:
23650 type
= die_type (die
, cu
);
23651 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23652 if (result
== NULL
)
23653 result
= write_constant_as_bytes (obstack
, byte_order
,
23656 case DW_FORM_data4
:
23657 type
= die_type (die
, cu
);
23658 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23659 if (result
== NULL
)
23660 result
= write_constant_as_bytes (obstack
, byte_order
,
23663 case DW_FORM_data8
:
23664 type
= die_type (die
, cu
);
23665 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23666 if (result
== NULL
)
23667 result
= write_constant_as_bytes (obstack
, byte_order
,
23671 case DW_FORM_sdata
:
23672 case DW_FORM_implicit_const
:
23673 type
= die_type (die
, cu
);
23674 result
= write_constant_as_bytes (obstack
, byte_order
,
23675 type
, attr
->as_signed (), len
);
23678 case DW_FORM_udata
:
23679 type
= die_type (die
, cu
);
23680 result
= write_constant_as_bytes (obstack
, byte_order
,
23681 type
, attr
->as_unsigned (), len
);
23685 complaint (_("unsupported const value attribute form: '%s'"),
23686 dwarf_form_name (attr
->form
));
23696 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23697 dwarf2_per_cu_data
*per_cu
,
23698 dwarf2_per_objfile
*per_objfile
,
23699 const char **var_name
)
23701 struct die_info
*die
;
23703 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23705 cu
= load_cu (per_cu
, per_objfile
, false);
23710 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23714 if (var_name
!= nullptr)
23715 *var_name
= var_decl_name (die
, cu
);
23716 return die_type (die
, cu
);
23722 dwarf2_get_die_type (cu_offset die_offset
,
23723 dwarf2_per_cu_data
*per_cu
,
23724 dwarf2_per_objfile
*per_objfile
)
23726 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23727 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23730 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23731 On entry *REF_CU is the CU of SRC_DIE.
23732 On exit *REF_CU is the CU of the result.
23733 Returns NULL if the referenced DIE isn't found. */
23735 static struct die_info
*
23736 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23737 struct dwarf2_cu
**ref_cu
)
23739 struct die_info temp_die
;
23740 struct dwarf2_cu
*sig_cu
;
23741 struct die_info
*die
;
23742 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23745 /* While it might be nice to assert sig_type->type == NULL here,
23746 we can get here for DW_AT_imported_declaration where we need
23747 the DIE not the type. */
23749 /* If necessary, add it to the queue and load its DIEs.
23751 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23752 it doesn't mean they are currently loaded. Since we require them
23753 to be loaded, we must check for ourselves. */
23754 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23756 || per_objfile
->get_cu (sig_type
) == nullptr)
23757 read_signatured_type (sig_type
, per_objfile
);
23759 sig_cu
= per_objfile
->get_cu (sig_type
);
23760 gdb_assert (sig_cu
!= NULL
);
23761 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23762 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23763 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23764 to_underlying (temp_die
.sect_off
));
23767 /* For .gdb_index version 7 keep track of included TUs.
23768 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23769 if (per_objfile
->per_bfd
->index_table
!= NULL
23770 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23772 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23782 /* Follow signatured type referenced by ATTR in SRC_DIE.
23783 On entry *REF_CU is the CU of SRC_DIE.
23784 On exit *REF_CU is the CU of the result.
23785 The result is the DIE of the type.
23786 If the referenced type cannot be found an error is thrown. */
23788 static struct die_info
*
23789 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23790 struct dwarf2_cu
**ref_cu
)
23792 ULONGEST signature
= attr
->as_signature ();
23793 struct signatured_type
*sig_type
;
23794 struct die_info
*die
;
23796 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23798 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23799 /* sig_type will be NULL if the signatured type is missing from
23801 if (sig_type
== NULL
)
23803 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23804 " from DIE at %s [in module %s]"),
23805 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23806 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23809 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23812 dump_die_for_error (src_die
);
23813 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23814 " from DIE at %s [in module %s]"),
23815 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23816 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23822 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23823 reading in and processing the type unit if necessary. */
23825 static struct type
*
23826 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23827 struct dwarf2_cu
*cu
)
23829 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23830 struct signatured_type
*sig_type
;
23831 struct dwarf2_cu
*type_cu
;
23832 struct die_info
*type_die
;
23835 sig_type
= lookup_signatured_type (cu
, signature
);
23836 /* sig_type will be NULL if the signatured type is missing from
23838 if (sig_type
== NULL
)
23840 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23841 " from DIE at %s [in module %s]"),
23842 hex_string (signature
), sect_offset_str (die
->sect_off
),
23843 objfile_name (per_objfile
->objfile
));
23844 return build_error_marker_type (cu
, die
);
23847 /* If we already know the type we're done. */
23848 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23849 if (type
!= nullptr)
23853 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23854 if (type_die
!= NULL
)
23856 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23857 is created. This is important, for example, because for c++ classes
23858 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23859 type
= read_type_die (type_die
, type_cu
);
23862 complaint (_("Dwarf Error: Cannot build signatured type %s"
23863 " referenced from DIE at %s [in module %s]"),
23864 hex_string (signature
), sect_offset_str (die
->sect_off
),
23865 objfile_name (per_objfile
->objfile
));
23866 type
= build_error_marker_type (cu
, die
);
23871 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23872 " from DIE at %s [in module %s]"),
23873 hex_string (signature
), sect_offset_str (die
->sect_off
),
23874 objfile_name (per_objfile
->objfile
));
23875 type
= build_error_marker_type (cu
, die
);
23878 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23883 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23884 reading in and processing the type unit if necessary. */
23886 static struct type
*
23887 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23888 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23890 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23891 if (attr
->form_is_ref ())
23893 struct dwarf2_cu
*type_cu
= cu
;
23894 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23896 return read_type_die (type_die
, type_cu
);
23898 else if (attr
->form
== DW_FORM_ref_sig8
)
23900 return get_signatured_type (die
, attr
->as_signature (), cu
);
23904 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23906 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23907 " at %s [in module %s]"),
23908 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23909 objfile_name (per_objfile
->objfile
));
23910 return build_error_marker_type (cu
, die
);
23914 /* Load the DIEs associated with type unit PER_CU into memory. */
23917 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23918 dwarf2_per_objfile
*per_objfile
)
23920 struct signatured_type
*sig_type
;
23922 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23923 gdb_assert (! per_cu
->type_unit_group_p ());
23925 /* We have the per_cu, but we need the signatured_type.
23926 Fortunately this is an easy translation. */
23927 gdb_assert (per_cu
->is_debug_types
);
23928 sig_type
= (struct signatured_type
*) per_cu
;
23930 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23932 read_signatured_type (sig_type
, per_objfile
);
23934 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23937 /* Read in a signatured type and build its CU and DIEs.
23938 If the type is a stub for the real type in a DWO file,
23939 read in the real type from the DWO file as well. */
23942 read_signatured_type (signatured_type
*sig_type
,
23943 dwarf2_per_objfile
*per_objfile
)
23945 gdb_assert (sig_type
->is_debug_types
);
23946 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23948 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23950 if (!reader
.dummy_p
)
23952 struct dwarf2_cu
*cu
= reader
.cu
;
23953 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23955 gdb_assert (cu
->die_hash
== NULL
);
23957 htab_create_alloc_ex (cu
->header
.length
/ 12,
23961 &cu
->comp_unit_obstack
,
23962 hashtab_obstack_allocate
,
23963 dummy_obstack_deallocate
);
23965 if (reader
.comp_unit_die
->has_children
)
23966 reader
.comp_unit_die
->child
23967 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23968 reader
.comp_unit_die
);
23969 cu
->dies
= reader
.comp_unit_die
;
23970 /* comp_unit_die is not stored in die_hash, no need. */
23972 /* We try not to read any attributes in this function, because
23973 not all CUs needed for references have been loaded yet, and
23974 symbol table processing isn't initialized. But we have to
23975 set the CU language, or we won't be able to build types
23976 correctly. Similarly, if we do not read the producer, we can
23977 not apply producer-specific interpretation. */
23978 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23983 sig_type
->tu_read
= 1;
23986 /* Decode simple location descriptions.
23987 Given a pointer to a dwarf block that defines a location, compute
23988 the location and return the value. If COMPUTED is non-null, it is
23989 set to true to indicate that decoding was successful, and false
23990 otherwise. If COMPUTED is null, then this function may emit a
23994 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23996 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23998 size_t size
= blk
->size
;
23999 const gdb_byte
*data
= blk
->data
;
24000 CORE_ADDR stack
[64];
24002 unsigned int bytes_read
, unsnd
;
24005 if (computed
!= nullptr)
24011 stack
[++stacki
] = 0;
24050 stack
[++stacki
] = op
- DW_OP_lit0
;
24085 stack
[++stacki
] = op
- DW_OP_reg0
;
24088 if (computed
== nullptr)
24089 dwarf2_complex_location_expr_complaint ();
24096 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24098 stack
[++stacki
] = unsnd
;
24101 if (computed
== nullptr)
24102 dwarf2_complex_location_expr_complaint ();
24109 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24114 case DW_OP_const1u
:
24115 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24119 case DW_OP_const1s
:
24120 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24124 case DW_OP_const2u
:
24125 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24129 case DW_OP_const2s
:
24130 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24134 case DW_OP_const4u
:
24135 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24139 case DW_OP_const4s
:
24140 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24144 case DW_OP_const8u
:
24145 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24150 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24156 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24161 stack
[stacki
+ 1] = stack
[stacki
];
24166 stack
[stacki
- 1] += stack
[stacki
];
24170 case DW_OP_plus_uconst
:
24171 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24177 stack
[stacki
- 1] -= stack
[stacki
];
24182 /* If we're not the last op, then we definitely can't encode
24183 this using GDB's address_class enum. This is valid for partial
24184 global symbols, although the variable's address will be bogus
24188 if (computed
== nullptr)
24189 dwarf2_complex_location_expr_complaint ();
24195 case DW_OP_GNU_push_tls_address
:
24196 case DW_OP_form_tls_address
:
24197 /* The top of the stack has the offset from the beginning
24198 of the thread control block at which the variable is located. */
24199 /* Nothing should follow this operator, so the top of stack would
24201 /* This is valid for partial global symbols, but the variable's
24202 address will be bogus in the psymtab. Make it always at least
24203 non-zero to not look as a variable garbage collected by linker
24204 which have DW_OP_addr 0. */
24207 if (computed
== nullptr)
24208 dwarf2_complex_location_expr_complaint ();
24215 case DW_OP_GNU_uninit
:
24216 if (computed
!= nullptr)
24221 case DW_OP_GNU_addr_index
:
24222 case DW_OP_GNU_const_index
:
24223 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24229 if (computed
== nullptr)
24231 const char *name
= get_DW_OP_name (op
);
24234 complaint (_("unsupported stack op: '%s'"),
24237 complaint (_("unsupported stack op: '%02x'"),
24241 return (stack
[stacki
]);
24244 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24245 outside of the allocated space. Also enforce minimum>0. */
24246 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24248 if (computed
== nullptr)
24249 complaint (_("location description stack overflow"));
24255 if (computed
== nullptr)
24256 complaint (_("location description stack underflow"));
24261 if (computed
!= nullptr)
24263 return (stack
[stacki
]);
24266 /* memory allocation interface */
24268 static struct dwarf_block
*
24269 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24271 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24274 static struct die_info
*
24275 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24277 struct die_info
*die
;
24278 size_t size
= sizeof (struct die_info
);
24281 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24283 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24284 memset (die
, 0, sizeof (struct die_info
));
24290 /* Macro support. */
24292 /* An overload of dwarf_decode_macros that finds the correct section
24293 and ensures it is read in before calling the other overload. */
24296 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24297 int section_is_gnu
)
24299 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24300 struct objfile
*objfile
= per_objfile
->objfile
;
24301 const struct line_header
*lh
= cu
->line_header
;
24302 unsigned int offset_size
= cu
->header
.offset_size
;
24303 struct dwarf2_section_info
*section
;
24304 const char *section_name
;
24306 if (cu
->dwo_unit
!= nullptr)
24308 if (section_is_gnu
)
24310 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24311 section_name
= ".debug_macro.dwo";
24315 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24316 section_name
= ".debug_macinfo.dwo";
24321 if (section_is_gnu
)
24323 section
= &per_objfile
->per_bfd
->macro
;
24324 section_name
= ".debug_macro";
24328 section
= &per_objfile
->per_bfd
->macinfo
;
24329 section_name
= ".debug_macinfo";
24333 section
->read (objfile
);
24334 if (section
->buffer
== nullptr)
24336 complaint (_("missing %s section"), section_name
);
24340 buildsym_compunit
*builder
= cu
->get_builder ();
24342 struct dwarf2_section_info
*str_offsets_section
;
24343 struct dwarf2_section_info
*str_section
;
24344 gdb::optional
<ULONGEST
> str_offsets_base
;
24346 if (cu
->dwo_unit
!= nullptr)
24348 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24349 ->sections
.str_offsets
;
24350 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24351 str_offsets_base
= cu
->header
.addr_size
;
24355 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24356 str_section
= &per_objfile
->per_bfd
->str
;
24357 str_offsets_base
= cu
->str_offsets_base
;
24360 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24361 offset_size
, offset
, str_section
, str_offsets_section
,
24362 str_offsets_base
, section_is_gnu
);
24365 /* Return the .debug_loc section to use for CU.
24366 For DWO files use .debug_loc.dwo. */
24368 static struct dwarf2_section_info
*
24369 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24371 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24375 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24377 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24379 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24380 : &per_objfile
->per_bfd
->loc
);
24383 /* Return the .debug_rnglists section to use for CU. */
24384 static struct dwarf2_section_info
*
24385 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24387 if (cu
->header
.version
< 5)
24388 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24389 cu
->header
.version
);
24390 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24392 /* Make sure we read the .debug_rnglists section from the file that
24393 contains the DW_AT_ranges attribute we are reading. Normally that
24394 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24395 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24397 if (cu
->dwo_unit
!= nullptr
24398 && tag
!= DW_TAG_compile_unit
24399 && tag
!= DW_TAG_skeleton_unit
)
24401 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24403 if (sections
->rnglists
.size
> 0)
24404 return §ions
->rnglists
;
24406 error (_(".debug_rnglists section is missing from .dwo file."));
24408 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24411 /* A helper function that fills in a dwarf2_loclist_baton. */
24414 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24415 struct dwarf2_loclist_baton
*baton
,
24416 const struct attribute
*attr
)
24418 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24419 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24421 section
->read (per_objfile
->objfile
);
24423 baton
->per_objfile
= per_objfile
;
24424 baton
->per_cu
= cu
->per_cu
;
24425 gdb_assert (baton
->per_cu
);
24426 /* We don't know how long the location list is, but make sure we
24427 don't run off the edge of the section. */
24428 baton
->size
= section
->size
- attr
->as_unsigned ();
24429 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24430 if (cu
->base_address
.has_value ())
24431 baton
->base_address
= *cu
->base_address
;
24433 baton
->base_address
= 0;
24434 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24438 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24439 struct dwarf2_cu
*cu
, int is_block
)
24441 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24442 struct objfile
*objfile
= per_objfile
->objfile
;
24443 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24445 if (attr
->form_is_section_offset ()
24446 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24447 the section. If so, fall through to the complaint in the
24449 && attr
->as_unsigned () < section
->get_size (objfile
))
24451 struct dwarf2_loclist_baton
*baton
;
24453 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24455 fill_in_loclist_baton (cu
, baton
, attr
);
24457 if (!cu
->base_address
.has_value ())
24458 complaint (_("Location list used without "
24459 "specifying the CU base address."));
24461 sym
->set_aclass_index ((is_block
24462 ? dwarf2_loclist_block_index
24463 : dwarf2_loclist_index
));
24464 SYMBOL_LOCATION_BATON (sym
) = baton
;
24468 struct dwarf2_locexpr_baton
*baton
;
24470 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24471 baton
->per_objfile
= per_objfile
;
24472 baton
->per_cu
= cu
->per_cu
;
24473 gdb_assert (baton
->per_cu
);
24475 if (attr
->form_is_block ())
24477 /* Note that we're just copying the block's data pointer
24478 here, not the actual data. We're still pointing into the
24479 info_buffer for SYM's objfile; right now we never release
24480 that buffer, but when we do clean up properly this may
24482 struct dwarf_block
*block
= attr
->as_block ();
24483 baton
->size
= block
->size
;
24484 baton
->data
= block
->data
;
24488 dwarf2_invalid_attrib_class_complaint ("location description",
24489 sym
->natural_name ());
24493 sym
->set_aclass_index ((is_block
24494 ? dwarf2_locexpr_block_index
24495 : dwarf2_locexpr_index
));
24496 SYMBOL_LOCATION_BATON (sym
) = baton
;
24502 const comp_unit_head
*
24503 dwarf2_per_cu_data::get_header () const
24505 if (!m_header_read_in
)
24507 const gdb_byte
*info_ptr
24508 = this->section
->buffer
+ to_underlying (this->sect_off
);
24510 memset (&m_header
, 0, sizeof (m_header
));
24512 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24513 rcuh_kind::COMPILE
);
24515 m_header_read_in
= true;
24524 dwarf2_per_cu_data::addr_size () const
24526 return this->get_header ()->addr_size
;
24532 dwarf2_per_cu_data::offset_size () const
24534 return this->get_header ()->offset_size
;
24540 dwarf2_per_cu_data::ref_addr_size () const
24542 const comp_unit_head
*header
= this->get_header ();
24544 if (header
->version
== 2)
24545 return header
->addr_size
;
24547 return header
->offset_size
;
24550 /* A helper function for dwarf2_find_containing_comp_unit that returns
24551 the index of the result, and that searches a vector. It will
24552 return a result even if the offset in question does not actually
24553 occur in any CU. This is separate so that it can be unit
24557 dwarf2_find_containing_comp_unit
24558 (sect_offset sect_off
,
24559 unsigned int offset_in_dwz
,
24560 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24565 high
= all_comp_units
.size () - 1;
24568 struct dwarf2_per_cu_data
*mid_cu
;
24569 int mid
= low
+ (high
- low
) / 2;
24571 mid_cu
= all_comp_units
[mid
].get ();
24572 if (mid_cu
->is_dwz
> offset_in_dwz
24573 || (mid_cu
->is_dwz
== offset_in_dwz
24574 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24579 gdb_assert (low
== high
);
24583 /* Locate the .debug_info compilation unit from CU's objfile which contains
24584 the DIE at OFFSET. Raises an error on failure. */
24586 static struct dwarf2_per_cu_data
*
24587 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24588 unsigned int offset_in_dwz
,
24589 dwarf2_per_bfd
*per_bfd
)
24591 int low
= dwarf2_find_containing_comp_unit
24592 (sect_off
, offset_in_dwz
, per_bfd
->all_comp_units
);
24593 dwarf2_per_cu_data
*this_cu
= per_bfd
->all_comp_units
[low
].get ();
24595 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24597 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24598 error (_("Dwarf Error: could not find partial DIE containing "
24599 "offset %s [in module %s]"),
24600 sect_offset_str (sect_off
),
24601 bfd_get_filename (per_bfd
->obfd
));
24603 gdb_assert (per_bfd
->all_comp_units
[low
-1]->sect_off
24605 return per_bfd
->all_comp_units
[low
- 1].get ();
24609 if (low
== per_bfd
->all_comp_units
.size () - 1
24610 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24611 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24612 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24619 namespace selftests
{
24620 namespace find_containing_comp_unit
{
24625 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24626 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24627 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24628 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24629 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24630 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24631 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24632 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24635 two
->sect_off
= sect_offset (one
->length
);
24640 four
->sect_off
= sect_offset (three
->length
);
24644 std::vector
<dwarf2_per_cu_data_up
> units
;
24645 units
.push_back (std::move (one
));
24646 units
.push_back (std::move (two
));
24647 units
.push_back (std::move (three
));
24648 units
.push_back (std::move (four
));
24652 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24653 SELF_CHECK (units
[result
].get () == one_ptr
);
24654 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24655 SELF_CHECK (units
[result
].get () == one_ptr
);
24656 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24657 SELF_CHECK (units
[result
].get () == two_ptr
);
24659 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24660 SELF_CHECK (units
[result
].get () == three_ptr
);
24661 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24662 SELF_CHECK (units
[result
].get () == three_ptr
);
24663 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24664 SELF_CHECK (units
[result
].get () == four_ptr
);
24670 #endif /* GDB_SELF_TEST */
24672 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24675 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24676 enum language pretend_language
)
24678 struct attribute
*attr
;
24680 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24682 /* Set the language we're debugging. */
24683 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24684 if (cu
->producer
!= nullptr
24685 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
24687 /* The XLCL doesn't generate DW_LANG_OpenCL because this
24688 attribute is not standardised yet. As a workaround for the
24689 language detection we fall back to the DW_AT_producer
24691 cu
->per_cu
->lang
= language_opencl
;
24693 else if (cu
->producer
!= nullptr
24694 && strstr (cu
->producer
, "GNU Go ") != NULL
)
24696 /* Similar hack for Go. */
24697 cu
->per_cu
->lang
= language_go
;
24699 else if (attr
!= nullptr)
24700 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
24702 cu
->per_cu
->lang
= pretend_language
;
24703 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
24709 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24711 auto it
= m_dwarf2_cus
.find (per_cu
);
24712 if (it
== m_dwarf2_cus
.end ())
24721 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24723 gdb_assert (this->get_cu (per_cu
) == nullptr);
24725 m_dwarf2_cus
[per_cu
] = cu
;
24731 dwarf2_per_objfile::age_comp_units ()
24733 dwarf_read_debug_printf_v ("running");
24735 /* This is not expected to be called in the middle of CU expansion. There is
24736 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24737 loaded in memory. Calling age_comp_units while the queue is in use could
24738 make us free the DIEs for a CU that is in the queue and therefore break
24740 gdb_assert (!this->per_bfd
->queue
.has_value ());
24742 /* Start by clearing all marks. */
24743 for (auto pair
: m_dwarf2_cus
)
24744 pair
.second
->clear_mark ();
24746 /* Traverse all CUs, mark them and their dependencies if used recently
24748 for (auto pair
: m_dwarf2_cus
)
24750 dwarf2_cu
*cu
= pair
.second
;
24753 if (cu
->last_used
<= dwarf_max_cache_age
)
24757 /* Delete all CUs still not marked. */
24758 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24760 dwarf2_cu
*cu
= it
->second
;
24762 if (!cu
->is_marked ())
24764 dwarf_read_debug_printf_v ("deleting old CU %s",
24765 sect_offset_str (cu
->per_cu
->sect_off
));
24767 it
= m_dwarf2_cus
.erase (it
);
24777 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24779 auto it
= m_dwarf2_cus
.find (per_cu
);
24780 if (it
== m_dwarf2_cus
.end ())
24785 m_dwarf2_cus
.erase (it
);
24788 dwarf2_per_objfile::~dwarf2_per_objfile ()
24793 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24794 We store these in a hash table separate from the DIEs, and preserve them
24795 when the DIEs are flushed out of cache.
24797 The CU "per_cu" pointer is needed because offset alone is not enough to
24798 uniquely identify the type. A file may have multiple .debug_types sections,
24799 or the type may come from a DWO file. Furthermore, while it's more logical
24800 to use per_cu->section+offset, with Fission the section with the data is in
24801 the DWO file but we don't know that section at the point we need it.
24802 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24803 because we can enter the lookup routine, get_die_type_at_offset, from
24804 outside this file, and thus won't necessarily have PER_CU->cu.
24805 Fortunately, PER_CU is stable for the life of the objfile. */
24807 struct dwarf2_per_cu_offset_and_type
24809 const struct dwarf2_per_cu_data
*per_cu
;
24810 sect_offset sect_off
;
24814 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24817 per_cu_offset_and_type_hash (const void *item
)
24819 const struct dwarf2_per_cu_offset_and_type
*ofs
24820 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24822 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24825 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24828 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24830 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24831 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24832 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24833 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24835 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24836 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24839 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24840 table if necessary. For convenience, return TYPE.
24842 The DIEs reading must have careful ordering to:
24843 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24844 reading current DIE.
24845 * Not trying to dereference contents of still incompletely read in types
24846 while reading in other DIEs.
24847 * Enable referencing still incompletely read in types just by a pointer to
24848 the type without accessing its fields.
24850 Therefore caller should follow these rules:
24851 * Try to fetch any prerequisite types we may need to build this DIE type
24852 before building the type and calling set_die_type.
24853 * After building type call set_die_type for current DIE as soon as
24854 possible before fetching more types to complete the current type.
24855 * Make the type as complete as possible before fetching more types. */
24857 static struct type
*
24858 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24859 bool skip_data_location
)
24861 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24862 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24863 struct objfile
*objfile
= per_objfile
->objfile
;
24864 struct attribute
*attr
;
24865 struct dynamic_prop prop
;
24867 /* For Ada types, make sure that the gnat-specific data is always
24868 initialized (if not already set). There are a few types where
24869 we should not be doing so, because the type-specific area is
24870 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24871 where the type-specific area is used to store the floatformat).
24872 But this is not a problem, because the gnat-specific information
24873 is actually not needed for these types. */
24874 if (need_gnat_info (cu
)
24875 && type
->code () != TYPE_CODE_FUNC
24876 && type
->code () != TYPE_CODE_FLT
24877 && type
->code () != TYPE_CODE_METHODPTR
24878 && type
->code () != TYPE_CODE_MEMBERPTR
24879 && type
->code () != TYPE_CODE_METHOD
24880 && type
->code () != TYPE_CODE_FIXED_POINT
24881 && !HAVE_GNAT_AUX_INFO (type
))
24882 INIT_GNAT_SPECIFIC (type
);
24884 /* Read DW_AT_allocated and set in type. */
24885 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24888 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24889 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24890 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24893 /* Read DW_AT_associated and set in type. */
24894 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24897 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24898 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24899 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24902 /* Read DW_AT_rank and set in type. */
24903 attr
= dwarf2_attr (die
, DW_AT_rank
, cu
);
24906 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24907 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24908 type
->add_dyn_prop (DYN_PROP_RANK
, prop
);
24911 /* Read DW_AT_data_location and set in type. */
24912 if (!skip_data_location
)
24914 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24915 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24916 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24919 if (per_objfile
->die_type_hash
== NULL
)
24920 per_objfile
->die_type_hash
24921 = htab_up (htab_create_alloc (127,
24922 per_cu_offset_and_type_hash
,
24923 per_cu_offset_and_type_eq
,
24924 NULL
, xcalloc
, xfree
));
24926 ofs
.per_cu
= cu
->per_cu
;
24927 ofs
.sect_off
= die
->sect_off
;
24929 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24930 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24932 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24933 sect_offset_str (die
->sect_off
));
24934 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24935 struct dwarf2_per_cu_offset_and_type
);
24940 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24941 or return NULL if the die does not have a saved type. */
24943 static struct type
*
24944 get_die_type_at_offset (sect_offset sect_off
,
24945 dwarf2_per_cu_data
*per_cu
,
24946 dwarf2_per_objfile
*per_objfile
)
24948 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24950 if (per_objfile
->die_type_hash
== NULL
)
24953 ofs
.per_cu
= per_cu
;
24954 ofs
.sect_off
= sect_off
;
24955 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24956 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24963 /* Look up the type for DIE in CU in die_type_hash,
24964 or return NULL if DIE does not have a saved type. */
24966 static struct type
*
24967 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24969 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24972 /* Trivial hash function for partial_die_info: the hash value of a DIE
24973 is its offset in .debug_info for this objfile. */
24976 partial_die_hash (const void *item
)
24978 const struct partial_die_info
*part_die
24979 = (const struct partial_die_info
*) item
;
24981 return to_underlying (part_die
->sect_off
);
24984 /* Trivial comparison function for partial_die_info structures: two DIEs
24985 are equal if they have the same offset. */
24988 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24990 const struct partial_die_info
*part_die_lhs
24991 = (const struct partial_die_info
*) item_lhs
;
24992 const struct partial_die_info
*part_die_rhs
24993 = (const struct partial_die_info
*) item_rhs
;
24995 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24998 struct cmd_list_element
*set_dwarf_cmdlist
;
24999 struct cmd_list_element
*show_dwarf_cmdlist
;
25002 show_check_physname (struct ui_file
*file
, int from_tty
,
25003 struct cmd_list_element
*c
, const char *value
)
25006 _("Whether to check \"physname\" is %s.\n"),
25010 void _initialize_dwarf2_read ();
25012 _initialize_dwarf2_read ()
25014 add_setshow_prefix_cmd ("dwarf", class_maintenance
,
25016 Set DWARF specific variables.\n\
25017 Configure DWARF variables such as the cache size."),
25019 Show DWARF specific variables.\n\
25020 Show DWARF variables such as the cache size."),
25021 &set_dwarf_cmdlist
, &show_dwarf_cmdlist
,
25022 &maintenance_set_cmdlist
, &maintenance_show_cmdlist
);
25024 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25025 &dwarf_max_cache_age
, _("\
25026 Set the upper bound on the age of cached DWARF compilation units."), _("\
25027 Show the upper bound on the age of cached DWARF compilation units."), _("\
25028 A higher limit means that cached compilation units will be stored\n\
25029 in memory longer, and more total memory will be used. Zero disables\n\
25030 caching, which can slow down startup."),
25032 show_dwarf_max_cache_age
,
25033 &set_dwarf_cmdlist
,
25034 &show_dwarf_cmdlist
);
25036 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25037 Set debugging of the DWARF reader."), _("\
25038 Show debugging of the DWARF reader."), _("\
25039 When enabled (non-zero), debugging messages are printed during DWARF\n\
25040 reading and symtab expansion. A value of 1 (one) provides basic\n\
25041 information. A value greater than 1 provides more verbose information."),
25044 &setdebuglist
, &showdebuglist
);
25046 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25047 Set debugging of the DWARF DIE reader."), _("\
25048 Show debugging of the DWARF DIE reader."), _("\
25049 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25050 The value is the maximum depth to print."),
25053 &setdebuglist
, &showdebuglist
);
25055 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25056 Set debugging of the dwarf line reader."), _("\
25057 Show debugging of the dwarf line reader."), _("\
25058 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25059 A value of 1 (one) provides basic information.\n\
25060 A value greater than 1 provides more verbose information."),
25063 &setdebuglist
, &showdebuglist
);
25065 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25066 Set cross-checking of \"physname\" code against demangler."), _("\
25067 Show cross-checking of \"physname\" code against demangler."), _("\
25068 When enabled, GDB's internal \"physname\" code is checked against\n\
25070 NULL
, show_check_physname
,
25071 &setdebuglist
, &showdebuglist
);
25073 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25074 no_class
, &use_deprecated_index_sections
, _("\
25075 Set whether to use deprecated gdb_index sections."), _("\
25076 Show whether to use deprecated gdb_index sections."), _("\
25077 When enabled, deprecated .gdb_index sections are used anyway.\n\
25078 Normally they are ignored either because of a missing feature or\n\
25079 performance issue.\n\
25080 Warning: This option must be enabled before gdb reads the file."),
25083 &setlist
, &showlist
);
25085 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25086 &dwarf2_locexpr_funcs
);
25087 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25088 &dwarf2_loclist_funcs
);
25090 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25091 &dwarf2_block_frame_base_locexpr_funcs
);
25092 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25093 &dwarf2_block_frame_base_loclist_funcs
);
25096 selftests::register_test ("dw2_expand_symtabs_matching",
25097 selftests::dw2_expand_symtabs_matching::run_test
);
25098 selftests::register_test ("dwarf2_find_containing_comp_unit",
25099 selftests::find_containing_comp_unit::run_test
);