1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2022 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit-head.h"
36 #include "dwarf2/cu.h"
37 #include "dwarf2/index-cache.h"
38 #include "dwarf2/index-common.h"
39 #include "dwarf2/leb.h"
40 #include "dwarf2/line-header.h"
41 #include "dwarf2/dwz.h"
42 #include "dwarf2/macro.h"
43 #include "dwarf2/die.h"
44 #include "dwarf2/sect-names.h"
45 #include "dwarf2/stringify.h"
46 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
91 #include <unordered_set>
92 #include "dwarf2/abbrev-cache.h"
93 #include "cooked-index.h"
94 #include "split-name.h"
95 #include "gdbsupport/parallel-for.h"
96 #include "gdbsupport/thread-pool.h"
98 /* When == 1, print basic high level tracing messages.
99 When > 1, be more verbose.
100 This is in contrast to the low level DIE reading of dwarf_die_debug. */
101 static unsigned int dwarf_read_debug
= 0;
103 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
105 #define dwarf_read_debug_printf(fmt, ...) \
106 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
109 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
111 #define dwarf_read_debug_printf_v(fmt, ...) \
112 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
115 /* When non-zero, dump DIEs after they are read in. */
116 static unsigned int dwarf_die_debug
= 0;
118 /* When non-zero, dump line number entries as they are read in. */
119 unsigned int dwarf_line_debug
= 0;
121 /* When true, cross-check physname against demangler. */
122 static bool check_physname
= false;
124 /* When true, do not reject deprecated .gdb_index sections. */
125 static bool use_deprecated_index_sections
= false;
127 /* This is used to store the data that is always per objfile. */
128 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
130 /* These are used to store the dwarf2_per_bfd objects.
132 objfiles having the same BFD, which doesn't require relocations, are going to
133 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
135 Other objfiles are not going to share a dwarf2_per_bfd with any other
136 objfiles, so they'll have their own version kept in the _objfile_data_key
138 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
139 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
141 /* The "aclass" indices for various kinds of computed DWARF symbols. */
143 static int dwarf2_locexpr_index
;
144 static int dwarf2_loclist_index
;
145 static int dwarf2_locexpr_block_index
;
146 static int dwarf2_loclist_block_index
;
148 /* Size of .debug_loclists section header for 32-bit DWARF format. */
149 #define LOCLIST_HEADER_SIZE32 12
151 /* Size of .debug_loclists section header for 64-bit DWARF format. */
152 #define LOCLIST_HEADER_SIZE64 20
154 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
155 #define RNGLIST_HEADER_SIZE32 12
157 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
158 #define RNGLIST_HEADER_SIZE64 20
160 /* An index into a (C++) symbol name component in a symbol name as
161 recorded in the mapped_index's symbol table. For each C++ symbol
162 in the symbol table, we record one entry for the start of each
163 component in the symbol in a table of name components, and then
164 sort the table, in order to be able to binary search symbol names,
165 ignoring leading namespaces, both completion and regular look up.
166 For example, for symbol "A::B::C", we'll have an entry that points
167 to "A::B::C", another that points to "B::C", and another for "C".
168 Note that function symbols in GDB index have no parameter
169 information, just the function/method names. You can convert a
170 name_component to a "const char *" using the
171 'mapped_index::symbol_name_at(offset_type)' method. */
173 struct name_component
175 /* Offset in the symbol name where the component starts. Stored as
176 a (32-bit) offset instead of a pointer to save memory and improve
177 locality on 64-bit architectures. */
178 offset_type name_offset
;
180 /* The symbol's index in the symbol and constant pool tables of a
185 /* Base class containing bits shared by both .gdb_index and
186 .debug_name indexes. */
188 struct mapped_index_base
190 mapped_index_base () = default;
191 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
193 /* The name_component table (a sorted vector). See name_component's
194 description above. */
195 std::vector
<name_component
> name_components
;
197 /* How NAME_COMPONENTS is sorted. */
198 enum case_sensitivity name_components_casing
;
200 /* Return the number of names in the symbol table. */
201 virtual size_t symbol_name_count () const = 0;
203 /* Get the name of the symbol at IDX in the symbol table. */
204 virtual const char *symbol_name_at
205 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
207 /* Return whether the name at IDX in the symbol table should be
209 virtual bool symbol_name_slot_invalid (offset_type idx
) const
214 /* Build the symbol name component sorted vector, if we haven't
216 void build_name_components (dwarf2_per_objfile
*per_objfile
);
218 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
219 possible matches for LN_NO_PARAMS in the name component
221 std::pair
<std::vector
<name_component
>::const_iterator
,
222 std::vector
<name_component
>::const_iterator
>
223 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
225 dwarf2_per_objfile
*per_objfile
) const;
227 /* Prevent deleting/destroying via a base class pointer. */
229 ~mapped_index_base() = default;
232 /* This is a view into the index that converts from bytes to an
233 offset_type, and allows indexing. Unaligned bytes are specifically
234 allowed here, and handled via unpacking. */
239 offset_view () = default;
241 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
246 /* Extract the INDEXth offset_type from the array. */
247 offset_type
operator[] (size_t index
) const
249 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
250 return (offset_type
) extract_unsigned_integer (bytes
,
251 sizeof (offset_type
),
255 /* Return the number of offset_types in this array. */
258 return m_bytes
.size () / sizeof (offset_type
);
261 /* Return true if this view is empty. */
264 return m_bytes
.empty ();
268 /* The underlying bytes. */
269 gdb::array_view
<const gdb_byte
> m_bytes
;
272 /* A description of the mapped index. The file format is described in
273 a comment by the code that writes the index. */
274 struct mapped_index final
: public mapped_index_base
276 /* Index data format version. */
279 /* The address table data. */
280 gdb::array_view
<const gdb_byte
> address_table
;
282 /* The symbol table, implemented as a hash table. */
283 offset_view symbol_table
;
285 /* A pointer to the constant pool. */
286 gdb::array_view
<const gdb_byte
> constant_pool
;
288 /* Return the index into the constant pool of the name of the IDXth
289 symbol in the symbol table. */
290 offset_type
symbol_name_index (offset_type idx
) const
292 return symbol_table
[2 * idx
];
295 /* Return the index into the constant pool of the CU vector of the
296 IDXth symbol in the symbol table. */
297 offset_type
symbol_vec_index (offset_type idx
) const
299 return symbol_table
[2 * idx
+ 1];
302 bool symbol_name_slot_invalid (offset_type idx
) const override
304 return (symbol_name_index (idx
) == 0
305 && symbol_vec_index (idx
) == 0);
308 /* Convenience method to get at the name of the symbol at IDX in the
310 const char *symbol_name_at
311 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
313 return (const char *) (this->constant_pool
.data ()
314 + symbol_name_index (idx
));
317 size_t symbol_name_count () const override
318 { return this->symbol_table
.size () / 2; }
321 /* A description of the mapped .debug_names.
322 Uninitialized map has CU_COUNT 0. */
323 struct mapped_debug_names final
: public mapped_index_base
325 bfd_endian dwarf5_byte_order
;
326 bool dwarf5_is_dwarf64
;
327 bool augmentation_is_gdb
;
329 uint32_t cu_count
= 0;
330 uint32_t tu_count
, bucket_count
, name_count
;
331 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
332 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
333 const gdb_byte
*name_table_string_offs_reordered
;
334 const gdb_byte
*name_table_entry_offs_reordered
;
335 const gdb_byte
*entry_pool
;
342 /* Attribute name DW_IDX_*. */
345 /* Attribute form DW_FORM_*. */
348 /* Value if FORM is DW_FORM_implicit_const. */
349 LONGEST implicit_const
;
351 std::vector
<attr
> attr_vec
;
354 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
356 const char *namei_to_name
357 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
359 /* Implementation of the mapped_index_base virtual interface, for
360 the name_components cache. */
362 const char *symbol_name_at
363 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
364 { return namei_to_name (idx
, per_objfile
); }
366 size_t symbol_name_count () const override
367 { return this->name_count
; }
370 /* See dwarf2/read.h. */
373 get_dwarf2_per_objfile (struct objfile
*objfile
)
375 return dwarf2_objfile_data_key
.get (objfile
);
378 /* Default names of the debugging sections. */
380 /* Note that if the debugging section has been compressed, it might
381 have a name like .zdebug_info. */
383 const struct dwarf2_debug_sections dwarf2_elf_names
=
385 { ".debug_info", ".zdebug_info" },
386 { ".debug_abbrev", ".zdebug_abbrev" },
387 { ".debug_line", ".zdebug_line" },
388 { ".debug_loc", ".zdebug_loc" },
389 { ".debug_loclists", ".zdebug_loclists" },
390 { ".debug_macinfo", ".zdebug_macinfo" },
391 { ".debug_macro", ".zdebug_macro" },
392 { ".debug_str", ".zdebug_str" },
393 { ".debug_str_offsets", ".zdebug_str_offsets" },
394 { ".debug_line_str", ".zdebug_line_str" },
395 { ".debug_ranges", ".zdebug_ranges" },
396 { ".debug_rnglists", ".zdebug_rnglists" },
397 { ".debug_types", ".zdebug_types" },
398 { ".debug_addr", ".zdebug_addr" },
399 { ".debug_frame", ".zdebug_frame" },
400 { ".eh_frame", NULL
},
401 { ".gdb_index", ".zgdb_index" },
402 { ".debug_names", ".zdebug_names" },
403 { ".debug_aranges", ".zdebug_aranges" },
407 /* List of DWO/DWP sections. */
409 static const struct dwop_section_names
411 struct dwarf2_section_names abbrev_dwo
;
412 struct dwarf2_section_names info_dwo
;
413 struct dwarf2_section_names line_dwo
;
414 struct dwarf2_section_names loc_dwo
;
415 struct dwarf2_section_names loclists_dwo
;
416 struct dwarf2_section_names macinfo_dwo
;
417 struct dwarf2_section_names macro_dwo
;
418 struct dwarf2_section_names rnglists_dwo
;
419 struct dwarf2_section_names str_dwo
;
420 struct dwarf2_section_names str_offsets_dwo
;
421 struct dwarf2_section_names types_dwo
;
422 struct dwarf2_section_names cu_index
;
423 struct dwarf2_section_names tu_index
;
427 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
428 { ".debug_info.dwo", ".zdebug_info.dwo" },
429 { ".debug_line.dwo", ".zdebug_line.dwo" },
430 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
431 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
432 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
433 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
434 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
435 { ".debug_str.dwo", ".zdebug_str.dwo" },
436 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
437 { ".debug_types.dwo", ".zdebug_types.dwo" },
438 { ".debug_cu_index", ".zdebug_cu_index" },
439 { ".debug_tu_index", ".zdebug_tu_index" },
442 /* local data types */
444 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
445 begin with a header, which contains the following information. */
446 struct loclists_rnglists_header
448 /* A 4-byte or 12-byte length containing the length of the
449 set of entries for this compilation unit, not including the
450 length field itself. */
453 /* A 2-byte version identifier. */
456 /* A 1-byte unsigned integer containing the size in bytes of an address on
457 the target system. */
458 unsigned char addr_size
;
460 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
461 on the target system. */
462 unsigned char segment_collector_size
;
464 /* A 4-byte count of the number of offsets that follow the header. */
465 unsigned int offset_entry_count
;
468 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
469 This includes type_unit_group and quick_file_names. */
471 struct stmt_list_hash
473 /* The DWO unit this table is from or NULL if there is none. */
474 struct dwo_unit
*dwo_unit
;
476 /* Offset in .debug_line or .debug_line.dwo. */
477 sect_offset line_sect_off
;
480 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
481 an object of this type. This contains elements of type unit groups
482 that can be shared across objfiles. The non-shareable parts are in
483 type_unit_group_unshareable. */
485 struct type_unit_group
: public dwarf2_per_cu_data
487 /* The TUs that share this DW_AT_stmt_list entry.
488 This is added to while parsing type units to build partial symtabs,
489 and is deleted afterwards and not used again. */
490 std::vector
<signatured_type
*> *tus
= nullptr;
492 /* The data used to construct the hash key. */
493 struct stmt_list_hash hash
{};
496 /* These sections are what may appear in a (real or virtual) DWO file. */
500 struct dwarf2_section_info abbrev
;
501 struct dwarf2_section_info line
;
502 struct dwarf2_section_info loc
;
503 struct dwarf2_section_info loclists
;
504 struct dwarf2_section_info macinfo
;
505 struct dwarf2_section_info macro
;
506 struct dwarf2_section_info rnglists
;
507 struct dwarf2_section_info str
;
508 struct dwarf2_section_info str_offsets
;
509 /* In the case of a virtual DWO file, these two are unused. */
510 struct dwarf2_section_info info
;
511 std::vector
<dwarf2_section_info
> types
;
514 /* CUs/TUs in DWP/DWO files. */
518 /* Backlink to the containing struct dwo_file. */
519 struct dwo_file
*dwo_file
;
521 /* The "id" that distinguishes this CU/TU.
522 .debug_info calls this "dwo_id", .debug_types calls this "signature".
523 Since signatures came first, we stick with it for consistency. */
526 /* The section this CU/TU lives in, in the DWO file. */
527 struct dwarf2_section_info
*section
;
529 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
530 sect_offset sect_off
;
533 /* For types, offset in the type's DIE of the type defined by this TU. */
534 cu_offset type_offset_in_tu
;
537 /* include/dwarf2.h defines the DWP section codes.
538 It defines a max value but it doesn't define a min value, which we
539 use for error checking, so provide one. */
541 enum dwp_v2_section_ids
546 /* Data for one DWO file.
548 This includes virtual DWO files (a virtual DWO file is a DWO file as it
549 appears in a DWP file). DWP files don't really have DWO files per se -
550 comdat folding of types "loses" the DWO file they came from, and from
551 a high level view DWP files appear to contain a mass of random types.
552 However, to maintain consistency with the non-DWP case we pretend DWP
553 files contain virtual DWO files, and we assign each TU with one virtual
554 DWO file (generally based on the line and abbrev section offsets -
555 a heuristic that seems to work in practice). */
559 dwo_file () = default;
560 DISABLE_COPY_AND_ASSIGN (dwo_file
);
562 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
563 For virtual DWO files the name is constructed from the section offsets
564 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
565 from related CU+TUs. */
566 const char *dwo_name
= nullptr;
568 /* The DW_AT_comp_dir attribute. */
569 const char *comp_dir
= nullptr;
571 /* The bfd, when the file is open. Otherwise this is NULL.
572 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
573 gdb_bfd_ref_ptr dbfd
;
575 /* The sections that make up this DWO file.
576 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
577 sections (for lack of a better name). */
578 struct dwo_sections sections
{};
580 /* The CUs in the file.
581 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
582 an extension to handle LLVM's Link Time Optimization output (where
583 multiple source files may be compiled into a single object/dwo pair). */
586 /* Table of TUs in the file.
587 Each element is a struct dwo_unit. */
591 /* These sections are what may appear in a DWP file. */
595 /* These are used by all DWP versions (1, 2 and 5). */
596 struct dwarf2_section_info str
;
597 struct dwarf2_section_info cu_index
;
598 struct dwarf2_section_info tu_index
;
600 /* These are only used by DWP version 2 and version 5 files.
601 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
602 sections are referenced by section number, and are not recorded here.
603 In DWP version 2 or 5 there is at most one copy of all these sections,
604 each section being (effectively) comprised of the concatenation of all of
605 the individual sections that exist in the version 1 format.
606 To keep the code simple we treat each of these concatenated pieces as a
607 section itself (a virtual section?). */
608 struct dwarf2_section_info abbrev
;
609 struct dwarf2_section_info info
;
610 struct dwarf2_section_info line
;
611 struct dwarf2_section_info loc
;
612 struct dwarf2_section_info loclists
;
613 struct dwarf2_section_info macinfo
;
614 struct dwarf2_section_info macro
;
615 struct dwarf2_section_info rnglists
;
616 struct dwarf2_section_info str_offsets
;
617 struct dwarf2_section_info types
;
620 /* These sections are what may appear in a virtual DWO file in DWP version 1.
621 A virtual DWO file is a DWO file as it appears in a DWP file. */
623 struct virtual_v1_dwo_sections
625 struct dwarf2_section_info abbrev
;
626 struct dwarf2_section_info line
;
627 struct dwarf2_section_info loc
;
628 struct dwarf2_section_info macinfo
;
629 struct dwarf2_section_info macro
;
630 struct dwarf2_section_info str_offsets
;
631 /* Each DWP hash table entry records one CU or one TU.
632 That is recorded here, and copied to dwo_unit.section. */
633 struct dwarf2_section_info info_or_types
;
636 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
637 In version 2, the sections of the DWO files are concatenated together
638 and stored in one section of that name. Thus each ELF section contains
639 several "virtual" sections. */
641 struct virtual_v2_or_v5_dwo_sections
643 bfd_size_type abbrev_offset
;
644 bfd_size_type abbrev_size
;
646 bfd_size_type line_offset
;
647 bfd_size_type line_size
;
649 bfd_size_type loc_offset
;
650 bfd_size_type loc_size
;
652 bfd_size_type loclists_offset
;
653 bfd_size_type loclists_size
;
655 bfd_size_type macinfo_offset
;
656 bfd_size_type macinfo_size
;
658 bfd_size_type macro_offset
;
659 bfd_size_type macro_size
;
661 bfd_size_type rnglists_offset
;
662 bfd_size_type rnglists_size
;
664 bfd_size_type str_offsets_offset
;
665 bfd_size_type str_offsets_size
;
667 /* Each DWP hash table entry records one CU or one TU.
668 That is recorded here, and copied to dwo_unit.section. */
669 bfd_size_type info_or_types_offset
;
670 bfd_size_type info_or_types_size
;
673 /* Contents of DWP hash tables. */
675 struct dwp_hash_table
677 uint32_t version
, nr_columns
;
678 uint32_t nr_units
, nr_slots
;
679 const gdb_byte
*hash_table
, *unit_table
;
684 const gdb_byte
*indices
;
688 /* This is indexed by column number and gives the id of the section
690 #define MAX_NR_V2_DWO_SECTIONS \
691 (1 /* .debug_info or .debug_types */ \
692 + 1 /* .debug_abbrev */ \
693 + 1 /* .debug_line */ \
694 + 1 /* .debug_loc */ \
695 + 1 /* .debug_str_offsets */ \
696 + 1 /* .debug_macro or .debug_macinfo */)
697 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
698 const gdb_byte
*offsets
;
699 const gdb_byte
*sizes
;
703 /* This is indexed by column number and gives the id of the section
705 #define MAX_NR_V5_DWO_SECTIONS \
706 (1 /* .debug_info */ \
707 + 1 /* .debug_abbrev */ \
708 + 1 /* .debug_line */ \
709 + 1 /* .debug_loclists */ \
710 + 1 /* .debug_str_offsets */ \
711 + 1 /* .debug_macro */ \
712 + 1 /* .debug_rnglists */)
713 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
714 const gdb_byte
*offsets
;
715 const gdb_byte
*sizes
;
720 /* Data for one DWP file. */
724 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
726 dbfd (std::move (abfd
))
730 /* Name of the file. */
733 /* File format version. */
737 gdb_bfd_ref_ptr dbfd
;
739 /* Section info for this file. */
740 struct dwp_sections sections
{};
742 /* Table of CUs in the file. */
743 const struct dwp_hash_table
*cus
= nullptr;
745 /* Table of TUs in the file. */
746 const struct dwp_hash_table
*tus
= nullptr;
748 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
752 /* Table to map ELF section numbers to their sections.
753 This is only needed for the DWP V1 file format. */
754 unsigned int num_sections
= 0;
755 asection
**elf_sections
= nullptr;
758 /* Struct used to pass misc. parameters to read_die_and_children, et
759 al. which are used for both .debug_info and .debug_types dies.
760 All parameters here are unchanging for the life of the call. This
761 struct exists to abstract away the constant parameters of die reading. */
763 struct die_reader_specs
765 /* The bfd of die_section. */
768 /* The CU of the DIE we are parsing. */
769 struct dwarf2_cu
*cu
;
771 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
772 struct dwo_file
*dwo_file
;
774 /* The section the die comes from.
775 This is either .debug_info or .debug_types, or the .dwo variants. */
776 struct dwarf2_section_info
*die_section
;
778 /* die_section->buffer. */
779 const gdb_byte
*buffer
;
781 /* The end of the buffer. */
782 const gdb_byte
*buffer_end
;
784 /* The abbreviation table to use when reading the DIEs. */
785 struct abbrev_table
*abbrev_table
;
788 /* A subclass of die_reader_specs that holds storage and has complex
789 constructor and destructor behavior. */
791 class cutu_reader
: public die_reader_specs
795 cutu_reader (dwarf2_per_cu_data
*this_cu
,
796 dwarf2_per_objfile
*per_objfile
,
797 struct abbrev_table
*abbrev_table
,
798 dwarf2_cu
*existing_cu
,
800 abbrev_cache
*cache
= nullptr);
802 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
803 dwarf2_per_objfile
*per_objfile
,
804 struct dwarf2_cu
*parent_cu
= nullptr,
805 struct dwo_file
*dwo_file
= nullptr);
807 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
809 cutu_reader (cutu_reader
&&) = default;
811 const gdb_byte
*info_ptr
= nullptr;
812 struct die_info
*comp_unit_die
= nullptr;
813 bool dummy_p
= false;
815 /* Release the new CU, putting it on the chain. This cannot be done
819 /* Release the abbrev table, transferring ownership to the
821 abbrev_table_up
release_abbrev_table ()
823 return std::move (m_abbrev_table_holder
);
827 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
828 dwarf2_per_objfile
*per_objfile
,
829 dwarf2_cu
*existing_cu
);
831 struct dwarf2_per_cu_data
*m_this_cu
;
832 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
834 /* The ordinary abbreviation table. */
835 abbrev_table_up m_abbrev_table_holder
;
837 /* The DWO abbreviation table. */
838 abbrev_table_up m_dwo_abbrev_table
;
841 /* When we construct a partial symbol table entry we only
842 need this much information. */
843 struct partial_die_info
: public allocate_on_obstack
845 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
847 /* Disable assign but still keep copy ctor, which is needed
848 load_partial_dies. */
849 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
850 partial_die_info (const partial_die_info
&) = default;
852 /* Adjust the partial die before generating a symbol for it. This
853 function may set the is_external flag or change the DIE's
855 void fixup (struct dwarf2_cu
*cu
);
857 /* Read a minimal amount of information into the minimal die
859 const gdb_byte
*read (const struct die_reader_specs
*reader
,
860 const struct abbrev_info
&abbrev
,
861 const gdb_byte
*info_ptr
);
863 /* Compute the name of this partial DIE. This memoizes the
864 result, so it is safe to call multiple times. */
865 const char *name (dwarf2_cu
*cu
);
867 /* Offset of this DIE. */
868 const sect_offset sect_off
;
870 /* DWARF-2 tag for this DIE. */
871 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
873 /* Assorted flags describing the data found in this DIE. */
874 const unsigned int has_children
: 1;
876 unsigned int is_external
: 1;
877 unsigned int is_declaration
: 1;
878 unsigned int has_type
: 1;
879 unsigned int has_specification
: 1;
880 unsigned int has_pc_info
: 1;
881 unsigned int has_range_info
: 1;
882 unsigned int may_be_inlined
: 1;
884 /* This DIE has been marked DW_AT_main_subprogram. */
885 unsigned int main_subprogram
: 1;
887 /* Flag set if the SCOPE field of this structure has been
889 unsigned int scope_set
: 1;
891 /* Flag set if the DIE has a byte_size attribute. */
892 unsigned int has_byte_size
: 1;
894 /* Flag set if the DIE has a DW_AT_const_value attribute. */
895 unsigned int has_const_value
: 1;
897 /* Flag set if any of the DIE's children are template arguments. */
898 unsigned int has_template_arguments
: 1;
900 /* Flag set if fixup has been called on this die. */
901 unsigned int fixup_called
: 1;
903 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
904 unsigned int is_dwz
: 1;
906 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
907 unsigned int spec_is_dwz
: 1;
909 unsigned int canonical_name
: 1;
911 /* The name of this DIE. Normally the value of DW_AT_name, but
912 sometimes a default name for unnamed DIEs. */
913 const char *raw_name
= nullptr;
915 /* The linkage name, if present. */
916 const char *linkage_name
= nullptr;
918 /* The scope to prepend to our children. This is generally
919 allocated on the comp_unit_obstack, so will disappear
920 when this compilation unit leaves the cache. */
921 const char *scope
= nullptr;
923 /* Some data associated with the partial DIE. The tag determines
924 which field is live. */
927 /* The location description associated with this DIE, if any. */
928 struct dwarf_block
*locdesc
;
929 /* The offset of an import, for DW_TAG_imported_unit. */
930 sect_offset sect_off
;
935 /* If HAS_PC_INFO, the PC range associated with this DIE. */
941 /* If HAS_RANGE_INFO, the ranges offset associated with this DIE. */
942 ULONGEST ranges_offset
;
945 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
946 DW_AT_sibling, if any. */
947 /* NOTE: This member isn't strictly necessary, partial_die_info::read
948 could return DW_AT_sibling values to its caller load_partial_dies. */
949 const gdb_byte
*sibling
= nullptr;
951 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
952 DW_AT_specification (or DW_AT_abstract_origin or
954 sect_offset spec_offset
{};
956 /* Pointers to this DIE's parent, first child, and next sibling,
958 struct partial_die_info
*die_parent
= nullptr;
959 struct partial_die_info
*die_child
= nullptr;
960 struct partial_die_info
*die_sibling
= nullptr;
962 friend struct partial_die_info
*
963 dwarf2_cu::find_partial_die (sect_offset sect_off
);
966 /* Only need to do look up in dwarf2_cu::find_partial_die. */
967 partial_die_info (sect_offset sect_off
)
968 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
972 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
974 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
979 has_specification
= 0;
987 has_template_arguments
= 0;
992 /* Don't set these using NSDMI (Non-static data member initialisation),
993 because g++-4.8 will error out. */
999 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1000 but this would require a corresponding change in unpack_field_as_long
1002 static int bits_per_byte
= 8;
1004 struct variant_part_builder
;
1006 /* When reading a variant, we track a bit more information about the
1007 field, and store it in an object of this type. */
1009 struct variant_field
1011 int first_field
= -1;
1012 int last_field
= -1;
1014 /* A variant can contain other variant parts. */
1015 std::vector
<variant_part_builder
> variant_parts
;
1017 /* If we see a DW_TAG_variant, then this will be set if this is the
1019 bool default_branch
= false;
1020 /* If we see a DW_AT_discr_value, then this will be the discriminant
1022 ULONGEST discriminant_value
= 0;
1023 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1025 struct dwarf_block
*discr_list_data
= nullptr;
1028 /* This represents a DW_TAG_variant_part. */
1030 struct variant_part_builder
1032 /* The offset of the discriminant field. */
1033 sect_offset discriminant_offset
{};
1035 /* Variants that are direct children of this variant part. */
1036 std::vector
<variant_field
> variants
;
1038 /* True if we're currently reading a variant. */
1039 bool processing_variant
= false;
1044 int accessibility
= 0;
1046 /* Variant parts need to find the discriminant, which is a DIE
1047 reference. We track the section offset of each field to make
1050 struct field field
{};
1055 const char *name
= nullptr;
1056 std::vector
<struct fn_field
> fnfields
;
1059 /* The routines that read and process dies for a C struct or C++ class
1060 pass lists of data member fields and lists of member function fields
1061 in an instance of a field_info structure, as defined below. */
1064 /* List of data member and baseclasses fields. */
1065 std::vector
<struct nextfield
> fields
;
1066 std::vector
<struct nextfield
> baseclasses
;
1068 /* Set if the accessibility of one of the fields is not public. */
1069 bool non_public_fields
= false;
1071 /* Member function fieldlist array, contains name of possibly overloaded
1072 member function, number of overloaded member functions and a pointer
1073 to the head of the member function field chain. */
1074 std::vector
<struct fnfieldlist
> fnfieldlists
;
1076 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1077 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1078 std::vector
<struct decl_field
> typedef_field_list
;
1080 /* Nested types defined by this class and the number of elements in this
1082 std::vector
<struct decl_field
> nested_types_list
;
1084 /* If non-null, this is the variant part we are currently
1086 variant_part_builder
*current_variant_part
= nullptr;
1087 /* This holds all the top-level variant parts attached to the type
1089 std::vector
<variant_part_builder
> variant_parts
;
1091 /* Return the total number of fields (including baseclasses). */
1092 int nfields () const
1094 return fields
.size () + baseclasses
.size ();
1098 /* Loaded secondary compilation units are kept in memory until they
1099 have not been referenced for the processing of this many
1100 compilation units. Set this to zero to disable caching. Cache
1101 sizes of up to at least twenty will improve startup time for
1102 typical inter-CU-reference binaries, at an obvious memory cost. */
1103 static int dwarf_max_cache_age
= 5;
1105 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1106 struct cmd_list_element
*c
, const char *value
)
1108 gdb_printf (file
, _("The upper bound on the age of cached "
1109 "DWARF compilation units is %s.\n"),
1113 /* local function prototypes */
1115 static void dwarf2_find_base_address (struct die_info
*die
,
1116 struct dwarf2_cu
*cu
);
1118 static dwarf2_psymtab
*create_partial_symtab
1119 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1122 class cooked_index_storage
;
1123 static void build_type_psymtabs_reader (cutu_reader
*reader
,
1124 cooked_index_storage
*storage
);
1126 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1128 static void scan_partial_symbols (struct partial_die_info
*,
1129 CORE_ADDR
*, CORE_ADDR
*,
1130 int, struct dwarf2_cu
*);
1132 static void add_partial_symbol (struct partial_die_info
*,
1133 struct dwarf2_cu
*);
1135 static void add_partial_namespace (struct partial_die_info
*pdi
,
1136 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1137 int set_addrmap
, struct dwarf2_cu
*cu
);
1139 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1140 CORE_ADDR
*highpc
, int set_addrmap
,
1141 struct dwarf2_cu
*cu
);
1143 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1144 struct dwarf2_cu
*cu
);
1146 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1147 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1148 int need_pc
, struct dwarf2_cu
*cu
);
1150 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1152 static struct partial_die_info
*load_partial_dies
1153 (const struct die_reader_specs
*, const gdb_byte
*, int);
1155 /* A pair of partial_die_info and compilation unit. */
1156 struct cu_partial_die_info
1158 /* The compilation unit of the partial_die_info. */
1159 struct dwarf2_cu
*cu
;
1160 /* A partial_die_info. */
1161 struct partial_die_info
*pdi
;
1163 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1169 cu_partial_die_info () = delete;
1172 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1173 struct dwarf2_cu
*);
1175 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1177 const struct attr_abbrev
*,
1180 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1181 struct attribute
*attr
, dwarf_tag tag
);
1183 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1185 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1186 dwarf2_section_info
*, sect_offset
);
1188 static const char *read_indirect_string
1189 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1190 const struct comp_unit_head
*, unsigned int *);
1192 static const char *read_indirect_string_at_offset
1193 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1195 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1199 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1200 ULONGEST str_index
);
1202 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1203 ULONGEST str_index
);
1205 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1206 struct dwarf2_cu
*);
1208 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1209 struct dwarf2_cu
*cu
);
1211 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1213 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1214 struct dwarf2_cu
*cu
);
1216 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1218 static struct die_info
*die_specification (struct die_info
*die
,
1219 struct dwarf2_cu
**);
1221 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1222 struct dwarf2_cu
*cu
);
1224 static void dwarf_decode_lines (struct line_header
*,
1225 const file_and_directory
&,
1226 struct dwarf2_cu
*, dwarf2_psymtab
*,
1227 CORE_ADDR
, int decode_mapping
);
1229 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1232 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1233 struct dwarf2_cu
*, struct symbol
* = NULL
);
1235 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1236 struct dwarf2_cu
*);
1238 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1241 struct obstack
*obstack
,
1242 struct dwarf2_cu
*cu
, LONGEST
*value
,
1243 const gdb_byte
**bytes
,
1244 struct dwarf2_locexpr_baton
**baton
);
1246 static struct type
*read_subrange_index_type (struct die_info
*die
,
1247 struct dwarf2_cu
*cu
);
1249 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1251 static int need_gnat_info (struct dwarf2_cu
*);
1253 static struct type
*die_descriptive_type (struct die_info
*,
1254 struct dwarf2_cu
*);
1256 static void set_descriptive_type (struct type
*, struct die_info
*,
1257 struct dwarf2_cu
*);
1259 static struct type
*die_containing_type (struct die_info
*,
1260 struct dwarf2_cu
*);
1262 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1263 struct dwarf2_cu
*);
1265 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1267 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1269 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1271 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1272 const char *suffix
, int physname
,
1273 struct dwarf2_cu
*cu
);
1275 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1277 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1279 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1281 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1283 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1285 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1287 /* Return the .debug_loclists section to use for cu. */
1288 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1290 /* Return the .debug_rnglists section to use for cu. */
1291 static struct dwarf2_section_info
*cu_debug_rnglists_section
1292 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1294 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1295 values. Keep the items ordered with increasing constraints compliance. */
1298 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1299 PC_BOUNDS_NOT_PRESENT
,
1301 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1302 were present but they do not form a valid range of PC addresses. */
1305 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1308 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1312 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1313 CORE_ADDR
*, CORE_ADDR
*,
1318 static void get_scope_pc_bounds (struct die_info
*,
1319 CORE_ADDR
*, CORE_ADDR
*,
1320 struct dwarf2_cu
*);
1322 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1323 CORE_ADDR
, struct dwarf2_cu
*);
1325 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1326 struct dwarf2_cu
*);
1328 static void dwarf2_attach_fields_to_type (struct field_info
*,
1329 struct type
*, struct dwarf2_cu
*);
1331 static void dwarf2_add_member_fn (struct field_info
*,
1332 struct die_info
*, struct type
*,
1333 struct dwarf2_cu
*);
1335 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1337 struct dwarf2_cu
*);
1339 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1341 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1343 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1345 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1347 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1349 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1351 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1353 static struct type
*read_module_type (struct die_info
*die
,
1354 struct dwarf2_cu
*cu
);
1356 static const char *namespace_name (struct die_info
*die
,
1357 int *is_anonymous
, struct dwarf2_cu
*);
1359 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1361 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1364 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1365 struct dwarf2_cu
*);
1367 static struct die_info
*read_die_and_siblings_1
1368 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1371 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1372 const gdb_byte
*info_ptr
,
1373 const gdb_byte
**new_info_ptr
,
1374 struct die_info
*parent
);
1376 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1377 struct die_info
**, const gdb_byte
*,
1380 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1381 struct die_info
**, const gdb_byte
*);
1383 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1385 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1388 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1390 static const char *dwarf2_full_name (const char *name
,
1391 struct die_info
*die
,
1392 struct dwarf2_cu
*cu
);
1394 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1395 struct dwarf2_cu
*cu
);
1397 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1398 struct dwarf2_cu
**);
1400 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1402 static void dump_die_for_error (struct die_info
*);
1404 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1407 /*static*/ void dump_die (struct die_info
*, int max_level
);
1409 static void store_in_ref_table (struct die_info
*,
1410 struct dwarf2_cu
*);
1412 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1413 const struct attribute
*,
1414 struct dwarf2_cu
**);
1416 static struct die_info
*follow_die_ref (struct die_info
*,
1417 const struct attribute
*,
1418 struct dwarf2_cu
**);
1420 static struct die_info
*follow_die_sig (struct die_info
*,
1421 const struct attribute
*,
1422 struct dwarf2_cu
**);
1424 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1425 struct dwarf2_cu
*);
1427 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1428 const struct attribute
*,
1429 struct dwarf2_cu
*);
1431 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1432 dwarf2_per_objfile
*per_objfile
);
1434 static void read_signatured_type (signatured_type
*sig_type
,
1435 dwarf2_per_objfile
*per_objfile
);
1437 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1438 struct die_info
*die
, struct dwarf2_cu
*cu
,
1439 struct dynamic_prop
*prop
, struct type
*type
);
1441 /* memory allocation interface */
1443 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1445 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1447 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1449 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1450 struct dwarf2_loclist_baton
*baton
,
1451 const struct attribute
*attr
);
1453 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1455 struct dwarf2_cu
*cu
,
1458 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1459 const gdb_byte
*info_ptr
,
1460 const struct abbrev_info
*abbrev
,
1461 bool do_skip_children
= true);
1463 static hashval_t
partial_die_hash (const void *item
);
1465 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1467 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1468 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1469 dwarf2_per_bfd
*per_bfd
);
1471 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1472 struct die_info
*comp_unit_die
,
1473 enum language pretend_language
);
1475 static struct type
*set_die_type (struct die_info
*, struct type
*,
1476 struct dwarf2_cu
*, bool = false);
1478 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1480 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1481 dwarf2_per_objfile
*per_objfile
,
1482 dwarf2_cu
*existing_cu
,
1484 enum language pretend_language
);
1486 static void process_full_comp_unit (dwarf2_cu
*cu
,
1487 enum language pretend_language
);
1489 static void process_full_type_unit (dwarf2_cu
*cu
,
1490 enum language pretend_language
);
1492 static struct type
*get_die_type_at_offset (sect_offset
,
1493 dwarf2_per_cu_data
*per_cu
,
1494 dwarf2_per_objfile
*per_objfile
);
1496 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1498 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1499 dwarf2_per_objfile
*per_objfile
,
1500 enum language pretend_language
);
1502 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1504 /* Class, the destructor of which frees all allocated queue entries. This
1505 will only have work to do if an error was thrown while processing the
1506 dwarf. If no error was thrown then the queue entries should have all
1507 been processed, and freed, as we went along. */
1509 class dwarf2_queue_guard
1512 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1513 : m_per_objfile (per_objfile
)
1515 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1517 m_per_objfile
->per_bfd
->queue
.emplace ();
1520 /* Free any entries remaining on the queue. There should only be
1521 entries left if we hit an error while processing the dwarf. */
1522 ~dwarf2_queue_guard ()
1524 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1526 m_per_objfile
->per_bfd
->queue
.reset ();
1529 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1532 dwarf2_per_objfile
*m_per_objfile
;
1535 dwarf2_queue_item::~dwarf2_queue_item ()
1537 /* Anything still marked queued is likely to be in an
1538 inconsistent state, so discard it. */
1541 per_objfile
->remove_cu (per_cu
);
1546 /* See dwarf2/read.h. */
1549 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1551 if (data
->is_debug_types
)
1552 delete static_cast<signatured_type
*> (data
);
1557 static file_and_directory
&find_file_and_directory
1558 (struct die_info
*die
, struct dwarf2_cu
*cu
);
1560 static const char *compute_include_file_name
1561 (const struct line_header
*lh
,
1562 const file_entry
&fe
,
1563 const file_and_directory
&cu_info
,
1564 gdb::unique_xmalloc_ptr
<char> *name_holder
);
1566 static htab_up
allocate_signatured_type_table ();
1568 static htab_up
allocate_dwo_unit_table ();
1570 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1571 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1572 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1574 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1576 static struct dwo_unit
*lookup_dwo_comp_unit
1577 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1578 ULONGEST signature
);
1580 static struct dwo_unit
*lookup_dwo_type_unit
1581 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1583 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1585 /* A unique pointer to a dwo_file. */
1587 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1589 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1591 static void check_producer (struct dwarf2_cu
*cu
);
1593 /* Various complaints about symbol reading that don't abort the process. */
1596 dwarf2_debug_line_missing_file_complaint (void)
1598 complaint (_(".debug_line section has line data without a file"));
1602 dwarf2_debug_line_missing_end_sequence_complaint (void)
1604 complaint (_(".debug_line section has line "
1605 "program sequence without an end"));
1609 dwarf2_complex_location_expr_complaint (void)
1611 complaint (_("location expression too complex"));
1615 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1618 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1623 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1625 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1629 /* Hash function for line_header_hash. */
1632 line_header_hash (const struct line_header
*ofs
)
1634 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1637 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1640 line_header_hash_voidp (const void *item
)
1642 const struct line_header
*ofs
= (const struct line_header
*) item
;
1644 return line_header_hash (ofs
);
1647 /* Equality function for line_header_hash. */
1650 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1652 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1653 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1655 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1656 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1661 /* An iterator for all_comp_units that is based on index. This
1662 approach makes it possible to iterate over all_comp_units safely,
1663 when some caller in the loop may add new units. */
1665 class all_comp_units_iterator
1669 all_comp_units_iterator (dwarf2_per_bfd
*per_bfd
, bool start
)
1670 : m_per_bfd (per_bfd
),
1671 m_index (start
? 0 : per_bfd
->all_comp_units
.size ())
1675 all_comp_units_iterator
&operator++ ()
1681 dwarf2_per_cu_data
*operator* () const
1683 return m_per_bfd
->get_cu (m_index
);
1686 bool operator== (const all_comp_units_iterator
&other
) const
1688 return m_index
== other
.m_index
;
1692 bool operator!= (const all_comp_units_iterator
&other
) const
1694 return m_index
!= other
.m_index
;
1699 dwarf2_per_bfd
*m_per_bfd
;
1703 /* A range adapter for the all_comp_units_iterator. */
1704 class all_comp_units_range
1708 all_comp_units_range (dwarf2_per_bfd
*per_bfd
)
1709 : m_per_bfd (per_bfd
)
1713 all_comp_units_iterator
begin ()
1715 return all_comp_units_iterator (m_per_bfd
, true);
1718 all_comp_units_iterator
end ()
1720 return all_comp_units_iterator (m_per_bfd
, false);
1725 dwarf2_per_bfd
*m_per_bfd
;
1728 /* See declaration. */
1730 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1733 can_copy (can_copy_
)
1736 names
= &dwarf2_elf_names
;
1738 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1739 locate_sections (obfd
, sec
, *names
);
1742 dwarf2_per_bfd::~dwarf2_per_bfd ()
1744 for (auto &per_cu
: all_comp_units
)
1746 per_cu
->imported_symtabs_free ();
1747 per_cu
->free_cached_file_names ();
1750 /* Everything else should be on this->obstack. */
1756 dwarf2_per_objfile::remove_all_cus ()
1758 gdb_assert (!this->per_bfd
->queue
.has_value ());
1760 for (auto pair
: m_dwarf2_cus
)
1763 m_dwarf2_cus
.clear ();
1766 /* A helper class that calls free_cached_comp_units on
1769 class free_cached_comp_units
1773 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1774 : m_per_objfile (per_objfile
)
1778 ~free_cached_comp_units ()
1780 m_per_objfile
->remove_all_cus ();
1783 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1787 dwarf2_per_objfile
*m_per_objfile
;
1793 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1795 if (per_cu
->index
< this->m_symtabs
.size ())
1796 return this->m_symtabs
[per_cu
->index
] != nullptr;
1803 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1805 if (per_cu
->index
< this->m_symtabs
.size ())
1806 return this->m_symtabs
[per_cu
->index
];
1813 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1814 compunit_symtab
*symtab
)
1816 if (per_cu
->index
>= this->m_symtabs
.size ())
1817 this->m_symtabs
.resize (per_cu
->index
+ 1);
1818 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1819 this->m_symtabs
[per_cu
->index
] = symtab
;
1822 /* Try to locate the sections we need for DWARF 2 debugging
1823 information and return true if we have enough to do something.
1824 NAMES points to the dwarf2 section names, or is NULL if the standard
1825 ELF names are used. CAN_COPY is true for formats where symbol
1826 interposition is possible and so symbol values must follow copy
1827 relocation rules. */
1830 dwarf2_has_info (struct objfile
*objfile
,
1831 const struct dwarf2_debug_sections
*names
,
1834 if (objfile
->flags
& OBJF_READNEVER
)
1837 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1839 if (per_objfile
== NULL
)
1841 dwarf2_per_bfd
*per_bfd
;
1843 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1844 BFD doesn't require relocations.
1846 We don't share with objfiles for which -readnow was requested,
1847 because it would complicate things when loading the same BFD with
1848 -readnow and then without -readnow. */
1849 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1850 && (objfile
->flags
& OBJF_READNOW
) == 0)
1852 /* See if one has been created for this BFD yet. */
1853 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1855 if (per_bfd
== nullptr)
1857 /* No, create it now. */
1858 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1859 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1864 /* No sharing possible, create one specifically for this objfile. */
1865 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1866 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1869 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1872 return (!per_objfile
->per_bfd
->info
.is_virtual
1873 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1874 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1875 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1878 /* See declaration. */
1881 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1882 const dwarf2_debug_sections
&names
)
1884 flagword aflag
= bfd_section_flags (sectp
);
1886 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1889 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1890 > bfd_get_file_size (abfd
))
1892 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1893 warning (_("Discarding section %s which has a section size (%s"
1894 ") larger than the file size [in module %s]"),
1895 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1896 bfd_get_filename (abfd
));
1898 else if (names
.info
.matches (sectp
->name
))
1900 this->info
.s
.section
= sectp
;
1901 this->info
.size
= bfd_section_size (sectp
);
1903 else if (names
.abbrev
.matches (sectp
->name
))
1905 this->abbrev
.s
.section
= sectp
;
1906 this->abbrev
.size
= bfd_section_size (sectp
);
1908 else if (names
.line
.matches (sectp
->name
))
1910 this->line
.s
.section
= sectp
;
1911 this->line
.size
= bfd_section_size (sectp
);
1913 else if (names
.loc
.matches (sectp
->name
))
1915 this->loc
.s
.section
= sectp
;
1916 this->loc
.size
= bfd_section_size (sectp
);
1918 else if (names
.loclists
.matches (sectp
->name
))
1920 this->loclists
.s
.section
= sectp
;
1921 this->loclists
.size
= bfd_section_size (sectp
);
1923 else if (names
.macinfo
.matches (sectp
->name
))
1925 this->macinfo
.s
.section
= sectp
;
1926 this->macinfo
.size
= bfd_section_size (sectp
);
1928 else if (names
.macro
.matches (sectp
->name
))
1930 this->macro
.s
.section
= sectp
;
1931 this->macro
.size
= bfd_section_size (sectp
);
1933 else if (names
.str
.matches (sectp
->name
))
1935 this->str
.s
.section
= sectp
;
1936 this->str
.size
= bfd_section_size (sectp
);
1938 else if (names
.str_offsets
.matches (sectp
->name
))
1940 this->str_offsets
.s
.section
= sectp
;
1941 this->str_offsets
.size
= bfd_section_size (sectp
);
1943 else if (names
.line_str
.matches (sectp
->name
))
1945 this->line_str
.s
.section
= sectp
;
1946 this->line_str
.size
= bfd_section_size (sectp
);
1948 else if (names
.addr
.matches (sectp
->name
))
1950 this->addr
.s
.section
= sectp
;
1951 this->addr
.size
= bfd_section_size (sectp
);
1953 else if (names
.frame
.matches (sectp
->name
))
1955 this->frame
.s
.section
= sectp
;
1956 this->frame
.size
= bfd_section_size (sectp
);
1958 else if (names
.eh_frame
.matches (sectp
->name
))
1960 this->eh_frame
.s
.section
= sectp
;
1961 this->eh_frame
.size
= bfd_section_size (sectp
);
1963 else if (names
.ranges
.matches (sectp
->name
))
1965 this->ranges
.s
.section
= sectp
;
1966 this->ranges
.size
= bfd_section_size (sectp
);
1968 else if (names
.rnglists
.matches (sectp
->name
))
1970 this->rnglists
.s
.section
= sectp
;
1971 this->rnglists
.size
= bfd_section_size (sectp
);
1973 else if (names
.types
.matches (sectp
->name
))
1975 struct dwarf2_section_info type_section
;
1977 memset (&type_section
, 0, sizeof (type_section
));
1978 type_section
.s
.section
= sectp
;
1979 type_section
.size
= bfd_section_size (sectp
);
1981 this->types
.push_back (type_section
);
1983 else if (names
.gdb_index
.matches (sectp
->name
))
1985 this->gdb_index
.s
.section
= sectp
;
1986 this->gdb_index
.size
= bfd_section_size (sectp
);
1988 else if (names
.debug_names
.matches (sectp
->name
))
1990 this->debug_names
.s
.section
= sectp
;
1991 this->debug_names
.size
= bfd_section_size (sectp
);
1993 else if (names
.debug_aranges
.matches (sectp
->name
))
1995 this->debug_aranges
.s
.section
= sectp
;
1996 this->debug_aranges
.size
= bfd_section_size (sectp
);
1999 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2000 && bfd_section_vma (sectp
) == 0)
2001 this->has_section_at_zero
= true;
2004 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2008 dwarf2_get_section_info (struct objfile
*objfile
,
2009 enum dwarf2_section_enum sect
,
2010 asection
**sectp
, const gdb_byte
**bufp
,
2011 bfd_size_type
*sizep
)
2013 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2014 struct dwarf2_section_info
*info
;
2016 /* We may see an objfile without any DWARF, in which case we just
2018 if (per_objfile
== NULL
)
2027 case DWARF2_DEBUG_FRAME
:
2028 info
= &per_objfile
->per_bfd
->frame
;
2030 case DWARF2_EH_FRAME
:
2031 info
= &per_objfile
->per_bfd
->eh_frame
;
2034 gdb_assert_not_reached ("unexpected section");
2037 info
->read (objfile
);
2039 *sectp
= info
->get_bfd_section ();
2040 *bufp
= info
->buffer
;
2041 *sizep
= info
->size
;
2044 /* See dwarf2/read.h. */
2047 dwarf2_per_bfd::map_info_sections (struct objfile
*objfile
)
2049 info
.read (objfile
);
2050 abbrev
.read (objfile
);
2051 line
.read (objfile
);
2053 str_offsets
.read (objfile
);
2054 line_str
.read (objfile
);
2055 ranges
.read (objfile
);
2056 rnglists
.read (objfile
);
2057 addr
.read (objfile
);
2059 for (auto §ion
: types
)
2060 section
.read (objfile
);
2064 /* DWARF quick_symbol_functions support. */
2066 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2067 unique line tables, so we maintain a separate table of all .debug_line
2068 derived entries to support the sharing.
2069 All the quick functions need is the list of file names. We discard the
2070 line_header when we're done and don't need to record it here. */
2071 struct quick_file_names
2073 /* The data used to construct the hash key. */
2074 struct stmt_list_hash hash
;
2076 /* The number of entries in file_names, real_names. */
2077 unsigned int num_file_names
;
2079 /* The CU directory, as given by DW_AT_comp_dir. May be
2081 const char *comp_dir
;
2083 /* The file names from the line table, after being run through
2085 const char **file_names
;
2087 /* The file names from the line table after being run through
2088 gdb_realpath. These are computed lazily. */
2089 const char **real_names
;
2092 /* When using the index (and thus not using psymtabs), each CU has an
2093 object of this type. This is used to hold information needed by
2094 the various "quick" methods. */
2095 struct dwarf2_per_cu_quick_data
2097 /* The file table. This can be NULL if there was no file table
2098 or it's currently not read in.
2099 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2100 struct quick_file_names
*file_names
;
2102 /* A temporary mark bit used when iterating over all CUs in
2103 expand_symtabs_matching. */
2104 unsigned int mark
: 1;
2106 /* True if we've tried to read the file table. There will be no
2107 point in trying to read it again next time. */
2108 bool files_read
: 1;
2111 /* A subclass of psymbol_functions that arranges to read the DWARF
2112 partial symbols when needed. */
2113 struct lazy_dwarf_reader
: public psymbol_functions
2115 using psymbol_functions::psymbol_functions
;
2117 bool can_lazily_read_symbols () override
2122 void read_partial_symbols (struct objfile
*objfile
) override
2124 if (dwarf2_has_info (objfile
, nullptr))
2125 dwarf2_build_psymtabs (objfile
, this);
2129 static quick_symbol_functions_up
2130 make_lazy_dwarf_reader ()
2132 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2135 struct dwarf2_base_index_functions
: public quick_symbol_functions
2137 bool has_symbols (struct objfile
*objfile
) override
;
2139 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
2141 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2143 void forget_cached_source_info (struct objfile
*objfile
) override
;
2145 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2148 bool *symbol_found_p
) override
2150 *symbol_found_p
= false;
2151 return language_unknown
;
2154 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2156 void expand_all_symtabs (struct objfile
*objfile
) override
;
2158 struct compunit_symtab
*find_pc_sect_compunit_symtab
2159 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2160 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2162 struct compunit_symtab
*find_compunit_symtab_by_address
2163 (struct objfile
*objfile
, CORE_ADDR address
) override
2168 void map_symbol_filenames (struct objfile
*objfile
,
2169 gdb::function_view
<symbol_filename_ftype
> fun
,
2170 bool need_fullname
) override
;
2173 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2175 void dump (struct objfile
*objfile
) override
;
2177 void expand_matching_symbols
2179 const lookup_name_info
&lookup_name
,
2182 symbol_compare_ftype
*ordered_compare
) override
;
2184 bool expand_symtabs_matching
2185 (struct objfile
*objfile
,
2186 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2187 const lookup_name_info
*lookup_name
,
2188 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2189 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2190 block_search_flags search_flags
,
2192 enum search_domain kind
) override
;
2195 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2197 void dump (struct objfile
*objfile
) override
;
2199 void expand_matching_symbols
2201 const lookup_name_info
&lookup_name
,
2204 symbol_compare_ftype
*ordered_compare
) override
;
2206 bool expand_symtabs_matching
2207 (struct objfile
*objfile
,
2208 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2209 const lookup_name_info
*lookup_name
,
2210 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2211 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2212 block_search_flags search_flags
,
2214 enum search_domain kind
) override
;
2217 static quick_symbol_functions_up
2218 make_dwarf_gdb_index ()
2220 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2223 static quick_symbol_functions_up
2224 make_dwarf_debug_names ()
2226 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2229 /* Utility hash function for a stmt_list_hash. */
2232 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2236 if (stmt_list_hash
->dwo_unit
!= NULL
)
2237 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2238 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2242 /* Utility equality function for a stmt_list_hash. */
2245 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2246 const struct stmt_list_hash
*rhs
)
2248 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2250 if (lhs
->dwo_unit
!= NULL
2251 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2254 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2257 /* Hash function for a quick_file_names. */
2260 hash_file_name_entry (const void *e
)
2262 const struct quick_file_names
*file_data
2263 = (const struct quick_file_names
*) e
;
2265 return hash_stmt_list_entry (&file_data
->hash
);
2268 /* Equality function for a quick_file_names. */
2271 eq_file_name_entry (const void *a
, const void *b
)
2273 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2274 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2276 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2279 /* Create a quick_file_names hash table. */
2282 create_quick_file_names_table (unsigned int nr_initial_entries
)
2284 return htab_up (htab_create_alloc (nr_initial_entries
,
2285 hash_file_name_entry
, eq_file_name_entry
,
2286 nullptr, xcalloc
, xfree
));
2289 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2290 function is unrelated to symtabs, symtab would have to be created afterwards.
2291 You should call age_cached_comp_units after processing the CU. */
2294 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2297 if (per_cu
->is_debug_types
)
2298 load_full_type_unit (per_cu
, per_objfile
);
2300 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2301 skip_partial
, language_minimal
);
2303 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2305 return nullptr; /* Dummy CU. */
2307 dwarf2_find_base_address (cu
->dies
, cu
);
2312 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2315 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2316 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2318 /* Skip type_unit_groups, reading the type units they contain
2319 is handled elsewhere. */
2320 if (per_cu
->type_unit_group_p ())
2324 /* The destructor of dwarf2_queue_guard frees any entries left on
2325 the queue. After this point we're guaranteed to leave this function
2326 with the dwarf queue empty. */
2327 dwarf2_queue_guard
q_guard (per_objfile
);
2329 if (!per_objfile
->symtab_set_p (per_cu
))
2331 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2332 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2334 /* If we just loaded a CU from a DWO, and we're working with an index
2335 that may badly handle TUs, load all the TUs in that DWO as well.
2336 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2337 if (!per_cu
->is_debug_types
2339 && cu
->dwo_unit
!= NULL
2340 && per_objfile
->per_bfd
->index_table
!= NULL
2341 && per_objfile
->per_bfd
->index_table
->version
<= 7
2342 /* DWP files aren't supported yet. */
2343 && get_dwp_file (per_objfile
) == NULL
)
2344 queue_and_load_all_dwo_tus (cu
);
2347 process_queue (per_objfile
);
2350 /* Age the cache, releasing compilation units that have not
2351 been used recently. */
2352 per_objfile
->age_comp_units ();
2355 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2356 the per-objfile for which this symtab is instantiated.
2358 Returns the resulting symbol table. */
2360 static struct compunit_symtab
*
2361 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2362 dwarf2_per_objfile
*per_objfile
,
2365 gdb_assert (per_objfile
->per_bfd
->using_index
);
2367 if (!per_objfile
->symtab_set_p (per_cu
))
2369 free_cached_comp_units
freer (per_objfile
);
2370 scoped_restore decrementer
= increment_reading_symtab ();
2371 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2372 process_cu_includes (per_objfile
);
2375 return per_objfile
->get_symtab (per_cu
);
2380 dwarf2_per_cu_data_up
2381 dwarf2_per_bfd::allocate_per_cu ()
2383 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2384 result
->per_bfd
= this;
2385 result
->index
= all_comp_units
.size ();
2392 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2394 signatured_type_up
result (new signatured_type (signature
));
2395 result
->per_bfd
= this;
2396 result
->index
= all_comp_units
.size ();
2397 result
->is_debug_types
= true;
2402 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2403 obstack, and constructed with the specified field values. */
2405 static dwarf2_per_cu_data_up
2406 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2407 struct dwarf2_section_info
*section
,
2409 sect_offset sect_off
, ULONGEST length
)
2411 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2412 the_cu
->sect_off
= sect_off
;
2413 the_cu
->length
= length
;
2414 the_cu
->section
= section
;
2415 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2416 struct dwarf2_per_cu_quick_data
);
2417 the_cu
->is_dwz
= is_dwz
;
2421 /* A helper for create_cus_from_index that handles a given list of
2425 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2426 const gdb_byte
*cu_list
, offset_type n_elements
,
2427 struct dwarf2_section_info
*section
,
2430 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2432 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2434 sect_offset sect_off
2435 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2436 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2439 dwarf2_per_cu_data_up per_cu
2440 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2442 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2446 /* Read the CU list from the mapped index, and use it to create all
2447 the CU objects for PER_BFD. */
2450 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2451 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2452 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2454 gdb_assert (per_bfd
->all_comp_units
.empty ());
2455 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2457 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2460 if (dwz_elements
== 0)
2463 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2464 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2468 /* Create the signatured type hash table from the index. */
2471 create_signatured_type_table_from_index
2472 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2473 const gdb_byte
*bytes
, offset_type elements
)
2475 htab_up sig_types_hash
= allocate_signatured_type_table ();
2477 for (offset_type i
= 0; i
< elements
; i
+= 3)
2479 signatured_type_up sig_type
;
2482 cu_offset type_offset_in_tu
;
2484 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2485 sect_offset sect_off
2486 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2488 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2490 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2493 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2494 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2495 sig_type
->section
= section
;
2496 sig_type
->sect_off
= sect_off
;
2498 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2499 struct dwarf2_per_cu_quick_data
);
2501 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2502 *slot
= sig_type
.get ();
2504 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2507 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2510 /* Create the signatured type hash table from .debug_names. */
2513 create_signatured_type_table_from_debug_names
2514 (dwarf2_per_objfile
*per_objfile
,
2515 const mapped_debug_names
&map
,
2516 struct dwarf2_section_info
*section
,
2517 struct dwarf2_section_info
*abbrev_section
)
2519 struct objfile
*objfile
= per_objfile
->objfile
;
2521 section
->read (objfile
);
2522 abbrev_section
->read (objfile
);
2524 htab_up sig_types_hash
= allocate_signatured_type_table ();
2526 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2528 signatured_type_up sig_type
;
2531 sect_offset sect_off
2532 = (sect_offset
) (extract_unsigned_integer
2533 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2535 map
.dwarf5_byte_order
));
2537 comp_unit_head cu_header
;
2538 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2540 section
->buffer
+ to_underlying (sect_off
),
2543 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2544 (cu_header
.signature
);
2545 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2546 sig_type
->section
= section
;
2547 sig_type
->sect_off
= sect_off
;
2549 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2550 struct dwarf2_per_cu_quick_data
);
2552 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2553 *slot
= sig_type
.get ();
2555 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2558 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2561 /* Read the address map data from the mapped index, and use it to
2562 populate the psymtabs_addrmap. */
2565 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2566 struct mapped_index
*index
)
2568 struct objfile
*objfile
= per_objfile
->objfile
;
2569 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2570 struct gdbarch
*gdbarch
= objfile
->arch ();
2571 const gdb_byte
*iter
, *end
;
2572 struct addrmap
*mutable_map
;
2575 auto_obstack temp_obstack
;
2577 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2579 iter
= index
->address_table
.data ();
2580 end
= iter
+ index
->address_table
.size ();
2582 baseaddr
= objfile
->text_section_offset ();
2586 ULONGEST hi
, lo
, cu_index
;
2587 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2589 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2591 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2596 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2597 hex_string (lo
), hex_string (hi
));
2601 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2603 complaint (_(".gdb_index address table has invalid CU number %u"),
2604 (unsigned) cu_index
);
2608 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2609 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2610 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2611 per_bfd
->get_cu (cu_index
));
2614 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2618 /* Read the address map data from DWARF-5 .debug_aranges, and use it
2619 to populate given addrmap. Returns true on success, false on
2623 read_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2624 struct dwarf2_section_info
*section
,
2625 addrmap
*mutable_map
)
2627 struct objfile
*objfile
= per_objfile
->objfile
;
2628 bfd
*abfd
= objfile
->obfd
;
2629 struct gdbarch
*gdbarch
= objfile
->arch ();
2630 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2631 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2633 std::unordered_map
<sect_offset
,
2634 dwarf2_per_cu_data
*,
2635 gdb::hash_enum
<sect_offset
>>
2636 debug_info_offset_to_per_cu
;
2637 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2639 /* A TU will not need aranges, and skipping them here is an easy
2640 way of ignoring .debug_types -- and possibly seeing a
2641 duplicate section offset -- entirely. The same applies to
2642 units coming from a dwz file. */
2643 if (per_cu
->is_debug_types
|| per_cu
->is_dwz
)
2646 const auto insertpair
2647 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2649 if (!insertpair
.second
)
2651 warning (_("Section .debug_aranges in %s has duplicate "
2652 "debug_info_offset %s, ignoring .debug_aranges."),
2653 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2658 section
->read (objfile
);
2660 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2662 const gdb_byte
*addr
= section
->buffer
;
2664 while (addr
< section
->buffer
+ section
->size
)
2666 const gdb_byte
*const entry_addr
= addr
;
2667 unsigned int bytes_read
;
2669 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2673 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2674 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2675 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2676 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2678 warning (_("Section .debug_aranges in %s entry at offset %s "
2679 "length %s exceeds section length %s, "
2680 "ignoring .debug_aranges."),
2681 objfile_name (objfile
),
2682 plongest (entry_addr
- section
->buffer
),
2683 plongest (bytes_read
+ entry_length
),
2684 pulongest (section
->size
));
2688 /* The version number. */
2689 const uint16_t version
= read_2_bytes (abfd
, addr
);
2693 warning (_("Section .debug_aranges in %s entry at offset %s "
2694 "has unsupported version %d, ignoring .debug_aranges."),
2695 objfile_name (objfile
),
2696 plongest (entry_addr
- section
->buffer
), version
);
2700 const uint64_t debug_info_offset
2701 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2702 addr
+= offset_size
;
2703 const auto per_cu_it
2704 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2705 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2707 warning (_("Section .debug_aranges in %s entry at offset %s "
2708 "debug_info_offset %s does not exists, "
2709 "ignoring .debug_aranges."),
2710 objfile_name (objfile
),
2711 plongest (entry_addr
- section
->buffer
),
2712 pulongest (debug_info_offset
));
2715 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2717 const uint8_t address_size
= *addr
++;
2718 if (address_size
< 1 || address_size
> 8)
2720 warning (_("Section .debug_aranges in %s entry at offset %s "
2721 "address_size %u is invalid, ignoring .debug_aranges."),
2722 objfile_name (objfile
),
2723 plongest (entry_addr
- section
->buffer
), address_size
);
2727 const uint8_t segment_selector_size
= *addr
++;
2728 if (segment_selector_size
!= 0)
2730 warning (_("Section .debug_aranges in %s entry at offset %s "
2731 "segment_selector_size %u is not supported, "
2732 "ignoring .debug_aranges."),
2733 objfile_name (objfile
),
2734 plongest (entry_addr
- section
->buffer
),
2735 segment_selector_size
);
2739 /* Must pad to an alignment boundary that is twice the address
2740 size. It is undocumented by the DWARF standard but GCC does
2741 use it. However, not every compiler does this. We can see
2742 whether it has happened by looking at the total length of the
2743 contents of the aranges for this CU -- it if isn't a multiple
2744 of twice the address size, then we skip any leftover
2746 addr
+= (entry_end
- addr
) % (2 * address_size
);
2750 if (addr
+ 2 * address_size
> entry_end
)
2752 warning (_("Section .debug_aranges in %s entry at offset %s "
2753 "address list is not properly terminated, "
2754 "ignoring .debug_aranges."),
2755 objfile_name (objfile
),
2756 plongest (entry_addr
- section
->buffer
));
2759 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2761 addr
+= address_size
;
2762 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2764 addr
+= address_size
;
2765 if (start
== 0 && length
== 0)
2767 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2769 /* Symbol was eliminated due to a COMDAT group. */
2772 ULONGEST end
= start
+ length
;
2773 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2775 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2777 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2780 per_cu
->addresses_seen
= true;
2786 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2787 populate the psymtabs_addrmap. */
2790 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2791 struct dwarf2_section_info
*section
)
2793 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2795 auto_obstack temp_obstack
;
2796 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2798 if (read_addrmap_from_aranges (per_objfile
, section
, mutable_map
))
2799 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2803 /* A helper function that reads the .gdb_index from BUFFER and fills
2804 in MAP. FILENAME is the name of the file containing the data;
2805 it is used for error reporting. DEPRECATED_OK is true if it is
2806 ok to use deprecated sections.
2808 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2809 out parameters that are filled in with information about the CU and
2810 TU lists in the section.
2812 Returns true if all went well, false otherwise. */
2815 read_gdb_index_from_buffer (const char *filename
,
2817 gdb::array_view
<const gdb_byte
> buffer
,
2818 struct mapped_index
*map
,
2819 const gdb_byte
**cu_list
,
2820 offset_type
*cu_list_elements
,
2821 const gdb_byte
**types_list
,
2822 offset_type
*types_list_elements
)
2824 const gdb_byte
*addr
= &buffer
[0];
2825 offset_view
metadata (buffer
);
2827 /* Version check. */
2828 offset_type version
= metadata
[0];
2829 /* Versions earlier than 3 emitted every copy of a psymbol. This
2830 causes the index to behave very poorly for certain requests. Version 3
2831 contained incomplete addrmap. So, it seems better to just ignore such
2835 static int warning_printed
= 0;
2836 if (!warning_printed
)
2838 warning (_("Skipping obsolete .gdb_index section in %s."),
2840 warning_printed
= 1;
2844 /* Index version 4 uses a different hash function than index version
2847 Versions earlier than 6 did not emit psymbols for inlined
2848 functions. Using these files will cause GDB not to be able to
2849 set breakpoints on inlined functions by name, so we ignore these
2850 indices unless the user has done
2851 "set use-deprecated-index-sections on". */
2852 if (version
< 6 && !deprecated_ok
)
2854 static int warning_printed
= 0;
2855 if (!warning_printed
)
2858 Skipping deprecated .gdb_index section in %s.\n\
2859 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2860 to use the section anyway."),
2862 warning_printed
= 1;
2866 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2867 of the TU (for symbols coming from TUs),
2868 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2869 Plus gold-generated indices can have duplicate entries for global symbols,
2870 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2871 These are just performance bugs, and we can't distinguish gdb-generated
2872 indices from gold-generated ones, so issue no warning here. */
2874 /* Indexes with higher version than the one supported by GDB may be no
2875 longer backward compatible. */
2879 map
->version
= version
;
2882 *cu_list
= addr
+ metadata
[i
];
2883 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2886 *types_list
= addr
+ metadata
[i
];
2887 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2890 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2891 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2893 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2896 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2897 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2899 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2903 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2905 if (map
->constant_pool
.empty () && !map
->symbol_table
.empty ())
2907 /* An empty constant pool implies that all symbol table entries are
2908 empty. Make map->symbol_table.empty () == true. */
2910 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2917 /* Callback types for dwarf2_read_gdb_index. */
2919 typedef gdb::function_view
2920 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2921 get_gdb_index_contents_ftype
;
2922 typedef gdb::function_view
2923 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2924 get_gdb_index_contents_dwz_ftype
;
2926 /* Read .gdb_index. If everything went ok, initialize the "quick"
2927 elements of all the CUs and return 1. Otherwise, return 0. */
2930 dwarf2_read_gdb_index
2931 (dwarf2_per_objfile
*per_objfile
,
2932 get_gdb_index_contents_ftype get_gdb_index_contents
,
2933 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2935 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2936 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2937 struct dwz_file
*dwz
;
2938 struct objfile
*objfile
= per_objfile
->objfile
;
2939 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2941 gdb::array_view
<const gdb_byte
> main_index_contents
2942 = get_gdb_index_contents (objfile
, per_bfd
);
2944 if (main_index_contents
.empty ())
2947 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2948 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2949 use_deprecated_index_sections
,
2950 main_index_contents
, map
.get (), &cu_list
,
2951 &cu_list_elements
, &types_list
,
2952 &types_list_elements
))
2955 /* Don't use the index if it's empty. */
2956 if (map
->symbol_table
.empty ())
2959 /* If there is a .dwz file, read it so we can get its CU list as
2961 dwz
= dwarf2_get_dwz_file (per_bfd
);
2964 struct mapped_index dwz_map
;
2965 const gdb_byte
*dwz_types_ignore
;
2966 offset_type dwz_types_elements_ignore
;
2968 gdb::array_view
<const gdb_byte
> dwz_index_content
2969 = get_gdb_index_contents_dwz (objfile
, dwz
);
2971 if (dwz_index_content
.empty ())
2974 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2975 1, dwz_index_content
, &dwz_map
,
2976 &dwz_list
, &dwz_list_elements
,
2978 &dwz_types_elements_ignore
))
2980 warning (_("could not read '.gdb_index' section from %s; skipping"),
2981 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2986 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2989 if (types_list_elements
)
2991 /* We can only handle a single .debug_types when we have an
2993 if (per_bfd
->types
.size () != 1)
2996 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2998 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2999 types_list_elements
);
3002 create_addrmap_from_index (per_objfile
, map
.get ());
3004 per_bfd
->index_table
= std::move (map
);
3005 per_bfd
->using_index
= 1;
3006 per_bfd
->quick_file_names_table
=
3007 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3012 /* die_reader_func for dw2_get_file_names. */
3015 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3016 struct die_info
*comp_unit_die
)
3018 struct dwarf2_cu
*cu
= reader
->cu
;
3019 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3020 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3021 struct dwarf2_per_cu_data
*lh_cu
;
3022 struct attribute
*attr
;
3024 struct quick_file_names
*qfn
;
3026 gdb_assert (! this_cu
->is_debug_types
);
3028 this_cu
->v
.quick
->files_read
= true;
3029 /* Our callers never want to match partial units -- instead they
3030 will match the enclosing full CU. */
3031 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3038 sect_offset line_offset
{};
3040 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3041 if (attr
!= nullptr && attr
->form_is_unsigned ())
3043 struct quick_file_names find_entry
;
3045 line_offset
= (sect_offset
) attr
->as_unsigned ();
3047 /* We may have already read in this line header (TU line header sharing).
3048 If we have we're done. */
3049 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3050 find_entry
.hash
.line_sect_off
= line_offset
;
3051 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3052 &find_entry
, INSERT
);
3055 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3059 lh
= dwarf_decode_line_header (line_offset
, cu
);
3062 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
3065 if (!fnd
.is_unknown ())
3067 else if (lh
== nullptr)
3070 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3071 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3072 qfn
->hash
.line_sect_off
= line_offset
;
3073 /* There may not be a DW_AT_stmt_list. */
3074 if (slot
!= nullptr)
3077 std::vector
<const char *> include_names
;
3080 for (const auto &entry
: lh
->file_names ())
3082 gdb::unique_xmalloc_ptr
<char> name_holder
;
3083 const char *include_name
=
3084 compute_include_file_name (lh
.get (), entry
, fnd
, &name_holder
);
3085 if (include_name
!= nullptr)
3087 include_name
= per_objfile
->objfile
->intern (include_name
);
3088 include_names
.push_back (include_name
);
3093 qfn
->num_file_names
= offset
+ include_names
.size ();
3094 qfn
->comp_dir
= fnd
.intern_comp_dir (per_objfile
->objfile
);
3096 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3097 qfn
->num_file_names
);
3099 qfn
->file_names
[0] = xstrdup (fnd
.get_name ());
3101 if (!include_names
.empty ())
3102 memcpy (&qfn
->file_names
[offset
], include_names
.data (),
3103 include_names
.size () * sizeof (const char *));
3105 qfn
->real_names
= NULL
;
3107 lh_cu
->v
.quick
->file_names
= qfn
;
3110 /* A helper for the "quick" functions which attempts to read the line
3111 table for THIS_CU. */
3113 static struct quick_file_names
*
3114 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3115 dwarf2_per_objfile
*per_objfile
)
3117 /* This should never be called for TUs. */
3118 gdb_assert (! this_cu
->is_debug_types
);
3119 /* Nor type unit groups. */
3120 gdb_assert (! this_cu
->type_unit_group_p ());
3122 if (this_cu
->v
.quick
->files_read
)
3123 return this_cu
->v
.quick
->file_names
;
3125 cutu_reader
reader (this_cu
, per_objfile
);
3126 if (!reader
.dummy_p
)
3127 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3129 return this_cu
->v
.quick
->file_names
;
3132 /* A helper for the "quick" functions which computes and caches the
3133 real path for a given file name from the line table. */
3136 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3137 struct quick_file_names
*qfn
, int index
)
3139 if (qfn
->real_names
== NULL
)
3140 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3141 qfn
->num_file_names
, const char *);
3143 if (qfn
->real_names
[index
] == NULL
)
3145 const char *dirname
= nullptr;
3147 if (!IS_ABSOLUTE_PATH (qfn
->file_names
[index
]))
3148 dirname
= qfn
->comp_dir
;
3150 gdb::unique_xmalloc_ptr
<char> fullname
;
3151 fullname
= find_source_or_rewrite (qfn
->file_names
[index
], dirname
);
3153 qfn
->real_names
[index
] = fullname
.release ();
3156 return qfn
->real_names
[index
];
3160 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3162 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3163 dwarf2_per_cu_data
*dwarf_cu
3164 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3165 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3170 return cust
->primary_filetab ();
3176 dwarf2_per_cu_data::free_cached_file_names ()
3179 fnd
->forget_fullname ();
3181 if (per_bfd
== nullptr || !per_bfd
->using_index
|| v
.quick
== nullptr)
3184 struct quick_file_names
*file_data
= v
.quick
->file_names
;
3185 if (file_data
!= nullptr && file_data
->real_names
!= nullptr)
3187 for (int i
= 0; i
< file_data
->num_file_names
; ++i
)
3189 xfree ((void *) file_data
->real_names
[i
]);
3190 file_data
->real_names
[i
] = nullptr;
3196 dwarf2_base_index_functions::forget_cached_source_info
3197 (struct objfile
*objfile
)
3199 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3201 for (auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3202 per_cu
->free_cached_file_names ();
3205 /* Struct used to manage iterating over all CUs looking for a symbol. */
3207 struct dw2_symtab_iterator
3209 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3210 dwarf2_per_objfile
*per_objfile
;
3211 /* If set, only look for symbols that match that block. Valid values are
3212 GLOBAL_BLOCK and STATIC_BLOCK. */
3213 gdb::optional
<block_enum
> block_index
;
3214 /* The kind of symbol we're looking for. */
3216 /* The list of CUs from the index entry of the symbol,
3217 or NULL if not found. */
3219 /* The next element in VEC to look at. */
3221 /* The number of elements in VEC, or zero if there is no match. */
3223 /* Have we seen a global version of the symbol?
3224 If so we can ignore all further global instances.
3225 This is to work around gold/15646, inefficient gold-generated
3230 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3233 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3234 dwarf2_per_objfile
*per_objfile
,
3235 gdb::optional
<block_enum
> block_index
,
3236 domain_enum domain
, offset_type namei
)
3238 iter
->per_objfile
= per_objfile
;
3239 iter
->block_index
= block_index
;
3240 iter
->domain
= domain
;
3242 iter
->global_seen
= 0;
3246 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3247 /* index is NULL if OBJF_READNOW. */
3251 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3252 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3254 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3255 iter
->length
= iter
->vec
[0];
3258 /* Return the next matching CU or NULL if there are no more. */
3260 static struct dwarf2_per_cu_data
*
3261 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3263 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3265 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3267 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3268 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3269 gdb_index_symbol_kind symbol_kind
=
3270 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3271 /* Only check the symbol attributes if they're present.
3272 Indices prior to version 7 don't record them,
3273 and indices >= 7 may elide them for certain symbols
3274 (gold does this). */
3276 (per_objfile
->per_bfd
->index_table
->version
>= 7
3277 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3279 /* Don't crash on bad data. */
3280 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3282 complaint (_(".gdb_index entry has bad CU index"
3283 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3287 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3289 /* Skip if already read in. */
3290 if (per_objfile
->symtab_set_p (per_cu
))
3293 /* Check static vs global. */
3296 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3298 if (iter
->block_index
.has_value ())
3300 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3302 if (is_static
!= want_static
)
3306 /* Work around gold/15646. */
3308 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3310 if (iter
->global_seen
)
3313 iter
->global_seen
= 1;
3317 /* Only check the symbol's kind if it has one. */
3320 switch (iter
->domain
)
3323 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3324 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3325 /* Some types are also in VAR_DOMAIN. */
3326 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3330 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3334 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3338 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3354 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3360 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3361 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3364 for (int i
= 0; i
< total
; ++i
)
3366 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3368 if (!per_objfile
->symtab_set_p (per_cu
))
3371 gdb_printf (_(" Number of read CUs: %d\n"), total
- count
);
3372 gdb_printf (_(" Number of unread CUs: %d\n"), count
);
3375 /* This dumps minimal information about the index.
3376 It is called via "mt print objfiles".
3377 One use is to verify .gdb_index has been loaded by the
3378 gdb.dwarf2/gdb-index.exp testcase. */
3381 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3383 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3385 gdb_assert (per_objfile
->per_bfd
->using_index
);
3386 gdb_printf (".gdb_index:");
3387 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3389 gdb_printf (" version %d\n",
3390 per_objfile
->per_bfd
->index_table
->version
);
3393 gdb_printf (" faked for \"readnow\"\n");
3398 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3400 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3401 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3403 for (int i
= 0; i
< total_units
; ++i
)
3405 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3407 /* We don't want to directly expand a partial CU, because if we
3408 read it with the wrong language, then assertion failures can
3409 be triggered later on. See PR symtab/23010. So, tell
3410 dw2_instantiate_symtab to skip partial CUs -- any important
3411 partial CU will be read via DW_TAG_imported_unit anyway. */
3412 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3417 dw2_expand_symtabs_matching_symbol
3418 (mapped_index_base
&index
,
3419 const lookup_name_info
&lookup_name_in
,
3420 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3421 gdb::function_view
<bool (offset_type
)> match_callback
,
3422 dwarf2_per_objfile
*per_objfile
);
3425 dw2_expand_symtabs_matching_one
3426 (dwarf2_per_cu_data
*per_cu
,
3427 dwarf2_per_objfile
*per_objfile
,
3428 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3429 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3432 dwarf2_gdb_index::expand_matching_symbols
3433 (struct objfile
*objfile
,
3434 const lookup_name_info
&name
, domain_enum domain
,
3436 symbol_compare_ftype
*ordered_compare
)
3439 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3441 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3443 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3445 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3447 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3448 auto matcher
= [&] (const char *symname
)
3450 if (ordered_compare
== nullptr)
3452 return ordered_compare (symname
, match_name
) == 0;
3455 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3456 [&] (offset_type namei
)
3458 struct dw2_symtab_iterator iter
;
3459 struct dwarf2_per_cu_data
*per_cu
;
3461 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3463 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3464 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3471 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3472 proceed assuming all symtabs have been read in. */
3476 /* Starting from a search name, return the string that finds the upper
3477 bound of all strings that start with SEARCH_NAME in a sorted name
3478 list. Returns the empty string to indicate that the upper bound is
3479 the end of the list. */
3482 make_sort_after_prefix_name (const char *search_name
)
3484 /* When looking to complete "func", we find the upper bound of all
3485 symbols that start with "func" by looking for where we'd insert
3486 the closest string that would follow "func" in lexicographical
3487 order. Usually, that's "func"-with-last-character-incremented,
3488 i.e. "fund". Mind non-ASCII characters, though. Usually those
3489 will be UTF-8 multi-byte sequences, but we can't be certain.
3490 Especially mind the 0xff character, which is a valid character in
3491 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3492 rule out compilers allowing it in identifiers. Note that
3493 conveniently, strcmp/strcasecmp are specified to compare
3494 characters interpreted as unsigned char. So what we do is treat
3495 the whole string as a base 256 number composed of a sequence of
3496 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3497 to 0, and carries 1 to the following more-significant position.
3498 If the very first character in SEARCH_NAME ends up incremented
3499 and carries/overflows, then the upper bound is the end of the
3500 list. The string after the empty string is also the empty
3503 Some examples of this operation:
3505 SEARCH_NAME => "+1" RESULT
3509 "\xff" "a" "\xff" => "\xff" "b"
3514 Then, with these symbols for example:
3520 completing "func" looks for symbols between "func" and
3521 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3522 which finds "func" and "func1", but not "fund".
3526 funcÿ (Latin1 'ÿ' [0xff])
3530 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3531 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3535 ÿÿ (Latin1 'ÿ' [0xff])
3538 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3539 the end of the list.
3541 std::string after
= search_name
;
3542 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3544 if (!after
.empty ())
3545 after
.back () = (unsigned char) after
.back () + 1;
3549 /* See declaration. */
3551 std::pair
<std::vector
<name_component
>::const_iterator
,
3552 std::vector
<name_component
>::const_iterator
>
3553 mapped_index_base::find_name_components_bounds
3554 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3555 dwarf2_per_objfile
*per_objfile
) const
3558 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3560 const char *lang_name
3561 = lookup_name_without_params
.language_lookup_name (lang
);
3563 /* Comparison function object for lower_bound that matches against a
3564 given symbol name. */
3565 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3568 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3569 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3570 return name_cmp (elem_name
, name
) < 0;
3573 /* Comparison function object for upper_bound that matches against a
3574 given symbol name. */
3575 auto lookup_compare_upper
= [&] (const char *name
,
3576 const name_component
&elem
)
3578 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3579 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3580 return name_cmp (name
, elem_name
) < 0;
3583 auto begin
= this->name_components
.begin ();
3584 auto end
= this->name_components
.end ();
3586 /* Find the lower bound. */
3589 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3592 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3595 /* Find the upper bound. */
3598 if (lookup_name_without_params
.completion_mode ())
3600 /* In completion mode, we want UPPER to point past all
3601 symbols names that have the same prefix. I.e., with
3602 these symbols, and completing "func":
3604 function << lower bound
3606 other_function << upper bound
3608 We find the upper bound by looking for the insertion
3609 point of "func"-with-last-character-incremented,
3611 std::string after
= make_sort_after_prefix_name (lang_name
);
3614 return std::lower_bound (lower
, end
, after
.c_str (),
3615 lookup_compare_lower
);
3618 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3621 return {lower
, upper
};
3624 /* See declaration. */
3627 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3629 if (!this->name_components
.empty ())
3632 this->name_components_casing
= case_sensitivity
;
3634 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3636 /* The code below only knows how to break apart components of C++
3637 symbol names (and other languages that use '::' as
3638 namespace/module separator) and Ada symbol names. */
3639 auto count
= this->symbol_name_count ();
3640 for (offset_type idx
= 0; idx
< count
; idx
++)
3642 if (this->symbol_name_slot_invalid (idx
))
3645 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3647 /* Add each name component to the name component table. */
3648 unsigned int previous_len
= 0;
3650 if (strstr (name
, "::") != nullptr)
3652 for (unsigned int current_len
= cp_find_first_component (name
);
3653 name
[current_len
] != '\0';
3654 current_len
+= cp_find_first_component (name
+ current_len
))
3656 gdb_assert (name
[current_len
] == ':');
3657 this->name_components
.push_back ({previous_len
, idx
});
3658 /* Skip the '::'. */
3660 previous_len
= current_len
;
3665 /* Handle the Ada encoded (aka mangled) form here. */
3666 for (const char *iter
= strstr (name
, "__");
3668 iter
= strstr (iter
, "__"))
3670 this->name_components
.push_back ({previous_len
, idx
});
3672 previous_len
= iter
- name
;
3676 this->name_components
.push_back ({previous_len
, idx
});
3679 /* Sort name_components elements by name. */
3680 auto name_comp_compare
= [&] (const name_component
&left
,
3681 const name_component
&right
)
3683 const char *left_qualified
3684 = this->symbol_name_at (left
.idx
, per_objfile
);
3685 const char *right_qualified
3686 = this->symbol_name_at (right
.idx
, per_objfile
);
3688 const char *left_name
= left_qualified
+ left
.name_offset
;
3689 const char *right_name
= right_qualified
+ right
.name_offset
;
3691 return name_cmp (left_name
, right_name
) < 0;
3694 std::sort (this->name_components
.begin (),
3695 this->name_components
.end (),
3699 /* Helper for dw2_expand_symtabs_matching that works with a
3700 mapped_index_base instead of the containing objfile. This is split
3701 to a separate function in order to be able to unit test the
3702 name_components matching using a mock mapped_index_base. For each
3703 symbol name that matches, calls MATCH_CALLBACK, passing it the
3704 symbol's index in the mapped_index_base symbol table. */
3707 dw2_expand_symtabs_matching_symbol
3708 (mapped_index_base
&index
,
3709 const lookup_name_info
&lookup_name_in
,
3710 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3711 gdb::function_view
<bool (offset_type
)> match_callback
,
3712 dwarf2_per_objfile
*per_objfile
)
3714 lookup_name_info lookup_name_without_params
3715 = lookup_name_in
.make_ignore_params ();
3717 /* Build the symbol name component sorted vector, if we haven't
3719 index
.build_name_components (per_objfile
);
3721 /* The same symbol may appear more than once in the range though.
3722 E.g., if we're looking for symbols that complete "w", and we have
3723 a symbol named "w1::w2", we'll find the two name components for
3724 that same symbol in the range. To be sure we only call the
3725 callback once per symbol, we first collect the symbol name
3726 indexes that matched in a temporary vector and ignore
3728 std::vector
<offset_type
> matches
;
3730 struct name_and_matcher
3732 symbol_name_matcher_ftype
*matcher
;
3735 bool operator== (const name_and_matcher
&other
) const
3737 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3741 /* A vector holding all the different symbol name matchers, for all
3743 std::vector
<name_and_matcher
> matchers
;
3745 for (int i
= 0; i
< nr_languages
; i
++)
3747 enum language lang_e
= (enum language
) i
;
3749 const language_defn
*lang
= language_def (lang_e
);
3750 symbol_name_matcher_ftype
*name_matcher
3751 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3753 name_and_matcher key
{
3755 lookup_name_without_params
.language_lookup_name (lang_e
)
3758 /* Don't insert the same comparison routine more than once.
3759 Note that we do this linear walk. This is not a problem in
3760 practice because the number of supported languages is
3762 if (std::find (matchers
.begin (), matchers
.end (), key
)
3765 matchers
.push_back (std::move (key
));
3768 = index
.find_name_components_bounds (lookup_name_without_params
,
3769 lang_e
, per_objfile
);
3771 /* Now for each symbol name in range, check to see if we have a name
3772 match, and if so, call the MATCH_CALLBACK callback. */
3774 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3776 const char *qualified
3777 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3779 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3780 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3783 matches
.push_back (bounds
.first
->idx
);
3787 std::sort (matches
.begin (), matches
.end ());
3789 /* Finally call the callback, once per match. */
3792 for (offset_type idx
: matches
)
3796 if (!match_callback (idx
))
3805 /* Above we use a type wider than idx's for 'prev', since 0 and
3806 (offset_type)-1 are both possible values. */
3807 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3814 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3816 /* A mock .gdb_index/.debug_names-like name index table, enough to
3817 exercise dw2_expand_symtabs_matching_symbol, which works with the
3818 mapped_index_base interface. Builds an index from the symbol list
3819 passed as parameter to the constructor. */
3820 class mock_mapped_index
: public mapped_index_base
3823 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3824 : m_symbol_table (symbols
)
3827 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3829 /* Return the number of names in the symbol table. */
3830 size_t symbol_name_count () const override
3832 return m_symbol_table
.size ();
3835 /* Get the name of the symbol at IDX in the symbol table. */
3836 const char *symbol_name_at
3837 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3839 return m_symbol_table
[idx
];
3843 gdb::array_view
<const char *> m_symbol_table
;
3846 /* Convenience function that converts a NULL pointer to a "<null>"
3847 string, to pass to print routines. */
3850 string_or_null (const char *str
)
3852 return str
!= NULL
? str
: "<null>";
3855 /* Check if a lookup_name_info built from
3856 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3857 index. EXPECTED_LIST is the list of expected matches, in expected
3858 matching order. If no match expected, then an empty list is
3859 specified. Returns true on success. On failure prints a warning
3860 indicating the file:line that failed, and returns false. */
3863 check_match (const char *file
, int line
,
3864 mock_mapped_index
&mock_index
,
3865 const char *name
, symbol_name_match_type match_type
,
3866 bool completion_mode
,
3867 std::initializer_list
<const char *> expected_list
,
3868 dwarf2_per_objfile
*per_objfile
)
3870 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3872 bool matched
= true;
3874 auto mismatch
= [&] (const char *expected_str
,
3877 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3878 "expected=\"%s\", got=\"%s\"\n"),
3880 (match_type
== symbol_name_match_type::FULL
3882 name
, string_or_null (expected_str
), string_or_null (got
));
3886 auto expected_it
= expected_list
.begin ();
3887 auto expected_end
= expected_list
.end ();
3889 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3891 [&] (offset_type idx
)
3893 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3894 const char *expected_str
3895 = expected_it
== expected_end
? NULL
: *expected_it
++;
3897 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3898 mismatch (expected_str
, matched_name
);
3902 const char *expected_str
3903 = expected_it
== expected_end
? NULL
: *expected_it
++;
3904 if (expected_str
!= NULL
)
3905 mismatch (expected_str
, NULL
);
3910 /* The symbols added to the mock mapped_index for testing (in
3912 static const char *test_symbols
[] = {
3921 "ns2::tmpl<int>::foo2",
3922 "(anonymous namespace)::A::B::C",
3924 /* These are used to check that the increment-last-char in the
3925 matching algorithm for completion doesn't match "t1_fund" when
3926 completing "t1_func". */
3932 /* A UTF-8 name with multi-byte sequences to make sure that
3933 cp-name-parser understands this as a single identifier ("função"
3934 is "function" in PT). */
3937 /* \377 (0xff) is Latin1 'ÿ'. */
3940 /* \377 (0xff) is Latin1 'ÿ'. */
3944 /* A name with all sorts of complications. Starts with "z" to make
3945 it easier for the completion tests below. */
3946 #define Z_SYM_NAME \
3947 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3948 "::tuple<(anonymous namespace)::ui*, " \
3949 "std::default_delete<(anonymous namespace)::ui>, void>"
3954 /* Returns true if the mapped_index_base::find_name_component_bounds
3955 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3956 in completion mode. */
3959 check_find_bounds_finds (mapped_index_base
&index
,
3960 const char *search_name
,
3961 gdb::array_view
<const char *> expected_syms
,
3962 dwarf2_per_objfile
*per_objfile
)
3964 lookup_name_info
lookup_name (search_name
,
3965 symbol_name_match_type::FULL
, true);
3967 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3971 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3972 if (distance
!= expected_syms
.size ())
3975 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3977 auto nc_elem
= bounds
.first
+ exp_elem
;
3978 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3979 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3986 /* Test the lower-level mapped_index::find_name_component_bounds
3990 test_mapped_index_find_name_component_bounds ()
3992 mock_mapped_index
mock_index (test_symbols
);
3994 mock_index
.build_name_components (NULL
/* per_objfile */);
3996 /* Test the lower-level mapped_index::find_name_component_bounds
3997 method in completion mode. */
3999 static const char *expected_syms
[] = {
4004 SELF_CHECK (check_find_bounds_finds
4005 (mock_index
, "t1_func", expected_syms
,
4006 NULL
/* per_objfile */));
4009 /* Check that the increment-last-char in the name matching algorithm
4010 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4012 static const char *expected_syms1
[] = {
4016 SELF_CHECK (check_find_bounds_finds
4017 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4019 static const char *expected_syms2
[] = {
4022 SELF_CHECK (check_find_bounds_finds
4023 (mock_index
, "\377\377", expected_syms2
,
4024 NULL
/* per_objfile */));
4028 /* Test dw2_expand_symtabs_matching_symbol. */
4031 test_dw2_expand_symtabs_matching_symbol ()
4033 mock_mapped_index
mock_index (test_symbols
);
4035 /* We let all tests run until the end even if some fails, for debug
4037 bool any_mismatch
= false;
4039 /* Create the expected symbols list (an initializer_list). Needed
4040 because lists have commas, and we need to pass them to CHECK,
4041 which is a macro. */
4042 #define EXPECT(...) { __VA_ARGS__ }
4044 /* Wrapper for check_match that passes down the current
4045 __FILE__/__LINE__. */
4046 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4047 any_mismatch |= !check_match (__FILE__, __LINE__, \
4049 NAME, MATCH_TYPE, COMPLETION_MODE, \
4050 EXPECTED_LIST, NULL)
4052 /* Identity checks. */
4053 for (const char *sym
: test_symbols
)
4055 /* Should be able to match all existing symbols. */
4056 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4059 /* Should be able to match all existing symbols with
4061 std::string with_params
= std::string (sym
) + "(int)";
4062 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4065 /* Should be able to match all existing symbols with
4066 parameters and qualifiers. */
4067 with_params
= std::string (sym
) + " ( int ) const";
4068 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4071 /* This should really find sym, but cp-name-parser.y doesn't
4072 know about lvalue/rvalue qualifiers yet. */
4073 with_params
= std::string (sym
) + " ( int ) &&";
4074 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4078 /* Check that the name matching algorithm for completion doesn't get
4079 confused with Latin1 'ÿ' / 0xff. */
4081 static const char str
[] = "\377";
4082 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4083 EXPECT ("\377", "\377\377123"));
4086 /* Check that the increment-last-char in the matching algorithm for
4087 completion doesn't match "t1_fund" when completing "t1_func". */
4089 static const char str
[] = "t1_func";
4090 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4091 EXPECT ("t1_func", "t1_func1"));
4094 /* Check that completion mode works at each prefix of the expected
4097 static const char str
[] = "function(int)";
4098 size_t len
= strlen (str
);
4101 for (size_t i
= 1; i
< len
; i
++)
4103 lookup
.assign (str
, i
);
4104 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4105 EXPECT ("function"));
4109 /* While "w" is a prefix of both components, the match function
4110 should still only be called once. */
4112 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4114 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4118 /* Same, with a "complicated" symbol. */
4120 static const char str
[] = Z_SYM_NAME
;
4121 size_t len
= strlen (str
);
4124 for (size_t i
= 1; i
< len
; i
++)
4126 lookup
.assign (str
, i
);
4127 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4128 EXPECT (Z_SYM_NAME
));
4132 /* In FULL mode, an incomplete symbol doesn't match. */
4134 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4138 /* A complete symbol with parameters matches any overload, since the
4139 index has no overload info. */
4141 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4142 EXPECT ("std::zfunction", "std::zfunction2"));
4143 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4144 EXPECT ("std::zfunction", "std::zfunction2"));
4145 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4146 EXPECT ("std::zfunction", "std::zfunction2"));
4149 /* Check that whitespace is ignored appropriately. A symbol with a
4150 template argument list. */
4152 static const char expected
[] = "ns::foo<int>";
4153 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4155 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4159 /* Check that whitespace is ignored appropriately. A symbol with a
4160 template argument list that includes a pointer. */
4162 static const char expected
[] = "ns::foo<char*>";
4163 /* Try both completion and non-completion modes. */
4164 static const bool completion_mode
[2] = {false, true};
4165 for (size_t i
= 0; i
< 2; i
++)
4167 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4168 completion_mode
[i
], EXPECT (expected
));
4169 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4170 completion_mode
[i
], EXPECT (expected
));
4172 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4173 completion_mode
[i
], EXPECT (expected
));
4174 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4175 completion_mode
[i
], EXPECT (expected
));
4180 /* Check method qualifiers are ignored. */
4181 static const char expected
[] = "ns::foo<char*>";
4182 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4183 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4184 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4185 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4186 CHECK_MATCH ("foo < char * > ( int ) const",
4187 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4188 CHECK_MATCH ("foo < char * > ( int ) &&",
4189 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4192 /* Test lookup names that don't match anything. */
4194 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4197 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4201 /* Some wild matching tests, exercising "(anonymous namespace)",
4202 which should not be confused with a parameter list. */
4204 static const char *syms
[] = {
4208 "A :: B :: C ( int )",
4213 for (const char *s
: syms
)
4215 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4216 EXPECT ("(anonymous namespace)::A::B::C"));
4221 static const char expected
[] = "ns2::tmpl<int>::foo2";
4222 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4224 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4228 SELF_CHECK (!any_mismatch
);
4237 test_mapped_index_find_name_component_bounds ();
4238 test_dw2_expand_symtabs_matching_symbol ();
4241 }} // namespace selftests::dw2_expand_symtabs_matching
4243 #endif /* GDB_SELF_TEST */
4245 /* If FILE_MATCHER is NULL or if PER_CU has
4246 dwarf2_per_cu_quick_data::MARK set (see
4247 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4248 EXPANSION_NOTIFY on it. */
4251 dw2_expand_symtabs_matching_one
4252 (dwarf2_per_cu_data
*per_cu
,
4253 dwarf2_per_objfile
*per_objfile
,
4254 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4255 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4257 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4259 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4261 compunit_symtab
*symtab
4262 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4263 gdb_assert (symtab
!= nullptr);
4265 if (expansion_notify
!= NULL
&& symtab_was_null
)
4266 return expansion_notify (symtab
);
4271 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4272 matched, to expand corresponding CUs that were marked. IDX is the
4273 index of the symbol name that matched. */
4276 dw2_expand_marked_cus
4277 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4278 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4279 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4280 block_search_flags search_flags
,
4283 offset_type vec_len
, vec_idx
;
4284 bool global_seen
= false;
4285 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4287 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4289 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4291 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4292 /* This value is only valid for index versions >= 7. */
4293 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4294 gdb_index_symbol_kind symbol_kind
=
4295 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4296 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4297 /* Only check the symbol attributes if they're present.
4298 Indices prior to version 7 don't record them,
4299 and indices >= 7 may elide them for certain symbols
4300 (gold does this). */
4303 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4305 /* Work around gold/15646. */
4308 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4316 /* Only check the symbol's kind if it has one. */
4321 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4326 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4332 case VARIABLES_DOMAIN
:
4333 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4336 case FUNCTIONS_DOMAIN
:
4337 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4341 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4344 case MODULES_DOMAIN
:
4345 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4353 /* Don't crash on bad data. */
4354 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4356 complaint (_(".gdb_index entry has bad CU index"
4357 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4361 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4362 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4370 /* If FILE_MATCHER is non-NULL, set all the
4371 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4372 that match FILE_MATCHER. */
4375 dw_expand_symtabs_matching_file_matcher
4376 (dwarf2_per_objfile
*per_objfile
,
4377 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4379 if (file_matcher
== NULL
)
4382 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4384 NULL
, xcalloc
, xfree
));
4385 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4387 NULL
, xcalloc
, xfree
));
4389 /* The rule is CUs specify all the files, including those used by
4390 any TU, so there's no need to scan TUs here. */
4392 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4396 if (per_cu
->is_debug_types
)
4398 per_cu
->v
.quick
->mark
= 0;
4400 /* We only need to look at symtabs not already expanded. */
4401 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4404 if (per_cu
->fnd
!= nullptr)
4406 file_and_directory
*fnd
= per_cu
->fnd
.get ();
4408 if (file_matcher (fnd
->get_name (), false))
4410 per_cu
->v
.quick
->mark
= 1;
4414 /* Before we invoke realpath, which can get expensive when many
4415 files are involved, do a quick comparison of the basenames. */
4416 if ((basenames_may_differ
4417 || file_matcher (lbasename (fnd
->get_name ()), true))
4418 && file_matcher (fnd
->get_fullname (), false))
4420 per_cu
->v
.quick
->mark
= 1;
4425 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4427 if (file_data
== NULL
)
4430 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4432 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4434 per_cu
->v
.quick
->mark
= 1;
4438 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4440 const char *this_real_name
;
4442 if (file_matcher (file_data
->file_names
[j
], false))
4444 per_cu
->v
.quick
->mark
= 1;
4448 /* Before we invoke realpath, which can get expensive when many
4449 files are involved, do a quick comparison of the basenames. */
4450 if (!basenames_may_differ
4451 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4455 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4456 if (file_matcher (this_real_name
, false))
4458 per_cu
->v
.quick
->mark
= 1;
4463 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4464 ? visited_found
.get ()
4465 : visited_not_found
.get (),
4472 dwarf2_gdb_index::expand_symtabs_matching
4473 (struct objfile
*objfile
,
4474 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4475 const lookup_name_info
*lookup_name
,
4476 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4477 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4478 block_search_flags search_flags
,
4480 enum search_domain kind
)
4482 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4484 /* index_table is NULL if OBJF_READNOW. */
4485 if (!per_objfile
->per_bfd
->index_table
)
4488 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4490 /* This invariant is documented in quick-functions.h. */
4491 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
4492 if (lookup_name
== nullptr)
4494 for (dwarf2_per_cu_data
*per_cu
4495 : all_comp_units_range (per_objfile
->per_bfd
))
4499 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4507 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4510 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4512 [&] (offset_type idx
)
4514 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4515 expansion_notify
, search_flags
, kind
))
4523 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4526 static struct compunit_symtab
*
4527 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4532 if (cust
->blockvector () != nullptr
4533 && blockvector_contains_pc (cust
->blockvector (), pc
))
4536 if (cust
->includes
== NULL
)
4539 for (i
= 0; cust
->includes
[i
]; ++i
)
4541 struct compunit_symtab
*s
= cust
->includes
[i
];
4543 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4551 struct compunit_symtab
*
4552 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4553 (struct objfile
*objfile
,
4554 struct bound_minimal_symbol msymbol
,
4556 struct obj_section
*section
,
4559 struct dwarf2_per_cu_data
*data
;
4560 struct compunit_symtab
*result
;
4562 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4563 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4566 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4567 data
= ((struct dwarf2_per_cu_data
*)
4568 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4573 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4574 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4575 paddress (objfile
->arch (), pc
));
4577 result
= recursively_find_pc_sect_compunit_symtab
4578 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4580 gdb_assert (result
!= NULL
);
4585 dwarf2_base_index_functions::map_symbol_filenames
4586 (struct objfile
*objfile
,
4587 gdb::function_view
<symbol_filename_ftype
> fun
,
4590 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4592 /* Use caches to ensure we only call FUN once for each filename. */
4593 filename_seen_cache filenames_cache
;
4594 std::unordered_set
<quick_file_names
*> qfn_cache
;
4596 /* The rule is CUs specify all the files, including those used by any TU,
4597 so there's no need to scan TUs here. We can ignore file names coming
4598 from already-expanded CUs. It is possible that an expanded CU might
4599 reuse the file names data from a currently unexpanded CU, in this
4600 case we don't want to report the files from the unexpanded CU. */
4602 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4604 if (!per_cu
->is_debug_types
4605 && per_objfile
->symtab_set_p (per_cu
.get ()))
4607 if (per_cu
->v
.quick
->file_names
!= nullptr)
4608 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4612 for (dwarf2_per_cu_data
*per_cu
4613 : all_comp_units_range (per_objfile
->per_bfd
))
4615 /* We only need to look at symtabs not already expanded. */
4616 if (per_cu
->is_debug_types
|| per_objfile
->symtab_set_p (per_cu
))
4619 if (per_cu
->fnd
!= nullptr)
4621 file_and_directory
*fnd
= per_cu
->fnd
.get ();
4623 const char *filename
= fnd
->get_name ();
4624 const char *key
= filename
;
4625 const char *fullname
= nullptr;
4629 fullname
= fnd
->get_fullname ();
4633 if (!filenames_cache
.seen (key
))
4634 fun (filename
, fullname
);
4637 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4638 if (file_data
== nullptr
4639 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4642 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4644 const char *filename
= file_data
->file_names
[j
];
4645 const char *key
= filename
;
4646 const char *fullname
= nullptr;
4650 fullname
= dw2_get_real_path (per_objfile
, file_data
, j
);
4654 if (!filenames_cache
.seen (key
))
4655 fun (filename
, fullname
);
4661 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4666 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
4669 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
4671 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4673 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4675 /* Is this already expanded? */
4676 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4679 /* It has not yet been expanded. */
4686 /* DWARF-5 debug_names reader. */
4688 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4689 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4691 /* A helper function that reads the .debug_names section in SECTION
4692 and fills in MAP. FILENAME is the name of the file containing the
4693 section; it is used for error reporting.
4695 Returns true if all went well, false otherwise. */
4698 read_debug_names_from_section (struct objfile
*objfile
,
4699 const char *filename
,
4700 struct dwarf2_section_info
*section
,
4701 mapped_debug_names
&map
)
4703 if (section
->empty ())
4706 /* Older elfutils strip versions could keep the section in the main
4707 executable while splitting it for the separate debug info file. */
4708 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4711 section
->read (objfile
);
4713 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4715 const gdb_byte
*addr
= section
->buffer
;
4717 bfd
*const abfd
= section
->get_bfd_owner ();
4719 unsigned int bytes_read
;
4720 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4723 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4724 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4725 if (bytes_read
+ length
!= section
->size
)
4727 /* There may be multiple per-CU indices. */
4728 warning (_("Section .debug_names in %s length %s does not match "
4729 "section length %s, ignoring .debug_names."),
4730 filename
, plongest (bytes_read
+ length
),
4731 pulongest (section
->size
));
4735 /* The version number. */
4736 uint16_t version
= read_2_bytes (abfd
, addr
);
4740 warning (_("Section .debug_names in %s has unsupported version %d, "
4741 "ignoring .debug_names."),
4747 uint16_t padding
= read_2_bytes (abfd
, addr
);
4751 warning (_("Section .debug_names in %s has unsupported padding %d, "
4752 "ignoring .debug_names."),
4757 /* comp_unit_count - The number of CUs in the CU list. */
4758 map
.cu_count
= read_4_bytes (abfd
, addr
);
4761 /* local_type_unit_count - The number of TUs in the local TU
4763 map
.tu_count
= read_4_bytes (abfd
, addr
);
4766 /* foreign_type_unit_count - The number of TUs in the foreign TU
4768 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4770 if (foreign_tu_count
!= 0)
4772 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4773 "ignoring .debug_names."),
4774 filename
, static_cast<unsigned long> (foreign_tu_count
));
4778 /* bucket_count - The number of hash buckets in the hash lookup
4780 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4783 /* name_count - The number of unique names in the index. */
4784 map
.name_count
= read_4_bytes (abfd
, addr
);
4787 /* abbrev_table_size - The size in bytes of the abbreviations
4789 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4792 /* augmentation_string_size - The size in bytes of the augmentation
4793 string. This value is rounded up to a multiple of 4. */
4794 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4796 map
.augmentation_is_gdb
= ((augmentation_string_size
4797 == sizeof (dwarf5_augmentation
))
4798 && memcmp (addr
, dwarf5_augmentation
,
4799 sizeof (dwarf5_augmentation
)) == 0);
4800 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4801 addr
+= augmentation_string_size
;
4804 map
.cu_table_reordered
= addr
;
4805 addr
+= map
.cu_count
* map
.offset_size
;
4807 /* List of Local TUs */
4808 map
.tu_table_reordered
= addr
;
4809 addr
+= map
.tu_count
* map
.offset_size
;
4811 /* Hash Lookup Table */
4812 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4813 addr
+= map
.bucket_count
* 4;
4814 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4815 addr
+= map
.name_count
* 4;
4818 map
.name_table_string_offs_reordered
= addr
;
4819 addr
+= map
.name_count
* map
.offset_size
;
4820 map
.name_table_entry_offs_reordered
= addr
;
4821 addr
+= map
.name_count
* map
.offset_size
;
4823 const gdb_byte
*abbrev_table_start
= addr
;
4826 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4831 const auto insertpair
4832 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4833 if (!insertpair
.second
)
4835 warning (_("Section .debug_names in %s has duplicate index %s, "
4836 "ignoring .debug_names."),
4837 filename
, pulongest (index_num
));
4840 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4841 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4846 mapped_debug_names::index_val::attr attr
;
4847 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4849 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4851 if (attr
.form
== DW_FORM_implicit_const
)
4853 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4857 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4859 indexval
.attr_vec
.push_back (std::move (attr
));
4862 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4864 warning (_("Section .debug_names in %s has abbreviation_table "
4865 "of size %s vs. written as %u, ignoring .debug_names."),
4866 filename
, plongest (addr
- abbrev_table_start
),
4870 map
.entry_pool
= addr
;
4875 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4879 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4880 const mapped_debug_names
&map
,
4881 dwarf2_section_info
§ion
,
4884 if (!map
.augmentation_is_gdb
)
4886 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4888 sect_offset sect_off
4889 = (sect_offset
) (extract_unsigned_integer
4890 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4892 map
.dwarf5_byte_order
));
4893 /* We don't know the length of the CU, because the CU list in a
4894 .debug_names index can be incomplete, so we can't use the start
4895 of the next CU as end of this CU. We create the CUs here with
4896 length 0, and in cutu_reader::cutu_reader we'll fill in the
4898 dwarf2_per_cu_data_up per_cu
4899 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4901 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4906 sect_offset sect_off_prev
;
4907 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4909 sect_offset sect_off_next
;
4910 if (i
< map
.cu_count
)
4913 = (sect_offset
) (extract_unsigned_integer
4914 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4916 map
.dwarf5_byte_order
));
4919 sect_off_next
= (sect_offset
) section
.size
;
4922 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4923 dwarf2_per_cu_data_up per_cu
4924 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4925 sect_off_prev
, length
);
4926 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4928 sect_off_prev
= sect_off_next
;
4932 /* Read the CU list from the mapped index, and use it to create all
4933 the CU objects for this dwarf2_per_objfile. */
4936 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4937 const mapped_debug_names
&map
,
4938 const mapped_debug_names
&dwz_map
)
4940 gdb_assert (per_bfd
->all_comp_units
.empty ());
4941 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4943 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4944 false /* is_dwz */);
4946 if (dwz_map
.cu_count
== 0)
4949 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4950 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4954 /* Read .debug_names. If everything went ok, initialize the "quick"
4955 elements of all the CUs and return true. Otherwise, return false. */
4958 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4960 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4961 mapped_debug_names dwz_map
;
4962 struct objfile
*objfile
= per_objfile
->objfile
;
4963 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4965 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4966 &per_bfd
->debug_names
, *map
))
4969 /* Don't use the index if it's empty. */
4970 if (map
->name_count
== 0)
4973 /* If there is a .dwz file, read it so we can get its CU list as
4975 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4978 if (!read_debug_names_from_section (objfile
,
4979 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4980 &dwz
->debug_names
, dwz_map
))
4982 warning (_("could not read '.debug_names' section from %s; skipping"),
4983 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4988 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4990 if (map
->tu_count
!= 0)
4992 /* We can only handle a single .debug_types when we have an
4994 if (per_bfd
->types
.size () != 1)
4997 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4999 create_signatured_type_table_from_debug_names
5000 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5003 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5005 per_bfd
->debug_names_table
= std::move (map
);
5006 per_bfd
->using_index
= 1;
5007 per_bfd
->quick_file_names_table
=
5008 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5013 /* Type used to manage iterating over all CUs looking for a symbol for
5016 class dw2_debug_names_iterator
5019 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5020 block_search_flags block_index
,
5022 const char *name
, dwarf2_per_objfile
*per_objfile
)
5023 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5024 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5025 m_per_objfile (per_objfile
)
5028 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5029 search_domain search
, uint32_t namei
,
5030 dwarf2_per_objfile
*per_objfile
,
5031 domain_enum domain
= UNDEF_DOMAIN
)
5035 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5036 m_per_objfile (per_objfile
)
5039 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5040 block_search_flags block_index
, domain_enum domain
,
5041 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5042 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5043 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5044 m_per_objfile (per_objfile
)
5047 /* Return the next matching CU or NULL if there are no more. */
5048 dwarf2_per_cu_data
*next ();
5051 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5053 dwarf2_per_objfile
*per_objfile
);
5054 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5056 dwarf2_per_objfile
*per_objfile
);
5058 /* The internalized form of .debug_names. */
5059 const mapped_debug_names
&m_map
;
5061 /* Restrict the search to these blocks. */
5062 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
5063 | SEARCH_STATIC_BLOCK
);
5065 /* The kind of symbol we're looking for. */
5066 const domain_enum m_domain
= UNDEF_DOMAIN
;
5067 const search_domain m_search
= ALL_DOMAIN
;
5069 /* The list of CUs from the index entry of the symbol, or NULL if
5071 const gdb_byte
*m_addr
;
5073 dwarf2_per_objfile
*m_per_objfile
;
5077 mapped_debug_names::namei_to_name
5078 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5080 const ULONGEST namei_string_offs
5081 = extract_unsigned_integer ((name_table_string_offs_reordered
5082 + namei
* offset_size
),
5085 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5088 /* Find a slot in .debug_names for the object named NAME. If NAME is
5089 found, return pointer to its pool data. If NAME cannot be found,
5093 dw2_debug_names_iterator::find_vec_in_debug_names
5094 (const mapped_debug_names
&map
, const char *name
,
5095 dwarf2_per_objfile
*per_objfile
)
5097 int (*cmp
) (const char *, const char *);
5099 gdb::unique_xmalloc_ptr
<char> without_params
;
5100 if (current_language
->la_language
== language_cplus
5101 || current_language
->la_language
== language_fortran
5102 || current_language
->la_language
== language_d
)
5104 /* NAME is already canonical. Drop any qualifiers as
5105 .debug_names does not contain any. */
5107 if (strchr (name
, '(') != NULL
)
5109 without_params
= cp_remove_params (name
);
5110 if (without_params
!= NULL
)
5111 name
= without_params
.get ();
5115 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5117 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5119 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5120 (map
.bucket_table_reordered
5121 + (full_hash
% map
.bucket_count
)), 4,
5122 map
.dwarf5_byte_order
);
5126 if (namei
>= map
.name_count
)
5128 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5130 namei
, map
.name_count
,
5131 objfile_name (per_objfile
->objfile
));
5137 const uint32_t namei_full_hash
5138 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5139 (map
.hash_table_reordered
+ namei
), 4,
5140 map
.dwarf5_byte_order
);
5141 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5144 if (full_hash
== namei_full_hash
)
5146 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5148 #if 0 /* An expensive sanity check. */
5149 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5151 complaint (_("Wrong .debug_names hash for string at index %u "
5153 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5158 if (cmp (namei_string
, name
) == 0)
5160 const ULONGEST namei_entry_offs
5161 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5162 + namei
* map
.offset_size
),
5163 map
.offset_size
, map
.dwarf5_byte_order
);
5164 return map
.entry_pool
+ namei_entry_offs
;
5169 if (namei
>= map
.name_count
)
5175 dw2_debug_names_iterator::find_vec_in_debug_names
5176 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5178 if (namei
>= map
.name_count
)
5180 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5182 namei
, map
.name_count
,
5183 objfile_name (per_objfile
->objfile
));
5187 const ULONGEST namei_entry_offs
5188 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5189 + namei
* map
.offset_size
),
5190 map
.offset_size
, map
.dwarf5_byte_order
);
5191 return map
.entry_pool
+ namei_entry_offs
;
5194 /* See dw2_debug_names_iterator. */
5196 dwarf2_per_cu_data
*
5197 dw2_debug_names_iterator::next ()
5202 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5203 struct objfile
*objfile
= m_per_objfile
->objfile
;
5204 bfd
*const abfd
= objfile
->obfd
;
5208 unsigned int bytes_read
;
5209 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5210 m_addr
+= bytes_read
;
5214 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5215 if (indexval_it
== m_map
.abbrev_map
.cend ())
5217 complaint (_("Wrong .debug_names undefined abbrev code %s "
5219 pulongest (abbrev
), objfile_name (objfile
));
5222 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5223 enum class symbol_linkage
{
5227 } symbol_linkage_
= symbol_linkage::unknown
;
5228 dwarf2_per_cu_data
*per_cu
= NULL
;
5229 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5234 case DW_FORM_implicit_const
:
5235 ull
= attr
.implicit_const
;
5237 case DW_FORM_flag_present
:
5241 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5242 m_addr
+= bytes_read
;
5245 ull
= read_4_bytes (abfd
, m_addr
);
5249 ull
= read_8_bytes (abfd
, m_addr
);
5252 case DW_FORM_ref_sig8
:
5253 ull
= read_8_bytes (abfd
, m_addr
);
5257 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5258 dwarf_form_name (attr
.form
),
5259 objfile_name (objfile
));
5262 switch (attr
.dw_idx
)
5264 case DW_IDX_compile_unit
:
5265 /* Don't crash on bad data. */
5266 if (ull
>= per_bfd
->all_comp_units
.size ())
5268 complaint (_(".debug_names entry has bad CU index %s"
5271 objfile_name (objfile
));
5274 per_cu
= per_bfd
->get_cu (ull
);
5276 case DW_IDX_type_unit
:
5277 /* Don't crash on bad data. */
5278 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5280 complaint (_(".debug_names entry has bad TU index %s"
5283 objfile_name (objfile
));
5286 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5288 case DW_IDX_die_offset
:
5289 /* In a per-CU index (as opposed to a per-module index), index
5290 entries without CU attribute implicitly refer to the single CU. */
5292 per_cu
= per_bfd
->get_cu (0);
5294 case DW_IDX_GNU_internal
:
5295 if (!m_map
.augmentation_is_gdb
)
5297 symbol_linkage_
= symbol_linkage::static_
;
5299 case DW_IDX_GNU_external
:
5300 if (!m_map
.augmentation_is_gdb
)
5302 symbol_linkage_
= symbol_linkage::extern_
;
5307 /* Skip if already read in. */
5308 if (m_per_objfile
->symtab_set_p (per_cu
))
5311 /* Check static vs global. */
5312 if (symbol_linkage_
!= symbol_linkage::unknown
)
5314 if (symbol_linkage_
== symbol_linkage::static_
)
5316 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5321 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5326 /* Match dw2_symtab_iter_next, symbol_kind
5327 and debug_names::psymbol_tag. */
5331 switch (indexval
.dwarf_tag
)
5333 case DW_TAG_variable
:
5334 case DW_TAG_subprogram
:
5335 /* Some types are also in VAR_DOMAIN. */
5336 case DW_TAG_typedef
:
5337 case DW_TAG_structure_type
:
5344 switch (indexval
.dwarf_tag
)
5346 case DW_TAG_typedef
:
5347 case DW_TAG_structure_type
:
5354 switch (indexval
.dwarf_tag
)
5357 case DW_TAG_variable
:
5364 switch (indexval
.dwarf_tag
)
5376 /* Match dw2_expand_symtabs_matching, symbol_kind and
5377 debug_names::psymbol_tag. */
5380 case VARIABLES_DOMAIN
:
5381 switch (indexval
.dwarf_tag
)
5383 case DW_TAG_variable
:
5389 case FUNCTIONS_DOMAIN
:
5390 switch (indexval
.dwarf_tag
)
5392 case DW_TAG_subprogram
:
5399 switch (indexval
.dwarf_tag
)
5401 case DW_TAG_typedef
:
5402 case DW_TAG_structure_type
:
5408 case MODULES_DOMAIN
:
5409 switch (indexval
.dwarf_tag
)
5423 /* This dumps minimal information about .debug_names. It is called
5424 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5425 uses this to verify that .debug_names has been loaded. */
5428 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5430 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5432 gdb_assert (per_objfile
->per_bfd
->using_index
);
5433 gdb_printf (".debug_names:");
5434 if (per_objfile
->per_bfd
->debug_names_table
)
5435 gdb_printf (" exists\n");
5437 gdb_printf (" faked for \"readnow\"\n");
5442 dwarf2_debug_names_index::expand_matching_symbols
5443 (struct objfile
*objfile
,
5444 const lookup_name_info
&name
, domain_enum domain
,
5446 symbol_compare_ftype
*ordered_compare
)
5448 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5450 /* debug_names_table is NULL if OBJF_READNOW. */
5451 if (!per_objfile
->per_bfd
->debug_names_table
)
5454 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5455 const block_search_flags block_flags
5456 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5458 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5459 auto matcher
= [&] (const char *symname
)
5461 if (ordered_compare
== nullptr)
5463 return ordered_compare (symname
, match_name
) == 0;
5466 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5467 [&] (offset_type namei
)
5469 /* The name was matched, now expand corresponding CUs that were
5471 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5474 struct dwarf2_per_cu_data
*per_cu
;
5475 while ((per_cu
= iter
.next ()) != NULL
)
5476 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5483 dwarf2_debug_names_index::expand_symtabs_matching
5484 (struct objfile
*objfile
,
5485 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5486 const lookup_name_info
*lookup_name
,
5487 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5488 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5489 block_search_flags search_flags
,
5491 enum search_domain kind
)
5493 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5495 /* debug_names_table is NULL if OBJF_READNOW. */
5496 if (!per_objfile
->per_bfd
->debug_names_table
)
5499 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5501 /* This invariant is documented in quick-functions.h. */
5502 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
5503 if (lookup_name
== nullptr)
5505 for (dwarf2_per_cu_data
*per_cu
5506 : all_comp_units_range (per_objfile
->per_bfd
))
5510 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5518 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5521 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5523 [&] (offset_type namei
)
5525 /* The name was matched, now expand corresponding CUs that were
5527 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5529 struct dwarf2_per_cu_data
*per_cu
;
5530 while ((per_cu
= iter
.next ()) != NULL
)
5531 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5541 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5542 to either a dwarf2_per_bfd or dwz_file object. */
5544 template <typename T
>
5545 static gdb::array_view
<const gdb_byte
>
5546 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5548 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5550 if (section
->empty ())
5553 /* Older elfutils strip versions could keep the section in the main
5554 executable while splitting it for the separate debug info file. */
5555 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5558 section
->read (obj
);
5560 /* dwarf2_section_info::size is a bfd_size_type, while
5561 gdb::array_view works with size_t. On 32-bit hosts, with
5562 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5563 is 32-bit. So we need an explicit narrowing conversion here.
5564 This is fine, because it's impossible to allocate or mmap an
5565 array/buffer larger than what size_t can represent. */
5566 return gdb::make_array_view (section
->buffer
, section
->size
);
5569 /* Lookup the index cache for the contents of the index associated to
5572 static gdb::array_view
<const gdb_byte
>
5573 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5575 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5576 if (build_id
== nullptr)
5579 return global_index_cache
.lookup_gdb_index (build_id
,
5580 &dwarf2_per_bfd
->index_cache_res
);
5583 /* Same as the above, but for DWZ. */
5585 static gdb::array_view
<const gdb_byte
>
5586 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5588 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5589 if (build_id
== nullptr)
5592 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5595 static quick_symbol_functions_up
make_cooked_index_funcs ();
5597 /* See dwarf2/public.h. */
5600 dwarf2_initialize_objfile (struct objfile
*objfile
)
5602 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5603 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5605 dwarf_read_debug_printf ("called");
5607 /* If we're about to read full symbols, don't bother with the
5608 indices. In this case we also don't care if some other debug
5609 format is making psymtabs, because they are all about to be
5611 if ((objfile
->flags
& OBJF_READNOW
))
5613 dwarf_read_debug_printf ("readnow requested");
5615 /* When using READNOW, the using_index flag (set below) indicates that
5616 PER_BFD was already initialized, when we loaded some other objfile. */
5617 if (per_bfd
->using_index
)
5619 dwarf_read_debug_printf ("using_index already set");
5620 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5624 per_bfd
->using_index
= 1;
5625 create_all_comp_units (per_objfile
);
5626 per_bfd
->quick_file_names_table
5627 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5629 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5631 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5633 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5634 struct dwarf2_per_cu_quick_data
);
5637 /* Arrange for gdb to see the "quick" functions. However, these
5638 functions will be no-ops because we will have expanded all
5640 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5644 /* Was a debug names index already read when we processed an objfile sharing
5646 if (per_bfd
->debug_names_table
!= nullptr)
5648 dwarf_read_debug_printf ("re-using shared debug names table");
5649 objfile
->qf
.push_front (make_dwarf_debug_names ());
5653 /* Was a GDB index already read when we processed an objfile sharing
5655 if (per_bfd
->index_table
!= nullptr)
5657 dwarf_read_debug_printf ("re-using shared index table");
5658 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5662 if (per_bfd
->cooked_index_table
!= nullptr)
5664 dwarf_read_debug_printf ("re-using cooked index table");
5665 objfile
->qf
.push_front (make_cooked_index_funcs ());
5669 /* There might already be partial symtabs built for this BFD. This happens
5670 when loading the same binary twice with the index-cache enabled. If so,
5671 don't try to read an index. The objfile / per_objfile initialization will
5672 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5674 if (per_bfd
->partial_symtabs
!= nullptr)
5676 dwarf_read_debug_printf ("re-using shared partial symtabs");
5677 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5681 if (dwarf2_read_debug_names (per_objfile
))
5683 dwarf_read_debug_printf ("found debug names");
5684 objfile
->qf
.push_front (make_dwarf_debug_names ());
5688 if (dwarf2_read_gdb_index (per_objfile
,
5689 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5690 get_gdb_index_contents_from_section
<dwz_file
>))
5692 dwarf_read_debug_printf ("found gdb index from file");
5693 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5697 /* ... otherwise, try to find the index in the index cache. */
5698 if (dwarf2_read_gdb_index (per_objfile
,
5699 get_gdb_index_contents_from_cache
,
5700 get_gdb_index_contents_from_cache_dwz
))
5702 dwarf_read_debug_printf ("found gdb index from cache");
5703 global_index_cache
.hit ();
5704 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5708 global_index_cache
.miss ();
5709 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5714 /* Build a partial symbol table. */
5717 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5719 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5720 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5722 if (per_bfd
->partial_symtabs
!= nullptr)
5724 /* Partial symbols were already read, so now we can simply
5728 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5729 objfile
->qf
.emplace_front (psf
);
5732 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5738 psf
= new psymbol_functions
;
5739 objfile
->qf
.emplace_front (psf
);
5741 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5742 = psf
->get_partial_symtabs ();
5744 /* Set the local reference to partial symtabs, so that we don't try
5745 to read them again if reading another objfile with the same BFD.
5746 If we can't in fact share, this won't make a difference anyway as
5747 the dwarf2_per_bfd object won't be shared. */
5748 per_bfd
->partial_symtabs
= partial_symtabs
;
5752 /* This isn't really ideal: all the data we allocate on the
5753 objfile's obstack is still uselessly kept around. However,
5754 freeing it seems unsafe. */
5755 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5756 dwarf2_build_psymtabs_hard (per_objfile
);
5759 /* (maybe) store an index in the cache. */
5760 global_index_cache
.store (per_objfile
);
5762 catch (const gdb_exception_error
&except
)
5764 exception_print (gdb_stderr
, except
);
5768 /* Find the base address of the compilation unit for range lists and
5769 location lists. It will normally be specified by DW_AT_low_pc.
5770 In DWARF-3 draft 4, the base address could be overridden by
5771 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5772 compilation units with discontinuous ranges. */
5775 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5777 struct attribute
*attr
;
5779 cu
->base_address
.reset ();
5781 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5782 if (attr
!= nullptr)
5783 cu
->base_address
= attr
->as_address ();
5786 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5787 if (attr
!= nullptr)
5788 cu
->base_address
= attr
->as_address ();
5792 /* Helper function that returns the proper abbrev section for
5795 static struct dwarf2_section_info
*
5796 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5798 struct dwarf2_section_info
*abbrev
;
5799 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5801 if (this_cu
->is_dwz
)
5802 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5804 abbrev
= &per_bfd
->abbrev
;
5809 /* Fetch the abbreviation table offset from a comp or type unit header. */
5812 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5813 struct dwarf2_section_info
*section
,
5814 sect_offset sect_off
)
5816 bfd
*abfd
= section
->get_bfd_owner ();
5817 const gdb_byte
*info_ptr
;
5818 unsigned int initial_length_size
, offset_size
;
5821 section
->read (per_objfile
->objfile
);
5822 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5823 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5824 offset_size
= initial_length_size
== 4 ? 4 : 8;
5825 info_ptr
+= initial_length_size
;
5827 version
= read_2_bytes (abfd
, info_ptr
);
5831 /* Skip unit type and address size. */
5835 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5838 /* A partial symtab that is used only for include files. */
5839 struct dwarf2_include_psymtab
: public partial_symtab
5841 dwarf2_include_psymtab (const char *filename
,
5842 psymtab_storage
*partial_symtabs
,
5843 objfile_per_bfd_storage
*objfile_per_bfd
)
5844 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5848 void read_symtab (struct objfile
*objfile
) override
5850 /* It's an include file, no symbols to read for it.
5851 Everything is in the includer symtab. */
5853 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5854 expansion of the includer psymtab. We use the dependencies[0] field to
5855 model the includer. But if we go the regular route of calling
5856 expand_psymtab here, and having expand_psymtab call expand_dependencies
5857 to expand the includer, we'll only use expand_psymtab on the includer
5858 (making it a non-toplevel psymtab), while if we expand the includer via
5859 another path, we'll use read_symtab (making it a toplevel psymtab).
5860 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5861 psymtab, and trigger read_symtab on the includer here directly. */
5862 includer ()->read_symtab (objfile
);
5865 void expand_psymtab (struct objfile
*objfile
) override
5867 /* This is not called by read_symtab, and should not be called by any
5868 expand_dependencies. */
5872 bool readin_p (struct objfile
*objfile
) const override
5874 return includer ()->readin_p (objfile
);
5877 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5879 compunit_symtab
*cust
= includer ()->get_compunit_symtab (objfile
);
5880 while (cust
!= nullptr && cust
->user
!= nullptr)
5886 partial_symtab
*includer () const
5888 /* An include psymtab has exactly one dependency: the psymtab that
5890 gdb_assert (this->number_of_dependencies
== 1);
5891 return this->dependencies
[0];
5895 /* Allocate a new partial symtab for file named NAME and mark this new
5896 partial symtab as being an include of PST. */
5899 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5901 dwarf2_psymtab
*pst
,
5902 psymtab_storage
*partial_symtabs
,
5903 objfile_per_bfd_storage
*objfile_per_bfd
)
5905 dwarf2_include_psymtab
*subpst
5906 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5908 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5909 subpst
->dirname
= pst
->dirname
;
5911 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5912 subpst
->dependencies
[0] = pst
;
5913 subpst
->number_of_dependencies
= 1;
5916 /* Read the Line Number Program data and extract the list of files
5917 included by the source file represented by PST. Build an include
5918 partial symtab for each of these included files. */
5921 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5922 struct die_info
*die
,
5923 const file_and_directory
&fnd
,
5924 dwarf2_psymtab
*pst
)
5927 struct attribute
*attr
;
5929 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5930 if (attr
!= nullptr && attr
->form_is_unsigned ())
5931 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5933 return; /* No linetable, so no includes. */
5935 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5936 that we pass in the raw text_low here; that is ok because we're
5937 only decoding the line table to make include partial symtabs, and
5938 so the addresses aren't really used. */
5939 dwarf_decode_lines (lh
.get (), fnd
, cu
, pst
,
5940 pst
->raw_text_low (), 1);
5944 hash_signatured_type (const void *item
)
5946 const struct signatured_type
*sig_type
5947 = (const struct signatured_type
*) item
;
5949 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5950 return sig_type
->signature
;
5954 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5956 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5957 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5959 return lhs
->signature
== rhs
->signature
;
5962 /* Allocate a hash table for signatured types. */
5965 allocate_signatured_type_table ()
5967 return htab_up (htab_create_alloc (41,
5968 hash_signatured_type
,
5970 NULL
, xcalloc
, xfree
));
5973 /* A helper for create_debug_types_hash_table. Read types from SECTION
5974 and fill them into TYPES_HTAB. It will process only type units,
5975 therefore DW_UT_type. */
5978 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5979 struct dwo_file
*dwo_file
,
5980 dwarf2_section_info
*section
, htab_up
&types_htab
,
5981 rcuh_kind section_kind
)
5983 struct objfile
*objfile
= per_objfile
->objfile
;
5984 struct dwarf2_section_info
*abbrev_section
;
5986 const gdb_byte
*info_ptr
, *end_ptr
;
5988 abbrev_section
= &dwo_file
->sections
.abbrev
;
5990 dwarf_read_debug_printf ("Reading %s for %s",
5991 section
->get_name (),
5992 abbrev_section
->get_file_name ());
5994 section
->read (objfile
);
5995 info_ptr
= section
->buffer
;
5997 if (info_ptr
== NULL
)
6000 /* We can't set abfd until now because the section may be empty or
6001 not present, in which case the bfd is unknown. */
6002 abfd
= section
->get_bfd_owner ();
6004 /* We don't use cutu_reader here because we don't need to read
6005 any dies: the signature is in the header. */
6007 end_ptr
= info_ptr
+ section
->size
;
6008 while (info_ptr
< end_ptr
)
6010 signatured_type_up sig_type
;
6011 struct dwo_unit
*dwo_tu
;
6013 const gdb_byte
*ptr
= info_ptr
;
6014 struct comp_unit_head header
;
6015 unsigned int length
;
6017 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6019 /* Initialize it due to a false compiler warning. */
6020 header
.signature
= -1;
6021 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6023 /* We need to read the type's signature in order to build the hash
6024 table, but we don't need anything else just yet. */
6026 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6027 abbrev_section
, ptr
, section_kind
);
6029 length
= header
.get_length ();
6031 /* Skip dummy type units. */
6032 if (ptr
>= info_ptr
+ length
6033 || peek_abbrev_code (abfd
, ptr
) == 0
6034 || (header
.unit_type
!= DW_UT_type
6035 && header
.unit_type
!= DW_UT_split_type
))
6041 if (types_htab
== NULL
)
6042 types_htab
= allocate_dwo_unit_table ();
6044 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6045 dwo_tu
->dwo_file
= dwo_file
;
6046 dwo_tu
->signature
= header
.signature
;
6047 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6048 dwo_tu
->section
= section
;
6049 dwo_tu
->sect_off
= sect_off
;
6050 dwo_tu
->length
= length
;
6052 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
6053 gdb_assert (slot
!= NULL
);
6055 complaint (_("debug type entry at offset %s is duplicate to"
6056 " the entry at offset %s, signature %s"),
6057 sect_offset_str (sect_off
),
6058 sect_offset_str (dwo_tu
->sect_off
),
6059 hex_string (header
.signature
));
6062 dwarf_read_debug_printf_v (" offset %s, signature %s",
6063 sect_offset_str (sect_off
),
6064 hex_string (header
.signature
));
6070 /* Create the hash table of all entries in the .debug_types
6071 (or .debug_types.dwo) section(s).
6072 DWO_FILE is a pointer to the DWO file object.
6074 The result is a pointer to the hash table or NULL if there are no types.
6076 Note: This function processes DWO files only, not DWP files. */
6079 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6080 struct dwo_file
*dwo_file
,
6081 gdb::array_view
<dwarf2_section_info
> type_sections
,
6082 htab_up
&types_htab
)
6084 for (dwarf2_section_info
§ion
: type_sections
)
6085 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6089 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6090 If SLOT is non-NULL, it is the entry to use in the hash table.
6091 Otherwise we find one. */
6093 static struct signatured_type
*
6094 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6096 if (per_objfile
->per_bfd
->all_comp_units
.size ()
6097 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
6098 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6100 signatured_type_up sig_type_holder
6101 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
6102 signatured_type
*sig_type
= sig_type_holder
.get ();
6104 per_objfile
->per_bfd
->all_comp_units
.emplace_back
6105 (sig_type_holder
.release ());
6106 if (per_objfile
->per_bfd
->using_index
)
6109 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6110 struct dwarf2_per_cu_quick_data
);
6115 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6118 gdb_assert (*slot
== NULL
);
6120 /* The rest of sig_type must be filled in by the caller. */
6124 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6125 Fill in SIG_ENTRY with DWO_ENTRY. */
6128 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6129 struct signatured_type
*sig_entry
,
6130 struct dwo_unit
*dwo_entry
)
6132 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6134 /* Make sure we're not clobbering something we don't expect to. */
6135 gdb_assert (! sig_entry
->queued
);
6136 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
6137 if (per_bfd
->using_index
)
6139 gdb_assert (sig_entry
->v
.quick
!= NULL
);
6140 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
6143 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
6144 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6145 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0
6146 || (to_underlying (sig_entry
->type_offset_in_section
)
6147 == to_underlying (dwo_entry
->type_offset_in_tu
)));
6148 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6149 gdb_assert (sig_entry
->dwo_unit
== NULL
6150 || sig_entry
->dwo_unit
== dwo_entry
);
6152 sig_entry
->section
= dwo_entry
->section
;
6153 sig_entry
->sect_off
= dwo_entry
->sect_off
;
6154 sig_entry
->length
= dwo_entry
->length
;
6155 sig_entry
->reading_dwo_directly
= 1;
6156 sig_entry
->per_bfd
= per_bfd
;
6157 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6158 sig_entry
->dwo_unit
= dwo_entry
;
6161 /* Subroutine of lookup_signatured_type.
6162 If we haven't read the TU yet, create the signatured_type data structure
6163 for a TU to be read in directly from a DWO file, bypassing the stub.
6164 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6165 using .gdb_index, then when reading a CU we want to stay in the DWO file
6166 containing that CU. Otherwise we could end up reading several other DWO
6167 files (due to comdat folding) to process the transitive closure of all the
6168 mentioned TUs, and that can be slow. The current DWO file will have every
6169 type signature that it needs.
6170 We only do this for .gdb_index because in the psymtab case we already have
6171 to read all the DWOs to build the type unit groups. */
6173 static struct signatured_type
*
6174 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6176 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6177 struct dwo_file
*dwo_file
;
6178 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6181 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6183 /* If TU skeletons have been removed then we may not have read in any
6185 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6186 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6188 /* We only ever need to read in one copy of a signatured type.
6189 Use the global signatured_types array to do our own comdat-folding
6190 of types. If this is the first time we're reading this TU, and
6191 the TU has an entry in .gdb_index, replace the recorded data from
6192 .gdb_index with this TU. */
6194 signatured_type
find_sig_entry (sig
);
6195 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6196 &find_sig_entry
, INSERT
);
6197 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6199 /* We can get here with the TU already read, *or* in the process of being
6200 read. Don't reassign the global entry to point to this DWO if that's
6201 the case. Also note that if the TU is already being read, it may not
6202 have come from a DWO, the program may be a mix of Fission-compiled
6203 code and non-Fission-compiled code. */
6205 /* Have we already tried to read this TU?
6206 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6207 needn't exist in the global table yet). */
6208 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6211 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6212 dwo_unit of the TU itself. */
6213 dwo_file
= cu
->dwo_unit
->dwo_file
;
6215 /* Ok, this is the first time we're reading this TU. */
6216 if (dwo_file
->tus
== NULL
)
6218 find_dwo_entry
.signature
= sig
;
6219 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6221 if (dwo_entry
== NULL
)
6224 /* If the global table doesn't have an entry for this TU, add one. */
6225 if (sig_entry
== NULL
)
6226 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6228 if (sig_entry
->dwo_unit
== nullptr)
6229 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6230 sig_entry
->tu_read
= 1;
6234 /* Subroutine of lookup_signatured_type.
6235 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6236 then try the DWP file. If the TU stub (skeleton) has been removed then
6237 it won't be in .gdb_index. */
6239 static struct signatured_type
*
6240 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6242 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6243 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6244 struct dwo_unit
*dwo_entry
;
6247 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6248 gdb_assert (dwp_file
!= NULL
);
6250 /* If TU skeletons have been removed then we may not have read in any
6252 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6253 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6255 signatured_type
find_sig_entry (sig
);
6256 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6257 &find_sig_entry
, INSERT
);
6258 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6260 /* Have we already tried to read this TU?
6261 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6262 needn't exist in the global table yet). */
6263 if (sig_entry
!= NULL
)
6266 if (dwp_file
->tus
== NULL
)
6268 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6269 1 /* is_debug_types */);
6270 if (dwo_entry
== NULL
)
6273 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6274 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6279 /* Lookup a signature based type for DW_FORM_ref_sig8.
6280 Returns NULL if signature SIG is not present in the table.
6281 It is up to the caller to complain about this. */
6283 static struct signatured_type
*
6284 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6286 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6288 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6290 /* We're in a DWO/DWP file, and we're using .gdb_index.
6291 These cases require special processing. */
6292 if (get_dwp_file (per_objfile
) == NULL
)
6293 return lookup_dwo_signatured_type (cu
, sig
);
6295 return lookup_dwp_signatured_type (cu
, sig
);
6299 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6301 signatured_type
find_entry (sig
);
6302 return ((struct signatured_type
*)
6303 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6308 /* Low level DIE reading support. */
6310 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6313 init_cu_die_reader (struct die_reader_specs
*reader
,
6314 struct dwarf2_cu
*cu
,
6315 struct dwarf2_section_info
*section
,
6316 struct dwo_file
*dwo_file
,
6317 struct abbrev_table
*abbrev_table
)
6319 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6320 reader
->abfd
= section
->get_bfd_owner ();
6322 reader
->dwo_file
= dwo_file
;
6323 reader
->die_section
= section
;
6324 reader
->buffer
= section
->buffer
;
6325 reader
->buffer_end
= section
->buffer
+ section
->size
;
6326 reader
->abbrev_table
= abbrev_table
;
6329 /* Subroutine of cutu_reader to simplify it.
6330 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6331 There's just a lot of work to do, and cutu_reader is big enough
6334 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6335 from it to the DIE in the DWO. If NULL we are skipping the stub.
6336 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6337 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6338 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6339 STUB_COMP_DIR may be non-NULL.
6340 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6341 are filled in with the info of the DIE from the DWO file.
6342 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6343 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6344 kept around for at least as long as *RESULT_READER.
6346 The result is non-zero if a valid (non-dummy) DIE was found. */
6349 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6350 struct dwo_unit
*dwo_unit
,
6351 struct die_info
*stub_comp_unit_die
,
6352 const char *stub_comp_dir
,
6353 struct die_reader_specs
*result_reader
,
6354 const gdb_byte
**result_info_ptr
,
6355 struct die_info
**result_comp_unit_die
,
6356 abbrev_table_up
*result_dwo_abbrev_table
)
6358 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6359 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6360 struct objfile
*objfile
= per_objfile
->objfile
;
6362 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6363 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6364 int i
,num_extra_attrs
;
6365 struct dwarf2_section_info
*dwo_abbrev_section
;
6366 struct die_info
*comp_unit_die
;
6368 /* At most one of these may be provided. */
6369 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6371 /* These attributes aren't processed until later:
6372 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6373 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6374 referenced later. However, these attributes are found in the stub
6375 which we won't have later. In order to not impose this complication
6376 on the rest of the code, we read them here and copy them to the
6385 if (stub_comp_unit_die
!= NULL
)
6387 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6389 if (!per_cu
->is_debug_types
)
6390 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6391 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6392 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6393 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6394 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6396 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6398 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6399 We need the value before we can process DW_AT_ranges values from the
6401 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6403 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6404 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6405 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6406 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6408 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6410 else if (stub_comp_dir
!= NULL
)
6412 /* Reconstruct the comp_dir attribute to simplify the code below. */
6413 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6414 comp_dir
->name
= DW_AT_comp_dir
;
6415 comp_dir
->form
= DW_FORM_string
;
6416 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6419 /* Set up for reading the DWO CU/TU. */
6420 cu
->dwo_unit
= dwo_unit
;
6421 dwarf2_section_info
*section
= dwo_unit
->section
;
6422 section
->read (objfile
);
6423 abfd
= section
->get_bfd_owner ();
6424 begin_info_ptr
= info_ptr
= (section
->buffer
6425 + to_underlying (dwo_unit
->sect_off
));
6426 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6428 if (per_cu
->is_debug_types
)
6430 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6432 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6433 section
, dwo_abbrev_section
,
6434 info_ptr
, rcuh_kind::TYPE
);
6435 /* This is not an assert because it can be caused by bad debug info. */
6436 if (sig_type
->signature
!= cu
->header
.signature
)
6438 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6439 " TU at offset %s [in module %s]"),
6440 hex_string (sig_type
->signature
),
6441 hex_string (cu
->header
.signature
),
6442 sect_offset_str (dwo_unit
->sect_off
),
6443 bfd_get_filename (abfd
));
6445 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6446 /* For DWOs coming from DWP files, we don't know the CU length
6447 nor the type's offset in the TU until now. */
6448 dwo_unit
->length
= cu
->header
.get_length ();
6449 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6451 /* Establish the type offset that can be used to lookup the type.
6452 For DWO files, we don't know it until now. */
6453 sig_type
->type_offset_in_section
6454 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6458 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6459 section
, dwo_abbrev_section
,
6460 info_ptr
, rcuh_kind::COMPILE
);
6461 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6462 /* For DWOs coming from DWP files, we don't know the CU length
6464 dwo_unit
->length
= cu
->header
.get_length ();
6467 dwo_abbrev_section
->read (objfile
);
6468 *result_dwo_abbrev_table
6469 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6470 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6471 result_dwo_abbrev_table
->get ());
6473 /* Read in the die, but leave space to copy over the attributes
6474 from the stub. This has the benefit of simplifying the rest of
6475 the code - all the work to maintain the illusion of a single
6476 DW_TAG_{compile,type}_unit DIE is done here. */
6477 num_extra_attrs
= ((stmt_list
!= NULL
)
6481 + (comp_dir
!= NULL
));
6482 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6485 /* Copy over the attributes from the stub to the DIE we just read in. */
6486 comp_unit_die
= *result_comp_unit_die
;
6487 i
= comp_unit_die
->num_attrs
;
6488 if (stmt_list
!= NULL
)
6489 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6491 comp_unit_die
->attrs
[i
++] = *low_pc
;
6492 if (high_pc
!= NULL
)
6493 comp_unit_die
->attrs
[i
++] = *high_pc
;
6495 comp_unit_die
->attrs
[i
++] = *ranges
;
6496 if (comp_dir
!= NULL
)
6497 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6498 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6500 if (dwarf_die_debug
)
6502 gdb_printf (gdb_stdlog
,
6503 "Read die from %s@0x%x of %s:\n",
6504 section
->get_name (),
6505 (unsigned) (begin_info_ptr
- section
->buffer
),
6506 bfd_get_filename (abfd
));
6507 dump_die (comp_unit_die
, dwarf_die_debug
);
6510 /* Skip dummy compilation units. */
6511 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6512 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6515 *result_info_ptr
= info_ptr
;
6519 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6520 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6521 signature is part of the header. */
6522 static gdb::optional
<ULONGEST
>
6523 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6525 if (cu
->header
.version
>= 5)
6526 return cu
->header
.signature
;
6527 struct attribute
*attr
;
6528 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6529 if (attr
== nullptr || !attr
->form_is_unsigned ())
6530 return gdb::optional
<ULONGEST
> ();
6531 return attr
->as_unsigned ();
6534 /* Subroutine of cutu_reader to simplify it.
6535 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6536 Returns NULL if the specified DWO unit cannot be found. */
6538 static struct dwo_unit
*
6539 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6542 /* We need a lock here both to handle the DWO hash table, and BFD,
6543 which is not thread-safe. */
6544 static std::mutex dwo_lock
;
6546 std::lock_guard
<std::mutex
> guard (dwo_lock
);
6549 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6550 struct dwo_unit
*dwo_unit
;
6551 const char *comp_dir
;
6553 gdb_assert (cu
!= NULL
);
6555 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6556 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6557 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6559 if (per_cu
->is_debug_types
)
6560 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6563 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6565 if (!signature
.has_value ())
6566 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6568 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6570 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6576 /* Subroutine of cutu_reader to simplify it.
6577 See it for a description of the parameters.
6578 Read a TU directly from a DWO file, bypassing the stub. */
6581 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6582 dwarf2_per_objfile
*per_objfile
,
6583 dwarf2_cu
*existing_cu
)
6585 struct signatured_type
*sig_type
;
6587 /* Verify we can do the following downcast, and that we have the
6589 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6590 sig_type
= (struct signatured_type
*) this_cu
;
6591 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6595 if (existing_cu
!= nullptr)
6598 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6599 /* There's no need to do the rereading_dwo_cu handling that
6600 cutu_reader does since we don't read the stub. */
6604 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6605 in per_objfile yet. */
6606 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6607 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6608 cu
= m_new_cu
.get ();
6611 /* A future optimization, if needed, would be to use an existing
6612 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6613 could share abbrev tables. */
6615 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6616 NULL
/* stub_comp_unit_die */,
6617 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6620 &m_dwo_abbrev_table
) == 0)
6627 /* Initialize a CU (or TU) and read its DIEs.
6628 If the CU defers to a DWO file, read the DWO file as well.
6630 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6631 Otherwise the table specified in the comp unit header is read in and used.
6632 This is an optimization for when we already have the abbrev table.
6634 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6637 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6638 dwarf2_per_objfile
*per_objfile
,
6639 struct abbrev_table
*abbrev_table
,
6640 dwarf2_cu
*existing_cu
,
6642 abbrev_cache
*cache
)
6643 : die_reader_specs
{},
6646 struct objfile
*objfile
= per_objfile
->objfile
;
6647 struct dwarf2_section_info
*section
= this_cu
->section
;
6648 bfd
*abfd
= section
->get_bfd_owner ();
6649 const gdb_byte
*begin_info_ptr
;
6650 struct signatured_type
*sig_type
= NULL
;
6651 struct dwarf2_section_info
*abbrev_section
;
6652 /* Non-zero if CU currently points to a DWO file and we need to
6653 reread it. When this happens we need to reread the skeleton die
6654 before we can reread the DWO file (this only applies to CUs, not TUs). */
6655 int rereading_dwo_cu
= 0;
6657 if (dwarf_die_debug
)
6658 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
6659 this_cu
->is_debug_types
? "type" : "comp",
6660 sect_offset_str (this_cu
->sect_off
));
6662 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6663 file (instead of going through the stub), short-circuit all of this. */
6664 if (this_cu
->reading_dwo_directly
)
6666 /* Narrow down the scope of possibilities to have to understand. */
6667 gdb_assert (this_cu
->is_debug_types
);
6668 gdb_assert (abbrev_table
== NULL
);
6669 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6673 /* This is cheap if the section is already read in. */
6674 section
->read (objfile
);
6676 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6678 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6682 if (existing_cu
!= nullptr)
6685 /* If this CU is from a DWO file we need to start over, we need to
6686 refetch the attributes from the skeleton CU.
6687 This could be optimized by retrieving those attributes from when we
6688 were here the first time: the previous comp_unit_die was stored in
6689 comp_unit_obstack. But there's no data yet that we need this
6691 if (cu
->dwo_unit
!= NULL
)
6692 rereading_dwo_cu
= 1;
6696 /* If an existing_cu is provided, a dwarf2_cu must not exist for
6697 this_cu in per_objfile yet. Here, CACHE doubles as a flag to
6698 let us know that the CU is being scanned using the parallel
6699 indexer. This assert is avoided in this case because (1) it
6700 is irrelevant, and (2) the get_cu method is not
6702 gdb_assert (cache
!= nullptr
6703 || per_objfile
->get_cu (this_cu
) == nullptr);
6704 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6705 cu
= m_new_cu
.get ();
6708 /* Get the header. */
6709 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6711 /* We already have the header, there's no need to read it in again. */
6712 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6716 if (this_cu
->is_debug_types
)
6718 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6719 section
, abbrev_section
,
6720 info_ptr
, rcuh_kind::TYPE
);
6722 /* Since per_cu is the first member of struct signatured_type,
6723 we can go from a pointer to one to a pointer to the other. */
6724 sig_type
= (struct signatured_type
*) this_cu
;
6725 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6726 gdb_assert (sig_type
->type_offset_in_tu
6727 == cu
->header
.type_cu_offset_in_tu
);
6728 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6730 /* LENGTH has not been set yet for type units if we're
6731 using .gdb_index. */
6732 this_cu
->length
= cu
->header
.get_length ();
6734 /* Establish the type offset that can be used to lookup the type. */
6735 sig_type
->type_offset_in_section
=
6736 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6738 this_cu
->dwarf_version
= cu
->header
.version
;
6742 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6743 section
, abbrev_section
,
6745 rcuh_kind::COMPILE
);
6747 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6748 if (this_cu
->length
== 0)
6749 this_cu
->length
= cu
->header
.get_length ();
6751 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6752 this_cu
->dwarf_version
= cu
->header
.version
;
6756 /* Skip dummy compilation units. */
6757 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6758 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6764 /* If we don't have them yet, read the abbrevs for this compilation unit.
6765 And if we need to read them now, make sure they're freed when we're
6767 if (abbrev_table
!= NULL
)
6768 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6771 if (cache
!= nullptr)
6772 abbrev_table
= cache
->find (abbrev_section
,
6773 cu
->header
.abbrev_sect_off
);
6774 if (abbrev_table
== nullptr)
6776 abbrev_section
->read (objfile
);
6777 m_abbrev_table_holder
6778 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6779 abbrev_table
= m_abbrev_table_holder
.get ();
6783 /* Read the top level CU/TU die. */
6784 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6785 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6787 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6793 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6794 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6795 table from the DWO file and pass the ownership over to us. It will be
6796 referenced from READER, so we must make sure to free it after we're done
6799 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6800 DWO CU, that this test will fail (the attribute will not be present). */
6801 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6802 if (dwo_name
!= nullptr)
6804 struct dwo_unit
*dwo_unit
;
6805 struct die_info
*dwo_comp_unit_die
;
6807 if (comp_unit_die
->has_children
)
6809 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6810 " has children (offset %s) [in module %s]"),
6811 sect_offset_str (this_cu
->sect_off
),
6812 bfd_get_filename (abfd
));
6814 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6815 if (dwo_unit
!= NULL
)
6817 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6818 comp_unit_die
, NULL
,
6821 &m_dwo_abbrev_table
) == 0)
6827 comp_unit_die
= dwo_comp_unit_die
;
6831 /* Yikes, we couldn't find the rest of the DIE, we only have
6832 the stub. A complaint has already been logged. There's
6833 not much more we can do except pass on the stub DIE to
6834 die_reader_func. We don't want to throw an error on bad
6841 cutu_reader::keep ()
6843 /* Done, clean up. */
6844 gdb_assert (!dummy_p
);
6845 if (m_new_cu
!= NULL
)
6847 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6849 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6850 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6854 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6855 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6856 assumed to have already done the lookup to find the DWO file).
6858 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6859 THIS_CU->is_debug_types, but nothing else.
6861 We fill in THIS_CU->length.
6863 THIS_CU->cu is always freed when done.
6864 This is done in order to not leave THIS_CU->cu in a state where we have
6865 to care whether it refers to the "main" CU or the DWO CU.
6867 When parent_cu is passed, it is used to provide a default value for
6868 str_offsets_base and addr_base from the parent. */
6870 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6871 dwarf2_per_objfile
*per_objfile
,
6872 struct dwarf2_cu
*parent_cu
,
6873 struct dwo_file
*dwo_file
)
6874 : die_reader_specs
{},
6877 struct objfile
*objfile
= per_objfile
->objfile
;
6878 struct dwarf2_section_info
*section
= this_cu
->section
;
6879 bfd
*abfd
= section
->get_bfd_owner ();
6880 struct dwarf2_section_info
*abbrev_section
;
6881 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6883 if (dwarf_die_debug
)
6884 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
6885 this_cu
->is_debug_types
? "type" : "comp",
6886 sect_offset_str (this_cu
->sect_off
));
6888 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6890 abbrev_section
= (dwo_file
!= NULL
6891 ? &dwo_file
->sections
.abbrev
6892 : get_abbrev_section_for_cu (this_cu
));
6894 /* This is cheap if the section is already read in. */
6895 section
->read (objfile
);
6897 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6899 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6900 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6901 section
, abbrev_section
, info_ptr
,
6902 (this_cu
->is_debug_types
6904 : rcuh_kind::COMPILE
));
6906 if (parent_cu
!= nullptr)
6908 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6909 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6911 this_cu
->length
= m_new_cu
->header
.get_length ();
6913 /* Skip dummy compilation units. */
6914 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6915 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6921 abbrev_section
->read (objfile
);
6922 m_abbrev_table_holder
6923 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6925 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6926 m_abbrev_table_holder
.get ());
6927 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6931 /* Type Unit Groups.
6933 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6934 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6935 so that all types coming from the same compilation (.o file) are grouped
6936 together. A future step could be to put the types in the same symtab as
6937 the CU the types ultimately came from. */
6940 hash_type_unit_group (const void *item
)
6942 const struct type_unit_group
*tu_group
6943 = (const struct type_unit_group
*) item
;
6945 return hash_stmt_list_entry (&tu_group
->hash
);
6949 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6951 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6952 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6954 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6957 /* Allocate a hash table for type unit groups. */
6960 allocate_type_unit_groups_table ()
6962 return htab_up (htab_create_alloc (3,
6963 hash_type_unit_group
,
6965 htab_delete_entry
<type_unit_group
>,
6969 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6970 partial symtabs. We combine several TUs per psymtab to not let the size
6971 of any one psymtab grow too big. */
6972 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6973 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6975 /* Helper routine for get_type_unit_group.
6976 Create the type_unit_group object used to hold one or more TUs. */
6978 static std::unique_ptr
<type_unit_group
>
6979 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6981 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6982 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6984 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6985 tu_group
->per_bfd
= per_bfd
;
6987 if (per_bfd
->using_index
)
6989 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6990 struct dwarf2_per_cu_quick_data
);
6994 unsigned int line_offset
= to_underlying (line_offset_struct
);
6995 dwarf2_psymtab
*pst
;
6998 /* Give the symtab a useful name for debug purposes. */
6999 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7000 name
= string_printf ("<type_units_%d>",
7001 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7003 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7005 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
7007 pst
->anonymous
= true;
7010 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7011 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7016 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7017 STMT_LIST is a DW_AT_stmt_list attribute. */
7019 static struct type_unit_group
*
7020 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7022 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7023 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7024 struct type_unit_group
*tu_group
;
7026 unsigned int line_offset
;
7027 struct type_unit_group type_unit_group_for_lookup
;
7029 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7030 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7032 /* Do we need to create a new group, or can we use an existing one? */
7034 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7036 line_offset
= stmt_list
->as_unsigned ();
7037 ++tu_stats
->nr_symtab_sharers
;
7041 /* Ugh, no stmt_list. Rare, but we have to handle it.
7042 We can do various things here like create one group per TU or
7043 spread them over multiple groups to split up the expansion work.
7044 To avoid worst case scenarios (too many groups or too large groups)
7045 we, umm, group them in bunches. */
7046 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7047 | (tu_stats
->nr_stmt_less_type_units
7048 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7049 ++tu_stats
->nr_stmt_less_type_units
;
7052 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7053 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7054 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7055 &type_unit_group_for_lookup
, INSERT
);
7056 if (*slot
== nullptr)
7058 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7059 std::unique_ptr
<type_unit_group
> grp
7060 = create_type_unit_group (cu
, line_offset_struct
);
7061 *slot
= grp
.release ();
7062 ++tu_stats
->nr_symtabs
;
7065 tu_group
= (struct type_unit_group
*) *slot
;
7066 gdb_assert (tu_group
!= nullptr);
7070 /* Partial symbol tables. */
7072 /* Create a psymtab named NAME and assign it to PER_CU.
7074 The caller must fill in the following details:
7075 dirname, textlow, texthigh. */
7077 static dwarf2_psymtab
*
7078 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7079 dwarf2_per_objfile
*per_objfile
,
7083 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
7084 per_objfile
->objfile
->per_bfd
, per_cu
);
7086 pst
->psymtabs_addrmap_supported
= true;
7088 /* This is the glue that links PST into GDB's symbol API. */
7089 per_cu
->v
.psymtab
= pst
;
7095 /* An instance of this is created when scanning DWARF to create a
7098 class cooked_index_storage
7102 cooked_index_storage ()
7103 : m_reader_hash (htab_create_alloc (10, hash_cutu_reader
,
7105 htab_delete_entry
<cutu_reader
>,
7107 m_index (new cooked_index
),
7108 m_addrmap_storage (),
7109 m_addrmap (addrmap_create_mutable (&m_addrmap_storage
))
7113 DISABLE_COPY_AND_ASSIGN (cooked_index_storage
);
7115 /* Return the current abbrev cache. */
7116 abbrev_cache
*get_abbrev_cache ()
7118 return &m_abbrev_cache
;
7121 /* Return the DIE reader corresponding to PER_CU. If no such reader
7122 has been registered, return NULL. */
7123 cutu_reader
*get_reader (dwarf2_per_cu_data
*per_cu
)
7125 int index
= per_cu
->index
;
7126 return (cutu_reader
*) htab_find_with_hash (m_reader_hash
.get (),
7130 /* Preserve READER by storing it in the local hash table. */
7131 cutu_reader
*preserve (std::unique_ptr
<cutu_reader
> reader
)
7133 m_abbrev_cache
.add (reader
->release_abbrev_table ());
7135 int index
= reader
->cu
->per_cu
->index
;
7136 void **slot
= htab_find_slot_with_hash (m_reader_hash
.get (), &index
,
7138 gdb_assert (*slot
== nullptr);
7139 cutu_reader
*result
= reader
.get ();
7140 *slot
= reader
.release ();
7144 /* Add an entry to the index. The arguments describe the entry; see
7145 cooked-index.h. The new entry is returned. */
7146 const cooked_index_entry
*add (sect_offset die_offset
, enum dwarf_tag tag
,
7147 cooked_index_flag flags
,
7149 const cooked_index_entry
*parent_entry
,
7150 dwarf2_per_cu_data
*per_cu
)
7152 return m_index
->add (die_offset
, tag
, flags
, name
, parent_entry
, per_cu
);
7155 /* Install the current addrmap into the index being constructed,
7156 then transfer ownership of the index to the caller. */
7157 std::unique_ptr
<cooked_index
> release ()
7159 m_index
->install_addrmap (m_addrmap
);
7160 return std::move (m_index
);
7163 /* Return the mutable addrmap that is currently being created. */
7164 addrmap
*get_addrmap ()
7171 /* Hash function for a cutu_reader. */
7172 static hashval_t
hash_cutu_reader (const void *a
)
7174 const cutu_reader
*reader
= (const cutu_reader
*) a
;
7175 return reader
->cu
->per_cu
->index
;
7178 /* Equality function for cutu_reader. */
7179 static int eq_cutu_reader (const void *a
, const void *b
)
7181 const cutu_reader
*ra
= (const cutu_reader
*) a
;
7182 const int *rb
= (const int *) b
;
7183 return ra
->cu
->per_cu
->index
== *rb
;
7186 /* The abbrev cache used by this indexer. */
7187 abbrev_cache m_abbrev_cache
;
7188 /* A hash table of cutu_reader objects. */
7189 htab_up m_reader_hash
;
7190 /* The index that is being constructed. */
7191 std::unique_ptr
<cooked_index
> m_index
;
7193 /* Storage for the writeable addrmap. */
7194 auto_obstack m_addrmap_storage
;
7195 /* A writeable addrmap being constructed by this scanner. */
7199 /* An instance of this is created to index a CU. */
7201 class cooked_indexer
7205 cooked_indexer (cooked_index_storage
*storage
,
7206 dwarf2_per_cu_data
*per_cu
,
7207 enum language language
)
7208 : m_index_storage (storage
),
7210 m_language (language
),
7212 m_die_range_map (addrmap_create_mutable (&m_obstack
))
7216 DISABLE_COPY_AND_ASSIGN (cooked_indexer
);
7218 /* Index the given CU. */
7219 void make_index (cutu_reader
*reader
);
7223 /* A helper function to turn a section offset into an address that
7224 can be used in an addrmap. */
7225 CORE_ADDR
form_addr (sect_offset offset
, bool is_dwz
)
7227 CORE_ADDR value
= to_underlying (offset
);
7229 value
|= ((CORE_ADDR
) 1) << (8 * sizeof (CORE_ADDR
) - 1);
7233 /* A helper function to scan the PC bounds of READER and record them
7234 in the storage's addrmap. */
7235 void check_bounds (cutu_reader
*reader
);
7237 /* Ensure that the indicated CU exists. The cutu_reader for it is
7238 returned. FOR_SCANNING is true if the caller intends to scan all
7239 the DIEs in the CU; when false, this use is assumed to be to look
7240 up just a single DIE. */
7241 cutu_reader
*ensure_cu_exists (cutu_reader
*reader
,
7242 dwarf2_per_objfile
*per_objfile
,
7243 sect_offset sect_off
,
7247 /* Index DIEs in the READER starting at INFO_PTR. PARENT_ENTRY is
7248 the entry for the enclosing scope (nullptr at top level). FULLY
7249 is true when a full scan must be done -- in some languages,
7250 function scopes must be fully explored in order to find nested
7251 functions. This returns a pointer to just after the spot where
7253 const gdb_byte
*index_dies (cutu_reader
*reader
,
7254 const gdb_byte
*info_ptr
,
7255 const cooked_index_entry
*parent_entry
,
7258 /* Scan the attributes for a given DIE and update the out
7259 parameters. Returns a pointer to the byte after the DIE. */
7260 const gdb_byte
*scan_attributes (dwarf2_per_cu_data
*scanning_per_cu
,
7261 cutu_reader
*reader
,
7262 const gdb_byte
*watermark_ptr
,
7263 const gdb_byte
*info_ptr
,
7264 const abbrev_info
*abbrev
,
7266 const char **linkage_name
,
7267 cooked_index_flag
*flags
,
7268 sect_offset
*sibling_offset
,
7269 const cooked_index_entry
**parent_entry
,
7270 CORE_ADDR
*maybe_defer
,
7271 bool for_specification
);
7273 /* Handle DW_TAG_imported_unit, by scanning the DIE to find
7274 DW_AT_import, and then scanning the referenced CU. Returns a
7275 pointer to the byte after the DIE. */
7276 const gdb_byte
*index_imported_unit (cutu_reader
*reader
,
7277 const gdb_byte
*info_ptr
,
7278 const abbrev_info
*abbrev
);
7280 /* Recursively read DIEs, recording the section offsets in
7281 m_die_range_map and then calling index_dies. */
7282 const gdb_byte
*recurse (cutu_reader
*reader
,
7283 const gdb_byte
*info_ptr
,
7284 const cooked_index_entry
*parent_entry
,
7287 /* The storage object, where the results are kept. */
7288 cooked_index_storage
*m_index_storage
;
7289 /* The CU that we are reading on behalf of. This object might be
7290 asked to index one CU but to treat the results as if they come
7291 from some including CU; in this case the including CU would be
7293 dwarf2_per_cu_data
*m_per_cu
;
7294 /* The language that we're assuming when reading. */
7295 enum language m_language
;
7297 /* Temporary storage. */
7298 auto_obstack m_obstack
;
7299 /* An addrmap that maps from section offsets (see the form_addr
7300 method) to newly-created entries. See m_deferred_entries to
7302 addrmap
*m_die_range_map
;
7304 /* A single deferred entry. */
7305 struct deferred_entry
7307 sect_offset die_offset
;
7309 CORE_ADDR spec_offset
;
7311 cooked_index_flag flags
;
7314 /* The generated DWARF can sometimes have the declaration for a
7315 method in a class (or perhaps namespace) scope, with the
7316 definition appearing outside this scope... just one of the many
7317 bad things about DWARF. In order to handle this situation, we
7318 defer certain entries until the end of scanning, at which point
7319 we'll know the containing context of all the DIEs that we might
7320 have scanned. This vector stores these deferred entries. */
7321 std::vector
<deferred_entry
> m_deferred_entries
;
7326 /* DIE reader function for process_psymtab_comp_unit. */
7329 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7330 const gdb_byte
*info_ptr
,
7331 struct die_info
*comp_unit_die
,
7332 enum language pretend_language
)
7334 struct dwarf2_cu
*cu
= reader
->cu
;
7335 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7336 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7337 struct objfile
*objfile
= per_objfile
->objfile
;
7338 struct gdbarch
*gdbarch
= objfile
->arch ();
7339 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7341 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7342 dwarf2_psymtab
*pst
;
7343 enum pc_bounds_kind cu_bounds_kind
;
7345 gdb_assert (! per_cu
->is_debug_types
);
7347 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7349 /* Allocate a new partial symbol table structure. */
7350 static const char artificial
[] = "<artificial>";
7351 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
7352 if (strcmp (fnd
.get_name (), artificial
) == 0)
7354 gdb::unique_xmalloc_ptr
<char> debug_filename
7355 (concat (artificial
, "@",
7356 sect_offset_str (per_cu
->sect_off
),
7358 fnd
.set_name (std::move (debug_filename
));
7361 pst
= create_partial_symtab (per_cu
, per_objfile
, fnd
.get_name ());
7363 /* This must be done before calling dwarf2_build_include_psymtabs. */
7364 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7366 baseaddr
= objfile
->text_section_offset ();
7368 dwarf2_find_base_address (comp_unit_die
, cu
);
7370 /* Possibly set the default values of LOWPC and HIGHPC from
7373 = dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7375 per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7377 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7380 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7383 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7385 /* Store the contiguous range if it is not empty; it can be
7386 empty for CUs with no code. */
7387 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7391 /* Check if comp unit has_children.
7392 If so, read the rest of the partial symbols from this comp unit.
7393 If not, there's no more debug_info for this comp unit. */
7394 if (comp_unit_die
->has_children
)
7396 struct partial_die_info
*first_die
;
7397 CORE_ADDR lowpc
, highpc
;
7399 lowpc
= ((CORE_ADDR
) -1);
7400 highpc
= ((CORE_ADDR
) 0);
7402 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7404 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7405 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7407 /* If we didn't find a lowpc, set it to highpc to avoid
7408 complaints from `maint check'. */
7409 if (lowpc
== ((CORE_ADDR
) -1))
7412 /* If the compilation unit didn't have an explicit address range,
7413 then use the information extracted from its child dies. */
7414 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7417 best_highpc
= highpc
;
7420 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7421 best_lowpc
+ baseaddr
)
7423 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7424 best_highpc
+ baseaddr
)
7429 if (!cu
->per_cu
->imported_symtabs_empty ())
7432 int len
= cu
->per_cu
->imported_symtabs_size ();
7434 /* Fill in 'dependencies' here; we fill in 'users' in a
7436 pst
->number_of_dependencies
= len
;
7438 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7439 for (i
= 0; i
< len
; ++i
)
7441 pst
->dependencies
[i
]
7442 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7445 cu
->per_cu
->imported_symtabs_free ();
7448 /* Get the list of files included in the current compilation unit,
7449 and build a psymtab for each of them. */
7450 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, fnd
, pst
);
7452 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7453 ", %d global, %d static syms",
7454 per_cu
->is_debug_types
? "type" : "comp",
7455 sect_offset_str (per_cu
->sect_off
),
7456 paddress (gdbarch
, pst
->text_low (objfile
)),
7457 paddress (gdbarch
, pst
->text_high (objfile
)),
7458 (int) pst
->global_psymbols
.size (),
7459 (int) pst
->static_psymbols
.size ());
7462 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7463 Process compilation unit THIS_CU for a psymtab. */
7466 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7467 dwarf2_per_objfile
*per_objfile
,
7468 bool want_partial_unit
,
7469 enum language pretend_language
,
7470 cooked_index_storage
*storage
)
7472 /* If this compilation unit was already read in, free the
7473 cached copy in order to read it in again. This is
7474 necessary because we skipped some symbols when we first
7475 read in the compilation unit (see load_partial_dies).
7476 This problem could be avoided, but the benefit is unclear. */
7477 if (!per_objfile
->per_bfd
->using_index
)
7478 per_objfile
->remove_cu (this_cu
);
7480 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false,
7483 : storage
->get_abbrev_cache ()));
7485 if (reader
.comp_unit_die
== nullptr)
7488 switch (reader
.comp_unit_die
->tag
)
7490 case DW_TAG_compile_unit
:
7491 this_cu
->unit_type
= DW_UT_compile
;
7493 case DW_TAG_partial_unit
:
7494 this_cu
->unit_type
= DW_UT_partial
;
7496 case DW_TAG_type_unit
:
7497 this_cu
->unit_type
= DW_UT_type
;
7500 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7501 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7502 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7503 objfile_name (per_objfile
->objfile
));
7510 else if (this_cu
->is_debug_types
)
7511 build_type_psymtabs_reader (&reader
, storage
);
7512 else if (want_partial_unit
7513 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7515 if (per_objfile
->per_bfd
->using_index
)
7518 if (this_cu
->scanned
.compare_exchange_strong (nope
, true))
7520 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7522 gdb_assert (storage
!= nullptr);
7523 cooked_indexer
indexer (storage
, this_cu
,
7524 reader
.cu
->per_cu
->lang
);
7525 indexer
.make_index (&reader
);
7529 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7530 reader
.comp_unit_die
,
7534 /* Age out any secondary CUs. */
7535 per_objfile
->age_comp_units ();
7538 /* Reader function for build_type_psymtabs. */
7541 build_type_psymtabs_reader (cutu_reader
*reader
,
7542 cooked_index_storage
*storage
)
7544 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7545 struct dwarf2_cu
*cu
= reader
->cu
;
7546 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7547 struct signatured_type
*sig_type
;
7548 struct type_unit_group
*tu_group
;
7549 struct attribute
*attr
;
7550 struct partial_die_info
*first_die
;
7551 CORE_ADDR lowpc
, highpc
;
7552 dwarf2_psymtab
*pst
;
7553 const gdb_byte
*info_ptr
= reader
->info_ptr
;
7554 struct die_info
*type_unit_die
= reader
->comp_unit_die
;
7556 gdb_assert (per_cu
->is_debug_types
);
7557 sig_type
= (struct signatured_type
*) per_cu
;
7559 if (! type_unit_die
->has_children
)
7562 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7563 tu_group
= get_type_unit_group (cu
, attr
);
7565 if (tu_group
->tus
== nullptr)
7566 tu_group
->tus
= new std::vector
<signatured_type
*>;
7567 tu_group
->tus
->push_back (sig_type
);
7569 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7571 if (per_objfile
->per_bfd
->using_index
)
7573 gdb_assert (storage
!= nullptr);
7574 cooked_indexer
indexer (storage
, per_cu
, cu
->per_cu
->lang
);
7575 indexer
.make_index (reader
);
7579 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7580 pst
->anonymous
= true;
7582 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7584 lowpc
= (CORE_ADDR
) -1;
7585 highpc
= (CORE_ADDR
) 0;
7586 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7592 /* Struct used to sort TUs by their abbreviation table offset. */
7594 struct tu_abbrev_offset
7596 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7597 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7600 /* This is used when sorting. */
7601 bool operator< (const tu_abbrev_offset
&other
) const
7603 return abbrev_offset
< other
.abbrev_offset
;
7606 signatured_type
*sig_type
;
7607 sect_offset abbrev_offset
;
7610 /* Efficiently read all the type units.
7612 The efficiency is because we sort TUs by the abbrev table they use and
7613 only read each abbrev table once. In one program there are 200K TUs
7614 sharing 8K abbrev tables.
7616 The main purpose of this function is to support building the
7617 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7618 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7619 can collapse the search space by grouping them by stmt_list.
7620 The savings can be significant, in the same program from above the 200K TUs
7621 share 8K stmt_list tables.
7623 FUNC is expected to call get_type_unit_group, which will create the
7624 struct type_unit_group if necessary and add it to
7625 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7628 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
,
7629 cooked_index_storage
*storage
)
7631 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7632 abbrev_table_up abbrev_table
;
7633 sect_offset abbrev_offset
;
7635 /* It's up to the caller to not call us multiple times. */
7636 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7638 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7641 /* TUs typically share abbrev tables, and there can be way more TUs than
7642 abbrev tables. Sort by abbrev table to reduce the number of times we
7643 read each abbrev table in.
7644 Alternatives are to punt or to maintain a cache of abbrev tables.
7645 This is simpler and efficient enough for now.
7647 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7648 symtab to use). Typically TUs with the same abbrev offset have the same
7649 stmt_list value too so in practice this should work well.
7651 The basic algorithm here is:
7653 sort TUs by abbrev table
7654 for each TU with same abbrev table:
7655 read abbrev table if first user
7656 read TU top level DIE
7657 [IWBN if DWO skeletons had DW_AT_stmt_list]
7660 dwarf_read_debug_printf ("Building type unit groups ...");
7662 /* Sort in a separate table to maintain the order of all_comp_units
7663 for .gdb_index: TU indices directly index all_type_units. */
7664 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7665 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7667 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7669 if (cu
->is_debug_types
)
7671 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7672 sorted_by_abbrev
.emplace_back
7673 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7674 sig_type
->sect_off
));
7678 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7680 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7682 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7684 /* Switch to the next abbrev table if necessary. */
7685 if (abbrev_table
== NULL
7686 || tu
.abbrev_offset
!= abbrev_offset
)
7688 abbrev_offset
= tu
.abbrev_offset
;
7689 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7691 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7692 ++tu_stats
->nr_uniq_abbrev_tables
;
7695 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7696 abbrev_table
.get (), nullptr, false);
7697 if (!reader
.dummy_p
)
7698 build_type_psymtabs_reader (&reader
, storage
);
7702 /* Print collected type unit statistics. */
7705 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7707 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7709 dwarf_read_debug_printf ("Type unit statistics:");
7710 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7711 dwarf_read_debug_printf (" %d uniq abbrev tables",
7712 tu_stats
->nr_uniq_abbrev_tables
);
7713 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7714 tu_stats
->nr_symtabs
);
7715 dwarf_read_debug_printf (" %d symtab sharers",
7716 tu_stats
->nr_symtab_sharers
);
7717 dwarf_read_debug_printf (" %d type units without a stmt_list",
7718 tu_stats
->nr_stmt_less_type_units
);
7719 dwarf_read_debug_printf (" %d all_type_units reallocs",
7720 tu_stats
->nr_all_type_units_reallocs
);
7723 /* Traversal function for build_type_psymtabs. */
7726 build_type_psymtab_dependencies (void **slot
, void *info
)
7728 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7729 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7730 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7731 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7732 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7735 gdb_assert (len
> 0);
7736 gdb_assert (tu_group
->type_unit_group_p ());
7738 pst
->number_of_dependencies
= len
;
7739 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7740 for (i
= 0; i
< len
; ++i
)
7742 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7743 gdb_assert (iter
->is_debug_types
);
7744 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7745 iter
->type_unit_group
= tu_group
;
7748 delete tu_group
->tus
;
7749 tu_group
->tus
= nullptr;
7754 struct skeleton_data
7756 dwarf2_per_objfile
*per_objfile
;
7757 cooked_index_storage
*storage
;
7760 /* Traversal function for process_skeletonless_type_unit.
7761 Read a TU in a DWO file and build partial symbols for it. */
7764 process_skeletonless_type_unit (void **slot
, void *info
)
7766 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7767 skeleton_data
*data
= (skeleton_data
*) info
;
7769 /* If this TU doesn't exist in the global table, add it and read it in. */
7771 if (data
->per_objfile
->per_bfd
->signatured_types
== NULL
)
7772 data
->per_objfile
->per_bfd
->signatured_types
7773 = allocate_signatured_type_table ();
7775 signatured_type
find_entry (dwo_unit
->signature
);
7776 slot
= htab_find_slot (data
->per_objfile
->per_bfd
->signatured_types
.get (),
7777 &find_entry
, INSERT
);
7778 /* If we've already seen this type there's nothing to do. What's happening
7779 is we're doing our own version of comdat-folding here. */
7783 /* This does the job that create_all_comp_units would have done for
7785 signatured_type
*entry
7786 = add_type_unit (data
->per_objfile
, dwo_unit
->signature
, slot
);
7787 fill_in_sig_entry_from_dwo_entry (data
->per_objfile
, entry
, dwo_unit
);
7790 /* This does the job that build_type_psymtabs would have done. */
7791 cutu_reader
reader (entry
, data
->per_objfile
, nullptr, nullptr, false);
7792 if (!reader
.dummy_p
)
7793 build_type_psymtabs_reader (&reader
, data
->storage
);
7798 /* Traversal function for process_skeletonless_type_units. */
7801 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7803 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7805 if (dwo_file
->tus
!= NULL
)
7806 htab_traverse_noresize (dwo_file
->tus
.get (),
7807 process_skeletonless_type_unit
, info
);
7812 /* Scan all TUs of DWO files, verifying we've processed them.
7813 This is needed in case a TU was emitted without its skeleton.
7814 Note: This can't be done until we know what all the DWO files are. */
7817 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
,
7818 cooked_index_storage
*storage
)
7820 skeleton_data data
{ per_objfile
, storage
};
7822 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7823 if (get_dwp_file (per_objfile
) == NULL
7824 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7826 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7827 process_dwo_file_for_skeletonless_type_units
,
7832 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7835 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7837 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7839 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7844 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7846 /* Set the 'user' field only if it is not already set. */
7847 if (pst
->dependencies
[j
]->user
== NULL
)
7848 pst
->dependencies
[j
]->user
= pst
;
7853 /* Build the partial symbol table by doing a quick pass through the
7854 .debug_info and .debug_abbrev sections. */
7857 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7859 struct objfile
*objfile
= per_objfile
->objfile
;
7860 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7862 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7863 objfile_name (objfile
));
7865 scoped_restore restore_reading_psyms
7866 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7868 per_bfd
->map_info_sections (objfile
);
7870 /* Any cached compilation units will be linked by the per-objfile
7871 read_in_chain. Make sure to free them when we're done. */
7872 free_cached_comp_units
freer (per_objfile
);
7874 /* Create a temporary address map on a temporary obstack. We later
7875 copy this to the final obstack. */
7876 auto_obstack temp_obstack
;
7878 scoped_restore save_psymtabs_addrmap
7879 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7880 addrmap_create_mutable (&temp_obstack
));
7882 cooked_index_storage index_storage
;
7883 cooked_index_storage
*index_storage_ptr
7884 = per_bfd
->using_index
? &index_storage
: nullptr;
7885 create_all_comp_units (per_objfile
);
7886 build_type_psymtabs (per_objfile
, index_storage_ptr
);
7887 std::vector
<std::unique_ptr
<cooked_index
>> indexes
;
7888 if (per_bfd
->using_index
)
7890 per_bfd
->quick_file_names_table
7891 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
7893 if (!per_bfd
->debug_aranges
.empty ())
7894 read_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
,
7895 index_storage
.get_addrmap ());
7898 /* Ensure that complaints are handled correctly. */
7899 complaint_interceptor complaint_handler
;
7901 using iter_type
= typeof (per_bfd
->all_comp_units
.begin ());
7903 /* Each thread returns a pair holding a cooked index, and a vector
7904 of errors that should be printed. The latter is done because
7905 GDB's I/O system is not thread-safe. run_on_main_thread could be
7906 used, but that would mean the messages are printed after the
7907 prompt, which looks weird. */
7908 using result_type
= std::pair
<std::unique_ptr
<cooked_index
>,
7909 std::vector
<gdb_exception
>>;
7910 std::vector
<result_type
> results
7911 = gdb::parallel_for_each (1, per_bfd
->all_comp_units
.begin (),
7912 per_bfd
->all_comp_units
.end (),
7913 [=] (iter_type iter
, iter_type end
)
7915 std::vector
<gdb_exception
> errors
;
7916 cooked_index_storage thread_storage
;
7917 for (; iter
!= end
; ++iter
)
7919 dwarf2_per_cu_data
*per_cu
= iter
->get ();
7922 process_psymtab_comp_unit (per_cu
, per_objfile
,
7927 catch (gdb_exception
&except
)
7929 errors
.push_back (std::move (except
));
7932 return result_type (thread_storage
.release (),
7933 std::move (errors
));
7936 /* Only show a given exception a single time. */
7937 std::unordered_set
<gdb_exception
> seen_exceptions
;
7938 for (auto &one_result
: results
)
7940 indexes
.push_back (std::move (one_result
.first
));
7941 for (auto &one_exc
: one_result
.second
)
7943 if (seen_exceptions
.insert (one_exc
).second
)
7944 exception_print (gdb_stderr
, one_exc
);
7951 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7953 if (!per_bfd
->using_index
&& per_cu
->v
.psymtab
!= NULL
)
7954 /* In case a forward DW_TAG_imported_unit has read the CU
7957 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7958 language_minimal
, nullptr);
7962 /* This has to wait until we read the CUs, we need the list of DWOs. */
7963 process_skeletonless_type_units (per_objfile
, &index_storage
);
7965 /* Now that all TUs have been processed we can fill in the dependencies. */
7966 if (!per_bfd
->using_index
&& per_bfd
->type_unit_groups
!= NULL
)
7968 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7969 build_type_psymtab_dependencies
, per_objfile
);
7972 if (dwarf_read_debug
> 0)
7973 print_tu_stats (per_objfile
);
7975 if (per_bfd
->using_index
)
7977 indexes
.push_back (index_storage
.release ());
7978 /* Remove any NULL entries. This might happen if parallel-for
7979 decides to throttle the number of threads that were used. */
7981 (std::remove_if (indexes
.begin (),
7983 [] (const std::unique_ptr
<cooked_index
> &entry
)
7985 return entry
== nullptr;
7988 indexes
.shrink_to_fit ();
7989 per_bfd
->cooked_index_table
.reset
7990 (new cooked_index_vector (std::move (indexes
)));
7992 const cooked_index_entry
*main_entry
7993 = per_bfd
->cooked_index_table
->get_main ();
7994 if (main_entry
!= nullptr)
7995 set_objfile_main_name (objfile
, main_entry
->name
,
7996 main_entry
->per_cu
->lang
);
8000 set_partial_user (per_objfile
);
8002 per_bfd
->partial_symtabs
->psymtabs_addrmap
8003 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8004 per_bfd
->partial_symtabs
->obstack ());
8005 /* At this point we want to keep the address map. */
8006 save_psymtabs_addrmap
.release ();
8008 dwarf_read_debug_printf ("Done building psymtabs of %s",
8009 objfile_name (objfile
));
8012 /* Load the partial DIEs for a secondary CU into memory.
8013 This is also used when rereading a primary CU with load_all_dies. */
8016 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8017 dwarf2_per_objfile
*per_objfile
,
8018 dwarf2_cu
*existing_cu
)
8020 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8022 if (!reader
.dummy_p
)
8024 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8027 /* Check if comp unit has_children.
8028 If so, read the rest of the partial symbols from this comp unit.
8029 If not, there's no more debug_info for this comp unit. */
8030 if (reader
.comp_unit_die
->has_children
)
8031 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8038 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8039 struct dwarf2_section_info
*section
,
8040 struct dwarf2_section_info
*abbrev_section
,
8041 unsigned int is_dwz
,
8042 htab_up
&types_htab
,
8043 rcuh_kind section_kind
)
8045 const gdb_byte
*info_ptr
;
8046 struct objfile
*objfile
= per_objfile
->objfile
;
8048 dwarf_read_debug_printf ("Reading %s for %s",
8049 section
->get_name (),
8050 section
->get_file_name ());
8052 section
->read (objfile
);
8054 info_ptr
= section
->buffer
;
8056 while (info_ptr
< section
->buffer
+ section
->size
)
8058 dwarf2_per_cu_data_up this_cu
;
8060 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8062 comp_unit_head cu_header
;
8063 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8064 abbrev_section
, info_ptr
,
8067 /* Save the compilation unit for later lookup. */
8068 if (cu_header
.unit_type
!= DW_UT_type
)
8069 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8072 if (types_htab
== nullptr)
8073 types_htab
= allocate_signatured_type_table ();
8075 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
8076 (cu_header
.signature
);
8077 signatured_type
*sig_ptr
= sig_type
.get ();
8078 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8079 this_cu
.reset (sig_type
.release ());
8081 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
8082 gdb_assert (slot
!= nullptr);
8083 if (*slot
!= nullptr)
8084 complaint (_("debug type entry at offset %s is duplicate to"
8085 " the entry at offset %s, signature %s"),
8086 sect_offset_str (sect_off
),
8087 sect_offset_str (sig_ptr
->sect_off
),
8088 hex_string (sig_ptr
->signature
));
8091 this_cu
->sect_off
= sect_off
;
8092 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8093 this_cu
->is_dwz
= is_dwz
;
8094 this_cu
->section
= section
;
8096 if (per_objfile
->per_bfd
->using_index
)
8097 this_cu
->v
.quick
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
8098 struct dwarf2_per_cu_quick_data
);
8100 info_ptr
= info_ptr
+ this_cu
->length
;
8101 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
8105 /* Create a list of all compilation units in OBJFILE.
8106 This is only done for -readnow and building partial symtabs. */
8109 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8113 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8114 &per_objfile
->per_bfd
->abbrev
, 0,
8115 types_htab
, rcuh_kind::COMPILE
);
8116 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
8117 read_comp_units_from_section (per_objfile
, §ion
,
8118 &per_objfile
->per_bfd
->abbrev
, 0,
8119 types_htab
, rcuh_kind::TYPE
);
8121 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8124 /* Pre-read the sections we'll need to construct an index. */
8125 struct objfile
*objfile
= per_objfile
->objfile
;
8126 dwz
->abbrev
.read (objfile
);
8127 dwz
->info
.read (objfile
);
8128 dwz
->str
.read (objfile
);
8129 dwz
->line
.read (objfile
);
8130 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
8131 types_htab
, rcuh_kind::COMPILE
);
8134 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
8137 /* Process all loaded DIEs for compilation unit CU, starting at
8138 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8139 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8140 DW_AT_ranges). See the comments of add_partial_subprogram on how
8141 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8144 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8145 CORE_ADDR
*highpc
, int set_addrmap
,
8146 struct dwarf2_cu
*cu
)
8148 struct partial_die_info
*pdi
;
8150 /* Now, march along the PDI's, descending into ones which have
8151 interesting children but skipping the children of the other ones,
8152 until we reach the end of the compilation unit. */
8160 /* Anonymous namespaces or modules have no name but have interesting
8161 children, so we need to look at them. Ditto for anonymous
8164 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8165 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8166 || pdi
->tag
== DW_TAG_imported_unit
8167 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8171 case DW_TAG_subprogram
:
8172 case DW_TAG_inlined_subroutine
:
8173 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8174 if (cu
->per_cu
->lang
== language_cplus
)
8175 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8178 case DW_TAG_constant
:
8179 case DW_TAG_variable
:
8180 case DW_TAG_typedef
:
8181 case DW_TAG_union_type
:
8182 if (!pdi
->is_declaration
8183 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8185 add_partial_symbol (pdi
, cu
);
8188 case DW_TAG_class_type
:
8189 case DW_TAG_interface_type
:
8190 case DW_TAG_structure_type
:
8191 if (!pdi
->is_declaration
)
8193 add_partial_symbol (pdi
, cu
);
8195 if ((cu
->per_cu
->lang
== language_rust
8196 || cu
->per_cu
->lang
== language_cplus
)
8197 && pdi
->has_children
)
8198 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8201 case DW_TAG_enumeration_type
:
8202 if (!pdi
->is_declaration
)
8203 add_partial_enumeration (pdi
, cu
);
8205 case DW_TAG_base_type
:
8206 case DW_TAG_generic_subrange
:
8207 case DW_TAG_subrange_type
:
8208 /* File scope base type definitions are added to the partial
8210 add_partial_symbol (pdi
, cu
);
8212 case DW_TAG_namespace
:
8213 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8216 if (!pdi
->is_declaration
)
8217 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8219 case DW_TAG_imported_unit
:
8221 struct dwarf2_per_cu_data
*per_cu
;
8223 /* For now we don't handle imported units in type units. */
8224 if (cu
->per_cu
->is_debug_types
)
8226 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8227 " supported in type units [in module %s]"),
8228 objfile_name (cu
->per_objfile
->objfile
));
8231 per_cu
= dwarf2_find_containing_comp_unit
8232 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8233 cu
->per_objfile
->per_bfd
);
8235 /* Go read the partial unit, if needed. */
8236 if (per_cu
->v
.psymtab
== NULL
)
8237 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8238 cu
->per_cu
->lang
, nullptr);
8240 if (pdi
->die_parent
== nullptr
8241 && per_cu
->unit_type
== DW_UT_compile
8242 && per_cu
->lang
== language_cplus
)
8243 /* Regard import as hint. See corresponding code in
8244 process_imported_unit_die. */
8247 cu
->per_cu
->imported_symtabs_push (per_cu
);
8250 case DW_TAG_imported_declaration
:
8251 add_partial_symbol (pdi
, cu
);
8258 /* If the die has a sibling, skip to the sibling. */
8260 pdi
= pdi
->die_sibling
;
8264 /* Functions used to compute the fully scoped name of a partial DIE.
8266 Normally, this is simple. For C++, the parent DIE's fully scoped
8267 name is concatenated with "::" and the partial DIE's name.
8268 Enumerators are an exception; they use the scope of their parent
8269 enumeration type, i.e. the name of the enumeration type is not
8270 prepended to the enumerator.
8272 There are two complexities. One is DW_AT_specification; in this
8273 case "parent" means the parent of the target of the specification,
8274 instead of the direct parent of the DIE. The other is compilers
8275 which do not emit DW_TAG_namespace; in this case we try to guess
8276 the fully qualified name of structure types from their members'
8277 linkage names. This must be done using the DIE's children rather
8278 than the children of any DW_AT_specification target. We only need
8279 to do this for structures at the top level, i.e. if the target of
8280 any DW_AT_specification (if any; otherwise the DIE itself) does not
8283 /* Compute the scope prefix associated with PDI's parent, in
8284 compilation unit CU. The result will be allocated on CU's
8285 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8286 field. NULL is returned if no prefix is necessary. */
8288 partial_die_parent_scope (struct partial_die_info
*pdi
,
8289 struct dwarf2_cu
*cu
)
8291 const char *grandparent_scope
;
8292 struct partial_die_info
*parent
, *real_pdi
;
8294 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8295 then this means the parent of the specification DIE. */
8298 while (real_pdi
->has_specification
)
8300 auto res
= find_partial_die (real_pdi
->spec_offset
,
8301 real_pdi
->spec_is_dwz
, cu
);
8306 parent
= real_pdi
->die_parent
;
8310 if (parent
->scope_set
)
8311 return parent
->scope
;
8315 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8317 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8318 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8319 Work around this problem here. */
8320 if (cu
->per_cu
->lang
== language_cplus
8321 && parent
->tag
== DW_TAG_namespace
8322 && strcmp (parent
->name (cu
), "::") == 0
8323 && grandparent_scope
== NULL
)
8325 parent
->scope
= NULL
;
8326 parent
->scope_set
= 1;
8330 /* Nested subroutines in Fortran get a prefix. */
8331 if (pdi
->tag
== DW_TAG_enumerator
)
8332 /* Enumerators should not get the name of the enumeration as a prefix. */
8333 parent
->scope
= grandparent_scope
;
8334 else if (parent
->tag
== DW_TAG_namespace
8335 || parent
->tag
== DW_TAG_module
8336 || parent
->tag
== DW_TAG_structure_type
8337 || parent
->tag
== DW_TAG_class_type
8338 || parent
->tag
== DW_TAG_interface_type
8339 || parent
->tag
== DW_TAG_union_type
8340 || parent
->tag
== DW_TAG_enumeration_type
8341 || (cu
->per_cu
->lang
== language_fortran
8342 && parent
->tag
== DW_TAG_subprogram
8343 && pdi
->tag
== DW_TAG_subprogram
))
8345 if (grandparent_scope
== NULL
)
8346 parent
->scope
= parent
->name (cu
);
8348 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8350 parent
->name (cu
), 0, cu
);
8354 /* FIXME drow/2004-04-01: What should we be doing with
8355 function-local names? For partial symbols, we should probably be
8357 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8358 dwarf_tag_name (parent
->tag
),
8359 sect_offset_str (pdi
->sect_off
));
8360 parent
->scope
= grandparent_scope
;
8363 parent
->scope_set
= 1;
8364 return parent
->scope
;
8367 /* Return the fully scoped name associated with PDI, from compilation unit
8368 CU. The result will be allocated with malloc. */
8370 static gdb::unique_xmalloc_ptr
<char>
8371 partial_die_full_name (struct partial_die_info
*pdi
,
8372 struct dwarf2_cu
*cu
)
8374 const char *parent_scope
;
8376 /* If this is a template instantiation, we can not work out the
8377 template arguments from partial DIEs. So, unfortunately, we have
8378 to go through the full DIEs. At least any work we do building
8379 types here will be reused if full symbols are loaded later. */
8380 if (pdi
->has_template_arguments
)
8384 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8386 struct die_info
*die
;
8387 struct attribute attr
;
8388 struct dwarf2_cu
*ref_cu
= cu
;
8390 /* DW_FORM_ref_addr is using section offset. */
8391 attr
.name
= (enum dwarf_attribute
) 0;
8392 attr
.form
= DW_FORM_ref_addr
;
8393 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8394 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8396 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8400 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8401 if (parent_scope
== NULL
)
8404 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8410 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8412 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8413 struct objfile
*objfile
= per_objfile
->objfile
;
8414 struct gdbarch
*gdbarch
= objfile
->arch ();
8416 const char *actual_name
= NULL
;
8419 baseaddr
= objfile
->text_section_offset ();
8421 gdb::unique_xmalloc_ptr
<char> built_actual_name
8422 = partial_die_full_name (pdi
, cu
);
8423 if (built_actual_name
!= NULL
)
8424 actual_name
= built_actual_name
.get ();
8426 if (actual_name
== NULL
)
8427 actual_name
= pdi
->name (cu
);
8429 partial_symbol psymbol
;
8430 memset (&psymbol
, 0, sizeof (psymbol
));
8431 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
8432 &objfile
->objfile_obstack
);
8433 psymbol
.ginfo
.set_section_index (-1);
8435 /* The code below indicates that the psymbol should be installed by
8437 gdb::optional
<psymbol_placement
> where
;
8441 case DW_TAG_inlined_subroutine
:
8442 case DW_TAG_subprogram
:
8443 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8445 if (pdi
->is_external
8446 || cu
->per_cu
->lang
== language_ada
8447 || (cu
->per_cu
->lang
== language_fortran
8448 && pdi
->die_parent
!= NULL
8449 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8451 /* Normally, only "external" DIEs are part of the global scope.
8452 But in Ada and Fortran, we want to be able to access nested
8453 procedures globally. So all Ada and Fortran subprograms are
8454 stored in the global scope. */
8455 where
= psymbol_placement::GLOBAL
;
8458 where
= psymbol_placement::STATIC
;
8460 psymbol
.domain
= VAR_DOMAIN
;
8461 psymbol
.aclass
= LOC_BLOCK
;
8462 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8463 psymbol
.ginfo
.set_value_address (addr
);
8465 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8466 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
8468 case DW_TAG_constant
:
8469 psymbol
.domain
= VAR_DOMAIN
;
8470 psymbol
.aclass
= LOC_STATIC
;
8471 where
= (pdi
->is_external
8472 ? psymbol_placement::GLOBAL
8473 : psymbol_placement::STATIC
);
8475 case DW_TAG_variable
:
8477 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8481 && !per_objfile
->per_bfd
->has_section_at_zero
)
8483 /* A global or static variable may also have been stripped
8484 out by the linker if unused, in which case its address
8485 will be nullified; do not add such variables into partial
8486 symbol table then. */
8488 else if (pdi
->is_external
)
8491 Don't enter into the minimal symbol tables as there is
8492 a minimal symbol table entry from the ELF symbols already.
8493 Enter into partial symbol table if it has a location
8494 descriptor or a type.
8495 If the location descriptor is missing, new_symbol will create
8496 a LOC_UNRESOLVED symbol, the address of the variable will then
8497 be determined from the minimal symbol table whenever the variable
8499 The address for the partial symbol table entry is not
8500 used by GDB, but it comes in handy for debugging partial symbol
8503 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8505 psymbol
.domain
= VAR_DOMAIN
;
8506 psymbol
.aclass
= LOC_STATIC
;
8507 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8508 psymbol
.ginfo
.set_value_address (addr
);
8509 where
= psymbol_placement::GLOBAL
;
8514 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8516 /* Static Variable. Skip symbols whose value we cannot know (those
8517 without location descriptors or constant values). */
8518 if (!has_loc
&& !pdi
->has_const_value
)
8521 psymbol
.domain
= VAR_DOMAIN
;
8522 psymbol
.aclass
= LOC_STATIC
;
8523 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8525 psymbol
.ginfo
.set_value_address (addr
);
8526 where
= psymbol_placement::STATIC
;
8529 case DW_TAG_array_type
:
8530 case DW_TAG_typedef
:
8531 case DW_TAG_base_type
:
8532 case DW_TAG_subrange_type
:
8533 case DW_TAG_generic_subrange
:
8534 psymbol
.domain
= VAR_DOMAIN
;
8535 psymbol
.aclass
= LOC_TYPEDEF
;
8536 where
= psymbol_placement::STATIC
;
8538 case DW_TAG_imported_declaration
:
8539 case DW_TAG_namespace
:
8540 psymbol
.domain
= VAR_DOMAIN
;
8541 psymbol
.aclass
= LOC_TYPEDEF
;
8542 where
= psymbol_placement::GLOBAL
;
8545 /* With Fortran 77 there might be a "BLOCK DATA" module
8546 available without any name. If so, we skip the module as it
8547 doesn't bring any value. */
8548 if (actual_name
!= nullptr)
8550 psymbol
.domain
= MODULE_DOMAIN
;
8551 psymbol
.aclass
= LOC_TYPEDEF
;
8552 where
= psymbol_placement::GLOBAL
;
8555 case DW_TAG_class_type
:
8556 case DW_TAG_interface_type
:
8557 case DW_TAG_structure_type
:
8558 case DW_TAG_union_type
:
8559 case DW_TAG_enumeration_type
:
8560 /* Skip external references. The DWARF standard says in the section
8561 about "Structure, Union, and Class Type Entries": "An incomplete
8562 structure, union or class type is represented by a structure,
8563 union or class entry that does not have a byte size attribute
8564 and that has a DW_AT_declaration attribute." */
8565 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8568 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8569 static vs. global. */
8570 psymbol
.domain
= STRUCT_DOMAIN
;
8571 psymbol
.aclass
= LOC_TYPEDEF
;
8572 where
= (cu
->per_cu
->lang
== language_cplus
8573 ? psymbol_placement::GLOBAL
8574 : psymbol_placement::STATIC
);
8576 case DW_TAG_enumerator
:
8577 psymbol
.domain
= VAR_DOMAIN
;
8578 psymbol
.aclass
= LOC_CONST
;
8579 where
= (cu
->per_cu
->lang
== language_cplus
8580 ? psymbol_placement::GLOBAL
8581 : psymbol_placement::STATIC
);
8587 if (where
.has_value ())
8589 if (built_actual_name
!= nullptr)
8590 actual_name
= objfile
->intern (actual_name
);
8591 if (pdi
->linkage_name
== nullptr
8592 || cu
->per_cu
->lang
== language_ada
)
8593 psymbol
.ginfo
.set_linkage_name (actual_name
);
8596 psymbol
.ginfo
.set_demangled_name (actual_name
,
8597 &objfile
->objfile_obstack
);
8598 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8600 cu
->per_cu
->v
.psymtab
->add_psymbol
8601 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8606 /* Read a partial die corresponding to a namespace; also, add a symbol
8607 corresponding to that namespace to the symbol table. NAMESPACE is
8608 the name of the enclosing namespace. */
8611 add_partial_namespace (struct partial_die_info
*pdi
,
8612 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8613 int set_addrmap
, struct dwarf2_cu
*cu
)
8615 /* Add a symbol for the namespace. */
8617 add_partial_symbol (pdi
, cu
);
8619 /* Now scan partial symbols in that namespace. */
8621 if (pdi
->has_children
)
8622 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8625 /* Read a partial die corresponding to a Fortran module. */
8628 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8629 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8631 /* Add a symbol for the namespace. */
8633 add_partial_symbol (pdi
, cu
);
8635 /* Now scan partial symbols in that module. */
8637 if (pdi
->has_children
)
8638 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8641 static int dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
8642 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
8643 addrmap
*map
, void *datum
, dwarf_tag tag
);
8645 /* Read a partial die corresponding to a subprogram or an inlined
8646 subprogram and create a partial symbol for that subprogram.
8647 When the CU language allows it, this routine also defines a partial
8648 symbol for each nested subprogram that this subprogram contains.
8649 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8650 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8652 PDI may also be a lexical block, in which case we simply search
8653 recursively for subprograms defined inside that lexical block.
8654 Again, this is only performed when the CU language allows this
8655 type of definitions. */
8658 add_partial_subprogram (struct partial_die_info
*pdi
,
8659 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8660 int set_addrmap
, struct dwarf2_cu
*cu
)
8662 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8664 if (pdi
->has_pc_info
)
8666 if (pdi
->lowpc
< *lowpc
)
8667 *lowpc
= pdi
->lowpc
;
8668 if (pdi
->highpc
> *highpc
)
8669 *highpc
= pdi
->highpc
;
8672 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8673 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8674 struct gdbarch
*gdbarch
= objfile
->arch ();
8676 CORE_ADDR this_highpc
;
8677 CORE_ADDR this_lowpc
;
8679 baseaddr
= objfile
->text_section_offset ();
8681 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8682 pdi
->lowpc
+ baseaddr
)
8685 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8686 pdi
->highpc
+ baseaddr
)
8688 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8689 this_lowpc
, this_highpc
- 1,
8690 cu
->per_cu
->v
.psymtab
);
8694 if (pdi
->has_range_info
8695 && dwarf2_ranges_read (pdi
->ranges_offset
, &pdi
->lowpc
, &pdi
->highpc
,
8698 ? cu
->per_objfile
->per_bfd
->partial_symtabs
->psymtabs_addrmap
8700 set_addrmap
? cu
->per_cu
->v
.psymtab
: nullptr,
8703 if (pdi
->lowpc
< *lowpc
)
8704 *lowpc
= pdi
->lowpc
;
8705 if (pdi
->highpc
> *highpc
)
8706 *highpc
= pdi
->highpc
;
8709 if (pdi
->has_pc_info
|| pdi
->has_range_info
8710 || (!pdi
->is_external
&& pdi
->may_be_inlined
))
8712 if (!pdi
->is_declaration
)
8713 /* Ignore subprogram DIEs that do not have a name, they are
8714 illegal. Do not emit a complaint at this point, we will
8715 do so when we convert this psymtab into a symtab. */
8717 add_partial_symbol (pdi
, cu
);
8721 if (! pdi
->has_children
)
8724 if (cu
->per_cu
->lang
== language_ada
8725 || cu
->per_cu
->lang
== language_fortran
)
8727 pdi
= pdi
->die_child
;
8731 if (pdi
->tag
== DW_TAG_subprogram
8732 || pdi
->tag
== DW_TAG_inlined_subroutine
8733 || pdi
->tag
== DW_TAG_lexical_block
)
8734 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8735 pdi
= pdi
->die_sibling
;
8740 /* Read a partial die corresponding to an enumeration type. */
8743 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8744 struct dwarf2_cu
*cu
)
8746 struct partial_die_info
*pdi
;
8748 if (enum_pdi
->name (cu
) != NULL
)
8749 add_partial_symbol (enum_pdi
, cu
);
8751 pdi
= enum_pdi
->die_child
;
8754 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8755 complaint (_("malformed enumerator DIE ignored"));
8757 add_partial_symbol (pdi
, cu
);
8758 pdi
= pdi
->die_sibling
;
8762 /* Return the initial uleb128 in the die at INFO_PTR. */
8765 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8767 unsigned int bytes_read
;
8769 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8772 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8773 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8775 Return the corresponding abbrev, or NULL if the number is zero (indicating
8776 an empty DIE). In either case *BYTES_READ will be set to the length of
8777 the initial number. */
8779 static const struct abbrev_info
*
8780 peek_die_abbrev (const die_reader_specs
&reader
,
8781 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8783 dwarf2_cu
*cu
= reader
.cu
;
8784 bfd
*abfd
= reader
.abfd
;
8785 unsigned int abbrev_number
8786 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8788 if (abbrev_number
== 0)
8791 const abbrev_info
*abbrev
8792 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8795 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8796 " at offset %s [in module %s]"),
8797 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8798 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8804 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8805 Returns a pointer to the end of a series of DIEs, terminated by an empty
8806 DIE. Any children of the skipped DIEs will also be skipped. */
8808 static const gdb_byte
*
8809 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8813 unsigned int bytes_read
;
8814 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8818 return info_ptr
+ bytes_read
;
8820 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8824 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8825 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8826 abbrev corresponding to that skipped uleb128 should be passed in
8829 If DO_SKIP_CHILDREN is true, or if the DIE has no children, this
8830 returns a pointer to this DIE's sibling, skipping any children.
8831 Otherwise, returns a pointer to the DIE's first child. */
8833 static const gdb_byte
*
8834 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8835 const struct abbrev_info
*abbrev
, bool do_skip_children
)
8837 unsigned int bytes_read
;
8838 struct attribute attr
;
8839 bfd
*abfd
= reader
->abfd
;
8840 struct dwarf2_cu
*cu
= reader
->cu
;
8841 const gdb_byte
*buffer
= reader
->buffer
;
8842 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8843 unsigned int form
, i
;
8845 if (do_skip_children
&& abbrev
->sibling_offset
!= (unsigned short) -1)
8847 /* We only handle DW_FORM_ref4 here. */
8848 const gdb_byte
*sibling_data
= info_ptr
+ abbrev
->sibling_offset
;
8849 unsigned int offset
= read_4_bytes (abfd
, sibling_data
);
8850 const gdb_byte
*sibling_ptr
8851 = buffer
+ to_underlying (cu
->header
.sect_off
) + offset
;
8852 if (sibling_ptr
>= info_ptr
&& sibling_ptr
< reader
->buffer_end
)
8854 /* Fall through to the slow way. */
8856 else if (abbrev
->size_if_constant
!= 0)
8858 info_ptr
+= abbrev
->size_if_constant
;
8859 if (do_skip_children
&& abbrev
->has_children
)
8860 return skip_children (reader
, info_ptr
);
8864 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8866 /* The only abbrev we care about is DW_AT_sibling. */
8867 if (do_skip_children
&& abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8869 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8870 if (attr
.form
== DW_FORM_ref_addr
)
8871 complaint (_("ignoring absolute DW_AT_sibling"));
8874 sect_offset off
= attr
.get_ref_die_offset ();
8875 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8877 if (sibling_ptr
< info_ptr
)
8878 complaint (_("DW_AT_sibling points backwards"));
8879 else if (sibling_ptr
> reader
->buffer_end
)
8880 reader
->die_section
->overflow_complaint ();
8886 /* If it isn't DW_AT_sibling, skip this attribute. */
8887 form
= abbrev
->attrs
[i
].form
;
8891 case DW_FORM_ref_addr
:
8892 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8893 and later it is offset sized. */
8894 if (cu
->header
.version
== 2)
8895 info_ptr
+= cu
->header
.addr_size
;
8897 info_ptr
+= cu
->header
.offset_size
;
8899 case DW_FORM_GNU_ref_alt
:
8900 info_ptr
+= cu
->header
.offset_size
;
8903 info_ptr
+= cu
->header
.addr_size
;
8911 case DW_FORM_flag_present
:
8912 case DW_FORM_implicit_const
:
8929 case DW_FORM_ref_sig8
:
8932 case DW_FORM_data16
:
8935 case DW_FORM_string
:
8936 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8937 info_ptr
+= bytes_read
;
8939 case DW_FORM_sec_offset
:
8941 case DW_FORM_GNU_strp_alt
:
8942 info_ptr
+= cu
->header
.offset_size
;
8944 case DW_FORM_exprloc
:
8946 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8947 info_ptr
+= bytes_read
;
8949 case DW_FORM_block1
:
8950 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8952 case DW_FORM_block2
:
8953 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8955 case DW_FORM_block4
:
8956 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8962 case DW_FORM_ref_udata
:
8963 case DW_FORM_GNU_addr_index
:
8964 case DW_FORM_GNU_str_index
:
8965 case DW_FORM_rnglistx
:
8966 case DW_FORM_loclistx
:
8967 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8969 case DW_FORM_indirect
:
8970 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8971 info_ptr
+= bytes_read
;
8972 /* We need to continue parsing from here, so just go back to
8974 goto skip_attribute
;
8977 error (_("Dwarf Error: Cannot handle %s "
8978 "in DWARF reader [in module %s]"),
8979 dwarf_form_name (form
),
8980 bfd_get_filename (abfd
));
8984 if (do_skip_children
&& abbrev
->has_children
)
8985 return skip_children (reader
, info_ptr
);
8990 /* Locate ORIG_PDI's sibling.
8991 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8993 static const gdb_byte
*
8994 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8995 struct partial_die_info
*orig_pdi
,
8996 const gdb_byte
*info_ptr
)
8998 /* Do we know the sibling already? */
9000 if (orig_pdi
->sibling
)
9001 return orig_pdi
->sibling
;
9003 /* Are there any children to deal with? */
9005 if (!orig_pdi
->has_children
)
9008 /* Skip the children the long way. */
9010 return skip_children (reader
, info_ptr
);
9013 /* Expand this partial symbol table into a full symbol table. SELF is
9017 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9019 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9021 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
9023 /* If this psymtab is constructed from a debug-only objfile, the
9024 has_section_at_zero flag will not necessarily be correct. We
9025 can get the correct value for this flag by looking at the data
9026 associated with the (presumably stripped) associated objfile. */
9027 if (objfile
->separate_debug_objfile_backlink
)
9029 dwarf2_per_objfile
*per_objfile_backlink
9030 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9032 per_objfile
->per_bfd
->has_section_at_zero
9033 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9036 expand_psymtab (objfile
);
9038 process_cu_includes (per_objfile
);
9041 /* Reading in full CUs. */
9043 /* Add PER_CU to the queue. */
9046 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9047 dwarf2_per_objfile
*per_objfile
,
9048 enum language pretend_language
)
9052 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
9053 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
9056 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
9058 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9061 Return true if maybe_queue_comp_unit requires the caller to load the CU's
9062 DIEs, false otherwise.
9064 Explanation: there is an invariant that if a CU is queued for expansion
9065 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
9066 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
9067 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
9068 are not yet loaded, the the caller must load the CU's DIEs to ensure the
9069 invariant is respected.
9071 The caller is therefore not required to load the CU's DIEs (we return false)
9074 - the CU is already expanded, and therefore does not get enqueued
9075 - the CU gets enqueued for expansion, but its DIEs are already loaded
9077 Note that the caller should not use this function's return value as an
9078 indicator of whether the CU's DIEs are loaded right now, it should check
9079 that by calling `dwarf2_per_objfile::get_cu` instead. */
9082 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9083 dwarf2_per_cu_data
*per_cu
,
9084 dwarf2_per_objfile
*per_objfile
,
9085 enum language pretend_language
)
9087 /* We may arrive here during partial symbol reading, if we need full
9088 DIEs to process an unusual case (e.g. template arguments). Do
9089 not queue PER_CU, just tell our caller to load its DIEs. */
9090 if (per_cu
->per_bfd
->reading_partial_symbols
)
9092 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9094 if (cu
== NULL
|| cu
->dies
== NULL
)
9099 /* Mark the dependence relation so that we don't flush PER_CU
9101 if (dependent_cu
!= NULL
)
9102 dependent_cu
->add_dependence (per_cu
);
9104 /* If it's already on the queue, we have nothing to do. */
9107 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
9109 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
9111 /* If the CU is queued for expansion, it should not already be
9113 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
9115 /* The DIEs are already loaded, the caller doesn't need to do it. */
9119 bool queued
= false;
9120 if (!per_objfile
->symtab_set_p (per_cu
))
9122 /* Add it to the queue. */
9123 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9127 /* If the compilation unit is already loaded, just mark it as
9129 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9133 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
9134 and the DIEs are not already loaded. */
9135 return queued
&& cu
== nullptr;
9138 /* Process the queue. */
9141 process_queue (dwarf2_per_objfile
*per_objfile
)
9143 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
9144 objfile_name (per_objfile
->objfile
));
9146 /* The queue starts out with one item, but following a DIE reference
9147 may load a new CU, adding it to the end of the queue. */
9148 while (!per_objfile
->per_bfd
->queue
->empty ())
9150 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
9151 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9153 if (!per_objfile
->symtab_set_p (per_cu
))
9155 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9157 /* Skip dummy CUs. */
9160 unsigned int debug_print_threshold
;
9163 if (per_cu
->is_debug_types
)
9165 struct signatured_type
*sig_type
=
9166 (struct signatured_type
*) per_cu
;
9168 sprintf (buf
, "TU %s at offset %s",
9169 hex_string (sig_type
->signature
),
9170 sect_offset_str (per_cu
->sect_off
));
9171 /* There can be 100s of TUs.
9172 Only print them in verbose mode. */
9173 debug_print_threshold
= 2;
9177 sprintf (buf
, "CU at offset %s",
9178 sect_offset_str (per_cu
->sect_off
));
9179 debug_print_threshold
= 1;
9182 if (dwarf_read_debug
>= debug_print_threshold
)
9183 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
9185 if (per_cu
->is_debug_types
)
9186 process_full_type_unit (cu
, item
.pretend_language
);
9188 process_full_comp_unit (cu
, item
.pretend_language
);
9190 if (dwarf_read_debug
>= debug_print_threshold
)
9191 dwarf_read_debug_printf ("Done expanding %s", buf
);
9196 per_objfile
->per_bfd
->queue
->pop ();
9199 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
9200 objfile_name (per_objfile
->objfile
));
9203 /* Read in full symbols for PST, and anything it depends on. */
9206 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9208 gdb_assert (!readin_p (objfile
));
9210 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9211 free_cached_comp_units
freer (per_objfile
);
9212 expand_dependencies (objfile
);
9214 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9215 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9218 /* See psympriv.h. */
9221 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9223 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9224 return per_objfile
->symtab_set_p (per_cu_data
);
9227 /* See psympriv.h. */
9230 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9232 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9233 return per_objfile
->get_symtab (per_cu_data
);
9236 /* Trivial hash function for die_info: the hash value of a DIE
9237 is its offset in .debug_info for this objfile. */
9240 die_hash (const void *item
)
9242 const struct die_info
*die
= (const struct die_info
*) item
;
9244 return to_underlying (die
->sect_off
);
9247 /* Trivial comparison function for die_info structures: two DIEs
9248 are equal if they have the same offset. */
9251 die_eq (const void *item_lhs
, const void *item_rhs
)
9253 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9254 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9256 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9259 /* Load the DIEs associated with PER_CU into memory.
9261 In some cases, the caller, while reading partial symbols, will need to load
9262 the full symbols for the CU for some reason. It will already have a
9263 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
9264 rather than creating a new one. */
9267 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9268 dwarf2_per_objfile
*per_objfile
,
9269 dwarf2_cu
*existing_cu
,
9271 enum language pretend_language
)
9273 gdb_assert (! this_cu
->is_debug_types
);
9275 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9279 struct dwarf2_cu
*cu
= reader
.cu
;
9280 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9282 gdb_assert (cu
->die_hash
== NULL
);
9284 htab_create_alloc_ex (cu
->header
.length
/ 12,
9288 &cu
->comp_unit_obstack
,
9289 hashtab_obstack_allocate
,
9290 dummy_obstack_deallocate
);
9292 if (reader
.comp_unit_die
->has_children
)
9293 reader
.comp_unit_die
->child
9294 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9295 &info_ptr
, reader
.comp_unit_die
);
9296 cu
->dies
= reader
.comp_unit_die
;
9297 /* comp_unit_die is not stored in die_hash, no need. */
9299 /* We try not to read any attributes in this function, because not
9300 all CUs needed for references have been loaded yet, and symbol
9301 table processing isn't initialized. But we have to set the CU language,
9302 or we won't be able to build types correctly.
9303 Similarly, if we do not read the producer, we can not apply
9304 producer-specific interpretation. */
9305 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9310 /* Add a DIE to the delayed physname list. */
9313 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9314 const char *name
, struct die_info
*die
,
9315 struct dwarf2_cu
*cu
)
9317 struct delayed_method_info mi
;
9319 mi
.fnfield_index
= fnfield_index
;
9323 cu
->method_list
.push_back (mi
);
9326 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9327 "const" / "volatile". If so, decrements LEN by the length of the
9328 modifier and return true. Otherwise return false. */
9332 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9334 size_t mod_len
= sizeof (mod
) - 1;
9335 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9343 /* Compute the physnames of any methods on the CU's method list.
9345 The computation of method physnames is delayed in order to avoid the
9346 (bad) condition that one of the method's formal parameters is of an as yet
9350 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9352 /* Only C++ delays computing physnames. */
9353 if (cu
->method_list
.empty ())
9355 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
9357 for (const delayed_method_info
&mi
: cu
->method_list
)
9359 const char *physname
;
9360 struct fn_fieldlist
*fn_flp
9361 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9362 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9363 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9364 = physname
? physname
: "";
9366 /* Since there's no tag to indicate whether a method is a
9367 const/volatile overload, extract that information out of the
9369 if (physname
!= NULL
)
9371 size_t len
= strlen (physname
);
9375 if (physname
[len
] == ')') /* shortcut */
9377 else if (check_modifier (physname
, len
, " const"))
9378 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9379 else if (check_modifier (physname
, len
, " volatile"))
9380 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9387 /* The list is no longer needed. */
9388 cu
->method_list
.clear ();
9391 /* Go objects should be embedded in a DW_TAG_module DIE,
9392 and it's not clear if/how imported objects will appear.
9393 To keep Go support simple until that's worked out,
9394 go back through what we've read and create something usable.
9395 We could do this while processing each DIE, and feels kinda cleaner,
9396 but that way is more invasive.
9397 This is to, for example, allow the user to type "p var" or "b main"
9398 without having to specify the package name, and allow lookups
9399 of module.object to work in contexts that use the expression
9403 fixup_go_packaging (struct dwarf2_cu
*cu
)
9405 gdb::unique_xmalloc_ptr
<char> package_name
;
9406 struct pending
*list
;
9409 for (list
= *cu
->get_builder ()->get_global_symbols ();
9413 for (i
= 0; i
< list
->nsyms
; ++i
)
9415 struct symbol
*sym
= list
->symbol
[i
];
9417 if (sym
->language () == language_go
9418 && sym
->aclass () == LOC_BLOCK
)
9420 gdb::unique_xmalloc_ptr
<char> this_package_name
9421 (go_symbol_package_name (sym
));
9423 if (this_package_name
== NULL
)
9425 if (package_name
== NULL
)
9426 package_name
= std::move (this_package_name
);
9429 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9430 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9431 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9432 (symbol_symtab (sym
) != NULL
9433 ? symtab_to_filename_for_display
9434 (symbol_symtab (sym
))
9435 : objfile_name (objfile
)),
9436 this_package_name
.get (), package_name
.get ());
9442 if (package_name
!= NULL
)
9444 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9445 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9446 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9447 saved_package_name
);
9450 sym
= new (&objfile
->objfile_obstack
) symbol
;
9451 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9452 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9453 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9454 e.g., "main" finds the "main" module and not C's main(). */
9455 sym
->set_domain (STRUCT_DOMAIN
);
9456 sym
->set_aclass_index (LOC_TYPEDEF
);
9457 sym
->set_type (type
);
9459 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9463 /* Allocate a fully-qualified name consisting of the two parts on the
9467 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9469 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9472 /* A helper that allocates a variant part to attach to a Rust enum
9473 type. OBSTACK is where the results should be allocated. TYPE is
9474 the type we're processing. DISCRIMINANT_INDEX is the index of the
9475 discriminant. It must be the index of one of the fields of TYPE,
9476 or -1 to mean there is no discriminant (univariant enum).
9477 DEFAULT_INDEX is the index of the default field; or -1 if there is
9478 no default. RANGES is indexed by "effective" field number (the
9479 field index, but omitting the discriminant and default fields) and
9480 must hold the discriminant values used by the variants. Note that
9481 RANGES must have a lifetime at least as long as OBSTACK -- either
9482 already allocated on it, or static. */
9485 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9486 int discriminant_index
, int default_index
,
9487 gdb::array_view
<discriminant_range
> ranges
)
9489 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9490 gdb_assert (discriminant_index
== -1
9491 || (discriminant_index
>= 0
9492 && discriminant_index
< type
->num_fields ()));
9493 gdb_assert (default_index
== -1
9494 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9496 /* We have one variant for each non-discriminant field. */
9497 int n_variants
= type
->num_fields ();
9498 if (discriminant_index
!= -1)
9501 variant
*variants
= new (obstack
) variant
[n_variants
];
9504 for (int i
= 0; i
< type
->num_fields (); ++i
)
9506 if (i
== discriminant_index
)
9509 variants
[var_idx
].first_field
= i
;
9510 variants
[var_idx
].last_field
= i
+ 1;
9512 /* The default field does not need a range, but other fields do.
9513 We skipped the discriminant above. */
9514 if (i
!= default_index
)
9516 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9523 gdb_assert (range_idx
== ranges
.size ());
9524 gdb_assert (var_idx
== n_variants
);
9526 variant_part
*part
= new (obstack
) variant_part
;
9527 part
->discriminant_index
= discriminant_index
;
9528 /* If there is no discriminant, then whether it is signed is of no
9531 = (discriminant_index
== -1
9533 : type
->field (discriminant_index
).type ()->is_unsigned ());
9534 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9536 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9537 gdb::array_view
<variant_part
> *prop_value
9538 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9540 struct dynamic_prop prop
;
9541 prop
.set_variant_parts (prop_value
);
9543 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9546 /* Some versions of rustc emitted enums in an unusual way.
9548 Ordinary enums were emitted as unions. The first element of each
9549 structure in the union was named "RUST$ENUM$DISR". This element
9550 held the discriminant.
9552 These versions of Rust also implemented the "non-zero"
9553 optimization. When the enum had two values, and one is empty and
9554 the other holds a pointer that cannot be zero, the pointer is used
9555 as the discriminant, with a zero value meaning the empty variant.
9556 Here, the union's first member is of the form
9557 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9558 where the fieldnos are the indices of the fields that should be
9559 traversed in order to find the field (which may be several fields deep)
9560 and the variantname is the name of the variant of the case when the
9563 This function recognizes whether TYPE is of one of these forms,
9564 and, if so, smashes it to be a variant type. */
9567 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9569 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9571 /* We don't need to deal with empty enums. */
9572 if (type
->num_fields () == 0)
9575 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9576 if (type
->num_fields () == 1
9577 && startswith (type
->field (0).name (), RUST_ENUM_PREFIX
))
9579 const char *name
= type
->field (0).name () + strlen (RUST_ENUM_PREFIX
);
9581 /* Decode the field name to find the offset of the
9583 ULONGEST bit_offset
= 0;
9584 struct type
*field_type
= type
->field (0).type ();
9585 while (name
[0] >= '0' && name
[0] <= '9')
9588 unsigned long index
= strtoul (name
, &tail
, 10);
9591 || index
>= field_type
->num_fields ()
9592 || (field_type
->field (index
).loc_kind ()
9593 != FIELD_LOC_KIND_BITPOS
))
9595 complaint (_("Could not parse Rust enum encoding string \"%s\""
9597 type
->field (0).name (),
9598 objfile_name (objfile
));
9603 bit_offset
+= field_type
->field (index
).loc_bitpos ();
9604 field_type
= field_type
->field (index
).type ();
9607 /* Smash this type to be a structure type. We have to do this
9608 because the type has already been recorded. */
9609 type
->set_code (TYPE_CODE_STRUCT
);
9610 type
->set_num_fields (3);
9611 /* Save the field we care about. */
9612 struct field saved_field
= type
->field (0);
9614 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9616 /* Put the discriminant at index 0. */
9617 type
->field (0).set_type (field_type
);
9618 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9619 type
->field (0).set_name ("<<discriminant>>");
9620 type
->field (0).set_loc_bitpos (bit_offset
);
9622 /* The order of fields doesn't really matter, so put the real
9623 field at index 1 and the data-less field at index 2. */
9624 type
->field (1) = saved_field
;
9625 type
->field (1).set_name
9626 (rust_last_path_segment (type
->field (1).type ()->name ()));
9627 type
->field (1).type ()->set_name
9628 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9629 type
->field (1).name ()));
9631 const char *dataless_name
9632 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9634 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9636 type
->field (2).set_type (dataless_type
);
9637 /* NAME points into the original discriminant name, which
9638 already has the correct lifetime. */
9639 type
->field (2).set_name (name
);
9640 type
->field (2).set_loc_bitpos (0);
9642 /* Indicate that this is a variant type. */
9643 static discriminant_range ranges
[1] = { { 0, 0 } };
9644 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9646 /* A union with a single anonymous field is probably an old-style
9648 else if (type
->num_fields () == 1 && streq (type
->field (0).name (), ""))
9650 /* Smash this type to be a structure type. We have to do this
9651 because the type has already been recorded. */
9652 type
->set_code (TYPE_CODE_STRUCT
);
9654 struct type
*field_type
= type
->field (0).type ();
9655 const char *variant_name
9656 = rust_last_path_segment (field_type
->name ());
9657 type
->field (0).set_name (variant_name
);
9658 field_type
->set_name
9659 (rust_fully_qualify (&objfile
->objfile_obstack
,
9660 type
->name (), variant_name
));
9662 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9666 struct type
*disr_type
= nullptr;
9667 for (int i
= 0; i
< type
->num_fields (); ++i
)
9669 disr_type
= type
->field (i
).type ();
9671 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9673 /* All fields of a true enum will be structs. */
9676 else if (disr_type
->num_fields () == 0)
9678 /* Could be data-less variant, so keep going. */
9679 disr_type
= nullptr;
9681 else if (strcmp (disr_type
->field (0).name (),
9682 "RUST$ENUM$DISR") != 0)
9684 /* Not a Rust enum. */
9694 /* If we got here without a discriminant, then it's probably
9696 if (disr_type
== nullptr)
9699 /* Smash this type to be a structure type. We have to do this
9700 because the type has already been recorded. */
9701 type
->set_code (TYPE_CODE_STRUCT
);
9703 /* Make space for the discriminant field. */
9704 struct field
*disr_field
= &disr_type
->field (0);
9706 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9707 * sizeof (struct field
)));
9708 memcpy (new_fields
+ 1, type
->fields (),
9709 type
->num_fields () * sizeof (struct field
));
9710 type
->set_fields (new_fields
);
9711 type
->set_num_fields (type
->num_fields () + 1);
9713 /* Install the discriminant at index 0 in the union. */
9714 type
->field (0) = *disr_field
;
9715 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9716 type
->field (0).set_name ("<<discriminant>>");
9718 /* We need a way to find the correct discriminant given a
9719 variant name. For convenience we build a map here. */
9720 struct type
*enum_type
= disr_field
->type ();
9721 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9722 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9724 if (enum_type
->field (i
).loc_kind () == FIELD_LOC_KIND_ENUMVAL
)
9727 = rust_last_path_segment (enum_type
->field (i
).name ());
9728 discriminant_map
[name
] = enum_type
->field (i
).loc_enumval ();
9732 int n_fields
= type
->num_fields ();
9733 /* We don't need a range entry for the discriminant, but we do
9734 need one for every other field, as there is no default
9736 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9739 /* Skip the discriminant here. */
9740 for (int i
= 1; i
< n_fields
; ++i
)
9742 /* Find the final word in the name of this variant's type.
9743 That name can be used to look up the correct
9745 const char *variant_name
9746 = rust_last_path_segment (type
->field (i
).type ()->name ());
9748 auto iter
= discriminant_map
.find (variant_name
);
9749 if (iter
!= discriminant_map
.end ())
9751 ranges
[i
- 1].low
= iter
->second
;
9752 ranges
[i
- 1].high
= iter
->second
;
9755 /* In Rust, each element should have the size of the
9757 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9759 /* Remove the discriminant field, if it exists. */
9760 struct type
*sub_type
= type
->field (i
).type ();
9761 if (sub_type
->num_fields () > 0)
9763 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9764 sub_type
->set_fields (sub_type
->fields () + 1);
9766 type
->field (i
).set_name (variant_name
);
9768 (rust_fully_qualify (&objfile
->objfile_obstack
,
9769 type
->name (), variant_name
));
9772 /* Indicate that this is a variant type. */
9773 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9774 gdb::array_view
<discriminant_range
> (ranges
,
9779 /* Rewrite some Rust unions to be structures with variants parts. */
9782 rust_union_quirks (struct dwarf2_cu
*cu
)
9784 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9785 for (type
*type_
: cu
->rust_unions
)
9786 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9787 /* We don't need this any more. */
9788 cu
->rust_unions
.clear ();
9793 type_unit_group_unshareable
*
9794 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9796 auto iter
= this->m_type_units
.find (tu_group
);
9797 if (iter
!= this->m_type_units
.end ())
9798 return iter
->second
.get ();
9800 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9801 type_unit_group_unshareable
*result
= uniq
.get ();
9802 this->m_type_units
[tu_group
] = std::move (uniq
);
9807 dwarf2_per_objfile::get_type_for_signatured_type
9808 (signatured_type
*sig_type
) const
9810 auto iter
= this->m_type_map
.find (sig_type
);
9811 if (iter
== this->m_type_map
.end ())
9814 return iter
->second
;
9817 void dwarf2_per_objfile::set_type_for_signatured_type
9818 (signatured_type
*sig_type
, struct type
*type
)
9820 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9822 this->m_type_map
[sig_type
] = type
;
9825 /* A helper function for computing the list of all symbol tables
9826 included by PER_CU. */
9829 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9830 htab_t all_children
, htab_t all_type_symtabs
,
9831 dwarf2_per_cu_data
*per_cu
,
9832 dwarf2_per_objfile
*per_objfile
,
9833 struct compunit_symtab
*immediate_parent
)
9835 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9838 /* This inclusion and its children have been processed. */
9844 /* Only add a CU if it has a symbol table. */
9845 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9848 /* If this is a type unit only add its symbol table if we haven't
9849 seen it yet (type unit per_cu's can share symtabs). */
9850 if (per_cu
->is_debug_types
)
9852 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9856 result
->push_back (cust
);
9857 if (cust
->user
== NULL
)
9858 cust
->user
= immediate_parent
;
9863 result
->push_back (cust
);
9864 if (cust
->user
== NULL
)
9865 cust
->user
= immediate_parent
;
9869 if (!per_cu
->imported_symtabs_empty ())
9870 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9872 recursively_compute_inclusions (result
, all_children
,
9873 all_type_symtabs
, ptr
, per_objfile
,
9878 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9882 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9883 dwarf2_per_objfile
*per_objfile
)
9885 gdb_assert (! per_cu
->is_debug_types
);
9887 if (!per_cu
->imported_symtabs_empty ())
9890 std::vector
<compunit_symtab
*> result_symtabs
;
9891 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9893 /* If we don't have a symtab, we can just skip this case. */
9897 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9899 NULL
, xcalloc
, xfree
));
9900 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9902 NULL
, xcalloc
, xfree
));
9904 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9906 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9907 all_type_symtabs
.get (), ptr
,
9911 /* Now we have a transitive closure of all the included symtabs. */
9912 len
= result_symtabs
.size ();
9914 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9915 struct compunit_symtab
*, len
+ 1);
9916 memcpy (cust
->includes
, result_symtabs
.data (),
9917 len
* sizeof (compunit_symtab
*));
9918 cust
->includes
[len
] = NULL
;
9922 /* Compute the 'includes' field for the symtabs of all the CUs we just
9926 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9928 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9930 if (! iter
->is_debug_types
)
9931 compute_compunit_symtab_includes (iter
, per_objfile
);
9934 per_objfile
->per_bfd
->just_read_cus
.clear ();
9937 /* Generate full symbol information for CU, whose DIEs have
9938 already been loaded into memory. */
9941 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9943 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9944 struct objfile
*objfile
= per_objfile
->objfile
;
9945 struct gdbarch
*gdbarch
= objfile
->arch ();
9946 CORE_ADDR lowpc
, highpc
;
9947 struct compunit_symtab
*cust
;
9949 struct block
*static_block
;
9952 baseaddr
= objfile
->text_section_offset ();
9954 /* Clear the list here in case something was left over. */
9955 cu
->method_list
.clear ();
9957 dwarf2_find_base_address (cu
->dies
, cu
);
9959 /* Before we start reading the top-level DIE, ensure it has a valid tag
9961 switch (cu
->dies
->tag
)
9963 case DW_TAG_compile_unit
:
9964 case DW_TAG_partial_unit
:
9965 case DW_TAG_type_unit
:
9968 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9969 dwarf_tag_name (cu
->dies
->tag
),
9970 sect_offset_str (cu
->per_cu
->sect_off
),
9971 objfile_name (per_objfile
->objfile
));
9974 /* Do line number decoding in read_file_scope () */
9975 process_die (cu
->dies
, cu
);
9977 /* For now fudge the Go package. */
9978 if (cu
->per_cu
->lang
== language_go
)
9979 fixup_go_packaging (cu
);
9981 /* Now that we have processed all the DIEs in the CU, all the types
9982 should be complete, and it should now be safe to compute all of the
9984 compute_delayed_physnames (cu
);
9986 if (cu
->per_cu
->lang
== language_rust
)
9987 rust_union_quirks (cu
);
9989 /* Some compilers don't define a DW_AT_high_pc attribute for the
9990 compilation unit. If the DW_AT_high_pc is missing, synthesize
9991 it, by scanning the DIE's below the compilation unit. */
9992 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9994 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9996 = cu
->get_builder ()->end_compunit_symtab_get_static_block (addr
, 0, 1);
9998 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9999 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10000 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10001 addrmap to help ensure it has an accurate map of pc values belonging to
10003 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10005 cust
= cu
->get_builder ()->end_compunit_symtab_from_static_block
10006 (static_block
, SECT_OFF_TEXT (objfile
), 0);
10010 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10012 /* Set symtab language to language from DW_AT_language. If the
10013 compilation is from a C file generated by language preprocessors, do
10014 not set the language if it was already deduced by start_subfile. */
10015 if (!(cu
->per_cu
->lang
== language_c
10016 && cust
->primary_filetab ()->language () != language_unknown
))
10017 cust
->primary_filetab ()->set_language (cu
->per_cu
->lang
);
10019 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10020 produce DW_AT_location with location lists but it can be possibly
10021 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10022 there were bugs in prologue debug info, fixed later in GCC-4.5
10023 by "unwind info for epilogues" patch (which is not directly related).
10025 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10026 needed, it would be wrong due to missing DW_AT_producer there.
10028 Still one can confuse GDB by using non-standard GCC compilation
10029 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10031 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10032 cust
->set_locations_valid (true);
10034 if (gcc_4_minor
>= 5)
10035 cust
->set_epilogue_unwind_valid (true);
10037 cust
->set_call_site_htab (cu
->call_site_htab
);
10040 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10042 /* Push it for inclusion processing later. */
10043 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
10045 /* Not needed any more. */
10046 cu
->reset_builder ();
10049 /* Generate full symbol information for type unit CU, whose DIEs have
10050 already been loaded into memory. */
10053 process_full_type_unit (dwarf2_cu
*cu
,
10054 enum language pretend_language
)
10056 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10057 struct objfile
*objfile
= per_objfile
->objfile
;
10058 struct compunit_symtab
*cust
;
10059 struct signatured_type
*sig_type
;
10061 gdb_assert (cu
->per_cu
->is_debug_types
);
10062 sig_type
= (struct signatured_type
*) cu
->per_cu
;
10064 /* Clear the list here in case something was left over. */
10065 cu
->method_list
.clear ();
10067 /* The symbol tables are set up in read_type_unit_scope. */
10068 process_die (cu
->dies
, cu
);
10070 /* For now fudge the Go package. */
10071 if (cu
->per_cu
->lang
== language_go
)
10072 fixup_go_packaging (cu
);
10074 /* Now that we have processed all the DIEs in the CU, all the types
10075 should be complete, and it should now be safe to compute all of the
10077 compute_delayed_physnames (cu
);
10079 if (cu
->per_cu
->lang
== language_rust
)
10080 rust_union_quirks (cu
);
10082 /* TUs share symbol tables.
10083 If this is the first TU to use this symtab, complete the construction
10084 of it with end_expandable_symtab. Otherwise, complete the addition of
10085 this TU's symbols to the existing symtab. */
10086 type_unit_group_unshareable
*tug_unshare
=
10087 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10088 if (tug_unshare
->compunit_symtab
== NULL
)
10090 buildsym_compunit
*builder
= cu
->get_builder ();
10091 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10092 tug_unshare
->compunit_symtab
= cust
;
10096 /* Set symtab language to language from DW_AT_language. If the
10097 compilation is from a C file generated by language preprocessors,
10098 do not set the language if it was already deduced by
10100 if (!(cu
->per_cu
->lang
== language_c
10101 && cust
->primary_filetab ()->language () != language_c
))
10102 cust
->primary_filetab ()->set_language (cu
->per_cu
->lang
);
10107 cu
->get_builder ()->augment_type_symtab ();
10108 cust
= tug_unshare
->compunit_symtab
;
10111 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10113 /* Not needed any more. */
10114 cu
->reset_builder ();
10117 /* Process an imported unit DIE. */
10120 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10122 struct attribute
*attr
;
10124 /* For now we don't handle imported units in type units. */
10125 if (cu
->per_cu
->is_debug_types
)
10127 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10128 " supported in type units [in module %s]"),
10129 objfile_name (cu
->per_objfile
->objfile
));
10132 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10135 sect_offset sect_off
= attr
->get_ref_die_offset ();
10136 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10137 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10138 dwarf2_per_cu_data
*per_cu
10139 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10140 per_objfile
->per_bfd
);
10142 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10143 into another compilation unit, at root level. Regard this as a hint,
10145 if (die
->parent
&& die
->parent
->parent
== NULL
10146 && per_cu
->unit_type
== DW_UT_compile
10147 && per_cu
->lang
== language_cplus
)
10150 /* If necessary, add it to the queue and load its DIEs. */
10151 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
10153 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
10154 false, cu
->per_cu
->lang
);
10156 cu
->per_cu
->imported_symtabs_push (per_cu
);
10160 /* RAII object that represents a process_die scope: i.e.,
10161 starts/finishes processing a DIE. */
10162 class process_die_scope
10165 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10166 : m_die (die
), m_cu (cu
)
10168 /* We should only be processing DIEs not already in process. */
10169 gdb_assert (!m_die
->in_process
);
10170 m_die
->in_process
= true;
10173 ~process_die_scope ()
10175 m_die
->in_process
= false;
10177 /* If we're done processing the DIE for the CU that owns the line
10178 header, we don't need the line header anymore. */
10179 if (m_cu
->line_header_die_owner
== m_die
)
10181 delete m_cu
->line_header
;
10182 m_cu
->line_header
= NULL
;
10183 m_cu
->line_header_die_owner
= NULL
;
10192 /* Process a die and its children. */
10195 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10197 process_die_scope
scope (die
, cu
);
10201 case DW_TAG_padding
:
10203 case DW_TAG_compile_unit
:
10204 case DW_TAG_partial_unit
:
10205 read_file_scope (die
, cu
);
10207 case DW_TAG_type_unit
:
10208 read_type_unit_scope (die
, cu
);
10210 case DW_TAG_subprogram
:
10211 /* Nested subprograms in Fortran get a prefix. */
10212 if (cu
->per_cu
->lang
== language_fortran
10213 && die
->parent
!= NULL
10214 && die
->parent
->tag
== DW_TAG_subprogram
)
10215 cu
->processing_has_namespace_info
= true;
10216 /* Fall through. */
10217 case DW_TAG_inlined_subroutine
:
10218 read_func_scope (die
, cu
);
10220 case DW_TAG_lexical_block
:
10221 case DW_TAG_try_block
:
10222 case DW_TAG_catch_block
:
10223 read_lexical_block_scope (die
, cu
);
10225 case DW_TAG_call_site
:
10226 case DW_TAG_GNU_call_site
:
10227 read_call_site_scope (die
, cu
);
10229 case DW_TAG_class_type
:
10230 case DW_TAG_interface_type
:
10231 case DW_TAG_structure_type
:
10232 case DW_TAG_union_type
:
10233 case DW_TAG_namelist
:
10234 process_structure_scope (die
, cu
);
10236 case DW_TAG_enumeration_type
:
10237 process_enumeration_scope (die
, cu
);
10240 /* These dies have a type, but processing them does not create
10241 a symbol or recurse to process the children. Therefore we can
10242 read them on-demand through read_type_die. */
10243 case DW_TAG_subroutine_type
:
10244 case DW_TAG_set_type
:
10245 case DW_TAG_pointer_type
:
10246 case DW_TAG_ptr_to_member_type
:
10247 case DW_TAG_reference_type
:
10248 case DW_TAG_rvalue_reference_type
:
10249 case DW_TAG_string_type
:
10252 case DW_TAG_array_type
:
10253 /* We only need to handle this case for Ada -- in other
10254 languages, it's normal for the compiler to emit a typedef
10256 if (cu
->per_cu
->lang
!= language_ada
)
10259 case DW_TAG_base_type
:
10260 case DW_TAG_subrange_type
:
10261 case DW_TAG_generic_subrange
:
10262 case DW_TAG_typedef
:
10263 /* Add a typedef symbol for the type definition, if it has a
10265 new_symbol (die
, read_type_die (die
, cu
), cu
);
10267 case DW_TAG_common_block
:
10268 read_common_block (die
, cu
);
10270 case DW_TAG_common_inclusion
:
10272 case DW_TAG_namespace
:
10273 cu
->processing_has_namespace_info
= true;
10274 read_namespace (die
, cu
);
10276 case DW_TAG_module
:
10277 cu
->processing_has_namespace_info
= true;
10278 read_module (die
, cu
);
10280 case DW_TAG_imported_declaration
:
10281 cu
->processing_has_namespace_info
= true;
10282 if (read_namespace_alias (die
, cu
))
10284 /* The declaration is not a global namespace alias. */
10285 /* Fall through. */
10286 case DW_TAG_imported_module
:
10287 cu
->processing_has_namespace_info
= true;
10288 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10289 || cu
->per_cu
->lang
!= language_fortran
))
10290 complaint (_("Tag '%s' has unexpected children"),
10291 dwarf_tag_name (die
->tag
));
10292 read_import_statement (die
, cu
);
10295 case DW_TAG_imported_unit
:
10296 process_imported_unit_die (die
, cu
);
10299 case DW_TAG_variable
:
10300 read_variable (die
, cu
);
10304 new_symbol (die
, NULL
, cu
);
10309 /* DWARF name computation. */
10311 /* A helper function for dwarf2_compute_name which determines whether DIE
10312 needs to have the name of the scope prepended to the name listed in the
10316 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10318 struct attribute
*attr
;
10322 case DW_TAG_namespace
:
10323 case DW_TAG_typedef
:
10324 case DW_TAG_class_type
:
10325 case DW_TAG_interface_type
:
10326 case DW_TAG_structure_type
:
10327 case DW_TAG_union_type
:
10328 case DW_TAG_enumeration_type
:
10329 case DW_TAG_enumerator
:
10330 case DW_TAG_subprogram
:
10331 case DW_TAG_inlined_subroutine
:
10332 case DW_TAG_member
:
10333 case DW_TAG_imported_declaration
:
10336 case DW_TAG_variable
:
10337 case DW_TAG_constant
:
10338 /* We only need to prefix "globally" visible variables. These include
10339 any variable marked with DW_AT_external or any variable that
10340 lives in a namespace. [Variables in anonymous namespaces
10341 require prefixing, but they are not DW_AT_external.] */
10343 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10345 struct dwarf2_cu
*spec_cu
= cu
;
10347 return die_needs_namespace (die_specification (die
, &spec_cu
),
10351 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10352 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10353 && die
->parent
->tag
!= DW_TAG_module
)
10355 /* A variable in a lexical block of some kind does not need a
10356 namespace, even though in C++ such variables may be external
10357 and have a mangled name. */
10358 if (die
->parent
->tag
== DW_TAG_lexical_block
10359 || die
->parent
->tag
== DW_TAG_try_block
10360 || die
->parent
->tag
== DW_TAG_catch_block
10361 || die
->parent
->tag
== DW_TAG_subprogram
)
10370 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10371 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10372 defined for the given DIE. */
10374 static struct attribute
*
10375 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10377 struct attribute
*attr
;
10379 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10381 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10386 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10387 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10388 defined for the given DIE. */
10390 static const char *
10391 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10393 const char *linkage_name
;
10395 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10396 if (linkage_name
== NULL
)
10397 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10399 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10400 See https://github.com/rust-lang/rust/issues/32925. */
10401 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
10402 && strchr (linkage_name
, '{') != NULL
)
10403 linkage_name
= NULL
;
10405 return linkage_name
;
10408 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10409 compute the physname for the object, which include a method's:
10410 - formal parameters (C++),
10411 - receiver type (Go),
10413 The term "physname" is a bit confusing.
10414 For C++, for example, it is the demangled name.
10415 For Go, for example, it's the mangled name.
10417 For Ada, return the DIE's linkage name rather than the fully qualified
10418 name. PHYSNAME is ignored..
10420 The result is allocated on the objfile->per_bfd's obstack and
10423 static const char *
10424 dwarf2_compute_name (const char *name
,
10425 struct die_info
*die
, struct dwarf2_cu
*cu
,
10428 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10431 name
= dwarf2_name (die
, cu
);
10433 enum language lang
= cu
->per_cu
->lang
;
10435 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10436 but otherwise compute it by typename_concat inside GDB.
10437 FIXME: Actually this is not really true, or at least not always true.
10438 It's all very confusing. compute_and_set_names doesn't try to demangle
10439 Fortran names because there is no mangling standard. So new_symbol
10440 will set the demangled name to the result of dwarf2_full_name, and it is
10441 the demangled name that GDB uses if it exists. */
10442 if (lang
== language_ada
10443 || (lang
== language_fortran
&& physname
))
10445 /* For Ada unit, we prefer the linkage name over the name, as
10446 the former contains the exported name, which the user expects
10447 to be able to reference. Ideally, we want the user to be able
10448 to reference this entity using either natural or linkage name,
10449 but we haven't started looking at this enhancement yet. */
10450 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10452 if (linkage_name
!= NULL
)
10453 return linkage_name
;
10456 /* These are the only languages we know how to qualify names in. */
10458 && (lang
== language_cplus
10459 || lang
== language_fortran
|| lang
== language_d
10460 || lang
== language_rust
))
10462 if (die_needs_namespace (die
, cu
))
10464 const char *prefix
;
10465 const char *canonical_name
= NULL
;
10469 prefix
= determine_prefix (die
, cu
);
10470 if (*prefix
!= '\0')
10472 gdb::unique_xmalloc_ptr
<char> prefixed_name
10473 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10475 buf
.puts (prefixed_name
.get ());
10480 /* Template parameters may be specified in the DIE's DW_AT_name, or
10481 as children with DW_TAG_template_type_param or
10482 DW_TAG_value_type_param. If the latter, add them to the name
10483 here. If the name already has template parameters, then
10484 skip this step; some versions of GCC emit both, and
10485 it is more efficient to use the pre-computed name.
10487 Something to keep in mind about this process: it is very
10488 unlikely, or in some cases downright impossible, to produce
10489 something that will match the mangled name of a function.
10490 If the definition of the function has the same debug info,
10491 we should be able to match up with it anyway. But fallbacks
10492 using the minimal symbol, for instance to find a method
10493 implemented in a stripped copy of libstdc++, will not work.
10494 If we do not have debug info for the definition, we will have to
10495 match them up some other way.
10497 When we do name matching there is a related problem with function
10498 templates; two instantiated function templates are allowed to
10499 differ only by their return types, which we do not add here. */
10501 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
10503 struct attribute
*attr
;
10504 struct die_info
*child
;
10507 die
->building_fullname
= 1;
10509 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10513 const gdb_byte
*bytes
;
10514 struct dwarf2_locexpr_baton
*baton
;
10517 if (child
->tag
!= DW_TAG_template_type_param
10518 && child
->tag
!= DW_TAG_template_value_param
)
10529 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10532 complaint (_("template parameter missing DW_AT_type"));
10533 buf
.puts ("UNKNOWN_TYPE");
10536 type
= die_type (child
, cu
);
10538 if (child
->tag
== DW_TAG_template_type_param
)
10540 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
10541 &type_print_raw_options
);
10545 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10548 complaint (_("template parameter missing "
10549 "DW_AT_const_value"));
10550 buf
.puts ("UNKNOWN_VALUE");
10554 dwarf2_const_value_attr (attr
, type
, name
,
10555 &cu
->comp_unit_obstack
, cu
,
10556 &value
, &bytes
, &baton
);
10558 if (type
->has_no_signedness ())
10559 /* GDB prints characters as NUMBER 'CHAR'. If that's
10560 changed, this can use value_print instead. */
10561 cu
->language_defn
->printchar (value
, type
, &buf
);
10564 struct value_print_options opts
;
10567 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10571 baton
->per_objfile
);
10572 else if (bytes
!= NULL
)
10574 v
= allocate_value (type
);
10575 memcpy (value_contents_writeable (v
).data (), bytes
,
10576 TYPE_LENGTH (type
));
10579 v
= value_from_longest (type
, value
);
10581 /* Specify decimal so that we do not depend on
10583 get_formatted_print_options (&opts
, 'd');
10585 value_print (v
, &buf
, &opts
);
10590 die
->building_fullname
= 0;
10594 /* Close the argument list, with a space if necessary
10595 (nested templates). */
10596 if (!buf
.empty () && buf
.string ().back () == '>')
10603 /* For C++ methods, append formal parameter type
10604 information, if PHYSNAME. */
10606 if (physname
&& die
->tag
== DW_TAG_subprogram
10607 && lang
== language_cplus
)
10609 struct type
*type
= read_type_die (die
, cu
);
10611 c_type_print_args (type
, &buf
, 1, lang
,
10612 &type_print_raw_options
);
10614 if (lang
== language_cplus
)
10616 /* Assume that an artificial first parameter is
10617 "this", but do not crash if it is not. RealView
10618 marks unnamed (and thus unused) parameters as
10619 artificial; there is no way to differentiate
10621 if (type
->num_fields () > 0
10622 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10623 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10624 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10625 buf
.puts (" const");
10629 const std::string
&intermediate_name
= buf
.string ();
10631 if (lang
== language_cplus
)
10633 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10636 /* If we only computed INTERMEDIATE_NAME, or if
10637 INTERMEDIATE_NAME is already canonical, then we need to
10639 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10640 name
= objfile
->intern (intermediate_name
);
10642 name
= canonical_name
;
10649 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10650 If scope qualifiers are appropriate they will be added. The result
10651 will be allocated on the storage_obstack, or NULL if the DIE does
10652 not have a name. NAME may either be from a previous call to
10653 dwarf2_name or NULL.
10655 The output string will be canonicalized (if C++). */
10657 static const char *
10658 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10660 return dwarf2_compute_name (name
, die
, cu
, 0);
10663 /* Construct a physname for the given DIE in CU. NAME may either be
10664 from a previous call to dwarf2_name or NULL. The result will be
10665 allocated on the objfile_objstack or NULL if the DIE does not have a
10668 The output string will be canonicalized (if C++). */
10670 static const char *
10671 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10673 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10674 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10677 /* In this case dwarf2_compute_name is just a shortcut not building anything
10679 if (!die_needs_namespace (die
, cu
))
10680 return dwarf2_compute_name (name
, die
, cu
, 1);
10682 if (cu
->per_cu
->lang
!= language_rust
)
10683 mangled
= dw2_linkage_name (die
, cu
);
10685 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10687 gdb::unique_xmalloc_ptr
<char> demangled
;
10688 if (mangled
!= NULL
)
10690 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10692 /* Do nothing (do not demangle the symbol name). */
10696 /* Use DMGL_RET_DROP for C++ template functions to suppress
10697 their return type. It is easier for GDB users to search
10698 for such functions as `name(params)' than `long name(params)'.
10699 In such case the minimal symbol names do not match the full
10700 symbol names but for template functions there is never a need
10701 to look up their definition from their declaration so
10702 the only disadvantage remains the minimal symbol variant
10703 `long name(params)' does not have the proper inferior type. */
10704 demangled
= gdb_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
10708 canon
= demangled
.get ();
10716 if (canon
== NULL
|| check_physname
)
10718 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10720 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10722 /* It may not mean a bug in GDB. The compiler could also
10723 compute DW_AT_linkage_name incorrectly. But in such case
10724 GDB would need to be bug-to-bug compatible. */
10726 complaint (_("Computed physname <%s> does not match demangled <%s> "
10727 "(from linkage <%s>) - DIE at %s [in module %s]"),
10728 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10729 objfile_name (objfile
));
10731 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10732 is available here - over computed PHYSNAME. It is safer
10733 against both buggy GDB and buggy compilers. */
10747 retval
= objfile
->intern (retval
);
10752 /* Inspect DIE in CU for a namespace alias. If one exists, record
10753 a new symbol for it.
10755 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10758 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10760 struct attribute
*attr
;
10762 /* If the die does not have a name, this is not a namespace
10764 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10768 struct die_info
*d
= die
;
10769 struct dwarf2_cu
*imported_cu
= cu
;
10771 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10772 keep inspecting DIEs until we hit the underlying import. */
10773 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10774 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10776 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10780 d
= follow_die_ref (d
, attr
, &imported_cu
);
10781 if (d
->tag
!= DW_TAG_imported_declaration
)
10785 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10787 complaint (_("DIE at %s has too many recursively imported "
10788 "declarations"), sect_offset_str (d
->sect_off
));
10795 sect_offset sect_off
= attr
->get_ref_die_offset ();
10797 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10798 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10800 /* This declaration is a global namespace alias. Add
10801 a symbol for it whose type is the aliased namespace. */
10802 new_symbol (die
, type
, cu
);
10811 /* Return the using directives repository (global or local?) to use in the
10812 current context for CU.
10814 For Ada, imported declarations can materialize renamings, which *may* be
10815 global. However it is impossible (for now?) in DWARF to distinguish
10816 "external" imported declarations and "static" ones. As all imported
10817 declarations seem to be static in all other languages, make them all CU-wide
10818 global only in Ada. */
10820 static struct using_direct
**
10821 using_directives (struct dwarf2_cu
*cu
)
10823 if (cu
->per_cu
->lang
== language_ada
10824 && cu
->get_builder ()->outermost_context_p ())
10825 return cu
->get_builder ()->get_global_using_directives ();
10827 return cu
->get_builder ()->get_local_using_directives ();
10830 /* Read the import statement specified by the given die and record it. */
10833 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10835 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10836 struct attribute
*import_attr
;
10837 struct die_info
*imported_die
, *child_die
;
10838 struct dwarf2_cu
*imported_cu
;
10839 const char *imported_name
;
10840 const char *imported_name_prefix
;
10841 const char *canonical_name
;
10842 const char *import_alias
;
10843 const char *imported_declaration
= NULL
;
10844 const char *import_prefix
;
10845 std::vector
<const char *> excludes
;
10847 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10848 if (import_attr
== NULL
)
10850 complaint (_("Tag '%s' has no DW_AT_import"),
10851 dwarf_tag_name (die
->tag
));
10856 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10857 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10858 if (imported_name
== NULL
)
10860 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10862 The import in the following code:
10876 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10877 <52> DW_AT_decl_file : 1
10878 <53> DW_AT_decl_line : 6
10879 <54> DW_AT_import : <0x75>
10880 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10881 <59> DW_AT_name : B
10882 <5b> DW_AT_decl_file : 1
10883 <5c> DW_AT_decl_line : 2
10884 <5d> DW_AT_type : <0x6e>
10886 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10887 <76> DW_AT_byte_size : 4
10888 <77> DW_AT_encoding : 5 (signed)
10890 imports the wrong die ( 0x75 instead of 0x58 ).
10891 This case will be ignored until the gcc bug is fixed. */
10895 /* Figure out the local name after import. */
10896 import_alias
= dwarf2_name (die
, cu
);
10898 /* Figure out where the statement is being imported to. */
10899 import_prefix
= determine_prefix (die
, cu
);
10901 /* Figure out what the scope of the imported die is and prepend it
10902 to the name of the imported die. */
10903 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10905 if (imported_die
->tag
!= DW_TAG_namespace
10906 && imported_die
->tag
!= DW_TAG_module
)
10908 imported_declaration
= imported_name
;
10909 canonical_name
= imported_name_prefix
;
10911 else if (strlen (imported_name_prefix
) > 0)
10912 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10913 imported_name_prefix
,
10914 (cu
->per_cu
->lang
== language_d
10917 imported_name
, (char *) NULL
);
10919 canonical_name
= imported_name
;
10921 if (die
->tag
== DW_TAG_imported_module
10922 && cu
->per_cu
->lang
== language_fortran
)
10923 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10924 child_die
= child_die
->sibling
)
10926 /* DWARF-4: A Fortran use statement with a “rename list” may be
10927 represented by an imported module entry with an import attribute
10928 referring to the module and owned entries corresponding to those
10929 entities that are renamed as part of being imported. */
10931 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10933 complaint (_("child DW_TAG_imported_declaration expected "
10934 "- DIE at %s [in module %s]"),
10935 sect_offset_str (child_die
->sect_off
),
10936 objfile_name (objfile
));
10940 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10941 if (import_attr
== NULL
)
10943 complaint (_("Tag '%s' has no DW_AT_import"),
10944 dwarf_tag_name (child_die
->tag
));
10949 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10951 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10952 if (imported_name
== NULL
)
10954 complaint (_("child DW_TAG_imported_declaration has unknown "
10955 "imported name - DIE at %s [in module %s]"),
10956 sect_offset_str (child_die
->sect_off
),
10957 objfile_name (objfile
));
10961 excludes
.push_back (imported_name
);
10963 process_die (child_die
, cu
);
10966 add_using_directive (using_directives (cu
),
10970 imported_declaration
,
10973 &objfile
->objfile_obstack
);
10976 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10977 types, but gives them a size of zero. Starting with version 14,
10978 ICC is compatible with GCC. */
10981 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10983 if (!cu
->checked_producer
)
10984 check_producer (cu
);
10986 return cu
->producer_is_icc_lt_14
;
10989 /* ICC generates a DW_AT_type for C void functions. This was observed on
10990 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10991 which says that void functions should not have a DW_AT_type. */
10994 producer_is_icc (struct dwarf2_cu
*cu
)
10996 if (!cu
->checked_producer
)
10997 check_producer (cu
);
10999 return cu
->producer_is_icc
;
11002 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11003 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11004 this, it was first present in GCC release 4.3.0. */
11007 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11009 if (!cu
->checked_producer
)
11010 check_producer (cu
);
11012 return cu
->producer_is_gcc_lt_4_3
;
11015 static file_and_directory
&
11016 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11018 if (cu
->per_cu
->fnd
!= nullptr)
11019 return *cu
->per_cu
->fnd
;
11021 /* Find the filename. Do not use dwarf2_name here, since the filename
11022 is not a source language identifier. */
11023 file_and_directory
res (dwarf2_string_attr (die
, DW_AT_name
, cu
),
11024 dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
));
11026 if (res
.get_comp_dir () == nullptr
11027 && producer_is_gcc_lt_4_3 (cu
)
11028 && res
.get_name () != nullptr
11029 && IS_ABSOLUTE_PATH (res
.get_name ()))
11030 res
.set_comp_dir (ldirname (res
.get_name ()));
11032 cu
->per_cu
->fnd
.reset (new file_and_directory (std::move (res
)));
11033 return *cu
->per_cu
->fnd
;
11036 /* Handle DW_AT_stmt_list for a compilation unit.
11037 DIE is the DW_TAG_compile_unit die for CU.
11038 COMP_DIR is the compilation directory. LOWPC is passed to
11039 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11042 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11043 const file_and_directory
&fnd
, CORE_ADDR lowpc
) /* ARI: editCase function */
11045 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11046 struct attribute
*attr
;
11047 struct line_header line_header_local
;
11048 hashval_t line_header_local_hash
;
11050 int decode_mapping
;
11052 gdb_assert (! cu
->per_cu
->is_debug_types
);
11054 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11055 if (attr
== NULL
|| !attr
->form_is_unsigned ())
11058 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11060 /* The line header hash table is only created if needed (it exists to
11061 prevent redundant reading of the line table for partial_units).
11062 If we're given a partial_unit, we'll need it. If we're given a
11063 compile_unit, then use the line header hash table if it's already
11064 created, but don't create one just yet. */
11066 if (per_objfile
->line_header_hash
== NULL
11067 && die
->tag
== DW_TAG_partial_unit
)
11069 per_objfile
->line_header_hash
11070 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11071 line_header_eq_voidp
,
11072 htab_delete_entry
<line_header
>,
11076 line_header_local
.sect_off
= line_offset
;
11077 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11078 line_header_local_hash
= line_header_hash (&line_header_local
);
11079 if (per_objfile
->line_header_hash
!= NULL
)
11081 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11082 &line_header_local
,
11083 line_header_local_hash
, NO_INSERT
);
11085 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11086 is not present in *SLOT (since if there is something in *SLOT then
11087 it will be for a partial_unit). */
11088 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11090 gdb_assert (*slot
!= NULL
);
11091 cu
->line_header
= (struct line_header
*) *slot
;
11096 /* dwarf_decode_line_header does not yet provide sufficient information.
11097 We always have to call also dwarf_decode_lines for it. */
11098 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11102 cu
->line_header
= lh
.release ();
11103 cu
->line_header_die_owner
= die
;
11105 if (per_objfile
->line_header_hash
== NULL
)
11109 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11110 &line_header_local
,
11111 line_header_local_hash
, INSERT
);
11112 gdb_assert (slot
!= NULL
);
11114 if (slot
!= NULL
&& *slot
== NULL
)
11116 /* This newly decoded line number information unit will be owned
11117 by line_header_hash hash table. */
11118 *slot
= cu
->line_header
;
11119 cu
->line_header_die_owner
= NULL
;
11123 /* We cannot free any current entry in (*slot) as that struct line_header
11124 may be already used by multiple CUs. Create only temporary decoded
11125 line_header for this CU - it may happen at most once for each line
11126 number information unit. And if we're not using line_header_hash
11127 then this is what we want as well. */
11128 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11130 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11131 dwarf_decode_lines (cu
->line_header
, fnd
, cu
, nullptr, lowpc
,
11136 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11139 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11141 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11142 struct objfile
*objfile
= per_objfile
->objfile
;
11143 struct gdbarch
*gdbarch
= objfile
->arch ();
11144 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11145 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11146 struct attribute
*attr
;
11147 struct die_info
*child_die
;
11148 CORE_ADDR baseaddr
;
11150 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
11151 baseaddr
= objfile
->text_section_offset ();
11153 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11155 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11156 from finish_block. */
11157 if (lowpc
== ((CORE_ADDR
) -1))
11159 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11161 file_and_directory
&fnd
= find_file_and_directory (die
, cu
);
11163 cu
->start_compunit_symtab (fnd
.get_name (), fnd
.intern_comp_dir (objfile
),
11166 gdb_assert (per_objfile
->sym_cu
== nullptr);
11167 scoped_restore restore_sym_cu
11168 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
11170 /* Decode line number information if present. We do this before
11171 processing child DIEs, so that the line header table is available
11172 for DW_AT_decl_file. The PC check is here because, if LOWPC and
11173 HIGHPC are both 0x0, then there won't be any interesting code in
11174 the CU, but a check later on (in
11175 lnp_state_machine::check_line_address) will fail to properly
11176 exclude an entry that was removed via --gc-sections. */
11177 if (lowpc
!= highpc
)
11178 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
);
11180 /* Process all dies in compilation unit. */
11181 if (die
->child
!= NULL
)
11183 child_die
= die
->child
;
11184 while (child_die
&& child_die
->tag
)
11186 process_die (child_die
, cu
);
11187 child_die
= child_die
->sibling
;
11190 per_objfile
->sym_cu
= nullptr;
11192 /* Decode macro information, if present. Dwarf 2 macro information
11193 refers to information in the line number info statement program
11194 header, so we can only read it if we've read the header
11196 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11198 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11199 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11201 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11202 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11204 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
11208 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11209 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11211 unsigned int macro_offset
= attr
->as_unsigned ();
11213 dwarf_decode_macros (cu
, macro_offset
, 0);
11219 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11221 struct type_unit_group
*tu_group
;
11223 struct attribute
*attr
;
11225 struct signatured_type
*sig_type
;
11227 gdb_assert (per_cu
->is_debug_types
);
11228 sig_type
= (struct signatured_type
*) per_cu
;
11230 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11232 /* If we're using .gdb_index (includes -readnow) then
11233 per_cu->type_unit_group may not have been set up yet. */
11234 if (sig_type
->type_unit_group
== NULL
)
11235 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11236 tu_group
= sig_type
->type_unit_group
;
11238 /* If we've already processed this stmt_list there's no real need to
11239 do it again, we could fake it and just recreate the part we need
11240 (file name,index -> symtab mapping). If data shows this optimization
11241 is useful we can do it then. */
11242 type_unit_group_unshareable
*tug_unshare
11243 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11244 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11246 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11249 if (attr
!= NULL
&& attr
->form_is_unsigned ())
11251 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11252 lh
= dwarf_decode_line_header (line_offset
, this);
11257 start_compunit_symtab ("", NULL
, 0);
11260 gdb_assert (tug_unshare
->symtabs
== NULL
);
11261 gdb_assert (m_builder
== nullptr);
11262 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11263 m_builder
.reset (new struct buildsym_compunit
11264 (cust
->objfile (), "",
11266 compunit_language (cust
),
11268 list_in_scope
= get_builder ()->get_file_symbols ();
11273 line_header
= lh
.release ();
11274 line_header_die_owner
= die
;
11278 struct compunit_symtab
*cust
= start_compunit_symtab ("", NULL
, 0);
11280 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11281 still initializing it, and our caller (a few levels up)
11282 process_full_type_unit still needs to know if this is the first
11285 tug_unshare
->symtabs
11286 = XOBNEWVEC (&cust
->objfile ()->objfile_obstack
,
11287 struct symtab
*, line_header
->file_names_size ());
11289 auto &file_names
= line_header
->file_names ();
11290 for (i
= 0; i
< file_names
.size (); ++i
)
11292 file_entry
&fe
= file_names
[i
];
11293 dwarf2_start_subfile (this, fe
.name
,
11294 fe
.include_dir (line_header
));
11295 buildsym_compunit
*b
= get_builder ();
11296 if (b
->get_current_subfile ()->symtab
== NULL
)
11298 /* NOTE: start_subfile will recognize when it's been
11299 passed a file it has already seen. So we can't
11300 assume there's a simple mapping from
11301 cu->line_header->file_names to subfiles, plus
11302 cu->line_header->file_names may contain dups. */
11303 b
->get_current_subfile ()->symtab
11304 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11307 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11308 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11313 gdb_assert (m_builder
== nullptr);
11314 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11315 m_builder
.reset (new struct buildsym_compunit
11316 (cust
->objfile (), "",
11318 compunit_language (cust
),
11320 list_in_scope
= get_builder ()->get_file_symbols ();
11322 auto &file_names
= line_header
->file_names ();
11323 for (i
= 0; i
< file_names
.size (); ++i
)
11325 file_entry
&fe
= file_names
[i
];
11326 fe
.symtab
= tug_unshare
->symtabs
[i
];
11330 /* The main symtab is allocated last. Type units don't have DW_AT_name
11331 so they don't have a "real" (so to speak) symtab anyway.
11332 There is later code that will assign the main symtab to all symbols
11333 that don't have one. We need to handle the case of a symbol with a
11334 missing symtab (DW_AT_decl_file) anyway. */
11337 /* Process DW_TAG_type_unit.
11338 For TUs we want to skip the first top level sibling if it's not the
11339 actual type being defined by this TU. In this case the first top
11340 level sibling is there to provide context only. */
11343 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11345 struct die_info
*child_die
;
11347 prepare_one_comp_unit (cu
, die
, language_minimal
);
11349 /* Initialize (or reinitialize) the machinery for building symtabs.
11350 We do this before processing child DIEs, so that the line header table
11351 is available for DW_AT_decl_file. */
11352 cu
->setup_type_unit_groups (die
);
11354 if (die
->child
!= NULL
)
11356 child_die
= die
->child
;
11357 while (child_die
&& child_die
->tag
)
11359 process_die (child_die
, cu
);
11360 child_die
= child_die
->sibling
;
11367 http://gcc.gnu.org/wiki/DebugFission
11368 http://gcc.gnu.org/wiki/DebugFissionDWP
11370 To simplify handling of both DWO files ("object" files with the DWARF info)
11371 and DWP files (a file with the DWOs packaged up into one file), we treat
11372 DWP files as having a collection of virtual DWO files. */
11375 hash_dwo_file (const void *item
)
11377 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11380 hash
= htab_hash_string (dwo_file
->dwo_name
);
11381 if (dwo_file
->comp_dir
!= NULL
)
11382 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11387 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11389 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11390 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11392 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11394 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11395 return lhs
->comp_dir
== rhs
->comp_dir
;
11396 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11399 /* Allocate a hash table for DWO files. */
11402 allocate_dwo_file_hash_table ()
11404 return htab_up (htab_create_alloc (41,
11407 htab_delete_entry
<dwo_file
>,
11411 /* Lookup DWO file DWO_NAME. */
11414 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11415 const char *dwo_name
,
11416 const char *comp_dir
)
11418 struct dwo_file find_entry
;
11421 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11422 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11424 find_entry
.dwo_name
= dwo_name
;
11425 find_entry
.comp_dir
= comp_dir
;
11426 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11433 hash_dwo_unit (const void *item
)
11435 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11437 /* This drops the top 32 bits of the id, but is ok for a hash. */
11438 return dwo_unit
->signature
;
11442 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11444 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11445 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11447 /* The signature is assumed to be unique within the DWO file.
11448 So while object file CU dwo_id's always have the value zero,
11449 that's OK, assuming each object file DWO file has only one CU,
11450 and that's the rule for now. */
11451 return lhs
->signature
== rhs
->signature
;
11454 /* Allocate a hash table for DWO CUs,TUs.
11455 There is one of these tables for each of CUs,TUs for each DWO file. */
11458 allocate_dwo_unit_table ()
11460 /* Start out with a pretty small number.
11461 Generally DWO files contain only one CU and maybe some TUs. */
11462 return htab_up (htab_create_alloc (3,
11465 NULL
, xcalloc
, xfree
));
11468 /* die_reader_func for create_dwo_cu. */
11471 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11472 const gdb_byte
*info_ptr
,
11473 struct die_info
*comp_unit_die
,
11474 struct dwo_file
*dwo_file
,
11475 struct dwo_unit
*dwo_unit
)
11477 struct dwarf2_cu
*cu
= reader
->cu
;
11478 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11479 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11481 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11482 if (!signature
.has_value ())
11484 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11485 " its dwo_id [in module %s]"),
11486 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11490 dwo_unit
->dwo_file
= dwo_file
;
11491 dwo_unit
->signature
= *signature
;
11492 dwo_unit
->section
= section
;
11493 dwo_unit
->sect_off
= sect_off
;
11494 dwo_unit
->length
= cu
->per_cu
->length
;
11496 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11497 sect_offset_str (sect_off
),
11498 hex_string (dwo_unit
->signature
));
11501 /* Create the dwo_units for the CUs in a DWO_FILE.
11502 Note: This function processes DWO files only, not DWP files. */
11505 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11506 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11507 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11509 struct objfile
*objfile
= per_objfile
->objfile
;
11510 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11511 const gdb_byte
*info_ptr
, *end_ptr
;
11513 section
.read (objfile
);
11514 info_ptr
= section
.buffer
;
11516 if (info_ptr
== NULL
)
11519 dwarf_read_debug_printf ("Reading %s for %s:",
11520 section
.get_name (),
11521 section
.get_file_name ());
11523 end_ptr
= info_ptr
+ section
.size
;
11524 while (info_ptr
< end_ptr
)
11526 struct dwarf2_per_cu_data per_cu
;
11527 struct dwo_unit read_unit
{};
11528 struct dwo_unit
*dwo_unit
;
11530 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11532 per_cu
.per_bfd
= per_bfd
;
11533 per_cu
.is_debug_types
= 0;
11534 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11535 per_cu
.section
= §ion
;
11537 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11538 if (!reader
.dummy_p
)
11539 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11540 &dwo_file
, &read_unit
);
11541 info_ptr
+= per_cu
.length
;
11543 // If the unit could not be parsed, skip it.
11544 if (read_unit
.dwo_file
== NULL
)
11547 if (cus_htab
== NULL
)
11548 cus_htab
= allocate_dwo_unit_table ();
11550 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11552 *dwo_unit
= read_unit
;
11553 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11554 gdb_assert (slot
!= NULL
);
11557 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11558 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11560 complaint (_("debug cu entry at offset %s is duplicate to"
11561 " the entry at offset %s, signature %s"),
11562 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11563 hex_string (dwo_unit
->signature
));
11565 *slot
= (void *)dwo_unit
;
11569 /* DWP file .debug_{cu,tu}_index section format:
11570 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11571 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11573 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11574 officially standard DWP format was published with DWARF v5 and is called
11575 Version 5. There are no versions 3 or 4.
11579 Both index sections have the same format, and serve to map a 64-bit
11580 signature to a set of section numbers. Each section begins with a header,
11581 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11582 indexes, and a pool of 32-bit section numbers. The index sections will be
11583 aligned at 8-byte boundaries in the file.
11585 The index section header consists of:
11587 V, 32 bit version number
11589 N, 32 bit number of compilation units or type units in the index
11590 M, 32 bit number of slots in the hash table
11592 Numbers are recorded using the byte order of the application binary.
11594 The hash table begins at offset 16 in the section, and consists of an array
11595 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11596 order of the application binary). Unused slots in the hash table are 0.
11597 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11599 The parallel table begins immediately after the hash table
11600 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11601 array of 32-bit indexes (using the byte order of the application binary),
11602 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11603 table contains a 32-bit index into the pool of section numbers. For unused
11604 hash table slots, the corresponding entry in the parallel table will be 0.
11606 The pool of section numbers begins immediately following the hash table
11607 (at offset 16 + 12 * M from the beginning of the section). The pool of
11608 section numbers consists of an array of 32-bit words (using the byte order
11609 of the application binary). Each item in the array is indexed starting
11610 from 0. The hash table entry provides the index of the first section
11611 number in the set. Additional section numbers in the set follow, and the
11612 set is terminated by a 0 entry (section number 0 is not used in ELF).
11614 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11615 section must be the first entry in the set, and the .debug_abbrev.dwo must
11616 be the second entry. Other members of the set may follow in any order.
11620 DWP Versions 2 and 5:
11622 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11623 and the entries in the index tables are now offsets into these sections.
11624 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11627 Index Section Contents:
11629 Hash Table of Signatures dwp_hash_table.hash_table
11630 Parallel Table of Indices dwp_hash_table.unit_table
11631 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11632 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11634 The index section header consists of:
11636 V, 32 bit version number
11637 L, 32 bit number of columns in the table of section offsets
11638 N, 32 bit number of compilation units or type units in the index
11639 M, 32 bit number of slots in the hash table
11641 Numbers are recorded using the byte order of the application binary.
11643 The hash table has the same format as version 1.
11644 The parallel table of indices has the same format as version 1,
11645 except that the entries are origin-1 indices into the table of sections
11646 offsets and the table of section sizes.
11648 The table of offsets begins immediately following the parallel table
11649 (at offset 16 + 12 * M from the beginning of the section). The table is
11650 a two-dimensional array of 32-bit words (using the byte order of the
11651 application binary), with L columns and N+1 rows, in row-major order.
11652 Each row in the array is indexed starting from 0. The first row provides
11653 a key to the remaining rows: each column in this row provides an identifier
11654 for a debug section, and the offsets in the same column of subsequent rows
11655 refer to that section. The section identifiers for Version 2 are:
11657 DW_SECT_INFO 1 .debug_info.dwo
11658 DW_SECT_TYPES 2 .debug_types.dwo
11659 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11660 DW_SECT_LINE 4 .debug_line.dwo
11661 DW_SECT_LOC 5 .debug_loc.dwo
11662 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11663 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11664 DW_SECT_MACRO 8 .debug_macro.dwo
11666 The section identifiers for Version 5 are:
11668 DW_SECT_INFO_V5 1 .debug_info.dwo
11669 DW_SECT_RESERVED_V5 2 --
11670 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11671 DW_SECT_LINE_V5 4 .debug_line.dwo
11672 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11673 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11674 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11675 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11677 The offsets provided by the CU and TU index sections are the base offsets
11678 for the contributions made by each CU or TU to the corresponding section
11679 in the package file. Each CU and TU header contains an abbrev_offset
11680 field, used to find the abbreviations table for that CU or TU within the
11681 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11682 be interpreted as relative to the base offset given in the index section.
11683 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11684 should be interpreted as relative to the base offset for .debug_line.dwo,
11685 and offsets into other debug sections obtained from DWARF attributes should
11686 also be interpreted as relative to the corresponding base offset.
11688 The table of sizes begins immediately following the table of offsets.
11689 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11690 with L columns and N rows, in row-major order. Each row in the array is
11691 indexed starting from 1 (row 0 is shared by the two tables).
11695 Hash table lookup is handled the same in version 1 and 2:
11697 We assume that N and M will not exceed 2^32 - 1.
11698 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11700 Given a 64-bit compilation unit signature or a type signature S, an entry
11701 in the hash table is located as follows:
11703 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11704 the low-order k bits all set to 1.
11706 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11708 3) If the hash table entry at index H matches the signature, use that
11709 entry. If the hash table entry at index H is unused (all zeroes),
11710 terminate the search: the signature is not present in the table.
11712 4) Let H = (H + H') modulo M. Repeat at Step 3.
11714 Because M > N and H' and M are relatively prime, the search is guaranteed
11715 to stop at an unused slot or find the match. */
11717 /* Create a hash table to map DWO IDs to their CU/TU entry in
11718 .debug_{info,types}.dwo in DWP_FILE.
11719 Returns NULL if there isn't one.
11720 Note: This function processes DWP files only, not DWO files. */
11722 static struct dwp_hash_table
*
11723 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11724 struct dwp_file
*dwp_file
, int is_debug_types
)
11726 struct objfile
*objfile
= per_objfile
->objfile
;
11727 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11728 const gdb_byte
*index_ptr
, *index_end
;
11729 struct dwarf2_section_info
*index
;
11730 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11731 struct dwp_hash_table
*htab
;
11733 if (is_debug_types
)
11734 index
= &dwp_file
->sections
.tu_index
;
11736 index
= &dwp_file
->sections
.cu_index
;
11738 if (index
->empty ())
11740 index
->read (objfile
);
11742 index_ptr
= index
->buffer
;
11743 index_end
= index_ptr
+ index
->size
;
11745 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11746 For now it's safe to just read 4 bytes (particularly as it's difficult to
11747 tell if you're dealing with Version 5 before you've read the version). */
11748 version
= read_4_bytes (dbfd
, index_ptr
);
11750 if (version
== 2 || version
== 5)
11751 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11755 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11757 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11760 if (version
!= 1 && version
!= 2 && version
!= 5)
11762 error (_("Dwarf Error: unsupported DWP file version (%s)"
11763 " [in module %s]"),
11764 pulongest (version
), dwp_file
->name
);
11766 if (nr_slots
!= (nr_slots
& -nr_slots
))
11768 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11769 " is not power of 2 [in module %s]"),
11770 pulongest (nr_slots
), dwp_file
->name
);
11773 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11774 htab
->version
= version
;
11775 htab
->nr_columns
= nr_columns
;
11776 htab
->nr_units
= nr_units
;
11777 htab
->nr_slots
= nr_slots
;
11778 htab
->hash_table
= index_ptr
;
11779 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11781 /* Exit early if the table is empty. */
11782 if (nr_slots
== 0 || nr_units
== 0
11783 || (version
== 2 && nr_columns
== 0)
11784 || (version
== 5 && nr_columns
== 0))
11786 /* All must be zero. */
11787 if (nr_slots
!= 0 || nr_units
!= 0
11788 || (version
== 2 && nr_columns
!= 0)
11789 || (version
== 5 && nr_columns
!= 0))
11791 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11792 " all zero [in modules %s]"),
11800 htab
->section_pool
.v1
.indices
=
11801 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11802 /* It's harder to decide whether the section is too small in v1.
11803 V1 is deprecated anyway so we punt. */
11805 else if (version
== 2)
11807 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11808 int *ids
= htab
->section_pool
.v2
.section_ids
;
11809 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11810 /* Reverse map for error checking. */
11811 int ids_seen
[DW_SECT_MAX
+ 1];
11814 if (nr_columns
< 2)
11816 error (_("Dwarf Error: bad DWP hash table, too few columns"
11817 " in section table [in module %s]"),
11820 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11822 error (_("Dwarf Error: bad DWP hash table, too many columns"
11823 " in section table [in module %s]"),
11826 memset (ids
, 255, sizeof_ids
);
11827 memset (ids_seen
, 255, sizeof (ids_seen
));
11828 for (i
= 0; i
< nr_columns
; ++i
)
11830 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11832 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11834 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11835 " in section table [in module %s]"),
11836 id
, dwp_file
->name
);
11838 if (ids_seen
[id
] != -1)
11840 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11841 " id %d in section table [in module %s]"),
11842 id
, dwp_file
->name
);
11847 /* Must have exactly one info or types section. */
11848 if (((ids_seen
[DW_SECT_INFO
] != -1)
11849 + (ids_seen
[DW_SECT_TYPES
] != -1))
11852 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11853 " DWO info/types section [in module %s]"),
11856 /* Must have an abbrev section. */
11857 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11859 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11860 " section [in module %s]"),
11863 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11864 htab
->section_pool
.v2
.sizes
=
11865 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11866 * nr_units
* nr_columns
);
11867 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11868 * nr_units
* nr_columns
))
11871 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11872 " [in module %s]"),
11876 else /* version == 5 */
11878 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11879 int *ids
= htab
->section_pool
.v5
.section_ids
;
11880 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11881 /* Reverse map for error checking. */
11882 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11884 if (nr_columns
< 2)
11886 error (_("Dwarf Error: bad DWP hash table, too few columns"
11887 " in section table [in module %s]"),
11890 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11892 error (_("Dwarf Error: bad DWP hash table, too many columns"
11893 " in section table [in module %s]"),
11896 memset (ids
, 255, sizeof_ids
);
11897 memset (ids_seen
, 255, sizeof (ids_seen
));
11898 for (int i
= 0; i
< nr_columns
; ++i
)
11900 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11902 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11904 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11905 " in section table [in module %s]"),
11906 id
, dwp_file
->name
);
11908 if (ids_seen
[id
] != -1)
11910 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11911 " id %d in section table [in module %s]"),
11912 id
, dwp_file
->name
);
11917 /* Must have seen an info section. */
11918 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11920 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11921 " DWO info/types section [in module %s]"),
11924 /* Must have an abbrev section. */
11925 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11927 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11928 " section [in module %s]"),
11931 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11932 htab
->section_pool
.v5
.sizes
11933 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11934 * nr_units
* nr_columns
);
11935 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11936 * nr_units
* nr_columns
))
11939 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11940 " [in module %s]"),
11948 /* Update SECTIONS with the data from SECTP.
11950 This function is like the other "locate" section routines, but in
11951 this context the sections to read comes from the DWP V1 hash table,
11952 not the full ELF section table.
11954 The result is non-zero for success, or zero if an error was found. */
11957 locate_v1_virtual_dwo_sections (asection
*sectp
,
11958 struct virtual_v1_dwo_sections
*sections
)
11960 const struct dwop_section_names
*names
= &dwop_section_names
;
11962 if (names
->abbrev_dwo
.matches (sectp
->name
))
11964 /* There can be only one. */
11965 if (sections
->abbrev
.s
.section
!= NULL
)
11967 sections
->abbrev
.s
.section
= sectp
;
11968 sections
->abbrev
.size
= bfd_section_size (sectp
);
11970 else if (names
->info_dwo
.matches (sectp
->name
)
11971 || names
->types_dwo
.matches (sectp
->name
))
11973 /* There can be only one. */
11974 if (sections
->info_or_types
.s
.section
!= NULL
)
11976 sections
->info_or_types
.s
.section
= sectp
;
11977 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11979 else if (names
->line_dwo
.matches (sectp
->name
))
11981 /* There can be only one. */
11982 if (sections
->line
.s
.section
!= NULL
)
11984 sections
->line
.s
.section
= sectp
;
11985 sections
->line
.size
= bfd_section_size (sectp
);
11987 else if (names
->loc_dwo
.matches (sectp
->name
))
11989 /* There can be only one. */
11990 if (sections
->loc
.s
.section
!= NULL
)
11992 sections
->loc
.s
.section
= sectp
;
11993 sections
->loc
.size
= bfd_section_size (sectp
);
11995 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11997 /* There can be only one. */
11998 if (sections
->macinfo
.s
.section
!= NULL
)
12000 sections
->macinfo
.s
.section
= sectp
;
12001 sections
->macinfo
.size
= bfd_section_size (sectp
);
12003 else if (names
->macro_dwo
.matches (sectp
->name
))
12005 /* There can be only one. */
12006 if (sections
->macro
.s
.section
!= NULL
)
12008 sections
->macro
.s
.section
= sectp
;
12009 sections
->macro
.size
= bfd_section_size (sectp
);
12011 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12013 /* There can be only one. */
12014 if (sections
->str_offsets
.s
.section
!= NULL
)
12016 sections
->str_offsets
.s
.section
= sectp
;
12017 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12021 /* No other kind of section is valid. */
12028 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12029 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12030 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12031 This is for DWP version 1 files. */
12033 static struct dwo_unit
*
12034 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
12035 struct dwp_file
*dwp_file
,
12036 uint32_t unit_index
,
12037 const char *comp_dir
,
12038 ULONGEST signature
, int is_debug_types
)
12040 const struct dwp_hash_table
*dwp_htab
=
12041 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12042 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12043 const char *kind
= is_debug_types
? "TU" : "CU";
12044 struct dwo_file
*dwo_file
;
12045 struct dwo_unit
*dwo_unit
;
12046 struct virtual_v1_dwo_sections sections
;
12047 void **dwo_file_slot
;
12050 gdb_assert (dwp_file
->version
== 1);
12052 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
12053 kind
, pulongest (unit_index
), hex_string (signature
),
12056 /* Fetch the sections of this DWO unit.
12057 Put a limit on the number of sections we look for so that bad data
12058 doesn't cause us to loop forever. */
12060 #define MAX_NR_V1_DWO_SECTIONS \
12061 (1 /* .debug_info or .debug_types */ \
12062 + 1 /* .debug_abbrev */ \
12063 + 1 /* .debug_line */ \
12064 + 1 /* .debug_loc */ \
12065 + 1 /* .debug_str_offsets */ \
12066 + 1 /* .debug_macro or .debug_macinfo */ \
12067 + 1 /* trailing zero */)
12069 memset (§ions
, 0, sizeof (sections
));
12071 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12074 uint32_t section_nr
=
12075 read_4_bytes (dbfd
,
12076 dwp_htab
->section_pool
.v1
.indices
12077 + (unit_index
+ i
) * sizeof (uint32_t));
12079 if (section_nr
== 0)
12081 if (section_nr
>= dwp_file
->num_sections
)
12083 error (_("Dwarf Error: bad DWP hash table, section number too large"
12084 " [in module %s]"),
12088 sectp
= dwp_file
->elf_sections
[section_nr
];
12089 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12091 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12092 " [in module %s]"),
12098 || sections
.info_or_types
.empty ()
12099 || sections
.abbrev
.empty ())
12101 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12102 " [in module %s]"),
12105 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12107 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12108 " [in module %s]"),
12112 /* It's easier for the rest of the code if we fake a struct dwo_file and
12113 have dwo_unit "live" in that. At least for now.
12115 The DWP file can be made up of a random collection of CUs and TUs.
12116 However, for each CU + set of TUs that came from the same original DWO
12117 file, we can combine them back into a virtual DWO file to save space
12118 (fewer struct dwo_file objects to allocate). Remember that for really
12119 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12121 std::string virtual_dwo_name
=
12122 string_printf ("virtual-dwo/%d-%d-%d-%d",
12123 sections
.abbrev
.get_id (),
12124 sections
.line
.get_id (),
12125 sections
.loc
.get_id (),
12126 sections
.str_offsets
.get_id ());
12127 /* Can we use an existing virtual DWO file? */
12128 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12130 /* Create one if necessary. */
12131 if (*dwo_file_slot
== NULL
)
12133 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12134 virtual_dwo_name
.c_str ());
12136 dwo_file
= new struct dwo_file
;
12137 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12138 dwo_file
->comp_dir
= comp_dir
;
12139 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12140 dwo_file
->sections
.line
= sections
.line
;
12141 dwo_file
->sections
.loc
= sections
.loc
;
12142 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12143 dwo_file
->sections
.macro
= sections
.macro
;
12144 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12145 /* The "str" section is global to the entire DWP file. */
12146 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12147 /* The info or types section is assigned below to dwo_unit,
12148 there's no need to record it in dwo_file.
12149 Also, we can't simply record type sections in dwo_file because
12150 we record a pointer into the vector in dwo_unit. As we collect more
12151 types we'll grow the vector and eventually have to reallocate space
12152 for it, invalidating all copies of pointers into the previous
12154 *dwo_file_slot
= dwo_file
;
12158 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12159 virtual_dwo_name
.c_str ());
12161 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12164 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12165 dwo_unit
->dwo_file
= dwo_file
;
12166 dwo_unit
->signature
= signature
;
12167 dwo_unit
->section
=
12168 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12169 *dwo_unit
->section
= sections
.info_or_types
;
12170 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12175 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12176 simplify them. Given a pointer to the containing section SECTION, and
12177 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12178 virtual section of just that piece. */
12180 static struct dwarf2_section_info
12181 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12182 struct dwarf2_section_info
*section
,
12183 bfd_size_type offset
, bfd_size_type size
)
12185 struct dwarf2_section_info result
;
12188 gdb_assert (section
!= NULL
);
12189 gdb_assert (!section
->is_virtual
);
12191 memset (&result
, 0, sizeof (result
));
12192 result
.s
.containing_section
= section
;
12193 result
.is_virtual
= true;
12198 sectp
= section
->get_bfd_section ();
12200 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12201 bounds of the real section. This is a pretty-rare event, so just
12202 flag an error (easier) instead of a warning and trying to cope. */
12204 || offset
+ size
> bfd_section_size (sectp
))
12206 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12207 " in section %s [in module %s]"),
12208 sectp
? bfd_section_name (sectp
) : "<unknown>",
12209 objfile_name (per_objfile
->objfile
));
12212 result
.virtual_offset
= offset
;
12213 result
.size
= size
;
12217 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12218 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12219 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12220 This is for DWP version 2 files. */
12222 static struct dwo_unit
*
12223 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12224 struct dwp_file
*dwp_file
,
12225 uint32_t unit_index
,
12226 const char *comp_dir
,
12227 ULONGEST signature
, int is_debug_types
)
12229 const struct dwp_hash_table
*dwp_htab
=
12230 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12231 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12232 const char *kind
= is_debug_types
? "TU" : "CU";
12233 struct dwo_file
*dwo_file
;
12234 struct dwo_unit
*dwo_unit
;
12235 struct virtual_v2_or_v5_dwo_sections sections
;
12236 void **dwo_file_slot
;
12239 gdb_assert (dwp_file
->version
== 2);
12241 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
12242 kind
, pulongest (unit_index
), hex_string (signature
),
12245 /* Fetch the section offsets of this DWO unit. */
12247 memset (§ions
, 0, sizeof (sections
));
12249 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12251 uint32_t offset
= read_4_bytes (dbfd
,
12252 dwp_htab
->section_pool
.v2
.offsets
12253 + (((unit_index
- 1) * dwp_htab
->nr_columns
12255 * sizeof (uint32_t)));
12256 uint32_t size
= read_4_bytes (dbfd
,
12257 dwp_htab
->section_pool
.v2
.sizes
12258 + (((unit_index
- 1) * dwp_htab
->nr_columns
12260 * sizeof (uint32_t)));
12262 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12265 case DW_SECT_TYPES
:
12266 sections
.info_or_types_offset
= offset
;
12267 sections
.info_or_types_size
= size
;
12269 case DW_SECT_ABBREV
:
12270 sections
.abbrev_offset
= offset
;
12271 sections
.abbrev_size
= size
;
12274 sections
.line_offset
= offset
;
12275 sections
.line_size
= size
;
12278 sections
.loc_offset
= offset
;
12279 sections
.loc_size
= size
;
12281 case DW_SECT_STR_OFFSETS
:
12282 sections
.str_offsets_offset
= offset
;
12283 sections
.str_offsets_size
= size
;
12285 case DW_SECT_MACINFO
:
12286 sections
.macinfo_offset
= offset
;
12287 sections
.macinfo_size
= size
;
12289 case DW_SECT_MACRO
:
12290 sections
.macro_offset
= offset
;
12291 sections
.macro_size
= size
;
12296 /* It's easier for the rest of the code if we fake a struct dwo_file and
12297 have dwo_unit "live" in that. At least for now.
12299 The DWP file can be made up of a random collection of CUs and TUs.
12300 However, for each CU + set of TUs that came from the same original DWO
12301 file, we can combine them back into a virtual DWO file to save space
12302 (fewer struct dwo_file objects to allocate). Remember that for really
12303 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12305 std::string virtual_dwo_name
=
12306 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12307 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12308 (long) (sections
.line_size
? sections
.line_offset
: 0),
12309 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12310 (long) (sections
.str_offsets_size
12311 ? sections
.str_offsets_offset
: 0));
12312 /* Can we use an existing virtual DWO file? */
12313 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12315 /* Create one if necessary. */
12316 if (*dwo_file_slot
== NULL
)
12318 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12319 virtual_dwo_name
.c_str ());
12321 dwo_file
= new struct dwo_file
;
12322 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12323 dwo_file
->comp_dir
= comp_dir
;
12324 dwo_file
->sections
.abbrev
=
12325 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12326 sections
.abbrev_offset
,
12327 sections
.abbrev_size
);
12328 dwo_file
->sections
.line
=
12329 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12330 sections
.line_offset
,
12331 sections
.line_size
);
12332 dwo_file
->sections
.loc
=
12333 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12334 sections
.loc_offset
, sections
.loc_size
);
12335 dwo_file
->sections
.macinfo
=
12336 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12337 sections
.macinfo_offset
,
12338 sections
.macinfo_size
);
12339 dwo_file
->sections
.macro
=
12340 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12341 sections
.macro_offset
,
12342 sections
.macro_size
);
12343 dwo_file
->sections
.str_offsets
=
12344 create_dwp_v2_or_v5_section (per_objfile
,
12345 &dwp_file
->sections
.str_offsets
,
12346 sections
.str_offsets_offset
,
12347 sections
.str_offsets_size
);
12348 /* The "str" section is global to the entire DWP file. */
12349 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12350 /* The info or types section is assigned below to dwo_unit,
12351 there's no need to record it in dwo_file.
12352 Also, we can't simply record type sections in dwo_file because
12353 we record a pointer into the vector in dwo_unit. As we collect more
12354 types we'll grow the vector and eventually have to reallocate space
12355 for it, invalidating all copies of pointers into the previous
12357 *dwo_file_slot
= dwo_file
;
12361 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12362 virtual_dwo_name
.c_str ());
12364 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12367 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12368 dwo_unit
->dwo_file
= dwo_file
;
12369 dwo_unit
->signature
= signature
;
12370 dwo_unit
->section
=
12371 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12372 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12375 ? &dwp_file
->sections
.types
12376 : &dwp_file
->sections
.info
,
12377 sections
.info_or_types_offset
,
12378 sections
.info_or_types_size
);
12379 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12384 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12385 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12386 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12387 This is for DWP version 5 files. */
12389 static struct dwo_unit
*
12390 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12391 struct dwp_file
*dwp_file
,
12392 uint32_t unit_index
,
12393 const char *comp_dir
,
12394 ULONGEST signature
, int is_debug_types
)
12396 const struct dwp_hash_table
*dwp_htab
12397 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12398 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12399 const char *kind
= is_debug_types
? "TU" : "CU";
12400 struct dwo_file
*dwo_file
;
12401 struct dwo_unit
*dwo_unit
;
12402 struct virtual_v2_or_v5_dwo_sections sections
{};
12403 void **dwo_file_slot
;
12405 gdb_assert (dwp_file
->version
== 5);
12407 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12408 kind
, pulongest (unit_index
), hex_string (signature
),
12411 /* Fetch the section offsets of this DWO unit. */
12413 /* memset (§ions, 0, sizeof (sections)); */
12415 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12417 uint32_t offset
= read_4_bytes (dbfd
,
12418 dwp_htab
->section_pool
.v5
.offsets
12419 + (((unit_index
- 1)
12420 * dwp_htab
->nr_columns
12422 * sizeof (uint32_t)));
12423 uint32_t size
= read_4_bytes (dbfd
,
12424 dwp_htab
->section_pool
.v5
.sizes
12425 + (((unit_index
- 1) * dwp_htab
->nr_columns
12427 * sizeof (uint32_t)));
12429 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12431 case DW_SECT_ABBREV_V5
:
12432 sections
.abbrev_offset
= offset
;
12433 sections
.abbrev_size
= size
;
12435 case DW_SECT_INFO_V5
:
12436 sections
.info_or_types_offset
= offset
;
12437 sections
.info_or_types_size
= size
;
12439 case DW_SECT_LINE_V5
:
12440 sections
.line_offset
= offset
;
12441 sections
.line_size
= size
;
12443 case DW_SECT_LOCLISTS_V5
:
12444 sections
.loclists_offset
= offset
;
12445 sections
.loclists_size
= size
;
12447 case DW_SECT_MACRO_V5
:
12448 sections
.macro_offset
= offset
;
12449 sections
.macro_size
= size
;
12451 case DW_SECT_RNGLISTS_V5
:
12452 sections
.rnglists_offset
= offset
;
12453 sections
.rnglists_size
= size
;
12455 case DW_SECT_STR_OFFSETS_V5
:
12456 sections
.str_offsets_offset
= offset
;
12457 sections
.str_offsets_size
= size
;
12459 case DW_SECT_RESERVED_V5
:
12465 /* It's easier for the rest of the code if we fake a struct dwo_file and
12466 have dwo_unit "live" in that. At least for now.
12468 The DWP file can be made up of a random collection of CUs and TUs.
12469 However, for each CU + set of TUs that came from the same original DWO
12470 file, we can combine them back into a virtual DWO file to save space
12471 (fewer struct dwo_file objects to allocate). Remember that for really
12472 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12474 std::string virtual_dwo_name
=
12475 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12476 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12477 (long) (sections
.line_size
? sections
.line_offset
: 0),
12478 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12479 (long) (sections
.str_offsets_size
12480 ? sections
.str_offsets_offset
: 0),
12481 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12482 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12483 /* Can we use an existing virtual DWO file? */
12484 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12485 virtual_dwo_name
.c_str (),
12487 /* Create one if necessary. */
12488 if (*dwo_file_slot
== NULL
)
12490 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12491 virtual_dwo_name
.c_str ());
12493 dwo_file
= new struct dwo_file
;
12494 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12495 dwo_file
->comp_dir
= comp_dir
;
12496 dwo_file
->sections
.abbrev
=
12497 create_dwp_v2_or_v5_section (per_objfile
,
12498 &dwp_file
->sections
.abbrev
,
12499 sections
.abbrev_offset
,
12500 sections
.abbrev_size
);
12501 dwo_file
->sections
.line
=
12502 create_dwp_v2_or_v5_section (per_objfile
,
12503 &dwp_file
->sections
.line
,
12504 sections
.line_offset
, sections
.line_size
);
12505 dwo_file
->sections
.macro
=
12506 create_dwp_v2_or_v5_section (per_objfile
,
12507 &dwp_file
->sections
.macro
,
12508 sections
.macro_offset
,
12509 sections
.macro_size
);
12510 dwo_file
->sections
.loclists
=
12511 create_dwp_v2_or_v5_section (per_objfile
,
12512 &dwp_file
->sections
.loclists
,
12513 sections
.loclists_offset
,
12514 sections
.loclists_size
);
12515 dwo_file
->sections
.rnglists
=
12516 create_dwp_v2_or_v5_section (per_objfile
,
12517 &dwp_file
->sections
.rnglists
,
12518 sections
.rnglists_offset
,
12519 sections
.rnglists_size
);
12520 dwo_file
->sections
.str_offsets
=
12521 create_dwp_v2_or_v5_section (per_objfile
,
12522 &dwp_file
->sections
.str_offsets
,
12523 sections
.str_offsets_offset
,
12524 sections
.str_offsets_size
);
12525 /* The "str" section is global to the entire DWP file. */
12526 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12527 /* The info or types section is assigned below to dwo_unit,
12528 there's no need to record it in dwo_file.
12529 Also, we can't simply record type sections in dwo_file because
12530 we record a pointer into the vector in dwo_unit. As we collect more
12531 types we'll grow the vector and eventually have to reallocate space
12532 for it, invalidating all copies of pointers into the previous
12534 *dwo_file_slot
= dwo_file
;
12538 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12539 virtual_dwo_name
.c_str ());
12541 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12544 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12545 dwo_unit
->dwo_file
= dwo_file
;
12546 dwo_unit
->signature
= signature
;
12548 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12549 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12550 &dwp_file
->sections
.info
,
12551 sections
.info_or_types_offset
,
12552 sections
.info_or_types_size
);
12553 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12558 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12559 Returns NULL if the signature isn't found. */
12561 static struct dwo_unit
*
12562 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12563 struct dwp_file
*dwp_file
, const char *comp_dir
,
12564 ULONGEST signature
, int is_debug_types
)
12566 const struct dwp_hash_table
*dwp_htab
=
12567 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12568 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12569 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12570 uint32_t hash
= signature
& mask
;
12571 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12574 struct dwo_unit find_dwo_cu
;
12576 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12577 find_dwo_cu
.signature
= signature
;
12578 slot
= htab_find_slot (is_debug_types
12579 ? dwp_file
->loaded_tus
.get ()
12580 : dwp_file
->loaded_cus
.get (),
12581 &find_dwo_cu
, INSERT
);
12584 return (struct dwo_unit
*) *slot
;
12586 /* Use a for loop so that we don't loop forever on bad debug info. */
12587 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12589 ULONGEST signature_in_table
;
12591 signature_in_table
=
12592 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12593 if (signature_in_table
== signature
)
12595 uint32_t unit_index
=
12596 read_4_bytes (dbfd
,
12597 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12599 if (dwp_file
->version
== 1)
12601 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12602 unit_index
, comp_dir
,
12603 signature
, is_debug_types
);
12605 else if (dwp_file
->version
== 2)
12607 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12608 unit_index
, comp_dir
,
12609 signature
, is_debug_types
);
12611 else /* version == 5 */
12613 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12614 unit_index
, comp_dir
,
12615 signature
, is_debug_types
);
12617 return (struct dwo_unit
*) *slot
;
12619 if (signature_in_table
== 0)
12621 hash
= (hash
+ hash2
) & mask
;
12624 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12625 " [in module %s]"),
12629 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12630 Open the file specified by FILE_NAME and hand it off to BFD for
12631 preliminary analysis. Return a newly initialized bfd *, which
12632 includes a canonicalized copy of FILE_NAME.
12633 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12634 SEARCH_CWD is true if the current directory is to be searched.
12635 It will be searched before debug-file-directory.
12636 If successful, the file is added to the bfd include table of the
12637 objfile's bfd (see gdb_bfd_record_inclusion).
12638 If unable to find/open the file, return NULL.
12639 NOTE: This function is derived from symfile_bfd_open. */
12641 static gdb_bfd_ref_ptr
12642 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12643 const char *file_name
, int is_dwp
, int search_cwd
)
12646 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12647 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12648 to debug_file_directory. */
12649 const char *search_path
;
12650 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12652 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12655 if (!debug_file_directory
.empty ())
12657 search_path_holder
.reset (concat (".", dirname_separator_string
,
12658 debug_file_directory
.c_str (),
12660 search_path
= search_path_holder
.get ();
12666 search_path
= debug_file_directory
.c_str ();
12668 /* Add the path for the executable binary to the list of search paths. */
12669 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12670 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12671 dirname_separator_string
,
12672 search_path
, nullptr));
12673 search_path
= search_path_holder
.get ();
12675 openp_flags flags
= OPF_RETURN_REALPATH
;
12677 flags
|= OPF_SEARCH_IN_PATH
;
12679 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12680 desc
= openp (search_path
, flags
, file_name
,
12681 O_RDONLY
| O_BINARY
, &absolute_name
);
12685 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12687 if (sym_bfd
== NULL
)
12689 bfd_set_cacheable (sym_bfd
.get (), 1);
12691 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12694 /* Success. Record the bfd as having been included by the objfile's bfd.
12695 This is important because things like demangled_names_hash lives in the
12696 objfile's per_bfd space and may have references to things like symbol
12697 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12698 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12703 /* Try to open DWO file FILE_NAME.
12704 COMP_DIR is the DW_AT_comp_dir attribute.
12705 The result is the bfd handle of the file.
12706 If there is a problem finding or opening the file, return NULL.
12707 Upon success, the canonicalized path of the file is stored in the bfd,
12708 same as symfile_bfd_open. */
12710 static gdb_bfd_ref_ptr
12711 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12712 const char *file_name
, const char *comp_dir
)
12714 if (IS_ABSOLUTE_PATH (file_name
))
12715 return try_open_dwop_file (per_objfile
, file_name
,
12716 0 /*is_dwp*/, 0 /*search_cwd*/);
12718 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12720 if (comp_dir
!= NULL
)
12722 gdb::unique_xmalloc_ptr
<char> path_to_try
12723 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12725 /* NOTE: If comp_dir is a relative path, this will also try the
12726 search path, which seems useful. */
12727 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12729 1 /*search_cwd*/));
12734 /* That didn't work, try debug-file-directory, which, despite its name,
12735 is a list of paths. */
12737 if (debug_file_directory
.empty ())
12740 return try_open_dwop_file (per_objfile
, file_name
,
12741 0 /*is_dwp*/, 1 /*search_cwd*/);
12744 /* This function is mapped across the sections and remembers the offset and
12745 size of each of the DWO debugging sections we are interested in. */
12748 dwarf2_locate_dwo_sections (struct objfile
*objfile
, bfd
*abfd
,
12749 asection
*sectp
, dwo_sections
*dwo_sections
)
12751 const struct dwop_section_names
*names
= &dwop_section_names
;
12753 struct dwarf2_section_info
*dw_sect
= nullptr;
12755 if (names
->abbrev_dwo
.matches (sectp
->name
))
12756 dw_sect
= &dwo_sections
->abbrev
;
12757 else if (names
->info_dwo
.matches (sectp
->name
))
12758 dw_sect
= &dwo_sections
->info
;
12759 else if (names
->line_dwo
.matches (sectp
->name
))
12760 dw_sect
= &dwo_sections
->line
;
12761 else if (names
->loc_dwo
.matches (sectp
->name
))
12762 dw_sect
= &dwo_sections
->loc
;
12763 else if (names
->loclists_dwo
.matches (sectp
->name
))
12764 dw_sect
= &dwo_sections
->loclists
;
12765 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12766 dw_sect
= &dwo_sections
->macinfo
;
12767 else if (names
->macro_dwo
.matches (sectp
->name
))
12768 dw_sect
= &dwo_sections
->macro
;
12769 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12770 dw_sect
= &dwo_sections
->rnglists
;
12771 else if (names
->str_dwo
.matches (sectp
->name
))
12772 dw_sect
= &dwo_sections
->str
;
12773 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12774 dw_sect
= &dwo_sections
->str_offsets
;
12775 else if (names
->types_dwo
.matches (sectp
->name
))
12777 struct dwarf2_section_info type_section
;
12779 memset (&type_section
, 0, sizeof (type_section
));
12780 dwo_sections
->types
.push_back (type_section
);
12781 dw_sect
= &dwo_sections
->types
.back ();
12784 if (dw_sect
!= nullptr)
12786 dw_sect
->s
.section
= sectp
;
12787 dw_sect
->size
= bfd_section_size (sectp
);
12788 dw_sect
->read (objfile
);
12792 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12793 by PER_CU. This is for the non-DWP case.
12794 The result is NULL if DWO_NAME can't be found. */
12796 static struct dwo_file
*
12797 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12798 const char *comp_dir
)
12800 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12802 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12805 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12810 dwo_file_up
dwo_file (new struct dwo_file
);
12811 dwo_file
->dwo_name
= dwo_name
;
12812 dwo_file
->comp_dir
= comp_dir
;
12813 dwo_file
->dbfd
= std::move (dbfd
);
12815 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12816 dwarf2_locate_dwo_sections (per_objfile
->objfile
, dwo_file
->dbfd
.get (),
12817 sec
, &dwo_file
->sections
);
12819 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12822 if (cu
->per_cu
->dwarf_version
< 5)
12824 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12825 dwo_file
->sections
.types
, dwo_file
->tus
);
12829 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12830 &dwo_file
->sections
.info
, dwo_file
->tus
,
12831 rcuh_kind::COMPILE
);
12834 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12836 return dwo_file
.release ();
12839 /* This function is mapped across the sections and remembers the offset and
12840 size of each of the DWP debugging sections common to version 1 and 2 that
12841 we are interested in. */
12844 dwarf2_locate_common_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
12845 asection
*sectp
, dwp_file
*dwp_file
)
12847 const struct dwop_section_names
*names
= &dwop_section_names
;
12848 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12850 /* Record the ELF section number for later lookup: this is what the
12851 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12852 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12853 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12855 /* Look for specific sections that we need. */
12856 struct dwarf2_section_info
*dw_sect
= nullptr;
12857 if (names
->str_dwo
.matches (sectp
->name
))
12858 dw_sect
= &dwp_file
->sections
.str
;
12859 else if (names
->cu_index
.matches (sectp
->name
))
12860 dw_sect
= &dwp_file
->sections
.cu_index
;
12861 else if (names
->tu_index
.matches (sectp
->name
))
12862 dw_sect
= &dwp_file
->sections
.tu_index
;
12864 if (dw_sect
!= nullptr)
12866 dw_sect
->s
.section
= sectp
;
12867 dw_sect
->size
= bfd_section_size (sectp
);
12868 dw_sect
->read (objfile
);
12872 /* This function is mapped across the sections and remembers the offset and
12873 size of each of the DWP version 2 debugging sections that we are interested
12874 in. This is split into a separate function because we don't know if we
12875 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12878 dwarf2_locate_v2_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
12879 asection
*sectp
, void *dwp_file_ptr
)
12881 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12882 const struct dwop_section_names
*names
= &dwop_section_names
;
12883 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12885 /* Record the ELF section number for later lookup: this is what the
12886 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12887 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12888 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12890 /* Look for specific sections that we need. */
12891 struct dwarf2_section_info
*dw_sect
= nullptr;
12892 if (names
->abbrev_dwo
.matches (sectp
->name
))
12893 dw_sect
= &dwp_file
->sections
.abbrev
;
12894 else if (names
->info_dwo
.matches (sectp
->name
))
12895 dw_sect
= &dwp_file
->sections
.info
;
12896 else if (names
->line_dwo
.matches (sectp
->name
))
12897 dw_sect
= &dwp_file
->sections
.line
;
12898 else if (names
->loc_dwo
.matches (sectp
->name
))
12899 dw_sect
= &dwp_file
->sections
.loc
;
12900 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12901 dw_sect
= &dwp_file
->sections
.macinfo
;
12902 else if (names
->macro_dwo
.matches (sectp
->name
))
12903 dw_sect
= &dwp_file
->sections
.macro
;
12904 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12905 dw_sect
= &dwp_file
->sections
.str_offsets
;
12906 else if (names
->types_dwo
.matches (sectp
->name
))
12907 dw_sect
= &dwp_file
->sections
.types
;
12909 if (dw_sect
!= nullptr)
12911 dw_sect
->s
.section
= sectp
;
12912 dw_sect
->size
= bfd_section_size (sectp
);
12913 dw_sect
->read (objfile
);
12917 /* This function is mapped across the sections and remembers the offset and
12918 size of each of the DWP version 5 debugging sections that we are interested
12919 in. This is split into a separate function because we don't know if we
12920 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12923 dwarf2_locate_v5_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
12924 asection
*sectp
, void *dwp_file_ptr
)
12926 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12927 const struct dwop_section_names
*names
= &dwop_section_names
;
12928 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12930 /* Record the ELF section number for later lookup: this is what the
12931 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12932 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12933 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12935 /* Look for specific sections that we need. */
12936 struct dwarf2_section_info
*dw_sect
= nullptr;
12937 if (names
->abbrev_dwo
.matches (sectp
->name
))
12938 dw_sect
= &dwp_file
->sections
.abbrev
;
12939 else if (names
->info_dwo
.matches (sectp
->name
))
12940 dw_sect
= &dwp_file
->sections
.info
;
12941 else if (names
->line_dwo
.matches (sectp
->name
))
12942 dw_sect
= &dwp_file
->sections
.line
;
12943 else if (names
->loclists_dwo
.matches (sectp
->name
))
12944 dw_sect
= &dwp_file
->sections
.loclists
;
12945 else if (names
->macro_dwo
.matches (sectp
->name
))
12946 dw_sect
= &dwp_file
->sections
.macro
;
12947 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12948 dw_sect
= &dwp_file
->sections
.rnglists
;
12949 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12950 dw_sect
= &dwp_file
->sections
.str_offsets
;
12952 if (dw_sect
!= nullptr)
12954 dw_sect
->s
.section
= sectp
;
12955 dw_sect
->size
= bfd_section_size (sectp
);
12956 dw_sect
->read (objfile
);
12960 /* Hash function for dwp_file loaded CUs/TUs. */
12963 hash_dwp_loaded_cutus (const void *item
)
12965 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12967 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12968 return dwo_unit
->signature
;
12971 /* Equality function for dwp_file loaded CUs/TUs. */
12974 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12976 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12977 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12979 return dua
->signature
== dub
->signature
;
12982 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12985 allocate_dwp_loaded_cutus_table ()
12987 return htab_up (htab_create_alloc (3,
12988 hash_dwp_loaded_cutus
,
12989 eq_dwp_loaded_cutus
,
12990 NULL
, xcalloc
, xfree
));
12993 /* Try to open DWP file FILE_NAME.
12994 The result is the bfd handle of the file.
12995 If there is a problem finding or opening the file, return NULL.
12996 Upon success, the canonicalized path of the file is stored in the bfd,
12997 same as symfile_bfd_open. */
12999 static gdb_bfd_ref_ptr
13000 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
13002 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
13004 1 /*search_cwd*/));
13008 /* Work around upstream bug 15652.
13009 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13010 [Whether that's a "bug" is debatable, but it is getting in our way.]
13011 We have no real idea where the dwp file is, because gdb's realpath-ing
13012 of the executable's path may have discarded the needed info.
13013 [IWBN if the dwp file name was recorded in the executable, akin to
13014 .gnu_debuglink, but that doesn't exist yet.]
13015 Strip the directory from FILE_NAME and search again. */
13016 if (!debug_file_directory
.empty ())
13018 /* Don't implicitly search the current directory here.
13019 If the user wants to search "." to handle this case,
13020 it must be added to debug-file-directory. */
13021 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
13029 /* Initialize the use of the DWP file for the current objfile.
13030 By convention the name of the DWP file is ${objfile}.dwp.
13031 The result is NULL if it can't be found. */
13033 static std::unique_ptr
<struct dwp_file
>
13034 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
13036 struct objfile
*objfile
= per_objfile
->objfile
;
13038 /* Try to find first .dwp for the binary file before any symbolic links
13041 /* If the objfile is a debug file, find the name of the real binary
13042 file and get the name of dwp file from there. */
13043 std::string dwp_name
;
13044 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13046 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13047 const char *backlink_basename
= lbasename (backlink
->original_name
);
13049 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13052 dwp_name
= objfile
->original_name
;
13054 dwp_name
+= ".dwp";
13056 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13058 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13060 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13061 dwp_name
= objfile_name (objfile
);
13062 dwp_name
+= ".dwp";
13063 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13068 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
13070 return std::unique_ptr
<dwp_file
> ();
13073 const char *name
= bfd_get_filename (dbfd
.get ());
13074 std::unique_ptr
<struct dwp_file
> dwp_file
13075 (new struct dwp_file (name
, std::move (dbfd
)));
13077 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13078 dwp_file
->elf_sections
=
13079 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13080 dwp_file
->num_sections
, asection
*);
13082 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13083 dwarf2_locate_common_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
13086 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13088 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13090 /* The DWP file version is stored in the hash table. Oh well. */
13091 if (dwp_file
->cus
&& dwp_file
->tus
13092 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13094 /* Technically speaking, we should try to limp along, but this is
13095 pretty bizarre. We use pulongest here because that's the established
13096 portability solution (e.g, we cannot use %u for uint32_t). */
13097 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13098 " TU version %s [in DWP file %s]"),
13099 pulongest (dwp_file
->cus
->version
),
13100 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13104 dwp_file
->version
= dwp_file
->cus
->version
;
13105 else if (dwp_file
->tus
)
13106 dwp_file
->version
= dwp_file
->tus
->version
;
13108 dwp_file
->version
= 2;
13110 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13112 if (dwp_file
->version
== 2)
13113 dwarf2_locate_v2_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
13116 dwarf2_locate_v5_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
13120 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13121 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13123 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
13124 dwarf_read_debug_printf (" %s CUs, %s TUs",
13125 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13126 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13131 /* Wrapper around open_and_init_dwp_file, only open it once. */
13133 static struct dwp_file
*
13134 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13136 if (!per_objfile
->per_bfd
->dwp_checked
)
13138 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13139 per_objfile
->per_bfd
->dwp_checked
= 1;
13141 return per_objfile
->per_bfd
->dwp_file
.get ();
13144 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13145 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13146 or in the DWP file for the objfile, referenced by THIS_UNIT.
13147 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13148 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13150 This is called, for example, when wanting to read a variable with a
13151 complex location. Therefore we don't want to do file i/o for every call.
13152 Therefore we don't want to look for a DWO file on every call.
13153 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13154 then we check if we've already seen DWO_NAME, and only THEN do we check
13157 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13158 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13160 static struct dwo_unit
*
13161 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13162 ULONGEST signature
, int is_debug_types
)
13164 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13165 struct objfile
*objfile
= per_objfile
->objfile
;
13166 const char *kind
= is_debug_types
? "TU" : "CU";
13167 void **dwo_file_slot
;
13168 struct dwo_file
*dwo_file
;
13169 struct dwp_file
*dwp_file
;
13171 /* First see if there's a DWP file.
13172 If we have a DWP file but didn't find the DWO inside it, don't
13173 look for the original DWO file. It makes gdb behave differently
13174 depending on whether one is debugging in the build tree. */
13176 dwp_file
= get_dwp_file (per_objfile
);
13177 if (dwp_file
!= NULL
)
13179 const struct dwp_hash_table
*dwp_htab
=
13180 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13182 if (dwp_htab
!= NULL
)
13184 struct dwo_unit
*dwo_cutu
=
13185 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13188 if (dwo_cutu
!= NULL
)
13190 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
13191 kind
, hex_string (signature
),
13192 host_address_to_string (dwo_cutu
));
13200 /* No DWP file, look for the DWO file. */
13202 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13203 if (*dwo_file_slot
== NULL
)
13205 /* Read in the file and build a table of the CUs/TUs it contains. */
13206 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13208 /* NOTE: This will be NULL if unable to open the file. */
13209 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13211 if (dwo_file
!= NULL
)
13213 struct dwo_unit
*dwo_cutu
= NULL
;
13215 if (is_debug_types
&& dwo_file
->tus
)
13217 struct dwo_unit find_dwo_cutu
;
13219 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13220 find_dwo_cutu
.signature
= signature
;
13222 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13225 else if (!is_debug_types
&& dwo_file
->cus
)
13227 struct dwo_unit find_dwo_cutu
;
13229 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13230 find_dwo_cutu
.signature
= signature
;
13231 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13235 if (dwo_cutu
!= NULL
)
13237 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
13238 kind
, dwo_name
, hex_string (signature
),
13239 host_address_to_string (dwo_cutu
));
13246 /* We didn't find it. This could mean a dwo_id mismatch, or
13247 someone deleted the DWO/DWP file, or the search path isn't set up
13248 correctly to find the file. */
13250 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
13251 kind
, dwo_name
, hex_string (signature
));
13253 /* This is a warning and not a complaint because it can be caused by
13254 pilot error (e.g., user accidentally deleting the DWO). */
13256 /* Print the name of the DWP file if we looked there, helps the user
13257 better diagnose the problem. */
13258 std::string dwp_text
;
13260 if (dwp_file
!= NULL
)
13261 dwp_text
= string_printf (" [in DWP file %s]",
13262 lbasename (dwp_file
->name
));
13264 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13265 " [in module %s]"),
13266 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13267 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13272 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13273 See lookup_dwo_cutu_unit for details. */
13275 static struct dwo_unit
*
13276 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13277 ULONGEST signature
)
13279 gdb_assert (!cu
->per_cu
->is_debug_types
);
13281 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13284 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13285 See lookup_dwo_cutu_unit for details. */
13287 static struct dwo_unit
*
13288 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13290 gdb_assert (cu
->per_cu
->is_debug_types
);
13292 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13294 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13297 /* Traversal function for queue_and_load_all_dwo_tus. */
13300 queue_and_load_dwo_tu (void **slot
, void *info
)
13302 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13303 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13304 ULONGEST signature
= dwo_unit
->signature
;
13305 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13307 if (sig_type
!= NULL
)
13309 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13310 a real dependency of PER_CU on SIG_TYPE. That is detected later
13311 while processing PER_CU. */
13312 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
13314 load_full_type_unit (sig_type
, cu
->per_objfile
);
13315 cu
->per_cu
->imported_symtabs_push (sig_type
);
13321 /* Queue all TUs contained in the DWO of CU to be read in.
13322 The DWO may have the only definition of the type, though it may not be
13323 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13324 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13327 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13329 struct dwo_unit
*dwo_unit
;
13330 struct dwo_file
*dwo_file
;
13332 gdb_assert (cu
!= nullptr);
13333 gdb_assert (!cu
->per_cu
->is_debug_types
);
13334 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13336 dwo_unit
= cu
->dwo_unit
;
13337 gdb_assert (dwo_unit
!= NULL
);
13339 dwo_file
= dwo_unit
->dwo_file
;
13340 if (dwo_file
->tus
!= NULL
)
13341 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13344 /* Read in various DIEs. */
13346 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13347 Inherit only the children of the DW_AT_abstract_origin DIE not being
13348 already referenced by DW_AT_abstract_origin from the children of the
13352 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13354 struct die_info
*child_die
;
13355 sect_offset
*offsetp
;
13356 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13357 struct die_info
*origin_die
;
13358 /* Iterator of the ORIGIN_DIE children. */
13359 struct die_info
*origin_child_die
;
13360 struct attribute
*attr
;
13361 struct dwarf2_cu
*origin_cu
;
13362 struct pending
**origin_previous_list_in_scope
;
13364 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13368 /* Note that following die references may follow to a die in a
13372 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13374 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13376 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13377 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13379 if (die
->tag
!= origin_die
->tag
13380 && !(die
->tag
== DW_TAG_inlined_subroutine
13381 && origin_die
->tag
== DW_TAG_subprogram
))
13382 complaint (_("DIE %s and its abstract origin %s have different tags"),
13383 sect_offset_str (die
->sect_off
),
13384 sect_offset_str (origin_die
->sect_off
));
13386 /* Find if the concrete and abstract trees are structurally the
13387 same. This is a shallow traversal and it is not bullet-proof;
13388 the compiler can trick the debugger into believing that the trees
13389 are isomorphic, whereas they actually are not. However, the
13390 likelyhood of this happening is pretty low, and a full-fledged
13391 check would be an overkill. */
13392 bool are_isomorphic
= true;
13393 die_info
*concrete_child
= die
->child
;
13394 die_info
*abstract_child
= origin_die
->child
;
13395 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
13397 if (concrete_child
== nullptr
13398 || abstract_child
== nullptr
13399 || concrete_child
->tag
!= abstract_child
->tag
)
13401 are_isomorphic
= false;
13405 concrete_child
= concrete_child
->sibling
;
13406 abstract_child
= abstract_child
->sibling
;
13409 /* Walk the origin's children in parallel to the concrete children.
13410 This helps match an origin child in case the debug info misses
13411 DW_AT_abstract_origin attributes. Keep in mind that the abstract
13412 origin tree may not have the same tree structure as the concrete
13414 die_info
*corresponding_abstract_child
13415 = are_isomorphic
? origin_die
->child
: nullptr;
13417 std::vector
<sect_offset
> offsets
;
13419 for (child_die
= die
->child
;
13420 child_die
&& child_die
->tag
;
13421 child_die
= child_die
->sibling
)
13423 struct die_info
*child_origin_die
;
13424 struct dwarf2_cu
*child_origin_cu
;
13426 /* We are trying to process concrete instance entries:
13427 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13428 it's not relevant to our analysis here. i.e. detecting DIEs that are
13429 present in the abstract instance but not referenced in the concrete
13431 if (child_die
->tag
== DW_TAG_call_site
13432 || child_die
->tag
== DW_TAG_GNU_call_site
)
13434 if (are_isomorphic
)
13435 corresponding_abstract_child
13436 = corresponding_abstract_child
->sibling
;
13440 /* For each CHILD_DIE, find the corresponding child of
13441 ORIGIN_DIE. If there is more than one layer of
13442 DW_AT_abstract_origin, follow them all; there shouldn't be,
13443 but GCC versions at least through 4.4 generate this (GCC PR
13445 child_origin_die
= child_die
;
13446 child_origin_cu
= cu
;
13449 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13453 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13457 /* If missing DW_AT_abstract_origin, try the corresponding child
13458 of the origin. Clang emits such lexical scopes. */
13459 if (child_origin_die
== child_die
13460 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
13462 && child_die
->tag
== DW_TAG_lexical_block
)
13463 child_origin_die
= corresponding_abstract_child
;
13465 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13466 counterpart may exist. */
13467 if (child_origin_die
!= child_die
)
13469 if (child_die
->tag
!= child_origin_die
->tag
13470 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13471 && child_origin_die
->tag
== DW_TAG_subprogram
))
13472 complaint (_("Child DIE %s and its abstract origin %s have "
13474 sect_offset_str (child_die
->sect_off
),
13475 sect_offset_str (child_origin_die
->sect_off
));
13476 if (child_origin_die
->parent
!= origin_die
)
13477 complaint (_("Child DIE %s and its abstract origin %s have "
13478 "different parents"),
13479 sect_offset_str (child_die
->sect_off
),
13480 sect_offset_str (child_origin_die
->sect_off
));
13482 offsets
.push_back (child_origin_die
->sect_off
);
13485 if (are_isomorphic
)
13486 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
13488 std::sort (offsets
.begin (), offsets
.end ());
13489 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13490 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13491 if (offsetp
[-1] == *offsetp
)
13492 complaint (_("Multiple children of DIE %s refer "
13493 "to DIE %s as their abstract origin"),
13494 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13496 offsetp
= offsets
.data ();
13497 origin_child_die
= origin_die
->child
;
13498 while (origin_child_die
&& origin_child_die
->tag
)
13500 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13501 while (offsetp
< offsets_end
13502 && *offsetp
< origin_child_die
->sect_off
)
13504 if (offsetp
>= offsets_end
13505 || *offsetp
> origin_child_die
->sect_off
)
13507 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13508 Check whether we're already processing ORIGIN_CHILD_DIE.
13509 This can happen with mutually referenced abstract_origins.
13511 if (!origin_child_die
->in_process
)
13512 process_die (origin_child_die
, origin_cu
);
13514 origin_child_die
= origin_child_die
->sibling
;
13516 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13518 if (cu
!= origin_cu
)
13519 compute_delayed_physnames (origin_cu
);
13523 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13525 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13526 struct gdbarch
*gdbarch
= objfile
->arch ();
13527 struct context_stack
*newobj
;
13530 struct die_info
*child_die
;
13531 struct attribute
*attr
, *call_line
, *call_file
;
13533 CORE_ADDR baseaddr
;
13534 struct block
*block
;
13535 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13536 std::vector
<struct symbol
*> template_args
;
13537 struct template_symbol
*templ_func
= NULL
;
13541 /* If we do not have call site information, we can't show the
13542 caller of this inlined function. That's too confusing, so
13543 only use the scope for local variables. */
13544 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13545 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13546 if (call_line
== NULL
|| call_file
== NULL
)
13548 read_lexical_block_scope (die
, cu
);
13553 baseaddr
= objfile
->text_section_offset ();
13555 name
= dwarf2_name (die
, cu
);
13557 /* Ignore functions with missing or empty names. These are actually
13558 illegal according to the DWARF standard. */
13561 complaint (_("missing name for subprogram DIE at %s"),
13562 sect_offset_str (die
->sect_off
));
13566 /* Ignore functions with missing or invalid low and high pc attributes. */
13567 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr)
13568 <= PC_BOUNDS_INVALID
)
13570 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13571 if (attr
== nullptr || !attr
->as_boolean ())
13572 complaint (_("cannot get low and high bounds "
13573 "for subprogram DIE at %s"),
13574 sect_offset_str (die
->sect_off
));
13578 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13579 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13581 /* If we have any template arguments, then we must allocate a
13582 different sort of symbol. */
13583 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13585 if (child_die
->tag
== DW_TAG_template_type_param
13586 || child_die
->tag
== DW_TAG_template_value_param
)
13588 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13589 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13594 gdb_assert (cu
->get_builder () != nullptr);
13595 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13596 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13597 (struct symbol
*) templ_func
);
13599 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13600 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13603 /* If there is a location expression for DW_AT_frame_base, record
13605 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13606 if (attr
!= nullptr)
13607 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13609 /* If there is a location for the static link, record it. */
13610 newobj
->static_link
= NULL
;
13611 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13612 if (attr
!= nullptr)
13614 newobj
->static_link
13615 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13616 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13620 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13622 if (die
->child
!= NULL
)
13624 child_die
= die
->child
;
13625 while (child_die
&& child_die
->tag
)
13627 if (child_die
->tag
== DW_TAG_template_type_param
13628 || child_die
->tag
== DW_TAG_template_value_param
)
13630 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13633 template_args
.push_back (arg
);
13636 process_die (child_die
, cu
);
13637 child_die
= child_die
->sibling
;
13641 inherit_abstract_dies (die
, cu
);
13643 /* If we have a DW_AT_specification, we might need to import using
13644 directives from the context of the specification DIE. See the
13645 comment in determine_prefix. */
13646 if (cu
->per_cu
->lang
== language_cplus
13647 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13649 struct dwarf2_cu
*spec_cu
= cu
;
13650 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13654 child_die
= spec_die
->child
;
13655 while (child_die
&& child_die
->tag
)
13657 if (child_die
->tag
== DW_TAG_imported_module
)
13658 process_die (child_die
, spec_cu
);
13659 child_die
= child_die
->sibling
;
13662 /* In some cases, GCC generates specification DIEs that
13663 themselves contain DW_AT_specification attributes. */
13664 spec_die
= die_specification (spec_die
, &spec_cu
);
13668 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13669 /* Make a block for the local symbols within. */
13670 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13671 cstk
.static_link
, lowpc
, highpc
);
13673 /* For C++, set the block's scope. */
13674 if ((cu
->per_cu
->lang
== language_cplus
13675 || cu
->per_cu
->lang
== language_fortran
13676 || cu
->per_cu
->lang
== language_d
13677 || cu
->per_cu
->lang
== language_rust
)
13678 && cu
->processing_has_namespace_info
)
13679 block_set_scope (block
, determine_prefix (die
, cu
),
13680 &objfile
->objfile_obstack
);
13682 /* If we have address ranges, record them. */
13683 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13685 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13687 /* Attach template arguments to function. */
13688 if (!template_args
.empty ())
13690 gdb_assert (templ_func
!= NULL
);
13692 templ_func
->n_template_arguments
= template_args
.size ();
13693 templ_func
->template_arguments
13694 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13695 templ_func
->n_template_arguments
);
13696 memcpy (templ_func
->template_arguments
,
13697 template_args
.data (),
13698 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13700 /* Make sure that the symtab is set on the new symbols. Even
13701 though they don't appear in this symtab directly, other parts
13702 of gdb assume that symbols do, and this is reasonably
13704 for (symbol
*sym
: template_args
)
13705 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13708 /* In C++, we can have functions nested inside functions (e.g., when
13709 a function declares a class that has methods). This means that
13710 when we finish processing a function scope, we may need to go
13711 back to building a containing block's symbol lists. */
13712 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13713 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13715 /* If we've finished processing a top-level function, subsequent
13716 symbols go in the file symbol list. */
13717 if (cu
->get_builder ()->outermost_context_p ())
13718 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13721 /* Process all the DIES contained within a lexical block scope. Start
13722 a new scope, process the dies, and then close the scope. */
13725 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13727 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13728 struct gdbarch
*gdbarch
= objfile
->arch ();
13729 CORE_ADDR lowpc
, highpc
;
13730 struct die_info
*child_die
;
13731 CORE_ADDR baseaddr
;
13733 baseaddr
= objfile
->text_section_offset ();
13735 /* Ignore blocks with missing or invalid low and high pc attributes. */
13736 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13737 as multiple lexical blocks? Handling children in a sane way would
13738 be nasty. Might be easier to properly extend generic blocks to
13739 describe ranges. */
13740 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr))
13742 case PC_BOUNDS_NOT_PRESENT
:
13743 /* DW_TAG_lexical_block has no attributes, process its children as if
13744 there was no wrapping by that DW_TAG_lexical_block.
13745 GCC does no longer produces such DWARF since GCC r224161. */
13746 for (child_die
= die
->child
;
13747 child_die
!= NULL
&& child_die
->tag
;
13748 child_die
= child_die
->sibling
)
13750 /* We might already be processing this DIE. This can happen
13751 in an unusual circumstance -- where a subroutine A
13752 appears lexically in another subroutine B, but A actually
13753 inlines B. The recursion is broken here, rather than in
13754 inherit_abstract_dies, because it seems better to simply
13755 drop concrete children here. */
13756 if (!child_die
->in_process
)
13757 process_die (child_die
, cu
);
13760 case PC_BOUNDS_INVALID
:
13763 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13764 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13766 cu
->get_builder ()->push_context (0, lowpc
);
13767 if (die
->child
!= NULL
)
13769 child_die
= die
->child
;
13770 while (child_die
&& child_die
->tag
)
13772 process_die (child_die
, cu
);
13773 child_die
= child_die
->sibling
;
13776 inherit_abstract_dies (die
, cu
);
13777 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13779 if (*cu
->get_builder ()->get_local_symbols () != NULL
13780 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13782 struct block
*block
13783 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13784 cstk
.start_addr
, highpc
);
13786 /* Note that recording ranges after traversing children, as we
13787 do here, means that recording a parent's ranges entails
13788 walking across all its children's ranges as they appear in
13789 the address map, which is quadratic behavior.
13791 It would be nicer to record the parent's ranges before
13792 traversing its children, simply overriding whatever you find
13793 there. But since we don't even decide whether to create a
13794 block until after we've traversed its children, that's hard
13796 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13798 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13799 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13802 static void dwarf2_ranges_read_low_addrs (unsigned offset
,
13803 struct dwarf2_cu
*cu
,
13805 std::vector
<CORE_ADDR
> &result
);
13807 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13810 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13812 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13813 struct objfile
*objfile
= per_objfile
->objfile
;
13814 struct gdbarch
*gdbarch
= objfile
->arch ();
13815 CORE_ADDR pc
, baseaddr
;
13816 struct attribute
*attr
;
13819 struct die_info
*child_die
;
13821 baseaddr
= objfile
->text_section_offset ();
13823 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13826 /* This was a pre-DWARF-5 GNU extension alias
13827 for DW_AT_call_return_pc. */
13828 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13832 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13833 "DIE %s [in module %s]"),
13834 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13837 pc
= attr
->as_address () + baseaddr
;
13838 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13841 if (cu
->call_site_htab
== NULL
)
13842 cu
->call_site_htab
= htab_create_alloc_ex (16, call_site::hash
,
13843 call_site::eq
, NULL
,
13844 &objfile
->objfile_obstack
,
13845 hashtab_obstack_allocate
, NULL
);
13846 struct call_site
call_site_local (pc
, nullptr, nullptr);
13847 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13850 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13851 "DIE %s [in module %s]"),
13852 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13853 objfile_name (objfile
));
13857 /* Count parameters at the caller. */
13860 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13861 child_die
= child_die
->sibling
)
13863 if (child_die
->tag
!= DW_TAG_call_site_parameter
13864 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13866 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13867 "DW_TAG_call_site child DIE %s [in module %s]"),
13868 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13869 objfile_name (objfile
));
13876 struct call_site
*call_site
13877 = new (XOBNEWVAR (&objfile
->objfile_obstack
,
13879 sizeof (*call_site
) + sizeof (call_site
->parameter
[0]) * nparams
))
13880 struct call_site (pc
, cu
->per_cu
, per_objfile
);
13883 /* We never call the destructor of call_site, so we must ensure it is
13884 trivially destructible. */
13885 gdb_static_assert(std::is_trivially_destructible
<struct call_site
>::value
);
13887 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13888 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13890 struct die_info
*func_die
;
13892 /* Skip also over DW_TAG_inlined_subroutine. */
13893 for (func_die
= die
->parent
;
13894 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13895 && func_die
->tag
!= DW_TAG_subroutine_type
;
13896 func_die
= func_die
->parent
);
13898 /* DW_AT_call_all_calls is a superset
13899 of DW_AT_call_all_tail_calls. */
13901 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13902 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13903 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13904 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13906 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13907 not complete. But keep CALL_SITE for look ups via call_site_htab,
13908 both the initial caller containing the real return address PC and
13909 the final callee containing the current PC of a chain of tail
13910 calls do not need to have the tail call list complete. But any
13911 function candidate for a virtual tail call frame searched via
13912 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13913 determined unambiguously. */
13917 struct type
*func_type
= NULL
;
13920 func_type
= get_die_type (func_die
, cu
);
13921 if (func_type
!= NULL
)
13923 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13925 /* Enlist this call site to the function. */
13926 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13927 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13930 complaint (_("Cannot find function owning DW_TAG_call_site "
13931 "DIE %s [in module %s]"),
13932 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13936 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13938 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13940 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13943 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13944 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13947 call_site
->target
.set_loc_dwarf_block (nullptr);
13948 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13949 /* Keep NULL DWARF_BLOCK. */;
13950 else if (attr
->form_is_block ())
13952 struct dwarf2_locexpr_baton
*dlbaton
;
13953 struct dwarf_block
*block
= attr
->as_block ();
13955 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13956 dlbaton
->data
= block
->data
;
13957 dlbaton
->size
= block
->size
;
13958 dlbaton
->per_objfile
= per_objfile
;
13959 dlbaton
->per_cu
= cu
->per_cu
;
13961 call_site
->target
.set_loc_dwarf_block (dlbaton
);
13963 else if (attr
->form_is_ref ())
13965 struct dwarf2_cu
*target_cu
= cu
;
13966 struct die_info
*target_die
;
13968 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13969 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13971 struct attribute
*ranges_attr
13972 = dwarf2_attr (target_die
, DW_AT_ranges
, target_cu
);
13974 if (die_is_declaration (target_die
, target_cu
))
13976 const char *target_physname
;
13978 /* Prefer the mangled name; otherwise compute the demangled one. */
13979 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13980 if (target_physname
== NULL
)
13981 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13982 if (target_physname
== NULL
)
13983 complaint (_("DW_AT_call_target target DIE has invalid "
13984 "physname, for referencing DIE %s [in module %s]"),
13985 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13987 call_site
->target
.set_loc_physname (target_physname
);
13989 else if (ranges_attr
!= nullptr && ranges_attr
->form_is_unsigned ())
13991 ULONGEST ranges_offset
= (ranges_attr
->as_unsigned ()
13992 + target_cu
->gnu_ranges_base
);
13993 std::vector
<CORE_ADDR
> addresses
;
13994 dwarf2_ranges_read_low_addrs (ranges_offset
, target_cu
,
13995 target_die
->tag
, addresses
);
13996 CORE_ADDR
*saved
= XOBNEWVAR (&objfile
->objfile_obstack
, CORE_ADDR
,
13997 addresses
.size ());
13998 std::copy (addresses
.begin (), addresses
.end (), saved
);
13999 call_site
->target
.set_loc_array (addresses
.size (), saved
);
14005 /* DW_AT_entry_pc should be preferred. */
14006 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
,
14008 <= PC_BOUNDS_INVALID
)
14009 complaint (_("DW_AT_call_target target DIE has invalid "
14010 "low pc, for referencing DIE %s [in module %s]"),
14011 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14014 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
)
14016 call_site
->target
.set_loc_physaddr (lowpc
);
14021 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14022 "block nor reference, for DIE %s [in module %s]"),
14023 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14025 for (child_die
= die
->child
;
14026 child_die
&& child_die
->tag
;
14027 child_die
= child_die
->sibling
)
14029 struct call_site_parameter
*parameter
;
14030 struct attribute
*loc
, *origin
;
14032 if (child_die
->tag
!= DW_TAG_call_site_parameter
14033 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14035 /* Already printed the complaint above. */
14039 gdb_assert (call_site
->parameter_count
< nparams
);
14040 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14042 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14043 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14044 register is contained in DW_AT_call_value. */
14046 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14047 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14048 if (origin
== NULL
)
14050 /* This was a pre-DWARF-5 GNU extension alias
14051 for DW_AT_call_parameter. */
14052 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14054 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
14056 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14058 sect_offset sect_off
= origin
->get_ref_die_offset ();
14059 if (!cu
->header
.offset_in_cu_p (sect_off
))
14061 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14062 binding can be done only inside one CU. Such referenced DIE
14063 therefore cannot be even moved to DW_TAG_partial_unit. */
14064 complaint (_("DW_AT_call_parameter offset is not in CU for "
14065 "DW_TAG_call_site child DIE %s [in module %s]"),
14066 sect_offset_str (child_die
->sect_off
),
14067 objfile_name (objfile
));
14070 parameter
->u
.param_cu_off
14071 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14073 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
14075 complaint (_("No DW_FORM_block* DW_AT_location for "
14076 "DW_TAG_call_site child DIE %s [in module %s]"),
14077 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14082 struct dwarf_block
*block
= loc
->as_block ();
14084 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14085 (block
->data
, &block
->data
[block
->size
]);
14086 if (parameter
->u
.dwarf_reg
!= -1)
14087 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14088 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
14089 &block
->data
[block
->size
],
14090 ¶meter
->u
.fb_offset
))
14091 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14094 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14095 "for DW_FORM_block* DW_AT_location is supported for "
14096 "DW_TAG_call_site child DIE %s "
14098 sect_offset_str (child_die
->sect_off
),
14099 objfile_name (objfile
));
14104 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14106 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14107 if (attr
== NULL
|| !attr
->form_is_block ())
14109 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14110 "DW_TAG_call_site child DIE %s [in module %s]"),
14111 sect_offset_str (child_die
->sect_off
),
14112 objfile_name (objfile
));
14116 struct dwarf_block
*block
= attr
->as_block ();
14117 parameter
->value
= block
->data
;
14118 parameter
->value_size
= block
->size
;
14120 /* Parameters are not pre-cleared by memset above. */
14121 parameter
->data_value
= NULL
;
14122 parameter
->data_value_size
= 0;
14123 call_site
->parameter_count
++;
14125 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14127 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14128 if (attr
!= nullptr)
14130 if (!attr
->form_is_block ())
14131 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14132 "DW_TAG_call_site child DIE %s [in module %s]"),
14133 sect_offset_str (child_die
->sect_off
),
14134 objfile_name (objfile
));
14137 block
= attr
->as_block ();
14138 parameter
->data_value
= block
->data
;
14139 parameter
->data_value_size
= block
->size
;
14145 /* Helper function for read_variable. If DIE represents a virtual
14146 table, then return the type of the concrete object that is
14147 associated with the virtual table. Otherwise, return NULL. */
14149 static struct type
*
14150 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14152 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14156 /* Find the type DIE. */
14157 struct die_info
*type_die
= NULL
;
14158 struct dwarf2_cu
*type_cu
= cu
;
14160 if (attr
->form_is_ref ())
14161 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14162 if (type_die
== NULL
)
14165 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14167 return die_containing_type (type_die
, type_cu
);
14170 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14173 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14175 struct rust_vtable_symbol
*storage
= NULL
;
14177 if (cu
->per_cu
->lang
== language_rust
)
14179 struct type
*containing_type
= rust_containing_type (die
, cu
);
14181 if (containing_type
!= NULL
)
14183 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14185 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14186 storage
->concrete_type
= containing_type
;
14187 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14191 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14192 struct attribute
*abstract_origin
14193 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14194 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14195 if (res
== NULL
&& loc
&& abstract_origin
)
14197 /* We have a variable without a name, but with a location and an abstract
14198 origin. This may be a concrete instance of an abstract variable
14199 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14201 struct dwarf2_cu
*origin_cu
= cu
;
14202 struct die_info
*origin_die
14203 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14204 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14205 per_objfile
->per_bfd
->abstract_to_concrete
14206 [origin_die
->sect_off
].push_back (die
->sect_off
);
14210 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14211 reading .debug_rnglists.
14212 Callback's type should be:
14213 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14214 Return true if the attributes are present and valid, otherwise,
14217 template <typename Callback
>
14219 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14220 dwarf_tag tag
, Callback
&&callback
)
14222 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14223 struct objfile
*objfile
= per_objfile
->objfile
;
14224 bfd
*obfd
= objfile
->obfd
;
14225 /* Base address selection entry. */
14226 gdb::optional
<CORE_ADDR
> base
;
14227 const gdb_byte
*buffer
;
14228 bool overflow
= false;
14229 ULONGEST addr_index
;
14230 struct dwarf2_section_info
*rnglists_section
;
14232 base
= cu
->base_address
;
14233 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14234 rnglists_section
->read (objfile
);
14236 if (offset
>= rnglists_section
->size
)
14238 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14242 buffer
= rnglists_section
->buffer
+ offset
;
14246 /* Initialize it due to a false compiler warning. */
14247 CORE_ADDR range_beginning
= 0, range_end
= 0;
14248 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14249 + rnglists_section
->size
);
14250 unsigned int bytes_read
;
14252 if (buffer
== buf_end
)
14257 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14260 case DW_RLE_end_of_list
:
14262 case DW_RLE_base_address
:
14263 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14268 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14269 buffer
+= bytes_read
;
14271 case DW_RLE_base_addressx
:
14272 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14273 buffer
+= bytes_read
;
14274 base
= read_addr_index (cu
, addr_index
);
14276 case DW_RLE_start_length
:
14277 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14282 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14284 buffer
+= bytes_read
;
14285 range_end
= (range_beginning
14286 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14287 buffer
+= bytes_read
;
14288 if (buffer
> buf_end
)
14294 case DW_RLE_startx_length
:
14295 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14296 buffer
+= bytes_read
;
14297 range_beginning
= read_addr_index (cu
, addr_index
);
14298 if (buffer
> buf_end
)
14303 range_end
= (range_beginning
14304 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14305 buffer
+= bytes_read
;
14307 case DW_RLE_offset_pair
:
14308 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14309 buffer
+= bytes_read
;
14310 if (buffer
> buf_end
)
14315 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14316 buffer
+= bytes_read
;
14317 if (buffer
> buf_end
)
14323 case DW_RLE_start_end
:
14324 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14329 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14331 buffer
+= bytes_read
;
14332 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14333 buffer
+= bytes_read
;
14335 case DW_RLE_startx_endx
:
14336 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14337 buffer
+= bytes_read
;
14338 range_beginning
= read_addr_index (cu
, addr_index
);
14339 if (buffer
> buf_end
)
14344 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14345 buffer
+= bytes_read
;
14346 range_end
= read_addr_index (cu
, addr_index
);
14349 complaint (_("Invalid .debug_rnglists data (no base address)"));
14352 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14354 if (rlet
== DW_RLE_base_address
)
14357 if (range_beginning
> range_end
)
14359 /* Inverted range entries are invalid. */
14360 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14364 /* Empty range entries have no effect. */
14365 if (range_beginning
== range_end
)
14368 /* Only DW_RLE_offset_pair needs the base address added. */
14369 if (rlet
== DW_RLE_offset_pair
)
14371 if (!base
.has_value ())
14373 /* We have no valid base address for the DW_RLE_offset_pair. */
14374 complaint (_("Invalid .debug_rnglists data (no base address for "
14375 "DW_RLE_offset_pair)"));
14379 range_beginning
+= *base
;
14380 range_end
+= *base
;
14383 /* A not-uncommon case of bad debug info.
14384 Don't pollute the addrmap with bad data. */
14385 if (range_beginning
== 0
14386 && !per_objfile
->per_bfd
->has_section_at_zero
)
14388 complaint (_(".debug_rnglists entry has start address of zero"
14389 " [in module %s]"), objfile_name (objfile
));
14393 callback (range_beginning
, range_end
);
14398 complaint (_("Offset %d is not terminated "
14399 "for DW_AT_ranges attribute"),
14407 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14408 Callback's type should be:
14409 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14410 Return 1 if the attributes are present and valid, otherwise, return 0. */
14412 template <typename Callback
>
14414 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14415 Callback
&&callback
)
14417 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14418 struct objfile
*objfile
= per_objfile
->objfile
;
14419 struct comp_unit_head
*cu_header
= &cu
->header
;
14420 bfd
*obfd
= objfile
->obfd
;
14421 unsigned int addr_size
= cu_header
->addr_size
;
14422 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14423 /* Base address selection entry. */
14424 gdb::optional
<CORE_ADDR
> base
;
14425 unsigned int dummy
;
14426 const gdb_byte
*buffer
;
14428 if (cu_header
->version
>= 5)
14429 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14431 base
= cu
->base_address
;
14433 per_objfile
->per_bfd
->ranges
.read (objfile
);
14434 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14436 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14440 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14444 CORE_ADDR range_beginning
, range_end
;
14446 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14447 buffer
+= addr_size
;
14448 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14449 buffer
+= addr_size
;
14450 offset
+= 2 * addr_size
;
14452 /* An end of list marker is a pair of zero addresses. */
14453 if (range_beginning
== 0 && range_end
== 0)
14454 /* Found the end of list entry. */
14457 /* Each base address selection entry is a pair of 2 values.
14458 The first is the largest possible address, the second is
14459 the base address. Check for a base address here. */
14460 if ((range_beginning
& mask
) == mask
)
14462 /* If we found the largest possible address, then we already
14463 have the base address in range_end. */
14468 if (!base
.has_value ())
14470 /* We have no valid base address for the ranges
14472 complaint (_("Invalid .debug_ranges data (no base address)"));
14476 if (range_beginning
> range_end
)
14478 /* Inverted range entries are invalid. */
14479 complaint (_("Invalid .debug_ranges data (inverted range)"));
14483 /* Empty range entries have no effect. */
14484 if (range_beginning
== range_end
)
14487 range_beginning
+= *base
;
14488 range_end
+= *base
;
14490 /* A not-uncommon case of bad debug info.
14491 Don't pollute the addrmap with bad data. */
14492 if (range_beginning
== 0
14493 && !per_objfile
->per_bfd
->has_section_at_zero
)
14495 complaint (_(".debug_ranges entry has start address of zero"
14496 " [in module %s]"), objfile_name (objfile
));
14500 callback (range_beginning
, range_end
);
14506 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14507 Return 1 if the attributes are present and valid, otherwise, return 0.
14508 TAG is passed to dwarf2_ranges_process. If MAP is not NULL, then
14509 ranges in MAP are set, using DATUM as the value. */
14512 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14513 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14514 addrmap
*map
, void *datum
, dwarf_tag tag
)
14516 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14517 struct gdbarch
*gdbarch
= objfile
->arch ();
14518 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14521 CORE_ADDR high
= 0;
14524 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14525 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14527 if (map
!= nullptr)
14532 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14533 range_beginning
+ baseaddr
)
14535 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14536 range_end
+ baseaddr
)
14538 addrmap_set_empty (map
, lowpc
, highpc
- 1, datum
);
14541 /* FIXME: This is recording everything as a low-high
14542 segment of consecutive addresses. We should have a
14543 data structure for discontiguous block ranges
14547 low
= range_beginning
;
14553 if (range_beginning
< low
)
14554 low
= range_beginning
;
14555 if (range_end
> high
)
14563 /* If the first entry is an end-of-list marker, the range
14564 describes an empty scope, i.e. no instructions. */
14570 *high_return
= high
;
14574 /* Process ranges and fill in a vector of the low PC values only. */
14577 dwarf2_ranges_read_low_addrs (unsigned offset
, struct dwarf2_cu
*cu
,
14579 std::vector
<CORE_ADDR
> &result
)
14581 dwarf2_ranges_process (offset
, cu
, tag
,
14582 [&] (CORE_ADDR start
, CORE_ADDR end
)
14584 result
.push_back (start
);
14588 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14589 definition for the return value. *LOWPC and *HIGHPC are set iff
14590 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14592 static enum pc_bounds_kind
14593 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14594 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14595 addrmap
*map
, void *datum
)
14597 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14598 struct attribute
*attr
;
14599 struct attribute
*attr_high
;
14601 CORE_ADDR high
= 0;
14602 enum pc_bounds_kind ret
;
14604 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14607 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14608 if (attr
!= nullptr)
14610 low
= attr
->as_address ();
14611 high
= attr_high
->as_address ();
14612 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14616 /* Found high w/o low attribute. */
14617 return PC_BOUNDS_INVALID
;
14619 /* Found consecutive range of addresses. */
14620 ret
= PC_BOUNDS_HIGH_LOW
;
14624 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14625 if (attr
!= nullptr && attr
->form_is_unsigned ())
14627 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14628 on DWARF version). */
14629 ULONGEST ranges_offset
= attr
->as_unsigned ();
14631 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14633 if (die
->tag
!= DW_TAG_compile_unit
)
14634 ranges_offset
+= cu
->gnu_ranges_base
;
14636 /* Value of the DW_AT_ranges attribute is the offset in the
14637 .debug_ranges section. */
14638 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
,
14639 map
, datum
, die
->tag
))
14640 return PC_BOUNDS_INVALID
;
14641 /* Found discontinuous range of addresses. */
14642 ret
= PC_BOUNDS_RANGES
;
14645 return PC_BOUNDS_NOT_PRESENT
;
14648 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14650 return PC_BOUNDS_INVALID
;
14652 /* When using the GNU linker, .gnu.linkonce. sections are used to
14653 eliminate duplicate copies of functions and vtables and such.
14654 The linker will arbitrarily choose one and discard the others.
14655 The AT_*_pc values for such functions refer to local labels in
14656 these sections. If the section from that file was discarded, the
14657 labels are not in the output, so the relocs get a value of 0.
14658 If this is a discarded function, mark the pc bounds as invalid,
14659 so that GDB will ignore it. */
14660 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14661 return PC_BOUNDS_INVALID
;
14669 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14670 its low and high PC addresses. Do nothing if these addresses could not
14671 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14672 and HIGHPC to the high address if greater than HIGHPC. */
14675 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14676 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14677 struct dwarf2_cu
*cu
)
14679 CORE_ADDR low
, high
;
14680 struct die_info
*child
= die
->child
;
14682 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, nullptr, nullptr)
14683 >= PC_BOUNDS_RANGES
)
14685 *lowpc
= std::min (*lowpc
, low
);
14686 *highpc
= std::max (*highpc
, high
);
14689 /* If the language does not allow nested subprograms (either inside
14690 subprograms or lexical blocks), we're done. */
14691 if (cu
->per_cu
->lang
!= language_ada
)
14694 /* Check all the children of the given DIE. If it contains nested
14695 subprograms, then check their pc bounds. Likewise, we need to
14696 check lexical blocks as well, as they may also contain subprogram
14698 while (child
&& child
->tag
)
14700 if (child
->tag
== DW_TAG_subprogram
14701 || child
->tag
== DW_TAG_lexical_block
)
14702 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14703 child
= child
->sibling
;
14707 /* Get the low and high pc's represented by the scope DIE, and store
14708 them in *LOWPC and *HIGHPC. If the correct values can't be
14709 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14712 get_scope_pc_bounds (struct die_info
*die
,
14713 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14714 struct dwarf2_cu
*cu
)
14716 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14717 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14718 CORE_ADDR current_low
, current_high
;
14720 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
,
14722 >= PC_BOUNDS_RANGES
)
14724 best_low
= current_low
;
14725 best_high
= current_high
;
14729 struct die_info
*child
= die
->child
;
14731 while (child
&& child
->tag
)
14733 switch (child
->tag
) {
14734 case DW_TAG_subprogram
:
14735 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14737 case DW_TAG_namespace
:
14738 case DW_TAG_module
:
14739 /* FIXME: carlton/2004-01-16: Should we do this for
14740 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14741 that current GCC's always emit the DIEs corresponding
14742 to definitions of methods of classes as children of a
14743 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14744 the DIEs giving the declarations, which could be
14745 anywhere). But I don't see any reason why the
14746 standards says that they have to be there. */
14747 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14749 if (current_low
!= ((CORE_ADDR
) -1))
14751 best_low
= std::min (best_low
, current_low
);
14752 best_high
= std::max (best_high
, current_high
);
14760 child
= child
->sibling
;
14765 *highpc
= best_high
;
14768 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14772 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14773 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14775 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14776 struct gdbarch
*gdbarch
= objfile
->arch ();
14777 struct attribute
*attr
;
14778 struct attribute
*attr_high
;
14780 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14783 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14784 if (attr
!= nullptr)
14786 CORE_ADDR low
= attr
->as_address ();
14787 CORE_ADDR high
= attr_high
->as_address ();
14789 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14792 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14793 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14794 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14798 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14799 if (attr
!= nullptr && attr
->form_is_unsigned ())
14801 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14802 on DWARF version). */
14803 ULONGEST ranges_offset
= attr
->as_unsigned ();
14805 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14807 if (die
->tag
!= DW_TAG_compile_unit
)
14808 ranges_offset
+= cu
->gnu_ranges_base
;
14810 std::vector
<blockrange
> blockvec
;
14811 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14812 [&] (CORE_ADDR start
, CORE_ADDR end
)
14816 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14817 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14818 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14819 blockvec
.emplace_back (start
, end
);
14822 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14826 /* Check whether the producer field indicates either of GCC < 4.6, or the
14827 Intel C/C++ compiler, and cache the result in CU. */
14830 check_producer (struct dwarf2_cu
*cu
)
14834 if (cu
->producer
== NULL
)
14836 /* For unknown compilers expect their behavior is DWARF version
14839 GCC started to support .debug_types sections by -gdwarf-4 since
14840 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14841 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14842 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14843 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14845 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14847 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14848 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14849 cu
->producer_is_gcc_11
= major
== 11;
14851 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14853 cu
->producer_is_icc
= true;
14854 cu
->producer_is_icc_lt_14
= major
< 14;
14856 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14857 cu
->producer_is_codewarrior
= true;
14860 /* For other non-GCC compilers, expect their behavior is DWARF version
14864 cu
->checked_producer
= true;
14867 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14868 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14869 during 4.6.0 experimental. */
14872 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14874 if (!cu
->checked_producer
)
14875 check_producer (cu
);
14877 return cu
->producer_is_gxx_lt_4_6
;
14881 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14882 with incorrect is_stmt attributes. */
14885 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14887 if (!cu
->checked_producer
)
14888 check_producer (cu
);
14890 return cu
->producer_is_codewarrior
;
14893 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14894 If that attribute is not available, return the appropriate
14897 static enum dwarf_access_attribute
14898 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14900 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14901 if (attr
!= nullptr)
14903 LONGEST value
= attr
->constant_value (-1);
14904 if (value
== DW_ACCESS_public
14905 || value
== DW_ACCESS_protected
14906 || value
== DW_ACCESS_private
)
14907 return (dwarf_access_attribute
) value
;
14908 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14912 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14914 /* The default DWARF 2 accessibility for members is public, the default
14915 accessibility for inheritance is private. */
14917 if (die
->tag
!= DW_TAG_inheritance
)
14918 return DW_ACCESS_public
;
14920 return DW_ACCESS_private
;
14924 /* DWARF 3+ defines the default accessibility a different way. The same
14925 rules apply now for DW_TAG_inheritance as for the members and it only
14926 depends on the container kind. */
14928 if (die
->parent
->tag
== DW_TAG_class_type
)
14929 return DW_ACCESS_private
;
14931 return DW_ACCESS_public
;
14935 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
14936 *OFFSET to the byte offset. If the attribute was not found return
14937 0, otherwise return 1. If it was found but could not properly be
14938 handled, set *OFFSET to 0. */
14941 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14944 struct attribute
*attr
;
14946 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14951 /* Note that we do not check for a section offset first here.
14952 This is because DW_AT_data_member_location is new in DWARF 4,
14953 so if we see it, we can assume that a constant form is really
14954 a constant and not a section offset. */
14955 if (attr
->form_is_constant ())
14956 *offset
= attr
->constant_value (0);
14957 else if (attr
->form_is_section_offset ())
14958 dwarf2_complex_location_expr_complaint ();
14959 else if (attr
->form_is_block ())
14960 *offset
= decode_locdesc (attr
->as_block (), cu
);
14962 dwarf2_complex_location_expr_complaint ();
14968 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14969 if (attr
!= nullptr)
14971 *offset
= attr
->constant_value (0);
14979 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
14980 store the results in FIELD. */
14983 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14984 struct field
*field
)
14986 struct attribute
*attr
;
14988 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14991 if (attr
->form_is_constant ())
14993 LONGEST offset
= attr
->constant_value (0);
14995 /* Work around this GCC 11 bug, where it would erroneously use -1
14996 data member locations, instead of 0:
14998 Negative DW_AT_data_member_location
14999 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
15001 if (offset
== -1 && cu
->producer_is_gcc_11
)
15003 complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
15007 field
->set_loc_bitpos (offset
* bits_per_byte
);
15009 else if (attr
->form_is_section_offset ())
15010 dwarf2_complex_location_expr_complaint ();
15011 else if (attr
->form_is_block ())
15014 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
15016 field
->set_loc_bitpos (offset
* bits_per_byte
);
15019 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
15020 struct objfile
*objfile
= per_objfile
->objfile
;
15021 struct dwarf2_locexpr_baton
*dlbaton
15022 = XOBNEW (&objfile
->objfile_obstack
,
15023 struct dwarf2_locexpr_baton
);
15024 dlbaton
->data
= attr
->as_block ()->data
;
15025 dlbaton
->size
= attr
->as_block ()->size
;
15026 /* When using this baton, we want to compute the address
15027 of the field, not the value. This is why
15028 is_reference is set to false here. */
15029 dlbaton
->is_reference
= false;
15030 dlbaton
->per_objfile
= per_objfile
;
15031 dlbaton
->per_cu
= cu
->per_cu
;
15033 field
->set_loc_dwarf_block (dlbaton
);
15037 dwarf2_complex_location_expr_complaint ();
15041 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15042 if (attr
!= nullptr)
15043 field
->set_loc_bitpos (attr
->constant_value (0));
15047 /* Add an aggregate field to the field list. */
15050 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15051 struct dwarf2_cu
*cu
)
15053 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15054 struct gdbarch
*gdbarch
= objfile
->arch ();
15055 struct nextfield
*new_field
;
15056 struct attribute
*attr
;
15058 const char *fieldname
= "";
15060 if (die
->tag
== DW_TAG_inheritance
)
15062 fip
->baseclasses
.emplace_back ();
15063 new_field
= &fip
->baseclasses
.back ();
15067 fip
->fields
.emplace_back ();
15068 new_field
= &fip
->fields
.back ();
15071 new_field
->offset
= die
->sect_off
;
15073 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
15074 if (new_field
->accessibility
!= DW_ACCESS_public
)
15075 fip
->non_public_fields
= true;
15077 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15078 if (attr
!= nullptr)
15079 new_field
->virtuality
= attr
->as_virtuality ();
15081 new_field
->virtuality
= DW_VIRTUALITY_none
;
15083 fp
= &new_field
->field
;
15085 if ((die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_namelist_item
)
15086 && !die_is_declaration (die
, cu
))
15088 if (die
->tag
== DW_TAG_namelist_item
)
15090 /* Typically, DW_TAG_namelist_item are references to namelist items.
15091 If so, follow that reference. */
15092 struct attribute
*attr1
= dwarf2_attr (die
, DW_AT_namelist_item
, cu
);
15093 struct die_info
*item_die
= nullptr;
15094 struct dwarf2_cu
*item_cu
= cu
;
15095 if (attr1
->form_is_ref ())
15096 item_die
= follow_die_ref (die
, attr1
, &item_cu
);
15097 if (item_die
!= nullptr)
15100 /* Data member other than a C++ static data member. */
15102 /* Get type of field. */
15103 fp
->set_type (die_type (die
, cu
));
15105 fp
->set_loc_bitpos (0);
15107 /* Get bit size of field (zero if none). */
15108 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15109 if (attr
!= nullptr)
15111 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
15115 FIELD_BITSIZE (*fp
) = 0;
15118 /* Get bit offset of field. */
15119 handle_member_location (die
, cu
, fp
);
15120 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15121 if (attr
!= nullptr && attr
->form_is_constant ())
15123 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15125 /* For big endian bits, the DW_AT_bit_offset gives the
15126 additional bit offset from the MSB of the containing
15127 anonymous object to the MSB of the field. We don't
15128 have to do anything special since we don't need to
15129 know the size of the anonymous object. */
15130 fp
->set_loc_bitpos (fp
->loc_bitpos () + attr
->constant_value (0));
15134 /* For little endian bits, compute the bit offset to the
15135 MSB of the anonymous object, subtract off the number of
15136 bits from the MSB of the field to the MSB of the
15137 object, and then subtract off the number of bits of
15138 the field itself. The result is the bit offset of
15139 the LSB of the field. */
15140 int anonymous_size
;
15141 int bit_offset
= attr
->constant_value (0);
15143 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15144 if (attr
!= nullptr && attr
->form_is_constant ())
15146 /* The size of the anonymous object containing
15147 the bit field is explicit, so use the
15148 indicated size (in bytes). */
15149 anonymous_size
= attr
->constant_value (0);
15153 /* The size of the anonymous object containing
15154 the bit field must be inferred from the type
15155 attribute of the data member containing the
15157 anonymous_size
= TYPE_LENGTH (fp
->type ());
15159 fp
->set_loc_bitpos (fp
->loc_bitpos ()
15160 + anonymous_size
* bits_per_byte
15161 - bit_offset
- FIELD_BITSIZE (*fp
));
15165 /* Get name of field. */
15166 fieldname
= dwarf2_name (die
, cu
);
15167 if (fieldname
== NULL
)
15170 /* The name is already allocated along with this objfile, so we don't
15171 need to duplicate it for the type. */
15172 fp
->set_name (fieldname
);
15174 /* Change accessibility for artificial fields (e.g. virtual table
15175 pointer or virtual base class pointer) to private. */
15176 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15178 FIELD_ARTIFICIAL (*fp
) = 1;
15179 new_field
->accessibility
= DW_ACCESS_private
;
15180 fip
->non_public_fields
= true;
15183 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15185 /* C++ static member. */
15187 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15188 is a declaration, but all versions of G++ as of this writing
15189 (so through at least 3.2.1) incorrectly generate
15190 DW_TAG_variable tags. */
15192 const char *physname
;
15194 /* Get name of field. */
15195 fieldname
= dwarf2_name (die
, cu
);
15196 if (fieldname
== NULL
)
15199 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15201 /* Only create a symbol if this is an external value.
15202 new_symbol checks this and puts the value in the global symbol
15203 table, which we want. If it is not external, new_symbol
15204 will try to put the value in cu->list_in_scope which is wrong. */
15205 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15207 /* A static const member, not much different than an enum as far as
15208 we're concerned, except that we can support more types. */
15209 new_symbol (die
, NULL
, cu
);
15212 /* Get physical name. */
15213 physname
= dwarf2_physname (fieldname
, die
, cu
);
15215 /* The name is already allocated along with this objfile, so we don't
15216 need to duplicate it for the type. */
15217 fp
->set_loc_physname (physname
? physname
: "");
15218 fp
->set_type (die_type (die
, cu
));
15219 fp
->set_name (fieldname
);
15221 else if (die
->tag
== DW_TAG_inheritance
)
15223 /* C++ base class field. */
15224 handle_member_location (die
, cu
, fp
);
15225 FIELD_BITSIZE (*fp
) = 0;
15226 fp
->set_type (die_type (die
, cu
));
15227 fp
->set_name (fp
->type ()->name ());
15230 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15233 /* Can the type given by DIE define another type? */
15236 type_can_define_types (const struct die_info
*die
)
15240 case DW_TAG_typedef
:
15241 case DW_TAG_class_type
:
15242 case DW_TAG_structure_type
:
15243 case DW_TAG_union_type
:
15244 case DW_TAG_enumeration_type
:
15252 /* Add a type definition defined in the scope of the FIP's class. */
15255 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15256 struct dwarf2_cu
*cu
)
15258 struct decl_field fp
;
15259 memset (&fp
, 0, sizeof (fp
));
15261 gdb_assert (type_can_define_types (die
));
15263 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15264 fp
.name
= dwarf2_name (die
, cu
);
15265 fp
.type
= read_type_die (die
, cu
);
15267 /* Save accessibility. */
15268 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15269 switch (accessibility
)
15271 case DW_ACCESS_public
:
15272 /* The assumed value if neither private nor protected. */
15274 case DW_ACCESS_private
:
15277 case DW_ACCESS_protected
:
15278 fp
.is_protected
= 1;
15282 if (die
->tag
== DW_TAG_typedef
)
15283 fip
->typedef_field_list
.push_back (fp
);
15285 fip
->nested_types_list
.push_back (fp
);
15288 /* A convenience typedef that's used when finding the discriminant
15289 field for a variant part. */
15290 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15293 /* Compute the discriminant range for a given variant. OBSTACK is
15294 where the results will be stored. VARIANT is the variant to
15295 process. IS_UNSIGNED indicates whether the discriminant is signed
15298 static const gdb::array_view
<discriminant_range
>
15299 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15302 std::vector
<discriminant_range
> ranges
;
15304 if (variant
.default_branch
)
15307 if (variant
.discr_list_data
== nullptr)
15309 discriminant_range r
15310 = {variant
.discriminant_value
, variant
.discriminant_value
};
15311 ranges
.push_back (r
);
15315 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15316 variant
.discr_list_data
->size
);
15317 while (!data
.empty ())
15319 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15321 complaint (_("invalid discriminant marker: %d"), data
[0]);
15324 bool is_range
= data
[0] == DW_DSC_range
;
15325 data
= data
.slice (1);
15327 ULONGEST low
, high
;
15328 unsigned int bytes_read
;
15332 complaint (_("DW_AT_discr_list missing low value"));
15336 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15338 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15340 data
= data
.slice (bytes_read
);
15346 complaint (_("DW_AT_discr_list missing high value"));
15350 high
= read_unsigned_leb128 (nullptr, data
.data (),
15353 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15355 data
= data
.slice (bytes_read
);
15360 ranges
.push_back ({ low
, high
});
15364 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15366 std::copy (ranges
.begin (), ranges
.end (), result
);
15367 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15370 static const gdb::array_view
<variant_part
> create_variant_parts
15371 (struct obstack
*obstack
,
15372 const offset_map_type
&offset_map
,
15373 struct field_info
*fi
,
15374 const std::vector
<variant_part_builder
> &variant_parts
);
15376 /* Fill in a "struct variant" for a given variant field. RESULT is
15377 the variant to fill in. OBSTACK is where any needed allocations
15378 will be done. OFFSET_MAP holds the mapping from section offsets to
15379 fields for the type. FI describes the fields of the type we're
15380 processing. FIELD is the variant field we're converting. */
15383 create_one_variant (variant
&result
, struct obstack
*obstack
,
15384 const offset_map_type
&offset_map
,
15385 struct field_info
*fi
, const variant_field
&field
)
15387 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15388 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15389 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15390 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15391 field
.variant_parts
);
15394 /* Fill in a "struct variant_part" for a given variant part. RESULT
15395 is the variant part to fill in. OBSTACK is where any needed
15396 allocations will be done. OFFSET_MAP holds the mapping from
15397 section offsets to fields for the type. FI describes the fields of
15398 the type we're processing. BUILDER is the variant part to be
15402 create_one_variant_part (variant_part
&result
,
15403 struct obstack
*obstack
,
15404 const offset_map_type
&offset_map
,
15405 struct field_info
*fi
,
15406 const variant_part_builder
&builder
)
15408 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15409 if (iter
== offset_map
.end ())
15411 result
.discriminant_index
= -1;
15412 /* Doesn't matter. */
15413 result
.is_unsigned
= false;
15417 result
.discriminant_index
= iter
->second
;
15419 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15422 size_t n
= builder
.variants
.size ();
15423 variant
*output
= new (obstack
) variant
[n
];
15424 for (size_t i
= 0; i
< n
; ++i
)
15425 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15426 builder
.variants
[i
]);
15428 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15431 /* Create a vector of variant parts that can be attached to a type.
15432 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15433 holds the mapping from section offsets to fields for the type. FI
15434 describes the fields of the type we're processing. VARIANT_PARTS
15435 is the vector to convert. */
15437 static const gdb::array_view
<variant_part
>
15438 create_variant_parts (struct obstack
*obstack
,
15439 const offset_map_type
&offset_map
,
15440 struct field_info
*fi
,
15441 const std::vector
<variant_part_builder
> &variant_parts
)
15443 if (variant_parts
.empty ())
15446 size_t n
= variant_parts
.size ();
15447 variant_part
*result
= new (obstack
) variant_part
[n
];
15448 for (size_t i
= 0; i
< n
; ++i
)
15449 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15452 return gdb::array_view
<variant_part
> (result
, n
);
15455 /* Compute the variant part vector for FIP, attaching it to TYPE when
15459 add_variant_property (struct field_info
*fip
, struct type
*type
,
15460 struct dwarf2_cu
*cu
)
15462 /* Map section offsets of fields to their field index. Note the
15463 field index here does not take the number of baseclasses into
15465 offset_map_type offset_map
;
15466 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15467 offset_map
[fip
->fields
[i
].offset
] = i
;
15469 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15470 gdb::array_view
<const variant_part
> parts
15471 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15472 fip
->variant_parts
);
15474 struct dynamic_prop prop
;
15475 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15476 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15479 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15482 /* Create the vector of fields, and attach it to the type. */
15485 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15486 struct dwarf2_cu
*cu
)
15488 int nfields
= fip
->nfields ();
15490 /* Record the field count, allocate space for the array of fields,
15491 and create blank accessibility bitfields if necessary. */
15492 type
->set_num_fields (nfields
);
15494 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15496 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
15498 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15500 TYPE_FIELD_PRIVATE_BITS (type
) =
15501 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15502 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15504 TYPE_FIELD_PROTECTED_BITS (type
) =
15505 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15506 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15508 TYPE_FIELD_IGNORE_BITS (type
) =
15509 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15510 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15513 /* If the type has baseclasses, allocate and clear a bit vector for
15514 TYPE_FIELD_VIRTUAL_BITS. */
15515 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
15517 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15518 unsigned char *pointer
;
15520 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15521 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15522 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15523 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15524 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15527 if (!fip
->variant_parts
.empty ())
15528 add_variant_property (fip
, type
, cu
);
15530 /* Copy the saved-up fields into the field vector. */
15531 for (int i
= 0; i
< nfields
; ++i
)
15533 struct nextfield
&field
15534 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15535 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15537 type
->field (i
) = field
.field
;
15538 switch (field
.accessibility
)
15540 case DW_ACCESS_private
:
15541 if (cu
->per_cu
->lang
!= language_ada
)
15542 SET_TYPE_FIELD_PRIVATE (type
, i
);
15545 case DW_ACCESS_protected
:
15546 if (cu
->per_cu
->lang
!= language_ada
)
15547 SET_TYPE_FIELD_PROTECTED (type
, i
);
15550 case DW_ACCESS_public
:
15554 /* Unknown accessibility. Complain and treat it as public. */
15556 complaint (_("unsupported accessibility %d"),
15557 field
.accessibility
);
15561 if (i
< fip
->baseclasses
.size ())
15563 switch (field
.virtuality
)
15565 case DW_VIRTUALITY_virtual
:
15566 case DW_VIRTUALITY_pure_virtual
:
15567 if (cu
->per_cu
->lang
== language_ada
)
15568 error (_("unexpected virtuality in component of Ada type"));
15569 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15576 /* Return true if this member function is a constructor, false
15580 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15582 const char *fieldname
;
15583 const char *type_name
;
15586 if (die
->parent
== NULL
)
15589 if (die
->parent
->tag
!= DW_TAG_structure_type
15590 && die
->parent
->tag
!= DW_TAG_union_type
15591 && die
->parent
->tag
!= DW_TAG_class_type
)
15594 fieldname
= dwarf2_name (die
, cu
);
15595 type_name
= dwarf2_name (die
->parent
, cu
);
15596 if (fieldname
== NULL
|| type_name
== NULL
)
15599 len
= strlen (fieldname
);
15600 return (strncmp (fieldname
, type_name
, len
) == 0
15601 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15604 /* Add a member function to the proper fieldlist. */
15607 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15608 struct type
*type
, struct dwarf2_cu
*cu
)
15610 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15611 struct attribute
*attr
;
15613 struct fnfieldlist
*flp
= nullptr;
15614 struct fn_field
*fnp
;
15615 const char *fieldname
;
15616 struct type
*this_type
;
15618 if (cu
->per_cu
->lang
== language_ada
)
15619 error (_("unexpected member function in Ada type"));
15621 /* Get name of member function. */
15622 fieldname
= dwarf2_name (die
, cu
);
15623 if (fieldname
== NULL
)
15626 /* Look up member function name in fieldlist. */
15627 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15629 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15631 flp
= &fip
->fnfieldlists
[i
];
15636 /* Create a new fnfieldlist if necessary. */
15637 if (flp
== nullptr)
15639 fip
->fnfieldlists
.emplace_back ();
15640 flp
= &fip
->fnfieldlists
.back ();
15641 flp
->name
= fieldname
;
15642 i
= fip
->fnfieldlists
.size () - 1;
15645 /* Create a new member function field and add it to the vector of
15647 flp
->fnfields
.emplace_back ();
15648 fnp
= &flp
->fnfields
.back ();
15650 /* Delay processing of the physname until later. */
15651 if (cu
->per_cu
->lang
== language_cplus
)
15652 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15656 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15657 fnp
->physname
= physname
? physname
: "";
15660 fnp
->type
= alloc_type (objfile
);
15661 this_type
= read_type_die (die
, cu
);
15662 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15664 int nparams
= this_type
->num_fields ();
15666 /* TYPE is the domain of this method, and THIS_TYPE is the type
15667 of the method itself (TYPE_CODE_METHOD). */
15668 smash_to_method_type (fnp
->type
, type
,
15669 TYPE_TARGET_TYPE (this_type
),
15670 this_type
->fields (),
15671 this_type
->num_fields (),
15672 this_type
->has_varargs ());
15674 /* Handle static member functions.
15675 Dwarf2 has no clean way to discern C++ static and non-static
15676 member functions. G++ helps GDB by marking the first
15677 parameter for non-static member functions (which is the this
15678 pointer) as artificial. We obtain this information from
15679 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15680 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15681 fnp
->voffset
= VOFFSET_STATIC
;
15684 complaint (_("member function type missing for '%s'"),
15685 dwarf2_full_name (fieldname
, die
, cu
));
15687 /* Get fcontext from DW_AT_containing_type if present. */
15688 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15689 fnp
->fcontext
= die_containing_type (die
, cu
);
15691 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15692 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15694 /* Get accessibility. */
15695 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15696 switch (accessibility
)
15698 case DW_ACCESS_private
:
15699 fnp
->is_private
= 1;
15701 case DW_ACCESS_protected
:
15702 fnp
->is_protected
= 1;
15706 /* Check for artificial methods. */
15707 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15708 if (attr
&& attr
->as_boolean ())
15709 fnp
->is_artificial
= 1;
15711 /* Check for defaulted methods. */
15712 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15713 if (attr
!= nullptr)
15714 fnp
->defaulted
= attr
->defaulted ();
15716 /* Check for deleted methods. */
15717 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15718 if (attr
!= nullptr && attr
->as_boolean ())
15719 fnp
->is_deleted
= 1;
15721 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15723 /* Get index in virtual function table if it is a virtual member
15724 function. For older versions of GCC, this is an offset in the
15725 appropriate virtual table, as specified by DW_AT_containing_type.
15726 For everyone else, it is an expression to be evaluated relative
15727 to the object address. */
15729 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15730 if (attr
!= nullptr)
15732 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15734 struct dwarf_block
*block
= attr
->as_block ();
15736 if (block
->data
[0] == DW_OP_constu
)
15738 /* Old-style GCC. */
15739 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15741 else if (block
->data
[0] == DW_OP_deref
15742 || (block
->size
> 1
15743 && block
->data
[0] == DW_OP_deref_size
15744 && block
->data
[1] == cu
->header
.addr_size
))
15746 fnp
->voffset
= decode_locdesc (block
, cu
);
15747 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15748 dwarf2_complex_location_expr_complaint ();
15750 fnp
->voffset
/= cu
->header
.addr_size
;
15754 dwarf2_complex_location_expr_complaint ();
15756 if (!fnp
->fcontext
)
15758 /* If there is no `this' field and no DW_AT_containing_type,
15759 we cannot actually find a base class context for the
15761 if (this_type
->num_fields () == 0
15762 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15764 complaint (_("cannot determine context for virtual member "
15765 "function \"%s\" (offset %s)"),
15766 fieldname
, sect_offset_str (die
->sect_off
));
15771 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15775 else if (attr
->form_is_section_offset ())
15777 dwarf2_complex_location_expr_complaint ();
15781 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15787 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15788 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15790 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15791 complaint (_("Member function \"%s\" (offset %s) is virtual "
15792 "but the vtable offset is not specified"),
15793 fieldname
, sect_offset_str (die
->sect_off
));
15794 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15795 TYPE_CPLUS_DYNAMIC (type
) = 1;
15800 /* Create the vector of member function fields, and attach it to the type. */
15803 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15804 struct dwarf2_cu
*cu
)
15806 if (cu
->per_cu
->lang
== language_ada
)
15807 error (_("unexpected member functions in Ada type"));
15809 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15810 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15812 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15814 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15816 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15817 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15819 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15820 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15821 fn_flp
->fn_fields
= (struct fn_field
*)
15822 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15824 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15825 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15828 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15831 /* Returns non-zero if NAME is the name of a vtable member in CU's
15832 language, zero otherwise. */
15834 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15836 static const char vptr
[] = "_vptr";
15838 /* Look for the C++ form of the vtable. */
15839 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15845 /* GCC outputs unnamed structures that are really pointers to member
15846 functions, with the ABI-specified layout. If TYPE describes
15847 such a structure, smash it into a member function type.
15849 GCC shouldn't do this; it should just output pointer to member DIEs.
15850 This is GCC PR debug/28767. */
15853 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15855 struct type
*pfn_type
, *self_type
, *new_type
;
15857 /* Check for a structure with no name and two children. */
15858 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15861 /* Check for __pfn and __delta members. */
15862 if (type
->field (0).name () == NULL
15863 || strcmp (type
->field (0).name (), "__pfn") != 0
15864 || type
->field (1).name () == NULL
15865 || strcmp (type
->field (1).name (), "__delta") != 0)
15868 /* Find the type of the method. */
15869 pfn_type
= type
->field (0).type ();
15870 if (pfn_type
== NULL
15871 || pfn_type
->code () != TYPE_CODE_PTR
15872 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15875 /* Look for the "this" argument. */
15876 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15877 if (pfn_type
->num_fields () == 0
15878 /* || pfn_type->field (0).type () == NULL */
15879 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15882 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15883 new_type
= alloc_type (objfile
);
15884 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15885 pfn_type
->fields (), pfn_type
->num_fields (),
15886 pfn_type
->has_varargs ());
15887 smash_to_methodptr_type (type
, new_type
);
15890 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15891 requires rewriting, then copy it and return the updated copy.
15892 Otherwise return nullptr. */
15894 static struct type
*
15895 rewrite_array_type (struct type
*type
)
15897 if (type
->code () != TYPE_CODE_ARRAY
)
15900 struct type
*index_type
= type
->index_type ();
15901 range_bounds
*current_bounds
= index_type
->bounds ();
15903 /* Handle multi-dimensional arrays. */
15904 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15905 if (new_target
== nullptr)
15907 /* Maybe we don't need to rewrite this array. */
15908 if (current_bounds
->low
.kind () == PROP_CONST
15909 && current_bounds
->high
.kind () == PROP_CONST
)
15913 /* Either the target type was rewritten, or the bounds have to be
15914 updated. Either way we want to copy the type and update
15916 struct type
*copy
= copy_type (type
);
15917 int nfields
= copy
->num_fields ();
15919 = ((struct field
*) TYPE_ZALLOC (copy
,
15920 nfields
* sizeof (struct field
)));
15921 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15922 copy
->set_fields (new_fields
);
15923 if (new_target
!= nullptr)
15924 TYPE_TARGET_TYPE (copy
) = new_target
;
15926 struct type
*index_copy
= copy_type (index_type
);
15927 range_bounds
*bounds
15928 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15929 sizeof (range_bounds
));
15930 *bounds
= *current_bounds
;
15931 bounds
->low
.set_const_val (1);
15932 bounds
->high
.set_const_val (0);
15933 index_copy
->set_bounds (bounds
);
15934 copy
->set_index_type (index_copy
);
15939 /* While some versions of GCC will generate complicated DWARF for an
15940 array (see quirk_ada_thick_pointer), more recent versions were
15941 modified to emit an explicit thick pointer structure. However, in
15942 this case, the array still has DWARF expressions for its ranges,
15943 and these must be ignored. */
15946 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15949 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15951 /* Check for a structure with two children. */
15952 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15955 /* Check for P_ARRAY and P_BOUNDS members. */
15956 if (type
->field (0).name () == NULL
15957 || strcmp (type
->field (0).name (), "P_ARRAY") != 0
15958 || type
->field (1).name () == NULL
15959 || strcmp (type
->field (1).name (), "P_BOUNDS") != 0)
15962 /* Make sure we're looking at a pointer to an array. */
15963 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15966 /* The Ada code already knows how to handle these types, so all that
15967 we need to do is turn the bounds into static bounds. However, we
15968 don't want to rewrite existing array or index types in-place,
15969 because those may be referenced in other contexts where this
15970 rewriting is undesirable. */
15971 struct type
*new_ary_type
15972 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15973 if (new_ary_type
!= nullptr)
15974 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15977 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15978 appropriate error checking and issuing complaints if there is a
15982 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15984 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15986 if (attr
== nullptr)
15989 if (!attr
->form_is_constant ())
15991 complaint (_("DW_AT_alignment must have constant form"
15992 " - DIE at %s [in module %s]"),
15993 sect_offset_str (die
->sect_off
),
15994 objfile_name (cu
->per_objfile
->objfile
));
15998 LONGEST val
= attr
->constant_value (0);
16001 complaint (_("DW_AT_alignment value must not be negative"
16002 " - DIE at %s [in module %s]"),
16003 sect_offset_str (die
->sect_off
),
16004 objfile_name (cu
->per_objfile
->objfile
));
16007 ULONGEST align
= val
;
16011 complaint (_("DW_AT_alignment value must not be zero"
16012 " - DIE at %s [in module %s]"),
16013 sect_offset_str (die
->sect_off
),
16014 objfile_name (cu
->per_objfile
->objfile
));
16017 if ((align
& (align
- 1)) != 0)
16019 complaint (_("DW_AT_alignment value must be a power of 2"
16020 " - DIE at %s [in module %s]"),
16021 sect_offset_str (die
->sect_off
),
16022 objfile_name (cu
->per_objfile
->objfile
));
16029 /* If the DIE has a DW_AT_alignment attribute, use its value to set
16030 the alignment for TYPE. */
16033 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
16036 if (!set_type_align (type
, get_alignment (cu
, die
)))
16037 complaint (_("DW_AT_alignment value too large"
16038 " - DIE at %s [in module %s]"),
16039 sect_offset_str (die
->sect_off
),
16040 objfile_name (cu
->per_objfile
->objfile
));
16043 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16044 constant for a type, according to DWARF5 spec, Table 5.5. */
16047 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
16052 case DW_CC_pass_by_reference
:
16053 case DW_CC_pass_by_value
:
16057 complaint (_("unrecognized DW_AT_calling_convention value "
16058 "(%s) for a type"), pulongest (value
));
16063 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16064 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
16065 also according to GNU-specific values (see include/dwarf2.h). */
16068 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
16073 case DW_CC_program
:
16077 case DW_CC_GNU_renesas_sh
:
16078 case DW_CC_GNU_borland_fastcall_i386
:
16079 case DW_CC_GDB_IBM_OpenCL
:
16083 complaint (_("unrecognized DW_AT_calling_convention value "
16084 "(%s) for a subroutine"), pulongest (value
));
16089 /* Called when we find the DIE that starts a structure or union scope
16090 (definition) to create a type for the structure or union. Fill in
16091 the type's name and general properties; the members will not be
16092 processed until process_structure_scope. A symbol table entry for
16093 the type will also not be done until process_structure_scope (assuming
16094 the type has a name).
16096 NOTE: we need to call these functions regardless of whether or not the
16097 DIE has a DW_AT_name attribute, since it might be an anonymous
16098 structure or union. This gets the type entered into our set of
16099 user defined types. */
16101 static struct type
*
16102 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16104 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16106 struct attribute
*attr
;
16109 /* If the definition of this type lives in .debug_types, read that type.
16110 Don't follow DW_AT_specification though, that will take us back up
16111 the chain and we want to go down. */
16112 attr
= die
->attr (DW_AT_signature
);
16113 if (attr
!= nullptr)
16115 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16117 /* The type's CU may not be the same as CU.
16118 Ensure TYPE is recorded with CU in die_type_hash. */
16119 return set_die_type (die
, type
, cu
);
16122 type
= alloc_type (objfile
);
16123 INIT_CPLUS_SPECIFIC (type
);
16125 name
= dwarf2_name (die
, cu
);
16128 if (cu
->per_cu
->lang
== language_cplus
16129 || cu
->per_cu
->lang
== language_d
16130 || cu
->per_cu
->lang
== language_rust
)
16132 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16134 /* dwarf2_full_name might have already finished building the DIE's
16135 type. If so, there is no need to continue. */
16136 if (get_die_type (die
, cu
) != NULL
)
16137 return get_die_type (die
, cu
);
16139 type
->set_name (full_name
);
16143 /* The name is already allocated along with this objfile, so
16144 we don't need to duplicate it for the type. */
16145 type
->set_name (name
);
16149 if (die
->tag
== DW_TAG_structure_type
)
16151 type
->set_code (TYPE_CODE_STRUCT
);
16153 else if (die
->tag
== DW_TAG_union_type
)
16155 type
->set_code (TYPE_CODE_UNION
);
16157 else if (die
->tag
== DW_TAG_namelist
)
16159 type
->set_code (TYPE_CODE_NAMELIST
);
16163 type
->set_code (TYPE_CODE_STRUCT
);
16166 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16167 type
->set_is_declared_class (true);
16169 /* Store the calling convention in the type if it's available in
16170 the die. Otherwise the calling convention remains set to
16171 the default value DW_CC_normal. */
16172 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16173 if (attr
!= nullptr
16174 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
16176 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16177 TYPE_CPLUS_CALLING_CONVENTION (type
)
16178 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
16181 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16182 if (attr
!= nullptr)
16184 if (attr
->form_is_constant ())
16185 TYPE_LENGTH (type
) = attr
->constant_value (0);
16188 struct dynamic_prop prop
;
16189 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16190 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16191 TYPE_LENGTH (type
) = 0;
16196 TYPE_LENGTH (type
) = 0;
16199 maybe_set_alignment (cu
, die
, type
);
16201 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16203 /* ICC<14 does not output the required DW_AT_declaration on
16204 incomplete types, but gives them a size of zero. */
16205 type
->set_is_stub (true);
16208 type
->set_stub_is_supported (true);
16210 if (die_is_declaration (die
, cu
))
16211 type
->set_is_stub (true);
16212 else if (attr
== NULL
&& die
->child
== NULL
16213 && producer_is_realview (cu
->producer
))
16214 /* RealView does not output the required DW_AT_declaration
16215 on incomplete types. */
16216 type
->set_is_stub (true);
16218 /* We need to add the type field to the die immediately so we don't
16219 infinitely recurse when dealing with pointers to the structure
16220 type within the structure itself. */
16221 set_die_type (die
, type
, cu
);
16223 /* set_die_type should be already done. */
16224 set_descriptive_type (type
, die
, cu
);
16229 static void handle_struct_member_die
16230 (struct die_info
*child_die
,
16232 struct field_info
*fi
,
16233 std::vector
<struct symbol
*> *template_args
,
16234 struct dwarf2_cu
*cu
);
16236 /* A helper for handle_struct_member_die that handles
16237 DW_TAG_variant_part. */
16240 handle_variant_part (struct die_info
*die
, struct type
*type
,
16241 struct field_info
*fi
,
16242 std::vector
<struct symbol
*> *template_args
,
16243 struct dwarf2_cu
*cu
)
16245 variant_part_builder
*new_part
;
16246 if (fi
->current_variant_part
== nullptr)
16248 fi
->variant_parts
.emplace_back ();
16249 new_part
= &fi
->variant_parts
.back ();
16251 else if (!fi
->current_variant_part
->processing_variant
)
16253 complaint (_("nested DW_TAG_variant_part seen "
16254 "- DIE at %s [in module %s]"),
16255 sect_offset_str (die
->sect_off
),
16256 objfile_name (cu
->per_objfile
->objfile
));
16261 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16262 current
.variant_parts
.emplace_back ();
16263 new_part
= ¤t
.variant_parts
.back ();
16266 /* When we recurse, we want callees to add to this new variant
16268 scoped_restore save_current_variant_part
16269 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16271 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16274 /* It's a univariant form, an extension we support. */
16276 else if (discr
->form_is_ref ())
16278 struct dwarf2_cu
*target_cu
= cu
;
16279 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16281 new_part
->discriminant_offset
= target_die
->sect_off
;
16285 complaint (_("DW_AT_discr does not have DIE reference form"
16286 " - DIE at %s [in module %s]"),
16287 sect_offset_str (die
->sect_off
),
16288 objfile_name (cu
->per_objfile
->objfile
));
16291 for (die_info
*child_die
= die
->child
;
16293 child_die
= child_die
->sibling
)
16294 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16297 /* A helper for handle_struct_member_die that handles
16301 handle_variant (struct die_info
*die
, struct type
*type
,
16302 struct field_info
*fi
,
16303 std::vector
<struct symbol
*> *template_args
,
16304 struct dwarf2_cu
*cu
)
16306 if (fi
->current_variant_part
== nullptr)
16308 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16309 "- DIE at %s [in module %s]"),
16310 sect_offset_str (die
->sect_off
),
16311 objfile_name (cu
->per_objfile
->objfile
));
16314 if (fi
->current_variant_part
->processing_variant
)
16316 complaint (_("nested DW_TAG_variant seen "
16317 "- DIE at %s [in module %s]"),
16318 sect_offset_str (die
->sect_off
),
16319 objfile_name (cu
->per_objfile
->objfile
));
16323 scoped_restore save_processing_variant
16324 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16327 fi
->current_variant_part
->variants
.emplace_back ();
16328 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16329 variant
.first_field
= fi
->fields
.size ();
16331 /* In a variant we want to get the discriminant and also add a
16332 field for our sole member child. */
16333 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16334 if (discr
== nullptr || !discr
->form_is_constant ())
16336 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16337 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16338 variant
.default_branch
= true;
16340 variant
.discr_list_data
= discr
->as_block ();
16343 variant
.discriminant_value
= discr
->constant_value (0);
16345 for (die_info
*variant_child
= die
->child
;
16346 variant_child
!= NULL
;
16347 variant_child
= variant_child
->sibling
)
16348 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16350 variant
.last_field
= fi
->fields
.size ();
16353 /* A helper for process_structure_scope that handles a single member
16357 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16358 struct field_info
*fi
,
16359 std::vector
<struct symbol
*> *template_args
,
16360 struct dwarf2_cu
*cu
)
16362 if (child_die
->tag
== DW_TAG_member
16363 || child_die
->tag
== DW_TAG_variable
16364 || child_die
->tag
== DW_TAG_namelist_item
)
16366 /* NOTE: carlton/2002-11-05: A C++ static data member
16367 should be a DW_TAG_member that is a declaration, but
16368 all versions of G++ as of this writing (so through at
16369 least 3.2.1) incorrectly generate DW_TAG_variable
16370 tags for them instead. */
16371 dwarf2_add_field (fi
, child_die
, cu
);
16373 else if (child_die
->tag
== DW_TAG_subprogram
)
16375 /* Rust doesn't have member functions in the C++ sense.
16376 However, it does emit ordinary functions as children
16377 of a struct DIE. */
16378 if (cu
->per_cu
->lang
== language_rust
)
16379 read_func_scope (child_die
, cu
);
16382 /* C++ member function. */
16383 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16386 else if (child_die
->tag
== DW_TAG_inheritance
)
16388 /* C++ base class field. */
16389 dwarf2_add_field (fi
, child_die
, cu
);
16391 else if (type_can_define_types (child_die
))
16392 dwarf2_add_type_defn (fi
, child_die
, cu
);
16393 else if (child_die
->tag
== DW_TAG_template_type_param
16394 || child_die
->tag
== DW_TAG_template_value_param
)
16396 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16399 template_args
->push_back (arg
);
16401 else if (child_die
->tag
== DW_TAG_variant_part
)
16402 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16403 else if (child_die
->tag
== DW_TAG_variant
)
16404 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16407 /* Finish creating a structure or union type, including filling in its
16408 members and creating a symbol for it. This function also handles Fortran
16409 namelist variables, their items or members and creating a symbol for
16413 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16415 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16416 struct die_info
*child_die
;
16419 type
= get_die_type (die
, cu
);
16421 type
= read_structure_type (die
, cu
);
16423 bool has_template_parameters
= false;
16424 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16426 struct field_info fi
;
16427 std::vector
<struct symbol
*> template_args
;
16429 child_die
= die
->child
;
16431 while (child_die
&& child_die
->tag
)
16433 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16434 child_die
= child_die
->sibling
;
16437 /* Attach template arguments to type. */
16438 if (!template_args
.empty ())
16440 has_template_parameters
= true;
16441 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16442 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16443 TYPE_TEMPLATE_ARGUMENTS (type
)
16444 = XOBNEWVEC (&objfile
->objfile_obstack
,
16446 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16447 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16448 template_args
.data (),
16449 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16450 * sizeof (struct symbol
*)));
16453 /* Attach fields and member functions to the type. */
16454 if (fi
.nfields () > 0)
16455 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16456 if (!fi
.fnfieldlists
.empty ())
16458 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16460 /* Get the type which refers to the base class (possibly this
16461 class itself) which contains the vtable pointer for the current
16462 class from the DW_AT_containing_type attribute. This use of
16463 DW_AT_containing_type is a GNU extension. */
16465 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16467 struct type
*t
= die_containing_type (die
, cu
);
16469 set_type_vptr_basetype (type
, t
);
16474 /* Our own class provides vtbl ptr. */
16475 for (i
= t
->num_fields () - 1;
16476 i
>= TYPE_N_BASECLASSES (t
);
16479 const char *fieldname
= t
->field (i
).name ();
16481 if (is_vtable_name (fieldname
, cu
))
16483 set_type_vptr_fieldno (type
, i
);
16488 /* Complain if virtual function table field not found. */
16489 if (i
< TYPE_N_BASECLASSES (t
))
16490 complaint (_("virtual function table pointer "
16491 "not found when defining class '%s'"),
16492 type
->name () ? type
->name () : "");
16496 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16499 else if (cu
->producer
16500 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16502 /* The IBM XLC compiler does not provide direct indication
16503 of the containing type, but the vtable pointer is
16504 always named __vfp. */
16508 for (i
= type
->num_fields () - 1;
16509 i
>= TYPE_N_BASECLASSES (type
);
16512 if (strcmp (type
->field (i
).name (), "__vfp") == 0)
16514 set_type_vptr_fieldno (type
, i
);
16515 set_type_vptr_basetype (type
, type
);
16522 /* Copy fi.typedef_field_list linked list elements content into the
16523 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16524 if (!fi
.typedef_field_list
.empty ())
16526 int count
= fi
.typedef_field_list
.size ();
16528 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16529 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16530 = ((struct decl_field
*)
16532 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16533 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16535 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16536 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16539 /* Copy fi.nested_types_list linked list elements content into the
16540 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16541 if (!fi
.nested_types_list
.empty ()
16542 && cu
->per_cu
->lang
!= language_ada
)
16544 int count
= fi
.nested_types_list
.size ();
16546 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16547 TYPE_NESTED_TYPES_ARRAY (type
)
16548 = ((struct decl_field
*)
16549 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16550 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16552 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16553 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16557 quirk_gcc_member_function_pointer (type
, objfile
);
16558 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16559 cu
->rust_unions
.push_back (type
);
16560 else if (cu
->per_cu
->lang
== language_ada
)
16561 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16563 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16564 snapshots) has been known to create a die giving a declaration
16565 for a class that has, as a child, a die giving a definition for a
16566 nested class. So we have to process our children even if the
16567 current die is a declaration. Normally, of course, a declaration
16568 won't have any children at all. */
16570 child_die
= die
->child
;
16572 while (child_die
!= NULL
&& child_die
->tag
)
16574 if (child_die
->tag
== DW_TAG_member
16575 || child_die
->tag
== DW_TAG_variable
16576 || child_die
->tag
== DW_TAG_inheritance
16577 || child_die
->tag
== DW_TAG_template_value_param
16578 || child_die
->tag
== DW_TAG_template_type_param
)
16583 process_die (child_die
, cu
);
16585 child_die
= child_die
->sibling
;
16588 /* Do not consider external references. According to the DWARF standard,
16589 these DIEs are identified by the fact that they have no byte_size
16590 attribute, and a declaration attribute. */
16591 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16592 || !die_is_declaration (die
, cu
)
16593 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16595 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16597 if (has_template_parameters
)
16599 struct symtab
*symtab
;
16600 if (sym
!= nullptr)
16601 symtab
= symbol_symtab (sym
);
16602 else if (cu
->line_header
!= nullptr)
16604 /* Any related symtab will do. */
16606 = cu
->line_header
->file_names ()[0].symtab
;
16611 complaint (_("could not find suitable "
16612 "symtab for template parameter"
16613 " - DIE at %s [in module %s]"),
16614 sect_offset_str (die
->sect_off
),
16615 objfile_name (objfile
));
16618 if (symtab
!= nullptr)
16620 /* Make sure that the symtab is set on the new symbols.
16621 Even though they don't appear in this symtab directly,
16622 other parts of gdb assume that symbols do, and this is
16623 reasonably true. */
16624 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16625 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16631 /* Assuming DIE is an enumeration type, and TYPE is its associated
16632 type, update TYPE using some information only available in DIE's
16633 children. In particular, the fields are computed. */
16636 update_enumeration_type_from_children (struct die_info
*die
,
16638 struct dwarf2_cu
*cu
)
16640 struct die_info
*child_die
;
16641 int unsigned_enum
= 1;
16644 auto_obstack obstack
;
16645 std::vector
<struct field
> fields
;
16647 for (child_die
= die
->child
;
16648 child_die
!= NULL
&& child_die
->tag
;
16649 child_die
= child_die
->sibling
)
16651 struct attribute
*attr
;
16653 const gdb_byte
*bytes
;
16654 struct dwarf2_locexpr_baton
*baton
;
16657 if (child_die
->tag
!= DW_TAG_enumerator
)
16660 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16664 name
= dwarf2_name (child_die
, cu
);
16666 name
= "<anonymous enumerator>";
16668 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16669 &value
, &bytes
, &baton
);
16677 if (count_one_bits_ll (value
) >= 2)
16681 fields
.emplace_back ();
16682 struct field
&field
= fields
.back ();
16683 field
.set_name (dwarf2_physname (name
, child_die
, cu
));
16684 field
.set_loc_enumval (value
);
16687 if (!fields
.empty ())
16689 type
->set_num_fields (fields
.size ());
16692 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16693 memcpy (type
->fields (), fields
.data (),
16694 sizeof (struct field
) * fields
.size ());
16698 type
->set_is_unsigned (true);
16701 type
->set_is_flag_enum (true);
16704 /* Given a DW_AT_enumeration_type die, set its type. We do not
16705 complete the type's fields yet, or create any symbols. */
16707 static struct type
*
16708 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16710 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16712 struct attribute
*attr
;
16715 /* If the definition of this type lives in .debug_types, read that type.
16716 Don't follow DW_AT_specification though, that will take us back up
16717 the chain and we want to go down. */
16718 attr
= die
->attr (DW_AT_signature
);
16719 if (attr
!= nullptr)
16721 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16723 /* The type's CU may not be the same as CU.
16724 Ensure TYPE is recorded with CU in die_type_hash. */
16725 return set_die_type (die
, type
, cu
);
16728 type
= alloc_type (objfile
);
16730 type
->set_code (TYPE_CODE_ENUM
);
16731 name
= dwarf2_full_name (NULL
, die
, cu
);
16733 type
->set_name (name
);
16735 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16738 struct type
*underlying_type
= die_type (die
, cu
);
16740 TYPE_TARGET_TYPE (type
) = underlying_type
;
16743 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16744 if (attr
!= nullptr)
16746 TYPE_LENGTH (type
) = attr
->constant_value (0);
16750 TYPE_LENGTH (type
) = 0;
16753 maybe_set_alignment (cu
, die
, type
);
16755 /* The enumeration DIE can be incomplete. In Ada, any type can be
16756 declared as private in the package spec, and then defined only
16757 inside the package body. Such types are known as Taft Amendment
16758 Types. When another package uses such a type, an incomplete DIE
16759 may be generated by the compiler. */
16760 if (die_is_declaration (die
, cu
))
16761 type
->set_is_stub (true);
16763 /* If this type has an underlying type that is not a stub, then we
16764 may use its attributes. We always use the "unsigned" attribute
16765 in this situation, because ordinarily we guess whether the type
16766 is unsigned -- but the guess can be wrong and the underlying type
16767 can tell us the reality. However, we defer to a local size
16768 attribute if one exists, because this lets the compiler override
16769 the underlying type if needed. */
16770 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16772 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16773 underlying_type
= check_typedef (underlying_type
);
16775 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16777 if (TYPE_LENGTH (type
) == 0)
16778 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16780 if (TYPE_RAW_ALIGN (type
) == 0
16781 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16782 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16785 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16787 set_die_type (die
, type
, cu
);
16789 /* Finish the creation of this type by using the enum's children.
16790 Note that, as usual, this must come after set_die_type to avoid
16791 infinite recursion when trying to compute the names of the
16793 update_enumeration_type_from_children (die
, type
, cu
);
16798 /* Given a pointer to a die which begins an enumeration, process all
16799 the dies that define the members of the enumeration, and create the
16800 symbol for the enumeration type.
16802 NOTE: We reverse the order of the element list. */
16805 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16807 struct type
*this_type
;
16809 this_type
= get_die_type (die
, cu
);
16810 if (this_type
== NULL
)
16811 this_type
= read_enumeration_type (die
, cu
);
16813 if (die
->child
!= NULL
)
16815 struct die_info
*child_die
;
16818 child_die
= die
->child
;
16819 while (child_die
&& child_die
->tag
)
16821 if (child_die
->tag
!= DW_TAG_enumerator
)
16823 process_die (child_die
, cu
);
16827 name
= dwarf2_name (child_die
, cu
);
16829 new_symbol (child_die
, this_type
, cu
);
16832 child_die
= child_die
->sibling
;
16836 /* If we are reading an enum from a .debug_types unit, and the enum
16837 is a declaration, and the enum is not the signatured type in the
16838 unit, then we do not want to add a symbol for it. Adding a
16839 symbol would in some cases obscure the true definition of the
16840 enum, giving users an incomplete type when the definition is
16841 actually available. Note that we do not want to do this for all
16842 enums which are just declarations, because C++0x allows forward
16843 enum declarations. */
16844 if (cu
->per_cu
->is_debug_types
16845 && die_is_declaration (die
, cu
))
16847 struct signatured_type
*sig_type
;
16849 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16850 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16851 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16855 new_symbol (die
, this_type
, cu
);
16858 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16859 expression for an index type and finds the corresponding field
16860 offset in the hidden "P_BOUNDS" structure. Returns true on success
16861 and updates *FIELD, false if it fails to recognize an
16865 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16866 int *bounds_offset
, struct field
*field
,
16867 struct dwarf2_cu
*cu
)
16869 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16870 if (attr
== nullptr || !attr
->form_is_block ())
16873 const struct dwarf_block
*block
= attr
->as_block ();
16874 const gdb_byte
*start
= block
->data
;
16875 const gdb_byte
*end
= block
->data
+ block
->size
;
16877 /* The expression to recognize generally looks like:
16879 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16880 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16882 However, the second "plus_uconst" may be missing:
16884 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16885 DW_OP_deref_size: 4)
16887 This happens when the field is at the start of the structure.
16889 Also, the final deref may not be sized:
16891 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16894 This happens when the size of the index type happens to be the
16895 same as the architecture's word size. This can occur with or
16896 without the second plus_uconst. */
16898 if (end
- start
< 2)
16900 if (*start
++ != DW_OP_push_object_address
)
16902 if (*start
++ != DW_OP_plus_uconst
)
16905 uint64_t this_bound_off
;
16906 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16907 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16909 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16910 is consistent among all bounds. */
16911 if (*bounds_offset
== -1)
16912 *bounds_offset
= this_bound_off
;
16913 else if (*bounds_offset
!= this_bound_off
)
16916 if (start
== end
|| *start
++ != DW_OP_deref
)
16922 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16924 /* This means an offset of 0. */
16926 else if (*start
++ != DW_OP_plus_uconst
)
16930 /* The size is the parameter to DW_OP_plus_uconst. */
16932 start
= gdb_read_uleb128 (start
, end
, &val
);
16933 if (start
== nullptr)
16935 if ((int) val
!= val
)
16944 if (*start
== DW_OP_deref_size
)
16946 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16947 if (start
== nullptr)
16950 else if (*start
== DW_OP_deref
)
16952 size
= cu
->header
.addr_size
;
16958 field
->set_loc_bitpos (8 * offset
);
16959 if (size
!= TYPE_LENGTH (field
->type ()))
16960 FIELD_BITSIZE (*field
) = 8 * size
;
16965 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16966 some kinds of Ada arrays:
16968 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16969 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16970 <11e0> DW_AT_data_location: 2 byte block: 97 6
16971 (DW_OP_push_object_address; DW_OP_deref)
16972 <11e3> DW_AT_type : <0x1173>
16973 <11e7> DW_AT_sibling : <0x1201>
16974 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16975 <11ec> DW_AT_type : <0x1206>
16976 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16977 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16978 DW_OP_deref_size: 4)
16979 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16980 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16981 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16983 This actually represents a "thick pointer", which is a structure
16984 with two elements: one that is a pointer to the array data, and one
16985 that is a pointer to another structure; this second structure holds
16988 This returns a new type on success, or nullptr if this didn't
16989 recognize the type. */
16991 static struct type
*
16992 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16995 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16996 /* So far we've only seen this with block form. */
16997 if (attr
== nullptr || !attr
->form_is_block ())
17000 /* Note that this will fail if the structure layout is changed by
17001 the compiler. However, we have no good way to recognize some
17002 other layout, because we don't know what expression the compiler
17003 might choose to emit should this happen. */
17004 struct dwarf_block
*blk
= attr
->as_block ();
17006 || blk
->data
[0] != DW_OP_push_object_address
17007 || blk
->data
[1] != DW_OP_deref
)
17010 int bounds_offset
= -1;
17011 int max_align
= -1;
17012 std::vector
<struct field
> range_fields
;
17013 for (struct die_info
*child_die
= die
->child
;
17015 child_die
= child_die
->sibling
)
17017 if (child_die
->tag
== DW_TAG_subrange_type
)
17019 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
17021 int this_align
= type_align (underlying
);
17022 if (this_align
> max_align
)
17023 max_align
= this_align
;
17025 range_fields
.emplace_back ();
17026 range_fields
.emplace_back ();
17028 struct field
&lower
= range_fields
[range_fields
.size () - 2];
17029 struct field
&upper
= range_fields
[range_fields
.size () - 1];
17031 lower
.set_type (underlying
);
17032 FIELD_ARTIFICIAL (lower
) = 1;
17034 upper
.set_type (underlying
);
17035 FIELD_ARTIFICIAL (upper
) = 1;
17037 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
17038 &bounds_offset
, &lower
, cu
)
17039 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
17040 &bounds_offset
, &upper
, cu
))
17045 /* This shouldn't really happen, but double-check that we found
17046 where the bounds are stored. */
17047 if (bounds_offset
== -1)
17050 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17051 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17055 /* Set the name of each field in the bounds. */
17056 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
17057 range_fields
[i
].set_name (objfile
->intern (name
));
17058 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
17059 range_fields
[i
+ 1].set_name (objfile
->intern (name
));
17062 struct type
*bounds
= alloc_type (objfile
);
17063 bounds
->set_code (TYPE_CODE_STRUCT
);
17065 bounds
->set_num_fields (range_fields
.size ());
17067 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
17068 * sizeof (struct field
))));
17069 memcpy (bounds
->fields (), range_fields
.data (),
17070 bounds
->num_fields () * sizeof (struct field
));
17072 int last_fieldno
= range_fields
.size () - 1;
17073 int bounds_size
= (bounds
->field (last_fieldno
).loc_bitpos () / 8
17074 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
17075 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
17077 /* Rewrite the existing array type in place. Specifically, we
17078 remove any dynamic properties we might have read, and we replace
17079 the index types. */
17080 struct type
*iter
= type
;
17081 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17083 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
17084 iter
->main_type
->dyn_prop_list
= nullptr;
17085 iter
->set_index_type
17086 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
17087 iter
= TYPE_TARGET_TYPE (iter
);
17090 struct type
*result
= alloc_type (objfile
);
17091 result
->set_code (TYPE_CODE_STRUCT
);
17093 result
->set_num_fields (2);
17095 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
17096 * sizeof (struct field
))));
17098 /* The names are chosen to coincide with what the compiler does with
17099 -fgnat-encodings=all, which the Ada code in gdb already
17101 result
->field (0).set_name ("P_ARRAY");
17102 result
->field (0).set_type (lookup_pointer_type (type
));
17104 result
->field (1).set_name ("P_BOUNDS");
17105 result
->field (1).set_type (lookup_pointer_type (bounds
));
17106 result
->field (1).set_loc_bitpos (8 * bounds_offset
);
17108 result
->set_name (type
->name ());
17109 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
17110 + TYPE_LENGTH (result
->field (1).type ()));
17115 /* Extract all information from a DW_TAG_array_type DIE and put it in
17116 the DIE's type field. For now, this only handles one dimensional
17119 static struct type
*
17120 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17122 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17123 struct die_info
*child_die
;
17125 struct type
*element_type
, *range_type
, *index_type
;
17126 struct attribute
*attr
;
17128 struct dynamic_prop
*byte_stride_prop
= NULL
;
17129 unsigned int bit_stride
= 0;
17131 element_type
= die_type (die
, cu
);
17133 /* The die_type call above may have already set the type for this DIE. */
17134 type
= get_die_type (die
, cu
);
17138 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17142 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17145 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
17146 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
17150 complaint (_("unable to read array DW_AT_byte_stride "
17151 " - DIE at %s [in module %s]"),
17152 sect_offset_str (die
->sect_off
),
17153 objfile_name (cu
->per_objfile
->objfile
));
17154 /* Ignore this attribute. We will likely not be able to print
17155 arrays of this type correctly, but there is little we can do
17156 to help if we cannot read the attribute's value. */
17157 byte_stride_prop
= NULL
;
17161 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17163 bit_stride
= attr
->constant_value (0);
17165 /* Irix 6.2 native cc creates array types without children for
17166 arrays with unspecified length. */
17167 if (die
->child
== NULL
)
17169 index_type
= objfile_type (objfile
)->builtin_int
;
17170 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
17171 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
17172 byte_stride_prop
, bit_stride
);
17173 return set_die_type (die
, type
, cu
);
17176 std::vector
<struct type
*> range_types
;
17177 child_die
= die
->child
;
17178 while (child_die
&& child_die
->tag
)
17180 if (child_die
->tag
== DW_TAG_subrange_type
17181 || child_die
->tag
== DW_TAG_generic_subrange
)
17183 struct type
*child_type
= read_type_die (child_die
, cu
);
17185 if (child_type
!= NULL
)
17187 /* The range type was succesfully read. Save it for the
17188 array type creation. */
17189 range_types
.push_back (child_type
);
17192 child_die
= child_die
->sibling
;
17195 if (range_types
.empty ())
17197 complaint (_("unable to find array range - DIE at %s [in module %s]"),
17198 sect_offset_str (die
->sect_off
),
17199 objfile_name (cu
->per_objfile
->objfile
));
17203 /* Dwarf2 dimensions are output from left to right, create the
17204 necessary array types in backwards order. */
17206 type
= element_type
;
17208 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
17212 while (i
< range_types
.size ())
17214 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
17215 byte_stride_prop
, bit_stride
);
17217 byte_stride_prop
= nullptr;
17222 size_t ndim
= range_types
.size ();
17225 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
17226 byte_stride_prop
, bit_stride
);
17228 byte_stride_prop
= nullptr;
17232 gdb_assert (type
!= element_type
);
17234 /* Understand Dwarf2 support for vector types (like they occur on
17235 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
17236 array type. This is not part of the Dwarf2/3 standard yet, but a
17237 custom vendor extension. The main difference between a regular
17238 array and the vector variant is that vectors are passed by value
17240 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
17241 if (attr
!= nullptr)
17242 make_vector_type (type
);
17244 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
17245 implementation may choose to implement triple vectors using this
17247 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17248 if (attr
!= nullptr && attr
->form_is_unsigned ())
17250 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
17251 TYPE_LENGTH (type
) = attr
->as_unsigned ();
17253 complaint (_("DW_AT_byte_size for array type smaller "
17254 "than the total size of elements"));
17257 name
= dwarf2_name (die
, cu
);
17259 type
->set_name (name
);
17261 maybe_set_alignment (cu
, die
, type
);
17263 struct type
*replacement_type
= nullptr;
17264 if (cu
->per_cu
->lang
== language_ada
)
17266 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
17267 if (replacement_type
!= nullptr)
17268 type
= replacement_type
;
17271 /* Install the type in the die. */
17272 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
17274 /* set_die_type should be already done. */
17275 set_descriptive_type (type
, die
, cu
);
17280 static enum dwarf_array_dim_ordering
17281 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
17283 struct attribute
*attr
;
17285 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
17287 if (attr
!= nullptr)
17289 LONGEST val
= attr
->constant_value (-1);
17290 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
17291 return (enum dwarf_array_dim_ordering
) val
;
17294 /* GNU F77 is a special case, as at 08/2004 array type info is the
17295 opposite order to the dwarf2 specification, but data is still
17296 laid out as per normal fortran.
17298 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
17299 version checking. */
17301 if (cu
->per_cu
->lang
== language_fortran
17302 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
17304 return DW_ORD_row_major
;
17307 switch (cu
->language_defn
->array_ordering ())
17309 case array_column_major
:
17310 return DW_ORD_col_major
;
17311 case array_row_major
:
17313 return DW_ORD_row_major
;
17317 /* Extract all information from a DW_TAG_set_type DIE and put it in
17318 the DIE's type field. */
17320 static struct type
*
17321 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17323 struct type
*domain_type
, *set_type
;
17324 struct attribute
*attr
;
17326 domain_type
= die_type (die
, cu
);
17328 /* The die_type call above may have already set the type for this DIE. */
17329 set_type
= get_die_type (die
, cu
);
17333 set_type
= create_set_type (NULL
, domain_type
);
17335 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17336 if (attr
!= nullptr && attr
->form_is_unsigned ())
17337 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
17339 maybe_set_alignment (cu
, die
, set_type
);
17341 return set_die_type (die
, set_type
, cu
);
17344 /* A helper for read_common_block that creates a locexpr baton.
17345 SYM is the symbol which we are marking as computed.
17346 COMMON_DIE is the DIE for the common block.
17347 COMMON_LOC is the location expression attribute for the common
17349 MEMBER_LOC is the location expression attribute for the particular
17350 member of the common block that we are processing.
17351 CU is the CU from which the above come. */
17354 mark_common_block_symbol_computed (struct symbol
*sym
,
17355 struct die_info
*common_die
,
17356 struct attribute
*common_loc
,
17357 struct attribute
*member_loc
,
17358 struct dwarf2_cu
*cu
)
17360 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17361 struct objfile
*objfile
= per_objfile
->objfile
;
17362 struct dwarf2_locexpr_baton
*baton
;
17364 unsigned int cu_off
;
17365 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
17366 LONGEST offset
= 0;
17368 gdb_assert (common_loc
&& member_loc
);
17369 gdb_assert (common_loc
->form_is_block ());
17370 gdb_assert (member_loc
->form_is_block ()
17371 || member_loc
->form_is_constant ());
17373 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17374 baton
->per_objfile
= per_objfile
;
17375 baton
->per_cu
= cu
->per_cu
;
17376 gdb_assert (baton
->per_cu
);
17378 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17380 if (member_loc
->form_is_constant ())
17382 offset
= member_loc
->constant_value (0);
17383 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17386 baton
->size
+= member_loc
->as_block ()->size
;
17388 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17391 *ptr
++ = DW_OP_call4
;
17392 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17393 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17396 if (member_loc
->form_is_constant ())
17398 *ptr
++ = DW_OP_addr
;
17399 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17400 ptr
+= cu
->header
.addr_size
;
17404 /* We have to copy the data here, because DW_OP_call4 will only
17405 use a DW_AT_location attribute. */
17406 struct dwarf_block
*block
= member_loc
->as_block ();
17407 memcpy (ptr
, block
->data
, block
->size
);
17408 ptr
+= block
->size
;
17411 *ptr
++ = DW_OP_plus
;
17412 gdb_assert (ptr
- baton
->data
== baton
->size
);
17414 SYMBOL_LOCATION_BATON (sym
) = baton
;
17415 sym
->set_aclass_index (dwarf2_locexpr_index
);
17418 /* Create appropriate locally-scoped variables for all the
17419 DW_TAG_common_block entries. Also create a struct common_block
17420 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17421 is used to separate the common blocks name namespace from regular
17425 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17427 struct attribute
*attr
;
17429 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17430 if (attr
!= nullptr)
17432 /* Support the .debug_loc offsets. */
17433 if (attr
->form_is_block ())
17437 else if (attr
->form_is_section_offset ())
17439 dwarf2_complex_location_expr_complaint ();
17444 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17445 "common block member");
17450 if (die
->child
!= NULL
)
17452 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17453 struct die_info
*child_die
;
17454 size_t n_entries
= 0, size
;
17455 struct common_block
*common_block
;
17456 struct symbol
*sym
;
17458 for (child_die
= die
->child
;
17459 child_die
&& child_die
->tag
;
17460 child_die
= child_die
->sibling
)
17463 size
= (sizeof (struct common_block
)
17464 + (n_entries
- 1) * sizeof (struct symbol
*));
17466 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17468 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17469 common_block
->n_entries
= 0;
17471 for (child_die
= die
->child
;
17472 child_die
&& child_die
->tag
;
17473 child_die
= child_die
->sibling
)
17475 /* Create the symbol in the DW_TAG_common_block block in the current
17477 sym
= new_symbol (child_die
, NULL
, cu
);
17480 struct attribute
*member_loc
;
17482 common_block
->contents
[common_block
->n_entries
++] = sym
;
17484 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17488 /* GDB has handled this for a long time, but it is
17489 not specified by DWARF. It seems to have been
17490 emitted by gfortran at least as recently as:
17491 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17492 complaint (_("Variable in common block has "
17493 "DW_AT_data_member_location "
17494 "- DIE at %s [in module %s]"),
17495 sect_offset_str (child_die
->sect_off
),
17496 objfile_name (objfile
));
17498 if (member_loc
->form_is_section_offset ())
17499 dwarf2_complex_location_expr_complaint ();
17500 else if (member_loc
->form_is_constant ()
17501 || member_loc
->form_is_block ())
17503 if (attr
!= nullptr)
17504 mark_common_block_symbol_computed (sym
, die
, attr
,
17508 dwarf2_complex_location_expr_complaint ();
17513 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17514 sym
->set_value_common_block (common_block
);
17518 /* Create a type for a C++ namespace. */
17520 static struct type
*
17521 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17523 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17524 const char *previous_prefix
, *name
;
17528 /* For extensions, reuse the type of the original namespace. */
17529 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17531 struct die_info
*ext_die
;
17532 struct dwarf2_cu
*ext_cu
= cu
;
17534 ext_die
= dwarf2_extension (die
, &ext_cu
);
17535 type
= read_type_die (ext_die
, ext_cu
);
17537 /* EXT_CU may not be the same as CU.
17538 Ensure TYPE is recorded with CU in die_type_hash. */
17539 return set_die_type (die
, type
, cu
);
17542 name
= namespace_name (die
, &is_anonymous
, cu
);
17544 /* Now build the name of the current namespace. */
17546 previous_prefix
= determine_prefix (die
, cu
);
17547 if (previous_prefix
[0] != '\0')
17548 name
= typename_concat (&objfile
->objfile_obstack
,
17549 previous_prefix
, name
, 0, cu
);
17551 /* Create the type. */
17552 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17554 return set_die_type (die
, type
, cu
);
17557 /* Read a namespace scope. */
17560 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17562 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17565 /* Add a symbol associated to this if we haven't seen the namespace
17566 before. Also, add a using directive if it's an anonymous
17569 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17573 type
= read_type_die (die
, cu
);
17574 new_symbol (die
, type
, cu
);
17576 namespace_name (die
, &is_anonymous
, cu
);
17579 const char *previous_prefix
= determine_prefix (die
, cu
);
17581 std::vector
<const char *> excludes
;
17582 add_using_directive (using_directives (cu
),
17583 previous_prefix
, type
->name (), NULL
,
17584 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17588 if (die
->child
!= NULL
)
17590 struct die_info
*child_die
= die
->child
;
17592 while (child_die
&& child_die
->tag
)
17594 process_die (child_die
, cu
);
17595 child_die
= child_die
->sibling
;
17600 /* Read a Fortran module as type. This DIE can be only a declaration used for
17601 imported module. Still we need that type as local Fortran "use ... only"
17602 declaration imports depend on the created type in determine_prefix. */
17604 static struct type
*
17605 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17607 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17608 const char *module_name
;
17611 module_name
= dwarf2_name (die
, cu
);
17612 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17614 return set_die_type (die
, type
, cu
);
17617 /* Read a Fortran module. */
17620 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17622 struct die_info
*child_die
= die
->child
;
17625 type
= read_type_die (die
, cu
);
17626 new_symbol (die
, type
, cu
);
17628 while (child_die
&& child_die
->tag
)
17630 process_die (child_die
, cu
);
17631 child_die
= child_die
->sibling
;
17635 /* Return the name of the namespace represented by DIE. Set
17636 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17639 static const char *
17640 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17642 struct die_info
*current_die
;
17643 const char *name
= NULL
;
17645 /* Loop through the extensions until we find a name. */
17647 for (current_die
= die
;
17648 current_die
!= NULL
;
17649 current_die
= dwarf2_extension (die
, &cu
))
17651 /* We don't use dwarf2_name here so that we can detect the absence
17652 of a name -> anonymous namespace. */
17653 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17659 /* Is it an anonymous namespace? */
17661 *is_anonymous
= (name
== NULL
);
17663 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17668 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17669 the user defined type vector. */
17671 static struct type
*
17672 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17674 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17675 struct comp_unit_head
*cu_header
= &cu
->header
;
17677 struct attribute
*attr_byte_size
;
17678 struct attribute
*attr_address_class
;
17679 int byte_size
, addr_class
;
17680 struct type
*target_type
;
17682 target_type
= die_type (die
, cu
);
17684 /* The die_type call above may have already set the type for this DIE. */
17685 type
= get_die_type (die
, cu
);
17689 type
= lookup_pointer_type (target_type
);
17691 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17692 if (attr_byte_size
)
17693 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17695 byte_size
= cu_header
->addr_size
;
17697 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17698 if (attr_address_class
)
17699 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17701 addr_class
= DW_ADDR_none
;
17703 ULONGEST alignment
= get_alignment (cu
, die
);
17705 /* If the pointer size, alignment, or address class is different
17706 than the default, create a type variant marked as such and set
17707 the length accordingly. */
17708 if (TYPE_LENGTH (type
) != byte_size
17709 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17710 && alignment
!= TYPE_RAW_ALIGN (type
))
17711 || addr_class
!= DW_ADDR_none
)
17713 if (gdbarch_address_class_type_flags_p (gdbarch
))
17715 type_instance_flags type_flags
17716 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17718 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17720 type
= make_type_with_address_space (type
, type_flags
);
17722 else if (TYPE_LENGTH (type
) != byte_size
)
17724 complaint (_("invalid pointer size %d"), byte_size
);
17726 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17728 complaint (_("Invalid DW_AT_alignment"
17729 " - DIE at %s [in module %s]"),
17730 sect_offset_str (die
->sect_off
),
17731 objfile_name (cu
->per_objfile
->objfile
));
17735 /* Should we also complain about unhandled address classes? */
17739 TYPE_LENGTH (type
) = byte_size
;
17740 set_type_align (type
, alignment
);
17741 return set_die_type (die
, type
, cu
);
17744 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17745 the user defined type vector. */
17747 static struct type
*
17748 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17751 struct type
*to_type
;
17752 struct type
*domain
;
17754 to_type
= die_type (die
, cu
);
17755 domain
= die_containing_type (die
, cu
);
17757 /* The calls above may have already set the type for this DIE. */
17758 type
= get_die_type (die
, cu
);
17762 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17763 type
= lookup_methodptr_type (to_type
);
17764 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17766 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17768 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17769 to_type
->fields (), to_type
->num_fields (),
17770 to_type
->has_varargs ());
17771 type
= lookup_methodptr_type (new_type
);
17774 type
= lookup_memberptr_type (to_type
, domain
);
17776 return set_die_type (die
, type
, cu
);
17779 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17780 the user defined type vector. */
17782 static struct type
*
17783 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17784 enum type_code refcode
)
17786 struct comp_unit_head
*cu_header
= &cu
->header
;
17787 struct type
*type
, *target_type
;
17788 struct attribute
*attr
;
17790 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17792 target_type
= die_type (die
, cu
);
17794 /* The die_type call above may have already set the type for this DIE. */
17795 type
= get_die_type (die
, cu
);
17799 type
= lookup_reference_type (target_type
, refcode
);
17800 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17801 if (attr
!= nullptr)
17803 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17807 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17809 maybe_set_alignment (cu
, die
, type
);
17810 return set_die_type (die
, type
, cu
);
17813 /* Add the given cv-qualifiers to the element type of the array. GCC
17814 outputs DWARF type qualifiers that apply to an array, not the
17815 element type. But GDB relies on the array element type to carry
17816 the cv-qualifiers. This mimics section 6.7.3 of the C99
17819 static struct type
*
17820 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17821 struct type
*base_type
, int cnst
, int voltl
)
17823 struct type
*el_type
, *inner_array
;
17825 base_type
= copy_type (base_type
);
17826 inner_array
= base_type
;
17828 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17830 TYPE_TARGET_TYPE (inner_array
) =
17831 copy_type (TYPE_TARGET_TYPE (inner_array
));
17832 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17835 el_type
= TYPE_TARGET_TYPE (inner_array
);
17836 cnst
|= TYPE_CONST (el_type
);
17837 voltl
|= TYPE_VOLATILE (el_type
);
17838 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17840 return set_die_type (die
, base_type
, cu
);
17843 static struct type
*
17844 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17846 struct type
*base_type
, *cv_type
;
17848 base_type
= die_type (die
, cu
);
17850 /* The die_type call above may have already set the type for this DIE. */
17851 cv_type
= get_die_type (die
, cu
);
17855 /* In case the const qualifier is applied to an array type, the element type
17856 is so qualified, not the array type (section 6.7.3 of C99). */
17857 if (base_type
->code () == TYPE_CODE_ARRAY
)
17858 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17860 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17861 return set_die_type (die
, cv_type
, cu
);
17864 static struct type
*
17865 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17867 struct type
*base_type
, *cv_type
;
17869 base_type
= die_type (die
, cu
);
17871 /* The die_type call above may have already set the type for this DIE. */
17872 cv_type
= get_die_type (die
, cu
);
17876 /* In case the volatile qualifier is applied to an array type, the
17877 element type is so qualified, not the array type (section 6.7.3
17879 if (base_type
->code () == TYPE_CODE_ARRAY
)
17880 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17882 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17883 return set_die_type (die
, cv_type
, cu
);
17886 /* Handle DW_TAG_restrict_type. */
17888 static struct type
*
17889 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17891 struct type
*base_type
, *cv_type
;
17893 base_type
= die_type (die
, cu
);
17895 /* The die_type call above may have already set the type for this DIE. */
17896 cv_type
= get_die_type (die
, cu
);
17900 cv_type
= make_restrict_type (base_type
);
17901 return set_die_type (die
, cv_type
, cu
);
17904 /* Handle DW_TAG_atomic_type. */
17906 static struct type
*
17907 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17909 struct type
*base_type
, *cv_type
;
17911 base_type
= die_type (die
, cu
);
17913 /* The die_type call above may have already set the type for this DIE. */
17914 cv_type
= get_die_type (die
, cu
);
17918 cv_type
= make_atomic_type (base_type
);
17919 return set_die_type (die
, cv_type
, cu
);
17922 /* Extract all information from a DW_TAG_string_type DIE and add to
17923 the user defined type vector. It isn't really a user defined type,
17924 but it behaves like one, with other DIE's using an AT_user_def_type
17925 attribute to reference it. */
17927 static struct type
*
17928 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17930 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17931 struct gdbarch
*gdbarch
= objfile
->arch ();
17932 struct type
*type
, *range_type
, *index_type
, *char_type
;
17933 struct attribute
*attr
;
17934 struct dynamic_prop prop
;
17935 bool length_is_constant
= true;
17938 /* There are a couple of places where bit sizes might be made use of
17939 when parsing a DW_TAG_string_type, however, no producer that we know
17940 of make use of these. Handling bit sizes that are a multiple of the
17941 byte size is easy enough, but what about other bit sizes? Lets deal
17942 with that problem when we have to. Warn about these attributes being
17943 unsupported, then parse the type and ignore them like we always
17945 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17946 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17948 static bool warning_printed
= false;
17949 if (!warning_printed
)
17951 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17952 "currently supported on DW_TAG_string_type."));
17953 warning_printed
= true;
17957 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17958 if (attr
!= nullptr && !attr
->form_is_constant ())
17960 /* The string length describes the location at which the length of
17961 the string can be found. The size of the length field can be
17962 specified with one of the attributes below. */
17963 struct type
*prop_type
;
17964 struct attribute
*len
17965 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17966 if (len
== nullptr)
17967 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17968 if (len
!= nullptr && len
->form_is_constant ())
17970 /* Pass 0 as the default as we know this attribute is constant
17971 and the default value will not be returned. */
17972 LONGEST sz
= len
->constant_value (0);
17973 prop_type
= objfile_int_type (objfile
, sz
, true);
17977 /* If the size is not specified then we assume it is the size of
17978 an address on this target. */
17979 prop_type
= cu
->addr_sized_int_type (true);
17982 /* Convert the attribute into a dynamic property. */
17983 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17986 length_is_constant
= false;
17988 else if (attr
!= nullptr)
17990 /* This DW_AT_string_length just contains the length with no
17991 indirection. There's no need to create a dynamic property in this
17992 case. Pass 0 for the default value as we know it will not be
17993 returned in this case. */
17994 length
= attr
->constant_value (0);
17996 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17998 /* We don't currently support non-constant byte sizes for strings. */
17999 length
= attr
->constant_value (1);
18003 /* Use 1 as a fallback length if we have nothing else. */
18007 index_type
= objfile_type (objfile
)->builtin_int
;
18008 if (length_is_constant
)
18009 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
18012 struct dynamic_prop low_bound
;
18014 low_bound
.set_const_val (1);
18015 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
18017 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
18018 type
= create_string_type (NULL
, char_type
, range_type
);
18020 return set_die_type (die
, type
, cu
);
18023 /* Assuming that DIE corresponds to a function, returns nonzero
18024 if the function is prototyped. */
18027 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
18029 struct attribute
*attr
;
18031 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
18032 if (attr
&& attr
->as_boolean ())
18035 /* The DWARF standard implies that the DW_AT_prototyped attribute
18036 is only meaningful for C, but the concept also extends to other
18037 languages that allow unprototyped functions (Eg: Objective C).
18038 For all other languages, assume that functions are always
18040 if (cu
->per_cu
->lang
!= language_c
18041 && cu
->per_cu
->lang
!= language_objc
18042 && cu
->per_cu
->lang
!= language_opencl
)
18045 /* RealView does not emit DW_AT_prototyped. We can not distinguish
18046 prototyped and unprototyped functions; default to prototyped,
18047 since that is more common in modern code (and RealView warns
18048 about unprototyped functions). */
18049 if (producer_is_realview (cu
->producer
))
18055 /* Handle DIES due to C code like:
18059 int (*funcp)(int a, long l);
18063 ('funcp' generates a DW_TAG_subroutine_type DIE). */
18065 static struct type
*
18066 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18068 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18069 struct type
*type
; /* Type that this function returns. */
18070 struct type
*ftype
; /* Function that returns above type. */
18071 struct attribute
*attr
;
18073 type
= die_type (die
, cu
);
18075 /* The die_type call above may have already set the type for this DIE. */
18076 ftype
= get_die_type (die
, cu
);
18080 ftype
= lookup_function_type (type
);
18082 if (prototyped_function_p (die
, cu
))
18083 ftype
->set_is_prototyped (true);
18085 /* Store the calling convention in the type if it's available in
18086 the subroutine die. Otherwise set the calling convention to
18087 the default value DW_CC_normal. */
18088 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
18089 if (attr
!= nullptr
18090 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
18091 TYPE_CALLING_CONVENTION (ftype
)
18092 = (enum dwarf_calling_convention
) attr
->constant_value (0);
18093 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
18094 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
18096 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
18098 /* Record whether the function returns normally to its caller or not
18099 if the DWARF producer set that information. */
18100 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
18101 if (attr
&& attr
->as_boolean ())
18102 TYPE_NO_RETURN (ftype
) = 1;
18104 /* We need to add the subroutine type to the die immediately so
18105 we don't infinitely recurse when dealing with parameters
18106 declared as the same subroutine type. */
18107 set_die_type (die
, ftype
, cu
);
18109 if (die
->child
!= NULL
)
18111 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
18112 struct die_info
*child_die
;
18113 int nparams
, iparams
;
18115 /* Count the number of parameters.
18116 FIXME: GDB currently ignores vararg functions, but knows about
18117 vararg member functions. */
18119 child_die
= die
->child
;
18120 while (child_die
&& child_die
->tag
)
18122 if (child_die
->tag
== DW_TAG_formal_parameter
)
18124 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
18125 ftype
->set_has_varargs (true);
18127 child_die
= child_die
->sibling
;
18130 /* Allocate storage for parameters and fill them in. */
18131 ftype
->set_num_fields (nparams
);
18133 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
18135 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
18136 even if we error out during the parameters reading below. */
18137 for (iparams
= 0; iparams
< nparams
; iparams
++)
18138 ftype
->field (iparams
).set_type (void_type
);
18141 child_die
= die
->child
;
18142 while (child_die
&& child_die
->tag
)
18144 if (child_die
->tag
== DW_TAG_formal_parameter
)
18146 struct type
*arg_type
;
18148 /* DWARF version 2 has no clean way to discern C++
18149 static and non-static member functions. G++ helps
18150 GDB by marking the first parameter for non-static
18151 member functions (which is the this pointer) as
18152 artificial. We pass this information to
18153 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
18155 DWARF version 3 added DW_AT_object_pointer, which GCC
18156 4.5 does not yet generate. */
18157 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
18158 if (attr
!= nullptr)
18159 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
18161 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
18162 arg_type
= die_type (child_die
, cu
);
18164 /* RealView does not mark THIS as const, which the testsuite
18165 expects. GCC marks THIS as const in method definitions,
18166 but not in the class specifications (GCC PR 43053). */
18167 if (cu
->per_cu
->lang
== language_cplus
18168 && !TYPE_CONST (arg_type
)
18169 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
18172 struct dwarf2_cu
*arg_cu
= cu
;
18173 const char *name
= dwarf2_name (child_die
, cu
);
18175 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
18176 if (attr
!= nullptr)
18178 /* If the compiler emits this, use it. */
18179 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
18182 else if (name
&& strcmp (name
, "this") == 0)
18183 /* Function definitions will have the argument names. */
18185 else if (name
== NULL
&& iparams
== 0)
18186 /* Declarations may not have the names, so like
18187 elsewhere in GDB, assume an artificial first
18188 argument is "this". */
18192 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
18196 ftype
->field (iparams
).set_type (arg_type
);
18199 child_die
= child_die
->sibling
;
18206 static struct type
*
18207 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
18209 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18210 const char *name
= NULL
;
18211 struct type
*this_type
, *target_type
;
18213 name
= dwarf2_full_name (NULL
, die
, cu
);
18214 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
18215 this_type
->set_target_is_stub (true);
18216 set_die_type (die
, this_type
, cu
);
18217 target_type
= die_type (die
, cu
);
18218 if (target_type
!= this_type
)
18219 TYPE_TARGET_TYPE (this_type
) = target_type
;
18222 /* Self-referential typedefs are, it seems, not allowed by the DWARF
18223 spec and cause infinite loops in GDB. */
18224 complaint (_("Self-referential DW_TAG_typedef "
18225 "- DIE at %s [in module %s]"),
18226 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
18227 TYPE_TARGET_TYPE (this_type
) = NULL
;
18231 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
18232 anonymous typedefs, which is, strictly speaking, invalid DWARF.
18233 Handle these by just returning the target type, rather than
18234 constructing an anonymous typedef type and trying to handle this
18236 set_die_type (die
, target_type
, cu
);
18237 return target_type
;
18242 /* Helper for get_dwarf2_rational_constant that computes the value of
18243 a given gmp_mpz given an attribute. */
18246 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
18248 /* GCC will sometimes emit a 16-byte constant value as a DWARF
18249 location expression that pushes an implicit value. */
18250 if (attr
->form
== DW_FORM_exprloc
)
18252 dwarf_block
*blk
= attr
->as_block ();
18253 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
18256 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
18257 blk
->data
+ blk
->size
,
18259 if (ptr
- blk
->data
+ len
<= blk
->size
)
18261 mpz_import (value
->val
, len
,
18262 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18268 /* On failure set it to 1. */
18269 *value
= gdb_mpz (1);
18271 else if (attr
->form_is_block ())
18273 dwarf_block
*blk
= attr
->as_block ();
18274 mpz_import (value
->val
, blk
->size
,
18275 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18276 1, 0, 0, blk
->data
);
18279 *value
= gdb_mpz (attr
->constant_value (1));
18282 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
18283 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
18285 If the numerator and/or numerator attribute is missing,
18286 a complaint is filed, and NUMERATOR and DENOMINATOR are left
18290 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
18291 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
18293 struct attribute
*num_attr
, *denom_attr
;
18295 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
18296 if (num_attr
== nullptr)
18297 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
18298 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18300 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
18301 if (denom_attr
== nullptr)
18302 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
18303 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18305 if (num_attr
== nullptr || denom_attr
== nullptr)
18308 get_mpz (cu
, numerator
, num_attr
);
18309 get_mpz (cu
, denominator
, denom_attr
);
18312 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
18313 rational constant, rather than a signed one.
18315 If the rational constant has a negative value, a complaint
18316 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
18319 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
18320 struct dwarf2_cu
*cu
,
18321 gdb_mpz
*numerator
,
18322 gdb_mpz
*denominator
)
18327 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
18328 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
18330 mpz_neg (num
.val
, num
.val
);
18331 mpz_neg (denom
.val
, denom
.val
);
18333 else if (mpz_sgn (num
.val
) == -1)
18335 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
18337 sect_offset_str (die
->sect_off
));
18340 else if (mpz_sgn (denom
.val
) == -1)
18342 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
18344 sect_offset_str (die
->sect_off
));
18348 *numerator
= std::move (num
);
18349 *denominator
= std::move (denom
);
18352 /* Assuming that ENCODING is a string whose contents starting at the
18353 K'th character is "_nn" where "nn" is a decimal number, scan that
18354 number and set RESULT to the value. K is updated to point to the
18355 character immediately following the number.
18357 If the string does not conform to the format described above, false
18358 is returned, and K may or may not be changed. */
18361 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
18363 /* The next character should be an underscore ('_') followed
18365 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
18368 /* Skip the underscore. */
18372 /* Determine the number of digits for our number. */
18373 while (isdigit (encoding
[k
]))
18378 std::string
copy (&encoding
[start
], k
- start
);
18379 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
18385 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
18386 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
18387 DENOM, update OFFSET, and return true on success. Return false on
18391 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
18392 gdb_mpz
*num
, gdb_mpz
*denom
)
18394 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
18396 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
18399 /* Assuming DIE corresponds to a fixed point type, finish the creation
18400 of the corresponding TYPE by setting its type-specific data. CU is
18401 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
18402 encodings. It is nullptr if the GNAT encoding should be
18406 finish_fixed_point_type (struct type
*type
, const char *suffix
,
18407 struct die_info
*die
, struct dwarf2_cu
*cu
)
18409 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
18410 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
18412 /* If GNAT encodings are preferred, don't examine the
18414 struct attribute
*attr
= nullptr;
18415 if (suffix
== nullptr)
18417 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
18418 if (attr
== nullptr)
18419 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
18420 if (attr
== nullptr)
18421 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18424 /* Numerator and denominator of our fixed-point type's scaling factor.
18425 The default is a scaling factor of 1, which we use as a fallback
18426 when we are not able to decode it (problem with the debugging info,
18427 unsupported forms, bug in GDB, etc...). Using that as the default
18428 allows us to at least print the unscaled value, which might still
18429 be useful to a user. */
18430 gdb_mpz
scale_num (1);
18431 gdb_mpz
scale_denom (1);
18433 if (attr
== nullptr)
18436 if (suffix
!= nullptr
18437 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18439 /* The number might be encoded as _nn_dd_nn_dd, where the
18440 second ratio is the 'small value. In this situation, we
18441 want the second value. */
18442 && (suffix
[offset
] != '_'
18443 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18450 /* Scaling factor not found. Assume a scaling factor of 1,
18451 and hope for the best. At least the user will be able to
18452 see the encoded value. */
18455 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18456 sect_offset_str (die
->sect_off
));
18459 else if (attr
->name
== DW_AT_binary_scale
)
18461 LONGEST scale_exp
= attr
->constant_value (0);
18462 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18464 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18466 else if (attr
->name
== DW_AT_decimal_scale
)
18468 LONGEST scale_exp
= attr
->constant_value (0);
18469 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18471 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18473 else if (attr
->name
== DW_AT_small
)
18475 struct die_info
*scale_die
;
18476 struct dwarf2_cu
*scale_cu
= cu
;
18478 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18479 if (scale_die
->tag
== DW_TAG_constant
)
18480 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18481 &scale_num
, &scale_denom
);
18483 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18485 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18489 complaint (_("unsupported scale attribute %s for fixed-point type"
18491 dwarf_attr_name (attr
->name
),
18492 sect_offset_str (die
->sect_off
));
18495 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18496 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18497 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18498 mpq_canonicalize (scaling_factor
.val
);
18501 /* The gnat-encoding suffix for fixed point. */
18503 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18505 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18506 "XF" suffix of the name. The text after this is what encodes the
18507 'small and 'delta information. Otherwise, return nullptr. */
18509 static const char *
18510 gnat_encoded_fixed_point_type_info (const char *name
)
18512 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18515 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18516 (which may be different from NAME) to the architecture back-end to allow
18517 it to guess the correct format if necessary. */
18519 static struct type
*
18520 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18521 const char *name_hint
, enum bfd_endian byte_order
)
18523 struct gdbarch
*gdbarch
= objfile
->arch ();
18524 const struct floatformat
**format
;
18527 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18529 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18531 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18536 /* Allocate an integer type of size BITS and name NAME. */
18538 static struct type
*
18539 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18540 int bits
, int unsigned_p
, const char *name
)
18544 /* Versions of Intel's C Compiler generate an integer type called "void"
18545 instead of using DW_TAG_unspecified_type. This has been seen on
18546 at least versions 14, 17, and 18. */
18547 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18548 && strcmp (name
, "void") == 0)
18549 type
= objfile_type (objfile
)->builtin_void
;
18551 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18556 /* Return true if DIE has a DW_AT_small attribute whose value is
18557 a constant rational, where both the numerator and denominator
18560 CU is the DIE's Compilation Unit. */
18563 has_zero_over_zero_small_attribute (struct die_info
*die
,
18564 struct dwarf2_cu
*cu
)
18566 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18567 if (attr
== nullptr)
18570 struct dwarf2_cu
*scale_cu
= cu
;
18571 struct die_info
*scale_die
18572 = follow_die_ref (die
, attr
, &scale_cu
);
18574 if (scale_die
->tag
!= DW_TAG_constant
)
18577 gdb_mpz
num (1), denom (1);
18578 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18579 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18582 /* Initialise and return a floating point type of size BITS suitable for
18583 use as a component of a complex number. The NAME_HINT is passed through
18584 when initialising the floating point type and is the name of the complex
18587 As DWARF doesn't currently provide an explicit name for the components
18588 of a complex number, but it can be helpful to have these components
18589 named, we try to select a suitable name based on the size of the
18591 static struct type
*
18592 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18593 struct objfile
*objfile
,
18594 int bits
, const char *name_hint
,
18595 enum bfd_endian byte_order
)
18597 gdbarch
*gdbarch
= objfile
->arch ();
18598 struct type
*tt
= nullptr;
18600 /* Try to find a suitable floating point builtin type of size BITS.
18601 We're going to use the name of this type as the name for the complex
18602 target type that we are about to create. */
18603 switch (cu
->per_cu
->lang
)
18605 case language_fortran
:
18609 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18612 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18614 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18616 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18624 tt
= builtin_type (gdbarch
)->builtin_float
;
18627 tt
= builtin_type (gdbarch
)->builtin_double
;
18629 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18631 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18637 /* If the type we found doesn't match the size we were looking for, then
18638 pretend we didn't find a type at all, the complex target type we
18639 create will then be nameless. */
18640 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18643 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18644 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18647 /* Find a representation of a given base type and install
18648 it in the TYPE field of the die. */
18650 static struct type
*
18651 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18653 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18655 struct attribute
*attr
;
18656 int encoding
= 0, bits
= 0;
18660 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18661 if (attr
!= nullptr && attr
->form_is_constant ())
18662 encoding
= attr
->constant_value (0);
18663 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18664 if (attr
!= nullptr)
18665 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18666 name
= dwarf2_name (die
, cu
);
18668 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18670 arch
= objfile
->arch ();
18671 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18673 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18674 if (attr
!= nullptr && attr
->form_is_constant ())
18676 int endianity
= attr
->constant_value (0);
18681 byte_order
= BFD_ENDIAN_BIG
;
18683 case DW_END_little
:
18684 byte_order
= BFD_ENDIAN_LITTLE
;
18687 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18692 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18693 && cu
->per_cu
->lang
== language_ada
18694 && has_zero_over_zero_small_attribute (die
, cu
))
18696 /* brobecker/2018-02-24: This is a fixed point type for which
18697 the scaling factor is represented as fraction whose value
18698 does not make sense (zero divided by zero), so we should
18699 normally never see these. However, there is a small category
18700 of fixed point types for which GNAT is unable to provide
18701 the scaling factor via the standard DWARF mechanisms, and
18702 for which the info is provided via the GNAT encodings instead.
18703 This is likely what this DIE is about. */
18704 encoding
= (encoding
== DW_ATE_signed_fixed
18706 : DW_ATE_unsigned
);
18709 /* With GNAT encodings, fixed-point information will be encoded in
18710 the type name. Note that this can also occur with the above
18711 zero-over-zero case, which is why this is a separate "if" rather
18712 than an "else if". */
18713 const char *gnat_encoding_suffix
= nullptr;
18714 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18715 && cu
->per_cu
->lang
== language_ada
18716 && name
!= nullptr)
18718 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18719 if (gnat_encoding_suffix
!= nullptr)
18721 gdb_assert (startswith (gnat_encoding_suffix
,
18722 GNAT_FIXED_POINT_SUFFIX
));
18723 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18724 name
, gnat_encoding_suffix
- name
);
18725 /* Use -1 here so that SUFFIX points at the "_" after the
18727 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18729 encoding
= (encoding
== DW_ATE_signed
18730 ? DW_ATE_signed_fixed
18731 : DW_ATE_unsigned_fixed
);
18737 case DW_ATE_address
:
18738 /* Turn DW_ATE_address into a void * pointer. */
18739 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18740 type
= init_pointer_type (objfile
, bits
, name
, type
);
18742 case DW_ATE_boolean
:
18743 type
= init_boolean_type (objfile
, bits
, 1, name
);
18745 case DW_ATE_complex_float
:
18746 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18748 if (type
->code () == TYPE_CODE_ERROR
)
18750 if (name
== nullptr)
18752 struct obstack
*obstack
18753 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18754 name
= obconcat (obstack
, "_Complex ", type
->name (),
18757 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18760 type
= init_complex_type (name
, type
);
18762 case DW_ATE_decimal_float
:
18763 type
= init_decfloat_type (objfile
, bits
, name
);
18766 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18768 case DW_ATE_signed
:
18769 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18771 case DW_ATE_unsigned
:
18772 if (cu
->per_cu
->lang
== language_fortran
18774 && startswith (name
, "character("))
18775 type
= init_character_type (objfile
, bits
, 1, name
);
18777 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18779 case DW_ATE_signed_char
:
18780 if (cu
->per_cu
->lang
== language_ada
18781 || cu
->per_cu
->lang
== language_m2
18782 || cu
->per_cu
->lang
== language_pascal
18783 || cu
->per_cu
->lang
== language_fortran
)
18784 type
= init_character_type (objfile
, bits
, 0, name
);
18786 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18788 case DW_ATE_unsigned_char
:
18789 if (cu
->per_cu
->lang
== language_ada
18790 || cu
->per_cu
->lang
== language_m2
18791 || cu
->per_cu
->lang
== language_pascal
18792 || cu
->per_cu
->lang
== language_fortran
18793 || cu
->per_cu
->lang
== language_rust
)
18794 type
= init_character_type (objfile
, bits
, 1, name
);
18796 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18800 type
= init_character_type (objfile
, bits
, 1, name
);
18801 return set_die_type (die
, type
, cu
);
18804 case DW_ATE_signed_fixed
:
18805 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18806 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18808 case DW_ATE_unsigned_fixed
:
18809 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18810 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18814 complaint (_("unsupported DW_AT_encoding: '%s'"),
18815 dwarf_type_encoding_name (encoding
));
18816 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18820 if (type
->code () == TYPE_CODE_INT
18822 && strcmp (name
, "char") == 0)
18823 type
->set_has_no_signedness (true);
18825 maybe_set_alignment (cu
, die
, type
);
18827 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18829 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18831 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18832 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18834 unsigned real_bit_size
= attr
->as_unsigned ();
18835 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18836 /* Only use the attributes if they make sense together. */
18837 if (attr
== nullptr
18838 || (attr
->as_unsigned () + real_bit_size
18839 <= 8 * TYPE_LENGTH (type
)))
18841 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18843 if (attr
!= nullptr)
18844 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18845 = attr
->as_unsigned ();
18850 return set_die_type (die
, type
, cu
);
18853 /* A helper function that returns the name of DIE, if it refers to a
18854 variable declaration. */
18856 static const char *
18857 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18859 if (die
->tag
!= DW_TAG_variable
)
18862 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18863 if (attr
== nullptr || !attr
->as_boolean ())
18866 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18867 if (attr
== nullptr)
18869 return attr
->as_string ();
18872 /* Parse dwarf attribute if it's a block, reference or constant and put the
18873 resulting value of the attribute into struct bound_prop.
18874 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18877 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18878 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18879 struct type
*default_type
)
18881 struct dwarf2_property_baton
*baton
;
18882 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18883 struct objfile
*objfile
= per_objfile
->objfile
;
18884 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18886 gdb_assert (default_type
!= NULL
);
18888 if (attr
== NULL
|| prop
== NULL
)
18891 if (attr
->form_is_block ())
18893 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18894 baton
->property_type
= default_type
;
18895 baton
->locexpr
.per_cu
= cu
->per_cu
;
18896 baton
->locexpr
.per_objfile
= per_objfile
;
18898 struct dwarf_block
*block
;
18899 if (attr
->form
== DW_FORM_data16
)
18901 size_t data_size
= 16;
18902 block
= XOBNEW (obstack
, struct dwarf_block
);
18903 block
->size
= (data_size
18904 + 2 /* Extra bytes for DW_OP and arg. */);
18905 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
18906 data
[0] = DW_OP_implicit_value
;
18907 data
[1] = data_size
;
18908 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
18909 block
->data
= data
;
18912 block
= attr
->as_block ();
18914 baton
->locexpr
.size
= block
->size
;
18915 baton
->locexpr
.data
= block
->data
;
18916 switch (attr
->name
)
18918 case DW_AT_string_length
:
18919 baton
->locexpr
.is_reference
= true;
18922 baton
->locexpr
.is_reference
= false;
18926 prop
->set_locexpr (baton
);
18927 gdb_assert (prop
->baton () != NULL
);
18929 else if (attr
->form_is_ref ())
18931 struct dwarf2_cu
*target_cu
= cu
;
18932 struct die_info
*target_die
;
18933 struct attribute
*target_attr
;
18935 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18936 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18937 if (target_attr
== NULL
)
18938 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18940 if (target_attr
== nullptr)
18941 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
18943 if (target_attr
== NULL
)
18945 const char *name
= var_decl_name (target_die
, target_cu
);
18946 if (name
!= nullptr)
18948 prop
->set_variable_name (name
);
18954 switch (target_attr
->name
)
18956 case DW_AT_location
:
18957 if (target_attr
->form_is_section_offset ())
18959 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18960 baton
->property_type
= die_type (target_die
, target_cu
);
18961 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18962 prop
->set_loclist (baton
);
18963 gdb_assert (prop
->baton () != NULL
);
18965 else if (target_attr
->form_is_block ())
18967 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18968 baton
->property_type
= die_type (target_die
, target_cu
);
18969 baton
->locexpr
.per_cu
= cu
->per_cu
;
18970 baton
->locexpr
.per_objfile
= per_objfile
;
18971 struct dwarf_block
*block
= target_attr
->as_block ();
18972 baton
->locexpr
.size
= block
->size
;
18973 baton
->locexpr
.data
= block
->data
;
18974 baton
->locexpr
.is_reference
= true;
18975 prop
->set_locexpr (baton
);
18976 gdb_assert (prop
->baton () != NULL
);
18980 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18981 "dynamic property");
18985 case DW_AT_data_member_location
:
18986 case DW_AT_data_bit_offset
:
18990 if (!handle_member_location (target_die
, target_cu
, &offset
))
18993 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18994 baton
->property_type
= read_type_die (target_die
->parent
,
18996 baton
->offset_info
.offset
= offset
;
18997 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18998 prop
->set_addr_offset (baton
);
19003 else if (attr
->form_is_constant ())
19004 prop
->set_const_val (attr
->constant_value (0));
19005 else if (attr
->form_is_section_offset ())
19007 switch (attr
->name
)
19009 case DW_AT_string_length
:
19010 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
19011 baton
->property_type
= default_type
;
19012 fill_in_loclist_baton (cu
, &baton
->loclist
, attr
);
19013 prop
->set_loclist (baton
);
19014 gdb_assert (prop
->baton () != NULL
);
19026 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
19027 dwarf2_name (die
, cu
));
19033 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
19034 present (which is valid) then compute the default type based on the
19035 compilation units address size. */
19037 static struct type
*
19038 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19040 struct type
*index_type
= die_type (die
, cu
);
19042 /* Dwarf-2 specifications explicitly allows to create subrange types
19043 without specifying a base type.
19044 In that case, the base type must be set to the type of
19045 the lower bound, upper bound or count, in that order, if any of these
19046 three attributes references an object that has a type.
19047 If no base type is found, the Dwarf-2 specifications say that
19048 a signed integer type of size equal to the size of an address should
19050 For the following C code: `extern char gdb_int [];'
19051 GCC produces an empty range DIE.
19052 FIXME: muller/2010-05-28: Possible references to object for low bound,
19053 high bound or count are not yet handled by this code. */
19054 if (index_type
->code () == TYPE_CODE_VOID
)
19055 index_type
= cu
->addr_sized_int_type (false);
19060 /* Read the given DW_AT_subrange DIE. */
19062 static struct type
*
19063 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19065 struct type
*base_type
, *orig_base_type
;
19066 struct type
*range_type
;
19067 struct attribute
*attr
;
19068 struct dynamic_prop low
, high
;
19069 int low_default_is_valid
;
19070 int high_bound_is_count
= 0;
19072 ULONGEST negative_mask
;
19074 orig_base_type
= read_subrange_index_type (die
, cu
);
19076 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
19077 whereas the real type might be. So, we use ORIG_BASE_TYPE when
19078 creating the range type, but we use the result of check_typedef
19079 when examining properties of the type. */
19080 base_type
= check_typedef (orig_base_type
);
19082 /* The die_type call above may have already set the type for this DIE. */
19083 range_type
= get_die_type (die
, cu
);
19087 high
.set_const_val (0);
19089 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
19090 omitting DW_AT_lower_bound. */
19091 switch (cu
->per_cu
->lang
)
19094 case language_cplus
:
19095 low
.set_const_val (0);
19096 low_default_is_valid
= 1;
19098 case language_fortran
:
19099 low
.set_const_val (1);
19100 low_default_is_valid
= 1;
19103 case language_objc
:
19104 case language_rust
:
19105 low
.set_const_val (0);
19106 low_default_is_valid
= (cu
->header
.version
>= 4);
19110 case language_pascal
:
19111 low
.set_const_val (1);
19112 low_default_is_valid
= (cu
->header
.version
>= 4);
19115 low
.set_const_val (0);
19116 low_default_is_valid
= 0;
19120 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
19121 if (attr
!= nullptr)
19122 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
19123 else if (!low_default_is_valid
)
19124 complaint (_("Missing DW_AT_lower_bound "
19125 "- DIE at %s [in module %s]"),
19126 sect_offset_str (die
->sect_off
),
19127 objfile_name (cu
->per_objfile
->objfile
));
19129 struct attribute
*attr_ub
, *attr_count
;
19130 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
19131 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19133 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
19134 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19136 /* If bounds are constant do the final calculation here. */
19137 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
19138 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
19140 high_bound_is_count
= 1;
19144 if (attr_ub
!= NULL
)
19145 complaint (_("Unresolved DW_AT_upper_bound "
19146 "- DIE at %s [in module %s]"),
19147 sect_offset_str (die
->sect_off
),
19148 objfile_name (cu
->per_objfile
->objfile
));
19149 if (attr_count
!= NULL
)
19150 complaint (_("Unresolved DW_AT_count "
19151 "- DIE at %s [in module %s]"),
19152 sect_offset_str (die
->sect_off
),
19153 objfile_name (cu
->per_objfile
->objfile
));
19158 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
19159 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
19160 bias
= bias_attr
->constant_value (0);
19162 /* Normally, the DWARF producers are expected to use a signed
19163 constant form (Eg. DW_FORM_sdata) to express negative bounds.
19164 But this is unfortunately not always the case, as witnessed
19165 with GCC, for instance, where the ambiguous DW_FORM_dataN form
19166 is used instead. To work around that ambiguity, we treat
19167 the bounds as signed, and thus sign-extend their values, when
19168 the base type is signed. */
19170 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
19171 if (low
.kind () == PROP_CONST
19172 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
19173 low
.set_const_val (low
.const_val () | negative_mask
);
19174 if (high
.kind () == PROP_CONST
19175 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
19176 high
.set_const_val (high
.const_val () | negative_mask
);
19178 /* Check for bit and byte strides. */
19179 struct dynamic_prop byte_stride_prop
;
19180 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
19181 if (attr_byte_stride
!= nullptr)
19183 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19184 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
19188 struct dynamic_prop bit_stride_prop
;
19189 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
19190 if (attr_bit_stride
!= nullptr)
19192 /* It only makes sense to have either a bit or byte stride. */
19193 if (attr_byte_stride
!= nullptr)
19195 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
19196 "- DIE at %s [in module %s]"),
19197 sect_offset_str (die
->sect_off
),
19198 objfile_name (cu
->per_objfile
->objfile
));
19199 attr_bit_stride
= nullptr;
19203 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19204 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
19209 if (attr_byte_stride
!= nullptr
19210 || attr_bit_stride
!= nullptr)
19212 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
19213 struct dynamic_prop
*stride
19214 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
19217 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
19218 &high
, bias
, stride
, byte_stride_p
);
19221 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
19223 if (high_bound_is_count
)
19224 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
19226 /* Ada expects an empty array on no boundary attributes. */
19227 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
19228 range_type
->bounds ()->high
.set_undefined ();
19230 name
= dwarf2_name (die
, cu
);
19232 range_type
->set_name (name
);
19234 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
19235 if (attr
!= nullptr)
19236 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
19238 maybe_set_alignment (cu
, die
, range_type
);
19240 set_die_type (die
, range_type
, cu
);
19242 /* set_die_type should be already done. */
19243 set_descriptive_type (range_type
, die
, cu
);
19248 static struct type
*
19249 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19253 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
19254 type
->set_name (dwarf2_name (die
, cu
));
19256 /* In Ada, an unspecified type is typically used when the description
19257 of the type is deferred to a different unit. When encountering
19258 such a type, we treat it as a stub, and try to resolve it later on,
19260 if (cu
->per_cu
->lang
== language_ada
)
19261 type
->set_is_stub (true);
19263 return set_die_type (die
, type
, cu
);
19266 /* Read a single die and all its descendents. Set the die's sibling
19267 field to NULL; set other fields in the die correctly, and set all
19268 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
19269 location of the info_ptr after reading all of those dies. PARENT
19270 is the parent of the die in question. */
19272 static struct die_info
*
19273 read_die_and_children (const struct die_reader_specs
*reader
,
19274 const gdb_byte
*info_ptr
,
19275 const gdb_byte
**new_info_ptr
,
19276 struct die_info
*parent
)
19278 struct die_info
*die
;
19279 const gdb_byte
*cur_ptr
;
19281 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
19284 *new_info_ptr
= cur_ptr
;
19287 store_in_ref_table (die
, reader
->cu
);
19289 if (die
->has_children
)
19290 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
19294 *new_info_ptr
= cur_ptr
;
19297 die
->sibling
= NULL
;
19298 die
->parent
= parent
;
19302 /* Read a die, all of its descendents, and all of its siblings; set
19303 all of the fields of all of the dies correctly. Arguments are as
19304 in read_die_and_children. */
19306 static struct die_info
*
19307 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
19308 const gdb_byte
*info_ptr
,
19309 const gdb_byte
**new_info_ptr
,
19310 struct die_info
*parent
)
19312 struct die_info
*first_die
, *last_sibling
;
19313 const gdb_byte
*cur_ptr
;
19315 cur_ptr
= info_ptr
;
19316 first_die
= last_sibling
= NULL
;
19320 struct die_info
*die
19321 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
19325 *new_info_ptr
= cur_ptr
;
19332 last_sibling
->sibling
= die
;
19334 last_sibling
= die
;
19338 /* Read a die, all of its descendents, and all of its siblings; set
19339 all of the fields of all of the dies correctly. Arguments are as
19340 in read_die_and_children.
19341 This the main entry point for reading a DIE and all its children. */
19343 static struct die_info
*
19344 read_die_and_siblings (const struct die_reader_specs
*reader
,
19345 const gdb_byte
*info_ptr
,
19346 const gdb_byte
**new_info_ptr
,
19347 struct die_info
*parent
)
19349 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
19350 new_info_ptr
, parent
);
19352 if (dwarf_die_debug
)
19354 gdb_printf (gdb_stdlog
,
19355 "Read die from %s@0x%x of %s:\n",
19356 reader
->die_section
->get_name (),
19357 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19358 bfd_get_filename (reader
->abfd
));
19359 dump_die (die
, dwarf_die_debug
);
19365 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
19367 The caller is responsible for filling in the extra attributes
19368 and updating (*DIEP)->num_attrs.
19369 Set DIEP to point to a newly allocated die with its information,
19370 except for its child, sibling, and parent fields. */
19372 static const gdb_byte
*
19373 read_full_die_1 (const struct die_reader_specs
*reader
,
19374 struct die_info
**diep
, const gdb_byte
*info_ptr
,
19375 int num_extra_attrs
)
19377 unsigned int abbrev_number
, bytes_read
, i
;
19378 const struct abbrev_info
*abbrev
;
19379 struct die_info
*die
;
19380 struct dwarf2_cu
*cu
= reader
->cu
;
19381 bfd
*abfd
= reader
->abfd
;
19383 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
19384 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19385 info_ptr
+= bytes_read
;
19386 if (!abbrev_number
)
19392 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
19394 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
19396 bfd_get_filename (abfd
));
19398 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
19399 die
->sect_off
= sect_off
;
19400 die
->tag
= abbrev
->tag
;
19401 die
->abbrev
= abbrev_number
;
19402 die
->has_children
= abbrev
->has_children
;
19404 /* Make the result usable.
19405 The caller needs to update num_attrs after adding the extra
19407 die
->num_attrs
= abbrev
->num_attrs
;
19409 bool any_need_reprocess
= false;
19410 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19412 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
19414 if (die
->attrs
[i
].requires_reprocessing_p ())
19415 any_need_reprocess
= true;
19418 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
19419 if (attr
!= nullptr && attr
->form_is_unsigned ())
19420 cu
->str_offsets_base
= attr
->as_unsigned ();
19422 attr
= die
->attr (DW_AT_loclists_base
);
19423 if (attr
!= nullptr)
19424 cu
->loclist_base
= attr
->as_unsigned ();
19426 auto maybe_addr_base
= die
->addr_base ();
19427 if (maybe_addr_base
.has_value ())
19428 cu
->addr_base
= *maybe_addr_base
;
19430 attr
= die
->attr (DW_AT_rnglists_base
);
19431 if (attr
!= nullptr)
19432 cu
->rnglists_base
= attr
->as_unsigned ();
19434 if (any_need_reprocess
)
19436 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19438 if (die
->attrs
[i
].requires_reprocessing_p ())
19439 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19446 /* Read a die and all its attributes.
19447 Set DIEP to point to a newly allocated die with its information,
19448 except for its child, sibling, and parent fields. */
19450 static const gdb_byte
*
19451 read_full_die (const struct die_reader_specs
*reader
,
19452 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19454 const gdb_byte
*result
;
19456 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19458 if (dwarf_die_debug
)
19460 gdb_printf (gdb_stdlog
,
19461 "Read die from %s@0x%x of %s:\n",
19462 reader
->die_section
->get_name (),
19463 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19464 bfd_get_filename (reader
->abfd
));
19465 dump_die (*diep
, dwarf_die_debug
);
19473 cooked_indexer::check_bounds (cutu_reader
*reader
)
19475 if (reader
->cu
->per_cu
->addresses_seen
)
19478 dwarf2_cu
*cu
= reader
->cu
;
19480 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
19481 /* Possibly set the default values of LOWPC and HIGHPC from
19483 dwarf2_find_base_address (reader
->comp_unit_die
, cu
);
19484 enum pc_bounds_kind cu_bounds_kind
19485 = dwarf2_get_pc_bounds (reader
->comp_unit_die
, &best_lowpc
, &best_highpc
,
19486 cu
, m_index_storage
->get_addrmap (), cu
->per_cu
);
19487 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
19489 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19490 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
19491 struct gdbarch
*gdbarch
= objfile
->arch ();
19493 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
19496 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
19498 /* Store the contiguous range if it is not empty; it can be
19499 empty for CUs with no code. */
19500 addrmap_set_empty (m_index_storage
->get_addrmap (), low
, high
,
19503 cu
->per_cu
->addresses_seen
= true;
19507 /* Helper function that returns true if TAG can have a linkage
19511 tag_can_have_linkage_name (enum dwarf_tag tag
)
19515 /* We include types here because an anonymous C++ type might
19516 have a name for linkage purposes. */
19517 case DW_TAG_class_type
:
19518 case DW_TAG_structure_type
:
19519 case DW_TAG_union_type
:
19520 case DW_TAG_variable
:
19521 case DW_TAG_subprogram
:
19530 cooked_indexer::ensure_cu_exists (cutu_reader
*reader
,
19531 dwarf2_per_objfile
*per_objfile
,
19532 sect_offset sect_off
, bool is_dwz
,
19535 /* Lookups for type unit references are always in the CU, and
19536 cross-CU references will crash. */
19537 if (reader
->cu
->per_cu
->is_dwz
== is_dwz
19538 && reader
->cu
->header
.offset_in_cu_p (sect_off
))
19541 dwarf2_per_cu_data
*per_cu
19542 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
19543 per_objfile
->per_bfd
);
19545 /* When scanning, we only want to visit a given CU a single time.
19546 Doing this check here avoids self-imports as well. */
19550 if (!per_cu
->scanned
.compare_exchange_strong (nope
, true))
19553 if (per_cu
== m_per_cu
)
19556 cutu_reader
*result
= m_index_storage
->get_reader (per_cu
);
19557 if (result
== nullptr)
19559 cutu_reader
new_reader (per_cu
, per_objfile
, nullptr, nullptr, false,
19560 m_index_storage
->get_abbrev_cache ());
19562 prepare_one_comp_unit (new_reader
.cu
, new_reader
.comp_unit_die
,
19564 std::unique_ptr
<cutu_reader
> copy
19565 (new cutu_reader (std::move (new_reader
)));
19566 result
= m_index_storage
->preserve (std::move (copy
));
19569 if (result
->dummy_p
|| !result
->comp_unit_die
->has_children
)
19573 check_bounds (result
);
19579 cooked_indexer::scan_attributes (dwarf2_per_cu_data
*scanning_per_cu
,
19580 cutu_reader
*reader
,
19581 const gdb_byte
*watermark_ptr
,
19582 const gdb_byte
*info_ptr
,
19583 const abbrev_info
*abbrev
,
19585 const char **linkage_name
,
19586 cooked_index_flag
*flags
,
19587 sect_offset
*sibling_offset
,
19588 const cooked_index_entry
**parent_entry
,
19589 CORE_ADDR
*maybe_defer
,
19590 bool for_specification
)
19592 bool origin_is_dwz
= false;
19593 bool is_declaration
= false;
19594 sect_offset origin_offset
{};
19596 gdb::optional
<CORE_ADDR
> low_pc
;
19597 gdb::optional
<CORE_ADDR
> high_pc
;
19598 bool high_pc_relative
= false;
19600 for (int i
= 0; i
< abbrev
->num_attrs
; ++i
)
19603 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
19604 if (attr
.requires_reprocessing_p ())
19605 read_attribute_reprocess (reader
, &attr
, abbrev
->tag
);
19607 /* Store the data if it is of an attribute we want to keep in a
19608 partial symbol table. */
19612 switch (abbrev
->tag
)
19614 case DW_TAG_compile_unit
:
19615 case DW_TAG_partial_unit
:
19616 case DW_TAG_type_unit
:
19617 /* Compilation units have a DW_AT_name that is a filename, not
19618 a source language identifier. */
19622 if (*name
== nullptr)
19623 *name
= attr
.as_string ();
19628 case DW_AT_linkage_name
:
19629 case DW_AT_MIPS_linkage_name
:
19630 /* Note that both forms of linkage name might appear. We
19631 assume they will be the same, and we only store the last
19633 if (*linkage_name
== nullptr)
19634 *linkage_name
= attr
.as_string ();
19637 case DW_AT_main_subprogram
:
19638 if (attr
.as_boolean ())
19642 case DW_AT_declaration
:
19643 is_declaration
= attr
.as_boolean ();
19646 case DW_AT_sibling
:
19647 if (sibling_offset
!= nullptr)
19648 *sibling_offset
= attr
.get_ref_die_offset ();
19651 case DW_AT_specification
:
19652 case DW_AT_abstract_origin
:
19653 case DW_AT_extension
:
19654 origin_offset
= attr
.get_ref_die_offset ();
19655 origin_is_dwz
= attr
.form
== DW_FORM_GNU_ref_alt
;
19658 case DW_AT_external
:
19659 if (attr
.as_boolean ())
19660 *flags
&= ~IS_STATIC
;
19663 case DW_AT_enum_class
:
19664 if (attr
.as_boolean ())
19665 *flags
|= IS_ENUM_CLASS
;
19669 low_pc
= attr
.as_address ();
19672 case DW_AT_high_pc
:
19673 high_pc
= attr
.as_address ();
19674 if (reader
->cu
->header
.version
>= 4 && attr
.form_is_constant ())
19675 high_pc_relative
= true;
19678 case DW_AT_location
:
19679 if (!scanning_per_cu
->addresses_seen
&& attr
.form_is_block ())
19681 struct dwarf_block
*locdesc
= attr
.as_block ();
19682 CORE_ADDR addr
= decode_locdesc (locdesc
, reader
->cu
);
19684 || reader
->cu
->per_objfile
->per_bfd
->has_section_at_zero
)
19687 /* For variables, we don't want to try decoding the
19688 type just to find the size -- for gdb's purposes
19689 we only need the address of a variable. */
19690 high_pc
= addr
+ 1;
19691 high_pc_relative
= false;
19697 if (!scanning_per_cu
->addresses_seen
)
19699 /* Offset in the .debug_ranges or .debug_rnglist section
19700 (depending on DWARF version). */
19701 ULONGEST ranges_offset
= attr
.as_unsigned ();
19703 /* See dwarf2_cu::gnu_ranges_base's doc for why we might
19704 want to add this value. */
19705 ranges_offset
+= reader
->cu
->gnu_ranges_base
;
19707 CORE_ADDR lowpc
, highpc
;
19708 dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, reader
->cu
,
19709 m_index_storage
->get_addrmap (),
19710 scanning_per_cu
, abbrev
->tag
);
19716 /* We don't want to examine declarations, but if we found a
19717 declaration when handling DW_AT_specification or the like, then
19718 that is ok. Similarly, we allow an external variable without a
19719 location; those are resolved via minimal symbols. */
19720 if (is_declaration
&& !for_specification
19721 && (abbrev
->tag
!= DW_TAG_variable
19722 || (*flags
& IS_STATIC
) != 0))
19724 *linkage_name
= nullptr;
19727 else if ((*name
== nullptr
19728 || (*linkage_name
== nullptr
19729 && tag_can_have_linkage_name (abbrev
->tag
))
19730 || (*parent_entry
== nullptr && m_language
!= language_c
))
19731 && origin_offset
!= sect_offset (0))
19733 cutu_reader
*new_reader
19734 = ensure_cu_exists (reader
, reader
->cu
->per_objfile
, origin_offset
,
19735 origin_is_dwz
, false);
19736 if (new_reader
!= nullptr)
19738 const gdb_byte
*new_info_ptr
= (new_reader
->buffer
19739 + to_underlying (origin_offset
));
19741 if (new_reader
->cu
== reader
->cu
19742 && new_info_ptr
> watermark_ptr
19743 && maybe_defer
!= nullptr
19744 && *parent_entry
== nullptr)
19745 *maybe_defer
= form_addr (origin_offset
, origin_is_dwz
);
19746 else if (*parent_entry
== nullptr)
19748 CORE_ADDR lookup
= form_addr (origin_offset
, origin_is_dwz
);
19750 = (cooked_index_entry
*) addrmap_find (m_die_range_map
,
19754 unsigned int bytes_read
;
19755 const abbrev_info
*new_abbrev
= peek_die_abbrev (*new_reader
,
19758 new_info_ptr
+= bytes_read
;
19759 scan_attributes (scanning_per_cu
, new_reader
, new_info_ptr
, new_info_ptr
,
19760 new_abbrev
, name
, linkage_name
, flags
, nullptr,
19761 parent_entry
, maybe_defer
, true);
19765 if (!for_specification
)
19767 if (m_language
== language_ada
19768 && *linkage_name
== nullptr)
19769 *linkage_name
= *name
;
19771 if (!scanning_per_cu
->addresses_seen
19772 && low_pc
.has_value ()
19773 && (reader
->cu
->per_objfile
->per_bfd
->has_section_at_zero
19775 && high_pc
.has_value ())
19777 if (high_pc_relative
)
19778 high_pc
= *high_pc
+ *low_pc
;
19780 if (*high_pc
> *low_pc
)
19782 struct objfile
*objfile
= reader
->cu
->per_objfile
->objfile
;
19783 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
19784 struct gdbarch
*gdbarch
= objfile
->arch ();
19786 = (gdbarch_adjust_dwarf2_addr (gdbarch
, *low_pc
+ baseaddr
)
19789 = (gdbarch_adjust_dwarf2_addr (gdbarch
, *high_pc
+ baseaddr
)
19791 addrmap_set_empty (m_index_storage
->get_addrmap (), lo
, hi
- 1,
19796 if (abbrev
->tag
== DW_TAG_module
|| abbrev
->tag
== DW_TAG_namespace
)
19797 *flags
&= ~IS_STATIC
;
19799 if (abbrev
->tag
== DW_TAG_namespace
&& *name
== nullptr)
19800 *name
= "(anonymous namespace)";
19802 if (m_language
== language_cplus
19803 && (abbrev
->tag
== DW_TAG_class_type
19804 || abbrev
->tag
== DW_TAG_interface_type
19805 || abbrev
->tag
== DW_TAG_structure_type
19806 || abbrev
->tag
== DW_TAG_union_type
19807 || abbrev
->tag
== DW_TAG_enumeration_type
19808 || abbrev
->tag
== DW_TAG_enumerator
))
19809 *flags
&= ~IS_STATIC
;
19816 cooked_indexer::index_imported_unit (cutu_reader
*reader
,
19817 const gdb_byte
*info_ptr
,
19818 const abbrev_info
*abbrev
)
19820 sect_offset sect_off
{};
19821 bool is_dwz
= false;
19823 for (int i
= 0; i
< abbrev
->num_attrs
; ++i
)
19825 /* Note that we never need to reprocess attributes here. */
19827 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
19829 if (attr
.name
== DW_AT_import
)
19831 sect_off
= attr
.get_ref_die_offset ();
19832 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19833 || reader
->cu
->per_cu
->is_dwz
);
19837 /* Did not find DW_AT_import. */
19838 if (sect_off
== sect_offset (0))
19841 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
19842 cutu_reader
*new_reader
= ensure_cu_exists (reader
, per_objfile
, sect_off
,
19844 if (new_reader
!= nullptr)
19846 index_dies (new_reader
, new_reader
->info_ptr
, nullptr, false);
19848 reader
->cu
->add_dependence (new_reader
->cu
->per_cu
);
19855 cooked_indexer::recurse (cutu_reader
*reader
,
19856 const gdb_byte
*info_ptr
,
19857 const cooked_index_entry
*parent_entry
,
19860 info_ptr
= index_dies (reader
, info_ptr
, parent_entry
, fully
);
19862 if (parent_entry
!= nullptr)
19864 CORE_ADDR start
= form_addr (parent_entry
->die_offset
,
19865 reader
->cu
->per_cu
->is_dwz
);
19866 CORE_ADDR end
= form_addr (sect_offset (info_ptr
- 1 - reader
->buffer
),
19867 reader
->cu
->per_cu
->is_dwz
);
19868 addrmap_set_empty (m_die_range_map
, start
, end
, (void *) parent_entry
);
19875 cooked_indexer::index_dies (cutu_reader
*reader
,
19876 const gdb_byte
*info_ptr
,
19877 const cooked_index_entry
*parent_entry
,
19880 const gdb_byte
*end_ptr
= info_ptr
+ reader
->cu
->header
.get_length ();
19882 while (info_ptr
< end_ptr
)
19884 sect_offset this_die
= (sect_offset
) (info_ptr
- reader
->buffer
);
19885 unsigned int bytes_read
;
19886 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19888 info_ptr
+= bytes_read
;
19889 if (abbrev
== nullptr)
19892 if (abbrev
->tag
== DW_TAG_imported_unit
)
19894 info_ptr
= index_imported_unit (reader
, info_ptr
, abbrev
);
19898 if (!abbrev
->interesting
)
19900 info_ptr
= skip_one_die (reader
, info_ptr
, abbrev
, !fully
);
19901 if (fully
&& abbrev
->has_children
)
19902 info_ptr
= index_dies (reader
, info_ptr
, parent_entry
, fully
);
19906 const char *name
= nullptr;
19907 const char *linkage_name
= nullptr;
19908 CORE_ADDR defer
= 0;
19909 cooked_index_flag flags
= IS_STATIC
;
19910 sect_offset sibling
{};
19911 const cooked_index_entry
*this_parent_entry
= parent_entry
;
19912 info_ptr
= scan_attributes (reader
->cu
->per_cu
, reader
, info_ptr
,
19913 info_ptr
, abbrev
, &name
, &linkage_name
,
19914 &flags
, &sibling
, &this_parent_entry
,
19917 if (abbrev
->tag
== DW_TAG_namespace
19918 && m_language
== language_cplus
19919 && strcmp (name
, "::") == 0)
19921 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they
19922 generated bogus DW_TAG_namespace DIEs with a name of "::"
19923 for the global namespace. Work around this problem
19928 const cooked_index_entry
*this_entry
= nullptr;
19929 if (name
!= nullptr)
19932 m_deferred_entries
.push_back ({
19933 this_die
, name
, defer
, abbrev
->tag
, flags
19936 this_entry
= m_index_storage
->add (this_die
, abbrev
->tag
, flags
,
19937 name
, this_parent_entry
,
19941 if (linkage_name
!= nullptr)
19943 /* We only want this to be "main" if it has a linkage name
19944 but not an ordinary name. */
19945 if (name
!= nullptr)
19946 flags
= flags
& ~IS_MAIN
;
19947 m_index_storage
->add (this_die
, abbrev
->tag
, flags
| IS_LINKAGE
,
19948 linkage_name
, nullptr, m_per_cu
);
19951 if (abbrev
->has_children
)
19953 switch (abbrev
->tag
)
19955 case DW_TAG_class_type
:
19956 case DW_TAG_interface_type
:
19957 case DW_TAG_structure_type
:
19958 case DW_TAG_union_type
:
19959 if (m_language
!= language_c
&& this_entry
!= nullptr)
19961 info_ptr
= recurse (reader
, info_ptr
, this_entry
, fully
);
19966 case DW_TAG_enumeration_type
:
19967 /* We need to recurse even for an anonymous enumeration.
19968 Which scope we record as the parent scope depends on
19969 whether we're reading an "enum class". If so, we use
19970 the enum itself as the parent, yielding names like
19971 "enum_class::enumerator"; otherwise we inject the
19972 names into our own parent scope. */
19973 info_ptr
= recurse (reader
, info_ptr
,
19974 ((flags
& IS_ENUM_CLASS
) == 0)
19980 case DW_TAG_module
:
19981 if (this_entry
== nullptr)
19984 case DW_TAG_namespace
:
19985 /* We don't check THIS_ENTRY for a namespace, to handle
19986 the ancient G++ workaround pointed out above. */
19987 info_ptr
= recurse (reader
, info_ptr
, this_entry
, fully
);
19990 case DW_TAG_subprogram
:
19991 if ((m_language
== language_fortran
19992 || m_language
== language_ada
)
19993 && this_entry
!= nullptr)
19995 info_ptr
= recurse (reader
, info_ptr
, this_entry
, true);
20001 if (sibling
!= sect_offset (0))
20003 const gdb_byte
*sibling_ptr
20004 = reader
->buffer
+ to_underlying (sibling
);
20006 if (sibling_ptr
< info_ptr
)
20007 complaint (_("DW_AT_sibling points backwards"));
20008 else if (sibling_ptr
> reader
->buffer_end
)
20009 reader
->die_section
->overflow_complaint ();
20011 info_ptr
= sibling_ptr
;
20014 info_ptr
= skip_children (reader
, info_ptr
);
20022 cooked_indexer::make_index (cutu_reader
*reader
)
20024 check_bounds (reader
);
20025 find_file_and_directory (reader
->comp_unit_die
, reader
->cu
);
20026 if (!reader
->comp_unit_die
->has_children
)
20028 index_dies (reader
, reader
->info_ptr
, nullptr, false);
20030 for (const auto &entry
: m_deferred_entries
)
20032 CORE_ADDR key
= form_addr (entry
.die_offset
, m_per_cu
->is_dwz
);
20033 cooked_index_entry
*parent
20034 = (cooked_index_entry
*) addrmap_find (m_die_range_map
, key
);
20035 m_index_storage
->add (entry
.die_offset
, entry
.tag
, entry
.flags
,
20036 entry
.name
, parent
, m_per_cu
);
20040 /* An implementation of quick_symbol_functions for the cooked DWARF
20043 struct cooked_index_functions
: public dwarf2_base_index_functions
20045 struct compunit_symtab
*find_pc_sect_compunit_symtab
20046 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
20047 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
20049 struct compunit_symtab
*find_compunit_symtab_by_address
20050 (struct objfile
*objfile
, CORE_ADDR address
) override
;
20052 void dump (struct objfile
*objfile
) override
20054 gdb_printf ("Cooked index in use\n");
20057 void expand_matching_symbols
20059 const lookup_name_info
&lookup_name
,
20060 domain_enum domain
,
20062 symbol_compare_ftype
*ordered_compare
) override
;
20064 bool expand_symtabs_matching
20065 (struct objfile
*objfile
,
20066 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
20067 const lookup_name_info
*lookup_name
,
20068 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
20069 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
20070 block_search_flags search_flags
,
20071 domain_enum domain
,
20072 enum search_domain kind
) override
;
20074 bool can_lazily_read_symbols () override
20079 void read_partial_symbols (struct objfile
*objfile
) override
20081 if (dwarf2_has_info (objfile
, nullptr))
20082 dwarf2_build_psymtabs (objfile
);
20086 struct compunit_symtab
*
20087 cooked_index_functions::find_pc_sect_compunit_symtab
20088 (struct objfile
*objfile
,
20089 struct bound_minimal_symbol msymbol
,
20091 struct obj_section
*section
,
20092 int warn_if_readin
)
20094 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
20095 if (per_objfile
->per_bfd
->cooked_index_table
== nullptr)
20098 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
20099 dwarf2_per_cu_data
*per_cu
20100 = per_objfile
->per_bfd
->cooked_index_table
->lookup (pc
- baseaddr
);
20101 if (per_cu
== nullptr)
20104 if (warn_if_readin
&& per_objfile
->symtab_set_p (per_cu
))
20105 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
20106 paddress (objfile
->arch (), pc
));
20108 compunit_symtab
*result
= (recursively_find_pc_sect_compunit_symtab
20109 (dw2_instantiate_symtab (per_cu
, per_objfile
,
20112 gdb_assert (result
!= nullptr);
20116 struct compunit_symtab
*
20117 cooked_index_functions::find_compunit_symtab_by_address
20118 (struct objfile
*objfile
, CORE_ADDR address
)
20120 if (objfile
->sect_index_data
== -1)
20123 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
20124 if (per_objfile
->per_bfd
->cooked_index_table
== nullptr)
20127 CORE_ADDR baseaddr
= objfile
->data_section_offset ();
20128 dwarf2_per_cu_data
*per_cu
20129 = per_objfile
->per_bfd
->cooked_index_table
->lookup (address
- baseaddr
);
20130 if (per_cu
== nullptr)
20133 return dw2_instantiate_symtab (per_cu
, per_objfile
, false);
20137 cooked_index_functions::expand_matching_symbols
20138 (struct objfile
*objfile
,
20139 const lookup_name_info
&lookup_name
,
20140 domain_enum domain
,
20142 symbol_compare_ftype
*ordered_compare
)
20144 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
20145 if (per_objfile
->per_bfd
->cooked_index_table
== nullptr)
20147 const block_search_flags search_flags
= (global
20148 ? SEARCH_GLOBAL_BLOCK
20149 : SEARCH_STATIC_BLOCK
);
20150 const language_defn
*lang
= language_def (language_ada
);
20151 symbol_name_matcher_ftype
*name_match
20152 = lang
->get_symbol_name_matcher (lookup_name
);
20154 for (const cooked_index_entry
*entry
20155 : per_objfile
->per_bfd
->cooked_index_table
->all_entries ())
20157 if (entry
->parent_entry
!= nullptr)
20160 if (!entry
->matches (search_flags
)
20161 || !entry
->matches (domain
))
20164 if (name_match (entry
->canonical
, lookup_name
, nullptr))
20165 dw2_instantiate_symtab (entry
->per_cu
, per_objfile
, false);
20170 cooked_index_functions::expand_symtabs_matching
20171 (struct objfile
*objfile
,
20172 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
20173 const lookup_name_info
*lookup_name
,
20174 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
20175 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
20176 block_search_flags search_flags
,
20177 domain_enum domain
,
20178 enum search_domain kind
)
20180 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
20181 if (per_objfile
->per_bfd
->cooked_index_table
== nullptr)
20184 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
20186 /* This invariant is documented in quick-functions.h. */
20187 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
20188 if (lookup_name
== nullptr)
20190 for (dwarf2_per_cu_data
*per_cu
20191 : all_comp_units_range (per_objfile
->per_bfd
))
20195 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
20203 lookup_name_info lookup_name_without_params
20204 = lookup_name
->make_ignore_params ();
20205 bool completing
= lookup_name
->completion_mode ();
20207 /* Unique styles of language splitting. */
20208 static const enum language unique_styles
[] =
20210 /* No splitting is also a style. */
20212 /* This includes Rust. */
20214 /* This includes Go. */
20219 for (enum language lang
: unique_styles
)
20221 std::vector
<gdb::string_view
> name_vec
20222 = lookup_name_without_params
.split_name (lang
);
20224 for (const cooked_index_entry
*entry
20225 : per_objfile
->per_bfd
->cooked_index_table
->find (name_vec
.back (),
20228 /* No need to consider symbols from expanded CUs. */
20229 if (per_objfile
->symtab_set_p (entry
->per_cu
))
20232 /* If file-matching was done, we don't need to consider
20233 symbols from unmarked CUs. */
20234 if (file_matcher
!= nullptr && !entry
->per_cu
->v
.quick
->mark
)
20237 /* See if the symbol matches the type filter. */
20238 if (!entry
->matches (search_flags
)
20239 || !entry
->matches (domain
)
20240 || !entry
->matches (kind
))
20243 /* We've found the base name of the symbol; now walk its
20244 parentage chain, ensuring that each component
20248 const cooked_index_entry
*parent
= entry
->parent_entry
;
20249 for (int i
= name_vec
.size () - 1; i
> 0; --i
)
20251 /* If we ran out of entries, or if this segment doesn't
20252 match, this did not match. */
20253 if (parent
== nullptr
20254 || strncmp (parent
->name
, name_vec
[i
- 1].data (),
20255 name_vec
[i
- 1].length ()) != 0)
20261 parent
= parent
->parent_entry
;
20267 /* Might have been looking for "a::b" and found
20269 if (symbol_matcher
== nullptr)
20271 symbol_name_match_type match_type
20272 = lookup_name_without_params
.match_type ();
20273 if ((match_type
== symbol_name_match_type::FULL
20274 || (lang
!= language_ada
20275 && match_type
== symbol_name_match_type::EXPRESSION
))
20276 && parent
!= nullptr)
20281 auto_obstack temp_storage
;
20282 const char *full_name
= entry
->full_name (&temp_storage
);
20283 if (!symbol_matcher (full_name
))
20287 if (!dw2_expand_symtabs_matching_one (entry
->per_cu
, per_objfile
,
20297 /* Return a new cooked_index_functions object. */
20299 static quick_symbol_functions_up
20300 make_cooked_index_funcs ()
20302 return quick_symbol_functions_up (new cooked_index_functions
);
20307 /* Returns nonzero if TAG represents a type that we might generate a partial
20311 is_type_tag_for_partial (int tag
, enum language lang
)
20316 /* Some types that would be reasonable to generate partial symbols for,
20317 that we don't at present. Note that normally this does not
20318 matter, mainly because C compilers don't give names to these
20319 types, but instead emit DW_TAG_typedef. */
20320 case DW_TAG_file_type
:
20321 case DW_TAG_ptr_to_member_type
:
20322 case DW_TAG_set_type
:
20323 case DW_TAG_string_type
:
20324 case DW_TAG_subroutine_type
:
20327 /* GNAT may emit an array with a name, but no typedef, so we
20328 need to make a symbol in this case. */
20329 case DW_TAG_array_type
:
20330 return lang
== language_ada
;
20332 case DW_TAG_base_type
:
20333 case DW_TAG_class_type
:
20334 case DW_TAG_interface_type
:
20335 case DW_TAG_enumeration_type
:
20336 case DW_TAG_structure_type
:
20337 case DW_TAG_subrange_type
:
20338 case DW_TAG_generic_subrange
:
20339 case DW_TAG_typedef
:
20340 case DW_TAG_union_type
:
20347 /* Load all DIEs that are interesting for partial symbols into memory. */
20349 static struct partial_die_info
*
20350 load_partial_dies (const struct die_reader_specs
*reader
,
20351 const gdb_byte
*info_ptr
, int building_psymtab
)
20353 struct dwarf2_cu
*cu
= reader
->cu
;
20354 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20355 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
20356 unsigned int bytes_read
;
20357 unsigned int load_all
= 0;
20358 int nesting_level
= 1;
20363 gdb_assert (cu
->per_cu
!= NULL
);
20364 if (cu
->load_all_dies
)
20368 = htab_create_alloc_ex (cu
->header
.length
/ 12,
20372 &cu
->comp_unit_obstack
,
20373 hashtab_obstack_allocate
,
20374 dummy_obstack_deallocate
);
20378 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
20381 /* A NULL abbrev means the end of a series of children. */
20382 if (abbrev
== NULL
)
20384 if (--nesting_level
== 0)
20387 info_ptr
+= bytes_read
;
20388 last_die
= parent_die
;
20389 parent_die
= parent_die
->die_parent
;
20393 /* Check for template arguments. We never save these; if
20394 they're seen, we just mark the parent, and go on our way. */
20395 if (parent_die
!= NULL
20396 && cu
->per_cu
->lang
== language_cplus
20397 && (abbrev
->tag
== DW_TAG_template_type_param
20398 || abbrev
->tag
== DW_TAG_template_value_param
))
20400 parent_die
->has_template_arguments
= 1;
20404 /* We don't need a partial DIE for the template argument. */
20405 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
20410 /* We only recurse into c++ subprograms looking for template arguments.
20411 Skip their other children. */
20413 && cu
->per_cu
->lang
== language_cplus
20414 && parent_die
!= NULL
20415 && parent_die
->tag
== DW_TAG_subprogram
20416 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
20418 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
20422 /* Check whether this DIE is interesting enough to save. Normally
20423 we would not be interested in members here, but there may be
20424 later variables referencing them via DW_AT_specification (for
20425 static members). */
20427 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
20428 && abbrev
->tag
!= DW_TAG_constant
20429 && abbrev
->tag
!= DW_TAG_enumerator
20430 && abbrev
->tag
!= DW_TAG_subprogram
20431 && abbrev
->tag
!= DW_TAG_inlined_subroutine
20432 && abbrev
->tag
!= DW_TAG_lexical_block
20433 && abbrev
->tag
!= DW_TAG_variable
20434 && abbrev
->tag
!= DW_TAG_namespace
20435 && abbrev
->tag
!= DW_TAG_module
20436 && abbrev
->tag
!= DW_TAG_member
20437 && abbrev
->tag
!= DW_TAG_imported_unit
20438 && abbrev
->tag
!= DW_TAG_imported_declaration
)
20440 /* Otherwise we skip to the next sibling, if any. */
20441 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
20445 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
20448 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
20450 /* This two-pass algorithm for processing partial symbols has a
20451 high cost in cache pressure. Thus, handle some simple cases
20452 here which cover the majority of C partial symbols. DIEs
20453 which neither have specification tags in them, nor could have
20454 specification tags elsewhere pointing at them, can simply be
20455 processed and discarded.
20457 This segment is also optional; scan_partial_symbols and
20458 add_partial_symbol will handle these DIEs if we chain
20459 them in normally. When compilers which do not emit large
20460 quantities of duplicate debug information are more common,
20461 this code can probably be removed. */
20463 /* Any complete simple types at the top level (pretty much all
20464 of them, for a language without namespaces), can be processed
20466 if (parent_die
== NULL
20467 && pdi
.has_specification
== 0
20468 && pdi
.is_declaration
== 0
20469 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
20470 || pdi
.tag
== DW_TAG_base_type
20471 || pdi
.tag
== DW_TAG_array_type
20472 || pdi
.tag
== DW_TAG_generic_subrange
20473 || pdi
.tag
== DW_TAG_subrange_type
))
20475 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
20476 add_partial_symbol (&pdi
, cu
);
20478 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
20482 /* The exception for DW_TAG_typedef with has_children above is
20483 a workaround of GCC PR debug/47510. In the case of this complaint
20484 type_name_or_error will error on such types later.
20486 GDB skipped children of DW_TAG_typedef by the shortcut above and then
20487 it could not find the child DIEs referenced later, this is checked
20488 above. In correct DWARF DW_TAG_typedef should have no children. */
20490 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
20491 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
20492 "- DIE at %s [in module %s]"),
20493 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
20495 /* If we're at the second level, and we're an enumerator, and
20496 our parent has no specification (meaning possibly lives in a
20497 namespace elsewhere), then we can add the partial symbol now
20498 instead of queueing it. */
20499 if (pdi
.tag
== DW_TAG_enumerator
20500 && parent_die
!= NULL
20501 && parent_die
->die_parent
== NULL
20502 && parent_die
->tag
== DW_TAG_enumeration_type
20503 && parent_die
->has_specification
== 0)
20505 if (pdi
.raw_name
== NULL
)
20506 complaint (_("malformed enumerator DIE ignored"));
20507 else if (building_psymtab
)
20508 add_partial_symbol (&pdi
, cu
);
20510 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
20514 struct partial_die_info
*part_die
20515 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
20517 /* We'll save this DIE so link it in. */
20518 part_die
->die_parent
= parent_die
;
20519 part_die
->die_sibling
= NULL
;
20520 part_die
->die_child
= NULL
;
20522 if (last_die
&& last_die
== parent_die
)
20523 last_die
->die_child
= part_die
;
20525 last_die
->die_sibling
= part_die
;
20527 last_die
= part_die
;
20529 if (first_die
== NULL
)
20530 first_die
= part_die
;
20532 /* Maybe add the DIE to the hash table. Not all DIEs that we
20533 find interesting need to be in the hash table, because we
20534 also have the parent/sibling/child chains; only those that we
20535 might refer to by offset later during partial symbol reading.
20537 For now this means things that might have be the target of a
20538 DW_AT_specification, DW_AT_abstract_origin, or
20539 DW_AT_extension. DW_AT_extension will refer only to
20540 namespaces; DW_AT_abstract_origin refers to functions (and
20541 many things under the function DIE, but we do not recurse
20542 into function DIEs during partial symbol reading) and
20543 possibly variables as well; DW_AT_specification refers to
20544 declarations. Declarations ought to have the DW_AT_declaration
20545 flag. It happens that GCC forgets to put it in sometimes, but
20546 only for functions, not for types.
20548 Adding more things than necessary to the hash table is harmless
20549 except for the performance cost. Adding too few will result in
20550 wasted time in find_partial_die, when we reread the compilation
20551 unit with load_all_dies set. */
20554 || abbrev
->tag
== DW_TAG_constant
20555 || abbrev
->tag
== DW_TAG_subprogram
20556 || abbrev
->tag
== DW_TAG_variable
20557 || abbrev
->tag
== DW_TAG_namespace
20558 || part_die
->is_declaration
)
20562 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
20563 to_underlying (part_die
->sect_off
),
20568 /* For some DIEs we want to follow their children (if any). For C
20569 we have no reason to follow the children of structures; for other
20570 languages we have to, so that we can get at method physnames
20571 to infer fully qualified class names, for DW_AT_specification,
20572 and for C++ template arguments. For C++, we also look one level
20573 inside functions to find template arguments (if the name of the
20574 function does not already contain the template arguments).
20576 For Ada and Fortran, we need to scan the children of subprograms
20577 and lexical blocks as well because these languages allow the
20578 definition of nested entities that could be interesting for the
20579 debugger, such as nested subprograms for instance. */
20580 if (last_die
->has_children
20582 || last_die
->tag
== DW_TAG_namespace
20583 || last_die
->tag
== DW_TAG_module
20584 || last_die
->tag
== DW_TAG_enumeration_type
20585 || (cu
->per_cu
->lang
== language_cplus
20586 && last_die
->tag
== DW_TAG_subprogram
20587 && (last_die
->raw_name
== NULL
20588 || strchr (last_die
->raw_name
, '<') == NULL
))
20589 || (cu
->per_cu
->lang
!= language_c
20590 && (last_die
->tag
== DW_TAG_class_type
20591 || last_die
->tag
== DW_TAG_interface_type
20592 || last_die
->tag
== DW_TAG_structure_type
20593 || last_die
->tag
== DW_TAG_union_type
))
20594 || ((cu
->per_cu
->lang
== language_ada
20595 || cu
->per_cu
->lang
== language_fortran
)
20596 && (last_die
->tag
== DW_TAG_subprogram
20597 || last_die
->tag
== DW_TAG_lexical_block
))))
20600 parent_die
= last_die
;
20604 /* Otherwise we skip to the next sibling, if any. */
20605 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
20607 /* Back to the top, do it again. */
20611 partial_die_info::partial_die_info (sect_offset sect_off_
,
20612 const struct abbrev_info
*abbrev
)
20613 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
20617 /* See class definition. */
20620 partial_die_info::name (dwarf2_cu
*cu
)
20622 if (!canonical_name
&& raw_name
!= nullptr)
20624 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20625 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
20626 canonical_name
= 1;
20632 /* Read a minimal amount of information into the minimal die structure.
20633 INFO_PTR should point just after the initial uleb128 of a DIE. */
20636 partial_die_info::read (const struct die_reader_specs
*reader
,
20637 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
20639 struct dwarf2_cu
*cu
= reader
->cu
;
20640 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20642 int has_low_pc_attr
= 0;
20643 int has_high_pc_attr
= 0;
20644 int high_pc_relative
= 0;
20646 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
20649 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
20650 /* String and address offsets that need to do the reprocessing have
20651 already been read at this point, so there is no need to wait until
20652 the loop terminates to do the reprocessing. */
20653 if (attr
.requires_reprocessing_p ())
20654 read_attribute_reprocess (reader
, &attr
, tag
);
20655 /* Store the data if it is of an attribute we want to keep in a
20656 partial symbol table. */
20662 case DW_TAG_compile_unit
:
20663 case DW_TAG_partial_unit
:
20664 case DW_TAG_type_unit
:
20665 /* Compilation units have a DW_AT_name that is a filename, not
20666 a source language identifier. */
20667 case DW_TAG_enumeration_type
:
20668 case DW_TAG_enumerator
:
20669 /* These tags always have simple identifiers already; no need
20670 to canonicalize them. */
20671 canonical_name
= 1;
20672 raw_name
= attr
.as_string ();
20675 canonical_name
= 0;
20676 raw_name
= attr
.as_string ();
20680 case DW_AT_linkage_name
:
20681 case DW_AT_MIPS_linkage_name
:
20682 /* Note that both forms of linkage name might appear. We
20683 assume they will be the same, and we only store the last
20685 linkage_name
= attr
.as_string ();
20688 has_low_pc_attr
= 1;
20689 lowpc
= attr
.as_address ();
20691 case DW_AT_high_pc
:
20692 has_high_pc_attr
= 1;
20693 highpc
= attr
.as_address ();
20694 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
20695 high_pc_relative
= 1;
20697 case DW_AT_location
:
20698 /* Support the .debug_loc offsets. */
20699 if (attr
.form_is_block ())
20701 d
.locdesc
= attr
.as_block ();
20703 else if (attr
.form_is_section_offset ())
20705 dwarf2_complex_location_expr_complaint ();
20709 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
20710 "partial symbol information");
20713 case DW_AT_external
:
20714 is_external
= attr
.as_boolean ();
20716 case DW_AT_declaration
:
20717 is_declaration
= attr
.as_boolean ();
20722 case DW_AT_abstract_origin
:
20723 case DW_AT_specification
:
20724 case DW_AT_extension
:
20725 has_specification
= 1;
20726 spec_offset
= attr
.get_ref_die_offset ();
20727 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
20728 || cu
->per_cu
->is_dwz
);
20730 case DW_AT_sibling
:
20731 /* Ignore absolute siblings, they might point outside of
20732 the current compile unit. */
20733 if (attr
.form
== DW_FORM_ref_addr
)
20734 complaint (_("ignoring absolute DW_AT_sibling"));
20737 const gdb_byte
*buffer
= reader
->buffer
;
20738 sect_offset off
= attr
.get_ref_die_offset ();
20739 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
20741 if (sibling_ptr
< info_ptr
)
20742 complaint (_("DW_AT_sibling points backwards"));
20743 else if (sibling_ptr
> reader
->buffer_end
)
20744 reader
->die_section
->overflow_complaint ();
20746 sibling
= sibling_ptr
;
20749 case DW_AT_byte_size
:
20752 case DW_AT_const_value
:
20753 has_const_value
= 1;
20755 case DW_AT_calling_convention
:
20756 /* DWARF doesn't provide a way to identify a program's source-level
20757 entry point. DW_AT_calling_convention attributes are only meant
20758 to describe functions' calling conventions.
20760 However, because it's a necessary piece of information in
20761 Fortran, and before DWARF 4 DW_CC_program was the only
20762 piece of debugging information whose definition refers to
20763 a 'main program' at all, several compilers marked Fortran
20764 main programs with DW_CC_program --- even when those
20765 functions use the standard calling conventions.
20767 Although DWARF now specifies a way to provide this
20768 information, we support this practice for backward
20770 if (attr
.constant_value (0) == DW_CC_program
20771 && cu
->per_cu
->lang
== language_fortran
)
20772 main_subprogram
= 1;
20776 LONGEST value
= attr
.constant_value (-1);
20777 if (value
== DW_INL_inlined
20778 || value
== DW_INL_declared_inlined
)
20779 may_be_inlined
= 1;
20784 if (tag
== DW_TAG_imported_unit
)
20786 d
.sect_off
= attr
.get_ref_die_offset ();
20787 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
20788 || cu
->per_cu
->is_dwz
);
20792 case DW_AT_main_subprogram
:
20793 main_subprogram
= attr
.as_boolean ();
20798 /* Offset in the .debug_ranges or .debug_rnglist section (depending
20799 on DWARF version). */
20800 ranges_offset
= attr
.as_unsigned ();
20802 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
20804 if (tag
!= DW_TAG_compile_unit
)
20805 ranges_offset
+= cu
->gnu_ranges_base
;
20807 has_range_info
= 1;
20816 /* For Ada, if both the name and the linkage name appear, we prefer
20817 the latter. This lets "catch exception" work better, regardless
20818 of the order in which the name and linkage name were emitted.
20819 Really, though, this is just a workaround for the fact that gdb
20820 doesn't store both the name and the linkage name. */
20821 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
20822 raw_name
= linkage_name
;
20824 if (high_pc_relative
)
20827 if (has_low_pc_attr
&& has_high_pc_attr
)
20829 /* When using the GNU linker, .gnu.linkonce. sections are used to
20830 eliminate duplicate copies of functions and vtables and such.
20831 The linker will arbitrarily choose one and discard the others.
20832 The AT_*_pc values for such functions refer to local labels in
20833 these sections. If the section from that file was discarded, the
20834 labels are not in the output, so the relocs get a value of 0.
20835 If this is a discarded function, mark the pc bounds as invalid,
20836 so that GDB will ignore it. */
20837 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
20839 struct objfile
*objfile
= per_objfile
->objfile
;
20840 struct gdbarch
*gdbarch
= objfile
->arch ();
20842 complaint (_("DW_AT_low_pc %s is zero "
20843 "for DIE at %s [in module %s]"),
20844 paddress (gdbarch
, lowpc
),
20845 sect_offset_str (sect_off
),
20846 objfile_name (objfile
));
20848 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
20849 else if (lowpc
>= highpc
)
20851 struct objfile
*objfile
= per_objfile
->objfile
;
20852 struct gdbarch
*gdbarch
= objfile
->arch ();
20854 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
20855 "for DIE at %s [in module %s]"),
20856 paddress (gdbarch
, lowpc
),
20857 paddress (gdbarch
, highpc
),
20858 sect_offset_str (sect_off
),
20859 objfile_name (objfile
));
20868 /* Find a cached partial DIE at OFFSET in CU. */
20870 struct partial_die_info
*
20871 dwarf2_cu::find_partial_die (sect_offset sect_off
)
20873 struct partial_die_info
*lookup_die
= NULL
;
20874 struct partial_die_info
part_die (sect_off
);
20876 lookup_die
= ((struct partial_die_info
*)
20877 htab_find_with_hash (partial_dies
, &part_die
,
20878 to_underlying (sect_off
)));
20883 /* Find a partial DIE at OFFSET, which may or may not be in CU,
20884 except in the case of .debug_types DIEs which do not reference
20885 outside their CU (they do however referencing other types via
20886 DW_FORM_ref_sig8). */
20888 static const struct cu_partial_die_info
20889 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
20891 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20892 struct objfile
*objfile
= per_objfile
->objfile
;
20893 struct partial_die_info
*pd
= NULL
;
20895 if (offset_in_dwz
== cu
->per_cu
->is_dwz
20896 && cu
->header
.offset_in_cu_p (sect_off
))
20898 pd
= cu
->find_partial_die (sect_off
);
20901 /* We missed recording what we needed.
20902 Load all dies and try again. */
20906 /* TUs don't reference other CUs/TUs (except via type signatures). */
20907 if (cu
->per_cu
->is_debug_types
)
20909 error (_("Dwarf Error: Type Unit at offset %s contains"
20910 " external reference to offset %s [in module %s].\n"),
20911 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
20912 bfd_get_filename (objfile
->obfd
));
20914 dwarf2_per_cu_data
*per_cu
20915 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
20916 per_objfile
->per_bfd
);
20918 cu
= per_objfile
->get_cu (per_cu
);
20919 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
20920 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
20922 cu
= per_objfile
->get_cu (per_cu
);
20925 pd
= cu
->find_partial_die (sect_off
);
20928 /* If we didn't find it, and not all dies have been loaded,
20929 load them all and try again. */
20931 if (pd
== NULL
&& cu
->load_all_dies
== 0)
20933 cu
->load_all_dies
= 1;
20935 /* This is nasty. When we reread the DIEs, somewhere up the call chain
20936 THIS_CU->cu may already be in use. So we can't just free it and
20937 replace its DIEs with the ones we read in. Instead, we leave those
20938 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
20939 and clobber THIS_CU->cu->partial_dies with the hash table for the new
20941 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
20943 pd
= cu
->find_partial_die (sect_off
);
20947 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
20948 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
20952 /* See if we can figure out if the class lives in a namespace. We do
20953 this by looking for a member function; its demangled name will
20954 contain namespace info, if there is any. */
20957 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
20958 struct dwarf2_cu
*cu
)
20960 /* NOTE: carlton/2003-10-07: Getting the info this way changes
20961 what template types look like, because the demangler
20962 frequently doesn't give the same name as the debug info. We
20963 could fix this by only using the demangled name to get the
20964 prefix (but see comment in read_structure_type). */
20966 struct partial_die_info
*real_pdi
;
20967 struct partial_die_info
*child_pdi
;
20969 /* If this DIE (this DIE's specification, if any) has a parent, then
20970 we should not do this. We'll prepend the parent's fully qualified
20971 name when we create the partial symbol. */
20973 real_pdi
= struct_pdi
;
20974 while (real_pdi
->has_specification
)
20976 auto res
= find_partial_die (real_pdi
->spec_offset
,
20977 real_pdi
->spec_is_dwz
, cu
);
20978 real_pdi
= res
.pdi
;
20982 if (real_pdi
->die_parent
!= NULL
)
20985 for (child_pdi
= struct_pdi
->die_child
;
20987 child_pdi
= child_pdi
->die_sibling
)
20989 if (child_pdi
->tag
== DW_TAG_subprogram
20990 && child_pdi
->linkage_name
!= NULL
)
20992 gdb::unique_xmalloc_ptr
<char> actual_class_name
20993 (cu
->language_defn
->class_name_from_physname
20994 (child_pdi
->linkage_name
));
20995 if (actual_class_name
!= NULL
)
20997 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20998 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
20999 struct_pdi
->canonical_name
= 1;
21006 /* Return true if a DIE with TAG may have the DW_AT_const_value
21010 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
21014 case DW_TAG_constant
:
21015 case DW_TAG_enumerator
:
21016 case DW_TAG_formal_parameter
:
21017 case DW_TAG_template_value_param
:
21018 case DW_TAG_variable
:
21026 partial_die_info::fixup (struct dwarf2_cu
*cu
)
21028 /* Once we've fixed up a die, there's no point in doing so again.
21029 This also avoids a memory leak if we were to call
21030 guess_partial_die_structure_name multiple times. */
21034 /* If we found a reference attribute and the DIE has no name, try
21035 to find a name in the referred to DIE. */
21037 if (raw_name
== NULL
&& has_specification
)
21039 struct partial_die_info
*spec_die
;
21041 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
21042 spec_die
= res
.pdi
;
21045 spec_die
->fixup (cu
);
21047 if (spec_die
->raw_name
)
21049 raw_name
= spec_die
->raw_name
;
21050 canonical_name
= spec_die
->canonical_name
;
21052 /* Copy DW_AT_external attribute if it is set. */
21053 if (spec_die
->is_external
)
21054 is_external
= spec_die
->is_external
;
21058 if (!has_const_value
&& has_specification
21059 && can_have_DW_AT_const_value_p (tag
))
21061 struct partial_die_info
*spec_die
;
21063 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
21064 spec_die
= res
.pdi
;
21067 spec_die
->fixup (cu
);
21069 if (spec_die
->has_const_value
)
21071 /* Copy DW_AT_const_value attribute if it is set. */
21072 has_const_value
= spec_die
->has_const_value
;
21076 /* Set default names for some unnamed DIEs. */
21078 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
21080 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
21081 canonical_name
= 1;
21084 /* If there is no parent die to provide a namespace, and there are
21085 children, see if we can determine the namespace from their linkage
21087 if (cu
->per_cu
->lang
== language_cplus
21088 && !cu
->per_objfile
->per_bfd
->types
.empty ()
21089 && die_parent
== NULL
21091 && (tag
== DW_TAG_class_type
21092 || tag
== DW_TAG_structure_type
21093 || tag
== DW_TAG_union_type
))
21094 guess_partial_die_structure_name (this, cu
);
21096 /* GCC might emit a nameless struct or union that has a linkage
21097 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21098 if (raw_name
== NULL
21099 && (tag
== DW_TAG_class_type
21100 || tag
== DW_TAG_interface_type
21101 || tag
== DW_TAG_structure_type
21102 || tag
== DW_TAG_union_type
)
21103 && linkage_name
!= NULL
)
21105 gdb::unique_xmalloc_ptr
<char> demangled
21106 (gdb_demangle (linkage_name
, DMGL_TYPES
));
21107 if (demangled
!= nullptr)
21111 /* Strip any leading namespaces/classes, keep only the base name.
21112 DW_AT_name for named DIEs does not contain the prefixes. */
21113 base
= strrchr (demangled
.get (), ':');
21114 if (base
&& base
> demangled
.get () && base
[-1] == ':')
21117 base
= demangled
.get ();
21119 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21120 raw_name
= objfile
->intern (base
);
21121 canonical_name
= 1;
21128 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
21129 contents from the given SECTION in the HEADER.
21131 HEADER_OFFSET is the offset of the header in the section. */
21133 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
21134 struct dwarf2_section_info
*section
,
21135 sect_offset header_offset
)
21137 unsigned int bytes_read
;
21138 bfd
*abfd
= section
->get_bfd_owner ();
21139 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
21141 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
21142 info_ptr
+= bytes_read
;
21144 header
->version
= read_2_bytes (abfd
, info_ptr
);
21147 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
21150 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
21153 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
21156 /* Return the DW_AT_loclists_base value for the CU. */
21158 lookup_loclist_base (struct dwarf2_cu
*cu
)
21160 /* For the .dwo unit, the loclist_base points to the first offset following
21161 the header. The header consists of the following entities-
21162 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
21164 2. version (2 bytes)
21165 3. address size (1 byte)
21166 4. segment selector size (1 byte)
21167 5. offset entry count (4 bytes)
21168 These sizes are derived as per the DWARFv5 standard. */
21169 if (cu
->dwo_unit
!= nullptr)
21171 if (cu
->header
.initial_length_size
== 4)
21172 return LOCLIST_HEADER_SIZE32
;
21173 return LOCLIST_HEADER_SIZE64
;
21175 return cu
->loclist_base
;
21178 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
21179 array of offsets in the .debug_loclists section. */
21182 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
21184 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21185 struct objfile
*objfile
= per_objfile
->objfile
;
21186 bfd
*abfd
= objfile
->obfd
;
21187 ULONGEST loclist_header_size
=
21188 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
21189 : LOCLIST_HEADER_SIZE64
);
21190 ULONGEST loclist_base
= lookup_loclist_base (cu
);
21192 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
21193 ULONGEST start_offset
=
21194 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
21196 /* Get loclists section. */
21197 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21199 /* Read the loclists section content. */
21200 section
->read (objfile
);
21201 if (section
->buffer
== NULL
)
21202 error (_("DW_FORM_loclistx used without .debug_loclists "
21203 "section [in module %s]"), objfile_name (objfile
));
21205 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
21206 so if loclist_base is smaller than the header size, we have a problem. */
21207 if (loclist_base
< loclist_header_size
)
21208 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
21209 objfile_name (objfile
));
21211 /* Read the header of the loclists contribution. */
21212 struct loclists_rnglists_header header
;
21213 read_loclists_rnglists_header (&header
, section
,
21214 (sect_offset
) (loclist_base
- loclist_header_size
));
21216 /* Verify the loclist index is valid. */
21217 if (loclist_index
>= header
.offset_entry_count
)
21218 error (_("DW_FORM_loclistx pointing outside of "
21219 ".debug_loclists offset array [in module %s]"),
21220 objfile_name (objfile
));
21222 /* Validate that reading won't go beyond the end of the section. */
21223 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
21224 error (_("Reading DW_FORM_loclistx index beyond end of"
21225 ".debug_loclists section [in module %s]"),
21226 objfile_name (objfile
));
21228 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
21230 if (cu
->header
.offset_size
== 4)
21231 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
21233 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
21236 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
21237 array of offsets in the .debug_rnglists section. */
21240 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
21243 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21244 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21245 bfd
*abfd
= objfile
->obfd
;
21246 ULONGEST rnglist_header_size
=
21247 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
21248 : RNGLIST_HEADER_SIZE64
);
21250 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
21251 .debug_rnglists.dwo section. The rnglists base given in the skeleton
21253 ULONGEST rnglist_base
=
21254 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
21256 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
21257 ULONGEST start_offset
=
21258 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
21260 /* Get rnglists section. */
21261 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
21263 /* Read the rnglists section content. */
21264 section
->read (objfile
);
21265 if (section
->buffer
== nullptr)
21266 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
21268 objfile_name (objfile
));
21270 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
21271 so if rnglist_base is smaller than the header size, we have a problem. */
21272 if (rnglist_base
< rnglist_header_size
)
21273 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
21274 objfile_name (objfile
));
21276 /* Read the header of the rnglists contribution. */
21277 struct loclists_rnglists_header header
;
21278 read_loclists_rnglists_header (&header
, section
,
21279 (sect_offset
) (rnglist_base
- rnglist_header_size
));
21281 /* Verify the rnglist index is valid. */
21282 if (rnglist_index
>= header
.offset_entry_count
)
21283 error (_("DW_FORM_rnglistx index pointing outside of "
21284 ".debug_rnglists offset array [in module %s]"),
21285 objfile_name (objfile
));
21287 /* Validate that reading won't go beyond the end of the section. */
21288 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
21289 error (_("Reading DW_FORM_rnglistx index beyond end of"
21290 ".debug_rnglists section [in module %s]"),
21291 objfile_name (objfile
));
21293 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
21295 if (cu
->header
.offset_size
== 4)
21296 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
21298 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
21301 /* Process the attributes that had to be skipped in the first round. These
21302 attributes are the ones that need str_offsets_base or addr_base attributes.
21303 They could not have been processed in the first round, because at the time
21304 the values of str_offsets_base or addr_base may not have been known. */
21306 read_attribute_reprocess (const struct die_reader_specs
*reader
,
21307 struct attribute
*attr
, dwarf_tag tag
)
21309 struct dwarf2_cu
*cu
= reader
->cu
;
21310 switch (attr
->form
)
21312 case DW_FORM_addrx
:
21313 case DW_FORM_GNU_addr_index
:
21314 attr
->set_address (read_addr_index (cu
,
21315 attr
->as_unsigned_reprocess ()));
21317 case DW_FORM_loclistx
:
21319 sect_offset loclists_sect_off
21320 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
21322 attr
->set_unsigned (to_underlying (loclists_sect_off
));
21325 case DW_FORM_rnglistx
:
21327 sect_offset rnglists_sect_off
21328 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
21330 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
21334 case DW_FORM_strx1
:
21335 case DW_FORM_strx2
:
21336 case DW_FORM_strx3
:
21337 case DW_FORM_strx4
:
21338 case DW_FORM_GNU_str_index
:
21340 unsigned int str_index
= attr
->as_unsigned_reprocess ();
21341 gdb_assert (!attr
->canonical_string_p ());
21342 if (reader
->dwo_file
!= NULL
)
21343 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
21346 attr
->set_string_noncanonical (read_stub_str_index (cu
,
21351 gdb_assert_not_reached ("Unexpected DWARF form.");
21355 /* Read an attribute value described by an attribute form. */
21357 static const gdb_byte
*
21358 read_attribute_value (const struct die_reader_specs
*reader
,
21359 struct attribute
*attr
, unsigned form
,
21360 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
21362 struct dwarf2_cu
*cu
= reader
->cu
;
21363 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21364 struct objfile
*objfile
= per_objfile
->objfile
;
21365 bfd
*abfd
= reader
->abfd
;
21366 struct comp_unit_head
*cu_header
= &cu
->header
;
21367 unsigned int bytes_read
;
21368 struct dwarf_block
*blk
;
21370 attr
->form
= (enum dwarf_form
) form
;
21373 case DW_FORM_ref_addr
:
21374 if (cu_header
->version
== 2)
21375 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
21378 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
21380 info_ptr
+= bytes_read
;
21382 case DW_FORM_GNU_ref_alt
:
21383 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
21385 info_ptr
+= bytes_read
;
21389 struct gdbarch
*gdbarch
= objfile
->arch ();
21390 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
21391 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
21392 attr
->set_address (addr
);
21393 info_ptr
+= bytes_read
;
21396 case DW_FORM_block2
:
21397 blk
= dwarf_alloc_block (cu
);
21398 blk
->size
= read_2_bytes (abfd
, info_ptr
);
21400 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
21401 info_ptr
+= blk
->size
;
21402 attr
->set_block (blk
);
21404 case DW_FORM_block4
:
21405 blk
= dwarf_alloc_block (cu
);
21406 blk
->size
= read_4_bytes (abfd
, info_ptr
);
21408 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
21409 info_ptr
+= blk
->size
;
21410 attr
->set_block (blk
);
21412 case DW_FORM_data2
:
21413 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
21416 case DW_FORM_data4
:
21417 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
21420 case DW_FORM_data8
:
21421 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
21424 case DW_FORM_data16
:
21425 blk
= dwarf_alloc_block (cu
);
21427 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
21429 attr
->set_block (blk
);
21431 case DW_FORM_sec_offset
:
21432 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
21434 info_ptr
+= bytes_read
;
21436 case DW_FORM_loclistx
:
21438 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
21440 info_ptr
+= bytes_read
;
21443 case DW_FORM_string
:
21444 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
21446 info_ptr
+= bytes_read
;
21449 if (!cu
->per_cu
->is_dwz
)
21451 attr
->set_string_noncanonical
21452 (read_indirect_string (per_objfile
,
21453 abfd
, info_ptr
, cu_header
,
21455 info_ptr
+= bytes_read
;
21459 case DW_FORM_line_strp
:
21460 if (!cu
->per_cu
->is_dwz
)
21462 attr
->set_string_noncanonical
21463 (per_objfile
->read_line_string (info_ptr
, cu_header
,
21465 info_ptr
+= bytes_read
;
21469 case DW_FORM_GNU_strp_alt
:
21471 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
21472 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
21475 attr
->set_string_noncanonical
21476 (dwz
->read_string (objfile
, str_offset
));
21477 info_ptr
+= bytes_read
;
21480 case DW_FORM_exprloc
:
21481 case DW_FORM_block
:
21482 blk
= dwarf_alloc_block (cu
);
21483 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
21484 info_ptr
+= bytes_read
;
21485 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
21486 info_ptr
+= blk
->size
;
21487 attr
->set_block (blk
);
21489 case DW_FORM_block1
:
21490 blk
= dwarf_alloc_block (cu
);
21491 blk
->size
= read_1_byte (abfd
, info_ptr
);
21493 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
21494 info_ptr
+= blk
->size
;
21495 attr
->set_block (blk
);
21497 case DW_FORM_data1
:
21499 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
21502 case DW_FORM_flag_present
:
21503 attr
->set_unsigned (1);
21505 case DW_FORM_sdata
:
21506 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
21507 info_ptr
+= bytes_read
;
21509 case DW_FORM_rnglistx
:
21511 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
21513 info_ptr
+= bytes_read
;
21516 case DW_FORM_udata
:
21517 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
21518 info_ptr
+= bytes_read
;
21521 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
21522 + read_1_byte (abfd
, info_ptr
)));
21526 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
21527 + read_2_bytes (abfd
, info_ptr
)));
21531 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
21532 + read_4_bytes (abfd
, info_ptr
)));
21536 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
21537 + read_8_bytes (abfd
, info_ptr
)));
21540 case DW_FORM_ref_sig8
:
21541 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
21544 case DW_FORM_ref_udata
:
21545 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
21546 + read_unsigned_leb128 (abfd
, info_ptr
,
21548 info_ptr
+= bytes_read
;
21550 case DW_FORM_indirect
:
21551 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
21552 info_ptr
+= bytes_read
;
21553 if (form
== DW_FORM_implicit_const
)
21555 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
21556 info_ptr
+= bytes_read
;
21558 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
21561 case DW_FORM_implicit_const
:
21562 attr
->set_signed (implicit_const
);
21564 case DW_FORM_addrx
:
21565 case DW_FORM_GNU_addr_index
:
21566 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
21568 info_ptr
+= bytes_read
;
21571 case DW_FORM_strx1
:
21572 case DW_FORM_strx2
:
21573 case DW_FORM_strx3
:
21574 case DW_FORM_strx4
:
21575 case DW_FORM_GNU_str_index
:
21577 ULONGEST str_index
;
21578 if (form
== DW_FORM_strx1
)
21580 str_index
= read_1_byte (abfd
, info_ptr
);
21583 else if (form
== DW_FORM_strx2
)
21585 str_index
= read_2_bytes (abfd
, info_ptr
);
21588 else if (form
== DW_FORM_strx3
)
21590 str_index
= read_3_bytes (abfd
, info_ptr
);
21593 else if (form
== DW_FORM_strx4
)
21595 str_index
= read_4_bytes (abfd
, info_ptr
);
21600 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
21601 info_ptr
+= bytes_read
;
21603 attr
->set_unsigned_reprocess (str_index
);
21607 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
21608 dwarf_form_name (form
),
21609 bfd_get_filename (abfd
));
21613 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
21614 attr
->form
= DW_FORM_GNU_ref_alt
;
21616 /* We have seen instances where the compiler tried to emit a byte
21617 size attribute of -1 which ended up being encoded as an unsigned
21618 0xffffffff. Although 0xffffffff is technically a valid size value,
21619 an object of this size seems pretty unlikely so we can relatively
21620 safely treat these cases as if the size attribute was invalid and
21621 treat them as zero by default. */
21622 if (attr
->name
== DW_AT_byte_size
21623 && form
== DW_FORM_data4
21624 && attr
->as_unsigned () >= 0xffffffff)
21627 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
21628 hex_string (attr
->as_unsigned ()));
21629 attr
->set_unsigned (0);
21635 /* Read an attribute described by an abbreviated attribute. */
21637 static const gdb_byte
*
21638 read_attribute (const struct die_reader_specs
*reader
,
21639 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
21640 const gdb_byte
*info_ptr
)
21642 attr
->name
= abbrev
->name
;
21643 attr
->string_is_canonical
= 0;
21644 attr
->requires_reprocessing
= 0;
21645 return read_attribute_value (reader
, attr
, abbrev
->form
,
21646 abbrev
->implicit_const
, info_ptr
);
21649 /* Return pointer to string at .debug_str offset STR_OFFSET. */
21651 static const char *
21652 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
21653 LONGEST str_offset
)
21655 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
21656 str_offset
, "DW_FORM_strp");
21659 /* Return pointer to string at .debug_str offset as read from BUF.
21660 BUF is assumed to be in a compilation unit described by CU_HEADER.
21661 Return *BYTES_READ_PTR count of bytes read from BUF. */
21663 static const char *
21664 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
21665 const gdb_byte
*buf
,
21666 const struct comp_unit_head
*cu_header
,
21667 unsigned int *bytes_read_ptr
)
21669 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
21671 return read_indirect_string_at_offset (per_objfile
, str_offset
);
21677 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
21678 unsigned int offset_size
)
21680 bfd
*abfd
= objfile
->obfd
;
21681 ULONGEST str_offset
= read_offset (abfd
, buf
, offset_size
);
21683 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
21689 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
21690 const struct comp_unit_head
*cu_header
,
21691 unsigned int *bytes_read_ptr
)
21693 bfd
*abfd
= objfile
->obfd
;
21694 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
21696 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
21699 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
21700 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
21701 ADDR_SIZE is the size of addresses from the CU header. */
21704 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
21705 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
21707 struct objfile
*objfile
= per_objfile
->objfile
;
21708 bfd
*abfd
= objfile
->obfd
;
21709 const gdb_byte
*info_ptr
;
21710 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
21712 per_objfile
->per_bfd
->addr
.read (objfile
);
21713 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
21714 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
21715 objfile_name (objfile
));
21716 if (addr_base_or_zero
+ addr_index
* addr_size
21717 >= per_objfile
->per_bfd
->addr
.size
)
21718 error (_("DW_FORM_addr_index pointing outside of "
21719 ".debug_addr section [in module %s]"),
21720 objfile_name (objfile
));
21721 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
21722 + addr_index
* addr_size
);
21723 if (addr_size
== 4)
21724 return bfd_get_32 (abfd
, info_ptr
);
21726 return bfd_get_64 (abfd
, info_ptr
);
21729 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
21732 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
21734 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
21735 cu
->addr_base
, cu
->header
.addr_size
);
21738 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
21741 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
21742 unsigned int *bytes_read
)
21744 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
21745 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
21747 return read_addr_index (cu
, addr_index
);
21753 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
21754 dwarf2_per_objfile
*per_objfile
,
21755 unsigned int addr_index
)
21757 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
21758 gdb::optional
<ULONGEST
> addr_base
;
21761 /* We need addr_base and addr_size.
21762 If we don't have PER_CU->cu, we have to get it.
21763 Nasty, but the alternative is storing the needed info in PER_CU,
21764 which at this point doesn't seem justified: it's not clear how frequently
21765 it would get used and it would increase the size of every PER_CU.
21766 Entry points like dwarf2_per_cu_addr_size do a similar thing
21767 so we're not in uncharted territory here.
21768 Alas we need to be a bit more complicated as addr_base is contained
21771 We don't need to read the entire CU(/TU).
21772 We just need the header and top level die.
21774 IWBN to use the aging mechanism to let us lazily later discard the CU.
21775 For now we skip this optimization. */
21779 addr_base
= cu
->addr_base
;
21780 addr_size
= cu
->header
.addr_size
;
21784 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
21785 addr_base
= reader
.cu
->addr_base
;
21786 addr_size
= reader
.cu
->header
.addr_size
;
21789 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
21792 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
21793 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
21796 static const char *
21797 read_str_index (struct dwarf2_cu
*cu
,
21798 struct dwarf2_section_info
*str_section
,
21799 struct dwarf2_section_info
*str_offsets_section
,
21800 ULONGEST str_offsets_base
, ULONGEST str_index
)
21802 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21803 struct objfile
*objfile
= per_objfile
->objfile
;
21804 const char *objf_name
= objfile_name (objfile
);
21805 bfd
*abfd
= objfile
->obfd
;
21806 const gdb_byte
*info_ptr
;
21807 ULONGEST str_offset
;
21808 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
21810 str_section
->read (objfile
);
21811 str_offsets_section
->read (objfile
);
21812 if (str_section
->buffer
== NULL
)
21813 error (_("%s used without %s section"
21814 " in CU at offset %s [in module %s]"),
21815 form_name
, str_section
->get_name (),
21816 sect_offset_str (cu
->header
.sect_off
), objf_name
);
21817 if (str_offsets_section
->buffer
== NULL
)
21818 error (_("%s used without %s section"
21819 " in CU at offset %s [in module %s]"),
21820 form_name
, str_section
->get_name (),
21821 sect_offset_str (cu
->header
.sect_off
), objf_name
);
21822 info_ptr
= (str_offsets_section
->buffer
21824 + str_index
* cu
->header
.offset_size
);
21825 if (cu
->header
.offset_size
== 4)
21826 str_offset
= bfd_get_32 (abfd
, info_ptr
);
21828 str_offset
= bfd_get_64 (abfd
, info_ptr
);
21829 if (str_offset
>= str_section
->size
)
21830 error (_("Offset from %s pointing outside of"
21831 " .debug_str.dwo section in CU at offset %s [in module %s]"),
21832 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
21833 return (const char *) (str_section
->buffer
+ str_offset
);
21836 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
21838 static const char *
21839 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
21841 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
21842 ? reader
->cu
->header
.addr_size
: 0;
21843 return read_str_index (reader
->cu
,
21844 &reader
->dwo_file
->sections
.str
,
21845 &reader
->dwo_file
->sections
.str_offsets
,
21846 str_offsets_base
, str_index
);
21849 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
21851 static const char *
21852 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
21854 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21855 const char *objf_name
= objfile_name (objfile
);
21856 static const char form_name
[] = "DW_FORM_GNU_str_index";
21857 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
21859 if (!cu
->str_offsets_base
.has_value ())
21860 error (_("%s used in Fission stub without %s"
21861 " in CU at offset 0x%lx [in module %s]"),
21862 form_name
, str_offsets_attr_name
,
21863 (long) cu
->header
.offset_size
, objf_name
);
21865 return read_str_index (cu
,
21866 &cu
->per_objfile
->per_bfd
->str
,
21867 &cu
->per_objfile
->per_bfd
->str_offsets
,
21868 *cu
->str_offsets_base
, str_index
);
21871 /* Return the length of an LEB128 number in BUF. */
21874 leb128_size (const gdb_byte
*buf
)
21876 const gdb_byte
*begin
= buf
;
21882 if ((byte
& 128) == 0)
21883 return buf
- begin
;
21887 static enum language
21888 dwarf_lang_to_enum_language (unsigned int lang
)
21890 enum language language
;
21899 language
= language_c
;
21902 case DW_LANG_C_plus_plus
:
21903 case DW_LANG_C_plus_plus_11
:
21904 case DW_LANG_C_plus_plus_14
:
21905 language
= language_cplus
;
21908 language
= language_d
;
21910 case DW_LANG_Fortran77
:
21911 case DW_LANG_Fortran90
:
21912 case DW_LANG_Fortran95
:
21913 case DW_LANG_Fortran03
:
21914 case DW_LANG_Fortran08
:
21915 language
= language_fortran
;
21918 language
= language_go
;
21920 case DW_LANG_Mips_Assembler
:
21921 language
= language_asm
;
21923 case DW_LANG_Ada83
:
21924 case DW_LANG_Ada95
:
21925 language
= language_ada
;
21927 case DW_LANG_Modula2
:
21928 language
= language_m2
;
21930 case DW_LANG_Pascal83
:
21931 language
= language_pascal
;
21934 language
= language_objc
;
21937 case DW_LANG_Rust_old
:
21938 language
= language_rust
;
21940 case DW_LANG_OpenCL
:
21941 language
= language_opencl
;
21943 case DW_LANG_Cobol74
:
21944 case DW_LANG_Cobol85
:
21946 language
= language_minimal
;
21953 /* Return the named attribute or NULL if not there. */
21955 static struct attribute
*
21956 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
21961 struct attribute
*spec
= NULL
;
21963 for (i
= 0; i
< die
->num_attrs
; ++i
)
21965 if (die
->attrs
[i
].name
== name
)
21966 return &die
->attrs
[i
];
21967 if (die
->attrs
[i
].name
== DW_AT_specification
21968 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
21969 spec
= &die
->attrs
[i
];
21975 die
= follow_die_ref (die
, spec
, &cu
);
21981 /* Return the string associated with a string-typed attribute, or NULL if it
21982 is either not found or is of an incorrect type. */
21984 static const char *
21985 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
21987 struct attribute
*attr
;
21988 const char *str
= NULL
;
21990 attr
= dwarf2_attr (die
, name
, cu
);
21994 str
= attr
->as_string ();
21995 if (str
== nullptr)
21996 complaint (_("string type expected for attribute %s for "
21997 "DIE at %s in module %s"),
21998 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
21999 objfile_name (cu
->per_objfile
->objfile
));
22005 /* Return the dwo name or NULL if not present. If present, it is in either
22006 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
22007 static const char *
22008 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22010 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
22011 if (dwo_name
== nullptr)
22012 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
22016 /* Return non-zero iff the attribute NAME is defined for the given DIE,
22017 and holds a non-zero value. This function should only be used for
22018 DW_FORM_flag or DW_FORM_flag_present attributes. */
22021 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
22023 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
22025 return attr
!= nullptr && attr
->as_boolean ();
22029 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
22031 /* A DIE is a declaration if it has a DW_AT_declaration attribute
22032 which value is non-zero. However, we have to be careful with
22033 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
22034 (via dwarf2_flag_true_p) follows this attribute. So we may
22035 end up accidently finding a declaration attribute that belongs
22036 to a different DIE referenced by the specification attribute,
22037 even though the given DIE does not have a declaration attribute. */
22038 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
22039 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
22042 /* Return the die giving the specification for DIE, if there is
22043 one. *SPEC_CU is the CU containing DIE on input, and the CU
22044 containing the return value on output. If there is no
22045 specification, but there is an abstract origin, that is
22048 static struct die_info
*
22049 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
22051 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
22054 if (spec_attr
== NULL
)
22055 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
22057 if (spec_attr
== NULL
)
22060 return follow_die_ref (die
, spec_attr
, spec_cu
);
22063 /* A convenience function to find the proper .debug_line section for a CU. */
22065 static struct dwarf2_section_info
*
22066 get_debug_line_section (struct dwarf2_cu
*cu
)
22068 struct dwarf2_section_info
*section
;
22069 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22071 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
22073 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
22074 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
22075 else if (cu
->per_cu
->is_dwz
)
22077 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
22079 section
= &dwz
->line
;
22082 section
= &per_objfile
->per_bfd
->line
;
22087 /* Read the statement program header starting at OFFSET in
22088 .debug_line, or .debug_line.dwo. Return a pointer
22089 to a struct line_header, allocated using xmalloc.
22090 Returns NULL if there is a problem reading the header, e.g., if it
22091 has a version we don't understand.
22093 NOTE: the strings in the include directory and file name tables of
22094 the returned object point into the dwarf line section buffer,
22095 and must not be freed. */
22097 static line_header_up
22098 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
22100 struct dwarf2_section_info
*section
;
22101 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22103 section
= get_debug_line_section (cu
);
22104 section
->read (per_objfile
->objfile
);
22105 if (section
->buffer
== NULL
)
22107 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
22108 complaint (_("missing .debug_line.dwo section"));
22110 complaint (_("missing .debug_line section"));
22114 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
22115 per_objfile
, section
, &cu
->header
);
22118 /* Subroutine of dwarf_decode_lines to simplify it.
22119 Return the file name for the given file_entry.
22120 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
22121 If space for the result is malloc'd, *NAME_HOLDER will be set.
22122 Returns NULL if FILE_INDEX should be ignored, i.e., it is
22123 equivalent to CU_INFO. */
22125 static const char *
22126 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
22127 const file_and_directory
&cu_info
,
22128 gdb::unique_xmalloc_ptr
<char> *name_holder
)
22130 const char *include_name
= fe
.name
;
22131 const char *include_name_to_compare
= include_name
;
22133 const char *dir_name
= fe
.include_dir (lh
);
22135 gdb::unique_xmalloc_ptr
<char> hold_compare
;
22136 if (!IS_ABSOLUTE_PATH (include_name
)
22137 && (dir_name
!= nullptr || cu_info
.get_comp_dir () != nullptr))
22139 /* Avoid creating a duplicate name for CU_INFO.
22140 We do this by comparing INCLUDE_NAME and CU_INFO.
22141 Before we do the comparison, however, we need to account
22142 for DIR_NAME and COMP_DIR.
22143 First prepend dir_name (if non-NULL). If we still don't
22144 have an absolute path prepend comp_dir (if non-NULL).
22145 However, the directory we record in the include-file's
22146 psymtab does not contain COMP_DIR (to match the
22147 corresponding symtab(s)).
22152 bash$ gcc -g ./hello.c
22153 include_name = "hello.c"
22155 DW_AT_comp_dir = comp_dir = "/tmp"
22156 DW_AT_name = "./hello.c"
22160 if (dir_name
!= NULL
)
22162 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
22163 include_name
, (char *) NULL
));
22164 include_name
= name_holder
->get ();
22165 include_name_to_compare
= include_name
;
22167 if (!IS_ABSOLUTE_PATH (include_name
)
22168 && cu_info
.get_comp_dir () != nullptr)
22170 hold_compare
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
22171 include_name
, (char *) NULL
));
22172 include_name_to_compare
= hold_compare
.get ();
22176 gdb::unique_xmalloc_ptr
<char> copied_name
;
22177 const char *cu_filename
= cu_info
.get_name ();
22178 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.get_comp_dir () != nullptr)
22180 copied_name
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
22181 cu_filename
, (char *) NULL
));
22182 cu_filename
= copied_name
.get ();
22185 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
22187 return include_name
;
22190 /* State machine to track the state of the line number program. */
22192 class lnp_state_machine
22195 /* Initialize a machine state for the start of a line number
22197 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
22198 bool record_lines_p
);
22200 file_entry
*current_file ()
22202 /* lh->file_names is 0-based, but the file name numbers in the
22203 statement program are 1-based. */
22204 return m_line_header
->file_name_at (m_file
);
22207 /* Record the line in the state machine. END_SEQUENCE is true if
22208 we're processing the end of a sequence. */
22209 void record_line (bool end_sequence
);
22211 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
22212 nop-out rest of the lines in this sequence. */
22213 void check_line_address (struct dwarf2_cu
*cu
,
22214 const gdb_byte
*line_ptr
,
22215 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
22217 void handle_set_discriminator (unsigned int discriminator
)
22219 m_discriminator
= discriminator
;
22220 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
22223 /* Handle DW_LNE_set_address. */
22224 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
22227 address
+= baseaddr
;
22228 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
22231 /* Handle DW_LNS_advance_pc. */
22232 void handle_advance_pc (CORE_ADDR adjust
);
22234 /* Handle a special opcode. */
22235 void handle_special_opcode (unsigned char op_code
);
22237 /* Handle DW_LNS_advance_line. */
22238 void handle_advance_line (int line_delta
)
22240 advance_line (line_delta
);
22243 /* Handle DW_LNS_set_file. */
22244 void handle_set_file (file_name_index file
);
22246 /* Handle DW_LNS_negate_stmt. */
22247 void handle_negate_stmt ()
22249 m_flags
^= LEF_IS_STMT
;
22252 /* Handle DW_LNS_const_add_pc. */
22253 void handle_const_add_pc ();
22255 /* Handle DW_LNS_fixed_advance_pc. */
22256 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
22258 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
22262 /* Handle DW_LNS_copy. */
22263 void handle_copy ()
22265 record_line (false);
22266 m_discriminator
= 0;
22267 m_flags
&= ~LEF_PROLOGUE_END
;
22270 /* Handle DW_LNE_end_sequence. */
22271 void handle_end_sequence ()
22273 m_currently_recording_lines
= true;
22276 /* Handle DW_LNS_set_prologue_end. */
22277 void handle_set_prologue_end ()
22279 m_flags
|= LEF_PROLOGUE_END
;
22283 /* Advance the line by LINE_DELTA. */
22284 void advance_line (int line_delta
)
22286 m_line
+= line_delta
;
22288 if (line_delta
!= 0)
22289 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
22292 struct dwarf2_cu
*m_cu
;
22294 gdbarch
*m_gdbarch
;
22296 /* True if we're recording lines.
22297 Otherwise we're building partial symtabs and are just interested in
22298 finding include files mentioned by the line number program. */
22299 bool m_record_lines_p
;
22301 /* The line number header. */
22302 line_header
*m_line_header
;
22304 /* These are part of the standard DWARF line number state machine,
22305 and initialized according to the DWARF spec. */
22307 unsigned char m_op_index
= 0;
22308 /* The line table index of the current file. */
22309 file_name_index m_file
= 1;
22310 unsigned int m_line
= 1;
22312 /* These are initialized in the constructor. */
22314 CORE_ADDR m_address
;
22315 linetable_entry_flags m_flags
;
22316 unsigned int m_discriminator
;
22318 /* Additional bits of state we need to track. */
22320 /* The last file that we called dwarf2_start_subfile for.
22321 This is only used for TLLs. */
22322 unsigned int m_last_file
= 0;
22323 /* The last file a line number was recorded for. */
22324 struct subfile
*m_last_subfile
= NULL
;
22326 /* The address of the last line entry. */
22327 CORE_ADDR m_last_address
;
22329 /* Set to true when a previous line at the same address (using
22330 m_last_address) had LEF_IS_STMT set in m_flags. This is reset to false
22331 when a line entry at a new address (m_address different to
22332 m_last_address) is processed. */
22333 bool m_stmt_at_address
= false;
22335 /* When true, record the lines we decode. */
22336 bool m_currently_recording_lines
= false;
22338 /* The last line number that was recorded, used to coalesce
22339 consecutive entries for the same line. This can happen, for
22340 example, when discriminators are present. PR 17276. */
22341 unsigned int m_last_line
= 0;
22342 bool m_line_has_non_zero_discriminator
= false;
22346 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
22348 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
22349 / m_line_header
->maximum_ops_per_instruction
)
22350 * m_line_header
->minimum_instruction_length
);
22351 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
22352 m_op_index
= ((m_op_index
+ adjust
)
22353 % m_line_header
->maximum_ops_per_instruction
);
22357 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
22359 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
22360 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
22361 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
22362 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
22363 / m_line_header
->maximum_ops_per_instruction
)
22364 * m_line_header
->minimum_instruction_length
);
22365 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
22366 m_op_index
= ((m_op_index
+ adj_opcode_d
)
22367 % m_line_header
->maximum_ops_per_instruction
);
22369 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
22370 advance_line (line_delta
);
22371 record_line (false);
22372 m_discriminator
= 0;
22373 m_flags
&= ~LEF_PROLOGUE_END
;
22377 lnp_state_machine::handle_set_file (file_name_index file
)
22381 const file_entry
*fe
= current_file ();
22383 dwarf2_debug_line_missing_file_complaint ();
22384 else if (m_record_lines_p
)
22386 const char *dir
= fe
->include_dir (m_line_header
);
22388 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
22389 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
22390 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
22395 lnp_state_machine::handle_const_add_pc ()
22398 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
22401 = (((m_op_index
+ adjust
)
22402 / m_line_header
->maximum_ops_per_instruction
)
22403 * m_line_header
->minimum_instruction_length
);
22405 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
22406 m_op_index
= ((m_op_index
+ adjust
)
22407 % m_line_header
->maximum_ops_per_instruction
);
22410 /* Return non-zero if we should add LINE to the line number table.
22411 LINE is the line to add, LAST_LINE is the last line that was added,
22412 LAST_SUBFILE is the subfile for LAST_LINE.
22413 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
22414 had a non-zero discriminator.
22416 We have to be careful in the presence of discriminators.
22417 E.g., for this line:
22419 for (i = 0; i < 100000; i++);
22421 clang can emit four line number entries for that one line,
22422 each with a different discriminator.
22423 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
22425 However, we want gdb to coalesce all four entries into one.
22426 Otherwise the user could stepi into the middle of the line and
22427 gdb would get confused about whether the pc really was in the
22428 middle of the line.
22430 Things are further complicated by the fact that two consecutive
22431 line number entries for the same line is a heuristic used by gcc
22432 to denote the end of the prologue. So we can't just discard duplicate
22433 entries, we have to be selective about it. The heuristic we use is
22434 that we only collapse consecutive entries for the same line if at least
22435 one of those entries has a non-zero discriminator. PR 17276.
22437 Note: Addresses in the line number state machine can never go backwards
22438 within one sequence, thus this coalescing is ok. */
22441 dwarf_record_line_p (struct dwarf2_cu
*cu
,
22442 unsigned int line
, unsigned int last_line
,
22443 int line_has_non_zero_discriminator
,
22444 struct subfile
*last_subfile
)
22446 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
22448 if (line
!= last_line
)
22450 /* Same line for the same file that we've seen already.
22451 As a last check, for pr 17276, only record the line if the line
22452 has never had a non-zero discriminator. */
22453 if (!line_has_non_zero_discriminator
)
22458 /* Use the CU's builder to record line number LINE beginning at
22459 address ADDRESS in the line table of subfile SUBFILE. */
22462 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
22463 unsigned int line
, CORE_ADDR address
,
22464 linetable_entry_flags flags
,
22465 struct dwarf2_cu
*cu
)
22467 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
22469 if (dwarf_line_debug
)
22471 gdb_printf (gdb_stdlog
,
22472 "Recording line %u, file %s, address %s\n",
22473 line
, lbasename (subfile
->name
),
22474 paddress (gdbarch
, address
));
22478 cu
->get_builder ()->record_line (subfile
, line
, addr
, flags
);
22481 /* Subroutine of dwarf_decode_lines_1 to simplify it.
22482 Mark the end of a set of line number records.
22483 The arguments are the same as for dwarf_record_line_1.
22484 If SUBFILE is NULL the request is ignored. */
22487 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
22488 CORE_ADDR address
, struct dwarf2_cu
*cu
)
22490 if (subfile
== NULL
)
22493 if (dwarf_line_debug
)
22495 gdb_printf (gdb_stdlog
,
22496 "Finishing current line, file %s, address %s\n",
22497 lbasename (subfile
->name
),
22498 paddress (gdbarch
, address
));
22501 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, LEF_IS_STMT
, cu
);
22505 lnp_state_machine::record_line (bool end_sequence
)
22507 if (dwarf_line_debug
)
22509 gdb_printf (gdb_stdlog
,
22510 "Processing actual line %u: file %u,"
22511 " address %s, is_stmt %u, prologue_end %u, discrim %u%s\n",
22513 paddress (m_gdbarch
, m_address
),
22514 (m_flags
& LEF_IS_STMT
) != 0,
22515 (m_flags
& LEF_PROLOGUE_END
) != 0,
22517 (end_sequence
? "\t(end sequence)" : ""));
22520 file_entry
*fe
= current_file ();
22523 dwarf2_debug_line_missing_file_complaint ();
22524 /* For now we ignore lines not starting on an instruction boundary.
22525 But not when processing end_sequence for compatibility with the
22526 previous version of the code. */
22527 else if (m_op_index
== 0 || end_sequence
)
22529 fe
->included_p
= true;
22530 if (m_record_lines_p
)
22532 /* When we switch files we insert an end maker in the first file,
22533 switch to the second file and add a new line entry. The
22534 problem is that the end marker inserted in the first file will
22535 discard any previous line entries at the same address. If the
22536 line entries in the first file are marked as is-stmt, while
22537 the new line in the second file is non-stmt, then this means
22538 the end marker will discard is-stmt lines so we can have a
22539 non-stmt line. This means that there are less addresses at
22540 which the user can insert a breakpoint.
22542 To improve this we track the last address in m_last_address,
22543 and whether we have seen an is-stmt at this address. Then
22544 when switching files, if we have seen a stmt at the current
22545 address, and we are switching to create a non-stmt line, then
22546 discard the new line. */
22548 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
22549 bool ignore_this_line
22550 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
22551 && ((m_flags
& LEF_IS_STMT
) == 0)
22552 && m_stmt_at_address
)
22553 || (!end_sequence
&& m_line
== 0));
22555 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
22557 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
22558 m_currently_recording_lines
? m_cu
: nullptr);
22561 if (!end_sequence
&& !ignore_this_line
)
22563 linetable_entry_flags lte_flags
= m_flags
;
22564 if (producer_is_codewarrior (m_cu
))
22565 lte_flags
|= LEF_IS_STMT
;
22567 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
22568 m_line_has_non_zero_discriminator
,
22571 buildsym_compunit
*builder
= m_cu
->get_builder ();
22572 dwarf_record_line_1 (m_gdbarch
,
22573 builder
->get_current_subfile (),
22574 m_line
, m_address
, lte_flags
,
22575 m_currently_recording_lines
? m_cu
: nullptr);
22577 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
22578 m_last_line
= m_line
;
22583 /* Track whether we have seen any IS_STMT true at m_address in case we
22584 have multiple line table entries all at m_address. */
22585 if (m_last_address
!= m_address
)
22587 m_stmt_at_address
= false;
22588 m_last_address
= m_address
;
22590 m_stmt_at_address
|= (m_flags
& LEF_IS_STMT
) != 0;
22593 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
22594 line_header
*lh
, bool record_lines_p
)
22598 m_record_lines_p
= record_lines_p
;
22599 m_line_header
= lh
;
22601 m_currently_recording_lines
= true;
22603 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
22604 was a line entry for it so that the backend has a chance to adjust it
22605 and also record it in case it needs it. This is currently used by MIPS
22606 code, cf. `mips_adjust_dwarf2_line'. */
22607 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
22609 if (lh
->default_is_stmt
)
22610 m_flags
|= LEF_IS_STMT
;
22611 m_discriminator
= 0;
22613 m_last_address
= m_address
;
22614 m_stmt_at_address
= false;
22618 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
22619 const gdb_byte
*line_ptr
,
22620 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
22622 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
22623 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
22624 located at 0x0. In this case, additionally check that if
22625 ADDRESS < UNRELOCATED_LOWPC. */
22627 if ((address
== 0 && address
< unrelocated_lowpc
)
22628 || address
== (CORE_ADDR
) -1)
22630 /* This line table is for a function which has been
22631 GCd by the linker. Ignore it. PR gdb/12528 */
22633 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22634 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
22636 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
22637 line_offset
, objfile_name (objfile
));
22638 m_currently_recording_lines
= false;
22639 /* Note: m_currently_recording_lines is left as false until we see
22640 DW_LNE_end_sequence. */
22644 /* Subroutine of dwarf_decode_lines to simplify it.
22645 Process the line number information in LH.
22646 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
22647 program in order to set included_p for every referenced header. */
22650 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
22651 const int decode_for_pst_p
, CORE_ADDR lowpc
)
22653 const gdb_byte
*line_ptr
, *extended_end
;
22654 const gdb_byte
*line_end
;
22655 unsigned int bytes_read
, extended_len
;
22656 unsigned char op_code
, extended_op
;
22657 CORE_ADDR baseaddr
;
22658 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22659 bfd
*abfd
= objfile
->obfd
;
22660 struct gdbarch
*gdbarch
= objfile
->arch ();
22661 /* True if we're recording line info (as opposed to building partial
22662 symtabs and just interested in finding include files mentioned by
22663 the line number program). */
22664 bool record_lines_p
= !decode_for_pst_p
;
22666 baseaddr
= objfile
->text_section_offset ();
22668 line_ptr
= lh
->statement_program_start
;
22669 line_end
= lh
->statement_program_end
;
22671 /* Read the statement sequences until there's nothing left. */
22672 while (line_ptr
< line_end
)
22674 /* The DWARF line number program state machine. Reset the state
22675 machine at the start of each sequence. */
22676 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
22677 bool end_sequence
= false;
22679 if (record_lines_p
)
22681 /* Start a subfile for the current file of the state
22683 const file_entry
*fe
= state_machine
.current_file ();
22686 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
22689 /* Decode the table. */
22690 while (line_ptr
< line_end
&& !end_sequence
)
22692 op_code
= read_1_byte (abfd
, line_ptr
);
22695 if (op_code
>= lh
->opcode_base
)
22697 /* Special opcode. */
22698 state_machine
.handle_special_opcode (op_code
);
22700 else switch (op_code
)
22702 case DW_LNS_extended_op
:
22703 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
22705 line_ptr
+= bytes_read
;
22706 extended_end
= line_ptr
+ extended_len
;
22707 extended_op
= read_1_byte (abfd
, line_ptr
);
22709 if (DW_LNE_lo_user
<= extended_op
22710 && extended_op
<= DW_LNE_hi_user
)
22712 /* Vendor extension, ignore. */
22713 line_ptr
= extended_end
;
22716 switch (extended_op
)
22718 case DW_LNE_end_sequence
:
22719 state_machine
.handle_end_sequence ();
22720 end_sequence
= true;
22722 case DW_LNE_set_address
:
22725 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
22726 line_ptr
+= bytes_read
;
22728 state_machine
.check_line_address (cu
, line_ptr
,
22729 lowpc
- baseaddr
, address
);
22730 state_machine
.handle_set_address (baseaddr
, address
);
22733 case DW_LNE_define_file
:
22735 const char *cur_file
;
22736 unsigned int mod_time
, length
;
22739 cur_file
= read_direct_string (abfd
, line_ptr
,
22741 line_ptr
+= bytes_read
;
22742 dindex
= (dir_index
)
22743 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
22744 line_ptr
+= bytes_read
;
22746 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
22747 line_ptr
+= bytes_read
;
22749 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
22750 line_ptr
+= bytes_read
;
22751 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
22754 case DW_LNE_set_discriminator
:
22756 /* The discriminator is not interesting to the
22757 debugger; just ignore it. We still need to
22758 check its value though:
22759 if there are consecutive entries for the same
22760 (non-prologue) line we want to coalesce them.
22763 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
22764 line_ptr
+= bytes_read
;
22766 state_machine
.handle_set_discriminator (discr
);
22770 complaint (_("mangled .debug_line section"));
22773 /* Make sure that we parsed the extended op correctly. If e.g.
22774 we expected a different address size than the producer used,
22775 we may have read the wrong number of bytes. */
22776 if (line_ptr
!= extended_end
)
22778 complaint (_("mangled .debug_line section"));
22783 state_machine
.handle_copy ();
22785 case DW_LNS_advance_pc
:
22788 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
22789 line_ptr
+= bytes_read
;
22791 state_machine
.handle_advance_pc (adjust
);
22794 case DW_LNS_advance_line
:
22797 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
22798 line_ptr
+= bytes_read
;
22800 state_machine
.handle_advance_line (line_delta
);
22803 case DW_LNS_set_file
:
22805 file_name_index file
22806 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
22808 line_ptr
+= bytes_read
;
22810 state_machine
.handle_set_file (file
);
22813 case DW_LNS_set_column
:
22814 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
22815 line_ptr
+= bytes_read
;
22817 case DW_LNS_negate_stmt
:
22818 state_machine
.handle_negate_stmt ();
22820 case DW_LNS_set_basic_block
:
22822 /* Add to the address register of the state machine the
22823 address increment value corresponding to special opcode
22824 255. I.e., this value is scaled by the minimum
22825 instruction length since special opcode 255 would have
22826 scaled the increment. */
22827 case DW_LNS_const_add_pc
:
22828 state_machine
.handle_const_add_pc ();
22830 case DW_LNS_fixed_advance_pc
:
22832 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
22835 state_machine
.handle_fixed_advance_pc (addr_adj
);
22838 case DW_LNS_set_prologue_end
:
22839 state_machine
.handle_set_prologue_end ();
22843 /* Unknown standard opcode, ignore it. */
22846 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
22848 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
22849 line_ptr
+= bytes_read
;
22856 dwarf2_debug_line_missing_end_sequence_complaint ();
22858 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
22859 in which case we still finish recording the last line). */
22860 state_machine
.record_line (true);
22864 /* Decode the Line Number Program (LNP) for the given line_header
22865 structure and CU. The actual information extracted and the type
22866 of structures created from the LNP depends on the value of PST.
22868 1. If PST is NULL, then this procedure uses the data from the program
22869 to create all necessary symbol tables, and their linetables.
22871 2. If PST is not NULL, this procedure reads the program to determine
22872 the list of files included by the unit represented by PST, and
22873 builds all the associated partial symbol tables.
22875 FND holds the CU file name and directory, if known.
22876 It is used for relative paths in the line table.
22878 NOTE: It is important that psymtabs have the same file name (via
22879 strcmp) as the corresponding symtab. Since the directory is not
22880 used in the name of the symtab we don't use it in the name of the
22881 psymtabs we create. E.g. expand_line_sal requires this when
22882 finding psymtabs to expand. A good testcase for this is
22885 LOWPC is the lowest address in CU (or 0 if not known).
22887 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
22888 for its PC<->lines mapping information. Otherwise only the filename
22889 table is read in. */
22892 dwarf_decode_lines (struct line_header
*lh
, const file_and_directory
&fnd
,
22893 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
22894 CORE_ADDR lowpc
, int decode_mapping
)
22896 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22897 const int decode_for_pst_p
= (pst
!= NULL
);
22899 if (decode_mapping
)
22900 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
22902 if (decode_for_pst_p
)
22904 /* Now that we're done scanning the Line Header Program, we can
22905 create the psymtab of each included file. */
22906 for (auto &file_entry
: lh
->file_names ())
22907 if (file_entry
.included_p
)
22909 gdb::unique_xmalloc_ptr
<char> name_holder
;
22910 const char *include_name
=
22911 compute_include_file_name (lh
, file_entry
, fnd
, &name_holder
);
22912 if (include_name
!= NULL
)
22913 dwarf2_create_include_psymtab
22914 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
22915 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
22921 /* Make sure a symtab is created for every file, even files
22922 which contain only variables (i.e. no code with associated
22924 buildsym_compunit
*builder
= cu
->get_builder ();
22925 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
22927 for (auto &fe
: lh
->file_names ())
22929 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
22930 if (builder
->get_current_subfile ()->symtab
== NULL
)
22932 builder
->get_current_subfile ()->symtab
22933 = allocate_symtab (cust
,
22934 builder
->get_current_subfile ()->name
);
22936 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
22941 /* Start a subfile for DWARF. FILENAME is the name of the file and
22942 DIRNAME the name of the source directory which contains FILENAME
22943 or NULL if not known.
22944 This routine tries to keep line numbers from identical absolute and
22945 relative file names in a common subfile.
22947 Using the `list' example from the GDB testsuite, which resides in
22948 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
22949 of /srcdir/list0.c yields the following debugging information for list0.c:
22951 DW_AT_name: /srcdir/list0.c
22952 DW_AT_comp_dir: /compdir
22953 files.files[0].name: list0.h
22954 files.files[0].dir: /srcdir
22955 files.files[1].name: list0.c
22956 files.files[1].dir: /srcdir
22958 The line number information for list0.c has to end up in a single
22959 subfile, so that `break /srcdir/list0.c:1' works as expected.
22960 start_subfile will ensure that this happens provided that we pass the
22961 concatenation of files.files[1].dir and files.files[1].name as the
22965 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
22966 const char *dirname
)
22968 gdb::unique_xmalloc_ptr
<char> copy
;
22970 /* In order not to lose the line information directory,
22971 we concatenate it to the filename when it makes sense.
22972 Note that the Dwarf3 standard says (speaking of filenames in line
22973 information): ``The directory index is ignored for file names
22974 that represent full path names''. Thus ignoring dirname in the
22975 `else' branch below isn't an issue. */
22977 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
22979 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
22980 filename
= copy
.get ();
22983 cu
->get_builder ()->start_subfile (filename
);
22987 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
22988 struct dwarf2_cu
*cu
)
22990 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22991 struct comp_unit_head
*cu_header
= &cu
->header
;
22993 /* NOTE drow/2003-01-30: There used to be a comment and some special
22994 code here to turn a symbol with DW_AT_external and a
22995 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
22996 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
22997 with some versions of binutils) where shared libraries could have
22998 relocations against symbols in their debug information - the
22999 minimal symbol would have the right address, but the debug info
23000 would not. It's no longer necessary, because we will explicitly
23001 apply relocations when we read in the debug information now. */
23003 /* A DW_AT_location attribute with no contents indicates that a
23004 variable has been optimized away. */
23005 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
23007 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
23011 /* Handle one degenerate form of location expression specially, to
23012 preserve GDB's previous behavior when section offsets are
23013 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
23014 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
23016 if (attr
->form_is_block ())
23018 struct dwarf_block
*block
= attr
->as_block ();
23020 if ((block
->data
[0] == DW_OP_addr
23021 && block
->size
== 1 + cu_header
->addr_size
)
23022 || ((block
->data
[0] == DW_OP_GNU_addr_index
23023 || block
->data
[0] == DW_OP_addrx
)
23025 == 1 + leb128_size (&block
->data
[1]))))
23027 unsigned int dummy
;
23029 if (block
->data
[0] == DW_OP_addr
)
23030 sym
->set_value_address
23031 (cu
->header
.read_address (objfile
->obfd
, block
->data
+ 1,
23034 sym
->set_value_address
23035 (read_addr_index_from_leb128 (cu
, block
->data
+ 1, &dummy
));
23036 sym
->set_aclass_index (LOC_STATIC
);
23037 fixup_symbol_section (sym
, objfile
);
23038 sym
->set_value_address
23039 (sym
->value_address ()
23040 + objfile
->section_offsets
[sym
->section_index ()]);
23045 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
23046 expression evaluator, and use LOC_COMPUTED only when necessary
23047 (i.e. when the value of a register or memory location is
23048 referenced, or a thread-local block, etc.). Then again, it might
23049 not be worthwhile. I'm assuming that it isn't unless performance
23050 or memory numbers show me otherwise. */
23052 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
23054 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
23055 cu
->has_loclist
= true;
23058 /* Given a pointer to a DWARF information entry, figure out if we need
23059 to make a symbol table entry for it, and if so, create a new entry
23060 and return a pointer to it.
23061 If TYPE is NULL, determine symbol type from the die, otherwise
23062 used the passed type.
23063 If SPACE is not NULL, use it to hold the new symbol. If it is
23064 NULL, allocate a new symbol on the objfile's obstack. */
23066 static struct symbol
*
23067 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
23068 struct symbol
*space
)
23070 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23071 struct objfile
*objfile
= per_objfile
->objfile
;
23072 struct gdbarch
*gdbarch
= objfile
->arch ();
23073 struct symbol
*sym
= NULL
;
23075 struct attribute
*attr
= NULL
;
23076 struct attribute
*attr2
= NULL
;
23077 CORE_ADDR baseaddr
;
23078 struct pending
**list_to_add
= NULL
;
23080 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
23082 baseaddr
= objfile
->text_section_offset ();
23084 name
= dwarf2_name (die
, cu
);
23087 int suppress_add
= 0;
23092 sym
= new (&objfile
->objfile_obstack
) symbol
;
23093 OBJSTAT (objfile
, n_syms
++);
23095 /* Cache this symbol's name and the name's demangled form (if any). */
23096 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
23097 /* Fortran does not have mangling standard and the mangling does differ
23098 between gfortran, iFort etc. */
23099 const char *physname
23100 = (cu
->per_cu
->lang
== language_fortran
23101 ? dwarf2_full_name (name
, die
, cu
)
23102 : dwarf2_physname (name
, die
, cu
));
23103 const char *linkagename
= dw2_linkage_name (die
, cu
);
23105 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
23106 sym
->set_linkage_name (physname
);
23109 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
23110 sym
->set_linkage_name (linkagename
);
23113 /* Handle DW_AT_artificial. */
23114 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
23115 if (attr
!= nullptr)
23116 sym
->artificial
= attr
->as_boolean ();
23118 /* Default assumptions.
23119 Use the passed type or decode it from the die. */
23120 sym
->set_domain (VAR_DOMAIN
);
23121 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
23123 sym
->set_type (type
);
23125 sym
->set_type (die_type (die
, cu
));
23126 attr
= dwarf2_attr (die
,
23127 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
23129 if (attr
!= nullptr)
23130 sym
->set_line (attr
->constant_value (0));
23132 attr
= dwarf2_attr (die
,
23133 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
23135 if (attr
!= nullptr && attr
->is_nonnegative ())
23137 file_name_index file_index
23138 = (file_name_index
) attr
->as_nonnegative ();
23139 struct file_entry
*fe
;
23141 if (cu
->line_header
!= NULL
)
23142 fe
= cu
->line_header
->file_name_at (file_index
);
23147 complaint (_("file index out of range"));
23149 symbol_set_symtab (sym
, fe
->symtab
);
23155 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
23156 if (attr
!= nullptr)
23160 addr
= attr
->as_address ();
23161 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
23162 sym
->set_value_address (addr
);
23163 sym
->set_aclass_index (LOC_LABEL
);
23166 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
23167 sym
->set_type (objfile_type (objfile
)->builtin_core_addr
);
23168 sym
->set_domain (LABEL_DOMAIN
);
23169 add_symbol_to_list (sym
, cu
->list_in_scope
);
23171 case DW_TAG_subprogram
:
23172 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
23174 sym
->set_aclass_index (LOC_BLOCK
);
23175 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
23176 if ((attr2
!= nullptr && attr2
->as_boolean ())
23177 || cu
->per_cu
->lang
== language_ada
23178 || cu
->per_cu
->lang
== language_fortran
)
23180 /* Subprograms marked external are stored as a global symbol.
23181 Ada and Fortran subprograms, whether marked external or
23182 not, are always stored as a global symbol, because we want
23183 to be able to access them globally. For instance, we want
23184 to be able to break on a nested subprogram without having
23185 to specify the context. */
23186 list_to_add
= cu
->get_builder ()->get_global_symbols ();
23190 list_to_add
= cu
->list_in_scope
;
23193 case DW_TAG_inlined_subroutine
:
23194 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
23196 sym
->set_aclass_index (LOC_BLOCK
);
23197 sym
->set_is_inlined (1);
23198 list_to_add
= cu
->list_in_scope
;
23200 case DW_TAG_template_value_param
:
23202 /* Fall through. */
23203 case DW_TAG_constant
:
23204 case DW_TAG_variable
:
23205 case DW_TAG_member
:
23206 /* Compilation with minimal debug info may result in
23207 variables with missing type entries. Change the
23208 misleading `void' type to something sensible. */
23209 if (sym
->type ()->code () == TYPE_CODE_VOID
)
23210 sym
->set_type (objfile_type (objfile
)->builtin_int
);
23212 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23213 /* In the case of DW_TAG_member, we should only be called for
23214 static const members. */
23215 if (die
->tag
== DW_TAG_member
)
23217 /* dwarf2_add_field uses die_is_declaration,
23218 so we do the same. */
23219 gdb_assert (die_is_declaration (die
, cu
));
23222 if (attr
!= nullptr)
23224 dwarf2_const_value (attr
, sym
, cu
);
23225 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
23228 if (attr2
!= nullptr && attr2
->as_boolean ())
23229 list_to_add
= cu
->get_builder ()->get_global_symbols ();
23231 list_to_add
= cu
->list_in_scope
;
23235 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23236 if (attr
!= nullptr)
23238 var_decode_location (attr
, sym
, cu
);
23239 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
23241 /* Fortran explicitly imports any global symbols to the local
23242 scope by DW_TAG_common_block. */
23243 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
23244 && die
->parent
->tag
== DW_TAG_common_block
)
23247 if (sym
->aclass () == LOC_STATIC
23248 && sym
->value_address () == 0
23249 && !per_objfile
->per_bfd
->has_section_at_zero
)
23251 /* When a static variable is eliminated by the linker,
23252 the corresponding debug information is not stripped
23253 out, but the variable address is set to null;
23254 do not add such variables into symbol table. */
23256 else if (attr2
!= nullptr && attr2
->as_boolean ())
23258 if (sym
->aclass () == LOC_STATIC
23259 && (objfile
->flags
& OBJF_MAINLINE
) == 0
23260 && per_objfile
->per_bfd
->can_copy
)
23262 /* A global static variable might be subject to
23263 copy relocation. We first check for a local
23264 minsym, though, because maybe the symbol was
23265 marked hidden, in which case this would not
23267 bound_minimal_symbol found
23268 = (lookup_minimal_symbol_linkage
23269 (sym
->linkage_name (), objfile
));
23270 if (found
.minsym
!= nullptr)
23271 sym
->maybe_copied
= 1;
23274 /* A variable with DW_AT_external is never static,
23275 but it may be block-scoped. */
23277 = ((cu
->list_in_scope
23278 == cu
->get_builder ()->get_file_symbols ())
23279 ? cu
->get_builder ()->get_global_symbols ()
23280 : cu
->list_in_scope
);
23283 list_to_add
= cu
->list_in_scope
;
23287 /* We do not know the address of this symbol.
23288 If it is an external symbol and we have type information
23289 for it, enter the symbol as a LOC_UNRESOLVED symbol.
23290 The address of the variable will then be determined from
23291 the minimal symbol table whenever the variable is
23293 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
23295 /* Fortran explicitly imports any global symbols to the local
23296 scope by DW_TAG_common_block. */
23297 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
23298 && die
->parent
->tag
== DW_TAG_common_block
)
23300 /* SYMBOL_CLASS doesn't matter here because
23301 read_common_block is going to reset it. */
23303 list_to_add
= cu
->list_in_scope
;
23305 else if (attr2
!= nullptr && attr2
->as_boolean ()
23306 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
23308 /* A variable with DW_AT_external is never static, but it
23309 may be block-scoped. */
23311 = ((cu
->list_in_scope
23312 == cu
->get_builder ()->get_file_symbols ())
23313 ? cu
->get_builder ()->get_global_symbols ()
23314 : cu
->list_in_scope
);
23316 sym
->set_aclass_index (LOC_UNRESOLVED
);
23318 else if (!die_is_declaration (die
, cu
))
23320 /* Use the default LOC_OPTIMIZED_OUT class. */
23321 gdb_assert (sym
->aclass () == LOC_OPTIMIZED_OUT
);
23323 list_to_add
= cu
->list_in_scope
;
23327 case DW_TAG_formal_parameter
:
23329 /* If we are inside a function, mark this as an argument. If
23330 not, we might be looking at an argument to an inlined function
23331 when we do not have enough information to show inlined frames;
23332 pretend it's a local variable in that case so that the user can
23334 struct context_stack
*curr
23335 = cu
->get_builder ()->get_current_context_stack ();
23336 if (curr
!= nullptr && curr
->name
!= nullptr)
23337 sym
->set_is_argument (1);
23338 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23339 if (attr
!= nullptr)
23341 var_decode_location (attr
, sym
, cu
);
23343 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23344 if (attr
!= nullptr)
23346 dwarf2_const_value (attr
, sym
, cu
);
23349 list_to_add
= cu
->list_in_scope
;
23352 case DW_TAG_unspecified_parameters
:
23353 /* From varargs functions; gdb doesn't seem to have any
23354 interest in this information, so just ignore it for now.
23357 case DW_TAG_template_type_param
:
23359 /* Fall through. */
23360 case DW_TAG_class_type
:
23361 case DW_TAG_interface_type
:
23362 case DW_TAG_structure_type
:
23363 case DW_TAG_union_type
:
23364 case DW_TAG_set_type
:
23365 case DW_TAG_enumeration_type
:
23366 case DW_TAG_namelist
:
23367 if (die
->tag
== DW_TAG_namelist
)
23369 sym
->set_aclass_index (LOC_STATIC
);
23370 sym
->set_domain (VAR_DOMAIN
);
23374 sym
->set_aclass_index (LOC_TYPEDEF
);
23375 sym
->set_domain (STRUCT_DOMAIN
);
23378 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
23379 really ever be static objects: otherwise, if you try
23380 to, say, break of a class's method and you're in a file
23381 which doesn't mention that class, it won't work unless
23382 the check for all static symbols in lookup_symbol_aux
23383 saves you. See the OtherFileClass tests in
23384 gdb.c++/namespace.exp. */
23388 buildsym_compunit
*builder
= cu
->get_builder ();
23390 = (cu
->list_in_scope
== builder
->get_file_symbols ()
23391 && cu
->per_cu
->lang
== language_cplus
23392 ? builder
->get_global_symbols ()
23393 : cu
->list_in_scope
);
23395 /* The semantics of C++ state that "struct foo {
23396 ... }" also defines a typedef for "foo". */
23397 if (cu
->per_cu
->lang
== language_cplus
23398 || cu
->per_cu
->lang
== language_ada
23399 || cu
->per_cu
->lang
== language_d
23400 || cu
->per_cu
->lang
== language_rust
)
23402 /* The symbol's name is already allocated along
23403 with this objfile, so we don't need to
23404 duplicate it for the type. */
23405 if (sym
->type ()->name () == 0)
23406 sym
->type ()->set_name (sym
->search_name ());
23411 case DW_TAG_typedef
:
23412 sym
->set_aclass_index (LOC_TYPEDEF
);
23413 sym
->set_domain (VAR_DOMAIN
);
23414 list_to_add
= cu
->list_in_scope
;
23416 case DW_TAG_array_type
:
23417 case DW_TAG_base_type
:
23418 case DW_TAG_subrange_type
:
23419 case DW_TAG_generic_subrange
:
23420 sym
->set_aclass_index (LOC_TYPEDEF
);
23421 sym
->set_domain (VAR_DOMAIN
);
23422 list_to_add
= cu
->list_in_scope
;
23424 case DW_TAG_enumerator
:
23425 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23426 if (attr
!= nullptr)
23428 dwarf2_const_value (attr
, sym
, cu
);
23431 /* NOTE: carlton/2003-11-10: See comment above in the
23432 DW_TAG_class_type, etc. block. */
23435 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
23436 && cu
->per_cu
->lang
== language_cplus
23437 ? cu
->get_builder ()->get_global_symbols ()
23438 : cu
->list_in_scope
);
23441 case DW_TAG_imported_declaration
:
23442 case DW_TAG_namespace
:
23443 sym
->set_aclass_index (LOC_TYPEDEF
);
23444 list_to_add
= cu
->get_builder ()->get_global_symbols ();
23446 case DW_TAG_module
:
23447 sym
->set_aclass_index (LOC_TYPEDEF
);
23448 sym
->set_domain (MODULE_DOMAIN
);
23449 list_to_add
= cu
->get_builder ()->get_global_symbols ();
23451 case DW_TAG_common_block
:
23452 sym
->set_aclass_index (LOC_COMMON_BLOCK
);
23453 sym
->set_domain (COMMON_BLOCK_DOMAIN
);
23454 add_symbol_to_list (sym
, cu
->list_in_scope
);
23457 /* Not a tag we recognize. Hopefully we aren't processing
23458 trash data, but since we must specifically ignore things
23459 we don't recognize, there is nothing else we should do at
23461 complaint (_("unsupported tag: '%s'"),
23462 dwarf_tag_name (die
->tag
));
23468 sym
->hash_next
= objfile
->template_symbols
;
23469 objfile
->template_symbols
= sym
;
23470 list_to_add
= NULL
;
23473 if (list_to_add
!= NULL
)
23474 add_symbol_to_list (sym
, list_to_add
);
23476 /* For the benefit of old versions of GCC, check for anonymous
23477 namespaces based on the demangled name. */
23478 if (!cu
->processing_has_namespace_info
23479 && cu
->per_cu
->lang
== language_cplus
)
23480 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
23485 /* Given an attr with a DW_FORM_dataN value in host byte order,
23486 zero-extend it as appropriate for the symbol's type. The DWARF
23487 standard (v4) is not entirely clear about the meaning of using
23488 DW_FORM_dataN for a constant with a signed type, where the type is
23489 wider than the data. The conclusion of a discussion on the DWARF
23490 list was that this is unspecified. We choose to always zero-extend
23491 because that is the interpretation long in use by GCC. */
23494 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
23495 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
23497 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23498 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
23499 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
23500 LONGEST l
= attr
->constant_value (0);
23502 if (bits
< sizeof (*value
) * 8)
23504 l
&= ((LONGEST
) 1 << bits
) - 1;
23507 else if (bits
== sizeof (*value
) * 8)
23511 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
23512 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
23519 /* Read a constant value from an attribute. Either set *VALUE, or if
23520 the value does not fit in *VALUE, set *BYTES - either already
23521 allocated on the objfile obstack, or newly allocated on OBSTACK,
23522 or, set *BATON, if we translated the constant to a location
23526 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
23527 const char *name
, struct obstack
*obstack
,
23528 struct dwarf2_cu
*cu
,
23529 LONGEST
*value
, const gdb_byte
**bytes
,
23530 struct dwarf2_locexpr_baton
**baton
)
23532 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23533 struct objfile
*objfile
= per_objfile
->objfile
;
23534 struct comp_unit_head
*cu_header
= &cu
->header
;
23535 struct dwarf_block
*blk
;
23536 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
23537 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23543 switch (attr
->form
)
23546 case DW_FORM_addrx
:
23547 case DW_FORM_GNU_addr_index
:
23551 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
23552 dwarf2_const_value_length_mismatch_complaint (name
,
23553 cu_header
->addr_size
,
23554 TYPE_LENGTH (type
));
23555 /* Symbols of this form are reasonably rare, so we just
23556 piggyback on the existing location code rather than writing
23557 a new implementation of symbol_computed_ops. */
23558 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
23559 (*baton
)->per_objfile
= per_objfile
;
23560 (*baton
)->per_cu
= cu
->per_cu
;
23561 gdb_assert ((*baton
)->per_cu
);
23563 (*baton
)->size
= 2 + cu_header
->addr_size
;
23564 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
23565 (*baton
)->data
= data
;
23567 data
[0] = DW_OP_addr
;
23568 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
23569 byte_order
, attr
->as_address ());
23570 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
23573 case DW_FORM_string
:
23576 case DW_FORM_GNU_str_index
:
23577 case DW_FORM_GNU_strp_alt
:
23578 /* The string is already allocated on the objfile obstack, point
23580 *bytes
= (const gdb_byte
*) attr
->as_string ();
23582 case DW_FORM_block1
:
23583 case DW_FORM_block2
:
23584 case DW_FORM_block4
:
23585 case DW_FORM_block
:
23586 case DW_FORM_exprloc
:
23587 case DW_FORM_data16
:
23588 blk
= attr
->as_block ();
23589 if (TYPE_LENGTH (type
) != blk
->size
)
23590 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
23591 TYPE_LENGTH (type
));
23592 *bytes
= blk
->data
;
23595 /* The DW_AT_const_value attributes are supposed to carry the
23596 symbol's value "represented as it would be on the target
23597 architecture." By the time we get here, it's already been
23598 converted to host endianness, so we just need to sign- or
23599 zero-extend it as appropriate. */
23600 case DW_FORM_data1
:
23601 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
23603 case DW_FORM_data2
:
23604 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
23606 case DW_FORM_data4
:
23607 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
23609 case DW_FORM_data8
:
23610 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
23613 case DW_FORM_sdata
:
23614 case DW_FORM_implicit_const
:
23615 *value
= attr
->as_signed ();
23618 case DW_FORM_udata
:
23619 *value
= attr
->as_unsigned ();
23623 complaint (_("unsupported const value attribute form: '%s'"),
23624 dwarf_form_name (attr
->form
));
23631 /* Copy constant value from an attribute to a symbol. */
23634 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
23635 struct dwarf2_cu
*cu
)
23637 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23639 const gdb_byte
*bytes
;
23640 struct dwarf2_locexpr_baton
*baton
;
23642 dwarf2_const_value_attr (attr
, sym
->type (),
23643 sym
->print_name (),
23644 &objfile
->objfile_obstack
, cu
,
23645 &value
, &bytes
, &baton
);
23649 SYMBOL_LOCATION_BATON (sym
) = baton
;
23650 sym
->set_aclass_index (dwarf2_locexpr_index
);
23652 else if (bytes
!= NULL
)
23654 sym
->set_value_bytes (bytes
);
23655 sym
->set_aclass_index (LOC_CONST_BYTES
);
23659 sym
->set_value_longest (value
);
23660 sym
->set_aclass_index (LOC_CONST
);
23664 /* Return the type of the die in question using its DW_AT_type attribute. */
23666 static struct type
*
23667 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23669 struct attribute
*type_attr
;
23671 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
23674 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23675 /* A missing DW_AT_type represents a void type. */
23676 return objfile_type (objfile
)->builtin_void
;
23679 return lookup_die_type (die
, type_attr
, cu
);
23682 /* True iff CU's producer generates GNAT Ada auxiliary information
23683 that allows to find parallel types through that information instead
23684 of having to do expensive parallel lookups by type name. */
23687 need_gnat_info (struct dwarf2_cu
*cu
)
23689 /* Assume that the Ada compiler was GNAT, which always produces
23690 the auxiliary information. */
23691 return (cu
->per_cu
->lang
== language_ada
);
23694 /* Return the auxiliary type of the die in question using its
23695 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
23696 attribute is not present. */
23698 static struct type
*
23699 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23701 struct attribute
*type_attr
;
23703 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
23707 return lookup_die_type (die
, type_attr
, cu
);
23710 /* If DIE has a descriptive_type attribute, then set the TYPE's
23711 descriptive type accordingly. */
23714 set_descriptive_type (struct type
*type
, struct die_info
*die
,
23715 struct dwarf2_cu
*cu
)
23717 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
23719 if (descriptive_type
)
23721 ALLOCATE_GNAT_AUX_TYPE (type
);
23722 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
23726 /* Return the containing type of the die in question using its
23727 DW_AT_containing_type attribute. */
23729 static struct type
*
23730 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23732 struct attribute
*type_attr
;
23733 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23735 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
23737 error (_("Dwarf Error: Problem turning containing type into gdb type "
23738 "[in module %s]"), objfile_name (objfile
));
23740 return lookup_die_type (die
, type_attr
, cu
);
23743 /* Return an error marker type to use for the ill formed type in DIE/CU. */
23745 static struct type
*
23746 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
23748 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23749 struct objfile
*objfile
= per_objfile
->objfile
;
23752 std::string message
23753 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
23754 objfile_name (objfile
),
23755 sect_offset_str (cu
->header
.sect_off
),
23756 sect_offset_str (die
->sect_off
));
23757 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
23759 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
23762 /* Look up the type of DIE in CU using its type attribute ATTR.
23763 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
23764 DW_AT_containing_type.
23765 If there is no type substitute an error marker. */
23767 static struct type
*
23768 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
23769 struct dwarf2_cu
*cu
)
23771 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23772 struct objfile
*objfile
= per_objfile
->objfile
;
23773 struct type
*this_type
;
23775 gdb_assert (attr
->name
== DW_AT_type
23776 || attr
->name
== DW_AT_GNAT_descriptive_type
23777 || attr
->name
== DW_AT_containing_type
);
23779 /* First see if we have it cached. */
23781 if (attr
->form
== DW_FORM_GNU_ref_alt
)
23783 struct dwarf2_per_cu_data
*per_cu
;
23784 sect_offset sect_off
= attr
->get_ref_die_offset ();
23786 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
23787 per_objfile
->per_bfd
);
23788 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
23790 else if (attr
->form_is_ref ())
23792 sect_offset sect_off
= attr
->get_ref_die_offset ();
23794 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
23796 else if (attr
->form
== DW_FORM_ref_sig8
)
23798 ULONGEST signature
= attr
->as_signature ();
23800 return get_signatured_type (die
, signature
, cu
);
23804 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
23805 " at %s [in module %s]"),
23806 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
23807 objfile_name (objfile
));
23808 return build_error_marker_type (cu
, die
);
23811 /* If not cached we need to read it in. */
23813 if (this_type
== NULL
)
23815 struct die_info
*type_die
= NULL
;
23816 struct dwarf2_cu
*type_cu
= cu
;
23818 if (attr
->form_is_ref ())
23819 type_die
= follow_die_ref (die
, attr
, &type_cu
);
23820 if (type_die
== NULL
)
23821 return build_error_marker_type (cu
, die
);
23822 /* If we find the type now, it's probably because the type came
23823 from an inter-CU reference and the type's CU got expanded before
23825 this_type
= read_type_die (type_die
, type_cu
);
23828 /* If we still don't have a type use an error marker. */
23830 if (this_type
== NULL
)
23831 return build_error_marker_type (cu
, die
);
23836 /* Return the type in DIE, CU.
23837 Returns NULL for invalid types.
23839 This first does a lookup in die_type_hash,
23840 and only reads the die in if necessary.
23842 NOTE: This can be called when reading in partial or full symbols. */
23844 static struct type
*
23845 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
23847 struct type
*this_type
;
23849 this_type
= get_die_type (die
, cu
);
23853 return read_type_die_1 (die
, cu
);
23856 /* Read the type in DIE, CU.
23857 Returns NULL for invalid types. */
23859 static struct type
*
23860 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
23862 struct type
*this_type
= NULL
;
23866 case DW_TAG_class_type
:
23867 case DW_TAG_interface_type
:
23868 case DW_TAG_structure_type
:
23869 case DW_TAG_union_type
:
23870 this_type
= read_structure_type (die
, cu
);
23872 case DW_TAG_enumeration_type
:
23873 this_type
= read_enumeration_type (die
, cu
);
23875 case DW_TAG_subprogram
:
23876 case DW_TAG_subroutine_type
:
23877 case DW_TAG_inlined_subroutine
:
23878 this_type
= read_subroutine_type (die
, cu
);
23880 case DW_TAG_array_type
:
23881 this_type
= read_array_type (die
, cu
);
23883 case DW_TAG_set_type
:
23884 this_type
= read_set_type (die
, cu
);
23886 case DW_TAG_pointer_type
:
23887 this_type
= read_tag_pointer_type (die
, cu
);
23889 case DW_TAG_ptr_to_member_type
:
23890 this_type
= read_tag_ptr_to_member_type (die
, cu
);
23892 case DW_TAG_reference_type
:
23893 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
23895 case DW_TAG_rvalue_reference_type
:
23896 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
23898 case DW_TAG_const_type
:
23899 this_type
= read_tag_const_type (die
, cu
);
23901 case DW_TAG_volatile_type
:
23902 this_type
= read_tag_volatile_type (die
, cu
);
23904 case DW_TAG_restrict_type
:
23905 this_type
= read_tag_restrict_type (die
, cu
);
23907 case DW_TAG_string_type
:
23908 this_type
= read_tag_string_type (die
, cu
);
23910 case DW_TAG_typedef
:
23911 this_type
= read_typedef (die
, cu
);
23913 case DW_TAG_generic_subrange
:
23914 case DW_TAG_subrange_type
:
23915 this_type
= read_subrange_type (die
, cu
);
23917 case DW_TAG_base_type
:
23918 this_type
= read_base_type (die
, cu
);
23920 case DW_TAG_unspecified_type
:
23921 this_type
= read_unspecified_type (die
, cu
);
23923 case DW_TAG_namespace
:
23924 this_type
= read_namespace_type (die
, cu
);
23926 case DW_TAG_module
:
23927 this_type
= read_module_type (die
, cu
);
23929 case DW_TAG_atomic_type
:
23930 this_type
= read_tag_atomic_type (die
, cu
);
23933 complaint (_("unexpected tag in read_type_die: '%s'"),
23934 dwarf_tag_name (die
->tag
));
23941 /* See if we can figure out if the class lives in a namespace. We do
23942 this by looking for a member function; its demangled name will
23943 contain namespace info, if there is any.
23944 Return the computed name or NULL.
23945 Space for the result is allocated on the objfile's obstack.
23946 This is the full-die version of guess_partial_die_structure_name.
23947 In this case we know DIE has no useful parent. */
23949 static const char *
23950 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23952 struct die_info
*spec_die
;
23953 struct dwarf2_cu
*spec_cu
;
23954 struct die_info
*child
;
23955 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23958 spec_die
= die_specification (die
, &spec_cu
);
23959 if (spec_die
!= NULL
)
23965 for (child
= die
->child
;
23967 child
= child
->sibling
)
23969 if (child
->tag
== DW_TAG_subprogram
)
23971 const char *linkage_name
= dw2_linkage_name (child
, cu
);
23973 if (linkage_name
!= NULL
)
23975 gdb::unique_xmalloc_ptr
<char> actual_name
23976 (cu
->language_defn
->class_name_from_physname (linkage_name
));
23977 const char *name
= NULL
;
23979 if (actual_name
!= NULL
)
23981 const char *die_name
= dwarf2_name (die
, cu
);
23983 if (die_name
!= NULL
23984 && strcmp (die_name
, actual_name
.get ()) != 0)
23986 /* Strip off the class name from the full name.
23987 We want the prefix. */
23988 int die_name_len
= strlen (die_name
);
23989 int actual_name_len
= strlen (actual_name
.get ());
23990 const char *ptr
= actual_name
.get ();
23992 /* Test for '::' as a sanity check. */
23993 if (actual_name_len
> die_name_len
+ 2
23994 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
23995 name
= obstack_strndup (
23996 &objfile
->per_bfd
->storage_obstack
,
23997 ptr
, actual_name_len
- die_name_len
- 2);
24008 /* GCC might emit a nameless typedef that has a linkage name. Determine the
24009 prefix part in such case. See
24010 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
24012 static const char *
24013 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
24015 struct attribute
*attr
;
24018 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
24019 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
24022 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
24025 attr
= dw2_linkage_name_attr (die
, cu
);
24026 const char *attr_name
= attr
->as_string ();
24027 if (attr
== NULL
|| attr_name
== NULL
)
24030 /* dwarf2_name had to be already called. */
24031 gdb_assert (attr
->canonical_string_p ());
24033 /* Strip the base name, keep any leading namespaces/classes. */
24034 base
= strrchr (attr_name
, ':');
24035 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
24038 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24039 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
24041 &base
[-1] - attr_name
);
24044 /* Return the name of the namespace/class that DIE is defined within,
24045 or "" if we can't tell. The caller should not xfree the result.
24047 For example, if we're within the method foo() in the following
24057 then determine_prefix on foo's die will return "N::C". */
24059 static const char *
24060 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
24062 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24063 struct die_info
*parent
, *spec_die
;
24064 struct dwarf2_cu
*spec_cu
;
24065 struct type
*parent_type
;
24066 const char *retval
;
24068 if (cu
->per_cu
->lang
!= language_cplus
24069 && cu
->per_cu
->lang
!= language_fortran
24070 && cu
->per_cu
->lang
!= language_d
24071 && cu
->per_cu
->lang
!= language_rust
)
24074 retval
= anonymous_struct_prefix (die
, cu
);
24078 /* We have to be careful in the presence of DW_AT_specification.
24079 For example, with GCC 3.4, given the code
24083 // Definition of N::foo.
24087 then we'll have a tree of DIEs like this:
24089 1: DW_TAG_compile_unit
24090 2: DW_TAG_namespace // N
24091 3: DW_TAG_subprogram // declaration of N::foo
24092 4: DW_TAG_subprogram // definition of N::foo
24093 DW_AT_specification // refers to die #3
24095 Thus, when processing die #4, we have to pretend that we're in
24096 the context of its DW_AT_specification, namely the contex of die
24099 spec_die
= die_specification (die
, &spec_cu
);
24100 if (spec_die
== NULL
)
24101 parent
= die
->parent
;
24104 parent
= spec_die
->parent
;
24108 if (parent
== NULL
)
24110 else if (parent
->building_fullname
)
24113 const char *parent_name
;
24115 /* It has been seen on RealView 2.2 built binaries,
24116 DW_TAG_template_type_param types actually _defined_ as
24117 children of the parent class:
24120 template class <class Enum> Class{};
24121 Class<enum E> class_e;
24123 1: DW_TAG_class_type (Class)
24124 2: DW_TAG_enumeration_type (E)
24125 3: DW_TAG_enumerator (enum1:0)
24126 3: DW_TAG_enumerator (enum2:1)
24128 2: DW_TAG_template_type_param
24129 DW_AT_type DW_FORM_ref_udata (E)
24131 Besides being broken debug info, it can put GDB into an
24132 infinite loop. Consider:
24134 When we're building the full name for Class<E>, we'll start
24135 at Class, and go look over its template type parameters,
24136 finding E. We'll then try to build the full name of E, and
24137 reach here. We're now trying to build the full name of E,
24138 and look over the parent DIE for containing scope. In the
24139 broken case, if we followed the parent DIE of E, we'd again
24140 find Class, and once again go look at its template type
24141 arguments, etc., etc. Simply don't consider such parent die
24142 as source-level parent of this die (it can't be, the language
24143 doesn't allow it), and break the loop here. */
24144 name
= dwarf2_name (die
, cu
);
24145 parent_name
= dwarf2_name (parent
, cu
);
24146 complaint (_("template param type '%s' defined within parent '%s'"),
24147 name
? name
: "<unknown>",
24148 parent_name
? parent_name
: "<unknown>");
24152 switch (parent
->tag
)
24154 case DW_TAG_namespace
:
24155 parent_type
= read_type_die (parent
, cu
);
24156 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
24157 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
24158 Work around this problem here. */
24159 if (cu
->per_cu
->lang
== language_cplus
24160 && strcmp (parent_type
->name (), "::") == 0)
24162 /* We give a name to even anonymous namespaces. */
24163 return parent_type
->name ();
24164 case DW_TAG_class_type
:
24165 case DW_TAG_interface_type
:
24166 case DW_TAG_structure_type
:
24167 case DW_TAG_union_type
:
24168 case DW_TAG_module
:
24169 parent_type
= read_type_die (parent
, cu
);
24170 if (parent_type
->name () != NULL
)
24171 return parent_type
->name ();
24173 /* An anonymous structure is only allowed non-static data
24174 members; no typedefs, no member functions, et cetera.
24175 So it does not need a prefix. */
24177 case DW_TAG_compile_unit
:
24178 case DW_TAG_partial_unit
:
24179 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
24180 if (cu
->per_cu
->lang
== language_cplus
24181 && !per_objfile
->per_bfd
->types
.empty ()
24182 && die
->child
!= NULL
24183 && (die
->tag
== DW_TAG_class_type
24184 || die
->tag
== DW_TAG_structure_type
24185 || die
->tag
== DW_TAG_union_type
))
24187 const char *name
= guess_full_die_structure_name (die
, cu
);
24192 case DW_TAG_subprogram
:
24193 /* Nested subroutines in Fortran get a prefix with the name
24194 of the parent's subroutine. */
24195 if (cu
->per_cu
->lang
== language_fortran
)
24197 if ((die
->tag
== DW_TAG_subprogram
)
24198 && (dwarf2_name (parent
, cu
) != NULL
))
24199 return dwarf2_name (parent
, cu
);
24202 case DW_TAG_enumeration_type
:
24203 parent_type
= read_type_die (parent
, cu
);
24204 if (parent_type
->is_declared_class ())
24206 if (parent_type
->name () != NULL
)
24207 return parent_type
->name ();
24210 /* Fall through. */
24212 return determine_prefix (parent
, cu
);
24216 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
24217 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
24218 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
24219 an obconcat, otherwise allocate storage for the result. The CU argument is
24220 used to determine the language and hence, the appropriate separator. */
24222 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
24225 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
24226 int physname
, struct dwarf2_cu
*cu
)
24228 const char *lead
= "";
24231 if (suffix
== NULL
|| suffix
[0] == '\0'
24232 || prefix
== NULL
|| prefix
[0] == '\0')
24234 else if (cu
->per_cu
->lang
== language_d
)
24236 /* For D, the 'main' function could be defined in any module, but it
24237 should never be prefixed. */
24238 if (strcmp (suffix
, "D main") == 0)
24246 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
24248 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
24249 DW_AT_MIPS_linkage_name is preferred and used instead. */
24257 if (prefix
== NULL
)
24259 if (suffix
== NULL
)
24266 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
24268 strcpy (retval
, lead
);
24269 strcat (retval
, prefix
);
24270 strcat (retval
, sep
);
24271 strcat (retval
, suffix
);
24276 /* We have an obstack. */
24277 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
24281 /* Get name of a die, return NULL if not found. */
24283 static const char *
24284 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
24285 struct objfile
*objfile
)
24287 if (name
&& cu
->per_cu
->lang
== language_cplus
)
24289 gdb::unique_xmalloc_ptr
<char> canon_name
24290 = cp_canonicalize_string (name
);
24292 if (canon_name
!= nullptr)
24293 name
= objfile
->intern (canon_name
.get ());
24299 /* Get name of a die, return NULL if not found.
24300 Anonymous namespaces are converted to their magic string. */
24302 static const char *
24303 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
24305 struct attribute
*attr
;
24306 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24308 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
24309 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
24310 if (attr_name
== nullptr
24311 && die
->tag
!= DW_TAG_namespace
24312 && die
->tag
!= DW_TAG_class_type
24313 && die
->tag
!= DW_TAG_interface_type
24314 && die
->tag
!= DW_TAG_structure_type
24315 && die
->tag
!= DW_TAG_namelist
24316 && die
->tag
!= DW_TAG_union_type
)
24321 case DW_TAG_compile_unit
:
24322 case DW_TAG_partial_unit
:
24323 /* Compilation units have a DW_AT_name that is a filename, not
24324 a source language identifier. */
24325 case DW_TAG_enumeration_type
:
24326 case DW_TAG_enumerator
:
24327 /* These tags always have simple identifiers already; no need
24328 to canonicalize them. */
24331 case DW_TAG_namespace
:
24332 if (attr_name
!= nullptr)
24334 return CP_ANONYMOUS_NAMESPACE_STR
;
24336 case DW_TAG_class_type
:
24337 case DW_TAG_interface_type
:
24338 case DW_TAG_structure_type
:
24339 case DW_TAG_union_type
:
24340 case DW_TAG_namelist
:
24341 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
24342 structures or unions. These were of the form "._%d" in GCC 4.1,
24343 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
24344 and GCC 4.4. We work around this problem by ignoring these. */
24345 if (attr_name
!= nullptr
24346 && (startswith (attr_name
, "._")
24347 || startswith (attr_name
, "<anonymous")))
24350 /* GCC might emit a nameless typedef that has a linkage name. See
24351 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
24352 if (!attr
|| attr_name
== NULL
)
24354 attr
= dw2_linkage_name_attr (die
, cu
);
24355 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
24356 if (attr
== NULL
|| attr_name
== NULL
)
24359 /* Avoid demangling attr_name the second time on a second
24360 call for the same DIE. */
24361 if (!attr
->canonical_string_p ())
24363 gdb::unique_xmalloc_ptr
<char> demangled
24364 (gdb_demangle (attr_name
, DMGL_TYPES
));
24365 if (demangled
== nullptr)
24368 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
24369 attr_name
= attr
->as_string ();
24372 /* Strip any leading namespaces/classes, keep only the
24373 base name. DW_AT_name for named DIEs does not
24374 contain the prefixes. */
24375 const char *base
= strrchr (attr_name
, ':');
24376 if (base
&& base
> attr_name
&& base
[-1] == ':')
24387 if (!attr
->canonical_string_p ())
24388 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
24390 return attr
->as_string ();
24393 /* Return the die that this die in an extension of, or NULL if there
24394 is none. *EXT_CU is the CU containing DIE on input, and the CU
24395 containing the return value on output. */
24397 static struct die_info
*
24398 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
24400 struct attribute
*attr
;
24402 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
24406 return follow_die_ref (die
, attr
, ext_cu
);
24410 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
24414 gdb_printf (f
, "%*sDie: %s (abbrev %d, offset %s)\n",
24416 dwarf_tag_name (die
->tag
), die
->abbrev
,
24417 sect_offset_str (die
->sect_off
));
24419 if (die
->parent
!= NULL
)
24420 gdb_printf (f
, "%*s parent at offset: %s\n",
24422 sect_offset_str (die
->parent
->sect_off
));
24424 gdb_printf (f
, "%*s has children: %s\n",
24426 dwarf_bool_name (die
->child
!= NULL
));
24428 gdb_printf (f
, "%*s attributes:\n", indent
, "");
24430 for (i
= 0; i
< die
->num_attrs
; ++i
)
24432 gdb_printf (f
, "%*s %s (%s) ",
24434 dwarf_attr_name (die
->attrs
[i
].name
),
24435 dwarf_form_name (die
->attrs
[i
].form
));
24437 switch (die
->attrs
[i
].form
)
24440 case DW_FORM_addrx
:
24441 case DW_FORM_GNU_addr_index
:
24442 gdb_printf (f
, "address: ");
24443 gdb_puts (hex_string (die
->attrs
[i
].as_address ()), f
);
24445 case DW_FORM_block2
:
24446 case DW_FORM_block4
:
24447 case DW_FORM_block
:
24448 case DW_FORM_block1
:
24449 gdb_printf (f
, "block: size %s",
24450 pulongest (die
->attrs
[i
].as_block ()->size
));
24452 case DW_FORM_exprloc
:
24453 gdb_printf (f
, "expression: size %s",
24454 pulongest (die
->attrs
[i
].as_block ()->size
));
24456 case DW_FORM_data16
:
24457 gdb_printf (f
, "constant of 16 bytes");
24459 case DW_FORM_ref_addr
:
24460 gdb_printf (f
, "ref address: ");
24461 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
24463 case DW_FORM_GNU_ref_alt
:
24464 gdb_printf (f
, "alt ref address: ");
24465 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
24471 case DW_FORM_ref_udata
:
24472 gdb_printf (f
, "constant ref: 0x%lx (adjusted)",
24473 (long) (die
->attrs
[i
].as_unsigned ()));
24475 case DW_FORM_data1
:
24476 case DW_FORM_data2
:
24477 case DW_FORM_data4
:
24478 case DW_FORM_data8
:
24479 case DW_FORM_udata
:
24480 gdb_printf (f
, "constant: %s",
24481 pulongest (die
->attrs
[i
].as_unsigned ()));
24483 case DW_FORM_sec_offset
:
24484 gdb_printf (f
, "section offset: %s",
24485 pulongest (die
->attrs
[i
].as_unsigned ()));
24487 case DW_FORM_ref_sig8
:
24488 gdb_printf (f
, "signature: %s",
24489 hex_string (die
->attrs
[i
].as_signature ()));
24491 case DW_FORM_string
:
24493 case DW_FORM_line_strp
:
24495 case DW_FORM_GNU_str_index
:
24496 case DW_FORM_GNU_strp_alt
:
24497 gdb_printf (f
, "string: \"%s\" (%s canonicalized)",
24498 die
->attrs
[i
].as_string ()
24499 ? die
->attrs
[i
].as_string () : "",
24500 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
24503 if (die
->attrs
[i
].as_boolean ())
24504 gdb_printf (f
, "flag: TRUE");
24506 gdb_printf (f
, "flag: FALSE");
24508 case DW_FORM_flag_present
:
24509 gdb_printf (f
, "flag: TRUE");
24511 case DW_FORM_indirect
:
24512 /* The reader will have reduced the indirect form to
24513 the "base form" so this form should not occur. */
24515 "unexpected attribute form: DW_FORM_indirect");
24517 case DW_FORM_sdata
:
24518 case DW_FORM_implicit_const
:
24519 gdb_printf (f
, "constant: %s",
24520 plongest (die
->attrs
[i
].as_signed ()));
24523 gdb_printf (f
, "unsupported attribute form: %d.",
24524 die
->attrs
[i
].form
);
24527 gdb_printf (f
, "\n");
24532 dump_die_for_error (struct die_info
*die
)
24534 dump_die_shallow (gdb_stderr
, 0, die
);
24538 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
24540 int indent
= level
* 4;
24542 gdb_assert (die
!= NULL
);
24544 if (level
>= max_level
)
24547 dump_die_shallow (f
, indent
, die
);
24549 if (die
->child
!= NULL
)
24551 gdb_printf (f
, "%*s Children:", indent
, "");
24552 if (level
+ 1 < max_level
)
24554 gdb_printf (f
, "\n");
24555 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
24560 " [not printed, max nesting level reached]\n");
24564 if (die
->sibling
!= NULL
&& level
> 0)
24566 dump_die_1 (f
, level
, max_level
, die
->sibling
);
24570 /* This is called from the pdie macro in gdbinit.in.
24571 It's not static so gcc will keep a copy callable from gdb. */
24574 dump_die (struct die_info
*die
, int max_level
)
24576 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
24580 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
24584 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
24585 to_underlying (die
->sect_off
),
24591 /* Follow reference or signature attribute ATTR of SRC_DIE.
24592 On entry *REF_CU is the CU of SRC_DIE.
24593 On exit *REF_CU is the CU of the result. */
24595 static struct die_info
*
24596 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
24597 struct dwarf2_cu
**ref_cu
)
24599 struct die_info
*die
;
24601 if (attr
->form_is_ref ())
24602 die
= follow_die_ref (src_die
, attr
, ref_cu
);
24603 else if (attr
->form
== DW_FORM_ref_sig8
)
24604 die
= follow_die_sig (src_die
, attr
, ref_cu
);
24607 dump_die_for_error (src_die
);
24608 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
24609 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24615 /* Follow reference OFFSET.
24616 On entry *REF_CU is the CU of the source die referencing OFFSET.
24617 On exit *REF_CU is the CU of the result.
24618 Returns NULL if OFFSET is invalid. */
24620 static struct die_info
*
24621 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
24622 struct dwarf2_cu
**ref_cu
)
24624 struct die_info temp_die
;
24625 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
24626 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24628 gdb_assert (cu
->per_cu
!= NULL
);
24632 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
24633 "source CU contains target offset: %d",
24634 sect_offset_str (cu
->per_cu
->sect_off
),
24635 sect_offset_str (sect_off
),
24636 cu
->header
.offset_in_cu_p (sect_off
));
24638 if (cu
->per_cu
->is_debug_types
)
24640 /* .debug_types CUs cannot reference anything outside their CU.
24641 If they need to, they have to reference a signatured type via
24642 DW_FORM_ref_sig8. */
24643 if (!cu
->header
.offset_in_cu_p (sect_off
))
24646 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
24647 || !cu
->header
.offset_in_cu_p (sect_off
))
24649 struct dwarf2_per_cu_data
*per_cu
;
24651 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
24652 per_objfile
->per_bfd
);
24654 dwarf_read_debug_printf_v ("target CU offset: %s, "
24655 "target CU DIEs loaded: %d",
24656 sect_offset_str (per_cu
->sect_off
),
24657 per_objfile
->get_cu (per_cu
) != nullptr);
24659 /* If necessary, add it to the queue and load its DIEs.
24661 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
24662 it doesn't mean they are currently loaded. Since we require them
24663 to be loaded, we must check for ourselves. */
24664 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
24665 || per_objfile
->get_cu (per_cu
) == nullptr)
24666 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
24667 false, cu
->per_cu
->lang
);
24669 target_cu
= per_objfile
->get_cu (per_cu
);
24670 gdb_assert (target_cu
!= nullptr);
24672 else if (cu
->dies
== NULL
)
24674 /* We're loading full DIEs during partial symbol reading. */
24675 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
24676 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
24680 *ref_cu
= target_cu
;
24681 temp_die
.sect_off
= sect_off
;
24683 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
24685 to_underlying (sect_off
));
24688 /* Follow reference attribute ATTR of SRC_DIE.
24689 On entry *REF_CU is the CU of SRC_DIE.
24690 On exit *REF_CU is the CU of the result. */
24692 static struct die_info
*
24693 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
24694 struct dwarf2_cu
**ref_cu
)
24696 sect_offset sect_off
= attr
->get_ref_die_offset ();
24697 struct dwarf2_cu
*cu
= *ref_cu
;
24698 struct die_info
*die
;
24700 die
= follow_die_offset (sect_off
,
24701 (attr
->form
== DW_FORM_GNU_ref_alt
24702 || cu
->per_cu
->is_dwz
),
24705 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
24706 "at %s [in module %s]"),
24707 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
24708 objfile_name (cu
->per_objfile
->objfile
));
24715 struct dwarf2_locexpr_baton
24716 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
24717 dwarf2_per_cu_data
*per_cu
,
24718 dwarf2_per_objfile
*per_objfile
,
24719 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
24720 bool resolve_abstract_p
)
24722 struct die_info
*die
;
24723 struct attribute
*attr
;
24724 struct dwarf2_locexpr_baton retval
;
24725 struct objfile
*objfile
= per_objfile
->objfile
;
24727 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24729 cu
= load_cu (per_cu
, per_objfile
, false);
24733 /* We shouldn't get here for a dummy CU, but don't crash on the user.
24734 Instead just throw an error, not much else we can do. */
24735 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
24736 sect_offset_str (sect_off
), objfile_name (objfile
));
24739 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
24741 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
24742 sect_offset_str (sect_off
), objfile_name (objfile
));
24744 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
24745 if (!attr
&& resolve_abstract_p
24746 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
24747 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
24749 CORE_ADDR pc
= get_frame_pc ();
24750 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
24751 struct gdbarch
*gdbarch
= objfile
->arch ();
24753 for (const auto &cand_off
24754 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
24756 struct dwarf2_cu
*cand_cu
= cu
;
24757 struct die_info
*cand
24758 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
24761 || cand
->parent
->tag
!= DW_TAG_subprogram
)
24764 CORE_ADDR pc_low
, pc_high
;
24765 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
24766 if (pc_low
== ((CORE_ADDR
) -1))
24768 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
24769 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
24770 if (!(pc_low
<= pc
&& pc
< pc_high
))
24774 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
24781 /* DWARF: "If there is no such attribute, then there is no effect.".
24782 DATA is ignored if SIZE is 0. */
24784 retval
.data
= NULL
;
24787 else if (attr
->form_is_section_offset ())
24789 struct dwarf2_loclist_baton loclist_baton
;
24790 CORE_ADDR pc
= get_frame_pc ();
24793 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
24795 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
24797 retval
.size
= size
;
24801 if (!attr
->form_is_block ())
24802 error (_("Dwarf Error: DIE at %s referenced in module %s "
24803 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
24804 sect_offset_str (sect_off
), objfile_name (objfile
));
24806 struct dwarf_block
*block
= attr
->as_block ();
24807 retval
.data
= block
->data
;
24808 retval
.size
= block
->size
;
24810 retval
.per_objfile
= per_objfile
;
24811 retval
.per_cu
= cu
->per_cu
;
24813 per_objfile
->age_comp_units ();
24820 struct dwarf2_locexpr_baton
24821 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
24822 dwarf2_per_cu_data
*per_cu
,
24823 dwarf2_per_objfile
*per_objfile
,
24824 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
24826 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
24828 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
24832 /* Write a constant of a given type as target-ordered bytes into
24835 static const gdb_byte
*
24836 write_constant_as_bytes (struct obstack
*obstack
,
24837 enum bfd_endian byte_order
,
24844 *len
= TYPE_LENGTH (type
);
24845 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
24846 store_unsigned_integer (result
, *len
, byte_order
, value
);
24854 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
24855 dwarf2_per_cu_data
*per_cu
,
24856 dwarf2_per_objfile
*per_objfile
,
24860 struct die_info
*die
;
24861 struct attribute
*attr
;
24862 const gdb_byte
*result
= NULL
;
24865 enum bfd_endian byte_order
;
24866 struct objfile
*objfile
= per_objfile
->objfile
;
24868 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24870 cu
= load_cu (per_cu
, per_objfile
, false);
24874 /* We shouldn't get here for a dummy CU, but don't crash on the user.
24875 Instead just throw an error, not much else we can do. */
24876 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
24877 sect_offset_str (sect_off
), objfile_name (objfile
));
24880 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
24882 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
24883 sect_offset_str (sect_off
), objfile_name (objfile
));
24885 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
24889 byte_order
= (bfd_big_endian (objfile
->obfd
)
24890 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
24892 switch (attr
->form
)
24895 case DW_FORM_addrx
:
24896 case DW_FORM_GNU_addr_index
:
24900 *len
= cu
->header
.addr_size
;
24901 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
24902 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
24906 case DW_FORM_string
:
24909 case DW_FORM_GNU_str_index
:
24910 case DW_FORM_GNU_strp_alt
:
24911 /* The string is already allocated on the objfile obstack, point
24914 const char *attr_name
= attr
->as_string ();
24915 result
= (const gdb_byte
*) attr_name
;
24916 *len
= strlen (attr_name
);
24919 case DW_FORM_block1
:
24920 case DW_FORM_block2
:
24921 case DW_FORM_block4
:
24922 case DW_FORM_block
:
24923 case DW_FORM_exprloc
:
24924 case DW_FORM_data16
:
24926 struct dwarf_block
*block
= attr
->as_block ();
24927 result
= block
->data
;
24928 *len
= block
->size
;
24932 /* The DW_AT_const_value attributes are supposed to carry the
24933 symbol's value "represented as it would be on the target
24934 architecture." By the time we get here, it's already been
24935 converted to host endianness, so we just need to sign- or
24936 zero-extend it as appropriate. */
24937 case DW_FORM_data1
:
24938 type
= die_type (die
, cu
);
24939 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
24940 if (result
== NULL
)
24941 result
= write_constant_as_bytes (obstack
, byte_order
,
24944 case DW_FORM_data2
:
24945 type
= die_type (die
, cu
);
24946 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
24947 if (result
== NULL
)
24948 result
= write_constant_as_bytes (obstack
, byte_order
,
24951 case DW_FORM_data4
:
24952 type
= die_type (die
, cu
);
24953 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
24954 if (result
== NULL
)
24955 result
= write_constant_as_bytes (obstack
, byte_order
,
24958 case DW_FORM_data8
:
24959 type
= die_type (die
, cu
);
24960 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
24961 if (result
== NULL
)
24962 result
= write_constant_as_bytes (obstack
, byte_order
,
24966 case DW_FORM_sdata
:
24967 case DW_FORM_implicit_const
:
24968 type
= die_type (die
, cu
);
24969 result
= write_constant_as_bytes (obstack
, byte_order
,
24970 type
, attr
->as_signed (), len
);
24973 case DW_FORM_udata
:
24974 type
= die_type (die
, cu
);
24975 result
= write_constant_as_bytes (obstack
, byte_order
,
24976 type
, attr
->as_unsigned (), len
);
24980 complaint (_("unsupported const value attribute form: '%s'"),
24981 dwarf_form_name (attr
->form
));
24991 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
24992 dwarf2_per_cu_data
*per_cu
,
24993 dwarf2_per_objfile
*per_objfile
,
24994 const char **var_name
)
24996 struct die_info
*die
;
24998 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25000 cu
= load_cu (per_cu
, per_objfile
, false);
25005 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
25009 if (var_name
!= nullptr)
25010 *var_name
= var_decl_name (die
, cu
);
25011 return die_type (die
, cu
);
25017 dwarf2_get_die_type (cu_offset die_offset
,
25018 dwarf2_per_cu_data
*per_cu
,
25019 dwarf2_per_objfile
*per_objfile
)
25021 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
25022 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
25025 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
25026 On entry *REF_CU is the CU of SRC_DIE.
25027 On exit *REF_CU is the CU of the result.
25028 Returns NULL if the referenced DIE isn't found. */
25030 static struct die_info
*
25031 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
25032 struct dwarf2_cu
**ref_cu
)
25034 struct die_info temp_die
;
25035 struct dwarf2_cu
*sig_cu
;
25036 struct die_info
*die
;
25037 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
25040 /* While it might be nice to assert sig_type->type == NULL here,
25041 we can get here for DW_AT_imported_declaration where we need
25042 the DIE not the type. */
25044 /* If necessary, add it to the queue and load its DIEs.
25046 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
25047 it doesn't mean they are currently loaded. Since we require them
25048 to be loaded, we must check for ourselves. */
25049 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
25051 || per_objfile
->get_cu (sig_type
) == nullptr)
25052 read_signatured_type (sig_type
, per_objfile
);
25054 sig_cu
= per_objfile
->get_cu (sig_type
);
25055 gdb_assert (sig_cu
!= NULL
);
25056 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
25057 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
25058 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
25059 to_underlying (temp_die
.sect_off
));
25062 /* For .gdb_index version 7 keep track of included TUs.
25063 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
25064 if (per_objfile
->per_bfd
->index_table
!= NULL
25065 && per_objfile
->per_bfd
->index_table
->version
<= 7)
25067 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
25077 /* Follow signatured type referenced by ATTR in SRC_DIE.
25078 On entry *REF_CU is the CU of SRC_DIE.
25079 On exit *REF_CU is the CU of the result.
25080 The result is the DIE of the type.
25081 If the referenced type cannot be found an error is thrown. */
25083 static struct die_info
*
25084 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
25085 struct dwarf2_cu
**ref_cu
)
25087 ULONGEST signature
= attr
->as_signature ();
25088 struct signatured_type
*sig_type
;
25089 struct die_info
*die
;
25091 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
25093 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
25094 /* sig_type will be NULL if the signatured type is missing from
25096 if (sig_type
== NULL
)
25098 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
25099 " from DIE at %s [in module %s]"),
25100 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
25101 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
25104 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
25107 dump_die_for_error (src_die
);
25108 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
25109 " from DIE at %s [in module %s]"),
25110 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
25111 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
25117 /* Get the type specified by SIGNATURE referenced in DIE/CU,
25118 reading in and processing the type unit if necessary. */
25120 static struct type
*
25121 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
25122 struct dwarf2_cu
*cu
)
25124 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25125 struct signatured_type
*sig_type
;
25126 struct dwarf2_cu
*type_cu
;
25127 struct die_info
*type_die
;
25130 sig_type
= lookup_signatured_type (cu
, signature
);
25131 /* sig_type will be NULL if the signatured type is missing from
25133 if (sig_type
== NULL
)
25135 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
25136 " from DIE at %s [in module %s]"),
25137 hex_string (signature
), sect_offset_str (die
->sect_off
),
25138 objfile_name (per_objfile
->objfile
));
25139 return build_error_marker_type (cu
, die
);
25142 /* If we already know the type we're done. */
25143 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
25144 if (type
!= nullptr)
25148 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
25149 if (type_die
!= NULL
)
25151 /* N.B. We need to call get_die_type to ensure only one type for this DIE
25152 is created. This is important, for example, because for c++ classes
25153 we need TYPE_NAME set which is only done by new_symbol. Blech. */
25154 type
= read_type_die (type_die
, type_cu
);
25157 complaint (_("Dwarf Error: Cannot build signatured type %s"
25158 " referenced from DIE at %s [in module %s]"),
25159 hex_string (signature
), sect_offset_str (die
->sect_off
),
25160 objfile_name (per_objfile
->objfile
));
25161 type
= build_error_marker_type (cu
, die
);
25166 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
25167 " from DIE at %s [in module %s]"),
25168 hex_string (signature
), sect_offset_str (die
->sect_off
),
25169 objfile_name (per_objfile
->objfile
));
25170 type
= build_error_marker_type (cu
, die
);
25173 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
25178 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
25179 reading in and processing the type unit if necessary. */
25181 static struct type
*
25182 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
25183 struct dwarf2_cu
*cu
) /* ARI: editCase function */
25185 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
25186 if (attr
->form_is_ref ())
25188 struct dwarf2_cu
*type_cu
= cu
;
25189 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
25191 return read_type_die (type_die
, type_cu
);
25193 else if (attr
->form
== DW_FORM_ref_sig8
)
25195 return get_signatured_type (die
, attr
->as_signature (), cu
);
25199 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25201 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
25202 " at %s [in module %s]"),
25203 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
25204 objfile_name (per_objfile
->objfile
));
25205 return build_error_marker_type (cu
, die
);
25209 /* Load the DIEs associated with type unit PER_CU into memory. */
25212 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
25213 dwarf2_per_objfile
*per_objfile
)
25215 struct signatured_type
*sig_type
;
25217 /* Caller is responsible for ensuring type_unit_groups don't get here. */
25218 gdb_assert (! per_cu
->type_unit_group_p ());
25220 /* We have the per_cu, but we need the signatured_type.
25221 Fortunately this is an easy translation. */
25222 gdb_assert (per_cu
->is_debug_types
);
25223 sig_type
= (struct signatured_type
*) per_cu
;
25225 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
25227 read_signatured_type (sig_type
, per_objfile
);
25229 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
25232 /* Read in a signatured type and build its CU and DIEs.
25233 If the type is a stub for the real type in a DWO file,
25234 read in the real type from the DWO file as well. */
25237 read_signatured_type (signatured_type
*sig_type
,
25238 dwarf2_per_objfile
*per_objfile
)
25240 gdb_assert (sig_type
->is_debug_types
);
25241 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
25243 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
25245 if (!reader
.dummy_p
)
25247 struct dwarf2_cu
*cu
= reader
.cu
;
25248 const gdb_byte
*info_ptr
= reader
.info_ptr
;
25250 gdb_assert (cu
->die_hash
== NULL
);
25252 htab_create_alloc_ex (cu
->header
.length
/ 12,
25256 &cu
->comp_unit_obstack
,
25257 hashtab_obstack_allocate
,
25258 dummy_obstack_deallocate
);
25260 if (reader
.comp_unit_die
->has_children
)
25261 reader
.comp_unit_die
->child
25262 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
25263 reader
.comp_unit_die
);
25264 cu
->dies
= reader
.comp_unit_die
;
25265 /* comp_unit_die is not stored in die_hash, no need. */
25267 /* We try not to read any attributes in this function, because
25268 not all CUs needed for references have been loaded yet, and
25269 symbol table processing isn't initialized. But we have to
25270 set the CU language, or we won't be able to build types
25271 correctly. Similarly, if we do not read the producer, we can
25272 not apply producer-specific interpretation. */
25273 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
25278 sig_type
->tu_read
= 1;
25281 /* Decode simple location descriptions.
25282 Given a pointer to a dwarf block that defines a location, compute
25283 the location and return the value. If COMPUTED is non-null, it is
25284 set to true to indicate that decoding was successful, and false
25285 otherwise. If COMPUTED is null, then this function may emit a
25289 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
25291 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
25293 size_t size
= blk
->size
;
25294 const gdb_byte
*data
= blk
->data
;
25295 CORE_ADDR stack
[64];
25297 unsigned int bytes_read
, unsnd
;
25300 if (computed
!= nullptr)
25306 stack
[++stacki
] = 0;
25345 stack
[++stacki
] = op
- DW_OP_lit0
;
25380 stack
[++stacki
] = op
- DW_OP_reg0
;
25383 if (computed
== nullptr)
25384 dwarf2_complex_location_expr_complaint ();
25391 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
25393 stack
[++stacki
] = unsnd
;
25396 if (computed
== nullptr)
25397 dwarf2_complex_location_expr_complaint ();
25404 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
25409 case DW_OP_const1u
:
25410 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
25414 case DW_OP_const1s
:
25415 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
25419 case DW_OP_const2u
:
25420 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
25424 case DW_OP_const2s
:
25425 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
25429 case DW_OP_const4u
:
25430 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
25434 case DW_OP_const4s
:
25435 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
25439 case DW_OP_const8u
:
25440 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
25445 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
25451 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
25456 stack
[stacki
+ 1] = stack
[stacki
];
25461 stack
[stacki
- 1] += stack
[stacki
];
25465 case DW_OP_plus_uconst
:
25466 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
25472 stack
[stacki
- 1] -= stack
[stacki
];
25477 /* If we're not the last op, then we definitely can't encode
25478 this using GDB's address_class enum. This is valid for partial
25479 global symbols, although the variable's address will be bogus
25483 if (computed
== nullptr)
25484 dwarf2_complex_location_expr_complaint ();
25490 case DW_OP_GNU_push_tls_address
:
25491 case DW_OP_form_tls_address
:
25492 /* The top of the stack has the offset from the beginning
25493 of the thread control block at which the variable is located. */
25494 /* Nothing should follow this operator, so the top of stack would
25496 /* This is valid for partial global symbols, but the variable's
25497 address will be bogus in the psymtab. Make it always at least
25498 non-zero to not look as a variable garbage collected by linker
25499 which have DW_OP_addr 0. */
25502 if (computed
== nullptr)
25503 dwarf2_complex_location_expr_complaint ();
25510 case DW_OP_GNU_uninit
:
25511 if (computed
!= nullptr)
25516 case DW_OP_GNU_addr_index
:
25517 case DW_OP_GNU_const_index
:
25518 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
25524 if (computed
== nullptr)
25526 const char *name
= get_DW_OP_name (op
);
25529 complaint (_("unsupported stack op: '%s'"),
25532 complaint (_("unsupported stack op: '%02x'"),
25536 return (stack
[stacki
]);
25539 /* Enforce maximum stack depth of SIZE-1 to avoid writing
25540 outside of the allocated space. Also enforce minimum>0. */
25541 if (stacki
>= ARRAY_SIZE (stack
) - 1)
25543 if (computed
== nullptr)
25544 complaint (_("location description stack overflow"));
25550 if (computed
== nullptr)
25551 complaint (_("location description stack underflow"));
25556 if (computed
!= nullptr)
25558 return (stack
[stacki
]);
25561 /* memory allocation interface */
25563 static struct dwarf_block
*
25564 dwarf_alloc_block (struct dwarf2_cu
*cu
)
25566 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
25569 static struct die_info
*
25570 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
25572 struct die_info
*die
;
25573 size_t size
= sizeof (struct die_info
);
25576 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
25578 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
25579 memset (die
, 0, sizeof (struct die_info
));
25585 /* Macro support. */
25587 /* An overload of dwarf_decode_macros that finds the correct section
25588 and ensures it is read in before calling the other overload. */
25591 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25592 int section_is_gnu
)
25594 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25595 struct objfile
*objfile
= per_objfile
->objfile
;
25596 const struct line_header
*lh
= cu
->line_header
;
25597 unsigned int offset_size
= cu
->header
.offset_size
;
25598 struct dwarf2_section_info
*section
;
25599 const char *section_name
;
25601 if (cu
->dwo_unit
!= nullptr)
25603 if (section_is_gnu
)
25605 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25606 section_name
= ".debug_macro.dwo";
25610 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25611 section_name
= ".debug_macinfo.dwo";
25616 if (section_is_gnu
)
25618 section
= &per_objfile
->per_bfd
->macro
;
25619 section_name
= ".debug_macro";
25623 section
= &per_objfile
->per_bfd
->macinfo
;
25624 section_name
= ".debug_macinfo";
25628 section
->read (objfile
);
25629 if (section
->buffer
== nullptr)
25631 complaint (_("missing %s section"), section_name
);
25635 buildsym_compunit
*builder
= cu
->get_builder ();
25637 struct dwarf2_section_info
*str_offsets_section
;
25638 struct dwarf2_section_info
*str_section
;
25639 gdb::optional
<ULONGEST
> str_offsets_base
;
25641 if (cu
->dwo_unit
!= nullptr)
25643 str_offsets_section
= &cu
->dwo_unit
->dwo_file
25644 ->sections
.str_offsets
;
25645 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
25646 str_offsets_base
= cu
->header
.addr_size
;
25650 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
25651 str_section
= &per_objfile
->per_bfd
->str
;
25652 str_offsets_base
= cu
->str_offsets_base
;
25655 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
25656 offset_size
, offset
, str_section
, str_offsets_section
,
25657 str_offsets_base
, section_is_gnu
);
25660 /* Return the .debug_loc section to use for CU.
25661 For DWO files use .debug_loc.dwo. */
25663 static struct dwarf2_section_info
*
25664 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25666 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25670 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25672 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25674 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
25675 : &per_objfile
->per_bfd
->loc
);
25678 /* Return the .debug_rnglists section to use for CU. */
25679 static struct dwarf2_section_info
*
25680 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
25682 if (cu
->header
.version
< 5)
25683 error (_(".debug_rnglists section cannot be used in DWARF %d"),
25684 cu
->header
.version
);
25685 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
25687 /* Make sure we read the .debug_rnglists section from the file that
25688 contains the DW_AT_ranges attribute we are reading. Normally that
25689 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
25690 or DW_TAG_skeleton unit, we always want to read from objfile/linked
25692 if (cu
->dwo_unit
!= nullptr
25693 && tag
!= DW_TAG_compile_unit
25694 && tag
!= DW_TAG_skeleton_unit
)
25696 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25698 if (sections
->rnglists
.size
> 0)
25699 return §ions
->rnglists
;
25701 error (_(".debug_rnglists section is missing from .dwo file."));
25703 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
25706 /* A helper function that fills in a dwarf2_loclist_baton. */
25709 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25710 struct dwarf2_loclist_baton
*baton
,
25711 const struct attribute
*attr
)
25713 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25714 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25716 section
->read (per_objfile
->objfile
);
25718 baton
->per_objfile
= per_objfile
;
25719 baton
->per_cu
= cu
->per_cu
;
25720 gdb_assert (baton
->per_cu
);
25721 /* We don't know how long the location list is, but make sure we
25722 don't run off the edge of the section. */
25723 baton
->size
= section
->size
- attr
->as_unsigned ();
25724 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
25725 if (cu
->base_address
.has_value ())
25726 baton
->base_address
= *cu
->base_address
;
25728 baton
->base_address
= 0;
25729 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25733 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25734 struct dwarf2_cu
*cu
, int is_block
)
25736 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25737 struct objfile
*objfile
= per_objfile
->objfile
;
25738 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25740 if (attr
->form_is_section_offset ()
25741 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25742 the section. If so, fall through to the complaint in the
25744 && attr
->as_unsigned () < section
->get_size (objfile
))
25746 struct dwarf2_loclist_baton
*baton
;
25748 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25750 fill_in_loclist_baton (cu
, baton
, attr
);
25752 if (!cu
->base_address
.has_value ())
25753 complaint (_("Location list used without "
25754 "specifying the CU base address."));
25756 sym
->set_aclass_index ((is_block
25757 ? dwarf2_loclist_block_index
25758 : dwarf2_loclist_index
));
25759 SYMBOL_LOCATION_BATON (sym
) = baton
;
25763 struct dwarf2_locexpr_baton
*baton
;
25765 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25766 baton
->per_objfile
= per_objfile
;
25767 baton
->per_cu
= cu
->per_cu
;
25768 gdb_assert (baton
->per_cu
);
25770 if (attr
->form_is_block ())
25772 /* Note that we're just copying the block's data pointer
25773 here, not the actual data. We're still pointing into the
25774 info_buffer for SYM's objfile; right now we never release
25775 that buffer, but when we do clean up properly this may
25777 struct dwarf_block
*block
= attr
->as_block ();
25778 baton
->size
= block
->size
;
25779 baton
->data
= block
->data
;
25783 dwarf2_invalid_attrib_class_complaint ("location description",
25784 sym
->natural_name ());
25788 sym
->set_aclass_index ((is_block
25789 ? dwarf2_locexpr_block_index
25790 : dwarf2_locexpr_index
));
25791 SYMBOL_LOCATION_BATON (sym
) = baton
;
25797 const comp_unit_head
*
25798 dwarf2_per_cu_data::get_header () const
25800 if (!m_header_read_in
)
25802 const gdb_byte
*info_ptr
25803 = this->section
->buffer
+ to_underlying (this->sect_off
);
25805 memset (&m_header
, 0, sizeof (m_header
));
25807 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
25808 rcuh_kind::COMPILE
);
25810 m_header_read_in
= true;
25819 dwarf2_per_cu_data::addr_size () const
25821 return this->get_header ()->addr_size
;
25827 dwarf2_per_cu_data::offset_size () const
25829 return this->get_header ()->offset_size
;
25835 dwarf2_per_cu_data::ref_addr_size () const
25837 const comp_unit_head
*header
= this->get_header ();
25839 if (header
->version
== 2)
25840 return header
->addr_size
;
25842 return header
->offset_size
;
25845 /* A helper function for dwarf2_find_containing_comp_unit that returns
25846 the index of the result, and that searches a vector. It will
25847 return a result even if the offset in question does not actually
25848 occur in any CU. This is separate so that it can be unit
25852 dwarf2_find_containing_comp_unit
25853 (sect_offset sect_off
,
25854 unsigned int offset_in_dwz
,
25855 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
25860 high
= all_comp_units
.size () - 1;
25863 struct dwarf2_per_cu_data
*mid_cu
;
25864 int mid
= low
+ (high
- low
) / 2;
25866 mid_cu
= all_comp_units
[mid
].get ();
25867 if (mid_cu
->is_dwz
> offset_in_dwz
25868 || (mid_cu
->is_dwz
== offset_in_dwz
25869 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
25874 gdb_assert (low
== high
);
25878 /* Locate the .debug_info compilation unit from CU's objfile which contains
25879 the DIE at OFFSET. Raises an error on failure. */
25881 static struct dwarf2_per_cu_data
*
25882 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25883 unsigned int offset_in_dwz
,
25884 dwarf2_per_bfd
*per_bfd
)
25886 int low
= dwarf2_find_containing_comp_unit
25887 (sect_off
, offset_in_dwz
, per_bfd
->all_comp_units
);
25888 dwarf2_per_cu_data
*this_cu
= per_bfd
->all_comp_units
[low
].get ();
25890 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25892 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25893 error (_("Dwarf Error: could not find partial DIE containing "
25894 "offset %s [in module %s]"),
25895 sect_offset_str (sect_off
),
25896 bfd_get_filename (per_bfd
->obfd
));
25898 gdb_assert (per_bfd
->all_comp_units
[low
-1]->sect_off
25900 return per_bfd
->all_comp_units
[low
- 1].get ();
25904 if (low
== per_bfd
->all_comp_units
.size () - 1
25905 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25906 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25907 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25914 namespace selftests
{
25915 namespace find_containing_comp_unit
{
25920 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
25921 dwarf2_per_cu_data
*one_ptr
= one
.get ();
25922 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
25923 dwarf2_per_cu_data
*two_ptr
= two
.get ();
25924 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
25925 dwarf2_per_cu_data
*three_ptr
= three
.get ();
25926 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
25927 dwarf2_per_cu_data
*four_ptr
= four
.get ();
25930 two
->sect_off
= sect_offset (one
->length
);
25935 four
->sect_off
= sect_offset (three
->length
);
25939 std::vector
<dwarf2_per_cu_data_up
> units
;
25940 units
.push_back (std::move (one
));
25941 units
.push_back (std::move (two
));
25942 units
.push_back (std::move (three
));
25943 units
.push_back (std::move (four
));
25947 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
25948 SELF_CHECK (units
[result
].get () == one_ptr
);
25949 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
25950 SELF_CHECK (units
[result
].get () == one_ptr
);
25951 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
25952 SELF_CHECK (units
[result
].get () == two_ptr
);
25954 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
25955 SELF_CHECK (units
[result
].get () == three_ptr
);
25956 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
25957 SELF_CHECK (units
[result
].get () == three_ptr
);
25958 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
25959 SELF_CHECK (units
[result
].get () == four_ptr
);
25965 #endif /* GDB_SELF_TEST */
25967 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25970 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25971 enum language pretend_language
)
25973 struct attribute
*attr
;
25975 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25977 /* Set the language we're debugging. */
25978 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25979 if (cu
->producer
!= nullptr
25980 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
25982 /* The XLCL doesn't generate DW_LANG_OpenCL because this
25983 attribute is not standardised yet. As a workaround for the
25984 language detection we fall back to the DW_AT_producer
25986 cu
->per_cu
->lang
= language_opencl
;
25988 else if (cu
->producer
!= nullptr
25989 && strstr (cu
->producer
, "GNU Go ") != NULL
)
25991 /* Similar hack for Go. */
25992 cu
->per_cu
->lang
= language_go
;
25994 else if (attr
!= nullptr)
25995 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
25997 cu
->per_cu
->lang
= pretend_language
;
25998 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
26004 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
26006 auto it
= m_dwarf2_cus
.find (per_cu
);
26007 if (it
== m_dwarf2_cus
.end ())
26016 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
26018 gdb_assert (this->get_cu (per_cu
) == nullptr);
26020 m_dwarf2_cus
[per_cu
] = cu
;
26026 dwarf2_per_objfile::age_comp_units ()
26028 dwarf_read_debug_printf_v ("running");
26030 /* This is not expected to be called in the middle of CU expansion. There is
26031 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
26032 loaded in memory. Calling age_comp_units while the queue is in use could
26033 make us free the DIEs for a CU that is in the queue and therefore break
26035 gdb_assert (!this->per_bfd
->queue
.has_value ());
26037 /* Start by clearing all marks. */
26038 for (auto pair
: m_dwarf2_cus
)
26039 pair
.second
->clear_mark ();
26041 /* Traverse all CUs, mark them and their dependencies if used recently
26043 for (auto pair
: m_dwarf2_cus
)
26045 dwarf2_cu
*cu
= pair
.second
;
26048 if (cu
->last_used
<= dwarf_max_cache_age
)
26052 /* Delete all CUs still not marked. */
26053 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
26055 dwarf2_cu
*cu
= it
->second
;
26057 if (!cu
->is_marked ())
26059 dwarf_read_debug_printf_v ("deleting old CU %s",
26060 sect_offset_str (cu
->per_cu
->sect_off
));
26062 it
= m_dwarf2_cus
.erase (it
);
26072 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
26074 auto it
= m_dwarf2_cus
.find (per_cu
);
26075 if (it
== m_dwarf2_cus
.end ())
26080 m_dwarf2_cus
.erase (it
);
26083 dwarf2_per_objfile::~dwarf2_per_objfile ()
26088 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
26089 We store these in a hash table separate from the DIEs, and preserve them
26090 when the DIEs are flushed out of cache.
26092 The CU "per_cu" pointer is needed because offset alone is not enough to
26093 uniquely identify the type. A file may have multiple .debug_types sections,
26094 or the type may come from a DWO file. Furthermore, while it's more logical
26095 to use per_cu->section+offset, with Fission the section with the data is in
26096 the DWO file but we don't know that section at the point we need it.
26097 We have to use something in dwarf2_per_cu_data (or the pointer to it)
26098 because we can enter the lookup routine, get_die_type_at_offset, from
26099 outside this file, and thus won't necessarily have PER_CU->cu.
26100 Fortunately, PER_CU is stable for the life of the objfile. */
26102 struct dwarf2_per_cu_offset_and_type
26104 const struct dwarf2_per_cu_data
*per_cu
;
26105 sect_offset sect_off
;
26109 /* Hash function for a dwarf2_per_cu_offset_and_type. */
26112 per_cu_offset_and_type_hash (const void *item
)
26114 const struct dwarf2_per_cu_offset_and_type
*ofs
26115 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
26117 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
26120 /* Equality function for a dwarf2_per_cu_offset_and_type. */
26123 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
26125 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
26126 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
26127 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
26128 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
26130 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
26131 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
26134 /* Set the type associated with DIE to TYPE. Save it in CU's hash
26135 table if necessary. For convenience, return TYPE.
26137 The DIEs reading must have careful ordering to:
26138 * Not cause infinite loops trying to read in DIEs as a prerequisite for
26139 reading current DIE.
26140 * Not trying to dereference contents of still incompletely read in types
26141 while reading in other DIEs.
26142 * Enable referencing still incompletely read in types just by a pointer to
26143 the type without accessing its fields.
26145 Therefore caller should follow these rules:
26146 * Try to fetch any prerequisite types we may need to build this DIE type
26147 before building the type and calling set_die_type.
26148 * After building type call set_die_type for current DIE as soon as
26149 possible before fetching more types to complete the current type.
26150 * Make the type as complete as possible before fetching more types. */
26152 static struct type
*
26153 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
26154 bool skip_data_location
)
26156 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
26157 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
26158 struct objfile
*objfile
= per_objfile
->objfile
;
26159 struct attribute
*attr
;
26160 struct dynamic_prop prop
;
26162 /* For Ada types, make sure that the gnat-specific data is always
26163 initialized (if not already set). There are a few types where
26164 we should not be doing so, because the type-specific area is
26165 already used to hold some other piece of info (eg: TYPE_CODE_FLT
26166 where the type-specific area is used to store the floatformat).
26167 But this is not a problem, because the gnat-specific information
26168 is actually not needed for these types. */
26169 if (need_gnat_info (cu
)
26170 && type
->code () != TYPE_CODE_FUNC
26171 && type
->code () != TYPE_CODE_FLT
26172 && type
->code () != TYPE_CODE_METHODPTR
26173 && type
->code () != TYPE_CODE_MEMBERPTR
26174 && type
->code () != TYPE_CODE_METHOD
26175 && type
->code () != TYPE_CODE_FIXED_POINT
26176 && !HAVE_GNAT_AUX_INFO (type
))
26177 INIT_GNAT_SPECIFIC (type
);
26179 /* Read DW_AT_allocated and set in type. */
26180 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
26183 struct type
*prop_type
= cu
->addr_sized_int_type (false);
26184 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
26185 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
26188 /* Read DW_AT_associated and set in type. */
26189 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
26192 struct type
*prop_type
= cu
->addr_sized_int_type (false);
26193 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
26194 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
26197 /* Read DW_AT_rank and set in type. */
26198 attr
= dwarf2_attr (die
, DW_AT_rank
, cu
);
26201 struct type
*prop_type
= cu
->addr_sized_int_type (false);
26202 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
26203 type
->add_dyn_prop (DYN_PROP_RANK
, prop
);
26206 /* Read DW_AT_data_location and set in type. */
26207 if (!skip_data_location
)
26209 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
26210 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
26211 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
26214 if (per_objfile
->die_type_hash
== NULL
)
26215 per_objfile
->die_type_hash
26216 = htab_up (htab_create_alloc (127,
26217 per_cu_offset_and_type_hash
,
26218 per_cu_offset_and_type_eq
,
26219 NULL
, xcalloc
, xfree
));
26221 ofs
.per_cu
= cu
->per_cu
;
26222 ofs
.sect_off
= die
->sect_off
;
26224 slot
= (struct dwarf2_per_cu_offset_and_type
**)
26225 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
26227 complaint (_("A problem internal to GDB: DIE %s has type already set"),
26228 sect_offset_str (die
->sect_off
));
26229 *slot
= XOBNEW (&objfile
->objfile_obstack
,
26230 struct dwarf2_per_cu_offset_and_type
);
26235 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
26236 or return NULL if the die does not have a saved type. */
26238 static struct type
*
26239 get_die_type_at_offset (sect_offset sect_off
,
26240 dwarf2_per_cu_data
*per_cu
,
26241 dwarf2_per_objfile
*per_objfile
)
26243 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
26245 if (per_objfile
->die_type_hash
== NULL
)
26248 ofs
.per_cu
= per_cu
;
26249 ofs
.sect_off
= sect_off
;
26250 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
26251 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
26258 /* Look up the type for DIE in CU in die_type_hash,
26259 or return NULL if DIE does not have a saved type. */
26261 static struct type
*
26262 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
26264 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
26267 /* Trivial hash function for partial_die_info: the hash value of a DIE
26268 is its offset in .debug_info for this objfile. */
26271 partial_die_hash (const void *item
)
26273 const struct partial_die_info
*part_die
26274 = (const struct partial_die_info
*) item
;
26276 return to_underlying (part_die
->sect_off
);
26279 /* Trivial comparison function for partial_die_info structures: two DIEs
26280 are equal if they have the same offset. */
26283 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26285 const struct partial_die_info
*part_die_lhs
26286 = (const struct partial_die_info
*) item_lhs
;
26287 const struct partial_die_info
*part_die_rhs
26288 = (const struct partial_die_info
*) item_rhs
;
26290 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26293 struct cmd_list_element
*set_dwarf_cmdlist
;
26294 struct cmd_list_element
*show_dwarf_cmdlist
;
26297 show_check_physname (struct ui_file
*file
, int from_tty
,
26298 struct cmd_list_element
*c
, const char *value
)
26301 _("Whether to check \"physname\" is %s.\n"),
26305 void _initialize_dwarf2_read ();
26307 _initialize_dwarf2_read ()
26309 add_setshow_prefix_cmd ("dwarf", class_maintenance
,
26311 Set DWARF specific variables.\n\
26312 Configure DWARF variables such as the cache size."),
26314 Show DWARF specific variables.\n\
26315 Show DWARF variables such as the cache size."),
26316 &set_dwarf_cmdlist
, &show_dwarf_cmdlist
,
26317 &maintenance_set_cmdlist
, &maintenance_show_cmdlist
);
26319 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26320 &dwarf_max_cache_age
, _("\
26321 Set the upper bound on the age of cached DWARF compilation units."), _("\
26322 Show the upper bound on the age of cached DWARF compilation units."), _("\
26323 A higher limit means that cached compilation units will be stored\n\
26324 in memory longer, and more total memory will be used. Zero disables\n\
26325 caching, which can slow down startup."),
26327 show_dwarf_max_cache_age
,
26328 &set_dwarf_cmdlist
,
26329 &show_dwarf_cmdlist
);
26331 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26332 Set debugging of the DWARF reader."), _("\
26333 Show debugging of the DWARF reader."), _("\
26334 When enabled (non-zero), debugging messages are printed during DWARF\n\
26335 reading and symtab expansion. A value of 1 (one) provides basic\n\
26336 information. A value greater than 1 provides more verbose information."),
26339 &setdebuglist
, &showdebuglist
);
26341 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26342 Set debugging of the DWARF DIE reader."), _("\
26343 Show debugging of the DWARF DIE reader."), _("\
26344 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26345 The value is the maximum depth to print."),
26348 &setdebuglist
, &showdebuglist
);
26350 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26351 Set debugging of the dwarf line reader."), _("\
26352 Show debugging of the dwarf line reader."), _("\
26353 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26354 A value of 1 (one) provides basic information.\n\
26355 A value greater than 1 provides more verbose information."),
26358 &setdebuglist
, &showdebuglist
);
26360 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26361 Set cross-checking of \"physname\" code against demangler."), _("\
26362 Show cross-checking of \"physname\" code against demangler."), _("\
26363 When enabled, GDB's internal \"physname\" code is checked against\n\
26365 NULL
, show_check_physname
,
26366 &setdebuglist
, &showdebuglist
);
26368 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26369 no_class
, &use_deprecated_index_sections
, _("\
26370 Set whether to use deprecated gdb_index sections."), _("\
26371 Show whether to use deprecated gdb_index sections."), _("\
26372 When enabled, deprecated .gdb_index sections are used anyway.\n\
26373 Normally they are ignored either because of a missing feature or\n\
26374 performance issue.\n\
26375 Warning: This option must be enabled before gdb reads the file."),
26378 &setlist
, &showlist
);
26380 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26381 &dwarf2_locexpr_funcs
);
26382 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26383 &dwarf2_loclist_funcs
);
26385 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26386 &dwarf2_block_frame_base_locexpr_funcs
);
26387 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26388 &dwarf2_block_frame_base_loclist_funcs
);
26391 selftests::register_test ("dw2_expand_symtabs_matching",
26392 selftests::dw2_expand_symtabs_matching::run_test
);
26393 selftests::register_test ("dwarf2_find_containing_comp_unit",
26394 selftests::find_containing_comp_unit::run_test
);