1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2021 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit-head.h"
36 #include "dwarf2/cu.h"
37 #include "dwarf2/index-cache.h"
38 #include "dwarf2/index-common.h"
39 #include "dwarf2/leb.h"
40 #include "dwarf2/line-header.h"
41 #include "dwarf2/dwz.h"
42 #include "dwarf2/macro.h"
43 #include "dwarf2/die.h"
44 #include "dwarf2/sect-names.h"
45 #include "dwarf2/stringify.h"
46 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
91 #include <unordered_set>
93 /* When == 1, print basic high level tracing messages.
94 When > 1, be more verbose.
95 This is in contrast to the low level DIE reading of dwarf_die_debug. */
96 static unsigned int dwarf_read_debug
= 0;
98 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
100 #define dwarf_read_debug_printf(fmt, ...) \
101 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
104 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
106 #define dwarf_read_debug_printf_v(fmt, ...) \
107 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
110 /* When non-zero, dump DIEs after they are read in. */
111 static unsigned int dwarf_die_debug
= 0;
113 /* When non-zero, dump line number entries as they are read in. */
114 unsigned int dwarf_line_debug
= 0;
116 /* When true, cross-check physname against demangler. */
117 static bool check_physname
= false;
119 /* When true, do not reject deprecated .gdb_index sections. */
120 static bool use_deprecated_index_sections
= false;
122 /* This is used to store the data that is always per objfile. */
123 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
125 /* These are used to store the dwarf2_per_bfd objects.
127 objfiles having the same BFD, which doesn't require relocations, are going to
128 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
130 Other objfiles are not going to share a dwarf2_per_bfd with any other
131 objfiles, so they'll have their own version kept in the _objfile_data_key
133 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
134 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
136 /* The "aclass" indices for various kinds of computed DWARF symbols. */
138 static int dwarf2_locexpr_index
;
139 static int dwarf2_loclist_index
;
140 static int dwarf2_locexpr_block_index
;
141 static int dwarf2_loclist_block_index
;
143 /* Size of .debug_loclists section header for 32-bit DWARF format. */
144 #define LOCLIST_HEADER_SIZE32 12
146 /* Size of .debug_loclists section header for 64-bit DWARF format. */
147 #define LOCLIST_HEADER_SIZE64 20
149 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
150 #define RNGLIST_HEADER_SIZE32 12
152 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
153 #define RNGLIST_HEADER_SIZE64 20
155 /* An index into a (C++) symbol name component in a symbol name as
156 recorded in the mapped_index's symbol table. For each C++ symbol
157 in the symbol table, we record one entry for the start of each
158 component in the symbol in a table of name components, and then
159 sort the table, in order to be able to binary search symbol names,
160 ignoring leading namespaces, both completion and regular look up.
161 For example, for symbol "A::B::C", we'll have an entry that points
162 to "A::B::C", another that points to "B::C", and another for "C".
163 Note that function symbols in GDB index have no parameter
164 information, just the function/method names. You can convert a
165 name_component to a "const char *" using the
166 'mapped_index::symbol_name_at(offset_type)' method. */
168 struct name_component
170 /* Offset in the symbol name where the component starts. Stored as
171 a (32-bit) offset instead of a pointer to save memory and improve
172 locality on 64-bit architectures. */
173 offset_type name_offset
;
175 /* The symbol's index in the symbol and constant pool tables of a
180 /* Base class containing bits shared by both .gdb_index and
181 .debug_name indexes. */
183 struct mapped_index_base
185 mapped_index_base () = default;
186 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
188 /* The name_component table (a sorted vector). See name_component's
189 description above. */
190 std::vector
<name_component
> name_components
;
192 /* How NAME_COMPONENTS is sorted. */
193 enum case_sensitivity name_components_casing
;
195 /* Return the number of names in the symbol table. */
196 virtual size_t symbol_name_count () const = 0;
198 /* Get the name of the symbol at IDX in the symbol table. */
199 virtual const char *symbol_name_at
200 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
202 /* Return whether the name at IDX in the symbol table should be
204 virtual bool symbol_name_slot_invalid (offset_type idx
) const
209 /* Build the symbol name component sorted vector, if we haven't
211 void build_name_components (dwarf2_per_objfile
*per_objfile
);
213 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
214 possible matches for LN_NO_PARAMS in the name component
216 std::pair
<std::vector
<name_component
>::const_iterator
,
217 std::vector
<name_component
>::const_iterator
>
218 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
220 dwarf2_per_objfile
*per_objfile
) const;
222 /* Prevent deleting/destroying via a base class pointer. */
224 ~mapped_index_base() = default;
227 /* This is a view into the index that converts from bytes to an
228 offset_type, and allows indexing. Unaligned bytes are specifically
229 allowed here, and handled via unpacking. */
234 offset_view () = default;
236 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
241 /* Extract the INDEXth offset_type from the array. */
242 offset_type
operator[] (size_t index
) const
244 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
245 return (offset_type
) extract_unsigned_integer (bytes
,
246 sizeof (offset_type
),
250 /* Return the number of offset_types in this array. */
253 return m_bytes
.size () / sizeof (offset_type
);
256 /* Return true if this view is empty. */
259 return m_bytes
.empty ();
263 /* The underlying bytes. */
264 gdb::array_view
<const gdb_byte
> m_bytes
;
267 /* A description of the mapped index. The file format is described in
268 a comment by the code that writes the index. */
269 struct mapped_index final
: public mapped_index_base
271 /* Index data format version. */
274 /* The address table data. */
275 gdb::array_view
<const gdb_byte
> address_table
;
277 /* The symbol table, implemented as a hash table. */
278 offset_view symbol_table
;
280 /* A pointer to the constant pool. */
281 gdb::array_view
<const gdb_byte
> constant_pool
;
283 /* Return the index into the constant pool of the name of the IDXth
284 symbol in the symbol table. */
285 offset_type
symbol_name_index (offset_type idx
) const
287 return symbol_table
[2 * idx
];
290 /* Return the index into the constant pool of the CU vector of the
291 IDXth symbol in the symbol table. */
292 offset_type
symbol_vec_index (offset_type idx
) const
294 return symbol_table
[2 * idx
+ 1];
297 bool symbol_name_slot_invalid (offset_type idx
) const override
299 return (symbol_name_index (idx
) == 0
300 && symbol_vec_index (idx
) == 0);
303 /* Convenience method to get at the name of the symbol at IDX in the
305 const char *symbol_name_at
306 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
308 return (const char *) (this->constant_pool
.data ()
309 + symbol_name_index (idx
));
312 size_t symbol_name_count () const override
313 { return this->symbol_table
.size () / 2; }
316 /* A description of the mapped .debug_names.
317 Uninitialized map has CU_COUNT 0. */
318 struct mapped_debug_names final
: public mapped_index_base
320 bfd_endian dwarf5_byte_order
;
321 bool dwarf5_is_dwarf64
;
322 bool augmentation_is_gdb
;
324 uint32_t cu_count
= 0;
325 uint32_t tu_count
, bucket_count
, name_count
;
326 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
327 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
328 const gdb_byte
*name_table_string_offs_reordered
;
329 const gdb_byte
*name_table_entry_offs_reordered
;
330 const gdb_byte
*entry_pool
;
337 /* Attribute name DW_IDX_*. */
340 /* Attribute form DW_FORM_*. */
343 /* Value if FORM is DW_FORM_implicit_const. */
344 LONGEST implicit_const
;
346 std::vector
<attr
> attr_vec
;
349 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
351 const char *namei_to_name
352 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
354 /* Implementation of the mapped_index_base virtual interface, for
355 the name_components cache. */
357 const char *symbol_name_at
358 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
359 { return namei_to_name (idx
, per_objfile
); }
361 size_t symbol_name_count () const override
362 { return this->name_count
; }
365 /* See dwarf2read.h. */
368 get_dwarf2_per_objfile (struct objfile
*objfile
)
370 return dwarf2_objfile_data_key
.get (objfile
);
373 /* Default names of the debugging sections. */
375 /* Note that if the debugging section has been compressed, it might
376 have a name like .zdebug_info. */
378 const struct dwarf2_debug_sections dwarf2_elf_names
=
380 { ".debug_info", ".zdebug_info" },
381 { ".debug_abbrev", ".zdebug_abbrev" },
382 { ".debug_line", ".zdebug_line" },
383 { ".debug_loc", ".zdebug_loc" },
384 { ".debug_loclists", ".zdebug_loclists" },
385 { ".debug_macinfo", ".zdebug_macinfo" },
386 { ".debug_macro", ".zdebug_macro" },
387 { ".debug_str", ".zdebug_str" },
388 { ".debug_str_offsets", ".zdebug_str_offsets" },
389 { ".debug_line_str", ".zdebug_line_str" },
390 { ".debug_ranges", ".zdebug_ranges" },
391 { ".debug_rnglists", ".zdebug_rnglists" },
392 { ".debug_types", ".zdebug_types" },
393 { ".debug_addr", ".zdebug_addr" },
394 { ".debug_frame", ".zdebug_frame" },
395 { ".eh_frame", NULL
},
396 { ".gdb_index", ".zgdb_index" },
397 { ".debug_names", ".zdebug_names" },
398 { ".debug_aranges", ".zdebug_aranges" },
402 /* List of DWO/DWP sections. */
404 static const struct dwop_section_names
406 struct dwarf2_section_names abbrev_dwo
;
407 struct dwarf2_section_names info_dwo
;
408 struct dwarf2_section_names line_dwo
;
409 struct dwarf2_section_names loc_dwo
;
410 struct dwarf2_section_names loclists_dwo
;
411 struct dwarf2_section_names macinfo_dwo
;
412 struct dwarf2_section_names macro_dwo
;
413 struct dwarf2_section_names rnglists_dwo
;
414 struct dwarf2_section_names str_dwo
;
415 struct dwarf2_section_names str_offsets_dwo
;
416 struct dwarf2_section_names types_dwo
;
417 struct dwarf2_section_names cu_index
;
418 struct dwarf2_section_names tu_index
;
422 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
423 { ".debug_info.dwo", ".zdebug_info.dwo" },
424 { ".debug_line.dwo", ".zdebug_line.dwo" },
425 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
426 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
427 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
428 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
429 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
430 { ".debug_str.dwo", ".zdebug_str.dwo" },
431 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
432 { ".debug_types.dwo", ".zdebug_types.dwo" },
433 { ".debug_cu_index", ".zdebug_cu_index" },
434 { ".debug_tu_index", ".zdebug_tu_index" },
437 /* local data types */
439 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
440 begin with a header, which contains the following information. */
441 struct loclists_rnglists_header
443 /* A 4-byte or 12-byte length containing the length of the
444 set of entries for this compilation unit, not including the
445 length field itself. */
448 /* A 2-byte version identifier. */
451 /* A 1-byte unsigned integer containing the size in bytes of an address on
452 the target system. */
453 unsigned char addr_size
;
455 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
456 on the target system. */
457 unsigned char segment_collector_size
;
459 /* A 4-byte count of the number of offsets that follow the header. */
460 unsigned int offset_entry_count
;
463 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
464 This includes type_unit_group and quick_file_names. */
466 struct stmt_list_hash
468 /* The DWO unit this table is from or NULL if there is none. */
469 struct dwo_unit
*dwo_unit
;
471 /* Offset in .debug_line or .debug_line.dwo. */
472 sect_offset line_sect_off
;
475 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
476 an object of this type. This contains elements of type unit groups
477 that can be shared across objfiles. The non-shareable parts are in
478 type_unit_group_unshareable. */
480 struct type_unit_group
: public dwarf2_per_cu_data
482 /* The TUs that share this DW_AT_stmt_list entry.
483 This is added to while parsing type units to build partial symtabs,
484 and is deleted afterwards and not used again. */
485 std::vector
<signatured_type
*> *tus
= nullptr;
487 /* The data used to construct the hash key. */
488 struct stmt_list_hash hash
{};
491 /* These sections are what may appear in a (real or virtual) DWO file. */
495 struct dwarf2_section_info abbrev
;
496 struct dwarf2_section_info line
;
497 struct dwarf2_section_info loc
;
498 struct dwarf2_section_info loclists
;
499 struct dwarf2_section_info macinfo
;
500 struct dwarf2_section_info macro
;
501 struct dwarf2_section_info rnglists
;
502 struct dwarf2_section_info str
;
503 struct dwarf2_section_info str_offsets
;
504 /* In the case of a virtual DWO file, these two are unused. */
505 struct dwarf2_section_info info
;
506 std::vector
<dwarf2_section_info
> types
;
509 /* CUs/TUs in DWP/DWO files. */
513 /* Backlink to the containing struct dwo_file. */
514 struct dwo_file
*dwo_file
;
516 /* The "id" that distinguishes this CU/TU.
517 .debug_info calls this "dwo_id", .debug_types calls this "signature".
518 Since signatures came first, we stick with it for consistency. */
521 /* The section this CU/TU lives in, in the DWO file. */
522 struct dwarf2_section_info
*section
;
524 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
525 sect_offset sect_off
;
528 /* For types, offset in the type's DIE of the type defined by this TU. */
529 cu_offset type_offset_in_tu
;
532 /* include/dwarf2.h defines the DWP section codes.
533 It defines a max value but it doesn't define a min value, which we
534 use for error checking, so provide one. */
536 enum dwp_v2_section_ids
541 /* Data for one DWO file.
543 This includes virtual DWO files (a virtual DWO file is a DWO file as it
544 appears in a DWP file). DWP files don't really have DWO files per se -
545 comdat folding of types "loses" the DWO file they came from, and from
546 a high level view DWP files appear to contain a mass of random types.
547 However, to maintain consistency with the non-DWP case we pretend DWP
548 files contain virtual DWO files, and we assign each TU with one virtual
549 DWO file (generally based on the line and abbrev section offsets -
550 a heuristic that seems to work in practice). */
554 dwo_file () = default;
555 DISABLE_COPY_AND_ASSIGN (dwo_file
);
557 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
558 For virtual DWO files the name is constructed from the section offsets
559 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
560 from related CU+TUs. */
561 const char *dwo_name
= nullptr;
563 /* The DW_AT_comp_dir attribute. */
564 const char *comp_dir
= nullptr;
566 /* The bfd, when the file is open. Otherwise this is NULL.
567 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
568 gdb_bfd_ref_ptr dbfd
;
570 /* The sections that make up this DWO file.
571 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
572 sections (for lack of a better name). */
573 struct dwo_sections sections
{};
575 /* The CUs in the file.
576 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
577 an extension to handle LLVM's Link Time Optimization output (where
578 multiple source files may be compiled into a single object/dwo pair). */
581 /* Table of TUs in the file.
582 Each element is a struct dwo_unit. */
586 /* These sections are what may appear in a DWP file. */
590 /* These are used by all DWP versions (1, 2 and 5). */
591 struct dwarf2_section_info str
;
592 struct dwarf2_section_info cu_index
;
593 struct dwarf2_section_info tu_index
;
595 /* These are only used by DWP version 2 and version 5 files.
596 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
597 sections are referenced by section number, and are not recorded here.
598 In DWP version 2 or 5 there is at most one copy of all these sections,
599 each section being (effectively) comprised of the concatenation of all of
600 the individual sections that exist in the version 1 format.
601 To keep the code simple we treat each of these concatenated pieces as a
602 section itself (a virtual section?). */
603 struct dwarf2_section_info abbrev
;
604 struct dwarf2_section_info info
;
605 struct dwarf2_section_info line
;
606 struct dwarf2_section_info loc
;
607 struct dwarf2_section_info loclists
;
608 struct dwarf2_section_info macinfo
;
609 struct dwarf2_section_info macro
;
610 struct dwarf2_section_info rnglists
;
611 struct dwarf2_section_info str_offsets
;
612 struct dwarf2_section_info types
;
615 /* These sections are what may appear in a virtual DWO file in DWP version 1.
616 A virtual DWO file is a DWO file as it appears in a DWP file. */
618 struct virtual_v1_dwo_sections
620 struct dwarf2_section_info abbrev
;
621 struct dwarf2_section_info line
;
622 struct dwarf2_section_info loc
;
623 struct dwarf2_section_info macinfo
;
624 struct dwarf2_section_info macro
;
625 struct dwarf2_section_info str_offsets
;
626 /* Each DWP hash table entry records one CU or one TU.
627 That is recorded here, and copied to dwo_unit.section. */
628 struct dwarf2_section_info info_or_types
;
631 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
632 In version 2, the sections of the DWO files are concatenated together
633 and stored in one section of that name. Thus each ELF section contains
634 several "virtual" sections. */
636 struct virtual_v2_or_v5_dwo_sections
638 bfd_size_type abbrev_offset
;
639 bfd_size_type abbrev_size
;
641 bfd_size_type line_offset
;
642 bfd_size_type line_size
;
644 bfd_size_type loc_offset
;
645 bfd_size_type loc_size
;
647 bfd_size_type loclists_offset
;
648 bfd_size_type loclists_size
;
650 bfd_size_type macinfo_offset
;
651 bfd_size_type macinfo_size
;
653 bfd_size_type macro_offset
;
654 bfd_size_type macro_size
;
656 bfd_size_type rnglists_offset
;
657 bfd_size_type rnglists_size
;
659 bfd_size_type str_offsets_offset
;
660 bfd_size_type str_offsets_size
;
662 /* Each DWP hash table entry records one CU or one TU.
663 That is recorded here, and copied to dwo_unit.section. */
664 bfd_size_type info_or_types_offset
;
665 bfd_size_type info_or_types_size
;
668 /* Contents of DWP hash tables. */
670 struct dwp_hash_table
672 uint32_t version
, nr_columns
;
673 uint32_t nr_units
, nr_slots
;
674 const gdb_byte
*hash_table
, *unit_table
;
679 const gdb_byte
*indices
;
683 /* This is indexed by column number and gives the id of the section
685 #define MAX_NR_V2_DWO_SECTIONS \
686 (1 /* .debug_info or .debug_types */ \
687 + 1 /* .debug_abbrev */ \
688 + 1 /* .debug_line */ \
689 + 1 /* .debug_loc */ \
690 + 1 /* .debug_str_offsets */ \
691 + 1 /* .debug_macro or .debug_macinfo */)
692 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
693 const gdb_byte
*offsets
;
694 const gdb_byte
*sizes
;
698 /* This is indexed by column number and gives the id of the section
700 #define MAX_NR_V5_DWO_SECTIONS \
701 (1 /* .debug_info */ \
702 + 1 /* .debug_abbrev */ \
703 + 1 /* .debug_line */ \
704 + 1 /* .debug_loclists */ \
705 + 1 /* .debug_str_offsets */ \
706 + 1 /* .debug_macro */ \
707 + 1 /* .debug_rnglists */)
708 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
709 const gdb_byte
*offsets
;
710 const gdb_byte
*sizes
;
715 /* Data for one DWP file. */
719 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
721 dbfd (std::move (abfd
))
725 /* Name of the file. */
728 /* File format version. */
732 gdb_bfd_ref_ptr dbfd
;
734 /* Section info for this file. */
735 struct dwp_sections sections
{};
737 /* Table of CUs in the file. */
738 const struct dwp_hash_table
*cus
= nullptr;
740 /* Table of TUs in the file. */
741 const struct dwp_hash_table
*tus
= nullptr;
743 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
747 /* Table to map ELF section numbers to their sections.
748 This is only needed for the DWP V1 file format. */
749 unsigned int num_sections
= 0;
750 asection
**elf_sections
= nullptr;
753 /* Struct used to pass misc. parameters to read_die_and_children, et
754 al. which are used for both .debug_info and .debug_types dies.
755 All parameters here are unchanging for the life of the call. This
756 struct exists to abstract away the constant parameters of die reading. */
758 struct die_reader_specs
760 /* The bfd of die_section. */
763 /* The CU of the DIE we are parsing. */
764 struct dwarf2_cu
*cu
;
766 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
767 struct dwo_file
*dwo_file
;
769 /* The section the die comes from.
770 This is either .debug_info or .debug_types, or the .dwo variants. */
771 struct dwarf2_section_info
*die_section
;
773 /* die_section->buffer. */
774 const gdb_byte
*buffer
;
776 /* The end of the buffer. */
777 const gdb_byte
*buffer_end
;
779 /* The abbreviation table to use when reading the DIEs. */
780 struct abbrev_table
*abbrev_table
;
783 /* A subclass of die_reader_specs that holds storage and has complex
784 constructor and destructor behavior. */
786 class cutu_reader
: public die_reader_specs
790 cutu_reader (dwarf2_per_cu_data
*this_cu
,
791 dwarf2_per_objfile
*per_objfile
,
792 struct abbrev_table
*abbrev_table
,
793 dwarf2_cu
*existing_cu
,
796 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
797 dwarf2_per_objfile
*per_objfile
,
798 struct dwarf2_cu
*parent_cu
= nullptr,
799 struct dwo_file
*dwo_file
= nullptr);
801 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
803 const gdb_byte
*info_ptr
= nullptr;
804 struct die_info
*comp_unit_die
= nullptr;
805 bool dummy_p
= false;
807 /* Release the new CU, putting it on the chain. This cannot be done
812 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
813 dwarf2_per_objfile
*per_objfile
,
814 dwarf2_cu
*existing_cu
);
816 struct dwarf2_per_cu_data
*m_this_cu
;
817 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
819 /* The ordinary abbreviation table. */
820 abbrev_table_up m_abbrev_table_holder
;
822 /* The DWO abbreviation table. */
823 abbrev_table_up m_dwo_abbrev_table
;
826 /* When we construct a partial symbol table entry we only
827 need this much information. */
828 struct partial_die_info
: public allocate_on_obstack
830 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
832 /* Disable assign but still keep copy ctor, which is needed
833 load_partial_dies. */
834 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
835 partial_die_info (const partial_die_info
&) = default;
837 /* Adjust the partial die before generating a symbol for it. This
838 function may set the is_external flag or change the DIE's
840 void fixup (struct dwarf2_cu
*cu
);
842 /* Read a minimal amount of information into the minimal die
844 const gdb_byte
*read (const struct die_reader_specs
*reader
,
845 const struct abbrev_info
&abbrev
,
846 const gdb_byte
*info_ptr
);
848 /* Compute the name of this partial DIE. This memoizes the
849 result, so it is safe to call multiple times. */
850 const char *name (dwarf2_cu
*cu
);
852 /* Offset of this DIE. */
853 const sect_offset sect_off
;
855 /* DWARF-2 tag for this DIE. */
856 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
858 /* Assorted flags describing the data found in this DIE. */
859 const unsigned int has_children
: 1;
861 unsigned int is_external
: 1;
862 unsigned int is_declaration
: 1;
863 unsigned int has_type
: 1;
864 unsigned int has_specification
: 1;
865 unsigned int has_pc_info
: 1;
866 unsigned int has_range_info
: 1;
867 unsigned int may_be_inlined
: 1;
869 /* This DIE has been marked DW_AT_main_subprogram. */
870 unsigned int main_subprogram
: 1;
872 /* Flag set if the SCOPE field of this structure has been
874 unsigned int scope_set
: 1;
876 /* Flag set if the DIE has a byte_size attribute. */
877 unsigned int has_byte_size
: 1;
879 /* Flag set if the DIE has a DW_AT_const_value attribute. */
880 unsigned int has_const_value
: 1;
882 /* Flag set if any of the DIE's children are template arguments. */
883 unsigned int has_template_arguments
: 1;
885 /* Flag set if fixup has been called on this die. */
886 unsigned int fixup_called
: 1;
888 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
889 unsigned int is_dwz
: 1;
891 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
892 unsigned int spec_is_dwz
: 1;
894 unsigned int canonical_name
: 1;
896 /* The name of this DIE. Normally the value of DW_AT_name, but
897 sometimes a default name for unnamed DIEs. */
898 const char *raw_name
= nullptr;
900 /* The linkage name, if present. */
901 const char *linkage_name
= nullptr;
903 /* The scope to prepend to our children. This is generally
904 allocated on the comp_unit_obstack, so will disappear
905 when this compilation unit leaves the cache. */
906 const char *scope
= nullptr;
908 /* Some data associated with the partial DIE. The tag determines
909 which field is live. */
912 /* The location description associated with this DIE, if any. */
913 struct dwarf_block
*locdesc
;
914 /* The offset of an import, for DW_TAG_imported_unit. */
915 sect_offset sect_off
;
920 /* If HAS_PC_INFO, the PC range associated with this DIE. */
924 CORE_ADDR highpc
= 0;
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;
980 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
981 but this would require a corresponding change in unpack_field_as_long
983 static int bits_per_byte
= 8;
985 struct variant_part_builder
;
987 /* When reading a variant, we track a bit more information about the
988 field, and store it in an object of this type. */
992 int first_field
= -1;
995 /* A variant can contain other variant parts. */
996 std::vector
<variant_part_builder
> variant_parts
;
998 /* If we see a DW_TAG_variant, then this will be set if this is the
1000 bool default_branch
= false;
1001 /* If we see a DW_AT_discr_value, then this will be the discriminant
1003 ULONGEST discriminant_value
= 0;
1004 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1006 struct dwarf_block
*discr_list_data
= nullptr;
1009 /* This represents a DW_TAG_variant_part. */
1011 struct variant_part_builder
1013 /* The offset of the discriminant field. */
1014 sect_offset discriminant_offset
{};
1016 /* Variants that are direct children of this variant part. */
1017 std::vector
<variant_field
> variants
;
1019 /* True if we're currently reading a variant. */
1020 bool processing_variant
= false;
1025 int accessibility
= 0;
1027 /* Variant parts need to find the discriminant, which is a DIE
1028 reference. We track the section offset of each field to make
1031 struct field field
{};
1036 const char *name
= nullptr;
1037 std::vector
<struct fn_field
> fnfields
;
1040 /* The routines that read and process dies for a C struct or C++ class
1041 pass lists of data member fields and lists of member function fields
1042 in an instance of a field_info structure, as defined below. */
1045 /* List of data member and baseclasses fields. */
1046 std::vector
<struct nextfield
> fields
;
1047 std::vector
<struct nextfield
> baseclasses
;
1049 /* Set if the accessibility of one of the fields is not public. */
1050 bool non_public_fields
= false;
1052 /* Member function fieldlist array, contains name of possibly overloaded
1053 member function, number of overloaded member functions and a pointer
1054 to the head of the member function field chain. */
1055 std::vector
<struct fnfieldlist
> fnfieldlists
;
1057 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1058 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1059 std::vector
<struct decl_field
> typedef_field_list
;
1061 /* Nested types defined by this class and the number of elements in this
1063 std::vector
<struct decl_field
> nested_types_list
;
1065 /* If non-null, this is the variant part we are currently
1067 variant_part_builder
*current_variant_part
= nullptr;
1068 /* This holds all the top-level variant parts attached to the type
1070 std::vector
<variant_part_builder
> variant_parts
;
1072 /* Return the total number of fields (including baseclasses). */
1073 int nfields () const
1075 return fields
.size () + baseclasses
.size ();
1079 /* Loaded secondary compilation units are kept in memory until they
1080 have not been referenced for the processing of this many
1081 compilation units. Set this to zero to disable caching. Cache
1082 sizes of up to at least twenty will improve startup time for
1083 typical inter-CU-reference binaries, at an obvious memory cost. */
1084 static int dwarf_max_cache_age
= 5;
1086 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1087 struct cmd_list_element
*c
, const char *value
)
1089 fprintf_filtered (file
, _("The upper bound on the age of cached "
1090 "DWARF compilation units is %s.\n"),
1094 /* local function prototypes */
1096 static void dwarf2_find_base_address (struct die_info
*die
,
1097 struct dwarf2_cu
*cu
);
1099 static dwarf2_psymtab
*create_partial_symtab
1100 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1103 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1104 const gdb_byte
*info_ptr
,
1105 struct die_info
*type_unit_die
);
1107 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1109 static void scan_partial_symbols (struct partial_die_info
*,
1110 CORE_ADDR
*, CORE_ADDR
*,
1111 int, struct dwarf2_cu
*);
1113 static void add_partial_symbol (struct partial_die_info
*,
1114 struct dwarf2_cu
*);
1116 static void add_partial_namespace (struct partial_die_info
*pdi
,
1117 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1118 int set_addrmap
, struct dwarf2_cu
*cu
);
1120 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1121 CORE_ADDR
*highpc
, int set_addrmap
,
1122 struct dwarf2_cu
*cu
);
1124 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1125 struct dwarf2_cu
*cu
);
1127 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1128 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1129 int need_pc
, struct dwarf2_cu
*cu
);
1131 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1133 static struct partial_die_info
*load_partial_dies
1134 (const struct die_reader_specs
*, const gdb_byte
*, int);
1136 /* A pair of partial_die_info and compilation unit. */
1137 struct cu_partial_die_info
1139 /* The compilation unit of the partial_die_info. */
1140 struct dwarf2_cu
*cu
;
1141 /* A partial_die_info. */
1142 struct partial_die_info
*pdi
;
1144 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1150 cu_partial_die_info () = delete;
1153 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1154 struct dwarf2_cu
*);
1156 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1158 const struct attr_abbrev
*,
1161 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1162 struct attribute
*attr
, dwarf_tag tag
);
1164 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1166 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1167 dwarf2_section_info
*, sect_offset
);
1169 static const char *read_indirect_string
1170 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1171 const struct comp_unit_head
*, unsigned int *);
1173 static const char *read_indirect_string_at_offset
1174 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1176 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1180 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1181 ULONGEST str_index
);
1183 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1184 ULONGEST str_index
);
1186 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1187 struct dwarf2_cu
*);
1189 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1190 struct dwarf2_cu
*cu
);
1192 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1194 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1195 struct dwarf2_cu
*cu
);
1197 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1199 static struct die_info
*die_specification (struct die_info
*die
,
1200 struct dwarf2_cu
**);
1202 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1203 struct dwarf2_cu
*cu
);
1205 struct file_and_directory
;
1206 static void dwarf_decode_lines (struct line_header
*,
1207 const file_and_directory
&,
1208 struct dwarf2_cu
*, dwarf2_psymtab
*,
1209 CORE_ADDR
, int decode_mapping
);
1211 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1214 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1215 struct dwarf2_cu
*, struct symbol
* = NULL
);
1217 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1218 struct dwarf2_cu
*);
1220 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1223 struct obstack
*obstack
,
1224 struct dwarf2_cu
*cu
, LONGEST
*value
,
1225 const gdb_byte
**bytes
,
1226 struct dwarf2_locexpr_baton
**baton
);
1228 static struct type
*read_subrange_index_type (struct die_info
*die
,
1229 struct dwarf2_cu
*cu
);
1231 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1233 static int need_gnat_info (struct dwarf2_cu
*);
1235 static struct type
*die_descriptive_type (struct die_info
*,
1236 struct dwarf2_cu
*);
1238 static void set_descriptive_type (struct type
*, struct die_info
*,
1239 struct dwarf2_cu
*);
1241 static struct type
*die_containing_type (struct die_info
*,
1242 struct dwarf2_cu
*);
1244 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1245 struct dwarf2_cu
*);
1247 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1249 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1251 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1253 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1254 const char *suffix
, int physname
,
1255 struct dwarf2_cu
*cu
);
1257 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1259 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1261 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1263 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1265 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1267 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1269 /* Return the .debug_loclists section to use for cu. */
1270 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1272 /* Return the .debug_rnglists section to use for cu. */
1273 static struct dwarf2_section_info
*cu_debug_rnglists_section
1274 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1276 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1277 values. Keep the items ordered with increasing constraints compliance. */
1280 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1281 PC_BOUNDS_NOT_PRESENT
,
1283 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1284 were present but they do not form a valid range of PC addresses. */
1287 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1290 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1294 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1295 CORE_ADDR
*, CORE_ADDR
*,
1299 static void get_scope_pc_bounds (struct die_info
*,
1300 CORE_ADDR
*, CORE_ADDR
*,
1301 struct dwarf2_cu
*);
1303 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1304 CORE_ADDR
, struct dwarf2_cu
*);
1306 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1307 struct dwarf2_cu
*);
1309 static void dwarf2_attach_fields_to_type (struct field_info
*,
1310 struct type
*, struct dwarf2_cu
*);
1312 static void dwarf2_add_member_fn (struct field_info
*,
1313 struct die_info
*, struct type
*,
1314 struct dwarf2_cu
*);
1316 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1318 struct dwarf2_cu
*);
1320 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1322 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1324 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1326 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1328 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1330 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1332 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1334 static struct type
*read_module_type (struct die_info
*die
,
1335 struct dwarf2_cu
*cu
);
1337 static const char *namespace_name (struct die_info
*die
,
1338 int *is_anonymous
, struct dwarf2_cu
*);
1340 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1342 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1345 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1346 struct dwarf2_cu
*);
1348 static struct die_info
*read_die_and_siblings_1
1349 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1352 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1353 const gdb_byte
*info_ptr
,
1354 const gdb_byte
**new_info_ptr
,
1355 struct die_info
*parent
);
1357 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1358 struct die_info
**, const gdb_byte
*,
1361 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1362 struct die_info
**, const gdb_byte
*);
1364 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1366 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1369 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1371 static const char *dwarf2_full_name (const char *name
,
1372 struct die_info
*die
,
1373 struct dwarf2_cu
*cu
);
1375 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1376 struct dwarf2_cu
*cu
);
1378 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1379 struct dwarf2_cu
**);
1381 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1383 static void dump_die_for_error (struct die_info
*);
1385 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1388 /*static*/ void dump_die (struct die_info
*, int max_level
);
1390 static void store_in_ref_table (struct die_info
*,
1391 struct dwarf2_cu
*);
1393 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1394 const struct attribute
*,
1395 struct dwarf2_cu
**);
1397 static struct die_info
*follow_die_ref (struct die_info
*,
1398 const struct attribute
*,
1399 struct dwarf2_cu
**);
1401 static struct die_info
*follow_die_sig (struct die_info
*,
1402 const struct attribute
*,
1403 struct dwarf2_cu
**);
1405 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1406 struct dwarf2_cu
*);
1408 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1409 const struct attribute
*,
1410 struct dwarf2_cu
*);
1412 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1413 dwarf2_per_objfile
*per_objfile
);
1415 static void read_signatured_type (signatured_type
*sig_type
,
1416 dwarf2_per_objfile
*per_objfile
);
1418 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1419 struct die_info
*die
, struct dwarf2_cu
*cu
,
1420 struct dynamic_prop
*prop
, struct type
*type
);
1422 /* memory allocation interface */
1424 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1426 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1428 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1430 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1431 struct dwarf2_loclist_baton
*baton
,
1432 const struct attribute
*attr
);
1434 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1436 struct dwarf2_cu
*cu
,
1439 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1440 const gdb_byte
*info_ptr
,
1441 const struct abbrev_info
*abbrev
);
1443 static hashval_t
partial_die_hash (const void *item
);
1445 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1447 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1448 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1449 dwarf2_per_objfile
*per_objfile
);
1451 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1452 struct die_info
*comp_unit_die
,
1453 enum language pretend_language
);
1455 static struct type
*set_die_type (struct die_info
*, struct type
*,
1456 struct dwarf2_cu
*, bool = false);
1458 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1460 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1461 dwarf2_per_objfile
*per_objfile
,
1462 dwarf2_cu
*existing_cu
,
1464 enum language pretend_language
);
1466 static void process_full_comp_unit (dwarf2_cu
*cu
,
1467 enum language pretend_language
);
1469 static void process_full_type_unit (dwarf2_cu
*cu
,
1470 enum language pretend_language
);
1472 static struct type
*get_die_type_at_offset (sect_offset
,
1473 dwarf2_per_cu_data
*per_cu
,
1474 dwarf2_per_objfile
*per_objfile
);
1476 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1478 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1479 dwarf2_per_objfile
*per_objfile
,
1480 enum language pretend_language
);
1482 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1484 /* Class, the destructor of which frees all allocated queue entries. This
1485 will only have work to do if an error was thrown while processing the
1486 dwarf. If no error was thrown then the queue entries should have all
1487 been processed, and freed, as we went along. */
1489 class dwarf2_queue_guard
1492 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1493 : m_per_objfile (per_objfile
)
1495 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1497 m_per_objfile
->per_bfd
->queue
.emplace ();
1500 /* Free any entries remaining on the queue. There should only be
1501 entries left if we hit an error while processing the dwarf. */
1502 ~dwarf2_queue_guard ()
1504 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1506 m_per_objfile
->per_bfd
->queue
.reset ();
1509 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1512 dwarf2_per_objfile
*m_per_objfile
;
1515 dwarf2_queue_item::~dwarf2_queue_item ()
1517 /* Anything still marked queued is likely to be in an
1518 inconsistent state, so discard it. */
1521 per_objfile
->remove_cu (per_cu
);
1526 /* See dwarf2/read.h. */
1529 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1531 if (data
->is_debug_types
)
1532 delete static_cast<signatured_type
*> (data
);
1537 /* The return type of find_file_and_directory. Note, the enclosed
1538 string pointers are only valid while this object is valid. */
1540 struct file_and_directory
1542 /* The filename. This is never NULL. */
1545 /* The compilation directory. NULL if not known. If we needed to
1546 compute a new string, it will be stored in the per-BFD string
1547 bcache; otherwise, points directly to the DW_AT_comp_dir string
1548 attribute owned by the obstack that owns the DIE. */
1549 const char *comp_dir
;
1552 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1553 struct dwarf2_cu
*cu
);
1555 static const char *compute_include_file_name
1556 (const struct line_header
*lh
,
1557 const file_entry
&fe
,
1558 const file_and_directory
&cu_info
,
1559 gdb::unique_xmalloc_ptr
<char> *name_holder
);
1561 static htab_up
allocate_signatured_type_table ();
1563 static htab_up
allocate_dwo_unit_table ();
1565 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1566 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1567 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1569 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1571 static struct dwo_unit
*lookup_dwo_comp_unit
1572 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1573 ULONGEST signature
);
1575 static struct dwo_unit
*lookup_dwo_type_unit
1576 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1578 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1580 /* A unique pointer to a dwo_file. */
1582 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1584 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1586 static void check_producer (struct dwarf2_cu
*cu
);
1588 /* Various complaints about symbol reading that don't abort the process. */
1591 dwarf2_debug_line_missing_file_complaint (void)
1593 complaint (_(".debug_line section has line data without a file"));
1597 dwarf2_debug_line_missing_end_sequence_complaint (void)
1599 complaint (_(".debug_line section has line "
1600 "program sequence without an end"));
1604 dwarf2_complex_location_expr_complaint (void)
1606 complaint (_("location expression too complex"));
1610 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1613 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1618 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1620 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1624 /* Hash function for line_header_hash. */
1627 line_header_hash (const struct line_header
*ofs
)
1629 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1632 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1635 line_header_hash_voidp (const void *item
)
1637 const struct line_header
*ofs
= (const struct line_header
*) item
;
1639 return line_header_hash (ofs
);
1642 /* Equality function for line_header_hash. */
1645 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1647 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1648 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1650 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1651 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1656 /* An iterator for all_comp_units that is based on index. This
1657 approach makes it possible to iterate over all_comp_units safely,
1658 when some caller in the loop may add new units. */
1660 class all_comp_units_iterator
1664 all_comp_units_iterator (dwarf2_per_bfd
*per_bfd
, bool start
)
1665 : m_per_bfd (per_bfd
),
1666 m_index (start
? 0 : per_bfd
->all_comp_units
.size ())
1670 all_comp_units_iterator
&operator++ ()
1676 dwarf2_per_cu_data
*operator* () const
1678 return m_per_bfd
->get_cu (m_index
);
1681 bool operator== (const all_comp_units_iterator
&other
) const
1683 return m_index
== other
.m_index
;
1687 bool operator!= (const all_comp_units_iterator
&other
) const
1689 return m_index
!= other
.m_index
;
1694 dwarf2_per_bfd
*m_per_bfd
;
1698 /* A range adapter for the all_comp_units_iterator. */
1699 class all_comp_units_range
1703 all_comp_units_range (dwarf2_per_bfd
*per_bfd
)
1704 : m_per_bfd (per_bfd
)
1708 all_comp_units_iterator
begin ()
1710 return all_comp_units_iterator (m_per_bfd
, true);
1713 all_comp_units_iterator
end ()
1715 return all_comp_units_iterator (m_per_bfd
, false);
1720 dwarf2_per_bfd
*m_per_bfd
;
1723 /* See declaration. */
1725 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1728 can_copy (can_copy_
)
1731 names
= &dwarf2_elf_names
;
1733 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1734 locate_sections (obfd
, sec
, *names
);
1737 dwarf2_per_bfd::~dwarf2_per_bfd ()
1739 for (auto &per_cu
: all_comp_units
)
1741 per_cu
->imported_symtabs_free ();
1742 per_cu
->free_cached_file_names ();
1745 /* Everything else should be on this->obstack. */
1751 dwarf2_per_objfile::remove_all_cus ()
1753 gdb_assert (!this->per_bfd
->queue
.has_value ());
1755 for (auto pair
: m_dwarf2_cus
)
1758 m_dwarf2_cus
.clear ();
1761 /* A helper class that calls free_cached_comp_units on
1764 class free_cached_comp_units
1768 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1769 : m_per_objfile (per_objfile
)
1773 ~free_cached_comp_units ()
1775 m_per_objfile
->remove_all_cus ();
1778 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1782 dwarf2_per_objfile
*m_per_objfile
;
1788 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1790 if (per_cu
->index
< this->m_symtabs
.size ())
1791 return this->m_symtabs
[per_cu
->index
] != nullptr;
1798 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1800 if (per_cu
->index
< this->m_symtabs
.size ())
1801 return this->m_symtabs
[per_cu
->index
];
1808 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1809 compunit_symtab
*symtab
)
1811 if (per_cu
->index
>= this->m_symtabs
.size ())
1812 this->m_symtabs
.resize (per_cu
->index
+ 1);
1813 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1814 this->m_symtabs
[per_cu
->index
] = symtab
;
1817 /* Try to locate the sections we need for DWARF 2 debugging
1818 information and return true if we have enough to do something.
1819 NAMES points to the dwarf2 section names, or is NULL if the standard
1820 ELF names are used. CAN_COPY is true for formats where symbol
1821 interposition is possible and so symbol values must follow copy
1822 relocation rules. */
1825 dwarf2_has_info (struct objfile
*objfile
,
1826 const struct dwarf2_debug_sections
*names
,
1829 if (objfile
->flags
& OBJF_READNEVER
)
1832 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1834 if (per_objfile
== NULL
)
1836 dwarf2_per_bfd
*per_bfd
;
1838 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1839 BFD doesn't require relocations.
1841 We don't share with objfiles for which -readnow was requested,
1842 because it would complicate things when loading the same BFD with
1843 -readnow and then without -readnow. */
1844 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1845 && (objfile
->flags
& OBJF_READNOW
) == 0)
1847 /* See if one has been created for this BFD yet. */
1848 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1850 if (per_bfd
== nullptr)
1852 /* No, create it now. */
1853 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1854 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1859 /* No sharing possible, create one specifically for this objfile. */
1860 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1861 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1864 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1867 return (!per_objfile
->per_bfd
->info
.is_virtual
1868 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1869 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1870 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1873 /* See declaration. */
1876 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1877 const dwarf2_debug_sections
&names
)
1879 flagword aflag
= bfd_section_flags (sectp
);
1881 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1884 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1885 > bfd_get_file_size (abfd
))
1887 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1888 warning (_("Discarding section %s which has a section size (%s"
1889 ") larger than the file size [in module %s]"),
1890 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1891 bfd_get_filename (abfd
));
1893 else if (names
.info
.matches (sectp
->name
))
1895 this->info
.s
.section
= sectp
;
1896 this->info
.size
= bfd_section_size (sectp
);
1898 else if (names
.abbrev
.matches (sectp
->name
))
1900 this->abbrev
.s
.section
= sectp
;
1901 this->abbrev
.size
= bfd_section_size (sectp
);
1903 else if (names
.line
.matches (sectp
->name
))
1905 this->line
.s
.section
= sectp
;
1906 this->line
.size
= bfd_section_size (sectp
);
1908 else if (names
.loc
.matches (sectp
->name
))
1910 this->loc
.s
.section
= sectp
;
1911 this->loc
.size
= bfd_section_size (sectp
);
1913 else if (names
.loclists
.matches (sectp
->name
))
1915 this->loclists
.s
.section
= sectp
;
1916 this->loclists
.size
= bfd_section_size (sectp
);
1918 else if (names
.macinfo
.matches (sectp
->name
))
1920 this->macinfo
.s
.section
= sectp
;
1921 this->macinfo
.size
= bfd_section_size (sectp
);
1923 else if (names
.macro
.matches (sectp
->name
))
1925 this->macro
.s
.section
= sectp
;
1926 this->macro
.size
= bfd_section_size (sectp
);
1928 else if (names
.str
.matches (sectp
->name
))
1930 this->str
.s
.section
= sectp
;
1931 this->str
.size
= bfd_section_size (sectp
);
1933 else if (names
.str_offsets
.matches (sectp
->name
))
1935 this->str_offsets
.s
.section
= sectp
;
1936 this->str_offsets
.size
= bfd_section_size (sectp
);
1938 else if (names
.line_str
.matches (sectp
->name
))
1940 this->line_str
.s
.section
= sectp
;
1941 this->line_str
.size
= bfd_section_size (sectp
);
1943 else if (names
.addr
.matches (sectp
->name
))
1945 this->addr
.s
.section
= sectp
;
1946 this->addr
.size
= bfd_section_size (sectp
);
1948 else if (names
.frame
.matches (sectp
->name
))
1950 this->frame
.s
.section
= sectp
;
1951 this->frame
.size
= bfd_section_size (sectp
);
1953 else if (names
.eh_frame
.matches (sectp
->name
))
1955 this->eh_frame
.s
.section
= sectp
;
1956 this->eh_frame
.size
= bfd_section_size (sectp
);
1958 else if (names
.ranges
.matches (sectp
->name
))
1960 this->ranges
.s
.section
= sectp
;
1961 this->ranges
.size
= bfd_section_size (sectp
);
1963 else if (names
.rnglists
.matches (sectp
->name
))
1965 this->rnglists
.s
.section
= sectp
;
1966 this->rnglists
.size
= bfd_section_size (sectp
);
1968 else if (names
.types
.matches (sectp
->name
))
1970 struct dwarf2_section_info type_section
;
1972 memset (&type_section
, 0, sizeof (type_section
));
1973 type_section
.s
.section
= sectp
;
1974 type_section
.size
= bfd_section_size (sectp
);
1976 this->types
.push_back (type_section
);
1978 else if (names
.gdb_index
.matches (sectp
->name
))
1980 this->gdb_index
.s
.section
= sectp
;
1981 this->gdb_index
.size
= bfd_section_size (sectp
);
1983 else if (names
.debug_names
.matches (sectp
->name
))
1985 this->debug_names
.s
.section
= sectp
;
1986 this->debug_names
.size
= bfd_section_size (sectp
);
1988 else if (names
.debug_aranges
.matches (sectp
->name
))
1990 this->debug_aranges
.s
.section
= sectp
;
1991 this->debug_aranges
.size
= bfd_section_size (sectp
);
1994 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1995 && bfd_section_vma (sectp
) == 0)
1996 this->has_section_at_zero
= true;
1999 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2003 dwarf2_get_section_info (struct objfile
*objfile
,
2004 enum dwarf2_section_enum sect
,
2005 asection
**sectp
, const gdb_byte
**bufp
,
2006 bfd_size_type
*sizep
)
2008 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2009 struct dwarf2_section_info
*info
;
2011 /* We may see an objfile without any DWARF, in which case we just
2013 if (per_objfile
== NULL
)
2022 case DWARF2_DEBUG_FRAME
:
2023 info
= &per_objfile
->per_bfd
->frame
;
2025 case DWARF2_EH_FRAME
:
2026 info
= &per_objfile
->per_bfd
->eh_frame
;
2029 gdb_assert_not_reached ("unexpected section");
2032 info
->read (objfile
);
2034 *sectp
= info
->get_bfd_section ();
2035 *bufp
= info
->buffer
;
2036 *sizep
= info
->size
;
2040 /* DWARF quick_symbol_functions support. */
2042 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2043 unique line tables, so we maintain a separate table of all .debug_line
2044 derived entries to support the sharing.
2045 All the quick functions need is the list of file names. We discard the
2046 line_header when we're done and don't need to record it here. */
2047 struct quick_file_names
2049 /* The data used to construct the hash key. */
2050 struct stmt_list_hash hash
;
2052 /* The number of entries in file_names, real_names. */
2053 unsigned int num_file_names
;
2055 /* The CU directory, as given by DW_AT_comp_dir. May be
2057 const char *comp_dir
;
2059 /* The file names from the line table, after being run through
2061 const char **file_names
;
2063 /* The file names from the line table after being run through
2064 gdb_realpath. These are computed lazily. */
2065 const char **real_names
;
2068 /* When using the index (and thus not using psymtabs), each CU has an
2069 object of this type. This is used to hold information needed by
2070 the various "quick" methods. */
2071 struct dwarf2_per_cu_quick_data
2073 /* The file table. This can be NULL if there was no file table
2074 or it's currently not read in.
2075 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2076 struct quick_file_names
*file_names
;
2078 /* A temporary mark bit used when iterating over all CUs in
2079 expand_symtabs_matching. */
2080 unsigned int mark
: 1;
2082 /* True if we've tried to read the file table. There will be no
2083 point in trying to read it again next time. */
2084 bool files_read
: 1;
2087 /* A subclass of psymbol_functions that arranges to read the DWARF
2088 partial symbols when needed. */
2089 struct lazy_dwarf_reader
: public psymbol_functions
2091 using psymbol_functions::psymbol_functions
;
2093 bool can_lazily_read_symbols () override
2098 void read_partial_symbols (struct objfile
*objfile
) override
2100 if (dwarf2_has_info (objfile
, nullptr))
2101 dwarf2_build_psymtabs (objfile
, this);
2105 static quick_symbol_functions_up
2106 make_lazy_dwarf_reader ()
2108 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2111 struct dwarf2_base_index_functions
: public quick_symbol_functions
2113 bool has_symbols (struct objfile
*objfile
) override
;
2115 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
2117 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2119 void forget_cached_source_info (struct objfile
*objfile
) override
;
2121 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2124 bool *symbol_found_p
) override
2126 *symbol_found_p
= false;
2127 return language_unknown
;
2130 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2132 void expand_all_symtabs (struct objfile
*objfile
) override
;
2134 struct compunit_symtab
*find_pc_sect_compunit_symtab
2135 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2136 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2138 struct compunit_symtab
*find_compunit_symtab_by_address
2139 (struct objfile
*objfile
, CORE_ADDR address
) override
2144 void map_symbol_filenames (struct objfile
*objfile
,
2145 gdb::function_view
<symbol_filename_ftype
> fun
,
2146 bool need_fullname
) override
;
2149 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2151 void dump (struct objfile
*objfile
) override
;
2153 void expand_matching_symbols
2155 const lookup_name_info
&lookup_name
,
2158 symbol_compare_ftype
*ordered_compare
) override
;
2160 bool expand_symtabs_matching
2161 (struct objfile
*objfile
,
2162 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2163 const lookup_name_info
*lookup_name
,
2164 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2165 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2166 block_search_flags search_flags
,
2168 enum search_domain kind
) override
;
2171 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2173 void dump (struct objfile
*objfile
) override
;
2175 void expand_matching_symbols
2177 const lookup_name_info
&lookup_name
,
2180 symbol_compare_ftype
*ordered_compare
) override
;
2182 bool expand_symtabs_matching
2183 (struct objfile
*objfile
,
2184 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2185 const lookup_name_info
*lookup_name
,
2186 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2187 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2188 block_search_flags search_flags
,
2190 enum search_domain kind
) override
;
2193 static quick_symbol_functions_up
2194 make_dwarf_gdb_index ()
2196 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2199 static quick_symbol_functions_up
2200 make_dwarf_debug_names ()
2202 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2205 /* Utility hash function for a stmt_list_hash. */
2208 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2212 if (stmt_list_hash
->dwo_unit
!= NULL
)
2213 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2214 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2218 /* Utility equality function for a stmt_list_hash. */
2221 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2222 const struct stmt_list_hash
*rhs
)
2224 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2226 if (lhs
->dwo_unit
!= NULL
2227 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2230 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2233 /* Hash function for a quick_file_names. */
2236 hash_file_name_entry (const void *e
)
2238 const struct quick_file_names
*file_data
2239 = (const struct quick_file_names
*) e
;
2241 return hash_stmt_list_entry (&file_data
->hash
);
2244 /* Equality function for a quick_file_names. */
2247 eq_file_name_entry (const void *a
, const void *b
)
2249 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2250 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2252 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2255 /* Create a quick_file_names hash table. */
2258 create_quick_file_names_table (unsigned int nr_initial_entries
)
2260 return htab_up (htab_create_alloc (nr_initial_entries
,
2261 hash_file_name_entry
, eq_file_name_entry
,
2262 nullptr, xcalloc
, xfree
));
2265 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2266 function is unrelated to symtabs, symtab would have to be created afterwards.
2267 You should call age_cached_comp_units after processing the CU. */
2270 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2273 if (per_cu
->is_debug_types
)
2274 load_full_type_unit (per_cu
, per_objfile
);
2276 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2277 skip_partial
, language_minimal
);
2279 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2281 return nullptr; /* Dummy CU. */
2283 dwarf2_find_base_address (cu
->dies
, cu
);
2288 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2291 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2292 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2294 /* Skip type_unit_groups, reading the type units they contain
2295 is handled elsewhere. */
2296 if (per_cu
->type_unit_group_p ())
2300 /* The destructor of dwarf2_queue_guard frees any entries left on
2301 the queue. After this point we're guaranteed to leave this function
2302 with the dwarf queue empty. */
2303 dwarf2_queue_guard
q_guard (per_objfile
);
2305 if (!per_objfile
->symtab_set_p (per_cu
))
2307 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2308 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2310 /* If we just loaded a CU from a DWO, and we're working with an index
2311 that may badly handle TUs, load all the TUs in that DWO as well.
2312 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2313 if (!per_cu
->is_debug_types
2315 && cu
->dwo_unit
!= NULL
2316 && per_objfile
->per_bfd
->index_table
!= NULL
2317 && per_objfile
->per_bfd
->index_table
->version
<= 7
2318 /* DWP files aren't supported yet. */
2319 && get_dwp_file (per_objfile
) == NULL
)
2320 queue_and_load_all_dwo_tus (cu
);
2323 process_queue (per_objfile
);
2326 /* Age the cache, releasing compilation units that have not
2327 been used recently. */
2328 per_objfile
->age_comp_units ();
2331 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2332 the per-objfile for which this symtab is instantiated.
2334 Returns the resulting symbol table. */
2336 static struct compunit_symtab
*
2337 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2338 dwarf2_per_objfile
*per_objfile
,
2341 gdb_assert (per_objfile
->per_bfd
->using_index
);
2343 if (!per_objfile
->symtab_set_p (per_cu
))
2345 free_cached_comp_units
freer (per_objfile
);
2346 scoped_restore decrementer
= increment_reading_symtab ();
2347 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2348 process_cu_includes (per_objfile
);
2351 return per_objfile
->get_symtab (per_cu
);
2356 dwarf2_per_cu_data_up
2357 dwarf2_per_bfd::allocate_per_cu ()
2359 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2360 result
->per_bfd
= this;
2361 result
->index
= all_comp_units
.size ();
2368 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2370 signatured_type_up
result (new signatured_type (signature
));
2371 result
->per_bfd
= this;
2372 result
->index
= all_comp_units
.size ();
2373 result
->is_debug_types
= true;
2378 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2379 obstack, and constructed with the specified field values. */
2381 static dwarf2_per_cu_data_up
2382 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2383 struct dwarf2_section_info
*section
,
2385 sect_offset sect_off
, ULONGEST length
)
2387 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2388 the_cu
->sect_off
= sect_off
;
2389 the_cu
->length
= length
;
2390 the_cu
->section
= section
;
2391 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2392 struct dwarf2_per_cu_quick_data
);
2393 the_cu
->is_dwz
= is_dwz
;
2397 /* A helper for create_cus_from_index that handles a given list of
2401 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2402 const gdb_byte
*cu_list
, offset_type n_elements
,
2403 struct dwarf2_section_info
*section
,
2406 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2408 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2410 sect_offset sect_off
2411 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2412 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2415 dwarf2_per_cu_data_up per_cu
2416 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2418 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2422 /* Read the CU list from the mapped index, and use it to create all
2423 the CU objects for PER_BFD. */
2426 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2427 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2428 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2430 gdb_assert (per_bfd
->all_comp_units
.empty ());
2431 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2433 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2436 if (dwz_elements
== 0)
2439 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2440 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2444 /* Create the signatured type hash table from the index. */
2447 create_signatured_type_table_from_index
2448 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2449 const gdb_byte
*bytes
, offset_type elements
)
2451 htab_up sig_types_hash
= allocate_signatured_type_table ();
2453 for (offset_type i
= 0; i
< elements
; i
+= 3)
2455 signatured_type_up sig_type
;
2458 cu_offset type_offset_in_tu
;
2460 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2461 sect_offset sect_off
2462 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2464 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2466 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2469 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2470 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2471 sig_type
->section
= section
;
2472 sig_type
->sect_off
= sect_off
;
2474 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2475 struct dwarf2_per_cu_quick_data
);
2477 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2478 *slot
= sig_type
.get ();
2480 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2483 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2486 /* Create the signatured type hash table from .debug_names. */
2489 create_signatured_type_table_from_debug_names
2490 (dwarf2_per_objfile
*per_objfile
,
2491 const mapped_debug_names
&map
,
2492 struct dwarf2_section_info
*section
,
2493 struct dwarf2_section_info
*abbrev_section
)
2495 struct objfile
*objfile
= per_objfile
->objfile
;
2497 section
->read (objfile
);
2498 abbrev_section
->read (objfile
);
2500 htab_up sig_types_hash
= allocate_signatured_type_table ();
2502 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2504 signatured_type_up sig_type
;
2507 sect_offset sect_off
2508 = (sect_offset
) (extract_unsigned_integer
2509 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2511 map
.dwarf5_byte_order
));
2513 comp_unit_head cu_header
;
2514 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2516 section
->buffer
+ to_underlying (sect_off
),
2519 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2520 (cu_header
.signature
);
2521 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2522 sig_type
->section
= section
;
2523 sig_type
->sect_off
= sect_off
;
2525 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2526 struct dwarf2_per_cu_quick_data
);
2528 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2529 *slot
= sig_type
.get ();
2531 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2534 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2537 /* Read the address map data from the mapped index, and use it to
2538 populate the psymtabs_addrmap. */
2541 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2542 struct mapped_index
*index
)
2544 struct objfile
*objfile
= per_objfile
->objfile
;
2545 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2546 struct gdbarch
*gdbarch
= objfile
->arch ();
2547 const gdb_byte
*iter
, *end
;
2548 struct addrmap
*mutable_map
;
2551 auto_obstack temp_obstack
;
2553 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2555 iter
= index
->address_table
.data ();
2556 end
= iter
+ index
->address_table
.size ();
2558 baseaddr
= objfile
->text_section_offset ();
2562 ULONGEST hi
, lo
, cu_index
;
2563 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2565 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2567 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2572 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2573 hex_string (lo
), hex_string (hi
));
2577 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2579 complaint (_(".gdb_index address table has invalid CU number %u"),
2580 (unsigned) cu_index
);
2584 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2585 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2586 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2587 per_bfd
->get_cu (cu_index
));
2590 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2594 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2595 populate the psymtabs_addrmap. */
2598 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2599 struct dwarf2_section_info
*section
)
2601 struct objfile
*objfile
= per_objfile
->objfile
;
2602 bfd
*abfd
= objfile
->obfd
;
2603 struct gdbarch
*gdbarch
= objfile
->arch ();
2604 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2605 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2607 auto_obstack temp_obstack
;
2608 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2610 std::unordered_map
<sect_offset
,
2611 dwarf2_per_cu_data
*,
2612 gdb::hash_enum
<sect_offset
>>
2613 debug_info_offset_to_per_cu
;
2614 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2616 /* A TU will not need aranges, and skipping them here is an easy
2617 way of ignoring .debug_types -- and possibly seeing a
2618 duplicate section offset -- entirely. */
2619 if (per_cu
->is_debug_types
)
2622 const auto insertpair
2623 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2625 if (!insertpair
.second
)
2627 warning (_("Section .debug_aranges in %s has duplicate "
2628 "debug_info_offset %s, ignoring .debug_aranges."),
2629 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2634 section
->read (objfile
);
2636 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2638 const gdb_byte
*addr
= section
->buffer
;
2640 while (addr
< section
->buffer
+ section
->size
)
2642 const gdb_byte
*const entry_addr
= addr
;
2643 unsigned int bytes_read
;
2645 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2649 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2650 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2651 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2652 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2654 warning (_("Section .debug_aranges in %s entry at offset %s "
2655 "length %s exceeds section length %s, "
2656 "ignoring .debug_aranges."),
2657 objfile_name (objfile
),
2658 plongest (entry_addr
- section
->buffer
),
2659 plongest (bytes_read
+ entry_length
),
2660 pulongest (section
->size
));
2664 /* The version number. */
2665 const uint16_t version
= read_2_bytes (abfd
, addr
);
2669 warning (_("Section .debug_aranges in %s entry at offset %s "
2670 "has unsupported version %d, ignoring .debug_aranges."),
2671 objfile_name (objfile
),
2672 plongest (entry_addr
- section
->buffer
), version
);
2676 const uint64_t debug_info_offset
2677 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2678 addr
+= offset_size
;
2679 const auto per_cu_it
2680 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2681 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2683 warning (_("Section .debug_aranges in %s entry at offset %s "
2684 "debug_info_offset %s does not exists, "
2685 "ignoring .debug_aranges."),
2686 objfile_name (objfile
),
2687 plongest (entry_addr
- section
->buffer
),
2688 pulongest (debug_info_offset
));
2691 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2693 const uint8_t address_size
= *addr
++;
2694 if (address_size
< 1 || address_size
> 8)
2696 warning (_("Section .debug_aranges in %s entry at offset %s "
2697 "address_size %u is invalid, ignoring .debug_aranges."),
2698 objfile_name (objfile
),
2699 plongest (entry_addr
- section
->buffer
), address_size
);
2703 const uint8_t segment_selector_size
= *addr
++;
2704 if (segment_selector_size
!= 0)
2706 warning (_("Section .debug_aranges in %s entry at offset %s "
2707 "segment_selector_size %u is not supported, "
2708 "ignoring .debug_aranges."),
2709 objfile_name (objfile
),
2710 plongest (entry_addr
- section
->buffer
),
2711 segment_selector_size
);
2715 /* Must pad to an alignment boundary that is twice the address
2716 size. It is undocumented by the DWARF standard but GCC does
2717 use it. However, not every compiler does this. We can see
2718 whether it has happened by looking at the total length of the
2719 contents of the aranges for this CU -- it if isn't a multiple
2720 of twice the address size, then we skip any leftover
2722 addr
+= (entry_end
- addr
) % (2 * address_size
);
2726 if (addr
+ 2 * address_size
> entry_end
)
2728 warning (_("Section .debug_aranges in %s entry at offset %s "
2729 "address list is not properly terminated, "
2730 "ignoring .debug_aranges."),
2731 objfile_name (objfile
),
2732 plongest (entry_addr
- section
->buffer
));
2735 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2737 addr
+= address_size
;
2738 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2740 addr
+= address_size
;
2741 if (start
== 0 && length
== 0)
2743 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2745 /* Symbol was eliminated due to a COMDAT group. */
2748 ULONGEST end
= start
+ length
;
2749 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2751 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2753 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2757 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2761 /* A helper function that reads the .gdb_index from BUFFER and fills
2762 in MAP. FILENAME is the name of the file containing the data;
2763 it is used for error reporting. DEPRECATED_OK is true if it is
2764 ok to use deprecated sections.
2766 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2767 out parameters that are filled in with information about the CU and
2768 TU lists in the section.
2770 Returns true if all went well, false otherwise. */
2773 read_gdb_index_from_buffer (const char *filename
,
2775 gdb::array_view
<const gdb_byte
> buffer
,
2776 struct mapped_index
*map
,
2777 const gdb_byte
**cu_list
,
2778 offset_type
*cu_list_elements
,
2779 const gdb_byte
**types_list
,
2780 offset_type
*types_list_elements
)
2782 const gdb_byte
*addr
= &buffer
[0];
2783 offset_view
metadata (buffer
);
2785 /* Version check. */
2786 offset_type version
= metadata
[0];
2787 /* Versions earlier than 3 emitted every copy of a psymbol. This
2788 causes the index to behave very poorly for certain requests. Version 3
2789 contained incomplete addrmap. So, it seems better to just ignore such
2793 static int warning_printed
= 0;
2794 if (!warning_printed
)
2796 warning (_("Skipping obsolete .gdb_index section in %s."),
2798 warning_printed
= 1;
2802 /* Index version 4 uses a different hash function than index version
2805 Versions earlier than 6 did not emit psymbols for inlined
2806 functions. Using these files will cause GDB not to be able to
2807 set breakpoints on inlined functions by name, so we ignore these
2808 indices unless the user has done
2809 "set use-deprecated-index-sections on". */
2810 if (version
< 6 && !deprecated_ok
)
2812 static int warning_printed
= 0;
2813 if (!warning_printed
)
2816 Skipping deprecated .gdb_index section in %s.\n\
2817 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2818 to use the section anyway."),
2820 warning_printed
= 1;
2824 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2825 of the TU (for symbols coming from TUs),
2826 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2827 Plus gold-generated indices can have duplicate entries for global symbols,
2828 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2829 These are just performance bugs, and we can't distinguish gdb-generated
2830 indices from gold-generated ones, so issue no warning here. */
2832 /* Indexes with higher version than the one supported by GDB may be no
2833 longer backward compatible. */
2837 map
->version
= version
;
2840 *cu_list
= addr
+ metadata
[i
];
2841 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2844 *types_list
= addr
+ metadata
[i
];
2845 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2848 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2849 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2851 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2854 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2855 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2857 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2861 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2863 if (map
->constant_pool
.empty () && !map
->symbol_table
.empty ())
2865 /* An empty constant pool implies that all symbol table entries are
2866 empty. Make map->symbol_table.empty () == true. */
2868 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2875 /* Callback types for dwarf2_read_gdb_index. */
2877 typedef gdb::function_view
2878 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2879 get_gdb_index_contents_ftype
;
2880 typedef gdb::function_view
2881 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2882 get_gdb_index_contents_dwz_ftype
;
2884 /* Read .gdb_index. If everything went ok, initialize the "quick"
2885 elements of all the CUs and return 1. Otherwise, return 0. */
2888 dwarf2_read_gdb_index
2889 (dwarf2_per_objfile
*per_objfile
,
2890 get_gdb_index_contents_ftype get_gdb_index_contents
,
2891 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2893 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2894 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2895 struct dwz_file
*dwz
;
2896 struct objfile
*objfile
= per_objfile
->objfile
;
2897 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2899 gdb::array_view
<const gdb_byte
> main_index_contents
2900 = get_gdb_index_contents (objfile
, per_bfd
);
2902 if (main_index_contents
.empty ())
2905 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2906 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2907 use_deprecated_index_sections
,
2908 main_index_contents
, map
.get (), &cu_list
,
2909 &cu_list_elements
, &types_list
,
2910 &types_list_elements
))
2913 /* Don't use the index if it's empty. */
2914 if (map
->symbol_table
.empty ())
2917 /* If there is a .dwz file, read it so we can get its CU list as
2919 dwz
= dwarf2_get_dwz_file (per_bfd
);
2922 struct mapped_index dwz_map
;
2923 const gdb_byte
*dwz_types_ignore
;
2924 offset_type dwz_types_elements_ignore
;
2926 gdb::array_view
<const gdb_byte
> dwz_index_content
2927 = get_gdb_index_contents_dwz (objfile
, dwz
);
2929 if (dwz_index_content
.empty ())
2932 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2933 1, dwz_index_content
, &dwz_map
,
2934 &dwz_list
, &dwz_list_elements
,
2936 &dwz_types_elements_ignore
))
2938 warning (_("could not read '.gdb_index' section from %s; skipping"),
2939 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2944 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2947 if (types_list_elements
)
2949 /* We can only handle a single .debug_types when we have an
2951 if (per_bfd
->types
.size () != 1)
2954 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2956 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2957 types_list_elements
);
2960 create_addrmap_from_index (per_objfile
, map
.get ());
2962 per_bfd
->index_table
= std::move (map
);
2963 per_bfd
->using_index
= 1;
2964 per_bfd
->quick_file_names_table
=
2965 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2970 /* die_reader_func for dw2_get_file_names. */
2973 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2974 struct die_info
*comp_unit_die
)
2976 struct dwarf2_cu
*cu
= reader
->cu
;
2977 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2978 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2979 struct dwarf2_per_cu_data
*lh_cu
;
2980 struct attribute
*attr
;
2982 struct quick_file_names
*qfn
;
2984 gdb_assert (! this_cu
->is_debug_types
);
2986 this_cu
->v
.quick
->files_read
= true;
2987 /* Our callers never want to match partial units -- instead they
2988 will match the enclosing full CU. */
2989 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2996 sect_offset line_offset
{};
2998 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2999 if (attr
!= nullptr && attr
->form_is_unsigned ())
3001 struct quick_file_names find_entry
;
3003 line_offset
= (sect_offset
) attr
->as_unsigned ();
3005 /* We may have already read in this line header (TU line header sharing).
3006 If we have we're done. */
3007 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3008 find_entry
.hash
.line_sect_off
= line_offset
;
3009 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3010 &find_entry
, INSERT
);
3013 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3017 lh
= dwarf_decode_line_header (line_offset
, cu
);
3020 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3023 if (strcmp (fnd
.name
, "<unknown>") != 0)
3025 else if (lh
== nullptr)
3028 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3029 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3030 qfn
->hash
.line_sect_off
= line_offset
;
3031 /* There may not be a DW_AT_stmt_list. */
3032 if (slot
!= nullptr)
3035 std::vector
<const char *> include_names
;
3038 for (const auto &entry
: lh
->file_names ())
3040 gdb::unique_xmalloc_ptr
<char> name_holder
;
3041 const char *include_name
=
3042 compute_include_file_name (lh
.get (), entry
, fnd
, &name_holder
);
3043 if (include_name
!= nullptr)
3045 include_name
= per_objfile
->objfile
->intern (include_name
);
3046 include_names
.push_back (include_name
);
3051 qfn
->num_file_names
= offset
+ include_names
.size ();
3052 qfn
->comp_dir
= fnd
.comp_dir
;
3054 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3055 qfn
->num_file_names
);
3057 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3059 if (!include_names
.empty ())
3060 memcpy (&qfn
->file_names
[offset
], include_names
.data (),
3061 include_names
.size () * sizeof (const char *));
3063 qfn
->real_names
= NULL
;
3065 lh_cu
->v
.quick
->file_names
= qfn
;
3068 /* A helper for the "quick" functions which attempts to read the line
3069 table for THIS_CU. */
3071 static struct quick_file_names
*
3072 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3073 dwarf2_per_objfile
*per_objfile
)
3075 /* This should never be called for TUs. */
3076 gdb_assert (! this_cu
->is_debug_types
);
3077 /* Nor type unit groups. */
3078 gdb_assert (! this_cu
->type_unit_group_p ());
3080 if (this_cu
->v
.quick
->files_read
)
3081 return this_cu
->v
.quick
->file_names
;
3083 cutu_reader
reader (this_cu
, per_objfile
);
3084 if (!reader
.dummy_p
)
3085 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3087 return this_cu
->v
.quick
->file_names
;
3090 /* A helper for the "quick" functions which computes and caches the
3091 real path for a given file name from the line table. */
3094 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3095 struct quick_file_names
*qfn
, int index
)
3097 if (qfn
->real_names
== NULL
)
3098 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3099 qfn
->num_file_names
, const char *);
3101 if (qfn
->real_names
[index
] == NULL
)
3103 const char *dirname
= nullptr;
3105 if (!IS_ABSOLUTE_PATH (qfn
->file_names
[index
]))
3106 dirname
= qfn
->comp_dir
;
3108 gdb::unique_xmalloc_ptr
<char> fullname
;
3109 fullname
= find_source_or_rewrite (qfn
->file_names
[index
], dirname
);
3111 qfn
->real_names
[index
] = fullname
.release ();
3114 return qfn
->real_names
[index
];
3118 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3120 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3121 dwarf2_per_cu_data
*dwarf_cu
3122 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3123 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3128 return compunit_primary_filetab (cust
);
3134 dwarf2_per_cu_data::free_cached_file_names ()
3136 if (per_bfd
== nullptr || !per_bfd
->using_index
|| v
.quick
== nullptr)
3139 struct quick_file_names
*file_data
= v
.quick
->file_names
;
3140 if (file_data
!= nullptr && file_data
->real_names
!= nullptr)
3142 for (int i
= 0; i
< file_data
->num_file_names
; ++i
)
3144 xfree ((void *) file_data
->real_names
[i
]);
3145 file_data
->real_names
[i
] = nullptr;
3151 dwarf2_base_index_functions::forget_cached_source_info
3152 (struct objfile
*objfile
)
3154 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3156 for (auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3157 per_cu
->free_cached_file_names ();
3160 /* Struct used to manage iterating over all CUs looking for a symbol. */
3162 struct dw2_symtab_iterator
3164 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3165 dwarf2_per_objfile
*per_objfile
;
3166 /* If set, only look for symbols that match that block. Valid values are
3167 GLOBAL_BLOCK and STATIC_BLOCK. */
3168 gdb::optional
<block_enum
> block_index
;
3169 /* The kind of symbol we're looking for. */
3171 /* The list of CUs from the index entry of the symbol,
3172 or NULL if not found. */
3174 /* The next element in VEC to look at. */
3176 /* The number of elements in VEC, or zero if there is no match. */
3178 /* Have we seen a global version of the symbol?
3179 If so we can ignore all further global instances.
3180 This is to work around gold/15646, inefficient gold-generated
3185 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3188 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3189 dwarf2_per_objfile
*per_objfile
,
3190 gdb::optional
<block_enum
> block_index
,
3191 domain_enum domain
, offset_type namei
)
3193 iter
->per_objfile
= per_objfile
;
3194 iter
->block_index
= block_index
;
3195 iter
->domain
= domain
;
3197 iter
->global_seen
= 0;
3201 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3202 /* index is NULL if OBJF_READNOW. */
3206 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3207 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3209 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3210 iter
->length
= iter
->vec
[0];
3213 /* Return the next matching CU or NULL if there are no more. */
3215 static struct dwarf2_per_cu_data
*
3216 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3218 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3220 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3222 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3223 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3224 gdb_index_symbol_kind symbol_kind
=
3225 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3226 /* Only check the symbol attributes if they're present.
3227 Indices prior to version 7 don't record them,
3228 and indices >= 7 may elide them for certain symbols
3229 (gold does this). */
3231 (per_objfile
->per_bfd
->index_table
->version
>= 7
3232 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3234 /* Don't crash on bad data. */
3235 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3237 complaint (_(".gdb_index entry has bad CU index"
3238 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3242 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3244 /* Skip if already read in. */
3245 if (per_objfile
->symtab_set_p (per_cu
))
3248 /* Check static vs global. */
3251 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3253 if (iter
->block_index
.has_value ())
3255 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3257 if (is_static
!= want_static
)
3261 /* Work around gold/15646. */
3263 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3265 if (iter
->global_seen
)
3268 iter
->global_seen
= 1;
3272 /* Only check the symbol's kind if it has one. */
3275 switch (iter
->domain
)
3278 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3279 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3280 /* Some types are also in VAR_DOMAIN. */
3281 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3285 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3289 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3293 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3309 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3315 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3316 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3319 for (int i
= 0; i
< total
; ++i
)
3321 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3323 if (!per_objfile
->symtab_set_p (per_cu
))
3326 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3327 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3330 /* This dumps minimal information about the index.
3331 It is called via "mt print objfiles".
3332 One use is to verify .gdb_index has been loaded by the
3333 gdb.dwarf2/gdb-index.exp testcase. */
3336 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3338 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3340 gdb_assert (per_objfile
->per_bfd
->using_index
);
3341 printf_filtered (".gdb_index:");
3342 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3344 printf_filtered (" version %d\n",
3345 per_objfile
->per_bfd
->index_table
->version
);
3348 printf_filtered (" faked for \"readnow\"\n");
3349 printf_filtered ("\n");
3353 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3355 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3356 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3358 for (int i
= 0; i
< total_units
; ++i
)
3360 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3362 /* We don't want to directly expand a partial CU, because if we
3363 read it with the wrong language, then assertion failures can
3364 be triggered later on. See PR symtab/23010. So, tell
3365 dw2_instantiate_symtab to skip partial CUs -- any important
3366 partial CU will be read via DW_TAG_imported_unit anyway. */
3367 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3372 dw2_expand_symtabs_matching_symbol
3373 (mapped_index_base
&index
,
3374 const lookup_name_info
&lookup_name_in
,
3375 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3376 gdb::function_view
<bool (offset_type
)> match_callback
,
3377 dwarf2_per_objfile
*per_objfile
);
3380 dw2_expand_symtabs_matching_one
3381 (dwarf2_per_cu_data
*per_cu
,
3382 dwarf2_per_objfile
*per_objfile
,
3383 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3384 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3387 dwarf2_gdb_index::expand_matching_symbols
3388 (struct objfile
*objfile
,
3389 const lookup_name_info
&name
, domain_enum domain
,
3391 symbol_compare_ftype
*ordered_compare
)
3394 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3396 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3398 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3400 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3402 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3403 auto matcher
= [&] (const char *symname
)
3405 if (ordered_compare
== nullptr)
3407 return ordered_compare (symname
, match_name
) == 0;
3410 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3411 [&] (offset_type namei
)
3413 struct dw2_symtab_iterator iter
;
3414 struct dwarf2_per_cu_data
*per_cu
;
3416 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3418 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3419 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3426 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3427 proceed assuming all symtabs have been read in. */
3431 /* Starting from a search name, return the string that finds the upper
3432 bound of all strings that start with SEARCH_NAME in a sorted name
3433 list. Returns the empty string to indicate that the upper bound is
3434 the end of the list. */
3437 make_sort_after_prefix_name (const char *search_name
)
3439 /* When looking to complete "func", we find the upper bound of all
3440 symbols that start with "func" by looking for where we'd insert
3441 the closest string that would follow "func" in lexicographical
3442 order. Usually, that's "func"-with-last-character-incremented,
3443 i.e. "fund". Mind non-ASCII characters, though. Usually those
3444 will be UTF-8 multi-byte sequences, but we can't be certain.
3445 Especially mind the 0xff character, which is a valid character in
3446 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3447 rule out compilers allowing it in identifiers. Note that
3448 conveniently, strcmp/strcasecmp are specified to compare
3449 characters interpreted as unsigned char. So what we do is treat
3450 the whole string as a base 256 number composed of a sequence of
3451 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3452 to 0, and carries 1 to the following more-significant position.
3453 If the very first character in SEARCH_NAME ends up incremented
3454 and carries/overflows, then the upper bound is the end of the
3455 list. The string after the empty string is also the empty
3458 Some examples of this operation:
3460 SEARCH_NAME => "+1" RESULT
3464 "\xff" "a" "\xff" => "\xff" "b"
3469 Then, with these symbols for example:
3475 completing "func" looks for symbols between "func" and
3476 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3477 which finds "func" and "func1", but not "fund".
3481 funcÿ (Latin1 'ÿ' [0xff])
3485 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3486 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3490 ÿÿ (Latin1 'ÿ' [0xff])
3493 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3494 the end of the list.
3496 std::string after
= search_name
;
3497 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3499 if (!after
.empty ())
3500 after
.back () = (unsigned char) after
.back () + 1;
3504 /* See declaration. */
3506 std::pair
<std::vector
<name_component
>::const_iterator
,
3507 std::vector
<name_component
>::const_iterator
>
3508 mapped_index_base::find_name_components_bounds
3509 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3510 dwarf2_per_objfile
*per_objfile
) const
3513 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3515 const char *lang_name
3516 = lookup_name_without_params
.language_lookup_name (lang
);
3518 /* Comparison function object for lower_bound that matches against a
3519 given symbol name. */
3520 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3523 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3524 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3525 return name_cmp (elem_name
, name
) < 0;
3528 /* Comparison function object for upper_bound that matches against a
3529 given symbol name. */
3530 auto lookup_compare_upper
= [&] (const char *name
,
3531 const name_component
&elem
)
3533 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3534 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3535 return name_cmp (name
, elem_name
) < 0;
3538 auto begin
= this->name_components
.begin ();
3539 auto end
= this->name_components
.end ();
3541 /* Find the lower bound. */
3544 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3547 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3550 /* Find the upper bound. */
3553 if (lookup_name_without_params
.completion_mode ())
3555 /* In completion mode, we want UPPER to point past all
3556 symbols names that have the same prefix. I.e., with
3557 these symbols, and completing "func":
3559 function << lower bound
3561 other_function << upper bound
3563 We find the upper bound by looking for the insertion
3564 point of "func"-with-last-character-incremented,
3566 std::string after
= make_sort_after_prefix_name (lang_name
);
3569 return std::lower_bound (lower
, end
, after
.c_str (),
3570 lookup_compare_lower
);
3573 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3576 return {lower
, upper
};
3579 /* See declaration. */
3582 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3584 if (!this->name_components
.empty ())
3587 this->name_components_casing
= case_sensitivity
;
3589 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3591 /* The code below only knows how to break apart components of C++
3592 symbol names (and other languages that use '::' as
3593 namespace/module separator) and Ada symbol names. */
3594 auto count
= this->symbol_name_count ();
3595 for (offset_type idx
= 0; idx
< count
; idx
++)
3597 if (this->symbol_name_slot_invalid (idx
))
3600 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3602 /* Add each name component to the name component table. */
3603 unsigned int previous_len
= 0;
3605 if (strstr (name
, "::") != nullptr)
3607 for (unsigned int current_len
= cp_find_first_component (name
);
3608 name
[current_len
] != '\0';
3609 current_len
+= cp_find_first_component (name
+ current_len
))
3611 gdb_assert (name
[current_len
] == ':');
3612 this->name_components
.push_back ({previous_len
, idx
});
3613 /* Skip the '::'. */
3615 previous_len
= current_len
;
3620 /* Handle the Ada encoded (aka mangled) form here. */
3621 for (const char *iter
= strstr (name
, "__");
3623 iter
= strstr (iter
, "__"))
3625 this->name_components
.push_back ({previous_len
, idx
});
3627 previous_len
= iter
- name
;
3631 this->name_components
.push_back ({previous_len
, idx
});
3634 /* Sort name_components elements by name. */
3635 auto name_comp_compare
= [&] (const name_component
&left
,
3636 const name_component
&right
)
3638 const char *left_qualified
3639 = this->symbol_name_at (left
.idx
, per_objfile
);
3640 const char *right_qualified
3641 = this->symbol_name_at (right
.idx
, per_objfile
);
3643 const char *left_name
= left_qualified
+ left
.name_offset
;
3644 const char *right_name
= right_qualified
+ right
.name_offset
;
3646 return name_cmp (left_name
, right_name
) < 0;
3649 std::sort (this->name_components
.begin (),
3650 this->name_components
.end (),
3654 /* Helper for dw2_expand_symtabs_matching that works with a
3655 mapped_index_base instead of the containing objfile. This is split
3656 to a separate function in order to be able to unit test the
3657 name_components matching using a mock mapped_index_base. For each
3658 symbol name that matches, calls MATCH_CALLBACK, passing it the
3659 symbol's index in the mapped_index_base symbol table. */
3662 dw2_expand_symtabs_matching_symbol
3663 (mapped_index_base
&index
,
3664 const lookup_name_info
&lookup_name_in
,
3665 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3666 gdb::function_view
<bool (offset_type
)> match_callback
,
3667 dwarf2_per_objfile
*per_objfile
)
3669 lookup_name_info lookup_name_without_params
3670 = lookup_name_in
.make_ignore_params ();
3672 /* Build the symbol name component sorted vector, if we haven't
3674 index
.build_name_components (per_objfile
);
3676 /* The same symbol may appear more than once in the range though.
3677 E.g., if we're looking for symbols that complete "w", and we have
3678 a symbol named "w1::w2", we'll find the two name components for
3679 that same symbol in the range. To be sure we only call the
3680 callback once per symbol, we first collect the symbol name
3681 indexes that matched in a temporary vector and ignore
3683 std::vector
<offset_type
> matches
;
3685 struct name_and_matcher
3687 symbol_name_matcher_ftype
*matcher
;
3690 bool operator== (const name_and_matcher
&other
) const
3692 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3696 /* A vector holding all the different symbol name matchers, for all
3698 std::vector
<name_and_matcher
> matchers
;
3700 for (int i
= 0; i
< nr_languages
; i
++)
3702 enum language lang_e
= (enum language
) i
;
3704 const language_defn
*lang
= language_def (lang_e
);
3705 symbol_name_matcher_ftype
*name_matcher
3706 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3708 name_and_matcher key
{
3710 lookup_name_without_params
.language_lookup_name (lang_e
)
3713 /* Don't insert the same comparison routine more than once.
3714 Note that we do this linear walk. This is not a problem in
3715 practice because the number of supported languages is
3717 if (std::find (matchers
.begin (), matchers
.end (), key
)
3720 matchers
.push_back (std::move (key
));
3723 = index
.find_name_components_bounds (lookup_name_without_params
,
3724 lang_e
, per_objfile
);
3726 /* Now for each symbol name in range, check to see if we have a name
3727 match, and if so, call the MATCH_CALLBACK callback. */
3729 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3731 const char *qualified
3732 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3734 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3735 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3738 matches
.push_back (bounds
.first
->idx
);
3742 std::sort (matches
.begin (), matches
.end ());
3744 /* Finally call the callback, once per match. */
3747 for (offset_type idx
: matches
)
3751 if (!match_callback (idx
))
3760 /* Above we use a type wider than idx's for 'prev', since 0 and
3761 (offset_type)-1 are both possible values. */
3762 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3769 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3771 /* A mock .gdb_index/.debug_names-like name index table, enough to
3772 exercise dw2_expand_symtabs_matching_symbol, which works with the
3773 mapped_index_base interface. Builds an index from the symbol list
3774 passed as parameter to the constructor. */
3775 class mock_mapped_index
: public mapped_index_base
3778 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3779 : m_symbol_table (symbols
)
3782 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3784 /* Return the number of names in the symbol table. */
3785 size_t symbol_name_count () const override
3787 return m_symbol_table
.size ();
3790 /* Get the name of the symbol at IDX in the symbol table. */
3791 const char *symbol_name_at
3792 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3794 return m_symbol_table
[idx
];
3798 gdb::array_view
<const char *> m_symbol_table
;
3801 /* Convenience function that converts a NULL pointer to a "<null>"
3802 string, to pass to print routines. */
3805 string_or_null (const char *str
)
3807 return str
!= NULL
? str
: "<null>";
3810 /* Check if a lookup_name_info built from
3811 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3812 index. EXPECTED_LIST is the list of expected matches, in expected
3813 matching order. If no match expected, then an empty list is
3814 specified. Returns true on success. On failure prints a warning
3815 indicating the file:line that failed, and returns false. */
3818 check_match (const char *file
, int line
,
3819 mock_mapped_index
&mock_index
,
3820 const char *name
, symbol_name_match_type match_type
,
3821 bool completion_mode
,
3822 std::initializer_list
<const char *> expected_list
,
3823 dwarf2_per_objfile
*per_objfile
)
3825 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3827 bool matched
= true;
3829 auto mismatch
= [&] (const char *expected_str
,
3832 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3833 "expected=\"%s\", got=\"%s\"\n"),
3835 (match_type
== symbol_name_match_type::FULL
3837 name
, string_or_null (expected_str
), string_or_null (got
));
3841 auto expected_it
= expected_list
.begin ();
3842 auto expected_end
= expected_list
.end ();
3844 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3846 [&] (offset_type idx
)
3848 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3849 const char *expected_str
3850 = expected_it
== expected_end
? NULL
: *expected_it
++;
3852 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3853 mismatch (expected_str
, matched_name
);
3857 const char *expected_str
3858 = expected_it
== expected_end
? NULL
: *expected_it
++;
3859 if (expected_str
!= NULL
)
3860 mismatch (expected_str
, NULL
);
3865 /* The symbols added to the mock mapped_index for testing (in
3867 static const char *test_symbols
[] = {
3876 "ns2::tmpl<int>::foo2",
3877 "(anonymous namespace)::A::B::C",
3879 /* These are used to check that the increment-last-char in the
3880 matching algorithm for completion doesn't match "t1_fund" when
3881 completing "t1_func". */
3887 /* A UTF-8 name with multi-byte sequences to make sure that
3888 cp-name-parser understands this as a single identifier ("função"
3889 is "function" in PT). */
3892 /* \377 (0xff) is Latin1 'ÿ'. */
3895 /* \377 (0xff) is Latin1 'ÿ'. */
3899 /* A name with all sorts of complications. Starts with "z" to make
3900 it easier for the completion tests below. */
3901 #define Z_SYM_NAME \
3902 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3903 "::tuple<(anonymous namespace)::ui*, " \
3904 "std::default_delete<(anonymous namespace)::ui>, void>"
3909 /* Returns true if the mapped_index_base::find_name_component_bounds
3910 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3911 in completion mode. */
3914 check_find_bounds_finds (mapped_index_base
&index
,
3915 const char *search_name
,
3916 gdb::array_view
<const char *> expected_syms
,
3917 dwarf2_per_objfile
*per_objfile
)
3919 lookup_name_info
lookup_name (search_name
,
3920 symbol_name_match_type::FULL
, true);
3922 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3926 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3927 if (distance
!= expected_syms
.size ())
3930 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3932 auto nc_elem
= bounds
.first
+ exp_elem
;
3933 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3934 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3941 /* Test the lower-level mapped_index::find_name_component_bounds
3945 test_mapped_index_find_name_component_bounds ()
3947 mock_mapped_index
mock_index (test_symbols
);
3949 mock_index
.build_name_components (NULL
/* per_objfile */);
3951 /* Test the lower-level mapped_index::find_name_component_bounds
3952 method in completion mode. */
3954 static const char *expected_syms
[] = {
3959 SELF_CHECK (check_find_bounds_finds
3960 (mock_index
, "t1_func", expected_syms
,
3961 NULL
/* per_objfile */));
3964 /* Check that the increment-last-char in the name matching algorithm
3965 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3967 static const char *expected_syms1
[] = {
3971 SELF_CHECK (check_find_bounds_finds
3972 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3974 static const char *expected_syms2
[] = {
3977 SELF_CHECK (check_find_bounds_finds
3978 (mock_index
, "\377\377", expected_syms2
,
3979 NULL
/* per_objfile */));
3983 /* Test dw2_expand_symtabs_matching_symbol. */
3986 test_dw2_expand_symtabs_matching_symbol ()
3988 mock_mapped_index
mock_index (test_symbols
);
3990 /* We let all tests run until the end even if some fails, for debug
3992 bool any_mismatch
= false;
3994 /* Create the expected symbols list (an initializer_list). Needed
3995 because lists have commas, and we need to pass them to CHECK,
3996 which is a macro. */
3997 #define EXPECT(...) { __VA_ARGS__ }
3999 /* Wrapper for check_match that passes down the current
4000 __FILE__/__LINE__. */
4001 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4002 any_mismatch |= !check_match (__FILE__, __LINE__, \
4004 NAME, MATCH_TYPE, COMPLETION_MODE, \
4005 EXPECTED_LIST, NULL)
4007 /* Identity checks. */
4008 for (const char *sym
: test_symbols
)
4010 /* Should be able to match all existing symbols. */
4011 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4014 /* Should be able to match all existing symbols with
4016 std::string with_params
= std::string (sym
) + "(int)";
4017 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4020 /* Should be able to match all existing symbols with
4021 parameters and qualifiers. */
4022 with_params
= std::string (sym
) + " ( int ) const";
4023 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4026 /* This should really find sym, but cp-name-parser.y doesn't
4027 know about lvalue/rvalue qualifiers yet. */
4028 with_params
= std::string (sym
) + " ( int ) &&";
4029 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4033 /* Check that the name matching algorithm for completion doesn't get
4034 confused with Latin1 'ÿ' / 0xff. */
4036 static const char str
[] = "\377";
4037 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4038 EXPECT ("\377", "\377\377123"));
4041 /* Check that the increment-last-char in the matching algorithm for
4042 completion doesn't match "t1_fund" when completing "t1_func". */
4044 static const char str
[] = "t1_func";
4045 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4046 EXPECT ("t1_func", "t1_func1"));
4049 /* Check that completion mode works at each prefix of the expected
4052 static const char str
[] = "function(int)";
4053 size_t len
= strlen (str
);
4056 for (size_t i
= 1; i
< len
; i
++)
4058 lookup
.assign (str
, i
);
4059 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4060 EXPECT ("function"));
4064 /* While "w" is a prefix of both components, the match function
4065 should still only be called once. */
4067 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4069 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4073 /* Same, with a "complicated" symbol. */
4075 static const char str
[] = Z_SYM_NAME
;
4076 size_t len
= strlen (str
);
4079 for (size_t i
= 1; i
< len
; i
++)
4081 lookup
.assign (str
, i
);
4082 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4083 EXPECT (Z_SYM_NAME
));
4087 /* In FULL mode, an incomplete symbol doesn't match. */
4089 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4093 /* A complete symbol with parameters matches any overload, since the
4094 index has no overload info. */
4096 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4097 EXPECT ("std::zfunction", "std::zfunction2"));
4098 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4099 EXPECT ("std::zfunction", "std::zfunction2"));
4100 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4101 EXPECT ("std::zfunction", "std::zfunction2"));
4104 /* Check that whitespace is ignored appropriately. A symbol with a
4105 template argument list. */
4107 static const char expected
[] = "ns::foo<int>";
4108 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4110 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4114 /* Check that whitespace is ignored appropriately. A symbol with a
4115 template argument list that includes a pointer. */
4117 static const char expected
[] = "ns::foo<char*>";
4118 /* Try both completion and non-completion modes. */
4119 static const bool completion_mode
[2] = {false, true};
4120 for (size_t i
= 0; i
< 2; i
++)
4122 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4123 completion_mode
[i
], EXPECT (expected
));
4124 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4125 completion_mode
[i
], EXPECT (expected
));
4127 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4128 completion_mode
[i
], EXPECT (expected
));
4129 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4130 completion_mode
[i
], EXPECT (expected
));
4135 /* Check method qualifiers are ignored. */
4136 static const char expected
[] = "ns::foo<char*>";
4137 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4138 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4139 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4140 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4141 CHECK_MATCH ("foo < char * > ( int ) const",
4142 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4143 CHECK_MATCH ("foo < char * > ( int ) &&",
4144 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4147 /* Test lookup names that don't match anything. */
4149 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4152 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4156 /* Some wild matching tests, exercising "(anonymous namespace)",
4157 which should not be confused with a parameter list. */
4159 static const char *syms
[] = {
4163 "A :: B :: C ( int )",
4168 for (const char *s
: syms
)
4170 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4171 EXPECT ("(anonymous namespace)::A::B::C"));
4176 static const char expected
[] = "ns2::tmpl<int>::foo2";
4177 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4179 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4183 SELF_CHECK (!any_mismatch
);
4192 test_mapped_index_find_name_component_bounds ();
4193 test_dw2_expand_symtabs_matching_symbol ();
4196 }} // namespace selftests::dw2_expand_symtabs_matching
4198 #endif /* GDB_SELF_TEST */
4200 /* If FILE_MATCHER is NULL or if PER_CU has
4201 dwarf2_per_cu_quick_data::MARK set (see
4202 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4203 EXPANSION_NOTIFY on it. */
4206 dw2_expand_symtabs_matching_one
4207 (dwarf2_per_cu_data
*per_cu
,
4208 dwarf2_per_objfile
*per_objfile
,
4209 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4210 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4212 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4214 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4216 compunit_symtab
*symtab
4217 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4218 gdb_assert (symtab
!= nullptr);
4220 if (expansion_notify
!= NULL
&& symtab_was_null
)
4221 return expansion_notify (symtab
);
4226 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4227 matched, to expand corresponding CUs that were marked. IDX is the
4228 index of the symbol name that matched. */
4231 dw2_expand_marked_cus
4232 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4233 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4234 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4235 block_search_flags search_flags
,
4238 offset_type vec_len
, vec_idx
;
4239 bool global_seen
= false;
4240 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4242 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4244 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4246 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4247 /* This value is only valid for index versions >= 7. */
4248 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4249 gdb_index_symbol_kind symbol_kind
=
4250 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4251 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4252 /* Only check the symbol attributes if they're present.
4253 Indices prior to version 7 don't record them,
4254 and indices >= 7 may elide them for certain symbols
4255 (gold does this). */
4258 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4260 /* Work around gold/15646. */
4263 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4271 /* Only check the symbol's kind if it has one. */
4276 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4281 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4287 case VARIABLES_DOMAIN
:
4288 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4291 case FUNCTIONS_DOMAIN
:
4292 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4296 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4299 case MODULES_DOMAIN
:
4300 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4308 /* Don't crash on bad data. */
4309 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4311 complaint (_(".gdb_index entry has bad CU index"
4312 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4316 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4317 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4325 /* If FILE_MATCHER is non-NULL, set all the
4326 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4327 that match FILE_MATCHER. */
4330 dw_expand_symtabs_matching_file_matcher
4331 (dwarf2_per_objfile
*per_objfile
,
4332 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4334 if (file_matcher
== NULL
)
4337 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4339 NULL
, xcalloc
, xfree
));
4340 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4342 NULL
, xcalloc
, xfree
));
4344 /* The rule is CUs specify all the files, including those used by
4345 any TU, so there's no need to scan TUs here. */
4347 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4351 if (per_cu
->is_debug_types
)
4353 per_cu
->v
.quick
->mark
= 0;
4355 /* We only need to look at symtabs not already expanded. */
4356 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4359 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4361 if (file_data
== NULL
)
4364 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4366 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4368 per_cu
->v
.quick
->mark
= 1;
4372 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4374 const char *this_real_name
;
4376 if (file_matcher (file_data
->file_names
[j
], false))
4378 per_cu
->v
.quick
->mark
= 1;
4382 /* Before we invoke realpath, which can get expensive when many
4383 files are involved, do a quick comparison of the basenames. */
4384 if (!basenames_may_differ
4385 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4389 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4390 if (file_matcher (this_real_name
, false))
4392 per_cu
->v
.quick
->mark
= 1;
4397 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4398 ? visited_found
.get ()
4399 : visited_not_found
.get (),
4406 dwarf2_gdb_index::expand_symtabs_matching
4407 (struct objfile
*objfile
,
4408 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4409 const lookup_name_info
*lookup_name
,
4410 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4411 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4412 block_search_flags search_flags
,
4414 enum search_domain kind
)
4416 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4418 /* index_table is NULL if OBJF_READNOW. */
4419 if (!per_objfile
->per_bfd
->index_table
)
4422 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4424 /* This invariant is documented in quick-functions.h. */
4425 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
4426 if (lookup_name
== nullptr)
4428 for (dwarf2_per_cu_data
*per_cu
4429 : all_comp_units_range (per_objfile
->per_bfd
))
4433 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4441 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4444 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4446 [&] (offset_type idx
)
4448 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4449 expansion_notify
, search_flags
, kind
))
4457 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4460 static struct compunit_symtab
*
4461 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4466 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4467 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4470 if (cust
->includes
== NULL
)
4473 for (i
= 0; cust
->includes
[i
]; ++i
)
4475 struct compunit_symtab
*s
= cust
->includes
[i
];
4477 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4485 struct compunit_symtab
*
4486 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4487 (struct objfile
*objfile
,
4488 struct bound_minimal_symbol msymbol
,
4490 struct obj_section
*section
,
4493 struct dwarf2_per_cu_data
*data
;
4494 struct compunit_symtab
*result
;
4496 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4497 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4500 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4501 data
= ((struct dwarf2_per_cu_data
*)
4502 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4507 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4508 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4509 paddress (objfile
->arch (), pc
));
4511 result
= recursively_find_pc_sect_compunit_symtab
4512 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4514 gdb_assert (result
!= NULL
);
4519 dwarf2_base_index_functions::map_symbol_filenames
4520 (struct objfile
*objfile
,
4521 gdb::function_view
<symbol_filename_ftype
> fun
,
4524 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4526 /* Use caches to ensure we only call FUN once for each filename. */
4527 filename_seen_cache filenames_cache
;
4528 std::unordered_set
<quick_file_names
*> qfn_cache
;
4530 /* The rule is CUs specify all the files, including those used by any TU,
4531 so there's no need to scan TUs here. We can ignore file names coming
4532 from already-expanded CUs. It is possible that an expanded CU might
4533 reuse the file names data from a currently unexpanded CU, in this
4534 case we don't want to report the files from the unexpanded CU. */
4536 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4538 if (!per_cu
->is_debug_types
4539 && per_objfile
->symtab_set_p (per_cu
.get ()))
4541 if (per_cu
->v
.quick
->file_names
!= nullptr)
4542 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4546 for (dwarf2_per_cu_data
*per_cu
4547 : all_comp_units_range (per_objfile
->per_bfd
))
4549 /* We only need to look at symtabs not already expanded. */
4550 if (per_cu
->is_debug_types
|| per_objfile
->symtab_set_p (per_cu
))
4553 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4554 if (file_data
== nullptr
4555 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4558 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4560 const char *filename
= file_data
->file_names
[j
];
4561 const char *key
= filename
;
4562 const char *fullname
= nullptr;
4566 fullname
= dw2_get_real_path (per_objfile
, file_data
, j
);
4570 if (!filenames_cache
.seen (key
))
4571 fun (filename
, fullname
);
4577 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4582 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
4585 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
4587 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4589 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4591 /* Is this already expanded? */
4592 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4595 /* It has not yet been expanded. */
4602 /* DWARF-5 debug_names reader. */
4604 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4605 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4607 /* A helper function that reads the .debug_names section in SECTION
4608 and fills in MAP. FILENAME is the name of the file containing the
4609 section; it is used for error reporting.
4611 Returns true if all went well, false otherwise. */
4614 read_debug_names_from_section (struct objfile
*objfile
,
4615 const char *filename
,
4616 struct dwarf2_section_info
*section
,
4617 mapped_debug_names
&map
)
4619 if (section
->empty ())
4622 /* Older elfutils strip versions could keep the section in the main
4623 executable while splitting it for the separate debug info file. */
4624 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4627 section
->read (objfile
);
4629 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4631 const gdb_byte
*addr
= section
->buffer
;
4633 bfd
*const abfd
= section
->get_bfd_owner ();
4635 unsigned int bytes_read
;
4636 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4639 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4640 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4641 if (bytes_read
+ length
!= section
->size
)
4643 /* There may be multiple per-CU indices. */
4644 warning (_("Section .debug_names in %s length %s does not match "
4645 "section length %s, ignoring .debug_names."),
4646 filename
, plongest (bytes_read
+ length
),
4647 pulongest (section
->size
));
4651 /* The version number. */
4652 uint16_t version
= read_2_bytes (abfd
, addr
);
4656 warning (_("Section .debug_names in %s has unsupported version %d, "
4657 "ignoring .debug_names."),
4663 uint16_t padding
= read_2_bytes (abfd
, addr
);
4667 warning (_("Section .debug_names in %s has unsupported padding %d, "
4668 "ignoring .debug_names."),
4673 /* comp_unit_count - The number of CUs in the CU list. */
4674 map
.cu_count
= read_4_bytes (abfd
, addr
);
4677 /* local_type_unit_count - The number of TUs in the local TU
4679 map
.tu_count
= read_4_bytes (abfd
, addr
);
4682 /* foreign_type_unit_count - The number of TUs in the foreign TU
4684 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4686 if (foreign_tu_count
!= 0)
4688 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4689 "ignoring .debug_names."),
4690 filename
, static_cast<unsigned long> (foreign_tu_count
));
4694 /* bucket_count - The number of hash buckets in the hash lookup
4696 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4699 /* name_count - The number of unique names in the index. */
4700 map
.name_count
= read_4_bytes (abfd
, addr
);
4703 /* abbrev_table_size - The size in bytes of the abbreviations
4705 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4708 /* augmentation_string_size - The size in bytes of the augmentation
4709 string. This value is rounded up to a multiple of 4. */
4710 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4712 map
.augmentation_is_gdb
= ((augmentation_string_size
4713 == sizeof (dwarf5_augmentation
))
4714 && memcmp (addr
, dwarf5_augmentation
,
4715 sizeof (dwarf5_augmentation
)) == 0);
4716 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4717 addr
+= augmentation_string_size
;
4720 map
.cu_table_reordered
= addr
;
4721 addr
+= map
.cu_count
* map
.offset_size
;
4723 /* List of Local TUs */
4724 map
.tu_table_reordered
= addr
;
4725 addr
+= map
.tu_count
* map
.offset_size
;
4727 /* Hash Lookup Table */
4728 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4729 addr
+= map
.bucket_count
* 4;
4730 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4731 addr
+= map
.name_count
* 4;
4734 map
.name_table_string_offs_reordered
= addr
;
4735 addr
+= map
.name_count
* map
.offset_size
;
4736 map
.name_table_entry_offs_reordered
= addr
;
4737 addr
+= map
.name_count
* map
.offset_size
;
4739 const gdb_byte
*abbrev_table_start
= addr
;
4742 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4747 const auto insertpair
4748 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4749 if (!insertpair
.second
)
4751 warning (_("Section .debug_names in %s has duplicate index %s, "
4752 "ignoring .debug_names."),
4753 filename
, pulongest (index_num
));
4756 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4757 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4762 mapped_debug_names::index_val::attr attr
;
4763 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4765 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4767 if (attr
.form
== DW_FORM_implicit_const
)
4769 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4773 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4775 indexval
.attr_vec
.push_back (std::move (attr
));
4778 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4780 warning (_("Section .debug_names in %s has abbreviation_table "
4781 "of size %s vs. written as %u, ignoring .debug_names."),
4782 filename
, plongest (addr
- abbrev_table_start
),
4786 map
.entry_pool
= addr
;
4791 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4795 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4796 const mapped_debug_names
&map
,
4797 dwarf2_section_info
§ion
,
4800 if (!map
.augmentation_is_gdb
)
4802 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4804 sect_offset sect_off
4805 = (sect_offset
) (extract_unsigned_integer
4806 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4808 map
.dwarf5_byte_order
));
4809 /* We don't know the length of the CU, because the CU list in a
4810 .debug_names index can be incomplete, so we can't use the start
4811 of the next CU as end of this CU. We create the CUs here with
4812 length 0, and in cutu_reader::cutu_reader we'll fill in the
4814 dwarf2_per_cu_data_up per_cu
4815 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4817 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4822 sect_offset sect_off_prev
;
4823 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4825 sect_offset sect_off_next
;
4826 if (i
< map
.cu_count
)
4829 = (sect_offset
) (extract_unsigned_integer
4830 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4832 map
.dwarf5_byte_order
));
4835 sect_off_next
= (sect_offset
) section
.size
;
4838 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4839 dwarf2_per_cu_data_up per_cu
4840 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4841 sect_off_prev
, length
);
4842 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4844 sect_off_prev
= sect_off_next
;
4848 /* Read the CU list from the mapped index, and use it to create all
4849 the CU objects for this dwarf2_per_objfile. */
4852 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4853 const mapped_debug_names
&map
,
4854 const mapped_debug_names
&dwz_map
)
4856 gdb_assert (per_bfd
->all_comp_units
.empty ());
4857 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4859 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4860 false /* is_dwz */);
4862 if (dwz_map
.cu_count
== 0)
4865 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4866 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4870 /* Read .debug_names. If everything went ok, initialize the "quick"
4871 elements of all the CUs and return true. Otherwise, return false. */
4874 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4876 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4877 mapped_debug_names dwz_map
;
4878 struct objfile
*objfile
= per_objfile
->objfile
;
4879 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4881 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4882 &per_bfd
->debug_names
, *map
))
4885 /* Don't use the index if it's empty. */
4886 if (map
->name_count
== 0)
4889 /* If there is a .dwz file, read it so we can get its CU list as
4891 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4894 if (!read_debug_names_from_section (objfile
,
4895 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4896 &dwz
->debug_names
, dwz_map
))
4898 warning (_("could not read '.debug_names' section from %s; skipping"),
4899 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4904 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4906 if (map
->tu_count
!= 0)
4908 /* We can only handle a single .debug_types when we have an
4910 if (per_bfd
->types
.size () != 1)
4913 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4915 create_signatured_type_table_from_debug_names
4916 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4919 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4921 per_bfd
->debug_names_table
= std::move (map
);
4922 per_bfd
->using_index
= 1;
4923 per_bfd
->quick_file_names_table
=
4924 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4929 /* Type used to manage iterating over all CUs looking for a symbol for
4932 class dw2_debug_names_iterator
4935 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4936 block_search_flags block_index
,
4938 const char *name
, dwarf2_per_objfile
*per_objfile
)
4939 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4940 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4941 m_per_objfile (per_objfile
)
4944 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4945 search_domain search
, uint32_t namei
,
4946 dwarf2_per_objfile
*per_objfile
,
4947 domain_enum domain
= UNDEF_DOMAIN
)
4951 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4952 m_per_objfile (per_objfile
)
4955 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4956 block_search_flags block_index
, domain_enum domain
,
4957 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4958 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4959 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4960 m_per_objfile (per_objfile
)
4963 /* Return the next matching CU or NULL if there are no more. */
4964 dwarf2_per_cu_data
*next ();
4967 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4969 dwarf2_per_objfile
*per_objfile
);
4970 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4972 dwarf2_per_objfile
*per_objfile
);
4974 /* The internalized form of .debug_names. */
4975 const mapped_debug_names
&m_map
;
4977 /* Restrict the search to these blocks. */
4978 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4979 | SEARCH_STATIC_BLOCK
);
4981 /* The kind of symbol we're looking for. */
4982 const domain_enum m_domain
= UNDEF_DOMAIN
;
4983 const search_domain m_search
= ALL_DOMAIN
;
4985 /* The list of CUs from the index entry of the symbol, or NULL if
4987 const gdb_byte
*m_addr
;
4989 dwarf2_per_objfile
*m_per_objfile
;
4993 mapped_debug_names::namei_to_name
4994 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
4996 const ULONGEST namei_string_offs
4997 = extract_unsigned_integer ((name_table_string_offs_reordered
4998 + namei
* offset_size
),
5001 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5004 /* Find a slot in .debug_names for the object named NAME. If NAME is
5005 found, return pointer to its pool data. If NAME cannot be found,
5009 dw2_debug_names_iterator::find_vec_in_debug_names
5010 (const mapped_debug_names
&map
, const char *name
,
5011 dwarf2_per_objfile
*per_objfile
)
5013 int (*cmp
) (const char *, const char *);
5015 gdb::unique_xmalloc_ptr
<char> without_params
;
5016 if (current_language
->la_language
== language_cplus
5017 || current_language
->la_language
== language_fortran
5018 || current_language
->la_language
== language_d
)
5020 /* NAME is already canonical. Drop any qualifiers as
5021 .debug_names does not contain any. */
5023 if (strchr (name
, '(') != NULL
)
5025 without_params
= cp_remove_params (name
);
5026 if (without_params
!= NULL
)
5027 name
= without_params
.get ();
5031 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5033 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5035 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5036 (map
.bucket_table_reordered
5037 + (full_hash
% map
.bucket_count
)), 4,
5038 map
.dwarf5_byte_order
);
5042 if (namei
>= map
.name_count
)
5044 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5046 namei
, map
.name_count
,
5047 objfile_name (per_objfile
->objfile
));
5053 const uint32_t namei_full_hash
5054 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5055 (map
.hash_table_reordered
+ namei
), 4,
5056 map
.dwarf5_byte_order
);
5057 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5060 if (full_hash
== namei_full_hash
)
5062 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5064 #if 0 /* An expensive sanity check. */
5065 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5067 complaint (_("Wrong .debug_names hash for string at index %u "
5069 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5074 if (cmp (namei_string
, name
) == 0)
5076 const ULONGEST namei_entry_offs
5077 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5078 + namei
* map
.offset_size
),
5079 map
.offset_size
, map
.dwarf5_byte_order
);
5080 return map
.entry_pool
+ namei_entry_offs
;
5085 if (namei
>= map
.name_count
)
5091 dw2_debug_names_iterator::find_vec_in_debug_names
5092 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5094 if (namei
>= map
.name_count
)
5096 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5098 namei
, map
.name_count
,
5099 objfile_name (per_objfile
->objfile
));
5103 const ULONGEST namei_entry_offs
5104 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5105 + namei
* map
.offset_size
),
5106 map
.offset_size
, map
.dwarf5_byte_order
);
5107 return map
.entry_pool
+ namei_entry_offs
;
5110 /* See dw2_debug_names_iterator. */
5112 dwarf2_per_cu_data
*
5113 dw2_debug_names_iterator::next ()
5118 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5119 struct objfile
*objfile
= m_per_objfile
->objfile
;
5120 bfd
*const abfd
= objfile
->obfd
;
5124 unsigned int bytes_read
;
5125 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5126 m_addr
+= bytes_read
;
5130 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5131 if (indexval_it
== m_map
.abbrev_map
.cend ())
5133 complaint (_("Wrong .debug_names undefined abbrev code %s "
5135 pulongest (abbrev
), objfile_name (objfile
));
5138 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5139 enum class symbol_linkage
{
5143 } symbol_linkage_
= symbol_linkage::unknown
;
5144 dwarf2_per_cu_data
*per_cu
= NULL
;
5145 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5150 case DW_FORM_implicit_const
:
5151 ull
= attr
.implicit_const
;
5153 case DW_FORM_flag_present
:
5157 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5158 m_addr
+= bytes_read
;
5161 ull
= read_4_bytes (abfd
, m_addr
);
5165 ull
= read_8_bytes (abfd
, m_addr
);
5168 case DW_FORM_ref_sig8
:
5169 ull
= read_8_bytes (abfd
, m_addr
);
5173 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5174 dwarf_form_name (attr
.form
),
5175 objfile_name (objfile
));
5178 switch (attr
.dw_idx
)
5180 case DW_IDX_compile_unit
:
5181 /* Don't crash on bad data. */
5182 if (ull
>= per_bfd
->all_comp_units
.size ())
5184 complaint (_(".debug_names entry has bad CU index %s"
5187 objfile_name (objfile
));
5190 per_cu
= per_bfd
->get_cu (ull
);
5192 case DW_IDX_type_unit
:
5193 /* Don't crash on bad data. */
5194 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5196 complaint (_(".debug_names entry has bad TU index %s"
5199 objfile_name (objfile
));
5202 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5204 case DW_IDX_die_offset
:
5205 /* In a per-CU index (as opposed to a per-module index), index
5206 entries without CU attribute implicitly refer to the single CU. */
5208 per_cu
= per_bfd
->get_cu (0);
5210 case DW_IDX_GNU_internal
:
5211 if (!m_map
.augmentation_is_gdb
)
5213 symbol_linkage_
= symbol_linkage::static_
;
5215 case DW_IDX_GNU_external
:
5216 if (!m_map
.augmentation_is_gdb
)
5218 symbol_linkage_
= symbol_linkage::extern_
;
5223 /* Skip if already read in. */
5224 if (m_per_objfile
->symtab_set_p (per_cu
))
5227 /* Check static vs global. */
5228 if (symbol_linkage_
!= symbol_linkage::unknown
)
5230 if (symbol_linkage_
== symbol_linkage::static_
)
5232 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5237 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5242 /* Match dw2_symtab_iter_next, symbol_kind
5243 and debug_names::psymbol_tag. */
5247 switch (indexval
.dwarf_tag
)
5249 case DW_TAG_variable
:
5250 case DW_TAG_subprogram
:
5251 /* Some types are also in VAR_DOMAIN. */
5252 case DW_TAG_typedef
:
5253 case DW_TAG_structure_type
:
5260 switch (indexval
.dwarf_tag
)
5262 case DW_TAG_typedef
:
5263 case DW_TAG_structure_type
:
5270 switch (indexval
.dwarf_tag
)
5273 case DW_TAG_variable
:
5280 switch (indexval
.dwarf_tag
)
5292 /* Match dw2_expand_symtabs_matching, symbol_kind and
5293 debug_names::psymbol_tag. */
5296 case VARIABLES_DOMAIN
:
5297 switch (indexval
.dwarf_tag
)
5299 case DW_TAG_variable
:
5305 case FUNCTIONS_DOMAIN
:
5306 switch (indexval
.dwarf_tag
)
5308 case DW_TAG_subprogram
:
5315 switch (indexval
.dwarf_tag
)
5317 case DW_TAG_typedef
:
5318 case DW_TAG_structure_type
:
5324 case MODULES_DOMAIN
:
5325 switch (indexval
.dwarf_tag
)
5339 /* This dumps minimal information about .debug_names. It is called
5340 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5341 uses this to verify that .debug_names has been loaded. */
5344 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5346 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5348 gdb_assert (per_objfile
->per_bfd
->using_index
);
5349 printf_filtered (".debug_names:");
5350 if (per_objfile
->per_bfd
->debug_names_table
)
5351 printf_filtered (" exists\n");
5353 printf_filtered (" faked for \"readnow\"\n");
5354 printf_filtered ("\n");
5358 dwarf2_debug_names_index::expand_matching_symbols
5359 (struct objfile
*objfile
,
5360 const lookup_name_info
&name
, domain_enum domain
,
5362 symbol_compare_ftype
*ordered_compare
)
5364 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5366 /* debug_names_table is NULL if OBJF_READNOW. */
5367 if (!per_objfile
->per_bfd
->debug_names_table
)
5370 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5371 const block_search_flags block_flags
5372 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5374 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5375 auto matcher
= [&] (const char *symname
)
5377 if (ordered_compare
== nullptr)
5379 return ordered_compare (symname
, match_name
) == 0;
5382 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5383 [&] (offset_type namei
)
5385 /* The name was matched, now expand corresponding CUs that were
5387 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5390 struct dwarf2_per_cu_data
*per_cu
;
5391 while ((per_cu
= iter
.next ()) != NULL
)
5392 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5399 dwarf2_debug_names_index::expand_symtabs_matching
5400 (struct objfile
*objfile
,
5401 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5402 const lookup_name_info
*lookup_name
,
5403 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5404 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5405 block_search_flags search_flags
,
5407 enum search_domain kind
)
5409 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5411 /* debug_names_table is NULL if OBJF_READNOW. */
5412 if (!per_objfile
->per_bfd
->debug_names_table
)
5415 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5417 /* This invariant is documented in quick-functions.h. */
5418 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
5419 if (lookup_name
== nullptr)
5421 for (dwarf2_per_cu_data
*per_cu
5422 : all_comp_units_range (per_objfile
->per_bfd
))
5426 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5434 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5437 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5439 [&] (offset_type namei
)
5441 /* The name was matched, now expand corresponding CUs that were
5443 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5445 struct dwarf2_per_cu_data
*per_cu
;
5446 while ((per_cu
= iter
.next ()) != NULL
)
5447 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5457 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5458 to either a dwarf2_per_bfd or dwz_file object. */
5460 template <typename T
>
5461 static gdb::array_view
<const gdb_byte
>
5462 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5464 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5466 if (section
->empty ())
5469 /* Older elfutils strip versions could keep the section in the main
5470 executable while splitting it for the separate debug info file. */
5471 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5474 section
->read (obj
);
5476 /* dwarf2_section_info::size is a bfd_size_type, while
5477 gdb::array_view works with size_t. On 32-bit hosts, with
5478 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5479 is 32-bit. So we need an explicit narrowing conversion here.
5480 This is fine, because it's impossible to allocate or mmap an
5481 array/buffer larger than what size_t can represent. */
5482 return gdb::make_array_view (section
->buffer
, section
->size
);
5485 /* Lookup the index cache for the contents of the index associated to
5488 static gdb::array_view
<const gdb_byte
>
5489 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5491 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5492 if (build_id
== nullptr)
5495 return global_index_cache
.lookup_gdb_index (build_id
,
5496 &dwarf2_per_bfd
->index_cache_res
);
5499 /* Same as the above, but for DWZ. */
5501 static gdb::array_view
<const gdb_byte
>
5502 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5504 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5505 if (build_id
== nullptr)
5508 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5511 /* See dwarf2/public.h. */
5514 dwarf2_initialize_objfile (struct objfile
*objfile
)
5516 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5517 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5519 dwarf_read_debug_printf ("called");
5521 /* If we're about to read full symbols, don't bother with the
5522 indices. In this case we also don't care if some other debug
5523 format is making psymtabs, because they are all about to be
5525 if ((objfile
->flags
& OBJF_READNOW
))
5527 dwarf_read_debug_printf ("readnow requested");
5529 /* When using READNOW, the using_index flag (set below) indicates that
5530 PER_BFD was already initialized, when we loaded some other objfile. */
5531 if (per_bfd
->using_index
)
5533 dwarf_read_debug_printf ("using_index already set");
5534 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5538 per_bfd
->using_index
= 1;
5539 create_all_comp_units (per_objfile
);
5540 per_bfd
->quick_file_names_table
5541 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5543 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5545 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5547 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5548 struct dwarf2_per_cu_quick_data
);
5551 /* Arrange for gdb to see the "quick" functions. However, these
5552 functions will be no-ops because we will have expanded all
5554 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5558 /* Was a debug names index already read when we processed an objfile sharing
5560 if (per_bfd
->debug_names_table
!= nullptr)
5562 dwarf_read_debug_printf ("re-using shared debug names table");
5563 objfile
->qf
.push_front (make_dwarf_debug_names ());
5567 /* Was a GDB index already read when we processed an objfile sharing
5569 if (per_bfd
->index_table
!= nullptr)
5571 dwarf_read_debug_printf ("re-using shared index table");
5572 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5576 /* There might already be partial symtabs built for this BFD. This happens
5577 when loading the same binary twice with the index-cache enabled. If so,
5578 don't try to read an index. The objfile / per_objfile initialization will
5579 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5581 if (per_bfd
->partial_symtabs
!= nullptr)
5583 dwarf_read_debug_printf ("re-using shared partial symtabs");
5584 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5588 if (dwarf2_read_debug_names (per_objfile
))
5590 dwarf_read_debug_printf ("found debug names");
5591 objfile
->qf
.push_front (make_dwarf_debug_names ());
5595 if (dwarf2_read_gdb_index (per_objfile
,
5596 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5597 get_gdb_index_contents_from_section
<dwz_file
>))
5599 dwarf_read_debug_printf ("found gdb index from file");
5600 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5604 /* ... otherwise, try to find the index in the index cache. */
5605 if (dwarf2_read_gdb_index (per_objfile
,
5606 get_gdb_index_contents_from_cache
,
5607 get_gdb_index_contents_from_cache_dwz
))
5609 dwarf_read_debug_printf ("found gdb index from cache");
5610 global_index_cache
.hit ();
5611 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5615 global_index_cache
.miss ();
5616 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5621 /* Build a partial symbol table. */
5624 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5626 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5627 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5629 if (per_bfd
->partial_symtabs
!= nullptr)
5631 /* Partial symbols were already read, so now we can simply
5635 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5636 objfile
->qf
.emplace_front (psf
);
5639 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5645 psf
= new psymbol_functions
;
5646 objfile
->qf
.emplace_front (psf
);
5648 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5649 = psf
->get_partial_symtabs ();
5651 /* Set the local reference to partial symtabs, so that we don't try
5652 to read them again if reading another objfile with the same BFD.
5653 If we can't in fact share, this won't make a difference anyway as
5654 the dwarf2_per_bfd object won't be shared. */
5655 per_bfd
->partial_symtabs
= partial_symtabs
;
5659 /* This isn't really ideal: all the data we allocate on the
5660 objfile's obstack is still uselessly kept around. However,
5661 freeing it seems unsafe. */
5662 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5663 dwarf2_build_psymtabs_hard (per_objfile
);
5666 /* (maybe) store an index in the cache. */
5667 global_index_cache
.store (per_objfile
);
5669 catch (const gdb_exception_error
&except
)
5671 exception_print (gdb_stderr
, except
);
5675 /* Find the base address of the compilation unit for range lists and
5676 location lists. It will normally be specified by DW_AT_low_pc.
5677 In DWARF-3 draft 4, the base address could be overridden by
5678 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5679 compilation units with discontinuous ranges. */
5682 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5684 struct attribute
*attr
;
5686 cu
->base_address
.reset ();
5688 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5689 if (attr
!= nullptr)
5690 cu
->base_address
= attr
->as_address ();
5693 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5694 if (attr
!= nullptr)
5695 cu
->base_address
= attr
->as_address ();
5699 /* Helper function that returns the proper abbrev section for
5702 static struct dwarf2_section_info
*
5703 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5705 struct dwarf2_section_info
*abbrev
;
5706 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5708 if (this_cu
->is_dwz
)
5709 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5711 abbrev
= &per_bfd
->abbrev
;
5716 /* Fetch the abbreviation table offset from a comp or type unit header. */
5719 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5720 struct dwarf2_section_info
*section
,
5721 sect_offset sect_off
)
5723 bfd
*abfd
= section
->get_bfd_owner ();
5724 const gdb_byte
*info_ptr
;
5725 unsigned int initial_length_size
, offset_size
;
5728 section
->read (per_objfile
->objfile
);
5729 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5730 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5731 offset_size
= initial_length_size
== 4 ? 4 : 8;
5732 info_ptr
+= initial_length_size
;
5734 version
= read_2_bytes (abfd
, info_ptr
);
5738 /* Skip unit type and address size. */
5742 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5745 /* A partial symtab that is used only for include files. */
5746 struct dwarf2_include_psymtab
: public partial_symtab
5748 dwarf2_include_psymtab (const char *filename
,
5749 psymtab_storage
*partial_symtabs
,
5750 objfile_per_bfd_storage
*objfile_per_bfd
)
5751 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5755 void read_symtab (struct objfile
*objfile
) override
5757 /* It's an include file, no symbols to read for it.
5758 Everything is in the includer symtab. */
5760 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5761 expansion of the includer psymtab. We use the dependencies[0] field to
5762 model the includer. But if we go the regular route of calling
5763 expand_psymtab here, and having expand_psymtab call expand_dependencies
5764 to expand the includer, we'll only use expand_psymtab on the includer
5765 (making it a non-toplevel psymtab), while if we expand the includer via
5766 another path, we'll use read_symtab (making it a toplevel psymtab).
5767 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5768 psymtab, and trigger read_symtab on the includer here directly. */
5769 includer ()->read_symtab (objfile
);
5772 void expand_psymtab (struct objfile
*objfile
) override
5774 /* This is not called by read_symtab, and should not be called by any
5775 expand_dependencies. */
5779 bool readin_p (struct objfile
*objfile
) const override
5781 return includer ()->readin_p (objfile
);
5784 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5790 partial_symtab
*includer () const
5792 /* An include psymtab has exactly one dependency: the psymtab that
5794 gdb_assert (this->number_of_dependencies
== 1);
5795 return this->dependencies
[0];
5799 /* Allocate a new partial symtab for file named NAME and mark this new
5800 partial symtab as being an include of PST. */
5803 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5805 dwarf2_psymtab
*pst
,
5806 psymtab_storage
*partial_symtabs
,
5807 objfile_per_bfd_storage
*objfile_per_bfd
)
5809 dwarf2_include_psymtab
*subpst
5810 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5812 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5813 subpst
->dirname
= pst
->dirname
;
5815 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5816 subpst
->dependencies
[0] = pst
;
5817 subpst
->number_of_dependencies
= 1;
5820 /* Read the Line Number Program data and extract the list of files
5821 included by the source file represented by PST. Build an include
5822 partial symtab for each of these included files. */
5825 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5826 struct die_info
*die
,
5827 const file_and_directory
&fnd
,
5828 dwarf2_psymtab
*pst
)
5831 struct attribute
*attr
;
5833 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5834 if (attr
!= nullptr && attr
->form_is_unsigned ())
5835 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5837 return; /* No linetable, so no includes. */
5839 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5840 that we pass in the raw text_low here; that is ok because we're
5841 only decoding the line table to make include partial symtabs, and
5842 so the addresses aren't really used. */
5843 dwarf_decode_lines (lh
.get (), fnd
, cu
, pst
,
5844 pst
->raw_text_low (), 1);
5848 hash_signatured_type (const void *item
)
5850 const struct signatured_type
*sig_type
5851 = (const struct signatured_type
*) item
;
5853 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5854 return sig_type
->signature
;
5858 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5860 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5861 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5863 return lhs
->signature
== rhs
->signature
;
5866 /* Allocate a hash table for signatured types. */
5869 allocate_signatured_type_table ()
5871 return htab_up (htab_create_alloc (41,
5872 hash_signatured_type
,
5874 NULL
, xcalloc
, xfree
));
5877 /* A helper for create_debug_types_hash_table. Read types from SECTION
5878 and fill them into TYPES_HTAB. It will process only type units,
5879 therefore DW_UT_type. */
5882 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5883 struct dwo_file
*dwo_file
,
5884 dwarf2_section_info
*section
, htab_up
&types_htab
,
5885 rcuh_kind section_kind
)
5887 struct objfile
*objfile
= per_objfile
->objfile
;
5888 struct dwarf2_section_info
*abbrev_section
;
5890 const gdb_byte
*info_ptr
, *end_ptr
;
5892 abbrev_section
= &dwo_file
->sections
.abbrev
;
5894 dwarf_read_debug_printf ("Reading %s for %s",
5895 section
->get_name (),
5896 abbrev_section
->get_file_name ());
5898 section
->read (objfile
);
5899 info_ptr
= section
->buffer
;
5901 if (info_ptr
== NULL
)
5904 /* We can't set abfd until now because the section may be empty or
5905 not present, in which case the bfd is unknown. */
5906 abfd
= section
->get_bfd_owner ();
5908 /* We don't use cutu_reader here because we don't need to read
5909 any dies: the signature is in the header. */
5911 end_ptr
= info_ptr
+ section
->size
;
5912 while (info_ptr
< end_ptr
)
5914 signatured_type_up sig_type
;
5915 struct dwo_unit
*dwo_tu
;
5917 const gdb_byte
*ptr
= info_ptr
;
5918 struct comp_unit_head header
;
5919 unsigned int length
;
5921 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5923 /* Initialize it due to a false compiler warning. */
5924 header
.signature
= -1;
5925 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5927 /* We need to read the type's signature in order to build the hash
5928 table, but we don't need anything else just yet. */
5930 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5931 abbrev_section
, ptr
, section_kind
);
5933 length
= header
.get_length ();
5935 /* Skip dummy type units. */
5936 if (ptr
>= info_ptr
+ length
5937 || peek_abbrev_code (abfd
, ptr
) == 0
5938 || (header
.unit_type
!= DW_UT_type
5939 && header
.unit_type
!= DW_UT_split_type
))
5945 if (types_htab
== NULL
)
5946 types_htab
= allocate_dwo_unit_table ();
5948 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5949 dwo_tu
->dwo_file
= dwo_file
;
5950 dwo_tu
->signature
= header
.signature
;
5951 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5952 dwo_tu
->section
= section
;
5953 dwo_tu
->sect_off
= sect_off
;
5954 dwo_tu
->length
= length
;
5956 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5957 gdb_assert (slot
!= NULL
);
5959 complaint (_("debug type entry at offset %s is duplicate to"
5960 " the entry at offset %s, signature %s"),
5961 sect_offset_str (sect_off
),
5962 sect_offset_str (dwo_tu
->sect_off
),
5963 hex_string (header
.signature
));
5966 dwarf_read_debug_printf_v (" offset %s, signature %s",
5967 sect_offset_str (sect_off
),
5968 hex_string (header
.signature
));
5974 /* Create the hash table of all entries in the .debug_types
5975 (or .debug_types.dwo) section(s).
5976 DWO_FILE is a pointer to the DWO file object.
5978 The result is a pointer to the hash table or NULL if there are no types.
5980 Note: This function processes DWO files only, not DWP files. */
5983 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5984 struct dwo_file
*dwo_file
,
5985 gdb::array_view
<dwarf2_section_info
> type_sections
,
5986 htab_up
&types_htab
)
5988 for (dwarf2_section_info
§ion
: type_sections
)
5989 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5993 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5994 If SLOT is non-NULL, it is the entry to use in the hash table.
5995 Otherwise we find one. */
5997 static struct signatured_type
*
5998 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6000 if (per_objfile
->per_bfd
->all_comp_units
.size ()
6001 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
6002 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6004 signatured_type_up sig_type_holder
6005 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
6006 signatured_type
*sig_type
= sig_type_holder
.get ();
6008 per_objfile
->per_bfd
->all_comp_units
.emplace_back
6009 (sig_type_holder
.release ());
6010 if (per_objfile
->per_bfd
->using_index
)
6013 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6014 struct dwarf2_per_cu_quick_data
);
6019 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6022 gdb_assert (*slot
== NULL
);
6024 /* The rest of sig_type must be filled in by the caller. */
6028 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6029 Fill in SIG_ENTRY with DWO_ENTRY. */
6032 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6033 struct signatured_type
*sig_entry
,
6034 struct dwo_unit
*dwo_entry
)
6036 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6038 /* Make sure we're not clobbering something we don't expect to. */
6039 gdb_assert (! sig_entry
->queued
);
6040 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
6041 if (per_bfd
->using_index
)
6043 gdb_assert (sig_entry
->v
.quick
!= NULL
);
6044 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
6047 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
6048 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6049 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6050 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6051 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6053 sig_entry
->section
= dwo_entry
->section
;
6054 sig_entry
->sect_off
= dwo_entry
->sect_off
;
6055 sig_entry
->length
= dwo_entry
->length
;
6056 sig_entry
->reading_dwo_directly
= 1;
6057 sig_entry
->per_bfd
= per_bfd
;
6058 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6059 sig_entry
->dwo_unit
= dwo_entry
;
6062 /* Subroutine of lookup_signatured_type.
6063 If we haven't read the TU yet, create the signatured_type data structure
6064 for a TU to be read in directly from a DWO file, bypassing the stub.
6065 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6066 using .gdb_index, then when reading a CU we want to stay in the DWO file
6067 containing that CU. Otherwise we could end up reading several other DWO
6068 files (due to comdat folding) to process the transitive closure of all the
6069 mentioned TUs, and that can be slow. The current DWO file will have every
6070 type signature that it needs.
6071 We only do this for .gdb_index because in the psymtab case we already have
6072 to read all the DWOs to build the type unit groups. */
6074 static struct signatured_type
*
6075 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6077 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6078 struct dwo_file
*dwo_file
;
6079 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6082 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6084 /* If TU skeletons have been removed then we may not have read in any
6086 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6087 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6089 /* We only ever need to read in one copy of a signatured type.
6090 Use the global signatured_types array to do our own comdat-folding
6091 of types. If this is the first time we're reading this TU, and
6092 the TU has an entry in .gdb_index, replace the recorded data from
6093 .gdb_index with this TU. */
6095 signatured_type
find_sig_entry (sig
);
6096 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6097 &find_sig_entry
, INSERT
);
6098 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6100 /* We can get here with the TU already read, *or* in the process of being
6101 read. Don't reassign the global entry to point to this DWO if that's
6102 the case. Also note that if the TU is already being read, it may not
6103 have come from a DWO, the program may be a mix of Fission-compiled
6104 code and non-Fission-compiled code. */
6106 /* Have we already tried to read this TU?
6107 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6108 needn't exist in the global table yet). */
6109 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6112 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6113 dwo_unit of the TU itself. */
6114 dwo_file
= cu
->dwo_unit
->dwo_file
;
6116 /* Ok, this is the first time we're reading this TU. */
6117 if (dwo_file
->tus
== NULL
)
6119 find_dwo_entry
.signature
= sig
;
6120 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6122 if (dwo_entry
== NULL
)
6125 /* If the global table doesn't have an entry for this TU, add one. */
6126 if (sig_entry
== NULL
)
6127 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6129 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6130 sig_entry
->tu_read
= 1;
6134 /* Subroutine of lookup_signatured_type.
6135 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6136 then try the DWP file. If the TU stub (skeleton) has been removed then
6137 it won't be in .gdb_index. */
6139 static struct signatured_type
*
6140 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6142 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6143 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6144 struct dwo_unit
*dwo_entry
;
6147 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6148 gdb_assert (dwp_file
!= NULL
);
6150 /* If TU skeletons have been removed then we may not have read in any
6152 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6153 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6155 signatured_type
find_sig_entry (sig
);
6156 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6157 &find_sig_entry
, INSERT
);
6158 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6160 /* Have we already tried to read this TU?
6161 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6162 needn't exist in the global table yet). */
6163 if (sig_entry
!= NULL
)
6166 if (dwp_file
->tus
== NULL
)
6168 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6169 1 /* is_debug_types */);
6170 if (dwo_entry
== NULL
)
6173 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6174 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6179 /* Lookup a signature based type for DW_FORM_ref_sig8.
6180 Returns NULL if signature SIG is not present in the table.
6181 It is up to the caller to complain about this. */
6183 static struct signatured_type
*
6184 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6186 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6188 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6190 /* We're in a DWO/DWP file, and we're using .gdb_index.
6191 These cases require special processing. */
6192 if (get_dwp_file (per_objfile
) == NULL
)
6193 return lookup_dwo_signatured_type (cu
, sig
);
6195 return lookup_dwp_signatured_type (cu
, sig
);
6199 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6201 signatured_type
find_entry (sig
);
6202 return ((struct signatured_type
*)
6203 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6208 /* Low level DIE reading support. */
6210 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6213 init_cu_die_reader (struct die_reader_specs
*reader
,
6214 struct dwarf2_cu
*cu
,
6215 struct dwarf2_section_info
*section
,
6216 struct dwo_file
*dwo_file
,
6217 struct abbrev_table
*abbrev_table
)
6219 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6220 reader
->abfd
= section
->get_bfd_owner ();
6222 reader
->dwo_file
= dwo_file
;
6223 reader
->die_section
= section
;
6224 reader
->buffer
= section
->buffer
;
6225 reader
->buffer_end
= section
->buffer
+ section
->size
;
6226 reader
->abbrev_table
= abbrev_table
;
6229 /* Subroutine of cutu_reader to simplify it.
6230 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6231 There's just a lot of work to do, and cutu_reader is big enough
6234 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6235 from it to the DIE in the DWO. If NULL we are skipping the stub.
6236 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6237 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6238 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6239 STUB_COMP_DIR may be non-NULL.
6240 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6241 are filled in with the info of the DIE from the DWO file.
6242 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6243 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6244 kept around for at least as long as *RESULT_READER.
6246 The result is non-zero if a valid (non-dummy) DIE was found. */
6249 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6250 struct dwo_unit
*dwo_unit
,
6251 struct die_info
*stub_comp_unit_die
,
6252 const char *stub_comp_dir
,
6253 struct die_reader_specs
*result_reader
,
6254 const gdb_byte
**result_info_ptr
,
6255 struct die_info
**result_comp_unit_die
,
6256 abbrev_table_up
*result_dwo_abbrev_table
)
6258 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6259 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6260 struct objfile
*objfile
= per_objfile
->objfile
;
6262 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6263 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6264 int i
,num_extra_attrs
;
6265 struct dwarf2_section_info
*dwo_abbrev_section
;
6266 struct die_info
*comp_unit_die
;
6268 /* At most one of these may be provided. */
6269 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6271 /* These attributes aren't processed until later:
6272 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6273 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6274 referenced later. However, these attributes are found in the stub
6275 which we won't have later. In order to not impose this complication
6276 on the rest of the code, we read them here and copy them to the
6285 if (stub_comp_unit_die
!= NULL
)
6287 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6289 if (!per_cu
->is_debug_types
)
6290 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6291 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6292 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6293 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6294 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6296 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6298 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6299 We need the value before we can process DW_AT_ranges values from the
6301 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6303 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6304 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6305 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6306 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6308 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6310 else if (stub_comp_dir
!= NULL
)
6312 /* Reconstruct the comp_dir attribute to simplify the code below. */
6313 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6314 comp_dir
->name
= DW_AT_comp_dir
;
6315 comp_dir
->form
= DW_FORM_string
;
6316 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6319 /* Set up for reading the DWO CU/TU. */
6320 cu
->dwo_unit
= dwo_unit
;
6321 dwarf2_section_info
*section
= dwo_unit
->section
;
6322 section
->read (objfile
);
6323 abfd
= section
->get_bfd_owner ();
6324 begin_info_ptr
= info_ptr
= (section
->buffer
6325 + to_underlying (dwo_unit
->sect_off
));
6326 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6328 if (per_cu
->is_debug_types
)
6330 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6332 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6333 section
, dwo_abbrev_section
,
6334 info_ptr
, rcuh_kind::TYPE
);
6335 /* This is not an assert because it can be caused by bad debug info. */
6336 if (sig_type
->signature
!= cu
->header
.signature
)
6338 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6339 " TU at offset %s [in module %s]"),
6340 hex_string (sig_type
->signature
),
6341 hex_string (cu
->header
.signature
),
6342 sect_offset_str (dwo_unit
->sect_off
),
6343 bfd_get_filename (abfd
));
6345 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6346 /* For DWOs coming from DWP files, we don't know the CU length
6347 nor the type's offset in the TU until now. */
6348 dwo_unit
->length
= cu
->header
.get_length ();
6349 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6351 /* Establish the type offset that can be used to lookup the type.
6352 For DWO files, we don't know it until now. */
6353 sig_type
->type_offset_in_section
6354 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6358 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6359 section
, dwo_abbrev_section
,
6360 info_ptr
, rcuh_kind::COMPILE
);
6361 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6362 /* For DWOs coming from DWP files, we don't know the CU length
6364 dwo_unit
->length
= cu
->header
.get_length ();
6367 dwo_abbrev_section
->read (objfile
);
6368 *result_dwo_abbrev_table
6369 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6370 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6371 result_dwo_abbrev_table
->get ());
6373 /* Read in the die, but leave space to copy over the attributes
6374 from the stub. This has the benefit of simplifying the rest of
6375 the code - all the work to maintain the illusion of a single
6376 DW_TAG_{compile,type}_unit DIE is done here. */
6377 num_extra_attrs
= ((stmt_list
!= NULL
)
6381 + (comp_dir
!= NULL
));
6382 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6385 /* Copy over the attributes from the stub to the DIE we just read in. */
6386 comp_unit_die
= *result_comp_unit_die
;
6387 i
= comp_unit_die
->num_attrs
;
6388 if (stmt_list
!= NULL
)
6389 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6391 comp_unit_die
->attrs
[i
++] = *low_pc
;
6392 if (high_pc
!= NULL
)
6393 comp_unit_die
->attrs
[i
++] = *high_pc
;
6395 comp_unit_die
->attrs
[i
++] = *ranges
;
6396 if (comp_dir
!= NULL
)
6397 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6398 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6400 if (dwarf_die_debug
)
6402 fprintf_unfiltered (gdb_stdlog
,
6403 "Read die from %s@0x%x of %s:\n",
6404 section
->get_name (),
6405 (unsigned) (begin_info_ptr
- section
->buffer
),
6406 bfd_get_filename (abfd
));
6407 dump_die (comp_unit_die
, dwarf_die_debug
);
6410 /* Skip dummy compilation units. */
6411 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6412 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6415 *result_info_ptr
= info_ptr
;
6419 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6420 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6421 signature is part of the header. */
6422 static gdb::optional
<ULONGEST
>
6423 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6425 if (cu
->header
.version
>= 5)
6426 return cu
->header
.signature
;
6427 struct attribute
*attr
;
6428 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6429 if (attr
== nullptr || !attr
->form_is_unsigned ())
6430 return gdb::optional
<ULONGEST
> ();
6431 return attr
->as_unsigned ();
6434 /* Subroutine of cutu_reader to simplify it.
6435 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6436 Returns NULL if the specified DWO unit cannot be found. */
6438 static struct dwo_unit
*
6439 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6441 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6442 struct dwo_unit
*dwo_unit
;
6443 const char *comp_dir
;
6445 gdb_assert (cu
!= NULL
);
6447 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6448 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6449 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6451 if (per_cu
->is_debug_types
)
6452 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6455 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6457 if (!signature
.has_value ())
6458 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6460 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6462 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6468 /* Subroutine of cutu_reader to simplify it.
6469 See it for a description of the parameters.
6470 Read a TU directly from a DWO file, bypassing the stub. */
6473 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6474 dwarf2_per_objfile
*per_objfile
,
6475 dwarf2_cu
*existing_cu
)
6477 struct signatured_type
*sig_type
;
6479 /* Verify we can do the following downcast, and that we have the
6481 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6482 sig_type
= (struct signatured_type
*) this_cu
;
6483 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6487 if (existing_cu
!= nullptr)
6490 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6491 /* There's no need to do the rereading_dwo_cu handling that
6492 cutu_reader does since we don't read the stub. */
6496 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6497 in per_objfile yet. */
6498 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6499 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6500 cu
= m_new_cu
.get ();
6503 /* A future optimization, if needed, would be to use an existing
6504 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6505 could share abbrev tables. */
6507 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6508 NULL
/* stub_comp_unit_die */,
6509 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6512 &m_dwo_abbrev_table
) == 0)
6519 /* Initialize a CU (or TU) and read its DIEs.
6520 If the CU defers to a DWO file, read the DWO file as well.
6522 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6523 Otherwise the table specified in the comp unit header is read in and used.
6524 This is an optimization for when we already have the abbrev table.
6526 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6529 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6530 dwarf2_per_objfile
*per_objfile
,
6531 struct abbrev_table
*abbrev_table
,
6532 dwarf2_cu
*existing_cu
,
6534 : die_reader_specs
{},
6537 struct objfile
*objfile
= per_objfile
->objfile
;
6538 struct dwarf2_section_info
*section
= this_cu
->section
;
6539 bfd
*abfd
= section
->get_bfd_owner ();
6540 const gdb_byte
*begin_info_ptr
;
6541 struct signatured_type
*sig_type
= NULL
;
6542 struct dwarf2_section_info
*abbrev_section
;
6543 /* Non-zero if CU currently points to a DWO file and we need to
6544 reread it. When this happens we need to reread the skeleton die
6545 before we can reread the DWO file (this only applies to CUs, not TUs). */
6546 int rereading_dwo_cu
= 0;
6548 if (dwarf_die_debug
)
6549 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6550 this_cu
->is_debug_types
? "type" : "comp",
6551 sect_offset_str (this_cu
->sect_off
));
6553 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6554 file (instead of going through the stub), short-circuit all of this. */
6555 if (this_cu
->reading_dwo_directly
)
6557 /* Narrow down the scope of possibilities to have to understand. */
6558 gdb_assert (this_cu
->is_debug_types
);
6559 gdb_assert (abbrev_table
== NULL
);
6560 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6564 /* This is cheap if the section is already read in. */
6565 section
->read (objfile
);
6567 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6569 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6573 if (existing_cu
!= nullptr)
6576 /* If this CU is from a DWO file we need to start over, we need to
6577 refetch the attributes from the skeleton CU.
6578 This could be optimized by retrieving those attributes from when we
6579 were here the first time: the previous comp_unit_die was stored in
6580 comp_unit_obstack. But there's no data yet that we need this
6582 if (cu
->dwo_unit
!= NULL
)
6583 rereading_dwo_cu
= 1;
6587 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6588 in per_objfile yet. */
6589 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6590 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6591 cu
= m_new_cu
.get ();
6594 /* Get the header. */
6595 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6597 /* We already have the header, there's no need to read it in again. */
6598 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6602 if (this_cu
->is_debug_types
)
6604 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6605 section
, abbrev_section
,
6606 info_ptr
, rcuh_kind::TYPE
);
6608 /* Since per_cu is the first member of struct signatured_type,
6609 we can go from a pointer to one to a pointer to the other. */
6610 sig_type
= (struct signatured_type
*) this_cu
;
6611 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6612 gdb_assert (sig_type
->type_offset_in_tu
6613 == cu
->header
.type_cu_offset_in_tu
);
6614 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6616 /* LENGTH has not been set yet for type units if we're
6617 using .gdb_index. */
6618 this_cu
->length
= cu
->header
.get_length ();
6620 /* Establish the type offset that can be used to lookup the type. */
6621 sig_type
->type_offset_in_section
=
6622 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6624 this_cu
->dwarf_version
= cu
->header
.version
;
6628 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6629 section
, abbrev_section
,
6631 rcuh_kind::COMPILE
);
6633 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6634 if (this_cu
->length
== 0)
6635 this_cu
->length
= cu
->header
.get_length ();
6637 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6638 this_cu
->dwarf_version
= cu
->header
.version
;
6642 /* Skip dummy compilation units. */
6643 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6644 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6650 /* If we don't have them yet, read the abbrevs for this compilation unit.
6651 And if we need to read them now, make sure they're freed when we're
6653 if (abbrev_table
!= NULL
)
6654 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6657 abbrev_section
->read (objfile
);
6658 m_abbrev_table_holder
6659 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6660 abbrev_table
= m_abbrev_table_holder
.get ();
6663 /* Read the top level CU/TU die. */
6664 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6665 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6667 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6673 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6674 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6675 table from the DWO file and pass the ownership over to us. It will be
6676 referenced from READER, so we must make sure to free it after we're done
6679 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6680 DWO CU, that this test will fail (the attribute will not be present). */
6681 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6682 if (dwo_name
!= nullptr)
6684 struct dwo_unit
*dwo_unit
;
6685 struct die_info
*dwo_comp_unit_die
;
6687 if (comp_unit_die
->has_children
)
6689 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6690 " has children (offset %s) [in module %s]"),
6691 sect_offset_str (this_cu
->sect_off
),
6692 bfd_get_filename (abfd
));
6694 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6695 if (dwo_unit
!= NULL
)
6697 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6698 comp_unit_die
, NULL
,
6701 &m_dwo_abbrev_table
) == 0)
6707 comp_unit_die
= dwo_comp_unit_die
;
6711 /* Yikes, we couldn't find the rest of the DIE, we only have
6712 the stub. A complaint has already been logged. There's
6713 not much more we can do except pass on the stub DIE to
6714 die_reader_func. We don't want to throw an error on bad
6721 cutu_reader::keep ()
6723 /* Done, clean up. */
6724 gdb_assert (!dummy_p
);
6725 if (m_new_cu
!= NULL
)
6727 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6729 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6730 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6734 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6735 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6736 assumed to have already done the lookup to find the DWO file).
6738 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6739 THIS_CU->is_debug_types, but nothing else.
6741 We fill in THIS_CU->length.
6743 THIS_CU->cu is always freed when done.
6744 This is done in order to not leave THIS_CU->cu in a state where we have
6745 to care whether it refers to the "main" CU or the DWO CU.
6747 When parent_cu is passed, it is used to provide a default value for
6748 str_offsets_base and addr_base from the parent. */
6750 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6751 dwarf2_per_objfile
*per_objfile
,
6752 struct dwarf2_cu
*parent_cu
,
6753 struct dwo_file
*dwo_file
)
6754 : die_reader_specs
{},
6757 struct objfile
*objfile
= per_objfile
->objfile
;
6758 struct dwarf2_section_info
*section
= this_cu
->section
;
6759 bfd
*abfd
= section
->get_bfd_owner ();
6760 struct dwarf2_section_info
*abbrev_section
;
6761 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6763 if (dwarf_die_debug
)
6764 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6765 this_cu
->is_debug_types
? "type" : "comp",
6766 sect_offset_str (this_cu
->sect_off
));
6768 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6770 abbrev_section
= (dwo_file
!= NULL
6771 ? &dwo_file
->sections
.abbrev
6772 : get_abbrev_section_for_cu (this_cu
));
6774 /* This is cheap if the section is already read in. */
6775 section
->read (objfile
);
6777 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6779 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6780 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6781 section
, abbrev_section
, info_ptr
,
6782 (this_cu
->is_debug_types
6784 : rcuh_kind::COMPILE
));
6786 if (parent_cu
!= nullptr)
6788 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6789 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6791 this_cu
->length
= m_new_cu
->header
.get_length ();
6793 /* Skip dummy compilation units. */
6794 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6795 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6801 abbrev_section
->read (objfile
);
6802 m_abbrev_table_holder
6803 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6805 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6806 m_abbrev_table_holder
.get ());
6807 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6811 /* Type Unit Groups.
6813 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6814 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6815 so that all types coming from the same compilation (.o file) are grouped
6816 together. A future step could be to put the types in the same symtab as
6817 the CU the types ultimately came from. */
6820 hash_type_unit_group (const void *item
)
6822 const struct type_unit_group
*tu_group
6823 = (const struct type_unit_group
*) item
;
6825 return hash_stmt_list_entry (&tu_group
->hash
);
6829 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6831 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6832 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6834 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6837 /* Allocate a hash table for type unit groups. */
6840 allocate_type_unit_groups_table ()
6842 return htab_up (htab_create_alloc (3,
6843 hash_type_unit_group
,
6845 htab_delete_entry
<type_unit_group
>,
6849 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6850 partial symtabs. We combine several TUs per psymtab to not let the size
6851 of any one psymtab grow too big. */
6852 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6853 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6855 /* Helper routine for get_type_unit_group.
6856 Create the type_unit_group object used to hold one or more TUs. */
6858 static std::unique_ptr
<type_unit_group
>
6859 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6861 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6862 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6864 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6865 tu_group
->per_bfd
= per_bfd
;
6867 if (per_bfd
->using_index
)
6869 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6870 struct dwarf2_per_cu_quick_data
);
6874 unsigned int line_offset
= to_underlying (line_offset_struct
);
6875 dwarf2_psymtab
*pst
;
6878 /* Give the symtab a useful name for debug purposes. */
6879 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6880 name
= string_printf ("<type_units_%d>",
6881 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6883 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6885 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6887 pst
->anonymous
= true;
6890 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6891 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6896 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6897 STMT_LIST is a DW_AT_stmt_list attribute. */
6899 static struct type_unit_group
*
6900 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6902 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6903 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6904 struct type_unit_group
*tu_group
;
6906 unsigned int line_offset
;
6907 struct type_unit_group type_unit_group_for_lookup
;
6909 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6910 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6912 /* Do we need to create a new group, or can we use an existing one? */
6914 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6916 line_offset
= stmt_list
->as_unsigned ();
6917 ++tu_stats
->nr_symtab_sharers
;
6921 /* Ugh, no stmt_list. Rare, but we have to handle it.
6922 We can do various things here like create one group per TU or
6923 spread them over multiple groups to split up the expansion work.
6924 To avoid worst case scenarios (too many groups or too large groups)
6925 we, umm, group them in bunches. */
6926 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6927 | (tu_stats
->nr_stmt_less_type_units
6928 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6929 ++tu_stats
->nr_stmt_less_type_units
;
6932 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6933 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6934 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6935 &type_unit_group_for_lookup
, INSERT
);
6936 if (*slot
== nullptr)
6938 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6939 std::unique_ptr
<type_unit_group
> grp
6940 = create_type_unit_group (cu
, line_offset_struct
);
6941 *slot
= grp
.release ();
6942 ++tu_stats
->nr_symtabs
;
6945 tu_group
= (struct type_unit_group
*) *slot
;
6946 gdb_assert (tu_group
!= nullptr);
6950 /* Partial symbol tables. */
6952 /* Create a psymtab named NAME and assign it to PER_CU.
6954 The caller must fill in the following details:
6955 dirname, textlow, texthigh. */
6957 static dwarf2_psymtab
*
6958 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6959 dwarf2_per_objfile
*per_objfile
,
6963 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6964 per_objfile
->objfile
->per_bfd
, per_cu
);
6966 pst
->psymtabs_addrmap_supported
= true;
6968 /* This is the glue that links PST into GDB's symbol API. */
6969 per_cu
->v
.psymtab
= pst
;
6974 /* DIE reader function for process_psymtab_comp_unit. */
6977 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6978 const gdb_byte
*info_ptr
,
6979 struct die_info
*comp_unit_die
,
6980 enum language pretend_language
)
6982 struct dwarf2_cu
*cu
= reader
->cu
;
6983 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6984 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6985 struct objfile
*objfile
= per_objfile
->objfile
;
6986 struct gdbarch
*gdbarch
= objfile
->arch ();
6987 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6989 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6990 dwarf2_psymtab
*pst
;
6991 enum pc_bounds_kind cu_bounds_kind
;
6993 gdb_assert (! per_cu
->is_debug_types
);
6995 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
6997 /* Allocate a new partial symbol table structure. */
6998 gdb::unique_xmalloc_ptr
<char> debug_filename
;
6999 static const char artificial
[] = "<artificial>";
7000 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
7001 if (strcmp (fnd
.name
, artificial
) == 0)
7003 debug_filename
.reset (concat (artificial
, "@",
7004 sect_offset_str (per_cu
->sect_off
),
7006 fnd
.name
= debug_filename
.get ();
7009 pst
= create_partial_symtab (per_cu
, per_objfile
, fnd
.name
);
7011 /* This must be done before calling dwarf2_build_include_psymtabs. */
7012 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7014 baseaddr
= objfile
->text_section_offset ();
7016 dwarf2_find_base_address (comp_unit_die
, cu
);
7018 /* Possibly set the default values of LOWPC and HIGHPC from
7020 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7021 &best_highpc
, cu
, pst
);
7022 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7025 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7028 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7030 /* Store the contiguous range if it is not empty; it can be
7031 empty for CUs with no code. */
7032 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7036 /* Check if comp unit has_children.
7037 If so, read the rest of the partial symbols from this comp unit.
7038 If not, there's no more debug_info for this comp unit. */
7039 if (comp_unit_die
->has_children
)
7041 struct partial_die_info
*first_die
;
7042 CORE_ADDR lowpc
, highpc
;
7044 lowpc
= ((CORE_ADDR
) -1);
7045 highpc
= ((CORE_ADDR
) 0);
7047 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7049 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7050 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7052 /* If we didn't find a lowpc, set it to highpc to avoid
7053 complaints from `maint check'. */
7054 if (lowpc
== ((CORE_ADDR
) -1))
7057 /* If the compilation unit didn't have an explicit address range,
7058 then use the information extracted from its child dies. */
7059 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7062 best_highpc
= highpc
;
7065 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7066 best_lowpc
+ baseaddr
)
7068 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7069 best_highpc
+ baseaddr
)
7074 if (!cu
->per_cu
->imported_symtabs_empty ())
7077 int len
= cu
->per_cu
->imported_symtabs_size ();
7079 /* Fill in 'dependencies' here; we fill in 'users' in a
7081 pst
->number_of_dependencies
= len
;
7083 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7084 for (i
= 0; i
< len
; ++i
)
7086 pst
->dependencies
[i
]
7087 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7090 cu
->per_cu
->imported_symtabs_free ();
7093 /* Get the list of files included in the current compilation unit,
7094 and build a psymtab for each of them. */
7095 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, fnd
, pst
);
7097 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7098 ", %d global, %d static syms",
7099 per_cu
->is_debug_types
? "type" : "comp",
7100 sect_offset_str (per_cu
->sect_off
),
7101 paddress (gdbarch
, pst
->text_low (objfile
)),
7102 paddress (gdbarch
, pst
->text_high (objfile
)),
7103 (int) pst
->global_psymbols
.size (),
7104 (int) pst
->static_psymbols
.size ());
7107 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7108 Process compilation unit THIS_CU for a psymtab. */
7111 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7112 dwarf2_per_objfile
*per_objfile
,
7113 bool want_partial_unit
,
7114 enum language pretend_language
)
7116 /* If this compilation unit was already read in, free the
7117 cached copy in order to read it in again. This is
7118 necessary because we skipped some symbols when we first
7119 read in the compilation unit (see load_partial_dies).
7120 This problem could be avoided, but the benefit is unclear. */
7121 per_objfile
->remove_cu (this_cu
);
7123 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7125 if (reader
.comp_unit_die
== nullptr)
7128 switch (reader
.comp_unit_die
->tag
)
7130 case DW_TAG_compile_unit
:
7131 this_cu
->unit_type
= DW_UT_compile
;
7133 case DW_TAG_partial_unit
:
7134 this_cu
->unit_type
= DW_UT_partial
;
7136 case DW_TAG_type_unit
:
7137 this_cu
->unit_type
= DW_UT_type
;
7140 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7141 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7142 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7143 objfile_name (per_objfile
->objfile
));
7150 else if (this_cu
->is_debug_types
)
7151 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7152 reader
.comp_unit_die
);
7153 else if (want_partial_unit
7154 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7155 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7156 reader
.comp_unit_die
,
7159 /* Age out any secondary CUs. */
7160 per_objfile
->age_comp_units ();
7163 /* Reader function for build_type_psymtabs. */
7166 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7167 const gdb_byte
*info_ptr
,
7168 struct die_info
*type_unit_die
)
7170 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7171 struct dwarf2_cu
*cu
= reader
->cu
;
7172 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7173 struct signatured_type
*sig_type
;
7174 struct type_unit_group
*tu_group
;
7175 struct attribute
*attr
;
7176 struct partial_die_info
*first_die
;
7177 CORE_ADDR lowpc
, highpc
;
7178 dwarf2_psymtab
*pst
;
7180 gdb_assert (per_cu
->is_debug_types
);
7181 sig_type
= (struct signatured_type
*) per_cu
;
7183 if (! type_unit_die
->has_children
)
7186 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7187 tu_group
= get_type_unit_group (cu
, attr
);
7189 if (tu_group
->tus
== nullptr)
7190 tu_group
->tus
= new std::vector
<signatured_type
*>;
7191 tu_group
->tus
->push_back (sig_type
);
7193 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7194 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7195 pst
->anonymous
= true;
7197 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7199 lowpc
= (CORE_ADDR
) -1;
7200 highpc
= (CORE_ADDR
) 0;
7201 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7206 /* Struct used to sort TUs by their abbreviation table offset. */
7208 struct tu_abbrev_offset
7210 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7211 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7214 /* This is used when sorting. */
7215 bool operator< (const tu_abbrev_offset
&other
) const
7217 return abbrev_offset
< other
.abbrev_offset
;
7220 signatured_type
*sig_type
;
7221 sect_offset abbrev_offset
;
7224 /* Efficiently read all the type units.
7226 The efficiency is because we sort TUs by the abbrev table they use and
7227 only read each abbrev table once. In one program there are 200K TUs
7228 sharing 8K abbrev tables.
7230 The main purpose of this function is to support building the
7231 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7232 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7233 can collapse the search space by grouping them by stmt_list.
7234 The savings can be significant, in the same program from above the 200K TUs
7235 share 8K stmt_list tables.
7237 FUNC is expected to call get_type_unit_group, which will create the
7238 struct type_unit_group if necessary and add it to
7239 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7242 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7244 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7245 abbrev_table_up abbrev_table
;
7246 sect_offset abbrev_offset
;
7248 /* It's up to the caller to not call us multiple times. */
7249 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7251 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7254 /* TUs typically share abbrev tables, and there can be way more TUs than
7255 abbrev tables. Sort by abbrev table to reduce the number of times we
7256 read each abbrev table in.
7257 Alternatives are to punt or to maintain a cache of abbrev tables.
7258 This is simpler and efficient enough for now.
7260 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7261 symtab to use). Typically TUs with the same abbrev offset have the same
7262 stmt_list value too so in practice this should work well.
7264 The basic algorithm here is:
7266 sort TUs by abbrev table
7267 for each TU with same abbrev table:
7268 read abbrev table if first user
7269 read TU top level DIE
7270 [IWBN if DWO skeletons had DW_AT_stmt_list]
7273 dwarf_read_debug_printf ("Building type unit groups ...");
7275 /* Sort in a separate table to maintain the order of all_comp_units
7276 for .gdb_index: TU indices directly index all_type_units. */
7277 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7278 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7280 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7282 if (cu
->is_debug_types
)
7284 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7285 sorted_by_abbrev
.emplace_back
7286 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7287 sig_type
->sect_off
));
7291 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7293 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7295 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7297 /* Switch to the next abbrev table if necessary. */
7298 if (abbrev_table
== NULL
7299 || tu
.abbrev_offset
!= abbrev_offset
)
7301 abbrev_offset
= tu
.abbrev_offset
;
7302 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7304 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7305 ++tu_stats
->nr_uniq_abbrev_tables
;
7308 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7309 abbrev_table
.get (), nullptr, false);
7310 if (!reader
.dummy_p
)
7311 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7312 reader
.comp_unit_die
);
7316 /* Print collected type unit statistics. */
7319 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7321 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7323 dwarf_read_debug_printf ("Type unit statistics:");
7324 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7325 dwarf_read_debug_printf (" %d uniq abbrev tables",
7326 tu_stats
->nr_uniq_abbrev_tables
);
7327 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7328 tu_stats
->nr_symtabs
);
7329 dwarf_read_debug_printf (" %d symtab sharers",
7330 tu_stats
->nr_symtab_sharers
);
7331 dwarf_read_debug_printf (" %d type units without a stmt_list",
7332 tu_stats
->nr_stmt_less_type_units
);
7333 dwarf_read_debug_printf (" %d all_type_units reallocs",
7334 tu_stats
->nr_all_type_units_reallocs
);
7337 /* Traversal function for build_type_psymtabs. */
7340 build_type_psymtab_dependencies (void **slot
, void *info
)
7342 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7343 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7344 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7345 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7346 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7349 gdb_assert (len
> 0);
7350 gdb_assert (tu_group
->type_unit_group_p ());
7352 pst
->number_of_dependencies
= len
;
7353 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7354 for (i
= 0; i
< len
; ++i
)
7356 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7357 gdb_assert (iter
->is_debug_types
);
7358 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7359 iter
->type_unit_group
= tu_group
;
7362 delete tu_group
->tus
;
7363 tu_group
->tus
= nullptr;
7368 /* Traversal function for process_skeletonless_type_unit.
7369 Read a TU in a DWO file and build partial symbols for it. */
7372 process_skeletonless_type_unit (void **slot
, void *info
)
7374 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7375 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7377 /* If this TU doesn't exist in the global table, add it and read it in. */
7379 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7380 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7382 signatured_type
find_entry (dwo_unit
->signature
);
7383 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7384 &find_entry
, INSERT
);
7385 /* If we've already seen this type there's nothing to do. What's happening
7386 is we're doing our own version of comdat-folding here. */
7390 /* This does the job that create_all_comp_units would have done for
7392 signatured_type
*entry
7393 = add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7394 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7397 /* This does the job that build_type_psymtabs would have done. */
7398 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7399 if (!reader
.dummy_p
)
7400 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7401 reader
.comp_unit_die
);
7406 /* Traversal function for process_skeletonless_type_units. */
7409 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7411 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7413 if (dwo_file
->tus
!= NULL
)
7414 htab_traverse_noresize (dwo_file
->tus
.get (),
7415 process_skeletonless_type_unit
, info
);
7420 /* Scan all TUs of DWO files, verifying we've processed them.
7421 This is needed in case a TU was emitted without its skeleton.
7422 Note: This can't be done until we know what all the DWO files are. */
7425 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7427 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7428 if (get_dwp_file (per_objfile
) == NULL
7429 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7431 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7432 process_dwo_file_for_skeletonless_type_units
,
7437 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7440 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7442 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7444 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7449 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7451 /* Set the 'user' field only if it is not already set. */
7452 if (pst
->dependencies
[j
]->user
== NULL
)
7453 pst
->dependencies
[j
]->user
= pst
;
7458 /* Build the partial symbol table by doing a quick pass through the
7459 .debug_info and .debug_abbrev sections. */
7462 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7464 struct objfile
*objfile
= per_objfile
->objfile
;
7465 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7467 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7468 objfile_name (objfile
));
7470 scoped_restore restore_reading_psyms
7471 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7473 per_bfd
->info
.read (objfile
);
7475 /* Any cached compilation units will be linked by the per-objfile
7476 read_in_chain. Make sure to free them when we're done. */
7477 free_cached_comp_units
freer (per_objfile
);
7479 create_all_comp_units (per_objfile
);
7480 build_type_psymtabs (per_objfile
);
7482 /* Create a temporary address map on a temporary obstack. We later
7483 copy this to the final obstack. */
7484 auto_obstack temp_obstack
;
7486 scoped_restore save_psymtabs_addrmap
7487 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7488 addrmap_create_mutable (&temp_obstack
));
7490 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7492 if (per_cu
->v
.psymtab
!= NULL
)
7493 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7495 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7499 /* This has to wait until we read the CUs, we need the list of DWOs. */
7500 process_skeletonless_type_units (per_objfile
);
7502 /* Now that all TUs have been processed we can fill in the dependencies. */
7503 if (per_bfd
->type_unit_groups
!= NULL
)
7505 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7506 build_type_psymtab_dependencies
, per_objfile
);
7509 if (dwarf_read_debug
> 0)
7510 print_tu_stats (per_objfile
);
7512 set_partial_user (per_objfile
);
7514 per_bfd
->partial_symtabs
->psymtabs_addrmap
7515 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7516 per_bfd
->partial_symtabs
->obstack ());
7517 /* At this point we want to keep the address map. */
7518 save_psymtabs_addrmap
.release ();
7520 dwarf_read_debug_printf ("Done building psymtabs of %s",
7521 objfile_name (objfile
));
7524 /* Load the partial DIEs for a secondary CU into memory.
7525 This is also used when rereading a primary CU with load_all_dies. */
7528 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7529 dwarf2_per_objfile
*per_objfile
,
7530 dwarf2_cu
*existing_cu
)
7532 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7534 if (!reader
.dummy_p
)
7536 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7539 /* Check if comp unit has_children.
7540 If so, read the rest of the partial symbols from this comp unit.
7541 If not, there's no more debug_info for this comp unit. */
7542 if (reader
.comp_unit_die
->has_children
)
7543 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7550 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7551 struct dwarf2_section_info
*section
,
7552 struct dwarf2_section_info
*abbrev_section
,
7553 unsigned int is_dwz
,
7554 htab_up
&types_htab
,
7555 rcuh_kind section_kind
)
7557 const gdb_byte
*info_ptr
;
7558 struct objfile
*objfile
= per_objfile
->objfile
;
7560 dwarf_read_debug_printf ("Reading %s for %s",
7561 section
->get_name (),
7562 section
->get_file_name ());
7564 section
->read (objfile
);
7566 info_ptr
= section
->buffer
;
7568 while (info_ptr
< section
->buffer
+ section
->size
)
7570 dwarf2_per_cu_data_up this_cu
;
7572 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7574 comp_unit_head cu_header
;
7575 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7576 abbrev_section
, info_ptr
,
7579 /* Save the compilation unit for later lookup. */
7580 if (cu_header
.unit_type
!= DW_UT_type
)
7581 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7584 if (types_htab
== nullptr)
7585 types_htab
= allocate_signatured_type_table ();
7587 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7588 (cu_header
.signature
);
7589 signatured_type
*sig_ptr
= sig_type
.get ();
7590 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7591 this_cu
.reset (sig_type
.release ());
7593 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7594 gdb_assert (slot
!= nullptr);
7595 if (*slot
!= nullptr)
7596 complaint (_("debug type entry at offset %s is duplicate to"
7597 " the entry at offset %s, signature %s"),
7598 sect_offset_str (sect_off
),
7599 sect_offset_str (sig_ptr
->sect_off
),
7600 hex_string (sig_ptr
->signature
));
7603 this_cu
->sect_off
= sect_off
;
7604 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7605 this_cu
->is_dwz
= is_dwz
;
7606 this_cu
->section
= section
;
7608 info_ptr
= info_ptr
+ this_cu
->length
;
7609 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7613 /* Create a list of all compilation units in OBJFILE.
7614 This is only done for -readnow and building partial symtabs. */
7617 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7621 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7622 &per_objfile
->per_bfd
->abbrev
, 0,
7623 types_htab
, rcuh_kind::COMPILE
);
7624 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7625 read_comp_units_from_section (per_objfile
, §ion
,
7626 &per_objfile
->per_bfd
->abbrev
, 0,
7627 types_htab
, rcuh_kind::TYPE
);
7629 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7631 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7632 types_htab
, rcuh_kind::COMPILE
);
7634 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7637 /* Process all loaded DIEs for compilation unit CU, starting at
7638 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7639 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7640 DW_AT_ranges). See the comments of add_partial_subprogram on how
7641 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7644 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7645 CORE_ADDR
*highpc
, int set_addrmap
,
7646 struct dwarf2_cu
*cu
)
7648 struct partial_die_info
*pdi
;
7650 /* Now, march along the PDI's, descending into ones which have
7651 interesting children but skipping the children of the other ones,
7652 until we reach the end of the compilation unit. */
7660 /* Anonymous namespaces or modules have no name but have interesting
7661 children, so we need to look at them. Ditto for anonymous
7664 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7665 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7666 || pdi
->tag
== DW_TAG_imported_unit
7667 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7671 case DW_TAG_subprogram
:
7672 case DW_TAG_inlined_subroutine
:
7673 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7674 if (cu
->per_cu
->lang
== language_cplus
)
7675 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7678 case DW_TAG_constant
:
7679 case DW_TAG_variable
:
7680 case DW_TAG_typedef
:
7681 case DW_TAG_union_type
:
7682 if (!pdi
->is_declaration
7683 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7685 add_partial_symbol (pdi
, cu
);
7688 case DW_TAG_class_type
:
7689 case DW_TAG_interface_type
:
7690 case DW_TAG_structure_type
:
7691 if (!pdi
->is_declaration
)
7693 add_partial_symbol (pdi
, cu
);
7695 if ((cu
->per_cu
->lang
== language_rust
7696 || cu
->per_cu
->lang
== language_cplus
)
7697 && pdi
->has_children
)
7698 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7701 case DW_TAG_enumeration_type
:
7702 if (!pdi
->is_declaration
)
7703 add_partial_enumeration (pdi
, cu
);
7705 case DW_TAG_base_type
:
7706 case DW_TAG_subrange_type
:
7707 /* File scope base type definitions are added to the partial
7709 add_partial_symbol (pdi
, cu
);
7711 case DW_TAG_namespace
:
7712 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7715 if (!pdi
->is_declaration
)
7716 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7718 case DW_TAG_imported_unit
:
7720 struct dwarf2_per_cu_data
*per_cu
;
7722 /* For now we don't handle imported units in type units. */
7723 if (cu
->per_cu
->is_debug_types
)
7725 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7726 " supported in type units [in module %s]"),
7727 objfile_name (cu
->per_objfile
->objfile
));
7730 per_cu
= dwarf2_find_containing_comp_unit
7731 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7733 /* Go read the partial unit, if needed. */
7734 if (per_cu
->v
.psymtab
== NULL
)
7735 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7738 if (pdi
->die_parent
== nullptr
7739 && per_cu
->unit_type
== DW_UT_compile
7740 && per_cu
->lang
== language_cplus
)
7741 /* Regard import as hint. See corresponding code in
7742 process_imported_unit_die. */
7745 cu
->per_cu
->imported_symtabs_push (per_cu
);
7748 case DW_TAG_imported_declaration
:
7749 add_partial_symbol (pdi
, cu
);
7756 /* If the die has a sibling, skip to the sibling. */
7758 pdi
= pdi
->die_sibling
;
7762 /* Functions used to compute the fully scoped name of a partial DIE.
7764 Normally, this is simple. For C++, the parent DIE's fully scoped
7765 name is concatenated with "::" and the partial DIE's name.
7766 Enumerators are an exception; they use the scope of their parent
7767 enumeration type, i.e. the name of the enumeration type is not
7768 prepended to the enumerator.
7770 There are two complexities. One is DW_AT_specification; in this
7771 case "parent" means the parent of the target of the specification,
7772 instead of the direct parent of the DIE. The other is compilers
7773 which do not emit DW_TAG_namespace; in this case we try to guess
7774 the fully qualified name of structure types from their members'
7775 linkage names. This must be done using the DIE's children rather
7776 than the children of any DW_AT_specification target. We only need
7777 to do this for structures at the top level, i.e. if the target of
7778 any DW_AT_specification (if any; otherwise the DIE itself) does not
7781 /* Compute the scope prefix associated with PDI's parent, in
7782 compilation unit CU. The result will be allocated on CU's
7783 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7784 field. NULL is returned if no prefix is necessary. */
7786 partial_die_parent_scope (struct partial_die_info
*pdi
,
7787 struct dwarf2_cu
*cu
)
7789 const char *grandparent_scope
;
7790 struct partial_die_info
*parent
, *real_pdi
;
7792 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7793 then this means the parent of the specification DIE. */
7796 while (real_pdi
->has_specification
)
7798 auto res
= find_partial_die (real_pdi
->spec_offset
,
7799 real_pdi
->spec_is_dwz
, cu
);
7804 parent
= real_pdi
->die_parent
;
7808 if (parent
->scope_set
)
7809 return parent
->scope
;
7813 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7815 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7816 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7817 Work around this problem here. */
7818 if (cu
->per_cu
->lang
== language_cplus
7819 && parent
->tag
== DW_TAG_namespace
7820 && strcmp (parent
->name (cu
), "::") == 0
7821 && grandparent_scope
== NULL
)
7823 parent
->scope
= NULL
;
7824 parent
->scope_set
= 1;
7828 /* Nested subroutines in Fortran get a prefix. */
7829 if (pdi
->tag
== DW_TAG_enumerator
)
7830 /* Enumerators should not get the name of the enumeration as a prefix. */
7831 parent
->scope
= grandparent_scope
;
7832 else if (parent
->tag
== DW_TAG_namespace
7833 || parent
->tag
== DW_TAG_module
7834 || parent
->tag
== DW_TAG_structure_type
7835 || parent
->tag
== DW_TAG_class_type
7836 || parent
->tag
== DW_TAG_interface_type
7837 || parent
->tag
== DW_TAG_union_type
7838 || parent
->tag
== DW_TAG_enumeration_type
7839 || (cu
->per_cu
->lang
== language_fortran
7840 && parent
->tag
== DW_TAG_subprogram
7841 && pdi
->tag
== DW_TAG_subprogram
))
7843 if (grandparent_scope
== NULL
)
7844 parent
->scope
= parent
->name (cu
);
7846 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7848 parent
->name (cu
), 0, cu
);
7852 /* FIXME drow/2004-04-01: What should we be doing with
7853 function-local names? For partial symbols, we should probably be
7855 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7856 dwarf_tag_name (parent
->tag
),
7857 sect_offset_str (pdi
->sect_off
));
7858 parent
->scope
= grandparent_scope
;
7861 parent
->scope_set
= 1;
7862 return parent
->scope
;
7865 /* Return the fully scoped name associated with PDI, from compilation unit
7866 CU. The result will be allocated with malloc. */
7868 static gdb::unique_xmalloc_ptr
<char>
7869 partial_die_full_name (struct partial_die_info
*pdi
,
7870 struct dwarf2_cu
*cu
)
7872 const char *parent_scope
;
7874 /* If this is a template instantiation, we can not work out the
7875 template arguments from partial DIEs. So, unfortunately, we have
7876 to go through the full DIEs. At least any work we do building
7877 types here will be reused if full symbols are loaded later. */
7878 if (pdi
->has_template_arguments
)
7882 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7884 struct die_info
*die
;
7885 struct attribute attr
;
7886 struct dwarf2_cu
*ref_cu
= cu
;
7888 /* DW_FORM_ref_addr is using section offset. */
7889 attr
.name
= (enum dwarf_attribute
) 0;
7890 attr
.form
= DW_FORM_ref_addr
;
7891 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7892 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7894 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7898 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7899 if (parent_scope
== NULL
)
7902 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7908 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7910 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7911 struct objfile
*objfile
= per_objfile
->objfile
;
7912 struct gdbarch
*gdbarch
= objfile
->arch ();
7914 const char *actual_name
= NULL
;
7917 baseaddr
= objfile
->text_section_offset ();
7919 gdb::unique_xmalloc_ptr
<char> built_actual_name
7920 = partial_die_full_name (pdi
, cu
);
7921 if (built_actual_name
!= NULL
)
7922 actual_name
= built_actual_name
.get ();
7924 if (actual_name
== NULL
)
7925 actual_name
= pdi
->name (cu
);
7927 partial_symbol psymbol
;
7928 memset (&psymbol
, 0, sizeof (psymbol
));
7929 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
7930 &objfile
->objfile_obstack
);
7931 psymbol
.ginfo
.set_section_index (-1);
7933 /* The code below indicates that the psymbol should be installed by
7935 gdb::optional
<psymbol_placement
> where
;
7939 case DW_TAG_inlined_subroutine
:
7940 case DW_TAG_subprogram
:
7941 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7943 if (pdi
->is_external
7944 || cu
->per_cu
->lang
== language_ada
7945 || (cu
->per_cu
->lang
== language_fortran
7946 && pdi
->die_parent
!= NULL
7947 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7949 /* Normally, only "external" DIEs are part of the global scope.
7950 But in Ada and Fortran, we want to be able to access nested
7951 procedures globally. So all Ada and Fortran subprograms are
7952 stored in the global scope. */
7953 where
= psymbol_placement::GLOBAL
;
7956 where
= psymbol_placement::STATIC
;
7958 psymbol
.domain
= VAR_DOMAIN
;
7959 psymbol
.aclass
= LOC_BLOCK
;
7960 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7961 psymbol
.ginfo
.value
.address
= addr
;
7963 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7964 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
7966 case DW_TAG_constant
:
7967 psymbol
.domain
= VAR_DOMAIN
;
7968 psymbol
.aclass
= LOC_STATIC
;
7969 where
= (pdi
->is_external
7970 ? psymbol_placement::GLOBAL
7971 : psymbol_placement::STATIC
);
7973 case DW_TAG_variable
:
7975 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7979 && !per_objfile
->per_bfd
->has_section_at_zero
)
7981 /* A global or static variable may also have been stripped
7982 out by the linker if unused, in which case its address
7983 will be nullified; do not add such variables into partial
7984 symbol table then. */
7986 else if (pdi
->is_external
)
7989 Don't enter into the minimal symbol tables as there is
7990 a minimal symbol table entry from the ELF symbols already.
7991 Enter into partial symbol table if it has a location
7992 descriptor or a type.
7993 If the location descriptor is missing, new_symbol will create
7994 a LOC_UNRESOLVED symbol, the address of the variable will then
7995 be determined from the minimal symbol table whenever the variable
7997 The address for the partial symbol table entry is not
7998 used by GDB, but it comes in handy for debugging partial symbol
8001 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8003 psymbol
.domain
= VAR_DOMAIN
;
8004 psymbol
.aclass
= LOC_STATIC
;
8005 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8006 psymbol
.ginfo
.value
.address
= addr
;
8007 where
= psymbol_placement::GLOBAL
;
8012 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8014 /* Static Variable. Skip symbols whose value we cannot know (those
8015 without location descriptors or constant values). */
8016 if (!has_loc
&& !pdi
->has_const_value
)
8019 psymbol
.domain
= VAR_DOMAIN
;
8020 psymbol
.aclass
= LOC_STATIC
;
8021 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8023 psymbol
.ginfo
.value
.address
= addr
;
8024 where
= psymbol_placement::STATIC
;
8027 case DW_TAG_array_type
:
8028 case DW_TAG_typedef
:
8029 case DW_TAG_base_type
:
8030 case DW_TAG_subrange_type
:
8031 psymbol
.domain
= VAR_DOMAIN
;
8032 psymbol
.aclass
= LOC_TYPEDEF
;
8033 where
= psymbol_placement::STATIC
;
8035 case DW_TAG_imported_declaration
:
8036 case DW_TAG_namespace
:
8037 psymbol
.domain
= VAR_DOMAIN
;
8038 psymbol
.aclass
= LOC_TYPEDEF
;
8039 where
= psymbol_placement::GLOBAL
;
8042 /* With Fortran 77 there might be a "BLOCK DATA" module
8043 available without any name. If so, we skip the module as it
8044 doesn't bring any value. */
8045 if (actual_name
!= nullptr)
8047 psymbol
.domain
= MODULE_DOMAIN
;
8048 psymbol
.aclass
= LOC_TYPEDEF
;
8049 where
= psymbol_placement::GLOBAL
;
8052 case DW_TAG_class_type
:
8053 case DW_TAG_interface_type
:
8054 case DW_TAG_structure_type
:
8055 case DW_TAG_union_type
:
8056 case DW_TAG_enumeration_type
:
8057 /* Skip external references. The DWARF standard says in the section
8058 about "Structure, Union, and Class Type Entries": "An incomplete
8059 structure, union or class type is represented by a structure,
8060 union or class entry that does not have a byte size attribute
8061 and that has a DW_AT_declaration attribute." */
8062 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8065 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8066 static vs. global. */
8067 psymbol
.domain
= STRUCT_DOMAIN
;
8068 psymbol
.aclass
= LOC_TYPEDEF
;
8069 where
= (cu
->per_cu
->lang
== language_cplus
8070 ? psymbol_placement::GLOBAL
8071 : psymbol_placement::STATIC
);
8073 case DW_TAG_enumerator
:
8074 psymbol
.domain
= VAR_DOMAIN
;
8075 psymbol
.aclass
= LOC_CONST
;
8076 where
= (cu
->per_cu
->lang
== language_cplus
8077 ? psymbol_placement::GLOBAL
8078 : psymbol_placement::STATIC
);
8084 if (where
.has_value ())
8086 if (built_actual_name
!= nullptr)
8087 actual_name
= objfile
->intern (actual_name
);
8088 if (pdi
->linkage_name
== nullptr
8089 || cu
->per_cu
->lang
== language_ada
)
8090 psymbol
.ginfo
.set_linkage_name (actual_name
);
8093 psymbol
.ginfo
.set_demangled_name (actual_name
,
8094 &objfile
->objfile_obstack
);
8095 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8097 cu
->per_cu
->v
.psymtab
->add_psymbol
8098 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8103 /* Read a partial die corresponding to a namespace; also, add a symbol
8104 corresponding to that namespace to the symbol table. NAMESPACE is
8105 the name of the enclosing namespace. */
8108 add_partial_namespace (struct partial_die_info
*pdi
,
8109 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8110 int set_addrmap
, struct dwarf2_cu
*cu
)
8112 /* Add a symbol for the namespace. */
8114 add_partial_symbol (pdi
, cu
);
8116 /* Now scan partial symbols in that namespace. */
8118 if (pdi
->has_children
)
8119 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8122 /* Read a partial die corresponding to a Fortran module. */
8125 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8126 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8128 /* Add a symbol for the namespace. */
8130 add_partial_symbol (pdi
, cu
);
8132 /* Now scan partial symbols in that module. */
8134 if (pdi
->has_children
)
8135 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8139 dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
8140 dwarf2_psymtab
*, dwarf_tag
);
8142 /* Read a partial die corresponding to a subprogram or an inlined
8143 subprogram and create a partial symbol for that subprogram.
8144 When the CU language allows it, this routine also defines a partial
8145 symbol for each nested subprogram that this subprogram contains.
8146 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8147 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8149 PDI may also be a lexical block, in which case we simply search
8150 recursively for subprograms defined inside that lexical block.
8151 Again, this is only performed when the CU language allows this
8152 type of definitions. */
8155 add_partial_subprogram (struct partial_die_info
*pdi
,
8156 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8157 int set_addrmap
, struct dwarf2_cu
*cu
)
8159 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8161 if (pdi
->has_pc_info
)
8163 if (pdi
->lowpc
< *lowpc
)
8164 *lowpc
= pdi
->lowpc
;
8165 if (pdi
->highpc
> *highpc
)
8166 *highpc
= pdi
->highpc
;
8169 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8170 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8171 struct gdbarch
*gdbarch
= objfile
->arch ();
8173 CORE_ADDR this_highpc
;
8174 CORE_ADDR this_lowpc
;
8176 baseaddr
= objfile
->text_section_offset ();
8178 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8179 pdi
->lowpc
+ baseaddr
)
8182 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8183 pdi
->highpc
+ baseaddr
)
8185 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8186 this_lowpc
, this_highpc
- 1,
8187 cu
->per_cu
->v
.psymtab
);
8191 if (pdi
->has_range_info
8192 && dwarf2_ranges_read (pdi
->ranges_offset
, &pdi
->lowpc
, &pdi
->highpc
,
8194 set_addrmap
? cu
->per_cu
->v
.psymtab
: nullptr,
8197 if (pdi
->lowpc
< *lowpc
)
8198 *lowpc
= pdi
->lowpc
;
8199 if (pdi
->highpc
> *highpc
)
8200 *highpc
= pdi
->highpc
;
8203 if (pdi
->has_pc_info
|| pdi
->has_range_info
8204 || (!pdi
->is_external
&& pdi
->may_be_inlined
))
8206 if (!pdi
->is_declaration
)
8207 /* Ignore subprogram DIEs that do not have a name, they are
8208 illegal. Do not emit a complaint at this point, we will
8209 do so when we convert this psymtab into a symtab. */
8211 add_partial_symbol (pdi
, cu
);
8215 if (! pdi
->has_children
)
8218 if (cu
->per_cu
->lang
== language_ada
8219 || cu
->per_cu
->lang
== language_fortran
)
8221 pdi
= pdi
->die_child
;
8225 if (pdi
->tag
== DW_TAG_subprogram
8226 || pdi
->tag
== DW_TAG_inlined_subroutine
8227 || pdi
->tag
== DW_TAG_lexical_block
)
8228 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8229 pdi
= pdi
->die_sibling
;
8234 /* Read a partial die corresponding to an enumeration type. */
8237 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8238 struct dwarf2_cu
*cu
)
8240 struct partial_die_info
*pdi
;
8242 if (enum_pdi
->name (cu
) != NULL
)
8243 add_partial_symbol (enum_pdi
, cu
);
8245 pdi
= enum_pdi
->die_child
;
8248 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8249 complaint (_("malformed enumerator DIE ignored"));
8251 add_partial_symbol (pdi
, cu
);
8252 pdi
= pdi
->die_sibling
;
8256 /* Return the initial uleb128 in the die at INFO_PTR. */
8259 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8261 unsigned int bytes_read
;
8263 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8266 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8267 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8269 Return the corresponding abbrev, or NULL if the number is zero (indicating
8270 an empty DIE). In either case *BYTES_READ will be set to the length of
8271 the initial number. */
8273 static const struct abbrev_info
*
8274 peek_die_abbrev (const die_reader_specs
&reader
,
8275 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8277 dwarf2_cu
*cu
= reader
.cu
;
8278 bfd
*abfd
= reader
.abfd
;
8279 unsigned int abbrev_number
8280 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8282 if (abbrev_number
== 0)
8285 const abbrev_info
*abbrev
8286 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8289 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8290 " at offset %s [in module %s]"),
8291 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8292 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8298 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8299 Returns a pointer to the end of a series of DIEs, terminated by an empty
8300 DIE. Any children of the skipped DIEs will also be skipped. */
8302 static const gdb_byte
*
8303 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8307 unsigned int bytes_read
;
8308 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8312 return info_ptr
+ bytes_read
;
8314 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8318 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8319 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8320 abbrev corresponding to that skipped uleb128 should be passed in
8321 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8324 static const gdb_byte
*
8325 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8326 const struct abbrev_info
*abbrev
)
8328 unsigned int bytes_read
;
8329 struct attribute attr
;
8330 bfd
*abfd
= reader
->abfd
;
8331 struct dwarf2_cu
*cu
= reader
->cu
;
8332 const gdb_byte
*buffer
= reader
->buffer
;
8333 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8334 unsigned int form
, i
;
8336 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8338 /* The only abbrev we care about is DW_AT_sibling. */
8339 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8341 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8342 if (attr
.form
== DW_FORM_ref_addr
)
8343 complaint (_("ignoring absolute DW_AT_sibling"));
8346 sect_offset off
= attr
.get_ref_die_offset ();
8347 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8349 if (sibling_ptr
< info_ptr
)
8350 complaint (_("DW_AT_sibling points backwards"));
8351 else if (sibling_ptr
> reader
->buffer_end
)
8352 reader
->die_section
->overflow_complaint ();
8358 /* If it isn't DW_AT_sibling, skip this attribute. */
8359 form
= abbrev
->attrs
[i
].form
;
8363 case DW_FORM_ref_addr
:
8364 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8365 and later it is offset sized. */
8366 if (cu
->header
.version
== 2)
8367 info_ptr
+= cu
->header
.addr_size
;
8369 info_ptr
+= cu
->header
.offset_size
;
8371 case DW_FORM_GNU_ref_alt
:
8372 info_ptr
+= cu
->header
.offset_size
;
8375 info_ptr
+= cu
->header
.addr_size
;
8383 case DW_FORM_flag_present
:
8384 case DW_FORM_implicit_const
:
8401 case DW_FORM_ref_sig8
:
8404 case DW_FORM_data16
:
8407 case DW_FORM_string
:
8408 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8409 info_ptr
+= bytes_read
;
8411 case DW_FORM_sec_offset
:
8413 case DW_FORM_GNU_strp_alt
:
8414 info_ptr
+= cu
->header
.offset_size
;
8416 case DW_FORM_exprloc
:
8418 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8419 info_ptr
+= bytes_read
;
8421 case DW_FORM_block1
:
8422 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8424 case DW_FORM_block2
:
8425 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8427 case DW_FORM_block4
:
8428 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8434 case DW_FORM_ref_udata
:
8435 case DW_FORM_GNU_addr_index
:
8436 case DW_FORM_GNU_str_index
:
8437 case DW_FORM_rnglistx
:
8438 case DW_FORM_loclistx
:
8439 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8441 case DW_FORM_indirect
:
8442 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8443 info_ptr
+= bytes_read
;
8444 /* We need to continue parsing from here, so just go back to
8446 goto skip_attribute
;
8449 error (_("Dwarf Error: Cannot handle %s "
8450 "in DWARF reader [in module %s]"),
8451 dwarf_form_name (form
),
8452 bfd_get_filename (abfd
));
8456 if (abbrev
->has_children
)
8457 return skip_children (reader
, info_ptr
);
8462 /* Locate ORIG_PDI's sibling.
8463 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8465 static const gdb_byte
*
8466 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8467 struct partial_die_info
*orig_pdi
,
8468 const gdb_byte
*info_ptr
)
8470 /* Do we know the sibling already? */
8472 if (orig_pdi
->sibling
)
8473 return orig_pdi
->sibling
;
8475 /* Are there any children to deal with? */
8477 if (!orig_pdi
->has_children
)
8480 /* Skip the children the long way. */
8482 return skip_children (reader
, info_ptr
);
8485 /* Expand this partial symbol table into a full symbol table. SELF is
8489 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8491 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8493 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8495 /* If this psymtab is constructed from a debug-only objfile, the
8496 has_section_at_zero flag will not necessarily be correct. We
8497 can get the correct value for this flag by looking at the data
8498 associated with the (presumably stripped) associated objfile. */
8499 if (objfile
->separate_debug_objfile_backlink
)
8501 dwarf2_per_objfile
*per_objfile_backlink
8502 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8504 per_objfile
->per_bfd
->has_section_at_zero
8505 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8508 expand_psymtab (objfile
);
8510 process_cu_includes (per_objfile
);
8513 /* Reading in full CUs. */
8515 /* Add PER_CU to the queue. */
8518 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8519 dwarf2_per_objfile
*per_objfile
,
8520 enum language pretend_language
)
8524 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8525 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8528 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8530 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8533 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8534 DIEs, false otherwise.
8536 Explanation: there is an invariant that if a CU is queued for expansion
8537 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8538 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8539 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8540 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8541 invariant is respected.
8543 The caller is therefore not required to load the CU's DIEs (we return false)
8546 - the CU is already expanded, and therefore does not get enqueued
8547 - the CU gets enqueued for expansion, but its DIEs are already loaded
8549 Note that the caller should not use this function's return value as an
8550 indicator of whether the CU's DIEs are loaded right now, it should check
8551 that by calling `dwarf2_per_objfile::get_cu` instead. */
8554 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8555 dwarf2_per_cu_data
*per_cu
,
8556 dwarf2_per_objfile
*per_objfile
,
8557 enum language pretend_language
)
8559 /* We may arrive here during partial symbol reading, if we need full
8560 DIEs to process an unusual case (e.g. template arguments). Do
8561 not queue PER_CU, just tell our caller to load its DIEs. */
8562 if (per_cu
->per_bfd
->reading_partial_symbols
)
8564 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8566 if (cu
== NULL
|| cu
->dies
== NULL
)
8571 /* Mark the dependence relation so that we don't flush PER_CU
8573 if (dependent_cu
!= NULL
)
8574 dependent_cu
->add_dependence (per_cu
);
8576 /* If it's already on the queue, we have nothing to do. */
8579 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8581 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8583 /* If the CU is queued for expansion, it should not already be
8585 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8587 /* The DIEs are already loaded, the caller doesn't need to do it. */
8591 bool queued
= false;
8592 if (!per_objfile
->symtab_set_p (per_cu
))
8594 /* Add it to the queue. */
8595 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8599 /* If the compilation unit is already loaded, just mark it as
8601 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8605 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8606 and the DIEs are not already loaded. */
8607 return queued
&& cu
== nullptr;
8610 /* Process the queue. */
8613 process_queue (dwarf2_per_objfile
*per_objfile
)
8615 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8616 objfile_name (per_objfile
->objfile
));
8618 /* The queue starts out with one item, but following a DIE reference
8619 may load a new CU, adding it to the end of the queue. */
8620 while (!per_objfile
->per_bfd
->queue
->empty ())
8622 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8623 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8625 if (!per_objfile
->symtab_set_p (per_cu
))
8627 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8629 /* Skip dummy CUs. */
8632 unsigned int debug_print_threshold
;
8635 if (per_cu
->is_debug_types
)
8637 struct signatured_type
*sig_type
=
8638 (struct signatured_type
*) per_cu
;
8640 sprintf (buf
, "TU %s at offset %s",
8641 hex_string (sig_type
->signature
),
8642 sect_offset_str (per_cu
->sect_off
));
8643 /* There can be 100s of TUs.
8644 Only print them in verbose mode. */
8645 debug_print_threshold
= 2;
8649 sprintf (buf
, "CU at offset %s",
8650 sect_offset_str (per_cu
->sect_off
));
8651 debug_print_threshold
= 1;
8654 if (dwarf_read_debug
>= debug_print_threshold
)
8655 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8657 if (per_cu
->is_debug_types
)
8658 process_full_type_unit (cu
, item
.pretend_language
);
8660 process_full_comp_unit (cu
, item
.pretend_language
);
8662 if (dwarf_read_debug
>= debug_print_threshold
)
8663 dwarf_read_debug_printf ("Done expanding %s", buf
);
8668 per_objfile
->per_bfd
->queue
->pop ();
8671 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8672 objfile_name (per_objfile
->objfile
));
8675 /* Read in full symbols for PST, and anything it depends on. */
8678 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8680 gdb_assert (!readin_p (objfile
));
8682 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8683 free_cached_comp_units
freer (per_objfile
);
8684 expand_dependencies (objfile
);
8686 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8687 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8690 /* See psympriv.h. */
8693 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8695 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8696 return per_objfile
->symtab_set_p (per_cu_data
);
8699 /* See psympriv.h. */
8702 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8704 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8705 return per_objfile
->get_symtab (per_cu_data
);
8708 /* Trivial hash function for die_info: the hash value of a DIE
8709 is its offset in .debug_info for this objfile. */
8712 die_hash (const void *item
)
8714 const struct die_info
*die
= (const struct die_info
*) item
;
8716 return to_underlying (die
->sect_off
);
8719 /* Trivial comparison function for die_info structures: two DIEs
8720 are equal if they have the same offset. */
8723 die_eq (const void *item_lhs
, const void *item_rhs
)
8725 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8726 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8728 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8731 /* Load the DIEs associated with PER_CU into memory.
8733 In some cases, the caller, while reading partial symbols, will need to load
8734 the full symbols for the CU for some reason. It will already have a
8735 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8736 rather than creating a new one. */
8739 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8740 dwarf2_per_objfile
*per_objfile
,
8741 dwarf2_cu
*existing_cu
,
8743 enum language pretend_language
)
8745 gdb_assert (! this_cu
->is_debug_types
);
8747 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8751 struct dwarf2_cu
*cu
= reader
.cu
;
8752 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8754 gdb_assert (cu
->die_hash
== NULL
);
8756 htab_create_alloc_ex (cu
->header
.length
/ 12,
8760 &cu
->comp_unit_obstack
,
8761 hashtab_obstack_allocate
,
8762 dummy_obstack_deallocate
);
8764 if (reader
.comp_unit_die
->has_children
)
8765 reader
.comp_unit_die
->child
8766 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8767 &info_ptr
, reader
.comp_unit_die
);
8768 cu
->dies
= reader
.comp_unit_die
;
8769 /* comp_unit_die is not stored in die_hash, no need. */
8771 /* We try not to read any attributes in this function, because not
8772 all CUs needed for references have been loaded yet, and symbol
8773 table processing isn't initialized. But we have to set the CU language,
8774 or we won't be able to build types correctly.
8775 Similarly, if we do not read the producer, we can not apply
8776 producer-specific interpretation. */
8777 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8782 /* Add a DIE to the delayed physname list. */
8785 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8786 const char *name
, struct die_info
*die
,
8787 struct dwarf2_cu
*cu
)
8789 struct delayed_method_info mi
;
8791 mi
.fnfield_index
= fnfield_index
;
8795 cu
->method_list
.push_back (mi
);
8798 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8799 "const" / "volatile". If so, decrements LEN by the length of the
8800 modifier and return true. Otherwise return false. */
8804 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8806 size_t mod_len
= sizeof (mod
) - 1;
8807 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8815 /* Compute the physnames of any methods on the CU's method list.
8817 The computation of method physnames is delayed in order to avoid the
8818 (bad) condition that one of the method's formal parameters is of an as yet
8822 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8824 /* Only C++ delays computing physnames. */
8825 if (cu
->method_list
.empty ())
8827 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
8829 for (const delayed_method_info
&mi
: cu
->method_list
)
8831 const char *physname
;
8832 struct fn_fieldlist
*fn_flp
8833 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8834 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8835 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8836 = physname
? physname
: "";
8838 /* Since there's no tag to indicate whether a method is a
8839 const/volatile overload, extract that information out of the
8841 if (physname
!= NULL
)
8843 size_t len
= strlen (physname
);
8847 if (physname
[len
] == ')') /* shortcut */
8849 else if (check_modifier (physname
, len
, " const"))
8850 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8851 else if (check_modifier (physname
, len
, " volatile"))
8852 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8859 /* The list is no longer needed. */
8860 cu
->method_list
.clear ();
8863 /* Go objects should be embedded in a DW_TAG_module DIE,
8864 and it's not clear if/how imported objects will appear.
8865 To keep Go support simple until that's worked out,
8866 go back through what we've read and create something usable.
8867 We could do this while processing each DIE, and feels kinda cleaner,
8868 but that way is more invasive.
8869 This is to, for example, allow the user to type "p var" or "b main"
8870 without having to specify the package name, and allow lookups
8871 of module.object to work in contexts that use the expression
8875 fixup_go_packaging (struct dwarf2_cu
*cu
)
8877 gdb::unique_xmalloc_ptr
<char> package_name
;
8878 struct pending
*list
;
8881 for (list
= *cu
->get_builder ()->get_global_symbols ();
8885 for (i
= 0; i
< list
->nsyms
; ++i
)
8887 struct symbol
*sym
= list
->symbol
[i
];
8889 if (sym
->language () == language_go
8890 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8892 gdb::unique_xmalloc_ptr
<char> this_package_name
8893 (go_symbol_package_name (sym
));
8895 if (this_package_name
== NULL
)
8897 if (package_name
== NULL
)
8898 package_name
= std::move (this_package_name
);
8901 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8902 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8903 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8904 (symbol_symtab (sym
) != NULL
8905 ? symtab_to_filename_for_display
8906 (symbol_symtab (sym
))
8907 : objfile_name (objfile
)),
8908 this_package_name
.get (), package_name
.get ());
8914 if (package_name
!= NULL
)
8916 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8917 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8918 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8919 saved_package_name
);
8922 sym
= new (&objfile
->objfile_obstack
) symbol
;
8923 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8924 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8925 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8926 e.g., "main" finds the "main" module and not C's main(). */
8927 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8928 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8929 SYMBOL_TYPE (sym
) = type
;
8931 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8935 /* Allocate a fully-qualified name consisting of the two parts on the
8939 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8941 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8944 /* A helper that allocates a variant part to attach to a Rust enum
8945 type. OBSTACK is where the results should be allocated. TYPE is
8946 the type we're processing. DISCRIMINANT_INDEX is the index of the
8947 discriminant. It must be the index of one of the fields of TYPE,
8948 or -1 to mean there is no discriminant (univariant enum).
8949 DEFAULT_INDEX is the index of the default field; or -1 if there is
8950 no default. RANGES is indexed by "effective" field number (the
8951 field index, but omitting the discriminant and default fields) and
8952 must hold the discriminant values used by the variants. Note that
8953 RANGES must have a lifetime at least as long as OBSTACK -- either
8954 already allocated on it, or static. */
8957 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8958 int discriminant_index
, int default_index
,
8959 gdb::array_view
<discriminant_range
> ranges
)
8961 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8962 gdb_assert (discriminant_index
== -1
8963 || (discriminant_index
>= 0
8964 && discriminant_index
< type
->num_fields ()));
8965 gdb_assert (default_index
== -1
8966 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8968 /* We have one variant for each non-discriminant field. */
8969 int n_variants
= type
->num_fields ();
8970 if (discriminant_index
!= -1)
8973 variant
*variants
= new (obstack
) variant
[n_variants
];
8976 for (int i
= 0; i
< type
->num_fields (); ++i
)
8978 if (i
== discriminant_index
)
8981 variants
[var_idx
].first_field
= i
;
8982 variants
[var_idx
].last_field
= i
+ 1;
8984 /* The default field does not need a range, but other fields do.
8985 We skipped the discriminant above. */
8986 if (i
!= default_index
)
8988 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8995 gdb_assert (range_idx
== ranges
.size ());
8996 gdb_assert (var_idx
== n_variants
);
8998 variant_part
*part
= new (obstack
) variant_part
;
8999 part
->discriminant_index
= discriminant_index
;
9000 /* If there is no discriminant, then whether it is signed is of no
9003 = (discriminant_index
== -1
9005 : type
->field (discriminant_index
).type ()->is_unsigned ());
9006 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9008 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9009 gdb::array_view
<variant_part
> *prop_value
9010 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9012 struct dynamic_prop prop
;
9013 prop
.set_variant_parts (prop_value
);
9015 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9018 /* Some versions of rustc emitted enums in an unusual way.
9020 Ordinary enums were emitted as unions. The first element of each
9021 structure in the union was named "RUST$ENUM$DISR". This element
9022 held the discriminant.
9024 These versions of Rust also implemented the "non-zero"
9025 optimization. When the enum had two values, and one is empty and
9026 the other holds a pointer that cannot be zero, the pointer is used
9027 as the discriminant, with a zero value meaning the empty variant.
9028 Here, the union's first member is of the form
9029 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9030 where the fieldnos are the indices of the fields that should be
9031 traversed in order to find the field (which may be several fields deep)
9032 and the variantname is the name of the variant of the case when the
9035 This function recognizes whether TYPE is of one of these forms,
9036 and, if so, smashes it to be a variant type. */
9039 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9041 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9043 /* We don't need to deal with empty enums. */
9044 if (type
->num_fields () == 0)
9047 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9048 if (type
->num_fields () == 1
9049 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9051 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9053 /* Decode the field name to find the offset of the
9055 ULONGEST bit_offset
= 0;
9056 struct type
*field_type
= type
->field (0).type ();
9057 while (name
[0] >= '0' && name
[0] <= '9')
9060 unsigned long index
= strtoul (name
, &tail
, 10);
9063 || index
>= field_type
->num_fields ()
9064 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9065 != FIELD_LOC_KIND_BITPOS
))
9067 complaint (_("Could not parse Rust enum encoding string \"%s\""
9069 TYPE_FIELD_NAME (type
, 0),
9070 objfile_name (objfile
));
9075 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9076 field_type
= field_type
->field (index
).type ();
9079 /* Smash this type to be a structure type. We have to do this
9080 because the type has already been recorded. */
9081 type
->set_code (TYPE_CODE_STRUCT
);
9082 type
->set_num_fields (3);
9083 /* Save the field we care about. */
9084 struct field saved_field
= type
->field (0);
9086 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9088 /* Put the discriminant at index 0. */
9089 type
->field (0).set_type (field_type
);
9090 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9091 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9092 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9094 /* The order of fields doesn't really matter, so put the real
9095 field at index 1 and the data-less field at index 2. */
9096 type
->field (1) = saved_field
;
9097 TYPE_FIELD_NAME (type
, 1)
9098 = rust_last_path_segment (type
->field (1).type ()->name ());
9099 type
->field (1).type ()->set_name
9100 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9101 TYPE_FIELD_NAME (type
, 1)));
9103 const char *dataless_name
9104 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9106 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9108 type
->field (2).set_type (dataless_type
);
9109 /* NAME points into the original discriminant name, which
9110 already has the correct lifetime. */
9111 TYPE_FIELD_NAME (type
, 2) = name
;
9112 SET_FIELD_BITPOS (type
->field (2), 0);
9114 /* Indicate that this is a variant type. */
9115 static discriminant_range ranges
[1] = { { 0, 0 } };
9116 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9118 /* A union with a single anonymous field is probably an old-style
9120 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9122 /* Smash this type to be a structure type. We have to do this
9123 because the type has already been recorded. */
9124 type
->set_code (TYPE_CODE_STRUCT
);
9126 struct type
*field_type
= type
->field (0).type ();
9127 const char *variant_name
9128 = rust_last_path_segment (field_type
->name ());
9129 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9130 field_type
->set_name
9131 (rust_fully_qualify (&objfile
->objfile_obstack
,
9132 type
->name (), variant_name
));
9134 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9138 struct type
*disr_type
= nullptr;
9139 for (int i
= 0; i
< type
->num_fields (); ++i
)
9141 disr_type
= type
->field (i
).type ();
9143 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9145 /* All fields of a true enum will be structs. */
9148 else if (disr_type
->num_fields () == 0)
9150 /* Could be data-less variant, so keep going. */
9151 disr_type
= nullptr;
9153 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9154 "RUST$ENUM$DISR") != 0)
9156 /* Not a Rust enum. */
9166 /* If we got here without a discriminant, then it's probably
9168 if (disr_type
== nullptr)
9171 /* Smash this type to be a structure type. We have to do this
9172 because the type has already been recorded. */
9173 type
->set_code (TYPE_CODE_STRUCT
);
9175 /* Make space for the discriminant field. */
9176 struct field
*disr_field
= &disr_type
->field (0);
9178 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9179 * sizeof (struct field
)));
9180 memcpy (new_fields
+ 1, type
->fields (),
9181 type
->num_fields () * sizeof (struct field
));
9182 type
->set_fields (new_fields
);
9183 type
->set_num_fields (type
->num_fields () + 1);
9185 /* Install the discriminant at index 0 in the union. */
9186 type
->field (0) = *disr_field
;
9187 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9188 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9190 /* We need a way to find the correct discriminant given a
9191 variant name. For convenience we build a map here. */
9192 struct type
*enum_type
= disr_field
->type ();
9193 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9194 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9196 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9199 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9200 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9204 int n_fields
= type
->num_fields ();
9205 /* We don't need a range entry for the discriminant, but we do
9206 need one for every other field, as there is no default
9208 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9211 /* Skip the discriminant here. */
9212 for (int i
= 1; i
< n_fields
; ++i
)
9214 /* Find the final word in the name of this variant's type.
9215 That name can be used to look up the correct
9217 const char *variant_name
9218 = rust_last_path_segment (type
->field (i
).type ()->name ());
9220 auto iter
= discriminant_map
.find (variant_name
);
9221 if (iter
!= discriminant_map
.end ())
9223 ranges
[i
- 1].low
= iter
->second
;
9224 ranges
[i
- 1].high
= iter
->second
;
9227 /* In Rust, each element should have the size of the
9229 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9231 /* Remove the discriminant field, if it exists. */
9232 struct type
*sub_type
= type
->field (i
).type ();
9233 if (sub_type
->num_fields () > 0)
9235 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9236 sub_type
->set_fields (sub_type
->fields () + 1);
9238 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9240 (rust_fully_qualify (&objfile
->objfile_obstack
,
9241 type
->name (), variant_name
));
9244 /* Indicate that this is a variant type. */
9245 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9246 gdb::array_view
<discriminant_range
> (ranges
,
9251 /* Rewrite some Rust unions to be structures with variants parts. */
9254 rust_union_quirks (struct dwarf2_cu
*cu
)
9256 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9257 for (type
*type_
: cu
->rust_unions
)
9258 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9259 /* We don't need this any more. */
9260 cu
->rust_unions
.clear ();
9265 type_unit_group_unshareable
*
9266 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9268 auto iter
= this->m_type_units
.find (tu_group
);
9269 if (iter
!= this->m_type_units
.end ())
9270 return iter
->second
.get ();
9272 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9273 type_unit_group_unshareable
*result
= uniq
.get ();
9274 this->m_type_units
[tu_group
] = std::move (uniq
);
9279 dwarf2_per_objfile::get_type_for_signatured_type
9280 (signatured_type
*sig_type
) const
9282 auto iter
= this->m_type_map
.find (sig_type
);
9283 if (iter
== this->m_type_map
.end ())
9286 return iter
->second
;
9289 void dwarf2_per_objfile::set_type_for_signatured_type
9290 (signatured_type
*sig_type
, struct type
*type
)
9292 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9294 this->m_type_map
[sig_type
] = type
;
9297 /* A helper function for computing the list of all symbol tables
9298 included by PER_CU. */
9301 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9302 htab_t all_children
, htab_t all_type_symtabs
,
9303 dwarf2_per_cu_data
*per_cu
,
9304 dwarf2_per_objfile
*per_objfile
,
9305 struct compunit_symtab
*immediate_parent
)
9307 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9310 /* This inclusion and its children have been processed. */
9316 /* Only add a CU if it has a symbol table. */
9317 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9320 /* If this is a type unit only add its symbol table if we haven't
9321 seen it yet (type unit per_cu's can share symtabs). */
9322 if (per_cu
->is_debug_types
)
9324 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9328 result
->push_back (cust
);
9329 if (cust
->user
== NULL
)
9330 cust
->user
= immediate_parent
;
9335 result
->push_back (cust
);
9336 if (cust
->user
== NULL
)
9337 cust
->user
= immediate_parent
;
9341 if (!per_cu
->imported_symtabs_empty ())
9342 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9344 recursively_compute_inclusions (result
, all_children
,
9345 all_type_symtabs
, ptr
, per_objfile
,
9350 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9354 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9355 dwarf2_per_objfile
*per_objfile
)
9357 gdb_assert (! per_cu
->is_debug_types
);
9359 if (!per_cu
->imported_symtabs_empty ())
9362 std::vector
<compunit_symtab
*> result_symtabs
;
9363 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9365 /* If we don't have a symtab, we can just skip this case. */
9369 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9371 NULL
, xcalloc
, xfree
));
9372 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9374 NULL
, xcalloc
, xfree
));
9376 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9378 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9379 all_type_symtabs
.get (), ptr
,
9383 /* Now we have a transitive closure of all the included symtabs. */
9384 len
= result_symtabs
.size ();
9386 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9387 struct compunit_symtab
*, len
+ 1);
9388 memcpy (cust
->includes
, result_symtabs
.data (),
9389 len
* sizeof (compunit_symtab
*));
9390 cust
->includes
[len
] = NULL
;
9394 /* Compute the 'includes' field for the symtabs of all the CUs we just
9398 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9400 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9402 if (! iter
->is_debug_types
)
9403 compute_compunit_symtab_includes (iter
, per_objfile
);
9406 per_objfile
->per_bfd
->just_read_cus
.clear ();
9409 /* Generate full symbol information for CU, whose DIEs have
9410 already been loaded into memory. */
9413 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9415 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9416 struct objfile
*objfile
= per_objfile
->objfile
;
9417 struct gdbarch
*gdbarch
= objfile
->arch ();
9418 CORE_ADDR lowpc
, highpc
;
9419 struct compunit_symtab
*cust
;
9421 struct block
*static_block
;
9424 baseaddr
= objfile
->text_section_offset ();
9426 /* Clear the list here in case something was left over. */
9427 cu
->method_list
.clear ();
9429 dwarf2_find_base_address (cu
->dies
, cu
);
9431 /* Before we start reading the top-level DIE, ensure it has a valid tag
9433 switch (cu
->dies
->tag
)
9435 case DW_TAG_compile_unit
:
9436 case DW_TAG_partial_unit
:
9437 case DW_TAG_type_unit
:
9440 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9441 dwarf_tag_name (cu
->dies
->tag
),
9442 sect_offset_str (cu
->per_cu
->sect_off
),
9443 objfile_name (per_objfile
->objfile
));
9446 /* Do line number decoding in read_file_scope () */
9447 process_die (cu
->dies
, cu
);
9449 /* For now fudge the Go package. */
9450 if (cu
->per_cu
->lang
== language_go
)
9451 fixup_go_packaging (cu
);
9453 /* Now that we have processed all the DIEs in the CU, all the types
9454 should be complete, and it should now be safe to compute all of the
9456 compute_delayed_physnames (cu
);
9458 if (cu
->per_cu
->lang
== language_rust
)
9459 rust_union_quirks (cu
);
9461 /* Some compilers don't define a DW_AT_high_pc attribute for the
9462 compilation unit. If the DW_AT_high_pc is missing, synthesize
9463 it, by scanning the DIE's below the compilation unit. */
9464 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9466 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9467 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9469 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9470 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9471 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9472 addrmap to help ensure it has an accurate map of pc values belonging to
9474 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9476 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9477 SECT_OFF_TEXT (objfile
),
9482 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9484 /* Set symtab language to language from DW_AT_language. If the
9485 compilation is from a C file generated by language preprocessors, do
9486 not set the language if it was already deduced by start_subfile. */
9487 if (!(cu
->per_cu
->lang
== language_c
9488 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9489 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9491 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9492 produce DW_AT_location with location lists but it can be possibly
9493 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9494 there were bugs in prologue debug info, fixed later in GCC-4.5
9495 by "unwind info for epilogues" patch (which is not directly related).
9497 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9498 needed, it would be wrong due to missing DW_AT_producer there.
9500 Still one can confuse GDB by using non-standard GCC compilation
9501 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9503 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9504 cust
->locations_valid
= 1;
9506 if (gcc_4_minor
>= 5)
9507 cust
->epilogue_unwind_valid
= 1;
9509 cust
->call_site_htab
= cu
->call_site_htab
;
9512 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9514 /* Push it for inclusion processing later. */
9515 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9517 /* Not needed any more. */
9518 cu
->reset_builder ();
9521 /* Generate full symbol information for type unit CU, whose DIEs have
9522 already been loaded into memory. */
9525 process_full_type_unit (dwarf2_cu
*cu
,
9526 enum language pretend_language
)
9528 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9529 struct objfile
*objfile
= per_objfile
->objfile
;
9530 struct compunit_symtab
*cust
;
9531 struct signatured_type
*sig_type
;
9533 gdb_assert (cu
->per_cu
->is_debug_types
);
9534 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9536 /* Clear the list here in case something was left over. */
9537 cu
->method_list
.clear ();
9539 /* The symbol tables are set up in read_type_unit_scope. */
9540 process_die (cu
->dies
, cu
);
9542 /* For now fudge the Go package. */
9543 if (cu
->per_cu
->lang
== language_go
)
9544 fixup_go_packaging (cu
);
9546 /* Now that we have processed all the DIEs in the CU, all the types
9547 should be complete, and it should now be safe to compute all of the
9549 compute_delayed_physnames (cu
);
9551 if (cu
->per_cu
->lang
== language_rust
)
9552 rust_union_quirks (cu
);
9554 /* TUs share symbol tables.
9555 If this is the first TU to use this symtab, complete the construction
9556 of it with end_expandable_symtab. Otherwise, complete the addition of
9557 this TU's symbols to the existing symtab. */
9558 type_unit_group_unshareable
*tug_unshare
=
9559 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9560 if (tug_unshare
->compunit_symtab
== NULL
)
9562 buildsym_compunit
*builder
= cu
->get_builder ();
9563 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9564 tug_unshare
->compunit_symtab
= cust
;
9568 /* Set symtab language to language from DW_AT_language. If the
9569 compilation is from a C file generated by language preprocessors,
9570 do not set the language if it was already deduced by
9572 if (!(cu
->per_cu
->lang
== language_c
9573 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9574 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9579 cu
->get_builder ()->augment_type_symtab ();
9580 cust
= tug_unshare
->compunit_symtab
;
9583 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9585 /* Not needed any more. */
9586 cu
->reset_builder ();
9589 /* Process an imported unit DIE. */
9592 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9594 struct attribute
*attr
;
9596 /* For now we don't handle imported units in type units. */
9597 if (cu
->per_cu
->is_debug_types
)
9599 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9600 " supported in type units [in module %s]"),
9601 objfile_name (cu
->per_objfile
->objfile
));
9604 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9607 sect_offset sect_off
= attr
->get_ref_die_offset ();
9608 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9609 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9610 dwarf2_per_cu_data
*per_cu
9611 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9613 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9614 into another compilation unit, at root level. Regard this as a hint,
9616 if (die
->parent
&& die
->parent
->parent
== NULL
9617 && per_cu
->unit_type
== DW_UT_compile
9618 && per_cu
->lang
== language_cplus
)
9621 /* If necessary, add it to the queue and load its DIEs. */
9622 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
9624 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9625 false, cu
->per_cu
->lang
);
9627 cu
->per_cu
->imported_symtabs_push (per_cu
);
9631 /* RAII object that represents a process_die scope: i.e.,
9632 starts/finishes processing a DIE. */
9633 class process_die_scope
9636 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9637 : m_die (die
), m_cu (cu
)
9639 /* We should only be processing DIEs not already in process. */
9640 gdb_assert (!m_die
->in_process
);
9641 m_die
->in_process
= true;
9644 ~process_die_scope ()
9646 m_die
->in_process
= false;
9648 /* If we're done processing the DIE for the CU that owns the line
9649 header, we don't need the line header anymore. */
9650 if (m_cu
->line_header_die_owner
== m_die
)
9652 delete m_cu
->line_header
;
9653 m_cu
->line_header
= NULL
;
9654 m_cu
->line_header_die_owner
= NULL
;
9663 /* Process a die and its children. */
9666 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9668 process_die_scope
scope (die
, cu
);
9672 case DW_TAG_padding
:
9674 case DW_TAG_compile_unit
:
9675 case DW_TAG_partial_unit
:
9676 read_file_scope (die
, cu
);
9678 case DW_TAG_type_unit
:
9679 read_type_unit_scope (die
, cu
);
9681 case DW_TAG_subprogram
:
9682 /* Nested subprograms in Fortran get a prefix. */
9683 if (cu
->per_cu
->lang
== language_fortran
9684 && die
->parent
!= NULL
9685 && die
->parent
->tag
== DW_TAG_subprogram
)
9686 cu
->processing_has_namespace_info
= true;
9688 case DW_TAG_inlined_subroutine
:
9689 read_func_scope (die
, cu
);
9691 case DW_TAG_lexical_block
:
9692 case DW_TAG_try_block
:
9693 case DW_TAG_catch_block
:
9694 read_lexical_block_scope (die
, cu
);
9696 case DW_TAG_call_site
:
9697 case DW_TAG_GNU_call_site
:
9698 read_call_site_scope (die
, cu
);
9700 case DW_TAG_class_type
:
9701 case DW_TAG_interface_type
:
9702 case DW_TAG_structure_type
:
9703 case DW_TAG_union_type
:
9704 process_structure_scope (die
, cu
);
9706 case DW_TAG_enumeration_type
:
9707 process_enumeration_scope (die
, cu
);
9710 /* These dies have a type, but processing them does not create
9711 a symbol or recurse to process the children. Therefore we can
9712 read them on-demand through read_type_die. */
9713 case DW_TAG_subroutine_type
:
9714 case DW_TAG_set_type
:
9715 case DW_TAG_pointer_type
:
9716 case DW_TAG_ptr_to_member_type
:
9717 case DW_TAG_reference_type
:
9718 case DW_TAG_rvalue_reference_type
:
9719 case DW_TAG_string_type
:
9722 case DW_TAG_array_type
:
9723 /* We only need to handle this case for Ada -- in other
9724 languages, it's normal for the compiler to emit a typedef
9726 if (cu
->per_cu
->lang
!= language_ada
)
9729 case DW_TAG_base_type
:
9730 case DW_TAG_subrange_type
:
9731 case DW_TAG_typedef
:
9732 /* Add a typedef symbol for the type definition, if it has a
9734 new_symbol (die
, read_type_die (die
, cu
), cu
);
9736 case DW_TAG_common_block
:
9737 read_common_block (die
, cu
);
9739 case DW_TAG_common_inclusion
:
9741 case DW_TAG_namespace
:
9742 cu
->processing_has_namespace_info
= true;
9743 read_namespace (die
, cu
);
9746 cu
->processing_has_namespace_info
= true;
9747 read_module (die
, cu
);
9749 case DW_TAG_imported_declaration
:
9750 cu
->processing_has_namespace_info
= true;
9751 if (read_namespace_alias (die
, cu
))
9753 /* The declaration is not a global namespace alias. */
9755 case DW_TAG_imported_module
:
9756 cu
->processing_has_namespace_info
= true;
9757 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9758 || cu
->per_cu
->lang
!= language_fortran
))
9759 complaint (_("Tag '%s' has unexpected children"),
9760 dwarf_tag_name (die
->tag
));
9761 read_import_statement (die
, cu
);
9764 case DW_TAG_imported_unit
:
9765 process_imported_unit_die (die
, cu
);
9768 case DW_TAG_variable
:
9769 read_variable (die
, cu
);
9773 new_symbol (die
, NULL
, cu
);
9778 /* DWARF name computation. */
9780 /* A helper function for dwarf2_compute_name which determines whether DIE
9781 needs to have the name of the scope prepended to the name listed in the
9785 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9787 struct attribute
*attr
;
9791 case DW_TAG_namespace
:
9792 case DW_TAG_typedef
:
9793 case DW_TAG_class_type
:
9794 case DW_TAG_interface_type
:
9795 case DW_TAG_structure_type
:
9796 case DW_TAG_union_type
:
9797 case DW_TAG_enumeration_type
:
9798 case DW_TAG_enumerator
:
9799 case DW_TAG_subprogram
:
9800 case DW_TAG_inlined_subroutine
:
9802 case DW_TAG_imported_declaration
:
9805 case DW_TAG_variable
:
9806 case DW_TAG_constant
:
9807 /* We only need to prefix "globally" visible variables. These include
9808 any variable marked with DW_AT_external or any variable that
9809 lives in a namespace. [Variables in anonymous namespaces
9810 require prefixing, but they are not DW_AT_external.] */
9812 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9814 struct dwarf2_cu
*spec_cu
= cu
;
9816 return die_needs_namespace (die_specification (die
, &spec_cu
),
9820 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9821 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9822 && die
->parent
->tag
!= DW_TAG_module
)
9824 /* A variable in a lexical block of some kind does not need a
9825 namespace, even though in C++ such variables may be external
9826 and have a mangled name. */
9827 if (die
->parent
->tag
== DW_TAG_lexical_block
9828 || die
->parent
->tag
== DW_TAG_try_block
9829 || die
->parent
->tag
== DW_TAG_catch_block
9830 || die
->parent
->tag
== DW_TAG_subprogram
)
9839 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9840 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9841 defined for the given DIE. */
9843 static struct attribute
*
9844 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9846 struct attribute
*attr
;
9848 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9850 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9855 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9856 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9857 defined for the given DIE. */
9860 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9862 const char *linkage_name
;
9864 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9865 if (linkage_name
== NULL
)
9866 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9868 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9869 See https://github.com/rust-lang/rust/issues/32925. */
9870 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
9871 && strchr (linkage_name
, '{') != NULL
)
9872 linkage_name
= NULL
;
9874 return linkage_name
;
9877 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9878 compute the physname for the object, which include a method's:
9879 - formal parameters (C++),
9880 - receiver type (Go),
9882 The term "physname" is a bit confusing.
9883 For C++, for example, it is the demangled name.
9884 For Go, for example, it's the mangled name.
9886 For Ada, return the DIE's linkage name rather than the fully qualified
9887 name. PHYSNAME is ignored..
9889 The result is allocated on the objfile->per_bfd's obstack and
9893 dwarf2_compute_name (const char *name
,
9894 struct die_info
*die
, struct dwarf2_cu
*cu
,
9897 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9900 name
= dwarf2_name (die
, cu
);
9902 enum language lang
= cu
->per_cu
->lang
;
9904 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9905 but otherwise compute it by typename_concat inside GDB.
9906 FIXME: Actually this is not really true, or at least not always true.
9907 It's all very confusing. compute_and_set_names doesn't try to demangle
9908 Fortran names because there is no mangling standard. So new_symbol
9909 will set the demangled name to the result of dwarf2_full_name, and it is
9910 the demangled name that GDB uses if it exists. */
9911 if (lang
== language_ada
9912 || (lang
== language_fortran
&& physname
))
9914 /* For Ada unit, we prefer the linkage name over the name, as
9915 the former contains the exported name, which the user expects
9916 to be able to reference. Ideally, we want the user to be able
9917 to reference this entity using either natural or linkage name,
9918 but we haven't started looking at this enhancement yet. */
9919 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9921 if (linkage_name
!= NULL
)
9922 return linkage_name
;
9925 /* These are the only languages we know how to qualify names in. */
9927 && (lang
== language_cplus
9928 || lang
== language_fortran
|| lang
== language_d
9929 || lang
== language_rust
))
9931 if (die_needs_namespace (die
, cu
))
9934 const char *canonical_name
= NULL
;
9938 prefix
= determine_prefix (die
, cu
);
9939 if (*prefix
!= '\0')
9941 gdb::unique_xmalloc_ptr
<char> prefixed_name
9942 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9944 buf
.puts (prefixed_name
.get ());
9949 /* Template parameters may be specified in the DIE's DW_AT_name, or
9950 as children with DW_TAG_template_type_param or
9951 DW_TAG_value_type_param. If the latter, add them to the name
9952 here. If the name already has template parameters, then
9953 skip this step; some versions of GCC emit both, and
9954 it is more efficient to use the pre-computed name.
9956 Something to keep in mind about this process: it is very
9957 unlikely, or in some cases downright impossible, to produce
9958 something that will match the mangled name of a function.
9959 If the definition of the function has the same debug info,
9960 we should be able to match up with it anyway. But fallbacks
9961 using the minimal symbol, for instance to find a method
9962 implemented in a stripped copy of libstdc++, will not work.
9963 If we do not have debug info for the definition, we will have to
9964 match them up some other way.
9966 When we do name matching there is a related problem with function
9967 templates; two instantiated function templates are allowed to
9968 differ only by their return types, which we do not add here. */
9970 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
9972 struct attribute
*attr
;
9973 struct die_info
*child
;
9976 die
->building_fullname
= 1;
9978 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9982 const gdb_byte
*bytes
;
9983 struct dwarf2_locexpr_baton
*baton
;
9986 if (child
->tag
!= DW_TAG_template_type_param
9987 && child
->tag
!= DW_TAG_template_value_param
)
9998 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10001 complaint (_("template parameter missing DW_AT_type"));
10002 buf
.puts ("UNKNOWN_TYPE");
10005 type
= die_type (child
, cu
);
10007 if (child
->tag
== DW_TAG_template_type_param
)
10009 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
10010 &type_print_raw_options
);
10014 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10017 complaint (_("template parameter missing "
10018 "DW_AT_const_value"));
10019 buf
.puts ("UNKNOWN_VALUE");
10023 dwarf2_const_value_attr (attr
, type
, name
,
10024 &cu
->comp_unit_obstack
, cu
,
10025 &value
, &bytes
, &baton
);
10027 if (type
->has_no_signedness ())
10028 /* GDB prints characters as NUMBER 'CHAR'. If that's
10029 changed, this can use value_print instead. */
10030 cu
->language_defn
->printchar (value
, type
, &buf
);
10033 struct value_print_options opts
;
10036 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10040 baton
->per_objfile
);
10041 else if (bytes
!= NULL
)
10043 v
= allocate_value (type
);
10044 memcpy (value_contents_writeable (v
), bytes
,
10045 TYPE_LENGTH (type
));
10048 v
= value_from_longest (type
, value
);
10050 /* Specify decimal so that we do not depend on
10052 get_formatted_print_options (&opts
, 'd');
10054 value_print (v
, &buf
, &opts
);
10059 die
->building_fullname
= 0;
10063 /* Close the argument list, with a space if necessary
10064 (nested templates). */
10065 if (!buf
.empty () && buf
.string ().back () == '>')
10072 /* For C++ methods, append formal parameter type
10073 information, if PHYSNAME. */
10075 if (physname
&& die
->tag
== DW_TAG_subprogram
10076 && lang
== language_cplus
)
10078 struct type
*type
= read_type_die (die
, cu
);
10080 c_type_print_args (type
, &buf
, 1, lang
,
10081 &type_print_raw_options
);
10083 if (lang
== language_cplus
)
10085 /* Assume that an artificial first parameter is
10086 "this", but do not crash if it is not. RealView
10087 marks unnamed (and thus unused) parameters as
10088 artificial; there is no way to differentiate
10090 if (type
->num_fields () > 0
10091 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10092 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10093 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10094 buf
.puts (" const");
10098 const std::string
&intermediate_name
= buf
.string ();
10100 if (lang
== language_cplus
)
10102 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10105 /* If we only computed INTERMEDIATE_NAME, or if
10106 INTERMEDIATE_NAME is already canonical, then we need to
10108 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10109 name
= objfile
->intern (intermediate_name
);
10111 name
= canonical_name
;
10118 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10119 If scope qualifiers are appropriate they will be added. The result
10120 will be allocated on the storage_obstack, or NULL if the DIE does
10121 not have a name. NAME may either be from a previous call to
10122 dwarf2_name or NULL.
10124 The output string will be canonicalized (if C++). */
10126 static const char *
10127 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10129 return dwarf2_compute_name (name
, die
, cu
, 0);
10132 /* Construct a physname for the given DIE in CU. NAME may either be
10133 from a previous call to dwarf2_name or NULL. The result will be
10134 allocated on the objfile_objstack or NULL if the DIE does not have a
10137 The output string will be canonicalized (if C++). */
10139 static const char *
10140 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10142 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10143 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10146 /* In this case dwarf2_compute_name is just a shortcut not building anything
10148 if (!die_needs_namespace (die
, cu
))
10149 return dwarf2_compute_name (name
, die
, cu
, 1);
10151 if (cu
->per_cu
->lang
!= language_rust
)
10152 mangled
= dw2_linkage_name (die
, cu
);
10154 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10156 gdb::unique_xmalloc_ptr
<char> demangled
;
10157 if (mangled
!= NULL
)
10159 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10161 /* Do nothing (do not demangle the symbol name). */
10165 /* Use DMGL_RET_DROP for C++ template functions to suppress
10166 their return type. It is easier for GDB users to search
10167 for such functions as `name(params)' than `long name(params)'.
10168 In such case the minimal symbol names do not match the full
10169 symbol names but for template functions there is never a need
10170 to look up their definition from their declaration so
10171 the only disadvantage remains the minimal symbol variant
10172 `long name(params)' does not have the proper inferior type. */
10173 demangled
.reset (gdb_demangle (mangled
,
10174 (DMGL_PARAMS
| DMGL_ANSI
10175 | DMGL_RET_DROP
)));
10178 canon
= demangled
.get ();
10186 if (canon
== NULL
|| check_physname
)
10188 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10190 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10192 /* It may not mean a bug in GDB. The compiler could also
10193 compute DW_AT_linkage_name incorrectly. But in such case
10194 GDB would need to be bug-to-bug compatible. */
10196 complaint (_("Computed physname <%s> does not match demangled <%s> "
10197 "(from linkage <%s>) - DIE at %s [in module %s]"),
10198 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10199 objfile_name (objfile
));
10201 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10202 is available here - over computed PHYSNAME. It is safer
10203 against both buggy GDB and buggy compilers. */
10217 retval
= objfile
->intern (retval
);
10222 /* Inspect DIE in CU for a namespace alias. If one exists, record
10223 a new symbol for it.
10225 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10228 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10230 struct attribute
*attr
;
10232 /* If the die does not have a name, this is not a namespace
10234 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10238 struct die_info
*d
= die
;
10239 struct dwarf2_cu
*imported_cu
= cu
;
10241 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10242 keep inspecting DIEs until we hit the underlying import. */
10243 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10244 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10246 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10250 d
= follow_die_ref (d
, attr
, &imported_cu
);
10251 if (d
->tag
!= DW_TAG_imported_declaration
)
10255 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10257 complaint (_("DIE at %s has too many recursively imported "
10258 "declarations"), sect_offset_str (d
->sect_off
));
10265 sect_offset sect_off
= attr
->get_ref_die_offset ();
10267 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10268 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10270 /* This declaration is a global namespace alias. Add
10271 a symbol for it whose type is the aliased namespace. */
10272 new_symbol (die
, type
, cu
);
10281 /* Return the using directives repository (global or local?) to use in the
10282 current context for CU.
10284 For Ada, imported declarations can materialize renamings, which *may* be
10285 global. However it is impossible (for now?) in DWARF to distinguish
10286 "external" imported declarations and "static" ones. As all imported
10287 declarations seem to be static in all other languages, make them all CU-wide
10288 global only in Ada. */
10290 static struct using_direct
**
10291 using_directives (struct dwarf2_cu
*cu
)
10293 if (cu
->per_cu
->lang
== language_ada
10294 && cu
->get_builder ()->outermost_context_p ())
10295 return cu
->get_builder ()->get_global_using_directives ();
10297 return cu
->get_builder ()->get_local_using_directives ();
10300 /* Read the import statement specified by the given die and record it. */
10303 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10305 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10306 struct attribute
*import_attr
;
10307 struct die_info
*imported_die
, *child_die
;
10308 struct dwarf2_cu
*imported_cu
;
10309 const char *imported_name
;
10310 const char *imported_name_prefix
;
10311 const char *canonical_name
;
10312 const char *import_alias
;
10313 const char *imported_declaration
= NULL
;
10314 const char *import_prefix
;
10315 std::vector
<const char *> excludes
;
10317 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10318 if (import_attr
== NULL
)
10320 complaint (_("Tag '%s' has no DW_AT_import"),
10321 dwarf_tag_name (die
->tag
));
10326 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10327 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10328 if (imported_name
== NULL
)
10330 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10332 The import in the following code:
10346 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10347 <52> DW_AT_decl_file : 1
10348 <53> DW_AT_decl_line : 6
10349 <54> DW_AT_import : <0x75>
10350 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10351 <59> DW_AT_name : B
10352 <5b> DW_AT_decl_file : 1
10353 <5c> DW_AT_decl_line : 2
10354 <5d> DW_AT_type : <0x6e>
10356 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10357 <76> DW_AT_byte_size : 4
10358 <77> DW_AT_encoding : 5 (signed)
10360 imports the wrong die ( 0x75 instead of 0x58 ).
10361 This case will be ignored until the gcc bug is fixed. */
10365 /* Figure out the local name after import. */
10366 import_alias
= dwarf2_name (die
, cu
);
10368 /* Figure out where the statement is being imported to. */
10369 import_prefix
= determine_prefix (die
, cu
);
10371 /* Figure out what the scope of the imported die is and prepend it
10372 to the name of the imported die. */
10373 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10375 if (imported_die
->tag
!= DW_TAG_namespace
10376 && imported_die
->tag
!= DW_TAG_module
)
10378 imported_declaration
= imported_name
;
10379 canonical_name
= imported_name_prefix
;
10381 else if (strlen (imported_name_prefix
) > 0)
10382 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10383 imported_name_prefix
,
10384 (cu
->per_cu
->lang
== language_d
10387 imported_name
, (char *) NULL
);
10389 canonical_name
= imported_name
;
10391 if (die
->tag
== DW_TAG_imported_module
10392 && cu
->per_cu
->lang
== language_fortran
)
10393 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10394 child_die
= child_die
->sibling
)
10396 /* DWARF-4: A Fortran use statement with a “rename list” may be
10397 represented by an imported module entry with an import attribute
10398 referring to the module and owned entries corresponding to those
10399 entities that are renamed as part of being imported. */
10401 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10403 complaint (_("child DW_TAG_imported_declaration expected "
10404 "- DIE at %s [in module %s]"),
10405 sect_offset_str (child_die
->sect_off
),
10406 objfile_name (objfile
));
10410 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10411 if (import_attr
== NULL
)
10413 complaint (_("Tag '%s' has no DW_AT_import"),
10414 dwarf_tag_name (child_die
->tag
));
10419 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10421 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10422 if (imported_name
== NULL
)
10424 complaint (_("child DW_TAG_imported_declaration has unknown "
10425 "imported name - DIE at %s [in module %s]"),
10426 sect_offset_str (child_die
->sect_off
),
10427 objfile_name (objfile
));
10431 excludes
.push_back (imported_name
);
10433 process_die (child_die
, cu
);
10436 add_using_directive (using_directives (cu
),
10440 imported_declaration
,
10443 &objfile
->objfile_obstack
);
10446 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10447 types, but gives them a size of zero. Starting with version 14,
10448 ICC is compatible with GCC. */
10451 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10453 if (!cu
->checked_producer
)
10454 check_producer (cu
);
10456 return cu
->producer_is_icc_lt_14
;
10459 /* ICC generates a DW_AT_type for C void functions. This was observed on
10460 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10461 which says that void functions should not have a DW_AT_type. */
10464 producer_is_icc (struct dwarf2_cu
*cu
)
10466 if (!cu
->checked_producer
)
10467 check_producer (cu
);
10469 return cu
->producer_is_icc
;
10472 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10473 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10474 this, it was first present in GCC release 4.3.0. */
10477 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10479 if (!cu
->checked_producer
)
10480 check_producer (cu
);
10482 return cu
->producer_is_gcc_lt_4_3
;
10485 static file_and_directory
10486 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10488 file_and_directory res
;
10490 /* Find the filename. Do not use dwarf2_name here, since the filename
10491 is not a source language identifier. */
10492 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10493 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10495 if (res
.comp_dir
== NULL
10496 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10497 && IS_ABSOLUTE_PATH (res
.name
))
10499 std::string comp_dir_storage
= ldirname (res
.name
);
10500 if (!comp_dir_storage
.empty ())
10502 = cu
->per_objfile
->objfile
->intern (comp_dir_storage
.c_str ());
10504 if (res
.comp_dir
!= NULL
)
10506 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10507 directory, get rid of it. */
10508 const char *cp
= strchr (res
.comp_dir
, ':');
10510 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10511 res
.comp_dir
= cp
+ 1;
10514 if (res
.name
== NULL
)
10515 res
.name
= "<unknown>";
10520 /* Handle DW_AT_stmt_list for a compilation unit.
10521 DIE is the DW_TAG_compile_unit die for CU.
10522 COMP_DIR is the compilation directory. LOWPC is passed to
10523 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10526 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10527 const file_and_directory
&fnd
, CORE_ADDR lowpc
) /* ARI: editCase function */
10529 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10530 struct attribute
*attr
;
10531 struct line_header line_header_local
;
10532 hashval_t line_header_local_hash
;
10534 int decode_mapping
;
10536 gdb_assert (! cu
->per_cu
->is_debug_types
);
10538 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10539 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10542 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10544 /* The line header hash table is only created if needed (it exists to
10545 prevent redundant reading of the line table for partial_units).
10546 If we're given a partial_unit, we'll need it. If we're given a
10547 compile_unit, then use the line header hash table if it's already
10548 created, but don't create one just yet. */
10550 if (per_objfile
->line_header_hash
== NULL
10551 && die
->tag
== DW_TAG_partial_unit
)
10553 per_objfile
->line_header_hash
10554 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10555 line_header_eq_voidp
,
10556 htab_delete_entry
<line_header
>,
10560 line_header_local
.sect_off
= line_offset
;
10561 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10562 line_header_local_hash
= line_header_hash (&line_header_local
);
10563 if (per_objfile
->line_header_hash
!= NULL
)
10565 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10566 &line_header_local
,
10567 line_header_local_hash
, NO_INSERT
);
10569 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10570 is not present in *SLOT (since if there is something in *SLOT then
10571 it will be for a partial_unit). */
10572 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10574 gdb_assert (*slot
!= NULL
);
10575 cu
->line_header
= (struct line_header
*) *slot
;
10580 /* dwarf_decode_line_header does not yet provide sufficient information.
10581 We always have to call also dwarf_decode_lines for it. */
10582 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10586 cu
->line_header
= lh
.release ();
10587 cu
->line_header_die_owner
= die
;
10589 if (per_objfile
->line_header_hash
== NULL
)
10593 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10594 &line_header_local
,
10595 line_header_local_hash
, INSERT
);
10596 gdb_assert (slot
!= NULL
);
10598 if (slot
!= NULL
&& *slot
== NULL
)
10600 /* This newly decoded line number information unit will be owned
10601 by line_header_hash hash table. */
10602 *slot
= cu
->line_header
;
10603 cu
->line_header_die_owner
= NULL
;
10607 /* We cannot free any current entry in (*slot) as that struct line_header
10608 may be already used by multiple CUs. Create only temporary decoded
10609 line_header for this CU - it may happen at most once for each line
10610 number information unit. And if we're not using line_header_hash
10611 then this is what we want as well. */
10612 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10614 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10615 dwarf_decode_lines (cu
->line_header
, fnd
, cu
, nullptr, lowpc
,
10620 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10623 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10625 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10626 struct objfile
*objfile
= per_objfile
->objfile
;
10627 struct gdbarch
*gdbarch
= objfile
->arch ();
10628 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10629 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10630 struct attribute
*attr
;
10631 struct die_info
*child_die
;
10632 CORE_ADDR baseaddr
;
10634 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
10635 baseaddr
= objfile
->text_section_offset ();
10637 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10639 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10640 from finish_block. */
10641 if (lowpc
== ((CORE_ADDR
) -1))
10643 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10645 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10647 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10649 gdb_assert (per_objfile
->sym_cu
== nullptr);
10650 scoped_restore restore_sym_cu
10651 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10653 /* Decode line number information if present. We do this before
10654 processing child DIEs, so that the line header table is available
10655 for DW_AT_decl_file. */
10656 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
);
10658 /* Process all dies in compilation unit. */
10659 if (die
->child
!= NULL
)
10661 child_die
= die
->child
;
10662 while (child_die
&& child_die
->tag
)
10664 process_die (child_die
, cu
);
10665 child_die
= child_die
->sibling
;
10668 per_objfile
->sym_cu
= nullptr;
10670 /* Decode macro information, if present. Dwarf 2 macro information
10671 refers to information in the line number info statement program
10672 header, so we can only read it if we've read the header
10674 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10676 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10677 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10679 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10680 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10682 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10686 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10687 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10689 unsigned int macro_offset
= attr
->as_unsigned ();
10691 dwarf_decode_macros (cu
, macro_offset
, 0);
10697 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10699 struct type_unit_group
*tu_group
;
10701 struct attribute
*attr
;
10703 struct signatured_type
*sig_type
;
10705 gdb_assert (per_cu
->is_debug_types
);
10706 sig_type
= (struct signatured_type
*) per_cu
;
10708 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10710 /* If we're using .gdb_index (includes -readnow) then
10711 per_cu->type_unit_group may not have been set up yet. */
10712 if (sig_type
->type_unit_group
== NULL
)
10713 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10714 tu_group
= sig_type
->type_unit_group
;
10716 /* If we've already processed this stmt_list there's no real need to
10717 do it again, we could fake it and just recreate the part we need
10718 (file name,index -> symtab mapping). If data shows this optimization
10719 is useful we can do it then. */
10720 type_unit_group_unshareable
*tug_unshare
10721 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10722 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10724 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10727 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10729 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10730 lh
= dwarf_decode_line_header (line_offset
, this);
10735 start_symtab ("", NULL
, 0);
10738 gdb_assert (tug_unshare
->symtabs
== NULL
);
10739 gdb_assert (m_builder
== nullptr);
10740 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10741 m_builder
.reset (new struct buildsym_compunit
10742 (COMPUNIT_OBJFILE (cust
), "",
10743 COMPUNIT_DIRNAME (cust
),
10744 compunit_language (cust
),
10746 list_in_scope
= get_builder ()->get_file_symbols ();
10751 line_header
= lh
.release ();
10752 line_header_die_owner
= die
;
10756 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10758 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10759 still initializing it, and our caller (a few levels up)
10760 process_full_type_unit still needs to know if this is the first
10763 tug_unshare
->symtabs
10764 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10765 struct symtab
*, line_header
->file_names_size ());
10767 auto &file_names
= line_header
->file_names ();
10768 for (i
= 0; i
< file_names
.size (); ++i
)
10770 file_entry
&fe
= file_names
[i
];
10771 dwarf2_start_subfile (this, fe
.name
,
10772 fe
.include_dir (line_header
));
10773 buildsym_compunit
*b
= get_builder ();
10774 if (b
->get_current_subfile ()->symtab
== NULL
)
10776 /* NOTE: start_subfile will recognize when it's been
10777 passed a file it has already seen. So we can't
10778 assume there's a simple mapping from
10779 cu->line_header->file_names to subfiles, plus
10780 cu->line_header->file_names may contain dups. */
10781 b
->get_current_subfile ()->symtab
10782 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10785 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10786 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10791 gdb_assert (m_builder
== nullptr);
10792 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10793 m_builder
.reset (new struct buildsym_compunit
10794 (COMPUNIT_OBJFILE (cust
), "",
10795 COMPUNIT_DIRNAME (cust
),
10796 compunit_language (cust
),
10798 list_in_scope
= get_builder ()->get_file_symbols ();
10800 auto &file_names
= line_header
->file_names ();
10801 for (i
= 0; i
< file_names
.size (); ++i
)
10803 file_entry
&fe
= file_names
[i
];
10804 fe
.symtab
= tug_unshare
->symtabs
[i
];
10808 /* The main symtab is allocated last. Type units don't have DW_AT_name
10809 so they don't have a "real" (so to speak) symtab anyway.
10810 There is later code that will assign the main symtab to all symbols
10811 that don't have one. We need to handle the case of a symbol with a
10812 missing symtab (DW_AT_decl_file) anyway. */
10815 /* Process DW_TAG_type_unit.
10816 For TUs we want to skip the first top level sibling if it's not the
10817 actual type being defined by this TU. In this case the first top
10818 level sibling is there to provide context only. */
10821 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10823 struct die_info
*child_die
;
10825 prepare_one_comp_unit (cu
, die
, language_minimal
);
10827 /* Initialize (or reinitialize) the machinery for building symtabs.
10828 We do this before processing child DIEs, so that the line header table
10829 is available for DW_AT_decl_file. */
10830 cu
->setup_type_unit_groups (die
);
10832 if (die
->child
!= NULL
)
10834 child_die
= die
->child
;
10835 while (child_die
&& child_die
->tag
)
10837 process_die (child_die
, cu
);
10838 child_die
= child_die
->sibling
;
10845 http://gcc.gnu.org/wiki/DebugFission
10846 http://gcc.gnu.org/wiki/DebugFissionDWP
10848 To simplify handling of both DWO files ("object" files with the DWARF info)
10849 and DWP files (a file with the DWOs packaged up into one file), we treat
10850 DWP files as having a collection of virtual DWO files. */
10853 hash_dwo_file (const void *item
)
10855 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10858 hash
= htab_hash_string (dwo_file
->dwo_name
);
10859 if (dwo_file
->comp_dir
!= NULL
)
10860 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10865 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10867 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10868 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10870 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10872 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10873 return lhs
->comp_dir
== rhs
->comp_dir
;
10874 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10877 /* Allocate a hash table for DWO files. */
10880 allocate_dwo_file_hash_table ()
10882 return htab_up (htab_create_alloc (41,
10885 htab_delete_entry
<dwo_file
>,
10889 /* Lookup DWO file DWO_NAME. */
10892 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10893 const char *dwo_name
,
10894 const char *comp_dir
)
10896 struct dwo_file find_entry
;
10899 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10900 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10902 find_entry
.dwo_name
= dwo_name
;
10903 find_entry
.comp_dir
= comp_dir
;
10904 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10911 hash_dwo_unit (const void *item
)
10913 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10915 /* This drops the top 32 bits of the id, but is ok for a hash. */
10916 return dwo_unit
->signature
;
10920 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10922 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10923 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10925 /* The signature is assumed to be unique within the DWO file.
10926 So while object file CU dwo_id's always have the value zero,
10927 that's OK, assuming each object file DWO file has only one CU,
10928 and that's the rule for now. */
10929 return lhs
->signature
== rhs
->signature
;
10932 /* Allocate a hash table for DWO CUs,TUs.
10933 There is one of these tables for each of CUs,TUs for each DWO file. */
10936 allocate_dwo_unit_table ()
10938 /* Start out with a pretty small number.
10939 Generally DWO files contain only one CU and maybe some TUs. */
10940 return htab_up (htab_create_alloc (3,
10943 NULL
, xcalloc
, xfree
));
10946 /* die_reader_func for create_dwo_cu. */
10949 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10950 const gdb_byte
*info_ptr
,
10951 struct die_info
*comp_unit_die
,
10952 struct dwo_file
*dwo_file
,
10953 struct dwo_unit
*dwo_unit
)
10955 struct dwarf2_cu
*cu
= reader
->cu
;
10956 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10957 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10959 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10960 if (!signature
.has_value ())
10962 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10963 " its dwo_id [in module %s]"),
10964 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10968 dwo_unit
->dwo_file
= dwo_file
;
10969 dwo_unit
->signature
= *signature
;
10970 dwo_unit
->section
= section
;
10971 dwo_unit
->sect_off
= sect_off
;
10972 dwo_unit
->length
= cu
->per_cu
->length
;
10974 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10975 sect_offset_str (sect_off
),
10976 hex_string (dwo_unit
->signature
));
10979 /* Create the dwo_units for the CUs in a DWO_FILE.
10980 Note: This function processes DWO files only, not DWP files. */
10983 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10984 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10985 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10987 struct objfile
*objfile
= per_objfile
->objfile
;
10988 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10989 const gdb_byte
*info_ptr
, *end_ptr
;
10991 section
.read (objfile
);
10992 info_ptr
= section
.buffer
;
10994 if (info_ptr
== NULL
)
10997 dwarf_read_debug_printf ("Reading %s for %s:",
10998 section
.get_name (),
10999 section
.get_file_name ());
11001 end_ptr
= info_ptr
+ section
.size
;
11002 while (info_ptr
< end_ptr
)
11004 struct dwarf2_per_cu_data per_cu
;
11005 struct dwo_unit read_unit
{};
11006 struct dwo_unit
*dwo_unit
;
11008 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11010 per_cu
.per_bfd
= per_bfd
;
11011 per_cu
.is_debug_types
= 0;
11012 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11013 per_cu
.section
= §ion
;
11015 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11016 if (!reader
.dummy_p
)
11017 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11018 &dwo_file
, &read_unit
);
11019 info_ptr
+= per_cu
.length
;
11021 // If the unit could not be parsed, skip it.
11022 if (read_unit
.dwo_file
== NULL
)
11025 if (cus_htab
== NULL
)
11026 cus_htab
= allocate_dwo_unit_table ();
11028 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11030 *dwo_unit
= read_unit
;
11031 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11032 gdb_assert (slot
!= NULL
);
11035 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11036 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11038 complaint (_("debug cu entry at offset %s is duplicate to"
11039 " the entry at offset %s, signature %s"),
11040 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11041 hex_string (dwo_unit
->signature
));
11043 *slot
= (void *)dwo_unit
;
11047 /* DWP file .debug_{cu,tu}_index section format:
11048 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11049 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11051 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11052 officially standard DWP format was published with DWARF v5 and is called
11053 Version 5. There are no versions 3 or 4.
11057 Both index sections have the same format, and serve to map a 64-bit
11058 signature to a set of section numbers. Each section begins with a header,
11059 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11060 indexes, and a pool of 32-bit section numbers. The index sections will be
11061 aligned at 8-byte boundaries in the file.
11063 The index section header consists of:
11065 V, 32 bit version number
11067 N, 32 bit number of compilation units or type units in the index
11068 M, 32 bit number of slots in the hash table
11070 Numbers are recorded using the byte order of the application binary.
11072 The hash table begins at offset 16 in the section, and consists of an array
11073 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11074 order of the application binary). Unused slots in the hash table are 0.
11075 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11077 The parallel table begins immediately after the hash table
11078 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11079 array of 32-bit indexes (using the byte order of the application binary),
11080 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11081 table contains a 32-bit index into the pool of section numbers. For unused
11082 hash table slots, the corresponding entry in the parallel table will be 0.
11084 The pool of section numbers begins immediately following the hash table
11085 (at offset 16 + 12 * M from the beginning of the section). The pool of
11086 section numbers consists of an array of 32-bit words (using the byte order
11087 of the application binary). Each item in the array is indexed starting
11088 from 0. The hash table entry provides the index of the first section
11089 number in the set. Additional section numbers in the set follow, and the
11090 set is terminated by a 0 entry (section number 0 is not used in ELF).
11092 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11093 section must be the first entry in the set, and the .debug_abbrev.dwo must
11094 be the second entry. Other members of the set may follow in any order.
11098 DWP Versions 2 and 5:
11100 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11101 and the entries in the index tables are now offsets into these sections.
11102 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11105 Index Section Contents:
11107 Hash Table of Signatures dwp_hash_table.hash_table
11108 Parallel Table of Indices dwp_hash_table.unit_table
11109 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11110 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11112 The index section header consists of:
11114 V, 32 bit version number
11115 L, 32 bit number of columns in the table of section offsets
11116 N, 32 bit number of compilation units or type units in the index
11117 M, 32 bit number of slots in the hash table
11119 Numbers are recorded using the byte order of the application binary.
11121 The hash table has the same format as version 1.
11122 The parallel table of indices has the same format as version 1,
11123 except that the entries are origin-1 indices into the table of sections
11124 offsets and the table of section sizes.
11126 The table of offsets begins immediately following the parallel table
11127 (at offset 16 + 12 * M from the beginning of the section). The table is
11128 a two-dimensional array of 32-bit words (using the byte order of the
11129 application binary), with L columns and N+1 rows, in row-major order.
11130 Each row in the array is indexed starting from 0. The first row provides
11131 a key to the remaining rows: each column in this row provides an identifier
11132 for a debug section, and the offsets in the same column of subsequent rows
11133 refer to that section. The section identifiers for Version 2 are:
11135 DW_SECT_INFO 1 .debug_info.dwo
11136 DW_SECT_TYPES 2 .debug_types.dwo
11137 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11138 DW_SECT_LINE 4 .debug_line.dwo
11139 DW_SECT_LOC 5 .debug_loc.dwo
11140 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11141 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11142 DW_SECT_MACRO 8 .debug_macro.dwo
11144 The section identifiers for Version 5 are:
11146 DW_SECT_INFO_V5 1 .debug_info.dwo
11147 DW_SECT_RESERVED_V5 2 --
11148 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11149 DW_SECT_LINE_V5 4 .debug_line.dwo
11150 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11151 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11152 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11153 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11155 The offsets provided by the CU and TU index sections are the base offsets
11156 for the contributions made by each CU or TU to the corresponding section
11157 in the package file. Each CU and TU header contains an abbrev_offset
11158 field, used to find the abbreviations table for that CU or TU within the
11159 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11160 be interpreted as relative to the base offset given in the index section.
11161 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11162 should be interpreted as relative to the base offset for .debug_line.dwo,
11163 and offsets into other debug sections obtained from DWARF attributes should
11164 also be interpreted as relative to the corresponding base offset.
11166 The table of sizes begins immediately following the table of offsets.
11167 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11168 with L columns and N rows, in row-major order. Each row in the array is
11169 indexed starting from 1 (row 0 is shared by the two tables).
11173 Hash table lookup is handled the same in version 1 and 2:
11175 We assume that N and M will not exceed 2^32 - 1.
11176 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11178 Given a 64-bit compilation unit signature or a type signature S, an entry
11179 in the hash table is located as follows:
11181 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11182 the low-order k bits all set to 1.
11184 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11186 3) If the hash table entry at index H matches the signature, use that
11187 entry. If the hash table entry at index H is unused (all zeroes),
11188 terminate the search: the signature is not present in the table.
11190 4) Let H = (H + H') modulo M. Repeat at Step 3.
11192 Because M > N and H' and M are relatively prime, the search is guaranteed
11193 to stop at an unused slot or find the match. */
11195 /* Create a hash table to map DWO IDs to their CU/TU entry in
11196 .debug_{info,types}.dwo in DWP_FILE.
11197 Returns NULL if there isn't one.
11198 Note: This function processes DWP files only, not DWO files. */
11200 static struct dwp_hash_table
*
11201 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11202 struct dwp_file
*dwp_file
, int is_debug_types
)
11204 struct objfile
*objfile
= per_objfile
->objfile
;
11205 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11206 const gdb_byte
*index_ptr
, *index_end
;
11207 struct dwarf2_section_info
*index
;
11208 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11209 struct dwp_hash_table
*htab
;
11211 if (is_debug_types
)
11212 index
= &dwp_file
->sections
.tu_index
;
11214 index
= &dwp_file
->sections
.cu_index
;
11216 if (index
->empty ())
11218 index
->read (objfile
);
11220 index_ptr
= index
->buffer
;
11221 index_end
= index_ptr
+ index
->size
;
11223 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11224 For now it's safe to just read 4 bytes (particularly as it's difficult to
11225 tell if you're dealing with Version 5 before you've read the version). */
11226 version
= read_4_bytes (dbfd
, index_ptr
);
11228 if (version
== 2 || version
== 5)
11229 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11233 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11235 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11238 if (version
!= 1 && version
!= 2 && version
!= 5)
11240 error (_("Dwarf Error: unsupported DWP file version (%s)"
11241 " [in module %s]"),
11242 pulongest (version
), dwp_file
->name
);
11244 if (nr_slots
!= (nr_slots
& -nr_slots
))
11246 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11247 " is not power of 2 [in module %s]"),
11248 pulongest (nr_slots
), dwp_file
->name
);
11251 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11252 htab
->version
= version
;
11253 htab
->nr_columns
= nr_columns
;
11254 htab
->nr_units
= nr_units
;
11255 htab
->nr_slots
= nr_slots
;
11256 htab
->hash_table
= index_ptr
;
11257 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11259 /* Exit early if the table is empty. */
11260 if (nr_slots
== 0 || nr_units
== 0
11261 || (version
== 2 && nr_columns
== 0)
11262 || (version
== 5 && nr_columns
== 0))
11264 /* All must be zero. */
11265 if (nr_slots
!= 0 || nr_units
!= 0
11266 || (version
== 2 && nr_columns
!= 0)
11267 || (version
== 5 && nr_columns
!= 0))
11269 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11270 " all zero [in modules %s]"),
11278 htab
->section_pool
.v1
.indices
=
11279 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11280 /* It's harder to decide whether the section is too small in v1.
11281 V1 is deprecated anyway so we punt. */
11283 else if (version
== 2)
11285 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11286 int *ids
= htab
->section_pool
.v2
.section_ids
;
11287 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11288 /* Reverse map for error checking. */
11289 int ids_seen
[DW_SECT_MAX
+ 1];
11292 if (nr_columns
< 2)
11294 error (_("Dwarf Error: bad DWP hash table, too few columns"
11295 " in section table [in module %s]"),
11298 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11300 error (_("Dwarf Error: bad DWP hash table, too many columns"
11301 " in section table [in module %s]"),
11304 memset (ids
, 255, sizeof_ids
);
11305 memset (ids_seen
, 255, sizeof (ids_seen
));
11306 for (i
= 0; i
< nr_columns
; ++i
)
11308 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11310 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11312 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11313 " in section table [in module %s]"),
11314 id
, dwp_file
->name
);
11316 if (ids_seen
[id
] != -1)
11318 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11319 " id %d in section table [in module %s]"),
11320 id
, dwp_file
->name
);
11325 /* Must have exactly one info or types section. */
11326 if (((ids_seen
[DW_SECT_INFO
] != -1)
11327 + (ids_seen
[DW_SECT_TYPES
] != -1))
11330 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11331 " DWO info/types section [in module %s]"),
11334 /* Must have an abbrev section. */
11335 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11337 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11338 " section [in module %s]"),
11341 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11342 htab
->section_pool
.v2
.sizes
=
11343 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11344 * nr_units
* nr_columns
);
11345 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11346 * nr_units
* nr_columns
))
11349 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11350 " [in module %s]"),
11354 else /* version == 5 */
11356 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11357 int *ids
= htab
->section_pool
.v5
.section_ids
;
11358 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11359 /* Reverse map for error checking. */
11360 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11362 if (nr_columns
< 2)
11364 error (_("Dwarf Error: bad DWP hash table, too few columns"
11365 " in section table [in module %s]"),
11368 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11370 error (_("Dwarf Error: bad DWP hash table, too many columns"
11371 " in section table [in module %s]"),
11374 memset (ids
, 255, sizeof_ids
);
11375 memset (ids_seen
, 255, sizeof (ids_seen
));
11376 for (int i
= 0; i
< nr_columns
; ++i
)
11378 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11380 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11382 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11383 " in section table [in module %s]"),
11384 id
, dwp_file
->name
);
11386 if (ids_seen
[id
] != -1)
11388 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11389 " id %d in section table [in module %s]"),
11390 id
, dwp_file
->name
);
11395 /* Must have seen an info section. */
11396 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11398 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11399 " DWO info/types section [in module %s]"),
11402 /* Must have an abbrev section. */
11403 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11405 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11406 " section [in module %s]"),
11409 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11410 htab
->section_pool
.v5
.sizes
11411 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11412 * nr_units
* nr_columns
);
11413 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11414 * nr_units
* nr_columns
))
11417 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11418 " [in module %s]"),
11426 /* Update SECTIONS with the data from SECTP.
11428 This function is like the other "locate" section routines, but in
11429 this context the sections to read comes from the DWP V1 hash table,
11430 not the full ELF section table.
11432 The result is non-zero for success, or zero if an error was found. */
11435 locate_v1_virtual_dwo_sections (asection
*sectp
,
11436 struct virtual_v1_dwo_sections
*sections
)
11438 const struct dwop_section_names
*names
= &dwop_section_names
;
11440 if (names
->abbrev_dwo
.matches (sectp
->name
))
11442 /* There can be only one. */
11443 if (sections
->abbrev
.s
.section
!= NULL
)
11445 sections
->abbrev
.s
.section
= sectp
;
11446 sections
->abbrev
.size
= bfd_section_size (sectp
);
11448 else if (names
->info_dwo
.matches (sectp
->name
)
11449 || names
->types_dwo
.matches (sectp
->name
))
11451 /* There can be only one. */
11452 if (sections
->info_or_types
.s
.section
!= NULL
)
11454 sections
->info_or_types
.s
.section
= sectp
;
11455 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11457 else if (names
->line_dwo
.matches (sectp
->name
))
11459 /* There can be only one. */
11460 if (sections
->line
.s
.section
!= NULL
)
11462 sections
->line
.s
.section
= sectp
;
11463 sections
->line
.size
= bfd_section_size (sectp
);
11465 else if (names
->loc_dwo
.matches (sectp
->name
))
11467 /* There can be only one. */
11468 if (sections
->loc
.s
.section
!= NULL
)
11470 sections
->loc
.s
.section
= sectp
;
11471 sections
->loc
.size
= bfd_section_size (sectp
);
11473 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11475 /* There can be only one. */
11476 if (sections
->macinfo
.s
.section
!= NULL
)
11478 sections
->macinfo
.s
.section
= sectp
;
11479 sections
->macinfo
.size
= bfd_section_size (sectp
);
11481 else if (names
->macro_dwo
.matches (sectp
->name
))
11483 /* There can be only one. */
11484 if (sections
->macro
.s
.section
!= NULL
)
11486 sections
->macro
.s
.section
= sectp
;
11487 sections
->macro
.size
= bfd_section_size (sectp
);
11489 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11491 /* There can be only one. */
11492 if (sections
->str_offsets
.s
.section
!= NULL
)
11494 sections
->str_offsets
.s
.section
= sectp
;
11495 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11499 /* No other kind of section is valid. */
11506 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11507 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11508 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11509 This is for DWP version 1 files. */
11511 static struct dwo_unit
*
11512 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11513 struct dwp_file
*dwp_file
,
11514 uint32_t unit_index
,
11515 const char *comp_dir
,
11516 ULONGEST signature
, int is_debug_types
)
11518 const struct dwp_hash_table
*dwp_htab
=
11519 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11520 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11521 const char *kind
= is_debug_types
? "TU" : "CU";
11522 struct dwo_file
*dwo_file
;
11523 struct dwo_unit
*dwo_unit
;
11524 struct virtual_v1_dwo_sections sections
;
11525 void **dwo_file_slot
;
11528 gdb_assert (dwp_file
->version
== 1);
11530 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11531 kind
, pulongest (unit_index
), hex_string (signature
),
11534 /* Fetch the sections of this DWO unit.
11535 Put a limit on the number of sections we look for so that bad data
11536 doesn't cause us to loop forever. */
11538 #define MAX_NR_V1_DWO_SECTIONS \
11539 (1 /* .debug_info or .debug_types */ \
11540 + 1 /* .debug_abbrev */ \
11541 + 1 /* .debug_line */ \
11542 + 1 /* .debug_loc */ \
11543 + 1 /* .debug_str_offsets */ \
11544 + 1 /* .debug_macro or .debug_macinfo */ \
11545 + 1 /* trailing zero */)
11547 memset (§ions
, 0, sizeof (sections
));
11549 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11552 uint32_t section_nr
=
11553 read_4_bytes (dbfd
,
11554 dwp_htab
->section_pool
.v1
.indices
11555 + (unit_index
+ i
) * sizeof (uint32_t));
11557 if (section_nr
== 0)
11559 if (section_nr
>= dwp_file
->num_sections
)
11561 error (_("Dwarf Error: bad DWP hash table, section number too large"
11562 " [in module %s]"),
11566 sectp
= dwp_file
->elf_sections
[section_nr
];
11567 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11569 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11570 " [in module %s]"),
11576 || sections
.info_or_types
.empty ()
11577 || sections
.abbrev
.empty ())
11579 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11580 " [in module %s]"),
11583 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11585 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11586 " [in module %s]"),
11590 /* It's easier for the rest of the code if we fake a struct dwo_file and
11591 have dwo_unit "live" in that. At least for now.
11593 The DWP file can be made up of a random collection of CUs and TUs.
11594 However, for each CU + set of TUs that came from the same original DWO
11595 file, we can combine them back into a virtual DWO file to save space
11596 (fewer struct dwo_file objects to allocate). Remember that for really
11597 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11599 std::string virtual_dwo_name
=
11600 string_printf ("virtual-dwo/%d-%d-%d-%d",
11601 sections
.abbrev
.get_id (),
11602 sections
.line
.get_id (),
11603 sections
.loc
.get_id (),
11604 sections
.str_offsets
.get_id ());
11605 /* Can we use an existing virtual DWO file? */
11606 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11608 /* Create one if necessary. */
11609 if (*dwo_file_slot
== NULL
)
11611 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11612 virtual_dwo_name
.c_str ());
11614 dwo_file
= new struct dwo_file
;
11615 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11616 dwo_file
->comp_dir
= comp_dir
;
11617 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11618 dwo_file
->sections
.line
= sections
.line
;
11619 dwo_file
->sections
.loc
= sections
.loc
;
11620 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11621 dwo_file
->sections
.macro
= sections
.macro
;
11622 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11623 /* The "str" section is global to the entire DWP file. */
11624 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11625 /* The info or types section is assigned below to dwo_unit,
11626 there's no need to record it in dwo_file.
11627 Also, we can't simply record type sections in dwo_file because
11628 we record a pointer into the vector in dwo_unit. As we collect more
11629 types we'll grow the vector and eventually have to reallocate space
11630 for it, invalidating all copies of pointers into the previous
11632 *dwo_file_slot
= dwo_file
;
11636 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11637 virtual_dwo_name
.c_str ());
11639 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11642 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11643 dwo_unit
->dwo_file
= dwo_file
;
11644 dwo_unit
->signature
= signature
;
11645 dwo_unit
->section
=
11646 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11647 *dwo_unit
->section
= sections
.info_or_types
;
11648 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11653 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11654 simplify them. Given a pointer to the containing section SECTION, and
11655 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11656 virtual section of just that piece. */
11658 static struct dwarf2_section_info
11659 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11660 struct dwarf2_section_info
*section
,
11661 bfd_size_type offset
, bfd_size_type size
)
11663 struct dwarf2_section_info result
;
11666 gdb_assert (section
!= NULL
);
11667 gdb_assert (!section
->is_virtual
);
11669 memset (&result
, 0, sizeof (result
));
11670 result
.s
.containing_section
= section
;
11671 result
.is_virtual
= true;
11676 sectp
= section
->get_bfd_section ();
11678 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11679 bounds of the real section. This is a pretty-rare event, so just
11680 flag an error (easier) instead of a warning and trying to cope. */
11682 || offset
+ size
> bfd_section_size (sectp
))
11684 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11685 " in section %s [in module %s]"),
11686 sectp
? bfd_section_name (sectp
) : "<unknown>",
11687 objfile_name (per_objfile
->objfile
));
11690 result
.virtual_offset
= offset
;
11691 result
.size
= size
;
11695 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11696 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11697 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11698 This is for DWP version 2 files. */
11700 static struct dwo_unit
*
11701 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11702 struct dwp_file
*dwp_file
,
11703 uint32_t unit_index
,
11704 const char *comp_dir
,
11705 ULONGEST signature
, int is_debug_types
)
11707 const struct dwp_hash_table
*dwp_htab
=
11708 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11709 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11710 const char *kind
= is_debug_types
? "TU" : "CU";
11711 struct dwo_file
*dwo_file
;
11712 struct dwo_unit
*dwo_unit
;
11713 struct virtual_v2_or_v5_dwo_sections sections
;
11714 void **dwo_file_slot
;
11717 gdb_assert (dwp_file
->version
== 2);
11719 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11720 kind
, pulongest (unit_index
), hex_string (signature
),
11723 /* Fetch the section offsets of this DWO unit. */
11725 memset (§ions
, 0, sizeof (sections
));
11727 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11729 uint32_t offset
= read_4_bytes (dbfd
,
11730 dwp_htab
->section_pool
.v2
.offsets
11731 + (((unit_index
- 1) * dwp_htab
->nr_columns
11733 * sizeof (uint32_t)));
11734 uint32_t size
= read_4_bytes (dbfd
,
11735 dwp_htab
->section_pool
.v2
.sizes
11736 + (((unit_index
- 1) * dwp_htab
->nr_columns
11738 * sizeof (uint32_t)));
11740 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11743 case DW_SECT_TYPES
:
11744 sections
.info_or_types_offset
= offset
;
11745 sections
.info_or_types_size
= size
;
11747 case DW_SECT_ABBREV
:
11748 sections
.abbrev_offset
= offset
;
11749 sections
.abbrev_size
= size
;
11752 sections
.line_offset
= offset
;
11753 sections
.line_size
= size
;
11756 sections
.loc_offset
= offset
;
11757 sections
.loc_size
= size
;
11759 case DW_SECT_STR_OFFSETS
:
11760 sections
.str_offsets_offset
= offset
;
11761 sections
.str_offsets_size
= size
;
11763 case DW_SECT_MACINFO
:
11764 sections
.macinfo_offset
= offset
;
11765 sections
.macinfo_size
= size
;
11767 case DW_SECT_MACRO
:
11768 sections
.macro_offset
= offset
;
11769 sections
.macro_size
= size
;
11774 /* It's easier for the rest of the code if we fake a struct dwo_file and
11775 have dwo_unit "live" in that. At least for now.
11777 The DWP file can be made up of a random collection of CUs and TUs.
11778 However, for each CU + set of TUs that came from the same original DWO
11779 file, we can combine them back into a virtual DWO file to save space
11780 (fewer struct dwo_file objects to allocate). Remember that for really
11781 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11783 std::string virtual_dwo_name
=
11784 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11785 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11786 (long) (sections
.line_size
? sections
.line_offset
: 0),
11787 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11788 (long) (sections
.str_offsets_size
11789 ? sections
.str_offsets_offset
: 0));
11790 /* Can we use an existing virtual DWO file? */
11791 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11793 /* Create one if necessary. */
11794 if (*dwo_file_slot
== NULL
)
11796 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11797 virtual_dwo_name
.c_str ());
11799 dwo_file
= new struct dwo_file
;
11800 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11801 dwo_file
->comp_dir
= comp_dir
;
11802 dwo_file
->sections
.abbrev
=
11803 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11804 sections
.abbrev_offset
,
11805 sections
.abbrev_size
);
11806 dwo_file
->sections
.line
=
11807 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11808 sections
.line_offset
,
11809 sections
.line_size
);
11810 dwo_file
->sections
.loc
=
11811 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11812 sections
.loc_offset
, sections
.loc_size
);
11813 dwo_file
->sections
.macinfo
=
11814 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11815 sections
.macinfo_offset
,
11816 sections
.macinfo_size
);
11817 dwo_file
->sections
.macro
=
11818 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11819 sections
.macro_offset
,
11820 sections
.macro_size
);
11821 dwo_file
->sections
.str_offsets
=
11822 create_dwp_v2_or_v5_section (per_objfile
,
11823 &dwp_file
->sections
.str_offsets
,
11824 sections
.str_offsets_offset
,
11825 sections
.str_offsets_size
);
11826 /* The "str" section is global to the entire DWP file. */
11827 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11828 /* The info or types section is assigned below to dwo_unit,
11829 there's no need to record it in dwo_file.
11830 Also, we can't simply record type sections in dwo_file because
11831 we record a pointer into the vector in dwo_unit. As we collect more
11832 types we'll grow the vector and eventually have to reallocate space
11833 for it, invalidating all copies of pointers into the previous
11835 *dwo_file_slot
= dwo_file
;
11839 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11840 virtual_dwo_name
.c_str ());
11842 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11845 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11846 dwo_unit
->dwo_file
= dwo_file
;
11847 dwo_unit
->signature
= signature
;
11848 dwo_unit
->section
=
11849 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11850 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11853 ? &dwp_file
->sections
.types
11854 : &dwp_file
->sections
.info
,
11855 sections
.info_or_types_offset
,
11856 sections
.info_or_types_size
);
11857 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11862 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11863 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11864 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11865 This is for DWP version 5 files. */
11867 static struct dwo_unit
*
11868 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11869 struct dwp_file
*dwp_file
,
11870 uint32_t unit_index
,
11871 const char *comp_dir
,
11872 ULONGEST signature
, int is_debug_types
)
11874 const struct dwp_hash_table
*dwp_htab
11875 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11876 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11877 const char *kind
= is_debug_types
? "TU" : "CU";
11878 struct dwo_file
*dwo_file
;
11879 struct dwo_unit
*dwo_unit
;
11880 struct virtual_v2_or_v5_dwo_sections sections
{};
11881 void **dwo_file_slot
;
11883 gdb_assert (dwp_file
->version
== 5);
11885 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11886 kind
, pulongest (unit_index
), hex_string (signature
),
11889 /* Fetch the section offsets of this DWO unit. */
11891 /* memset (§ions, 0, sizeof (sections)); */
11893 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11895 uint32_t offset
= read_4_bytes (dbfd
,
11896 dwp_htab
->section_pool
.v5
.offsets
11897 + (((unit_index
- 1)
11898 * dwp_htab
->nr_columns
11900 * sizeof (uint32_t)));
11901 uint32_t size
= read_4_bytes (dbfd
,
11902 dwp_htab
->section_pool
.v5
.sizes
11903 + (((unit_index
- 1) * dwp_htab
->nr_columns
11905 * sizeof (uint32_t)));
11907 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11909 case DW_SECT_ABBREV_V5
:
11910 sections
.abbrev_offset
= offset
;
11911 sections
.abbrev_size
= size
;
11913 case DW_SECT_INFO_V5
:
11914 sections
.info_or_types_offset
= offset
;
11915 sections
.info_or_types_size
= size
;
11917 case DW_SECT_LINE_V5
:
11918 sections
.line_offset
= offset
;
11919 sections
.line_size
= size
;
11921 case DW_SECT_LOCLISTS_V5
:
11922 sections
.loclists_offset
= offset
;
11923 sections
.loclists_size
= size
;
11925 case DW_SECT_MACRO_V5
:
11926 sections
.macro_offset
= offset
;
11927 sections
.macro_size
= size
;
11929 case DW_SECT_RNGLISTS_V5
:
11930 sections
.rnglists_offset
= offset
;
11931 sections
.rnglists_size
= size
;
11933 case DW_SECT_STR_OFFSETS_V5
:
11934 sections
.str_offsets_offset
= offset
;
11935 sections
.str_offsets_size
= size
;
11937 case DW_SECT_RESERVED_V5
:
11943 /* It's easier for the rest of the code if we fake a struct dwo_file and
11944 have dwo_unit "live" in that. At least for now.
11946 The DWP file can be made up of a random collection of CUs and TUs.
11947 However, for each CU + set of TUs that came from the same original DWO
11948 file, we can combine them back into a virtual DWO file to save space
11949 (fewer struct dwo_file objects to allocate). Remember that for really
11950 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11952 std::string virtual_dwo_name
=
11953 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11954 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11955 (long) (sections
.line_size
? sections
.line_offset
: 0),
11956 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11957 (long) (sections
.str_offsets_size
11958 ? sections
.str_offsets_offset
: 0),
11959 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11960 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11961 /* Can we use an existing virtual DWO file? */
11962 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11963 virtual_dwo_name
.c_str (),
11965 /* Create one if necessary. */
11966 if (*dwo_file_slot
== NULL
)
11968 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11969 virtual_dwo_name
.c_str ());
11971 dwo_file
= new struct dwo_file
;
11972 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11973 dwo_file
->comp_dir
= comp_dir
;
11974 dwo_file
->sections
.abbrev
=
11975 create_dwp_v2_or_v5_section (per_objfile
,
11976 &dwp_file
->sections
.abbrev
,
11977 sections
.abbrev_offset
,
11978 sections
.abbrev_size
);
11979 dwo_file
->sections
.line
=
11980 create_dwp_v2_or_v5_section (per_objfile
,
11981 &dwp_file
->sections
.line
,
11982 sections
.line_offset
, sections
.line_size
);
11983 dwo_file
->sections
.macro
=
11984 create_dwp_v2_or_v5_section (per_objfile
,
11985 &dwp_file
->sections
.macro
,
11986 sections
.macro_offset
,
11987 sections
.macro_size
);
11988 dwo_file
->sections
.loclists
=
11989 create_dwp_v2_or_v5_section (per_objfile
,
11990 &dwp_file
->sections
.loclists
,
11991 sections
.loclists_offset
,
11992 sections
.loclists_size
);
11993 dwo_file
->sections
.rnglists
=
11994 create_dwp_v2_or_v5_section (per_objfile
,
11995 &dwp_file
->sections
.rnglists
,
11996 sections
.rnglists_offset
,
11997 sections
.rnglists_size
);
11998 dwo_file
->sections
.str_offsets
=
11999 create_dwp_v2_or_v5_section (per_objfile
,
12000 &dwp_file
->sections
.str_offsets
,
12001 sections
.str_offsets_offset
,
12002 sections
.str_offsets_size
);
12003 /* The "str" section is global to the entire DWP file. */
12004 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12005 /* The info or types section is assigned below to dwo_unit,
12006 there's no need to record it in dwo_file.
12007 Also, we can't simply record type sections in dwo_file because
12008 we record a pointer into the vector in dwo_unit. As we collect more
12009 types we'll grow the vector and eventually have to reallocate space
12010 for it, invalidating all copies of pointers into the previous
12012 *dwo_file_slot
= dwo_file
;
12016 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12017 virtual_dwo_name
.c_str ());
12019 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12022 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12023 dwo_unit
->dwo_file
= dwo_file
;
12024 dwo_unit
->signature
= signature
;
12026 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12027 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12028 &dwp_file
->sections
.info
,
12029 sections
.info_or_types_offset
,
12030 sections
.info_or_types_size
);
12031 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12036 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12037 Returns NULL if the signature isn't found. */
12039 static struct dwo_unit
*
12040 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12041 struct dwp_file
*dwp_file
, const char *comp_dir
,
12042 ULONGEST signature
, int is_debug_types
)
12044 const struct dwp_hash_table
*dwp_htab
=
12045 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12046 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12047 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12048 uint32_t hash
= signature
& mask
;
12049 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12052 struct dwo_unit find_dwo_cu
;
12054 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12055 find_dwo_cu
.signature
= signature
;
12056 slot
= htab_find_slot (is_debug_types
12057 ? dwp_file
->loaded_tus
.get ()
12058 : dwp_file
->loaded_cus
.get (),
12059 &find_dwo_cu
, INSERT
);
12062 return (struct dwo_unit
*) *slot
;
12064 /* Use a for loop so that we don't loop forever on bad debug info. */
12065 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12067 ULONGEST signature_in_table
;
12069 signature_in_table
=
12070 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12071 if (signature_in_table
== signature
)
12073 uint32_t unit_index
=
12074 read_4_bytes (dbfd
,
12075 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12077 if (dwp_file
->version
== 1)
12079 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12080 unit_index
, comp_dir
,
12081 signature
, is_debug_types
);
12083 else if (dwp_file
->version
== 2)
12085 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12086 unit_index
, comp_dir
,
12087 signature
, is_debug_types
);
12089 else /* version == 5 */
12091 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12092 unit_index
, comp_dir
,
12093 signature
, is_debug_types
);
12095 return (struct dwo_unit
*) *slot
;
12097 if (signature_in_table
== 0)
12099 hash
= (hash
+ hash2
) & mask
;
12102 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12103 " [in module %s]"),
12107 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12108 Open the file specified by FILE_NAME and hand it off to BFD for
12109 preliminary analysis. Return a newly initialized bfd *, which
12110 includes a canonicalized copy of FILE_NAME.
12111 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12112 SEARCH_CWD is true if the current directory is to be searched.
12113 It will be searched before debug-file-directory.
12114 If successful, the file is added to the bfd include table of the
12115 objfile's bfd (see gdb_bfd_record_inclusion).
12116 If unable to find/open the file, return NULL.
12117 NOTE: This function is derived from symfile_bfd_open. */
12119 static gdb_bfd_ref_ptr
12120 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12121 const char *file_name
, int is_dwp
, int search_cwd
)
12124 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12125 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12126 to debug_file_directory. */
12127 const char *search_path
;
12128 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12130 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12133 if (*debug_file_directory
!= '\0')
12135 search_path_holder
.reset (concat (".", dirname_separator_string
,
12136 debug_file_directory
,
12138 search_path
= search_path_holder
.get ();
12144 search_path
= debug_file_directory
;
12146 /* Add the path for the executable binary to the list of search paths. */
12147 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12148 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12149 dirname_separator_string
,
12150 search_path
, nullptr));
12151 search_path
= search_path_holder
.get ();
12153 openp_flags flags
= OPF_RETURN_REALPATH
;
12155 flags
|= OPF_SEARCH_IN_PATH
;
12157 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12158 desc
= openp (search_path
, flags
, file_name
,
12159 O_RDONLY
| O_BINARY
, &absolute_name
);
12163 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12165 if (sym_bfd
== NULL
)
12167 bfd_set_cacheable (sym_bfd
.get (), 1);
12169 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12172 /* Success. Record the bfd as having been included by the objfile's bfd.
12173 This is important because things like demangled_names_hash lives in the
12174 objfile's per_bfd space and may have references to things like symbol
12175 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12176 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12181 /* Try to open DWO file FILE_NAME.
12182 COMP_DIR is the DW_AT_comp_dir attribute.
12183 The result is the bfd handle of the file.
12184 If there is a problem finding or opening the file, return NULL.
12185 Upon success, the canonicalized path of the file is stored in the bfd,
12186 same as symfile_bfd_open. */
12188 static gdb_bfd_ref_ptr
12189 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12190 const char *file_name
, const char *comp_dir
)
12192 if (IS_ABSOLUTE_PATH (file_name
))
12193 return try_open_dwop_file (per_objfile
, file_name
,
12194 0 /*is_dwp*/, 0 /*search_cwd*/);
12196 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12198 if (comp_dir
!= NULL
)
12200 gdb::unique_xmalloc_ptr
<char> path_to_try
12201 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12203 /* NOTE: If comp_dir is a relative path, this will also try the
12204 search path, which seems useful. */
12205 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12207 1 /*search_cwd*/));
12212 /* That didn't work, try debug-file-directory, which, despite its name,
12213 is a list of paths. */
12215 if (*debug_file_directory
== '\0')
12218 return try_open_dwop_file (per_objfile
, file_name
,
12219 0 /*is_dwp*/, 1 /*search_cwd*/);
12222 /* This function is mapped across the sections and remembers the offset and
12223 size of each of the DWO debugging sections we are interested in. */
12226 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12227 dwo_sections
*dwo_sections
)
12229 const struct dwop_section_names
*names
= &dwop_section_names
;
12231 if (names
->abbrev_dwo
.matches (sectp
->name
))
12233 dwo_sections
->abbrev
.s
.section
= sectp
;
12234 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12236 else if (names
->info_dwo
.matches (sectp
->name
))
12238 dwo_sections
->info
.s
.section
= sectp
;
12239 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12241 else if (names
->line_dwo
.matches (sectp
->name
))
12243 dwo_sections
->line
.s
.section
= sectp
;
12244 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12246 else if (names
->loc_dwo
.matches (sectp
->name
))
12248 dwo_sections
->loc
.s
.section
= sectp
;
12249 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12251 else if (names
->loclists_dwo
.matches (sectp
->name
))
12253 dwo_sections
->loclists
.s
.section
= sectp
;
12254 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12256 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12258 dwo_sections
->macinfo
.s
.section
= sectp
;
12259 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12261 else if (names
->macro_dwo
.matches (sectp
->name
))
12263 dwo_sections
->macro
.s
.section
= sectp
;
12264 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12266 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12268 dwo_sections
->rnglists
.s
.section
= sectp
;
12269 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12271 else if (names
->str_dwo
.matches (sectp
->name
))
12273 dwo_sections
->str
.s
.section
= sectp
;
12274 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12276 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12278 dwo_sections
->str_offsets
.s
.section
= sectp
;
12279 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12281 else if (names
->types_dwo
.matches (sectp
->name
))
12283 struct dwarf2_section_info type_section
;
12285 memset (&type_section
, 0, sizeof (type_section
));
12286 type_section
.s
.section
= sectp
;
12287 type_section
.size
= bfd_section_size (sectp
);
12288 dwo_sections
->types
.push_back (type_section
);
12292 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12293 by PER_CU. This is for the non-DWP case.
12294 The result is NULL if DWO_NAME can't be found. */
12296 static struct dwo_file
*
12297 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12298 const char *comp_dir
)
12300 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12302 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12305 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12310 dwo_file_up
dwo_file (new struct dwo_file
);
12311 dwo_file
->dwo_name
= dwo_name
;
12312 dwo_file
->comp_dir
= comp_dir
;
12313 dwo_file
->dbfd
= std::move (dbfd
);
12315 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12316 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12317 &dwo_file
->sections
);
12319 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12322 if (cu
->per_cu
->dwarf_version
< 5)
12324 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12325 dwo_file
->sections
.types
, dwo_file
->tus
);
12329 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12330 &dwo_file
->sections
.info
, dwo_file
->tus
,
12331 rcuh_kind::COMPILE
);
12334 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12336 return dwo_file
.release ();
12339 /* This function is mapped across the sections and remembers the offset and
12340 size of each of the DWP debugging sections common to version 1 and 2 that
12341 we are interested in. */
12344 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12345 dwp_file
*dwp_file
)
12347 const struct dwop_section_names
*names
= &dwop_section_names
;
12348 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12350 /* Record the ELF section number for later lookup: this is what the
12351 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12352 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12353 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12355 /* Look for specific sections that we need. */
12356 if (names
->str_dwo
.matches (sectp
->name
))
12358 dwp_file
->sections
.str
.s
.section
= sectp
;
12359 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12361 else if (names
->cu_index
.matches (sectp
->name
))
12363 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12364 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12366 else if (names
->tu_index
.matches (sectp
->name
))
12368 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12369 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12373 /* This function is mapped across the sections and remembers the offset and
12374 size of each of the DWP version 2 debugging sections that we are interested
12375 in. This is split into a separate function because we don't know if we
12376 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12379 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12381 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12382 const struct dwop_section_names
*names
= &dwop_section_names
;
12383 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12385 /* Record the ELF section number for later lookup: this is what the
12386 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12387 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12388 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12390 /* Look for specific sections that we need. */
12391 if (names
->abbrev_dwo
.matches (sectp
->name
))
12393 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12394 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12396 else if (names
->info_dwo
.matches (sectp
->name
))
12398 dwp_file
->sections
.info
.s
.section
= sectp
;
12399 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12401 else if (names
->line_dwo
.matches (sectp
->name
))
12403 dwp_file
->sections
.line
.s
.section
= sectp
;
12404 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12406 else if (names
->loc_dwo
.matches (sectp
->name
))
12408 dwp_file
->sections
.loc
.s
.section
= sectp
;
12409 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12411 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12413 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12414 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12416 else if (names
->macro_dwo
.matches (sectp
->name
))
12418 dwp_file
->sections
.macro
.s
.section
= sectp
;
12419 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12421 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12423 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12424 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12426 else if (names
->types_dwo
.matches (sectp
->name
))
12428 dwp_file
->sections
.types
.s
.section
= sectp
;
12429 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12433 /* This function is mapped across the sections and remembers the offset and
12434 size of each of the DWP version 5 debugging sections that we are interested
12435 in. This is split into a separate function because we don't know if we
12436 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12439 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12441 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12442 const struct dwop_section_names
*names
= &dwop_section_names
;
12443 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12445 /* Record the ELF section number for later lookup: this is what the
12446 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12447 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12448 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12450 /* Look for specific sections that we need. */
12451 if (names
->abbrev_dwo
.matches (sectp
->name
))
12453 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12454 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12456 else if (names
->info_dwo
.matches (sectp
->name
))
12458 dwp_file
->sections
.info
.s
.section
= sectp
;
12459 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12461 else if (names
->line_dwo
.matches (sectp
->name
))
12463 dwp_file
->sections
.line
.s
.section
= sectp
;
12464 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12466 else if (names
->loclists_dwo
.matches (sectp
->name
))
12468 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12469 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12471 else if (names
->macro_dwo
.matches (sectp
->name
))
12473 dwp_file
->sections
.macro
.s
.section
= sectp
;
12474 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12476 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12478 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12479 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12481 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12483 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12484 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12488 /* Hash function for dwp_file loaded CUs/TUs. */
12491 hash_dwp_loaded_cutus (const void *item
)
12493 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12495 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12496 return dwo_unit
->signature
;
12499 /* Equality function for dwp_file loaded CUs/TUs. */
12502 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12504 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12505 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12507 return dua
->signature
== dub
->signature
;
12510 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12513 allocate_dwp_loaded_cutus_table ()
12515 return htab_up (htab_create_alloc (3,
12516 hash_dwp_loaded_cutus
,
12517 eq_dwp_loaded_cutus
,
12518 NULL
, xcalloc
, xfree
));
12521 /* Try to open DWP file FILE_NAME.
12522 The result is the bfd handle of the file.
12523 If there is a problem finding or opening the file, return NULL.
12524 Upon success, the canonicalized path of the file is stored in the bfd,
12525 same as symfile_bfd_open. */
12527 static gdb_bfd_ref_ptr
12528 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12530 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12532 1 /*search_cwd*/));
12536 /* Work around upstream bug 15652.
12537 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12538 [Whether that's a "bug" is debatable, but it is getting in our way.]
12539 We have no real idea where the dwp file is, because gdb's realpath-ing
12540 of the executable's path may have discarded the needed info.
12541 [IWBN if the dwp file name was recorded in the executable, akin to
12542 .gnu_debuglink, but that doesn't exist yet.]
12543 Strip the directory from FILE_NAME and search again. */
12544 if (*debug_file_directory
!= '\0')
12546 /* Don't implicitly search the current directory here.
12547 If the user wants to search "." to handle this case,
12548 it must be added to debug-file-directory. */
12549 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12557 /* Initialize the use of the DWP file for the current objfile.
12558 By convention the name of the DWP file is ${objfile}.dwp.
12559 The result is NULL if it can't be found. */
12561 static std::unique_ptr
<struct dwp_file
>
12562 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12564 struct objfile
*objfile
= per_objfile
->objfile
;
12566 /* Try to find first .dwp for the binary file before any symbolic links
12569 /* If the objfile is a debug file, find the name of the real binary
12570 file and get the name of dwp file from there. */
12571 std::string dwp_name
;
12572 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12574 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12575 const char *backlink_basename
= lbasename (backlink
->original_name
);
12577 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12580 dwp_name
= objfile
->original_name
;
12582 dwp_name
+= ".dwp";
12584 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12586 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12588 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12589 dwp_name
= objfile_name (objfile
);
12590 dwp_name
+= ".dwp";
12591 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12596 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12598 return std::unique_ptr
<dwp_file
> ();
12601 const char *name
= bfd_get_filename (dbfd
.get ());
12602 std::unique_ptr
<struct dwp_file
> dwp_file
12603 (new struct dwp_file (name
, std::move (dbfd
)));
12605 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12606 dwp_file
->elf_sections
=
12607 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12608 dwp_file
->num_sections
, asection
*);
12610 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12611 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12614 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12616 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12618 /* The DWP file version is stored in the hash table. Oh well. */
12619 if (dwp_file
->cus
&& dwp_file
->tus
12620 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12622 /* Technically speaking, we should try to limp along, but this is
12623 pretty bizarre. We use pulongest here because that's the established
12624 portability solution (e.g, we cannot use %u for uint32_t). */
12625 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12626 " TU version %s [in DWP file %s]"),
12627 pulongest (dwp_file
->cus
->version
),
12628 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12632 dwp_file
->version
= dwp_file
->cus
->version
;
12633 else if (dwp_file
->tus
)
12634 dwp_file
->version
= dwp_file
->tus
->version
;
12636 dwp_file
->version
= 2;
12638 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12640 if (dwp_file
->version
== 2)
12641 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12644 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12648 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12649 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12651 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12652 dwarf_read_debug_printf (" %s CUs, %s TUs",
12653 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12654 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12659 /* Wrapper around open_and_init_dwp_file, only open it once. */
12661 static struct dwp_file
*
12662 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12664 if (!per_objfile
->per_bfd
->dwp_checked
)
12666 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12667 per_objfile
->per_bfd
->dwp_checked
= 1;
12669 return per_objfile
->per_bfd
->dwp_file
.get ();
12672 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12673 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12674 or in the DWP file for the objfile, referenced by THIS_UNIT.
12675 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12676 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12678 This is called, for example, when wanting to read a variable with a
12679 complex location. Therefore we don't want to do file i/o for every call.
12680 Therefore we don't want to look for a DWO file on every call.
12681 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12682 then we check if we've already seen DWO_NAME, and only THEN do we check
12685 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12686 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12688 static struct dwo_unit
*
12689 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12690 ULONGEST signature
, int is_debug_types
)
12692 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12693 struct objfile
*objfile
= per_objfile
->objfile
;
12694 const char *kind
= is_debug_types
? "TU" : "CU";
12695 void **dwo_file_slot
;
12696 struct dwo_file
*dwo_file
;
12697 struct dwp_file
*dwp_file
;
12699 /* First see if there's a DWP file.
12700 If we have a DWP file but didn't find the DWO inside it, don't
12701 look for the original DWO file. It makes gdb behave differently
12702 depending on whether one is debugging in the build tree. */
12704 dwp_file
= get_dwp_file (per_objfile
);
12705 if (dwp_file
!= NULL
)
12707 const struct dwp_hash_table
*dwp_htab
=
12708 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12710 if (dwp_htab
!= NULL
)
12712 struct dwo_unit
*dwo_cutu
=
12713 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12716 if (dwo_cutu
!= NULL
)
12718 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12719 kind
, hex_string (signature
),
12720 host_address_to_string (dwo_cutu
));
12728 /* No DWP file, look for the DWO file. */
12730 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12731 if (*dwo_file_slot
== NULL
)
12733 /* Read in the file and build a table of the CUs/TUs it contains. */
12734 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12736 /* NOTE: This will be NULL if unable to open the file. */
12737 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12739 if (dwo_file
!= NULL
)
12741 struct dwo_unit
*dwo_cutu
= NULL
;
12743 if (is_debug_types
&& dwo_file
->tus
)
12745 struct dwo_unit find_dwo_cutu
;
12747 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12748 find_dwo_cutu
.signature
= signature
;
12750 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12753 else if (!is_debug_types
&& dwo_file
->cus
)
12755 struct dwo_unit find_dwo_cutu
;
12757 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12758 find_dwo_cutu
.signature
= signature
;
12759 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12763 if (dwo_cutu
!= NULL
)
12765 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12766 kind
, dwo_name
, hex_string (signature
),
12767 host_address_to_string (dwo_cutu
));
12774 /* We didn't find it. This could mean a dwo_id mismatch, or
12775 someone deleted the DWO/DWP file, or the search path isn't set up
12776 correctly to find the file. */
12778 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12779 kind
, dwo_name
, hex_string (signature
));
12781 /* This is a warning and not a complaint because it can be caused by
12782 pilot error (e.g., user accidentally deleting the DWO). */
12784 /* Print the name of the DWP file if we looked there, helps the user
12785 better diagnose the problem. */
12786 std::string dwp_text
;
12788 if (dwp_file
!= NULL
)
12789 dwp_text
= string_printf (" [in DWP file %s]",
12790 lbasename (dwp_file
->name
));
12792 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12793 " [in module %s]"),
12794 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12795 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12800 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12801 See lookup_dwo_cutu_unit for details. */
12803 static struct dwo_unit
*
12804 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12805 ULONGEST signature
)
12807 gdb_assert (!cu
->per_cu
->is_debug_types
);
12809 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12812 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12813 See lookup_dwo_cutu_unit for details. */
12815 static struct dwo_unit
*
12816 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12818 gdb_assert (cu
->per_cu
->is_debug_types
);
12820 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12822 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12825 /* Traversal function for queue_and_load_all_dwo_tus. */
12828 queue_and_load_dwo_tu (void **slot
, void *info
)
12830 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12831 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12832 ULONGEST signature
= dwo_unit
->signature
;
12833 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12835 if (sig_type
!= NULL
)
12837 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12838 a real dependency of PER_CU on SIG_TYPE. That is detected later
12839 while processing PER_CU. */
12840 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12842 load_full_type_unit (sig_type
, cu
->per_objfile
);
12843 cu
->per_cu
->imported_symtabs_push (sig_type
);
12849 /* Queue all TUs contained in the DWO of CU to be read in.
12850 The DWO may have the only definition of the type, though it may not be
12851 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12852 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12855 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12857 struct dwo_unit
*dwo_unit
;
12858 struct dwo_file
*dwo_file
;
12860 gdb_assert (cu
!= nullptr);
12861 gdb_assert (!cu
->per_cu
->is_debug_types
);
12862 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12864 dwo_unit
= cu
->dwo_unit
;
12865 gdb_assert (dwo_unit
!= NULL
);
12867 dwo_file
= dwo_unit
->dwo_file
;
12868 if (dwo_file
->tus
!= NULL
)
12869 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12872 /* Read in various DIEs. */
12874 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12875 Inherit only the children of the DW_AT_abstract_origin DIE not being
12876 already referenced by DW_AT_abstract_origin from the children of the
12880 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12882 struct die_info
*child_die
;
12883 sect_offset
*offsetp
;
12884 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12885 struct die_info
*origin_die
;
12886 /* Iterator of the ORIGIN_DIE children. */
12887 struct die_info
*origin_child_die
;
12888 struct attribute
*attr
;
12889 struct dwarf2_cu
*origin_cu
;
12890 struct pending
**origin_previous_list_in_scope
;
12892 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12896 /* Note that following die references may follow to a die in a
12900 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12902 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12904 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12905 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12907 if (die
->tag
!= origin_die
->tag
12908 && !(die
->tag
== DW_TAG_inlined_subroutine
12909 && origin_die
->tag
== DW_TAG_subprogram
))
12910 complaint (_("DIE %s and its abstract origin %s have different tags"),
12911 sect_offset_str (die
->sect_off
),
12912 sect_offset_str (origin_die
->sect_off
));
12914 /* Find if the concrete and abstract trees are structurally the
12915 same. This is a shallow traversal and it is not bullet-proof;
12916 the compiler can trick the debugger into believing that the trees
12917 are isomorphic, whereas they actually are not. However, the
12918 likelyhood of this happening is pretty low, and a full-fledged
12919 check would be an overkill. */
12920 bool are_isomorphic
= true;
12921 die_info
*concrete_child
= die
->child
;
12922 die_info
*abstract_child
= origin_die
->child
;
12923 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12925 if (concrete_child
== nullptr
12926 || abstract_child
== nullptr
12927 || concrete_child
->tag
!= abstract_child
->tag
)
12929 are_isomorphic
= false;
12933 concrete_child
= concrete_child
->sibling
;
12934 abstract_child
= abstract_child
->sibling
;
12937 /* Walk the origin's children in parallel to the concrete children.
12938 This helps match an origin child in case the debug info misses
12939 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12940 origin tree may not have the same tree structure as the concrete
12942 die_info
*corresponding_abstract_child
12943 = are_isomorphic
? origin_die
->child
: nullptr;
12945 std::vector
<sect_offset
> offsets
;
12947 for (child_die
= die
->child
;
12948 child_die
&& child_die
->tag
;
12949 child_die
= child_die
->sibling
)
12951 struct die_info
*child_origin_die
;
12952 struct dwarf2_cu
*child_origin_cu
;
12954 /* We are trying to process concrete instance entries:
12955 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12956 it's not relevant to our analysis here. i.e. detecting DIEs that are
12957 present in the abstract instance but not referenced in the concrete
12959 if (child_die
->tag
== DW_TAG_call_site
12960 || child_die
->tag
== DW_TAG_GNU_call_site
)
12962 if (are_isomorphic
)
12963 corresponding_abstract_child
12964 = corresponding_abstract_child
->sibling
;
12968 /* For each CHILD_DIE, find the corresponding child of
12969 ORIGIN_DIE. If there is more than one layer of
12970 DW_AT_abstract_origin, follow them all; there shouldn't be,
12971 but GCC versions at least through 4.4 generate this (GCC PR
12973 child_origin_die
= child_die
;
12974 child_origin_cu
= cu
;
12977 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12981 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12985 /* If missing DW_AT_abstract_origin, try the corresponding child
12986 of the origin. Clang emits such lexical scopes. */
12987 if (child_origin_die
== child_die
12988 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12990 && child_die
->tag
== DW_TAG_lexical_block
)
12991 child_origin_die
= corresponding_abstract_child
;
12993 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12994 counterpart may exist. */
12995 if (child_origin_die
!= child_die
)
12997 if (child_die
->tag
!= child_origin_die
->tag
12998 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12999 && child_origin_die
->tag
== DW_TAG_subprogram
))
13000 complaint (_("Child DIE %s and its abstract origin %s have "
13002 sect_offset_str (child_die
->sect_off
),
13003 sect_offset_str (child_origin_die
->sect_off
));
13004 if (child_origin_die
->parent
!= origin_die
)
13005 complaint (_("Child DIE %s and its abstract origin %s have "
13006 "different parents"),
13007 sect_offset_str (child_die
->sect_off
),
13008 sect_offset_str (child_origin_die
->sect_off
));
13010 offsets
.push_back (child_origin_die
->sect_off
);
13013 if (are_isomorphic
)
13014 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
13016 std::sort (offsets
.begin (), offsets
.end ());
13017 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13018 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13019 if (offsetp
[-1] == *offsetp
)
13020 complaint (_("Multiple children of DIE %s refer "
13021 "to DIE %s as their abstract origin"),
13022 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13024 offsetp
= offsets
.data ();
13025 origin_child_die
= origin_die
->child
;
13026 while (origin_child_die
&& origin_child_die
->tag
)
13028 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13029 while (offsetp
< offsets_end
13030 && *offsetp
< origin_child_die
->sect_off
)
13032 if (offsetp
>= offsets_end
13033 || *offsetp
> origin_child_die
->sect_off
)
13035 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13036 Check whether we're already processing ORIGIN_CHILD_DIE.
13037 This can happen with mutually referenced abstract_origins.
13039 if (!origin_child_die
->in_process
)
13040 process_die (origin_child_die
, origin_cu
);
13042 origin_child_die
= origin_child_die
->sibling
;
13044 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13046 if (cu
!= origin_cu
)
13047 compute_delayed_physnames (origin_cu
);
13051 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13053 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13054 struct gdbarch
*gdbarch
= objfile
->arch ();
13055 struct context_stack
*newobj
;
13058 struct die_info
*child_die
;
13059 struct attribute
*attr
, *call_line
, *call_file
;
13061 CORE_ADDR baseaddr
;
13062 struct block
*block
;
13063 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13064 std::vector
<struct symbol
*> template_args
;
13065 struct template_symbol
*templ_func
= NULL
;
13069 /* If we do not have call site information, we can't show the
13070 caller of this inlined function. That's too confusing, so
13071 only use the scope for local variables. */
13072 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13073 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13074 if (call_line
== NULL
|| call_file
== NULL
)
13076 read_lexical_block_scope (die
, cu
);
13081 baseaddr
= objfile
->text_section_offset ();
13083 name
= dwarf2_name (die
, cu
);
13085 /* Ignore functions with missing or empty names. These are actually
13086 illegal according to the DWARF standard. */
13089 complaint (_("missing name for subprogram DIE at %s"),
13090 sect_offset_str (die
->sect_off
));
13094 /* Ignore functions with missing or invalid low and high pc attributes. */
13095 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13096 <= PC_BOUNDS_INVALID
)
13098 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13099 if (attr
== nullptr || !attr
->as_boolean ())
13100 complaint (_("cannot get low and high bounds "
13101 "for subprogram DIE at %s"),
13102 sect_offset_str (die
->sect_off
));
13106 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13107 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13109 /* If we have any template arguments, then we must allocate a
13110 different sort of symbol. */
13111 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13113 if (child_die
->tag
== DW_TAG_template_type_param
13114 || child_die
->tag
== DW_TAG_template_value_param
)
13116 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13117 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13122 gdb_assert (cu
->get_builder () != nullptr);
13123 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13124 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13125 (struct symbol
*) templ_func
);
13127 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13128 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13131 /* If there is a location expression for DW_AT_frame_base, record
13133 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13134 if (attr
!= nullptr)
13135 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13137 /* If there is a location for the static link, record it. */
13138 newobj
->static_link
= NULL
;
13139 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13140 if (attr
!= nullptr)
13142 newobj
->static_link
13143 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13144 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13148 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13150 if (die
->child
!= NULL
)
13152 child_die
= die
->child
;
13153 while (child_die
&& child_die
->tag
)
13155 if (child_die
->tag
== DW_TAG_template_type_param
13156 || child_die
->tag
== DW_TAG_template_value_param
)
13158 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13161 template_args
.push_back (arg
);
13164 process_die (child_die
, cu
);
13165 child_die
= child_die
->sibling
;
13169 inherit_abstract_dies (die
, cu
);
13171 /* If we have a DW_AT_specification, we might need to import using
13172 directives from the context of the specification DIE. See the
13173 comment in determine_prefix. */
13174 if (cu
->per_cu
->lang
== language_cplus
13175 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13177 struct dwarf2_cu
*spec_cu
= cu
;
13178 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13182 child_die
= spec_die
->child
;
13183 while (child_die
&& child_die
->tag
)
13185 if (child_die
->tag
== DW_TAG_imported_module
)
13186 process_die (child_die
, spec_cu
);
13187 child_die
= child_die
->sibling
;
13190 /* In some cases, GCC generates specification DIEs that
13191 themselves contain DW_AT_specification attributes. */
13192 spec_die
= die_specification (spec_die
, &spec_cu
);
13196 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13197 /* Make a block for the local symbols within. */
13198 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13199 cstk
.static_link
, lowpc
, highpc
);
13201 /* For C++, set the block's scope. */
13202 if ((cu
->per_cu
->lang
== language_cplus
13203 || cu
->per_cu
->lang
== language_fortran
13204 || cu
->per_cu
->lang
== language_d
13205 || cu
->per_cu
->lang
== language_rust
)
13206 && cu
->processing_has_namespace_info
)
13207 block_set_scope (block
, determine_prefix (die
, cu
),
13208 &objfile
->objfile_obstack
);
13210 /* If we have address ranges, record them. */
13211 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13213 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13215 /* Attach template arguments to function. */
13216 if (!template_args
.empty ())
13218 gdb_assert (templ_func
!= NULL
);
13220 templ_func
->n_template_arguments
= template_args
.size ();
13221 templ_func
->template_arguments
13222 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13223 templ_func
->n_template_arguments
);
13224 memcpy (templ_func
->template_arguments
,
13225 template_args
.data (),
13226 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13228 /* Make sure that the symtab is set on the new symbols. Even
13229 though they don't appear in this symtab directly, other parts
13230 of gdb assume that symbols do, and this is reasonably
13232 for (symbol
*sym
: template_args
)
13233 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13236 /* In C++, we can have functions nested inside functions (e.g., when
13237 a function declares a class that has methods). This means that
13238 when we finish processing a function scope, we may need to go
13239 back to building a containing block's symbol lists. */
13240 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13241 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13243 /* If we've finished processing a top-level function, subsequent
13244 symbols go in the file symbol list. */
13245 if (cu
->get_builder ()->outermost_context_p ())
13246 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13249 /* Process all the DIES contained within a lexical block scope. Start
13250 a new scope, process the dies, and then close the scope. */
13253 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13255 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13256 struct gdbarch
*gdbarch
= objfile
->arch ();
13257 CORE_ADDR lowpc
, highpc
;
13258 struct die_info
*child_die
;
13259 CORE_ADDR baseaddr
;
13261 baseaddr
= objfile
->text_section_offset ();
13263 /* Ignore blocks with missing or invalid low and high pc attributes. */
13264 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13265 as multiple lexical blocks? Handling children in a sane way would
13266 be nasty. Might be easier to properly extend generic blocks to
13267 describe ranges. */
13268 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13270 case PC_BOUNDS_NOT_PRESENT
:
13271 /* DW_TAG_lexical_block has no attributes, process its children as if
13272 there was no wrapping by that DW_TAG_lexical_block.
13273 GCC does no longer produces such DWARF since GCC r224161. */
13274 for (child_die
= die
->child
;
13275 child_die
!= NULL
&& child_die
->tag
;
13276 child_die
= child_die
->sibling
)
13278 /* We might already be processing this DIE. This can happen
13279 in an unusual circumstance -- where a subroutine A
13280 appears lexically in another subroutine B, but A actually
13281 inlines B. The recursion is broken here, rather than in
13282 inherit_abstract_dies, because it seems better to simply
13283 drop concrete children here. */
13284 if (!child_die
->in_process
)
13285 process_die (child_die
, cu
);
13288 case PC_BOUNDS_INVALID
:
13291 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13292 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13294 cu
->get_builder ()->push_context (0, lowpc
);
13295 if (die
->child
!= NULL
)
13297 child_die
= die
->child
;
13298 while (child_die
&& child_die
->tag
)
13300 process_die (child_die
, cu
);
13301 child_die
= child_die
->sibling
;
13304 inherit_abstract_dies (die
, cu
);
13305 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13307 if (*cu
->get_builder ()->get_local_symbols () != NULL
13308 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13310 struct block
*block
13311 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13312 cstk
.start_addr
, highpc
);
13314 /* Note that recording ranges after traversing children, as we
13315 do here, means that recording a parent's ranges entails
13316 walking across all its children's ranges as they appear in
13317 the address map, which is quadratic behavior.
13319 It would be nicer to record the parent's ranges before
13320 traversing its children, simply overriding whatever you find
13321 there. But since we don't even decide whether to create a
13322 block until after we've traversed its children, that's hard
13324 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13326 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13327 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13330 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13333 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13335 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13336 struct objfile
*objfile
= per_objfile
->objfile
;
13337 struct gdbarch
*gdbarch
= objfile
->arch ();
13338 CORE_ADDR pc
, baseaddr
;
13339 struct attribute
*attr
;
13340 struct call_site
*call_site
, call_site_local
;
13343 struct die_info
*child_die
;
13345 baseaddr
= objfile
->text_section_offset ();
13347 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13350 /* This was a pre-DWARF-5 GNU extension alias
13351 for DW_AT_call_return_pc. */
13352 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13356 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13357 "DIE %s [in module %s]"),
13358 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13361 pc
= attr
->as_address () + baseaddr
;
13362 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13364 if (cu
->call_site_htab
== NULL
)
13365 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13366 NULL
, &objfile
->objfile_obstack
,
13367 hashtab_obstack_allocate
, NULL
);
13368 call_site_local
.pc
= pc
;
13369 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13372 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13373 "DIE %s [in module %s]"),
13374 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13375 objfile_name (objfile
));
13379 /* Count parameters at the caller. */
13382 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13383 child_die
= child_die
->sibling
)
13385 if (child_die
->tag
!= DW_TAG_call_site_parameter
13386 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13388 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13389 "DW_TAG_call_site child DIE %s [in module %s]"),
13390 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13391 objfile_name (objfile
));
13399 = ((struct call_site
*)
13400 obstack_alloc (&objfile
->objfile_obstack
,
13401 sizeof (*call_site
)
13402 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13404 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13405 call_site
->pc
= pc
;
13407 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13408 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13410 struct die_info
*func_die
;
13412 /* Skip also over DW_TAG_inlined_subroutine. */
13413 for (func_die
= die
->parent
;
13414 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13415 && func_die
->tag
!= DW_TAG_subroutine_type
;
13416 func_die
= func_die
->parent
);
13418 /* DW_AT_call_all_calls is a superset
13419 of DW_AT_call_all_tail_calls. */
13421 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13422 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13423 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13424 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13426 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13427 not complete. But keep CALL_SITE for look ups via call_site_htab,
13428 both the initial caller containing the real return address PC and
13429 the final callee containing the current PC of a chain of tail
13430 calls do not need to have the tail call list complete. But any
13431 function candidate for a virtual tail call frame searched via
13432 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13433 determined unambiguously. */
13437 struct type
*func_type
= NULL
;
13440 func_type
= get_die_type (func_die
, cu
);
13441 if (func_type
!= NULL
)
13443 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13445 /* Enlist this call site to the function. */
13446 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13447 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13450 complaint (_("Cannot find function owning DW_TAG_call_site "
13451 "DIE %s [in module %s]"),
13452 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13456 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13458 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13460 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13463 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13464 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13466 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13467 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13468 /* Keep NULL DWARF_BLOCK. */;
13469 else if (attr
->form_is_block ())
13471 struct dwarf2_locexpr_baton
*dlbaton
;
13472 struct dwarf_block
*block
= attr
->as_block ();
13474 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13475 dlbaton
->data
= block
->data
;
13476 dlbaton
->size
= block
->size
;
13477 dlbaton
->per_objfile
= per_objfile
;
13478 dlbaton
->per_cu
= cu
->per_cu
;
13480 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13482 else if (attr
->form_is_ref ())
13484 struct dwarf2_cu
*target_cu
= cu
;
13485 struct die_info
*target_die
;
13487 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13488 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13489 if (die_is_declaration (target_die
, target_cu
))
13491 const char *target_physname
;
13493 /* Prefer the mangled name; otherwise compute the demangled one. */
13494 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13495 if (target_physname
== NULL
)
13496 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13497 if (target_physname
== NULL
)
13498 complaint (_("DW_AT_call_target target DIE has invalid "
13499 "physname, for referencing DIE %s [in module %s]"),
13500 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13502 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13508 /* DW_AT_entry_pc should be preferred. */
13509 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13510 <= PC_BOUNDS_INVALID
)
13511 complaint (_("DW_AT_call_target target DIE has invalid "
13512 "low pc, for referencing DIE %s [in module %s]"),
13513 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13516 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13517 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13522 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13523 "block nor reference, for DIE %s [in module %s]"),
13524 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13526 call_site
->per_cu
= cu
->per_cu
;
13527 call_site
->per_objfile
= per_objfile
;
13529 for (child_die
= die
->child
;
13530 child_die
&& child_die
->tag
;
13531 child_die
= child_die
->sibling
)
13533 struct call_site_parameter
*parameter
;
13534 struct attribute
*loc
, *origin
;
13536 if (child_die
->tag
!= DW_TAG_call_site_parameter
13537 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13539 /* Already printed the complaint above. */
13543 gdb_assert (call_site
->parameter_count
< nparams
);
13544 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13546 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13547 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13548 register is contained in DW_AT_call_value. */
13550 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13551 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13552 if (origin
== NULL
)
13554 /* This was a pre-DWARF-5 GNU extension alias
13555 for DW_AT_call_parameter. */
13556 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13558 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13560 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13562 sect_offset sect_off
= origin
->get_ref_die_offset ();
13563 if (!cu
->header
.offset_in_cu_p (sect_off
))
13565 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13566 binding can be done only inside one CU. Such referenced DIE
13567 therefore cannot be even moved to DW_TAG_partial_unit. */
13568 complaint (_("DW_AT_call_parameter offset is not in CU for "
13569 "DW_TAG_call_site child DIE %s [in module %s]"),
13570 sect_offset_str (child_die
->sect_off
),
13571 objfile_name (objfile
));
13574 parameter
->u
.param_cu_off
13575 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13577 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13579 complaint (_("No DW_FORM_block* DW_AT_location for "
13580 "DW_TAG_call_site child DIE %s [in module %s]"),
13581 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13586 struct dwarf_block
*block
= loc
->as_block ();
13588 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13589 (block
->data
, &block
->data
[block
->size
]);
13590 if (parameter
->u
.dwarf_reg
!= -1)
13591 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13592 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13593 &block
->data
[block
->size
],
13594 ¶meter
->u
.fb_offset
))
13595 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13598 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13599 "for DW_FORM_block* DW_AT_location is supported for "
13600 "DW_TAG_call_site child DIE %s "
13602 sect_offset_str (child_die
->sect_off
),
13603 objfile_name (objfile
));
13608 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13610 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13611 if (attr
== NULL
|| !attr
->form_is_block ())
13613 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13614 "DW_TAG_call_site child DIE %s [in module %s]"),
13615 sect_offset_str (child_die
->sect_off
),
13616 objfile_name (objfile
));
13620 struct dwarf_block
*block
= attr
->as_block ();
13621 parameter
->value
= block
->data
;
13622 parameter
->value_size
= block
->size
;
13624 /* Parameters are not pre-cleared by memset above. */
13625 parameter
->data_value
= NULL
;
13626 parameter
->data_value_size
= 0;
13627 call_site
->parameter_count
++;
13629 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13631 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13632 if (attr
!= nullptr)
13634 if (!attr
->form_is_block ())
13635 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13636 "DW_TAG_call_site child DIE %s [in module %s]"),
13637 sect_offset_str (child_die
->sect_off
),
13638 objfile_name (objfile
));
13641 block
= attr
->as_block ();
13642 parameter
->data_value
= block
->data
;
13643 parameter
->data_value_size
= block
->size
;
13649 /* Helper function for read_variable. If DIE represents a virtual
13650 table, then return the type of the concrete object that is
13651 associated with the virtual table. Otherwise, return NULL. */
13653 static struct type
*
13654 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13656 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13660 /* Find the type DIE. */
13661 struct die_info
*type_die
= NULL
;
13662 struct dwarf2_cu
*type_cu
= cu
;
13664 if (attr
->form_is_ref ())
13665 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13666 if (type_die
== NULL
)
13669 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13671 return die_containing_type (type_die
, type_cu
);
13674 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13677 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13679 struct rust_vtable_symbol
*storage
= NULL
;
13681 if (cu
->per_cu
->lang
== language_rust
)
13683 struct type
*containing_type
= rust_containing_type (die
, cu
);
13685 if (containing_type
!= NULL
)
13687 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13689 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13690 storage
->concrete_type
= containing_type
;
13691 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13695 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13696 struct attribute
*abstract_origin
13697 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13698 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13699 if (res
== NULL
&& loc
&& abstract_origin
)
13701 /* We have a variable without a name, but with a location and an abstract
13702 origin. This may be a concrete instance of an abstract variable
13703 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13705 struct dwarf2_cu
*origin_cu
= cu
;
13706 struct die_info
*origin_die
13707 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13708 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13709 per_objfile
->per_bfd
->abstract_to_concrete
13710 [origin_die
->sect_off
].push_back (die
->sect_off
);
13714 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13715 reading .debug_rnglists.
13716 Callback's type should be:
13717 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13718 Return true if the attributes are present and valid, otherwise,
13721 template <typename Callback
>
13723 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13724 dwarf_tag tag
, Callback
&&callback
)
13726 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13727 struct objfile
*objfile
= per_objfile
->objfile
;
13728 bfd
*obfd
= objfile
->obfd
;
13729 /* Base address selection entry. */
13730 gdb::optional
<CORE_ADDR
> base
;
13731 const gdb_byte
*buffer
;
13732 bool overflow
= false;
13733 ULONGEST addr_index
;
13734 struct dwarf2_section_info
*rnglists_section
;
13736 base
= cu
->base_address
;
13737 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13738 rnglists_section
->read (objfile
);
13740 if (offset
>= rnglists_section
->size
)
13742 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13746 buffer
= rnglists_section
->buffer
+ offset
;
13750 /* Initialize it due to a false compiler warning. */
13751 CORE_ADDR range_beginning
= 0, range_end
= 0;
13752 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13753 + rnglists_section
->size
);
13754 unsigned int bytes_read
;
13756 if (buffer
== buf_end
)
13761 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13764 case DW_RLE_end_of_list
:
13766 case DW_RLE_base_address
:
13767 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13772 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13773 buffer
+= bytes_read
;
13775 case DW_RLE_base_addressx
:
13776 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13777 buffer
+= bytes_read
;
13778 base
= read_addr_index (cu
, addr_index
);
13780 case DW_RLE_start_length
:
13781 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13786 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13788 buffer
+= bytes_read
;
13789 range_end
= (range_beginning
13790 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13791 buffer
+= bytes_read
;
13792 if (buffer
> buf_end
)
13798 case DW_RLE_startx_length
:
13799 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13800 buffer
+= bytes_read
;
13801 range_beginning
= read_addr_index (cu
, addr_index
);
13802 if (buffer
> buf_end
)
13807 range_end
= (range_beginning
13808 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13809 buffer
+= bytes_read
;
13811 case DW_RLE_offset_pair
:
13812 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13813 buffer
+= bytes_read
;
13814 if (buffer
> buf_end
)
13819 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13820 buffer
+= bytes_read
;
13821 if (buffer
> buf_end
)
13827 case DW_RLE_start_end
:
13828 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13833 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13835 buffer
+= bytes_read
;
13836 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13837 buffer
+= bytes_read
;
13839 case DW_RLE_startx_endx
:
13840 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13841 buffer
+= bytes_read
;
13842 range_beginning
= read_addr_index (cu
, addr_index
);
13843 if (buffer
> buf_end
)
13848 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13849 buffer
+= bytes_read
;
13850 range_end
= read_addr_index (cu
, addr_index
);
13853 complaint (_("Invalid .debug_rnglists data (no base address)"));
13856 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13858 if (rlet
== DW_RLE_base_address
)
13861 if (range_beginning
> range_end
)
13863 /* Inverted range entries are invalid. */
13864 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13868 /* Empty range entries have no effect. */
13869 if (range_beginning
== range_end
)
13872 /* Only DW_RLE_offset_pair needs the base address added. */
13873 if (rlet
== DW_RLE_offset_pair
)
13875 if (!base
.has_value ())
13877 /* We have no valid base address for the DW_RLE_offset_pair. */
13878 complaint (_("Invalid .debug_rnglists data (no base address for "
13879 "DW_RLE_offset_pair)"));
13883 range_beginning
+= *base
;
13884 range_end
+= *base
;
13887 /* A not-uncommon case of bad debug info.
13888 Don't pollute the addrmap with bad data. */
13889 if (range_beginning
== 0
13890 && !per_objfile
->per_bfd
->has_section_at_zero
)
13892 complaint (_(".debug_rnglists entry has start address of zero"
13893 " [in module %s]"), objfile_name (objfile
));
13897 callback (range_beginning
, range_end
);
13902 complaint (_("Offset %d is not terminated "
13903 "for DW_AT_ranges attribute"),
13911 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13912 Callback's type should be:
13913 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13914 Return 1 if the attributes are present and valid, otherwise, return 0. */
13916 template <typename Callback
>
13918 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13919 Callback
&&callback
)
13921 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13922 struct objfile
*objfile
= per_objfile
->objfile
;
13923 struct comp_unit_head
*cu_header
= &cu
->header
;
13924 bfd
*obfd
= objfile
->obfd
;
13925 unsigned int addr_size
= cu_header
->addr_size
;
13926 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13927 /* Base address selection entry. */
13928 gdb::optional
<CORE_ADDR
> base
;
13929 unsigned int dummy
;
13930 const gdb_byte
*buffer
;
13932 if (cu_header
->version
>= 5)
13933 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13935 base
= cu
->base_address
;
13937 per_objfile
->per_bfd
->ranges
.read (objfile
);
13938 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13940 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13944 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13948 CORE_ADDR range_beginning
, range_end
;
13950 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13951 buffer
+= addr_size
;
13952 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13953 buffer
+= addr_size
;
13954 offset
+= 2 * addr_size
;
13956 /* An end of list marker is a pair of zero addresses. */
13957 if (range_beginning
== 0 && range_end
== 0)
13958 /* Found the end of list entry. */
13961 /* Each base address selection entry is a pair of 2 values.
13962 The first is the largest possible address, the second is
13963 the base address. Check for a base address here. */
13964 if ((range_beginning
& mask
) == mask
)
13966 /* If we found the largest possible address, then we already
13967 have the base address in range_end. */
13972 if (!base
.has_value ())
13974 /* We have no valid base address for the ranges
13976 complaint (_("Invalid .debug_ranges data (no base address)"));
13980 if (range_beginning
> range_end
)
13982 /* Inverted range entries are invalid. */
13983 complaint (_("Invalid .debug_ranges data (inverted range)"));
13987 /* Empty range entries have no effect. */
13988 if (range_beginning
== range_end
)
13991 range_beginning
+= *base
;
13992 range_end
+= *base
;
13994 /* A not-uncommon case of bad debug info.
13995 Don't pollute the addrmap with bad data. */
13996 if (range_beginning
== 0
13997 && !per_objfile
->per_bfd
->has_section_at_zero
)
13999 complaint (_(".debug_ranges entry has start address of zero"
14000 " [in module %s]"), objfile_name (objfile
));
14004 callback (range_beginning
, range_end
);
14010 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14011 Return 1 if the attributes are present and valid, otherwise, return 0.
14012 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
14015 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14016 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14017 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14019 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14020 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
14021 struct gdbarch
*gdbarch
= objfile
->arch ();
14022 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14025 CORE_ADDR high
= 0;
14028 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14029 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14031 if (ranges_pst
!= NULL
)
14036 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14037 range_beginning
+ baseaddr
)
14039 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14040 range_end
+ baseaddr
)
14042 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
14043 lowpc
, highpc
- 1, ranges_pst
);
14046 /* FIXME: This is recording everything as a low-high
14047 segment of consecutive addresses. We should have a
14048 data structure for discontiguous block ranges
14052 low
= range_beginning
;
14058 if (range_beginning
< low
)
14059 low
= range_beginning
;
14060 if (range_end
> high
)
14068 /* If the first entry is an end-of-list marker, the range
14069 describes an empty scope, i.e. no instructions. */
14075 *high_return
= high
;
14079 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14080 definition for the return value. *LOWPC and *HIGHPC are set iff
14081 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14083 static enum pc_bounds_kind
14084 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14085 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14086 dwarf2_psymtab
*pst
)
14088 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14089 struct attribute
*attr
;
14090 struct attribute
*attr_high
;
14092 CORE_ADDR high
= 0;
14093 enum pc_bounds_kind ret
;
14095 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14098 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14099 if (attr
!= nullptr)
14101 low
= attr
->as_address ();
14102 high
= attr_high
->as_address ();
14103 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14107 /* Found high w/o low attribute. */
14108 return PC_BOUNDS_INVALID
;
14110 /* Found consecutive range of addresses. */
14111 ret
= PC_BOUNDS_HIGH_LOW
;
14115 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14116 if (attr
!= nullptr && attr
->form_is_unsigned ())
14118 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14119 on DWARF version). */
14120 ULONGEST ranges_offset
= attr
->as_unsigned ();
14122 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14124 if (die
->tag
!= DW_TAG_compile_unit
)
14125 ranges_offset
+= cu
->gnu_ranges_base
;
14127 /* Value of the DW_AT_ranges attribute is the offset in the
14128 .debug_ranges section. */
14129 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14131 return PC_BOUNDS_INVALID
;
14132 /* Found discontinuous range of addresses. */
14133 ret
= PC_BOUNDS_RANGES
;
14136 return PC_BOUNDS_NOT_PRESENT
;
14139 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14141 return PC_BOUNDS_INVALID
;
14143 /* When using the GNU linker, .gnu.linkonce. sections are used to
14144 eliminate duplicate copies of functions and vtables and such.
14145 The linker will arbitrarily choose one and discard the others.
14146 The AT_*_pc values for such functions refer to local labels in
14147 these sections. If the section from that file was discarded, the
14148 labels are not in the output, so the relocs get a value of 0.
14149 If this is a discarded function, mark the pc bounds as invalid,
14150 so that GDB will ignore it. */
14151 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14152 return PC_BOUNDS_INVALID
;
14160 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14161 its low and high PC addresses. Do nothing if these addresses could not
14162 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14163 and HIGHPC to the high address if greater than HIGHPC. */
14166 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14167 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14168 struct dwarf2_cu
*cu
)
14170 CORE_ADDR low
, high
;
14171 struct die_info
*child
= die
->child
;
14173 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14175 *lowpc
= std::min (*lowpc
, low
);
14176 *highpc
= std::max (*highpc
, high
);
14179 /* If the language does not allow nested subprograms (either inside
14180 subprograms or lexical blocks), we're done. */
14181 if (cu
->per_cu
->lang
!= language_ada
)
14184 /* Check all the children of the given DIE. If it contains nested
14185 subprograms, then check their pc bounds. Likewise, we need to
14186 check lexical blocks as well, as they may also contain subprogram
14188 while (child
&& child
->tag
)
14190 if (child
->tag
== DW_TAG_subprogram
14191 || child
->tag
== DW_TAG_lexical_block
)
14192 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14193 child
= child
->sibling
;
14197 /* Get the low and high pc's represented by the scope DIE, and store
14198 them in *LOWPC and *HIGHPC. If the correct values can't be
14199 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14202 get_scope_pc_bounds (struct die_info
*die
,
14203 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14204 struct dwarf2_cu
*cu
)
14206 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14207 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14208 CORE_ADDR current_low
, current_high
;
14210 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14211 >= PC_BOUNDS_RANGES
)
14213 best_low
= current_low
;
14214 best_high
= current_high
;
14218 struct die_info
*child
= die
->child
;
14220 while (child
&& child
->tag
)
14222 switch (child
->tag
) {
14223 case DW_TAG_subprogram
:
14224 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14226 case DW_TAG_namespace
:
14227 case DW_TAG_module
:
14228 /* FIXME: carlton/2004-01-16: Should we do this for
14229 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14230 that current GCC's always emit the DIEs corresponding
14231 to definitions of methods of classes as children of a
14232 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14233 the DIEs giving the declarations, which could be
14234 anywhere). But I don't see any reason why the
14235 standards says that they have to be there. */
14236 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14238 if (current_low
!= ((CORE_ADDR
) -1))
14240 best_low
= std::min (best_low
, current_low
);
14241 best_high
= std::max (best_high
, current_high
);
14249 child
= child
->sibling
;
14254 *highpc
= best_high
;
14257 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14261 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14262 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14264 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14265 struct gdbarch
*gdbarch
= objfile
->arch ();
14266 struct attribute
*attr
;
14267 struct attribute
*attr_high
;
14269 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14272 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14273 if (attr
!= nullptr)
14275 CORE_ADDR low
= attr
->as_address ();
14276 CORE_ADDR high
= attr_high
->as_address ();
14278 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14281 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14282 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14283 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14287 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14288 if (attr
!= nullptr && attr
->form_is_unsigned ())
14290 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14291 on DWARF version). */
14292 ULONGEST ranges_offset
= attr
->as_unsigned ();
14294 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14296 if (die
->tag
!= DW_TAG_compile_unit
)
14297 ranges_offset
+= cu
->gnu_ranges_base
;
14299 std::vector
<blockrange
> blockvec
;
14300 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14301 [&] (CORE_ADDR start
, CORE_ADDR end
)
14305 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14306 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14307 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14308 blockvec
.emplace_back (start
, end
);
14311 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14315 /* Check whether the producer field indicates either of GCC < 4.6, or the
14316 Intel C/C++ compiler, and cache the result in CU. */
14319 check_producer (struct dwarf2_cu
*cu
)
14323 if (cu
->producer
== NULL
)
14325 /* For unknown compilers expect their behavior is DWARF version
14328 GCC started to support .debug_types sections by -gdwarf-4 since
14329 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14330 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14331 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14332 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14334 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14336 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14337 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14339 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14341 cu
->producer_is_icc
= true;
14342 cu
->producer_is_icc_lt_14
= major
< 14;
14344 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14345 cu
->producer_is_codewarrior
= true;
14348 /* For other non-GCC compilers, expect their behavior is DWARF version
14352 cu
->checked_producer
= true;
14355 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14356 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14357 during 4.6.0 experimental. */
14360 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14362 if (!cu
->checked_producer
)
14363 check_producer (cu
);
14365 return cu
->producer_is_gxx_lt_4_6
;
14369 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14370 with incorrect is_stmt attributes. */
14373 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14375 if (!cu
->checked_producer
)
14376 check_producer (cu
);
14378 return cu
->producer_is_codewarrior
;
14381 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14382 If that attribute is not available, return the appropriate
14385 static enum dwarf_access_attribute
14386 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14388 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14389 if (attr
!= nullptr)
14391 LONGEST value
= attr
->constant_value (-1);
14392 if (value
== DW_ACCESS_public
14393 || value
== DW_ACCESS_protected
14394 || value
== DW_ACCESS_private
)
14395 return (dwarf_access_attribute
) value
;
14396 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14400 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14402 /* The default DWARF 2 accessibility for members is public, the default
14403 accessibility for inheritance is private. */
14405 if (die
->tag
!= DW_TAG_inheritance
)
14406 return DW_ACCESS_public
;
14408 return DW_ACCESS_private
;
14412 /* DWARF 3+ defines the default accessibility a different way. The same
14413 rules apply now for DW_TAG_inheritance as for the members and it only
14414 depends on the container kind. */
14416 if (die
->parent
->tag
== DW_TAG_class_type
)
14417 return DW_ACCESS_private
;
14419 return DW_ACCESS_public
;
14423 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
14424 *OFFSET to the byte offset. If the attribute was not found return
14425 0, otherwise return 1. If it was found but could not properly be
14426 handled, set *OFFSET to 0. */
14429 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14432 struct attribute
*attr
;
14434 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14439 /* Note that we do not check for a section offset first here.
14440 This is because DW_AT_data_member_location is new in DWARF 4,
14441 so if we see it, we can assume that a constant form is really
14442 a constant and not a section offset. */
14443 if (attr
->form_is_constant ())
14444 *offset
= attr
->constant_value (0);
14445 else if (attr
->form_is_section_offset ())
14446 dwarf2_complex_location_expr_complaint ();
14447 else if (attr
->form_is_block ())
14448 *offset
= decode_locdesc (attr
->as_block (), cu
);
14450 dwarf2_complex_location_expr_complaint ();
14456 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14457 if (attr
!= nullptr)
14459 *offset
= attr
->constant_value (0);
14467 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
14468 store the results in FIELD. */
14471 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14472 struct field
*field
)
14474 struct attribute
*attr
;
14476 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14479 if (attr
->form_is_constant ())
14481 LONGEST offset
= attr
->constant_value (0);
14482 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14484 else if (attr
->form_is_section_offset ())
14485 dwarf2_complex_location_expr_complaint ();
14486 else if (attr
->form_is_block ())
14489 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14491 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14494 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14495 struct objfile
*objfile
= per_objfile
->objfile
;
14496 struct dwarf2_locexpr_baton
*dlbaton
14497 = XOBNEW (&objfile
->objfile_obstack
,
14498 struct dwarf2_locexpr_baton
);
14499 dlbaton
->data
= attr
->as_block ()->data
;
14500 dlbaton
->size
= attr
->as_block ()->size
;
14501 /* When using this baton, we want to compute the address
14502 of the field, not the value. This is why
14503 is_reference is set to false here. */
14504 dlbaton
->is_reference
= false;
14505 dlbaton
->per_objfile
= per_objfile
;
14506 dlbaton
->per_cu
= cu
->per_cu
;
14508 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14512 dwarf2_complex_location_expr_complaint ();
14516 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14517 if (attr
!= nullptr)
14518 SET_FIELD_BITPOS (*field
, attr
->constant_value (0));
14522 /* Add an aggregate field to the field list. */
14525 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14526 struct dwarf2_cu
*cu
)
14528 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14529 struct gdbarch
*gdbarch
= objfile
->arch ();
14530 struct nextfield
*new_field
;
14531 struct attribute
*attr
;
14533 const char *fieldname
= "";
14535 if (die
->tag
== DW_TAG_inheritance
)
14537 fip
->baseclasses
.emplace_back ();
14538 new_field
= &fip
->baseclasses
.back ();
14542 fip
->fields
.emplace_back ();
14543 new_field
= &fip
->fields
.back ();
14546 new_field
->offset
= die
->sect_off
;
14548 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14549 if (new_field
->accessibility
!= DW_ACCESS_public
)
14550 fip
->non_public_fields
= true;
14552 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14553 if (attr
!= nullptr)
14554 new_field
->virtuality
= attr
->as_virtuality ();
14556 new_field
->virtuality
= DW_VIRTUALITY_none
;
14558 fp
= &new_field
->field
;
14560 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14562 /* Data member other than a C++ static data member. */
14564 /* Get type of field. */
14565 fp
->set_type (die_type (die
, cu
));
14567 SET_FIELD_BITPOS (*fp
, 0);
14569 /* Get bit size of field (zero if none). */
14570 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14571 if (attr
!= nullptr)
14573 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14577 FIELD_BITSIZE (*fp
) = 0;
14580 /* Get bit offset of field. */
14581 handle_member_location (die
, cu
, fp
);
14582 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14583 if (attr
!= nullptr && attr
->form_is_constant ())
14585 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14587 /* For big endian bits, the DW_AT_bit_offset gives the
14588 additional bit offset from the MSB of the containing
14589 anonymous object to the MSB of the field. We don't
14590 have to do anything special since we don't need to
14591 know the size of the anonymous object. */
14592 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14593 + attr
->constant_value (0)));
14597 /* For little endian bits, compute the bit offset to the
14598 MSB of the anonymous object, subtract off the number of
14599 bits from the MSB of the field to the MSB of the
14600 object, and then subtract off the number of bits of
14601 the field itself. The result is the bit offset of
14602 the LSB of the field. */
14603 int anonymous_size
;
14604 int bit_offset
= attr
->constant_value (0);
14606 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14607 if (attr
!= nullptr && attr
->form_is_constant ())
14609 /* The size of the anonymous object containing
14610 the bit field is explicit, so use the
14611 indicated size (in bytes). */
14612 anonymous_size
= attr
->constant_value (0);
14616 /* The size of the anonymous object containing
14617 the bit field must be inferred from the type
14618 attribute of the data member containing the
14620 anonymous_size
= TYPE_LENGTH (fp
->type ());
14622 SET_FIELD_BITPOS (*fp
,
14623 (FIELD_BITPOS (*fp
)
14624 + anonymous_size
* bits_per_byte
14625 - bit_offset
- FIELD_BITSIZE (*fp
)));
14629 /* Get name of field. */
14630 fieldname
= dwarf2_name (die
, cu
);
14631 if (fieldname
== NULL
)
14634 /* The name is already allocated along with this objfile, so we don't
14635 need to duplicate it for the type. */
14636 fp
->name
= fieldname
;
14638 /* Change accessibility for artificial fields (e.g. virtual table
14639 pointer or virtual base class pointer) to private. */
14640 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14642 FIELD_ARTIFICIAL (*fp
) = 1;
14643 new_field
->accessibility
= DW_ACCESS_private
;
14644 fip
->non_public_fields
= true;
14647 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14649 /* C++ static member. */
14651 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14652 is a declaration, but all versions of G++ as of this writing
14653 (so through at least 3.2.1) incorrectly generate
14654 DW_TAG_variable tags. */
14656 const char *physname
;
14658 /* Get name of field. */
14659 fieldname
= dwarf2_name (die
, cu
);
14660 if (fieldname
== NULL
)
14663 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14665 /* Only create a symbol if this is an external value.
14666 new_symbol checks this and puts the value in the global symbol
14667 table, which we want. If it is not external, new_symbol
14668 will try to put the value in cu->list_in_scope which is wrong. */
14669 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14671 /* A static const member, not much different than an enum as far as
14672 we're concerned, except that we can support more types. */
14673 new_symbol (die
, NULL
, cu
);
14676 /* Get physical name. */
14677 physname
= dwarf2_physname (fieldname
, die
, cu
);
14679 /* The name is already allocated along with this objfile, so we don't
14680 need to duplicate it for the type. */
14681 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14682 fp
->set_type (die_type (die
, cu
));
14683 FIELD_NAME (*fp
) = fieldname
;
14685 else if (die
->tag
== DW_TAG_inheritance
)
14687 /* C++ base class field. */
14688 handle_member_location (die
, cu
, fp
);
14689 FIELD_BITSIZE (*fp
) = 0;
14690 fp
->set_type (die_type (die
, cu
));
14691 FIELD_NAME (*fp
) = fp
->type ()->name ();
14694 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14697 /* Can the type given by DIE define another type? */
14700 type_can_define_types (const struct die_info
*die
)
14704 case DW_TAG_typedef
:
14705 case DW_TAG_class_type
:
14706 case DW_TAG_structure_type
:
14707 case DW_TAG_union_type
:
14708 case DW_TAG_enumeration_type
:
14716 /* Add a type definition defined in the scope of the FIP's class. */
14719 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14720 struct dwarf2_cu
*cu
)
14722 struct decl_field fp
;
14723 memset (&fp
, 0, sizeof (fp
));
14725 gdb_assert (type_can_define_types (die
));
14727 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14728 fp
.name
= dwarf2_name (die
, cu
);
14729 fp
.type
= read_type_die (die
, cu
);
14731 /* Save accessibility. */
14732 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14733 switch (accessibility
)
14735 case DW_ACCESS_public
:
14736 /* The assumed value if neither private nor protected. */
14738 case DW_ACCESS_private
:
14741 case DW_ACCESS_protected
:
14742 fp
.is_protected
= 1;
14746 if (die
->tag
== DW_TAG_typedef
)
14747 fip
->typedef_field_list
.push_back (fp
);
14749 fip
->nested_types_list
.push_back (fp
);
14752 /* A convenience typedef that's used when finding the discriminant
14753 field for a variant part. */
14754 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14757 /* Compute the discriminant range for a given variant. OBSTACK is
14758 where the results will be stored. VARIANT is the variant to
14759 process. IS_UNSIGNED indicates whether the discriminant is signed
14762 static const gdb::array_view
<discriminant_range
>
14763 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14766 std::vector
<discriminant_range
> ranges
;
14768 if (variant
.default_branch
)
14771 if (variant
.discr_list_data
== nullptr)
14773 discriminant_range r
14774 = {variant
.discriminant_value
, variant
.discriminant_value
};
14775 ranges
.push_back (r
);
14779 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14780 variant
.discr_list_data
->size
);
14781 while (!data
.empty ())
14783 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14785 complaint (_("invalid discriminant marker: %d"), data
[0]);
14788 bool is_range
= data
[0] == DW_DSC_range
;
14789 data
= data
.slice (1);
14791 ULONGEST low
, high
;
14792 unsigned int bytes_read
;
14796 complaint (_("DW_AT_discr_list missing low value"));
14800 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14802 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14804 data
= data
.slice (bytes_read
);
14810 complaint (_("DW_AT_discr_list missing high value"));
14814 high
= read_unsigned_leb128 (nullptr, data
.data (),
14817 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14819 data
= data
.slice (bytes_read
);
14824 ranges
.push_back ({ low
, high
});
14828 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14830 std::copy (ranges
.begin (), ranges
.end (), result
);
14831 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14834 static const gdb::array_view
<variant_part
> create_variant_parts
14835 (struct obstack
*obstack
,
14836 const offset_map_type
&offset_map
,
14837 struct field_info
*fi
,
14838 const std::vector
<variant_part_builder
> &variant_parts
);
14840 /* Fill in a "struct variant" for a given variant field. RESULT is
14841 the variant to fill in. OBSTACK is where any needed allocations
14842 will be done. OFFSET_MAP holds the mapping from section offsets to
14843 fields for the type. FI describes the fields of the type we're
14844 processing. FIELD is the variant field we're converting. */
14847 create_one_variant (variant
&result
, struct obstack
*obstack
,
14848 const offset_map_type
&offset_map
,
14849 struct field_info
*fi
, const variant_field
&field
)
14851 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14852 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14853 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14854 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14855 field
.variant_parts
);
14858 /* Fill in a "struct variant_part" for a given variant part. RESULT
14859 is the variant part to fill in. OBSTACK is where any needed
14860 allocations will be done. OFFSET_MAP holds the mapping from
14861 section offsets to fields for the type. FI describes the fields of
14862 the type we're processing. BUILDER is the variant part to be
14866 create_one_variant_part (variant_part
&result
,
14867 struct obstack
*obstack
,
14868 const offset_map_type
&offset_map
,
14869 struct field_info
*fi
,
14870 const variant_part_builder
&builder
)
14872 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14873 if (iter
== offset_map
.end ())
14875 result
.discriminant_index
= -1;
14876 /* Doesn't matter. */
14877 result
.is_unsigned
= false;
14881 result
.discriminant_index
= iter
->second
;
14883 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14886 size_t n
= builder
.variants
.size ();
14887 variant
*output
= new (obstack
) variant
[n
];
14888 for (size_t i
= 0; i
< n
; ++i
)
14889 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14890 builder
.variants
[i
]);
14892 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14895 /* Create a vector of variant parts that can be attached to a type.
14896 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14897 holds the mapping from section offsets to fields for the type. FI
14898 describes the fields of the type we're processing. VARIANT_PARTS
14899 is the vector to convert. */
14901 static const gdb::array_view
<variant_part
>
14902 create_variant_parts (struct obstack
*obstack
,
14903 const offset_map_type
&offset_map
,
14904 struct field_info
*fi
,
14905 const std::vector
<variant_part_builder
> &variant_parts
)
14907 if (variant_parts
.empty ())
14910 size_t n
= variant_parts
.size ();
14911 variant_part
*result
= new (obstack
) variant_part
[n
];
14912 for (size_t i
= 0; i
< n
; ++i
)
14913 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14916 return gdb::array_view
<variant_part
> (result
, n
);
14919 /* Compute the variant part vector for FIP, attaching it to TYPE when
14923 add_variant_property (struct field_info
*fip
, struct type
*type
,
14924 struct dwarf2_cu
*cu
)
14926 /* Map section offsets of fields to their field index. Note the
14927 field index here does not take the number of baseclasses into
14929 offset_map_type offset_map
;
14930 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14931 offset_map
[fip
->fields
[i
].offset
] = i
;
14933 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14934 gdb::array_view
<variant_part
> parts
14935 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14936 fip
->variant_parts
);
14938 struct dynamic_prop prop
;
14939 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14940 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14943 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14946 /* Create the vector of fields, and attach it to the type. */
14949 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14950 struct dwarf2_cu
*cu
)
14952 int nfields
= fip
->nfields ();
14954 /* Record the field count, allocate space for the array of fields,
14955 and create blank accessibility bitfields if necessary. */
14956 type
->set_num_fields (nfields
);
14958 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14960 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
14962 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14964 TYPE_FIELD_PRIVATE_BITS (type
) =
14965 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14966 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14968 TYPE_FIELD_PROTECTED_BITS (type
) =
14969 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14970 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14972 TYPE_FIELD_IGNORE_BITS (type
) =
14973 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14974 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14977 /* If the type has baseclasses, allocate and clear a bit vector for
14978 TYPE_FIELD_VIRTUAL_BITS. */
14979 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
14981 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14982 unsigned char *pointer
;
14984 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14985 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14986 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14987 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14988 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14991 if (!fip
->variant_parts
.empty ())
14992 add_variant_property (fip
, type
, cu
);
14994 /* Copy the saved-up fields into the field vector. */
14995 for (int i
= 0; i
< nfields
; ++i
)
14997 struct nextfield
&field
14998 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14999 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15001 type
->field (i
) = field
.field
;
15002 switch (field
.accessibility
)
15004 case DW_ACCESS_private
:
15005 if (cu
->per_cu
->lang
!= language_ada
)
15006 SET_TYPE_FIELD_PRIVATE (type
, i
);
15009 case DW_ACCESS_protected
:
15010 if (cu
->per_cu
->lang
!= language_ada
)
15011 SET_TYPE_FIELD_PROTECTED (type
, i
);
15014 case DW_ACCESS_public
:
15018 /* Unknown accessibility. Complain and treat it as public. */
15020 complaint (_("unsupported accessibility %d"),
15021 field
.accessibility
);
15025 if (i
< fip
->baseclasses
.size ())
15027 switch (field
.virtuality
)
15029 case DW_VIRTUALITY_virtual
:
15030 case DW_VIRTUALITY_pure_virtual
:
15031 if (cu
->per_cu
->lang
== language_ada
)
15032 error (_("unexpected virtuality in component of Ada type"));
15033 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15040 /* Return true if this member function is a constructor, false
15044 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15046 const char *fieldname
;
15047 const char *type_name
;
15050 if (die
->parent
== NULL
)
15053 if (die
->parent
->tag
!= DW_TAG_structure_type
15054 && die
->parent
->tag
!= DW_TAG_union_type
15055 && die
->parent
->tag
!= DW_TAG_class_type
)
15058 fieldname
= dwarf2_name (die
, cu
);
15059 type_name
= dwarf2_name (die
->parent
, cu
);
15060 if (fieldname
== NULL
|| type_name
== NULL
)
15063 len
= strlen (fieldname
);
15064 return (strncmp (fieldname
, type_name
, len
) == 0
15065 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15068 /* Add a member function to the proper fieldlist. */
15071 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15072 struct type
*type
, struct dwarf2_cu
*cu
)
15074 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15075 struct attribute
*attr
;
15077 struct fnfieldlist
*flp
= nullptr;
15078 struct fn_field
*fnp
;
15079 const char *fieldname
;
15080 struct type
*this_type
;
15082 if (cu
->per_cu
->lang
== language_ada
)
15083 error (_("unexpected member function in Ada type"));
15085 /* Get name of member function. */
15086 fieldname
= dwarf2_name (die
, cu
);
15087 if (fieldname
== NULL
)
15090 /* Look up member function name in fieldlist. */
15091 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15093 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15095 flp
= &fip
->fnfieldlists
[i
];
15100 /* Create a new fnfieldlist if necessary. */
15101 if (flp
== nullptr)
15103 fip
->fnfieldlists
.emplace_back ();
15104 flp
= &fip
->fnfieldlists
.back ();
15105 flp
->name
= fieldname
;
15106 i
= fip
->fnfieldlists
.size () - 1;
15109 /* Create a new member function field and add it to the vector of
15111 flp
->fnfields
.emplace_back ();
15112 fnp
= &flp
->fnfields
.back ();
15114 /* Delay processing of the physname until later. */
15115 if (cu
->per_cu
->lang
== language_cplus
)
15116 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15120 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15121 fnp
->physname
= physname
? physname
: "";
15124 fnp
->type
= alloc_type (objfile
);
15125 this_type
= read_type_die (die
, cu
);
15126 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15128 int nparams
= this_type
->num_fields ();
15130 /* TYPE is the domain of this method, and THIS_TYPE is the type
15131 of the method itself (TYPE_CODE_METHOD). */
15132 smash_to_method_type (fnp
->type
, type
,
15133 TYPE_TARGET_TYPE (this_type
),
15134 this_type
->fields (),
15135 this_type
->num_fields (),
15136 this_type
->has_varargs ());
15138 /* Handle static member functions.
15139 Dwarf2 has no clean way to discern C++ static and non-static
15140 member functions. G++ helps GDB by marking the first
15141 parameter for non-static member functions (which is the this
15142 pointer) as artificial. We obtain this information from
15143 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15144 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15145 fnp
->voffset
= VOFFSET_STATIC
;
15148 complaint (_("member function type missing for '%s'"),
15149 dwarf2_full_name (fieldname
, die
, cu
));
15151 /* Get fcontext from DW_AT_containing_type if present. */
15152 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15153 fnp
->fcontext
= die_containing_type (die
, cu
);
15155 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15156 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15158 /* Get accessibility. */
15159 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15160 switch (accessibility
)
15162 case DW_ACCESS_private
:
15163 fnp
->is_private
= 1;
15165 case DW_ACCESS_protected
:
15166 fnp
->is_protected
= 1;
15170 /* Check for artificial methods. */
15171 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15172 if (attr
&& attr
->as_boolean ())
15173 fnp
->is_artificial
= 1;
15175 /* Check for defaulted methods. */
15176 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15177 if (attr
!= nullptr)
15178 fnp
->defaulted
= attr
->defaulted ();
15180 /* Check for deleted methods. */
15181 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15182 if (attr
!= nullptr && attr
->as_boolean ())
15183 fnp
->is_deleted
= 1;
15185 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15187 /* Get index in virtual function table if it is a virtual member
15188 function. For older versions of GCC, this is an offset in the
15189 appropriate virtual table, as specified by DW_AT_containing_type.
15190 For everyone else, it is an expression to be evaluated relative
15191 to the object address. */
15193 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15194 if (attr
!= nullptr)
15196 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15198 struct dwarf_block
*block
= attr
->as_block ();
15200 if (block
->data
[0] == DW_OP_constu
)
15202 /* Old-style GCC. */
15203 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15205 else if (block
->data
[0] == DW_OP_deref
15206 || (block
->size
> 1
15207 && block
->data
[0] == DW_OP_deref_size
15208 && block
->data
[1] == cu
->header
.addr_size
))
15210 fnp
->voffset
= decode_locdesc (block
, cu
);
15211 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15212 dwarf2_complex_location_expr_complaint ();
15214 fnp
->voffset
/= cu
->header
.addr_size
;
15218 dwarf2_complex_location_expr_complaint ();
15220 if (!fnp
->fcontext
)
15222 /* If there is no `this' field and no DW_AT_containing_type,
15223 we cannot actually find a base class context for the
15225 if (this_type
->num_fields () == 0
15226 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15228 complaint (_("cannot determine context for virtual member "
15229 "function \"%s\" (offset %s)"),
15230 fieldname
, sect_offset_str (die
->sect_off
));
15235 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15239 else if (attr
->form_is_section_offset ())
15241 dwarf2_complex_location_expr_complaint ();
15245 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15251 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15252 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15254 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15255 complaint (_("Member function \"%s\" (offset %s) is virtual "
15256 "but the vtable offset is not specified"),
15257 fieldname
, sect_offset_str (die
->sect_off
));
15258 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15259 TYPE_CPLUS_DYNAMIC (type
) = 1;
15264 /* Create the vector of member function fields, and attach it to the type. */
15267 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15268 struct dwarf2_cu
*cu
)
15270 if (cu
->per_cu
->lang
== language_ada
)
15271 error (_("unexpected member functions in Ada type"));
15273 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15274 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15276 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15278 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15280 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15281 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15283 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15284 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15285 fn_flp
->fn_fields
= (struct fn_field
*)
15286 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15288 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15289 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15292 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15295 /* Returns non-zero if NAME is the name of a vtable member in CU's
15296 language, zero otherwise. */
15298 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15300 static const char vptr
[] = "_vptr";
15302 /* Look for the C++ form of the vtable. */
15303 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15309 /* GCC outputs unnamed structures that are really pointers to member
15310 functions, with the ABI-specified layout. If TYPE describes
15311 such a structure, smash it into a member function type.
15313 GCC shouldn't do this; it should just output pointer to member DIEs.
15314 This is GCC PR debug/28767. */
15317 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15319 struct type
*pfn_type
, *self_type
, *new_type
;
15321 /* Check for a structure with no name and two children. */
15322 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15325 /* Check for __pfn and __delta members. */
15326 if (TYPE_FIELD_NAME (type
, 0) == NULL
15327 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15328 || TYPE_FIELD_NAME (type
, 1) == NULL
15329 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15332 /* Find the type of the method. */
15333 pfn_type
= type
->field (0).type ();
15334 if (pfn_type
== NULL
15335 || pfn_type
->code () != TYPE_CODE_PTR
15336 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15339 /* Look for the "this" argument. */
15340 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15341 if (pfn_type
->num_fields () == 0
15342 /* || pfn_type->field (0).type () == NULL */
15343 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15346 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15347 new_type
= alloc_type (objfile
);
15348 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15349 pfn_type
->fields (), pfn_type
->num_fields (),
15350 pfn_type
->has_varargs ());
15351 smash_to_methodptr_type (type
, new_type
);
15354 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15355 requires rewriting, then copy it and return the updated copy.
15356 Otherwise return nullptr. */
15358 static struct type
*
15359 rewrite_array_type (struct type
*type
)
15361 if (type
->code () != TYPE_CODE_ARRAY
)
15364 struct type
*index_type
= type
->index_type ();
15365 range_bounds
*current_bounds
= index_type
->bounds ();
15367 /* Handle multi-dimensional arrays. */
15368 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15369 if (new_target
== nullptr)
15371 /* Maybe we don't need to rewrite this array. */
15372 if (current_bounds
->low
.kind () == PROP_CONST
15373 && current_bounds
->high
.kind () == PROP_CONST
)
15377 /* Either the target type was rewritten, or the bounds have to be
15378 updated. Either way we want to copy the type and update
15380 struct type
*copy
= copy_type (type
);
15381 int nfields
= copy
->num_fields ();
15383 = ((struct field
*) TYPE_ZALLOC (copy
,
15384 nfields
* sizeof (struct field
)));
15385 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15386 copy
->set_fields (new_fields
);
15387 if (new_target
!= nullptr)
15388 TYPE_TARGET_TYPE (copy
) = new_target
;
15390 struct type
*index_copy
= copy_type (index_type
);
15391 range_bounds
*bounds
15392 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15393 sizeof (range_bounds
));
15394 *bounds
= *current_bounds
;
15395 bounds
->low
.set_const_val (1);
15396 bounds
->high
.set_const_val (0);
15397 index_copy
->set_bounds (bounds
);
15398 copy
->set_index_type (index_copy
);
15403 /* While some versions of GCC will generate complicated DWARF for an
15404 array (see quirk_ada_thick_pointer), more recent versions were
15405 modified to emit an explicit thick pointer structure. However, in
15406 this case, the array still has DWARF expressions for its ranges,
15407 and these must be ignored. */
15410 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15413 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15415 /* Check for a structure with two children. */
15416 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15419 /* Check for P_ARRAY and P_BOUNDS members. */
15420 if (TYPE_FIELD_NAME (type
, 0) == NULL
15421 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15422 || TYPE_FIELD_NAME (type
, 1) == NULL
15423 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15426 /* Make sure we're looking at a pointer to an array. */
15427 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15430 /* The Ada code already knows how to handle these types, so all that
15431 we need to do is turn the bounds into static bounds. However, we
15432 don't want to rewrite existing array or index types in-place,
15433 because those may be referenced in other contexts where this
15434 rewriting is undesirable. */
15435 struct type
*new_ary_type
15436 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15437 if (new_ary_type
!= nullptr)
15438 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15441 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15442 appropriate error checking and issuing complaints if there is a
15446 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15448 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15450 if (attr
== nullptr)
15453 if (!attr
->form_is_constant ())
15455 complaint (_("DW_AT_alignment must have constant form"
15456 " - DIE at %s [in module %s]"),
15457 sect_offset_str (die
->sect_off
),
15458 objfile_name (cu
->per_objfile
->objfile
));
15462 LONGEST val
= attr
->constant_value (0);
15465 complaint (_("DW_AT_alignment value must not be negative"
15466 " - DIE at %s [in module %s]"),
15467 sect_offset_str (die
->sect_off
),
15468 objfile_name (cu
->per_objfile
->objfile
));
15471 ULONGEST align
= val
;
15475 complaint (_("DW_AT_alignment value must not be zero"
15476 " - DIE at %s [in module %s]"),
15477 sect_offset_str (die
->sect_off
),
15478 objfile_name (cu
->per_objfile
->objfile
));
15481 if ((align
& (align
- 1)) != 0)
15483 complaint (_("DW_AT_alignment value must be a power of 2"
15484 " - DIE at %s [in module %s]"),
15485 sect_offset_str (die
->sect_off
),
15486 objfile_name (cu
->per_objfile
->objfile
));
15493 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15494 the alignment for TYPE. */
15497 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15500 if (!set_type_align (type
, get_alignment (cu
, die
)))
15501 complaint (_("DW_AT_alignment value too large"
15502 " - DIE at %s [in module %s]"),
15503 sect_offset_str (die
->sect_off
),
15504 objfile_name (cu
->per_objfile
->objfile
));
15507 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15508 constant for a type, according to DWARF5 spec, Table 5.5. */
15511 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15516 case DW_CC_pass_by_reference
:
15517 case DW_CC_pass_by_value
:
15521 complaint (_("unrecognized DW_AT_calling_convention value "
15522 "(%s) for a type"), pulongest (value
));
15527 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15528 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15529 also according to GNU-specific values (see include/dwarf2.h). */
15532 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15537 case DW_CC_program
:
15541 case DW_CC_GNU_renesas_sh
:
15542 case DW_CC_GNU_borland_fastcall_i386
:
15543 case DW_CC_GDB_IBM_OpenCL
:
15547 complaint (_("unrecognized DW_AT_calling_convention value "
15548 "(%s) for a subroutine"), pulongest (value
));
15553 /* Called when we find the DIE that starts a structure or union scope
15554 (definition) to create a type for the structure or union. Fill in
15555 the type's name and general properties; the members will not be
15556 processed until process_structure_scope. A symbol table entry for
15557 the type will also not be done until process_structure_scope (assuming
15558 the type has a name).
15560 NOTE: we need to call these functions regardless of whether or not the
15561 DIE has a DW_AT_name attribute, since it might be an anonymous
15562 structure or union. This gets the type entered into our set of
15563 user defined types. */
15565 static struct type
*
15566 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15568 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15570 struct attribute
*attr
;
15573 /* If the definition of this type lives in .debug_types, read that type.
15574 Don't follow DW_AT_specification though, that will take us back up
15575 the chain and we want to go down. */
15576 attr
= die
->attr (DW_AT_signature
);
15577 if (attr
!= nullptr)
15579 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15581 /* The type's CU may not be the same as CU.
15582 Ensure TYPE is recorded with CU in die_type_hash. */
15583 return set_die_type (die
, type
, cu
);
15586 type
= alloc_type (objfile
);
15587 INIT_CPLUS_SPECIFIC (type
);
15589 name
= dwarf2_name (die
, cu
);
15592 if (cu
->per_cu
->lang
== language_cplus
15593 || cu
->per_cu
->lang
== language_d
15594 || cu
->per_cu
->lang
== language_rust
)
15596 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15598 /* dwarf2_full_name might have already finished building the DIE's
15599 type. If so, there is no need to continue. */
15600 if (get_die_type (die
, cu
) != NULL
)
15601 return get_die_type (die
, cu
);
15603 type
->set_name (full_name
);
15607 /* The name is already allocated along with this objfile, so
15608 we don't need to duplicate it for the type. */
15609 type
->set_name (name
);
15613 if (die
->tag
== DW_TAG_structure_type
)
15615 type
->set_code (TYPE_CODE_STRUCT
);
15617 else if (die
->tag
== DW_TAG_union_type
)
15619 type
->set_code (TYPE_CODE_UNION
);
15623 type
->set_code (TYPE_CODE_STRUCT
);
15626 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15627 type
->set_is_declared_class (true);
15629 /* Store the calling convention in the type if it's available in
15630 the die. Otherwise the calling convention remains set to
15631 the default value DW_CC_normal. */
15632 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15633 if (attr
!= nullptr
15634 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15636 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15637 TYPE_CPLUS_CALLING_CONVENTION (type
)
15638 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15641 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15642 if (attr
!= nullptr)
15644 if (attr
->form_is_constant ())
15645 TYPE_LENGTH (type
) = attr
->constant_value (0);
15648 struct dynamic_prop prop
;
15649 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15650 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15651 TYPE_LENGTH (type
) = 0;
15656 TYPE_LENGTH (type
) = 0;
15659 maybe_set_alignment (cu
, die
, type
);
15661 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15663 /* ICC<14 does not output the required DW_AT_declaration on
15664 incomplete types, but gives them a size of zero. */
15665 type
->set_is_stub (true);
15668 type
->set_stub_is_supported (true);
15670 if (die_is_declaration (die
, cu
))
15671 type
->set_is_stub (true);
15672 else if (attr
== NULL
&& die
->child
== NULL
15673 && producer_is_realview (cu
->producer
))
15674 /* RealView does not output the required DW_AT_declaration
15675 on incomplete types. */
15676 type
->set_is_stub (true);
15678 /* We need to add the type field to the die immediately so we don't
15679 infinitely recurse when dealing with pointers to the structure
15680 type within the structure itself. */
15681 set_die_type (die
, type
, cu
);
15683 /* set_die_type should be already done. */
15684 set_descriptive_type (type
, die
, cu
);
15689 static void handle_struct_member_die
15690 (struct die_info
*child_die
,
15692 struct field_info
*fi
,
15693 std::vector
<struct symbol
*> *template_args
,
15694 struct dwarf2_cu
*cu
);
15696 /* A helper for handle_struct_member_die that handles
15697 DW_TAG_variant_part. */
15700 handle_variant_part (struct die_info
*die
, struct type
*type
,
15701 struct field_info
*fi
,
15702 std::vector
<struct symbol
*> *template_args
,
15703 struct dwarf2_cu
*cu
)
15705 variant_part_builder
*new_part
;
15706 if (fi
->current_variant_part
== nullptr)
15708 fi
->variant_parts
.emplace_back ();
15709 new_part
= &fi
->variant_parts
.back ();
15711 else if (!fi
->current_variant_part
->processing_variant
)
15713 complaint (_("nested DW_TAG_variant_part seen "
15714 "- DIE at %s [in module %s]"),
15715 sect_offset_str (die
->sect_off
),
15716 objfile_name (cu
->per_objfile
->objfile
));
15721 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15722 current
.variant_parts
.emplace_back ();
15723 new_part
= ¤t
.variant_parts
.back ();
15726 /* When we recurse, we want callees to add to this new variant
15728 scoped_restore save_current_variant_part
15729 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15731 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15734 /* It's a univariant form, an extension we support. */
15736 else if (discr
->form_is_ref ())
15738 struct dwarf2_cu
*target_cu
= cu
;
15739 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15741 new_part
->discriminant_offset
= target_die
->sect_off
;
15745 complaint (_("DW_AT_discr does not have DIE reference form"
15746 " - DIE at %s [in module %s]"),
15747 sect_offset_str (die
->sect_off
),
15748 objfile_name (cu
->per_objfile
->objfile
));
15751 for (die_info
*child_die
= die
->child
;
15753 child_die
= child_die
->sibling
)
15754 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15757 /* A helper for handle_struct_member_die that handles
15761 handle_variant (struct die_info
*die
, struct type
*type
,
15762 struct field_info
*fi
,
15763 std::vector
<struct symbol
*> *template_args
,
15764 struct dwarf2_cu
*cu
)
15766 if (fi
->current_variant_part
== nullptr)
15768 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15769 "- DIE at %s [in module %s]"),
15770 sect_offset_str (die
->sect_off
),
15771 objfile_name (cu
->per_objfile
->objfile
));
15774 if (fi
->current_variant_part
->processing_variant
)
15776 complaint (_("nested DW_TAG_variant seen "
15777 "- DIE at %s [in module %s]"),
15778 sect_offset_str (die
->sect_off
),
15779 objfile_name (cu
->per_objfile
->objfile
));
15783 scoped_restore save_processing_variant
15784 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15787 fi
->current_variant_part
->variants
.emplace_back ();
15788 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15789 variant
.first_field
= fi
->fields
.size ();
15791 /* In a variant we want to get the discriminant and also add a
15792 field for our sole member child. */
15793 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15794 if (discr
== nullptr || !discr
->form_is_constant ())
15796 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15797 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15798 variant
.default_branch
= true;
15800 variant
.discr_list_data
= discr
->as_block ();
15803 variant
.discriminant_value
= discr
->constant_value (0);
15805 for (die_info
*variant_child
= die
->child
;
15806 variant_child
!= NULL
;
15807 variant_child
= variant_child
->sibling
)
15808 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15810 variant
.last_field
= fi
->fields
.size ();
15813 /* A helper for process_structure_scope that handles a single member
15817 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15818 struct field_info
*fi
,
15819 std::vector
<struct symbol
*> *template_args
,
15820 struct dwarf2_cu
*cu
)
15822 if (child_die
->tag
== DW_TAG_member
15823 || child_die
->tag
== DW_TAG_variable
)
15825 /* NOTE: carlton/2002-11-05: A C++ static data member
15826 should be a DW_TAG_member that is a declaration, but
15827 all versions of G++ as of this writing (so through at
15828 least 3.2.1) incorrectly generate DW_TAG_variable
15829 tags for them instead. */
15830 dwarf2_add_field (fi
, child_die
, cu
);
15832 else if (child_die
->tag
== DW_TAG_subprogram
)
15834 /* Rust doesn't have member functions in the C++ sense.
15835 However, it does emit ordinary functions as children
15836 of a struct DIE. */
15837 if (cu
->per_cu
->lang
== language_rust
)
15838 read_func_scope (child_die
, cu
);
15841 /* C++ member function. */
15842 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15845 else if (child_die
->tag
== DW_TAG_inheritance
)
15847 /* C++ base class field. */
15848 dwarf2_add_field (fi
, child_die
, cu
);
15850 else if (type_can_define_types (child_die
))
15851 dwarf2_add_type_defn (fi
, child_die
, cu
);
15852 else if (child_die
->tag
== DW_TAG_template_type_param
15853 || child_die
->tag
== DW_TAG_template_value_param
)
15855 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15858 template_args
->push_back (arg
);
15860 else if (child_die
->tag
== DW_TAG_variant_part
)
15861 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15862 else if (child_die
->tag
== DW_TAG_variant
)
15863 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15866 /* Finish creating a structure or union type, including filling in
15867 its members and creating a symbol for it. */
15870 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15872 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15873 struct die_info
*child_die
;
15876 type
= get_die_type (die
, cu
);
15878 type
= read_structure_type (die
, cu
);
15880 bool has_template_parameters
= false;
15881 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15883 struct field_info fi
;
15884 std::vector
<struct symbol
*> template_args
;
15886 child_die
= die
->child
;
15888 while (child_die
&& child_die
->tag
)
15890 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15891 child_die
= child_die
->sibling
;
15894 /* Attach template arguments to type. */
15895 if (!template_args
.empty ())
15897 has_template_parameters
= true;
15898 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15899 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15900 TYPE_TEMPLATE_ARGUMENTS (type
)
15901 = XOBNEWVEC (&objfile
->objfile_obstack
,
15903 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15904 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15905 template_args
.data (),
15906 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15907 * sizeof (struct symbol
*)));
15910 /* Attach fields and member functions to the type. */
15911 if (fi
.nfields () > 0)
15912 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15913 if (!fi
.fnfieldlists
.empty ())
15915 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15917 /* Get the type which refers to the base class (possibly this
15918 class itself) which contains the vtable pointer for the current
15919 class from the DW_AT_containing_type attribute. This use of
15920 DW_AT_containing_type is a GNU extension. */
15922 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15924 struct type
*t
= die_containing_type (die
, cu
);
15926 set_type_vptr_basetype (type
, t
);
15931 /* Our own class provides vtbl ptr. */
15932 for (i
= t
->num_fields () - 1;
15933 i
>= TYPE_N_BASECLASSES (t
);
15936 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15938 if (is_vtable_name (fieldname
, cu
))
15940 set_type_vptr_fieldno (type
, i
);
15945 /* Complain if virtual function table field not found. */
15946 if (i
< TYPE_N_BASECLASSES (t
))
15947 complaint (_("virtual function table pointer "
15948 "not found when defining class '%s'"),
15949 type
->name () ? type
->name () : "");
15953 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15956 else if (cu
->producer
15957 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15959 /* The IBM XLC compiler does not provide direct indication
15960 of the containing type, but the vtable pointer is
15961 always named __vfp. */
15965 for (i
= type
->num_fields () - 1;
15966 i
>= TYPE_N_BASECLASSES (type
);
15969 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15971 set_type_vptr_fieldno (type
, i
);
15972 set_type_vptr_basetype (type
, type
);
15979 /* Copy fi.typedef_field_list linked list elements content into the
15980 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15981 if (!fi
.typedef_field_list
.empty ())
15983 int count
= fi
.typedef_field_list
.size ();
15985 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15986 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15987 = ((struct decl_field
*)
15989 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15990 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15992 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15993 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15996 /* Copy fi.nested_types_list linked list elements content into the
15997 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15998 if (!fi
.nested_types_list
.empty ()
15999 && cu
->per_cu
->lang
!= language_ada
)
16001 int count
= fi
.nested_types_list
.size ();
16003 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16004 TYPE_NESTED_TYPES_ARRAY (type
)
16005 = ((struct decl_field
*)
16006 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16007 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16009 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16010 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16014 quirk_gcc_member_function_pointer (type
, objfile
);
16015 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16016 cu
->rust_unions
.push_back (type
);
16017 else if (cu
->per_cu
->lang
== language_ada
)
16018 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16020 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16021 snapshots) has been known to create a die giving a declaration
16022 for a class that has, as a child, a die giving a definition for a
16023 nested class. So we have to process our children even if the
16024 current die is a declaration. Normally, of course, a declaration
16025 won't have any children at all. */
16027 child_die
= die
->child
;
16029 while (child_die
!= NULL
&& child_die
->tag
)
16031 if (child_die
->tag
== DW_TAG_member
16032 || child_die
->tag
== DW_TAG_variable
16033 || child_die
->tag
== DW_TAG_inheritance
16034 || child_die
->tag
== DW_TAG_template_value_param
16035 || child_die
->tag
== DW_TAG_template_type_param
)
16040 process_die (child_die
, cu
);
16042 child_die
= child_die
->sibling
;
16045 /* Do not consider external references. According to the DWARF standard,
16046 these DIEs are identified by the fact that they have no byte_size
16047 attribute, and a declaration attribute. */
16048 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16049 || !die_is_declaration (die
, cu
)
16050 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16052 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16054 if (has_template_parameters
)
16056 struct symtab
*symtab
;
16057 if (sym
!= nullptr)
16058 symtab
= symbol_symtab (sym
);
16059 else if (cu
->line_header
!= nullptr)
16061 /* Any related symtab will do. */
16063 = cu
->line_header
->file_names ()[0].symtab
;
16068 complaint (_("could not find suitable "
16069 "symtab for template parameter"
16070 " - DIE at %s [in module %s]"),
16071 sect_offset_str (die
->sect_off
),
16072 objfile_name (objfile
));
16075 if (symtab
!= nullptr)
16077 /* Make sure that the symtab is set on the new symbols.
16078 Even though they don't appear in this symtab directly,
16079 other parts of gdb assume that symbols do, and this is
16080 reasonably true. */
16081 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16082 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16088 /* Assuming DIE is an enumeration type, and TYPE is its associated
16089 type, update TYPE using some information only available in DIE's
16090 children. In particular, the fields are computed. */
16093 update_enumeration_type_from_children (struct die_info
*die
,
16095 struct dwarf2_cu
*cu
)
16097 struct die_info
*child_die
;
16098 int unsigned_enum
= 1;
16101 auto_obstack obstack
;
16102 std::vector
<struct field
> fields
;
16104 for (child_die
= die
->child
;
16105 child_die
!= NULL
&& child_die
->tag
;
16106 child_die
= child_die
->sibling
)
16108 struct attribute
*attr
;
16110 const gdb_byte
*bytes
;
16111 struct dwarf2_locexpr_baton
*baton
;
16114 if (child_die
->tag
!= DW_TAG_enumerator
)
16117 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16121 name
= dwarf2_name (child_die
, cu
);
16123 name
= "<anonymous enumerator>";
16125 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16126 &value
, &bytes
, &baton
);
16134 if (count_one_bits_ll (value
) >= 2)
16138 fields
.emplace_back ();
16139 struct field
&field
= fields
.back ();
16140 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16141 SET_FIELD_ENUMVAL (field
, value
);
16144 if (!fields
.empty ())
16146 type
->set_num_fields (fields
.size ());
16149 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16150 memcpy (type
->fields (), fields
.data (),
16151 sizeof (struct field
) * fields
.size ());
16155 type
->set_is_unsigned (true);
16158 type
->set_is_flag_enum (true);
16161 /* Given a DW_AT_enumeration_type die, set its type. We do not
16162 complete the type's fields yet, or create any symbols. */
16164 static struct type
*
16165 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16167 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16169 struct attribute
*attr
;
16172 /* If the definition of this type lives in .debug_types, read that type.
16173 Don't follow DW_AT_specification though, that will take us back up
16174 the chain and we want to go down. */
16175 attr
= die
->attr (DW_AT_signature
);
16176 if (attr
!= nullptr)
16178 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16180 /* The type's CU may not be the same as CU.
16181 Ensure TYPE is recorded with CU in die_type_hash. */
16182 return set_die_type (die
, type
, cu
);
16185 type
= alloc_type (objfile
);
16187 type
->set_code (TYPE_CODE_ENUM
);
16188 name
= dwarf2_full_name (NULL
, die
, cu
);
16190 type
->set_name (name
);
16192 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16195 struct type
*underlying_type
= die_type (die
, cu
);
16197 TYPE_TARGET_TYPE (type
) = underlying_type
;
16200 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16201 if (attr
!= nullptr)
16203 TYPE_LENGTH (type
) = attr
->constant_value (0);
16207 TYPE_LENGTH (type
) = 0;
16210 maybe_set_alignment (cu
, die
, type
);
16212 /* The enumeration DIE can be incomplete. In Ada, any type can be
16213 declared as private in the package spec, and then defined only
16214 inside the package body. Such types are known as Taft Amendment
16215 Types. When another package uses such a type, an incomplete DIE
16216 may be generated by the compiler. */
16217 if (die_is_declaration (die
, cu
))
16218 type
->set_is_stub (true);
16220 /* If this type has an underlying type that is not a stub, then we
16221 may use its attributes. We always use the "unsigned" attribute
16222 in this situation, because ordinarily we guess whether the type
16223 is unsigned -- but the guess can be wrong and the underlying type
16224 can tell us the reality. However, we defer to a local size
16225 attribute if one exists, because this lets the compiler override
16226 the underlying type if needed. */
16227 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16229 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16230 underlying_type
= check_typedef (underlying_type
);
16232 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16234 if (TYPE_LENGTH (type
) == 0)
16235 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16237 if (TYPE_RAW_ALIGN (type
) == 0
16238 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16239 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16242 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16244 set_die_type (die
, type
, cu
);
16246 /* Finish the creation of this type by using the enum's children.
16247 Note that, as usual, this must come after set_die_type to avoid
16248 infinite recursion when trying to compute the names of the
16250 update_enumeration_type_from_children (die
, type
, cu
);
16255 /* Given a pointer to a die which begins an enumeration, process all
16256 the dies that define the members of the enumeration, and create the
16257 symbol for the enumeration type.
16259 NOTE: We reverse the order of the element list. */
16262 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16264 struct type
*this_type
;
16266 this_type
= get_die_type (die
, cu
);
16267 if (this_type
== NULL
)
16268 this_type
= read_enumeration_type (die
, cu
);
16270 if (die
->child
!= NULL
)
16272 struct die_info
*child_die
;
16275 child_die
= die
->child
;
16276 while (child_die
&& child_die
->tag
)
16278 if (child_die
->tag
!= DW_TAG_enumerator
)
16280 process_die (child_die
, cu
);
16284 name
= dwarf2_name (child_die
, cu
);
16286 new_symbol (child_die
, this_type
, cu
);
16289 child_die
= child_die
->sibling
;
16293 /* If we are reading an enum from a .debug_types unit, and the enum
16294 is a declaration, and the enum is not the signatured type in the
16295 unit, then we do not want to add a symbol for it. Adding a
16296 symbol would in some cases obscure the true definition of the
16297 enum, giving users an incomplete type when the definition is
16298 actually available. Note that we do not want to do this for all
16299 enums which are just declarations, because C++0x allows forward
16300 enum declarations. */
16301 if (cu
->per_cu
->is_debug_types
16302 && die_is_declaration (die
, cu
))
16304 struct signatured_type
*sig_type
;
16306 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16307 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16308 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16312 new_symbol (die
, this_type
, cu
);
16315 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16316 expression for an index type and finds the corresponding field
16317 offset in the hidden "P_BOUNDS" structure. Returns true on success
16318 and updates *FIELD, false if it fails to recognize an
16322 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16323 int *bounds_offset
, struct field
*field
,
16324 struct dwarf2_cu
*cu
)
16326 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16327 if (attr
== nullptr || !attr
->form_is_block ())
16330 const struct dwarf_block
*block
= attr
->as_block ();
16331 const gdb_byte
*start
= block
->data
;
16332 const gdb_byte
*end
= block
->data
+ block
->size
;
16334 /* The expression to recognize generally looks like:
16336 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16337 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16339 However, the second "plus_uconst" may be missing:
16341 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16342 DW_OP_deref_size: 4)
16344 This happens when the field is at the start of the structure.
16346 Also, the final deref may not be sized:
16348 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16351 This happens when the size of the index type happens to be the
16352 same as the architecture's word size. This can occur with or
16353 without the second plus_uconst. */
16355 if (end
- start
< 2)
16357 if (*start
++ != DW_OP_push_object_address
)
16359 if (*start
++ != DW_OP_plus_uconst
)
16362 uint64_t this_bound_off
;
16363 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16364 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16366 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16367 is consistent among all bounds. */
16368 if (*bounds_offset
== -1)
16369 *bounds_offset
= this_bound_off
;
16370 else if (*bounds_offset
!= this_bound_off
)
16373 if (start
== end
|| *start
++ != DW_OP_deref
)
16379 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16381 /* This means an offset of 0. */
16383 else if (*start
++ != DW_OP_plus_uconst
)
16387 /* The size is the parameter to DW_OP_plus_uconst. */
16389 start
= gdb_read_uleb128 (start
, end
, &val
);
16390 if (start
== nullptr)
16392 if ((int) val
!= val
)
16401 if (*start
== DW_OP_deref_size
)
16403 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16404 if (start
== nullptr)
16407 else if (*start
== DW_OP_deref
)
16409 size
= cu
->header
.addr_size
;
16415 SET_FIELD_BITPOS (*field
, 8 * offset
);
16416 if (size
!= TYPE_LENGTH (field
->type ()))
16417 FIELD_BITSIZE (*field
) = 8 * size
;
16422 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16423 some kinds of Ada arrays:
16425 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16426 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16427 <11e0> DW_AT_data_location: 2 byte block: 97 6
16428 (DW_OP_push_object_address; DW_OP_deref)
16429 <11e3> DW_AT_type : <0x1173>
16430 <11e7> DW_AT_sibling : <0x1201>
16431 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16432 <11ec> DW_AT_type : <0x1206>
16433 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16434 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16435 DW_OP_deref_size: 4)
16436 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16437 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16438 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16440 This actually represents a "thick pointer", which is a structure
16441 with two elements: one that is a pointer to the array data, and one
16442 that is a pointer to another structure; this second structure holds
16445 This returns a new type on success, or nullptr if this didn't
16446 recognize the type. */
16448 static struct type
*
16449 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16452 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16453 /* So far we've only seen this with block form. */
16454 if (attr
== nullptr || !attr
->form_is_block ())
16457 /* Note that this will fail if the structure layout is changed by
16458 the compiler. However, we have no good way to recognize some
16459 other layout, because we don't know what expression the compiler
16460 might choose to emit should this happen. */
16461 struct dwarf_block
*blk
= attr
->as_block ();
16463 || blk
->data
[0] != DW_OP_push_object_address
16464 || blk
->data
[1] != DW_OP_deref
)
16467 int bounds_offset
= -1;
16468 int max_align
= -1;
16469 std::vector
<struct field
> range_fields
;
16470 for (struct die_info
*child_die
= die
->child
;
16472 child_die
= child_die
->sibling
)
16474 if (child_die
->tag
== DW_TAG_subrange_type
)
16476 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16478 int this_align
= type_align (underlying
);
16479 if (this_align
> max_align
)
16480 max_align
= this_align
;
16482 range_fields
.emplace_back ();
16483 range_fields
.emplace_back ();
16485 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16486 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16488 lower
.set_type (underlying
);
16489 FIELD_ARTIFICIAL (lower
) = 1;
16491 upper
.set_type (underlying
);
16492 FIELD_ARTIFICIAL (upper
) = 1;
16494 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16495 &bounds_offset
, &lower
, cu
)
16496 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16497 &bounds_offset
, &upper
, cu
))
16502 /* This shouldn't really happen, but double-check that we found
16503 where the bounds are stored. */
16504 if (bounds_offset
== -1)
16507 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16508 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16512 /* Set the name of each field in the bounds. */
16513 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16514 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16515 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16516 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16519 struct type
*bounds
= alloc_type (objfile
);
16520 bounds
->set_code (TYPE_CODE_STRUCT
);
16522 bounds
->set_num_fields (range_fields
.size ());
16524 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16525 * sizeof (struct field
))));
16526 memcpy (bounds
->fields (), range_fields
.data (),
16527 bounds
->num_fields () * sizeof (struct field
));
16529 int last_fieldno
= range_fields
.size () - 1;
16530 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16531 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16532 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16534 /* Rewrite the existing array type in place. Specifically, we
16535 remove any dynamic properties we might have read, and we replace
16536 the index types. */
16537 struct type
*iter
= type
;
16538 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16540 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16541 iter
->main_type
->dyn_prop_list
= nullptr;
16542 iter
->set_index_type
16543 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16544 iter
= TYPE_TARGET_TYPE (iter
);
16547 struct type
*result
= alloc_type (objfile
);
16548 result
->set_code (TYPE_CODE_STRUCT
);
16550 result
->set_num_fields (2);
16552 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16553 * sizeof (struct field
))));
16555 /* The names are chosen to coincide with what the compiler does with
16556 -fgnat-encodings=all, which the Ada code in gdb already
16558 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16559 result
->field (0).set_type (lookup_pointer_type (type
));
16561 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16562 result
->field (1).set_type (lookup_pointer_type (bounds
));
16563 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16565 result
->set_name (type
->name ());
16566 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16567 + TYPE_LENGTH (result
->field (1).type ()));
16572 /* Extract all information from a DW_TAG_array_type DIE and put it in
16573 the DIE's type field. For now, this only handles one dimensional
16576 static struct type
*
16577 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16579 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16580 struct die_info
*child_die
;
16582 struct type
*element_type
, *range_type
, *index_type
;
16583 struct attribute
*attr
;
16585 struct dynamic_prop
*byte_stride_prop
= NULL
;
16586 unsigned int bit_stride
= 0;
16588 element_type
= die_type (die
, cu
);
16590 /* The die_type call above may have already set the type for this DIE. */
16591 type
= get_die_type (die
, cu
);
16595 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16599 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16602 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16603 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16607 complaint (_("unable to read array DW_AT_byte_stride "
16608 " - DIE at %s [in module %s]"),
16609 sect_offset_str (die
->sect_off
),
16610 objfile_name (cu
->per_objfile
->objfile
));
16611 /* Ignore this attribute. We will likely not be able to print
16612 arrays of this type correctly, but there is little we can do
16613 to help if we cannot read the attribute's value. */
16614 byte_stride_prop
= NULL
;
16618 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16620 bit_stride
= attr
->constant_value (0);
16622 /* Irix 6.2 native cc creates array types without children for
16623 arrays with unspecified length. */
16624 if (die
->child
== NULL
)
16626 index_type
= objfile_type (objfile
)->builtin_int
;
16627 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16628 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16629 byte_stride_prop
, bit_stride
);
16630 return set_die_type (die
, type
, cu
);
16633 std::vector
<struct type
*> range_types
;
16634 child_die
= die
->child
;
16635 while (child_die
&& child_die
->tag
)
16637 if (child_die
->tag
== DW_TAG_subrange_type
)
16639 struct type
*child_type
= read_type_die (child_die
, cu
);
16641 if (child_type
!= NULL
)
16643 /* The range type was succesfully read. Save it for the
16644 array type creation. */
16645 range_types
.push_back (child_type
);
16648 child_die
= child_die
->sibling
;
16651 if (range_types
.empty ())
16653 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16654 sect_offset_str (die
->sect_off
),
16655 objfile_name (cu
->per_objfile
->objfile
));
16659 /* Dwarf2 dimensions are output from left to right, create the
16660 necessary array types in backwards order. */
16662 type
= element_type
;
16664 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16668 while (i
< range_types
.size ())
16670 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16671 byte_stride_prop
, bit_stride
);
16673 byte_stride_prop
= nullptr;
16678 size_t ndim
= range_types
.size ();
16681 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16682 byte_stride_prop
, bit_stride
);
16684 byte_stride_prop
= nullptr;
16688 gdb_assert (type
!= element_type
);
16690 /* Understand Dwarf2 support for vector types (like they occur on
16691 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16692 array type. This is not part of the Dwarf2/3 standard yet, but a
16693 custom vendor extension. The main difference between a regular
16694 array and the vector variant is that vectors are passed by value
16696 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16697 if (attr
!= nullptr)
16698 make_vector_type (type
);
16700 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16701 implementation may choose to implement triple vectors using this
16703 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16704 if (attr
!= nullptr && attr
->form_is_unsigned ())
16706 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16707 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16709 complaint (_("DW_AT_byte_size for array type smaller "
16710 "than the total size of elements"));
16713 name
= dwarf2_name (die
, cu
);
16715 type
->set_name (name
);
16717 maybe_set_alignment (cu
, die
, type
);
16719 struct type
*replacement_type
= nullptr;
16720 if (cu
->per_cu
->lang
== language_ada
)
16722 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16723 if (replacement_type
!= nullptr)
16724 type
= replacement_type
;
16727 /* Install the type in the die. */
16728 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16730 /* set_die_type should be already done. */
16731 set_descriptive_type (type
, die
, cu
);
16736 static enum dwarf_array_dim_ordering
16737 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16739 struct attribute
*attr
;
16741 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16743 if (attr
!= nullptr)
16745 LONGEST val
= attr
->constant_value (-1);
16746 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16747 return (enum dwarf_array_dim_ordering
) val
;
16750 /* GNU F77 is a special case, as at 08/2004 array type info is the
16751 opposite order to the dwarf2 specification, but data is still
16752 laid out as per normal fortran.
16754 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16755 version checking. */
16757 if (cu
->per_cu
->lang
== language_fortran
16758 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16760 return DW_ORD_row_major
;
16763 switch (cu
->language_defn
->array_ordering ())
16765 case array_column_major
:
16766 return DW_ORD_col_major
;
16767 case array_row_major
:
16769 return DW_ORD_row_major
;
16773 /* Extract all information from a DW_TAG_set_type DIE and put it in
16774 the DIE's type field. */
16776 static struct type
*
16777 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16779 struct type
*domain_type
, *set_type
;
16780 struct attribute
*attr
;
16782 domain_type
= die_type (die
, cu
);
16784 /* The die_type call above may have already set the type for this DIE. */
16785 set_type
= get_die_type (die
, cu
);
16789 set_type
= create_set_type (NULL
, domain_type
);
16791 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16792 if (attr
!= nullptr && attr
->form_is_unsigned ())
16793 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16795 maybe_set_alignment (cu
, die
, set_type
);
16797 return set_die_type (die
, set_type
, cu
);
16800 /* A helper for read_common_block that creates a locexpr baton.
16801 SYM is the symbol which we are marking as computed.
16802 COMMON_DIE is the DIE for the common block.
16803 COMMON_LOC is the location expression attribute for the common
16805 MEMBER_LOC is the location expression attribute for the particular
16806 member of the common block that we are processing.
16807 CU is the CU from which the above come. */
16810 mark_common_block_symbol_computed (struct symbol
*sym
,
16811 struct die_info
*common_die
,
16812 struct attribute
*common_loc
,
16813 struct attribute
*member_loc
,
16814 struct dwarf2_cu
*cu
)
16816 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16817 struct objfile
*objfile
= per_objfile
->objfile
;
16818 struct dwarf2_locexpr_baton
*baton
;
16820 unsigned int cu_off
;
16821 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16822 LONGEST offset
= 0;
16824 gdb_assert (common_loc
&& member_loc
);
16825 gdb_assert (common_loc
->form_is_block ());
16826 gdb_assert (member_loc
->form_is_block ()
16827 || member_loc
->form_is_constant ());
16829 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16830 baton
->per_objfile
= per_objfile
;
16831 baton
->per_cu
= cu
->per_cu
;
16832 gdb_assert (baton
->per_cu
);
16834 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16836 if (member_loc
->form_is_constant ())
16838 offset
= member_loc
->constant_value (0);
16839 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16842 baton
->size
+= member_loc
->as_block ()->size
;
16844 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16847 *ptr
++ = DW_OP_call4
;
16848 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16849 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16852 if (member_loc
->form_is_constant ())
16854 *ptr
++ = DW_OP_addr
;
16855 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16856 ptr
+= cu
->header
.addr_size
;
16860 /* We have to copy the data here, because DW_OP_call4 will only
16861 use a DW_AT_location attribute. */
16862 struct dwarf_block
*block
= member_loc
->as_block ();
16863 memcpy (ptr
, block
->data
, block
->size
);
16864 ptr
+= block
->size
;
16867 *ptr
++ = DW_OP_plus
;
16868 gdb_assert (ptr
- baton
->data
== baton
->size
);
16870 SYMBOL_LOCATION_BATON (sym
) = baton
;
16871 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16874 /* Create appropriate locally-scoped variables for all the
16875 DW_TAG_common_block entries. Also create a struct common_block
16876 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16877 is used to separate the common blocks name namespace from regular
16881 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16883 struct attribute
*attr
;
16885 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16886 if (attr
!= nullptr)
16888 /* Support the .debug_loc offsets. */
16889 if (attr
->form_is_block ())
16893 else if (attr
->form_is_section_offset ())
16895 dwarf2_complex_location_expr_complaint ();
16900 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16901 "common block member");
16906 if (die
->child
!= NULL
)
16908 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16909 struct die_info
*child_die
;
16910 size_t n_entries
= 0, size
;
16911 struct common_block
*common_block
;
16912 struct symbol
*sym
;
16914 for (child_die
= die
->child
;
16915 child_die
&& child_die
->tag
;
16916 child_die
= child_die
->sibling
)
16919 size
= (sizeof (struct common_block
)
16920 + (n_entries
- 1) * sizeof (struct symbol
*));
16922 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16924 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16925 common_block
->n_entries
= 0;
16927 for (child_die
= die
->child
;
16928 child_die
&& child_die
->tag
;
16929 child_die
= child_die
->sibling
)
16931 /* Create the symbol in the DW_TAG_common_block block in the current
16933 sym
= new_symbol (child_die
, NULL
, cu
);
16936 struct attribute
*member_loc
;
16938 common_block
->contents
[common_block
->n_entries
++] = sym
;
16940 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16944 /* GDB has handled this for a long time, but it is
16945 not specified by DWARF. It seems to have been
16946 emitted by gfortran at least as recently as:
16947 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16948 complaint (_("Variable in common block has "
16949 "DW_AT_data_member_location "
16950 "- DIE at %s [in module %s]"),
16951 sect_offset_str (child_die
->sect_off
),
16952 objfile_name (objfile
));
16954 if (member_loc
->form_is_section_offset ())
16955 dwarf2_complex_location_expr_complaint ();
16956 else if (member_loc
->form_is_constant ()
16957 || member_loc
->form_is_block ())
16959 if (attr
!= nullptr)
16960 mark_common_block_symbol_computed (sym
, die
, attr
,
16964 dwarf2_complex_location_expr_complaint ();
16969 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16970 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16974 /* Create a type for a C++ namespace. */
16976 static struct type
*
16977 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16979 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16980 const char *previous_prefix
, *name
;
16984 /* For extensions, reuse the type of the original namespace. */
16985 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16987 struct die_info
*ext_die
;
16988 struct dwarf2_cu
*ext_cu
= cu
;
16990 ext_die
= dwarf2_extension (die
, &ext_cu
);
16991 type
= read_type_die (ext_die
, ext_cu
);
16993 /* EXT_CU may not be the same as CU.
16994 Ensure TYPE is recorded with CU in die_type_hash. */
16995 return set_die_type (die
, type
, cu
);
16998 name
= namespace_name (die
, &is_anonymous
, cu
);
17000 /* Now build the name of the current namespace. */
17002 previous_prefix
= determine_prefix (die
, cu
);
17003 if (previous_prefix
[0] != '\0')
17004 name
= typename_concat (&objfile
->objfile_obstack
,
17005 previous_prefix
, name
, 0, cu
);
17007 /* Create the type. */
17008 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17010 return set_die_type (die
, type
, cu
);
17013 /* Read a namespace scope. */
17016 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17018 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17021 /* Add a symbol associated to this if we haven't seen the namespace
17022 before. Also, add a using directive if it's an anonymous
17025 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17029 type
= read_type_die (die
, cu
);
17030 new_symbol (die
, type
, cu
);
17032 namespace_name (die
, &is_anonymous
, cu
);
17035 const char *previous_prefix
= determine_prefix (die
, cu
);
17037 std::vector
<const char *> excludes
;
17038 add_using_directive (using_directives (cu
),
17039 previous_prefix
, type
->name (), NULL
,
17040 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17044 if (die
->child
!= NULL
)
17046 struct die_info
*child_die
= die
->child
;
17048 while (child_die
&& child_die
->tag
)
17050 process_die (child_die
, cu
);
17051 child_die
= child_die
->sibling
;
17056 /* Read a Fortran module as type. This DIE can be only a declaration used for
17057 imported module. Still we need that type as local Fortran "use ... only"
17058 declaration imports depend on the created type in determine_prefix. */
17060 static struct type
*
17061 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17063 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17064 const char *module_name
;
17067 module_name
= dwarf2_name (die
, cu
);
17068 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17070 return set_die_type (die
, type
, cu
);
17073 /* Read a Fortran module. */
17076 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17078 struct die_info
*child_die
= die
->child
;
17081 type
= read_type_die (die
, cu
);
17082 new_symbol (die
, type
, cu
);
17084 while (child_die
&& child_die
->tag
)
17086 process_die (child_die
, cu
);
17087 child_die
= child_die
->sibling
;
17091 /* Return the name of the namespace represented by DIE. Set
17092 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17095 static const char *
17096 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17098 struct die_info
*current_die
;
17099 const char *name
= NULL
;
17101 /* Loop through the extensions until we find a name. */
17103 for (current_die
= die
;
17104 current_die
!= NULL
;
17105 current_die
= dwarf2_extension (die
, &cu
))
17107 /* We don't use dwarf2_name here so that we can detect the absence
17108 of a name -> anonymous namespace. */
17109 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17115 /* Is it an anonymous namespace? */
17117 *is_anonymous
= (name
== NULL
);
17119 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17124 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17125 the user defined type vector. */
17127 static struct type
*
17128 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17130 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17131 struct comp_unit_head
*cu_header
= &cu
->header
;
17133 struct attribute
*attr_byte_size
;
17134 struct attribute
*attr_address_class
;
17135 int byte_size
, addr_class
;
17136 struct type
*target_type
;
17138 target_type
= die_type (die
, cu
);
17140 /* The die_type call above may have already set the type for this DIE. */
17141 type
= get_die_type (die
, cu
);
17145 type
= lookup_pointer_type (target_type
);
17147 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17148 if (attr_byte_size
)
17149 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17151 byte_size
= cu_header
->addr_size
;
17153 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17154 if (attr_address_class
)
17155 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17157 addr_class
= DW_ADDR_none
;
17159 ULONGEST alignment
= get_alignment (cu
, die
);
17161 /* If the pointer size, alignment, or address class is different
17162 than the default, create a type variant marked as such and set
17163 the length accordingly. */
17164 if (TYPE_LENGTH (type
) != byte_size
17165 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17166 && alignment
!= TYPE_RAW_ALIGN (type
))
17167 || addr_class
!= DW_ADDR_none
)
17169 if (gdbarch_address_class_type_flags_p (gdbarch
))
17171 type_instance_flags type_flags
17172 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17174 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17176 type
= make_type_with_address_space (type
, type_flags
);
17178 else if (TYPE_LENGTH (type
) != byte_size
)
17180 complaint (_("invalid pointer size %d"), byte_size
);
17182 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17184 complaint (_("Invalid DW_AT_alignment"
17185 " - DIE at %s [in module %s]"),
17186 sect_offset_str (die
->sect_off
),
17187 objfile_name (cu
->per_objfile
->objfile
));
17191 /* Should we also complain about unhandled address classes? */
17195 TYPE_LENGTH (type
) = byte_size
;
17196 set_type_align (type
, alignment
);
17197 return set_die_type (die
, type
, cu
);
17200 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17201 the user defined type vector. */
17203 static struct type
*
17204 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17207 struct type
*to_type
;
17208 struct type
*domain
;
17210 to_type
= die_type (die
, cu
);
17211 domain
= die_containing_type (die
, cu
);
17213 /* The calls above may have already set the type for this DIE. */
17214 type
= get_die_type (die
, cu
);
17218 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17219 type
= lookup_methodptr_type (to_type
);
17220 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17222 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17224 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17225 to_type
->fields (), to_type
->num_fields (),
17226 to_type
->has_varargs ());
17227 type
= lookup_methodptr_type (new_type
);
17230 type
= lookup_memberptr_type (to_type
, domain
);
17232 return set_die_type (die
, type
, cu
);
17235 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17236 the user defined type vector. */
17238 static struct type
*
17239 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17240 enum type_code refcode
)
17242 struct comp_unit_head
*cu_header
= &cu
->header
;
17243 struct type
*type
, *target_type
;
17244 struct attribute
*attr
;
17246 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17248 target_type
= die_type (die
, cu
);
17250 /* The die_type call above may have already set the type for this DIE. */
17251 type
= get_die_type (die
, cu
);
17255 type
= lookup_reference_type (target_type
, refcode
);
17256 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17257 if (attr
!= nullptr)
17259 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17263 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17265 maybe_set_alignment (cu
, die
, type
);
17266 return set_die_type (die
, type
, cu
);
17269 /* Add the given cv-qualifiers to the element type of the array. GCC
17270 outputs DWARF type qualifiers that apply to an array, not the
17271 element type. But GDB relies on the array element type to carry
17272 the cv-qualifiers. This mimics section 6.7.3 of the C99
17275 static struct type
*
17276 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17277 struct type
*base_type
, int cnst
, int voltl
)
17279 struct type
*el_type
, *inner_array
;
17281 base_type
= copy_type (base_type
);
17282 inner_array
= base_type
;
17284 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17286 TYPE_TARGET_TYPE (inner_array
) =
17287 copy_type (TYPE_TARGET_TYPE (inner_array
));
17288 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17291 el_type
= TYPE_TARGET_TYPE (inner_array
);
17292 cnst
|= TYPE_CONST (el_type
);
17293 voltl
|= TYPE_VOLATILE (el_type
);
17294 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17296 return set_die_type (die
, base_type
, cu
);
17299 static struct type
*
17300 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17302 struct type
*base_type
, *cv_type
;
17304 base_type
= die_type (die
, cu
);
17306 /* The die_type call above may have already set the type for this DIE. */
17307 cv_type
= get_die_type (die
, cu
);
17311 /* In case the const qualifier is applied to an array type, the element type
17312 is so qualified, not the array type (section 6.7.3 of C99). */
17313 if (base_type
->code () == TYPE_CODE_ARRAY
)
17314 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17316 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17317 return set_die_type (die
, cv_type
, cu
);
17320 static struct type
*
17321 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17323 struct type
*base_type
, *cv_type
;
17325 base_type
= die_type (die
, cu
);
17327 /* The die_type call above may have already set the type for this DIE. */
17328 cv_type
= get_die_type (die
, cu
);
17332 /* In case the volatile qualifier is applied to an array type, the
17333 element type is so qualified, not the array type (section 6.7.3
17335 if (base_type
->code () == TYPE_CODE_ARRAY
)
17336 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17338 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17339 return set_die_type (die
, cv_type
, cu
);
17342 /* Handle DW_TAG_restrict_type. */
17344 static struct type
*
17345 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17347 struct type
*base_type
, *cv_type
;
17349 base_type
= die_type (die
, cu
);
17351 /* The die_type call above may have already set the type for this DIE. */
17352 cv_type
= get_die_type (die
, cu
);
17356 cv_type
= make_restrict_type (base_type
);
17357 return set_die_type (die
, cv_type
, cu
);
17360 /* Handle DW_TAG_atomic_type. */
17362 static struct type
*
17363 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17365 struct type
*base_type
, *cv_type
;
17367 base_type
= die_type (die
, cu
);
17369 /* The die_type call above may have already set the type for this DIE. */
17370 cv_type
= get_die_type (die
, cu
);
17374 cv_type
= make_atomic_type (base_type
);
17375 return set_die_type (die
, cv_type
, cu
);
17378 /* Extract all information from a DW_TAG_string_type DIE and add to
17379 the user defined type vector. It isn't really a user defined type,
17380 but it behaves like one, with other DIE's using an AT_user_def_type
17381 attribute to reference it. */
17383 static struct type
*
17384 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17386 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17387 struct gdbarch
*gdbarch
= objfile
->arch ();
17388 struct type
*type
, *range_type
, *index_type
, *char_type
;
17389 struct attribute
*attr
;
17390 struct dynamic_prop prop
;
17391 bool length_is_constant
= true;
17394 /* There are a couple of places where bit sizes might be made use of
17395 when parsing a DW_TAG_string_type, however, no producer that we know
17396 of make use of these. Handling bit sizes that are a multiple of the
17397 byte size is easy enough, but what about other bit sizes? Lets deal
17398 with that problem when we have to. Warn about these attributes being
17399 unsupported, then parse the type and ignore them like we always
17401 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17402 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17404 static bool warning_printed
= false;
17405 if (!warning_printed
)
17407 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17408 "currently supported on DW_TAG_string_type."));
17409 warning_printed
= true;
17413 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17414 if (attr
!= nullptr && !attr
->form_is_constant ())
17416 /* The string length describes the location at which the length of
17417 the string can be found. The size of the length field can be
17418 specified with one of the attributes below. */
17419 struct type
*prop_type
;
17420 struct attribute
*len
17421 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17422 if (len
== nullptr)
17423 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17424 if (len
!= nullptr && len
->form_is_constant ())
17426 /* Pass 0 as the default as we know this attribute is constant
17427 and the default value will not be returned. */
17428 LONGEST sz
= len
->constant_value (0);
17429 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17433 /* If the size is not specified then we assume it is the size of
17434 an address on this target. */
17435 prop_type
= cu
->addr_sized_int_type (true);
17438 /* Convert the attribute into a dynamic property. */
17439 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17442 length_is_constant
= false;
17444 else if (attr
!= nullptr)
17446 /* This DW_AT_string_length just contains the length with no
17447 indirection. There's no need to create a dynamic property in this
17448 case. Pass 0 for the default value as we know it will not be
17449 returned in this case. */
17450 length
= attr
->constant_value (0);
17452 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17454 /* We don't currently support non-constant byte sizes for strings. */
17455 length
= attr
->constant_value (1);
17459 /* Use 1 as a fallback length if we have nothing else. */
17463 index_type
= objfile_type (objfile
)->builtin_int
;
17464 if (length_is_constant
)
17465 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17468 struct dynamic_prop low_bound
;
17470 low_bound
.set_const_val (1);
17471 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17473 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17474 type
= create_string_type (NULL
, char_type
, range_type
);
17476 return set_die_type (die
, type
, cu
);
17479 /* Assuming that DIE corresponds to a function, returns nonzero
17480 if the function is prototyped. */
17483 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17485 struct attribute
*attr
;
17487 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17488 if (attr
&& attr
->as_boolean ())
17491 /* The DWARF standard implies that the DW_AT_prototyped attribute
17492 is only meaningful for C, but the concept also extends to other
17493 languages that allow unprototyped functions (Eg: Objective C).
17494 For all other languages, assume that functions are always
17496 if (cu
->per_cu
->lang
!= language_c
17497 && cu
->per_cu
->lang
!= language_objc
17498 && cu
->per_cu
->lang
!= language_opencl
)
17501 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17502 prototyped and unprototyped functions; default to prototyped,
17503 since that is more common in modern code (and RealView warns
17504 about unprototyped functions). */
17505 if (producer_is_realview (cu
->producer
))
17511 /* Handle DIES due to C code like:
17515 int (*funcp)(int a, long l);
17519 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17521 static struct type
*
17522 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17524 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17525 struct type
*type
; /* Type that this function returns. */
17526 struct type
*ftype
; /* Function that returns above type. */
17527 struct attribute
*attr
;
17529 type
= die_type (die
, cu
);
17531 /* The die_type call above may have already set the type for this DIE. */
17532 ftype
= get_die_type (die
, cu
);
17536 ftype
= lookup_function_type (type
);
17538 if (prototyped_function_p (die
, cu
))
17539 ftype
->set_is_prototyped (true);
17541 /* Store the calling convention in the type if it's available in
17542 the subroutine die. Otherwise set the calling convention to
17543 the default value DW_CC_normal. */
17544 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17545 if (attr
!= nullptr
17546 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17547 TYPE_CALLING_CONVENTION (ftype
)
17548 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17549 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17550 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17552 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17554 /* Record whether the function returns normally to its caller or not
17555 if the DWARF producer set that information. */
17556 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17557 if (attr
&& attr
->as_boolean ())
17558 TYPE_NO_RETURN (ftype
) = 1;
17560 /* We need to add the subroutine type to the die immediately so
17561 we don't infinitely recurse when dealing with parameters
17562 declared as the same subroutine type. */
17563 set_die_type (die
, ftype
, cu
);
17565 if (die
->child
!= NULL
)
17567 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17568 struct die_info
*child_die
;
17569 int nparams
, iparams
;
17571 /* Count the number of parameters.
17572 FIXME: GDB currently ignores vararg functions, but knows about
17573 vararg member functions. */
17575 child_die
= die
->child
;
17576 while (child_die
&& child_die
->tag
)
17578 if (child_die
->tag
== DW_TAG_formal_parameter
)
17580 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17581 ftype
->set_has_varargs (true);
17583 child_die
= child_die
->sibling
;
17586 /* Allocate storage for parameters and fill them in. */
17587 ftype
->set_num_fields (nparams
);
17589 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17591 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17592 even if we error out during the parameters reading below. */
17593 for (iparams
= 0; iparams
< nparams
; iparams
++)
17594 ftype
->field (iparams
).set_type (void_type
);
17597 child_die
= die
->child
;
17598 while (child_die
&& child_die
->tag
)
17600 if (child_die
->tag
== DW_TAG_formal_parameter
)
17602 struct type
*arg_type
;
17604 /* DWARF version 2 has no clean way to discern C++
17605 static and non-static member functions. G++ helps
17606 GDB by marking the first parameter for non-static
17607 member functions (which is the this pointer) as
17608 artificial. We pass this information to
17609 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17611 DWARF version 3 added DW_AT_object_pointer, which GCC
17612 4.5 does not yet generate. */
17613 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17614 if (attr
!= nullptr)
17615 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17617 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17618 arg_type
= die_type (child_die
, cu
);
17620 /* RealView does not mark THIS as const, which the testsuite
17621 expects. GCC marks THIS as const in method definitions,
17622 but not in the class specifications (GCC PR 43053). */
17623 if (cu
->per_cu
->lang
== language_cplus
17624 && !TYPE_CONST (arg_type
)
17625 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17628 struct dwarf2_cu
*arg_cu
= cu
;
17629 const char *name
= dwarf2_name (child_die
, cu
);
17631 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17632 if (attr
!= nullptr)
17634 /* If the compiler emits this, use it. */
17635 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17638 else if (name
&& strcmp (name
, "this") == 0)
17639 /* Function definitions will have the argument names. */
17641 else if (name
== NULL
&& iparams
== 0)
17642 /* Declarations may not have the names, so like
17643 elsewhere in GDB, assume an artificial first
17644 argument is "this". */
17648 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17652 ftype
->field (iparams
).set_type (arg_type
);
17655 child_die
= child_die
->sibling
;
17662 static struct type
*
17663 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17665 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17666 const char *name
= NULL
;
17667 struct type
*this_type
, *target_type
;
17669 name
= dwarf2_full_name (NULL
, die
, cu
);
17670 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17671 this_type
->set_target_is_stub (true);
17672 set_die_type (die
, this_type
, cu
);
17673 target_type
= die_type (die
, cu
);
17674 if (target_type
!= this_type
)
17675 TYPE_TARGET_TYPE (this_type
) = target_type
;
17678 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17679 spec and cause infinite loops in GDB. */
17680 complaint (_("Self-referential DW_TAG_typedef "
17681 "- DIE at %s [in module %s]"),
17682 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17683 TYPE_TARGET_TYPE (this_type
) = NULL
;
17687 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17688 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17689 Handle these by just returning the target type, rather than
17690 constructing an anonymous typedef type and trying to handle this
17692 set_die_type (die
, target_type
, cu
);
17693 return target_type
;
17698 /* Helper for get_dwarf2_rational_constant that computes the value of
17699 a given gmp_mpz given an attribute. */
17702 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17704 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17705 location expression that pushes an implicit value. */
17706 if (attr
->form
== DW_FORM_exprloc
)
17708 dwarf_block
*blk
= attr
->as_block ();
17709 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17712 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17713 blk
->data
+ blk
->size
,
17715 if (ptr
- blk
->data
+ len
<= blk
->size
)
17717 mpz_import (value
->val
, len
,
17718 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17724 /* On failure set it to 1. */
17725 *value
= gdb_mpz (1);
17727 else if (attr
->form_is_block ())
17729 dwarf_block
*blk
= attr
->as_block ();
17730 mpz_import (value
->val
, blk
->size
,
17731 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17732 1, 0, 0, blk
->data
);
17735 *value
= gdb_mpz (attr
->constant_value (1));
17738 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17739 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17741 If the numerator and/or numerator attribute is missing,
17742 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17746 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17747 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17749 struct attribute
*num_attr
, *denom_attr
;
17751 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17752 if (num_attr
== nullptr)
17753 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17754 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17756 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17757 if (denom_attr
== nullptr)
17758 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17759 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17761 if (num_attr
== nullptr || denom_attr
== nullptr)
17764 get_mpz (cu
, numerator
, num_attr
);
17765 get_mpz (cu
, denominator
, denom_attr
);
17768 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17769 rational constant, rather than a signed one.
17771 If the rational constant has a negative value, a complaint
17772 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17775 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17776 struct dwarf2_cu
*cu
,
17777 gdb_mpz
*numerator
,
17778 gdb_mpz
*denominator
)
17783 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17784 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17786 mpz_neg (num
.val
, num
.val
);
17787 mpz_neg (denom
.val
, denom
.val
);
17789 else if (mpz_sgn (num
.val
) == -1)
17791 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17793 sect_offset_str (die
->sect_off
));
17796 else if (mpz_sgn (denom
.val
) == -1)
17798 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17800 sect_offset_str (die
->sect_off
));
17804 *numerator
= std::move (num
);
17805 *denominator
= std::move (denom
);
17808 /* Assuming that ENCODING is a string whose contents starting at the
17809 K'th character is "_nn" where "nn" is a decimal number, scan that
17810 number and set RESULT to the value. K is updated to point to the
17811 character immediately following the number.
17813 If the string does not conform to the format described above, false
17814 is returned, and K may or may not be changed. */
17817 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17819 /* The next character should be an underscore ('_') followed
17821 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17824 /* Skip the underscore. */
17828 /* Determine the number of digits for our number. */
17829 while (isdigit (encoding
[k
]))
17834 std::string
copy (&encoding
[start
], k
- start
);
17835 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17841 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17842 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17843 DENOM, update OFFSET, and return true on success. Return false on
17847 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17848 gdb_mpz
*num
, gdb_mpz
*denom
)
17850 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17852 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17855 /* Assuming DIE corresponds to a fixed point type, finish the creation
17856 of the corresponding TYPE by setting its type-specific data. CU is
17857 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17858 encodings. It is nullptr if the GNAT encoding should be
17862 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17863 struct die_info
*die
, struct dwarf2_cu
*cu
)
17865 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17866 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17868 /* If GNAT encodings are preferred, don't examine the
17870 struct attribute
*attr
= nullptr;
17871 if (suffix
== nullptr)
17873 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17874 if (attr
== nullptr)
17875 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17876 if (attr
== nullptr)
17877 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17880 /* Numerator and denominator of our fixed-point type's scaling factor.
17881 The default is a scaling factor of 1, which we use as a fallback
17882 when we are not able to decode it (problem with the debugging info,
17883 unsupported forms, bug in GDB, etc...). Using that as the default
17884 allows us to at least print the unscaled value, which might still
17885 be useful to a user. */
17886 gdb_mpz
scale_num (1);
17887 gdb_mpz
scale_denom (1);
17889 if (attr
== nullptr)
17892 if (suffix
!= nullptr
17893 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17895 /* The number might be encoded as _nn_dd_nn_dd, where the
17896 second ratio is the 'small value. In this situation, we
17897 want the second value. */
17898 && (suffix
[offset
] != '_'
17899 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17906 /* Scaling factor not found. Assume a scaling factor of 1,
17907 and hope for the best. At least the user will be able to
17908 see the encoded value. */
17911 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17912 sect_offset_str (die
->sect_off
));
17915 else if (attr
->name
== DW_AT_binary_scale
)
17917 LONGEST scale_exp
= attr
->constant_value (0);
17918 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17920 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17922 else if (attr
->name
== DW_AT_decimal_scale
)
17924 LONGEST scale_exp
= attr
->constant_value (0);
17925 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17927 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17929 else if (attr
->name
== DW_AT_small
)
17931 struct die_info
*scale_die
;
17932 struct dwarf2_cu
*scale_cu
= cu
;
17934 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17935 if (scale_die
->tag
== DW_TAG_constant
)
17936 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17937 &scale_num
, &scale_denom
);
17939 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17941 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17945 complaint (_("unsupported scale attribute %s for fixed-point type"
17947 dwarf_attr_name (attr
->name
),
17948 sect_offset_str (die
->sect_off
));
17951 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17952 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17953 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17954 mpq_canonicalize (scaling_factor
.val
);
17957 /* The gnat-encoding suffix for fixed point. */
17959 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17961 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17962 "XF" suffix of the name. The text after this is what encodes the
17963 'small and 'delta information. Otherwise, return nullptr. */
17965 static const char *
17966 gnat_encoded_fixed_point_type_info (const char *name
)
17968 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17971 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17972 (which may be different from NAME) to the architecture back-end to allow
17973 it to guess the correct format if necessary. */
17975 static struct type
*
17976 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17977 const char *name_hint
, enum bfd_endian byte_order
)
17979 struct gdbarch
*gdbarch
= objfile
->arch ();
17980 const struct floatformat
**format
;
17983 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17985 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17987 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17992 /* Allocate an integer type of size BITS and name NAME. */
17994 static struct type
*
17995 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17996 int bits
, int unsigned_p
, const char *name
)
18000 /* Versions of Intel's C Compiler generate an integer type called "void"
18001 instead of using DW_TAG_unspecified_type. This has been seen on
18002 at least versions 14, 17, and 18. */
18003 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18004 && strcmp (name
, "void") == 0)
18005 type
= objfile_type (objfile
)->builtin_void
;
18007 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18012 /* Return true if DIE has a DW_AT_small attribute whose value is
18013 a constant rational, where both the numerator and denominator
18016 CU is the DIE's Compilation Unit. */
18019 has_zero_over_zero_small_attribute (struct die_info
*die
,
18020 struct dwarf2_cu
*cu
)
18022 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18023 if (attr
== nullptr)
18026 struct dwarf2_cu
*scale_cu
= cu
;
18027 struct die_info
*scale_die
18028 = follow_die_ref (die
, attr
, &scale_cu
);
18030 if (scale_die
->tag
!= DW_TAG_constant
)
18033 gdb_mpz
num (1), denom (1);
18034 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18035 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18038 /* Initialise and return a floating point type of size BITS suitable for
18039 use as a component of a complex number. The NAME_HINT is passed through
18040 when initialising the floating point type and is the name of the complex
18043 As DWARF doesn't currently provide an explicit name for the components
18044 of a complex number, but it can be helpful to have these components
18045 named, we try to select a suitable name based on the size of the
18047 static struct type
*
18048 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18049 struct objfile
*objfile
,
18050 int bits
, const char *name_hint
,
18051 enum bfd_endian byte_order
)
18053 gdbarch
*gdbarch
= objfile
->arch ();
18054 struct type
*tt
= nullptr;
18056 /* Try to find a suitable floating point builtin type of size BITS.
18057 We're going to use the name of this type as the name for the complex
18058 target type that we are about to create. */
18059 switch (cu
->per_cu
->lang
)
18061 case language_fortran
:
18065 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18068 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18070 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18072 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18080 tt
= builtin_type (gdbarch
)->builtin_float
;
18083 tt
= builtin_type (gdbarch
)->builtin_double
;
18085 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18087 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18093 /* If the type we found doesn't match the size we were looking for, then
18094 pretend we didn't find a type at all, the complex target type we
18095 create will then be nameless. */
18096 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18099 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18100 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18103 /* Find a representation of a given base type and install
18104 it in the TYPE field of the die. */
18106 static struct type
*
18107 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18109 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18111 struct attribute
*attr
;
18112 int encoding
= 0, bits
= 0;
18116 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18117 if (attr
!= nullptr && attr
->form_is_constant ())
18118 encoding
= attr
->constant_value (0);
18119 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18120 if (attr
!= nullptr)
18121 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18122 name
= dwarf2_name (die
, cu
);
18124 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18126 arch
= objfile
->arch ();
18127 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18129 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18130 if (attr
!= nullptr && attr
->form_is_constant ())
18132 int endianity
= attr
->constant_value (0);
18137 byte_order
= BFD_ENDIAN_BIG
;
18139 case DW_END_little
:
18140 byte_order
= BFD_ENDIAN_LITTLE
;
18143 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18148 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18149 && cu
->per_cu
->lang
== language_ada
18150 && has_zero_over_zero_small_attribute (die
, cu
))
18152 /* brobecker/2018-02-24: This is a fixed point type for which
18153 the scaling factor is represented as fraction whose value
18154 does not make sense (zero divided by zero), so we should
18155 normally never see these. However, there is a small category
18156 of fixed point types for which GNAT is unable to provide
18157 the scaling factor via the standard DWARF mechanisms, and
18158 for which the info is provided via the GNAT encodings instead.
18159 This is likely what this DIE is about. */
18160 encoding
= (encoding
== DW_ATE_signed_fixed
18162 : DW_ATE_unsigned
);
18165 /* With GNAT encodings, fixed-point information will be encoded in
18166 the type name. Note that this can also occur with the above
18167 zero-over-zero case, which is why this is a separate "if" rather
18168 than an "else if". */
18169 const char *gnat_encoding_suffix
= nullptr;
18170 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18171 && cu
->per_cu
->lang
== language_ada
18172 && name
!= nullptr)
18174 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18175 if (gnat_encoding_suffix
!= nullptr)
18177 gdb_assert (startswith (gnat_encoding_suffix
,
18178 GNAT_FIXED_POINT_SUFFIX
));
18179 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18180 name
, gnat_encoding_suffix
- name
);
18181 /* Use -1 here so that SUFFIX points at the "_" after the
18183 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18185 encoding
= (encoding
== DW_ATE_signed
18186 ? DW_ATE_signed_fixed
18187 : DW_ATE_unsigned_fixed
);
18193 case DW_ATE_address
:
18194 /* Turn DW_ATE_address into a void * pointer. */
18195 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18196 type
= init_pointer_type (objfile
, bits
, name
, type
);
18198 case DW_ATE_boolean
:
18199 type
= init_boolean_type (objfile
, bits
, 1, name
);
18201 case DW_ATE_complex_float
:
18202 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18204 if (type
->code () == TYPE_CODE_ERROR
)
18206 if (name
== nullptr)
18208 struct obstack
*obstack
18209 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18210 name
= obconcat (obstack
, "_Complex ", type
->name (),
18213 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18216 type
= init_complex_type (name
, type
);
18218 case DW_ATE_decimal_float
:
18219 type
= init_decfloat_type (objfile
, bits
, name
);
18222 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18224 case DW_ATE_signed
:
18225 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18227 case DW_ATE_unsigned
:
18228 if (cu
->per_cu
->lang
== language_fortran
18230 && startswith (name
, "character("))
18231 type
= init_character_type (objfile
, bits
, 1, name
);
18233 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18235 case DW_ATE_signed_char
:
18236 if (cu
->per_cu
->lang
== language_ada
18237 || cu
->per_cu
->lang
== language_m2
18238 || cu
->per_cu
->lang
== language_pascal
18239 || cu
->per_cu
->lang
== language_fortran
)
18240 type
= init_character_type (objfile
, bits
, 0, name
);
18242 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18244 case DW_ATE_unsigned_char
:
18245 if (cu
->per_cu
->lang
== language_ada
18246 || cu
->per_cu
->lang
== language_m2
18247 || cu
->per_cu
->lang
== language_pascal
18248 || cu
->per_cu
->lang
== language_fortran
18249 || cu
->per_cu
->lang
== language_rust
)
18250 type
= init_character_type (objfile
, bits
, 1, name
);
18252 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18257 type
= builtin_type (arch
)->builtin_char16
;
18258 else if (bits
== 32)
18259 type
= builtin_type (arch
)->builtin_char32
;
18262 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18264 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18266 return set_die_type (die
, type
, cu
);
18269 case DW_ATE_signed_fixed
:
18270 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18271 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18273 case DW_ATE_unsigned_fixed
:
18274 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18275 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18279 complaint (_("unsupported DW_AT_encoding: '%s'"),
18280 dwarf_type_encoding_name (encoding
));
18281 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18285 if (name
&& strcmp (name
, "char") == 0)
18286 type
->set_has_no_signedness (true);
18288 maybe_set_alignment (cu
, die
, type
);
18290 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18292 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18294 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18295 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18297 unsigned real_bit_size
= attr
->as_unsigned ();
18298 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18299 /* Only use the attributes if they make sense together. */
18300 if (attr
== nullptr
18301 || (attr
->as_unsigned () + real_bit_size
18302 <= 8 * TYPE_LENGTH (type
)))
18304 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18306 if (attr
!= nullptr)
18307 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18308 = attr
->as_unsigned ();
18313 return set_die_type (die
, type
, cu
);
18316 /* A helper function that returns the name of DIE, if it refers to a
18317 variable declaration. */
18319 static const char *
18320 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18322 if (die
->tag
!= DW_TAG_variable
)
18325 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18326 if (attr
== nullptr || !attr
->as_boolean ())
18329 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18330 if (attr
== nullptr)
18332 return attr
->as_string ();
18335 /* Parse dwarf attribute if it's a block, reference or constant and put the
18336 resulting value of the attribute into struct bound_prop.
18337 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18340 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18341 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18342 struct type
*default_type
)
18344 struct dwarf2_property_baton
*baton
;
18345 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18346 struct objfile
*objfile
= per_objfile
->objfile
;
18347 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18349 gdb_assert (default_type
!= NULL
);
18351 if (attr
== NULL
|| prop
== NULL
)
18354 if (attr
->form_is_block ())
18356 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18357 baton
->property_type
= default_type
;
18358 baton
->locexpr
.per_cu
= cu
->per_cu
;
18359 baton
->locexpr
.per_objfile
= per_objfile
;
18361 struct dwarf_block
*block
;
18362 if (attr
->form
== DW_FORM_data16
)
18364 size_t data_size
= 16;
18365 block
= XOBNEW (obstack
, struct dwarf_block
);
18366 block
->size
= (data_size
18367 + 2 /* Extra bytes for DW_OP and arg. */);
18368 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
18369 data
[0] = DW_OP_implicit_value
;
18370 data
[1] = data_size
;
18371 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
18372 block
->data
= data
;
18375 block
= attr
->as_block ();
18377 baton
->locexpr
.size
= block
->size
;
18378 baton
->locexpr
.data
= block
->data
;
18379 switch (attr
->name
)
18381 case DW_AT_string_length
:
18382 baton
->locexpr
.is_reference
= true;
18385 baton
->locexpr
.is_reference
= false;
18389 prop
->set_locexpr (baton
);
18390 gdb_assert (prop
->baton () != NULL
);
18392 else if (attr
->form_is_ref ())
18394 struct dwarf2_cu
*target_cu
= cu
;
18395 struct die_info
*target_die
;
18396 struct attribute
*target_attr
;
18398 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18399 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18400 if (target_attr
== NULL
)
18401 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18403 if (target_attr
== nullptr)
18404 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
18406 if (target_attr
== NULL
)
18408 const char *name
= var_decl_name (target_die
, target_cu
);
18409 if (name
!= nullptr)
18411 prop
->set_variable_name (name
);
18417 switch (target_attr
->name
)
18419 case DW_AT_location
:
18420 if (target_attr
->form_is_section_offset ())
18422 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18423 baton
->property_type
= die_type (target_die
, target_cu
);
18424 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18425 prop
->set_loclist (baton
);
18426 gdb_assert (prop
->baton () != NULL
);
18428 else if (target_attr
->form_is_block ())
18430 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18431 baton
->property_type
= die_type (target_die
, target_cu
);
18432 baton
->locexpr
.per_cu
= cu
->per_cu
;
18433 baton
->locexpr
.per_objfile
= per_objfile
;
18434 struct dwarf_block
*block
= target_attr
->as_block ();
18435 baton
->locexpr
.size
= block
->size
;
18436 baton
->locexpr
.data
= block
->data
;
18437 baton
->locexpr
.is_reference
= true;
18438 prop
->set_locexpr (baton
);
18439 gdb_assert (prop
->baton () != NULL
);
18443 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18444 "dynamic property");
18448 case DW_AT_data_member_location
:
18449 case DW_AT_data_bit_offset
:
18453 if (!handle_member_location (target_die
, target_cu
, &offset
))
18456 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18457 baton
->property_type
= read_type_die (target_die
->parent
,
18459 baton
->offset_info
.offset
= offset
;
18460 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18461 prop
->set_addr_offset (baton
);
18466 else if (attr
->form_is_constant ())
18467 prop
->set_const_val (attr
->constant_value (0));
18470 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18471 dwarf2_name (die
, cu
));
18481 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18483 struct type
*int_type
;
18485 /* Helper macro to examine the various builtin types. */
18486 #define TRY_TYPE(F) \
18487 int_type = (unsigned_p \
18488 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18489 : objfile_type (objfile)->builtin_ ## F); \
18490 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18497 TRY_TYPE (long_long
);
18501 gdb_assert_not_reached ("unable to find suitable integer type");
18504 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18505 present (which is valid) then compute the default type based on the
18506 compilation units address size. */
18508 static struct type
*
18509 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18511 struct type
*index_type
= die_type (die
, cu
);
18513 /* Dwarf-2 specifications explicitly allows to create subrange types
18514 without specifying a base type.
18515 In that case, the base type must be set to the type of
18516 the lower bound, upper bound or count, in that order, if any of these
18517 three attributes references an object that has a type.
18518 If no base type is found, the Dwarf-2 specifications say that
18519 a signed integer type of size equal to the size of an address should
18521 For the following C code: `extern char gdb_int [];'
18522 GCC produces an empty range DIE.
18523 FIXME: muller/2010-05-28: Possible references to object for low bound,
18524 high bound or count are not yet handled by this code. */
18525 if (index_type
->code () == TYPE_CODE_VOID
)
18526 index_type
= cu
->addr_sized_int_type (false);
18531 /* Read the given DW_AT_subrange DIE. */
18533 static struct type
*
18534 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18536 struct type
*base_type
, *orig_base_type
;
18537 struct type
*range_type
;
18538 struct attribute
*attr
;
18539 struct dynamic_prop low
, high
;
18540 int low_default_is_valid
;
18541 int high_bound_is_count
= 0;
18543 ULONGEST negative_mask
;
18545 orig_base_type
= read_subrange_index_type (die
, cu
);
18547 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18548 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18549 creating the range type, but we use the result of check_typedef
18550 when examining properties of the type. */
18551 base_type
= check_typedef (orig_base_type
);
18553 /* The die_type call above may have already set the type for this DIE. */
18554 range_type
= get_die_type (die
, cu
);
18558 high
.set_const_val (0);
18560 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18561 omitting DW_AT_lower_bound. */
18562 switch (cu
->per_cu
->lang
)
18565 case language_cplus
:
18566 low
.set_const_val (0);
18567 low_default_is_valid
= 1;
18569 case language_fortran
:
18570 low
.set_const_val (1);
18571 low_default_is_valid
= 1;
18574 case language_objc
:
18575 case language_rust
:
18576 low
.set_const_val (0);
18577 low_default_is_valid
= (cu
->header
.version
>= 4);
18581 case language_pascal
:
18582 low
.set_const_val (1);
18583 low_default_is_valid
= (cu
->header
.version
>= 4);
18586 low
.set_const_val (0);
18587 low_default_is_valid
= 0;
18591 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18592 if (attr
!= nullptr)
18593 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18594 else if (!low_default_is_valid
)
18595 complaint (_("Missing DW_AT_lower_bound "
18596 "- DIE at %s [in module %s]"),
18597 sect_offset_str (die
->sect_off
),
18598 objfile_name (cu
->per_objfile
->objfile
));
18600 struct attribute
*attr_ub
, *attr_count
;
18601 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18602 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18604 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18605 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18607 /* If bounds are constant do the final calculation here. */
18608 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18609 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18611 high_bound_is_count
= 1;
18615 if (attr_ub
!= NULL
)
18616 complaint (_("Unresolved DW_AT_upper_bound "
18617 "- DIE at %s [in module %s]"),
18618 sect_offset_str (die
->sect_off
),
18619 objfile_name (cu
->per_objfile
->objfile
));
18620 if (attr_count
!= NULL
)
18621 complaint (_("Unresolved DW_AT_count "
18622 "- DIE at %s [in module %s]"),
18623 sect_offset_str (die
->sect_off
),
18624 objfile_name (cu
->per_objfile
->objfile
));
18629 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18630 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18631 bias
= bias_attr
->constant_value (0);
18633 /* Normally, the DWARF producers are expected to use a signed
18634 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18635 But this is unfortunately not always the case, as witnessed
18636 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18637 is used instead. To work around that ambiguity, we treat
18638 the bounds as signed, and thus sign-extend their values, when
18639 the base type is signed. */
18641 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18642 if (low
.kind () == PROP_CONST
18643 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18644 low
.set_const_val (low
.const_val () | negative_mask
);
18645 if (high
.kind () == PROP_CONST
18646 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18647 high
.set_const_val (high
.const_val () | negative_mask
);
18649 /* Check for bit and byte strides. */
18650 struct dynamic_prop byte_stride_prop
;
18651 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18652 if (attr_byte_stride
!= nullptr)
18654 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18655 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18659 struct dynamic_prop bit_stride_prop
;
18660 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18661 if (attr_bit_stride
!= nullptr)
18663 /* It only makes sense to have either a bit or byte stride. */
18664 if (attr_byte_stride
!= nullptr)
18666 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18667 "- DIE at %s [in module %s]"),
18668 sect_offset_str (die
->sect_off
),
18669 objfile_name (cu
->per_objfile
->objfile
));
18670 attr_bit_stride
= nullptr;
18674 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18675 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18680 if (attr_byte_stride
!= nullptr
18681 || attr_bit_stride
!= nullptr)
18683 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18684 struct dynamic_prop
*stride
18685 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18688 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18689 &high
, bias
, stride
, byte_stride_p
);
18692 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18694 if (high_bound_is_count
)
18695 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18697 /* Ada expects an empty array on no boundary attributes. */
18698 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
18699 range_type
->bounds ()->high
.set_undefined ();
18701 name
= dwarf2_name (die
, cu
);
18703 range_type
->set_name (name
);
18705 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18706 if (attr
!= nullptr)
18707 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18709 maybe_set_alignment (cu
, die
, range_type
);
18711 set_die_type (die
, range_type
, cu
);
18713 /* set_die_type should be already done. */
18714 set_descriptive_type (range_type
, die
, cu
);
18719 static struct type
*
18720 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18724 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18725 type
->set_name (dwarf2_name (die
, cu
));
18727 /* In Ada, an unspecified type is typically used when the description
18728 of the type is deferred to a different unit. When encountering
18729 such a type, we treat it as a stub, and try to resolve it later on,
18731 if (cu
->per_cu
->lang
== language_ada
)
18732 type
->set_is_stub (true);
18734 return set_die_type (die
, type
, cu
);
18737 /* Read a single die and all its descendents. Set the die's sibling
18738 field to NULL; set other fields in the die correctly, and set all
18739 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18740 location of the info_ptr after reading all of those dies. PARENT
18741 is the parent of the die in question. */
18743 static struct die_info
*
18744 read_die_and_children (const struct die_reader_specs
*reader
,
18745 const gdb_byte
*info_ptr
,
18746 const gdb_byte
**new_info_ptr
,
18747 struct die_info
*parent
)
18749 struct die_info
*die
;
18750 const gdb_byte
*cur_ptr
;
18752 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18755 *new_info_ptr
= cur_ptr
;
18758 store_in_ref_table (die
, reader
->cu
);
18760 if (die
->has_children
)
18761 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18765 *new_info_ptr
= cur_ptr
;
18768 die
->sibling
= NULL
;
18769 die
->parent
= parent
;
18773 /* Read a die, all of its descendents, and all of its siblings; set
18774 all of the fields of all of the dies correctly. Arguments are as
18775 in read_die_and_children. */
18777 static struct die_info
*
18778 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18779 const gdb_byte
*info_ptr
,
18780 const gdb_byte
**new_info_ptr
,
18781 struct die_info
*parent
)
18783 struct die_info
*first_die
, *last_sibling
;
18784 const gdb_byte
*cur_ptr
;
18786 cur_ptr
= info_ptr
;
18787 first_die
= last_sibling
= NULL
;
18791 struct die_info
*die
18792 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18796 *new_info_ptr
= cur_ptr
;
18803 last_sibling
->sibling
= die
;
18805 last_sibling
= die
;
18809 /* Read a die, all of its descendents, and all of its siblings; set
18810 all of the fields of all of the dies correctly. Arguments are as
18811 in read_die_and_children.
18812 This the main entry point for reading a DIE and all its children. */
18814 static struct die_info
*
18815 read_die_and_siblings (const struct die_reader_specs
*reader
,
18816 const gdb_byte
*info_ptr
,
18817 const gdb_byte
**new_info_ptr
,
18818 struct die_info
*parent
)
18820 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18821 new_info_ptr
, parent
);
18823 if (dwarf_die_debug
)
18825 fprintf_unfiltered (gdb_stdlog
,
18826 "Read die from %s@0x%x of %s:\n",
18827 reader
->die_section
->get_name (),
18828 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18829 bfd_get_filename (reader
->abfd
));
18830 dump_die (die
, dwarf_die_debug
);
18836 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18838 The caller is responsible for filling in the extra attributes
18839 and updating (*DIEP)->num_attrs.
18840 Set DIEP to point to a newly allocated die with its information,
18841 except for its child, sibling, and parent fields. */
18843 static const gdb_byte
*
18844 read_full_die_1 (const struct die_reader_specs
*reader
,
18845 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18846 int num_extra_attrs
)
18848 unsigned int abbrev_number
, bytes_read
, i
;
18849 const struct abbrev_info
*abbrev
;
18850 struct die_info
*die
;
18851 struct dwarf2_cu
*cu
= reader
->cu
;
18852 bfd
*abfd
= reader
->abfd
;
18854 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18855 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18856 info_ptr
+= bytes_read
;
18857 if (!abbrev_number
)
18863 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18865 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18867 bfd_get_filename (abfd
));
18869 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18870 die
->sect_off
= sect_off
;
18871 die
->tag
= abbrev
->tag
;
18872 die
->abbrev
= abbrev_number
;
18873 die
->has_children
= abbrev
->has_children
;
18875 /* Make the result usable.
18876 The caller needs to update num_attrs after adding the extra
18878 die
->num_attrs
= abbrev
->num_attrs
;
18880 bool any_need_reprocess
= false;
18881 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18883 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18885 if (die
->attrs
[i
].requires_reprocessing_p ())
18886 any_need_reprocess
= true;
18889 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18890 if (attr
!= nullptr && attr
->form_is_unsigned ())
18891 cu
->str_offsets_base
= attr
->as_unsigned ();
18893 attr
= die
->attr (DW_AT_loclists_base
);
18894 if (attr
!= nullptr)
18895 cu
->loclist_base
= attr
->as_unsigned ();
18897 auto maybe_addr_base
= die
->addr_base ();
18898 if (maybe_addr_base
.has_value ())
18899 cu
->addr_base
= *maybe_addr_base
;
18901 attr
= die
->attr (DW_AT_rnglists_base
);
18902 if (attr
!= nullptr)
18903 cu
->rnglists_base
= attr
->as_unsigned ();
18905 if (any_need_reprocess
)
18907 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18909 if (die
->attrs
[i
].requires_reprocessing_p ())
18910 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18917 /* Read a die and all its attributes.
18918 Set DIEP to point to a newly allocated die with its information,
18919 except for its child, sibling, and parent fields. */
18921 static const gdb_byte
*
18922 read_full_die (const struct die_reader_specs
*reader
,
18923 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18925 const gdb_byte
*result
;
18927 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18929 if (dwarf_die_debug
)
18931 fprintf_unfiltered (gdb_stdlog
,
18932 "Read die from %s@0x%x of %s:\n",
18933 reader
->die_section
->get_name (),
18934 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18935 bfd_get_filename (reader
->abfd
));
18936 dump_die (*diep
, dwarf_die_debug
);
18943 /* Returns nonzero if TAG represents a type that we might generate a partial
18947 is_type_tag_for_partial (int tag
, enum language lang
)
18952 /* Some types that would be reasonable to generate partial symbols for,
18953 that we don't at present. Note that normally this does not
18954 matter, mainly because C compilers don't give names to these
18955 types, but instead emit DW_TAG_typedef. */
18956 case DW_TAG_file_type
:
18957 case DW_TAG_ptr_to_member_type
:
18958 case DW_TAG_set_type
:
18959 case DW_TAG_string_type
:
18960 case DW_TAG_subroutine_type
:
18963 /* GNAT may emit an array with a name, but no typedef, so we
18964 need to make a symbol in this case. */
18965 case DW_TAG_array_type
:
18966 return lang
== language_ada
;
18968 case DW_TAG_base_type
:
18969 case DW_TAG_class_type
:
18970 case DW_TAG_interface_type
:
18971 case DW_TAG_enumeration_type
:
18972 case DW_TAG_structure_type
:
18973 case DW_TAG_subrange_type
:
18974 case DW_TAG_typedef
:
18975 case DW_TAG_union_type
:
18982 /* Load all DIEs that are interesting for partial symbols into memory. */
18984 static struct partial_die_info
*
18985 load_partial_dies (const struct die_reader_specs
*reader
,
18986 const gdb_byte
*info_ptr
, int building_psymtab
)
18988 struct dwarf2_cu
*cu
= reader
->cu
;
18989 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18990 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18991 unsigned int bytes_read
;
18992 unsigned int load_all
= 0;
18993 int nesting_level
= 1;
18998 gdb_assert (cu
->per_cu
!= NULL
);
18999 if (cu
->load_all_dies
)
19003 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19007 &cu
->comp_unit_obstack
,
19008 hashtab_obstack_allocate
,
19009 dummy_obstack_deallocate
);
19013 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19016 /* A NULL abbrev means the end of a series of children. */
19017 if (abbrev
== NULL
)
19019 if (--nesting_level
== 0)
19022 info_ptr
+= bytes_read
;
19023 last_die
= parent_die
;
19024 parent_die
= parent_die
->die_parent
;
19028 /* Check for template arguments. We never save these; if
19029 they're seen, we just mark the parent, and go on our way. */
19030 if (parent_die
!= NULL
19031 && cu
->per_cu
->lang
== language_cplus
19032 && (abbrev
->tag
== DW_TAG_template_type_param
19033 || abbrev
->tag
== DW_TAG_template_value_param
))
19035 parent_die
->has_template_arguments
= 1;
19039 /* We don't need a partial DIE for the template argument. */
19040 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19045 /* We only recurse into c++ subprograms looking for template arguments.
19046 Skip their other children. */
19048 && cu
->per_cu
->lang
== language_cplus
19049 && parent_die
!= NULL
19050 && parent_die
->tag
== DW_TAG_subprogram
19051 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19053 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19057 /* Check whether this DIE is interesting enough to save. Normally
19058 we would not be interested in members here, but there may be
19059 later variables referencing them via DW_AT_specification (for
19060 static members). */
19062 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
19063 && abbrev
->tag
!= DW_TAG_constant
19064 && abbrev
->tag
!= DW_TAG_enumerator
19065 && abbrev
->tag
!= DW_TAG_subprogram
19066 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19067 && abbrev
->tag
!= DW_TAG_lexical_block
19068 && abbrev
->tag
!= DW_TAG_variable
19069 && abbrev
->tag
!= DW_TAG_namespace
19070 && abbrev
->tag
!= DW_TAG_module
19071 && abbrev
->tag
!= DW_TAG_member
19072 && abbrev
->tag
!= DW_TAG_imported_unit
19073 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19075 /* Otherwise we skip to the next sibling, if any. */
19076 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19080 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19083 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19085 /* This two-pass algorithm for processing partial symbols has a
19086 high cost in cache pressure. Thus, handle some simple cases
19087 here which cover the majority of C partial symbols. DIEs
19088 which neither have specification tags in them, nor could have
19089 specification tags elsewhere pointing at them, can simply be
19090 processed and discarded.
19092 This segment is also optional; scan_partial_symbols and
19093 add_partial_symbol will handle these DIEs if we chain
19094 them in normally. When compilers which do not emit large
19095 quantities of duplicate debug information are more common,
19096 this code can probably be removed. */
19098 /* Any complete simple types at the top level (pretty much all
19099 of them, for a language without namespaces), can be processed
19101 if (parent_die
== NULL
19102 && pdi
.has_specification
== 0
19103 && pdi
.is_declaration
== 0
19104 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19105 || pdi
.tag
== DW_TAG_base_type
19106 || pdi
.tag
== DW_TAG_array_type
19107 || pdi
.tag
== DW_TAG_subrange_type
))
19109 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19110 add_partial_symbol (&pdi
, cu
);
19112 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19116 /* The exception for DW_TAG_typedef with has_children above is
19117 a workaround of GCC PR debug/47510. In the case of this complaint
19118 type_name_or_error will error on such types later.
19120 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19121 it could not find the child DIEs referenced later, this is checked
19122 above. In correct DWARF DW_TAG_typedef should have no children. */
19124 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19125 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19126 "- DIE at %s [in module %s]"),
19127 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19129 /* If we're at the second level, and we're an enumerator, and
19130 our parent has no specification (meaning possibly lives in a
19131 namespace elsewhere), then we can add the partial symbol now
19132 instead of queueing it. */
19133 if (pdi
.tag
== DW_TAG_enumerator
19134 && parent_die
!= NULL
19135 && parent_die
->die_parent
== NULL
19136 && parent_die
->tag
== DW_TAG_enumeration_type
19137 && parent_die
->has_specification
== 0)
19139 if (pdi
.raw_name
== NULL
)
19140 complaint (_("malformed enumerator DIE ignored"));
19141 else if (building_psymtab
)
19142 add_partial_symbol (&pdi
, cu
);
19144 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19148 struct partial_die_info
*part_die
19149 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19151 /* We'll save this DIE so link it in. */
19152 part_die
->die_parent
= parent_die
;
19153 part_die
->die_sibling
= NULL
;
19154 part_die
->die_child
= NULL
;
19156 if (last_die
&& last_die
== parent_die
)
19157 last_die
->die_child
= part_die
;
19159 last_die
->die_sibling
= part_die
;
19161 last_die
= part_die
;
19163 if (first_die
== NULL
)
19164 first_die
= part_die
;
19166 /* Maybe add the DIE to the hash table. Not all DIEs that we
19167 find interesting need to be in the hash table, because we
19168 also have the parent/sibling/child chains; only those that we
19169 might refer to by offset later during partial symbol reading.
19171 For now this means things that might have be the target of a
19172 DW_AT_specification, DW_AT_abstract_origin, or
19173 DW_AT_extension. DW_AT_extension will refer only to
19174 namespaces; DW_AT_abstract_origin refers to functions (and
19175 many things under the function DIE, but we do not recurse
19176 into function DIEs during partial symbol reading) and
19177 possibly variables as well; DW_AT_specification refers to
19178 declarations. Declarations ought to have the DW_AT_declaration
19179 flag. It happens that GCC forgets to put it in sometimes, but
19180 only for functions, not for types.
19182 Adding more things than necessary to the hash table is harmless
19183 except for the performance cost. Adding too few will result in
19184 wasted time in find_partial_die, when we reread the compilation
19185 unit with load_all_dies set. */
19188 || abbrev
->tag
== DW_TAG_constant
19189 || abbrev
->tag
== DW_TAG_subprogram
19190 || abbrev
->tag
== DW_TAG_variable
19191 || abbrev
->tag
== DW_TAG_namespace
19192 || part_die
->is_declaration
)
19196 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19197 to_underlying (part_die
->sect_off
),
19202 /* For some DIEs we want to follow their children (if any). For C
19203 we have no reason to follow the children of structures; for other
19204 languages we have to, so that we can get at method physnames
19205 to infer fully qualified class names, for DW_AT_specification,
19206 and for C++ template arguments. For C++, we also look one level
19207 inside functions to find template arguments (if the name of the
19208 function does not already contain the template arguments).
19210 For Ada and Fortran, we need to scan the children of subprograms
19211 and lexical blocks as well because these languages allow the
19212 definition of nested entities that could be interesting for the
19213 debugger, such as nested subprograms for instance. */
19214 if (last_die
->has_children
19216 || last_die
->tag
== DW_TAG_namespace
19217 || last_die
->tag
== DW_TAG_module
19218 || last_die
->tag
== DW_TAG_enumeration_type
19219 || (cu
->per_cu
->lang
== language_cplus
19220 && last_die
->tag
== DW_TAG_subprogram
19221 && (last_die
->raw_name
== NULL
19222 || strchr (last_die
->raw_name
, '<') == NULL
))
19223 || (cu
->per_cu
->lang
!= language_c
19224 && (last_die
->tag
== DW_TAG_class_type
19225 || last_die
->tag
== DW_TAG_interface_type
19226 || last_die
->tag
== DW_TAG_structure_type
19227 || last_die
->tag
== DW_TAG_union_type
))
19228 || ((cu
->per_cu
->lang
== language_ada
19229 || cu
->per_cu
->lang
== language_fortran
)
19230 && (last_die
->tag
== DW_TAG_subprogram
19231 || last_die
->tag
== DW_TAG_lexical_block
))))
19234 parent_die
= last_die
;
19238 /* Otherwise we skip to the next sibling, if any. */
19239 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19241 /* Back to the top, do it again. */
19245 partial_die_info::partial_die_info (sect_offset sect_off_
,
19246 const struct abbrev_info
*abbrev
)
19247 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19251 /* See class definition. */
19254 partial_die_info::name (dwarf2_cu
*cu
)
19256 if (!canonical_name
&& raw_name
!= nullptr)
19258 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19259 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19260 canonical_name
= 1;
19266 /* Read a minimal amount of information into the minimal die structure.
19267 INFO_PTR should point just after the initial uleb128 of a DIE. */
19270 partial_die_info::read (const struct die_reader_specs
*reader
,
19271 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19273 struct dwarf2_cu
*cu
= reader
->cu
;
19274 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19276 int has_low_pc_attr
= 0;
19277 int has_high_pc_attr
= 0;
19278 int high_pc_relative
= 0;
19280 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19283 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19284 /* String and address offsets that need to do the reprocessing have
19285 already been read at this point, so there is no need to wait until
19286 the loop terminates to do the reprocessing. */
19287 if (attr
.requires_reprocessing_p ())
19288 read_attribute_reprocess (reader
, &attr
, tag
);
19289 /* Store the data if it is of an attribute we want to keep in a
19290 partial symbol table. */
19296 case DW_TAG_compile_unit
:
19297 case DW_TAG_partial_unit
:
19298 case DW_TAG_type_unit
:
19299 /* Compilation units have a DW_AT_name that is a filename, not
19300 a source language identifier. */
19301 case DW_TAG_enumeration_type
:
19302 case DW_TAG_enumerator
:
19303 /* These tags always have simple identifiers already; no need
19304 to canonicalize them. */
19305 canonical_name
= 1;
19306 raw_name
= attr
.as_string ();
19309 canonical_name
= 0;
19310 raw_name
= attr
.as_string ();
19314 case DW_AT_linkage_name
:
19315 case DW_AT_MIPS_linkage_name
:
19316 /* Note that both forms of linkage name might appear. We
19317 assume they will be the same, and we only store the last
19319 linkage_name
= attr
.as_string ();
19322 has_low_pc_attr
= 1;
19323 lowpc
= attr
.as_address ();
19325 case DW_AT_high_pc
:
19326 has_high_pc_attr
= 1;
19327 highpc
= attr
.as_address ();
19328 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19329 high_pc_relative
= 1;
19331 case DW_AT_location
:
19332 /* Support the .debug_loc offsets. */
19333 if (attr
.form_is_block ())
19335 d
.locdesc
= attr
.as_block ();
19337 else if (attr
.form_is_section_offset ())
19339 dwarf2_complex_location_expr_complaint ();
19343 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19344 "partial symbol information");
19347 case DW_AT_external
:
19348 is_external
= attr
.as_boolean ();
19350 case DW_AT_declaration
:
19351 is_declaration
= attr
.as_boolean ();
19356 case DW_AT_abstract_origin
:
19357 case DW_AT_specification
:
19358 case DW_AT_extension
:
19359 has_specification
= 1;
19360 spec_offset
= attr
.get_ref_die_offset ();
19361 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19362 || cu
->per_cu
->is_dwz
);
19364 case DW_AT_sibling
:
19365 /* Ignore absolute siblings, they might point outside of
19366 the current compile unit. */
19367 if (attr
.form
== DW_FORM_ref_addr
)
19368 complaint (_("ignoring absolute DW_AT_sibling"));
19371 const gdb_byte
*buffer
= reader
->buffer
;
19372 sect_offset off
= attr
.get_ref_die_offset ();
19373 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19375 if (sibling_ptr
< info_ptr
)
19376 complaint (_("DW_AT_sibling points backwards"));
19377 else if (sibling_ptr
> reader
->buffer_end
)
19378 reader
->die_section
->overflow_complaint ();
19380 sibling
= sibling_ptr
;
19383 case DW_AT_byte_size
:
19386 case DW_AT_const_value
:
19387 has_const_value
= 1;
19389 case DW_AT_calling_convention
:
19390 /* DWARF doesn't provide a way to identify a program's source-level
19391 entry point. DW_AT_calling_convention attributes are only meant
19392 to describe functions' calling conventions.
19394 However, because it's a necessary piece of information in
19395 Fortran, and before DWARF 4 DW_CC_program was the only
19396 piece of debugging information whose definition refers to
19397 a 'main program' at all, several compilers marked Fortran
19398 main programs with DW_CC_program --- even when those
19399 functions use the standard calling conventions.
19401 Although DWARF now specifies a way to provide this
19402 information, we support this practice for backward
19404 if (attr
.constant_value (0) == DW_CC_program
19405 && cu
->per_cu
->lang
== language_fortran
)
19406 main_subprogram
= 1;
19410 LONGEST value
= attr
.constant_value (-1);
19411 if (value
== DW_INL_inlined
19412 || value
== DW_INL_declared_inlined
)
19413 may_be_inlined
= 1;
19418 if (tag
== DW_TAG_imported_unit
)
19420 d
.sect_off
= attr
.get_ref_die_offset ();
19421 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19422 || cu
->per_cu
->is_dwz
);
19426 case DW_AT_main_subprogram
:
19427 main_subprogram
= attr
.as_boolean ();
19432 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19433 on DWARF version). */
19434 ranges_offset
= attr
.as_unsigned ();
19436 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19438 if (tag
!= DW_TAG_compile_unit
)
19439 ranges_offset
+= cu
->gnu_ranges_base
;
19441 has_range_info
= 1;
19450 /* For Ada, if both the name and the linkage name appear, we prefer
19451 the latter. This lets "catch exception" work better, regardless
19452 of the order in which the name and linkage name were emitted.
19453 Really, though, this is just a workaround for the fact that gdb
19454 doesn't store both the name and the linkage name. */
19455 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
19456 raw_name
= linkage_name
;
19458 if (high_pc_relative
)
19461 if (has_low_pc_attr
&& has_high_pc_attr
)
19463 /* When using the GNU linker, .gnu.linkonce. sections are used to
19464 eliminate duplicate copies of functions and vtables and such.
19465 The linker will arbitrarily choose one and discard the others.
19466 The AT_*_pc values for such functions refer to local labels in
19467 these sections. If the section from that file was discarded, the
19468 labels are not in the output, so the relocs get a value of 0.
19469 If this is a discarded function, mark the pc bounds as invalid,
19470 so that GDB will ignore it. */
19471 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19473 struct objfile
*objfile
= per_objfile
->objfile
;
19474 struct gdbarch
*gdbarch
= objfile
->arch ();
19476 complaint (_("DW_AT_low_pc %s is zero "
19477 "for DIE at %s [in module %s]"),
19478 paddress (gdbarch
, lowpc
),
19479 sect_offset_str (sect_off
),
19480 objfile_name (objfile
));
19482 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19483 else if (lowpc
>= highpc
)
19485 struct objfile
*objfile
= per_objfile
->objfile
;
19486 struct gdbarch
*gdbarch
= objfile
->arch ();
19488 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19489 "for DIE at %s [in module %s]"),
19490 paddress (gdbarch
, lowpc
),
19491 paddress (gdbarch
, highpc
),
19492 sect_offset_str (sect_off
),
19493 objfile_name (objfile
));
19502 /* Find a cached partial DIE at OFFSET in CU. */
19504 struct partial_die_info
*
19505 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19507 struct partial_die_info
*lookup_die
= NULL
;
19508 struct partial_die_info
part_die (sect_off
);
19510 lookup_die
= ((struct partial_die_info
*)
19511 htab_find_with_hash (partial_dies
, &part_die
,
19512 to_underlying (sect_off
)));
19517 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19518 except in the case of .debug_types DIEs which do not reference
19519 outside their CU (they do however referencing other types via
19520 DW_FORM_ref_sig8). */
19522 static const struct cu_partial_die_info
19523 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19525 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19526 struct objfile
*objfile
= per_objfile
->objfile
;
19527 struct partial_die_info
*pd
= NULL
;
19529 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19530 && cu
->header
.offset_in_cu_p (sect_off
))
19532 pd
= cu
->find_partial_die (sect_off
);
19535 /* We missed recording what we needed.
19536 Load all dies and try again. */
19540 /* TUs don't reference other CUs/TUs (except via type signatures). */
19541 if (cu
->per_cu
->is_debug_types
)
19543 error (_("Dwarf Error: Type Unit at offset %s contains"
19544 " external reference to offset %s [in module %s].\n"),
19545 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19546 bfd_get_filename (objfile
->obfd
));
19548 dwarf2_per_cu_data
*per_cu
19549 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19552 cu
= per_objfile
->get_cu (per_cu
);
19553 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19554 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19556 cu
= per_objfile
->get_cu (per_cu
);
19559 pd
= cu
->find_partial_die (sect_off
);
19562 /* If we didn't find it, and not all dies have been loaded,
19563 load them all and try again. */
19565 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19567 cu
->load_all_dies
= 1;
19569 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19570 THIS_CU->cu may already be in use. So we can't just free it and
19571 replace its DIEs with the ones we read in. Instead, we leave those
19572 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19573 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19575 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19577 pd
= cu
->find_partial_die (sect_off
);
19581 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19582 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19586 /* See if we can figure out if the class lives in a namespace. We do
19587 this by looking for a member function; its demangled name will
19588 contain namespace info, if there is any. */
19591 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19592 struct dwarf2_cu
*cu
)
19594 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19595 what template types look like, because the demangler
19596 frequently doesn't give the same name as the debug info. We
19597 could fix this by only using the demangled name to get the
19598 prefix (but see comment in read_structure_type). */
19600 struct partial_die_info
*real_pdi
;
19601 struct partial_die_info
*child_pdi
;
19603 /* If this DIE (this DIE's specification, if any) has a parent, then
19604 we should not do this. We'll prepend the parent's fully qualified
19605 name when we create the partial symbol. */
19607 real_pdi
= struct_pdi
;
19608 while (real_pdi
->has_specification
)
19610 auto res
= find_partial_die (real_pdi
->spec_offset
,
19611 real_pdi
->spec_is_dwz
, cu
);
19612 real_pdi
= res
.pdi
;
19616 if (real_pdi
->die_parent
!= NULL
)
19619 for (child_pdi
= struct_pdi
->die_child
;
19621 child_pdi
= child_pdi
->die_sibling
)
19623 if (child_pdi
->tag
== DW_TAG_subprogram
19624 && child_pdi
->linkage_name
!= NULL
)
19626 gdb::unique_xmalloc_ptr
<char> actual_class_name
19627 (cu
->language_defn
->class_name_from_physname
19628 (child_pdi
->linkage_name
));
19629 if (actual_class_name
!= NULL
)
19631 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19632 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19633 struct_pdi
->canonical_name
= 1;
19640 /* Return true if a DIE with TAG may have the DW_AT_const_value
19644 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19648 case DW_TAG_constant
:
19649 case DW_TAG_enumerator
:
19650 case DW_TAG_formal_parameter
:
19651 case DW_TAG_template_value_param
:
19652 case DW_TAG_variable
:
19660 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19662 /* Once we've fixed up a die, there's no point in doing so again.
19663 This also avoids a memory leak if we were to call
19664 guess_partial_die_structure_name multiple times. */
19668 /* If we found a reference attribute and the DIE has no name, try
19669 to find a name in the referred to DIE. */
19671 if (raw_name
== NULL
&& has_specification
)
19673 struct partial_die_info
*spec_die
;
19675 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19676 spec_die
= res
.pdi
;
19679 spec_die
->fixup (cu
);
19681 if (spec_die
->raw_name
)
19683 raw_name
= spec_die
->raw_name
;
19684 canonical_name
= spec_die
->canonical_name
;
19686 /* Copy DW_AT_external attribute if it is set. */
19687 if (spec_die
->is_external
)
19688 is_external
= spec_die
->is_external
;
19692 if (!has_const_value
&& has_specification
19693 && can_have_DW_AT_const_value_p (tag
))
19695 struct partial_die_info
*spec_die
;
19697 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19698 spec_die
= res
.pdi
;
19701 spec_die
->fixup (cu
);
19703 if (spec_die
->has_const_value
)
19705 /* Copy DW_AT_const_value attribute if it is set. */
19706 has_const_value
= spec_die
->has_const_value
;
19710 /* Set default names for some unnamed DIEs. */
19712 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19714 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19715 canonical_name
= 1;
19718 /* If there is no parent die to provide a namespace, and there are
19719 children, see if we can determine the namespace from their linkage
19721 if (cu
->per_cu
->lang
== language_cplus
19722 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19723 && die_parent
== NULL
19725 && (tag
== DW_TAG_class_type
19726 || tag
== DW_TAG_structure_type
19727 || tag
== DW_TAG_union_type
))
19728 guess_partial_die_structure_name (this, cu
);
19730 /* GCC might emit a nameless struct or union that has a linkage
19731 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19732 if (raw_name
== NULL
19733 && (tag
== DW_TAG_class_type
19734 || tag
== DW_TAG_interface_type
19735 || tag
== DW_TAG_structure_type
19736 || tag
== DW_TAG_union_type
)
19737 && linkage_name
!= NULL
)
19739 gdb::unique_xmalloc_ptr
<char> demangled
19740 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19741 if (demangled
!= nullptr)
19745 /* Strip any leading namespaces/classes, keep only the base name.
19746 DW_AT_name for named DIEs does not contain the prefixes. */
19747 base
= strrchr (demangled
.get (), ':');
19748 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19751 base
= demangled
.get ();
19753 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19754 raw_name
= objfile
->intern (base
);
19755 canonical_name
= 1;
19762 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19763 contents from the given SECTION in the HEADER.
19765 HEADER_OFFSET is the offset of the header in the section. */
19767 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19768 struct dwarf2_section_info
*section
,
19769 sect_offset header_offset
)
19771 unsigned int bytes_read
;
19772 bfd
*abfd
= section
->get_bfd_owner ();
19773 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19775 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19776 info_ptr
+= bytes_read
;
19778 header
->version
= read_2_bytes (abfd
, info_ptr
);
19781 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19784 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19787 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19790 /* Return the DW_AT_loclists_base value for the CU. */
19792 lookup_loclist_base (struct dwarf2_cu
*cu
)
19794 /* For the .dwo unit, the loclist_base points to the first offset following
19795 the header. The header consists of the following entities-
19796 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19798 2. version (2 bytes)
19799 3. address size (1 byte)
19800 4. segment selector size (1 byte)
19801 5. offset entry count (4 bytes)
19802 These sizes are derived as per the DWARFv5 standard. */
19803 if (cu
->dwo_unit
!= nullptr)
19805 if (cu
->header
.initial_length_size
== 4)
19806 return LOCLIST_HEADER_SIZE32
;
19807 return LOCLIST_HEADER_SIZE64
;
19809 return cu
->loclist_base
;
19812 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19813 array of offsets in the .debug_loclists section. */
19816 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19818 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19819 struct objfile
*objfile
= per_objfile
->objfile
;
19820 bfd
*abfd
= objfile
->obfd
;
19821 ULONGEST loclist_header_size
=
19822 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19823 : LOCLIST_HEADER_SIZE64
);
19824 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19826 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19827 ULONGEST start_offset
=
19828 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19830 /* Get loclists section. */
19831 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19833 /* Read the loclists section content. */
19834 section
->read (objfile
);
19835 if (section
->buffer
== NULL
)
19836 error (_("DW_FORM_loclistx used without .debug_loclists "
19837 "section [in module %s]"), objfile_name (objfile
));
19839 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19840 so if loclist_base is smaller than the header size, we have a problem. */
19841 if (loclist_base
< loclist_header_size
)
19842 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19843 objfile_name (objfile
));
19845 /* Read the header of the loclists contribution. */
19846 struct loclists_rnglists_header header
;
19847 read_loclists_rnglists_header (&header
, section
,
19848 (sect_offset
) (loclist_base
- loclist_header_size
));
19850 /* Verify the loclist index is valid. */
19851 if (loclist_index
>= header
.offset_entry_count
)
19852 error (_("DW_FORM_loclistx pointing outside of "
19853 ".debug_loclists offset array [in module %s]"),
19854 objfile_name (objfile
));
19856 /* Validate that reading won't go beyond the end of the section. */
19857 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19858 error (_("Reading DW_FORM_loclistx index beyond end of"
19859 ".debug_loclists section [in module %s]"),
19860 objfile_name (objfile
));
19862 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19864 if (cu
->header
.offset_size
== 4)
19865 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19867 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19870 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19871 array of offsets in the .debug_rnglists section. */
19874 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19877 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19878 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19879 bfd
*abfd
= objfile
->obfd
;
19880 ULONGEST rnglist_header_size
=
19881 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19882 : RNGLIST_HEADER_SIZE64
);
19884 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19885 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19887 ULONGEST rnglist_base
=
19888 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19890 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19891 ULONGEST start_offset
=
19892 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19894 /* Get rnglists section. */
19895 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19897 /* Read the rnglists section content. */
19898 section
->read (objfile
);
19899 if (section
->buffer
== nullptr)
19900 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19902 objfile_name (objfile
));
19904 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19905 so if rnglist_base is smaller than the header size, we have a problem. */
19906 if (rnglist_base
< rnglist_header_size
)
19907 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19908 objfile_name (objfile
));
19910 /* Read the header of the rnglists contribution. */
19911 struct loclists_rnglists_header header
;
19912 read_loclists_rnglists_header (&header
, section
,
19913 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19915 /* Verify the rnglist index is valid. */
19916 if (rnglist_index
>= header
.offset_entry_count
)
19917 error (_("DW_FORM_rnglistx index pointing outside of "
19918 ".debug_rnglists offset array [in module %s]"),
19919 objfile_name (objfile
));
19921 /* Validate that reading won't go beyond the end of the section. */
19922 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19923 error (_("Reading DW_FORM_rnglistx index beyond end of"
19924 ".debug_rnglists section [in module %s]"),
19925 objfile_name (objfile
));
19927 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19929 if (cu
->header
.offset_size
== 4)
19930 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19932 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19935 /* Process the attributes that had to be skipped in the first round. These
19936 attributes are the ones that need str_offsets_base or addr_base attributes.
19937 They could not have been processed in the first round, because at the time
19938 the values of str_offsets_base or addr_base may not have been known. */
19940 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19941 struct attribute
*attr
, dwarf_tag tag
)
19943 struct dwarf2_cu
*cu
= reader
->cu
;
19944 switch (attr
->form
)
19946 case DW_FORM_addrx
:
19947 case DW_FORM_GNU_addr_index
:
19948 attr
->set_address (read_addr_index (cu
,
19949 attr
->as_unsigned_reprocess ()));
19951 case DW_FORM_loclistx
:
19953 sect_offset loclists_sect_off
19954 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19956 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19959 case DW_FORM_rnglistx
:
19961 sect_offset rnglists_sect_off
19962 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19964 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19968 case DW_FORM_strx1
:
19969 case DW_FORM_strx2
:
19970 case DW_FORM_strx3
:
19971 case DW_FORM_strx4
:
19972 case DW_FORM_GNU_str_index
:
19974 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19975 gdb_assert (!attr
->canonical_string_p ());
19976 if (reader
->dwo_file
!= NULL
)
19977 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19980 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19985 gdb_assert_not_reached (_("Unexpected DWARF form."));
19989 /* Read an attribute value described by an attribute form. */
19991 static const gdb_byte
*
19992 read_attribute_value (const struct die_reader_specs
*reader
,
19993 struct attribute
*attr
, unsigned form
,
19994 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19996 struct dwarf2_cu
*cu
= reader
->cu
;
19997 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19998 struct objfile
*objfile
= per_objfile
->objfile
;
19999 bfd
*abfd
= reader
->abfd
;
20000 struct comp_unit_head
*cu_header
= &cu
->header
;
20001 unsigned int bytes_read
;
20002 struct dwarf_block
*blk
;
20004 attr
->form
= (enum dwarf_form
) form
;
20007 case DW_FORM_ref_addr
:
20008 if (cu_header
->version
== 2)
20009 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20012 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20014 info_ptr
+= bytes_read
;
20016 case DW_FORM_GNU_ref_alt
:
20017 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20019 info_ptr
+= bytes_read
;
20023 struct gdbarch
*gdbarch
= objfile
->arch ();
20024 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20025 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20026 attr
->set_address (addr
);
20027 info_ptr
+= bytes_read
;
20030 case DW_FORM_block2
:
20031 blk
= dwarf_alloc_block (cu
);
20032 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20034 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20035 info_ptr
+= blk
->size
;
20036 attr
->set_block (blk
);
20038 case DW_FORM_block4
:
20039 blk
= dwarf_alloc_block (cu
);
20040 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20042 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20043 info_ptr
+= blk
->size
;
20044 attr
->set_block (blk
);
20046 case DW_FORM_data2
:
20047 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20050 case DW_FORM_data4
:
20051 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20054 case DW_FORM_data8
:
20055 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20058 case DW_FORM_data16
:
20059 blk
= dwarf_alloc_block (cu
);
20061 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20063 attr
->set_block (blk
);
20065 case DW_FORM_sec_offset
:
20066 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20068 info_ptr
+= bytes_read
;
20070 case DW_FORM_loclistx
:
20072 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20074 info_ptr
+= bytes_read
;
20077 case DW_FORM_string
:
20078 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20080 info_ptr
+= bytes_read
;
20083 if (!cu
->per_cu
->is_dwz
)
20085 attr
->set_string_noncanonical
20086 (read_indirect_string (per_objfile
,
20087 abfd
, info_ptr
, cu_header
,
20089 info_ptr
+= bytes_read
;
20093 case DW_FORM_line_strp
:
20094 if (!cu
->per_cu
->is_dwz
)
20096 attr
->set_string_noncanonical
20097 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20099 info_ptr
+= bytes_read
;
20103 case DW_FORM_GNU_strp_alt
:
20105 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20106 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20109 attr
->set_string_noncanonical
20110 (dwz
->read_string (objfile
, str_offset
));
20111 info_ptr
+= bytes_read
;
20114 case DW_FORM_exprloc
:
20115 case DW_FORM_block
:
20116 blk
= dwarf_alloc_block (cu
);
20117 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20118 info_ptr
+= bytes_read
;
20119 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20120 info_ptr
+= blk
->size
;
20121 attr
->set_block (blk
);
20123 case DW_FORM_block1
:
20124 blk
= dwarf_alloc_block (cu
);
20125 blk
->size
= read_1_byte (abfd
, info_ptr
);
20127 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20128 info_ptr
+= blk
->size
;
20129 attr
->set_block (blk
);
20131 case DW_FORM_data1
:
20133 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20136 case DW_FORM_flag_present
:
20137 attr
->set_unsigned (1);
20139 case DW_FORM_sdata
:
20140 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20141 info_ptr
+= bytes_read
;
20143 case DW_FORM_rnglistx
:
20145 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20147 info_ptr
+= bytes_read
;
20150 case DW_FORM_udata
:
20151 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20152 info_ptr
+= bytes_read
;
20155 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20156 + read_1_byte (abfd
, info_ptr
)));
20160 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20161 + read_2_bytes (abfd
, info_ptr
)));
20165 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20166 + read_4_bytes (abfd
, info_ptr
)));
20170 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20171 + read_8_bytes (abfd
, info_ptr
)));
20174 case DW_FORM_ref_sig8
:
20175 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20178 case DW_FORM_ref_udata
:
20179 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20180 + read_unsigned_leb128 (abfd
, info_ptr
,
20182 info_ptr
+= bytes_read
;
20184 case DW_FORM_indirect
:
20185 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20186 info_ptr
+= bytes_read
;
20187 if (form
== DW_FORM_implicit_const
)
20189 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20190 info_ptr
+= bytes_read
;
20192 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20195 case DW_FORM_implicit_const
:
20196 attr
->set_signed (implicit_const
);
20198 case DW_FORM_addrx
:
20199 case DW_FORM_GNU_addr_index
:
20200 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20202 info_ptr
+= bytes_read
;
20205 case DW_FORM_strx1
:
20206 case DW_FORM_strx2
:
20207 case DW_FORM_strx3
:
20208 case DW_FORM_strx4
:
20209 case DW_FORM_GNU_str_index
:
20211 ULONGEST str_index
;
20212 if (form
== DW_FORM_strx1
)
20214 str_index
= read_1_byte (abfd
, info_ptr
);
20217 else if (form
== DW_FORM_strx2
)
20219 str_index
= read_2_bytes (abfd
, info_ptr
);
20222 else if (form
== DW_FORM_strx3
)
20224 str_index
= read_3_bytes (abfd
, info_ptr
);
20227 else if (form
== DW_FORM_strx4
)
20229 str_index
= read_4_bytes (abfd
, info_ptr
);
20234 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20235 info_ptr
+= bytes_read
;
20237 attr
->set_unsigned_reprocess (str_index
);
20241 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20242 dwarf_form_name (form
),
20243 bfd_get_filename (abfd
));
20247 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20248 attr
->form
= DW_FORM_GNU_ref_alt
;
20250 /* We have seen instances where the compiler tried to emit a byte
20251 size attribute of -1 which ended up being encoded as an unsigned
20252 0xffffffff. Although 0xffffffff is technically a valid size value,
20253 an object of this size seems pretty unlikely so we can relatively
20254 safely treat these cases as if the size attribute was invalid and
20255 treat them as zero by default. */
20256 if (attr
->name
== DW_AT_byte_size
20257 && form
== DW_FORM_data4
20258 && attr
->as_unsigned () >= 0xffffffff)
20261 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20262 hex_string (attr
->as_unsigned ()));
20263 attr
->set_unsigned (0);
20269 /* Read an attribute described by an abbreviated attribute. */
20271 static const gdb_byte
*
20272 read_attribute (const struct die_reader_specs
*reader
,
20273 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20274 const gdb_byte
*info_ptr
)
20276 attr
->name
= abbrev
->name
;
20277 attr
->string_is_canonical
= 0;
20278 attr
->requires_reprocessing
= 0;
20279 return read_attribute_value (reader
, attr
, abbrev
->form
,
20280 abbrev
->implicit_const
, info_ptr
);
20283 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20285 static const char *
20286 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20287 LONGEST str_offset
)
20289 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20290 str_offset
, "DW_FORM_strp");
20293 /* Return pointer to string at .debug_str offset as read from BUF.
20294 BUF is assumed to be in a compilation unit described by CU_HEADER.
20295 Return *BYTES_READ_PTR count of bytes read from BUF. */
20297 static const char *
20298 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20299 const gdb_byte
*buf
,
20300 const struct comp_unit_head
*cu_header
,
20301 unsigned int *bytes_read_ptr
)
20303 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20305 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20311 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20312 const struct comp_unit_head
*cu_header
,
20313 unsigned int *bytes_read_ptr
)
20315 bfd
*abfd
= objfile
->obfd
;
20316 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20318 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20321 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20322 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20323 ADDR_SIZE is the size of addresses from the CU header. */
20326 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20327 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20329 struct objfile
*objfile
= per_objfile
->objfile
;
20330 bfd
*abfd
= objfile
->obfd
;
20331 const gdb_byte
*info_ptr
;
20332 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20334 per_objfile
->per_bfd
->addr
.read (objfile
);
20335 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20336 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20337 objfile_name (objfile
));
20338 if (addr_base_or_zero
+ addr_index
* addr_size
20339 >= per_objfile
->per_bfd
->addr
.size
)
20340 error (_("DW_FORM_addr_index pointing outside of "
20341 ".debug_addr section [in module %s]"),
20342 objfile_name (objfile
));
20343 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20344 + addr_index
* addr_size
);
20345 if (addr_size
== 4)
20346 return bfd_get_32 (abfd
, info_ptr
);
20348 return bfd_get_64 (abfd
, info_ptr
);
20351 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20354 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20356 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20357 cu
->addr_base
, cu
->header
.addr_size
);
20360 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20363 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20364 unsigned int *bytes_read
)
20366 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20367 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20369 return read_addr_index (cu
, addr_index
);
20375 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20376 dwarf2_per_objfile
*per_objfile
,
20377 unsigned int addr_index
)
20379 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20380 gdb::optional
<ULONGEST
> addr_base
;
20383 /* We need addr_base and addr_size.
20384 If we don't have PER_CU->cu, we have to get it.
20385 Nasty, but the alternative is storing the needed info in PER_CU,
20386 which at this point doesn't seem justified: it's not clear how frequently
20387 it would get used and it would increase the size of every PER_CU.
20388 Entry points like dwarf2_per_cu_addr_size do a similar thing
20389 so we're not in uncharted territory here.
20390 Alas we need to be a bit more complicated as addr_base is contained
20393 We don't need to read the entire CU(/TU).
20394 We just need the header and top level die.
20396 IWBN to use the aging mechanism to let us lazily later discard the CU.
20397 For now we skip this optimization. */
20401 addr_base
= cu
->addr_base
;
20402 addr_size
= cu
->header
.addr_size
;
20406 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20407 addr_base
= reader
.cu
->addr_base
;
20408 addr_size
= reader
.cu
->header
.addr_size
;
20411 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20414 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20415 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20418 static const char *
20419 read_str_index (struct dwarf2_cu
*cu
,
20420 struct dwarf2_section_info
*str_section
,
20421 struct dwarf2_section_info
*str_offsets_section
,
20422 ULONGEST str_offsets_base
, ULONGEST str_index
)
20424 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20425 struct objfile
*objfile
= per_objfile
->objfile
;
20426 const char *objf_name
= objfile_name (objfile
);
20427 bfd
*abfd
= objfile
->obfd
;
20428 const gdb_byte
*info_ptr
;
20429 ULONGEST str_offset
;
20430 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20432 str_section
->read (objfile
);
20433 str_offsets_section
->read (objfile
);
20434 if (str_section
->buffer
== NULL
)
20435 error (_("%s used without %s section"
20436 " in CU at offset %s [in module %s]"),
20437 form_name
, str_section
->get_name (),
20438 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20439 if (str_offsets_section
->buffer
== NULL
)
20440 error (_("%s used without %s section"
20441 " in CU at offset %s [in module %s]"),
20442 form_name
, str_section
->get_name (),
20443 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20444 info_ptr
= (str_offsets_section
->buffer
20446 + str_index
* cu
->header
.offset_size
);
20447 if (cu
->header
.offset_size
== 4)
20448 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20450 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20451 if (str_offset
>= str_section
->size
)
20452 error (_("Offset from %s pointing outside of"
20453 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20454 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20455 return (const char *) (str_section
->buffer
+ str_offset
);
20458 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20460 static const char *
20461 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20463 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20464 ? reader
->cu
->header
.addr_size
: 0;
20465 return read_str_index (reader
->cu
,
20466 &reader
->dwo_file
->sections
.str
,
20467 &reader
->dwo_file
->sections
.str_offsets
,
20468 str_offsets_base
, str_index
);
20471 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20473 static const char *
20474 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20476 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20477 const char *objf_name
= objfile_name (objfile
);
20478 static const char form_name
[] = "DW_FORM_GNU_str_index";
20479 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20481 if (!cu
->str_offsets_base
.has_value ())
20482 error (_("%s used in Fission stub without %s"
20483 " in CU at offset 0x%lx [in module %s]"),
20484 form_name
, str_offsets_attr_name
,
20485 (long) cu
->header
.offset_size
, objf_name
);
20487 return read_str_index (cu
,
20488 &cu
->per_objfile
->per_bfd
->str
,
20489 &cu
->per_objfile
->per_bfd
->str_offsets
,
20490 *cu
->str_offsets_base
, str_index
);
20493 /* Return the length of an LEB128 number in BUF. */
20496 leb128_size (const gdb_byte
*buf
)
20498 const gdb_byte
*begin
= buf
;
20504 if ((byte
& 128) == 0)
20505 return buf
- begin
;
20509 static enum language
20510 dwarf_lang_to_enum_language (unsigned int lang
)
20512 enum language language
;
20521 language
= language_c
;
20524 case DW_LANG_C_plus_plus
:
20525 case DW_LANG_C_plus_plus_11
:
20526 case DW_LANG_C_plus_plus_14
:
20527 language
= language_cplus
;
20530 language
= language_d
;
20532 case DW_LANG_Fortran77
:
20533 case DW_LANG_Fortran90
:
20534 case DW_LANG_Fortran95
:
20535 case DW_LANG_Fortran03
:
20536 case DW_LANG_Fortran08
:
20537 language
= language_fortran
;
20540 language
= language_go
;
20542 case DW_LANG_Mips_Assembler
:
20543 language
= language_asm
;
20545 case DW_LANG_Ada83
:
20546 case DW_LANG_Ada95
:
20547 language
= language_ada
;
20549 case DW_LANG_Modula2
:
20550 language
= language_m2
;
20552 case DW_LANG_Pascal83
:
20553 language
= language_pascal
;
20556 language
= language_objc
;
20559 case DW_LANG_Rust_old
:
20560 language
= language_rust
;
20562 case DW_LANG_OpenCL
:
20563 language
= language_opencl
;
20565 case DW_LANG_Cobol74
:
20566 case DW_LANG_Cobol85
:
20568 language
= language_minimal
;
20575 /* Return the named attribute or NULL if not there. */
20577 static struct attribute
*
20578 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20583 struct attribute
*spec
= NULL
;
20585 for (i
= 0; i
< die
->num_attrs
; ++i
)
20587 if (die
->attrs
[i
].name
== name
)
20588 return &die
->attrs
[i
];
20589 if (die
->attrs
[i
].name
== DW_AT_specification
20590 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20591 spec
= &die
->attrs
[i
];
20597 die
= follow_die_ref (die
, spec
, &cu
);
20603 /* Return the string associated with a string-typed attribute, or NULL if it
20604 is either not found or is of an incorrect type. */
20606 static const char *
20607 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20609 struct attribute
*attr
;
20610 const char *str
= NULL
;
20612 attr
= dwarf2_attr (die
, name
, cu
);
20616 str
= attr
->as_string ();
20617 if (str
== nullptr)
20618 complaint (_("string type expected for attribute %s for "
20619 "DIE at %s in module %s"),
20620 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20621 objfile_name (cu
->per_objfile
->objfile
));
20627 /* Return the dwo name or NULL if not present. If present, it is in either
20628 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20629 static const char *
20630 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20632 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20633 if (dwo_name
== nullptr)
20634 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20638 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20639 and holds a non-zero value. This function should only be used for
20640 DW_FORM_flag or DW_FORM_flag_present attributes. */
20643 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20645 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20647 return attr
!= nullptr && attr
->as_boolean ();
20651 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20653 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20654 which value is non-zero. However, we have to be careful with
20655 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20656 (via dwarf2_flag_true_p) follows this attribute. So we may
20657 end up accidently finding a declaration attribute that belongs
20658 to a different DIE referenced by the specification attribute,
20659 even though the given DIE does not have a declaration attribute. */
20660 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20661 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20664 /* Return the die giving the specification for DIE, if there is
20665 one. *SPEC_CU is the CU containing DIE on input, and the CU
20666 containing the return value on output. If there is no
20667 specification, but there is an abstract origin, that is
20670 static struct die_info
*
20671 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20673 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20676 if (spec_attr
== NULL
)
20677 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20679 if (spec_attr
== NULL
)
20682 return follow_die_ref (die
, spec_attr
, spec_cu
);
20685 /* A convenience function to find the proper .debug_line section for a CU. */
20687 static struct dwarf2_section_info
*
20688 get_debug_line_section (struct dwarf2_cu
*cu
)
20690 struct dwarf2_section_info
*section
;
20691 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20693 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20695 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20696 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20697 else if (cu
->per_cu
->is_dwz
)
20699 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20701 section
= &dwz
->line
;
20704 section
= &per_objfile
->per_bfd
->line
;
20709 /* Read the statement program header starting at OFFSET in
20710 .debug_line, or .debug_line.dwo. Return a pointer
20711 to a struct line_header, allocated using xmalloc.
20712 Returns NULL if there is a problem reading the header, e.g., if it
20713 has a version we don't understand.
20715 NOTE: the strings in the include directory and file name tables of
20716 the returned object point into the dwarf line section buffer,
20717 and must not be freed. */
20719 static line_header_up
20720 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20722 struct dwarf2_section_info
*section
;
20723 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20725 section
= get_debug_line_section (cu
);
20726 section
->read (per_objfile
->objfile
);
20727 if (section
->buffer
== NULL
)
20729 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20730 complaint (_("missing .debug_line.dwo section"));
20732 complaint (_("missing .debug_line section"));
20736 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20737 per_objfile
, section
, &cu
->header
);
20740 /* Subroutine of dwarf_decode_lines to simplify it.
20741 Return the file name for the given file_entry.
20742 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
20743 If space for the result is malloc'd, *NAME_HOLDER will be set.
20744 Returns NULL if FILE_INDEX should be ignored, i.e., it is
20745 equivalent to CU_INFO. */
20747 static const char *
20748 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20749 const file_and_directory
&cu_info
,
20750 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20752 const char *include_name
= fe
.name
;
20753 const char *include_name_to_compare
= include_name
;
20755 const char *dir_name
= fe
.include_dir (lh
);
20757 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20758 if (!IS_ABSOLUTE_PATH (include_name
)
20759 && (dir_name
!= NULL
|| cu_info
.comp_dir
!= NULL
))
20761 /* Avoid creating a duplicate name for CU_INFO.
20762 We do this by comparing INCLUDE_NAME and CU_INFO.
20763 Before we do the comparison, however, we need to account
20764 for DIR_NAME and COMP_DIR.
20765 First prepend dir_name (if non-NULL). If we still don't
20766 have an absolute path prepend comp_dir (if non-NULL).
20767 However, the directory we record in the include-file's
20768 psymtab does not contain COMP_DIR (to match the
20769 corresponding symtab(s)).
20774 bash$ gcc -g ./hello.c
20775 include_name = "hello.c"
20777 DW_AT_comp_dir = comp_dir = "/tmp"
20778 DW_AT_name = "./hello.c"
20782 if (dir_name
!= NULL
)
20784 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20785 include_name
, (char *) NULL
));
20786 include_name
= name_holder
->get ();
20787 include_name_to_compare
= include_name
;
20789 if (!IS_ABSOLUTE_PATH (include_name
) && cu_info
.comp_dir
!= nullptr)
20791 hold_compare
.reset (concat (cu_info
.comp_dir
, SLASH_STRING
,
20792 include_name
, (char *) NULL
));
20793 include_name_to_compare
= hold_compare
.get ();
20797 gdb::unique_xmalloc_ptr
<char> copied_name
;
20798 const char *cu_filename
= cu_info
.name
;
20799 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.comp_dir
!= nullptr)
20801 copied_name
.reset (concat (cu_info
.comp_dir
, SLASH_STRING
,
20802 cu_filename
, (char *) NULL
));
20803 cu_filename
= copied_name
.get ();
20806 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
20808 return include_name
;
20811 /* State machine to track the state of the line number program. */
20813 class lnp_state_machine
20816 /* Initialize a machine state for the start of a line number
20818 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20819 bool record_lines_p
);
20821 file_entry
*current_file ()
20823 /* lh->file_names is 0-based, but the file name numbers in the
20824 statement program are 1-based. */
20825 return m_line_header
->file_name_at (m_file
);
20828 /* Record the line in the state machine. END_SEQUENCE is true if
20829 we're processing the end of a sequence. */
20830 void record_line (bool end_sequence
);
20832 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20833 nop-out rest of the lines in this sequence. */
20834 void check_line_address (struct dwarf2_cu
*cu
,
20835 const gdb_byte
*line_ptr
,
20836 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20838 void handle_set_discriminator (unsigned int discriminator
)
20840 m_discriminator
= discriminator
;
20841 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20844 /* Handle DW_LNE_set_address. */
20845 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20848 address
+= baseaddr
;
20849 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20852 /* Handle DW_LNS_advance_pc. */
20853 void handle_advance_pc (CORE_ADDR adjust
);
20855 /* Handle a special opcode. */
20856 void handle_special_opcode (unsigned char op_code
);
20858 /* Handle DW_LNS_advance_line. */
20859 void handle_advance_line (int line_delta
)
20861 advance_line (line_delta
);
20864 /* Handle DW_LNS_set_file. */
20865 void handle_set_file (file_name_index file
);
20867 /* Handle DW_LNS_negate_stmt. */
20868 void handle_negate_stmt ()
20870 m_is_stmt
= !m_is_stmt
;
20873 /* Handle DW_LNS_const_add_pc. */
20874 void handle_const_add_pc ();
20876 /* Handle DW_LNS_fixed_advance_pc. */
20877 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20879 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20883 /* Handle DW_LNS_copy. */
20884 void handle_copy ()
20886 record_line (false);
20887 m_discriminator
= 0;
20890 /* Handle DW_LNE_end_sequence. */
20891 void handle_end_sequence ()
20893 m_currently_recording_lines
= true;
20897 /* Advance the line by LINE_DELTA. */
20898 void advance_line (int line_delta
)
20900 m_line
+= line_delta
;
20902 if (line_delta
!= 0)
20903 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20906 struct dwarf2_cu
*m_cu
;
20908 gdbarch
*m_gdbarch
;
20910 /* True if we're recording lines.
20911 Otherwise we're building partial symtabs and are just interested in
20912 finding include files mentioned by the line number program. */
20913 bool m_record_lines_p
;
20915 /* The line number header. */
20916 line_header
*m_line_header
;
20918 /* These are part of the standard DWARF line number state machine,
20919 and initialized according to the DWARF spec. */
20921 unsigned char m_op_index
= 0;
20922 /* The line table index of the current file. */
20923 file_name_index m_file
= 1;
20924 unsigned int m_line
= 1;
20926 /* These are initialized in the constructor. */
20928 CORE_ADDR m_address
;
20930 unsigned int m_discriminator
;
20932 /* Additional bits of state we need to track. */
20934 /* The last file that we called dwarf2_start_subfile for.
20935 This is only used for TLLs. */
20936 unsigned int m_last_file
= 0;
20937 /* The last file a line number was recorded for. */
20938 struct subfile
*m_last_subfile
= NULL
;
20940 /* The address of the last line entry. */
20941 CORE_ADDR m_last_address
;
20943 /* Set to true when a previous line at the same address (using
20944 m_last_address) had m_is_stmt true. This is reset to false when a
20945 line entry at a new address (m_address different to m_last_address) is
20947 bool m_stmt_at_address
= false;
20949 /* When true, record the lines we decode. */
20950 bool m_currently_recording_lines
= false;
20952 /* The last line number that was recorded, used to coalesce
20953 consecutive entries for the same line. This can happen, for
20954 example, when discriminators are present. PR 17276. */
20955 unsigned int m_last_line
= 0;
20956 bool m_line_has_non_zero_discriminator
= false;
20960 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20962 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20963 / m_line_header
->maximum_ops_per_instruction
)
20964 * m_line_header
->minimum_instruction_length
);
20965 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20966 m_op_index
= ((m_op_index
+ adjust
)
20967 % m_line_header
->maximum_ops_per_instruction
);
20971 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20973 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20974 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20975 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20976 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20977 / m_line_header
->maximum_ops_per_instruction
)
20978 * m_line_header
->minimum_instruction_length
);
20979 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20980 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20981 % m_line_header
->maximum_ops_per_instruction
);
20983 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20984 advance_line (line_delta
);
20985 record_line (false);
20986 m_discriminator
= 0;
20990 lnp_state_machine::handle_set_file (file_name_index file
)
20994 const file_entry
*fe
= current_file ();
20996 dwarf2_debug_line_missing_file_complaint ();
20997 else if (m_record_lines_p
)
20999 const char *dir
= fe
->include_dir (m_line_header
);
21001 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21002 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21003 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21008 lnp_state_machine::handle_const_add_pc ()
21011 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21014 = (((m_op_index
+ adjust
)
21015 / m_line_header
->maximum_ops_per_instruction
)
21016 * m_line_header
->minimum_instruction_length
);
21018 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21019 m_op_index
= ((m_op_index
+ adjust
)
21020 % m_line_header
->maximum_ops_per_instruction
);
21023 /* Return non-zero if we should add LINE to the line number table.
21024 LINE is the line to add, LAST_LINE is the last line that was added,
21025 LAST_SUBFILE is the subfile for LAST_LINE.
21026 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21027 had a non-zero discriminator.
21029 We have to be careful in the presence of discriminators.
21030 E.g., for this line:
21032 for (i = 0; i < 100000; i++);
21034 clang can emit four line number entries for that one line,
21035 each with a different discriminator.
21036 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21038 However, we want gdb to coalesce all four entries into one.
21039 Otherwise the user could stepi into the middle of the line and
21040 gdb would get confused about whether the pc really was in the
21041 middle of the line.
21043 Things are further complicated by the fact that two consecutive
21044 line number entries for the same line is a heuristic used by gcc
21045 to denote the end of the prologue. So we can't just discard duplicate
21046 entries, we have to be selective about it. The heuristic we use is
21047 that we only collapse consecutive entries for the same line if at least
21048 one of those entries has a non-zero discriminator. PR 17276.
21050 Note: Addresses in the line number state machine can never go backwards
21051 within one sequence, thus this coalescing is ok. */
21054 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21055 unsigned int line
, unsigned int last_line
,
21056 int line_has_non_zero_discriminator
,
21057 struct subfile
*last_subfile
)
21059 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21061 if (line
!= last_line
)
21063 /* Same line for the same file that we've seen already.
21064 As a last check, for pr 17276, only record the line if the line
21065 has never had a non-zero discriminator. */
21066 if (!line_has_non_zero_discriminator
)
21071 /* Use the CU's builder to record line number LINE beginning at
21072 address ADDRESS in the line table of subfile SUBFILE. */
21075 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21076 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21077 struct dwarf2_cu
*cu
)
21079 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21081 if (dwarf_line_debug
)
21083 fprintf_unfiltered (gdb_stdlog
,
21084 "Recording line %u, file %s, address %s\n",
21085 line
, lbasename (subfile
->name
),
21086 paddress (gdbarch
, address
));
21090 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21093 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21094 Mark the end of a set of line number records.
21095 The arguments are the same as for dwarf_record_line_1.
21096 If SUBFILE is NULL the request is ignored. */
21099 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21100 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21102 if (subfile
== NULL
)
21105 if (dwarf_line_debug
)
21107 fprintf_unfiltered (gdb_stdlog
,
21108 "Finishing current line, file %s, address %s\n",
21109 lbasename (subfile
->name
),
21110 paddress (gdbarch
, address
));
21113 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21117 lnp_state_machine::record_line (bool end_sequence
)
21119 if (dwarf_line_debug
)
21121 fprintf_unfiltered (gdb_stdlog
,
21122 "Processing actual line %u: file %u,"
21123 " address %s, is_stmt %u, discrim %u%s\n",
21125 paddress (m_gdbarch
, m_address
),
21126 m_is_stmt
, m_discriminator
,
21127 (end_sequence
? "\t(end sequence)" : ""));
21130 file_entry
*fe
= current_file ();
21133 dwarf2_debug_line_missing_file_complaint ();
21134 /* For now we ignore lines not starting on an instruction boundary.
21135 But not when processing end_sequence for compatibility with the
21136 previous version of the code. */
21137 else if (m_op_index
== 0 || end_sequence
)
21139 fe
->included_p
= true;
21140 if (m_record_lines_p
)
21142 /* When we switch files we insert an end maker in the first file,
21143 switch to the second file and add a new line entry. The
21144 problem is that the end marker inserted in the first file will
21145 discard any previous line entries at the same address. If the
21146 line entries in the first file are marked as is-stmt, while
21147 the new line in the second file is non-stmt, then this means
21148 the end marker will discard is-stmt lines so we can have a
21149 non-stmt line. This means that there are less addresses at
21150 which the user can insert a breakpoint.
21152 To improve this we track the last address in m_last_address,
21153 and whether we have seen an is-stmt at this address. Then
21154 when switching files, if we have seen a stmt at the current
21155 address, and we are switching to create a non-stmt line, then
21156 discard the new line. */
21158 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21159 bool ignore_this_line
21160 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21161 && !m_is_stmt
&& m_stmt_at_address
)
21162 || (!end_sequence
&& m_line
== 0));
21164 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21166 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21167 m_currently_recording_lines
? m_cu
: nullptr);
21170 if (!end_sequence
&& !ignore_this_line
)
21172 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21174 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21175 m_line_has_non_zero_discriminator
,
21178 buildsym_compunit
*builder
= m_cu
->get_builder ();
21179 dwarf_record_line_1 (m_gdbarch
,
21180 builder
->get_current_subfile (),
21181 m_line
, m_address
, is_stmt
,
21182 m_currently_recording_lines
? m_cu
: nullptr);
21184 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21185 m_last_line
= m_line
;
21190 /* Track whether we have seen any m_is_stmt true at m_address in case we
21191 have multiple line table entries all at m_address. */
21192 if (m_last_address
!= m_address
)
21194 m_stmt_at_address
= false;
21195 m_last_address
= m_address
;
21197 m_stmt_at_address
|= m_is_stmt
;
21200 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21201 line_header
*lh
, bool record_lines_p
)
21205 m_record_lines_p
= record_lines_p
;
21206 m_line_header
= lh
;
21208 m_currently_recording_lines
= true;
21210 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21211 was a line entry for it so that the backend has a chance to adjust it
21212 and also record it in case it needs it. This is currently used by MIPS
21213 code, cf. `mips_adjust_dwarf2_line'. */
21214 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21215 m_is_stmt
= lh
->default_is_stmt
;
21216 m_discriminator
= 0;
21218 m_last_address
= m_address
;
21219 m_stmt_at_address
= false;
21223 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21224 const gdb_byte
*line_ptr
,
21225 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21227 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21228 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21229 located at 0x0. In this case, additionally check that if
21230 ADDRESS < UNRELOCATED_LOWPC. */
21232 if ((address
== 0 && address
< unrelocated_lowpc
)
21233 || address
== (CORE_ADDR
) -1)
21235 /* This line table is for a function which has been
21236 GCd by the linker. Ignore it. PR gdb/12528 */
21238 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21239 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21241 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21242 line_offset
, objfile_name (objfile
));
21243 m_currently_recording_lines
= false;
21244 /* Note: m_currently_recording_lines is left as false until we see
21245 DW_LNE_end_sequence. */
21249 /* Subroutine of dwarf_decode_lines to simplify it.
21250 Process the line number information in LH.
21251 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21252 program in order to set included_p for every referenced header. */
21255 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21256 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21258 const gdb_byte
*line_ptr
, *extended_end
;
21259 const gdb_byte
*line_end
;
21260 unsigned int bytes_read
, extended_len
;
21261 unsigned char op_code
, extended_op
;
21262 CORE_ADDR baseaddr
;
21263 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21264 bfd
*abfd
= objfile
->obfd
;
21265 struct gdbarch
*gdbarch
= objfile
->arch ();
21266 /* True if we're recording line info (as opposed to building partial
21267 symtabs and just interested in finding include files mentioned by
21268 the line number program). */
21269 bool record_lines_p
= !decode_for_pst_p
;
21271 baseaddr
= objfile
->text_section_offset ();
21273 line_ptr
= lh
->statement_program_start
;
21274 line_end
= lh
->statement_program_end
;
21276 /* Read the statement sequences until there's nothing left. */
21277 while (line_ptr
< line_end
)
21279 /* The DWARF line number program state machine. Reset the state
21280 machine at the start of each sequence. */
21281 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21282 bool end_sequence
= false;
21284 if (record_lines_p
)
21286 /* Start a subfile for the current file of the state
21288 const file_entry
*fe
= state_machine
.current_file ();
21291 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21294 /* Decode the table. */
21295 while (line_ptr
< line_end
&& !end_sequence
)
21297 op_code
= read_1_byte (abfd
, line_ptr
);
21300 if (op_code
>= lh
->opcode_base
)
21302 /* Special opcode. */
21303 state_machine
.handle_special_opcode (op_code
);
21305 else switch (op_code
)
21307 case DW_LNS_extended_op
:
21308 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21310 line_ptr
+= bytes_read
;
21311 extended_end
= line_ptr
+ extended_len
;
21312 extended_op
= read_1_byte (abfd
, line_ptr
);
21314 if (DW_LNE_lo_user
<= extended_op
21315 && extended_op
<= DW_LNE_hi_user
)
21317 /* Vendor extension, ignore. */
21318 line_ptr
= extended_end
;
21321 switch (extended_op
)
21323 case DW_LNE_end_sequence
:
21324 state_machine
.handle_end_sequence ();
21325 end_sequence
= true;
21327 case DW_LNE_set_address
:
21330 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21331 line_ptr
+= bytes_read
;
21333 state_machine
.check_line_address (cu
, line_ptr
,
21334 lowpc
- baseaddr
, address
);
21335 state_machine
.handle_set_address (baseaddr
, address
);
21338 case DW_LNE_define_file
:
21340 const char *cur_file
;
21341 unsigned int mod_time
, length
;
21344 cur_file
= read_direct_string (abfd
, line_ptr
,
21346 line_ptr
+= bytes_read
;
21347 dindex
= (dir_index
)
21348 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21349 line_ptr
+= bytes_read
;
21351 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21352 line_ptr
+= bytes_read
;
21354 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21355 line_ptr
+= bytes_read
;
21356 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21359 case DW_LNE_set_discriminator
:
21361 /* The discriminator is not interesting to the
21362 debugger; just ignore it. We still need to
21363 check its value though:
21364 if there are consecutive entries for the same
21365 (non-prologue) line we want to coalesce them.
21368 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21369 line_ptr
+= bytes_read
;
21371 state_machine
.handle_set_discriminator (discr
);
21375 complaint (_("mangled .debug_line section"));
21378 /* Make sure that we parsed the extended op correctly. If e.g.
21379 we expected a different address size than the producer used,
21380 we may have read the wrong number of bytes. */
21381 if (line_ptr
!= extended_end
)
21383 complaint (_("mangled .debug_line section"));
21388 state_machine
.handle_copy ();
21390 case DW_LNS_advance_pc
:
21393 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21394 line_ptr
+= bytes_read
;
21396 state_machine
.handle_advance_pc (adjust
);
21399 case DW_LNS_advance_line
:
21402 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21403 line_ptr
+= bytes_read
;
21405 state_machine
.handle_advance_line (line_delta
);
21408 case DW_LNS_set_file
:
21410 file_name_index file
21411 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21413 line_ptr
+= bytes_read
;
21415 state_machine
.handle_set_file (file
);
21418 case DW_LNS_set_column
:
21419 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21420 line_ptr
+= bytes_read
;
21422 case DW_LNS_negate_stmt
:
21423 state_machine
.handle_negate_stmt ();
21425 case DW_LNS_set_basic_block
:
21427 /* Add to the address register of the state machine the
21428 address increment value corresponding to special opcode
21429 255. I.e., this value is scaled by the minimum
21430 instruction length since special opcode 255 would have
21431 scaled the increment. */
21432 case DW_LNS_const_add_pc
:
21433 state_machine
.handle_const_add_pc ();
21435 case DW_LNS_fixed_advance_pc
:
21437 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21440 state_machine
.handle_fixed_advance_pc (addr_adj
);
21445 /* Unknown standard opcode, ignore it. */
21448 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21450 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21451 line_ptr
+= bytes_read
;
21458 dwarf2_debug_line_missing_end_sequence_complaint ();
21460 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21461 in which case we still finish recording the last line). */
21462 state_machine
.record_line (true);
21466 /* Decode the Line Number Program (LNP) for the given line_header
21467 structure and CU. The actual information extracted and the type
21468 of structures created from the LNP depends on the value of PST.
21470 1. If PST is NULL, then this procedure uses the data from the program
21471 to create all necessary symbol tables, and their linetables.
21473 2. If PST is not NULL, this procedure reads the program to determine
21474 the list of files included by the unit represented by PST, and
21475 builds all the associated partial symbol tables.
21477 FND holds the CU file name and directory, if known.
21478 It is used for relative paths in the line table.
21480 NOTE: It is important that psymtabs have the same file name (via
21481 strcmp) as the corresponding symtab. Since the directory is not
21482 used in the name of the symtab we don't use it in the name of the
21483 psymtabs we create. E.g. expand_line_sal requires this when
21484 finding psymtabs to expand. A good testcase for this is
21487 LOWPC is the lowest address in CU (or 0 if not known).
21489 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21490 for its PC<->lines mapping information. Otherwise only the filename
21491 table is read in. */
21494 dwarf_decode_lines (struct line_header
*lh
, const file_and_directory
&fnd
,
21495 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21496 CORE_ADDR lowpc
, int decode_mapping
)
21498 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21499 const int decode_for_pst_p
= (pst
!= NULL
);
21501 if (decode_mapping
)
21502 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21504 if (decode_for_pst_p
)
21506 /* Now that we're done scanning the Line Header Program, we can
21507 create the psymtab of each included file. */
21508 for (auto &file_entry
: lh
->file_names ())
21509 if (file_entry
.included_p
)
21511 gdb::unique_xmalloc_ptr
<char> name_holder
;
21512 const char *include_name
=
21513 compute_include_file_name (lh
, file_entry
, fnd
, &name_holder
);
21514 if (include_name
!= NULL
)
21515 dwarf2_create_include_psymtab
21516 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21517 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21523 /* Make sure a symtab is created for every file, even files
21524 which contain only variables (i.e. no code with associated
21526 buildsym_compunit
*builder
= cu
->get_builder ();
21527 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21529 for (auto &fe
: lh
->file_names ())
21531 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21532 if (builder
->get_current_subfile ()->symtab
== NULL
)
21534 builder
->get_current_subfile ()->symtab
21535 = allocate_symtab (cust
,
21536 builder
->get_current_subfile ()->name
);
21538 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21543 /* Start a subfile for DWARF. FILENAME is the name of the file and
21544 DIRNAME the name of the source directory which contains FILENAME
21545 or NULL if not known.
21546 This routine tries to keep line numbers from identical absolute and
21547 relative file names in a common subfile.
21549 Using the `list' example from the GDB testsuite, which resides in
21550 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21551 of /srcdir/list0.c yields the following debugging information for list0.c:
21553 DW_AT_name: /srcdir/list0.c
21554 DW_AT_comp_dir: /compdir
21555 files.files[0].name: list0.h
21556 files.files[0].dir: /srcdir
21557 files.files[1].name: list0.c
21558 files.files[1].dir: /srcdir
21560 The line number information for list0.c has to end up in a single
21561 subfile, so that `break /srcdir/list0.c:1' works as expected.
21562 start_subfile will ensure that this happens provided that we pass the
21563 concatenation of files.files[1].dir and files.files[1].name as the
21567 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21568 const char *dirname
)
21570 gdb::unique_xmalloc_ptr
<char> copy
;
21572 /* In order not to lose the line information directory,
21573 we concatenate it to the filename when it makes sense.
21574 Note that the Dwarf3 standard says (speaking of filenames in line
21575 information): ``The directory index is ignored for file names
21576 that represent full path names''. Thus ignoring dirname in the
21577 `else' branch below isn't an issue. */
21579 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21581 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21582 filename
= copy
.get ();
21585 cu
->get_builder ()->start_subfile (filename
);
21589 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21590 struct dwarf2_cu
*cu
)
21592 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21593 struct comp_unit_head
*cu_header
= &cu
->header
;
21595 /* NOTE drow/2003-01-30: There used to be a comment and some special
21596 code here to turn a symbol with DW_AT_external and a
21597 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21598 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21599 with some versions of binutils) where shared libraries could have
21600 relocations against symbols in their debug information - the
21601 minimal symbol would have the right address, but the debug info
21602 would not. It's no longer necessary, because we will explicitly
21603 apply relocations when we read in the debug information now. */
21605 /* A DW_AT_location attribute with no contents indicates that a
21606 variable has been optimized away. */
21607 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21609 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21613 /* Handle one degenerate form of location expression specially, to
21614 preserve GDB's previous behavior when section offsets are
21615 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21616 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21618 if (attr
->form_is_block ())
21620 struct dwarf_block
*block
= attr
->as_block ();
21622 if ((block
->data
[0] == DW_OP_addr
21623 && block
->size
== 1 + cu_header
->addr_size
)
21624 || ((block
->data
[0] == DW_OP_GNU_addr_index
21625 || block
->data
[0] == DW_OP_addrx
)
21627 == 1 + leb128_size (&block
->data
[1]))))
21629 unsigned int dummy
;
21631 if (block
->data
[0] == DW_OP_addr
)
21632 SET_SYMBOL_VALUE_ADDRESS
21633 (sym
, cu
->header
.read_address (objfile
->obfd
,
21637 SET_SYMBOL_VALUE_ADDRESS
21638 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21640 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21641 fixup_symbol_section (sym
, objfile
);
21642 SET_SYMBOL_VALUE_ADDRESS
21644 SYMBOL_VALUE_ADDRESS (sym
)
21645 + objfile
->section_offsets
[sym
->section_index ()]);
21650 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21651 expression evaluator, and use LOC_COMPUTED only when necessary
21652 (i.e. when the value of a register or memory location is
21653 referenced, or a thread-local block, etc.). Then again, it might
21654 not be worthwhile. I'm assuming that it isn't unless performance
21655 or memory numbers show me otherwise. */
21657 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21659 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21660 cu
->has_loclist
= true;
21663 /* Given a pointer to a DWARF information entry, figure out if we need
21664 to make a symbol table entry for it, and if so, create a new entry
21665 and return a pointer to it.
21666 If TYPE is NULL, determine symbol type from the die, otherwise
21667 used the passed type.
21668 If SPACE is not NULL, use it to hold the new symbol. If it is
21669 NULL, allocate a new symbol on the objfile's obstack. */
21671 static struct symbol
*
21672 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21673 struct symbol
*space
)
21675 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21676 struct objfile
*objfile
= per_objfile
->objfile
;
21677 struct gdbarch
*gdbarch
= objfile
->arch ();
21678 struct symbol
*sym
= NULL
;
21680 struct attribute
*attr
= NULL
;
21681 struct attribute
*attr2
= NULL
;
21682 CORE_ADDR baseaddr
;
21683 struct pending
**list_to_add
= NULL
;
21685 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21687 baseaddr
= objfile
->text_section_offset ();
21689 name
= dwarf2_name (die
, cu
);
21692 int suppress_add
= 0;
21697 sym
= new (&objfile
->objfile_obstack
) symbol
;
21698 OBJSTAT (objfile
, n_syms
++);
21700 /* Cache this symbol's name and the name's demangled form (if any). */
21701 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
21702 /* Fortran does not have mangling standard and the mangling does differ
21703 between gfortran, iFort etc. */
21704 const char *physname
21705 = (cu
->per_cu
->lang
== language_fortran
21706 ? dwarf2_full_name (name
, die
, cu
)
21707 : dwarf2_physname (name
, die
, cu
));
21708 const char *linkagename
= dw2_linkage_name (die
, cu
);
21710 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
21711 sym
->set_linkage_name (physname
);
21714 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21715 sym
->set_linkage_name (linkagename
);
21718 /* Handle DW_AT_artificial. */
21719 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
21720 if (attr
!= nullptr)
21721 sym
->artificial
= attr
->as_boolean ();
21723 /* Default assumptions.
21724 Use the passed type or decode it from the die. */
21725 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21726 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21728 SYMBOL_TYPE (sym
) = type
;
21730 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21731 attr
= dwarf2_attr (die
,
21732 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21734 if (attr
!= nullptr)
21735 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21737 attr
= dwarf2_attr (die
,
21738 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21740 if (attr
!= nullptr && attr
->is_nonnegative ())
21742 file_name_index file_index
21743 = (file_name_index
) attr
->as_nonnegative ();
21744 struct file_entry
*fe
;
21746 if (cu
->line_header
!= NULL
)
21747 fe
= cu
->line_header
->file_name_at (file_index
);
21752 complaint (_("file index out of range"));
21754 symbol_set_symtab (sym
, fe
->symtab
);
21760 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21761 if (attr
!= nullptr)
21765 addr
= attr
->as_address ();
21766 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21767 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21768 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21771 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21772 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21773 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21774 add_symbol_to_list (sym
, cu
->list_in_scope
);
21776 case DW_TAG_subprogram
:
21777 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21779 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21780 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21781 if ((attr2
!= nullptr && attr2
->as_boolean ())
21782 || cu
->per_cu
->lang
== language_ada
21783 || cu
->per_cu
->lang
== language_fortran
)
21785 /* Subprograms marked external are stored as a global symbol.
21786 Ada and Fortran subprograms, whether marked external or
21787 not, are always stored as a global symbol, because we want
21788 to be able to access them globally. For instance, we want
21789 to be able to break on a nested subprogram without having
21790 to specify the context. */
21791 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21795 list_to_add
= cu
->list_in_scope
;
21798 case DW_TAG_inlined_subroutine
:
21799 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21801 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21802 SYMBOL_INLINED (sym
) = 1;
21803 list_to_add
= cu
->list_in_scope
;
21805 case DW_TAG_template_value_param
:
21807 /* Fall through. */
21808 case DW_TAG_constant
:
21809 case DW_TAG_variable
:
21810 case DW_TAG_member
:
21811 /* Compilation with minimal debug info may result in
21812 variables with missing type entries. Change the
21813 misleading `void' type to something sensible. */
21814 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21815 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21817 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21818 /* In the case of DW_TAG_member, we should only be called for
21819 static const members. */
21820 if (die
->tag
== DW_TAG_member
)
21822 /* dwarf2_add_field uses die_is_declaration,
21823 so we do the same. */
21824 gdb_assert (die_is_declaration (die
, cu
));
21827 if (attr
!= nullptr)
21829 dwarf2_const_value (attr
, sym
, cu
);
21830 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21833 if (attr2
!= nullptr && attr2
->as_boolean ())
21834 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21836 list_to_add
= cu
->list_in_scope
;
21840 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21841 if (attr
!= nullptr)
21843 var_decode_location (attr
, sym
, cu
);
21844 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21846 /* Fortran explicitly imports any global symbols to the local
21847 scope by DW_TAG_common_block. */
21848 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21849 && die
->parent
->tag
== DW_TAG_common_block
)
21852 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21853 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21854 && !per_objfile
->per_bfd
->has_section_at_zero
)
21856 /* When a static variable is eliminated by the linker,
21857 the corresponding debug information is not stripped
21858 out, but the variable address is set to null;
21859 do not add such variables into symbol table. */
21861 else if (attr2
!= nullptr && attr2
->as_boolean ())
21863 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21864 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21865 && per_objfile
->per_bfd
->can_copy
)
21867 /* A global static variable might be subject to
21868 copy relocation. We first check for a local
21869 minsym, though, because maybe the symbol was
21870 marked hidden, in which case this would not
21872 bound_minimal_symbol found
21873 = (lookup_minimal_symbol_linkage
21874 (sym
->linkage_name (), objfile
));
21875 if (found
.minsym
!= nullptr)
21876 sym
->maybe_copied
= 1;
21879 /* A variable with DW_AT_external is never static,
21880 but it may be block-scoped. */
21882 = ((cu
->list_in_scope
21883 == cu
->get_builder ()->get_file_symbols ())
21884 ? cu
->get_builder ()->get_global_symbols ()
21885 : cu
->list_in_scope
);
21888 list_to_add
= cu
->list_in_scope
;
21892 /* We do not know the address of this symbol.
21893 If it is an external symbol and we have type information
21894 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21895 The address of the variable will then be determined from
21896 the minimal symbol table whenever the variable is
21898 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21900 /* Fortran explicitly imports any global symbols to the local
21901 scope by DW_TAG_common_block. */
21902 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21903 && die
->parent
->tag
== DW_TAG_common_block
)
21905 /* SYMBOL_CLASS doesn't matter here because
21906 read_common_block is going to reset it. */
21908 list_to_add
= cu
->list_in_scope
;
21910 else if (attr2
!= nullptr && attr2
->as_boolean ()
21911 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21913 /* A variable with DW_AT_external is never static, but it
21914 may be block-scoped. */
21916 = ((cu
->list_in_scope
21917 == cu
->get_builder ()->get_file_symbols ())
21918 ? cu
->get_builder ()->get_global_symbols ()
21919 : cu
->list_in_scope
);
21921 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21923 else if (!die_is_declaration (die
, cu
))
21925 /* Use the default LOC_OPTIMIZED_OUT class. */
21926 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21928 list_to_add
= cu
->list_in_scope
;
21932 case DW_TAG_formal_parameter
:
21934 /* If we are inside a function, mark this as an argument. If
21935 not, we might be looking at an argument to an inlined function
21936 when we do not have enough information to show inlined frames;
21937 pretend it's a local variable in that case so that the user can
21939 struct context_stack
*curr
21940 = cu
->get_builder ()->get_current_context_stack ();
21941 if (curr
!= nullptr && curr
->name
!= nullptr)
21942 SYMBOL_IS_ARGUMENT (sym
) = 1;
21943 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21944 if (attr
!= nullptr)
21946 var_decode_location (attr
, sym
, cu
);
21948 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21949 if (attr
!= nullptr)
21951 dwarf2_const_value (attr
, sym
, cu
);
21954 list_to_add
= cu
->list_in_scope
;
21957 case DW_TAG_unspecified_parameters
:
21958 /* From varargs functions; gdb doesn't seem to have any
21959 interest in this information, so just ignore it for now.
21962 case DW_TAG_template_type_param
:
21964 /* Fall through. */
21965 case DW_TAG_class_type
:
21966 case DW_TAG_interface_type
:
21967 case DW_TAG_structure_type
:
21968 case DW_TAG_union_type
:
21969 case DW_TAG_set_type
:
21970 case DW_TAG_enumeration_type
:
21971 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21972 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21975 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21976 really ever be static objects: otherwise, if you try
21977 to, say, break of a class's method and you're in a file
21978 which doesn't mention that class, it won't work unless
21979 the check for all static symbols in lookup_symbol_aux
21980 saves you. See the OtherFileClass tests in
21981 gdb.c++/namespace.exp. */
21985 buildsym_compunit
*builder
= cu
->get_builder ();
21987 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21988 && cu
->per_cu
->lang
== language_cplus
21989 ? builder
->get_global_symbols ()
21990 : cu
->list_in_scope
);
21992 /* The semantics of C++ state that "struct foo {
21993 ... }" also defines a typedef for "foo". */
21994 if (cu
->per_cu
->lang
== language_cplus
21995 || cu
->per_cu
->lang
== language_ada
21996 || cu
->per_cu
->lang
== language_d
21997 || cu
->per_cu
->lang
== language_rust
)
21999 /* The symbol's name is already allocated along
22000 with this objfile, so we don't need to
22001 duplicate it for the type. */
22002 if (SYMBOL_TYPE (sym
)->name () == 0)
22003 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22008 case DW_TAG_typedef
:
22009 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22010 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22011 list_to_add
= cu
->list_in_scope
;
22013 case DW_TAG_array_type
:
22014 case DW_TAG_base_type
:
22015 case DW_TAG_subrange_type
:
22016 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22017 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22018 list_to_add
= cu
->list_in_scope
;
22020 case DW_TAG_enumerator
:
22021 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22022 if (attr
!= nullptr)
22024 dwarf2_const_value (attr
, sym
, cu
);
22027 /* NOTE: carlton/2003-11-10: See comment above in the
22028 DW_TAG_class_type, etc. block. */
22031 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22032 && cu
->per_cu
->lang
== language_cplus
22033 ? cu
->get_builder ()->get_global_symbols ()
22034 : cu
->list_in_scope
);
22037 case DW_TAG_imported_declaration
:
22038 case DW_TAG_namespace
:
22039 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22040 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22042 case DW_TAG_module
:
22043 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22044 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22045 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22047 case DW_TAG_common_block
:
22048 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22049 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22050 add_symbol_to_list (sym
, cu
->list_in_scope
);
22053 /* Not a tag we recognize. Hopefully we aren't processing
22054 trash data, but since we must specifically ignore things
22055 we don't recognize, there is nothing else we should do at
22057 complaint (_("unsupported tag: '%s'"),
22058 dwarf_tag_name (die
->tag
));
22064 sym
->hash_next
= objfile
->template_symbols
;
22065 objfile
->template_symbols
= sym
;
22066 list_to_add
= NULL
;
22069 if (list_to_add
!= NULL
)
22070 add_symbol_to_list (sym
, list_to_add
);
22072 /* For the benefit of old versions of GCC, check for anonymous
22073 namespaces based on the demangled name. */
22074 if (!cu
->processing_has_namespace_info
22075 && cu
->per_cu
->lang
== language_cplus
)
22076 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22081 /* Given an attr with a DW_FORM_dataN value in host byte order,
22082 zero-extend it as appropriate for the symbol's type. The DWARF
22083 standard (v4) is not entirely clear about the meaning of using
22084 DW_FORM_dataN for a constant with a signed type, where the type is
22085 wider than the data. The conclusion of a discussion on the DWARF
22086 list was that this is unspecified. We choose to always zero-extend
22087 because that is the interpretation long in use by GCC. */
22090 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22091 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22093 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22094 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22095 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22096 LONGEST l
= attr
->constant_value (0);
22098 if (bits
< sizeof (*value
) * 8)
22100 l
&= ((LONGEST
) 1 << bits
) - 1;
22103 else if (bits
== sizeof (*value
) * 8)
22107 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22108 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22115 /* Read a constant value from an attribute. Either set *VALUE, or if
22116 the value does not fit in *VALUE, set *BYTES - either already
22117 allocated on the objfile obstack, or newly allocated on OBSTACK,
22118 or, set *BATON, if we translated the constant to a location
22122 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22123 const char *name
, struct obstack
*obstack
,
22124 struct dwarf2_cu
*cu
,
22125 LONGEST
*value
, const gdb_byte
**bytes
,
22126 struct dwarf2_locexpr_baton
**baton
)
22128 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22129 struct objfile
*objfile
= per_objfile
->objfile
;
22130 struct comp_unit_head
*cu_header
= &cu
->header
;
22131 struct dwarf_block
*blk
;
22132 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22133 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22139 switch (attr
->form
)
22142 case DW_FORM_addrx
:
22143 case DW_FORM_GNU_addr_index
:
22147 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22148 dwarf2_const_value_length_mismatch_complaint (name
,
22149 cu_header
->addr_size
,
22150 TYPE_LENGTH (type
));
22151 /* Symbols of this form are reasonably rare, so we just
22152 piggyback on the existing location code rather than writing
22153 a new implementation of symbol_computed_ops. */
22154 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22155 (*baton
)->per_objfile
= per_objfile
;
22156 (*baton
)->per_cu
= cu
->per_cu
;
22157 gdb_assert ((*baton
)->per_cu
);
22159 (*baton
)->size
= 2 + cu_header
->addr_size
;
22160 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22161 (*baton
)->data
= data
;
22163 data
[0] = DW_OP_addr
;
22164 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22165 byte_order
, attr
->as_address ());
22166 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22169 case DW_FORM_string
:
22172 case DW_FORM_GNU_str_index
:
22173 case DW_FORM_GNU_strp_alt
:
22174 /* The string is already allocated on the objfile obstack, point
22176 *bytes
= (const gdb_byte
*) attr
->as_string ();
22178 case DW_FORM_block1
:
22179 case DW_FORM_block2
:
22180 case DW_FORM_block4
:
22181 case DW_FORM_block
:
22182 case DW_FORM_exprloc
:
22183 case DW_FORM_data16
:
22184 blk
= attr
->as_block ();
22185 if (TYPE_LENGTH (type
) != blk
->size
)
22186 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22187 TYPE_LENGTH (type
));
22188 *bytes
= blk
->data
;
22191 /* The DW_AT_const_value attributes are supposed to carry the
22192 symbol's value "represented as it would be on the target
22193 architecture." By the time we get here, it's already been
22194 converted to host endianness, so we just need to sign- or
22195 zero-extend it as appropriate. */
22196 case DW_FORM_data1
:
22197 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22199 case DW_FORM_data2
:
22200 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22202 case DW_FORM_data4
:
22203 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22205 case DW_FORM_data8
:
22206 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22209 case DW_FORM_sdata
:
22210 case DW_FORM_implicit_const
:
22211 *value
= attr
->as_signed ();
22214 case DW_FORM_udata
:
22215 *value
= attr
->as_unsigned ();
22219 complaint (_("unsupported const value attribute form: '%s'"),
22220 dwarf_form_name (attr
->form
));
22227 /* Copy constant value from an attribute to a symbol. */
22230 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22231 struct dwarf2_cu
*cu
)
22233 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22235 const gdb_byte
*bytes
;
22236 struct dwarf2_locexpr_baton
*baton
;
22238 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22239 sym
->print_name (),
22240 &objfile
->objfile_obstack
, cu
,
22241 &value
, &bytes
, &baton
);
22245 SYMBOL_LOCATION_BATON (sym
) = baton
;
22246 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22248 else if (bytes
!= NULL
)
22250 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22251 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22255 SYMBOL_VALUE (sym
) = value
;
22256 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22260 /* Return the type of the die in question using its DW_AT_type attribute. */
22262 static struct type
*
22263 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22265 struct attribute
*type_attr
;
22267 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22270 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22271 /* A missing DW_AT_type represents a void type. */
22272 return objfile_type (objfile
)->builtin_void
;
22275 return lookup_die_type (die
, type_attr
, cu
);
22278 /* True iff CU's producer generates GNAT Ada auxiliary information
22279 that allows to find parallel types through that information instead
22280 of having to do expensive parallel lookups by type name. */
22283 need_gnat_info (struct dwarf2_cu
*cu
)
22285 /* Assume that the Ada compiler was GNAT, which always produces
22286 the auxiliary information. */
22287 return (cu
->per_cu
->lang
== language_ada
);
22290 /* Return the auxiliary type of the die in question using its
22291 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22292 attribute is not present. */
22294 static struct type
*
22295 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22297 struct attribute
*type_attr
;
22299 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22303 return lookup_die_type (die
, type_attr
, cu
);
22306 /* If DIE has a descriptive_type attribute, then set the TYPE's
22307 descriptive type accordingly. */
22310 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22311 struct dwarf2_cu
*cu
)
22313 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22315 if (descriptive_type
)
22317 ALLOCATE_GNAT_AUX_TYPE (type
);
22318 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22322 /* Return the containing type of the die in question using its
22323 DW_AT_containing_type attribute. */
22325 static struct type
*
22326 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22328 struct attribute
*type_attr
;
22329 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22331 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22333 error (_("Dwarf Error: Problem turning containing type into gdb type "
22334 "[in module %s]"), objfile_name (objfile
));
22336 return lookup_die_type (die
, type_attr
, cu
);
22339 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22341 static struct type
*
22342 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22344 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22345 struct objfile
*objfile
= per_objfile
->objfile
;
22348 std::string message
22349 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22350 objfile_name (objfile
),
22351 sect_offset_str (cu
->header
.sect_off
),
22352 sect_offset_str (die
->sect_off
));
22353 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22355 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22358 /* Look up the type of DIE in CU using its type attribute ATTR.
22359 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22360 DW_AT_containing_type.
22361 If there is no type substitute an error marker. */
22363 static struct type
*
22364 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22365 struct dwarf2_cu
*cu
)
22367 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22368 struct objfile
*objfile
= per_objfile
->objfile
;
22369 struct type
*this_type
;
22371 gdb_assert (attr
->name
== DW_AT_type
22372 || attr
->name
== DW_AT_GNAT_descriptive_type
22373 || attr
->name
== DW_AT_containing_type
);
22375 /* First see if we have it cached. */
22377 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22379 struct dwarf2_per_cu_data
*per_cu
;
22380 sect_offset sect_off
= attr
->get_ref_die_offset ();
22382 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22383 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22385 else if (attr
->form_is_ref ())
22387 sect_offset sect_off
= attr
->get_ref_die_offset ();
22389 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22391 else if (attr
->form
== DW_FORM_ref_sig8
)
22393 ULONGEST signature
= attr
->as_signature ();
22395 return get_signatured_type (die
, signature
, cu
);
22399 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22400 " at %s [in module %s]"),
22401 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22402 objfile_name (objfile
));
22403 return build_error_marker_type (cu
, die
);
22406 /* If not cached we need to read it in. */
22408 if (this_type
== NULL
)
22410 struct die_info
*type_die
= NULL
;
22411 struct dwarf2_cu
*type_cu
= cu
;
22413 if (attr
->form_is_ref ())
22414 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22415 if (type_die
== NULL
)
22416 return build_error_marker_type (cu
, die
);
22417 /* If we find the type now, it's probably because the type came
22418 from an inter-CU reference and the type's CU got expanded before
22420 this_type
= read_type_die (type_die
, type_cu
);
22423 /* If we still don't have a type use an error marker. */
22425 if (this_type
== NULL
)
22426 return build_error_marker_type (cu
, die
);
22431 /* Return the type in DIE, CU.
22432 Returns NULL for invalid types.
22434 This first does a lookup in die_type_hash,
22435 and only reads the die in if necessary.
22437 NOTE: This can be called when reading in partial or full symbols. */
22439 static struct type
*
22440 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22442 struct type
*this_type
;
22444 this_type
= get_die_type (die
, cu
);
22448 return read_type_die_1 (die
, cu
);
22451 /* Read the type in DIE, CU.
22452 Returns NULL for invalid types. */
22454 static struct type
*
22455 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22457 struct type
*this_type
= NULL
;
22461 case DW_TAG_class_type
:
22462 case DW_TAG_interface_type
:
22463 case DW_TAG_structure_type
:
22464 case DW_TAG_union_type
:
22465 this_type
= read_structure_type (die
, cu
);
22467 case DW_TAG_enumeration_type
:
22468 this_type
= read_enumeration_type (die
, cu
);
22470 case DW_TAG_subprogram
:
22471 case DW_TAG_subroutine_type
:
22472 case DW_TAG_inlined_subroutine
:
22473 this_type
= read_subroutine_type (die
, cu
);
22475 case DW_TAG_array_type
:
22476 this_type
= read_array_type (die
, cu
);
22478 case DW_TAG_set_type
:
22479 this_type
= read_set_type (die
, cu
);
22481 case DW_TAG_pointer_type
:
22482 this_type
= read_tag_pointer_type (die
, cu
);
22484 case DW_TAG_ptr_to_member_type
:
22485 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22487 case DW_TAG_reference_type
:
22488 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22490 case DW_TAG_rvalue_reference_type
:
22491 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22493 case DW_TAG_const_type
:
22494 this_type
= read_tag_const_type (die
, cu
);
22496 case DW_TAG_volatile_type
:
22497 this_type
= read_tag_volatile_type (die
, cu
);
22499 case DW_TAG_restrict_type
:
22500 this_type
= read_tag_restrict_type (die
, cu
);
22502 case DW_TAG_string_type
:
22503 this_type
= read_tag_string_type (die
, cu
);
22505 case DW_TAG_typedef
:
22506 this_type
= read_typedef (die
, cu
);
22508 case DW_TAG_subrange_type
:
22509 this_type
= read_subrange_type (die
, cu
);
22511 case DW_TAG_base_type
:
22512 this_type
= read_base_type (die
, cu
);
22514 case DW_TAG_unspecified_type
:
22515 this_type
= read_unspecified_type (die
, cu
);
22517 case DW_TAG_namespace
:
22518 this_type
= read_namespace_type (die
, cu
);
22520 case DW_TAG_module
:
22521 this_type
= read_module_type (die
, cu
);
22523 case DW_TAG_atomic_type
:
22524 this_type
= read_tag_atomic_type (die
, cu
);
22527 complaint (_("unexpected tag in read_type_die: '%s'"),
22528 dwarf_tag_name (die
->tag
));
22535 /* See if we can figure out if the class lives in a namespace. We do
22536 this by looking for a member function; its demangled name will
22537 contain namespace info, if there is any.
22538 Return the computed name or NULL.
22539 Space for the result is allocated on the objfile's obstack.
22540 This is the full-die version of guess_partial_die_structure_name.
22541 In this case we know DIE has no useful parent. */
22543 static const char *
22544 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22546 struct die_info
*spec_die
;
22547 struct dwarf2_cu
*spec_cu
;
22548 struct die_info
*child
;
22549 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22552 spec_die
= die_specification (die
, &spec_cu
);
22553 if (spec_die
!= NULL
)
22559 for (child
= die
->child
;
22561 child
= child
->sibling
)
22563 if (child
->tag
== DW_TAG_subprogram
)
22565 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22567 if (linkage_name
!= NULL
)
22569 gdb::unique_xmalloc_ptr
<char> actual_name
22570 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22571 const char *name
= NULL
;
22573 if (actual_name
!= NULL
)
22575 const char *die_name
= dwarf2_name (die
, cu
);
22577 if (die_name
!= NULL
22578 && strcmp (die_name
, actual_name
.get ()) != 0)
22580 /* Strip off the class name from the full name.
22581 We want the prefix. */
22582 int die_name_len
= strlen (die_name
);
22583 int actual_name_len
= strlen (actual_name
.get ());
22584 const char *ptr
= actual_name
.get ();
22586 /* Test for '::' as a sanity check. */
22587 if (actual_name_len
> die_name_len
+ 2
22588 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22589 name
= obstack_strndup (
22590 &objfile
->per_bfd
->storage_obstack
,
22591 ptr
, actual_name_len
- die_name_len
- 2);
22602 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22603 prefix part in such case. See
22604 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22606 static const char *
22607 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22609 struct attribute
*attr
;
22612 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22613 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22616 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22619 attr
= dw2_linkage_name_attr (die
, cu
);
22620 const char *attr_name
= attr
->as_string ();
22621 if (attr
== NULL
|| attr_name
== NULL
)
22624 /* dwarf2_name had to be already called. */
22625 gdb_assert (attr
->canonical_string_p ());
22627 /* Strip the base name, keep any leading namespaces/classes. */
22628 base
= strrchr (attr_name
, ':');
22629 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22632 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22633 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22635 &base
[-1] - attr_name
);
22638 /* Return the name of the namespace/class that DIE is defined within,
22639 or "" if we can't tell. The caller should not xfree the result.
22641 For example, if we're within the method foo() in the following
22651 then determine_prefix on foo's die will return "N::C". */
22653 static const char *
22654 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22656 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22657 struct die_info
*parent
, *spec_die
;
22658 struct dwarf2_cu
*spec_cu
;
22659 struct type
*parent_type
;
22660 const char *retval
;
22662 if (cu
->per_cu
->lang
!= language_cplus
22663 && cu
->per_cu
->lang
!= language_fortran
22664 && cu
->per_cu
->lang
!= language_d
22665 && cu
->per_cu
->lang
!= language_rust
)
22668 retval
= anonymous_struct_prefix (die
, cu
);
22672 /* We have to be careful in the presence of DW_AT_specification.
22673 For example, with GCC 3.4, given the code
22677 // Definition of N::foo.
22681 then we'll have a tree of DIEs like this:
22683 1: DW_TAG_compile_unit
22684 2: DW_TAG_namespace // N
22685 3: DW_TAG_subprogram // declaration of N::foo
22686 4: DW_TAG_subprogram // definition of N::foo
22687 DW_AT_specification // refers to die #3
22689 Thus, when processing die #4, we have to pretend that we're in
22690 the context of its DW_AT_specification, namely the contex of die
22693 spec_die
= die_specification (die
, &spec_cu
);
22694 if (spec_die
== NULL
)
22695 parent
= die
->parent
;
22698 parent
= spec_die
->parent
;
22702 if (parent
== NULL
)
22704 else if (parent
->building_fullname
)
22707 const char *parent_name
;
22709 /* It has been seen on RealView 2.2 built binaries,
22710 DW_TAG_template_type_param types actually _defined_ as
22711 children of the parent class:
22714 template class <class Enum> Class{};
22715 Class<enum E> class_e;
22717 1: DW_TAG_class_type (Class)
22718 2: DW_TAG_enumeration_type (E)
22719 3: DW_TAG_enumerator (enum1:0)
22720 3: DW_TAG_enumerator (enum2:1)
22722 2: DW_TAG_template_type_param
22723 DW_AT_type DW_FORM_ref_udata (E)
22725 Besides being broken debug info, it can put GDB into an
22726 infinite loop. Consider:
22728 When we're building the full name for Class<E>, we'll start
22729 at Class, and go look over its template type parameters,
22730 finding E. We'll then try to build the full name of E, and
22731 reach here. We're now trying to build the full name of E,
22732 and look over the parent DIE for containing scope. In the
22733 broken case, if we followed the parent DIE of E, we'd again
22734 find Class, and once again go look at its template type
22735 arguments, etc., etc. Simply don't consider such parent die
22736 as source-level parent of this die (it can't be, the language
22737 doesn't allow it), and break the loop here. */
22738 name
= dwarf2_name (die
, cu
);
22739 parent_name
= dwarf2_name (parent
, cu
);
22740 complaint (_("template param type '%s' defined within parent '%s'"),
22741 name
? name
: "<unknown>",
22742 parent_name
? parent_name
: "<unknown>");
22746 switch (parent
->tag
)
22748 case DW_TAG_namespace
:
22749 parent_type
= read_type_die (parent
, cu
);
22750 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22751 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22752 Work around this problem here. */
22753 if (cu
->per_cu
->lang
== language_cplus
22754 && strcmp (parent_type
->name (), "::") == 0)
22756 /* We give a name to even anonymous namespaces. */
22757 return parent_type
->name ();
22758 case DW_TAG_class_type
:
22759 case DW_TAG_interface_type
:
22760 case DW_TAG_structure_type
:
22761 case DW_TAG_union_type
:
22762 case DW_TAG_module
:
22763 parent_type
= read_type_die (parent
, cu
);
22764 if (parent_type
->name () != NULL
)
22765 return parent_type
->name ();
22767 /* An anonymous structure is only allowed non-static data
22768 members; no typedefs, no member functions, et cetera.
22769 So it does not need a prefix. */
22771 case DW_TAG_compile_unit
:
22772 case DW_TAG_partial_unit
:
22773 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22774 if (cu
->per_cu
->lang
== language_cplus
22775 && !per_objfile
->per_bfd
->types
.empty ()
22776 && die
->child
!= NULL
22777 && (die
->tag
== DW_TAG_class_type
22778 || die
->tag
== DW_TAG_structure_type
22779 || die
->tag
== DW_TAG_union_type
))
22781 const char *name
= guess_full_die_structure_name (die
, cu
);
22786 case DW_TAG_subprogram
:
22787 /* Nested subroutines in Fortran get a prefix with the name
22788 of the parent's subroutine. */
22789 if (cu
->per_cu
->lang
== language_fortran
)
22791 if ((die
->tag
== DW_TAG_subprogram
)
22792 && (dwarf2_name (parent
, cu
) != NULL
))
22793 return dwarf2_name (parent
, cu
);
22796 case DW_TAG_enumeration_type
:
22797 parent_type
= read_type_die (parent
, cu
);
22798 if (parent_type
->is_declared_class ())
22800 if (parent_type
->name () != NULL
)
22801 return parent_type
->name ();
22804 /* Fall through. */
22806 return determine_prefix (parent
, cu
);
22810 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22811 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22812 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22813 an obconcat, otherwise allocate storage for the result. The CU argument is
22814 used to determine the language and hence, the appropriate separator. */
22816 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22819 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22820 int physname
, struct dwarf2_cu
*cu
)
22822 const char *lead
= "";
22825 if (suffix
== NULL
|| suffix
[0] == '\0'
22826 || prefix
== NULL
|| prefix
[0] == '\0')
22828 else if (cu
->per_cu
->lang
== language_d
)
22830 /* For D, the 'main' function could be defined in any module, but it
22831 should never be prefixed. */
22832 if (strcmp (suffix
, "D main") == 0)
22840 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
22842 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22843 DW_AT_MIPS_linkage_name is preferred and used instead. */
22851 if (prefix
== NULL
)
22853 if (suffix
== NULL
)
22860 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22862 strcpy (retval
, lead
);
22863 strcat (retval
, prefix
);
22864 strcat (retval
, sep
);
22865 strcat (retval
, suffix
);
22870 /* We have an obstack. */
22871 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22875 /* Get name of a die, return NULL if not found. */
22877 static const char *
22878 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22879 struct objfile
*objfile
)
22881 if (name
&& cu
->per_cu
->lang
== language_cplus
)
22883 gdb::unique_xmalloc_ptr
<char> canon_name
22884 = cp_canonicalize_string (name
);
22886 if (canon_name
!= nullptr)
22887 name
= objfile
->intern (canon_name
.get ());
22893 /* Get name of a die, return NULL if not found.
22894 Anonymous namespaces are converted to their magic string. */
22896 static const char *
22897 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22899 struct attribute
*attr
;
22900 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22902 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22903 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22904 if (attr_name
== nullptr
22905 && die
->tag
!= DW_TAG_namespace
22906 && die
->tag
!= DW_TAG_class_type
22907 && die
->tag
!= DW_TAG_interface_type
22908 && die
->tag
!= DW_TAG_structure_type
22909 && die
->tag
!= DW_TAG_union_type
)
22914 case DW_TAG_compile_unit
:
22915 case DW_TAG_partial_unit
:
22916 /* Compilation units have a DW_AT_name that is a filename, not
22917 a source language identifier. */
22918 case DW_TAG_enumeration_type
:
22919 case DW_TAG_enumerator
:
22920 /* These tags always have simple identifiers already; no need
22921 to canonicalize them. */
22924 case DW_TAG_namespace
:
22925 if (attr_name
!= nullptr)
22927 return CP_ANONYMOUS_NAMESPACE_STR
;
22929 case DW_TAG_class_type
:
22930 case DW_TAG_interface_type
:
22931 case DW_TAG_structure_type
:
22932 case DW_TAG_union_type
:
22933 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22934 structures or unions. These were of the form "._%d" in GCC 4.1,
22935 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22936 and GCC 4.4. We work around this problem by ignoring these. */
22937 if (attr_name
!= nullptr
22938 && (startswith (attr_name
, "._")
22939 || startswith (attr_name
, "<anonymous")))
22942 /* GCC might emit a nameless typedef that has a linkage name. See
22943 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22944 if (!attr
|| attr_name
== NULL
)
22946 attr
= dw2_linkage_name_attr (die
, cu
);
22947 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22948 if (attr
== NULL
|| attr_name
== NULL
)
22951 /* Avoid demangling attr_name the second time on a second
22952 call for the same DIE. */
22953 if (!attr
->canonical_string_p ())
22955 gdb::unique_xmalloc_ptr
<char> demangled
22956 (gdb_demangle (attr_name
, DMGL_TYPES
));
22957 if (demangled
== nullptr)
22960 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22961 attr_name
= attr
->as_string ();
22964 /* Strip any leading namespaces/classes, keep only the
22965 base name. DW_AT_name for named DIEs does not
22966 contain the prefixes. */
22967 const char *base
= strrchr (attr_name
, ':');
22968 if (base
&& base
> attr_name
&& base
[-1] == ':')
22979 if (!attr
->canonical_string_p ())
22980 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22982 return attr
->as_string ();
22985 /* Return the die that this die in an extension of, or NULL if there
22986 is none. *EXT_CU is the CU containing DIE on input, and the CU
22987 containing the return value on output. */
22989 static struct die_info
*
22990 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22992 struct attribute
*attr
;
22994 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22998 return follow_die_ref (die
, attr
, ext_cu
);
23002 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23006 print_spaces (indent
, f
);
23007 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23008 dwarf_tag_name (die
->tag
), die
->abbrev
,
23009 sect_offset_str (die
->sect_off
));
23011 if (die
->parent
!= NULL
)
23013 print_spaces (indent
, f
);
23014 fprintf_unfiltered (f
, " parent at offset: %s\n",
23015 sect_offset_str (die
->parent
->sect_off
));
23018 print_spaces (indent
, f
);
23019 fprintf_unfiltered (f
, " has children: %s\n",
23020 dwarf_bool_name (die
->child
!= NULL
));
23022 print_spaces (indent
, f
);
23023 fprintf_unfiltered (f
, " attributes:\n");
23025 for (i
= 0; i
< die
->num_attrs
; ++i
)
23027 print_spaces (indent
, f
);
23028 fprintf_unfiltered (f
, " %s (%s) ",
23029 dwarf_attr_name (die
->attrs
[i
].name
),
23030 dwarf_form_name (die
->attrs
[i
].form
));
23032 switch (die
->attrs
[i
].form
)
23035 case DW_FORM_addrx
:
23036 case DW_FORM_GNU_addr_index
:
23037 fprintf_unfiltered (f
, "address: ");
23038 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23040 case DW_FORM_block2
:
23041 case DW_FORM_block4
:
23042 case DW_FORM_block
:
23043 case DW_FORM_block1
:
23044 fprintf_unfiltered (f
, "block: size %s",
23045 pulongest (die
->attrs
[i
].as_block ()->size
));
23047 case DW_FORM_exprloc
:
23048 fprintf_unfiltered (f
, "expression: size %s",
23049 pulongest (die
->attrs
[i
].as_block ()->size
));
23051 case DW_FORM_data16
:
23052 fprintf_unfiltered (f
, "constant of 16 bytes");
23054 case DW_FORM_ref_addr
:
23055 fprintf_unfiltered (f
, "ref address: ");
23056 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23058 case DW_FORM_GNU_ref_alt
:
23059 fprintf_unfiltered (f
, "alt ref address: ");
23060 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23066 case DW_FORM_ref_udata
:
23067 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23068 (long) (die
->attrs
[i
].as_unsigned ()));
23070 case DW_FORM_data1
:
23071 case DW_FORM_data2
:
23072 case DW_FORM_data4
:
23073 case DW_FORM_data8
:
23074 case DW_FORM_udata
:
23075 fprintf_unfiltered (f
, "constant: %s",
23076 pulongest (die
->attrs
[i
].as_unsigned ()));
23078 case DW_FORM_sec_offset
:
23079 fprintf_unfiltered (f
, "section offset: %s",
23080 pulongest (die
->attrs
[i
].as_unsigned ()));
23082 case DW_FORM_ref_sig8
:
23083 fprintf_unfiltered (f
, "signature: %s",
23084 hex_string (die
->attrs
[i
].as_signature ()));
23086 case DW_FORM_string
:
23088 case DW_FORM_line_strp
:
23090 case DW_FORM_GNU_str_index
:
23091 case DW_FORM_GNU_strp_alt
:
23092 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23093 die
->attrs
[i
].as_string ()
23094 ? die
->attrs
[i
].as_string () : "",
23095 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23098 if (die
->attrs
[i
].as_boolean ())
23099 fprintf_unfiltered (f
, "flag: TRUE");
23101 fprintf_unfiltered (f
, "flag: FALSE");
23103 case DW_FORM_flag_present
:
23104 fprintf_unfiltered (f
, "flag: TRUE");
23106 case DW_FORM_indirect
:
23107 /* The reader will have reduced the indirect form to
23108 the "base form" so this form should not occur. */
23109 fprintf_unfiltered (f
,
23110 "unexpected attribute form: DW_FORM_indirect");
23112 case DW_FORM_sdata
:
23113 case DW_FORM_implicit_const
:
23114 fprintf_unfiltered (f
, "constant: %s",
23115 plongest (die
->attrs
[i
].as_signed ()));
23118 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23119 die
->attrs
[i
].form
);
23122 fprintf_unfiltered (f
, "\n");
23127 dump_die_for_error (struct die_info
*die
)
23129 dump_die_shallow (gdb_stderr
, 0, die
);
23133 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23135 int indent
= level
* 4;
23137 gdb_assert (die
!= NULL
);
23139 if (level
>= max_level
)
23142 dump_die_shallow (f
, indent
, die
);
23144 if (die
->child
!= NULL
)
23146 print_spaces (indent
, f
);
23147 fprintf_unfiltered (f
, " Children:");
23148 if (level
+ 1 < max_level
)
23150 fprintf_unfiltered (f
, "\n");
23151 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23155 fprintf_unfiltered (f
,
23156 " [not printed, max nesting level reached]\n");
23160 if (die
->sibling
!= NULL
&& level
> 0)
23162 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23166 /* This is called from the pdie macro in gdbinit.in.
23167 It's not static so gcc will keep a copy callable from gdb. */
23170 dump_die (struct die_info
*die
, int max_level
)
23172 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23176 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23180 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23181 to_underlying (die
->sect_off
),
23187 /* Follow reference or signature attribute ATTR of SRC_DIE.
23188 On entry *REF_CU is the CU of SRC_DIE.
23189 On exit *REF_CU is the CU of the result. */
23191 static struct die_info
*
23192 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23193 struct dwarf2_cu
**ref_cu
)
23195 struct die_info
*die
;
23197 if (attr
->form_is_ref ())
23198 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23199 else if (attr
->form
== DW_FORM_ref_sig8
)
23200 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23203 dump_die_for_error (src_die
);
23204 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23205 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23211 /* Follow reference OFFSET.
23212 On entry *REF_CU is the CU of the source die referencing OFFSET.
23213 On exit *REF_CU is the CU of the result.
23214 Returns NULL if OFFSET is invalid. */
23216 static struct die_info
*
23217 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23218 struct dwarf2_cu
**ref_cu
)
23220 struct die_info temp_die
;
23221 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23222 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23224 gdb_assert (cu
->per_cu
!= NULL
);
23228 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23229 "source CU contains target offset: %d",
23230 sect_offset_str (cu
->per_cu
->sect_off
),
23231 sect_offset_str (sect_off
),
23232 cu
->header
.offset_in_cu_p (sect_off
));
23234 if (cu
->per_cu
->is_debug_types
)
23236 /* .debug_types CUs cannot reference anything outside their CU.
23237 If they need to, they have to reference a signatured type via
23238 DW_FORM_ref_sig8. */
23239 if (!cu
->header
.offset_in_cu_p (sect_off
))
23242 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23243 || !cu
->header
.offset_in_cu_p (sect_off
))
23245 struct dwarf2_per_cu_data
*per_cu
;
23247 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23250 dwarf_read_debug_printf_v ("target CU offset: %s, "
23251 "target CU DIEs loaded: %d",
23252 sect_offset_str (per_cu
->sect_off
),
23253 per_objfile
->get_cu (per_cu
) != nullptr);
23255 /* If necessary, add it to the queue and load its DIEs.
23257 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23258 it doesn't mean they are currently loaded. Since we require them
23259 to be loaded, we must check for ourselves. */
23260 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
23261 || per_objfile
->get_cu (per_cu
) == nullptr)
23262 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23263 false, cu
->per_cu
->lang
);
23265 target_cu
= per_objfile
->get_cu (per_cu
);
23266 gdb_assert (target_cu
!= nullptr);
23268 else if (cu
->dies
== NULL
)
23270 /* We're loading full DIEs during partial symbol reading. */
23271 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23272 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23276 *ref_cu
= target_cu
;
23277 temp_die
.sect_off
= sect_off
;
23279 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23281 to_underlying (sect_off
));
23284 /* Follow reference attribute ATTR of SRC_DIE.
23285 On entry *REF_CU is the CU of SRC_DIE.
23286 On exit *REF_CU is the CU of the result. */
23288 static struct die_info
*
23289 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23290 struct dwarf2_cu
**ref_cu
)
23292 sect_offset sect_off
= attr
->get_ref_die_offset ();
23293 struct dwarf2_cu
*cu
= *ref_cu
;
23294 struct die_info
*die
;
23296 die
= follow_die_offset (sect_off
,
23297 (attr
->form
== DW_FORM_GNU_ref_alt
23298 || cu
->per_cu
->is_dwz
),
23301 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23302 "at %s [in module %s]"),
23303 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23304 objfile_name (cu
->per_objfile
->objfile
));
23311 struct dwarf2_locexpr_baton
23312 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23313 dwarf2_per_cu_data
*per_cu
,
23314 dwarf2_per_objfile
*per_objfile
,
23315 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23316 bool resolve_abstract_p
)
23318 struct die_info
*die
;
23319 struct attribute
*attr
;
23320 struct dwarf2_locexpr_baton retval
;
23321 struct objfile
*objfile
= per_objfile
->objfile
;
23323 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23325 cu
= load_cu (per_cu
, per_objfile
, false);
23329 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23330 Instead just throw an error, not much else we can do. */
23331 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23332 sect_offset_str (sect_off
), objfile_name (objfile
));
23335 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23337 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23338 sect_offset_str (sect_off
), objfile_name (objfile
));
23340 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23341 if (!attr
&& resolve_abstract_p
23342 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23343 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23345 CORE_ADDR pc
= get_frame_pc ();
23346 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23347 struct gdbarch
*gdbarch
= objfile
->arch ();
23349 for (const auto &cand_off
23350 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23352 struct dwarf2_cu
*cand_cu
= cu
;
23353 struct die_info
*cand
23354 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23357 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23360 CORE_ADDR pc_low
, pc_high
;
23361 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23362 if (pc_low
== ((CORE_ADDR
) -1))
23364 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23365 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23366 if (!(pc_low
<= pc
&& pc
< pc_high
))
23370 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23377 /* DWARF: "If there is no such attribute, then there is no effect.".
23378 DATA is ignored if SIZE is 0. */
23380 retval
.data
= NULL
;
23383 else if (attr
->form_is_section_offset ())
23385 struct dwarf2_loclist_baton loclist_baton
;
23386 CORE_ADDR pc
= get_frame_pc ();
23389 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23391 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23393 retval
.size
= size
;
23397 if (!attr
->form_is_block ())
23398 error (_("Dwarf Error: DIE at %s referenced in module %s "
23399 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23400 sect_offset_str (sect_off
), objfile_name (objfile
));
23402 struct dwarf_block
*block
= attr
->as_block ();
23403 retval
.data
= block
->data
;
23404 retval
.size
= block
->size
;
23406 retval
.per_objfile
= per_objfile
;
23407 retval
.per_cu
= cu
->per_cu
;
23409 per_objfile
->age_comp_units ();
23416 struct dwarf2_locexpr_baton
23417 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23418 dwarf2_per_cu_data
*per_cu
,
23419 dwarf2_per_objfile
*per_objfile
,
23420 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23422 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23424 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23428 /* Write a constant of a given type as target-ordered bytes into
23431 static const gdb_byte
*
23432 write_constant_as_bytes (struct obstack
*obstack
,
23433 enum bfd_endian byte_order
,
23440 *len
= TYPE_LENGTH (type
);
23441 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23442 store_unsigned_integer (result
, *len
, byte_order
, value
);
23450 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23451 dwarf2_per_cu_data
*per_cu
,
23452 dwarf2_per_objfile
*per_objfile
,
23456 struct die_info
*die
;
23457 struct attribute
*attr
;
23458 const gdb_byte
*result
= NULL
;
23461 enum bfd_endian byte_order
;
23462 struct objfile
*objfile
= per_objfile
->objfile
;
23464 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23466 cu
= load_cu (per_cu
, per_objfile
, false);
23470 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23471 Instead just throw an error, not much else we can do. */
23472 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23473 sect_offset_str (sect_off
), objfile_name (objfile
));
23476 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23478 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23479 sect_offset_str (sect_off
), objfile_name (objfile
));
23481 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23485 byte_order
= (bfd_big_endian (objfile
->obfd
)
23486 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23488 switch (attr
->form
)
23491 case DW_FORM_addrx
:
23492 case DW_FORM_GNU_addr_index
:
23496 *len
= cu
->header
.addr_size
;
23497 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23498 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23502 case DW_FORM_string
:
23505 case DW_FORM_GNU_str_index
:
23506 case DW_FORM_GNU_strp_alt
:
23507 /* The string is already allocated on the objfile obstack, point
23510 const char *attr_name
= attr
->as_string ();
23511 result
= (const gdb_byte
*) attr_name
;
23512 *len
= strlen (attr_name
);
23515 case DW_FORM_block1
:
23516 case DW_FORM_block2
:
23517 case DW_FORM_block4
:
23518 case DW_FORM_block
:
23519 case DW_FORM_exprloc
:
23520 case DW_FORM_data16
:
23522 struct dwarf_block
*block
= attr
->as_block ();
23523 result
= block
->data
;
23524 *len
= block
->size
;
23528 /* The DW_AT_const_value attributes are supposed to carry the
23529 symbol's value "represented as it would be on the target
23530 architecture." By the time we get here, it's already been
23531 converted to host endianness, so we just need to sign- or
23532 zero-extend it as appropriate. */
23533 case DW_FORM_data1
:
23534 type
= die_type (die
, cu
);
23535 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23536 if (result
== NULL
)
23537 result
= write_constant_as_bytes (obstack
, byte_order
,
23540 case DW_FORM_data2
:
23541 type
= die_type (die
, cu
);
23542 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23543 if (result
== NULL
)
23544 result
= write_constant_as_bytes (obstack
, byte_order
,
23547 case DW_FORM_data4
:
23548 type
= die_type (die
, cu
);
23549 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23550 if (result
== NULL
)
23551 result
= write_constant_as_bytes (obstack
, byte_order
,
23554 case DW_FORM_data8
:
23555 type
= die_type (die
, cu
);
23556 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23557 if (result
== NULL
)
23558 result
= write_constant_as_bytes (obstack
, byte_order
,
23562 case DW_FORM_sdata
:
23563 case DW_FORM_implicit_const
:
23564 type
= die_type (die
, cu
);
23565 result
= write_constant_as_bytes (obstack
, byte_order
,
23566 type
, attr
->as_signed (), len
);
23569 case DW_FORM_udata
:
23570 type
= die_type (die
, cu
);
23571 result
= write_constant_as_bytes (obstack
, byte_order
,
23572 type
, attr
->as_unsigned (), len
);
23576 complaint (_("unsupported const value attribute form: '%s'"),
23577 dwarf_form_name (attr
->form
));
23587 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23588 dwarf2_per_cu_data
*per_cu
,
23589 dwarf2_per_objfile
*per_objfile
,
23590 const char **var_name
)
23592 struct die_info
*die
;
23594 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23596 cu
= load_cu (per_cu
, per_objfile
, false);
23601 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23605 if (var_name
!= nullptr)
23606 *var_name
= var_decl_name (die
, cu
);
23607 return die_type (die
, cu
);
23613 dwarf2_get_die_type (cu_offset die_offset
,
23614 dwarf2_per_cu_data
*per_cu
,
23615 dwarf2_per_objfile
*per_objfile
)
23617 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23618 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23621 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23622 On entry *REF_CU is the CU of SRC_DIE.
23623 On exit *REF_CU is the CU of the result.
23624 Returns NULL if the referenced DIE isn't found. */
23626 static struct die_info
*
23627 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23628 struct dwarf2_cu
**ref_cu
)
23630 struct die_info temp_die
;
23631 struct dwarf2_cu
*sig_cu
;
23632 struct die_info
*die
;
23633 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23636 /* While it might be nice to assert sig_type->type == NULL here,
23637 we can get here for DW_AT_imported_declaration where we need
23638 the DIE not the type. */
23640 /* If necessary, add it to the queue and load its DIEs.
23642 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23643 it doesn't mean they are currently loaded. Since we require them
23644 to be loaded, we must check for ourselves. */
23645 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23647 || per_objfile
->get_cu (sig_type
) == nullptr)
23648 read_signatured_type (sig_type
, per_objfile
);
23650 sig_cu
= per_objfile
->get_cu (sig_type
);
23651 gdb_assert (sig_cu
!= NULL
);
23652 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23653 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23654 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23655 to_underlying (temp_die
.sect_off
));
23658 /* For .gdb_index version 7 keep track of included TUs.
23659 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23660 if (per_objfile
->per_bfd
->index_table
!= NULL
23661 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23663 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23673 /* Follow signatured type referenced by ATTR in SRC_DIE.
23674 On entry *REF_CU is the CU of SRC_DIE.
23675 On exit *REF_CU is the CU of the result.
23676 The result is the DIE of the type.
23677 If the referenced type cannot be found an error is thrown. */
23679 static struct die_info
*
23680 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23681 struct dwarf2_cu
**ref_cu
)
23683 ULONGEST signature
= attr
->as_signature ();
23684 struct signatured_type
*sig_type
;
23685 struct die_info
*die
;
23687 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23689 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23690 /* sig_type will be NULL if the signatured type is missing from
23692 if (sig_type
== NULL
)
23694 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23695 " from DIE at %s [in module %s]"),
23696 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23697 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23700 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23703 dump_die_for_error (src_die
);
23704 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23705 " from DIE at %s [in module %s]"),
23706 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23707 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23713 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23714 reading in and processing the type unit if necessary. */
23716 static struct type
*
23717 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23718 struct dwarf2_cu
*cu
)
23720 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23721 struct signatured_type
*sig_type
;
23722 struct dwarf2_cu
*type_cu
;
23723 struct die_info
*type_die
;
23726 sig_type
= lookup_signatured_type (cu
, signature
);
23727 /* sig_type will be NULL if the signatured type is missing from
23729 if (sig_type
== NULL
)
23731 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23732 " from DIE at %s [in module %s]"),
23733 hex_string (signature
), sect_offset_str (die
->sect_off
),
23734 objfile_name (per_objfile
->objfile
));
23735 return build_error_marker_type (cu
, die
);
23738 /* If we already know the type we're done. */
23739 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23740 if (type
!= nullptr)
23744 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23745 if (type_die
!= NULL
)
23747 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23748 is created. This is important, for example, because for c++ classes
23749 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23750 type
= read_type_die (type_die
, type_cu
);
23753 complaint (_("Dwarf Error: Cannot build signatured type %s"
23754 " referenced from DIE at %s [in module %s]"),
23755 hex_string (signature
), sect_offset_str (die
->sect_off
),
23756 objfile_name (per_objfile
->objfile
));
23757 type
= build_error_marker_type (cu
, die
);
23762 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23763 " from DIE at %s [in module %s]"),
23764 hex_string (signature
), sect_offset_str (die
->sect_off
),
23765 objfile_name (per_objfile
->objfile
));
23766 type
= build_error_marker_type (cu
, die
);
23769 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23774 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23775 reading in and processing the type unit if necessary. */
23777 static struct type
*
23778 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23779 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23781 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23782 if (attr
->form_is_ref ())
23784 struct dwarf2_cu
*type_cu
= cu
;
23785 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23787 return read_type_die (type_die
, type_cu
);
23789 else if (attr
->form
== DW_FORM_ref_sig8
)
23791 return get_signatured_type (die
, attr
->as_signature (), cu
);
23795 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23797 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23798 " at %s [in module %s]"),
23799 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23800 objfile_name (per_objfile
->objfile
));
23801 return build_error_marker_type (cu
, die
);
23805 /* Load the DIEs associated with type unit PER_CU into memory. */
23808 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23809 dwarf2_per_objfile
*per_objfile
)
23811 struct signatured_type
*sig_type
;
23813 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23814 gdb_assert (! per_cu
->type_unit_group_p ());
23816 /* We have the per_cu, but we need the signatured_type.
23817 Fortunately this is an easy translation. */
23818 gdb_assert (per_cu
->is_debug_types
);
23819 sig_type
= (struct signatured_type
*) per_cu
;
23821 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23823 read_signatured_type (sig_type
, per_objfile
);
23825 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23828 /* Read in a signatured type and build its CU and DIEs.
23829 If the type is a stub for the real type in a DWO file,
23830 read in the real type from the DWO file as well. */
23833 read_signatured_type (signatured_type
*sig_type
,
23834 dwarf2_per_objfile
*per_objfile
)
23836 gdb_assert (sig_type
->is_debug_types
);
23837 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23839 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23841 if (!reader
.dummy_p
)
23843 struct dwarf2_cu
*cu
= reader
.cu
;
23844 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23846 gdb_assert (cu
->die_hash
== NULL
);
23848 htab_create_alloc_ex (cu
->header
.length
/ 12,
23852 &cu
->comp_unit_obstack
,
23853 hashtab_obstack_allocate
,
23854 dummy_obstack_deallocate
);
23856 if (reader
.comp_unit_die
->has_children
)
23857 reader
.comp_unit_die
->child
23858 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23859 reader
.comp_unit_die
);
23860 cu
->dies
= reader
.comp_unit_die
;
23861 /* comp_unit_die is not stored in die_hash, no need. */
23863 /* We try not to read any attributes in this function, because
23864 not all CUs needed for references have been loaded yet, and
23865 symbol table processing isn't initialized. But we have to
23866 set the CU language, or we won't be able to build types
23867 correctly. Similarly, if we do not read the producer, we can
23868 not apply producer-specific interpretation. */
23869 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23874 sig_type
->tu_read
= 1;
23877 /* Decode simple location descriptions.
23878 Given a pointer to a dwarf block that defines a location, compute
23879 the location and return the value. If COMPUTED is non-null, it is
23880 set to true to indicate that decoding was successful, and false
23881 otherwise. If COMPUTED is null, then this function may emit a
23885 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23887 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23889 size_t size
= blk
->size
;
23890 const gdb_byte
*data
= blk
->data
;
23891 CORE_ADDR stack
[64];
23893 unsigned int bytes_read
, unsnd
;
23896 if (computed
!= nullptr)
23902 stack
[++stacki
] = 0;
23941 stack
[++stacki
] = op
- DW_OP_lit0
;
23976 stack
[++stacki
] = op
- DW_OP_reg0
;
23979 if (computed
== nullptr)
23980 dwarf2_complex_location_expr_complaint ();
23987 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23989 stack
[++stacki
] = unsnd
;
23992 if (computed
== nullptr)
23993 dwarf2_complex_location_expr_complaint ();
24000 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24005 case DW_OP_const1u
:
24006 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24010 case DW_OP_const1s
:
24011 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24015 case DW_OP_const2u
:
24016 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24020 case DW_OP_const2s
:
24021 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24025 case DW_OP_const4u
:
24026 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24030 case DW_OP_const4s
:
24031 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24035 case DW_OP_const8u
:
24036 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24041 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24047 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24052 stack
[stacki
+ 1] = stack
[stacki
];
24057 stack
[stacki
- 1] += stack
[stacki
];
24061 case DW_OP_plus_uconst
:
24062 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24068 stack
[stacki
- 1] -= stack
[stacki
];
24073 /* If we're not the last op, then we definitely can't encode
24074 this using GDB's address_class enum. This is valid for partial
24075 global symbols, although the variable's address will be bogus
24079 if (computed
== nullptr)
24080 dwarf2_complex_location_expr_complaint ();
24086 case DW_OP_GNU_push_tls_address
:
24087 case DW_OP_form_tls_address
:
24088 /* The top of the stack has the offset from the beginning
24089 of the thread control block at which the variable is located. */
24090 /* Nothing should follow this operator, so the top of stack would
24092 /* This is valid for partial global symbols, but the variable's
24093 address will be bogus in the psymtab. Make it always at least
24094 non-zero to not look as a variable garbage collected by linker
24095 which have DW_OP_addr 0. */
24098 if (computed
== nullptr)
24099 dwarf2_complex_location_expr_complaint ();
24106 case DW_OP_GNU_uninit
:
24107 if (computed
!= nullptr)
24112 case DW_OP_GNU_addr_index
:
24113 case DW_OP_GNU_const_index
:
24114 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24120 if (computed
== nullptr)
24122 const char *name
= get_DW_OP_name (op
);
24125 complaint (_("unsupported stack op: '%s'"),
24128 complaint (_("unsupported stack op: '%02x'"),
24132 return (stack
[stacki
]);
24135 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24136 outside of the allocated space. Also enforce minimum>0. */
24137 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24139 if (computed
== nullptr)
24140 complaint (_("location description stack overflow"));
24146 if (computed
== nullptr)
24147 complaint (_("location description stack underflow"));
24152 if (computed
!= nullptr)
24154 return (stack
[stacki
]);
24157 /* memory allocation interface */
24159 static struct dwarf_block
*
24160 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24162 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24165 static struct die_info
*
24166 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24168 struct die_info
*die
;
24169 size_t size
= sizeof (struct die_info
);
24172 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24174 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24175 memset (die
, 0, sizeof (struct die_info
));
24181 /* Macro support. */
24183 /* An overload of dwarf_decode_macros that finds the correct section
24184 and ensures it is read in before calling the other overload. */
24187 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24188 int section_is_gnu
)
24190 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24191 struct objfile
*objfile
= per_objfile
->objfile
;
24192 const struct line_header
*lh
= cu
->line_header
;
24193 unsigned int offset_size
= cu
->header
.offset_size
;
24194 struct dwarf2_section_info
*section
;
24195 const char *section_name
;
24197 if (cu
->dwo_unit
!= nullptr)
24199 if (section_is_gnu
)
24201 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24202 section_name
= ".debug_macro.dwo";
24206 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24207 section_name
= ".debug_macinfo.dwo";
24212 if (section_is_gnu
)
24214 section
= &per_objfile
->per_bfd
->macro
;
24215 section_name
= ".debug_macro";
24219 section
= &per_objfile
->per_bfd
->macinfo
;
24220 section_name
= ".debug_macinfo";
24224 section
->read (objfile
);
24225 if (section
->buffer
== nullptr)
24227 complaint (_("missing %s section"), section_name
);
24231 buildsym_compunit
*builder
= cu
->get_builder ();
24233 struct dwarf2_section_info
*str_offsets_section
;
24234 struct dwarf2_section_info
*str_section
;
24235 gdb::optional
<ULONGEST
> str_offsets_base
;
24237 if (cu
->dwo_unit
!= nullptr)
24239 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24240 ->sections
.str_offsets
;
24241 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24242 str_offsets_base
= cu
->header
.addr_size
;
24246 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24247 str_section
= &per_objfile
->per_bfd
->str
;
24248 str_offsets_base
= cu
->str_offsets_base
;
24251 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24252 offset_size
, offset
, str_section
, str_offsets_section
,
24253 str_offsets_base
, section_is_gnu
);
24256 /* Return the .debug_loc section to use for CU.
24257 For DWO files use .debug_loc.dwo. */
24259 static struct dwarf2_section_info
*
24260 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24262 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24266 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24268 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24270 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24271 : &per_objfile
->per_bfd
->loc
);
24274 /* Return the .debug_rnglists section to use for CU. */
24275 static struct dwarf2_section_info
*
24276 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24278 if (cu
->header
.version
< 5)
24279 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24280 cu
->header
.version
);
24281 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24283 /* Make sure we read the .debug_rnglists section from the file that
24284 contains the DW_AT_ranges attribute we are reading. Normally that
24285 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24286 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24288 if (cu
->dwo_unit
!= nullptr
24289 && tag
!= DW_TAG_compile_unit
24290 && tag
!= DW_TAG_skeleton_unit
)
24292 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24294 if (sections
->rnglists
.size
> 0)
24295 return §ions
->rnglists
;
24297 error (_(".debug_rnglists section is missing from .dwo file."));
24299 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24302 /* A helper function that fills in a dwarf2_loclist_baton. */
24305 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24306 struct dwarf2_loclist_baton
*baton
,
24307 const struct attribute
*attr
)
24309 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24310 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24312 section
->read (per_objfile
->objfile
);
24314 baton
->per_objfile
= per_objfile
;
24315 baton
->per_cu
= cu
->per_cu
;
24316 gdb_assert (baton
->per_cu
);
24317 /* We don't know how long the location list is, but make sure we
24318 don't run off the edge of the section. */
24319 baton
->size
= section
->size
- attr
->as_unsigned ();
24320 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24321 if (cu
->base_address
.has_value ())
24322 baton
->base_address
= *cu
->base_address
;
24324 baton
->base_address
= 0;
24325 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24329 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24330 struct dwarf2_cu
*cu
, int is_block
)
24332 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24333 struct objfile
*objfile
= per_objfile
->objfile
;
24334 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24336 if (attr
->form_is_section_offset ()
24337 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24338 the section. If so, fall through to the complaint in the
24340 && attr
->as_unsigned () < section
->get_size (objfile
))
24342 struct dwarf2_loclist_baton
*baton
;
24344 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24346 fill_in_loclist_baton (cu
, baton
, attr
);
24348 if (!cu
->base_address
.has_value ())
24349 complaint (_("Location list used without "
24350 "specifying the CU base address."));
24352 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24353 ? dwarf2_loclist_block_index
24354 : dwarf2_loclist_index
);
24355 SYMBOL_LOCATION_BATON (sym
) = baton
;
24359 struct dwarf2_locexpr_baton
*baton
;
24361 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24362 baton
->per_objfile
= per_objfile
;
24363 baton
->per_cu
= cu
->per_cu
;
24364 gdb_assert (baton
->per_cu
);
24366 if (attr
->form_is_block ())
24368 /* Note that we're just copying the block's data pointer
24369 here, not the actual data. We're still pointing into the
24370 info_buffer for SYM's objfile; right now we never release
24371 that buffer, but when we do clean up properly this may
24373 struct dwarf_block
*block
= attr
->as_block ();
24374 baton
->size
= block
->size
;
24375 baton
->data
= block
->data
;
24379 dwarf2_invalid_attrib_class_complaint ("location description",
24380 sym
->natural_name ());
24384 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24385 ? dwarf2_locexpr_block_index
24386 : dwarf2_locexpr_index
);
24387 SYMBOL_LOCATION_BATON (sym
) = baton
;
24393 const comp_unit_head
*
24394 dwarf2_per_cu_data::get_header () const
24396 if (!m_header_read_in
)
24398 const gdb_byte
*info_ptr
24399 = this->section
->buffer
+ to_underlying (this->sect_off
);
24401 memset (&m_header
, 0, sizeof (m_header
));
24403 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24404 rcuh_kind::COMPILE
);
24406 m_header_read_in
= true;
24415 dwarf2_per_cu_data::addr_size () const
24417 return this->get_header ()->addr_size
;
24423 dwarf2_per_cu_data::offset_size () const
24425 return this->get_header ()->offset_size
;
24431 dwarf2_per_cu_data::ref_addr_size () const
24433 const comp_unit_head
*header
= this->get_header ();
24435 if (header
->version
== 2)
24436 return header
->addr_size
;
24438 return header
->offset_size
;
24441 /* A helper function for dwarf2_find_containing_comp_unit that returns
24442 the index of the result, and that searches a vector. It will
24443 return a result even if the offset in question does not actually
24444 occur in any CU. This is separate so that it can be unit
24448 dwarf2_find_containing_comp_unit
24449 (sect_offset sect_off
,
24450 unsigned int offset_in_dwz
,
24451 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24456 high
= all_comp_units
.size () - 1;
24459 struct dwarf2_per_cu_data
*mid_cu
;
24460 int mid
= low
+ (high
- low
) / 2;
24462 mid_cu
= all_comp_units
[mid
].get ();
24463 if (mid_cu
->is_dwz
> offset_in_dwz
24464 || (mid_cu
->is_dwz
== offset_in_dwz
24465 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24470 gdb_assert (low
== high
);
24474 /* Locate the .debug_info compilation unit from CU's objfile which contains
24475 the DIE at OFFSET. Raises an error on failure. */
24477 static struct dwarf2_per_cu_data
*
24478 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24479 unsigned int offset_in_dwz
,
24480 dwarf2_per_objfile
*per_objfile
)
24482 int low
= dwarf2_find_containing_comp_unit
24483 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24484 dwarf2_per_cu_data
*this_cu
24485 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24487 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24489 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24490 error (_("Dwarf Error: could not find partial DIE containing "
24491 "offset %s [in module %s]"),
24492 sect_offset_str (sect_off
),
24493 bfd_get_filename (per_objfile
->objfile
->obfd
));
24495 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24497 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24501 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24502 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24503 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24504 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24511 namespace selftests
{
24512 namespace find_containing_comp_unit
{
24517 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24518 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24519 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24520 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24521 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24522 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24523 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24524 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24527 two
->sect_off
= sect_offset (one
->length
);
24532 four
->sect_off
= sect_offset (three
->length
);
24536 std::vector
<dwarf2_per_cu_data_up
> units
;
24537 units
.push_back (std::move (one
));
24538 units
.push_back (std::move (two
));
24539 units
.push_back (std::move (three
));
24540 units
.push_back (std::move (four
));
24544 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24545 SELF_CHECK (units
[result
].get () == one_ptr
);
24546 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24547 SELF_CHECK (units
[result
].get () == one_ptr
);
24548 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24549 SELF_CHECK (units
[result
].get () == two_ptr
);
24551 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24552 SELF_CHECK (units
[result
].get () == three_ptr
);
24553 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24554 SELF_CHECK (units
[result
].get () == three_ptr
);
24555 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24556 SELF_CHECK (units
[result
].get () == four_ptr
);
24562 #endif /* GDB_SELF_TEST */
24564 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24567 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24568 enum language pretend_language
)
24570 struct attribute
*attr
;
24572 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24574 /* Set the language we're debugging. */
24575 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24576 if (cu
->producer
!= nullptr
24577 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
24579 /* The XLCL doesn't generate DW_LANG_OpenCL because this
24580 attribute is not standardised yet. As a workaround for the
24581 language detection we fall back to the DW_AT_producer
24583 cu
->per_cu
->lang
= language_opencl
;
24585 else if (cu
->producer
!= nullptr
24586 && strstr (cu
->producer
, "GNU Go ") != NULL
)
24588 /* Similar hack for Go. */
24589 cu
->per_cu
->lang
= language_go
;
24591 else if (attr
!= nullptr)
24592 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
24594 cu
->per_cu
->lang
= pretend_language
;
24595 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
24601 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24603 auto it
= m_dwarf2_cus
.find (per_cu
);
24604 if (it
== m_dwarf2_cus
.end ())
24613 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24615 gdb_assert (this->get_cu (per_cu
) == nullptr);
24617 m_dwarf2_cus
[per_cu
] = cu
;
24623 dwarf2_per_objfile::age_comp_units ()
24625 dwarf_read_debug_printf_v ("running");
24627 /* This is not expected to be called in the middle of CU expansion. There is
24628 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24629 loaded in memory. Calling age_comp_units while the queue is in use could
24630 make us free the DIEs for a CU that is in the queue and therefore break
24632 gdb_assert (!this->per_bfd
->queue
.has_value ());
24634 /* Start by clearing all marks. */
24635 for (auto pair
: m_dwarf2_cus
)
24636 pair
.second
->clear_mark ();
24638 /* Traverse all CUs, mark them and their dependencies if used recently
24640 for (auto pair
: m_dwarf2_cus
)
24642 dwarf2_cu
*cu
= pair
.second
;
24645 if (cu
->last_used
<= dwarf_max_cache_age
)
24649 /* Delete all CUs still not marked. */
24650 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24652 dwarf2_cu
*cu
= it
->second
;
24654 if (!cu
->is_marked ())
24656 dwarf_read_debug_printf_v ("deleting old CU %s",
24657 sect_offset_str (cu
->per_cu
->sect_off
));
24659 it
= m_dwarf2_cus
.erase (it
);
24669 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24671 auto it
= m_dwarf2_cus
.find (per_cu
);
24672 if (it
== m_dwarf2_cus
.end ())
24677 m_dwarf2_cus
.erase (it
);
24680 dwarf2_per_objfile::~dwarf2_per_objfile ()
24685 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24686 We store these in a hash table separate from the DIEs, and preserve them
24687 when the DIEs are flushed out of cache.
24689 The CU "per_cu" pointer is needed because offset alone is not enough to
24690 uniquely identify the type. A file may have multiple .debug_types sections,
24691 or the type may come from a DWO file. Furthermore, while it's more logical
24692 to use per_cu->section+offset, with Fission the section with the data is in
24693 the DWO file but we don't know that section at the point we need it.
24694 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24695 because we can enter the lookup routine, get_die_type_at_offset, from
24696 outside this file, and thus won't necessarily have PER_CU->cu.
24697 Fortunately, PER_CU is stable for the life of the objfile. */
24699 struct dwarf2_per_cu_offset_and_type
24701 const struct dwarf2_per_cu_data
*per_cu
;
24702 sect_offset sect_off
;
24706 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24709 per_cu_offset_and_type_hash (const void *item
)
24711 const struct dwarf2_per_cu_offset_and_type
*ofs
24712 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24714 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24717 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24720 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24722 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24723 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24724 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24725 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24727 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24728 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24731 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24732 table if necessary. For convenience, return TYPE.
24734 The DIEs reading must have careful ordering to:
24735 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24736 reading current DIE.
24737 * Not trying to dereference contents of still incompletely read in types
24738 while reading in other DIEs.
24739 * Enable referencing still incompletely read in types just by a pointer to
24740 the type without accessing its fields.
24742 Therefore caller should follow these rules:
24743 * Try to fetch any prerequisite types we may need to build this DIE type
24744 before building the type and calling set_die_type.
24745 * After building type call set_die_type for current DIE as soon as
24746 possible before fetching more types to complete the current type.
24747 * Make the type as complete as possible before fetching more types. */
24749 static struct type
*
24750 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24751 bool skip_data_location
)
24753 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24754 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24755 struct objfile
*objfile
= per_objfile
->objfile
;
24756 struct attribute
*attr
;
24757 struct dynamic_prop prop
;
24759 /* For Ada types, make sure that the gnat-specific data is always
24760 initialized (if not already set). There are a few types where
24761 we should not be doing so, because the type-specific area is
24762 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24763 where the type-specific area is used to store the floatformat).
24764 But this is not a problem, because the gnat-specific information
24765 is actually not needed for these types. */
24766 if (need_gnat_info (cu
)
24767 && type
->code () != TYPE_CODE_FUNC
24768 && type
->code () != TYPE_CODE_FLT
24769 && type
->code () != TYPE_CODE_METHODPTR
24770 && type
->code () != TYPE_CODE_MEMBERPTR
24771 && type
->code () != TYPE_CODE_METHOD
24772 && type
->code () != TYPE_CODE_FIXED_POINT
24773 && !HAVE_GNAT_AUX_INFO (type
))
24774 INIT_GNAT_SPECIFIC (type
);
24776 /* Read DW_AT_allocated and set in type. */
24777 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24780 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24781 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24782 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24785 /* Read DW_AT_associated and set in type. */
24786 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24789 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24790 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24791 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24794 /* Read DW_AT_data_location and set in type. */
24795 if (!skip_data_location
)
24797 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24798 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24799 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24802 if (per_objfile
->die_type_hash
== NULL
)
24803 per_objfile
->die_type_hash
24804 = htab_up (htab_create_alloc (127,
24805 per_cu_offset_and_type_hash
,
24806 per_cu_offset_and_type_eq
,
24807 NULL
, xcalloc
, xfree
));
24809 ofs
.per_cu
= cu
->per_cu
;
24810 ofs
.sect_off
= die
->sect_off
;
24812 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24813 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24815 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24816 sect_offset_str (die
->sect_off
));
24817 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24818 struct dwarf2_per_cu_offset_and_type
);
24823 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24824 or return NULL if the die does not have a saved type. */
24826 static struct type
*
24827 get_die_type_at_offset (sect_offset sect_off
,
24828 dwarf2_per_cu_data
*per_cu
,
24829 dwarf2_per_objfile
*per_objfile
)
24831 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24833 if (per_objfile
->die_type_hash
== NULL
)
24836 ofs
.per_cu
= per_cu
;
24837 ofs
.sect_off
= sect_off
;
24838 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24839 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24846 /* Look up the type for DIE in CU in die_type_hash,
24847 or return NULL if DIE does not have a saved type. */
24849 static struct type
*
24850 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24852 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24855 /* Trivial hash function for partial_die_info: the hash value of a DIE
24856 is its offset in .debug_info for this objfile. */
24859 partial_die_hash (const void *item
)
24861 const struct partial_die_info
*part_die
24862 = (const struct partial_die_info
*) item
;
24864 return to_underlying (part_die
->sect_off
);
24867 /* Trivial comparison function for partial_die_info structures: two DIEs
24868 are equal if they have the same offset. */
24871 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24873 const struct partial_die_info
*part_die_lhs
24874 = (const struct partial_die_info
*) item_lhs
;
24875 const struct partial_die_info
*part_die_rhs
24876 = (const struct partial_die_info
*) item_rhs
;
24878 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24881 struct cmd_list_element
*set_dwarf_cmdlist
;
24882 struct cmd_list_element
*show_dwarf_cmdlist
;
24885 show_check_physname (struct ui_file
*file
, int from_tty
,
24886 struct cmd_list_element
*c
, const char *value
)
24888 fprintf_filtered (file
,
24889 _("Whether to check \"physname\" is %s.\n"),
24893 void _initialize_dwarf2_read ();
24895 _initialize_dwarf2_read ()
24897 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24898 Set DWARF specific variables.\n\
24899 Configure DWARF variables such as the cache size."),
24900 &set_dwarf_cmdlist
,
24901 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24903 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24904 Show DWARF specific variables.\n\
24905 Show DWARF variables such as the cache size."),
24906 &show_dwarf_cmdlist
,
24907 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24909 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24910 &dwarf_max_cache_age
, _("\
24911 Set the upper bound on the age of cached DWARF compilation units."), _("\
24912 Show the upper bound on the age of cached DWARF compilation units."), _("\
24913 A higher limit means that cached compilation units will be stored\n\
24914 in memory longer, and more total memory will be used. Zero disables\n\
24915 caching, which can slow down startup."),
24917 show_dwarf_max_cache_age
,
24918 &set_dwarf_cmdlist
,
24919 &show_dwarf_cmdlist
);
24921 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24922 Set debugging of the DWARF reader."), _("\
24923 Show debugging of the DWARF reader."), _("\
24924 When enabled (non-zero), debugging messages are printed during DWARF\n\
24925 reading and symtab expansion. A value of 1 (one) provides basic\n\
24926 information. A value greater than 1 provides more verbose information."),
24929 &setdebuglist
, &showdebuglist
);
24931 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24932 Set debugging of the DWARF DIE reader."), _("\
24933 Show debugging of the DWARF DIE reader."), _("\
24934 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24935 The value is the maximum depth to print."),
24938 &setdebuglist
, &showdebuglist
);
24940 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24941 Set debugging of the dwarf line reader."), _("\
24942 Show debugging of the dwarf line reader."), _("\
24943 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24944 A value of 1 (one) provides basic information.\n\
24945 A value greater than 1 provides more verbose information."),
24948 &setdebuglist
, &showdebuglist
);
24950 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24951 Set cross-checking of \"physname\" code against demangler."), _("\
24952 Show cross-checking of \"physname\" code against demangler."), _("\
24953 When enabled, GDB's internal \"physname\" code is checked against\n\
24955 NULL
, show_check_physname
,
24956 &setdebuglist
, &showdebuglist
);
24958 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24959 no_class
, &use_deprecated_index_sections
, _("\
24960 Set whether to use deprecated gdb_index sections."), _("\
24961 Show whether to use deprecated gdb_index sections."), _("\
24962 When enabled, deprecated .gdb_index sections are used anyway.\n\
24963 Normally they are ignored either because of a missing feature or\n\
24964 performance issue.\n\
24965 Warning: This option must be enabled before gdb reads the file."),
24968 &setlist
, &showlist
);
24970 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24971 &dwarf2_locexpr_funcs
);
24972 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24973 &dwarf2_loclist_funcs
);
24975 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24976 &dwarf2_block_frame_base_locexpr_funcs
);
24977 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24978 &dwarf2_block_frame_base_loclist_funcs
);
24981 selftests::register_test ("dw2_expand_symtabs_matching",
24982 selftests::dw2_expand_symtabs_matching::run_test
);
24983 selftests::register_test ("dwarf2_find_containing_comp_unit",
24984 selftests::find_containing_comp_unit::run_test
);