1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2023 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"
70 #include "gdbcore.h" /* for gnutarget */
71 #include "gdb/gdb-index.h"
76 #include "namespace.h"
77 #include "gdbsupport/function-view.h"
78 #include "gdbsupport/gdb_optional.h"
79 #include "gdbsupport/underlying.h"
80 #include "gdbsupport/hash_enum.h"
81 #include "filename-seen-cache.h"
85 #include <unordered_map>
86 #include "gdbsupport/selftest.h"
87 #include "rust-lang.h"
88 #include "gdbsupport/pathstuff.h"
89 #include "count-one-bits.h"
90 #include <unordered_set>
91 #include "dwarf2/abbrev-cache.h"
92 #include "cooked-index.h"
93 #include "split-name.h"
94 #include "gdbsupport/parallel-for.h"
95 #include "gdbsupport/thread-pool.h"
97 /* When == 1, print basic high level tracing messages.
98 When > 1, be more verbose.
99 This is in contrast to the low level DIE reading of dwarf_die_debug. */
100 static unsigned int dwarf_read_debug
= 0;
102 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
104 #define dwarf_read_debug_printf(fmt, ...) \
105 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
108 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
110 #define dwarf_read_debug_printf_v(fmt, ...) \
111 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
114 /* When non-zero, dump DIEs after they are read in. */
115 static unsigned int dwarf_die_debug
= 0;
117 /* When non-zero, dump line number entries as they are read in. */
118 unsigned int dwarf_line_debug
= 0;
120 /* When true, cross-check physname against demangler. */
121 static bool check_physname
= false;
123 /* When true, do not reject deprecated .gdb_index sections. */
124 static bool use_deprecated_index_sections
= false;
126 /* This is used to store the data that is always per objfile. */
127 static const registry
<objfile
>::key
<dwarf2_per_objfile
>
128 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 registry
<bfd
>::key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
139 static const registry
<objfile
>::key
<dwarf2_per_bfd
>
140 dwarf2_per_bfd_objfile_data_key
;
142 /* The "aclass" indices for various kinds of computed DWARF symbols. */
144 static int dwarf2_locexpr_index
;
145 static int dwarf2_loclist_index
;
146 static int dwarf2_locexpr_block_index
;
147 static int dwarf2_loclist_block_index
;
149 /* Size of .debug_loclists section header for 32-bit DWARF format. */
150 #define LOCLIST_HEADER_SIZE32 12
152 /* Size of .debug_loclists section header for 64-bit DWARF format. */
153 #define LOCLIST_HEADER_SIZE64 20
155 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
156 #define RNGLIST_HEADER_SIZE32 12
158 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
159 #define RNGLIST_HEADER_SIZE64 20
161 /* This is a view into the index that converts from bytes to an
162 offset_type, and allows indexing. Unaligned bytes are specifically
163 allowed here, and handled via unpacking. */
168 offset_view () = default;
170 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
175 /* Extract the INDEXth offset_type from the array. */
176 offset_type
operator[] (size_t index
) const
178 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
179 return (offset_type
) extract_unsigned_integer (bytes
,
180 sizeof (offset_type
),
184 /* Return the number of offset_types in this array. */
187 return m_bytes
.size () / sizeof (offset_type
);
190 /* Return true if this view is empty. */
193 return m_bytes
.empty ();
197 /* The underlying bytes. */
198 gdb::array_view
<const gdb_byte
> m_bytes
;
201 /* A description of the mapped index. The file format is described in
202 a comment by the code that writes the index. */
203 struct mapped_index final
: public mapped_index_base
205 /* Index data format version. */
208 /* The address table data. */
209 gdb::array_view
<const gdb_byte
> address_table
;
211 /* The symbol table, implemented as a hash table. */
212 offset_view symbol_table
;
214 /* A pointer to the constant pool. */
215 gdb::array_view
<const gdb_byte
> constant_pool
;
217 /* Return the index into the constant pool of the name of the IDXth
218 symbol in the symbol table. */
219 offset_type
symbol_name_index (offset_type idx
) const
221 return symbol_table
[2 * idx
];
224 /* Return the index into the constant pool of the CU vector of the
225 IDXth symbol in the symbol table. */
226 offset_type
symbol_vec_index (offset_type idx
) const
228 return symbol_table
[2 * idx
+ 1];
231 bool symbol_name_slot_invalid (offset_type idx
) const override
233 return (symbol_name_index (idx
) == 0
234 && symbol_vec_index (idx
) == 0);
237 /* Convenience method to get at the name of the symbol at IDX in the
239 const char *symbol_name_at
240 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
242 return (const char *) (this->constant_pool
.data ()
243 + symbol_name_index (idx
));
246 size_t symbol_name_count () const override
247 { return this->symbol_table
.size () / 2; }
249 quick_symbol_functions_up
make_quick_functions () const override
;
251 bool version_check () const override
257 /* A description of the mapped .debug_names.
258 Uninitialized map has CU_COUNT 0. */
259 struct mapped_debug_names final
: public mapped_index_base
261 bfd_endian dwarf5_byte_order
;
262 bool dwarf5_is_dwarf64
;
263 bool augmentation_is_gdb
;
265 uint32_t cu_count
= 0;
266 uint32_t tu_count
, bucket_count
, name_count
;
267 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
268 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
269 const gdb_byte
*name_table_string_offs_reordered
;
270 const gdb_byte
*name_table_entry_offs_reordered
;
271 const gdb_byte
*entry_pool
;
278 /* Attribute name DW_IDX_*. */
281 /* Attribute form DW_FORM_*. */
284 /* Value if FORM is DW_FORM_implicit_const. */
285 LONGEST implicit_const
;
287 std::vector
<attr
> attr_vec
;
290 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
292 const char *namei_to_name
293 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
295 /* Implementation of the mapped_index_base virtual interface, for
296 the name_components cache. */
298 const char *symbol_name_at
299 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
300 { return namei_to_name (idx
, per_objfile
); }
302 size_t symbol_name_count () const override
303 { return this->name_count
; }
305 quick_symbol_functions_up
make_quick_functions () const override
;
308 /* See dwarf2/read.h. */
311 get_dwarf2_per_objfile (struct objfile
*objfile
)
313 return dwarf2_objfile_data_key
.get (objfile
);
316 /* Default names of the debugging sections. */
318 /* Note that if the debugging section has been compressed, it might
319 have a name like .zdebug_info. */
321 const struct dwarf2_debug_sections dwarf2_elf_names
=
323 { ".debug_info", ".zdebug_info" },
324 { ".debug_abbrev", ".zdebug_abbrev" },
325 { ".debug_line", ".zdebug_line" },
326 { ".debug_loc", ".zdebug_loc" },
327 { ".debug_loclists", ".zdebug_loclists" },
328 { ".debug_macinfo", ".zdebug_macinfo" },
329 { ".debug_macro", ".zdebug_macro" },
330 { ".debug_str", ".zdebug_str" },
331 { ".debug_str_offsets", ".zdebug_str_offsets" },
332 { ".debug_line_str", ".zdebug_line_str" },
333 { ".debug_ranges", ".zdebug_ranges" },
334 { ".debug_rnglists", ".zdebug_rnglists" },
335 { ".debug_types", ".zdebug_types" },
336 { ".debug_addr", ".zdebug_addr" },
337 { ".debug_frame", ".zdebug_frame" },
338 { ".eh_frame", NULL
},
339 { ".gdb_index", ".zgdb_index" },
340 { ".debug_names", ".zdebug_names" },
341 { ".debug_aranges", ".zdebug_aranges" },
345 /* List of DWO/DWP sections. */
347 static const struct dwop_section_names
349 struct dwarf2_section_names abbrev_dwo
;
350 struct dwarf2_section_names info_dwo
;
351 struct dwarf2_section_names line_dwo
;
352 struct dwarf2_section_names loc_dwo
;
353 struct dwarf2_section_names loclists_dwo
;
354 struct dwarf2_section_names macinfo_dwo
;
355 struct dwarf2_section_names macro_dwo
;
356 struct dwarf2_section_names rnglists_dwo
;
357 struct dwarf2_section_names str_dwo
;
358 struct dwarf2_section_names str_offsets_dwo
;
359 struct dwarf2_section_names types_dwo
;
360 struct dwarf2_section_names cu_index
;
361 struct dwarf2_section_names tu_index
;
365 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
366 { ".debug_info.dwo", ".zdebug_info.dwo" },
367 { ".debug_line.dwo", ".zdebug_line.dwo" },
368 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
369 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
370 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
371 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
372 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
373 { ".debug_str.dwo", ".zdebug_str.dwo" },
374 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
375 { ".debug_types.dwo", ".zdebug_types.dwo" },
376 { ".debug_cu_index", ".zdebug_cu_index" },
377 { ".debug_tu_index", ".zdebug_tu_index" },
380 /* local data types */
382 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
383 begin with a header, which contains the following information. */
384 struct loclists_rnglists_header
386 /* A 4-byte or 12-byte length containing the length of the
387 set of entries for this compilation unit, not including the
388 length field itself. */
391 /* A 2-byte version identifier. */
394 /* A 1-byte unsigned integer containing the size in bytes of an address on
395 the target system. */
396 unsigned char addr_size
;
398 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
399 on the target system. */
400 unsigned char segment_collector_size
;
402 /* A 4-byte count of the number of offsets that follow the header. */
403 unsigned int offset_entry_count
;
406 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
407 This includes type_unit_group and quick_file_names. */
409 struct stmt_list_hash
411 /* The DWO unit this table is from or NULL if there is none. */
412 struct dwo_unit
*dwo_unit
;
414 /* Offset in .debug_line or .debug_line.dwo. */
415 sect_offset line_sect_off
;
418 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
419 an object of this type. This contains elements of type unit groups
420 that can be shared across objfiles. The non-shareable parts are in
421 type_unit_group_unshareable. */
423 struct type_unit_group
425 /* The data used to construct the hash key. */
426 struct stmt_list_hash hash
{};
429 /* These sections are what may appear in a (real or virtual) DWO file. */
433 struct dwarf2_section_info abbrev
;
434 struct dwarf2_section_info line
;
435 struct dwarf2_section_info loc
;
436 struct dwarf2_section_info loclists
;
437 struct dwarf2_section_info macinfo
;
438 struct dwarf2_section_info macro
;
439 struct dwarf2_section_info rnglists
;
440 struct dwarf2_section_info str
;
441 struct dwarf2_section_info str_offsets
;
442 /* In the case of a virtual DWO file, these two are unused. */
443 struct dwarf2_section_info info
;
444 std::vector
<dwarf2_section_info
> types
;
447 /* CUs/TUs in DWP/DWO files. */
451 /* Backlink to the containing struct dwo_file. */
452 struct dwo_file
*dwo_file
;
454 /* The "id" that distinguishes this CU/TU.
455 .debug_info calls this "dwo_id", .debug_types calls this "signature".
456 Since signatures came first, we stick with it for consistency. */
459 /* The section this CU/TU lives in, in the DWO file. */
460 struct dwarf2_section_info
*section
;
462 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
463 sect_offset sect_off
;
466 /* For types, offset in the type's DIE of the type defined by this TU. */
467 cu_offset type_offset_in_tu
;
470 /* include/dwarf2.h defines the DWP section codes.
471 It defines a max value but it doesn't define a min value, which we
472 use for error checking, so provide one. */
474 enum dwp_v2_section_ids
479 /* Data for one DWO file.
481 This includes virtual DWO files (a virtual DWO file is a DWO file as it
482 appears in a DWP file). DWP files don't really have DWO files per se -
483 comdat folding of types "loses" the DWO file they came from, and from
484 a high level view DWP files appear to contain a mass of random types.
485 However, to maintain consistency with the non-DWP case we pretend DWP
486 files contain virtual DWO files, and we assign each TU with one virtual
487 DWO file (generally based on the line and abbrev section offsets -
488 a heuristic that seems to work in practice). */
492 dwo_file () = default;
493 DISABLE_COPY_AND_ASSIGN (dwo_file
);
495 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
496 For virtual DWO files the name is constructed from the section offsets
497 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
498 from related CU+TUs. */
499 const char *dwo_name
= nullptr;
501 /* The DW_AT_comp_dir attribute. */
502 const char *comp_dir
= nullptr;
504 /* The bfd, when the file is open. Otherwise this is NULL.
505 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
506 gdb_bfd_ref_ptr dbfd
;
508 /* The sections that make up this DWO file.
509 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
510 sections (for lack of a better name). */
511 struct dwo_sections sections
{};
513 /* The CUs in the file.
514 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
515 an extension to handle LLVM's Link Time Optimization output (where
516 multiple source files may be compiled into a single object/dwo pair). */
519 /* Table of TUs in the file.
520 Each element is a struct dwo_unit. */
524 /* These sections are what may appear in a DWP file. */
528 /* These are used by all DWP versions (1, 2 and 5). */
529 struct dwarf2_section_info str
;
530 struct dwarf2_section_info cu_index
;
531 struct dwarf2_section_info tu_index
;
533 /* These are only used by DWP version 2 and version 5 files.
534 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
535 sections are referenced by section number, and are not recorded here.
536 In DWP version 2 or 5 there is at most one copy of all these sections,
537 each section being (effectively) comprised of the concatenation of all of
538 the individual sections that exist in the version 1 format.
539 To keep the code simple we treat each of these concatenated pieces as a
540 section itself (a virtual section?). */
541 struct dwarf2_section_info abbrev
;
542 struct dwarf2_section_info info
;
543 struct dwarf2_section_info line
;
544 struct dwarf2_section_info loc
;
545 struct dwarf2_section_info loclists
;
546 struct dwarf2_section_info macinfo
;
547 struct dwarf2_section_info macro
;
548 struct dwarf2_section_info rnglists
;
549 struct dwarf2_section_info str_offsets
;
550 struct dwarf2_section_info types
;
553 /* These sections are what may appear in a virtual DWO file in DWP version 1.
554 A virtual DWO file is a DWO file as it appears in a DWP file. */
556 struct virtual_v1_dwo_sections
558 struct dwarf2_section_info abbrev
;
559 struct dwarf2_section_info line
;
560 struct dwarf2_section_info loc
;
561 struct dwarf2_section_info macinfo
;
562 struct dwarf2_section_info macro
;
563 struct dwarf2_section_info str_offsets
;
564 /* Each DWP hash table entry records one CU or one TU.
565 That is recorded here, and copied to dwo_unit.section. */
566 struct dwarf2_section_info info_or_types
;
569 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
570 In version 2, the sections of the DWO files are concatenated together
571 and stored in one section of that name. Thus each ELF section contains
572 several "virtual" sections. */
574 struct virtual_v2_or_v5_dwo_sections
576 bfd_size_type abbrev_offset
;
577 bfd_size_type abbrev_size
;
579 bfd_size_type line_offset
;
580 bfd_size_type line_size
;
582 bfd_size_type loc_offset
;
583 bfd_size_type loc_size
;
585 bfd_size_type loclists_offset
;
586 bfd_size_type loclists_size
;
588 bfd_size_type macinfo_offset
;
589 bfd_size_type macinfo_size
;
591 bfd_size_type macro_offset
;
592 bfd_size_type macro_size
;
594 bfd_size_type rnglists_offset
;
595 bfd_size_type rnglists_size
;
597 bfd_size_type str_offsets_offset
;
598 bfd_size_type str_offsets_size
;
600 /* Each DWP hash table entry records one CU or one TU.
601 That is recorded here, and copied to dwo_unit.section. */
602 bfd_size_type info_or_types_offset
;
603 bfd_size_type info_or_types_size
;
606 /* Contents of DWP hash tables. */
608 struct dwp_hash_table
610 uint32_t version
, nr_columns
;
611 uint32_t nr_units
, nr_slots
;
612 const gdb_byte
*hash_table
, *unit_table
;
617 const gdb_byte
*indices
;
621 /* This is indexed by column number and gives the id of the section
623 #define MAX_NR_V2_DWO_SECTIONS \
624 (1 /* .debug_info or .debug_types */ \
625 + 1 /* .debug_abbrev */ \
626 + 1 /* .debug_line */ \
627 + 1 /* .debug_loc */ \
628 + 1 /* .debug_str_offsets */ \
629 + 1 /* .debug_macro or .debug_macinfo */)
630 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
631 const gdb_byte
*offsets
;
632 const gdb_byte
*sizes
;
636 /* This is indexed by column number and gives the id of the section
638 #define MAX_NR_V5_DWO_SECTIONS \
639 (1 /* .debug_info */ \
640 + 1 /* .debug_abbrev */ \
641 + 1 /* .debug_line */ \
642 + 1 /* .debug_loclists */ \
643 + 1 /* .debug_str_offsets */ \
644 + 1 /* .debug_macro */ \
645 + 1 /* .debug_rnglists */)
646 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
647 const gdb_byte
*offsets
;
648 const gdb_byte
*sizes
;
653 /* Data for one DWP file. */
657 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
659 dbfd (std::move (abfd
))
663 /* Name of the file. */
666 /* File format version. */
670 gdb_bfd_ref_ptr dbfd
;
672 /* Section info for this file. */
673 struct dwp_sections sections
{};
675 /* Table of CUs in the file. */
676 const struct dwp_hash_table
*cus
= nullptr;
678 /* Table of TUs in the file. */
679 const struct dwp_hash_table
*tus
= nullptr;
681 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
685 /* Table to map ELF section numbers to their sections.
686 This is only needed for the DWP V1 file format. */
687 unsigned int num_sections
= 0;
688 asection
**elf_sections
= nullptr;
691 /* Struct used to pass misc. parameters to read_die_and_children, et
692 al. which are used for both .debug_info and .debug_types dies.
693 All parameters here are unchanging for the life of the call. This
694 struct exists to abstract away the constant parameters of die reading. */
696 struct die_reader_specs
698 /* The bfd of die_section. */
701 /* The CU of the DIE we are parsing. */
702 struct dwarf2_cu
*cu
;
704 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
705 struct dwo_file
*dwo_file
;
707 /* The section the die comes from.
708 This is either .debug_info or .debug_types, or the .dwo variants. */
709 struct dwarf2_section_info
*die_section
;
711 /* die_section->buffer. */
712 const gdb_byte
*buffer
;
714 /* The end of the buffer. */
715 const gdb_byte
*buffer_end
;
717 /* The abbreviation table to use when reading the DIEs. */
718 struct abbrev_table
*abbrev_table
;
721 /* A subclass of die_reader_specs that holds storage and has complex
722 constructor and destructor behavior. */
724 class cutu_reader
: public die_reader_specs
728 cutu_reader (dwarf2_per_cu_data
*this_cu
,
729 dwarf2_per_objfile
*per_objfile
,
730 struct abbrev_table
*abbrev_table
,
731 dwarf2_cu
*existing_cu
,
733 abbrev_cache
*cache
= nullptr);
735 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
736 dwarf2_per_objfile
*per_objfile
,
737 struct dwarf2_cu
*parent_cu
= nullptr,
738 struct dwo_file
*dwo_file
= nullptr);
740 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
742 cutu_reader (cutu_reader
&&) = default;
744 const gdb_byte
*info_ptr
= nullptr;
745 struct die_info
*comp_unit_die
= nullptr;
746 bool dummy_p
= false;
748 /* Release the new CU, putting it on the chain. This cannot be done
752 /* Release the abbrev table, transferring ownership to the
754 abbrev_table_up
release_abbrev_table ()
756 return std::move (m_abbrev_table_holder
);
760 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
761 dwarf2_per_objfile
*per_objfile
,
762 dwarf2_cu
*existing_cu
);
764 struct dwarf2_per_cu_data
*m_this_cu
;
765 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
767 /* The ordinary abbreviation table. */
768 abbrev_table_up m_abbrev_table_holder
;
770 /* The DWO abbreviation table. */
771 abbrev_table_up m_dwo_abbrev_table
;
774 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
775 but this would require a corresponding change in unpack_field_as_long
777 static int bits_per_byte
= 8;
779 struct variant_part_builder
;
781 /* When reading a variant, we track a bit more information about the
782 field, and store it in an object of this type. */
786 int first_field
= -1;
789 /* A variant can contain other variant parts. */
790 std::vector
<variant_part_builder
> variant_parts
;
792 /* If we see a DW_TAG_variant, then this will be set if this is the
794 bool default_branch
= false;
795 /* If we see a DW_AT_discr_value, then this will be the discriminant
797 ULONGEST discriminant_value
= 0;
798 /* If we see a DW_AT_discr_list, then this is a pointer to the list
800 struct dwarf_block
*discr_list_data
= nullptr;
803 /* This represents a DW_TAG_variant_part. */
805 struct variant_part_builder
807 /* The offset of the discriminant field. */
808 sect_offset discriminant_offset
{};
810 /* Variants that are direct children of this variant part. */
811 std::vector
<variant_field
> variants
;
813 /* True if we're currently reading a variant. */
814 bool processing_variant
= false;
819 int accessibility
= 0;
821 /* Variant parts need to find the discriminant, which is a DIE
822 reference. We track the section offset of each field to make
825 struct field field
{};
830 const char *name
= nullptr;
831 std::vector
<struct fn_field
> fnfields
;
834 /* The routines that read and process dies for a C struct or C++ class
835 pass lists of data member fields and lists of member function fields
836 in an instance of a field_info structure, as defined below. */
839 /* List of data member and baseclasses fields. */
840 std::vector
<struct nextfield
> fields
;
841 std::vector
<struct nextfield
> baseclasses
;
843 /* Set if the accessibility of one of the fields is not public. */
844 bool non_public_fields
= false;
846 /* Member function fieldlist array, contains name of possibly overloaded
847 member function, number of overloaded member functions and a pointer
848 to the head of the member function field chain. */
849 std::vector
<struct fnfieldlist
> fnfieldlists
;
851 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
852 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
853 std::vector
<struct decl_field
> typedef_field_list
;
855 /* Nested types defined by this class and the number of elements in this
857 std::vector
<struct decl_field
> nested_types_list
;
859 /* If non-null, this is the variant part we are currently
861 variant_part_builder
*current_variant_part
= nullptr;
862 /* This holds all the top-level variant parts attached to the type
864 std::vector
<variant_part_builder
> variant_parts
;
866 /* Return the total number of fields (including baseclasses). */
869 return fields
.size () + baseclasses
.size ();
873 /* Loaded secondary compilation units are kept in memory until they
874 have not been referenced for the processing of this many
875 compilation units. Set this to zero to disable caching. Cache
876 sizes of up to at least twenty will improve startup time for
877 typical inter-CU-reference binaries, at an obvious memory cost. */
878 static int dwarf_max_cache_age
= 5;
880 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
881 struct cmd_list_element
*c
, const char *value
)
883 gdb_printf (file
, _("The upper bound on the age of cached "
884 "DWARF compilation units is %s.\n"),
888 /* local function prototypes */
890 static void dwarf2_find_base_address (struct die_info
*die
,
891 struct dwarf2_cu
*cu
);
893 class cooked_index_storage
;
894 static void build_type_psymtabs_reader (cutu_reader
*reader
,
895 cooked_index_storage
*storage
);
897 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
899 static void var_decode_location (struct attribute
*attr
,
901 struct dwarf2_cu
*cu
);
903 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
905 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
907 const struct attr_abbrev
*,
910 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
911 struct attribute
*attr
, dwarf_tag tag
);
913 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
915 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
916 dwarf2_section_info
*, sect_offset
);
918 static const char *read_indirect_string
919 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
920 const struct comp_unit_head
*, unsigned int *);
922 static const char *read_indirect_string_at_offset
923 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
925 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
929 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
932 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
935 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
938 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
939 struct dwarf2_cu
*cu
);
941 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
943 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
944 struct dwarf2_cu
*cu
);
946 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
948 static struct die_info
*die_specification (struct die_info
*die
,
949 struct dwarf2_cu
**);
951 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
952 struct dwarf2_cu
*cu
,
953 const char *comp_dir
);
955 static void dwarf_decode_lines (struct line_header
*,
957 CORE_ADDR
, int decode_mapping
);
959 static void dwarf2_start_subfile (dwarf2_cu
*cu
, const file_entry
&fe
,
960 const line_header
&lh
);
962 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
963 struct dwarf2_cu
*, struct symbol
* = NULL
);
965 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
968 static void dwarf2_const_value_attr (const struct attribute
*attr
,
971 struct obstack
*obstack
,
972 struct dwarf2_cu
*cu
, LONGEST
*value
,
973 const gdb_byte
**bytes
,
974 struct dwarf2_locexpr_baton
**baton
);
976 static struct type
*read_subrange_index_type (struct die_info
*die
,
977 struct dwarf2_cu
*cu
);
979 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
981 static int need_gnat_info (struct dwarf2_cu
*);
983 static struct type
*die_descriptive_type (struct die_info
*,
986 static void set_descriptive_type (struct type
*, struct die_info
*,
989 static struct type
*die_containing_type (struct die_info
*,
992 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
995 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
997 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
999 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1001 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1002 const char *suffix
, int physname
,
1003 struct dwarf2_cu
*cu
);
1005 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1007 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1009 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1011 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1013 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1015 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1017 /* Return the .debug_loclists section to use for cu. */
1018 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1020 /* Return the .debug_rnglists section to use for cu. */
1021 static struct dwarf2_section_info
*cu_debug_rnglists_section
1022 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1024 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1025 values. Keep the items ordered with increasing constraints compliance. */
1028 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1029 PC_BOUNDS_NOT_PRESENT
,
1031 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1032 were present but they do not form a valid range of PC addresses. */
1035 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1038 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1042 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1043 CORE_ADDR
*, CORE_ADDR
*,
1048 static void get_scope_pc_bounds (struct die_info
*,
1049 CORE_ADDR
*, CORE_ADDR
*,
1050 struct dwarf2_cu
*);
1052 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1053 CORE_ADDR
, struct dwarf2_cu
*);
1055 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1056 struct dwarf2_cu
*);
1058 static void dwarf2_attach_fields_to_type (struct field_info
*,
1059 struct type
*, struct dwarf2_cu
*);
1061 static void dwarf2_add_member_fn (struct field_info
*,
1062 struct die_info
*, struct type
*,
1063 struct dwarf2_cu
*);
1065 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1067 struct dwarf2_cu
*);
1069 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1071 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1073 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1075 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1077 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1079 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1081 static bool read_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1083 static struct type
*read_module_type (struct die_info
*die
,
1084 struct dwarf2_cu
*cu
);
1086 static const char *namespace_name (struct die_info
*die
,
1087 int *is_anonymous
, struct dwarf2_cu
*);
1089 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1091 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1094 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1095 struct dwarf2_cu
*);
1097 static struct die_info
*read_die_and_siblings_1
1098 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1101 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1102 const gdb_byte
*info_ptr
,
1103 const gdb_byte
**new_info_ptr
,
1104 struct die_info
*parent
);
1106 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1107 struct die_info
**, const gdb_byte
*,
1110 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1111 struct die_info
**, const gdb_byte
*);
1113 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1115 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1118 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1120 static const char *dwarf2_full_name (const char *name
,
1121 struct die_info
*die
,
1122 struct dwarf2_cu
*cu
);
1124 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1125 struct dwarf2_cu
*cu
);
1127 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1128 struct dwarf2_cu
**);
1130 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1132 static void dump_die_for_error (struct die_info
*);
1134 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1137 /*static*/ void dump_die (struct die_info
*, int max_level
);
1139 static void store_in_ref_table (struct die_info
*,
1140 struct dwarf2_cu
*);
1142 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1143 const struct attribute
*,
1144 struct dwarf2_cu
**);
1146 static struct die_info
*follow_die_ref (struct die_info
*,
1147 const struct attribute
*,
1148 struct dwarf2_cu
**);
1150 static struct die_info
*follow_die_sig (struct die_info
*,
1151 const struct attribute
*,
1152 struct dwarf2_cu
**);
1154 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1155 struct dwarf2_cu
*);
1157 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1158 const struct attribute
*,
1159 struct dwarf2_cu
*);
1161 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1162 dwarf2_per_objfile
*per_objfile
);
1164 static void read_signatured_type (signatured_type
*sig_type
,
1165 dwarf2_per_objfile
*per_objfile
);
1167 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1168 struct die_info
*die
, struct dwarf2_cu
*cu
,
1169 struct dynamic_prop
*prop
, struct type
*type
);
1171 /* memory allocation interface */
1173 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1175 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1177 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1179 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1180 struct dwarf2_loclist_baton
*baton
,
1181 const struct attribute
*attr
);
1183 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1185 struct dwarf2_cu
*cu
,
1188 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1189 const gdb_byte
*info_ptr
,
1190 const struct abbrev_info
*abbrev
,
1191 bool do_skip_children
= true);
1193 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1194 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1195 dwarf2_per_bfd
*per_bfd
);
1197 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1198 struct die_info
*comp_unit_die
,
1199 enum language pretend_language
);
1201 static struct type
*set_die_type (struct die_info
*, struct type
*,
1202 struct dwarf2_cu
*, bool = false);
1204 static void create_all_units (dwarf2_per_objfile
*per_objfile
);
1206 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1207 dwarf2_per_objfile
*per_objfile
,
1208 dwarf2_cu
*existing_cu
,
1210 enum language pretend_language
);
1212 static void process_full_comp_unit (dwarf2_cu
*cu
,
1213 enum language pretend_language
);
1215 static void process_full_type_unit (dwarf2_cu
*cu
,
1216 enum language pretend_language
);
1218 static struct type
*get_die_type_at_offset (sect_offset
,
1219 dwarf2_per_cu_data
*per_cu
,
1220 dwarf2_per_objfile
*per_objfile
);
1222 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1224 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1225 dwarf2_per_objfile
*per_objfile
,
1226 enum language pretend_language
);
1228 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1230 /* Class, the destructor of which frees all allocated queue entries. This
1231 will only have work to do if an error was thrown while processing the
1232 dwarf. If no error was thrown then the queue entries should have all
1233 been processed, and freed, as we went along. */
1235 class dwarf2_queue_guard
1238 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1239 : m_per_objfile (per_objfile
)
1241 gdb_assert (!m_per_objfile
->queue
.has_value ());
1243 m_per_objfile
->queue
.emplace ();
1246 /* Free any entries remaining on the queue. There should only be
1247 entries left if we hit an error while processing the dwarf. */
1248 ~dwarf2_queue_guard ()
1250 gdb_assert (m_per_objfile
->queue
.has_value ());
1252 m_per_objfile
->queue
.reset ();
1255 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1258 dwarf2_per_objfile
*m_per_objfile
;
1261 dwarf2_queue_item::~dwarf2_queue_item ()
1263 /* Anything still marked queued is likely to be in an
1264 inconsistent state, so discard it. */
1267 per_objfile
->remove_cu (per_cu
);
1272 /* See dwarf2/read.h. */
1275 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1277 if (data
->is_debug_types
)
1278 delete static_cast<signatured_type
*> (data
);
1283 static file_and_directory
&find_file_and_directory
1284 (struct die_info
*die
, struct dwarf2_cu
*cu
);
1286 static const char *compute_include_file_name
1287 (const struct line_header
*lh
,
1288 const file_entry
&fe
,
1289 const file_and_directory
&cu_info
,
1290 std::string
&name_holder
);
1292 static htab_up
allocate_signatured_type_table ();
1294 static htab_up
allocate_dwo_unit_table ();
1296 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1297 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1298 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1300 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1302 static struct dwo_unit
*lookup_dwo_comp_unit
1303 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1304 ULONGEST signature
);
1306 static struct dwo_unit
*lookup_dwo_type_unit
1307 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1309 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1311 /* A unique pointer to a dwo_file. */
1313 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1315 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1317 static void check_producer (struct dwarf2_cu
*cu
);
1319 /* Various complaints about symbol reading that don't abort the process. */
1322 dwarf2_debug_line_missing_file_complaint (void)
1324 complaint (_(".debug_line section has line data without a file"));
1328 dwarf2_debug_line_missing_end_sequence_complaint (void)
1330 complaint (_(".debug_line section has line "
1331 "program sequence without an end"));
1335 dwarf2_complex_location_expr_complaint (void)
1337 complaint (_("location expression too complex"));
1341 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1344 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1349 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1351 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1355 /* Hash function for line_header_hash. */
1358 line_header_hash (const struct line_header
*ofs
)
1360 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1363 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1366 line_header_hash_voidp (const void *item
)
1368 const struct line_header
*ofs
= (const struct line_header
*) item
;
1370 return line_header_hash (ofs
);
1373 /* Equality function for line_header_hash. */
1376 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1378 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1379 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1381 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1382 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1387 /* An iterator for all_units that is based on index. This
1388 approach makes it possible to iterate over all_units safely,
1389 when some caller in the loop may add new units. */
1391 class all_units_iterator
1395 all_units_iterator (dwarf2_per_bfd
*per_bfd
, bool start
)
1396 : m_per_bfd (per_bfd
),
1397 m_index (start
? 0 : per_bfd
->all_units
.size ())
1401 all_units_iterator
&operator++ ()
1407 dwarf2_per_cu_data
*operator* () const
1409 return m_per_bfd
->get_cu (m_index
);
1412 bool operator== (const all_units_iterator
&other
) const
1414 return m_index
== other
.m_index
;
1418 bool operator!= (const all_units_iterator
&other
) const
1420 return m_index
!= other
.m_index
;
1425 dwarf2_per_bfd
*m_per_bfd
;
1429 /* A range adapter for the all_units_iterator. */
1430 class all_units_range
1434 all_units_range (dwarf2_per_bfd
*per_bfd
)
1435 : m_per_bfd (per_bfd
)
1439 all_units_iterator
begin ()
1441 return all_units_iterator (m_per_bfd
, true);
1444 all_units_iterator
end ()
1446 return all_units_iterator (m_per_bfd
, false);
1451 dwarf2_per_bfd
*m_per_bfd
;
1454 /* See declaration. */
1456 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1459 can_copy (can_copy_
)
1462 names
= &dwarf2_elf_names
;
1464 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1465 locate_sections (obfd
, sec
, *names
);
1468 dwarf2_per_bfd::~dwarf2_per_bfd ()
1470 for (auto &per_cu
: all_units
)
1472 per_cu
->imported_symtabs_free ();
1473 per_cu
->free_cached_file_names ();
1476 /* Everything else should be on this->obstack. */
1482 dwarf2_per_objfile::remove_all_cus ()
1484 gdb_assert (!queue
.has_value ());
1486 m_dwarf2_cus
.clear ();
1489 /* A helper class that calls free_cached_comp_units on
1492 class free_cached_comp_units
1496 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1497 : m_per_objfile (per_objfile
)
1501 ~free_cached_comp_units ()
1503 m_per_objfile
->remove_all_cus ();
1506 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1510 dwarf2_per_objfile
*m_per_objfile
;
1516 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1518 if (per_cu
->index
< this->m_symtabs
.size ())
1519 return this->m_symtabs
[per_cu
->index
] != nullptr;
1526 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1528 if (per_cu
->index
< this->m_symtabs
.size ())
1529 return this->m_symtabs
[per_cu
->index
];
1536 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1537 compunit_symtab
*symtab
)
1539 if (per_cu
->index
>= this->m_symtabs
.size ())
1540 this->m_symtabs
.resize (per_cu
->index
+ 1);
1541 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1542 this->m_symtabs
[per_cu
->index
] = symtab
;
1545 /* Try to locate the sections we need for DWARF 2 debugging
1546 information and return true if we have enough to do something.
1547 NAMES points to the dwarf2 section names, or is NULL if the standard
1548 ELF names are used. CAN_COPY is true for formats where symbol
1549 interposition is possible and so symbol values must follow copy
1550 relocation rules. */
1553 dwarf2_has_info (struct objfile
*objfile
,
1554 const struct dwarf2_debug_sections
*names
,
1557 if (objfile
->flags
& OBJF_READNEVER
)
1560 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1562 if (per_objfile
== NULL
)
1564 dwarf2_per_bfd
*per_bfd
;
1566 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1567 BFD doesn't require relocations.
1569 We don't share with objfiles for which -readnow was requested,
1570 because it would complicate things when loading the same BFD with
1571 -readnow and then without -readnow. */
1572 if (!gdb_bfd_requires_relocations (objfile
->obfd
.get ())
1573 && (objfile
->flags
& OBJF_READNOW
) == 0)
1575 /* See if one has been created for this BFD yet. */
1576 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
.get ());
1578 if (per_bfd
== nullptr)
1580 /* No, create it now. */
1581 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
.get (), names
,
1583 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
.get (), per_bfd
);
1588 /* No sharing possible, create one specifically for this objfile. */
1589 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
.get (), names
, can_copy
);
1590 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1593 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1596 return (!per_objfile
->per_bfd
->info
.is_virtual
1597 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1598 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1599 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1602 /* See declaration. */
1605 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1606 const dwarf2_debug_sections
&names
)
1608 flagword aflag
= bfd_section_flags (sectp
);
1610 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1613 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1614 > bfd_get_file_size (abfd
))
1616 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1617 warning (_("Discarding section %s which has a section size (%s"
1618 ") larger than the file size [in module %s]"),
1619 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1620 bfd_get_filename (abfd
));
1622 else if (names
.info
.matches (sectp
->name
))
1624 this->info
.s
.section
= sectp
;
1625 this->info
.size
= bfd_section_size (sectp
);
1627 else if (names
.abbrev
.matches (sectp
->name
))
1629 this->abbrev
.s
.section
= sectp
;
1630 this->abbrev
.size
= bfd_section_size (sectp
);
1632 else if (names
.line
.matches (sectp
->name
))
1634 this->line
.s
.section
= sectp
;
1635 this->line
.size
= bfd_section_size (sectp
);
1637 else if (names
.loc
.matches (sectp
->name
))
1639 this->loc
.s
.section
= sectp
;
1640 this->loc
.size
= bfd_section_size (sectp
);
1642 else if (names
.loclists
.matches (sectp
->name
))
1644 this->loclists
.s
.section
= sectp
;
1645 this->loclists
.size
= bfd_section_size (sectp
);
1647 else if (names
.macinfo
.matches (sectp
->name
))
1649 this->macinfo
.s
.section
= sectp
;
1650 this->macinfo
.size
= bfd_section_size (sectp
);
1652 else if (names
.macro
.matches (sectp
->name
))
1654 this->macro
.s
.section
= sectp
;
1655 this->macro
.size
= bfd_section_size (sectp
);
1657 else if (names
.str
.matches (sectp
->name
))
1659 this->str
.s
.section
= sectp
;
1660 this->str
.size
= bfd_section_size (sectp
);
1662 else if (names
.str_offsets
.matches (sectp
->name
))
1664 this->str_offsets
.s
.section
= sectp
;
1665 this->str_offsets
.size
= bfd_section_size (sectp
);
1667 else if (names
.line_str
.matches (sectp
->name
))
1669 this->line_str
.s
.section
= sectp
;
1670 this->line_str
.size
= bfd_section_size (sectp
);
1672 else if (names
.addr
.matches (sectp
->name
))
1674 this->addr
.s
.section
= sectp
;
1675 this->addr
.size
= bfd_section_size (sectp
);
1677 else if (names
.frame
.matches (sectp
->name
))
1679 this->frame
.s
.section
= sectp
;
1680 this->frame
.size
= bfd_section_size (sectp
);
1682 else if (names
.eh_frame
.matches (sectp
->name
))
1684 this->eh_frame
.s
.section
= sectp
;
1685 this->eh_frame
.size
= bfd_section_size (sectp
);
1687 else if (names
.ranges
.matches (sectp
->name
))
1689 this->ranges
.s
.section
= sectp
;
1690 this->ranges
.size
= bfd_section_size (sectp
);
1692 else if (names
.rnglists
.matches (sectp
->name
))
1694 this->rnglists
.s
.section
= sectp
;
1695 this->rnglists
.size
= bfd_section_size (sectp
);
1697 else if (names
.types
.matches (sectp
->name
))
1699 struct dwarf2_section_info type_section
;
1701 memset (&type_section
, 0, sizeof (type_section
));
1702 type_section
.s
.section
= sectp
;
1703 type_section
.size
= bfd_section_size (sectp
);
1705 this->types
.push_back (type_section
);
1707 else if (names
.gdb_index
.matches (sectp
->name
))
1709 this->gdb_index
.s
.section
= sectp
;
1710 this->gdb_index
.size
= bfd_section_size (sectp
);
1712 else if (names
.debug_names
.matches (sectp
->name
))
1714 this->debug_names
.s
.section
= sectp
;
1715 this->debug_names
.size
= bfd_section_size (sectp
);
1717 else if (names
.debug_aranges
.matches (sectp
->name
))
1719 this->debug_aranges
.s
.section
= sectp
;
1720 this->debug_aranges
.size
= bfd_section_size (sectp
);
1723 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1724 && bfd_section_vma (sectp
) == 0)
1725 this->has_section_at_zero
= true;
1728 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1732 dwarf2_get_section_info (struct objfile
*objfile
,
1733 enum dwarf2_section_enum sect
,
1734 asection
**sectp
, const gdb_byte
**bufp
,
1735 bfd_size_type
*sizep
)
1737 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1738 struct dwarf2_section_info
*info
;
1740 /* We may see an objfile without any DWARF, in which case we just
1742 if (per_objfile
== NULL
)
1751 case DWARF2_DEBUG_FRAME
:
1752 info
= &per_objfile
->per_bfd
->frame
;
1754 case DWARF2_EH_FRAME
:
1755 info
= &per_objfile
->per_bfd
->eh_frame
;
1758 gdb_assert_not_reached ("unexpected section");
1761 info
->read (objfile
);
1763 *sectp
= info
->get_bfd_section ();
1764 *bufp
= info
->buffer
;
1765 *sizep
= info
->size
;
1768 /* See dwarf2/read.h. */
1771 dwarf2_per_bfd::map_info_sections (struct objfile
*objfile
)
1773 info
.read (objfile
);
1774 abbrev
.read (objfile
);
1775 line
.read (objfile
);
1777 str_offsets
.read (objfile
);
1778 line_str
.read (objfile
);
1779 ranges
.read (objfile
);
1780 rnglists
.read (objfile
);
1781 addr
.read (objfile
);
1783 for (auto §ion
: types
)
1784 section
.read (objfile
);
1788 /* DWARF quick_symbol_functions support. */
1790 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1791 unique line tables, so we maintain a separate table of all .debug_line
1792 derived entries to support the sharing.
1793 All the quick functions need is the list of file names. We discard the
1794 line_header when we're done and don't need to record it here. */
1795 struct quick_file_names
1797 /* The data used to construct the hash key. */
1798 struct stmt_list_hash hash
;
1800 /* The number of entries in file_names, real_names. */
1801 unsigned int num_file_names
;
1803 /* The CU directory, as given by DW_AT_comp_dir. May be
1805 const char *comp_dir
;
1807 /* The file names from the line table, after being run through
1809 const char **file_names
;
1811 /* The file names from the line table after being run through
1812 gdb_realpath. These are computed lazily. */
1813 const char **real_names
;
1816 struct dwarf2_base_index_functions
: public quick_symbol_functions
1818 bool has_symbols (struct objfile
*objfile
) override
;
1820 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
1822 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
1824 void forget_cached_source_info (struct objfile
*objfile
) override
;
1826 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
1829 bool *symbol_found_p
) override
1831 *symbol_found_p
= false;
1832 return language_unknown
;
1835 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
1837 void expand_all_symtabs (struct objfile
*objfile
) override
;
1839 /* A helper function that finds the per-cu object from an "adjusted"
1840 PC -- a PC with the base text offset removed. */
1841 virtual dwarf2_per_cu_data
*find_per_cu (dwarf2_per_bfd
*per_bfd
,
1842 CORE_ADDR adjusted_pc
);
1844 struct compunit_symtab
*find_pc_sect_compunit_symtab
1845 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
1846 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
)
1849 struct compunit_symtab
*find_compunit_symtab_by_address
1850 (struct objfile
*objfile
, CORE_ADDR address
) override
1855 void map_symbol_filenames (struct objfile
*objfile
,
1856 gdb::function_view
<symbol_filename_ftype
> fun
,
1857 bool need_fullname
) override
;
1860 /* With OBJF_READNOW, the DWARF reader expands all CUs immediately.
1861 It's handy in this case to have an empty implementation of the
1862 quick symbol functions, to avoid special cases in the rest of the
1865 struct readnow_functions
: public dwarf2_base_index_functions
1867 void dump (struct objfile
*objfile
) override
1871 void expand_matching_symbols
1873 const lookup_name_info
&lookup_name
,
1876 symbol_compare_ftype
*ordered_compare
) override
1880 bool expand_symtabs_matching
1881 (struct objfile
*objfile
,
1882 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1883 const lookup_name_info
*lookup_name
,
1884 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1885 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1886 block_search_flags search_flags
,
1888 enum search_domain kind
) override
1894 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
1896 void dump (struct objfile
*objfile
) override
;
1898 void expand_matching_symbols
1900 const lookup_name_info
&lookup_name
,
1903 symbol_compare_ftype
*ordered_compare
) override
;
1905 bool expand_symtabs_matching
1906 (struct objfile
*objfile
,
1907 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1908 const lookup_name_info
*lookup_name
,
1909 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1910 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1911 block_search_flags search_flags
,
1913 enum search_domain kind
) override
;
1916 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
1918 void dump (struct objfile
*objfile
) override
;
1920 void expand_matching_symbols
1922 const lookup_name_info
&lookup_name
,
1925 symbol_compare_ftype
*ordered_compare
) override
;
1927 bool expand_symtabs_matching
1928 (struct objfile
*objfile
,
1929 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1930 const lookup_name_info
*lookup_name
,
1931 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1932 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1933 block_search_flags search_flags
,
1935 enum search_domain kind
) override
;
1938 quick_symbol_functions_up
1939 mapped_index::make_quick_functions () const
1941 return quick_symbol_functions_up (new dwarf2_gdb_index
);
1944 quick_symbol_functions_up
1945 mapped_debug_names::make_quick_functions () const
1947 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
1950 /* Utility hash function for a stmt_list_hash. */
1953 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
1957 if (stmt_list_hash
->dwo_unit
!= NULL
)
1958 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
1959 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
1963 /* Utility equality function for a stmt_list_hash. */
1966 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
1967 const struct stmt_list_hash
*rhs
)
1969 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
1971 if (lhs
->dwo_unit
!= NULL
1972 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
1975 return lhs
->line_sect_off
== rhs
->line_sect_off
;
1978 /* Hash function for a quick_file_names. */
1981 hash_file_name_entry (const void *e
)
1983 const struct quick_file_names
*file_data
1984 = (const struct quick_file_names
*) e
;
1986 return hash_stmt_list_entry (&file_data
->hash
);
1989 /* Equality function for a quick_file_names. */
1992 eq_file_name_entry (const void *a
, const void *b
)
1994 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
1995 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
1997 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2000 /* Create a quick_file_names hash table. */
2003 create_quick_file_names_table (unsigned int nr_initial_entries
)
2005 return htab_up (htab_create_alloc (nr_initial_entries
,
2006 hash_file_name_entry
, eq_file_name_entry
,
2007 nullptr, xcalloc
, xfree
));
2010 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2011 function is unrelated to symtabs, symtab would have to be created afterwards.
2012 You should call age_cached_comp_units after processing the CU. */
2015 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2018 if (per_cu
->is_debug_types
)
2019 load_full_type_unit (per_cu
, per_objfile
);
2021 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2022 skip_partial
, language_minimal
);
2024 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2026 return nullptr; /* Dummy CU. */
2028 dwarf2_find_base_address (cu
->dies
, cu
);
2033 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2036 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2037 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2040 /* The destructor of dwarf2_queue_guard frees any entries left on
2041 the queue. After this point we're guaranteed to leave this function
2042 with the dwarf queue empty. */
2043 dwarf2_queue_guard
q_guard (per_objfile
);
2045 if (!per_objfile
->symtab_set_p (per_cu
))
2047 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2048 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2050 /* If we just loaded a CU from a DWO, and we're working with an index
2051 that may badly handle TUs, load all the TUs in that DWO as well.
2052 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2053 if (!per_cu
->is_debug_types
2055 && cu
->dwo_unit
!= NULL
2056 && per_objfile
->per_bfd
->index_table
!= NULL
2057 && !per_objfile
->per_bfd
->index_table
->version_check ()
2058 /* DWP files aren't supported yet. */
2059 && get_dwp_file (per_objfile
) == NULL
)
2060 queue_and_load_all_dwo_tus (cu
);
2063 process_queue (per_objfile
);
2066 /* Age the cache, releasing compilation units that have not
2067 been used recently. */
2068 per_objfile
->age_comp_units ();
2071 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2072 the per-objfile for which this symtab is instantiated.
2074 Returns the resulting symbol table. */
2076 static struct compunit_symtab
*
2077 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2078 dwarf2_per_objfile
*per_objfile
,
2081 if (!per_objfile
->symtab_set_p (per_cu
))
2083 free_cached_comp_units
freer (per_objfile
);
2084 scoped_restore decrementer
= increment_reading_symtab ();
2085 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2086 process_cu_includes (per_objfile
);
2089 return per_objfile
->get_symtab (per_cu
);
2094 dwarf2_per_cu_data_up
2095 dwarf2_per_bfd::allocate_per_cu ()
2097 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2098 result
->per_bfd
= this;
2099 result
->index
= all_units
.size ();
2106 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2108 signatured_type_up
result (new signatured_type (signature
));
2109 result
->per_bfd
= this;
2110 result
->index
= all_units
.size ();
2111 result
->is_debug_types
= true;
2116 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2117 obstack, and constructed with the specified field values. */
2119 static dwarf2_per_cu_data_up
2120 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2121 struct dwarf2_section_info
*section
,
2123 sect_offset sect_off
, ULONGEST length
)
2125 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2126 the_cu
->sect_off
= sect_off
;
2127 the_cu
->set_length (length
);
2128 the_cu
->section
= section
;
2129 the_cu
->is_dwz
= is_dwz
;
2133 /* A helper for create_cus_from_index that handles a given list of
2137 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2138 const gdb_byte
*cu_list
, offset_type n_elements
,
2139 struct dwarf2_section_info
*section
,
2142 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2144 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2146 sect_offset sect_off
2147 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2148 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2151 dwarf2_per_cu_data_up per_cu
2152 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2154 per_bfd
->all_units
.push_back (std::move (per_cu
));
2158 /* Read the CU list from the mapped index, and use it to create all
2159 the CU objects for PER_BFD. */
2162 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2163 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2164 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2166 gdb_assert (per_bfd
->all_units
.empty ());
2167 per_bfd
->all_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2169 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2172 if (dwz_elements
== 0)
2175 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2176 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2180 /* Create the signatured type hash table from the index. */
2183 create_signatured_type_table_from_index
2184 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2185 const gdb_byte
*bytes
, offset_type elements
)
2187 htab_up sig_types_hash
= allocate_signatured_type_table ();
2189 for (offset_type i
= 0; i
< elements
; i
+= 3)
2191 signatured_type_up sig_type
;
2194 cu_offset type_offset_in_tu
;
2196 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2197 sect_offset sect_off
2198 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2200 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2202 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2205 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2206 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2207 sig_type
->section
= section
;
2208 sig_type
->sect_off
= sect_off
;
2210 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2211 *slot
= sig_type
.get ();
2213 per_bfd
->all_units
.emplace_back (sig_type
.release ());
2216 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2219 /* Create the signatured type hash table from .debug_names. */
2222 create_signatured_type_table_from_debug_names
2223 (dwarf2_per_objfile
*per_objfile
,
2224 const mapped_debug_names
&map
,
2225 struct dwarf2_section_info
*section
,
2226 struct dwarf2_section_info
*abbrev_section
)
2228 struct objfile
*objfile
= per_objfile
->objfile
;
2230 section
->read (objfile
);
2231 abbrev_section
->read (objfile
);
2233 htab_up sig_types_hash
= allocate_signatured_type_table ();
2235 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2237 signatured_type_up sig_type
;
2240 sect_offset sect_off
2241 = (sect_offset
) (extract_unsigned_integer
2242 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2244 map
.dwarf5_byte_order
));
2246 comp_unit_head cu_header
;
2247 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2249 section
->buffer
+ to_underlying (sect_off
),
2252 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2253 (cu_header
.signature
);
2254 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2255 sig_type
->section
= section
;
2256 sig_type
->sect_off
= sect_off
;
2258 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2259 *slot
= sig_type
.get ();
2261 per_objfile
->per_bfd
->all_units
.emplace_back (sig_type
.release ());
2264 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2267 /* Read the address map data from the mapped index, and use it to
2268 populate the index_addrmap. */
2271 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2272 struct mapped_index
*index
)
2274 struct objfile
*objfile
= per_objfile
->objfile
;
2275 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2276 struct gdbarch
*gdbarch
= objfile
->arch ();
2277 const gdb_byte
*iter
, *end
;
2280 addrmap_mutable mutable_map
;
2282 iter
= index
->address_table
.data ();
2283 end
= iter
+ index
->address_table
.size ();
2285 baseaddr
= objfile
->text_section_offset ();
2289 ULONGEST hi
, lo
, cu_index
;
2290 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2292 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2294 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2299 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2300 hex_string (lo
), hex_string (hi
));
2304 if (cu_index
>= per_bfd
->all_units
.size ())
2306 complaint (_(".gdb_index address table has invalid CU number %u"),
2307 (unsigned) cu_index
);
2311 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2312 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2313 mutable_map
.set_empty (lo
, hi
- 1, per_bfd
->get_cu (cu_index
));
2316 per_bfd
->index_addrmap
2317 = new (&per_bfd
->obstack
) addrmap_fixed (&per_bfd
->obstack
, &mutable_map
);
2320 /* Read the address map data from DWARF-5 .debug_aranges, and use it
2321 to populate given addrmap. Returns true on success, false on
2325 read_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2326 struct dwarf2_section_info
*section
,
2327 addrmap
*mutable_map
)
2329 struct objfile
*objfile
= per_objfile
->objfile
;
2330 bfd
*abfd
= objfile
->obfd
.get ();
2331 struct gdbarch
*gdbarch
= objfile
->arch ();
2332 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2333 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2335 std::unordered_map
<sect_offset
,
2336 dwarf2_per_cu_data
*,
2337 gdb::hash_enum
<sect_offset
>>
2338 debug_info_offset_to_per_cu
;
2339 for (const auto &per_cu
: per_bfd
->all_units
)
2341 /* A TU will not need aranges, and skipping them here is an easy
2342 way of ignoring .debug_types -- and possibly seeing a
2343 duplicate section offset -- entirely. The same applies to
2344 units coming from a dwz file. */
2345 if (per_cu
->is_debug_types
|| per_cu
->is_dwz
)
2348 const auto insertpair
2349 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2352 /* Assume no duplicate offsets in all_units. */
2353 gdb_assert (insertpair
.second
);
2356 std::set
<sect_offset
> debug_info_offset_seen
;
2358 section
->read (objfile
);
2360 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2362 const gdb_byte
*addr
= section
->buffer
;
2364 while (addr
< section
->buffer
+ section
->size
)
2366 const gdb_byte
*const entry_addr
= addr
;
2367 unsigned int bytes_read
;
2369 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2373 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2374 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2375 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2376 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2378 warning (_("Section .debug_aranges in %s entry at offset %s "
2379 "length %s exceeds section length %s, "
2380 "ignoring .debug_aranges."),
2381 objfile_name (objfile
),
2382 plongest (entry_addr
- section
->buffer
),
2383 plongest (bytes_read
+ entry_length
),
2384 pulongest (section
->size
));
2388 /* The version number. */
2389 const uint16_t version
= read_2_bytes (abfd
, addr
);
2393 warning (_("Section .debug_aranges in %s entry at offset %s "
2394 "has unsupported version %d, ignoring .debug_aranges."),
2395 objfile_name (objfile
),
2396 plongest (entry_addr
- section
->buffer
), version
);
2400 const uint64_t debug_info_offset
2401 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2402 addr
+= offset_size
;
2403 const auto per_cu_it
2404 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2405 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2407 warning (_("Section .debug_aranges in %s entry at offset %s "
2408 "debug_info_offset %s does not exists, "
2409 "ignoring .debug_aranges."),
2410 objfile_name (objfile
),
2411 plongest (entry_addr
- section
->buffer
),
2412 pulongest (debug_info_offset
));
2415 const auto insertpair
2416 = debug_info_offset_seen
.insert (sect_offset (debug_info_offset
));
2417 if (!insertpair
.second
)
2419 warning (_("Section .debug_aranges in %s has duplicate "
2420 "debug_info_offset %s, ignoring .debug_aranges."),
2421 objfile_name (objfile
),
2422 sect_offset_str (sect_offset (debug_info_offset
)));
2425 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2427 const uint8_t address_size
= *addr
++;
2428 if (address_size
< 1 || address_size
> 8)
2430 warning (_("Section .debug_aranges in %s entry at offset %s "
2431 "address_size %u is invalid, ignoring .debug_aranges."),
2432 objfile_name (objfile
),
2433 plongest (entry_addr
- section
->buffer
), address_size
);
2437 const uint8_t segment_selector_size
= *addr
++;
2438 if (segment_selector_size
!= 0)
2440 warning (_("Section .debug_aranges in %s entry at offset %s "
2441 "segment_selector_size %u is not supported, "
2442 "ignoring .debug_aranges."),
2443 objfile_name (objfile
),
2444 plongest (entry_addr
- section
->buffer
),
2445 segment_selector_size
);
2449 /* Must pad to an alignment boundary that is twice the address
2450 size. It is undocumented by the DWARF standard but GCC does
2451 use it. However, not every compiler does this. We can see
2452 whether it has happened by looking at the total length of the
2453 contents of the aranges for this CU -- it if isn't a multiple
2454 of twice the address size, then we skip any leftover
2456 addr
+= (entry_end
- addr
) % (2 * address_size
);
2458 while (addr
< entry_end
)
2460 if (addr
+ 2 * address_size
> entry_end
)
2462 warning (_("Section .debug_aranges in %s entry at offset %s "
2463 "address list is not properly terminated, "
2464 "ignoring .debug_aranges."),
2465 objfile_name (objfile
),
2466 plongest (entry_addr
- section
->buffer
));
2469 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2471 addr
+= address_size
;
2472 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2474 addr
+= address_size
;
2475 if (start
== 0 && length
== 0)
2477 /* This can happen on some targets with --gc-sections.
2478 This pair of values is also used to mark the end of
2479 the entries for a given CU, but we ignore it and
2480 instead handle termination using the check at the top
2484 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2486 /* Symbol was eliminated due to a COMDAT group. */
2489 ULONGEST end
= start
+ length
;
2490 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2492 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2494 mutable_map
->set_empty (start
, end
- 1, per_cu
);
2497 per_cu
->addresses_seen
= true;
2503 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2504 populate the index_addrmap. */
2507 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2508 struct dwarf2_section_info
*section
)
2510 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2512 addrmap_mutable mutable_map
;
2514 if (read_addrmap_from_aranges (per_objfile
, section
, &mutable_map
))
2515 per_bfd
->index_addrmap
2516 = new (&per_bfd
->obstack
) addrmap_fixed (&per_bfd
->obstack
,
2520 /* A helper function that reads the .gdb_index from BUFFER and fills
2521 in MAP. FILENAME is the name of the file containing the data;
2522 it is used for error reporting. DEPRECATED_OK is true if it is
2523 ok to use deprecated sections.
2525 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2526 out parameters that are filled in with information about the CU and
2527 TU lists in the section.
2529 Returns true if all went well, false otherwise. */
2532 read_gdb_index_from_buffer (const char *filename
,
2534 gdb::array_view
<const gdb_byte
> buffer
,
2535 struct mapped_index
*map
,
2536 const gdb_byte
**cu_list
,
2537 offset_type
*cu_list_elements
,
2538 const gdb_byte
**types_list
,
2539 offset_type
*types_list_elements
)
2541 const gdb_byte
*addr
= &buffer
[0];
2542 offset_view
metadata (buffer
);
2544 /* Version check. */
2545 offset_type version
= metadata
[0];
2546 /* Versions earlier than 3 emitted every copy of a psymbol. This
2547 causes the index to behave very poorly for certain requests. Version 3
2548 contained incomplete addrmap. So, it seems better to just ignore such
2552 static int warning_printed
= 0;
2553 if (!warning_printed
)
2555 warning (_("Skipping obsolete .gdb_index section in %s."),
2557 warning_printed
= 1;
2561 /* Index version 4 uses a different hash function than index version
2564 Versions earlier than 6 did not emit psymbols for inlined
2565 functions. Using these files will cause GDB not to be able to
2566 set breakpoints on inlined functions by name, so we ignore these
2567 indices unless the user has done
2568 "set use-deprecated-index-sections on". */
2569 if (version
< 6 && !deprecated_ok
)
2571 static int warning_printed
= 0;
2572 if (!warning_printed
)
2575 Skipping deprecated .gdb_index section in %s.\n\
2576 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2577 to use the section anyway."),
2579 warning_printed
= 1;
2583 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2584 of the TU (for symbols coming from TUs),
2585 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2586 Plus gold-generated indices can have duplicate entries for global symbols,
2587 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2588 These are just performance bugs, and we can't distinguish gdb-generated
2589 indices from gold-generated ones, so issue no warning here. */
2591 /* Indexes with higher version than the one supported by GDB may be no
2592 longer backward compatible. */
2596 map
->version
= version
;
2599 *cu_list
= addr
+ metadata
[i
];
2600 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2603 *types_list
= addr
+ metadata
[i
];
2604 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2607 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2608 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2610 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2613 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2614 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2616 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2620 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2622 if (map
->constant_pool
.empty () && !map
->symbol_table
.empty ())
2624 /* An empty constant pool implies that all symbol table entries are
2625 empty. Make map->symbol_table.empty () == true. */
2627 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2634 static void finalize_all_units (dwarf2_per_bfd
*per_bfd
);
2636 /* Callback types for dwarf2_read_gdb_index. */
2638 typedef gdb::function_view
2639 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2640 get_gdb_index_contents_ftype
;
2641 typedef gdb::function_view
2642 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2643 get_gdb_index_contents_dwz_ftype
;
2645 /* Read .gdb_index. If everything went ok, initialize the "quick"
2646 elements of all the CUs and return 1. Otherwise, return 0. */
2649 dwarf2_read_gdb_index
2650 (dwarf2_per_objfile
*per_objfile
,
2651 get_gdb_index_contents_ftype get_gdb_index_contents
,
2652 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2654 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2655 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2656 struct dwz_file
*dwz
;
2657 struct objfile
*objfile
= per_objfile
->objfile
;
2658 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2660 gdb::array_view
<const gdb_byte
> main_index_contents
2661 = get_gdb_index_contents (objfile
, per_bfd
);
2663 if (main_index_contents
.empty ())
2666 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2667 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2668 use_deprecated_index_sections
,
2669 main_index_contents
, map
.get (), &cu_list
,
2670 &cu_list_elements
, &types_list
,
2671 &types_list_elements
))
2674 /* Don't use the index if it's empty. */
2675 if (map
->symbol_table
.empty ())
2678 /* If there is a .dwz file, read it so we can get its CU list as
2680 dwz
= dwarf2_get_dwz_file (per_bfd
);
2683 struct mapped_index dwz_map
;
2684 const gdb_byte
*dwz_types_ignore
;
2685 offset_type dwz_types_elements_ignore
;
2687 gdb::array_view
<const gdb_byte
> dwz_index_content
2688 = get_gdb_index_contents_dwz (objfile
, dwz
);
2690 if (dwz_index_content
.empty ())
2693 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2694 1, dwz_index_content
, &dwz_map
,
2695 &dwz_list
, &dwz_list_elements
,
2697 &dwz_types_elements_ignore
))
2699 warning (_("could not read '.gdb_index' section from %s; skipping"),
2700 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2705 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2708 if (types_list_elements
)
2710 /* We can only handle a single .debug_types when we have an
2712 if (per_bfd
->types
.size () > 1)
2714 per_bfd
->all_units
.clear ();
2718 dwarf2_section_info
*section
2719 = (per_bfd
->types
.size () == 1
2720 ? &per_bfd
->types
[0]
2723 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2724 types_list_elements
);
2727 finalize_all_units (per_bfd
);
2729 create_addrmap_from_index (per_objfile
, map
.get ());
2731 per_bfd
->index_table
= std::move (map
);
2732 per_bfd
->quick_file_names_table
=
2733 create_quick_file_names_table (per_bfd
->all_units
.size ());
2738 /* die_reader_func for dw2_get_file_names. */
2741 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2742 struct die_info
*comp_unit_die
)
2744 struct dwarf2_cu
*cu
= reader
->cu
;
2745 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2746 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2747 struct dwarf2_per_cu_data
*lh_cu
;
2748 struct attribute
*attr
;
2750 struct quick_file_names
*qfn
;
2752 gdb_assert (! this_cu
->is_debug_types
);
2754 this_cu
->files_read
= true;
2755 /* Our callers never want to match partial units -- instead they
2756 will match the enclosing full CU. */
2757 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2764 sect_offset line_offset
{};
2766 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
2768 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2769 if (attr
!= nullptr && attr
->form_is_unsigned ())
2771 struct quick_file_names find_entry
;
2773 line_offset
= (sect_offset
) attr
->as_unsigned ();
2775 /* We may have already read in this line header (TU line header sharing).
2776 If we have we're done. */
2777 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2778 find_entry
.hash
.line_sect_off
= line_offset
;
2779 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2780 &find_entry
, INSERT
);
2783 lh_cu
->file_names
= (struct quick_file_names
*) *slot
;
2787 lh
= dwarf_decode_line_header (line_offset
, cu
, fnd
.get_comp_dir ());
2791 if (!fnd
.is_unknown ())
2793 else if (lh
== nullptr)
2796 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
2797 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2798 qfn
->hash
.line_sect_off
= line_offset
;
2799 /* There may not be a DW_AT_stmt_list. */
2800 if (slot
!= nullptr)
2803 std::vector
<const char *> include_names
;
2806 for (const auto &entry
: lh
->file_names ())
2808 std::string name_holder
;
2809 const char *include_name
=
2810 compute_include_file_name (lh
.get (), entry
, fnd
, name_holder
);
2811 if (include_name
!= nullptr)
2813 include_name
= per_objfile
->objfile
->intern (include_name
);
2814 include_names
.push_back (include_name
);
2819 qfn
->num_file_names
= offset
+ include_names
.size ();
2820 qfn
->comp_dir
= fnd
.intern_comp_dir (per_objfile
->objfile
);
2822 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
2823 qfn
->num_file_names
);
2825 qfn
->file_names
[0] = per_objfile
->objfile
->intern (fnd
.get_name ());
2827 if (!include_names
.empty ())
2828 memcpy (&qfn
->file_names
[offset
], include_names
.data (),
2829 include_names
.size () * sizeof (const char *));
2831 qfn
->real_names
= NULL
;
2833 lh_cu
->file_names
= qfn
;
2836 /* A helper for the "quick" functions which attempts to read the line
2837 table for THIS_CU. */
2839 static struct quick_file_names
*
2840 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
2841 dwarf2_per_objfile
*per_objfile
)
2843 /* This should never be called for TUs. */
2844 gdb_assert (! this_cu
->is_debug_types
);
2846 if (this_cu
->files_read
)
2847 return this_cu
->file_names
;
2849 cutu_reader
reader (this_cu
, per_objfile
);
2850 if (!reader
.dummy_p
)
2851 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
2853 return this_cu
->file_names
;
2856 /* A helper for the "quick" functions which computes and caches the
2857 real path for a given file name from the line table. */
2860 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
2861 struct quick_file_names
*qfn
, int index
)
2863 if (qfn
->real_names
== NULL
)
2864 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
2865 qfn
->num_file_names
, const char *);
2867 if (qfn
->real_names
[index
] == NULL
)
2869 const char *dirname
= nullptr;
2871 if (!IS_ABSOLUTE_PATH (qfn
->file_names
[index
]))
2872 dirname
= qfn
->comp_dir
;
2874 gdb::unique_xmalloc_ptr
<char> fullname
;
2875 fullname
= find_source_or_rewrite (qfn
->file_names
[index
], dirname
);
2877 qfn
->real_names
[index
] = fullname
.release ();
2880 return qfn
->real_names
[index
];
2884 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
2886 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2887 dwarf2_per_cu_data
*dwarf_cu
2888 = per_objfile
->per_bfd
->all_units
.back ().get ();
2889 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
2894 return cust
->primary_filetab ();
2900 dwarf2_per_cu_data::free_cached_file_names ()
2903 fnd
->forget_fullname ();
2905 if (per_bfd
== nullptr)
2908 struct quick_file_names
*file_data
= file_names
;
2909 if (file_data
!= nullptr && file_data
->real_names
!= nullptr)
2911 for (int i
= 0; i
< file_data
->num_file_names
; ++i
)
2913 xfree ((void *) file_data
->real_names
[i
]);
2914 file_data
->real_names
[i
] = nullptr;
2920 dwarf2_base_index_functions::forget_cached_source_info
2921 (struct objfile
*objfile
)
2923 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2925 for (auto &per_cu
: per_objfile
->per_bfd
->all_units
)
2926 per_cu
->free_cached_file_names ();
2929 /* Struct used to manage iterating over all CUs looking for a symbol. */
2931 struct dw2_symtab_iterator
2933 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
2934 dwarf2_per_objfile
*per_objfile
;
2935 /* If set, only look for symbols that match that block. Valid values are
2936 GLOBAL_BLOCK and STATIC_BLOCK. */
2937 gdb::optional
<block_enum
> block_index
;
2938 /* The kind of symbol we're looking for. */
2940 /* The list of CUs from the index entry of the symbol,
2941 or NULL if not found. */
2943 /* The next element in VEC to look at. */
2945 /* The number of elements in VEC, or zero if there is no match. */
2947 /* Have we seen a global version of the symbol?
2948 If so we can ignore all further global instances.
2949 This is to work around gold/15646, inefficient gold-generated
2954 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
2957 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
2958 dwarf2_per_objfile
*per_objfile
,
2959 gdb::optional
<block_enum
> block_index
,
2960 domain_enum domain
, offset_type namei
,
2961 mapped_index
&index
)
2963 iter
->per_objfile
= per_objfile
;
2964 iter
->block_index
= block_index
;
2965 iter
->domain
= domain
;
2967 iter
->global_seen
= 0;
2971 gdb_assert (!index
.symbol_name_slot_invalid (namei
));
2972 offset_type vec_idx
= index
.symbol_vec_index (namei
);
2974 iter
->vec
= offset_view (index
.constant_pool
.slice (vec_idx
));
2975 iter
->length
= iter
->vec
[0];
2978 /* Return the next matching CU or NULL if there are no more. */
2980 static struct dwarf2_per_cu_data
*
2981 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
,
2982 mapped_index
&index
)
2984 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
2986 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
2988 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
2989 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
2990 gdb_index_symbol_kind symbol_kind
=
2991 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
2992 /* Only check the symbol attributes if they're present.
2993 Indices prior to version 7 don't record them,
2994 and indices >= 7 may elide them for certain symbols
2995 (gold does this). */
2996 int attrs_valid
= (index
.version
>= 7
2997 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
2999 /* Don't crash on bad data. */
3000 if (cu_index
>= per_objfile
->per_bfd
->all_units
.size ())
3002 complaint (_(".gdb_index entry has bad CU index"
3003 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3007 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3009 /* Skip if already read in. */
3010 if (per_objfile
->symtab_set_p (per_cu
))
3013 /* Check static vs global. */
3016 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3018 if (iter
->block_index
.has_value ())
3020 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3022 if (is_static
!= want_static
)
3026 /* Work around gold/15646. */
3028 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3030 if (iter
->global_seen
)
3033 iter
->global_seen
= 1;
3037 /* Only check the symbol's kind if it has one. */
3040 switch (iter
->domain
)
3043 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3044 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3045 /* Some types are also in VAR_DOMAIN. */
3046 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3050 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3054 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3058 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3074 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3080 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3081 int total
= per_objfile
->per_bfd
->all_units
.size ();
3084 for (int i
= 0; i
< total
; ++i
)
3086 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3088 if (!per_objfile
->symtab_set_p (per_cu
))
3091 gdb_printf (_(" Number of read CUs: %d\n"), total
- count
);
3092 gdb_printf (_(" Number of unread CUs: %d\n"), count
);
3095 /* This dumps minimal information about the index.
3096 It is called via "mt print objfiles".
3097 One use is to verify .gdb_index has been loaded by the
3098 gdb.dwarf2/gdb-index.exp testcase. */
3101 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3103 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3105 mapped_index
*index
= (gdb::checked_static_cast
<mapped_index
*>
3106 (per_objfile
->per_bfd
->index_table
.get ()));
3107 gdb_printf (".gdb_index: version %d\n", index
->version
);
3112 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3114 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3115 int total_units
= per_objfile
->per_bfd
->all_units
.size ();
3117 for (int i
= 0; i
< total_units
; ++i
)
3119 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3121 /* We don't want to directly expand a partial CU, because if we
3122 read it with the wrong language, then assertion failures can
3123 be triggered later on. See PR symtab/23010. So, tell
3124 dw2_instantiate_symtab to skip partial CUs -- any important
3125 partial CU will be read via DW_TAG_imported_unit anyway. */
3126 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3131 dw2_expand_symtabs_matching_symbol
3132 (mapped_index_base
&index
,
3133 const lookup_name_info
&lookup_name_in
,
3134 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3135 gdb::function_view
<bool (offset_type
)> match_callback
,
3136 dwarf2_per_objfile
*per_objfile
);
3139 dw2_expand_symtabs_matching_one
3140 (dwarf2_per_cu_data
*per_cu
,
3141 dwarf2_per_objfile
*per_objfile
,
3142 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3143 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3146 dwarf2_gdb_index::expand_matching_symbols
3147 (struct objfile
*objfile
,
3148 const lookup_name_info
&name
, domain_enum domain
,
3150 symbol_compare_ftype
*ordered_compare
)
3153 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3155 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3158 = *(gdb::checked_static_cast
<mapped_index
*>
3159 (per_objfile
->per_bfd
->index_table
.get ()));
3161 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3162 auto matcher
= [&] (const char *symname
)
3164 if (ordered_compare
== nullptr)
3166 return ordered_compare (symname
, match_name
) == 0;
3169 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3170 [&] (offset_type namei
)
3172 struct dw2_symtab_iterator iter
;
3173 struct dwarf2_per_cu_data
*per_cu
;
3175 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
, namei
,
3177 while ((per_cu
= dw2_symtab_iter_next (&iter
, index
)) != NULL
)
3178 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3184 /* Starting from a search name, return the string that finds the upper
3185 bound of all strings that start with SEARCH_NAME in a sorted name
3186 list. Returns the empty string to indicate that the upper bound is
3187 the end of the list. */
3190 make_sort_after_prefix_name (const char *search_name
)
3192 /* When looking to complete "func", we find the upper bound of all
3193 symbols that start with "func" by looking for where we'd insert
3194 the closest string that would follow "func" in lexicographical
3195 order. Usually, that's "func"-with-last-character-incremented,
3196 i.e. "fund". Mind non-ASCII characters, though. Usually those
3197 will be UTF-8 multi-byte sequences, but we can't be certain.
3198 Especially mind the 0xff character, which is a valid character in
3199 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3200 rule out compilers allowing it in identifiers. Note that
3201 conveniently, strcmp/strcasecmp are specified to compare
3202 characters interpreted as unsigned char. So what we do is treat
3203 the whole string as a base 256 number composed of a sequence of
3204 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3205 to 0, and carries 1 to the following more-significant position.
3206 If the very first character in SEARCH_NAME ends up incremented
3207 and carries/overflows, then the upper bound is the end of the
3208 list. The string after the empty string is also the empty
3211 Some examples of this operation:
3213 SEARCH_NAME => "+1" RESULT
3217 "\xff" "a" "\xff" => "\xff" "b"
3222 Then, with these symbols for example:
3228 completing "func" looks for symbols between "func" and
3229 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3230 which finds "func" and "func1", but not "fund".
3234 funcÿ (Latin1 'ÿ' [0xff])
3238 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3239 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3243 ÿÿ (Latin1 'ÿ' [0xff])
3246 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3247 the end of the list.
3249 std::string after
= search_name
;
3250 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3252 if (!after
.empty ())
3253 after
.back () = (unsigned char) after
.back () + 1;
3257 /* See declaration. */
3259 std::pair
<std::vector
<name_component
>::const_iterator
,
3260 std::vector
<name_component
>::const_iterator
>
3261 mapped_index_base::find_name_components_bounds
3262 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3263 dwarf2_per_objfile
*per_objfile
) const
3266 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3268 const char *lang_name
3269 = lookup_name_without_params
.language_lookup_name (lang
);
3271 /* Comparison function object for lower_bound that matches against a
3272 given symbol name. */
3273 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3276 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3277 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3278 return name_cmp (elem_name
, name
) < 0;
3281 /* Comparison function object for upper_bound that matches against a
3282 given symbol name. */
3283 auto lookup_compare_upper
= [&] (const char *name
,
3284 const name_component
&elem
)
3286 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3287 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3288 return name_cmp (name
, elem_name
) < 0;
3291 auto begin
= this->name_components
.begin ();
3292 auto end
= this->name_components
.end ();
3294 /* Find the lower bound. */
3297 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3300 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3303 /* Find the upper bound. */
3306 if (lookup_name_without_params
.completion_mode ())
3308 /* In completion mode, we want UPPER to point past all
3309 symbols names that have the same prefix. I.e., with
3310 these symbols, and completing "func":
3312 function << lower bound
3314 other_function << upper bound
3316 We find the upper bound by looking for the insertion
3317 point of "func"-with-last-character-incremented,
3319 std::string after
= make_sort_after_prefix_name (lang_name
);
3322 return std::lower_bound (lower
, end
, after
.c_str (),
3323 lookup_compare_lower
);
3326 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3329 return {lower
, upper
};
3332 /* See declaration. */
3335 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3337 if (!this->name_components
.empty ())
3340 this->name_components_casing
= case_sensitivity
;
3342 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3344 /* The code below only knows how to break apart components of C++
3345 symbol names (and other languages that use '::' as
3346 namespace/module separator) and Ada symbol names. */
3347 auto count
= this->symbol_name_count ();
3348 for (offset_type idx
= 0; idx
< count
; idx
++)
3350 if (this->symbol_name_slot_invalid (idx
))
3353 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3355 /* Add each name component to the name component table. */
3356 unsigned int previous_len
= 0;
3358 if (strstr (name
, "::") != nullptr)
3360 for (unsigned int current_len
= cp_find_first_component (name
);
3361 name
[current_len
] != '\0';
3362 current_len
+= cp_find_first_component (name
+ current_len
))
3364 gdb_assert (name
[current_len
] == ':');
3365 this->name_components
.push_back ({previous_len
, idx
});
3366 /* Skip the '::'. */
3368 previous_len
= current_len
;
3373 /* Handle the Ada encoded (aka mangled) form here. */
3374 for (const char *iter
= strstr (name
, "__");
3376 iter
= strstr (iter
, "__"))
3378 this->name_components
.push_back ({previous_len
, idx
});
3380 previous_len
= iter
- name
;
3384 this->name_components
.push_back ({previous_len
, idx
});
3387 /* Sort name_components elements by name. */
3388 auto name_comp_compare
= [&] (const name_component
&left
,
3389 const name_component
&right
)
3391 const char *left_qualified
3392 = this->symbol_name_at (left
.idx
, per_objfile
);
3393 const char *right_qualified
3394 = this->symbol_name_at (right
.idx
, per_objfile
);
3396 const char *left_name
= left_qualified
+ left
.name_offset
;
3397 const char *right_name
= right_qualified
+ right
.name_offset
;
3399 return name_cmp (left_name
, right_name
) < 0;
3402 std::sort (this->name_components
.begin (),
3403 this->name_components
.end (),
3407 /* Helper for dw2_expand_symtabs_matching that works with a
3408 mapped_index_base instead of the containing objfile. This is split
3409 to a separate function in order to be able to unit test the
3410 name_components matching using a mock mapped_index_base. For each
3411 symbol name that matches, calls MATCH_CALLBACK, passing it the
3412 symbol's index in the mapped_index_base symbol table. */
3415 dw2_expand_symtabs_matching_symbol
3416 (mapped_index_base
&index
,
3417 const lookup_name_info
&lookup_name_in
,
3418 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3419 gdb::function_view
<bool (offset_type
)> match_callback
,
3420 dwarf2_per_objfile
*per_objfile
)
3422 lookup_name_info lookup_name_without_params
3423 = lookup_name_in
.make_ignore_params ();
3425 /* Build the symbol name component sorted vector, if we haven't
3427 index
.build_name_components (per_objfile
);
3429 /* The same symbol may appear more than once in the range though.
3430 E.g., if we're looking for symbols that complete "w", and we have
3431 a symbol named "w1::w2", we'll find the two name components for
3432 that same symbol in the range. To be sure we only call the
3433 callback once per symbol, we first collect the symbol name
3434 indexes that matched in a temporary vector and ignore
3436 std::vector
<offset_type
> matches
;
3438 struct name_and_matcher
3440 symbol_name_matcher_ftype
*matcher
;
3443 bool operator== (const name_and_matcher
&other
) const
3445 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3449 /* A vector holding all the different symbol name matchers, for all
3451 std::vector
<name_and_matcher
> matchers
;
3453 for (int i
= 0; i
< nr_languages
; i
++)
3455 enum language lang_e
= (enum language
) i
;
3457 const language_defn
*lang
= language_def (lang_e
);
3458 symbol_name_matcher_ftype
*name_matcher
3459 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3461 name_and_matcher key
{
3463 lookup_name_without_params
.language_lookup_name (lang_e
)
3466 /* Don't insert the same comparison routine more than once.
3467 Note that we do this linear walk. This is not a problem in
3468 practice because the number of supported languages is
3470 if (std::find (matchers
.begin (), matchers
.end (), key
)
3473 matchers
.push_back (std::move (key
));
3476 = index
.find_name_components_bounds (lookup_name_without_params
,
3477 lang_e
, per_objfile
);
3479 /* Now for each symbol name in range, check to see if we have a name
3480 match, and if so, call the MATCH_CALLBACK callback. */
3482 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3484 const char *qualified
3485 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3487 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3488 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3491 matches
.push_back (bounds
.first
->idx
);
3495 std::sort (matches
.begin (), matches
.end ());
3497 /* Finally call the callback, once per match. */
3500 for (offset_type idx
: matches
)
3504 if (!match_callback (idx
))
3513 /* Above we use a type wider than idx's for 'prev', since 0 and
3514 (offset_type)-1 are both possible values. */
3515 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3522 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3524 /* A mock .gdb_index/.debug_names-like name index table, enough to
3525 exercise dw2_expand_symtabs_matching_symbol, which works with the
3526 mapped_index_base interface. Builds an index from the symbol list
3527 passed as parameter to the constructor. */
3528 class mock_mapped_index
: public mapped_index_base
3531 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3532 : m_symbol_table (symbols
)
3535 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3537 /* Return the number of names in the symbol table. */
3538 size_t symbol_name_count () const override
3540 return m_symbol_table
.size ();
3543 /* Get the name of the symbol at IDX in the symbol table. */
3544 const char *symbol_name_at
3545 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3547 return m_symbol_table
[idx
];
3550 quick_symbol_functions_up
make_quick_functions () const override
3556 gdb::array_view
<const char *> m_symbol_table
;
3559 /* Convenience function that converts a NULL pointer to a "<null>"
3560 string, to pass to print routines. */
3563 string_or_null (const char *str
)
3565 return str
!= NULL
? str
: "<null>";
3568 /* Check if a lookup_name_info built from
3569 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3570 index. EXPECTED_LIST is the list of expected matches, in expected
3571 matching order. If no match expected, then an empty list is
3572 specified. Returns true on success. On failure prints a warning
3573 indicating the file:line that failed, and returns false. */
3576 check_match (const char *file
, int line
,
3577 mock_mapped_index
&mock_index
,
3578 const char *name
, symbol_name_match_type match_type
,
3579 bool completion_mode
,
3580 std::initializer_list
<const char *> expected_list
,
3581 dwarf2_per_objfile
*per_objfile
)
3583 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3585 bool matched
= true;
3587 auto mismatch
= [&] (const char *expected_str
,
3590 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3591 "expected=\"%s\", got=\"%s\"\n"),
3593 (match_type
== symbol_name_match_type::FULL
3595 name
, string_or_null (expected_str
), string_or_null (got
));
3599 auto expected_it
= expected_list
.begin ();
3600 auto expected_end
= expected_list
.end ();
3602 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3604 [&] (offset_type idx
)
3606 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3607 const char *expected_str
3608 = expected_it
== expected_end
? NULL
: *expected_it
++;
3610 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3611 mismatch (expected_str
, matched_name
);
3615 const char *expected_str
3616 = expected_it
== expected_end
? NULL
: *expected_it
++;
3617 if (expected_str
!= NULL
)
3618 mismatch (expected_str
, NULL
);
3623 /* The symbols added to the mock mapped_index for testing (in
3625 static const char *test_symbols
[] = {
3634 "ns2::tmpl<int>::foo2",
3635 "(anonymous namespace)::A::B::C",
3637 /* These are used to check that the increment-last-char in the
3638 matching algorithm for completion doesn't match "t1_fund" when
3639 completing "t1_func". */
3645 /* A UTF-8 name with multi-byte sequences to make sure that
3646 cp-name-parser understands this as a single identifier ("função"
3647 is "function" in PT). */
3650 /* Test a symbol name that ends with a 0xff character, which is a
3651 valid character in non-UTF-8 source character sets (e.g. Latin1
3652 'ÿ'), and we can't rule out compilers allowing it in identifiers.
3653 We test this because the completion algorithm finds the upper
3654 bound of symbols by looking for the insertion point of
3655 "func"-with-last-character-incremented, i.e. "fund", and adding 1
3656 to 0xff should wraparound and carry to the previous character.
3657 See comments in make_sort_after_prefix_name. */
3660 /* Some more symbols with \377 (0xff). See above. */
3664 /* A name with all sorts of complications. Starts with "z" to make
3665 it easier for the completion tests below. */
3666 #define Z_SYM_NAME \
3667 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3668 "::tuple<(anonymous namespace)::ui*, " \
3669 "std::default_delete<(anonymous namespace)::ui>, void>"
3674 /* Returns true if the mapped_index_base::find_name_component_bounds
3675 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3676 in completion mode. */
3679 check_find_bounds_finds (mapped_index_base
&index
,
3680 const char *search_name
,
3681 gdb::array_view
<const char *> expected_syms
,
3682 dwarf2_per_objfile
*per_objfile
)
3684 lookup_name_info
lookup_name (search_name
,
3685 symbol_name_match_type::FULL
, true);
3687 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3691 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3692 if (distance
!= expected_syms
.size ())
3695 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3697 auto nc_elem
= bounds
.first
+ exp_elem
;
3698 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3699 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3706 /* Test the lower-level mapped_index::find_name_component_bounds
3710 test_mapped_index_find_name_component_bounds ()
3712 mock_mapped_index
mock_index (test_symbols
);
3714 mock_index
.build_name_components (NULL
/* per_objfile */);
3716 /* Test the lower-level mapped_index::find_name_component_bounds
3717 method in completion mode. */
3719 static const char *expected_syms
[] = {
3724 SELF_CHECK (check_find_bounds_finds
3725 (mock_index
, "t1_func", expected_syms
,
3726 NULL
/* per_objfile */));
3729 /* Check that the increment-last-char in the name matching algorithm
3730 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. See
3731 make_sort_after_prefix_name. */
3733 static const char *expected_syms1
[] = {
3737 SELF_CHECK (check_find_bounds_finds
3738 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3740 static const char *expected_syms2
[] = {
3743 SELF_CHECK (check_find_bounds_finds
3744 (mock_index
, "\377\377", expected_syms2
,
3745 NULL
/* per_objfile */));
3749 /* Test dw2_expand_symtabs_matching_symbol. */
3752 test_dw2_expand_symtabs_matching_symbol ()
3754 mock_mapped_index
mock_index (test_symbols
);
3756 /* We let all tests run until the end even if some fails, for debug
3758 bool any_mismatch
= false;
3760 /* Create the expected symbols list (an initializer_list). Needed
3761 because lists have commas, and we need to pass them to CHECK,
3762 which is a macro. */
3763 #define EXPECT(...) { __VA_ARGS__ }
3765 /* Wrapper for check_match that passes down the current
3766 __FILE__/__LINE__. */
3767 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
3768 any_mismatch |= !check_match (__FILE__, __LINE__, \
3770 NAME, MATCH_TYPE, COMPLETION_MODE, \
3771 EXPECTED_LIST, NULL)
3773 /* Identity checks. */
3774 for (const char *sym
: test_symbols
)
3776 /* Should be able to match all existing symbols. */
3777 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
3780 /* Should be able to match all existing symbols with
3782 std::string with_params
= std::string (sym
) + "(int)";
3783 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3786 /* Should be able to match all existing symbols with
3787 parameters and qualifiers. */
3788 with_params
= std::string (sym
) + " ( int ) const";
3789 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3792 /* This should really find sym, but cp-name-parser.y doesn't
3793 know about lvalue/rvalue qualifiers yet. */
3794 with_params
= std::string (sym
) + " ( int ) &&";
3795 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3799 /* Check that the name matching algorithm for completion doesn't get
3800 confused with Latin1 'ÿ' / 0xff. See
3801 make_sort_after_prefix_name. */
3803 static const char str
[] = "\377";
3804 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3805 EXPECT ("\377", "\377\377123"));
3808 /* Check that the increment-last-char in the matching algorithm for
3809 completion doesn't match "t1_fund" when completing "t1_func". */
3811 static const char str
[] = "t1_func";
3812 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3813 EXPECT ("t1_func", "t1_func1"));
3816 /* Check that completion mode works at each prefix of the expected
3819 static const char str
[] = "function(int)";
3820 size_t len
= strlen (str
);
3823 for (size_t i
= 1; i
< len
; i
++)
3825 lookup
.assign (str
, i
);
3826 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3827 EXPECT ("function"));
3831 /* While "w" is a prefix of both components, the match function
3832 should still only be called once. */
3834 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
3836 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
3840 /* Same, with a "complicated" symbol. */
3842 static const char str
[] = Z_SYM_NAME
;
3843 size_t len
= strlen (str
);
3846 for (size_t i
= 1; i
< len
; i
++)
3848 lookup
.assign (str
, i
);
3849 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3850 EXPECT (Z_SYM_NAME
));
3854 /* In FULL mode, an incomplete symbol doesn't match. */
3856 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
3860 /* A complete symbol with parameters matches any overload, since the
3861 index has no overload info. */
3863 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
3864 EXPECT ("std::zfunction", "std::zfunction2"));
3865 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
3866 EXPECT ("std::zfunction", "std::zfunction2"));
3867 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
3868 EXPECT ("std::zfunction", "std::zfunction2"));
3871 /* Check that whitespace is ignored appropriately. A symbol with a
3872 template argument list. */
3874 static const char expected
[] = "ns::foo<int>";
3875 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
3877 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
3881 /* Check that whitespace is ignored appropriately. A symbol with a
3882 template argument list that includes a pointer. */
3884 static const char expected
[] = "ns::foo<char*>";
3885 /* Try both completion and non-completion modes. */
3886 static const bool completion_mode
[2] = {false, true};
3887 for (size_t i
= 0; i
< 2; i
++)
3889 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
3890 completion_mode
[i
], EXPECT (expected
));
3891 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
3892 completion_mode
[i
], EXPECT (expected
));
3894 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
3895 completion_mode
[i
], EXPECT (expected
));
3896 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
3897 completion_mode
[i
], EXPECT (expected
));
3902 /* Check method qualifiers are ignored. */
3903 static const char expected
[] = "ns::foo<char*>";
3904 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
3905 symbol_name_match_type::FULL
, true, EXPECT (expected
));
3906 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
3907 symbol_name_match_type::FULL
, true, EXPECT (expected
));
3908 CHECK_MATCH ("foo < char * > ( int ) const",
3909 symbol_name_match_type::WILD
, true, EXPECT (expected
));
3910 CHECK_MATCH ("foo < char * > ( int ) &&",
3911 symbol_name_match_type::WILD
, true, EXPECT (expected
));
3914 /* Test lookup names that don't match anything. */
3916 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
3919 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
3923 /* Some wild matching tests, exercising "(anonymous namespace)",
3924 which should not be confused with a parameter list. */
3926 static const char *syms
[] = {
3930 "A :: B :: C ( int )",
3935 for (const char *s
: syms
)
3937 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
3938 EXPECT ("(anonymous namespace)::A::B::C"));
3943 static const char expected
[] = "ns2::tmpl<int>::foo2";
3944 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
3946 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
3950 SELF_CHECK (!any_mismatch
);
3959 test_mapped_index_find_name_component_bounds ();
3960 test_dw2_expand_symtabs_matching_symbol ();
3963 }} // namespace selftests::dw2_expand_symtabs_matching
3965 #endif /* GDB_SELF_TEST */
3967 /* If FILE_MATCHER is NULL or if PER_CU has
3968 dwarf2_per_cu_quick_data::MARK set (see
3969 dw_expand_symtabs_matching_file_matcher), expand the CU and call
3970 EXPANSION_NOTIFY on it. */
3973 dw2_expand_symtabs_matching_one
3974 (dwarf2_per_cu_data
*per_cu
,
3975 dwarf2_per_objfile
*per_objfile
,
3976 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3977 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
3979 if (file_matcher
== NULL
|| per_cu
->mark
)
3981 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
3983 compunit_symtab
*symtab
3984 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3985 gdb_assert (symtab
!= nullptr);
3987 if (expansion_notify
!= NULL
&& symtab_was_null
)
3988 return expansion_notify (symtab
);
3993 /* Helper for dw2_expand_matching symtabs. Called on each symbol
3994 matched, to expand corresponding CUs that were marked. IDX is the
3995 index of the symbol name that matched. */
3998 dw2_expand_marked_cus
3999 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4000 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4001 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4002 block_search_flags search_flags
,
4005 offset_type vec_len
, vec_idx
;
4006 bool global_seen
= false;
4008 = *(gdb::checked_static_cast
<mapped_index
*>
4009 (per_objfile
->per_bfd
->index_table
.get ()));
4011 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4013 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4015 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4016 /* This value is only valid for index versions >= 7. */
4017 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4018 gdb_index_symbol_kind symbol_kind
=
4019 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4020 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4021 /* Only check the symbol attributes if they're present.
4022 Indices prior to version 7 don't record them,
4023 and indices >= 7 may elide them for certain symbols
4024 (gold does this). */
4027 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4029 /* Work around gold/15646. */
4032 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4040 /* Only check the symbol's kind if it has one. */
4045 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4050 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4056 case VARIABLES_DOMAIN
:
4057 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4060 case FUNCTIONS_DOMAIN
:
4061 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4065 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4068 case MODULES_DOMAIN
:
4069 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4077 /* Don't crash on bad data. */
4078 if (cu_index
>= per_objfile
->per_bfd
->all_units
.size ())
4080 complaint (_(".gdb_index entry has bad CU index"
4081 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4085 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4086 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4094 /* If FILE_MATCHER is non-NULL, set all the
4095 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4096 that match FILE_MATCHER. */
4099 dw_expand_symtabs_matching_file_matcher
4100 (dwarf2_per_objfile
*per_objfile
,
4101 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4103 if (file_matcher
== NULL
)
4106 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4108 NULL
, xcalloc
, xfree
));
4109 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4111 NULL
, xcalloc
, xfree
));
4113 /* The rule is CUs specify all the files, including those used by
4114 any TU, so there's no need to scan TUs here. */
4116 for (const auto &per_cu
: per_objfile
->per_bfd
->all_units
)
4120 if (per_cu
->is_debug_types
)
4124 /* We only need to look at symtabs not already expanded. */
4125 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4128 if (per_cu
->fnd
!= nullptr)
4130 file_and_directory
*fnd
= per_cu
->fnd
.get ();
4132 if (file_matcher (fnd
->get_name (), false))
4138 /* Before we invoke realpath, which can get expensive when many
4139 files are involved, do a quick comparison of the basenames. */
4140 if ((basenames_may_differ
4141 || file_matcher (lbasename (fnd
->get_name ()), true))
4142 && file_matcher (fnd
->get_fullname (), false))
4149 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4151 if (file_data
== NULL
)
4154 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4156 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4162 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4164 const char *this_real_name
;
4166 if (file_matcher (file_data
->file_names
[j
], false))
4172 /* Before we invoke realpath, which can get expensive when many
4173 files are involved, do a quick comparison of the basenames. */
4174 if (!basenames_may_differ
4175 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4179 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4180 if (file_matcher (this_real_name
, false))
4187 void **slot
= htab_find_slot (per_cu
->mark
4188 ? visited_found
.get ()
4189 : visited_not_found
.get (),
4196 dwarf2_gdb_index::expand_symtabs_matching
4197 (struct objfile
*objfile
,
4198 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4199 const lookup_name_info
*lookup_name
,
4200 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4201 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4202 block_search_flags search_flags
,
4204 enum search_domain kind
)
4206 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4208 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4210 /* This invariant is documented in quick-functions.h. */
4211 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
4212 if (lookup_name
== nullptr)
4214 for (dwarf2_per_cu_data
*per_cu
4215 : all_units_range (per_objfile
->per_bfd
))
4219 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4228 = *(gdb::checked_static_cast
<mapped_index
*>
4229 (per_objfile
->per_bfd
->index_table
.get ()));
4232 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4234 [&] (offset_type idx
)
4236 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4237 expansion_notify
, search_flags
, kind
))
4245 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4248 static struct compunit_symtab
*
4249 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4254 if (cust
->blockvector () != nullptr
4255 && blockvector_contains_pc (cust
->blockvector (), pc
))
4258 if (cust
->includes
== NULL
)
4261 for (i
= 0; cust
->includes
[i
]; ++i
)
4263 struct compunit_symtab
*s
= cust
->includes
[i
];
4265 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4273 dwarf2_per_cu_data
*
4274 dwarf2_base_index_functions::find_per_cu (dwarf2_per_bfd
*per_bfd
,
4275 CORE_ADDR adjusted_pc
)
4277 if (per_bfd
->index_addrmap
== nullptr)
4279 return ((struct dwarf2_per_cu_data
*)
4280 per_bfd
->index_addrmap
->find (adjusted_pc
));
4283 struct compunit_symtab
*
4284 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4285 (struct objfile
*objfile
,
4286 struct bound_minimal_symbol msymbol
,
4288 struct obj_section
*section
,
4291 struct compunit_symtab
*result
;
4293 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4295 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4296 struct dwarf2_per_cu_data
*data
= find_per_cu (per_objfile
->per_bfd
,
4298 if (data
== nullptr)
4301 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4302 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4303 paddress (objfile
->arch (), pc
));
4305 result
= recursively_find_pc_sect_compunit_symtab
4306 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4308 if (warn_if_readin
&& result
== nullptr)
4309 warning (_("(Error: pc %s in address map, but not in symtab.)"),
4310 paddress (objfile
->arch (), pc
));
4316 dwarf2_base_index_functions::map_symbol_filenames
4317 (struct objfile
*objfile
,
4318 gdb::function_view
<symbol_filename_ftype
> fun
,
4321 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4323 /* Use caches to ensure we only call FUN once for each filename. */
4324 filename_seen_cache filenames_cache
;
4325 std::unordered_set
<quick_file_names
*> qfn_cache
;
4327 /* The rule is CUs specify all the files, including those used by any TU,
4328 so there's no need to scan TUs here. We can ignore file names coming
4329 from already-expanded CUs. It is possible that an expanded CU might
4330 reuse the file names data from a currently unexpanded CU, in this
4331 case we don't want to report the files from the unexpanded CU. */
4333 for (const auto &per_cu
: per_objfile
->per_bfd
->all_units
)
4335 if (!per_cu
->is_debug_types
4336 && per_objfile
->symtab_set_p (per_cu
.get ()))
4338 if (per_cu
->file_names
!= nullptr)
4339 qfn_cache
.insert (per_cu
->file_names
);
4343 for (dwarf2_per_cu_data
*per_cu
4344 : all_units_range (per_objfile
->per_bfd
))
4346 /* We only need to look at symtabs not already expanded. */
4347 if (per_cu
->is_debug_types
|| per_objfile
->symtab_set_p (per_cu
))
4350 if (per_cu
->fnd
!= nullptr)
4352 file_and_directory
*fnd
= per_cu
->fnd
.get ();
4354 const char *filename
= fnd
->get_name ();
4355 const char *key
= filename
;
4356 const char *fullname
= nullptr;
4360 fullname
= fnd
->get_fullname ();
4364 if (!filenames_cache
.seen (key
))
4365 fun (filename
, fullname
);
4368 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4369 if (file_data
== nullptr
4370 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4373 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4375 const char *filename
= file_data
->file_names
[j
];
4376 const char *key
= filename
;
4377 const char *fullname
= nullptr;
4381 fullname
= dw2_get_real_path (per_objfile
, file_data
, j
);
4385 if (!filenames_cache
.seen (key
))
4386 fun (filename
, fullname
);
4392 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4397 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
4400 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
4402 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4404 for (const auto &per_cu
: per_objfile
->per_bfd
->all_units
)
4406 /* Is this already expanded? */
4407 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4410 /* It has not yet been expanded. */
4417 /* DWARF-5 debug_names reader. */
4419 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4420 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4422 /* A helper function that reads the .debug_names section in SECTION
4423 and fills in MAP. FILENAME is the name of the file containing the
4424 section; it is used for error reporting.
4426 Returns true if all went well, false otherwise. */
4429 read_debug_names_from_section (struct objfile
*objfile
,
4430 const char *filename
,
4431 struct dwarf2_section_info
*section
,
4432 mapped_debug_names
&map
)
4434 if (section
->empty ())
4437 /* Older elfutils strip versions could keep the section in the main
4438 executable while splitting it for the separate debug info file. */
4439 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4442 section
->read (objfile
);
4444 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4446 const gdb_byte
*addr
= section
->buffer
;
4448 bfd
*const abfd
= section
->get_bfd_owner ();
4450 unsigned int bytes_read
;
4451 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4454 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4455 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4456 if (bytes_read
+ length
!= section
->size
)
4458 /* There may be multiple per-CU indices. */
4459 warning (_("Section .debug_names in %s length %s does not match "
4460 "section length %s, ignoring .debug_names."),
4461 filename
, plongest (bytes_read
+ length
),
4462 pulongest (section
->size
));
4466 /* The version number. */
4467 uint16_t version
= read_2_bytes (abfd
, addr
);
4471 warning (_("Section .debug_names in %s has unsupported version %d, "
4472 "ignoring .debug_names."),
4478 uint16_t padding
= read_2_bytes (abfd
, addr
);
4482 warning (_("Section .debug_names in %s has unsupported padding %d, "
4483 "ignoring .debug_names."),
4488 /* comp_unit_count - The number of CUs in the CU list. */
4489 map
.cu_count
= read_4_bytes (abfd
, addr
);
4492 /* local_type_unit_count - The number of TUs in the local TU
4494 map
.tu_count
= read_4_bytes (abfd
, addr
);
4497 /* foreign_type_unit_count - The number of TUs in the foreign TU
4499 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4501 if (foreign_tu_count
!= 0)
4503 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4504 "ignoring .debug_names."),
4505 filename
, static_cast<unsigned long> (foreign_tu_count
));
4509 /* bucket_count - The number of hash buckets in the hash lookup
4511 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4514 /* name_count - The number of unique names in the index. */
4515 map
.name_count
= read_4_bytes (abfd
, addr
);
4518 /* abbrev_table_size - The size in bytes of the abbreviations
4520 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4523 /* augmentation_string_size - The size in bytes of the augmentation
4524 string. This value is rounded up to a multiple of 4. */
4525 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4527 map
.augmentation_is_gdb
= ((augmentation_string_size
4528 == sizeof (dwarf5_augmentation
))
4529 && memcmp (addr
, dwarf5_augmentation
,
4530 sizeof (dwarf5_augmentation
)) == 0);
4531 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4532 addr
+= augmentation_string_size
;
4535 map
.cu_table_reordered
= addr
;
4536 addr
+= map
.cu_count
* map
.offset_size
;
4538 /* List of Local TUs */
4539 map
.tu_table_reordered
= addr
;
4540 addr
+= map
.tu_count
* map
.offset_size
;
4542 /* Hash Lookup Table */
4543 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4544 addr
+= map
.bucket_count
* 4;
4545 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4546 addr
+= map
.name_count
* 4;
4549 map
.name_table_string_offs_reordered
= addr
;
4550 addr
+= map
.name_count
* map
.offset_size
;
4551 map
.name_table_entry_offs_reordered
= addr
;
4552 addr
+= map
.name_count
* map
.offset_size
;
4554 const gdb_byte
*abbrev_table_start
= addr
;
4557 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4562 const auto insertpair
4563 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4564 if (!insertpair
.second
)
4566 warning (_("Section .debug_names in %s has duplicate index %s, "
4567 "ignoring .debug_names."),
4568 filename
, pulongest (index_num
));
4571 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4572 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4577 mapped_debug_names::index_val::attr attr
;
4578 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4580 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4582 if (attr
.form
== DW_FORM_implicit_const
)
4584 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4588 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4590 indexval
.attr_vec
.push_back (std::move (attr
));
4593 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4595 warning (_("Section .debug_names in %s has abbreviation_table "
4596 "of size %s vs. written as %u, ignoring .debug_names."),
4597 filename
, plongest (addr
- abbrev_table_start
),
4601 map
.entry_pool
= addr
;
4606 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4610 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4611 const mapped_debug_names
&map
,
4612 dwarf2_section_info
§ion
,
4615 if (!map
.augmentation_is_gdb
)
4617 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4619 sect_offset sect_off
4620 = (sect_offset
) (extract_unsigned_integer
4621 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4623 map
.dwarf5_byte_order
));
4624 /* We don't know the length of the CU, because the CU list in a
4625 .debug_names index can be incomplete, so we can't use the start
4626 of the next CU as end of this CU. We create the CUs here with
4627 length 0, and in cutu_reader::cutu_reader we'll fill in the
4629 dwarf2_per_cu_data_up per_cu
4630 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4632 per_bfd
->all_units
.push_back (std::move (per_cu
));
4637 sect_offset sect_off_prev
;
4638 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4640 sect_offset sect_off_next
;
4641 if (i
< map
.cu_count
)
4644 = (sect_offset
) (extract_unsigned_integer
4645 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4647 map
.dwarf5_byte_order
));
4650 sect_off_next
= (sect_offset
) section
.size
;
4653 if (sect_off_next
== sect_off_prev
)
4655 warning (_("Section .debug_names has duplicate entry in CU table,"
4656 " ignoring .debug_names."));
4659 if (sect_off_next
< sect_off_prev
)
4661 warning (_("Section .debug_names has non-ascending CU table,"
4662 " ignoring .debug_names."));
4665 /* Note: we're not using length = sect_off_next - sect_off_prev,
4666 to gracefully handle an incomplete CU list. */
4667 const ULONGEST length
= 0;
4668 dwarf2_per_cu_data_up per_cu
4669 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4670 sect_off_prev
, length
);
4671 per_bfd
->all_units
.push_back (std::move (per_cu
));
4673 sect_off_prev
= sect_off_next
;
4679 /* Read the CU list from the mapped index, and use it to create all
4680 the CU objects for this dwarf2_per_objfile. */
4683 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4684 const mapped_debug_names
&map
,
4685 const mapped_debug_names
&dwz_map
)
4687 gdb_assert (per_bfd
->all_units
.empty ());
4688 per_bfd
->all_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4690 if (!create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4691 false /* is_dwz */))
4694 if (dwz_map
.cu_count
== 0)
4697 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4698 return create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4702 /* Read .debug_names. If everything went ok, initialize the "quick"
4703 elements of all the CUs and return true. Otherwise, return false. */
4706 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4708 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4709 mapped_debug_names dwz_map
;
4710 struct objfile
*objfile
= per_objfile
->objfile
;
4711 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4713 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4714 &per_bfd
->debug_names
, *map
))
4717 /* Don't use the index if it's empty. */
4718 if (map
->name_count
== 0)
4721 /* If there is a .dwz file, read it so we can get its CU list as
4723 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4726 if (!read_debug_names_from_section (objfile
,
4727 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4728 &dwz
->debug_names
, dwz_map
))
4730 warning (_("could not read '.debug_names' section from %s; skipping"),
4731 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4736 if (!create_cus_from_debug_names (per_bfd
, *map
, dwz_map
))
4738 per_bfd
->all_units
.clear ();
4742 if (map
->tu_count
!= 0)
4744 /* We can only handle a single .debug_types when we have an
4746 if (per_bfd
->types
.size () > 1)
4748 per_bfd
->all_units
.clear ();
4752 dwarf2_section_info
*section
4753 = (per_bfd
->types
.size () == 1
4754 ? &per_bfd
->types
[0]
4757 create_signatured_type_table_from_debug_names
4758 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4761 finalize_all_units (per_bfd
);
4763 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4765 per_bfd
->index_table
= std::move (map
);
4766 per_bfd
->quick_file_names_table
=
4767 create_quick_file_names_table (per_bfd
->all_units
.size ());
4772 /* Type used to manage iterating over all CUs looking for a symbol for
4775 class dw2_debug_names_iterator
4778 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4779 block_search_flags block_index
,
4781 const char *name
, dwarf2_per_objfile
*per_objfile
)
4782 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4783 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4784 m_per_objfile (per_objfile
)
4787 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4788 search_domain search
, uint32_t namei
,
4789 dwarf2_per_objfile
*per_objfile
,
4790 domain_enum domain
= UNDEF_DOMAIN
)
4794 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4795 m_per_objfile (per_objfile
)
4798 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4799 block_search_flags block_index
, domain_enum domain
,
4800 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4801 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4802 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4803 m_per_objfile (per_objfile
)
4806 /* Return the next matching CU or NULL if there are no more. */
4807 dwarf2_per_cu_data
*next ();
4810 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4812 dwarf2_per_objfile
*per_objfile
);
4813 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4815 dwarf2_per_objfile
*per_objfile
);
4817 /* The internalized form of .debug_names. */
4818 const mapped_debug_names
&m_map
;
4820 /* Restrict the search to these blocks. */
4821 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4822 | SEARCH_STATIC_BLOCK
);
4824 /* The kind of symbol we're looking for. */
4825 const domain_enum m_domain
= UNDEF_DOMAIN
;
4826 const search_domain m_search
= ALL_DOMAIN
;
4828 /* The list of CUs from the index entry of the symbol, or NULL if
4830 const gdb_byte
*m_addr
;
4832 dwarf2_per_objfile
*m_per_objfile
;
4836 mapped_debug_names::namei_to_name
4837 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
4839 const ULONGEST namei_string_offs
4840 = extract_unsigned_integer ((name_table_string_offs_reordered
4841 + namei
* offset_size
),
4844 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
4847 /* Find a slot in .debug_names for the object named NAME. If NAME is
4848 found, return pointer to its pool data. If NAME cannot be found,
4852 dw2_debug_names_iterator::find_vec_in_debug_names
4853 (const mapped_debug_names
&map
, const char *name
,
4854 dwarf2_per_objfile
*per_objfile
)
4856 int (*cmp
) (const char *, const char *);
4858 gdb::unique_xmalloc_ptr
<char> without_params
;
4859 if (current_language
->la_language
== language_cplus
4860 || current_language
->la_language
== language_fortran
4861 || current_language
->la_language
== language_d
)
4863 /* NAME is already canonical. Drop any qualifiers as
4864 .debug_names does not contain any. */
4866 if (strchr (name
, '(') != NULL
)
4868 without_params
= cp_remove_params (name
);
4869 if (without_params
!= NULL
)
4870 name
= without_params
.get ();
4874 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
4876 const uint32_t full_hash
= dwarf5_djb_hash (name
);
4878 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4879 (map
.bucket_table_reordered
4880 + (full_hash
% map
.bucket_count
)), 4,
4881 map
.dwarf5_byte_order
);
4885 if (namei
>= map
.name_count
)
4887 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4889 namei
, map
.name_count
,
4890 objfile_name (per_objfile
->objfile
));
4896 const uint32_t namei_full_hash
4897 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4898 (map
.hash_table_reordered
+ namei
), 4,
4899 map
.dwarf5_byte_order
);
4900 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
4903 if (full_hash
== namei_full_hash
)
4905 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
4907 #if 0 /* An expensive sanity check. */
4908 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
4910 complaint (_("Wrong .debug_names hash for string at index %u "
4912 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
4917 if (cmp (namei_string
, name
) == 0)
4919 const ULONGEST namei_entry_offs
4920 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4921 + namei
* map
.offset_size
),
4922 map
.offset_size
, map
.dwarf5_byte_order
);
4923 return map
.entry_pool
+ namei_entry_offs
;
4928 if (namei
>= map
.name_count
)
4934 dw2_debug_names_iterator::find_vec_in_debug_names
4935 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4937 if (namei
>= map
.name_count
)
4939 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4941 namei
, map
.name_count
,
4942 objfile_name (per_objfile
->objfile
));
4946 const ULONGEST namei_entry_offs
4947 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4948 + namei
* map
.offset_size
),
4949 map
.offset_size
, map
.dwarf5_byte_order
);
4950 return map
.entry_pool
+ namei_entry_offs
;
4953 /* See dw2_debug_names_iterator. */
4955 dwarf2_per_cu_data
*
4956 dw2_debug_names_iterator::next ()
4961 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
4962 struct objfile
*objfile
= m_per_objfile
->objfile
;
4963 bfd
*const abfd
= objfile
->obfd
.get ();
4967 unsigned int bytes_read
;
4968 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
4969 m_addr
+= bytes_read
;
4973 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
4974 if (indexval_it
== m_map
.abbrev_map
.cend ())
4976 complaint (_("Wrong .debug_names undefined abbrev code %s "
4978 pulongest (abbrev
), objfile_name (objfile
));
4981 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
4982 enum class symbol_linkage
{
4986 } symbol_linkage_
= symbol_linkage::unknown
;
4987 dwarf2_per_cu_data
*per_cu
= NULL
;
4988 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
4993 case DW_FORM_implicit_const
:
4994 ull
= attr
.implicit_const
;
4996 case DW_FORM_flag_present
:
5000 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5001 m_addr
+= bytes_read
;
5004 ull
= read_4_bytes (abfd
, m_addr
);
5008 ull
= read_8_bytes (abfd
, m_addr
);
5011 case DW_FORM_ref_sig8
:
5012 ull
= read_8_bytes (abfd
, m_addr
);
5016 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5017 dwarf_form_name (attr
.form
),
5018 objfile_name (objfile
));
5021 switch (attr
.dw_idx
)
5023 case DW_IDX_compile_unit
:
5025 /* Don't crash on bad data. */
5026 if (ull
>= per_bfd
->all_comp_units
.size ())
5028 complaint (_(".debug_names entry has bad CU index %s"
5031 objfile_name (objfile
));
5035 per_cu
= per_bfd
->get_cu (ull
);
5037 case DW_IDX_type_unit
:
5038 /* Don't crash on bad data. */
5039 if (ull
>= per_bfd
->all_type_units
.size ())
5041 complaint (_(".debug_names entry has bad TU index %s"
5044 objfile_name (objfile
));
5048 int nr_cus
= per_bfd
->all_comp_units
.size ();
5049 per_cu
= per_bfd
->get_cu (nr_cus
+ ull
);
5052 case DW_IDX_die_offset
:
5053 /* In a per-CU index (as opposed to a per-module index), index
5054 entries without CU attribute implicitly refer to the single CU. */
5056 per_cu
= per_bfd
->get_cu (0);
5058 case DW_IDX_GNU_internal
:
5059 if (!m_map
.augmentation_is_gdb
)
5061 symbol_linkage_
= symbol_linkage::static_
;
5063 case DW_IDX_GNU_external
:
5064 if (!m_map
.augmentation_is_gdb
)
5066 symbol_linkage_
= symbol_linkage::extern_
;
5071 /* Skip if we couldn't find a valid CU/TU index. */
5072 if (per_cu
== nullptr)
5075 /* Skip if already read in. */
5076 if (m_per_objfile
->symtab_set_p (per_cu
))
5079 /* Check static vs global. */
5080 if (symbol_linkage_
!= symbol_linkage::unknown
)
5082 if (symbol_linkage_
== symbol_linkage::static_
)
5084 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5089 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5094 /* Match dw2_symtab_iter_next, symbol_kind
5095 and debug_names::psymbol_tag. */
5099 switch (indexval
.dwarf_tag
)
5101 case DW_TAG_variable
:
5102 case DW_TAG_subprogram
:
5103 /* Some types are also in VAR_DOMAIN. */
5104 case DW_TAG_typedef
:
5105 case DW_TAG_structure_type
:
5112 switch (indexval
.dwarf_tag
)
5114 case DW_TAG_typedef
:
5115 case DW_TAG_structure_type
:
5122 switch (indexval
.dwarf_tag
)
5125 case DW_TAG_variable
:
5132 switch (indexval
.dwarf_tag
)
5144 /* Match dw2_expand_symtabs_matching, symbol_kind and
5145 debug_names::psymbol_tag. */
5148 case VARIABLES_DOMAIN
:
5149 switch (indexval
.dwarf_tag
)
5151 case DW_TAG_variable
:
5157 case FUNCTIONS_DOMAIN
:
5158 switch (indexval
.dwarf_tag
)
5160 case DW_TAG_subprogram
:
5167 switch (indexval
.dwarf_tag
)
5169 case DW_TAG_typedef
:
5170 case DW_TAG_structure_type
:
5176 case MODULES_DOMAIN
:
5177 switch (indexval
.dwarf_tag
)
5191 /* This dumps minimal information about .debug_names. It is called
5192 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5193 uses this to verify that .debug_names has been loaded. */
5196 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5198 gdb_printf (".debug_names: exists\n");
5202 dwarf2_debug_names_index::expand_matching_symbols
5203 (struct objfile
*objfile
,
5204 const lookup_name_info
&name
, domain_enum domain
,
5206 symbol_compare_ftype
*ordered_compare
)
5208 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5210 mapped_debug_names
&map
5211 = *(gdb::checked_static_cast
<mapped_debug_names
*>
5212 (per_objfile
->per_bfd
->index_table
.get ()));
5213 const block_search_flags block_flags
5214 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5216 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5217 auto matcher
= [&] (const char *symname
)
5219 if (ordered_compare
== nullptr)
5221 return ordered_compare (symname
, match_name
) == 0;
5224 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5225 [&] (offset_type namei
)
5227 /* The name was matched, now expand corresponding CUs that were
5229 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5232 struct dwarf2_per_cu_data
*per_cu
;
5233 while ((per_cu
= iter
.next ()) != NULL
)
5234 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5241 dwarf2_debug_names_index::expand_symtabs_matching
5242 (struct objfile
*objfile
,
5243 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5244 const lookup_name_info
*lookup_name
,
5245 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5246 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5247 block_search_flags search_flags
,
5249 enum search_domain kind
)
5251 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5253 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5255 /* This invariant is documented in quick-functions.h. */
5256 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
5257 if (lookup_name
== nullptr)
5259 for (dwarf2_per_cu_data
*per_cu
5260 : all_units_range (per_objfile
->per_bfd
))
5264 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5272 mapped_debug_names
&map
5273 = *(gdb::checked_static_cast
<mapped_debug_names
*>
5274 (per_objfile
->per_bfd
->index_table
.get ()));
5277 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5279 [&] (offset_type namei
)
5281 /* The name was matched, now expand corresponding CUs that were
5283 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5285 struct dwarf2_per_cu_data
*per_cu
;
5286 while ((per_cu
= iter
.next ()) != NULL
)
5287 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5297 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5298 to either a dwarf2_per_bfd or dwz_file object. */
5300 template <typename T
>
5301 static gdb::array_view
<const gdb_byte
>
5302 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5304 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5306 if (section
->empty ())
5309 /* Older elfutils strip versions could keep the section in the main
5310 executable while splitting it for the separate debug info file. */
5311 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5314 section
->read (obj
);
5316 /* dwarf2_section_info::size is a bfd_size_type, while
5317 gdb::array_view works with size_t. On 32-bit hosts, with
5318 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5319 is 32-bit. So we need an explicit narrowing conversion here.
5320 This is fine, because it's impossible to allocate or mmap an
5321 array/buffer larger than what size_t can represent. */
5322 return gdb::make_array_view (section
->buffer
, section
->size
);
5325 /* Lookup the index cache for the contents of the index associated to
5328 static gdb::array_view
<const gdb_byte
>
5329 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5331 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
.get ());
5332 if (build_id
== nullptr)
5335 return global_index_cache
.lookup_gdb_index (build_id
,
5336 &dwarf2_per_bfd
->index_cache_res
);
5339 /* Same as the above, but for DWZ. */
5341 static gdb::array_view
<const gdb_byte
>
5342 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5344 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5345 if (build_id
== nullptr)
5348 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5351 static quick_symbol_functions_up
make_cooked_index_funcs ();
5353 /* See dwarf2/public.h. */
5356 dwarf2_initialize_objfile (struct objfile
*objfile
)
5358 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5359 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5361 dwarf_read_debug_printf ("called");
5363 /* If we're about to read full symbols, don't bother with the
5364 indices. In this case we also don't care if some other debug
5365 format is making psymtabs, because they are all about to be
5367 if ((objfile
->flags
& OBJF_READNOW
))
5369 dwarf_read_debug_printf ("readnow requested");
5371 create_all_units (per_objfile
);
5372 per_bfd
->quick_file_names_table
5373 = create_quick_file_names_table (per_bfd
->all_units
.size ());
5375 objfile
->qf
.emplace_front (new readnow_functions
);
5379 /* Was a GDB index already read when we processed an objfile sharing
5381 if (per_bfd
->index_table
!= nullptr)
5383 dwarf_read_debug_printf ("re-using symbols");
5384 objfile
->qf
.push_front (per_bfd
->index_table
->make_quick_functions ());
5388 if (dwarf2_read_debug_names (per_objfile
))
5390 dwarf_read_debug_printf ("found debug names");
5391 objfile
->qf
.push_front
5392 (per_bfd
->index_table
->make_quick_functions ());
5396 if (dwarf2_read_gdb_index (per_objfile
,
5397 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5398 get_gdb_index_contents_from_section
<dwz_file
>))
5400 dwarf_read_debug_printf ("found gdb index from file");
5401 objfile
->qf
.push_front (per_bfd
->index_table
->make_quick_functions ());
5405 /* ... otherwise, try to find the index in the index cache. */
5406 if (dwarf2_read_gdb_index (per_objfile
,
5407 get_gdb_index_contents_from_cache
,
5408 get_gdb_index_contents_from_cache_dwz
))
5410 dwarf_read_debug_printf ("found gdb index from cache");
5411 global_index_cache
.hit ();
5412 objfile
->qf
.push_front (per_bfd
->index_table
->make_quick_functions ());
5416 global_index_cache
.miss ();
5417 objfile
->qf
.push_front (make_cooked_index_funcs ());
5422 /* Build a partial symbol table. */
5425 dwarf2_build_psymtabs (struct objfile
*objfile
)
5427 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5429 if (per_objfile
->per_bfd
->index_table
!= nullptr)
5434 dwarf2_build_psymtabs_hard (per_objfile
);
5436 /* (maybe) store an index in the cache. */
5437 global_index_cache
.store (per_objfile
);
5439 catch (const gdb_exception_error
&except
)
5441 exception_print (gdb_stderr
, except
);
5445 /* Find the base address of the compilation unit for range lists and
5446 location lists. It will normally be specified by DW_AT_low_pc.
5447 In DWARF-3 draft 4, the base address could be overridden by
5448 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5449 compilation units with discontinuous ranges. */
5452 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5454 struct attribute
*attr
;
5456 cu
->base_address
.reset ();
5458 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5459 if (attr
!= nullptr)
5460 cu
->base_address
= attr
->as_address ();
5463 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5464 if (attr
!= nullptr)
5465 cu
->base_address
= attr
->as_address ();
5469 /* Helper function that returns the proper abbrev section for
5472 static struct dwarf2_section_info
*
5473 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5475 struct dwarf2_section_info
*abbrev
;
5476 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5478 if (this_cu
->is_dwz
)
5479 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5481 abbrev
= &per_bfd
->abbrev
;
5486 /* Fetch the abbreviation table offset from a comp or type unit header. */
5489 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5490 struct dwarf2_section_info
*section
,
5491 sect_offset sect_off
)
5493 bfd
*abfd
= section
->get_bfd_owner ();
5494 const gdb_byte
*info_ptr
;
5495 unsigned int initial_length_size
, offset_size
;
5498 section
->read (per_objfile
->objfile
);
5499 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5500 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5501 offset_size
= initial_length_size
== 4 ? 4 : 8;
5502 info_ptr
+= initial_length_size
;
5504 version
= read_2_bytes (abfd
, info_ptr
);
5508 /* Skip unit type and address size. */
5512 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5516 hash_signatured_type (const void *item
)
5518 const struct signatured_type
*sig_type
5519 = (const struct signatured_type
*) item
;
5521 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5522 return sig_type
->signature
;
5526 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5528 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5529 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5531 return lhs
->signature
== rhs
->signature
;
5534 /* Allocate a hash table for signatured types. */
5537 allocate_signatured_type_table ()
5539 return htab_up (htab_create_alloc (41,
5540 hash_signatured_type
,
5542 NULL
, xcalloc
, xfree
));
5545 /* A helper for create_debug_types_hash_table. Read types from SECTION
5546 and fill them into TYPES_HTAB. It will process only type units,
5547 therefore DW_UT_type. */
5550 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5551 struct dwo_file
*dwo_file
,
5552 dwarf2_section_info
*section
, htab_up
&types_htab
,
5553 rcuh_kind section_kind
)
5555 struct objfile
*objfile
= per_objfile
->objfile
;
5556 struct dwarf2_section_info
*abbrev_section
;
5558 const gdb_byte
*info_ptr
, *end_ptr
;
5560 abbrev_section
= &dwo_file
->sections
.abbrev
;
5562 dwarf_read_debug_printf ("Reading %s for %s",
5563 section
->get_name (),
5564 abbrev_section
->get_file_name ());
5566 section
->read (objfile
);
5567 info_ptr
= section
->buffer
;
5569 if (info_ptr
== NULL
)
5572 /* We can't set abfd until now because the section may be empty or
5573 not present, in which case the bfd is unknown. */
5574 abfd
= section
->get_bfd_owner ();
5576 /* We don't use cutu_reader here because we don't need to read
5577 any dies: the signature is in the header. */
5579 end_ptr
= info_ptr
+ section
->size
;
5580 while (info_ptr
< end_ptr
)
5582 signatured_type_up sig_type
;
5583 struct dwo_unit
*dwo_tu
;
5585 const gdb_byte
*ptr
= info_ptr
;
5586 struct comp_unit_head header
;
5587 unsigned int length
;
5589 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5591 /* Initialize it due to a false compiler warning. */
5592 header
.signature
= -1;
5593 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5595 /* We need to read the type's signature in order to build the hash
5596 table, but we don't need anything else just yet. */
5598 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5599 abbrev_section
, ptr
, section_kind
);
5601 length
= header
.get_length_with_initial ();
5603 /* Skip dummy type units. */
5604 if (ptr
>= info_ptr
+ length
5605 || peek_abbrev_code (abfd
, ptr
) == 0
5606 || (header
.unit_type
!= DW_UT_type
5607 && header
.unit_type
!= DW_UT_split_type
))
5613 if (types_htab
== NULL
)
5614 types_htab
= allocate_dwo_unit_table ();
5616 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5617 dwo_tu
->dwo_file
= dwo_file
;
5618 dwo_tu
->signature
= header
.signature
;
5619 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5620 dwo_tu
->section
= section
;
5621 dwo_tu
->sect_off
= sect_off
;
5622 dwo_tu
->length
= length
;
5624 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5625 gdb_assert (slot
!= NULL
);
5627 complaint (_("debug type entry at offset %s is duplicate to"
5628 " the entry at offset %s, signature %s"),
5629 sect_offset_str (sect_off
),
5630 sect_offset_str (dwo_tu
->sect_off
),
5631 hex_string (header
.signature
));
5634 dwarf_read_debug_printf_v (" offset %s, signature %s",
5635 sect_offset_str (sect_off
),
5636 hex_string (header
.signature
));
5642 /* Create the hash table of all entries in the .debug_types
5643 (or .debug_types.dwo) section(s).
5644 DWO_FILE is a pointer to the DWO file object.
5646 The result is a pointer to the hash table or NULL if there are no types.
5648 Note: This function processes DWO files only, not DWP files. */
5651 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5652 struct dwo_file
*dwo_file
,
5653 gdb::array_view
<dwarf2_section_info
> type_sections
,
5654 htab_up
&types_htab
)
5656 for (dwarf2_section_info
§ion
: type_sections
)
5657 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5661 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5662 If SLOT is non-NULL, it is the entry to use in the hash table.
5663 Otherwise we find one. */
5665 static struct signatured_type
*
5666 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
5668 if (per_objfile
->per_bfd
->all_units
.size ()
5669 == per_objfile
->per_bfd
->all_units
.capacity ())
5670 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
5672 signatured_type_up sig_type_holder
5673 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
5674 signatured_type
*sig_type
= sig_type_holder
.get ();
5676 per_objfile
->per_bfd
->all_units
.emplace_back
5677 (sig_type_holder
.release ());
5681 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5684 gdb_assert (*slot
== NULL
);
5686 /* The rest of sig_type must be filled in by the caller. */
5690 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5691 Fill in SIG_ENTRY with DWO_ENTRY. */
5694 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
5695 struct signatured_type
*sig_entry
,
5696 struct dwo_unit
*dwo_entry
)
5698 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5700 /* Make sure we're not clobbering something we don't expect to. */
5701 gdb_assert (! sig_entry
->queued
);
5702 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
5703 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
5704 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5705 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0
5706 || (to_underlying (sig_entry
->type_offset_in_section
)
5707 == to_underlying (dwo_entry
->type_offset_in_tu
)));
5708 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5709 gdb_assert (sig_entry
->dwo_unit
== NULL
5710 || sig_entry
->dwo_unit
== dwo_entry
);
5712 sig_entry
->section
= dwo_entry
->section
;
5713 sig_entry
->sect_off
= dwo_entry
->sect_off
;
5714 sig_entry
->set_length (dwo_entry
->length
, false);
5715 sig_entry
->reading_dwo_directly
= 1;
5716 sig_entry
->per_bfd
= per_bfd
;
5717 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5718 sig_entry
->dwo_unit
= dwo_entry
;
5721 /* Subroutine of lookup_signatured_type.
5722 If we haven't read the TU yet, create the signatured_type data structure
5723 for a TU to be read in directly from a DWO file, bypassing the stub.
5724 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5725 using .gdb_index, then when reading a CU we want to stay in the DWO file
5726 containing that CU. Otherwise we could end up reading several other DWO
5727 files (due to comdat folding) to process the transitive closure of all the
5728 mentioned TUs, and that can be slow. The current DWO file will have every
5729 type signature that it needs.
5730 We only do this for .gdb_index because in the psymtab case we already have
5731 to read all the DWOs to build the type unit groups. */
5733 static struct signatured_type
*
5734 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5736 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
5737 struct dwo_file
*dwo_file
;
5738 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5741 gdb_assert (cu
->dwo_unit
);
5743 /* If TU skeletons have been removed then we may not have read in any
5745 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
5746 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
5748 /* We only ever need to read in one copy of a signatured type.
5749 Use the global signatured_types array to do our own comdat-folding
5750 of types. If this is the first time we're reading this TU, and
5751 the TU has an entry in .gdb_index, replace the recorded data from
5752 .gdb_index with this TU. */
5754 signatured_type
find_sig_entry (sig
);
5755 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5756 &find_sig_entry
, INSERT
);
5757 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
5759 /* We can get here with the TU already read, *or* in the process of being
5760 read. Don't reassign the global entry to point to this DWO if that's
5761 the case. Also note that if the TU is already being read, it may not
5762 have come from a DWO, the program may be a mix of Fission-compiled
5763 code and non-Fission-compiled code. */
5765 /* Have we already tried to read this TU?
5766 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5767 needn't exist in the global table yet). */
5768 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
5771 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
5772 dwo_unit of the TU itself. */
5773 dwo_file
= cu
->dwo_unit
->dwo_file
;
5775 /* Ok, this is the first time we're reading this TU. */
5776 if (dwo_file
->tus
== NULL
)
5778 find_dwo_entry
.signature
= sig
;
5779 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
5781 if (dwo_entry
== NULL
)
5784 /* If the global table doesn't have an entry for this TU, add one. */
5785 if (sig_entry
== NULL
)
5786 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
5788 if (sig_entry
->dwo_unit
== nullptr)
5789 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
5790 sig_entry
->tu_read
= 1;
5794 /* Subroutine of lookup_signatured_type.
5795 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
5796 then try the DWP file. If the TU stub (skeleton) has been removed then
5797 it won't be in .gdb_index. */
5799 static struct signatured_type
*
5800 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5802 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
5803 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
5804 struct dwo_unit
*dwo_entry
;
5807 gdb_assert (cu
->dwo_unit
);
5808 gdb_assert (dwp_file
!= NULL
);
5810 /* If TU skeletons have been removed then we may not have read in any
5812 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
5813 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
5815 signatured_type
find_sig_entry (sig
);
5816 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5817 &find_sig_entry
, INSERT
);
5818 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
5820 /* Have we already tried to read this TU?
5821 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5822 needn't exist in the global table yet). */
5823 if (sig_entry
!= NULL
)
5826 if (dwp_file
->tus
== NULL
)
5828 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
5829 1 /* is_debug_types */);
5830 if (dwo_entry
== NULL
)
5833 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
5834 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
5839 /* Lookup a signature based type for DW_FORM_ref_sig8.
5840 Returns NULL if signature SIG is not present in the table.
5841 It is up to the caller to complain about this. */
5843 static struct signatured_type
*
5844 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5846 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
5850 /* We're in a DWO/DWP file, and we're using .gdb_index.
5851 These cases require special processing. */
5852 if (get_dwp_file (per_objfile
) == NULL
)
5853 return lookup_dwo_signatured_type (cu
, sig
);
5855 return lookup_dwp_signatured_type (cu
, sig
);
5859 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
5861 signatured_type
find_entry (sig
);
5862 return ((struct signatured_type
*)
5863 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
5868 /* Low level DIE reading support. */
5870 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5873 init_cu_die_reader (struct die_reader_specs
*reader
,
5874 struct dwarf2_cu
*cu
,
5875 struct dwarf2_section_info
*section
,
5876 struct dwo_file
*dwo_file
,
5877 struct abbrev_table
*abbrev_table
)
5879 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5880 reader
->abfd
= section
->get_bfd_owner ();
5882 reader
->dwo_file
= dwo_file
;
5883 reader
->die_section
= section
;
5884 reader
->buffer
= section
->buffer
;
5885 reader
->buffer_end
= section
->buffer
+ section
->size
;
5886 reader
->abbrev_table
= abbrev_table
;
5889 /* Subroutine of cutu_reader to simplify it.
5890 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5891 There's just a lot of work to do, and cutu_reader is big enough
5894 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5895 from it to the DIE in the DWO. If NULL we are skipping the stub.
5896 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5897 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5898 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5899 STUB_COMP_DIR may be non-NULL.
5900 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
5901 are filled in with the info of the DIE from the DWO file.
5902 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
5903 from the dwo. Since *RESULT_READER references this abbrev table, it must be
5904 kept around for at least as long as *RESULT_READER.
5906 The result is non-zero if a valid (non-dummy) DIE was found. */
5909 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
5910 struct dwo_unit
*dwo_unit
,
5911 struct die_info
*stub_comp_unit_die
,
5912 const char *stub_comp_dir
,
5913 struct die_reader_specs
*result_reader
,
5914 const gdb_byte
**result_info_ptr
,
5915 struct die_info
**result_comp_unit_die
,
5916 abbrev_table_up
*result_dwo_abbrev_table
)
5918 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
5919 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5920 struct objfile
*objfile
= per_objfile
->objfile
;
5922 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5923 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5924 int i
,num_extra_attrs
;
5925 struct dwarf2_section_info
*dwo_abbrev_section
;
5926 struct die_info
*comp_unit_die
;
5928 /* At most one of these may be provided. */
5929 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5931 /* These attributes aren't processed until later:
5932 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5933 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5934 referenced later. However, these attributes are found in the stub
5935 which we won't have later. In order to not impose this complication
5936 on the rest of the code, we read them here and copy them to the
5945 if (stub_comp_unit_die
!= NULL
)
5947 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5949 if (!per_cu
->is_debug_types
)
5950 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5951 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5952 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5953 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5954 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5956 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
5958 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
5959 We need the value before we can process DW_AT_ranges values from the
5961 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
5963 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
5964 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
5965 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
5966 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
5968 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
5970 else if (stub_comp_dir
!= NULL
)
5972 /* Reconstruct the comp_dir attribute to simplify the code below. */
5973 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
5974 comp_dir
->name
= DW_AT_comp_dir
;
5975 comp_dir
->form
= DW_FORM_string
;
5976 comp_dir
->set_string_noncanonical (stub_comp_dir
);
5979 /* Set up for reading the DWO CU/TU. */
5980 cu
->dwo_unit
= dwo_unit
;
5981 dwarf2_section_info
*section
= dwo_unit
->section
;
5982 section
->read (objfile
);
5983 abfd
= section
->get_bfd_owner ();
5984 begin_info_ptr
= info_ptr
= (section
->buffer
5985 + to_underlying (dwo_unit
->sect_off
));
5986 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5988 if (per_cu
->is_debug_types
)
5990 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
5992 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
5993 section
, dwo_abbrev_section
,
5994 info_ptr
, rcuh_kind::TYPE
);
5995 /* This is not an assert because it can be caused by bad debug info. */
5996 if (sig_type
->signature
!= cu
->header
.signature
)
5998 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5999 " TU at offset %s [in module %s]"),
6000 hex_string (sig_type
->signature
),
6001 hex_string (cu
->header
.signature
),
6002 sect_offset_str (dwo_unit
->sect_off
),
6003 bfd_get_filename (abfd
));
6005 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6006 /* For DWOs coming from DWP files, we don't know the CU length
6007 nor the type's offset in the TU until now. */
6008 dwo_unit
->length
= cu
->header
.get_length_with_initial ();
6009 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6011 /* Establish the type offset that can be used to lookup the type.
6012 For DWO files, we don't know it until now. */
6013 sig_type
->type_offset_in_section
6014 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6018 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6019 section
, dwo_abbrev_section
,
6020 info_ptr
, rcuh_kind::COMPILE
);
6021 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6022 /* For DWOs coming from DWP files, we don't know the CU length
6024 dwo_unit
->length
= cu
->header
.get_length_with_initial ();
6027 dwo_abbrev_section
->read (objfile
);
6028 *result_dwo_abbrev_table
6029 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6030 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6031 result_dwo_abbrev_table
->get ());
6033 /* Read in the die, but leave space to copy over the attributes
6034 from the stub. This has the benefit of simplifying the rest of
6035 the code - all the work to maintain the illusion of a single
6036 DW_TAG_{compile,type}_unit DIE is done here. */
6037 num_extra_attrs
= ((stmt_list
!= NULL
)
6041 + (comp_dir
!= NULL
));
6042 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6045 /* Copy over the attributes from the stub to the DIE we just read in. */
6046 comp_unit_die
= *result_comp_unit_die
;
6047 i
= comp_unit_die
->num_attrs
;
6048 if (stmt_list
!= NULL
)
6049 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6051 comp_unit_die
->attrs
[i
++] = *low_pc
;
6052 if (high_pc
!= NULL
)
6053 comp_unit_die
->attrs
[i
++] = *high_pc
;
6055 comp_unit_die
->attrs
[i
++] = *ranges
;
6056 if (comp_dir
!= NULL
)
6057 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6058 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6060 if (dwarf_die_debug
)
6062 gdb_printf (gdb_stdlog
,
6063 "Read die from %s@0x%x of %s:\n",
6064 section
->get_name (),
6065 (unsigned) (begin_info_ptr
- section
->buffer
),
6066 bfd_get_filename (abfd
));
6067 dump_die (comp_unit_die
, dwarf_die_debug
);
6070 /* Skip dummy compilation units. */
6071 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6072 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6075 *result_info_ptr
= info_ptr
;
6079 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6080 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6081 signature is part of the header. */
6082 static gdb::optional
<ULONGEST
>
6083 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6085 if (cu
->header
.version
>= 5)
6086 return cu
->header
.signature
;
6087 struct attribute
*attr
;
6088 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6089 if (attr
== nullptr || !attr
->form_is_unsigned ())
6090 return gdb::optional
<ULONGEST
> ();
6091 return attr
->as_unsigned ();
6094 /* Subroutine of cutu_reader to simplify it.
6095 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6096 Returns NULL if the specified DWO unit cannot be found. */
6098 static struct dwo_unit
*
6099 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6102 /* We need a lock here both to handle the DWO hash table, and BFD,
6103 which is not thread-safe. */
6104 static std::mutex dwo_lock
;
6106 std::lock_guard
<std::mutex
> guard (dwo_lock
);
6109 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6110 struct dwo_unit
*dwo_unit
;
6111 const char *comp_dir
;
6113 gdb_assert (cu
!= NULL
);
6115 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6116 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6117 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6119 if (per_cu
->is_debug_types
)
6120 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6123 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6125 if (!signature
.has_value ())
6126 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6128 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6130 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6136 /* Subroutine of cutu_reader to simplify it.
6137 See it for a description of the parameters.
6138 Read a TU directly from a DWO file, bypassing the stub. */
6141 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6142 dwarf2_per_objfile
*per_objfile
,
6143 dwarf2_cu
*existing_cu
)
6145 struct signatured_type
*sig_type
;
6147 /* Verify we can do the following downcast, and that we have the
6149 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6150 sig_type
= (struct signatured_type
*) this_cu
;
6151 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6155 if (existing_cu
!= nullptr)
6158 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6159 /* There's no need to do the rereading_dwo_cu handling that
6160 cutu_reader does since we don't read the stub. */
6164 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6165 in per_objfile yet. */
6166 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6167 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6168 cu
= m_new_cu
.get ();
6171 /* A future optimization, if needed, would be to use an existing
6172 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6173 could share abbrev tables. */
6175 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6176 NULL
/* stub_comp_unit_die */,
6177 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6180 &m_dwo_abbrev_table
) == 0)
6187 /* Initialize a CU (or TU) and read its DIEs.
6188 If the CU defers to a DWO file, read the DWO file as well.
6190 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6191 Otherwise the table specified in the comp unit header is read in and used.
6192 This is an optimization for when we already have the abbrev table.
6194 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6197 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6198 dwarf2_per_objfile
*per_objfile
,
6199 struct abbrev_table
*abbrev_table
,
6200 dwarf2_cu
*existing_cu
,
6202 abbrev_cache
*cache
)
6203 : die_reader_specs
{},
6206 struct objfile
*objfile
= per_objfile
->objfile
;
6207 struct dwarf2_section_info
*section
= this_cu
->section
;
6208 bfd
*abfd
= section
->get_bfd_owner ();
6209 const gdb_byte
*begin_info_ptr
;
6210 struct signatured_type
*sig_type
= NULL
;
6211 struct dwarf2_section_info
*abbrev_section
;
6212 /* Non-zero if CU currently points to a DWO file and we need to
6213 reread it. When this happens we need to reread the skeleton die
6214 before we can reread the DWO file (this only applies to CUs, not TUs). */
6215 int rereading_dwo_cu
= 0;
6217 if (dwarf_die_debug
)
6218 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
6219 this_cu
->is_debug_types
? "type" : "comp",
6220 sect_offset_str (this_cu
->sect_off
));
6222 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6223 file (instead of going through the stub), short-circuit all of this. */
6224 if (this_cu
->reading_dwo_directly
)
6226 /* Narrow down the scope of possibilities to have to understand. */
6227 gdb_assert (this_cu
->is_debug_types
);
6228 gdb_assert (abbrev_table
== NULL
);
6229 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6233 /* This is cheap if the section is already read in. */
6234 section
->read (objfile
);
6236 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6238 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6242 if (existing_cu
!= nullptr)
6245 /* If this CU is from a DWO file we need to start over, we need to
6246 refetch the attributes from the skeleton CU.
6247 This could be optimized by retrieving those attributes from when we
6248 were here the first time: the previous comp_unit_die was stored in
6249 comp_unit_obstack. But there's no data yet that we need this
6251 if (cu
->dwo_unit
!= NULL
)
6252 rereading_dwo_cu
= 1;
6256 /* If an existing_cu is provided, a dwarf2_cu must not exist for
6257 this_cu in per_objfile yet. Here, CACHE doubles as a flag to
6258 let us know that the CU is being scanned using the parallel
6259 indexer. This assert is avoided in this case because (1) it
6260 is irrelevant, and (2) the get_cu method is not
6262 gdb_assert (cache
!= nullptr
6263 || per_objfile
->get_cu (this_cu
) == nullptr);
6264 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6265 cu
= m_new_cu
.get ();
6268 /* Get the header. */
6269 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6271 /* We already have the header, there's no need to read it in again. */
6272 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6276 if (this_cu
->is_debug_types
)
6278 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6279 section
, abbrev_section
,
6280 info_ptr
, rcuh_kind::TYPE
);
6282 /* Since per_cu is the first member of struct signatured_type,
6283 we can go from a pointer to one to a pointer to the other. */
6284 sig_type
= (struct signatured_type
*) this_cu
;
6285 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6286 gdb_assert (sig_type
->type_offset_in_tu
6287 == cu
->header
.type_cu_offset_in_tu
);
6288 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6290 /* LENGTH has not been set yet for type units if we're
6291 using .gdb_index. */
6292 this_cu
->set_length (cu
->header
.get_length_with_initial ());
6294 /* Establish the type offset that can be used to lookup the type. */
6295 sig_type
->type_offset_in_section
=
6296 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6298 this_cu
->set_version (cu
->header
.version
);
6302 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6303 section
, abbrev_section
,
6305 rcuh_kind::COMPILE
);
6307 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6308 this_cu
->set_length (cu
->header
.get_length_with_initial ());
6309 this_cu
->set_version (cu
->header
.version
);
6313 /* Skip dummy compilation units. */
6314 if (info_ptr
>= begin_info_ptr
+ this_cu
->length ()
6315 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6321 /* If we don't have them yet, read the abbrevs for this compilation unit.
6322 And if we need to read them now, make sure they're freed when we're
6324 if (abbrev_table
!= NULL
)
6325 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6328 if (cache
!= nullptr)
6329 abbrev_table
= cache
->find (abbrev_section
,
6330 cu
->header
.abbrev_sect_off
);
6331 if (abbrev_table
== nullptr)
6333 abbrev_section
->read (objfile
);
6334 m_abbrev_table_holder
6335 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6336 abbrev_table
= m_abbrev_table_holder
.get ();
6340 /* Read the top level CU/TU die. */
6341 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6342 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6344 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6350 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6351 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6352 table from the DWO file and pass the ownership over to us. It will be
6353 referenced from READER, so we must make sure to free it after we're done
6356 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6357 DWO CU, that this test will fail (the attribute will not be present). */
6358 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6359 if (dwo_name
!= nullptr)
6361 struct dwo_unit
*dwo_unit
;
6362 struct die_info
*dwo_comp_unit_die
;
6364 if (comp_unit_die
->has_children
)
6366 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6367 " has children (offset %s) [in module %s]"),
6368 sect_offset_str (this_cu
->sect_off
),
6369 bfd_get_filename (abfd
));
6371 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6372 if (dwo_unit
!= NULL
)
6374 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6375 comp_unit_die
, NULL
,
6378 &m_dwo_abbrev_table
) == 0)
6384 comp_unit_die
= dwo_comp_unit_die
;
6388 /* Yikes, we couldn't find the rest of the DIE, we only have
6389 the stub. A complaint has already been logged. There's
6390 not much more we can do except pass on the stub DIE to
6391 die_reader_func. We don't want to throw an error on bad
6398 cutu_reader::keep ()
6400 /* Done, clean up. */
6401 gdb_assert (!dummy_p
);
6402 if (m_new_cu
!= NULL
)
6404 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6406 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6407 per_objfile
->set_cu (m_this_cu
, std::move (m_new_cu
));
6411 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6412 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6413 assumed to have already done the lookup to find the DWO file).
6415 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6416 THIS_CU->is_debug_types, but nothing else.
6418 We fill in THIS_CU->length.
6420 THIS_CU->cu is always freed when done.
6421 This is done in order to not leave THIS_CU->cu in a state where we have
6422 to care whether it refers to the "main" CU or the DWO CU.
6424 When parent_cu is passed, it is used to provide a default value for
6425 str_offsets_base and addr_base from the parent. */
6427 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6428 dwarf2_per_objfile
*per_objfile
,
6429 struct dwarf2_cu
*parent_cu
,
6430 struct dwo_file
*dwo_file
)
6431 : die_reader_specs
{},
6434 struct objfile
*objfile
= per_objfile
->objfile
;
6435 struct dwarf2_section_info
*section
= this_cu
->section
;
6436 bfd
*abfd
= section
->get_bfd_owner ();
6437 struct dwarf2_section_info
*abbrev_section
;
6438 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6440 if (dwarf_die_debug
)
6441 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
6442 this_cu
->is_debug_types
? "type" : "comp",
6443 sect_offset_str (this_cu
->sect_off
));
6445 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6447 abbrev_section
= (dwo_file
!= NULL
6448 ? &dwo_file
->sections
.abbrev
6449 : get_abbrev_section_for_cu (this_cu
));
6451 /* This is cheap if the section is already read in. */
6452 section
->read (objfile
);
6454 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6456 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6457 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6458 section
, abbrev_section
, info_ptr
,
6459 (this_cu
->is_debug_types
6461 : rcuh_kind::COMPILE
));
6463 if (parent_cu
!= nullptr)
6465 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6466 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6468 this_cu
->set_length (m_new_cu
->header
.get_length_with_initial ());
6470 /* Skip dummy compilation units. */
6471 if (info_ptr
>= begin_info_ptr
+ this_cu
->length ()
6472 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6478 abbrev_section
->read (objfile
);
6479 m_abbrev_table_holder
6480 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6482 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6483 m_abbrev_table_holder
.get ());
6484 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6488 /* Type Unit Groups.
6490 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6491 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6492 so that all types coming from the same compilation (.o file) are grouped
6493 together. A future step could be to put the types in the same symtab as
6494 the CU the types ultimately came from. */
6497 hash_type_unit_group (const void *item
)
6499 const struct type_unit_group
*tu_group
6500 = (const struct type_unit_group
*) item
;
6502 return hash_stmt_list_entry (&tu_group
->hash
);
6506 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6508 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6509 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6511 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6514 /* Allocate a hash table for type unit groups. */
6517 allocate_type_unit_groups_table ()
6519 return htab_up (htab_create_alloc (3,
6520 hash_type_unit_group
,
6522 htab_delete_entry
<type_unit_group
>,
6526 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6527 partial symtabs. We combine several TUs per psymtab to not let the size
6528 of any one psymtab grow too big. */
6529 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6530 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6532 /* Helper routine for get_type_unit_group.
6533 Create the type_unit_group object used to hold one or more TUs. */
6535 static std::unique_ptr
<type_unit_group
>
6536 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6538 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6540 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6541 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6546 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6547 STMT_LIST is a DW_AT_stmt_list attribute. */
6549 static struct type_unit_group
*
6550 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6552 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6553 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6554 struct type_unit_group
*tu_group
;
6556 unsigned int line_offset
;
6557 struct type_unit_group type_unit_group_for_lookup
;
6559 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6560 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6562 /* Do we need to create a new group, or can we use an existing one? */
6564 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6566 line_offset
= stmt_list
->as_unsigned ();
6567 ++tu_stats
->nr_symtab_sharers
;
6571 /* Ugh, no stmt_list. Rare, but we have to handle it.
6572 We can do various things here like create one group per TU or
6573 spread them over multiple groups to split up the expansion work.
6574 To avoid worst case scenarios (too many groups or too large groups)
6575 we, umm, group them in bunches. */
6576 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6577 | (tu_stats
->nr_stmt_less_type_units
6578 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6579 ++tu_stats
->nr_stmt_less_type_units
;
6582 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6583 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6584 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6585 &type_unit_group_for_lookup
, INSERT
);
6586 if (*slot
== nullptr)
6588 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6589 std::unique_ptr
<type_unit_group
> grp
6590 = create_type_unit_group (cu
, line_offset_struct
);
6591 *slot
= grp
.release ();
6592 ++tu_stats
->nr_symtabs
;
6595 tu_group
= (struct type_unit_group
*) *slot
;
6596 gdb_assert (tu_group
!= nullptr);
6601 /* An instance of this is created when scanning DWARF to create a
6604 class cooked_index_storage
6608 cooked_index_storage ()
6609 : m_reader_hash (htab_create_alloc (10, hash_cutu_reader
,
6611 htab_delete_entry
<cutu_reader
>,
6613 m_index (new cooked_index
)
6617 DISABLE_COPY_AND_ASSIGN (cooked_index_storage
);
6619 /* Return the current abbrev cache. */
6620 abbrev_cache
*get_abbrev_cache ()
6622 return &m_abbrev_cache
;
6625 /* Return the DIE reader corresponding to PER_CU. If no such reader
6626 has been registered, return NULL. */
6627 cutu_reader
*get_reader (dwarf2_per_cu_data
*per_cu
)
6629 int index
= per_cu
->index
;
6630 return (cutu_reader
*) htab_find_with_hash (m_reader_hash
.get (),
6634 /* Preserve READER by storing it in the local hash table. */
6635 cutu_reader
*preserve (std::unique_ptr
<cutu_reader
> reader
)
6637 m_abbrev_cache
.add (reader
->release_abbrev_table ());
6639 int index
= reader
->cu
->per_cu
->index
;
6640 void **slot
= htab_find_slot_with_hash (m_reader_hash
.get (), &index
,
6642 gdb_assert (*slot
== nullptr);
6643 cutu_reader
*result
= reader
.get ();
6644 *slot
= reader
.release ();
6648 /* Add an entry to the index. The arguments describe the entry; see
6649 cooked-index.h. The new entry is returned. */
6650 const cooked_index_entry
*add (sect_offset die_offset
, enum dwarf_tag tag
,
6651 cooked_index_flag flags
,
6653 const cooked_index_entry
*parent_entry
,
6654 dwarf2_per_cu_data
*per_cu
)
6656 return m_index
->add (die_offset
, tag
, flags
, name
, parent_entry
, per_cu
);
6659 /* Install the current addrmap into the index being constructed,
6660 then transfer ownership of the index to the caller. */
6661 std::unique_ptr
<cooked_index
> release ()
6663 m_index
->install_addrmap (&m_addrmap
);
6664 return std::move (m_index
);
6667 /* Return the mutable addrmap that is currently being created. */
6668 addrmap_mutable
*get_addrmap ()
6675 /* Hash function for a cutu_reader. */
6676 static hashval_t
hash_cutu_reader (const void *a
)
6678 const cutu_reader
*reader
= (const cutu_reader
*) a
;
6679 return reader
->cu
->per_cu
->index
;
6682 /* Equality function for cutu_reader. */
6683 static int eq_cutu_reader (const void *a
, const void *b
)
6685 const cutu_reader
*ra
= (const cutu_reader
*) a
;
6686 const int *rb
= (const int *) b
;
6687 return ra
->cu
->per_cu
->index
== *rb
;
6690 /* The abbrev cache used by this indexer. */
6691 abbrev_cache m_abbrev_cache
;
6692 /* A hash table of cutu_reader objects. */
6693 htab_up m_reader_hash
;
6694 /* The index that is being constructed. */
6695 std::unique_ptr
<cooked_index
> m_index
;
6697 /* A writeable addrmap being constructed by this scanner. */
6698 addrmap_mutable m_addrmap
;
6701 /* An instance of this is created to index a CU. */
6703 class cooked_indexer
6707 cooked_indexer (cooked_index_storage
*storage
,
6708 dwarf2_per_cu_data
*per_cu
,
6709 enum language language
)
6710 : m_index_storage (storage
),
6712 m_language (language
)
6716 DISABLE_COPY_AND_ASSIGN (cooked_indexer
);
6718 /* Index the given CU. */
6719 void make_index (cutu_reader
*reader
);
6723 /* A helper function to turn a section offset into an address that
6724 can be used in an addrmap. */
6725 CORE_ADDR
form_addr (sect_offset offset
, bool is_dwz
)
6727 CORE_ADDR value
= to_underlying (offset
);
6729 value
|= ((CORE_ADDR
) 1) << (8 * sizeof (CORE_ADDR
) - 1);
6733 /* A helper function to scan the PC bounds of READER and record them
6734 in the storage's addrmap. */
6735 void check_bounds (cutu_reader
*reader
);
6737 /* Ensure that the indicated CU exists. The cutu_reader for it is
6738 returned. FOR_SCANNING is true if the caller intends to scan all
6739 the DIEs in the CU; when false, this use is assumed to be to look
6740 up just a single DIE. */
6741 cutu_reader
*ensure_cu_exists (cutu_reader
*reader
,
6742 dwarf2_per_objfile
*per_objfile
,
6743 sect_offset sect_off
,
6747 /* Index DIEs in the READER starting at INFO_PTR. PARENT_ENTRY is
6748 the entry for the enclosing scope (nullptr at top level). FULLY
6749 is true when a full scan must be done -- in some languages,
6750 function scopes must be fully explored in order to find nested
6751 functions. This returns a pointer to just after the spot where
6753 const gdb_byte
*index_dies (cutu_reader
*reader
,
6754 const gdb_byte
*info_ptr
,
6755 const cooked_index_entry
*parent_entry
,
6758 /* Scan the attributes for a given DIE and update the out
6759 parameters. Returns a pointer to the byte after the DIE. */
6760 const gdb_byte
*scan_attributes (dwarf2_per_cu_data
*scanning_per_cu
,
6761 cutu_reader
*reader
,
6762 const gdb_byte
*watermark_ptr
,
6763 const gdb_byte
*info_ptr
,
6764 const abbrev_info
*abbrev
,
6766 const char **linkage_name
,
6767 cooked_index_flag
*flags
,
6768 sect_offset
*sibling_offset
,
6769 const cooked_index_entry
**parent_entry
,
6770 CORE_ADDR
*maybe_defer
,
6771 bool for_specification
);
6773 /* Handle DW_TAG_imported_unit, by scanning the DIE to find
6774 DW_AT_import, and then scanning the referenced CU. Returns a
6775 pointer to the byte after the DIE. */
6776 const gdb_byte
*index_imported_unit (cutu_reader
*reader
,
6777 const gdb_byte
*info_ptr
,
6778 const abbrev_info
*abbrev
);
6780 /* Recursively read DIEs, recording the section offsets in
6781 m_die_range_map and then calling index_dies. */
6782 const gdb_byte
*recurse (cutu_reader
*reader
,
6783 const gdb_byte
*info_ptr
,
6784 const cooked_index_entry
*parent_entry
,
6787 /* The storage object, where the results are kept. */
6788 cooked_index_storage
*m_index_storage
;
6789 /* The CU that we are reading on behalf of. This object might be
6790 asked to index one CU but to treat the results as if they come
6791 from some including CU; in this case the including CU would be
6793 dwarf2_per_cu_data
*m_per_cu
;
6794 /* The language that we're assuming when reading. */
6795 enum language m_language
;
6797 /* An addrmap that maps from section offsets (see the form_addr
6798 method) to newly-created entries. See m_deferred_entries to
6800 addrmap_mutable m_die_range_map
;
6802 /* A single deferred entry. */
6803 struct deferred_entry
6805 sect_offset die_offset
;
6807 CORE_ADDR spec_offset
;
6809 cooked_index_flag flags
;
6812 /* The generated DWARF can sometimes have the declaration for a
6813 method in a class (or perhaps namespace) scope, with the
6814 definition appearing outside this scope... just one of the many
6815 bad things about DWARF. In order to handle this situation, we
6816 defer certain entries until the end of scanning, at which point
6817 we'll know the containing context of all the DIEs that we might
6818 have scanned. This vector stores these deferred entries. */
6819 std::vector
<deferred_entry
> m_deferred_entries
;
6822 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6823 Process compilation unit THIS_CU for a psymtab. */
6826 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
6827 dwarf2_per_objfile
*per_objfile
,
6828 cooked_index_storage
*storage
)
6830 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false,
6831 storage
->get_abbrev_cache ());
6833 if (reader
.comp_unit_die
== nullptr)
6840 else if (this_cu
->is_debug_types
)
6841 build_type_psymtabs_reader (&reader
, storage
);
6842 else if (reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
6845 if (this_cu
->scanned
.compare_exchange_strong (nope
, true))
6847 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
6849 gdb_assert (storage
!= nullptr);
6850 cooked_indexer
indexer (storage
, this_cu
, reader
.cu
->lang ());
6851 indexer
.make_index (&reader
);
6856 /* Reader function for build_type_psymtabs. */
6859 build_type_psymtabs_reader (cutu_reader
*reader
,
6860 cooked_index_storage
*storage
)
6862 struct dwarf2_cu
*cu
= reader
->cu
;
6863 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6864 struct die_info
*type_unit_die
= reader
->comp_unit_die
;
6866 gdb_assert (per_cu
->is_debug_types
);
6868 if (! type_unit_die
->has_children
)
6871 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6873 gdb_assert (storage
!= nullptr);
6874 cooked_indexer
indexer (storage
, per_cu
, cu
->lang ());
6875 indexer
.make_index (reader
);
6878 /* Struct used to sort TUs by their abbreviation table offset. */
6880 struct tu_abbrev_offset
6882 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
6883 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
6886 /* This is used when sorting. */
6887 bool operator< (const tu_abbrev_offset
&other
) const
6889 return abbrev_offset
< other
.abbrev_offset
;
6892 signatured_type
*sig_type
;
6893 sect_offset abbrev_offset
;
6896 /* Efficiently read all the type units.
6898 The efficiency is because we sort TUs by the abbrev table they use and
6899 only read each abbrev table once. In one program there are 200K TUs
6900 sharing 8K abbrev tables.
6902 The main purpose of this function is to support building the
6903 dwarf2_per_objfile->per_bfd->type_unit_groups table.
6904 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6905 can collapse the search space by grouping them by stmt_list.
6906 The savings can be significant, in the same program from above the 200K TUs
6907 share 8K stmt_list tables.
6909 FUNC is expected to call get_type_unit_group, which will create the
6910 struct type_unit_group if necessary and add it to
6911 dwarf2_per_objfile->per_bfd->type_unit_groups. */
6914 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
,
6915 cooked_index_storage
*storage
)
6917 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6918 abbrev_table_up abbrev_table
;
6919 sect_offset abbrev_offset
;
6921 /* It's up to the caller to not call us multiple times. */
6922 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
6924 if (per_objfile
->per_bfd
->all_type_units
.size () == 0)
6927 /* TUs typically share abbrev tables, and there can be way more TUs than
6928 abbrev tables. Sort by abbrev table to reduce the number of times we
6929 read each abbrev table in.
6930 Alternatives are to punt or to maintain a cache of abbrev tables.
6931 This is simpler and efficient enough for now.
6933 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6934 symtab to use). Typically TUs with the same abbrev offset have the same
6935 stmt_list value too so in practice this should work well.
6937 The basic algorithm here is:
6939 sort TUs by abbrev table
6940 for each TU with same abbrev table:
6941 read abbrev table if first user
6942 read TU top level DIE
6943 [IWBN if DWO skeletons had DW_AT_stmt_list]
6946 dwarf_read_debug_printf ("Building type unit groups ...");
6948 /* Sort in a separate table to maintain the order of all_units
6949 for .gdb_index: TU indices directly index all_type_units. */
6950 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
6951 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
6953 for (const auto &cu
: per_objfile
->per_bfd
->all_units
)
6955 if (cu
->is_debug_types
)
6957 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
6958 sorted_by_abbrev
.emplace_back
6959 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
6960 sig_type
->sect_off
));
6964 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
6966 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
6968 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
6970 /* Switch to the next abbrev table if necessary. */
6971 if (abbrev_table
== NULL
6972 || tu
.abbrev_offset
!= abbrev_offset
)
6974 abbrev_offset
= tu
.abbrev_offset
;
6975 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
6977 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
6978 ++tu_stats
->nr_uniq_abbrev_tables
;
6981 cutu_reader
reader (tu
.sig_type
, per_objfile
,
6982 abbrev_table
.get (), nullptr, false);
6983 if (!reader
.dummy_p
)
6984 build_type_psymtabs_reader (&reader
, storage
);
6988 /* Print collected type unit statistics. */
6991 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
6993 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6995 dwarf_read_debug_printf ("Type unit statistics:");
6996 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
6997 dwarf_read_debug_printf (" %d uniq abbrev tables",
6998 tu_stats
->nr_uniq_abbrev_tables
);
6999 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7000 tu_stats
->nr_symtabs
);
7001 dwarf_read_debug_printf (" %d symtab sharers",
7002 tu_stats
->nr_symtab_sharers
);
7003 dwarf_read_debug_printf (" %d type units without a stmt_list",
7004 tu_stats
->nr_stmt_less_type_units
);
7005 dwarf_read_debug_printf (" %d all_type_units reallocs",
7006 tu_stats
->nr_all_type_units_reallocs
);
7009 struct skeleton_data
7011 dwarf2_per_objfile
*per_objfile
;
7012 cooked_index_storage
*storage
;
7015 /* Traversal function for process_skeletonless_type_unit.
7016 Read a TU in a DWO file and build partial symbols for it. */
7019 process_skeletonless_type_unit (void **slot
, void *info
)
7021 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7022 skeleton_data
*data
= (skeleton_data
*) info
;
7024 /* If this TU doesn't exist in the global table, add it and read it in. */
7026 if (data
->per_objfile
->per_bfd
->signatured_types
== NULL
)
7027 data
->per_objfile
->per_bfd
->signatured_types
7028 = allocate_signatured_type_table ();
7030 signatured_type
find_entry (dwo_unit
->signature
);
7031 slot
= htab_find_slot (data
->per_objfile
->per_bfd
->signatured_types
.get (),
7032 &find_entry
, INSERT
);
7033 /* If we've already seen this type there's nothing to do. What's happening
7034 is we're doing our own version of comdat-folding here. */
7038 /* This does the job that create_all_units would have done for
7040 signatured_type
*entry
7041 = add_type_unit (data
->per_objfile
, dwo_unit
->signature
, slot
);
7042 fill_in_sig_entry_from_dwo_entry (data
->per_objfile
, entry
, dwo_unit
);
7045 /* This does the job that build_type_psymtabs would have done. */
7046 cutu_reader
reader (entry
, data
->per_objfile
, nullptr, nullptr, false);
7047 if (!reader
.dummy_p
)
7048 build_type_psymtabs_reader (&reader
, data
->storage
);
7053 /* Traversal function for process_skeletonless_type_units. */
7056 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7058 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7060 if (dwo_file
->tus
!= NULL
)
7061 htab_traverse_noresize (dwo_file
->tus
.get (),
7062 process_skeletonless_type_unit
, info
);
7067 /* Scan all TUs of DWO files, verifying we've processed them.
7068 This is needed in case a TU was emitted without its skeleton.
7069 Note: This can't be done until we know what all the DWO files are. */
7072 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
,
7073 cooked_index_storage
*storage
)
7075 skeleton_data data
{ per_objfile
, storage
};
7077 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7078 if (get_dwp_file (per_objfile
) == NULL
7079 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7081 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7082 process_dwo_file_for_skeletonless_type_units
,
7087 /* Build the partial symbol table by doing a quick pass through the
7088 .debug_info and .debug_abbrev sections. */
7091 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7093 struct objfile
*objfile
= per_objfile
->objfile
;
7094 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7096 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7097 objfile_name (objfile
));
7099 per_bfd
->map_info_sections (objfile
);
7101 cooked_index_storage index_storage
;
7102 create_all_units (per_objfile
);
7103 build_type_psymtabs (per_objfile
, &index_storage
);
7104 std::vector
<std::unique_ptr
<cooked_index
>> indexes
;
7106 per_bfd
->quick_file_names_table
7107 = create_quick_file_names_table (per_bfd
->all_units
.size ());
7108 if (!per_bfd
->debug_aranges
.empty ())
7109 read_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
,
7110 index_storage
.get_addrmap ());
7113 /* Ensure that complaints are handled correctly. */
7114 complaint_interceptor complaint_handler
;
7116 using iter_type
= decltype (per_bfd
->all_units
.begin ());
7118 auto task_size_
= [] (iter_type iter
)
7120 dwarf2_per_cu_data
*per_cu
= iter
->get ();
7121 return (size_t)per_cu
->length ();
7123 auto task_size
= gdb::make_function_view (task_size_
);
7125 /* Each thread returns a pair holding a cooked index, and a vector
7126 of errors that should be printed. The latter is done because
7127 GDB's I/O system is not thread-safe. run_on_main_thread could be
7128 used, but that would mean the messages are printed after the
7129 prompt, which looks weird. */
7130 using result_type
= std::pair
<std::unique_ptr
<cooked_index
>,
7131 std::vector
<gdb_exception
>>;
7132 std::vector
<result_type
> results
7133 = gdb::parallel_for_each (1, per_bfd
->all_units
.begin (),
7134 per_bfd
->all_units
.end (),
7135 [=] (iter_type iter
, iter_type end
)
7137 std::vector
<gdb_exception
> errors
;
7138 cooked_index_storage thread_storage
;
7139 for (; iter
!= end
; ++iter
)
7141 dwarf2_per_cu_data
*per_cu
= iter
->get ();
7144 process_psymtab_comp_unit (per_cu
, per_objfile
,
7147 catch (gdb_exception
&except
)
7149 errors
.push_back (std::move (except
));
7152 return result_type (thread_storage
.release (), std::move (errors
));
7155 /* Only show a given exception a single time. */
7156 std::unordered_set
<gdb_exception
> seen_exceptions
;
7157 for (auto &one_result
: results
)
7159 indexes
.push_back (std::move (one_result
.first
));
7160 for (auto &one_exc
: one_result
.second
)
7161 if (seen_exceptions
.insert (one_exc
).second
)
7162 exception_print (gdb_stderr
, one_exc
);
7166 /* This has to wait until we read the CUs, we need the list of DWOs. */
7167 process_skeletonless_type_units (per_objfile
, &index_storage
);
7169 if (dwarf_read_debug
> 0)
7170 print_tu_stats (per_objfile
);
7172 indexes
.push_back (index_storage
.release ());
7173 indexes
.shrink_to_fit ();
7175 cooked_index_vector
*vec
= new cooked_index_vector (std::move (indexes
));
7176 per_bfd
->index_table
.reset (vec
);
7178 const cooked_index_entry
*main_entry
= vec
->get_main ();
7179 if (main_entry
!= nullptr)
7180 set_objfile_main_name (objfile
, main_entry
->name
,
7181 main_entry
->per_cu
->lang ());
7183 dwarf_read_debug_printf ("Done building psymtabs of %s",
7184 objfile_name (objfile
));
7188 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7189 struct dwarf2_section_info
*section
,
7190 struct dwarf2_section_info
*abbrev_section
,
7191 unsigned int is_dwz
,
7192 htab_up
&types_htab
,
7193 rcuh_kind section_kind
)
7195 const gdb_byte
*info_ptr
;
7196 struct objfile
*objfile
= per_objfile
->objfile
;
7198 dwarf_read_debug_printf ("Reading %s for %s",
7199 section
->get_name (),
7200 section
->get_file_name ());
7202 section
->read (objfile
);
7204 info_ptr
= section
->buffer
;
7206 while (info_ptr
< section
->buffer
+ section
->size
)
7208 dwarf2_per_cu_data_up this_cu
;
7210 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7212 comp_unit_head cu_header
;
7213 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7214 abbrev_section
, info_ptr
,
7217 /* Save the compilation unit for later lookup. */
7218 if (cu_header
.unit_type
!= DW_UT_type
)
7219 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7222 if (types_htab
== nullptr)
7223 types_htab
= allocate_signatured_type_table ();
7225 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7226 (cu_header
.signature
);
7227 signatured_type
*sig_ptr
= sig_type
.get ();
7228 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7229 this_cu
.reset (sig_type
.release ());
7231 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7232 gdb_assert (slot
!= nullptr);
7233 if (*slot
!= nullptr)
7234 complaint (_("debug type entry at offset %s is duplicate to"
7235 " the entry at offset %s, signature %s"),
7236 sect_offset_str (sect_off
),
7237 sect_offset_str (sig_ptr
->sect_off
),
7238 hex_string (sig_ptr
->signature
));
7241 this_cu
->sect_off
= sect_off
;
7242 this_cu
->set_length (cu_header
.get_length_with_initial ());
7243 this_cu
->is_dwz
= is_dwz
;
7244 this_cu
->section
= section
;
7245 /* Init this asap, to avoid a data race in the set_version in
7246 cutu_reader::cutu_reader (which may be run in parallel for the cooked
7248 this_cu
->set_version (cu_header
.version
);
7250 info_ptr
= info_ptr
+ this_cu
->length ();
7251 per_objfile
->per_bfd
->all_units
.push_back (std::move (this_cu
));
7255 /* Initialize the views on all_units. */
7258 finalize_all_units (dwarf2_per_bfd
*per_bfd
)
7260 size_t nr_tus
= per_bfd
->tu_stats
.nr_tus
;
7261 size_t nr_cus
= per_bfd
->all_units
.size () - nr_tus
;
7262 gdb::array_view
<dwarf2_per_cu_data_up
> tmp
= per_bfd
->all_units
;
7263 per_bfd
->all_comp_units
= tmp
.slice (0, nr_cus
);
7264 per_bfd
->all_type_units
= tmp
.slice (nr_cus
, nr_tus
);
7267 /* Create a list of all compilation units in OBJFILE.
7268 This is only done for -readnow and building partial symtabs. */
7271 create_all_units (dwarf2_per_objfile
*per_objfile
)
7274 gdb_assert (per_objfile
->per_bfd
->all_units
.empty ());
7276 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7277 &per_objfile
->per_bfd
->abbrev
, 0,
7278 types_htab
, rcuh_kind::COMPILE
);
7279 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7280 read_comp_units_from_section (per_objfile
, §ion
,
7281 &per_objfile
->per_bfd
->abbrev
, 0,
7282 types_htab
, rcuh_kind::TYPE
);
7287 dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7289 catch (const gdb_exception_error
&)
7291 per_objfile
->per_bfd
->all_units
.clear ();
7296 /* Pre-read the sections we'll need to construct an index. */
7297 struct objfile
*objfile
= per_objfile
->objfile
;
7298 dwz
->abbrev
.read (objfile
);
7299 dwz
->info
.read (objfile
);
7300 dwz
->str
.read (objfile
);
7301 dwz
->line
.read (objfile
);
7302 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7303 types_htab
, rcuh_kind::COMPILE
);
7306 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7308 finalize_all_units (per_objfile
->per_bfd
);
7311 /* Return the initial uleb128 in the die at INFO_PTR. */
7314 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7316 unsigned int bytes_read
;
7318 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7321 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
7322 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
7324 Return the corresponding abbrev, or NULL if the number is zero (indicating
7325 an empty DIE). In either case *BYTES_READ will be set to the length of
7326 the initial number. */
7328 static const struct abbrev_info
*
7329 peek_die_abbrev (const die_reader_specs
&reader
,
7330 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
7332 dwarf2_cu
*cu
= reader
.cu
;
7333 bfd
*abfd
= reader
.abfd
;
7334 unsigned int abbrev_number
7335 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7337 if (abbrev_number
== 0)
7340 const abbrev_info
*abbrev
7341 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
7344 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7345 " at offset %s [in module %s]"),
7346 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7347 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
7353 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7354 Returns a pointer to the end of a series of DIEs, terminated by an empty
7355 DIE. Any children of the skipped DIEs will also be skipped. */
7357 static const gdb_byte
*
7358 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7362 unsigned int bytes_read
;
7363 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
7367 return info_ptr
+ bytes_read
;
7369 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7373 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7374 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7375 abbrev corresponding to that skipped uleb128 should be passed in
7378 If DO_SKIP_CHILDREN is true, or if the DIE has no children, this
7379 returns a pointer to this DIE's sibling, skipping any children.
7380 Otherwise, returns a pointer to the DIE's first child. */
7382 static const gdb_byte
*
7383 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7384 const struct abbrev_info
*abbrev
, bool do_skip_children
)
7386 unsigned int bytes_read
;
7387 struct attribute attr
;
7388 bfd
*abfd
= reader
->abfd
;
7389 struct dwarf2_cu
*cu
= reader
->cu
;
7390 const gdb_byte
*buffer
= reader
->buffer
;
7391 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7392 unsigned int form
, i
;
7394 if (do_skip_children
&& abbrev
->sibling_offset
!= (unsigned short) -1)
7396 /* We only handle DW_FORM_ref4 here. */
7397 const gdb_byte
*sibling_data
= info_ptr
+ abbrev
->sibling_offset
;
7398 unsigned int offset
= read_4_bytes (abfd
, sibling_data
);
7399 const gdb_byte
*sibling_ptr
7400 = buffer
+ to_underlying (cu
->header
.sect_off
) + offset
;
7401 if (sibling_ptr
>= info_ptr
&& sibling_ptr
< reader
->buffer_end
)
7403 /* Fall through to the slow way. */
7405 else if (abbrev
->size_if_constant
!= 0)
7407 info_ptr
+= abbrev
->size_if_constant
;
7408 if (do_skip_children
&& abbrev
->has_children
)
7409 return skip_children (reader
, info_ptr
);
7413 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7415 /* The only abbrev we care about is DW_AT_sibling. */
7416 if (do_skip_children
&& abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7418 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7419 if (attr
.form
== DW_FORM_ref_addr
)
7420 complaint (_("ignoring absolute DW_AT_sibling"));
7423 sect_offset off
= attr
.get_ref_die_offset ();
7424 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
7426 if (sibling_ptr
< info_ptr
)
7427 complaint (_("DW_AT_sibling points backwards"));
7428 else if (sibling_ptr
> reader
->buffer_end
)
7429 reader
->die_section
->overflow_complaint ();
7435 /* If it isn't DW_AT_sibling, skip this attribute. */
7436 form
= abbrev
->attrs
[i
].form
;
7440 case DW_FORM_ref_addr
:
7441 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7442 and later it is offset sized. */
7443 if (cu
->header
.version
== 2)
7444 info_ptr
+= cu
->header
.addr_size
;
7446 info_ptr
+= cu
->header
.offset_size
;
7448 case DW_FORM_GNU_ref_alt
:
7449 info_ptr
+= cu
->header
.offset_size
;
7452 info_ptr
+= cu
->header
.addr_size
;
7460 case DW_FORM_flag_present
:
7461 case DW_FORM_implicit_const
:
7478 case DW_FORM_ref_sig8
:
7481 case DW_FORM_data16
:
7484 case DW_FORM_string
:
7485 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7486 info_ptr
+= bytes_read
;
7488 case DW_FORM_sec_offset
:
7490 case DW_FORM_GNU_strp_alt
:
7491 info_ptr
+= cu
->header
.offset_size
;
7493 case DW_FORM_exprloc
:
7495 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7496 info_ptr
+= bytes_read
;
7498 case DW_FORM_block1
:
7499 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7501 case DW_FORM_block2
:
7502 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7504 case DW_FORM_block4
:
7505 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7511 case DW_FORM_ref_udata
:
7512 case DW_FORM_GNU_addr_index
:
7513 case DW_FORM_GNU_str_index
:
7514 case DW_FORM_rnglistx
:
7515 case DW_FORM_loclistx
:
7516 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7518 case DW_FORM_indirect
:
7519 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7520 info_ptr
+= bytes_read
;
7521 /* We need to continue parsing from here, so just go back to
7523 goto skip_attribute
;
7526 error (_("Dwarf Error: Cannot handle %s "
7527 "in DWARF reader [in module %s]"),
7528 dwarf_form_name (form
),
7529 bfd_get_filename (abfd
));
7533 if (do_skip_children
&& abbrev
->has_children
)
7534 return skip_children (reader
, info_ptr
);
7539 /* Reading in full CUs. */
7541 /* Add PER_CU to the queue. */
7544 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
7545 dwarf2_per_objfile
*per_objfile
,
7546 enum language pretend_language
)
7550 gdb_assert (per_objfile
->queue
.has_value ());
7551 per_objfile
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
7554 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
7556 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7559 Return true if maybe_queue_comp_unit requires the caller to load the CU's
7560 DIEs, false otherwise.
7562 Explanation: there is an invariant that if a CU is queued for expansion
7563 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
7564 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
7565 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
7566 are not yet loaded, the the caller must load the CU's DIEs to ensure the
7567 invariant is respected.
7569 The caller is therefore not required to load the CU's DIEs (we return false)
7572 - the CU is already expanded, and therefore does not get enqueued
7573 - the CU gets enqueued for expansion, but its DIEs are already loaded
7575 Note that the caller should not use this function's return value as an
7576 indicator of whether the CU's DIEs are loaded right now, it should check
7577 that by calling `dwarf2_per_objfile::get_cu` instead. */
7580 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7581 dwarf2_per_cu_data
*per_cu
,
7582 dwarf2_per_objfile
*per_objfile
,
7583 enum language pretend_language
)
7585 /* Mark the dependence relation so that we don't flush PER_CU
7587 if (dependent_cu
!= NULL
)
7588 dependent_cu
->add_dependence (per_cu
);
7590 /* If it's already on the queue, we have nothing to do. */
7593 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
7595 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
7597 /* If the CU is queued for expansion, it should not already be
7599 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
7601 /* The DIEs are already loaded, the caller doesn't need to do it. */
7605 bool queued
= false;
7606 if (!per_objfile
->symtab_set_p (per_cu
))
7608 /* Add it to the queue. */
7609 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
7613 /* If the compilation unit is already loaded, just mark it as
7615 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
7619 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
7620 and the DIEs are not already loaded. */
7621 return queued
&& cu
== nullptr;
7624 /* Process the queue. */
7627 process_queue (dwarf2_per_objfile
*per_objfile
)
7629 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
7630 objfile_name (per_objfile
->objfile
));
7632 /* The queue starts out with one item, but following a DIE reference
7633 may load a new CU, adding it to the end of the queue. */
7634 while (!per_objfile
->queue
->empty ())
7636 dwarf2_queue_item
&item
= per_objfile
->queue
->front ();
7637 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
7639 if (!per_objfile
->symtab_set_p (per_cu
))
7641 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
7643 /* Skip dummy CUs. */
7646 unsigned int debug_print_threshold
;
7649 if (per_cu
->is_debug_types
)
7651 struct signatured_type
*sig_type
=
7652 (struct signatured_type
*) per_cu
;
7654 sprintf (buf
, "TU %s at offset %s",
7655 hex_string (sig_type
->signature
),
7656 sect_offset_str (per_cu
->sect_off
));
7657 /* There can be 100s of TUs.
7658 Only print them in verbose mode. */
7659 debug_print_threshold
= 2;
7663 sprintf (buf
, "CU at offset %s",
7664 sect_offset_str (per_cu
->sect_off
));
7665 debug_print_threshold
= 1;
7668 if (dwarf_read_debug
>= debug_print_threshold
)
7669 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
7671 if (per_cu
->is_debug_types
)
7672 process_full_type_unit (cu
, item
.pretend_language
);
7674 process_full_comp_unit (cu
, item
.pretend_language
);
7676 if (dwarf_read_debug
>= debug_print_threshold
)
7677 dwarf_read_debug_printf ("Done expanding %s", buf
);
7682 per_objfile
->queue
->pop ();
7685 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
7686 objfile_name (per_objfile
->objfile
));
7689 /* Trivial hash function for die_info: the hash value of a DIE
7690 is its offset in .debug_info for this objfile. */
7693 die_hash (const void *item
)
7695 const struct die_info
*die
= (const struct die_info
*) item
;
7697 return to_underlying (die
->sect_off
);
7700 /* Trivial comparison function for die_info structures: two DIEs
7701 are equal if they have the same offset. */
7704 die_eq (const void *item_lhs
, const void *item_rhs
)
7706 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
7707 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
7709 return die_lhs
->sect_off
== die_rhs
->sect_off
;
7712 /* Load the DIEs associated with PER_CU into memory.
7714 In some cases, the caller, while reading partial symbols, will need to load
7715 the full symbols for the CU for some reason. It will already have a
7716 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
7717 rather than creating a new one. */
7720 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
7721 dwarf2_per_objfile
*per_objfile
,
7722 dwarf2_cu
*existing_cu
,
7724 enum language pretend_language
)
7726 gdb_assert (! this_cu
->is_debug_types
);
7728 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
7732 struct dwarf2_cu
*cu
= reader
.cu
;
7733 const gdb_byte
*info_ptr
= reader
.info_ptr
;
7735 gdb_assert (cu
->die_hash
== NULL
);
7737 htab_create_alloc_ex (cu
->header
.get_length_without_initial () / 12,
7741 &cu
->comp_unit_obstack
,
7742 hashtab_obstack_allocate
,
7743 dummy_obstack_deallocate
);
7745 if (reader
.comp_unit_die
->has_children
)
7746 reader
.comp_unit_die
->child
7747 = read_die_and_siblings (&reader
, reader
.info_ptr
,
7748 &info_ptr
, reader
.comp_unit_die
);
7749 cu
->dies
= reader
.comp_unit_die
;
7750 /* comp_unit_die is not stored in die_hash, no need. */
7752 /* We try not to read any attributes in this function, because not
7753 all CUs needed for references have been loaded yet, and symbol
7754 table processing isn't initialized. But we have to set the CU language,
7755 or we won't be able to build types correctly.
7756 Similarly, if we do not read the producer, we can not apply
7757 producer-specific interpretation. */
7758 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
7763 /* Add a DIE to the delayed physname list. */
7766 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7767 const char *name
, struct die_info
*die
,
7768 struct dwarf2_cu
*cu
)
7770 struct delayed_method_info mi
;
7772 mi
.fnfield_index
= fnfield_index
;
7776 cu
->method_list
.push_back (mi
);
7779 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
7780 "const" / "volatile". If so, decrements LEN by the length of the
7781 modifier and return true. Otherwise return false. */
7785 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
7787 size_t mod_len
= sizeof (mod
) - 1;
7788 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
7796 /* Compute the physnames of any methods on the CU's method list.
7798 The computation of method physnames is delayed in order to avoid the
7799 (bad) condition that one of the method's formal parameters is of an as yet
7803 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7805 /* Only C++ delays computing physnames. */
7806 if (cu
->method_list
.empty ())
7808 gdb_assert (cu
->lang () == language_cplus
);
7810 for (const delayed_method_info
&mi
: cu
->method_list
)
7812 const char *physname
;
7813 struct fn_fieldlist
*fn_flp
7814 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
7815 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
7816 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
7817 = physname
? physname
: "";
7819 /* Since there's no tag to indicate whether a method is a
7820 const/volatile overload, extract that information out of the
7822 if (physname
!= NULL
)
7824 size_t len
= strlen (physname
);
7828 if (physname
[len
] == ')') /* shortcut */
7830 else if (check_modifier (physname
, len
, " const"))
7831 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
7832 else if (check_modifier (physname
, len
, " volatile"))
7833 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
7840 /* The list is no longer needed. */
7841 cu
->method_list
.clear ();
7844 /* Go objects should be embedded in a DW_TAG_module DIE,
7845 and it's not clear if/how imported objects will appear.
7846 To keep Go support simple until that's worked out,
7847 go back through what we've read and create something usable.
7848 We could do this while processing each DIE, and feels kinda cleaner,
7849 but that way is more invasive.
7850 This is to, for example, allow the user to type "p var" or "b main"
7851 without having to specify the package name, and allow lookups
7852 of module.object to work in contexts that use the expression
7856 fixup_go_packaging (struct dwarf2_cu
*cu
)
7858 gdb::unique_xmalloc_ptr
<char> package_name
;
7859 struct pending
*list
;
7862 for (list
= *cu
->get_builder ()->get_global_symbols ();
7866 for (i
= 0; i
< list
->nsyms
; ++i
)
7868 struct symbol
*sym
= list
->symbol
[i
];
7870 if (sym
->language () == language_go
7871 && sym
->aclass () == LOC_BLOCK
)
7873 gdb::unique_xmalloc_ptr
<char> this_package_name
7874 (go_symbol_package_name (sym
));
7876 if (this_package_name
== NULL
)
7878 if (package_name
== NULL
)
7879 package_name
= std::move (this_package_name
);
7882 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
7883 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
7884 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
7885 (sym
->symtab () != NULL
7886 ? symtab_to_filename_for_display
7888 : objfile_name (objfile
)),
7889 this_package_name
.get (), package_name
.get ());
7895 if (package_name
!= NULL
)
7897 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
7898 const char *saved_package_name
= objfile
->intern (package_name
.get ());
7899 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
7900 saved_package_name
);
7903 sym
= new (&objfile
->objfile_obstack
) symbol
;
7904 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
7905 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
7906 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7907 e.g., "main" finds the "main" module and not C's main(). */
7908 sym
->set_domain (STRUCT_DOMAIN
);
7909 sym
->set_aclass_index (LOC_TYPEDEF
);
7910 sym
->set_type (type
);
7912 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
7916 /* Allocate a fully-qualified name consisting of the two parts on the
7920 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
7922 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
7925 /* A helper that allocates a variant part to attach to a Rust enum
7926 type. OBSTACK is where the results should be allocated. TYPE is
7927 the type we're processing. DISCRIMINANT_INDEX is the index of the
7928 discriminant. It must be the index of one of the fields of TYPE,
7929 or -1 to mean there is no discriminant (univariant enum).
7930 DEFAULT_INDEX is the index of the default field; or -1 if there is
7931 no default. RANGES is indexed by "effective" field number (the
7932 field index, but omitting the discriminant and default fields) and
7933 must hold the discriminant values used by the variants. Note that
7934 RANGES must have a lifetime at least as long as OBSTACK -- either
7935 already allocated on it, or static. */
7938 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
7939 int discriminant_index
, int default_index
,
7940 gdb::array_view
<discriminant_range
> ranges
)
7942 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
7943 gdb_assert (discriminant_index
== -1
7944 || (discriminant_index
>= 0
7945 && discriminant_index
< type
->num_fields ()));
7946 gdb_assert (default_index
== -1
7947 || (default_index
>= 0 && default_index
< type
->num_fields ()));
7949 /* We have one variant for each non-discriminant field. */
7950 int n_variants
= type
->num_fields ();
7951 if (discriminant_index
!= -1)
7954 variant
*variants
= new (obstack
) variant
[n_variants
];
7957 for (int i
= 0; i
< type
->num_fields (); ++i
)
7959 if (i
== discriminant_index
)
7962 variants
[var_idx
].first_field
= i
;
7963 variants
[var_idx
].last_field
= i
+ 1;
7965 /* The default field does not need a range, but other fields do.
7966 We skipped the discriminant above. */
7967 if (i
!= default_index
)
7969 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
7976 gdb_assert (range_idx
== ranges
.size ());
7977 gdb_assert (var_idx
== n_variants
);
7979 variant_part
*part
= new (obstack
) variant_part
;
7980 part
->discriminant_index
= discriminant_index
;
7981 /* If there is no discriminant, then whether it is signed is of no
7984 = (discriminant_index
== -1
7986 : type
->field (discriminant_index
).type ()->is_unsigned ());
7987 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
7989 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
7990 gdb::array_view
<variant_part
> *prop_value
7991 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
7993 struct dynamic_prop prop
;
7994 prop
.set_variant_parts (prop_value
);
7996 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
7999 /* Some versions of rustc emitted enums in an unusual way.
8001 Ordinary enums were emitted as unions. The first element of each
8002 structure in the union was named "RUST$ENUM$DISR". This element
8003 held the discriminant.
8005 These versions of Rust also implemented the "non-zero"
8006 optimization. When the enum had two values, and one is empty and
8007 the other holds a pointer that cannot be zero, the pointer is used
8008 as the discriminant, with a zero value meaning the empty variant.
8009 Here, the union's first member is of the form
8010 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
8011 where the fieldnos are the indices of the fields that should be
8012 traversed in order to find the field (which may be several fields deep)
8013 and the variantname is the name of the variant of the case when the
8016 This function recognizes whether TYPE is of one of these forms,
8017 and, if so, smashes it to be a variant type. */
8020 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
8022 gdb_assert (type
->code () == TYPE_CODE_UNION
);
8024 /* We don't need to deal with empty enums. */
8025 if (type
->num_fields () == 0)
8028 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
8029 if (type
->num_fields () == 1
8030 && startswith (type
->field (0).name (), RUST_ENUM_PREFIX
))
8032 const char *name
= type
->field (0).name () + strlen (RUST_ENUM_PREFIX
);
8034 /* Decode the field name to find the offset of the
8036 ULONGEST bit_offset
= 0;
8037 struct type
*field_type
= type
->field (0).type ();
8038 while (name
[0] >= '0' && name
[0] <= '9')
8041 unsigned long index
= strtoul (name
, &tail
, 10);
8044 || index
>= field_type
->num_fields ()
8045 || (field_type
->field (index
).loc_kind ()
8046 != FIELD_LOC_KIND_BITPOS
))
8048 complaint (_("Could not parse Rust enum encoding string \"%s\""
8050 type
->field (0).name (),
8051 objfile_name (objfile
));
8056 bit_offset
+= field_type
->field (index
).loc_bitpos ();
8057 field_type
= field_type
->field (index
).type ();
8060 /* Smash this type to be a structure type. We have to do this
8061 because the type has already been recorded. */
8062 type
->set_code (TYPE_CODE_STRUCT
);
8063 type
->set_num_fields (3);
8064 /* Save the field we care about. */
8065 struct field saved_field
= type
->field (0);
8067 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
8069 /* Put the discriminant at index 0. */
8070 type
->field (0).set_type (field_type
);
8071 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
8072 type
->field (0).set_name ("<<discriminant>>");
8073 type
->field (0).set_loc_bitpos (bit_offset
);
8075 /* The order of fields doesn't really matter, so put the real
8076 field at index 1 and the data-less field at index 2. */
8077 type
->field (1) = saved_field
;
8078 type
->field (1).set_name
8079 (rust_last_path_segment (type
->field (1).type ()->name ()));
8080 type
->field (1).type ()->set_name
8081 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8082 type
->field (1).name ()));
8084 const char *dataless_name
8085 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8087 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
8089 type
->field (2).set_type (dataless_type
);
8090 /* NAME points into the original discriminant name, which
8091 already has the correct lifetime. */
8092 type
->field (2).set_name (name
);
8093 type
->field (2).set_loc_bitpos (0);
8095 /* Indicate that this is a variant type. */
8096 static discriminant_range ranges
[1] = { { 0, 0 } };
8097 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
8099 /* A union with a single anonymous field is probably an old-style
8101 else if (type
->num_fields () == 1 && streq (type
->field (0).name (), ""))
8103 /* Smash this type to be a structure type. We have to do this
8104 because the type has already been recorded. */
8105 type
->set_code (TYPE_CODE_STRUCT
);
8107 struct type
*field_type
= type
->field (0).type ();
8108 const char *variant_name
8109 = rust_last_path_segment (field_type
->name ());
8110 type
->field (0).set_name (variant_name
);
8111 field_type
->set_name
8112 (rust_fully_qualify (&objfile
->objfile_obstack
,
8113 type
->name (), variant_name
));
8115 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
8119 struct type
*disr_type
= nullptr;
8120 for (int i
= 0; i
< type
->num_fields (); ++i
)
8122 disr_type
= type
->field (i
).type ();
8124 if (disr_type
->code () != TYPE_CODE_STRUCT
)
8126 /* All fields of a true enum will be structs. */
8129 else if (disr_type
->num_fields () == 0)
8131 /* Could be data-less variant, so keep going. */
8132 disr_type
= nullptr;
8134 else if (strcmp (disr_type
->field (0).name (),
8135 "RUST$ENUM$DISR") != 0)
8137 /* Not a Rust enum. */
8147 /* If we got here without a discriminant, then it's probably
8149 if (disr_type
== nullptr)
8152 /* Smash this type to be a structure type. We have to do this
8153 because the type has already been recorded. */
8154 type
->set_code (TYPE_CODE_STRUCT
);
8156 /* Make space for the discriminant field. */
8157 struct field
*disr_field
= &disr_type
->field (0);
8159 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
8160 * sizeof (struct field
)));
8161 memcpy (new_fields
+ 1, type
->fields (),
8162 type
->num_fields () * sizeof (struct field
));
8163 type
->set_fields (new_fields
);
8164 type
->set_num_fields (type
->num_fields () + 1);
8166 /* Install the discriminant at index 0 in the union. */
8167 type
->field (0) = *disr_field
;
8168 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
8169 type
->field (0).set_name ("<<discriminant>>");
8171 /* We need a way to find the correct discriminant given a
8172 variant name. For convenience we build a map here. */
8173 struct type
*enum_type
= disr_field
->type ();
8174 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
8175 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
8177 if (enum_type
->field (i
).loc_kind () == FIELD_LOC_KIND_ENUMVAL
)
8180 = rust_last_path_segment (enum_type
->field (i
).name ());
8181 discriminant_map
[name
] = enum_type
->field (i
).loc_enumval ();
8185 int n_fields
= type
->num_fields ();
8186 /* We don't need a range entry for the discriminant, but we do
8187 need one for every other field, as there is no default
8189 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
8192 /* Skip the discriminant here. */
8193 for (int i
= 1; i
< n_fields
; ++i
)
8195 /* Find the final word in the name of this variant's type.
8196 That name can be used to look up the correct
8198 const char *variant_name
8199 = rust_last_path_segment (type
->field (i
).type ()->name ());
8201 auto iter
= discriminant_map
.find (variant_name
);
8202 if (iter
!= discriminant_map
.end ())
8204 ranges
[i
- 1].low
= iter
->second
;
8205 ranges
[i
- 1].high
= iter
->second
;
8208 /* In Rust, each element should have the size of the
8210 type
->field (i
).type ()->set_length (type
->length ());
8212 /* Remove the discriminant field, if it exists. */
8213 struct type
*sub_type
= type
->field (i
).type ();
8214 if (sub_type
->num_fields () > 0)
8216 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
8217 sub_type
->set_fields (sub_type
->fields () + 1);
8219 type
->field (i
).set_name (variant_name
);
8221 (rust_fully_qualify (&objfile
->objfile_obstack
,
8222 type
->name (), variant_name
));
8225 /* Indicate that this is a variant type. */
8226 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
8227 gdb::array_view
<discriminant_range
> (ranges
,
8232 /* Rewrite some Rust unions to be structures with variants parts. */
8235 rust_union_quirks (struct dwarf2_cu
*cu
)
8237 gdb_assert (cu
->lang () == language_rust
);
8238 for (type
*type_
: cu
->rust_unions
)
8239 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
8240 /* We don't need this any more. */
8241 cu
->rust_unions
.clear ();
8246 type_unit_group_unshareable
*
8247 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
8249 auto iter
= this->m_type_units
.find (tu_group
);
8250 if (iter
!= this->m_type_units
.end ())
8251 return iter
->second
.get ();
8253 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
8254 type_unit_group_unshareable
*result
= uniq
.get ();
8255 this->m_type_units
[tu_group
] = std::move (uniq
);
8260 dwarf2_per_objfile::get_type_for_signatured_type
8261 (signatured_type
*sig_type
) const
8263 auto iter
= this->m_type_map
.find (sig_type
);
8264 if (iter
== this->m_type_map
.end ())
8267 return iter
->second
;
8270 void dwarf2_per_objfile::set_type_for_signatured_type
8271 (signatured_type
*sig_type
, struct type
*type
)
8273 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
8275 this->m_type_map
[sig_type
] = type
;
8278 /* A helper function for computing the list of all symbol tables
8279 included by PER_CU. */
8282 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
8283 htab_t all_children
, htab_t all_type_symtabs
,
8284 dwarf2_per_cu_data
*per_cu
,
8285 dwarf2_per_objfile
*per_objfile
,
8286 struct compunit_symtab
*immediate_parent
)
8288 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
8291 /* This inclusion and its children have been processed. */
8297 /* Only add a CU if it has a symbol table. */
8298 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
8301 /* If this is a type unit only add its symbol table if we haven't
8302 seen it yet (type unit per_cu's can share symtabs). */
8303 if (per_cu
->is_debug_types
)
8305 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
8309 result
->push_back (cust
);
8310 if (cust
->user
== NULL
)
8311 cust
->user
= immediate_parent
;
8316 result
->push_back (cust
);
8317 if (cust
->user
== NULL
)
8318 cust
->user
= immediate_parent
;
8322 if (!per_cu
->imported_symtabs_empty ())
8323 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
8325 recursively_compute_inclusions (result
, all_children
,
8326 all_type_symtabs
, ptr
, per_objfile
,
8331 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
8335 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
8336 dwarf2_per_objfile
*per_objfile
)
8338 gdb_assert (! per_cu
->is_debug_types
);
8340 if (!per_cu
->imported_symtabs_empty ())
8343 std::vector
<compunit_symtab
*> result_symtabs
;
8344 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
8346 /* If we don't have a symtab, we can just skip this case. */
8350 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
8352 NULL
, xcalloc
, xfree
));
8353 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
8355 NULL
, xcalloc
, xfree
));
8357 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
8359 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
8360 all_type_symtabs
.get (), ptr
,
8364 /* Now we have a transitive closure of all the included symtabs. */
8365 len
= result_symtabs
.size ();
8367 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
8368 struct compunit_symtab
*, len
+ 1);
8369 memcpy (cust
->includes
, result_symtabs
.data (),
8370 len
* sizeof (compunit_symtab
*));
8371 cust
->includes
[len
] = NULL
;
8375 /* Compute the 'includes' field for the symtabs of all the CUs we just
8379 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
8381 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
8383 if (! iter
->is_debug_types
)
8384 compute_compunit_symtab_includes (iter
, per_objfile
);
8387 per_objfile
->per_bfd
->just_read_cus
.clear ();
8390 /* Generate full symbol information for CU, whose DIEs have
8391 already been loaded into memory. */
8394 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
8396 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8397 struct objfile
*objfile
= per_objfile
->objfile
;
8398 struct gdbarch
*gdbarch
= objfile
->arch ();
8399 CORE_ADDR lowpc
, highpc
;
8400 struct compunit_symtab
*cust
;
8402 struct block
*static_block
;
8405 baseaddr
= objfile
->text_section_offset ();
8407 /* Clear the list here in case something was left over. */
8408 cu
->method_list
.clear ();
8410 dwarf2_find_base_address (cu
->dies
, cu
);
8412 /* Before we start reading the top-level DIE, ensure it has a valid tag
8414 switch (cu
->dies
->tag
)
8416 case DW_TAG_compile_unit
:
8417 case DW_TAG_partial_unit
:
8418 case DW_TAG_type_unit
:
8421 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
8422 dwarf_tag_name (cu
->dies
->tag
),
8423 sect_offset_str (cu
->per_cu
->sect_off
),
8424 objfile_name (per_objfile
->objfile
));
8427 /* Do line number decoding in read_file_scope () */
8428 process_die (cu
->dies
, cu
);
8430 /* For now fudge the Go package. */
8431 if (cu
->lang () == language_go
)
8432 fixup_go_packaging (cu
);
8434 /* Now that we have processed all the DIEs in the CU, all the types
8435 should be complete, and it should now be safe to compute all of the
8437 compute_delayed_physnames (cu
);
8439 if (cu
->lang () == language_rust
)
8440 rust_union_quirks (cu
);
8442 /* Some compilers don't define a DW_AT_high_pc attribute for the
8443 compilation unit. If the DW_AT_high_pc is missing, synthesize
8444 it, by scanning the DIE's below the compilation unit. */
8445 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8447 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8449 = cu
->get_builder ()->end_compunit_symtab_get_static_block (addr
, 0, 1);
8451 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8452 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8453 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8454 addrmap to help ensure it has an accurate map of pc values belonging to
8456 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8458 cust
= cu
->get_builder ()->end_compunit_symtab_from_static_block
8459 (static_block
, SECT_OFF_TEXT (objfile
), 0);
8463 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8465 /* Set symtab language to language from DW_AT_language. If the
8466 compilation is from a C file generated by language preprocessors, do
8467 not set the language if it was already deduced by start_subfile. */
8468 if (!(cu
->lang () == language_c
8469 && cust
->primary_filetab ()->language () != language_unknown
))
8470 cust
->primary_filetab ()->set_language (cu
->lang ());
8472 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8473 produce DW_AT_location with location lists but it can be possibly
8474 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8475 there were bugs in prologue debug info, fixed later in GCC-4.5
8476 by "unwind info for epilogues" patch (which is not directly related).
8478 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8479 needed, it would be wrong due to missing DW_AT_producer there.
8481 Still one can confuse GDB by using non-standard GCC compilation
8482 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8484 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8485 cust
->set_locations_valid (true);
8487 if (gcc_4_minor
>= 5)
8488 cust
->set_epilogue_unwind_valid (true);
8490 cust
->set_call_site_htab (cu
->call_site_htab
);
8493 per_objfile
->set_symtab (cu
->per_cu
, cust
);
8495 /* Push it for inclusion processing later. */
8496 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
8498 /* Not needed any more. */
8499 cu
->reset_builder ();
8502 /* Generate full symbol information for type unit CU, whose DIEs have
8503 already been loaded into memory. */
8506 process_full_type_unit (dwarf2_cu
*cu
,
8507 enum language pretend_language
)
8509 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8510 struct objfile
*objfile
= per_objfile
->objfile
;
8511 struct compunit_symtab
*cust
;
8512 struct signatured_type
*sig_type
;
8514 gdb_assert (cu
->per_cu
->is_debug_types
);
8515 sig_type
= (struct signatured_type
*) cu
->per_cu
;
8517 /* Clear the list here in case something was left over. */
8518 cu
->method_list
.clear ();
8520 /* The symbol tables are set up in read_type_unit_scope. */
8521 process_die (cu
->dies
, cu
);
8523 /* For now fudge the Go package. */
8524 if (cu
->lang () == language_go
)
8525 fixup_go_packaging (cu
);
8527 /* Now that we have processed all the DIEs in the CU, all the types
8528 should be complete, and it should now be safe to compute all of the
8530 compute_delayed_physnames (cu
);
8532 if (cu
->lang () == language_rust
)
8533 rust_union_quirks (cu
);
8535 /* TUs share symbol tables.
8536 If this is the first TU to use this symtab, complete the construction
8537 of it with end_expandable_symtab. Otherwise, complete the addition of
8538 this TU's symbols to the existing symtab. */
8539 type_unit_group_unshareable
*tug_unshare
=
8540 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
8541 if (tug_unshare
->compunit_symtab
== NULL
)
8543 buildsym_compunit
*builder
= cu
->get_builder ();
8544 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8545 tug_unshare
->compunit_symtab
= cust
;
8549 /* Set symtab language to language from DW_AT_language. If the
8550 compilation is from a C file generated by language preprocessors,
8551 do not set the language if it was already deduced by
8553 if (!(cu
->lang () == language_c
8554 && cust
->primary_filetab ()->language () != language_c
))
8555 cust
->primary_filetab ()->set_language (cu
->lang ());
8560 cu
->get_builder ()->augment_type_symtab ();
8561 cust
= tug_unshare
->compunit_symtab
;
8564 per_objfile
->set_symtab (cu
->per_cu
, cust
);
8566 /* Not needed any more. */
8567 cu
->reset_builder ();
8570 /* Process an imported unit DIE. */
8573 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8575 struct attribute
*attr
;
8577 /* For now we don't handle imported units in type units. */
8578 if (cu
->per_cu
->is_debug_types
)
8580 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8581 " supported in type units [in module %s]"),
8582 objfile_name (cu
->per_objfile
->objfile
));
8585 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8588 sect_offset sect_off
= attr
->get_ref_die_offset ();
8589 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8590 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8591 dwarf2_per_cu_data
*per_cu
8592 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
8593 per_objfile
->per_bfd
);
8595 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
8596 into another compilation unit, at root level. Regard this as a hint,
8597 and ignore it. This is a best effort, it only works if unit_type and
8598 lang are already set. */
8599 if (die
->parent
&& die
->parent
->parent
== NULL
8600 && per_cu
->unit_type (false) == DW_UT_compile
8601 && per_cu
->lang (false) == language_cplus
)
8604 /* If necessary, add it to the queue and load its DIEs. */
8605 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
8607 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
8608 false, cu
->lang ());
8610 cu
->per_cu
->imported_symtabs_push (per_cu
);
8614 /* RAII object that represents a process_die scope: i.e.,
8615 starts/finishes processing a DIE. */
8616 class process_die_scope
8619 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
8620 : m_die (die
), m_cu (cu
)
8622 /* We should only be processing DIEs not already in process. */
8623 gdb_assert (!m_die
->in_process
);
8624 m_die
->in_process
= true;
8627 ~process_die_scope ()
8629 m_die
->in_process
= false;
8631 /* If we're done processing the DIE for the CU that owns the line
8632 header, we don't need the line header anymore. */
8633 if (m_cu
->line_header_die_owner
== m_die
)
8635 delete m_cu
->line_header
;
8636 m_cu
->line_header
= NULL
;
8637 m_cu
->line_header_die_owner
= NULL
;
8646 /* Process a die and its children. */
8649 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8651 process_die_scope
scope (die
, cu
);
8655 case DW_TAG_padding
:
8657 case DW_TAG_compile_unit
:
8658 case DW_TAG_partial_unit
:
8659 read_file_scope (die
, cu
);
8661 case DW_TAG_type_unit
:
8662 read_type_unit_scope (die
, cu
);
8664 case DW_TAG_subprogram
:
8665 /* Nested subprograms in Fortran get a prefix. */
8666 if (cu
->lang () == language_fortran
8667 && die
->parent
!= NULL
8668 && die
->parent
->tag
== DW_TAG_subprogram
)
8669 cu
->processing_has_namespace_info
= true;
8671 case DW_TAG_inlined_subroutine
:
8672 read_func_scope (die
, cu
);
8674 case DW_TAG_lexical_block
:
8675 case DW_TAG_try_block
:
8676 case DW_TAG_catch_block
:
8677 read_lexical_block_scope (die
, cu
);
8679 case DW_TAG_call_site
:
8680 case DW_TAG_GNU_call_site
:
8681 read_call_site_scope (die
, cu
);
8683 case DW_TAG_class_type
:
8684 case DW_TAG_interface_type
:
8685 case DW_TAG_structure_type
:
8686 case DW_TAG_union_type
:
8687 case DW_TAG_namelist
:
8688 process_structure_scope (die
, cu
);
8690 case DW_TAG_enumeration_type
:
8691 process_enumeration_scope (die
, cu
);
8694 /* These dies have a type, but processing them does not create
8695 a symbol or recurse to process the children. Therefore we can
8696 read them on-demand through read_type_die. */
8697 case DW_TAG_subroutine_type
:
8698 case DW_TAG_set_type
:
8699 case DW_TAG_pointer_type
:
8700 case DW_TAG_ptr_to_member_type
:
8701 case DW_TAG_reference_type
:
8702 case DW_TAG_rvalue_reference_type
:
8703 case DW_TAG_string_type
:
8706 case DW_TAG_array_type
:
8707 /* We only need to handle this case for Ada -- in other
8708 languages, it's normal for the compiler to emit a typedef
8710 if (cu
->lang () != language_ada
)
8713 case DW_TAG_base_type
:
8714 case DW_TAG_subrange_type
:
8715 case DW_TAG_generic_subrange
:
8716 case DW_TAG_typedef
:
8717 /* Add a typedef symbol for the type definition, if it has a
8719 new_symbol (die
, read_type_die (die
, cu
), cu
);
8721 case DW_TAG_common_block
:
8722 read_common_block (die
, cu
);
8724 case DW_TAG_common_inclusion
:
8726 case DW_TAG_namespace
:
8727 cu
->processing_has_namespace_info
= true;
8728 read_namespace (die
, cu
);
8731 cu
->processing_has_namespace_info
= true;
8732 read_module (die
, cu
);
8734 case DW_TAG_imported_declaration
:
8735 cu
->processing_has_namespace_info
= true;
8736 if (read_alias (die
, cu
))
8738 /* The declaration is neither a global namespace nor a variable
8741 case DW_TAG_imported_module
:
8742 cu
->processing_has_namespace_info
= true;
8743 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8744 || cu
->lang () != language_fortran
))
8745 complaint (_("Tag '%s' has unexpected children"),
8746 dwarf_tag_name (die
->tag
));
8747 read_import_statement (die
, cu
);
8750 case DW_TAG_imported_unit
:
8751 process_imported_unit_die (die
, cu
);
8754 case DW_TAG_variable
:
8755 read_variable (die
, cu
);
8759 new_symbol (die
, NULL
, cu
);
8764 /* DWARF name computation. */
8766 /* A helper function for dwarf2_compute_name which determines whether DIE
8767 needs to have the name of the scope prepended to the name listed in the
8771 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8773 struct attribute
*attr
;
8777 case DW_TAG_namespace
:
8778 case DW_TAG_typedef
:
8779 case DW_TAG_class_type
:
8780 case DW_TAG_interface_type
:
8781 case DW_TAG_structure_type
:
8782 case DW_TAG_union_type
:
8783 case DW_TAG_enumeration_type
:
8784 case DW_TAG_enumerator
:
8785 case DW_TAG_subprogram
:
8786 case DW_TAG_inlined_subroutine
:
8788 case DW_TAG_imported_declaration
:
8791 case DW_TAG_variable
:
8792 case DW_TAG_constant
:
8793 /* We only need to prefix "globally" visible variables. These include
8794 any variable marked with DW_AT_external or any variable that
8795 lives in a namespace. [Variables in anonymous namespaces
8796 require prefixing, but they are not DW_AT_external.] */
8798 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8800 struct dwarf2_cu
*spec_cu
= cu
;
8802 return die_needs_namespace (die_specification (die
, &spec_cu
),
8806 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8807 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8808 && die
->parent
->tag
!= DW_TAG_module
)
8810 /* A variable in a lexical block of some kind does not need a
8811 namespace, even though in C++ such variables may be external
8812 and have a mangled name. */
8813 if (die
->parent
->tag
== DW_TAG_lexical_block
8814 || die
->parent
->tag
== DW_TAG_try_block
8815 || die
->parent
->tag
== DW_TAG_catch_block
8816 || die
->parent
->tag
== DW_TAG_subprogram
)
8825 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
8826 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
8827 defined for the given DIE. */
8829 static struct attribute
*
8830 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
8832 struct attribute
*attr
;
8834 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
8836 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8841 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
8842 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
8843 defined for the given DIE. */
8846 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8848 const char *linkage_name
;
8850 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8851 if (linkage_name
== NULL
)
8852 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8854 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
8855 See https://github.com/rust-lang/rust/issues/32925. */
8856 if (cu
->lang () == language_rust
&& linkage_name
!= NULL
8857 && strchr (linkage_name
, '{') != NULL
)
8858 linkage_name
= NULL
;
8860 return linkage_name
;
8863 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8864 compute the physname for the object, which include a method's:
8865 - formal parameters (C++),
8866 - receiver type (Go),
8868 The term "physname" is a bit confusing.
8869 For C++, for example, it is the demangled name.
8870 For Go, for example, it's the mangled name.
8872 For Ada, return the DIE's linkage name rather than the fully qualified
8873 name. PHYSNAME is ignored..
8875 The result is allocated on the objfile->per_bfd's obstack and
8879 dwarf2_compute_name (const char *name
,
8880 struct die_info
*die
, struct dwarf2_cu
*cu
,
8883 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8886 name
= dwarf2_name (die
, cu
);
8888 enum language lang
= cu
->lang ();
8890 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
8891 but otherwise compute it by typename_concat inside GDB.
8892 FIXME: Actually this is not really true, or at least not always true.
8893 It's all very confusing. compute_and_set_names doesn't try to demangle
8894 Fortran names because there is no mangling standard. So new_symbol
8895 will set the demangled name to the result of dwarf2_full_name, and it is
8896 the demangled name that GDB uses if it exists. */
8897 if (lang
== language_ada
8898 || (lang
== language_fortran
&& physname
))
8900 /* For Ada unit, we prefer the linkage name over the name, as
8901 the former contains the exported name, which the user expects
8902 to be able to reference. Ideally, we want the user to be able
8903 to reference this entity using either natural or linkage name,
8904 but we haven't started looking at this enhancement yet. */
8905 const char *linkage_name
= dw2_linkage_name (die
, cu
);
8907 if (linkage_name
!= NULL
)
8908 return linkage_name
;
8911 /* These are the only languages we know how to qualify names in. */
8913 && (lang
== language_cplus
8914 || lang
== language_fortran
|| lang
== language_d
8915 || lang
== language_rust
))
8917 if (die_needs_namespace (die
, cu
))
8923 prefix
= determine_prefix (die
, cu
);
8924 if (*prefix
!= '\0')
8926 gdb::unique_xmalloc_ptr
<char> prefixed_name
8927 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
8929 buf
.puts (prefixed_name
.get ());
8934 /* Template parameters may be specified in the DIE's DW_AT_name, or
8935 as children with DW_TAG_template_type_param or
8936 DW_TAG_value_type_param. If the latter, add them to the name
8937 here. If the name already has template parameters, then
8938 skip this step; some versions of GCC emit both, and
8939 it is more efficient to use the pre-computed name.
8941 Something to keep in mind about this process: it is very
8942 unlikely, or in some cases downright impossible, to produce
8943 something that will match the mangled name of a function.
8944 If the definition of the function has the same debug info,
8945 we should be able to match up with it anyway. But fallbacks
8946 using the minimal symbol, for instance to find a method
8947 implemented in a stripped copy of libstdc++, will not work.
8948 If we do not have debug info for the definition, we will have to
8949 match them up some other way.
8951 When we do name matching there is a related problem with function
8952 templates; two instantiated function templates are allowed to
8953 differ only by their return types, which we do not add here. */
8955 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
8957 struct attribute
*attr
;
8958 struct die_info
*child
;
8961 die
->building_fullname
= 1;
8963 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8967 const gdb_byte
*bytes
;
8968 struct dwarf2_locexpr_baton
*baton
;
8971 if (child
->tag
!= DW_TAG_template_type_param
8972 && child
->tag
!= DW_TAG_template_value_param
)
8983 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8986 complaint (_("template parameter missing DW_AT_type"));
8987 buf
.puts ("UNKNOWN_TYPE");
8990 type
= die_type (child
, cu
);
8992 if (child
->tag
== DW_TAG_template_type_param
)
8994 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
8995 &type_print_raw_options
);
8999 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
9002 complaint (_("template parameter missing "
9003 "DW_AT_const_value"));
9004 buf
.puts ("UNKNOWN_VALUE");
9008 dwarf2_const_value_attr (attr
, type
, name
,
9009 &cu
->comp_unit_obstack
, cu
,
9010 &value
, &bytes
, &baton
);
9012 if (type
->has_no_signedness ())
9013 /* GDB prints characters as NUMBER 'CHAR'. If that's
9014 changed, this can use value_print instead. */
9015 cu
->language_defn
->printchar (value
, type
, &buf
);
9018 struct value_print_options opts
;
9021 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
9025 baton
->per_objfile
);
9026 else if (bytes
!= NULL
)
9028 v
= allocate_value (type
);
9029 memcpy (value_contents_writeable (v
).data (), bytes
,
9033 v
= value_from_longest (type
, value
);
9035 /* Specify decimal so that we do not depend on
9037 get_formatted_print_options (&opts
, 'd');
9039 value_print (v
, &buf
, &opts
);
9044 die
->building_fullname
= 0;
9048 /* Close the argument list, with a space if necessary
9049 (nested templates). */
9050 if (!buf
.empty () && buf
.string ().back () == '>')
9057 /* For C++ methods, append formal parameter type
9058 information, if PHYSNAME. */
9060 if (physname
&& die
->tag
== DW_TAG_subprogram
9061 && lang
== language_cplus
)
9063 struct type
*type
= read_type_die (die
, cu
);
9065 c_type_print_args (type
, &buf
, 1, lang
,
9066 &type_print_raw_options
);
9068 if (lang
== language_cplus
)
9070 /* Assume that an artificial first parameter is
9071 "this", but do not crash if it is not. RealView
9072 marks unnamed (and thus unused) parameters as
9073 artificial; there is no way to differentiate
9075 if (type
->num_fields () > 0
9076 && TYPE_FIELD_ARTIFICIAL (type
, 0)
9077 && type
->field (0).type ()->code () == TYPE_CODE_PTR
9078 && TYPE_CONST (type
->field (0).type ()->target_type ()))
9079 buf
.puts (" const");
9083 const std::string
&intermediate_name
= buf
.string ();
9085 const char *canonical_name
9086 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
9089 /* If we only computed INTERMEDIATE_NAME, or if
9090 INTERMEDIATE_NAME is already canonical, then we need to
9092 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
9093 name
= objfile
->intern (intermediate_name
);
9095 name
= canonical_name
;
9102 /* Return the fully qualified name of DIE, based on its DW_AT_name.
9103 If scope qualifiers are appropriate they will be added. The result
9104 will be allocated on the storage_obstack, or NULL if the DIE does
9105 not have a name. NAME may either be from a previous call to
9106 dwarf2_name or NULL.
9108 The output string will be canonicalized (if C++). */
9111 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
9113 return dwarf2_compute_name (name
, die
, cu
, 0);
9116 /* Construct a physname for the given DIE in CU. NAME may either be
9117 from a previous call to dwarf2_name or NULL. The result will be
9118 allocated on the objfile_objstack or NULL if the DIE does not have a
9121 The output string will be canonicalized (if C++). */
9124 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
9126 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9127 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
9130 /* In this case dwarf2_compute_name is just a shortcut not building anything
9132 if (!die_needs_namespace (die
, cu
))
9133 return dwarf2_compute_name (name
, die
, cu
, 1);
9135 if (cu
->lang () != language_rust
)
9136 mangled
= dw2_linkage_name (die
, cu
);
9138 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
9140 gdb::unique_xmalloc_ptr
<char> demangled
;
9141 if (mangled
!= NULL
)
9143 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
9145 /* Do nothing (do not demangle the symbol name). */
9149 /* Use DMGL_RET_DROP for C++ template functions to suppress
9150 their return type. It is easier for GDB users to search
9151 for such functions as `name(params)' than `long name(params)'.
9152 In such case the minimal symbol names do not match the full
9153 symbol names but for template functions there is never a need
9154 to look up their definition from their declaration so
9155 the only disadvantage remains the minimal symbol variant
9156 `long name(params)' does not have the proper inferior type. */
9157 demangled
= gdb_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
9161 canon
= demangled
.get ();
9169 if (canon
== NULL
|| check_physname
)
9171 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
9173 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
9175 /* It may not mean a bug in GDB. The compiler could also
9176 compute DW_AT_linkage_name incorrectly. But in such case
9177 GDB would need to be bug-to-bug compatible. */
9179 complaint (_("Computed physname <%s> does not match demangled <%s> "
9180 "(from linkage <%s>) - DIE at %s [in module %s]"),
9181 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
9182 objfile_name (objfile
));
9184 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
9185 is available here - over computed PHYSNAME. It is safer
9186 against both buggy GDB and buggy compilers. */
9200 retval
= objfile
->intern (retval
);
9205 /* Inspect DIE in CU for a namespace alias or a variable with alias
9206 attribute. If one exists, record a new symbol for it.
9208 Returns true if an alias was recorded, false otherwise. */
9211 read_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
9213 struct attribute
*attr
;
9215 /* If the die does not have a name, this is neither a namespace
9216 alias nor a variable alias. */
9217 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9221 struct die_info
*d
= die
;
9222 struct dwarf2_cu
*imported_cu
= cu
;
9224 /* If the compiler has nested DW_AT_imported_declaration DIEs,
9225 keep inspecting DIEs until we hit the underlying import. */
9226 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
9227 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
9229 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
9233 d
= follow_die_ref (d
, attr
, &imported_cu
);
9234 if (d
->tag
!= DW_TAG_imported_declaration
)
9238 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
9240 complaint (_("DIE at %s has too many recursively imported "
9241 "declarations"), sect_offset_str (d
->sect_off
));
9248 if (d
->tag
== DW_TAG_variable
)
9250 /* This declaration is a C/C++ global variable alias.
9251 Add a symbol for it whose type is the same as the
9252 aliased variable's. */
9253 type
= die_type (d
, imported_cu
);
9254 struct symbol
*sym
= new_symbol (die
, type
, cu
);
9255 attr
= dwarf2_attr (d
, DW_AT_location
, imported_cu
);
9256 sym
->set_aclass_index (LOC_UNRESOLVED
);
9257 if (attr
!= nullptr)
9258 var_decode_location (attr
, sym
, cu
);
9263 sect_offset sect_off
= attr
->get_ref_die_offset ();
9264 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
,
9266 if (type
!= nullptr && type
->code () == TYPE_CODE_NAMESPACE
)
9268 /* This declaration is a global namespace alias. Add
9269 a symbol for it whose type is the aliased
9271 new_symbol (die
, type
, cu
);
9280 /* Return the using directives repository (global or local?) to use in the
9281 current context for CU.
9283 For Ada, imported declarations can materialize renamings, which *may* be
9284 global. However it is impossible (for now?) in DWARF to distinguish
9285 "external" imported declarations and "static" ones. As all imported
9286 declarations seem to be static in all other languages, make them all CU-wide
9287 global only in Ada. */
9289 static struct using_direct
**
9290 using_directives (struct dwarf2_cu
*cu
)
9292 if (cu
->lang () == language_ada
9293 && cu
->get_builder ()->outermost_context_p ())
9294 return cu
->get_builder ()->get_global_using_directives ();
9296 return cu
->get_builder ()->get_local_using_directives ();
9299 /* Read the DW_ATTR_decl_line attribute for the given DIE in the
9300 given CU. If the format is not recognized or the attribute is
9301 not present, set it to 0. */
9304 read_decl_line (struct die_info
*die
, struct dwarf2_cu
*cu
)
9306 struct attribute
*decl_line
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
9307 if (decl_line
== nullptr)
9309 if (decl_line
->form_is_constant ())
9311 LONGEST val
= decl_line
->constant_value (0);
9312 if (0 <= val
&& val
<= UINT_MAX
)
9313 return (unsigned int) val
;
9315 complaint (_("Declared line for using directive is too large"));
9319 complaint (_("Declared line for using directive is of incorrect format"));
9323 /* Read the import statement specified by the given die and record it. */
9326 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
9328 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9329 struct attribute
*import_attr
;
9330 struct die_info
*imported_die
, *child_die
;
9331 struct dwarf2_cu
*imported_cu
;
9332 const char *imported_name
;
9333 const char *imported_name_prefix
;
9334 const char *canonical_name
;
9335 const char *import_alias
;
9336 const char *imported_declaration
= NULL
;
9337 const char *import_prefix
;
9338 std::vector
<const char *> excludes
;
9340 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9341 if (import_attr
== NULL
)
9343 complaint (_("Tag '%s' has no DW_AT_import"),
9344 dwarf_tag_name (die
->tag
));
9349 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
9350 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9351 if (imported_name
== NULL
)
9353 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
9355 The import in the following code:
9369 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
9370 <52> DW_AT_decl_file : 1
9371 <53> DW_AT_decl_line : 6
9372 <54> DW_AT_import : <0x75>
9373 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
9375 <5b> DW_AT_decl_file : 1
9376 <5c> DW_AT_decl_line : 2
9377 <5d> DW_AT_type : <0x6e>
9379 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
9380 <76> DW_AT_byte_size : 4
9381 <77> DW_AT_encoding : 5 (signed)
9383 imports the wrong die ( 0x75 instead of 0x58 ).
9384 This case will be ignored until the gcc bug is fixed. */
9388 /* Figure out the local name after import. */
9389 import_alias
= dwarf2_name (die
, cu
);
9391 /* Figure out where the statement is being imported to. */
9392 import_prefix
= determine_prefix (die
, cu
);
9394 /* Figure out what the scope of the imported die is and prepend it
9395 to the name of the imported die. */
9396 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
9398 if (imported_die
->tag
!= DW_TAG_namespace
9399 && imported_die
->tag
!= DW_TAG_module
)
9401 imported_declaration
= imported_name
;
9402 canonical_name
= imported_name_prefix
;
9404 else if (strlen (imported_name_prefix
) > 0)
9405 canonical_name
= obconcat (&objfile
->objfile_obstack
,
9406 imported_name_prefix
,
9407 (cu
->lang () == language_d
9410 imported_name
, (char *) NULL
);
9412 canonical_name
= imported_name
;
9414 if (die
->tag
== DW_TAG_imported_module
9415 && cu
->lang () == language_fortran
)
9416 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9417 child_die
= child_die
->sibling
)
9419 /* DWARF-4: A Fortran use statement with a “rename list” may be
9420 represented by an imported module entry with an import attribute
9421 referring to the module and owned entries corresponding to those
9422 entities that are renamed as part of being imported. */
9424 if (child_die
->tag
!= DW_TAG_imported_declaration
)
9426 complaint (_("child DW_TAG_imported_declaration expected "
9427 "- DIE at %s [in module %s]"),
9428 sect_offset_str (child_die
->sect_off
),
9429 objfile_name (objfile
));
9433 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
9434 if (import_attr
== NULL
)
9436 complaint (_("Tag '%s' has no DW_AT_import"),
9437 dwarf_tag_name (child_die
->tag
));
9442 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
9444 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9445 if (imported_name
== NULL
)
9447 complaint (_("child DW_TAG_imported_declaration has unknown "
9448 "imported name - DIE at %s [in module %s]"),
9449 sect_offset_str (child_die
->sect_off
),
9450 objfile_name (objfile
));
9454 excludes
.push_back (imported_name
);
9456 process_die (child_die
, cu
);
9459 add_using_directive (using_directives (cu
),
9463 imported_declaration
,
9465 read_decl_line (die
, cu
),
9467 &objfile
->objfile_obstack
);
9470 /* ICC<14 does not output the required DW_AT_declaration on incomplete
9471 types, but gives them a size of zero. Starting with version 14,
9472 ICC is compatible with GCC. */
9475 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
9477 if (!cu
->checked_producer
)
9478 check_producer (cu
);
9480 return cu
->producer_is_icc_lt_14
;
9483 /* ICC generates a DW_AT_type for C void functions. This was observed on
9484 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
9485 which says that void functions should not have a DW_AT_type. */
9488 producer_is_icc (struct dwarf2_cu
*cu
)
9490 if (!cu
->checked_producer
)
9491 check_producer (cu
);
9493 return cu
->producer_is_icc
;
9496 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9497 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9498 this, it was first present in GCC release 4.3.0. */
9501 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9503 if (!cu
->checked_producer
)
9504 check_producer (cu
);
9506 return cu
->producer_is_gcc_lt_4_3
;
9509 /* See dwarf2/read.h. */
9511 producer_is_clang (struct dwarf2_cu
*cu
)
9513 if (!cu
->checked_producer
)
9514 check_producer (cu
);
9516 return cu
->producer_is_clang
;
9519 static file_and_directory
&
9520 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
9522 if (cu
->per_cu
->fnd
!= nullptr)
9523 return *cu
->per_cu
->fnd
;
9525 /* Find the filename. Do not use dwarf2_name here, since the filename
9526 is not a source language identifier. */
9527 file_and_directory
res (dwarf2_string_attr (die
, DW_AT_name
, cu
),
9528 dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
));
9530 if (res
.get_comp_dir () == nullptr
9531 && producer_is_gcc_lt_4_3 (cu
)
9532 && res
.get_name () != nullptr
9533 && IS_ABSOLUTE_PATH (res
.get_name ()))
9535 res
.set_comp_dir (ldirname (res
.get_name ()));
9536 res
.set_name (make_unique_xstrdup (lbasename (res
.get_name ())));
9539 cu
->per_cu
->fnd
.reset (new file_and_directory (std::move (res
)));
9540 return *cu
->per_cu
->fnd
;
9543 /* Handle DW_AT_stmt_list for a compilation unit.
9544 DIE is the DW_TAG_compile_unit die for CU.
9545 COMP_DIR is the compilation directory. LOWPC is passed to
9546 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9549 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9550 const file_and_directory
&fnd
, CORE_ADDR lowpc
,
9551 bool have_code
) /* ARI: editCase function */
9553 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9554 struct attribute
*attr
;
9555 hashval_t line_header_local_hash
;
9559 gdb_assert (! cu
->per_cu
->is_debug_types
);
9561 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9562 if (attr
== NULL
|| !attr
->form_is_unsigned ())
9565 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
9567 /* The line header hash table is only created if needed (it exists to
9568 prevent redundant reading of the line table for partial_units).
9569 If we're given a partial_unit, we'll need it. If we're given a
9570 compile_unit, then use the line header hash table if it's already
9571 created, but don't create one just yet. */
9573 if (per_objfile
->line_header_hash
== NULL
9574 && die
->tag
== DW_TAG_partial_unit
)
9576 per_objfile
->line_header_hash
9577 .reset (htab_create_alloc (127, line_header_hash_voidp
,
9578 line_header_eq_voidp
,
9579 htab_delete_entry
<line_header
>,
9583 line_header
line_header_local (line_offset
, cu
->per_cu
->is_dwz
);
9584 line_header_local_hash
= line_header_hash (&line_header_local
);
9585 if (per_objfile
->line_header_hash
!= NULL
)
9587 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
9589 line_header_local_hash
, NO_INSERT
);
9591 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9592 is not present in *SLOT (since if there is something in *SLOT then
9593 it will be for a partial_unit). */
9594 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9596 gdb_assert (*slot
!= NULL
);
9597 cu
->line_header
= (struct line_header
*) *slot
;
9602 /* dwarf_decode_line_header does not yet provide sufficient information.
9603 We always have to call also dwarf_decode_lines for it. */
9604 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
,
9605 fnd
.get_comp_dir ());
9609 cu
->line_header
= lh
.release ();
9610 cu
->line_header_die_owner
= die
;
9612 if (per_objfile
->line_header_hash
== NULL
)
9616 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
9618 line_header_local_hash
, INSERT
);
9619 gdb_assert (slot
!= NULL
);
9621 if (slot
!= NULL
&& *slot
== NULL
)
9623 /* This newly decoded line number information unit will be owned
9624 by line_header_hash hash table. */
9625 *slot
= cu
->line_header
;
9626 cu
->line_header_die_owner
= NULL
;
9630 /* We cannot free any current entry in (*slot) as that struct line_header
9631 may be already used by multiple CUs. Create only temporary decoded
9632 line_header for this CU - it may happen at most once for each line
9633 number information unit. And if we're not using line_header_hash
9634 then this is what we want as well. */
9635 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9637 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9638 /* The have_code check is here because, if LOWPC and HIGHPC are both 0x0,
9639 then there won't be any interesting code in the CU, but a check later on
9640 (in lnp_state_machine::check_line_address) will fail to properly exclude
9641 an entry that was removed via --gc-sections. */
9643 dwarf_decode_lines (cu
->line_header
, cu
, lowpc
, decode_mapping
);
9646 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9649 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9651 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9652 struct objfile
*objfile
= per_objfile
->objfile
;
9653 struct gdbarch
*gdbarch
= objfile
->arch ();
9654 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9655 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9656 struct attribute
*attr
;
9657 struct die_info
*child_die
;
9660 prepare_one_comp_unit (cu
, die
, cu
->lang ());
9661 baseaddr
= objfile
->text_section_offset ();
9663 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9665 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9666 from finish_block. */
9667 if (lowpc
== ((CORE_ADDR
) -1))
9669 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9671 file_and_directory
&fnd
= find_file_and_directory (die
, cu
);
9673 cu
->start_compunit_symtab (fnd
.get_name (), fnd
.intern_comp_dir (objfile
),
9676 gdb_assert (per_objfile
->sym_cu
== nullptr);
9677 scoped_restore restore_sym_cu
9678 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
9680 /* Decode line number information if present. We do this before
9681 processing child DIEs, so that the line header table is available
9682 for DW_AT_decl_file. */
9683 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
, lowpc
!= highpc
);
9685 /* Process all dies in compilation unit. */
9686 if (die
->child
!= NULL
)
9688 child_die
= die
->child
;
9689 while (child_die
&& child_die
->tag
)
9691 process_die (child_die
, cu
);
9692 child_die
= child_die
->sibling
;
9695 per_objfile
->sym_cu
= nullptr;
9697 /* Decode macro information, if present. Dwarf 2 macro information
9698 refers to information in the line number info statement program
9699 header, so we can only read it if we've read the header
9701 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
9703 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9704 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
9706 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9707 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
9709 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
9713 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9714 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
9716 unsigned int macro_offset
= attr
->as_unsigned ();
9718 dwarf_decode_macros (cu
, macro_offset
, 0);
9724 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
9726 struct type_unit_group
*tu_group
;
9728 struct attribute
*attr
;
9730 struct signatured_type
*sig_type
;
9732 gdb_assert (per_cu
->is_debug_types
);
9733 sig_type
= (struct signatured_type
*) per_cu
;
9735 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
9737 /* If we're using .gdb_index (includes -readnow) then
9738 per_cu->type_unit_group may not have been set up yet. */
9739 if (sig_type
->type_unit_group
== NULL
)
9740 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
9741 tu_group
= sig_type
->type_unit_group
;
9743 /* If we've already processed this stmt_list there's no real need to
9744 do it again, we could fake it and just recreate the part we need
9745 (file name,index -> symtab mapping). If data shows this optimization
9746 is useful we can do it then. */
9747 type_unit_group_unshareable
*tug_unshare
9748 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
9749 first_time
= tug_unshare
->compunit_symtab
== NULL
;
9751 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9754 if (attr
!= NULL
&& attr
->form_is_unsigned ())
9756 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
9757 lh
= dwarf_decode_line_header (line_offset
, this, nullptr);
9762 start_compunit_symtab ("", NULL
, 0);
9765 gdb_assert (tug_unshare
->symtabs
== NULL
);
9766 gdb_assert (m_builder
== nullptr);
9767 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
9768 m_builder
.reset (new struct buildsym_compunit
9769 (cust
->objfile (), "",
9773 list_in_scope
= get_builder ()->get_file_symbols ();
9778 line_header
= lh
.release ();
9779 line_header_die_owner
= die
;
9783 struct compunit_symtab
*cust
= start_compunit_symtab ("", NULL
, 0);
9785 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9786 still initializing it, and our caller (a few levels up)
9787 process_full_type_unit still needs to know if this is the first
9790 tug_unshare
->symtabs
9791 = XOBNEWVEC (&cust
->objfile ()->objfile_obstack
,
9792 struct symtab
*, line_header
->file_names_size ());
9794 auto &file_names
= line_header
->file_names ();
9795 for (i
= 0; i
< file_names
.size (); ++i
)
9797 file_entry
&fe
= file_names
[i
];
9798 dwarf2_start_subfile (this, fe
, *line_header
);
9799 buildsym_compunit
*b
= get_builder ();
9800 subfile
*sf
= b
->get_current_subfile ();
9802 if (sf
->symtab
== nullptr)
9804 /* NOTE: start_subfile will recognize when it's been
9805 passed a file it has already seen. So we can't
9806 assume there's a simple mapping from
9807 cu->line_header->file_names to subfiles, plus
9808 cu->line_header->file_names may contain dups. */
9809 const char *name
= sf
->name
.c_str ();
9810 const char *name_for_id
= sf
->name_for_id
.c_str ();
9811 sf
->symtab
= allocate_symtab (cust
, name
, name_for_id
);
9814 fe
.symtab
= b
->get_current_subfile ()->symtab
;
9815 tug_unshare
->symtabs
[i
] = fe
.symtab
;
9820 gdb_assert (m_builder
== nullptr);
9821 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
9822 m_builder
.reset (new struct buildsym_compunit
9823 (cust
->objfile (), "",
9827 list_in_scope
= get_builder ()->get_file_symbols ();
9829 auto &file_names
= line_header
->file_names ();
9830 for (i
= 0; i
< file_names
.size (); ++i
)
9832 file_entry
&fe
= file_names
[i
];
9833 fe
.symtab
= tug_unshare
->symtabs
[i
];
9837 /* The main symtab is allocated last. Type units don't have DW_AT_name
9838 so they don't have a "real" (so to speak) symtab anyway.
9839 There is later code that will assign the main symtab to all symbols
9840 that don't have one. We need to handle the case of a symbol with a
9841 missing symtab (DW_AT_decl_file) anyway. */
9844 /* Process DW_TAG_type_unit.
9845 For TUs we want to skip the first top level sibling if it's not the
9846 actual type being defined by this TU. In this case the first top
9847 level sibling is there to provide context only. */
9850 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9852 struct die_info
*child_die
;
9854 prepare_one_comp_unit (cu
, die
, language_minimal
);
9856 /* Initialize (or reinitialize) the machinery for building symtabs.
9857 We do this before processing child DIEs, so that the line header table
9858 is available for DW_AT_decl_file. */
9859 cu
->setup_type_unit_groups (die
);
9861 if (die
->child
!= NULL
)
9863 child_die
= die
->child
;
9864 while (child_die
&& child_die
->tag
)
9866 process_die (child_die
, cu
);
9867 child_die
= child_die
->sibling
;
9874 http://gcc.gnu.org/wiki/DebugFission
9875 http://gcc.gnu.org/wiki/DebugFissionDWP
9877 To simplify handling of both DWO files ("object" files with the DWARF info)
9878 and DWP files (a file with the DWOs packaged up into one file), we treat
9879 DWP files as having a collection of virtual DWO files. */
9882 hash_dwo_file (const void *item
)
9884 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
9887 hash
= htab_hash_string (dwo_file
->dwo_name
);
9888 if (dwo_file
->comp_dir
!= NULL
)
9889 hash
+= htab_hash_string (dwo_file
->comp_dir
);
9894 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
9896 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
9897 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
9899 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
9901 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
9902 return lhs
->comp_dir
== rhs
->comp_dir
;
9903 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
9906 /* Allocate a hash table for DWO files. */
9909 allocate_dwo_file_hash_table ()
9911 return htab_up (htab_create_alloc (41,
9914 htab_delete_entry
<dwo_file
>,
9918 /* Lookup DWO file DWO_NAME. */
9921 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
9922 const char *dwo_name
,
9923 const char *comp_dir
)
9925 struct dwo_file find_entry
;
9928 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
9929 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
9931 find_entry
.dwo_name
= dwo_name
;
9932 find_entry
.comp_dir
= comp_dir
;
9933 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
9940 hash_dwo_unit (const void *item
)
9942 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9944 /* This drops the top 32 bits of the id, but is ok for a hash. */
9945 return dwo_unit
->signature
;
9949 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9951 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
9952 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
9954 /* The signature is assumed to be unique within the DWO file.
9955 So while object file CU dwo_id's always have the value zero,
9956 that's OK, assuming each object file DWO file has only one CU,
9957 and that's the rule for now. */
9958 return lhs
->signature
== rhs
->signature
;
9961 /* Allocate a hash table for DWO CUs,TUs.
9962 There is one of these tables for each of CUs,TUs for each DWO file. */
9965 allocate_dwo_unit_table ()
9967 /* Start out with a pretty small number.
9968 Generally DWO files contain only one CU and maybe some TUs. */
9969 return htab_up (htab_create_alloc (3,
9972 NULL
, xcalloc
, xfree
));
9975 /* die_reader_func for create_dwo_cu. */
9978 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9979 const gdb_byte
*info_ptr
,
9980 struct die_info
*comp_unit_die
,
9981 struct dwo_file
*dwo_file
,
9982 struct dwo_unit
*dwo_unit
)
9984 struct dwarf2_cu
*cu
= reader
->cu
;
9985 sect_offset sect_off
= cu
->per_cu
->sect_off
;
9986 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9988 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
9989 if (!signature
.has_value ())
9991 complaint (_("Dwarf Error: debug entry at offset %s is missing"
9992 " its dwo_id [in module %s]"),
9993 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
9997 dwo_unit
->dwo_file
= dwo_file
;
9998 dwo_unit
->signature
= *signature
;
9999 dwo_unit
->section
= section
;
10000 dwo_unit
->sect_off
= sect_off
;
10001 dwo_unit
->length
= cu
->per_cu
->length ();
10003 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10004 sect_offset_str (sect_off
),
10005 hex_string (dwo_unit
->signature
));
10008 /* Create the dwo_units for the CUs in a DWO_FILE.
10009 Note: This function processes DWO files only, not DWP files. */
10012 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10013 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10014 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10016 struct objfile
*objfile
= per_objfile
->objfile
;
10017 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10018 const gdb_byte
*info_ptr
, *end_ptr
;
10020 section
.read (objfile
);
10021 info_ptr
= section
.buffer
;
10023 if (info_ptr
== NULL
)
10026 dwarf_read_debug_printf ("Reading %s for %s:",
10027 section
.get_name (),
10028 section
.get_file_name ());
10030 end_ptr
= info_ptr
+ section
.size
;
10031 while (info_ptr
< end_ptr
)
10033 struct dwarf2_per_cu_data per_cu
;
10034 struct dwo_unit read_unit
{};
10035 struct dwo_unit
*dwo_unit
;
10037 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10039 per_cu
.per_bfd
= per_bfd
;
10040 per_cu
.is_debug_types
= 0;
10041 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10042 per_cu
.section
= §ion
;
10044 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
10045 if (!reader
.dummy_p
)
10046 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
10047 &dwo_file
, &read_unit
);
10048 info_ptr
+= per_cu
.length ();
10050 // If the unit could not be parsed, skip it.
10051 if (read_unit
.dwo_file
== NULL
)
10054 if (cus_htab
== NULL
)
10055 cus_htab
= allocate_dwo_unit_table ();
10057 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
10059 *dwo_unit
= read_unit
;
10060 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
10061 gdb_assert (slot
!= NULL
);
10064 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
10065 sect_offset dup_sect_off
= dup_cu
->sect_off
;
10067 complaint (_("debug cu entry at offset %s is duplicate to"
10068 " the entry at offset %s, signature %s"),
10069 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
10070 hex_string (dwo_unit
->signature
));
10072 *slot
= (void *)dwo_unit
;
10076 /* DWP file .debug_{cu,tu}_index section format:
10077 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10078 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
10080 DWP Versions 1 & 2 are older, pre-standard format versions. The first
10081 officially standard DWP format was published with DWARF v5 and is called
10082 Version 5. There are no versions 3 or 4.
10086 Both index sections have the same format, and serve to map a 64-bit
10087 signature to a set of section numbers. Each section begins with a header,
10088 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10089 indexes, and a pool of 32-bit section numbers. The index sections will be
10090 aligned at 8-byte boundaries in the file.
10092 The index section header consists of:
10094 V, 32 bit version number
10096 N, 32 bit number of compilation units or type units in the index
10097 M, 32 bit number of slots in the hash table
10099 Numbers are recorded using the byte order of the application binary.
10101 The hash table begins at offset 16 in the section, and consists of an array
10102 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
10103 order of the application binary). Unused slots in the hash table are 0.
10104 (We rely on the extreme unlikeliness of a signature being exactly 0.)
10106 The parallel table begins immediately after the hash table
10107 (at offset 16 + 8 * M from the beginning of the section), and consists of an
10108 array of 32-bit indexes (using the byte order of the application binary),
10109 corresponding 1-1 with slots in the hash table. Each entry in the parallel
10110 table contains a 32-bit index into the pool of section numbers. For unused
10111 hash table slots, the corresponding entry in the parallel table will be 0.
10113 The pool of section numbers begins immediately following the hash table
10114 (at offset 16 + 12 * M from the beginning of the section). The pool of
10115 section numbers consists of an array of 32-bit words (using the byte order
10116 of the application binary). Each item in the array is indexed starting
10117 from 0. The hash table entry provides the index of the first section
10118 number in the set. Additional section numbers in the set follow, and the
10119 set is terminated by a 0 entry (section number 0 is not used in ELF).
10121 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
10122 section must be the first entry in the set, and the .debug_abbrev.dwo must
10123 be the second entry. Other members of the set may follow in any order.
10127 DWP Versions 2 and 5:
10129 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
10130 and the entries in the index tables are now offsets into these sections.
10131 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
10134 Index Section Contents:
10136 Hash Table of Signatures dwp_hash_table.hash_table
10137 Parallel Table of Indices dwp_hash_table.unit_table
10138 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
10139 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
10141 The index section header consists of:
10143 V, 32 bit version number
10144 L, 32 bit number of columns in the table of section offsets
10145 N, 32 bit number of compilation units or type units in the index
10146 M, 32 bit number of slots in the hash table
10148 Numbers are recorded using the byte order of the application binary.
10150 The hash table has the same format as version 1.
10151 The parallel table of indices has the same format as version 1,
10152 except that the entries are origin-1 indices into the table of sections
10153 offsets and the table of section sizes.
10155 The table of offsets begins immediately following the parallel table
10156 (at offset 16 + 12 * M from the beginning of the section). The table is
10157 a two-dimensional array of 32-bit words (using the byte order of the
10158 application binary), with L columns and N+1 rows, in row-major order.
10159 Each row in the array is indexed starting from 0. The first row provides
10160 a key to the remaining rows: each column in this row provides an identifier
10161 for a debug section, and the offsets in the same column of subsequent rows
10162 refer to that section. The section identifiers for Version 2 are:
10164 DW_SECT_INFO 1 .debug_info.dwo
10165 DW_SECT_TYPES 2 .debug_types.dwo
10166 DW_SECT_ABBREV 3 .debug_abbrev.dwo
10167 DW_SECT_LINE 4 .debug_line.dwo
10168 DW_SECT_LOC 5 .debug_loc.dwo
10169 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
10170 DW_SECT_MACINFO 7 .debug_macinfo.dwo
10171 DW_SECT_MACRO 8 .debug_macro.dwo
10173 The section identifiers for Version 5 are:
10175 DW_SECT_INFO_V5 1 .debug_info.dwo
10176 DW_SECT_RESERVED_V5 2 --
10177 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
10178 DW_SECT_LINE_V5 4 .debug_line.dwo
10179 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
10180 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
10181 DW_SECT_MACRO_V5 7 .debug_macro.dwo
10182 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
10184 The offsets provided by the CU and TU index sections are the base offsets
10185 for the contributions made by each CU or TU to the corresponding section
10186 in the package file. Each CU and TU header contains an abbrev_offset
10187 field, used to find the abbreviations table for that CU or TU within the
10188 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
10189 be interpreted as relative to the base offset given in the index section.
10190 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
10191 should be interpreted as relative to the base offset for .debug_line.dwo,
10192 and offsets into other debug sections obtained from DWARF attributes should
10193 also be interpreted as relative to the corresponding base offset.
10195 The table of sizes begins immediately following the table of offsets.
10196 Like the table of offsets, it is a two-dimensional array of 32-bit words,
10197 with L columns and N rows, in row-major order. Each row in the array is
10198 indexed starting from 1 (row 0 is shared by the two tables).
10202 Hash table lookup is handled the same in version 1 and 2:
10204 We assume that N and M will not exceed 2^32 - 1.
10205 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
10207 Given a 64-bit compilation unit signature or a type signature S, an entry
10208 in the hash table is located as follows:
10210 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
10211 the low-order k bits all set to 1.
10213 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
10215 3) If the hash table entry at index H matches the signature, use that
10216 entry. If the hash table entry at index H is unused (all zeroes),
10217 terminate the search: the signature is not present in the table.
10219 4) Let H = (H + H') modulo M. Repeat at Step 3.
10221 Because M > N and H' and M are relatively prime, the search is guaranteed
10222 to stop at an unused slot or find the match. */
10224 /* Create a hash table to map DWO IDs to their CU/TU entry in
10225 .debug_{info,types}.dwo in DWP_FILE.
10226 Returns NULL if there isn't one.
10227 Note: This function processes DWP files only, not DWO files. */
10229 static struct dwp_hash_table
*
10230 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
10231 struct dwp_file
*dwp_file
, int is_debug_types
)
10233 struct objfile
*objfile
= per_objfile
->objfile
;
10234 bfd
*dbfd
= dwp_file
->dbfd
.get ();
10235 const gdb_byte
*index_ptr
, *index_end
;
10236 struct dwarf2_section_info
*index
;
10237 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
10238 struct dwp_hash_table
*htab
;
10240 if (is_debug_types
)
10241 index
= &dwp_file
->sections
.tu_index
;
10243 index
= &dwp_file
->sections
.cu_index
;
10245 if (index
->empty ())
10247 index
->read (objfile
);
10249 index_ptr
= index
->buffer
;
10250 index_end
= index_ptr
+ index
->size
;
10252 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
10253 For now it's safe to just read 4 bytes (particularly as it's difficult to
10254 tell if you're dealing with Version 5 before you've read the version). */
10255 version
= read_4_bytes (dbfd
, index_ptr
);
10257 if (version
== 2 || version
== 5)
10258 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
10262 nr_units
= read_4_bytes (dbfd
, index_ptr
);
10264 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
10267 if (version
!= 1 && version
!= 2 && version
!= 5)
10269 error (_("Dwarf Error: unsupported DWP file version (%s)"
10270 " [in module %s]"),
10271 pulongest (version
), dwp_file
->name
);
10273 if (nr_slots
!= (nr_slots
& -nr_slots
))
10275 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
10276 " is not power of 2 [in module %s]"),
10277 pulongest (nr_slots
), dwp_file
->name
);
10280 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
10281 htab
->version
= version
;
10282 htab
->nr_columns
= nr_columns
;
10283 htab
->nr_units
= nr_units
;
10284 htab
->nr_slots
= nr_slots
;
10285 htab
->hash_table
= index_ptr
;
10286 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
10288 /* Exit early if the table is empty. */
10289 if (nr_slots
== 0 || nr_units
== 0
10290 || (version
== 2 && nr_columns
== 0)
10291 || (version
== 5 && nr_columns
== 0))
10293 /* All must be zero. */
10294 if (nr_slots
!= 0 || nr_units
!= 0
10295 || (version
== 2 && nr_columns
!= 0)
10296 || (version
== 5 && nr_columns
!= 0))
10298 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
10299 " all zero [in modules %s]"),
10307 htab
->section_pool
.v1
.indices
=
10308 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
10309 /* It's harder to decide whether the section is too small in v1.
10310 V1 is deprecated anyway so we punt. */
10312 else if (version
== 2)
10314 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
10315 int *ids
= htab
->section_pool
.v2
.section_ids
;
10316 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
10317 /* Reverse map for error checking. */
10318 int ids_seen
[DW_SECT_MAX
+ 1];
10321 if (nr_columns
< 2)
10323 error (_("Dwarf Error: bad DWP hash table, too few columns"
10324 " in section table [in module %s]"),
10327 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
10329 error (_("Dwarf Error: bad DWP hash table, too many columns"
10330 " in section table [in module %s]"),
10333 memset (ids
, 255, sizeof_ids
);
10334 memset (ids_seen
, 255, sizeof (ids_seen
));
10335 for (i
= 0; i
< nr_columns
; ++i
)
10337 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
10339 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
10341 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
10342 " in section table [in module %s]"),
10343 id
, dwp_file
->name
);
10345 if (ids_seen
[id
] != -1)
10347 error (_("Dwarf Error: bad DWP hash table, duplicate section"
10348 " id %d in section table [in module %s]"),
10349 id
, dwp_file
->name
);
10354 /* Must have exactly one info or types section. */
10355 if (((ids_seen
[DW_SECT_INFO
] != -1)
10356 + (ids_seen
[DW_SECT_TYPES
] != -1))
10359 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
10360 " DWO info/types section [in module %s]"),
10363 /* Must have an abbrev section. */
10364 if (ids_seen
[DW_SECT_ABBREV
] == -1)
10366 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
10367 " section [in module %s]"),
10370 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
10371 htab
->section_pool
.v2
.sizes
=
10372 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
10373 * nr_units
* nr_columns
);
10374 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
10375 * nr_units
* nr_columns
))
10378 error (_("Dwarf Error: DWP index section is corrupt (too small)"
10379 " [in module %s]"),
10383 else /* version == 5 */
10385 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
10386 int *ids
= htab
->section_pool
.v5
.section_ids
;
10387 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
10388 /* Reverse map for error checking. */
10389 int ids_seen
[DW_SECT_MAX_V5
+ 1];
10391 if (nr_columns
< 2)
10393 error (_("Dwarf Error: bad DWP hash table, too few columns"
10394 " in section table [in module %s]"),
10397 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
10399 error (_("Dwarf Error: bad DWP hash table, too many columns"
10400 " in section table [in module %s]"),
10403 memset (ids
, 255, sizeof_ids
);
10404 memset (ids_seen
, 255, sizeof (ids_seen
));
10405 for (int i
= 0; i
< nr_columns
; ++i
)
10407 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
10409 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
10411 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
10412 " in section table [in module %s]"),
10413 id
, dwp_file
->name
);
10415 if (ids_seen
[id
] != -1)
10417 error (_("Dwarf Error: bad DWP hash table, duplicate section"
10418 " id %d in section table [in module %s]"),
10419 id
, dwp_file
->name
);
10424 /* Must have seen an info section. */
10425 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
10427 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
10428 " DWO info/types section [in module %s]"),
10431 /* Must have an abbrev section. */
10432 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
10434 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
10435 " section [in module %s]"),
10438 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
10439 htab
->section_pool
.v5
.sizes
10440 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
10441 * nr_units
* nr_columns
);
10442 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
10443 * nr_units
* nr_columns
))
10446 error (_("Dwarf Error: DWP index section is corrupt (too small)"
10447 " [in module %s]"),
10455 /* Update SECTIONS with the data from SECTP.
10457 This function is like the other "locate" section routines, but in
10458 this context the sections to read comes from the DWP V1 hash table,
10459 not the full ELF section table.
10461 The result is non-zero for success, or zero if an error was found. */
10464 locate_v1_virtual_dwo_sections (asection
*sectp
,
10465 struct virtual_v1_dwo_sections
*sections
)
10467 const struct dwop_section_names
*names
= &dwop_section_names
;
10469 if (names
->abbrev_dwo
.matches (sectp
->name
))
10471 /* There can be only one. */
10472 if (sections
->abbrev
.s
.section
!= NULL
)
10474 sections
->abbrev
.s
.section
= sectp
;
10475 sections
->abbrev
.size
= bfd_section_size (sectp
);
10477 else if (names
->info_dwo
.matches (sectp
->name
)
10478 || names
->types_dwo
.matches (sectp
->name
))
10480 /* There can be only one. */
10481 if (sections
->info_or_types
.s
.section
!= NULL
)
10483 sections
->info_or_types
.s
.section
= sectp
;
10484 sections
->info_or_types
.size
= bfd_section_size (sectp
);
10486 else if (names
->line_dwo
.matches (sectp
->name
))
10488 /* There can be only one. */
10489 if (sections
->line
.s
.section
!= NULL
)
10491 sections
->line
.s
.section
= sectp
;
10492 sections
->line
.size
= bfd_section_size (sectp
);
10494 else if (names
->loc_dwo
.matches (sectp
->name
))
10496 /* There can be only one. */
10497 if (sections
->loc
.s
.section
!= NULL
)
10499 sections
->loc
.s
.section
= sectp
;
10500 sections
->loc
.size
= bfd_section_size (sectp
);
10502 else if (names
->macinfo_dwo
.matches (sectp
->name
))
10504 /* There can be only one. */
10505 if (sections
->macinfo
.s
.section
!= NULL
)
10507 sections
->macinfo
.s
.section
= sectp
;
10508 sections
->macinfo
.size
= bfd_section_size (sectp
);
10510 else if (names
->macro_dwo
.matches (sectp
->name
))
10512 /* There can be only one. */
10513 if (sections
->macro
.s
.section
!= NULL
)
10515 sections
->macro
.s
.section
= sectp
;
10516 sections
->macro
.size
= bfd_section_size (sectp
);
10518 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
10520 /* There can be only one. */
10521 if (sections
->str_offsets
.s
.section
!= NULL
)
10523 sections
->str_offsets
.s
.section
= sectp
;
10524 sections
->str_offsets
.size
= bfd_section_size (sectp
);
10528 /* No other kind of section is valid. */
10535 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10536 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10537 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10538 This is for DWP version 1 files. */
10540 static struct dwo_unit
*
10541 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
10542 struct dwp_file
*dwp_file
,
10543 uint32_t unit_index
,
10544 const char *comp_dir
,
10545 ULONGEST signature
, int is_debug_types
)
10547 const struct dwp_hash_table
*dwp_htab
=
10548 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10549 bfd
*dbfd
= dwp_file
->dbfd
.get ();
10550 const char *kind
= is_debug_types
? "TU" : "CU";
10551 struct dwo_file
*dwo_file
;
10552 struct dwo_unit
*dwo_unit
;
10553 struct virtual_v1_dwo_sections sections
;
10554 void **dwo_file_slot
;
10557 gdb_assert (dwp_file
->version
== 1);
10559 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
10560 kind
, pulongest (unit_index
), hex_string (signature
),
10563 /* Fetch the sections of this DWO unit.
10564 Put a limit on the number of sections we look for so that bad data
10565 doesn't cause us to loop forever. */
10567 #define MAX_NR_V1_DWO_SECTIONS \
10568 (1 /* .debug_info or .debug_types */ \
10569 + 1 /* .debug_abbrev */ \
10570 + 1 /* .debug_line */ \
10571 + 1 /* .debug_loc */ \
10572 + 1 /* .debug_str_offsets */ \
10573 + 1 /* .debug_macro or .debug_macinfo */ \
10574 + 1 /* trailing zero */)
10576 memset (§ions
, 0, sizeof (sections
));
10578 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10581 uint32_t section_nr
=
10582 read_4_bytes (dbfd
,
10583 dwp_htab
->section_pool
.v1
.indices
10584 + (unit_index
+ i
) * sizeof (uint32_t));
10586 if (section_nr
== 0)
10588 if (section_nr
>= dwp_file
->num_sections
)
10590 error (_("Dwarf Error: bad DWP hash table, section number too large"
10591 " [in module %s]"),
10595 sectp
= dwp_file
->elf_sections
[section_nr
];
10596 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10598 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10599 " [in module %s]"),
10605 || sections
.info_or_types
.empty ()
10606 || sections
.abbrev
.empty ())
10608 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10609 " [in module %s]"),
10612 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10614 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10615 " [in module %s]"),
10619 /* It's easier for the rest of the code if we fake a struct dwo_file and
10620 have dwo_unit "live" in that. At least for now.
10622 The DWP file can be made up of a random collection of CUs and TUs.
10623 However, for each CU + set of TUs that came from the same original DWO
10624 file, we can combine them back into a virtual DWO file to save space
10625 (fewer struct dwo_file objects to allocate). Remember that for really
10626 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10628 std::string virtual_dwo_name
=
10629 string_printf ("virtual-dwo/%d-%d-%d-%d",
10630 sections
.abbrev
.get_id (),
10631 sections
.line
.get_id (),
10632 sections
.loc
.get_id (),
10633 sections
.str_offsets
.get_id ());
10634 /* Can we use an existing virtual DWO file? */
10635 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
10637 /* Create one if necessary. */
10638 if (*dwo_file_slot
== NULL
)
10640 dwarf_read_debug_printf ("Creating virtual DWO: %s",
10641 virtual_dwo_name
.c_str ());
10643 dwo_file
= new struct dwo_file
;
10644 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
10645 dwo_file
->comp_dir
= comp_dir
;
10646 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10647 dwo_file
->sections
.line
= sections
.line
;
10648 dwo_file
->sections
.loc
= sections
.loc
;
10649 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10650 dwo_file
->sections
.macro
= sections
.macro
;
10651 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10652 /* The "str" section is global to the entire DWP file. */
10653 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10654 /* The info or types section is assigned below to dwo_unit,
10655 there's no need to record it in dwo_file.
10656 Also, we can't simply record type sections in dwo_file because
10657 we record a pointer into the vector in dwo_unit. As we collect more
10658 types we'll grow the vector and eventually have to reallocate space
10659 for it, invalidating all copies of pointers into the previous
10661 *dwo_file_slot
= dwo_file
;
10665 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
10666 virtual_dwo_name
.c_str ());
10668 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10671 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
10672 dwo_unit
->dwo_file
= dwo_file
;
10673 dwo_unit
->signature
= signature
;
10674 dwo_unit
->section
=
10675 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
10676 *dwo_unit
->section
= sections
.info_or_types
;
10677 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10682 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
10683 simplify them. Given a pointer to the containing section SECTION, and
10684 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
10685 virtual section of just that piece. */
10687 static struct dwarf2_section_info
10688 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
10689 struct dwarf2_section_info
*section
,
10690 bfd_size_type offset
, bfd_size_type size
)
10692 struct dwarf2_section_info result
;
10695 gdb_assert (section
!= NULL
);
10696 gdb_assert (!section
->is_virtual
);
10698 memset (&result
, 0, sizeof (result
));
10699 result
.s
.containing_section
= section
;
10700 result
.is_virtual
= true;
10705 sectp
= section
->get_bfd_section ();
10707 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10708 bounds of the real section. This is a pretty-rare event, so just
10709 flag an error (easier) instead of a warning and trying to cope. */
10711 || offset
+ size
> bfd_section_size (sectp
))
10713 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
10714 " in section %s [in module %s]"),
10715 sectp
? bfd_section_name (sectp
) : "<unknown>",
10716 objfile_name (per_objfile
->objfile
));
10719 result
.virtual_offset
= offset
;
10720 result
.size
= size
;
10724 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10725 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10726 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10727 This is for DWP version 2 files. */
10729 static struct dwo_unit
*
10730 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
10731 struct dwp_file
*dwp_file
,
10732 uint32_t unit_index
,
10733 const char *comp_dir
,
10734 ULONGEST signature
, int is_debug_types
)
10736 const struct dwp_hash_table
*dwp_htab
=
10737 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10738 bfd
*dbfd
= dwp_file
->dbfd
.get ();
10739 const char *kind
= is_debug_types
? "TU" : "CU";
10740 struct dwo_file
*dwo_file
;
10741 struct dwo_unit
*dwo_unit
;
10742 struct virtual_v2_or_v5_dwo_sections sections
;
10743 void **dwo_file_slot
;
10746 gdb_assert (dwp_file
->version
== 2);
10748 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
10749 kind
, pulongest (unit_index
), hex_string (signature
),
10752 /* Fetch the section offsets of this DWO unit. */
10754 memset (§ions
, 0, sizeof (sections
));
10756 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10758 uint32_t offset
= read_4_bytes (dbfd
,
10759 dwp_htab
->section_pool
.v2
.offsets
10760 + (((unit_index
- 1) * dwp_htab
->nr_columns
10762 * sizeof (uint32_t)));
10763 uint32_t size
= read_4_bytes (dbfd
,
10764 dwp_htab
->section_pool
.v2
.sizes
10765 + (((unit_index
- 1) * dwp_htab
->nr_columns
10767 * sizeof (uint32_t)));
10769 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10772 case DW_SECT_TYPES
:
10773 sections
.info_or_types_offset
= offset
;
10774 sections
.info_or_types_size
= size
;
10776 case DW_SECT_ABBREV
:
10777 sections
.abbrev_offset
= offset
;
10778 sections
.abbrev_size
= size
;
10781 sections
.line_offset
= offset
;
10782 sections
.line_size
= size
;
10785 sections
.loc_offset
= offset
;
10786 sections
.loc_size
= size
;
10788 case DW_SECT_STR_OFFSETS
:
10789 sections
.str_offsets_offset
= offset
;
10790 sections
.str_offsets_size
= size
;
10792 case DW_SECT_MACINFO
:
10793 sections
.macinfo_offset
= offset
;
10794 sections
.macinfo_size
= size
;
10796 case DW_SECT_MACRO
:
10797 sections
.macro_offset
= offset
;
10798 sections
.macro_size
= size
;
10803 /* It's easier for the rest of the code if we fake a struct dwo_file and
10804 have dwo_unit "live" in that. At least for now.
10806 The DWP file can be made up of a random collection of CUs and TUs.
10807 However, for each CU + set of TUs that came from the same original DWO
10808 file, we can combine them back into a virtual DWO file to save space
10809 (fewer struct dwo_file objects to allocate). Remember that for really
10810 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10812 std::string virtual_dwo_name
=
10813 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
10814 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10815 (long) (sections
.line_size
? sections
.line_offset
: 0),
10816 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10817 (long) (sections
.str_offsets_size
10818 ? sections
.str_offsets_offset
: 0));
10819 /* Can we use an existing virtual DWO file? */
10820 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
10822 /* Create one if necessary. */
10823 if (*dwo_file_slot
== NULL
)
10825 dwarf_read_debug_printf ("Creating virtual DWO: %s",
10826 virtual_dwo_name
.c_str ());
10828 dwo_file
= new struct dwo_file
;
10829 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
10830 dwo_file
->comp_dir
= comp_dir
;
10831 dwo_file
->sections
.abbrev
=
10832 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
10833 sections
.abbrev_offset
,
10834 sections
.abbrev_size
);
10835 dwo_file
->sections
.line
=
10836 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
10837 sections
.line_offset
,
10838 sections
.line_size
);
10839 dwo_file
->sections
.loc
=
10840 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
10841 sections
.loc_offset
, sections
.loc_size
);
10842 dwo_file
->sections
.macinfo
=
10843 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
10844 sections
.macinfo_offset
,
10845 sections
.macinfo_size
);
10846 dwo_file
->sections
.macro
=
10847 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
10848 sections
.macro_offset
,
10849 sections
.macro_size
);
10850 dwo_file
->sections
.str_offsets
=
10851 create_dwp_v2_or_v5_section (per_objfile
,
10852 &dwp_file
->sections
.str_offsets
,
10853 sections
.str_offsets_offset
,
10854 sections
.str_offsets_size
);
10855 /* The "str" section is global to the entire DWP file. */
10856 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10857 /* The info or types section is assigned below to dwo_unit,
10858 there's no need to record it in dwo_file.
10859 Also, we can't simply record type sections in dwo_file because
10860 we record a pointer into the vector in dwo_unit. As we collect more
10861 types we'll grow the vector and eventually have to reallocate space
10862 for it, invalidating all copies of pointers into the previous
10864 *dwo_file_slot
= dwo_file
;
10868 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
10869 virtual_dwo_name
.c_str ());
10871 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10874 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
10875 dwo_unit
->dwo_file
= dwo_file
;
10876 dwo_unit
->signature
= signature
;
10877 dwo_unit
->section
=
10878 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
10879 *dwo_unit
->section
= create_dwp_v2_or_v5_section
10882 ? &dwp_file
->sections
.types
10883 : &dwp_file
->sections
.info
,
10884 sections
.info_or_types_offset
,
10885 sections
.info_or_types_size
);
10886 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10891 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10892 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10893 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10894 This is for DWP version 5 files. */
10896 static struct dwo_unit
*
10897 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
10898 struct dwp_file
*dwp_file
,
10899 uint32_t unit_index
,
10900 const char *comp_dir
,
10901 ULONGEST signature
, int is_debug_types
)
10903 const struct dwp_hash_table
*dwp_htab
10904 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10905 bfd
*dbfd
= dwp_file
->dbfd
.get ();
10906 const char *kind
= is_debug_types
? "TU" : "CU";
10907 struct dwo_file
*dwo_file
;
10908 struct dwo_unit
*dwo_unit
;
10909 struct virtual_v2_or_v5_dwo_sections sections
{};
10910 void **dwo_file_slot
;
10912 gdb_assert (dwp_file
->version
== 5);
10914 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
10915 kind
, pulongest (unit_index
), hex_string (signature
),
10918 /* Fetch the section offsets of this DWO unit. */
10920 /* memset (§ions, 0, sizeof (sections)); */
10922 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10924 uint32_t offset
= read_4_bytes (dbfd
,
10925 dwp_htab
->section_pool
.v5
.offsets
10926 + (((unit_index
- 1)
10927 * dwp_htab
->nr_columns
10929 * sizeof (uint32_t)));
10930 uint32_t size
= read_4_bytes (dbfd
,
10931 dwp_htab
->section_pool
.v5
.sizes
10932 + (((unit_index
- 1) * dwp_htab
->nr_columns
10934 * sizeof (uint32_t)));
10936 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
10938 case DW_SECT_ABBREV_V5
:
10939 sections
.abbrev_offset
= offset
;
10940 sections
.abbrev_size
= size
;
10942 case DW_SECT_INFO_V5
:
10943 sections
.info_or_types_offset
= offset
;
10944 sections
.info_or_types_size
= size
;
10946 case DW_SECT_LINE_V5
:
10947 sections
.line_offset
= offset
;
10948 sections
.line_size
= size
;
10950 case DW_SECT_LOCLISTS_V5
:
10951 sections
.loclists_offset
= offset
;
10952 sections
.loclists_size
= size
;
10954 case DW_SECT_MACRO_V5
:
10955 sections
.macro_offset
= offset
;
10956 sections
.macro_size
= size
;
10958 case DW_SECT_RNGLISTS_V5
:
10959 sections
.rnglists_offset
= offset
;
10960 sections
.rnglists_size
= size
;
10962 case DW_SECT_STR_OFFSETS_V5
:
10963 sections
.str_offsets_offset
= offset
;
10964 sections
.str_offsets_size
= size
;
10966 case DW_SECT_RESERVED_V5
:
10972 /* It's easier for the rest of the code if we fake a struct dwo_file and
10973 have dwo_unit "live" in that. At least for now.
10975 The DWP file can be made up of a random collection of CUs and TUs.
10976 However, for each CU + set of TUs that came from the same original DWO
10977 file, we can combine them back into a virtual DWO file to save space
10978 (fewer struct dwo_file objects to allocate). Remember that for really
10979 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10981 std::string virtual_dwo_name
=
10982 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
10983 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10984 (long) (sections
.line_size
? sections
.line_offset
: 0),
10985 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
10986 (long) (sections
.str_offsets_size
10987 ? sections
.str_offsets_offset
: 0),
10988 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
10989 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
10990 /* Can we use an existing virtual DWO file? */
10991 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
10992 virtual_dwo_name
.c_str (),
10994 /* Create one if necessary. */
10995 if (*dwo_file_slot
== NULL
)
10997 dwarf_read_debug_printf ("Creating virtual DWO: %s",
10998 virtual_dwo_name
.c_str ());
11000 dwo_file
= new struct dwo_file
;
11001 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11002 dwo_file
->comp_dir
= comp_dir
;
11003 dwo_file
->sections
.abbrev
=
11004 create_dwp_v2_or_v5_section (per_objfile
,
11005 &dwp_file
->sections
.abbrev
,
11006 sections
.abbrev_offset
,
11007 sections
.abbrev_size
);
11008 dwo_file
->sections
.line
=
11009 create_dwp_v2_or_v5_section (per_objfile
,
11010 &dwp_file
->sections
.line
,
11011 sections
.line_offset
, sections
.line_size
);
11012 dwo_file
->sections
.macro
=
11013 create_dwp_v2_or_v5_section (per_objfile
,
11014 &dwp_file
->sections
.macro
,
11015 sections
.macro_offset
,
11016 sections
.macro_size
);
11017 dwo_file
->sections
.loclists
=
11018 create_dwp_v2_or_v5_section (per_objfile
,
11019 &dwp_file
->sections
.loclists
,
11020 sections
.loclists_offset
,
11021 sections
.loclists_size
);
11022 dwo_file
->sections
.rnglists
=
11023 create_dwp_v2_or_v5_section (per_objfile
,
11024 &dwp_file
->sections
.rnglists
,
11025 sections
.rnglists_offset
,
11026 sections
.rnglists_size
);
11027 dwo_file
->sections
.str_offsets
=
11028 create_dwp_v2_or_v5_section (per_objfile
,
11029 &dwp_file
->sections
.str_offsets
,
11030 sections
.str_offsets_offset
,
11031 sections
.str_offsets_size
);
11032 /* The "str" section is global to the entire DWP file. */
11033 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11034 /* The info or types section is assigned below to dwo_unit,
11035 there's no need to record it in dwo_file.
11036 Also, we can't simply record type sections in dwo_file because
11037 we record a pointer into the vector in dwo_unit. As we collect more
11038 types we'll grow the vector and eventually have to reallocate space
11039 for it, invalidating all copies of pointers into the previous
11041 *dwo_file_slot
= dwo_file
;
11045 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11046 virtual_dwo_name
.c_str ());
11048 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11051 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11052 dwo_unit
->dwo_file
= dwo_file
;
11053 dwo_unit
->signature
= signature
;
11055 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11056 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
11057 &dwp_file
->sections
.info
,
11058 sections
.info_or_types_offset
,
11059 sections
.info_or_types_size
);
11060 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11065 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11066 Returns NULL if the signature isn't found. */
11068 static struct dwo_unit
*
11069 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
11070 struct dwp_file
*dwp_file
, const char *comp_dir
,
11071 ULONGEST signature
, int is_debug_types
)
11073 const struct dwp_hash_table
*dwp_htab
=
11074 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11075 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11076 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11077 uint32_t hash
= signature
& mask
;
11078 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11081 struct dwo_unit find_dwo_cu
;
11083 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11084 find_dwo_cu
.signature
= signature
;
11085 slot
= htab_find_slot (is_debug_types
11086 ? dwp_file
->loaded_tus
.get ()
11087 : dwp_file
->loaded_cus
.get (),
11088 &find_dwo_cu
, INSERT
);
11091 return (struct dwo_unit
*) *slot
;
11093 /* Use a for loop so that we don't loop forever on bad debug info. */
11094 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11096 ULONGEST signature_in_table
;
11098 signature_in_table
=
11099 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11100 if (signature_in_table
== signature
)
11102 uint32_t unit_index
=
11103 read_4_bytes (dbfd
,
11104 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11106 if (dwp_file
->version
== 1)
11108 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
11109 unit_index
, comp_dir
,
11110 signature
, is_debug_types
);
11112 else if (dwp_file
->version
== 2)
11114 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
11115 unit_index
, comp_dir
,
11116 signature
, is_debug_types
);
11118 else /* version == 5 */
11120 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
11121 unit_index
, comp_dir
,
11122 signature
, is_debug_types
);
11124 return (struct dwo_unit
*) *slot
;
11126 if (signature_in_table
== 0)
11128 hash
= (hash
+ hash2
) & mask
;
11131 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11132 " [in module %s]"),
11136 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11137 Open the file specified by FILE_NAME and hand it off to BFD for
11138 preliminary analysis. Return a newly initialized bfd *, which
11139 includes a canonicalized copy of FILE_NAME.
11140 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11141 SEARCH_CWD is true if the current directory is to be searched.
11142 It will be searched before debug-file-directory.
11143 If successful, the file is added to the bfd include table of the
11144 objfile's bfd (see gdb_bfd_record_inclusion).
11145 If unable to find/open the file, return NULL.
11146 NOTE: This function is derived from symfile_bfd_open. */
11148 static gdb_bfd_ref_ptr
11149 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
11150 const char *file_name
, int is_dwp
, int search_cwd
)
11153 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11154 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11155 to debug_file_directory. */
11156 const char *search_path
;
11157 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11159 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11162 if (!debug_file_directory
.empty ())
11164 search_path_holder
.reset (concat (".", dirname_separator_string
,
11165 debug_file_directory
.c_str (),
11167 search_path
= search_path_holder
.get ();
11173 search_path
= debug_file_directory
.c_str ();
11175 /* Add the path for the executable binary to the list of search paths. */
11176 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
11177 search_path_holder
.reset (concat (objfile_dir
.c_str (),
11178 dirname_separator_string
,
11179 search_path
, nullptr));
11180 search_path
= search_path_holder
.get ();
11182 openp_flags flags
= OPF_RETURN_REALPATH
;
11184 flags
|= OPF_SEARCH_IN_PATH
;
11186 gdb::unique_xmalloc_ptr
<char> absolute_name
;
11187 desc
= openp (search_path
, flags
, file_name
,
11188 O_RDONLY
| O_BINARY
, &absolute_name
);
11192 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
11194 if (sym_bfd
== NULL
)
11196 bfd_set_cacheable (sym_bfd
.get (), 1);
11198 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
11201 /* Success. Record the bfd as having been included by the objfile's bfd.
11202 This is important because things like demangled_names_hash lives in the
11203 objfile's per_bfd space and may have references to things like symbol
11204 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11205 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
.get (), sym_bfd
.get ());
11210 /* Try to open DWO file FILE_NAME.
11211 COMP_DIR is the DW_AT_comp_dir attribute.
11212 The result is the bfd handle of the file.
11213 If there is a problem finding or opening the file, return NULL.
11214 Upon success, the canonicalized path of the file is stored in the bfd,
11215 same as symfile_bfd_open. */
11217 static gdb_bfd_ref_ptr
11218 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
11219 const char *file_name
, const char *comp_dir
)
11221 if (IS_ABSOLUTE_PATH (file_name
))
11222 return try_open_dwop_file (per_objfile
, file_name
,
11223 0 /*is_dwp*/, 0 /*search_cwd*/);
11225 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
11227 if (comp_dir
!= NULL
)
11229 std::string path_to_try
= path_join (comp_dir
, file_name
);
11231 /* NOTE: If comp_dir is a relative path, this will also try the
11232 search path, which seems useful. */
11233 gdb_bfd_ref_ptr
abfd (try_open_dwop_file
11234 (per_objfile
, path_to_try
.c_str (), 0 /*is_dwp*/, 1 /*search_cwd*/));
11240 /* That didn't work, try debug-file-directory, which, despite its name,
11241 is a list of paths. */
11243 if (debug_file_directory
.empty ())
11246 return try_open_dwop_file (per_objfile
, file_name
,
11247 0 /*is_dwp*/, 1 /*search_cwd*/);
11250 /* This function is mapped across the sections and remembers the offset and
11251 size of each of the DWO debugging sections we are interested in. */
11254 dwarf2_locate_dwo_sections (struct objfile
*objfile
, bfd
*abfd
,
11255 asection
*sectp
, dwo_sections
*dwo_sections
)
11257 const struct dwop_section_names
*names
= &dwop_section_names
;
11259 struct dwarf2_section_info
*dw_sect
= nullptr;
11261 if (names
->abbrev_dwo
.matches (sectp
->name
))
11262 dw_sect
= &dwo_sections
->abbrev
;
11263 else if (names
->info_dwo
.matches (sectp
->name
))
11264 dw_sect
= &dwo_sections
->info
;
11265 else if (names
->line_dwo
.matches (sectp
->name
))
11266 dw_sect
= &dwo_sections
->line
;
11267 else if (names
->loc_dwo
.matches (sectp
->name
))
11268 dw_sect
= &dwo_sections
->loc
;
11269 else if (names
->loclists_dwo
.matches (sectp
->name
))
11270 dw_sect
= &dwo_sections
->loclists
;
11271 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11272 dw_sect
= &dwo_sections
->macinfo
;
11273 else if (names
->macro_dwo
.matches (sectp
->name
))
11274 dw_sect
= &dwo_sections
->macro
;
11275 else if (names
->rnglists_dwo
.matches (sectp
->name
))
11276 dw_sect
= &dwo_sections
->rnglists
;
11277 else if (names
->str_dwo
.matches (sectp
->name
))
11278 dw_sect
= &dwo_sections
->str
;
11279 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11280 dw_sect
= &dwo_sections
->str_offsets
;
11281 else if (names
->types_dwo
.matches (sectp
->name
))
11283 struct dwarf2_section_info type_section
;
11285 memset (&type_section
, 0, sizeof (type_section
));
11286 dwo_sections
->types
.push_back (type_section
);
11287 dw_sect
= &dwo_sections
->types
.back ();
11290 if (dw_sect
!= nullptr)
11292 dw_sect
->s
.section
= sectp
;
11293 dw_sect
->size
= bfd_section_size (sectp
);
11294 dw_sect
->read (objfile
);
11298 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
11299 by PER_CU. This is for the non-DWP case.
11300 The result is NULL if DWO_NAME can't be found. */
11302 static struct dwo_file
*
11303 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
11304 const char *comp_dir
)
11306 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11308 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
11311 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
11316 dwo_file_up
dwo_file (new struct dwo_file
);
11317 dwo_file
->dwo_name
= dwo_name
;
11318 dwo_file
->comp_dir
= comp_dir
;
11319 dwo_file
->dbfd
= std::move (dbfd
);
11321 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
11322 dwarf2_locate_dwo_sections (per_objfile
->objfile
, dwo_file
->dbfd
.get (),
11323 sec
, &dwo_file
->sections
);
11325 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
11328 if (cu
->per_cu
->version () < 5)
11330 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
11331 dwo_file
->sections
.types
, dwo_file
->tus
);
11335 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
11336 &dwo_file
->sections
.info
, dwo_file
->tus
,
11337 rcuh_kind::COMPILE
);
11340 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
11342 return dwo_file
.release ();
11345 /* This function is mapped across the sections and remembers the offset and
11346 size of each of the DWP debugging sections common to version 1 and 2 that
11347 we are interested in. */
11350 dwarf2_locate_common_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
11351 asection
*sectp
, dwp_file
*dwp_file
)
11353 const struct dwop_section_names
*names
= &dwop_section_names
;
11354 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
11356 /* Record the ELF section number for later lookup: this is what the
11357 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11358 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
11359 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
11361 /* Look for specific sections that we need. */
11362 struct dwarf2_section_info
*dw_sect
= nullptr;
11363 if (names
->str_dwo
.matches (sectp
->name
))
11364 dw_sect
= &dwp_file
->sections
.str
;
11365 else if (names
->cu_index
.matches (sectp
->name
))
11366 dw_sect
= &dwp_file
->sections
.cu_index
;
11367 else if (names
->tu_index
.matches (sectp
->name
))
11368 dw_sect
= &dwp_file
->sections
.tu_index
;
11370 if (dw_sect
!= nullptr)
11372 dw_sect
->s
.section
= sectp
;
11373 dw_sect
->size
= bfd_section_size (sectp
);
11374 dw_sect
->read (objfile
);
11378 /* This function is mapped across the sections and remembers the offset and
11379 size of each of the DWP version 2 debugging sections that we are interested
11380 in. This is split into a separate function because we don't know if we
11381 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
11384 dwarf2_locate_v2_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
11385 asection
*sectp
, void *dwp_file_ptr
)
11387 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
11388 const struct dwop_section_names
*names
= &dwop_section_names
;
11389 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
11391 /* Record the ELF section number for later lookup: this is what the
11392 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11393 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
11394 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
11396 /* Look for specific sections that we need. */
11397 struct dwarf2_section_info
*dw_sect
= nullptr;
11398 if (names
->abbrev_dwo
.matches (sectp
->name
))
11399 dw_sect
= &dwp_file
->sections
.abbrev
;
11400 else if (names
->info_dwo
.matches (sectp
->name
))
11401 dw_sect
= &dwp_file
->sections
.info
;
11402 else if (names
->line_dwo
.matches (sectp
->name
))
11403 dw_sect
= &dwp_file
->sections
.line
;
11404 else if (names
->loc_dwo
.matches (sectp
->name
))
11405 dw_sect
= &dwp_file
->sections
.loc
;
11406 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11407 dw_sect
= &dwp_file
->sections
.macinfo
;
11408 else if (names
->macro_dwo
.matches (sectp
->name
))
11409 dw_sect
= &dwp_file
->sections
.macro
;
11410 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11411 dw_sect
= &dwp_file
->sections
.str_offsets
;
11412 else if (names
->types_dwo
.matches (sectp
->name
))
11413 dw_sect
= &dwp_file
->sections
.types
;
11415 if (dw_sect
!= nullptr)
11417 dw_sect
->s
.section
= sectp
;
11418 dw_sect
->size
= bfd_section_size (sectp
);
11419 dw_sect
->read (objfile
);
11423 /* This function is mapped across the sections and remembers the offset and
11424 size of each of the DWP version 5 debugging sections that we are interested
11425 in. This is split into a separate function because we don't know if we
11426 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
11429 dwarf2_locate_v5_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
11430 asection
*sectp
, void *dwp_file_ptr
)
11432 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
11433 const struct dwop_section_names
*names
= &dwop_section_names
;
11434 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
11436 /* Record the ELF section number for later lookup: this is what the
11437 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11438 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
11439 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
11441 /* Look for specific sections that we need. */
11442 struct dwarf2_section_info
*dw_sect
= nullptr;
11443 if (names
->abbrev_dwo
.matches (sectp
->name
))
11444 dw_sect
= &dwp_file
->sections
.abbrev
;
11445 else if (names
->info_dwo
.matches (sectp
->name
))
11446 dw_sect
= &dwp_file
->sections
.info
;
11447 else if (names
->line_dwo
.matches (sectp
->name
))
11448 dw_sect
= &dwp_file
->sections
.line
;
11449 else if (names
->loclists_dwo
.matches (sectp
->name
))
11450 dw_sect
= &dwp_file
->sections
.loclists
;
11451 else if (names
->macro_dwo
.matches (sectp
->name
))
11452 dw_sect
= &dwp_file
->sections
.macro
;
11453 else if (names
->rnglists_dwo
.matches (sectp
->name
))
11454 dw_sect
= &dwp_file
->sections
.rnglists
;
11455 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11456 dw_sect
= &dwp_file
->sections
.str_offsets
;
11458 if (dw_sect
!= nullptr)
11460 dw_sect
->s
.section
= sectp
;
11461 dw_sect
->size
= bfd_section_size (sectp
);
11462 dw_sect
->read (objfile
);
11466 /* Hash function for dwp_file loaded CUs/TUs. */
11469 hash_dwp_loaded_cutus (const void *item
)
11471 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11473 /* This drops the top 32 bits of the signature, but is ok for a hash. */
11474 return dwo_unit
->signature
;
11477 /* Equality function for dwp_file loaded CUs/TUs. */
11480 eq_dwp_loaded_cutus (const void *a
, const void *b
)
11482 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
11483 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
11485 return dua
->signature
== dub
->signature
;
11488 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
11491 allocate_dwp_loaded_cutus_table ()
11493 return htab_up (htab_create_alloc (3,
11494 hash_dwp_loaded_cutus
,
11495 eq_dwp_loaded_cutus
,
11496 NULL
, xcalloc
, xfree
));
11499 /* Try to open DWP file FILE_NAME.
11500 The result is the bfd handle of the file.
11501 If there is a problem finding or opening the file, return NULL.
11502 Upon success, the canonicalized path of the file is stored in the bfd,
11503 same as symfile_bfd_open. */
11505 static gdb_bfd_ref_ptr
11506 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
11508 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
11510 1 /*search_cwd*/));
11514 /* Work around upstream bug 15652.
11515 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
11516 [Whether that's a "bug" is debatable, but it is getting in our way.]
11517 We have no real idea where the dwp file is, because gdb's realpath-ing
11518 of the executable's path may have discarded the needed info.
11519 [IWBN if the dwp file name was recorded in the executable, akin to
11520 .gnu_debuglink, but that doesn't exist yet.]
11521 Strip the directory from FILE_NAME and search again. */
11522 if (!debug_file_directory
.empty ())
11524 /* Don't implicitly search the current directory here.
11525 If the user wants to search "." to handle this case,
11526 it must be added to debug-file-directory. */
11527 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
11535 /* Initialize the use of the DWP file for the current objfile.
11536 By convention the name of the DWP file is ${objfile}.dwp.
11537 The result is NULL if it can't be found. */
11539 static std::unique_ptr
<struct dwp_file
>
11540 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
11542 struct objfile
*objfile
= per_objfile
->objfile
;
11544 /* Try to find first .dwp for the binary file before any symbolic links
11547 /* If the objfile is a debug file, find the name of the real binary
11548 file and get the name of dwp file from there. */
11549 std::string dwp_name
;
11550 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
11552 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
11553 const char *backlink_basename
= lbasename (backlink
->original_name
);
11555 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
11558 dwp_name
= objfile
->original_name
;
11560 dwp_name
+= ".dwp";
11562 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
11564 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
11566 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
11567 dwp_name
= objfile_name (objfile
);
11568 dwp_name
+= ".dwp";
11569 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
11574 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
11576 return std::unique_ptr
<dwp_file
> ();
11579 const char *name
= bfd_get_filename (dbfd
.get ());
11580 std::unique_ptr
<struct dwp_file
> dwp_file
11581 (new struct dwp_file (name
, std::move (dbfd
)));
11583 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
11584 dwp_file
->elf_sections
=
11585 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
11586 dwp_file
->num_sections
, asection
*);
11588 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
11589 dwarf2_locate_common_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
11592 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
11594 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
11596 /* The DWP file version is stored in the hash table. Oh well. */
11597 if (dwp_file
->cus
&& dwp_file
->tus
11598 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
11600 /* Technically speaking, we should try to limp along, but this is
11601 pretty bizarre. We use pulongest here because that's the established
11602 portability solution (e.g, we cannot use %u for uint32_t). */
11603 error (_("Dwarf Error: DWP file CU version %s doesn't match"
11604 " TU version %s [in DWP file %s]"),
11605 pulongest (dwp_file
->cus
->version
),
11606 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
11610 dwp_file
->version
= dwp_file
->cus
->version
;
11611 else if (dwp_file
->tus
)
11612 dwp_file
->version
= dwp_file
->tus
->version
;
11614 dwp_file
->version
= 2;
11616 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
11618 if (dwp_file
->version
== 2)
11619 dwarf2_locate_v2_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
11622 dwarf2_locate_v5_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
11626 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
11627 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
11629 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
11630 dwarf_read_debug_printf (" %s CUs, %s TUs",
11631 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
11632 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
11637 /* Wrapper around open_and_init_dwp_file, only open it once. */
11639 static struct dwp_file
*
11640 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
11642 if (!per_objfile
->per_bfd
->dwp_checked
)
11644 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
11645 per_objfile
->per_bfd
->dwp_checked
= 1;
11647 return per_objfile
->per_bfd
->dwp_file
.get ();
11650 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
11651 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
11652 or in the DWP file for the objfile, referenced by THIS_UNIT.
11653 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
11654 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
11656 This is called, for example, when wanting to read a variable with a
11657 complex location. Therefore we don't want to do file i/o for every call.
11658 Therefore we don't want to look for a DWO file on every call.
11659 Therefore we first see if we've already seen SIGNATURE in a DWP file,
11660 then we check if we've already seen DWO_NAME, and only THEN do we check
11663 The result is a pointer to the dwo_unit object or NULL if we didn't find it
11664 (dwo_id mismatch or couldn't find the DWO/DWP file). */
11666 static struct dwo_unit
*
11667 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
11668 ULONGEST signature
, int is_debug_types
)
11670 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11671 struct objfile
*objfile
= per_objfile
->objfile
;
11672 const char *kind
= is_debug_types
? "TU" : "CU";
11673 void **dwo_file_slot
;
11674 struct dwo_file
*dwo_file
;
11675 struct dwp_file
*dwp_file
;
11677 /* First see if there's a DWP file.
11678 If we have a DWP file but didn't find the DWO inside it, don't
11679 look for the original DWO file. It makes gdb behave differently
11680 depending on whether one is debugging in the build tree. */
11682 dwp_file
= get_dwp_file (per_objfile
);
11683 if (dwp_file
!= NULL
)
11685 const struct dwp_hash_table
*dwp_htab
=
11686 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11688 if (dwp_htab
!= NULL
)
11690 struct dwo_unit
*dwo_cutu
=
11691 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
11694 if (dwo_cutu
!= NULL
)
11696 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
11697 kind
, hex_string (signature
),
11698 host_address_to_string (dwo_cutu
));
11706 /* No DWP file, look for the DWO file. */
11708 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
11709 if (*dwo_file_slot
== NULL
)
11711 /* Read in the file and build a table of the CUs/TUs it contains. */
11712 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
11714 /* NOTE: This will be NULL if unable to open the file. */
11715 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11717 if (dwo_file
!= NULL
)
11719 struct dwo_unit
*dwo_cutu
= NULL
;
11721 if (is_debug_types
&& dwo_file
->tus
)
11723 struct dwo_unit find_dwo_cutu
;
11725 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11726 find_dwo_cutu
.signature
= signature
;
11728 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
11731 else if (!is_debug_types
&& dwo_file
->cus
)
11733 struct dwo_unit find_dwo_cutu
;
11735 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11736 find_dwo_cutu
.signature
= signature
;
11737 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
11741 if (dwo_cutu
!= NULL
)
11743 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
11744 kind
, dwo_name
, hex_string (signature
),
11745 host_address_to_string (dwo_cutu
));
11752 /* We didn't find it. This could mean a dwo_id mismatch, or
11753 someone deleted the DWO/DWP file, or the search path isn't set up
11754 correctly to find the file. */
11756 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
11757 kind
, dwo_name
, hex_string (signature
));
11759 /* This is a warning and not a complaint because it can be caused by
11760 pilot error (e.g., user accidentally deleting the DWO). */
11762 /* Print the name of the DWP file if we looked there, helps the user
11763 better diagnose the problem. */
11764 std::string dwp_text
;
11766 if (dwp_file
!= NULL
)
11767 dwp_text
= string_printf (" [in DWP file %s]",
11768 lbasename (dwp_file
->name
));
11770 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
11771 " [in module %s]"),
11772 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
11773 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
11778 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11779 See lookup_dwo_cutu_unit for details. */
11781 static struct dwo_unit
*
11782 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
11783 ULONGEST signature
)
11785 gdb_assert (!cu
->per_cu
->is_debug_types
);
11787 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
11790 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11791 See lookup_dwo_cutu_unit for details. */
11793 static struct dwo_unit
*
11794 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
11796 gdb_assert (cu
->per_cu
->is_debug_types
);
11798 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
11800 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
11803 /* Traversal function for queue_and_load_all_dwo_tus. */
11806 queue_and_load_dwo_tu (void **slot
, void *info
)
11808 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11809 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
11810 ULONGEST signature
= dwo_unit
->signature
;
11811 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
11813 if (sig_type
!= NULL
)
11815 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11816 a real dependency of PER_CU on SIG_TYPE. That is detected later
11817 while processing PER_CU. */
11818 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
11820 load_full_type_unit (sig_type
, cu
->per_objfile
);
11821 cu
->per_cu
->imported_symtabs_push (sig_type
);
11827 /* Queue all TUs contained in the DWO of CU to be read in.
11828 The DWO may have the only definition of the type, though it may not be
11829 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11830 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11833 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
11835 struct dwo_unit
*dwo_unit
;
11836 struct dwo_file
*dwo_file
;
11838 gdb_assert (cu
!= nullptr);
11839 gdb_assert (!cu
->per_cu
->is_debug_types
);
11840 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
11842 dwo_unit
= cu
->dwo_unit
;
11843 gdb_assert (dwo_unit
!= NULL
);
11845 dwo_file
= dwo_unit
->dwo_file
;
11846 if (dwo_file
->tus
!= NULL
)
11847 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
11850 /* Read in various DIEs. */
11852 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11853 Inherit only the children of the DW_AT_abstract_origin DIE not being
11854 already referenced by DW_AT_abstract_origin from the children of the
11858 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11860 attribute
*attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11861 if (attr
== nullptr)
11864 /* Note that following die references may follow to a die in a
11866 dwarf2_cu
*origin_cu
= cu
;
11868 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11869 die_info
*origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11871 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11873 struct pending
**origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11874 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11876 if (die
->tag
!= origin_die
->tag
11877 && !(die
->tag
== DW_TAG_inlined_subroutine
11878 && origin_die
->tag
== DW_TAG_subprogram
))
11879 complaint (_("DIE %s and its abstract origin %s have different tags"),
11880 sect_offset_str (die
->sect_off
),
11881 sect_offset_str (origin_die
->sect_off
));
11883 /* Find if the concrete and abstract trees are structurally the
11884 same. This is a shallow traversal and it is not bullet-proof;
11885 the compiler can trick the debugger into believing that the trees
11886 are isomorphic, whereas they actually are not. However, the
11887 likelyhood of this happening is pretty low, and a full-fledged
11888 check would be an overkill. */
11889 bool are_isomorphic
= true;
11890 die_info
*concrete_child
= die
->child
;
11891 die_info
*abstract_child
= origin_die
->child
;
11892 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
11894 if (concrete_child
== nullptr
11895 || abstract_child
== nullptr
11896 || concrete_child
->tag
!= abstract_child
->tag
)
11898 are_isomorphic
= false;
11902 concrete_child
= concrete_child
->sibling
;
11903 abstract_child
= abstract_child
->sibling
;
11906 /* Walk the origin's children in parallel to the concrete children.
11907 This helps match an origin child in case the debug info misses
11908 DW_AT_abstract_origin attributes. Keep in mind that the abstract
11909 origin tree may not have the same tree structure as the concrete
11911 die_info
*corresponding_abstract_child
11912 = are_isomorphic
? origin_die
->child
: nullptr;
11914 std::vector
<sect_offset
> offsets
;
11916 for (die_info
*child_die
= die
->child
;
11917 child_die
&& child_die
->tag
;
11918 child_die
= child_die
->sibling
)
11920 /* We are trying to process concrete instance entries:
11921 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11922 it's not relevant to our analysis here. i.e. detecting DIEs that are
11923 present in the abstract instance but not referenced in the concrete
11925 if (child_die
->tag
== DW_TAG_call_site
11926 || child_die
->tag
== DW_TAG_GNU_call_site
)
11928 if (are_isomorphic
)
11929 corresponding_abstract_child
11930 = corresponding_abstract_child
->sibling
;
11934 /* For each CHILD_DIE, find the corresponding child of
11935 ORIGIN_DIE. If there is more than one layer of
11936 DW_AT_abstract_origin, follow them all; there shouldn't be,
11937 but GCC versions at least through 4.4 generate this (GCC PR
11939 die_info
*child_origin_die
= child_die
;
11940 dwarf2_cu
*child_origin_cu
= cu
;
11943 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11945 if (attr
== nullptr)
11948 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11952 /* If missing DW_AT_abstract_origin, try the corresponding child
11953 of the origin. Clang emits such lexical scopes. */
11954 if (child_origin_die
== child_die
11955 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
11957 && child_die
->tag
== DW_TAG_lexical_block
)
11958 child_origin_die
= corresponding_abstract_child
;
11960 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11961 counterpart may exist. */
11962 if (child_origin_die
!= child_die
)
11964 if (child_die
->tag
!= child_origin_die
->tag
11965 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11966 && child_origin_die
->tag
== DW_TAG_subprogram
))
11967 complaint (_("Child DIE %s and its abstract origin %s have "
11969 sect_offset_str (child_die
->sect_off
),
11970 sect_offset_str (child_origin_die
->sect_off
));
11971 if (child_origin_die
->parent
!= origin_die
)
11972 complaint (_("Child DIE %s and its abstract origin %s have "
11973 "different parents"),
11974 sect_offset_str (child_die
->sect_off
),
11975 sect_offset_str (child_origin_die
->sect_off
));
11977 offsets
.push_back (child_origin_die
->sect_off
);
11980 if (are_isomorphic
)
11981 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
11984 if (!offsets
.empty ())
11986 std::sort (offsets
.begin (), offsets
.end ());
11988 for (auto offsets_it
= offsets
.begin () + 1;
11989 offsets_it
< offsets
.end ();
11991 if (*(offsets_it
- 1) == *offsets_it
)
11992 complaint (_("Multiple children of DIE %s refer "
11993 "to DIE %s as their abstract origin"),
11994 sect_offset_str (die
->sect_off
),
11995 sect_offset_str (*offsets_it
));
11998 auto offsets_it
= offsets
.begin ();
11999 die_info
*origin_child_die
= origin_die
->child
;
12000 while (origin_child_die
!= nullptr && origin_child_die
->tag
!= 0)
12002 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12003 while (offsets_it
< offsets
.end ()
12004 && *offsets_it
< origin_child_die
->sect_off
)
12007 if (offsets_it
== offsets
.end ()
12008 || *offsets_it
> origin_child_die
->sect_off
)
12010 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12011 Check whether we're already processing ORIGIN_CHILD_DIE.
12012 This can happen with mutually referenced abstract_origins.
12014 if (!origin_child_die
->in_process
)
12015 process_die (origin_child_die
, origin_cu
);
12018 origin_child_die
= origin_child_die
->sibling
;
12021 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12023 if (cu
!= origin_cu
)
12024 compute_delayed_physnames (origin_cu
);
12028 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12030 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12031 struct gdbarch
*gdbarch
= objfile
->arch ();
12032 struct context_stack
*newobj
;
12035 struct die_info
*child_die
;
12036 struct attribute
*attr
, *call_line
, *call_file
;
12038 CORE_ADDR baseaddr
;
12039 struct block
*block
;
12040 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12041 std::vector
<struct symbol
*> template_args
;
12042 struct template_symbol
*templ_func
= NULL
;
12046 /* If we do not have call site information, we can't show the
12047 caller of this inlined function. That's too confusing, so
12048 only use the scope for local variables. */
12049 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12050 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12051 if (call_line
== NULL
|| call_file
== NULL
)
12053 read_lexical_block_scope (die
, cu
);
12058 baseaddr
= objfile
->text_section_offset ();
12060 name
= dwarf2_name (die
, cu
);
12061 if (name
== nullptr)
12062 name
= dw2_linkage_name (die
, cu
);
12064 /* Ignore functions with missing or empty names. These are actually
12065 illegal according to the DWARF standard. */
12068 complaint (_("missing name for subprogram DIE at %s"),
12069 sect_offset_str (die
->sect_off
));
12073 /* Ignore functions with missing or invalid low and high pc attributes. */
12074 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr)
12075 <= PC_BOUNDS_INVALID
)
12077 if (have_complaint ())
12079 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12080 bool external_p
= attr
!= nullptr && attr
->as_boolean ();
12081 attr
= dwarf2_attr (die
, DW_AT_inline
, cu
);
12084 && attr
->is_nonnegative ()
12085 && (attr
->as_nonnegative () == DW_INL_inlined
12086 || attr
->as_nonnegative () == DW_INL_declared_inlined
));
12087 attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
12088 bool decl_p
= attr
!= nullptr && attr
->as_boolean ();
12089 if (!external_p
&& !inlined_p
&& !decl_p
)
12090 complaint (_("cannot get low and high bounds "
12091 "for subprogram DIE at %s"),
12092 sect_offset_str (die
->sect_off
));
12097 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12098 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12100 /* If we have any template arguments, then we must allocate a
12101 different sort of symbol. */
12102 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12104 if (child_die
->tag
== DW_TAG_template_type_param
12105 || child_die
->tag
== DW_TAG_template_value_param
)
12107 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
12108 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12113 gdb_assert (cu
->get_builder () != nullptr);
12114 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12115 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12116 (struct symbol
*) templ_func
);
12118 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12119 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12122 /* If there is a location expression for DW_AT_frame_base, record
12124 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12125 if (attr
!= nullptr)
12126 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12128 /* If there is a location for the static link, record it. */
12129 newobj
->static_link
= NULL
;
12130 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12131 if (attr
!= nullptr)
12133 newobj
->static_link
12134 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12135 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12139 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12141 if (die
->child
!= NULL
)
12143 child_die
= die
->child
;
12144 while (child_die
&& child_die
->tag
)
12146 if (child_die
->tag
== DW_TAG_template_type_param
12147 || child_die
->tag
== DW_TAG_template_value_param
)
12149 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12152 template_args
.push_back (arg
);
12155 process_die (child_die
, cu
);
12156 child_die
= child_die
->sibling
;
12160 inherit_abstract_dies (die
, cu
);
12162 /* If we have a DW_AT_specification, we might need to import using
12163 directives from the context of the specification DIE. See the
12164 comment in determine_prefix. */
12165 if (cu
->lang () == language_cplus
12166 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12168 struct dwarf2_cu
*spec_cu
= cu
;
12169 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12173 child_die
= spec_die
->child
;
12174 while (child_die
&& child_die
->tag
)
12176 if (child_die
->tag
== DW_TAG_imported_module
)
12177 process_die (child_die
, spec_cu
);
12178 child_die
= child_die
->sibling
;
12181 /* In some cases, GCC generates specification DIEs that
12182 themselves contain DW_AT_specification attributes. */
12183 spec_die
= die_specification (spec_die
, &spec_cu
);
12187 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12188 /* Make a block for the local symbols within. */
12189 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12190 cstk
.static_link
, lowpc
, highpc
);
12192 /* For C++, set the block's scope. */
12193 if ((cu
->lang () == language_cplus
12194 || cu
->lang () == language_fortran
12195 || cu
->lang () == language_d
12196 || cu
->lang () == language_rust
)
12197 && cu
->processing_has_namespace_info
)
12198 block_set_scope (block
, determine_prefix (die
, cu
),
12199 &objfile
->objfile_obstack
);
12201 /* If we have address ranges, record them. */
12202 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12204 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12206 /* Attach template arguments to function. */
12207 if (!template_args
.empty ())
12209 gdb_assert (templ_func
!= NULL
);
12211 templ_func
->n_template_arguments
= template_args
.size ();
12212 templ_func
->template_arguments
12213 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12214 templ_func
->n_template_arguments
);
12215 memcpy (templ_func
->template_arguments
,
12216 template_args
.data (),
12217 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12219 /* Make sure that the symtab is set on the new symbols. Even
12220 though they don't appear in this symtab directly, other parts
12221 of gdb assume that symbols do, and this is reasonably
12223 for (symbol
*sym
: template_args
)
12224 sym
->set_symtab (templ_func
->symtab ());
12227 /* In C++, we can have functions nested inside functions (e.g., when
12228 a function declares a class that has methods). This means that
12229 when we finish processing a function scope, we may need to go
12230 back to building a containing block's symbol lists. */
12231 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12232 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12234 /* If we've finished processing a top-level function, subsequent
12235 symbols go in the file symbol list. */
12236 if (cu
->get_builder ()->outermost_context_p ())
12237 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12240 /* Process all the DIES contained within a lexical block scope. Start
12241 a new scope, process the dies, and then close the scope. */
12244 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12246 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12247 struct gdbarch
*gdbarch
= objfile
->arch ();
12248 CORE_ADDR lowpc
, highpc
;
12249 struct die_info
*child_die
;
12250 CORE_ADDR baseaddr
;
12252 baseaddr
= objfile
->text_section_offset ();
12254 /* Ignore blocks with missing or invalid low and high pc attributes. */
12255 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12256 as multiple lexical blocks? Handling children in a sane way would
12257 be nasty. Might be easier to properly extend generic blocks to
12258 describe ranges. */
12259 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr))
12261 case PC_BOUNDS_NOT_PRESENT
:
12262 /* DW_TAG_lexical_block has no attributes, process its children as if
12263 there was no wrapping by that DW_TAG_lexical_block.
12264 GCC does no longer produces such DWARF since GCC r224161. */
12265 for (child_die
= die
->child
;
12266 child_die
!= NULL
&& child_die
->tag
;
12267 child_die
= child_die
->sibling
)
12269 /* We might already be processing this DIE. This can happen
12270 in an unusual circumstance -- where a subroutine A
12271 appears lexically in another subroutine B, but A actually
12272 inlines B. The recursion is broken here, rather than in
12273 inherit_abstract_dies, because it seems better to simply
12274 drop concrete children here. */
12275 if (!child_die
->in_process
)
12276 process_die (child_die
, cu
);
12279 case PC_BOUNDS_INVALID
:
12282 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12283 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12285 cu
->get_builder ()->push_context (0, lowpc
);
12286 if (die
->child
!= NULL
)
12288 child_die
= die
->child
;
12289 while (child_die
&& child_die
->tag
)
12291 process_die (child_die
, cu
);
12292 child_die
= child_die
->sibling
;
12295 inherit_abstract_dies (die
, cu
);
12296 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12298 if (*cu
->get_builder ()->get_local_symbols () != NULL
12299 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
12301 struct block
*block
12302 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
12303 cstk
.start_addr
, highpc
);
12305 /* Note that recording ranges after traversing children, as we
12306 do here, means that recording a parent's ranges entails
12307 walking across all its children's ranges as they appear in
12308 the address map, which is quadratic behavior.
12310 It would be nicer to record the parent's ranges before
12311 traversing its children, simply overriding whatever you find
12312 there. But since we don't even decide whether to create a
12313 block until after we've traversed its children, that's hard
12315 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12317 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12318 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12321 static void dwarf2_ranges_read_low_addrs (unsigned offset
,
12322 struct dwarf2_cu
*cu
,
12324 std::vector
<CORE_ADDR
> &result
);
12326 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
12329 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12331 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12332 struct objfile
*objfile
= per_objfile
->objfile
;
12333 struct gdbarch
*gdbarch
= objfile
->arch ();
12334 CORE_ADDR pc
, baseaddr
;
12335 struct attribute
*attr
;
12338 struct die_info
*child_die
;
12340 baseaddr
= objfile
->text_section_offset ();
12342 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
12345 /* This was a pre-DWARF-5 GNU extension alias
12346 for DW_AT_call_return_pc. */
12347 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12351 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
12352 "DIE %s [in module %s]"),
12353 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
12356 pc
= attr
->as_address () + baseaddr
;
12357 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
12360 if (cu
->call_site_htab
== NULL
)
12361 cu
->call_site_htab
= htab_create_alloc_ex (16, call_site::hash
,
12362 call_site::eq
, NULL
,
12363 &objfile
->objfile_obstack
,
12364 hashtab_obstack_allocate
, NULL
);
12365 struct call_site
call_site_local (pc
, nullptr, nullptr);
12366 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
12369 complaint (_("Duplicate PC %s for DW_TAG_call_site "
12370 "DIE %s [in module %s]"),
12371 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
12372 objfile_name (objfile
));
12376 /* Count parameters at the caller. */
12379 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
12380 child_die
= child_die
->sibling
)
12382 if (child_die
->tag
!= DW_TAG_call_site_parameter
12383 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
12385 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
12386 "DW_TAG_call_site child DIE %s [in module %s]"),
12387 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
12388 objfile_name (objfile
));
12395 struct call_site
*call_site
12396 = new (XOBNEWVAR (&objfile
->objfile_obstack
,
12398 sizeof (*call_site
) + sizeof (call_site
->parameter
[0]) * nparams
))
12399 struct call_site (pc
, cu
->per_cu
, per_objfile
);
12402 /* We never call the destructor of call_site, so we must ensure it is
12403 trivially destructible. */
12404 gdb_static_assert(std::is_trivially_destructible
<struct call_site
>::value
);
12406 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
12407 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
12409 struct die_info
*func_die
;
12411 /* Skip also over DW_TAG_inlined_subroutine. */
12412 for (func_die
= die
->parent
;
12413 func_die
&& func_die
->tag
!= DW_TAG_subprogram
12414 && func_die
->tag
!= DW_TAG_subroutine_type
;
12415 func_die
= func_die
->parent
);
12417 /* DW_AT_call_all_calls is a superset
12418 of DW_AT_call_all_tail_calls. */
12420 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
12421 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
12422 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
12423 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
12425 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
12426 not complete. But keep CALL_SITE for look ups via call_site_htab,
12427 both the initial caller containing the real return address PC and
12428 the final callee containing the current PC of a chain of tail
12429 calls do not need to have the tail call list complete. But any
12430 function candidate for a virtual tail call frame searched via
12431 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
12432 determined unambiguously. */
12436 struct type
*func_type
= NULL
;
12439 func_type
= get_die_type (func_die
, cu
);
12440 if (func_type
!= NULL
)
12442 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
12444 /* Enlist this call site to the function. */
12445 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
12446 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
12449 complaint (_("Cannot find function owning DW_TAG_call_site "
12450 "DIE %s [in module %s]"),
12451 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
12455 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
12457 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
12459 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
12462 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
12463 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12466 call_site
->target
.set_loc_dwarf_block (nullptr);
12467 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
12468 /* Keep NULL DWARF_BLOCK. */;
12469 else if (attr
->form_is_block ())
12471 struct dwarf2_locexpr_baton
*dlbaton
;
12472 struct dwarf_block
*block
= attr
->as_block ();
12474 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
12475 dlbaton
->data
= block
->data
;
12476 dlbaton
->size
= block
->size
;
12477 dlbaton
->per_objfile
= per_objfile
;
12478 dlbaton
->per_cu
= cu
->per_cu
;
12480 call_site
->target
.set_loc_dwarf_block (dlbaton
);
12482 else if (attr
->form_is_ref ())
12484 struct dwarf2_cu
*target_cu
= cu
;
12485 struct die_info
*target_die
;
12487 target_die
= follow_die_ref (die
, attr
, &target_cu
);
12488 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
12490 struct attribute
*ranges_attr
12491 = dwarf2_attr (target_die
, DW_AT_ranges
, target_cu
);
12493 if (die_is_declaration (target_die
, target_cu
))
12495 const char *target_physname
;
12497 /* Prefer the mangled name; otherwise compute the demangled one. */
12498 target_physname
= dw2_linkage_name (target_die
, target_cu
);
12499 if (target_physname
== NULL
)
12500 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
12501 if (target_physname
== NULL
)
12502 complaint (_("DW_AT_call_target target DIE has invalid "
12503 "physname, for referencing DIE %s [in module %s]"),
12504 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
12506 call_site
->target
.set_loc_physname (target_physname
);
12508 else if (ranges_attr
!= nullptr && ranges_attr
->form_is_unsigned ())
12510 ULONGEST ranges_offset
= (ranges_attr
->as_unsigned ()
12511 + target_cu
->gnu_ranges_base
);
12512 std::vector
<CORE_ADDR
> addresses
;
12513 dwarf2_ranges_read_low_addrs (ranges_offset
, target_cu
,
12514 target_die
->tag
, addresses
);
12515 CORE_ADDR
*saved
= XOBNEWVAR (&objfile
->objfile_obstack
, CORE_ADDR
,
12516 addresses
.size ());
12517 std::copy (addresses
.begin (), addresses
.end (), saved
);
12518 call_site
->target
.set_loc_array (addresses
.size (), saved
);
12524 /* DW_AT_entry_pc should be preferred. */
12525 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
,
12527 <= PC_BOUNDS_INVALID
)
12528 complaint (_("DW_AT_call_target target DIE has invalid "
12529 "low pc, for referencing DIE %s [in module %s]"),
12530 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
12533 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
)
12535 call_site
->target
.set_loc_physaddr (lowpc
);
12540 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
12541 "block nor reference, for DIE %s [in module %s]"),
12542 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
12544 for (child_die
= die
->child
;
12545 child_die
&& child_die
->tag
;
12546 child_die
= child_die
->sibling
)
12548 struct call_site_parameter
*parameter
;
12549 struct attribute
*loc
, *origin
;
12551 if (child_die
->tag
!= DW_TAG_call_site_parameter
12552 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
12554 /* Already printed the complaint above. */
12558 gdb_assert (call_site
->parameter_count
< nparams
);
12559 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
12561 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
12562 specifies DW_TAG_formal_parameter. Value of the data assumed for the
12563 register is contained in DW_AT_call_value. */
12565 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
12566 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
12567 if (origin
== NULL
)
12569 /* This was a pre-DWARF-5 GNU extension alias
12570 for DW_AT_call_parameter. */
12571 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
12573 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
12575 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
12577 sect_offset sect_off
= origin
->get_ref_die_offset ();
12578 if (!cu
->header
.offset_in_cu_p (sect_off
))
12580 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
12581 binding can be done only inside one CU. Such referenced DIE
12582 therefore cannot be even moved to DW_TAG_partial_unit. */
12583 complaint (_("DW_AT_call_parameter offset is not in CU for "
12584 "DW_TAG_call_site child DIE %s [in module %s]"),
12585 sect_offset_str (child_die
->sect_off
),
12586 objfile_name (objfile
));
12589 parameter
->u
.param_cu_off
12590 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
12592 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
12594 complaint (_("No DW_FORM_block* DW_AT_location for "
12595 "DW_TAG_call_site child DIE %s [in module %s]"),
12596 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
12601 struct dwarf_block
*block
= loc
->as_block ();
12603 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
12604 (block
->data
, &block
->data
[block
->size
]);
12605 if (parameter
->u
.dwarf_reg
!= -1)
12606 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
12607 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
12608 &block
->data
[block
->size
],
12609 ¶meter
->u
.fb_offset
))
12610 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
12613 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
12614 "for DW_FORM_block* DW_AT_location is supported for "
12615 "DW_TAG_call_site child DIE %s "
12617 sect_offset_str (child_die
->sect_off
),
12618 objfile_name (objfile
));
12623 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
12625 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
12626 if (attr
== NULL
|| !attr
->form_is_block ())
12628 complaint (_("No DW_FORM_block* DW_AT_call_value for "
12629 "DW_TAG_call_site child DIE %s [in module %s]"),
12630 sect_offset_str (child_die
->sect_off
),
12631 objfile_name (objfile
));
12635 struct dwarf_block
*block
= attr
->as_block ();
12636 parameter
->value
= block
->data
;
12637 parameter
->value_size
= block
->size
;
12639 /* Parameters are not pre-cleared by memset above. */
12640 parameter
->data_value
= NULL
;
12641 parameter
->data_value_size
= 0;
12642 call_site
->parameter_count
++;
12644 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
12646 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
12647 if (attr
!= nullptr)
12649 if (!attr
->form_is_block ())
12650 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
12651 "DW_TAG_call_site child DIE %s [in module %s]"),
12652 sect_offset_str (child_die
->sect_off
),
12653 objfile_name (objfile
));
12656 block
= attr
->as_block ();
12657 parameter
->data_value
= block
->data
;
12658 parameter
->data_value_size
= block
->size
;
12664 /* Helper function for read_variable. If DIE represents a virtual
12665 table, then return the type of the concrete object that is
12666 associated with the virtual table. Otherwise, return NULL. */
12668 static struct type
*
12669 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12671 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12675 /* Find the type DIE. */
12676 struct die_info
*type_die
= NULL
;
12677 struct dwarf2_cu
*type_cu
= cu
;
12679 if (attr
->form_is_ref ())
12680 type_die
= follow_die_ref (die
, attr
, &type_cu
);
12681 if (type_die
== NULL
)
12684 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
12686 return die_containing_type (type_die
, type_cu
);
12689 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
12692 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
12694 struct rust_vtable_symbol
*storage
= NULL
;
12696 if (cu
->lang () == language_rust
)
12698 struct type
*containing_type
= rust_containing_type (die
, cu
);
12700 if (containing_type
!= NULL
)
12702 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12704 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
12705 storage
->concrete_type
= containing_type
;
12706 storage
->subclass
= SYMBOL_RUST_VTABLE
;
12710 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
12711 struct attribute
*abstract_origin
12712 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12713 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
12714 if (res
== NULL
&& loc
&& abstract_origin
)
12716 /* We have a variable without a name, but with a location and an abstract
12717 origin. This may be a concrete instance of an abstract variable
12718 referenced from an DW_OP_GNU_variable_value, so save it to find it back
12720 struct dwarf2_cu
*origin_cu
= cu
;
12721 struct die_info
*origin_die
12722 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
12723 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12724 per_objfile
->per_bfd
->abstract_to_concrete
12725 [origin_die
->sect_off
].push_back (die
->sect_off
);
12729 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
12730 reading .debug_rnglists.
12731 Callback's type should be:
12732 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12733 Return true if the attributes are present and valid, otherwise,
12736 template <typename Callback
>
12738 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
12739 dwarf_tag tag
, Callback
&&callback
)
12741 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12742 struct objfile
*objfile
= per_objfile
->objfile
;
12743 bfd
*obfd
= objfile
->obfd
.get ();
12744 /* Base address selection entry. */
12745 gdb::optional
<CORE_ADDR
> base
;
12746 const gdb_byte
*buffer
;
12747 bool overflow
= false;
12748 ULONGEST addr_index
;
12749 struct dwarf2_section_info
*rnglists_section
;
12751 base
= cu
->base_address
;
12752 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
12753 rnglists_section
->read (objfile
);
12755 if (offset
>= rnglists_section
->size
)
12757 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
12761 buffer
= rnglists_section
->buffer
+ offset
;
12765 /* Initialize it due to a false compiler warning. */
12766 CORE_ADDR range_beginning
= 0, range_end
= 0;
12767 const gdb_byte
*buf_end
= (rnglists_section
->buffer
12768 + rnglists_section
->size
);
12769 unsigned int bytes_read
;
12771 if (buffer
== buf_end
)
12776 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
12779 case DW_RLE_end_of_list
:
12781 case DW_RLE_base_address
:
12782 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12787 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
12788 buffer
+= bytes_read
;
12790 case DW_RLE_base_addressx
:
12791 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12792 buffer
+= bytes_read
;
12793 base
= read_addr_index (cu
, addr_index
);
12795 case DW_RLE_start_length
:
12796 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12801 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
12803 buffer
+= bytes_read
;
12804 range_end
= (range_beginning
12805 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
12806 buffer
+= bytes_read
;
12807 if (buffer
> buf_end
)
12813 case DW_RLE_startx_length
:
12814 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12815 buffer
+= bytes_read
;
12816 range_beginning
= read_addr_index (cu
, addr_index
);
12817 if (buffer
> buf_end
)
12822 range_end
= (range_beginning
12823 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
12824 buffer
+= bytes_read
;
12826 case DW_RLE_offset_pair
:
12827 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12828 buffer
+= bytes_read
;
12829 if (buffer
> buf_end
)
12834 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12835 buffer
+= bytes_read
;
12836 if (buffer
> buf_end
)
12842 case DW_RLE_start_end
:
12843 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
12848 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
12850 buffer
+= bytes_read
;
12851 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
12852 buffer
+= bytes_read
;
12854 case DW_RLE_startx_endx
:
12855 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12856 buffer
+= bytes_read
;
12857 range_beginning
= read_addr_index (cu
, addr_index
);
12858 if (buffer
> buf_end
)
12863 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12864 buffer
+= bytes_read
;
12865 range_end
= read_addr_index (cu
, addr_index
);
12868 complaint (_("Invalid .debug_rnglists data (no base address)"));
12871 if (rlet
== DW_RLE_end_of_list
|| overflow
)
12873 if (rlet
== DW_RLE_base_address
)
12876 if (range_beginning
> range_end
)
12878 /* Inverted range entries are invalid. */
12879 complaint (_("Invalid .debug_rnglists data (inverted range)"));
12883 /* Empty range entries have no effect. */
12884 if (range_beginning
== range_end
)
12887 /* Only DW_RLE_offset_pair needs the base address added. */
12888 if (rlet
== DW_RLE_offset_pair
)
12890 if (!base
.has_value ())
12892 /* We have no valid base address for the DW_RLE_offset_pair. */
12893 complaint (_("Invalid .debug_rnglists data (no base address for "
12894 "DW_RLE_offset_pair)"));
12898 range_beginning
+= *base
;
12899 range_end
+= *base
;
12902 /* A not-uncommon case of bad debug info.
12903 Don't pollute the addrmap with bad data. */
12904 if (range_beginning
== 0
12905 && !per_objfile
->per_bfd
->has_section_at_zero
)
12907 complaint (_(".debug_rnglists entry has start address of zero"
12908 " [in module %s]"), objfile_name (objfile
));
12912 callback (range_beginning
, range_end
);
12917 complaint (_("Offset %d is not terminated "
12918 "for DW_AT_ranges attribute"),
12926 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
12927 Callback's type should be:
12928 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12929 Return 1 if the attributes are present and valid, otherwise, return 0. */
12931 template <typename Callback
>
12933 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
12934 Callback
&&callback
)
12936 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12937 struct objfile
*objfile
= per_objfile
->objfile
;
12938 struct comp_unit_head
*cu_header
= &cu
->header
;
12939 bfd
*obfd
= objfile
->obfd
.get ();
12940 unsigned int addr_size
= cu_header
->addr_size
;
12941 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12942 /* Base address selection entry. */
12943 gdb::optional
<CORE_ADDR
> base
;
12944 unsigned int dummy
;
12945 const gdb_byte
*buffer
;
12947 if (cu_header
->version
>= 5)
12948 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
12950 base
= cu
->base_address
;
12952 per_objfile
->per_bfd
->ranges
.read (objfile
);
12953 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
12955 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
12959 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
12963 CORE_ADDR range_beginning
, range_end
;
12965 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
12966 buffer
+= addr_size
;
12967 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
12968 buffer
+= addr_size
;
12969 offset
+= 2 * addr_size
;
12971 /* An end of list marker is a pair of zero addresses. */
12972 if (range_beginning
== 0 && range_end
== 0)
12973 /* Found the end of list entry. */
12976 /* Each base address selection entry is a pair of 2 values.
12977 The first is the largest possible address, the second is
12978 the base address. Check for a base address here. */
12979 if ((range_beginning
& mask
) == mask
)
12981 /* If we found the largest possible address, then we already
12982 have the base address in range_end. */
12987 if (!base
.has_value ())
12989 /* We have no valid base address for the ranges
12991 complaint (_("Invalid .debug_ranges data (no base address)"));
12995 if (range_beginning
> range_end
)
12997 /* Inverted range entries are invalid. */
12998 complaint (_("Invalid .debug_ranges data (inverted range)"));
13002 /* Empty range entries have no effect. */
13003 if (range_beginning
== range_end
)
13006 range_beginning
+= *base
;
13007 range_end
+= *base
;
13009 /* A not-uncommon case of bad debug info.
13010 Don't pollute the addrmap with bad data. */
13011 if (range_beginning
== 0
13012 && !per_objfile
->per_bfd
->has_section_at_zero
)
13014 complaint (_(".debug_ranges entry has start address of zero"
13015 " [in module %s]"), objfile_name (objfile
));
13019 callback (range_beginning
, range_end
);
13025 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13026 Return 1 if the attributes are present and valid, otherwise, return 0.
13027 TAG is passed to dwarf2_ranges_process. If MAP is not NULL, then
13028 ranges in MAP are set, using DATUM as the value. */
13031 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13032 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13033 addrmap
*map
, void *datum
, dwarf_tag tag
)
13035 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13036 struct gdbarch
*gdbarch
= objfile
->arch ();
13037 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13040 CORE_ADDR high
= 0;
13043 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
13044 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13046 if (map
!= nullptr)
13051 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13052 range_beginning
+ baseaddr
)
13054 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13055 range_end
+ baseaddr
)
13057 map
->set_empty (lowpc
, highpc
- 1, datum
);
13060 /* FIXME: This is recording everything as a low-high
13061 segment of consecutive addresses. We should have a
13062 data structure for discontiguous block ranges
13066 low
= range_beginning
;
13072 if (range_beginning
< low
)
13073 low
= range_beginning
;
13074 if (range_end
> high
)
13082 /* If the first entry is an end-of-list marker, the range
13083 describes an empty scope, i.e. no instructions. */
13089 *high_return
= high
;
13093 /* Process ranges and fill in a vector of the low PC values only. */
13096 dwarf2_ranges_read_low_addrs (unsigned offset
, struct dwarf2_cu
*cu
,
13098 std::vector
<CORE_ADDR
> &result
)
13100 dwarf2_ranges_process (offset
, cu
, tag
,
13101 [&] (CORE_ADDR start
, CORE_ADDR end
)
13103 result
.push_back (start
);
13107 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13108 definition for the return value. *LOWPC and *HIGHPC are set iff
13109 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13111 static enum pc_bounds_kind
13112 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13113 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13114 addrmap
*map
, void *datum
)
13116 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13117 struct attribute
*attr
;
13118 struct attribute
*attr_high
;
13120 CORE_ADDR high
= 0;
13121 enum pc_bounds_kind ret
;
13123 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13126 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13127 if (attr
!= nullptr)
13129 low
= attr
->as_address ();
13130 high
= attr_high
->as_address ();
13131 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13135 /* Found high w/o low attribute. */
13136 return PC_BOUNDS_INVALID
;
13138 /* Found consecutive range of addresses. */
13139 ret
= PC_BOUNDS_HIGH_LOW
;
13143 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13144 if (attr
!= nullptr && attr
->form_is_unsigned ())
13146 /* Offset in the .debug_ranges or .debug_rnglist section (depending
13147 on DWARF version). */
13148 ULONGEST ranges_offset
= attr
->as_unsigned ();
13150 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
13152 if (die
->tag
!= DW_TAG_compile_unit
)
13153 ranges_offset
+= cu
->gnu_ranges_base
;
13155 /* Value of the DW_AT_ranges attribute is the offset in the
13156 .debug_ranges section. */
13157 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
,
13158 map
, datum
, die
->tag
))
13159 return PC_BOUNDS_INVALID
;
13160 /* Found discontinuous range of addresses. */
13161 ret
= PC_BOUNDS_RANGES
;
13164 return PC_BOUNDS_NOT_PRESENT
;
13167 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13169 return PC_BOUNDS_INVALID
;
13171 /* When using the GNU linker, .gnu.linkonce. sections are used to
13172 eliminate duplicate copies of functions and vtables and such.
13173 The linker will arbitrarily choose one and discard the others.
13174 The AT_*_pc values for such functions refer to local labels in
13175 these sections. If the section from that file was discarded, the
13176 labels are not in the output, so the relocs get a value of 0.
13177 If this is a discarded function, mark the pc bounds as invalid,
13178 so that GDB will ignore it. */
13179 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
13180 return PC_BOUNDS_INVALID
;
13188 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13189 its low and high PC addresses. Do nothing if these addresses could not
13190 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13191 and HIGHPC to the high address if greater than HIGHPC. */
13194 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13195 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13196 struct dwarf2_cu
*cu
)
13198 CORE_ADDR low
, high
;
13199 struct die_info
*child
= die
->child
;
13201 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, nullptr, nullptr)
13202 >= PC_BOUNDS_RANGES
)
13204 *lowpc
= std::min (*lowpc
, low
);
13205 *highpc
= std::max (*highpc
, high
);
13208 /* If the language does not allow nested subprograms (either inside
13209 subprograms or lexical blocks), we're done. */
13210 if (cu
->lang () != language_ada
)
13213 /* Check all the children of the given DIE. If it contains nested
13214 subprograms, then check their pc bounds. Likewise, we need to
13215 check lexical blocks as well, as they may also contain subprogram
13217 while (child
&& child
->tag
)
13219 if (child
->tag
== DW_TAG_subprogram
13220 || child
->tag
== DW_TAG_lexical_block
)
13221 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13222 child
= child
->sibling
;
13226 /* Get the low and high pc's represented by the scope DIE, and store
13227 them in *LOWPC and *HIGHPC. If the correct values can't be
13228 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13231 get_scope_pc_bounds (struct die_info
*die
,
13232 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13233 struct dwarf2_cu
*cu
)
13235 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13236 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13237 CORE_ADDR current_low
, current_high
;
13239 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
,
13241 >= PC_BOUNDS_RANGES
)
13243 best_low
= current_low
;
13244 best_high
= current_high
;
13248 struct die_info
*child
= die
->child
;
13250 while (child
&& child
->tag
)
13252 switch (child
->tag
) {
13253 case DW_TAG_subprogram
:
13254 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13256 case DW_TAG_namespace
:
13257 case DW_TAG_module
:
13258 /* FIXME: carlton/2004-01-16: Should we do this for
13259 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13260 that current GCC's always emit the DIEs corresponding
13261 to definitions of methods of classes as children of a
13262 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13263 the DIEs giving the declarations, which could be
13264 anywhere). But I don't see any reason why the
13265 standards says that they have to be there. */
13266 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13268 if (current_low
!= ((CORE_ADDR
) -1))
13270 best_low
= std::min (best_low
, current_low
);
13271 best_high
= std::max (best_high
, current_high
);
13279 child
= child
->sibling
;
13284 *highpc
= best_high
;
13287 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13291 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13292 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13294 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13295 struct gdbarch
*gdbarch
= objfile
->arch ();
13296 struct attribute
*attr
;
13297 struct attribute
*attr_high
;
13299 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13302 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13303 if (attr
!= nullptr)
13305 CORE_ADDR low
= attr
->as_address ();
13306 CORE_ADDR high
= attr_high
->as_address ();
13308 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13311 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13312 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13313 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13317 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13318 if (attr
!= nullptr && attr
->form_is_unsigned ())
13320 /* Offset in the .debug_ranges or .debug_rnglist section (depending
13321 on DWARF version). */
13322 ULONGEST ranges_offset
= attr
->as_unsigned ();
13324 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
13326 if (die
->tag
!= DW_TAG_compile_unit
)
13327 ranges_offset
+= cu
->gnu_ranges_base
;
13329 std::vector
<blockrange
> blockvec
;
13330 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
13331 [&] (CORE_ADDR start
, CORE_ADDR end
)
13335 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13336 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13337 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
13338 blockvec
.emplace_back (start
, end
);
13341 block
->set_ranges (make_blockranges (objfile
, blockvec
));
13345 /* Check whether the producer field indicates either of GCC < 4.6, or the
13346 Intel C/C++ compiler, and cache the result in CU. */
13349 check_producer (struct dwarf2_cu
*cu
)
13353 if (cu
->producer
== NULL
)
13355 /* For unknown compilers expect their behavior is DWARF version
13358 GCC started to support .debug_types sections by -gdwarf-4 since
13359 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
13360 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
13361 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
13362 interpreted incorrectly by GDB now - GCC PR debug/48229. */
13364 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
13366 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
13367 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
13368 cu
->producer_is_gcc_11
= major
== 11;
13370 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
13372 cu
->producer_is_icc
= true;
13373 cu
->producer_is_icc_lt_14
= major
< 14;
13375 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
13376 cu
->producer_is_codewarrior
= true;
13377 else if (producer_is_clang (cu
->producer
, &major
, &minor
))
13378 cu
->producer_is_clang
= true;
13381 /* For other non-GCC compilers, expect their behavior is DWARF version
13385 cu
->checked_producer
= true;
13388 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
13389 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
13390 during 4.6.0 experimental. */
13393 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
13395 if (!cu
->checked_producer
)
13396 check_producer (cu
);
13398 return cu
->producer_is_gxx_lt_4_6
;
13402 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
13403 with incorrect is_stmt attributes. */
13406 producer_is_codewarrior (struct dwarf2_cu
*cu
)
13408 if (!cu
->checked_producer
)
13409 check_producer (cu
);
13411 return cu
->producer_is_codewarrior
;
13414 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
13415 If that attribute is not available, return the appropriate
13418 static enum dwarf_access_attribute
13419 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
13421 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13422 if (attr
!= nullptr)
13424 LONGEST value
= attr
->constant_value (-1);
13425 if (value
== DW_ACCESS_public
13426 || value
== DW_ACCESS_protected
13427 || value
== DW_ACCESS_private
)
13428 return (dwarf_access_attribute
) value
;
13429 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
13433 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
13435 /* The default DWARF 2 accessibility for members is public, the default
13436 accessibility for inheritance is private. */
13438 if (die
->tag
!= DW_TAG_inheritance
)
13439 return DW_ACCESS_public
;
13441 return DW_ACCESS_private
;
13445 /* DWARF 3+ defines the default accessibility a different way. The same
13446 rules apply now for DW_TAG_inheritance as for the members and it only
13447 depends on the container kind. */
13449 if (die
->parent
->tag
== DW_TAG_class_type
)
13450 return DW_ACCESS_private
;
13452 return DW_ACCESS_public
;
13456 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
13457 *OFFSET to the byte offset. If the attribute was not found return
13458 0, otherwise return 1. If it was found but could not properly be
13459 handled, set *OFFSET to 0. */
13462 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
13465 struct attribute
*attr
;
13467 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
13472 /* Note that we do not check for a section offset first here.
13473 This is because DW_AT_data_member_location is new in DWARF 4,
13474 so if we see it, we can assume that a constant form is really
13475 a constant and not a section offset. */
13476 if (attr
->form_is_constant ())
13477 *offset
= attr
->constant_value (0);
13478 else if (attr
->form_is_section_offset ())
13479 dwarf2_complex_location_expr_complaint ();
13480 else if (attr
->form_is_block ())
13481 *offset
= decode_locdesc (attr
->as_block (), cu
);
13483 dwarf2_complex_location_expr_complaint ();
13489 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
13490 if (attr
!= nullptr)
13492 *offset
= attr
->constant_value (0);
13500 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
13501 store the results in FIELD. */
13504 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
13505 struct field
*field
)
13507 struct attribute
*attr
;
13509 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
13512 if (attr
->form_is_constant ())
13514 LONGEST offset
= attr
->constant_value (0);
13516 /* Work around this GCC 11 bug, where it would erroneously use -1
13517 data member locations, instead of 0:
13519 Negative DW_AT_data_member_location
13520 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
13522 if (offset
== -1 && cu
->producer_is_gcc_11
)
13524 complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
13528 field
->set_loc_bitpos (offset
* bits_per_byte
);
13530 else if (attr
->form_is_section_offset ())
13531 dwarf2_complex_location_expr_complaint ();
13532 else if (attr
->form_is_block ())
13535 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
13537 field
->set_loc_bitpos (offset
* bits_per_byte
);
13540 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13541 struct objfile
*objfile
= per_objfile
->objfile
;
13542 struct dwarf2_locexpr_baton
*dlbaton
13543 = XOBNEW (&objfile
->objfile_obstack
,
13544 struct dwarf2_locexpr_baton
);
13545 dlbaton
->data
= attr
->as_block ()->data
;
13546 dlbaton
->size
= attr
->as_block ()->size
;
13547 /* When using this baton, we want to compute the address
13548 of the field, not the value. This is why
13549 is_reference is set to false here. */
13550 dlbaton
->is_reference
= false;
13551 dlbaton
->per_objfile
= per_objfile
;
13552 dlbaton
->per_cu
= cu
->per_cu
;
13554 field
->set_loc_dwarf_block (dlbaton
);
13558 dwarf2_complex_location_expr_complaint ();
13562 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
13563 if (attr
!= nullptr)
13564 field
->set_loc_bitpos (attr
->constant_value (0));
13568 /* Add an aggregate field to the field list. */
13571 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
13572 struct dwarf2_cu
*cu
)
13574 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13575 struct gdbarch
*gdbarch
= objfile
->arch ();
13576 struct nextfield
*new_field
;
13577 struct attribute
*attr
;
13579 const char *fieldname
= "";
13581 if (die
->tag
== DW_TAG_inheritance
)
13583 fip
->baseclasses
.emplace_back ();
13584 new_field
= &fip
->baseclasses
.back ();
13588 fip
->fields
.emplace_back ();
13589 new_field
= &fip
->fields
.back ();
13592 new_field
->offset
= die
->sect_off
;
13594 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
13595 if (new_field
->accessibility
!= DW_ACCESS_public
)
13596 fip
->non_public_fields
= true;
13598 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13599 if (attr
!= nullptr)
13600 new_field
->virtuality
= attr
->as_virtuality ();
13602 new_field
->virtuality
= DW_VIRTUALITY_none
;
13604 fp
= &new_field
->field
;
13606 if ((die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_namelist_item
)
13607 && !die_is_declaration (die
, cu
))
13609 if (die
->tag
== DW_TAG_namelist_item
)
13611 /* Typically, DW_TAG_namelist_item are references to namelist items.
13612 If so, follow that reference. */
13613 struct attribute
*attr1
= dwarf2_attr (die
, DW_AT_namelist_item
, cu
);
13614 struct die_info
*item_die
= nullptr;
13615 struct dwarf2_cu
*item_cu
= cu
;
13616 if (attr1
->form_is_ref ())
13617 item_die
= follow_die_ref (die
, attr1
, &item_cu
);
13618 if (item_die
!= nullptr)
13621 /* Data member other than a C++ static data member. */
13623 /* Get type of field. */
13624 fp
->set_type (die_type (die
, cu
));
13626 fp
->set_loc_bitpos (0);
13628 /* Get bit size of field (zero if none). */
13629 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
13630 if (attr
!= nullptr)
13632 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
13636 FIELD_BITSIZE (*fp
) = 0;
13639 /* Get bit offset of field. */
13640 handle_member_location (die
, cu
, fp
);
13641 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
13642 if (attr
!= nullptr && attr
->form_is_constant ())
13644 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
13646 /* For big endian bits, the DW_AT_bit_offset gives the
13647 additional bit offset from the MSB of the containing
13648 anonymous object to the MSB of the field. We don't
13649 have to do anything special since we don't need to
13650 know the size of the anonymous object. */
13651 fp
->set_loc_bitpos (fp
->loc_bitpos () + attr
->constant_value (0));
13655 /* For little endian bits, compute the bit offset to the
13656 MSB of the anonymous object, subtract off the number of
13657 bits from the MSB of the field to the MSB of the
13658 object, and then subtract off the number of bits of
13659 the field itself. The result is the bit offset of
13660 the LSB of the field. */
13661 int anonymous_size
;
13662 int bit_offset
= attr
->constant_value (0);
13664 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13665 if (attr
!= nullptr && attr
->form_is_constant ())
13667 /* The size of the anonymous object containing
13668 the bit field is explicit, so use the
13669 indicated size (in bytes). */
13670 anonymous_size
= attr
->constant_value (0);
13674 /* The size of the anonymous object containing
13675 the bit field must be inferred from the type
13676 attribute of the data member containing the
13678 anonymous_size
= fp
->type ()->length ();
13680 fp
->set_loc_bitpos (fp
->loc_bitpos ()
13681 + anonymous_size
* bits_per_byte
13682 - bit_offset
- FIELD_BITSIZE (*fp
));
13686 /* Get name of field. */
13687 fieldname
= dwarf2_name (die
, cu
);
13688 if (fieldname
== NULL
)
13691 /* The name is already allocated along with this objfile, so we don't
13692 need to duplicate it for the type. */
13693 fp
->set_name (fieldname
);
13695 /* Change accessibility for artificial fields (e.g. virtual table
13696 pointer or virtual base class pointer) to private. */
13697 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
13699 FIELD_ARTIFICIAL (*fp
) = 1;
13700 new_field
->accessibility
= DW_ACCESS_private
;
13701 fip
->non_public_fields
= true;
13704 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
13706 /* C++ static member. */
13708 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
13709 is a declaration, but all versions of G++ as of this writing
13710 (so through at least 3.2.1) incorrectly generate
13711 DW_TAG_variable tags. */
13713 const char *physname
;
13715 /* Get name of field. */
13716 fieldname
= dwarf2_name (die
, cu
);
13717 if (fieldname
== NULL
)
13720 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13722 /* Only create a symbol if this is an external value.
13723 new_symbol checks this and puts the value in the global symbol
13724 table, which we want. If it is not external, new_symbol
13725 will try to put the value in cu->list_in_scope which is wrong. */
13726 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
13728 /* A static const member, not much different than an enum as far as
13729 we're concerned, except that we can support more types. */
13730 new_symbol (die
, NULL
, cu
);
13733 /* Get physical name. */
13734 physname
= dwarf2_physname (fieldname
, die
, cu
);
13736 /* The name is already allocated along with this objfile, so we don't
13737 need to duplicate it for the type. */
13738 fp
->set_loc_physname (physname
? physname
: "");
13739 fp
->set_type (die_type (die
, cu
));
13740 fp
->set_name (fieldname
);
13742 else if (die
->tag
== DW_TAG_inheritance
)
13744 /* C++ base class field. */
13745 handle_member_location (die
, cu
, fp
);
13746 FIELD_BITSIZE (*fp
) = 0;
13747 fp
->set_type (die_type (die
, cu
));
13748 fp
->set_name (fp
->type ()->name ());
13751 gdb_assert_not_reached ("missing case in dwarf2_add_field");
13754 /* Can the type given by DIE define another type? */
13757 type_can_define_types (const struct die_info
*die
)
13761 case DW_TAG_typedef
:
13762 case DW_TAG_class_type
:
13763 case DW_TAG_structure_type
:
13764 case DW_TAG_union_type
:
13765 case DW_TAG_enumeration_type
:
13773 /* Add a type definition defined in the scope of the FIP's class. */
13776 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
13777 struct dwarf2_cu
*cu
)
13779 struct decl_field fp
;
13780 memset (&fp
, 0, sizeof (fp
));
13782 gdb_assert (type_can_define_types (die
));
13784 /* Get name of field. NULL is okay here, meaning an anonymous type. */
13785 fp
.name
= dwarf2_name (die
, cu
);
13786 fp
.type
= read_type_die (die
, cu
);
13788 /* Save accessibility. */
13789 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
13790 switch (accessibility
)
13792 case DW_ACCESS_public
:
13793 /* The assumed value if neither private nor protected. */
13795 case DW_ACCESS_private
:
13798 case DW_ACCESS_protected
:
13799 fp
.is_protected
= 1;
13803 if (die
->tag
== DW_TAG_typedef
)
13804 fip
->typedef_field_list
.push_back (fp
);
13806 fip
->nested_types_list
.push_back (fp
);
13809 /* A convenience typedef that's used when finding the discriminant
13810 field for a variant part. */
13811 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
13814 /* Compute the discriminant range for a given variant. OBSTACK is
13815 where the results will be stored. VARIANT is the variant to
13816 process. IS_UNSIGNED indicates whether the discriminant is signed
13819 static const gdb::array_view
<discriminant_range
>
13820 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
13823 std::vector
<discriminant_range
> ranges
;
13825 if (variant
.default_branch
)
13828 if (variant
.discr_list_data
== nullptr)
13830 discriminant_range r
13831 = {variant
.discriminant_value
, variant
.discriminant_value
};
13832 ranges
.push_back (r
);
13836 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
13837 variant
.discr_list_data
->size
);
13838 while (!data
.empty ())
13840 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
13842 complaint (_("invalid discriminant marker: %d"), data
[0]);
13845 bool is_range
= data
[0] == DW_DSC_range
;
13846 data
= data
.slice (1);
13848 ULONGEST low
, high
;
13849 unsigned int bytes_read
;
13853 complaint (_("DW_AT_discr_list missing low value"));
13857 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
13859 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
13861 data
= data
.slice (bytes_read
);
13867 complaint (_("DW_AT_discr_list missing high value"));
13871 high
= read_unsigned_leb128 (nullptr, data
.data (),
13874 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
13876 data
= data
.slice (bytes_read
);
13881 ranges
.push_back ({ low
, high
});
13885 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
13887 std::copy (ranges
.begin (), ranges
.end (), result
);
13888 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
13891 static const gdb::array_view
<variant_part
> create_variant_parts
13892 (struct obstack
*obstack
,
13893 const offset_map_type
&offset_map
,
13894 struct field_info
*fi
,
13895 const std::vector
<variant_part_builder
> &variant_parts
);
13897 /* Fill in a "struct variant" for a given variant field. RESULT is
13898 the variant to fill in. OBSTACK is where any needed allocations
13899 will be done. OFFSET_MAP holds the mapping from section offsets to
13900 fields for the type. FI describes the fields of the type we're
13901 processing. FIELD is the variant field we're converting. */
13904 create_one_variant (variant
&result
, struct obstack
*obstack
,
13905 const offset_map_type
&offset_map
,
13906 struct field_info
*fi
, const variant_field
&field
)
13908 result
.discriminants
= convert_variant_range (obstack
, field
, false);
13909 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
13910 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
13911 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
13912 field
.variant_parts
);
13915 /* Fill in a "struct variant_part" for a given variant part. RESULT
13916 is the variant part to fill in. OBSTACK is where any needed
13917 allocations will be done. OFFSET_MAP holds the mapping from
13918 section offsets to fields for the type. FI describes the fields of
13919 the type we're processing. BUILDER is the variant part to be
13923 create_one_variant_part (variant_part
&result
,
13924 struct obstack
*obstack
,
13925 const offset_map_type
&offset_map
,
13926 struct field_info
*fi
,
13927 const variant_part_builder
&builder
)
13929 auto iter
= offset_map
.find (builder
.discriminant_offset
);
13930 if (iter
== offset_map
.end ())
13932 result
.discriminant_index
= -1;
13933 /* Doesn't matter. */
13934 result
.is_unsigned
= false;
13938 result
.discriminant_index
= iter
->second
;
13940 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
13943 size_t n
= builder
.variants
.size ();
13944 variant
*output
= new (obstack
) variant
[n
];
13945 for (size_t i
= 0; i
< n
; ++i
)
13946 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
13947 builder
.variants
[i
]);
13949 result
.variants
= gdb::array_view
<variant
> (output
, n
);
13952 /* Create a vector of variant parts that can be attached to a type.
13953 OBSTACK is where any needed allocations will be done. OFFSET_MAP
13954 holds the mapping from section offsets to fields for the type. FI
13955 describes the fields of the type we're processing. VARIANT_PARTS
13956 is the vector to convert. */
13958 static const gdb::array_view
<variant_part
>
13959 create_variant_parts (struct obstack
*obstack
,
13960 const offset_map_type
&offset_map
,
13961 struct field_info
*fi
,
13962 const std::vector
<variant_part_builder
> &variant_parts
)
13964 if (variant_parts
.empty ())
13967 size_t n
= variant_parts
.size ();
13968 variant_part
*result
= new (obstack
) variant_part
[n
];
13969 for (size_t i
= 0; i
< n
; ++i
)
13970 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
13973 return gdb::array_view
<variant_part
> (result
, n
);
13976 /* Compute the variant part vector for FIP, attaching it to TYPE when
13980 add_variant_property (struct field_info
*fip
, struct type
*type
,
13981 struct dwarf2_cu
*cu
)
13983 /* Map section offsets of fields to their field index. Note the
13984 field index here does not take the number of baseclasses into
13986 offset_map_type offset_map
;
13987 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
13988 offset_map
[fip
->fields
[i
].offset
] = i
;
13990 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13991 gdb::array_view
<const variant_part
> parts
13992 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
13993 fip
->variant_parts
);
13995 struct dynamic_prop prop
;
13996 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
13997 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14000 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14003 /* Create the vector of fields, and attach it to the type. */
14006 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14007 struct dwarf2_cu
*cu
)
14009 int nfields
= fip
->nfields ();
14011 /* Record the field count, allocate space for the array of fields,
14012 and create blank accessibility bitfields if necessary. */
14013 type
->set_num_fields (nfields
);
14015 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14017 if (fip
->non_public_fields
&& cu
->lang () != language_ada
)
14019 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14021 TYPE_FIELD_PRIVATE_BITS (type
) =
14022 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14023 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14025 TYPE_FIELD_PROTECTED_BITS (type
) =
14026 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14027 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14029 TYPE_FIELD_IGNORE_BITS (type
) =
14030 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14031 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14034 /* If the type has baseclasses, allocate and clear a bit vector for
14035 TYPE_FIELD_VIRTUAL_BITS. */
14036 if (!fip
->baseclasses
.empty () && cu
->lang () != language_ada
)
14038 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14039 unsigned char *pointer
;
14041 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14042 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14043 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14044 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14045 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14048 if (!fip
->variant_parts
.empty ())
14049 add_variant_property (fip
, type
, cu
);
14051 /* Copy the saved-up fields into the field vector. */
14052 for (int i
= 0; i
< nfields
; ++i
)
14054 struct nextfield
&field
14055 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14056 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14058 type
->field (i
) = field
.field
;
14059 switch (field
.accessibility
)
14061 case DW_ACCESS_private
:
14062 if (cu
->lang () != language_ada
)
14063 SET_TYPE_FIELD_PRIVATE (type
, i
);
14066 case DW_ACCESS_protected
:
14067 if (cu
->lang () != language_ada
)
14068 SET_TYPE_FIELD_PROTECTED (type
, i
);
14071 case DW_ACCESS_public
:
14075 /* Unknown accessibility. Complain and treat it as public. */
14077 complaint (_("unsupported accessibility %d"),
14078 field
.accessibility
);
14082 if (i
< fip
->baseclasses
.size ())
14084 switch (field
.virtuality
)
14086 case DW_VIRTUALITY_virtual
:
14087 case DW_VIRTUALITY_pure_virtual
:
14088 if (cu
->lang () == language_ada
)
14089 error (_("unexpected virtuality in component of Ada type"));
14090 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14097 /* Return true if this member function is a constructor, false
14101 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14103 const char *fieldname
;
14104 const char *type_name
;
14107 if (die
->parent
== NULL
)
14110 if (die
->parent
->tag
!= DW_TAG_structure_type
14111 && die
->parent
->tag
!= DW_TAG_union_type
14112 && die
->parent
->tag
!= DW_TAG_class_type
)
14115 fieldname
= dwarf2_name (die
, cu
);
14116 type_name
= dwarf2_name (die
->parent
, cu
);
14117 if (fieldname
== NULL
|| type_name
== NULL
)
14120 len
= strlen (fieldname
);
14121 return (strncmp (fieldname
, type_name
, len
) == 0
14122 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14125 /* Add a member function to the proper fieldlist. */
14128 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14129 struct type
*type
, struct dwarf2_cu
*cu
)
14131 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14132 struct attribute
*attr
;
14134 struct fnfieldlist
*flp
= nullptr;
14135 struct fn_field
*fnp
;
14136 const char *fieldname
;
14137 struct type
*this_type
;
14139 if (cu
->lang () == language_ada
)
14140 error (_("unexpected member function in Ada type"));
14142 /* Get name of member function. */
14143 fieldname
= dwarf2_name (die
, cu
);
14144 if (fieldname
== NULL
)
14147 /* Look up member function name in fieldlist. */
14148 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14150 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14152 flp
= &fip
->fnfieldlists
[i
];
14157 /* Create a new fnfieldlist if necessary. */
14158 if (flp
== nullptr)
14160 fip
->fnfieldlists
.emplace_back ();
14161 flp
= &fip
->fnfieldlists
.back ();
14162 flp
->name
= fieldname
;
14163 i
= fip
->fnfieldlists
.size () - 1;
14166 /* Create a new member function field and add it to the vector of
14168 flp
->fnfields
.emplace_back ();
14169 fnp
= &flp
->fnfields
.back ();
14171 /* Delay processing of the physname until later. */
14172 if (cu
->lang () == language_cplus
)
14173 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14177 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14178 fnp
->physname
= physname
? physname
: "";
14181 fnp
->type
= alloc_type (objfile
);
14182 this_type
= read_type_die (die
, cu
);
14183 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
14185 int nparams
= this_type
->num_fields ();
14187 /* TYPE is the domain of this method, and THIS_TYPE is the type
14188 of the method itself (TYPE_CODE_METHOD). */
14189 smash_to_method_type (fnp
->type
, type
,
14190 this_type
->target_type (),
14191 this_type
->fields (),
14192 this_type
->num_fields (),
14193 this_type
->has_varargs ());
14195 /* Handle static member functions.
14196 Dwarf2 has no clean way to discern C++ static and non-static
14197 member functions. G++ helps GDB by marking the first
14198 parameter for non-static member functions (which is the this
14199 pointer) as artificial. We obtain this information from
14200 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14201 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14202 fnp
->voffset
= VOFFSET_STATIC
;
14205 complaint (_("member function type missing for '%s'"),
14206 dwarf2_full_name (fieldname
, die
, cu
));
14208 /* Get fcontext from DW_AT_containing_type if present. */
14209 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14210 fnp
->fcontext
= die_containing_type (die
, cu
);
14212 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14213 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14215 /* Get accessibility. */
14216 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14217 switch (accessibility
)
14219 case DW_ACCESS_private
:
14220 fnp
->is_private
= 1;
14222 case DW_ACCESS_protected
:
14223 fnp
->is_protected
= 1;
14227 /* Check for artificial methods. */
14228 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14229 if (attr
&& attr
->as_boolean ())
14230 fnp
->is_artificial
= 1;
14232 /* Check for defaulted methods. */
14233 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14234 if (attr
!= nullptr)
14235 fnp
->defaulted
= attr
->defaulted ();
14237 /* Check for deleted methods. */
14238 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14239 if (attr
!= nullptr && attr
->as_boolean ())
14240 fnp
->is_deleted
= 1;
14242 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14244 /* Get index in virtual function table if it is a virtual member
14245 function. For older versions of GCC, this is an offset in the
14246 appropriate virtual table, as specified by DW_AT_containing_type.
14247 For everyone else, it is an expression to be evaluated relative
14248 to the object address. */
14250 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14251 if (attr
!= nullptr)
14253 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
14255 struct dwarf_block
*block
= attr
->as_block ();
14257 if (block
->data
[0] == DW_OP_constu
)
14259 /* Old-style GCC. */
14260 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
14262 else if (block
->data
[0] == DW_OP_deref
14263 || (block
->size
> 1
14264 && block
->data
[0] == DW_OP_deref_size
14265 && block
->data
[1] == cu
->header
.addr_size
))
14267 fnp
->voffset
= decode_locdesc (block
, cu
);
14268 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14269 dwarf2_complex_location_expr_complaint ();
14271 fnp
->voffset
/= cu
->header
.addr_size
;
14275 dwarf2_complex_location_expr_complaint ();
14277 if (!fnp
->fcontext
)
14279 /* If there is no `this' field and no DW_AT_containing_type,
14280 we cannot actually find a base class context for the
14282 if (this_type
->num_fields () == 0
14283 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14285 complaint (_("cannot determine context for virtual member "
14286 "function \"%s\" (offset %s)"),
14287 fieldname
, sect_offset_str (die
->sect_off
));
14291 fnp
->fcontext
= this_type
->field (0).type ()->target_type ();
14295 else if (attr
->form_is_section_offset ())
14297 dwarf2_complex_location_expr_complaint ();
14301 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14307 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14308 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
14310 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14311 complaint (_("Member function \"%s\" (offset %s) is virtual "
14312 "but the vtable offset is not specified"),
14313 fieldname
, sect_offset_str (die
->sect_off
));
14314 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14315 TYPE_CPLUS_DYNAMIC (type
) = 1;
14320 /* Create the vector of member function fields, and attach it to the type. */
14323 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14324 struct dwarf2_cu
*cu
)
14326 if (cu
->lang () == language_ada
)
14327 error (_("unexpected member functions in Ada type"));
14329 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14330 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14332 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14334 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14336 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14337 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14339 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14340 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14341 fn_flp
->fn_fields
= (struct fn_field
*)
14342 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14344 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14345 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14348 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14351 /* Returns non-zero if NAME is the name of a vtable member in CU's
14352 language, zero otherwise. */
14354 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14356 static const char vptr
[] = "_vptr";
14358 /* Look for the C++ form of the vtable. */
14359 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14365 /* GCC outputs unnamed structures that are really pointers to member
14366 functions, with the ABI-specified layout. If TYPE describes
14367 such a structure, smash it into a member function type.
14369 GCC shouldn't do this; it should just output pointer to member DIEs.
14370 This is GCC PR debug/28767. */
14373 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14375 struct type
*pfn_type
, *self_type
, *new_type
;
14377 /* Check for a structure with no name and two children. */
14378 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
14381 /* Check for __pfn and __delta members. */
14382 if (type
->field (0).name () == NULL
14383 || strcmp (type
->field (0).name (), "__pfn") != 0
14384 || type
->field (1).name () == NULL
14385 || strcmp (type
->field (1).name (), "__delta") != 0)
14388 /* Find the type of the method. */
14389 pfn_type
= type
->field (0).type ();
14390 if (pfn_type
== NULL
14391 || pfn_type
->code () != TYPE_CODE_PTR
14392 || pfn_type
->target_type ()->code () != TYPE_CODE_FUNC
)
14395 /* Look for the "this" argument. */
14396 pfn_type
= pfn_type
->target_type ();
14397 if (pfn_type
->num_fields () == 0
14398 /* || pfn_type->field (0).type () == NULL */
14399 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
14402 self_type
= pfn_type
->field (0).type ()->target_type ();
14403 new_type
= alloc_type (objfile
);
14404 smash_to_method_type (new_type
, self_type
, pfn_type
->target_type (),
14405 pfn_type
->fields (), pfn_type
->num_fields (),
14406 pfn_type
->has_varargs ());
14407 smash_to_methodptr_type (type
, new_type
);
14410 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
14411 requires rewriting, then copy it and return the updated copy.
14412 Otherwise return nullptr. */
14414 static struct type
*
14415 rewrite_array_type (struct type
*type
)
14417 if (type
->code () != TYPE_CODE_ARRAY
)
14420 struct type
*index_type
= type
->index_type ();
14421 range_bounds
*current_bounds
= index_type
->bounds ();
14423 /* Handle multi-dimensional arrays. */
14424 struct type
*new_target
= rewrite_array_type (type
->target_type ());
14425 if (new_target
== nullptr)
14427 /* Maybe we don't need to rewrite this array. */
14428 if (current_bounds
->low
.kind () == PROP_CONST
14429 && current_bounds
->high
.kind () == PROP_CONST
)
14433 /* Either the target type was rewritten, or the bounds have to be
14434 updated. Either way we want to copy the type and update
14436 struct type
*copy
= copy_type (type
);
14437 int nfields
= copy
->num_fields ();
14439 = ((struct field
*) TYPE_ZALLOC (copy
,
14440 nfields
* sizeof (struct field
)));
14441 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
14442 copy
->set_fields (new_fields
);
14443 if (new_target
!= nullptr)
14444 copy
->set_target_type (new_target
);
14446 struct type
*index_copy
= copy_type (index_type
);
14447 range_bounds
*bounds
14448 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
14449 sizeof (range_bounds
));
14450 *bounds
= *current_bounds
;
14451 bounds
->low
.set_const_val (1);
14452 bounds
->high
.set_const_val (0);
14453 index_copy
->set_bounds (bounds
);
14454 copy
->set_index_type (index_copy
);
14459 /* While some versions of GCC will generate complicated DWARF for an
14460 array (see quirk_ada_thick_pointer), more recent versions were
14461 modified to emit an explicit thick pointer structure. However, in
14462 this case, the array still has DWARF expressions for its ranges,
14463 and these must be ignored. */
14466 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
14469 gdb_assert (cu
->lang () == language_ada
);
14471 /* Check for a structure with two children. */
14472 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
14475 /* Check for P_ARRAY and P_BOUNDS members. */
14476 if (type
->field (0).name () == NULL
14477 || strcmp (type
->field (0).name (), "P_ARRAY") != 0
14478 || type
->field (1).name () == NULL
14479 || strcmp (type
->field (1).name (), "P_BOUNDS") != 0)
14482 /* Make sure we're looking at a pointer to an array. */
14483 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
14486 /* The Ada code already knows how to handle these types, so all that
14487 we need to do is turn the bounds into static bounds. However, we
14488 don't want to rewrite existing array or index types in-place,
14489 because those may be referenced in other contexts where this
14490 rewriting is undesirable. */
14491 struct type
*new_ary_type
14492 = rewrite_array_type (type
->field (0).type ()->target_type ());
14493 if (new_ary_type
!= nullptr)
14494 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
14497 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14498 appropriate error checking and issuing complaints if there is a
14502 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14504 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14506 if (attr
== nullptr)
14509 if (!attr
->form_is_constant ())
14511 complaint (_("DW_AT_alignment must have constant form"
14512 " - DIE at %s [in module %s]"),
14513 sect_offset_str (die
->sect_off
),
14514 objfile_name (cu
->per_objfile
->objfile
));
14518 LONGEST val
= attr
->constant_value (0);
14521 complaint (_("DW_AT_alignment value must not be negative"
14522 " - DIE at %s [in module %s]"),
14523 sect_offset_str (die
->sect_off
),
14524 objfile_name (cu
->per_objfile
->objfile
));
14527 ULONGEST align
= val
;
14531 complaint (_("DW_AT_alignment value must not be zero"
14532 " - DIE at %s [in module %s]"),
14533 sect_offset_str (die
->sect_off
),
14534 objfile_name (cu
->per_objfile
->objfile
));
14537 if ((align
& (align
- 1)) != 0)
14539 complaint (_("DW_AT_alignment value must be a power of 2"
14540 " - DIE at %s [in module %s]"),
14541 sect_offset_str (die
->sect_off
),
14542 objfile_name (cu
->per_objfile
->objfile
));
14549 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14550 the alignment for TYPE. */
14553 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14556 if (!set_type_align (type
, get_alignment (cu
, die
)))
14557 complaint (_("DW_AT_alignment value too large"
14558 " - DIE at %s [in module %s]"),
14559 sect_offset_str (die
->sect_off
),
14560 objfile_name (cu
->per_objfile
->objfile
));
14563 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14564 constant for a type, according to DWARF5 spec, Table 5.5. */
14567 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14572 case DW_CC_pass_by_reference
:
14573 case DW_CC_pass_by_value
:
14577 complaint (_("unrecognized DW_AT_calling_convention value "
14578 "(%s) for a type"), pulongest (value
));
14583 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14584 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14585 also according to GNU-specific values (see include/dwarf2.h). */
14588 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14593 case DW_CC_program
:
14597 case DW_CC_GNU_renesas_sh
:
14598 case DW_CC_GNU_borland_fastcall_i386
:
14599 case DW_CC_GDB_IBM_OpenCL
:
14603 complaint (_("unrecognized DW_AT_calling_convention value "
14604 "(%s) for a subroutine"), pulongest (value
));
14609 /* Called when we find the DIE that starts a structure or union scope
14610 (definition) to create a type for the structure or union. Fill in
14611 the type's name and general properties; the members will not be
14612 processed until process_structure_scope. A symbol table entry for
14613 the type will also not be done until process_structure_scope (assuming
14614 the type has a name).
14616 NOTE: we need to call these functions regardless of whether or not the
14617 DIE has a DW_AT_name attribute, since it might be an anonymous
14618 structure or union. This gets the type entered into our set of
14619 user defined types. */
14621 static struct type
*
14622 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14624 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14626 struct attribute
*attr
;
14629 /* If the definition of this type lives in .debug_types, read that type.
14630 Don't follow DW_AT_specification though, that will take us back up
14631 the chain and we want to go down. */
14632 attr
= die
->attr (DW_AT_signature
);
14633 if (attr
!= nullptr)
14635 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14637 /* The type's CU may not be the same as CU.
14638 Ensure TYPE is recorded with CU in die_type_hash. */
14639 return set_die_type (die
, type
, cu
);
14642 type
= alloc_type (objfile
);
14643 INIT_CPLUS_SPECIFIC (type
);
14645 name
= dwarf2_name (die
, cu
);
14648 if (cu
->lang () == language_cplus
14649 || cu
->lang () == language_d
14650 || cu
->lang () == language_rust
)
14652 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
14654 /* dwarf2_full_name might have already finished building the DIE's
14655 type. If so, there is no need to continue. */
14656 if (get_die_type (die
, cu
) != NULL
)
14657 return get_die_type (die
, cu
);
14659 type
->set_name (full_name
);
14663 /* The name is already allocated along with this objfile, so
14664 we don't need to duplicate it for the type. */
14665 type
->set_name (name
);
14669 if (die
->tag
== DW_TAG_structure_type
)
14671 type
->set_code (TYPE_CODE_STRUCT
);
14673 else if (die
->tag
== DW_TAG_union_type
)
14675 type
->set_code (TYPE_CODE_UNION
);
14677 else if (die
->tag
== DW_TAG_namelist
)
14679 type
->set_code (TYPE_CODE_NAMELIST
);
14683 type
->set_code (TYPE_CODE_STRUCT
);
14686 if (cu
->lang () == language_cplus
&& die
->tag
== DW_TAG_class_type
)
14687 type
->set_is_declared_class (true);
14689 /* Store the calling convention in the type if it's available in
14690 the die. Otherwise the calling convention remains set to
14691 the default value DW_CC_normal. */
14692 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14693 if (attr
!= nullptr
14694 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
14696 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14697 TYPE_CPLUS_CALLING_CONVENTION (type
)
14698 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
14701 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14702 if (attr
!= nullptr)
14704 if (attr
->form_is_constant ())
14705 type
->set_length (attr
->constant_value (0));
14708 struct dynamic_prop prop
;
14709 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
14710 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
14712 type
->set_length (0);
14716 type
->set_length (0);
14718 maybe_set_alignment (cu
, die
, type
);
14720 if (producer_is_icc_lt_14 (cu
) && (type
->length () == 0))
14722 /* ICC<14 does not output the required DW_AT_declaration on
14723 incomplete types, but gives them a size of zero. */
14724 type
->set_is_stub (true);
14727 type
->set_stub_is_supported (true);
14729 if (die_is_declaration (die
, cu
))
14730 type
->set_is_stub (true);
14731 else if (attr
== NULL
&& die
->child
== NULL
14732 && producer_is_realview (cu
->producer
))
14733 /* RealView does not output the required DW_AT_declaration
14734 on incomplete types. */
14735 type
->set_is_stub (true);
14737 /* We need to add the type field to the die immediately so we don't
14738 infinitely recurse when dealing with pointers to the structure
14739 type within the structure itself. */
14740 set_die_type (die
, type
, cu
);
14742 /* set_die_type should be already done. */
14743 set_descriptive_type (type
, die
, cu
);
14748 static void handle_struct_member_die
14749 (struct die_info
*child_die
,
14751 struct field_info
*fi
,
14752 std::vector
<struct symbol
*> *template_args
,
14753 struct dwarf2_cu
*cu
);
14755 /* A helper for handle_struct_member_die that handles
14756 DW_TAG_variant_part. */
14759 handle_variant_part (struct die_info
*die
, struct type
*type
,
14760 struct field_info
*fi
,
14761 std::vector
<struct symbol
*> *template_args
,
14762 struct dwarf2_cu
*cu
)
14764 variant_part_builder
*new_part
;
14765 if (fi
->current_variant_part
== nullptr)
14767 fi
->variant_parts
.emplace_back ();
14768 new_part
= &fi
->variant_parts
.back ();
14770 else if (!fi
->current_variant_part
->processing_variant
)
14772 complaint (_("nested DW_TAG_variant_part seen "
14773 "- DIE at %s [in module %s]"),
14774 sect_offset_str (die
->sect_off
),
14775 objfile_name (cu
->per_objfile
->objfile
));
14780 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
14781 current
.variant_parts
.emplace_back ();
14782 new_part
= ¤t
.variant_parts
.back ();
14785 /* When we recurse, we want callees to add to this new variant
14787 scoped_restore save_current_variant_part
14788 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
14790 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
14793 /* It's a univariant form, an extension we support. */
14795 else if (discr
->form_is_ref ())
14797 struct dwarf2_cu
*target_cu
= cu
;
14798 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
14800 new_part
->discriminant_offset
= target_die
->sect_off
;
14804 complaint (_("DW_AT_discr does not have DIE reference form"
14805 " - DIE at %s [in module %s]"),
14806 sect_offset_str (die
->sect_off
),
14807 objfile_name (cu
->per_objfile
->objfile
));
14810 for (die_info
*child_die
= die
->child
;
14812 child_die
= child_die
->sibling
)
14813 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
14816 /* A helper for handle_struct_member_die that handles
14820 handle_variant (struct die_info
*die
, struct type
*type
,
14821 struct field_info
*fi
,
14822 std::vector
<struct symbol
*> *template_args
,
14823 struct dwarf2_cu
*cu
)
14825 if (fi
->current_variant_part
== nullptr)
14827 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
14828 "- DIE at %s [in module %s]"),
14829 sect_offset_str (die
->sect_off
),
14830 objfile_name (cu
->per_objfile
->objfile
));
14833 if (fi
->current_variant_part
->processing_variant
)
14835 complaint (_("nested DW_TAG_variant seen "
14836 "- DIE at %s [in module %s]"),
14837 sect_offset_str (die
->sect_off
),
14838 objfile_name (cu
->per_objfile
->objfile
));
14842 scoped_restore save_processing_variant
14843 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
14846 fi
->current_variant_part
->variants
.emplace_back ();
14847 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
14848 variant
.first_field
= fi
->fields
.size ();
14850 /* In a variant we want to get the discriminant and also add a
14851 field for our sole member child. */
14852 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
14853 if (discr
== nullptr || !discr
->form_is_constant ())
14855 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
14856 if (discr
== nullptr || discr
->as_block ()->size
== 0)
14857 variant
.default_branch
= true;
14859 variant
.discr_list_data
= discr
->as_block ();
14862 variant
.discriminant_value
= discr
->constant_value (0);
14864 for (die_info
*variant_child
= die
->child
;
14865 variant_child
!= NULL
;
14866 variant_child
= variant_child
->sibling
)
14867 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
14869 variant
.last_field
= fi
->fields
.size ();
14872 /* A helper for process_structure_scope that handles a single member
14876 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
14877 struct field_info
*fi
,
14878 std::vector
<struct symbol
*> *template_args
,
14879 struct dwarf2_cu
*cu
)
14881 if (child_die
->tag
== DW_TAG_member
14882 || child_die
->tag
== DW_TAG_variable
14883 || child_die
->tag
== DW_TAG_namelist_item
)
14885 /* NOTE: carlton/2002-11-05: A C++ static data member
14886 should be a DW_TAG_member that is a declaration, but
14887 all versions of G++ as of this writing (so through at
14888 least 3.2.1) incorrectly generate DW_TAG_variable
14889 tags for them instead. */
14890 dwarf2_add_field (fi
, child_die
, cu
);
14892 else if (child_die
->tag
== DW_TAG_subprogram
)
14894 /* Rust doesn't have member functions in the C++ sense.
14895 However, it does emit ordinary functions as children
14896 of a struct DIE. */
14897 if (cu
->lang () == language_rust
)
14898 read_func_scope (child_die
, cu
);
14901 /* C++ member function. */
14902 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
14905 else if (child_die
->tag
== DW_TAG_inheritance
)
14907 /* C++ base class field. */
14908 dwarf2_add_field (fi
, child_die
, cu
);
14910 else if (type_can_define_types (child_die
))
14911 dwarf2_add_type_defn (fi
, child_die
, cu
);
14912 else if (child_die
->tag
== DW_TAG_template_type_param
14913 || child_die
->tag
== DW_TAG_template_value_param
)
14915 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
14918 template_args
->push_back (arg
);
14920 else if (child_die
->tag
== DW_TAG_variant_part
)
14921 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
14922 else if (child_die
->tag
== DW_TAG_variant
)
14923 handle_variant (child_die
, type
, fi
, template_args
, cu
);
14926 /* Finish creating a structure or union type, including filling in its
14927 members and creating a symbol for it. This function also handles Fortran
14928 namelist variables, their items or members and creating a symbol for
14932 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14934 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14935 struct die_info
*child_die
;
14938 type
= get_die_type (die
, cu
);
14940 type
= read_structure_type (die
, cu
);
14942 bool has_template_parameters
= false;
14943 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
14945 struct field_info fi
;
14946 std::vector
<struct symbol
*> template_args
;
14948 child_die
= die
->child
;
14950 while (child_die
&& child_die
->tag
)
14952 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
14953 child_die
= child_die
->sibling
;
14956 /* Attach template arguments to type. */
14957 if (!template_args
.empty ())
14959 has_template_parameters
= true;
14960 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14961 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
14962 TYPE_TEMPLATE_ARGUMENTS (type
)
14963 = XOBNEWVEC (&objfile
->objfile_obstack
,
14965 TYPE_N_TEMPLATE_ARGUMENTS (type
));
14966 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
14967 template_args
.data (),
14968 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
14969 * sizeof (struct symbol
*)));
14972 /* Attach fields and member functions to the type. */
14973 if (fi
.nfields () > 0)
14974 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
14975 if (!fi
.fnfieldlists
.empty ())
14977 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
14979 /* Get the type which refers to the base class (possibly this
14980 class itself) which contains the vtable pointer for the current
14981 class from the DW_AT_containing_type attribute. This use of
14982 DW_AT_containing_type is a GNU extension. */
14984 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14986 struct type
*t
= die_containing_type (die
, cu
);
14988 set_type_vptr_basetype (type
, t
);
14993 /* Our own class provides vtbl ptr. */
14994 for (i
= t
->num_fields () - 1;
14995 i
>= TYPE_N_BASECLASSES (t
);
14998 const char *fieldname
= t
->field (i
).name ();
15000 if (is_vtable_name (fieldname
, cu
))
15002 set_type_vptr_fieldno (type
, i
);
15007 /* Complain if virtual function table field not found. */
15008 if (i
< TYPE_N_BASECLASSES (t
))
15009 complaint (_("virtual function table pointer "
15010 "not found when defining class '%s'"),
15011 type
->name () ? type
->name () : "");
15015 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15018 else if (cu
->producer
15019 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15021 /* The IBM XLC compiler does not provide direct indication
15022 of the containing type, but the vtable pointer is
15023 always named __vfp. */
15027 for (i
= type
->num_fields () - 1;
15028 i
>= TYPE_N_BASECLASSES (type
);
15031 if (strcmp (type
->field (i
).name (), "__vfp") == 0)
15033 set_type_vptr_fieldno (type
, i
);
15034 set_type_vptr_basetype (type
, type
);
15041 /* Copy fi.typedef_field_list linked list elements content into the
15042 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15043 if (!fi
.typedef_field_list
.empty ())
15045 int count
= fi
.typedef_field_list
.size ();
15047 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15048 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15049 = ((struct decl_field
*)
15051 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15052 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15054 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15055 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15058 /* Copy fi.nested_types_list linked list elements content into the
15059 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15060 if (!fi
.nested_types_list
.empty ()
15061 && cu
->lang () != language_ada
)
15063 int count
= fi
.nested_types_list
.size ();
15065 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15066 TYPE_NESTED_TYPES_ARRAY (type
)
15067 = ((struct decl_field
*)
15068 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15069 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15071 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15072 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15076 quirk_gcc_member_function_pointer (type
, objfile
);
15077 if (cu
->lang () == language_rust
&& die
->tag
== DW_TAG_union_type
)
15078 cu
->rust_unions
.push_back (type
);
15079 else if (cu
->lang () == language_ada
)
15080 quirk_ada_thick_pointer_struct (die
, cu
, type
);
15082 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15083 snapshots) has been known to create a die giving a declaration
15084 for a class that has, as a child, a die giving a definition for a
15085 nested class. So we have to process our children even if the
15086 current die is a declaration. Normally, of course, a declaration
15087 won't have any children at all. */
15089 child_die
= die
->child
;
15091 while (child_die
!= NULL
&& child_die
->tag
)
15093 if (child_die
->tag
== DW_TAG_member
15094 || child_die
->tag
== DW_TAG_variable
15095 || child_die
->tag
== DW_TAG_inheritance
15096 || child_die
->tag
== DW_TAG_template_value_param
15097 || child_die
->tag
== DW_TAG_template_type_param
)
15102 process_die (child_die
, cu
);
15104 child_die
= child_die
->sibling
;
15107 /* Do not consider external references. According to the DWARF standard,
15108 these DIEs are identified by the fact that they have no byte_size
15109 attribute, and a declaration attribute. */
15110 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15111 || !die_is_declaration (die
, cu
)
15112 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15114 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15116 if (has_template_parameters
)
15118 struct symtab
*symtab
;
15119 if (sym
!= nullptr)
15120 symtab
= sym
->symtab ();
15121 else if (cu
->line_header
!= nullptr)
15123 /* Any related symtab will do. */
15125 = cu
->line_header
->file_names ()[0].symtab
;
15130 complaint (_("could not find suitable "
15131 "symtab for template parameter"
15132 " - DIE at %s [in module %s]"),
15133 sect_offset_str (die
->sect_off
),
15134 objfile_name (objfile
));
15137 if (symtab
!= nullptr)
15139 /* Make sure that the symtab is set on the new symbols.
15140 Even though they don't appear in this symtab directly,
15141 other parts of gdb assume that symbols do, and this is
15142 reasonably true. */
15143 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15144 TYPE_TEMPLATE_ARGUMENT (type
, i
)->set_symtab (symtab
);
15150 /* Assuming DIE is an enumeration type, and TYPE is its associated
15151 type, update TYPE using some information only available in DIE's
15152 children. In particular, the fields are computed. */
15155 update_enumeration_type_from_children (struct die_info
*die
,
15157 struct dwarf2_cu
*cu
)
15159 struct die_info
*child_die
;
15160 int unsigned_enum
= 1;
15163 auto_obstack obstack
;
15164 std::vector
<struct field
> fields
;
15166 for (child_die
= die
->child
;
15167 child_die
!= NULL
&& child_die
->tag
;
15168 child_die
= child_die
->sibling
)
15170 struct attribute
*attr
;
15172 const gdb_byte
*bytes
;
15173 struct dwarf2_locexpr_baton
*baton
;
15176 if (child_die
->tag
!= DW_TAG_enumerator
)
15179 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15183 name
= dwarf2_name (child_die
, cu
);
15185 name
= "<anonymous enumerator>";
15187 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15188 &value
, &bytes
, &baton
);
15196 if (count_one_bits_ll (value
) >= 2)
15200 fields
.emplace_back ();
15201 struct field
&field
= fields
.back ();
15202 field
.set_name (dwarf2_physname (name
, child_die
, cu
));
15203 field
.set_loc_enumval (value
);
15206 if (!fields
.empty ())
15208 type
->set_num_fields (fields
.size ());
15211 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
15212 memcpy (type
->fields (), fields
.data (),
15213 sizeof (struct field
) * fields
.size ());
15217 type
->set_is_unsigned (true);
15220 type
->set_is_flag_enum (true);
15223 /* Given a DW_AT_enumeration_type die, set its type. We do not
15224 complete the type's fields yet, or create any symbols. */
15226 static struct type
*
15227 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15229 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15231 struct attribute
*attr
;
15234 /* If the definition of this type lives in .debug_types, read that type.
15235 Don't follow DW_AT_specification though, that will take us back up
15236 the chain and we want to go down. */
15237 attr
= die
->attr (DW_AT_signature
);
15238 if (attr
!= nullptr)
15240 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15242 /* The type's CU may not be the same as CU.
15243 Ensure TYPE is recorded with CU in die_type_hash. */
15244 return set_die_type (die
, type
, cu
);
15247 type
= alloc_type (objfile
);
15249 type
->set_code (TYPE_CODE_ENUM
);
15250 name
= dwarf2_full_name (NULL
, die
, cu
);
15252 type
->set_name (name
);
15254 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15257 struct type
*underlying_type
= die_type (die
, cu
);
15259 type
->set_target_type (underlying_type
);
15262 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15263 if (attr
!= nullptr)
15264 type
->set_length (attr
->constant_value (0));
15266 type
->set_length (0);
15268 maybe_set_alignment (cu
, die
, type
);
15270 /* The enumeration DIE can be incomplete. In Ada, any type can be
15271 declared as private in the package spec, and then defined only
15272 inside the package body. Such types are known as Taft Amendment
15273 Types. When another package uses such a type, an incomplete DIE
15274 may be generated by the compiler. */
15275 if (die_is_declaration (die
, cu
))
15276 type
->set_is_stub (true);
15278 /* If this type has an underlying type that is not a stub, then we
15279 may use its attributes. We always use the "unsigned" attribute
15280 in this situation, because ordinarily we guess whether the type
15281 is unsigned -- but the guess can be wrong and the underlying type
15282 can tell us the reality. However, we defer to a local size
15283 attribute if one exists, because this lets the compiler override
15284 the underlying type if needed. */
15285 if (type
->target_type () != NULL
&& !type
->target_type ()->is_stub ())
15287 struct type
*underlying_type
= type
->target_type ();
15288 underlying_type
= check_typedef (underlying_type
);
15290 type
->set_is_unsigned (underlying_type
->is_unsigned ());
15292 if (type
->length () == 0)
15293 type
->set_length (underlying_type
->length ());
15295 if (TYPE_RAW_ALIGN (type
) == 0
15296 && TYPE_RAW_ALIGN (underlying_type
) != 0)
15297 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
15300 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
15302 set_die_type (die
, type
, cu
);
15304 /* Finish the creation of this type by using the enum's children.
15305 Note that, as usual, this must come after set_die_type to avoid
15306 infinite recursion when trying to compute the names of the
15308 update_enumeration_type_from_children (die
, type
, cu
);
15313 /* Given a pointer to a die which begins an enumeration, process all
15314 the dies that define the members of the enumeration, and create the
15315 symbol for the enumeration type.
15317 NOTE: We reverse the order of the element list. */
15320 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15322 struct type
*this_type
;
15324 this_type
= get_die_type (die
, cu
);
15325 if (this_type
== NULL
)
15326 this_type
= read_enumeration_type (die
, cu
);
15328 if (die
->child
!= NULL
)
15330 struct die_info
*child_die
;
15333 child_die
= die
->child
;
15334 while (child_die
&& child_die
->tag
)
15336 if (child_die
->tag
!= DW_TAG_enumerator
)
15338 process_die (child_die
, cu
);
15342 name
= dwarf2_name (child_die
, cu
);
15344 new_symbol (child_die
, this_type
, cu
);
15347 child_die
= child_die
->sibling
;
15351 /* If we are reading an enum from a .debug_types unit, and the enum
15352 is a declaration, and the enum is not the signatured type in the
15353 unit, then we do not want to add a symbol for it. Adding a
15354 symbol would in some cases obscure the true definition of the
15355 enum, giving users an incomplete type when the definition is
15356 actually available. Note that we do not want to do this for all
15357 enums which are just declarations, because C++0x allows forward
15358 enum declarations. */
15359 if (cu
->per_cu
->is_debug_types
15360 && die_is_declaration (die
, cu
))
15362 struct signatured_type
*sig_type
;
15364 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15365 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15366 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15370 new_symbol (die
, this_type
, cu
);
15373 /* Helper function for quirk_ada_thick_pointer that examines a bounds
15374 expression for an index type and finds the corresponding field
15375 offset in the hidden "P_BOUNDS" structure. Returns true on success
15376 and updates *FIELD, false if it fails to recognize an
15380 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
15381 int *bounds_offset
, struct field
*field
,
15382 struct dwarf2_cu
*cu
)
15384 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
15385 if (attr
== nullptr || !attr
->form_is_block ())
15388 const struct dwarf_block
*block
= attr
->as_block ();
15389 const gdb_byte
*start
= block
->data
;
15390 const gdb_byte
*end
= block
->data
+ block
->size
;
15392 /* The expression to recognize generally looks like:
15394 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
15395 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
15397 However, the second "plus_uconst" may be missing:
15399 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
15400 DW_OP_deref_size: 4)
15402 This happens when the field is at the start of the structure.
15404 Also, the final deref may not be sized:
15406 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
15409 This happens when the size of the index type happens to be the
15410 same as the architecture's word size. This can occur with or
15411 without the second plus_uconst. */
15413 if (end
- start
< 2)
15415 if (*start
++ != DW_OP_push_object_address
)
15417 if (*start
++ != DW_OP_plus_uconst
)
15420 uint64_t this_bound_off
;
15421 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
15422 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
15424 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
15425 is consistent among all bounds. */
15426 if (*bounds_offset
== -1)
15427 *bounds_offset
= this_bound_off
;
15428 else if (*bounds_offset
!= this_bound_off
)
15431 if (start
== end
|| *start
++ != DW_OP_deref
)
15437 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
15439 /* This means an offset of 0. */
15441 else if (*start
++ != DW_OP_plus_uconst
)
15445 /* The size is the parameter to DW_OP_plus_uconst. */
15447 start
= gdb_read_uleb128 (start
, end
, &val
);
15448 if (start
== nullptr)
15450 if ((int) val
!= val
)
15459 if (*start
== DW_OP_deref_size
)
15461 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
15462 if (start
== nullptr)
15465 else if (*start
== DW_OP_deref
)
15467 size
= cu
->header
.addr_size
;
15473 field
->set_loc_bitpos (8 * offset
);
15474 if (size
!= field
->type ()->length ())
15475 FIELD_BITSIZE (*field
) = 8 * size
;
15480 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
15481 some kinds of Ada arrays:
15483 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
15484 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
15485 <11e0> DW_AT_data_location: 2 byte block: 97 6
15486 (DW_OP_push_object_address; DW_OP_deref)
15487 <11e3> DW_AT_type : <0x1173>
15488 <11e7> DW_AT_sibling : <0x1201>
15489 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
15490 <11ec> DW_AT_type : <0x1206>
15491 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
15492 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
15493 DW_OP_deref_size: 4)
15494 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
15495 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
15496 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
15498 This actually represents a "thick pointer", which is a structure
15499 with two elements: one that is a pointer to the array data, and one
15500 that is a pointer to another structure; this second structure holds
15503 This returns a new type on success, or nullptr if this didn't
15504 recognize the type. */
15506 static struct type
*
15507 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
15510 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
15511 /* So far we've only seen this with block form. */
15512 if (attr
== nullptr || !attr
->form_is_block ())
15515 /* Note that this will fail if the structure layout is changed by
15516 the compiler. However, we have no good way to recognize some
15517 other layout, because we don't know what expression the compiler
15518 might choose to emit should this happen. */
15519 struct dwarf_block
*blk
= attr
->as_block ();
15521 || blk
->data
[0] != DW_OP_push_object_address
15522 || blk
->data
[1] != DW_OP_deref
)
15525 int bounds_offset
= -1;
15526 int max_align
= -1;
15527 std::vector
<struct field
> range_fields
;
15528 for (struct die_info
*child_die
= die
->child
;
15530 child_die
= child_die
->sibling
)
15532 if (child_die
->tag
== DW_TAG_subrange_type
)
15534 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
15536 int this_align
= type_align (underlying
);
15537 if (this_align
> max_align
)
15538 max_align
= this_align
;
15540 range_fields
.emplace_back ();
15541 range_fields
.emplace_back ();
15543 struct field
&lower
= range_fields
[range_fields
.size () - 2];
15544 struct field
&upper
= range_fields
[range_fields
.size () - 1];
15546 lower
.set_type (underlying
);
15547 FIELD_ARTIFICIAL (lower
) = 1;
15549 upper
.set_type (underlying
);
15550 FIELD_ARTIFICIAL (upper
) = 1;
15552 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
15553 &bounds_offset
, &lower
, cu
)
15554 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
15555 &bounds_offset
, &upper
, cu
))
15560 /* This shouldn't really happen, but double-check that we found
15561 where the bounds are stored. */
15562 if (bounds_offset
== -1)
15565 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15566 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
15570 /* Set the name of each field in the bounds. */
15571 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
15572 range_fields
[i
].set_name (objfile
->intern (name
));
15573 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
15574 range_fields
[i
+ 1].set_name (objfile
->intern (name
));
15577 struct type
*bounds
= alloc_type (objfile
);
15578 bounds
->set_code (TYPE_CODE_STRUCT
);
15580 bounds
->set_num_fields (range_fields
.size ());
15582 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
15583 * sizeof (struct field
))));
15584 memcpy (bounds
->fields (), range_fields
.data (),
15585 bounds
->num_fields () * sizeof (struct field
));
15587 int last_fieldno
= range_fields
.size () - 1;
15588 int bounds_size
= (bounds
->field (last_fieldno
).loc_bitpos () / 8
15589 + bounds
->field (last_fieldno
).type ()->length ());
15590 bounds
->set_length (align_up (bounds_size
, max_align
));
15592 /* Rewrite the existing array type in place. Specifically, we
15593 remove any dynamic properties we might have read, and we replace
15594 the index types. */
15595 struct type
*iter
= type
;
15596 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
15598 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
15599 iter
->main_type
->dyn_prop_list
= nullptr;
15600 iter
->set_index_type
15601 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
15602 iter
= iter
->target_type ();
15605 struct type
*result
= alloc_type (objfile
);
15606 result
->set_code (TYPE_CODE_STRUCT
);
15608 result
->set_num_fields (2);
15610 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
15611 * sizeof (struct field
))));
15613 /* The names are chosen to coincide with what the compiler does with
15614 -fgnat-encodings=all, which the Ada code in gdb already
15616 result
->field (0).set_name ("P_ARRAY");
15617 result
->field (0).set_type (lookup_pointer_type (type
));
15619 result
->field (1).set_name ("P_BOUNDS");
15620 result
->field (1).set_type (lookup_pointer_type (bounds
));
15621 result
->field (1).set_loc_bitpos (8 * bounds_offset
);
15623 result
->set_name (type
->name ());
15624 result
->set_length (result
->field (0).type ()->length ()
15625 + result
->field (1).type ()->length ());
15630 /* Extract all information from a DW_TAG_array_type DIE and put it in
15631 the DIE's type field. For now, this only handles one dimensional
15634 static struct type
*
15635 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15637 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15638 struct die_info
*child_die
;
15640 struct type
*element_type
, *range_type
, *index_type
;
15641 struct attribute
*attr
;
15643 struct dynamic_prop
*byte_stride_prop
= NULL
;
15644 unsigned int bit_stride
= 0;
15646 element_type
= die_type (die
, cu
);
15648 /* The die_type call above may have already set the type for this DIE. */
15649 type
= get_die_type (die
, cu
);
15653 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15657 struct type
*prop_type
= cu
->addr_sized_int_type (false);
15660 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15661 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15665 complaint (_("unable to read array DW_AT_byte_stride "
15666 " - DIE at %s [in module %s]"),
15667 sect_offset_str (die
->sect_off
),
15668 objfile_name (cu
->per_objfile
->objfile
));
15669 /* Ignore this attribute. We will likely not be able to print
15670 arrays of this type correctly, but there is little we can do
15671 to help if we cannot read the attribute's value. */
15672 byte_stride_prop
= NULL
;
15676 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15678 bit_stride
= attr
->constant_value (0);
15680 /* Irix 6.2 native cc creates array types without children for
15681 arrays with unspecified length. */
15682 if (die
->child
== NULL
)
15684 index_type
= objfile_type (objfile
)->builtin_int
;
15685 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15686 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15687 byte_stride_prop
, bit_stride
);
15688 return set_die_type (die
, type
, cu
);
15691 std::vector
<struct type
*> range_types
;
15692 child_die
= die
->child
;
15693 while (child_die
&& child_die
->tag
)
15695 if (child_die
->tag
== DW_TAG_subrange_type
15696 || child_die
->tag
== DW_TAG_generic_subrange
)
15698 struct type
*child_type
= read_type_die (child_die
, cu
);
15700 if (child_type
!= NULL
)
15702 /* The range type was succesfully read. Save it for the
15703 array type creation. */
15704 range_types
.push_back (child_type
);
15707 child_die
= child_die
->sibling
;
15710 if (range_types
.empty ())
15712 complaint (_("unable to find array range - DIE at %s [in module %s]"),
15713 sect_offset_str (die
->sect_off
),
15714 objfile_name (cu
->per_objfile
->objfile
));
15718 /* Dwarf2 dimensions are output from left to right, create the
15719 necessary array types in backwards order. */
15721 type
= element_type
;
15723 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15727 while (i
< range_types
.size ())
15729 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15730 byte_stride_prop
, bit_stride
);
15731 type
->set_is_multi_dimensional (true);
15733 byte_stride_prop
= nullptr;
15738 size_t ndim
= range_types
.size ();
15741 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15742 byte_stride_prop
, bit_stride
);
15743 type
->set_is_multi_dimensional (true);
15745 byte_stride_prop
= nullptr;
15749 /* Clear the flag on the outermost array type. */
15750 type
->set_is_multi_dimensional (false);
15751 gdb_assert (type
!= element_type
);
15753 /* Understand Dwarf2 support for vector types (like they occur on
15754 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15755 array type. This is not part of the Dwarf2/3 standard yet, but a
15756 custom vendor extension. The main difference between a regular
15757 array and the vector variant is that vectors are passed by value
15759 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15760 if (attr
!= nullptr)
15761 make_vector_type (type
);
15763 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15764 implementation may choose to implement triple vectors using this
15766 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15767 if (attr
!= nullptr && attr
->form_is_unsigned ())
15769 if (attr
->as_unsigned () >= type
->length ())
15770 type
->set_length (attr
->as_unsigned ());
15772 complaint (_("DW_AT_byte_size for array type smaller "
15773 "than the total size of elements"));
15776 name
= dwarf2_name (die
, cu
);
15778 type
->set_name (name
);
15780 maybe_set_alignment (cu
, die
, type
);
15782 struct type
*replacement_type
= nullptr;
15783 if (cu
->lang () == language_ada
)
15785 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
15786 if (replacement_type
!= nullptr)
15787 type
= replacement_type
;
15790 /* Install the type in the die. */
15791 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
15793 /* set_die_type should be already done. */
15794 set_descriptive_type (type
, die
, cu
);
15799 static enum dwarf_array_dim_ordering
15800 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15802 struct attribute
*attr
;
15804 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15806 if (attr
!= nullptr)
15808 LONGEST val
= attr
->constant_value (-1);
15809 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
15810 return (enum dwarf_array_dim_ordering
) val
;
15813 /* GNU F77 is a special case, as at 08/2004 array type info is the
15814 opposite order to the dwarf2 specification, but data is still
15815 laid out as per normal fortran.
15817 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15818 version checking. */
15820 if (cu
->lang () == language_fortran
15821 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15823 return DW_ORD_row_major
;
15826 switch (cu
->language_defn
->array_ordering ())
15828 case array_column_major
:
15829 return DW_ORD_col_major
;
15830 case array_row_major
:
15832 return DW_ORD_row_major
;
15836 /* Extract all information from a DW_TAG_set_type DIE and put it in
15837 the DIE's type field. */
15839 static struct type
*
15840 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15842 struct type
*domain_type
, *set_type
;
15843 struct attribute
*attr
;
15845 domain_type
= die_type (die
, cu
);
15847 /* The die_type call above may have already set the type for this DIE. */
15848 set_type
= get_die_type (die
, cu
);
15852 set_type
= create_set_type (NULL
, domain_type
);
15854 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15855 if (attr
!= nullptr && attr
->form_is_unsigned ())
15856 set_type
->set_length (attr
->as_unsigned ());
15858 maybe_set_alignment (cu
, die
, set_type
);
15860 return set_die_type (die
, set_type
, cu
);
15863 /* A helper for read_common_block that creates a locexpr baton.
15864 SYM is the symbol which we are marking as computed.
15865 COMMON_DIE is the DIE for the common block.
15866 COMMON_LOC is the location expression attribute for the common
15868 MEMBER_LOC is the location expression attribute for the particular
15869 member of the common block that we are processing.
15870 CU is the CU from which the above come. */
15873 mark_common_block_symbol_computed (struct symbol
*sym
,
15874 struct die_info
*common_die
,
15875 struct attribute
*common_loc
,
15876 struct attribute
*member_loc
,
15877 struct dwarf2_cu
*cu
)
15879 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
15880 struct objfile
*objfile
= per_objfile
->objfile
;
15881 struct dwarf2_locexpr_baton
*baton
;
15883 unsigned int cu_off
;
15884 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
15885 LONGEST offset
= 0;
15887 gdb_assert (common_loc
&& member_loc
);
15888 gdb_assert (common_loc
->form_is_block ());
15889 gdb_assert (member_loc
->form_is_block ()
15890 || member_loc
->form_is_constant ());
15892 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15893 baton
->per_objfile
= per_objfile
;
15894 baton
->per_cu
= cu
->per_cu
;
15895 gdb_assert (baton
->per_cu
);
15897 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15899 if (member_loc
->form_is_constant ())
15901 offset
= member_loc
->constant_value (0);
15902 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15905 baton
->size
+= member_loc
->as_block ()->size
;
15907 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15910 *ptr
++ = DW_OP_call4
;
15911 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15912 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15915 if (member_loc
->form_is_constant ())
15917 *ptr
++ = DW_OP_addr
;
15918 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15919 ptr
+= cu
->header
.addr_size
;
15923 /* We have to copy the data here, because DW_OP_call4 will only
15924 use a DW_AT_location attribute. */
15925 struct dwarf_block
*block
= member_loc
->as_block ();
15926 memcpy (ptr
, block
->data
, block
->size
);
15927 ptr
+= block
->size
;
15930 *ptr
++ = DW_OP_plus
;
15931 gdb_assert (ptr
- baton
->data
== baton
->size
);
15933 SYMBOL_LOCATION_BATON (sym
) = baton
;
15934 sym
->set_aclass_index (dwarf2_locexpr_index
);
15937 /* Create appropriate locally-scoped variables for all the
15938 DW_TAG_common_block entries. Also create a struct common_block
15939 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15940 is used to separate the common blocks name namespace from regular
15944 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15946 struct attribute
*attr
;
15948 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15949 if (attr
!= nullptr)
15951 /* Support the .debug_loc offsets. */
15952 if (attr
->form_is_block ())
15956 else if (attr
->form_is_section_offset ())
15958 dwarf2_complex_location_expr_complaint ();
15963 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15964 "common block member");
15969 if (die
->child
!= NULL
)
15971 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15972 struct die_info
*child_die
;
15973 size_t n_entries
= 0, size
;
15974 struct common_block
*common_block
;
15975 struct symbol
*sym
;
15977 for (child_die
= die
->child
;
15978 child_die
&& child_die
->tag
;
15979 child_die
= child_die
->sibling
)
15982 size
= (sizeof (struct common_block
)
15983 + (n_entries
- 1) * sizeof (struct symbol
*));
15985 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
15987 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
15988 common_block
->n_entries
= 0;
15990 for (child_die
= die
->child
;
15991 child_die
&& child_die
->tag
;
15992 child_die
= child_die
->sibling
)
15994 /* Create the symbol in the DW_TAG_common_block block in the current
15996 sym
= new_symbol (child_die
, NULL
, cu
);
15999 struct attribute
*member_loc
;
16001 common_block
->contents
[common_block
->n_entries
++] = sym
;
16003 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16007 /* GDB has handled this for a long time, but it is
16008 not specified by DWARF. It seems to have been
16009 emitted by gfortran at least as recently as:
16010 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16011 complaint (_("Variable in common block has "
16012 "DW_AT_data_member_location "
16013 "- DIE at %s [in module %s]"),
16014 sect_offset_str (child_die
->sect_off
),
16015 objfile_name (objfile
));
16017 if (member_loc
->form_is_section_offset ())
16018 dwarf2_complex_location_expr_complaint ();
16019 else if (member_loc
->form_is_constant ()
16020 || member_loc
->form_is_block ())
16022 if (attr
!= nullptr)
16023 mark_common_block_symbol_computed (sym
, die
, attr
,
16027 dwarf2_complex_location_expr_complaint ();
16032 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16033 sym
->set_value_common_block (common_block
);
16037 /* Create a type for a C++ namespace. */
16039 static struct type
*
16040 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16042 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16043 const char *previous_prefix
, *name
;
16047 /* For extensions, reuse the type of the original namespace. */
16048 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16050 struct die_info
*ext_die
;
16051 struct dwarf2_cu
*ext_cu
= cu
;
16053 ext_die
= dwarf2_extension (die
, &ext_cu
);
16054 type
= read_type_die (ext_die
, ext_cu
);
16056 /* EXT_CU may not be the same as CU.
16057 Ensure TYPE is recorded with CU in die_type_hash. */
16058 return set_die_type (die
, type
, cu
);
16061 name
= namespace_name (die
, &is_anonymous
, cu
);
16063 /* Now build the name of the current namespace. */
16065 previous_prefix
= determine_prefix (die
, cu
);
16066 if (previous_prefix
[0] != '\0')
16067 name
= typename_concat (&objfile
->objfile_obstack
,
16068 previous_prefix
, name
, 0, cu
);
16070 /* Create the type. */
16071 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16073 return set_die_type (die
, type
, cu
);
16076 /* Read a namespace scope. */
16079 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16081 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16084 /* Add a symbol associated to this if we haven't seen the namespace
16085 before. Also, add a using directive if it's an anonymous
16088 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16092 type
= read_type_die (die
, cu
);
16093 new_symbol (die
, type
, cu
);
16095 namespace_name (die
, &is_anonymous
, cu
);
16098 const char *previous_prefix
= determine_prefix (die
, cu
);
16100 std::vector
<const char *> excludes
;
16101 add_using_directive (using_directives (cu
),
16102 previous_prefix
, type
->name (), NULL
,
16104 read_decl_line (die
, cu
),
16105 0, &objfile
->objfile_obstack
);
16109 if (die
->child
!= NULL
)
16111 struct die_info
*child_die
= die
->child
;
16113 while (child_die
&& child_die
->tag
)
16115 process_die (child_die
, cu
);
16116 child_die
= child_die
->sibling
;
16121 /* Read a Fortran module as type. This DIE can be only a declaration used for
16122 imported module. Still we need that type as local Fortran "use ... only"
16123 declaration imports depend on the created type in determine_prefix. */
16125 static struct type
*
16126 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16128 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16129 const char *module_name
;
16132 module_name
= dwarf2_name (die
, cu
);
16133 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16135 return set_die_type (die
, type
, cu
);
16138 /* Read a Fortran module. */
16141 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16143 struct die_info
*child_die
= die
->child
;
16146 type
= read_type_die (die
, cu
);
16147 new_symbol (die
, type
, cu
);
16149 while (child_die
&& child_die
->tag
)
16151 process_die (child_die
, cu
);
16152 child_die
= child_die
->sibling
;
16156 /* Return the name of the namespace represented by DIE. Set
16157 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16160 static const char *
16161 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16163 struct die_info
*current_die
;
16164 const char *name
= NULL
;
16166 /* Loop through the extensions until we find a name. */
16168 for (current_die
= die
;
16169 current_die
!= NULL
;
16170 current_die
= dwarf2_extension (die
, &cu
))
16172 /* We don't use dwarf2_name here so that we can detect the absence
16173 of a name -> anonymous namespace. */
16174 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16180 /* Is it an anonymous namespace? */
16182 *is_anonymous
= (name
== NULL
);
16184 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16189 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16190 the user defined type vector. */
16192 static struct type
*
16193 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16195 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16196 struct comp_unit_head
*cu_header
= &cu
->header
;
16198 struct attribute
*attr_byte_size
;
16199 struct attribute
*attr_address_class
;
16200 int byte_size
, addr_class
;
16201 struct type
*target_type
;
16203 target_type
= die_type (die
, cu
);
16205 /* The die_type call above may have already set the type for this DIE. */
16206 type
= get_die_type (die
, cu
);
16210 type
= lookup_pointer_type (target_type
);
16212 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16213 if (attr_byte_size
)
16214 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
16216 byte_size
= cu_header
->addr_size
;
16218 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16219 if (attr_address_class
)
16220 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
16222 addr_class
= DW_ADDR_none
;
16224 ULONGEST alignment
= get_alignment (cu
, die
);
16226 /* If the pointer size, alignment, or address class is different
16227 than the default, create a type variant marked as such and set
16228 the length accordingly. */
16229 if (type
->length () != byte_size
16230 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16231 && alignment
!= TYPE_RAW_ALIGN (type
))
16232 || addr_class
!= DW_ADDR_none
)
16234 if (gdbarch_address_class_type_flags_p (gdbarch
))
16236 type_instance_flags type_flags
16237 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
16239 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16241 type
= make_type_with_address_space (type
, type_flags
);
16243 else if (type
->length () != byte_size
)
16245 complaint (_("invalid pointer size %d"), byte_size
);
16247 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16249 complaint (_("Invalid DW_AT_alignment"
16250 " - DIE at %s [in module %s]"),
16251 sect_offset_str (die
->sect_off
),
16252 objfile_name (cu
->per_objfile
->objfile
));
16256 /* Should we also complain about unhandled address classes? */
16260 type
->set_length (byte_size
);
16261 set_type_align (type
, alignment
);
16262 return set_die_type (die
, type
, cu
);
16265 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16266 the user defined type vector. */
16268 static struct type
*
16269 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16272 struct type
*to_type
;
16273 struct type
*domain
;
16275 to_type
= die_type (die
, cu
);
16276 domain
= die_containing_type (die
, cu
);
16278 /* The calls above may have already set the type for this DIE. */
16279 type
= get_die_type (die
, cu
);
16283 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16284 type
= lookup_methodptr_type (to_type
);
16285 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16287 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16289 smash_to_method_type (new_type
, domain
, to_type
->target_type (),
16290 to_type
->fields (), to_type
->num_fields (),
16291 to_type
->has_varargs ());
16292 type
= lookup_methodptr_type (new_type
);
16295 type
= lookup_memberptr_type (to_type
, domain
);
16297 return set_die_type (die
, type
, cu
);
16300 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16301 the user defined type vector. */
16303 static struct type
*
16304 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16305 enum type_code refcode
)
16307 struct comp_unit_head
*cu_header
= &cu
->header
;
16308 struct type
*type
, *target_type
;
16309 struct attribute
*attr
;
16311 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16313 target_type
= die_type (die
, cu
);
16315 /* The die_type call above may have already set the type for this DIE. */
16316 type
= get_die_type (die
, cu
);
16320 type
= lookup_reference_type (target_type
, refcode
);
16321 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16322 if (attr
!= nullptr)
16323 type
->set_length (attr
->constant_value (cu_header
->addr_size
));
16325 type
->set_length (cu_header
->addr_size
);
16327 maybe_set_alignment (cu
, die
, type
);
16328 return set_die_type (die
, type
, cu
);
16331 /* Add the given cv-qualifiers to the element type of the array. GCC
16332 outputs DWARF type qualifiers that apply to an array, not the
16333 element type. But GDB relies on the array element type to carry
16334 the cv-qualifiers. This mimics section 6.7.3 of the C99
16337 static struct type
*
16338 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16339 struct type
*base_type
, int cnst
, int voltl
)
16341 struct type
*el_type
, *inner_array
;
16343 base_type
= copy_type (base_type
);
16344 inner_array
= base_type
;
16346 while (inner_array
->target_type ()->code () == TYPE_CODE_ARRAY
)
16348 inner_array
->set_target_type (copy_type (inner_array
->target_type ()));
16349 inner_array
= inner_array
->target_type ();
16352 el_type
= inner_array
->target_type ();
16353 cnst
|= TYPE_CONST (el_type
);
16354 voltl
|= TYPE_VOLATILE (el_type
);
16355 inner_array
->set_target_type (make_cv_type (cnst
, voltl
, el_type
, NULL
));
16357 return set_die_type (die
, base_type
, cu
);
16360 static struct type
*
16361 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16363 struct type
*base_type
, *cv_type
;
16365 base_type
= die_type (die
, cu
);
16367 /* The die_type call above may have already set the type for this DIE. */
16368 cv_type
= get_die_type (die
, cu
);
16372 /* In case the const qualifier is applied to an array type, the element type
16373 is so qualified, not the array type (section 6.7.3 of C99). */
16374 if (base_type
->code () == TYPE_CODE_ARRAY
)
16375 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16377 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16378 return set_die_type (die
, cv_type
, cu
);
16381 static struct type
*
16382 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16384 struct type
*base_type
, *cv_type
;
16386 base_type
= die_type (die
, cu
);
16388 /* The die_type call above may have already set the type for this DIE. */
16389 cv_type
= get_die_type (die
, cu
);
16393 /* In case the volatile qualifier is applied to an array type, the
16394 element type is so qualified, not the array type (section 6.7.3
16396 if (base_type
->code () == TYPE_CODE_ARRAY
)
16397 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16399 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16400 return set_die_type (die
, cv_type
, cu
);
16403 /* Handle DW_TAG_restrict_type. */
16405 static struct type
*
16406 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16408 struct type
*base_type
, *cv_type
;
16410 base_type
= die_type (die
, cu
);
16412 /* The die_type call above may have already set the type for this DIE. */
16413 cv_type
= get_die_type (die
, cu
);
16417 cv_type
= make_restrict_type (base_type
);
16418 return set_die_type (die
, cv_type
, cu
);
16421 /* Handle DW_TAG_atomic_type. */
16423 static struct type
*
16424 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16426 struct type
*base_type
, *cv_type
;
16428 base_type
= die_type (die
, cu
);
16430 /* The die_type call above may have already set the type for this DIE. */
16431 cv_type
= get_die_type (die
, cu
);
16435 cv_type
= make_atomic_type (base_type
);
16436 return set_die_type (die
, cv_type
, cu
);
16439 /* Extract all information from a DW_TAG_string_type DIE and add to
16440 the user defined type vector. It isn't really a user defined type,
16441 but it behaves like one, with other DIE's using an AT_user_def_type
16442 attribute to reference it. */
16444 static struct type
*
16445 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16447 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16448 struct gdbarch
*gdbarch
= objfile
->arch ();
16449 struct type
*type
, *range_type
, *index_type
, *char_type
;
16450 struct attribute
*attr
;
16451 struct dynamic_prop prop
;
16452 bool length_is_constant
= true;
16455 /* There are a couple of places where bit sizes might be made use of
16456 when parsing a DW_TAG_string_type, however, no producer that we know
16457 of make use of these. Handling bit sizes that are a multiple of the
16458 byte size is easy enough, but what about other bit sizes? Lets deal
16459 with that problem when we have to. Warn about these attributes being
16460 unsupported, then parse the type and ignore them like we always
16462 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16463 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16465 static bool warning_printed
= false;
16466 if (!warning_printed
)
16468 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16469 "currently supported on DW_TAG_string_type."));
16470 warning_printed
= true;
16474 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16475 if (attr
!= nullptr && !attr
->form_is_constant ())
16477 /* The string length describes the location at which the length of
16478 the string can be found. The size of the length field can be
16479 specified with one of the attributes below. */
16480 struct type
*prop_type
;
16481 struct attribute
*len
16482 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16483 if (len
== nullptr)
16484 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16485 if (len
!= nullptr && len
->form_is_constant ())
16487 /* Pass 0 as the default as we know this attribute is constant
16488 and the default value will not be returned. */
16489 LONGEST sz
= len
->constant_value (0);
16490 prop_type
= objfile_int_type (objfile
, sz
, true);
16494 /* If the size is not specified then we assume it is the size of
16495 an address on this target. */
16496 prop_type
= cu
->addr_sized_int_type (true);
16499 /* Convert the attribute into a dynamic property. */
16500 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16503 length_is_constant
= false;
16505 else if (attr
!= nullptr)
16507 /* This DW_AT_string_length just contains the length with no
16508 indirection. There's no need to create a dynamic property in this
16509 case. Pass 0 for the default value as we know it will not be
16510 returned in this case. */
16511 length
= attr
->constant_value (0);
16513 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16515 /* We don't currently support non-constant byte sizes for strings. */
16516 length
= attr
->constant_value (1);
16520 /* Use 1 as a fallback length if we have nothing else. */
16524 index_type
= objfile_type (objfile
)->builtin_int
;
16525 if (length_is_constant
)
16526 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16529 struct dynamic_prop low_bound
;
16531 low_bound
.set_const_val (1);
16532 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16534 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16535 type
= create_string_type (NULL
, char_type
, range_type
);
16537 return set_die_type (die
, type
, cu
);
16540 /* Assuming that DIE corresponds to a function, returns nonzero
16541 if the function is prototyped. */
16544 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16546 struct attribute
*attr
;
16548 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16549 if (attr
&& attr
->as_boolean ())
16552 /* The DWARF standard implies that the DW_AT_prototyped attribute
16553 is only meaningful for C, but the concept also extends to other
16554 languages that allow unprototyped functions (Eg: Objective C).
16555 For all other languages, assume that functions are always
16557 if (cu
->lang () != language_c
16558 && cu
->lang () != language_objc
16559 && cu
->lang () != language_opencl
)
16562 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16563 prototyped and unprototyped functions; default to prototyped,
16564 since that is more common in modern code (and RealView warns
16565 about unprototyped functions). */
16566 if (producer_is_realview (cu
->producer
))
16572 /* Handle DIES due to C code like:
16576 int (*funcp)(int a, long l);
16580 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16582 static struct type
*
16583 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16585 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16586 struct type
*type
; /* Type that this function returns. */
16587 struct type
*ftype
; /* Function that returns above type. */
16588 struct attribute
*attr
;
16590 type
= die_type (die
, cu
);
16592 /* The die_type call above may have already set the type for this DIE. */
16593 ftype
= get_die_type (die
, cu
);
16597 ftype
= lookup_function_type (type
);
16599 if (prototyped_function_p (die
, cu
))
16600 ftype
->set_is_prototyped (true);
16602 /* Store the calling convention in the type if it's available in
16603 the subroutine die. Otherwise set the calling convention to
16604 the default value DW_CC_normal. */
16605 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16606 if (attr
!= nullptr
16607 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
16608 TYPE_CALLING_CONVENTION (ftype
)
16609 = (enum dwarf_calling_convention
) attr
->constant_value (0);
16610 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16611 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16613 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16615 /* Record whether the function returns normally to its caller or not
16616 if the DWARF producer set that information. */
16617 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16618 if (attr
&& attr
->as_boolean ())
16619 TYPE_NO_RETURN (ftype
) = 1;
16621 /* We need to add the subroutine type to the die immediately so
16622 we don't infinitely recurse when dealing with parameters
16623 declared as the same subroutine type. */
16624 set_die_type (die
, ftype
, cu
);
16626 if (die
->child
!= NULL
)
16628 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16629 struct die_info
*child_die
;
16630 int nparams
, iparams
;
16632 /* Count the number of parameters.
16633 FIXME: GDB currently ignores vararg functions, but knows about
16634 vararg member functions. */
16636 child_die
= die
->child
;
16637 while (child_die
&& child_die
->tag
)
16639 if (child_die
->tag
== DW_TAG_formal_parameter
)
16641 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16642 ftype
->set_has_varargs (true);
16644 child_die
= child_die
->sibling
;
16647 /* Allocate storage for parameters and fill them in. */
16648 ftype
->set_num_fields (nparams
);
16650 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
16652 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16653 even if we error out during the parameters reading below. */
16654 for (iparams
= 0; iparams
< nparams
; iparams
++)
16655 ftype
->field (iparams
).set_type (void_type
);
16658 child_die
= die
->child
;
16659 while (child_die
&& child_die
->tag
)
16661 if (child_die
->tag
== DW_TAG_formal_parameter
)
16663 struct type
*arg_type
;
16665 /* DWARF version 2 has no clean way to discern C++
16666 static and non-static member functions. G++ helps
16667 GDB by marking the first parameter for non-static
16668 member functions (which is the this pointer) as
16669 artificial. We pass this information to
16670 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16672 DWARF version 3 added DW_AT_object_pointer, which GCC
16673 4.5 does not yet generate. */
16674 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16675 if (attr
!= nullptr)
16676 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
16678 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16679 arg_type
= die_type (child_die
, cu
);
16681 /* RealView does not mark THIS as const, which the testsuite
16682 expects. GCC marks THIS as const in method definitions,
16683 but not in the class specifications (GCC PR 43053). */
16684 if (cu
->lang () == language_cplus
16685 && !TYPE_CONST (arg_type
)
16686 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16689 struct dwarf2_cu
*arg_cu
= cu
;
16690 const char *name
= dwarf2_name (child_die
, cu
);
16692 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16693 if (attr
!= nullptr)
16695 /* If the compiler emits this, use it. */
16696 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16699 else if (name
&& strcmp (name
, "this") == 0)
16700 /* Function definitions will have the argument names. */
16702 else if (name
== NULL
&& iparams
== 0)
16703 /* Declarations may not have the names, so like
16704 elsewhere in GDB, assume an artificial first
16705 argument is "this". */
16709 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16713 ftype
->field (iparams
).set_type (arg_type
);
16716 child_die
= child_die
->sibling
;
16723 static struct type
*
16724 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16726 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16727 const char *name
= NULL
;
16728 struct type
*this_type
, *target_type
;
16730 name
= dwarf2_full_name (NULL
, die
, cu
);
16731 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16732 this_type
->set_target_is_stub (true);
16733 set_die_type (die
, this_type
, cu
);
16734 target_type
= die_type (die
, cu
);
16735 if (target_type
!= this_type
)
16736 this_type
->set_target_type (target_type
);
16739 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16740 spec and cause infinite loops in GDB. */
16741 complaint (_("Self-referential DW_TAG_typedef "
16742 "- DIE at %s [in module %s]"),
16743 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16744 this_type
->set_target_type (nullptr);
16748 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16749 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16750 Handle these by just returning the target type, rather than
16751 constructing an anonymous typedef type and trying to handle this
16753 set_die_type (die
, target_type
, cu
);
16754 return target_type
;
16759 /* Helper for get_dwarf2_rational_constant that computes the value of
16760 a given gmp_mpz given an attribute. */
16763 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
16765 /* GCC will sometimes emit a 16-byte constant value as a DWARF
16766 location expression that pushes an implicit value. */
16767 if (attr
->form
== DW_FORM_exprloc
)
16769 dwarf_block
*blk
= attr
->as_block ();
16770 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
16773 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
16774 blk
->data
+ blk
->size
,
16776 if (ptr
- blk
->data
+ len
<= blk
->size
)
16778 mpz_import (value
->val
, len
,
16779 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
.get ())
16786 /* On failure set it to 1. */
16787 *value
= gdb_mpz (1);
16789 else if (attr
->form_is_block ())
16791 dwarf_block
*blk
= attr
->as_block ();
16792 mpz_import (value
->val
, blk
->size
,
16793 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
.get ())
16795 1, 0, 0, blk
->data
);
16798 *value
= gdb_mpz (attr
->constant_value (1));
16801 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
16802 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
16804 If the numerator and/or numerator attribute is missing,
16805 a complaint is filed, and NUMERATOR and DENOMINATOR are left
16809 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
16810 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
16812 struct attribute
*num_attr
, *denom_attr
;
16814 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
16815 if (num_attr
== nullptr)
16816 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
16817 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
16819 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
16820 if (denom_attr
== nullptr)
16821 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
16822 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
16824 if (num_attr
== nullptr || denom_attr
== nullptr)
16827 get_mpz (cu
, numerator
, num_attr
);
16828 get_mpz (cu
, denominator
, denom_attr
);
16831 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
16832 rational constant, rather than a signed one.
16834 If the rational constant has a negative value, a complaint
16835 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
16838 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
16839 struct dwarf2_cu
*cu
,
16840 gdb_mpz
*numerator
,
16841 gdb_mpz
*denominator
)
16846 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
16847 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
16849 mpz_neg (num
.val
, num
.val
);
16850 mpz_neg (denom
.val
, denom
.val
);
16852 else if (mpz_sgn (num
.val
) == -1)
16854 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
16856 sect_offset_str (die
->sect_off
));
16859 else if (mpz_sgn (denom
.val
) == -1)
16861 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
16863 sect_offset_str (die
->sect_off
));
16867 *numerator
= std::move (num
);
16868 *denominator
= std::move (denom
);
16871 /* Assuming that ENCODING is a string whose contents starting at the
16872 K'th character is "_nn" where "nn" is a decimal number, scan that
16873 number and set RESULT to the value. K is updated to point to the
16874 character immediately following the number.
16876 If the string does not conform to the format described above, false
16877 is returned, and K may or may not be changed. */
16880 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
16882 /* The next character should be an underscore ('_') followed
16884 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
16887 /* Skip the underscore. */
16891 /* Determine the number of digits for our number. */
16892 while (isdigit (encoding
[k
]))
16897 std::string
copy (&encoding
[start
], k
- start
);
16898 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
16904 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
16905 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
16906 DENOM, update OFFSET, and return true on success. Return false on
16910 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
16911 gdb_mpz
*num
, gdb_mpz
*denom
)
16913 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
16915 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
16918 /* Assuming DIE corresponds to a fixed point type, finish the creation
16919 of the corresponding TYPE by setting its type-specific data. CU is
16920 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
16921 encodings. It is nullptr if the GNAT encoding should be
16925 finish_fixed_point_type (struct type
*type
, const char *suffix
,
16926 struct die_info
*die
, struct dwarf2_cu
*cu
)
16928 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
16929 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
16931 /* If GNAT encodings are preferred, don't examine the
16933 struct attribute
*attr
= nullptr;
16934 if (suffix
== nullptr)
16936 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
16937 if (attr
== nullptr)
16938 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
16939 if (attr
== nullptr)
16940 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
16943 /* Numerator and denominator of our fixed-point type's scaling factor.
16944 The default is a scaling factor of 1, which we use as a fallback
16945 when we are not able to decode it (problem with the debugging info,
16946 unsupported forms, bug in GDB, etc...). Using that as the default
16947 allows us to at least print the unscaled value, which might still
16948 be useful to a user. */
16949 gdb_mpz
scale_num (1);
16950 gdb_mpz
scale_denom (1);
16952 if (attr
== nullptr)
16955 if (suffix
!= nullptr
16956 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
16958 /* The number might be encoded as _nn_dd_nn_dd, where the
16959 second ratio is the 'small value. In this situation, we
16960 want the second value. */
16961 && (suffix
[offset
] != '_'
16962 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
16969 /* Scaling factor not found. Assume a scaling factor of 1,
16970 and hope for the best. At least the user will be able to
16971 see the encoded value. */
16974 complaint (_("no scale found for fixed-point type (DIE at %s)"),
16975 sect_offset_str (die
->sect_off
));
16978 else if (attr
->name
== DW_AT_binary_scale
)
16980 LONGEST scale_exp
= attr
->constant_value (0);
16981 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
16983 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
16985 else if (attr
->name
== DW_AT_decimal_scale
)
16987 LONGEST scale_exp
= attr
->constant_value (0);
16988 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
16990 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
16992 else if (attr
->name
== DW_AT_small
)
16994 struct die_info
*scale_die
;
16995 struct dwarf2_cu
*scale_cu
= cu
;
16997 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
16998 if (scale_die
->tag
== DW_TAG_constant
)
16999 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17000 &scale_num
, &scale_denom
);
17002 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17004 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17008 complaint (_("unsupported scale attribute %s for fixed-point type"
17010 dwarf_attr_name (attr
->name
),
17011 sect_offset_str (die
->sect_off
));
17014 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17015 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17016 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17017 mpq_canonicalize (scaling_factor
.val
);
17020 /* The gnat-encoding suffix for fixed point. */
17022 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17024 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17025 "XF" suffix of the name. The text after this is what encodes the
17026 'small and 'delta information. Otherwise, return nullptr. */
17028 static const char *
17029 gnat_encoded_fixed_point_type_info (const char *name
)
17031 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17034 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17035 (which may be different from NAME) to the architecture back-end to allow
17036 it to guess the correct format if necessary. */
17038 static struct type
*
17039 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17040 const char *name_hint
, enum bfd_endian byte_order
)
17042 struct gdbarch
*gdbarch
= objfile
->arch ();
17043 const struct floatformat
**format
;
17046 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17048 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17050 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17055 /* Allocate an integer type of size BITS and name NAME. */
17057 static struct type
*
17058 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17059 int bits
, int unsigned_p
, const char *name
)
17063 /* Versions of Intel's C Compiler generate an integer type called "void"
17064 instead of using DW_TAG_unspecified_type. This has been seen on
17065 at least versions 14, 17, and 18. */
17066 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17067 && strcmp (name
, "void") == 0)
17068 type
= objfile_type (objfile
)->builtin_void
;
17070 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17075 /* Return true if DIE has a DW_AT_small attribute whose value is
17076 a constant rational, where both the numerator and denominator
17079 CU is the DIE's Compilation Unit. */
17082 has_zero_over_zero_small_attribute (struct die_info
*die
,
17083 struct dwarf2_cu
*cu
)
17085 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17086 if (attr
== nullptr)
17089 struct dwarf2_cu
*scale_cu
= cu
;
17090 struct die_info
*scale_die
17091 = follow_die_ref (die
, attr
, &scale_cu
);
17093 if (scale_die
->tag
!= DW_TAG_constant
)
17096 gdb_mpz
num (1), denom (1);
17097 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
17098 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
17101 /* Initialise and return a floating point type of size BITS suitable for
17102 use as a component of a complex number. The NAME_HINT is passed through
17103 when initialising the floating point type and is the name of the complex
17106 As DWARF doesn't currently provide an explicit name for the components
17107 of a complex number, but it can be helpful to have these components
17108 named, we try to select a suitable name based on the size of the
17110 static struct type
*
17111 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17112 struct objfile
*objfile
,
17113 int bits
, const char *name_hint
,
17114 enum bfd_endian byte_order
)
17116 gdbarch
*gdbarch
= objfile
->arch ();
17117 struct type
*tt
= nullptr;
17119 /* Try to find a suitable floating point builtin type of size BITS.
17120 We're going to use the name of this type as the name for the complex
17121 target type that we are about to create. */
17122 switch (cu
->lang ())
17124 case language_fortran
:
17128 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17131 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17133 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17135 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17143 tt
= builtin_type (gdbarch
)->builtin_float
;
17146 tt
= builtin_type (gdbarch
)->builtin_double
;
17148 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17150 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17156 /* If the type we found doesn't match the size we were looking for, then
17157 pretend we didn't find a type at all, the complex target type we
17158 create will then be nameless. */
17159 if (tt
!= nullptr && tt
->length () * TARGET_CHAR_BIT
!= bits
)
17162 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17163 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17166 /* Find a representation of a given base type and install
17167 it in the TYPE field of the die. */
17169 static struct type
*
17170 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17172 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17174 struct attribute
*attr
;
17175 int encoding
= 0, bits
= 0;
17179 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17180 if (attr
!= nullptr && attr
->form_is_constant ())
17181 encoding
= attr
->constant_value (0);
17182 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17183 if (attr
!= nullptr)
17184 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
17185 name
= dwarf2_name (die
, cu
);
17187 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17189 arch
= objfile
->arch ();
17190 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17192 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17193 if (attr
!= nullptr && attr
->form_is_constant ())
17195 int endianity
= attr
->constant_value (0);
17200 byte_order
= BFD_ENDIAN_BIG
;
17202 case DW_END_little
:
17203 byte_order
= BFD_ENDIAN_LITTLE
;
17206 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17211 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
17212 && cu
->lang () == language_ada
17213 && has_zero_over_zero_small_attribute (die
, cu
))
17215 /* brobecker/2018-02-24: This is a fixed point type for which
17216 the scaling factor is represented as fraction whose value
17217 does not make sense (zero divided by zero), so we should
17218 normally never see these. However, there is a small category
17219 of fixed point types for which GNAT is unable to provide
17220 the scaling factor via the standard DWARF mechanisms, and
17221 for which the info is provided via the GNAT encodings instead.
17222 This is likely what this DIE is about. */
17223 encoding
= (encoding
== DW_ATE_signed_fixed
17225 : DW_ATE_unsigned
);
17228 /* With GNAT encodings, fixed-point information will be encoded in
17229 the type name. Note that this can also occur with the above
17230 zero-over-zero case, which is why this is a separate "if" rather
17231 than an "else if". */
17232 const char *gnat_encoding_suffix
= nullptr;
17233 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
17234 && cu
->lang () == language_ada
17235 && name
!= nullptr)
17237 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
17238 if (gnat_encoding_suffix
!= nullptr)
17240 gdb_assert (startswith (gnat_encoding_suffix
,
17241 GNAT_FIXED_POINT_SUFFIX
));
17242 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
17243 name
, gnat_encoding_suffix
- name
);
17244 /* Use -1 here so that SUFFIX points at the "_" after the
17246 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
17248 encoding
= (encoding
== DW_ATE_signed
17249 ? DW_ATE_signed_fixed
17250 : DW_ATE_unsigned_fixed
);
17256 case DW_ATE_address
:
17257 /* Turn DW_ATE_address into a void * pointer. */
17258 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17259 type
= init_pointer_type (objfile
, bits
, name
, type
);
17261 case DW_ATE_boolean
:
17262 type
= init_boolean_type (objfile
, bits
, 1, name
);
17264 case DW_ATE_complex_float
:
17265 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17267 if (type
->code () == TYPE_CODE_ERROR
)
17269 if (name
== nullptr)
17271 struct obstack
*obstack
17272 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17273 name
= obconcat (obstack
, "_Complex ", type
->name (),
17276 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17279 type
= init_complex_type (name
, type
);
17281 case DW_ATE_decimal_float
:
17282 type
= init_decfloat_type (objfile
, bits
, name
);
17285 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17287 case DW_ATE_signed
:
17288 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17290 case DW_ATE_unsigned
:
17291 if (cu
->lang () == language_fortran
17293 && startswith (name
, "character("))
17294 type
= init_character_type (objfile
, bits
, 1, name
);
17296 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17298 case DW_ATE_signed_char
:
17299 if (cu
->lang () == language_ada
17300 || cu
->lang () == language_m2
17301 || cu
->lang () == language_pascal
17302 || cu
->lang () == language_fortran
)
17303 type
= init_character_type (objfile
, bits
, 0, name
);
17305 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17307 case DW_ATE_unsigned_char
:
17308 if (cu
->lang () == language_ada
17309 || cu
->lang () == language_m2
17310 || cu
->lang () == language_pascal
17311 || cu
->lang () == language_fortran
17312 || cu
->lang () == language_rust
)
17313 type
= init_character_type (objfile
, bits
, 1, name
);
17315 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17319 type
= init_character_type (objfile
, bits
, 1, name
);
17320 return set_die_type (die
, type
, cu
);
17323 case DW_ATE_signed_fixed
:
17324 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
17325 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
17327 case DW_ATE_unsigned_fixed
:
17328 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
17329 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
17333 complaint (_("unsupported DW_AT_encoding: '%s'"),
17334 dwarf_type_encoding_name (encoding
));
17335 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17339 if (type
->code () == TYPE_CODE_INT
17341 && strcmp (name
, "char") == 0)
17342 type
->set_has_no_signedness (true);
17344 maybe_set_alignment (cu
, die
, type
);
17346 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
17348 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
17350 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
17351 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * type
->length ())
17353 unsigned real_bit_size
= attr
->as_unsigned ();
17354 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
17355 /* Only use the attributes if they make sense together. */
17356 if (attr
== nullptr
17357 || (attr
->as_unsigned () + real_bit_size
17358 <= 8 * type
->length ()))
17360 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
17362 if (attr
!= nullptr)
17363 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
17364 = attr
->as_unsigned ();
17369 return set_die_type (die
, type
, cu
);
17372 /* A helper function that returns the name of DIE, if it refers to a
17373 variable declaration. */
17375 static const char *
17376 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
17378 if (die
->tag
!= DW_TAG_variable
)
17381 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
17382 if (attr
== nullptr || !attr
->as_boolean ())
17385 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
17386 if (attr
== nullptr)
17388 return attr
->as_string ();
17391 /* Parse dwarf attribute if it's a block, reference or constant and put the
17392 resulting value of the attribute into struct bound_prop.
17393 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17396 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17397 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17398 struct type
*default_type
)
17400 struct dwarf2_property_baton
*baton
;
17401 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17402 struct objfile
*objfile
= per_objfile
->objfile
;
17403 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17405 gdb_assert (default_type
!= NULL
);
17407 if (attr
== NULL
|| prop
== NULL
)
17410 if (attr
->form_is_block ())
17412 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17413 baton
->property_type
= default_type
;
17414 baton
->locexpr
.per_cu
= cu
->per_cu
;
17415 baton
->locexpr
.per_objfile
= per_objfile
;
17417 struct dwarf_block
*block
;
17418 if (attr
->form
== DW_FORM_data16
)
17420 size_t data_size
= 16;
17421 block
= XOBNEW (obstack
, struct dwarf_block
);
17422 block
->size
= (data_size
17423 + 2 /* Extra bytes for DW_OP and arg. */);
17424 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
17425 data
[0] = DW_OP_implicit_value
;
17426 data
[1] = data_size
;
17427 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
17428 block
->data
= data
;
17431 block
= attr
->as_block ();
17433 baton
->locexpr
.size
= block
->size
;
17434 baton
->locexpr
.data
= block
->data
;
17435 switch (attr
->name
)
17437 case DW_AT_string_length
:
17438 baton
->locexpr
.is_reference
= true;
17441 baton
->locexpr
.is_reference
= false;
17445 prop
->set_locexpr (baton
);
17446 gdb_assert (prop
->baton () != NULL
);
17448 else if (attr
->form_is_ref ())
17450 struct dwarf2_cu
*target_cu
= cu
;
17451 struct die_info
*target_die
;
17452 struct attribute
*target_attr
;
17454 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17455 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17456 if (target_attr
== NULL
)
17457 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17459 if (target_attr
== nullptr)
17460 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
17462 if (target_attr
== NULL
)
17464 const char *name
= var_decl_name (target_die
, target_cu
);
17465 if (name
!= nullptr)
17467 prop
->set_variable_name (name
);
17473 switch (target_attr
->name
)
17475 case DW_AT_location
:
17476 if (target_attr
->form_is_section_offset ())
17478 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17479 baton
->property_type
= die_type (target_die
, target_cu
);
17480 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17481 prop
->set_loclist (baton
);
17482 gdb_assert (prop
->baton () != NULL
);
17484 else if (target_attr
->form_is_block ())
17486 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17487 baton
->property_type
= die_type (target_die
, target_cu
);
17488 baton
->locexpr
.per_cu
= cu
->per_cu
;
17489 baton
->locexpr
.per_objfile
= per_objfile
;
17490 struct dwarf_block
*block
= target_attr
->as_block ();
17491 baton
->locexpr
.size
= block
->size
;
17492 baton
->locexpr
.data
= block
->data
;
17493 baton
->locexpr
.is_reference
= true;
17494 prop
->set_locexpr (baton
);
17495 gdb_assert (prop
->baton () != NULL
);
17499 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17500 "dynamic property");
17504 case DW_AT_data_member_location
:
17505 case DW_AT_data_bit_offset
:
17509 if (!handle_member_location (target_die
, target_cu
, &offset
))
17512 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17513 baton
->property_type
= read_type_die (target_die
->parent
,
17515 baton
->offset_info
.offset
= offset
;
17516 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17517 prop
->set_addr_offset (baton
);
17522 else if (attr
->form_is_constant ())
17523 prop
->set_const_val (attr
->constant_value (0));
17524 else if (attr
->form_is_section_offset ())
17526 switch (attr
->name
)
17528 case DW_AT_string_length
:
17529 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17530 baton
->property_type
= default_type
;
17531 fill_in_loclist_baton (cu
, &baton
->loclist
, attr
);
17532 prop
->set_loclist (baton
);
17533 gdb_assert (prop
->baton () != NULL
);
17545 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17546 dwarf2_name (die
, cu
));
17552 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17553 present (which is valid) then compute the default type based on the
17554 compilation units address size. */
17556 static struct type
*
17557 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17559 struct type
*index_type
= die_type (die
, cu
);
17561 /* Dwarf-2 specifications explicitly allows to create subrange types
17562 without specifying a base type.
17563 In that case, the base type must be set to the type of
17564 the lower bound, upper bound or count, in that order, if any of these
17565 three attributes references an object that has a type.
17566 If no base type is found, the Dwarf-2 specifications say that
17567 a signed integer type of size equal to the size of an address should
17569 For the following C code: `extern char gdb_int [];'
17570 GCC produces an empty range DIE.
17571 FIXME: muller/2010-05-28: Possible references to object for low bound,
17572 high bound or count are not yet handled by this code. */
17573 if (index_type
->code () == TYPE_CODE_VOID
)
17574 index_type
= cu
->addr_sized_int_type (false);
17579 /* Read the given DW_AT_subrange DIE. */
17581 static struct type
*
17582 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17584 struct type
*base_type
, *orig_base_type
;
17585 struct type
*range_type
;
17586 struct attribute
*attr
;
17587 struct dynamic_prop low
, high
;
17588 int low_default_is_valid
;
17589 int high_bound_is_count
= 0;
17591 ULONGEST negative_mask
;
17593 orig_base_type
= read_subrange_index_type (die
, cu
);
17595 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17596 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17597 creating the range type, but we use the result of check_typedef
17598 when examining properties of the type. */
17599 base_type
= check_typedef (orig_base_type
);
17601 /* The die_type call above may have already set the type for this DIE. */
17602 range_type
= get_die_type (die
, cu
);
17606 high
.set_const_val (0);
17608 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17609 omitting DW_AT_lower_bound. */
17610 switch (cu
->lang ())
17613 case language_cplus
:
17614 low
.set_const_val (0);
17615 low_default_is_valid
= 1;
17617 case language_fortran
:
17618 low
.set_const_val (1);
17619 low_default_is_valid
= 1;
17622 case language_objc
:
17623 case language_rust
:
17624 low
.set_const_val (0);
17625 low_default_is_valid
= (cu
->header
.version
>= 4);
17629 case language_pascal
:
17630 low
.set_const_val (1);
17631 low_default_is_valid
= (cu
->header
.version
>= 4);
17634 low
.set_const_val (0);
17635 low_default_is_valid
= 0;
17639 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17640 if (attr
!= nullptr)
17641 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17642 else if (!low_default_is_valid
)
17643 complaint (_("Missing DW_AT_lower_bound "
17644 "- DIE at %s [in module %s]"),
17645 sect_offset_str (die
->sect_off
),
17646 objfile_name (cu
->per_objfile
->objfile
));
17648 struct attribute
*attr_ub
, *attr_count
;
17649 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17650 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17652 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17653 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17655 /* If bounds are constant do the final calculation here. */
17656 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
17657 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
17659 high_bound_is_count
= 1;
17663 if (attr_ub
!= NULL
)
17664 complaint (_("Unresolved DW_AT_upper_bound "
17665 "- DIE at %s [in module %s]"),
17666 sect_offset_str (die
->sect_off
),
17667 objfile_name (cu
->per_objfile
->objfile
));
17668 if (attr_count
!= NULL
)
17669 complaint (_("Unresolved DW_AT_count "
17670 "- DIE at %s [in module %s]"),
17671 sect_offset_str (die
->sect_off
),
17672 objfile_name (cu
->per_objfile
->objfile
));
17677 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17678 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17679 bias
= bias_attr
->constant_value (0);
17681 /* Normally, the DWARF producers are expected to use a signed
17682 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17683 But this is unfortunately not always the case, as witnessed
17684 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17685 is used instead. To work around that ambiguity, we treat
17686 the bounds as signed, and thus sign-extend their values, when
17687 the base type is signed. */
17689 -((ULONGEST
) 1 << (base_type
->length () * TARGET_CHAR_BIT
- 1));
17690 if (low
.kind () == PROP_CONST
17691 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
17692 low
.set_const_val (low
.const_val () | negative_mask
);
17693 if (high
.kind () == PROP_CONST
17694 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
17695 high
.set_const_val (high
.const_val () | negative_mask
);
17697 /* Check for bit and byte strides. */
17698 struct dynamic_prop byte_stride_prop
;
17699 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17700 if (attr_byte_stride
!= nullptr)
17702 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17703 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17707 struct dynamic_prop bit_stride_prop
;
17708 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17709 if (attr_bit_stride
!= nullptr)
17711 /* It only makes sense to have either a bit or byte stride. */
17712 if (attr_byte_stride
!= nullptr)
17714 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17715 "- DIE at %s [in module %s]"),
17716 sect_offset_str (die
->sect_off
),
17717 objfile_name (cu
->per_objfile
->objfile
));
17718 attr_bit_stride
= nullptr;
17722 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17723 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17728 if (attr_byte_stride
!= nullptr
17729 || attr_bit_stride
!= nullptr)
17731 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17732 struct dynamic_prop
*stride
17733 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17736 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17737 &high
, bias
, stride
, byte_stride_p
);
17740 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17742 if (high_bound_is_count
)
17743 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
17745 /* Ada expects an empty array on no boundary attributes. */
17746 if (attr
== NULL
&& cu
->lang () != language_ada
)
17747 range_type
->bounds ()->high
.set_undefined ();
17749 name
= dwarf2_name (die
, cu
);
17751 range_type
->set_name (name
);
17753 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17754 if (attr
!= nullptr)
17755 range_type
->set_length (attr
->constant_value (0));
17757 maybe_set_alignment (cu
, die
, range_type
);
17759 set_die_type (die
, range_type
, cu
);
17761 /* set_die_type should be already done. */
17762 set_descriptive_type (range_type
, die
, cu
);
17767 static struct type
*
17768 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17772 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17773 type
->set_name (dwarf2_name (die
, cu
));
17775 /* In Ada, an unspecified type is typically used when the description
17776 of the type is deferred to a different unit. When encountering
17777 such a type, we treat it as a stub, and try to resolve it later on,
17779 Mark this as a stub type for all languages though. */
17780 type
->set_is_stub (true);
17782 return set_die_type (die
, type
, cu
);
17785 /* Read a single die and all its descendents. Set the die's sibling
17786 field to NULL; set other fields in the die correctly, and set all
17787 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17788 location of the info_ptr after reading all of those dies. PARENT
17789 is the parent of the die in question. */
17791 static struct die_info
*
17792 read_die_and_children (const struct die_reader_specs
*reader
,
17793 const gdb_byte
*info_ptr
,
17794 const gdb_byte
**new_info_ptr
,
17795 struct die_info
*parent
)
17797 struct die_info
*die
;
17798 const gdb_byte
*cur_ptr
;
17800 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17803 *new_info_ptr
= cur_ptr
;
17806 store_in_ref_table (die
, reader
->cu
);
17808 if (die
->has_children
)
17809 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17813 *new_info_ptr
= cur_ptr
;
17816 die
->sibling
= NULL
;
17817 die
->parent
= parent
;
17821 /* Read a die, all of its descendents, and all of its siblings; set
17822 all of the fields of all of the dies correctly. Arguments are as
17823 in read_die_and_children. */
17825 static struct die_info
*
17826 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17827 const gdb_byte
*info_ptr
,
17828 const gdb_byte
**new_info_ptr
,
17829 struct die_info
*parent
)
17831 struct die_info
*first_die
, *last_sibling
;
17832 const gdb_byte
*cur_ptr
;
17834 cur_ptr
= info_ptr
;
17835 first_die
= last_sibling
= NULL
;
17839 struct die_info
*die
17840 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17844 *new_info_ptr
= cur_ptr
;
17851 last_sibling
->sibling
= die
;
17853 last_sibling
= die
;
17857 /* Read a die, all of its descendents, and all of its siblings; set
17858 all of the fields of all of the dies correctly. Arguments are as
17859 in read_die_and_children.
17860 This the main entry point for reading a DIE and all its children. */
17862 static struct die_info
*
17863 read_die_and_siblings (const struct die_reader_specs
*reader
,
17864 const gdb_byte
*info_ptr
,
17865 const gdb_byte
**new_info_ptr
,
17866 struct die_info
*parent
)
17868 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17869 new_info_ptr
, parent
);
17871 if (dwarf_die_debug
)
17873 gdb_printf (gdb_stdlog
,
17874 "Read die from %s@0x%x of %s:\n",
17875 reader
->die_section
->get_name (),
17876 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17877 bfd_get_filename (reader
->abfd
));
17878 dump_die (die
, dwarf_die_debug
);
17884 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17886 The caller is responsible for filling in the extra attributes
17887 and updating (*DIEP)->num_attrs.
17888 Set DIEP to point to a newly allocated die with its information,
17889 except for its child, sibling, and parent fields. */
17891 static const gdb_byte
*
17892 read_full_die_1 (const struct die_reader_specs
*reader
,
17893 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17894 int num_extra_attrs
)
17896 unsigned int abbrev_number
, bytes_read
, i
;
17897 const struct abbrev_info
*abbrev
;
17898 struct die_info
*die
;
17899 struct dwarf2_cu
*cu
= reader
->cu
;
17900 bfd
*abfd
= reader
->abfd
;
17902 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17903 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17904 info_ptr
+= bytes_read
;
17905 if (!abbrev_number
)
17911 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17913 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17915 bfd_get_filename (abfd
));
17917 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17918 die
->sect_off
= sect_off
;
17919 die
->tag
= abbrev
->tag
;
17920 die
->abbrev
= abbrev_number
;
17921 die
->has_children
= abbrev
->has_children
;
17923 /* Make the result usable.
17924 The caller needs to update num_attrs after adding the extra
17926 die
->num_attrs
= abbrev
->num_attrs
;
17928 bool any_need_reprocess
= false;
17929 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17931 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17933 if (die
->attrs
[i
].requires_reprocessing_p ())
17934 any_need_reprocess
= true;
17937 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17938 if (attr
!= nullptr && attr
->form_is_unsigned ())
17939 cu
->str_offsets_base
= attr
->as_unsigned ();
17941 attr
= die
->attr (DW_AT_loclists_base
);
17942 if (attr
!= nullptr)
17943 cu
->loclist_base
= attr
->as_unsigned ();
17945 auto maybe_addr_base
= die
->addr_base ();
17946 if (maybe_addr_base
.has_value ())
17947 cu
->addr_base
= *maybe_addr_base
;
17949 attr
= die
->attr (DW_AT_rnglists_base
);
17950 if (attr
!= nullptr)
17951 cu
->rnglists_base
= attr
->as_unsigned ();
17953 if (any_need_reprocess
)
17955 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17957 if (die
->attrs
[i
].requires_reprocessing_p ())
17958 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
17965 /* Read a die and all its attributes.
17966 Set DIEP to point to a newly allocated die with its information,
17967 except for its child, sibling, and parent fields. */
17969 static const gdb_byte
*
17970 read_full_die (const struct die_reader_specs
*reader
,
17971 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17973 const gdb_byte
*result
;
17975 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17977 if (dwarf_die_debug
)
17979 gdb_printf (gdb_stdlog
,
17980 "Read die from %s@0x%x of %s:\n",
17981 reader
->die_section
->get_name (),
17982 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17983 bfd_get_filename (reader
->abfd
));
17984 dump_die (*diep
, dwarf_die_debug
);
17992 cooked_indexer::check_bounds (cutu_reader
*reader
)
17994 if (reader
->cu
->per_cu
->addresses_seen
)
17997 dwarf2_cu
*cu
= reader
->cu
;
17999 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
18000 /* Possibly set the default values of LOWPC and HIGHPC from
18002 dwarf2_find_base_address (reader
->comp_unit_die
, cu
);
18003 enum pc_bounds_kind cu_bounds_kind
18004 = dwarf2_get_pc_bounds (reader
->comp_unit_die
, &best_lowpc
, &best_highpc
,
18005 cu
, m_index_storage
->get_addrmap (), cu
->per_cu
);
18006 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
18008 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18009 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
18010 struct gdbarch
*gdbarch
= objfile
->arch ();
18012 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
18015 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
18017 /* Store the contiguous range if it is not empty; it can be
18018 empty for CUs with no code. */
18019 m_index_storage
->get_addrmap ()->set_empty (low
, high
, cu
->per_cu
);
18021 cu
->per_cu
->addresses_seen
= true;
18025 /* Helper function that returns true if TAG can have a linkage
18029 tag_can_have_linkage_name (enum dwarf_tag tag
)
18033 case DW_TAG_variable
:
18034 case DW_TAG_subprogram
:
18043 cooked_indexer::ensure_cu_exists (cutu_reader
*reader
,
18044 dwarf2_per_objfile
*per_objfile
,
18045 sect_offset sect_off
, bool is_dwz
,
18048 /* Lookups for type unit references are always in the CU, and
18049 cross-CU references will crash. */
18050 if (reader
->cu
->per_cu
->is_dwz
== is_dwz
18051 && reader
->cu
->header
.offset_in_cu_p (sect_off
))
18054 dwarf2_per_cu_data
*per_cu
18055 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
18056 per_objfile
->per_bfd
);
18058 /* When scanning, we only want to visit a given CU a single time.
18059 Doing this check here avoids self-imports as well. */
18063 if (!per_cu
->scanned
.compare_exchange_strong (nope
, true))
18066 if (per_cu
== m_per_cu
)
18069 cutu_reader
*result
= m_index_storage
->get_reader (per_cu
);
18070 if (result
== nullptr)
18072 cutu_reader
new_reader (per_cu
, per_objfile
, nullptr, nullptr, false,
18073 m_index_storage
->get_abbrev_cache ());
18075 prepare_one_comp_unit (new_reader
.cu
, new_reader
.comp_unit_die
,
18077 std::unique_ptr
<cutu_reader
> copy
18078 (new cutu_reader (std::move (new_reader
)));
18079 result
= m_index_storage
->preserve (std::move (copy
));
18082 if (result
->dummy_p
|| !result
->comp_unit_die
->has_children
)
18086 check_bounds (result
);
18092 cooked_indexer::scan_attributes (dwarf2_per_cu_data
*scanning_per_cu
,
18093 cutu_reader
*reader
,
18094 const gdb_byte
*watermark_ptr
,
18095 const gdb_byte
*info_ptr
,
18096 const abbrev_info
*abbrev
,
18098 const char **linkage_name
,
18099 cooked_index_flag
*flags
,
18100 sect_offset
*sibling_offset
,
18101 const cooked_index_entry
**parent_entry
,
18102 CORE_ADDR
*maybe_defer
,
18103 bool for_specification
)
18105 bool origin_is_dwz
= false;
18106 bool is_declaration
= false;
18107 sect_offset origin_offset
{};
18109 gdb::optional
<CORE_ADDR
> low_pc
;
18110 gdb::optional
<CORE_ADDR
> high_pc
;
18111 bool high_pc_relative
= false;
18113 for (int i
= 0; i
< abbrev
->num_attrs
; ++i
)
18116 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
18117 if (attr
.requires_reprocessing_p ())
18118 read_attribute_reprocess (reader
, &attr
, abbrev
->tag
);
18120 /* Store the data if it is of an attribute we want to keep in a
18121 partial symbol table. */
18125 switch (abbrev
->tag
)
18127 case DW_TAG_compile_unit
:
18128 case DW_TAG_partial_unit
:
18129 case DW_TAG_type_unit
:
18130 /* Compilation units have a DW_AT_name that is a filename, not
18131 a source language identifier. */
18135 if (*name
== nullptr)
18136 *name
= attr
.as_string ();
18141 case DW_AT_linkage_name
:
18142 case DW_AT_MIPS_linkage_name
:
18143 /* Note that both forms of linkage name might appear. We
18144 assume they will be the same, and we only store the last
18146 if (*linkage_name
== nullptr)
18147 *linkage_name
= attr
.as_string ();
18150 case DW_AT_main_subprogram
:
18151 if (attr
.as_boolean ())
18155 case DW_AT_declaration
:
18156 is_declaration
= attr
.as_boolean ();
18159 case DW_AT_sibling
:
18160 if (sibling_offset
!= nullptr)
18161 *sibling_offset
= attr
.get_ref_die_offset ();
18164 case DW_AT_specification
:
18165 case DW_AT_abstract_origin
:
18166 case DW_AT_extension
:
18167 origin_offset
= attr
.get_ref_die_offset ();
18168 origin_is_dwz
= attr
.form
== DW_FORM_GNU_ref_alt
;
18171 case DW_AT_external
:
18172 if (attr
.as_boolean ())
18173 *flags
&= ~IS_STATIC
;
18176 case DW_AT_enum_class
:
18177 if (attr
.as_boolean ())
18178 *flags
|= IS_ENUM_CLASS
;
18182 low_pc
= attr
.as_address ();
18185 case DW_AT_high_pc
:
18186 high_pc
= attr
.as_address ();
18187 if (reader
->cu
->header
.version
>= 4 && attr
.form_is_constant ())
18188 high_pc_relative
= true;
18191 case DW_AT_location
:
18192 if (!scanning_per_cu
->addresses_seen
&& attr
.form_is_block ())
18194 struct dwarf_block
*locdesc
= attr
.as_block ();
18195 CORE_ADDR addr
= decode_locdesc (locdesc
, reader
->cu
);
18197 || reader
->cu
->per_objfile
->per_bfd
->has_section_at_zero
)
18200 /* For variables, we don't want to try decoding the
18201 type just to find the size -- for gdb's purposes
18202 we only need the address of a variable. */
18203 high_pc
= addr
+ 1;
18204 high_pc_relative
= false;
18210 if (!scanning_per_cu
->addresses_seen
)
18212 /* Offset in the .debug_ranges or .debug_rnglist section
18213 (depending on DWARF version). */
18214 ULONGEST ranges_offset
= attr
.as_unsigned ();
18216 /* See dwarf2_cu::gnu_ranges_base's doc for why we might
18217 want to add this value. */
18218 ranges_offset
+= reader
->cu
->gnu_ranges_base
;
18220 CORE_ADDR lowpc
, highpc
;
18221 dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, reader
->cu
,
18222 m_index_storage
->get_addrmap (),
18223 scanning_per_cu
, abbrev
->tag
);
18229 /* We don't want to examine declarations, but if we found a
18230 declaration when handling DW_AT_specification or the like, then
18231 that is ok. Similarly, we allow an external variable without a
18232 location; those are resolved via minimal symbols. */
18233 if (is_declaration
&& !for_specification
18234 && !(abbrev
->tag
== DW_TAG_variable
&& (*flags
& IS_STATIC
) == 0))
18236 /* We always want to recurse into some types, but we may not
18237 want to treat them as definitions. */
18238 if ((abbrev
->tag
== DW_TAG_class_type
18239 || abbrev
->tag
== DW_TAG_structure_type
18240 || abbrev
->tag
== DW_TAG_union_type
)
18241 && abbrev
->has_children
)
18242 *flags
|= IS_TYPE_DECLARATION
;
18245 *linkage_name
= nullptr;
18249 else if ((*name
== nullptr
18250 || (*linkage_name
== nullptr
18251 && tag_can_have_linkage_name (abbrev
->tag
))
18252 || (*parent_entry
== nullptr && m_language
!= language_c
))
18253 && origin_offset
!= sect_offset (0))
18255 cutu_reader
*new_reader
18256 = ensure_cu_exists (reader
, reader
->cu
->per_objfile
, origin_offset
,
18257 origin_is_dwz
, false);
18258 if (new_reader
!= nullptr)
18260 const gdb_byte
*new_info_ptr
= (new_reader
->buffer
18261 + to_underlying (origin_offset
));
18263 if (new_reader
->cu
== reader
->cu
18264 && new_info_ptr
> watermark_ptr
18265 && *parent_entry
== nullptr)
18266 *maybe_defer
= form_addr (origin_offset
, origin_is_dwz
);
18267 else if (*parent_entry
== nullptr)
18269 CORE_ADDR lookup
= form_addr (origin_offset
, origin_is_dwz
);
18271 = (cooked_index_entry
*) m_die_range_map
.find (lookup
);
18274 unsigned int bytes_read
;
18275 const abbrev_info
*new_abbrev
= peek_die_abbrev (*new_reader
,
18278 new_info_ptr
+= bytes_read
;
18279 scan_attributes (scanning_per_cu
, new_reader
, new_info_ptr
, new_info_ptr
,
18280 new_abbrev
, name
, linkage_name
, flags
, nullptr,
18281 parent_entry
, maybe_defer
, true);
18285 if (!for_specification
)
18287 if (m_language
== language_ada
18288 && *linkage_name
== nullptr)
18289 *linkage_name
= *name
;
18291 if (!scanning_per_cu
->addresses_seen
18292 && low_pc
.has_value ()
18293 && (reader
->cu
->per_objfile
->per_bfd
->has_section_at_zero
18295 && high_pc
.has_value ())
18297 if (high_pc_relative
)
18298 high_pc
= *high_pc
+ *low_pc
;
18300 if (*high_pc
> *low_pc
)
18302 struct objfile
*objfile
= reader
->cu
->per_objfile
->objfile
;
18303 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
18304 struct gdbarch
*gdbarch
= objfile
->arch ();
18306 = (gdbarch_adjust_dwarf2_addr (gdbarch
, *low_pc
+ baseaddr
)
18309 = (gdbarch_adjust_dwarf2_addr (gdbarch
, *high_pc
+ baseaddr
)
18311 m_index_storage
->get_addrmap ()->set_empty (lo
, hi
- 1,
18316 if (abbrev
->tag
== DW_TAG_module
|| abbrev
->tag
== DW_TAG_namespace
)
18317 *flags
&= ~IS_STATIC
;
18319 if (abbrev
->tag
== DW_TAG_namespace
&& *name
== nullptr)
18320 *name
= "(anonymous namespace)";
18322 if (m_language
== language_cplus
18323 && (abbrev
->tag
== DW_TAG_class_type
18324 || abbrev
->tag
== DW_TAG_interface_type
18325 || abbrev
->tag
== DW_TAG_structure_type
18326 || abbrev
->tag
== DW_TAG_union_type
18327 || abbrev
->tag
== DW_TAG_enumeration_type
18328 || abbrev
->tag
== DW_TAG_enumerator
))
18329 *flags
&= ~IS_STATIC
;
18336 cooked_indexer::index_imported_unit (cutu_reader
*reader
,
18337 const gdb_byte
*info_ptr
,
18338 const abbrev_info
*abbrev
)
18340 sect_offset sect_off
{};
18341 bool is_dwz
= false;
18343 for (int i
= 0; i
< abbrev
->num_attrs
; ++i
)
18345 /* Note that we never need to reprocess attributes here. */
18347 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
18349 if (attr
.name
== DW_AT_import
)
18351 sect_off
= attr
.get_ref_die_offset ();
18352 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18353 || reader
->cu
->per_cu
->is_dwz
);
18357 /* Did not find DW_AT_import. */
18358 if (sect_off
== sect_offset (0))
18361 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
18362 cutu_reader
*new_reader
= ensure_cu_exists (reader
, per_objfile
, sect_off
,
18364 if (new_reader
!= nullptr)
18366 index_dies (new_reader
, new_reader
->info_ptr
, nullptr, false);
18368 reader
->cu
->add_dependence (new_reader
->cu
->per_cu
);
18375 cooked_indexer::recurse (cutu_reader
*reader
,
18376 const gdb_byte
*info_ptr
,
18377 const cooked_index_entry
*parent_entry
,
18380 info_ptr
= index_dies (reader
, info_ptr
, parent_entry
, fully
);
18382 if (parent_entry
!= nullptr)
18384 CORE_ADDR start
= form_addr (parent_entry
->die_offset
,
18385 reader
->cu
->per_cu
->is_dwz
);
18386 CORE_ADDR end
= form_addr (sect_offset (info_ptr
- 1 - reader
->buffer
),
18387 reader
->cu
->per_cu
->is_dwz
);
18388 m_die_range_map
.set_empty (start
, end
, (void *) parent_entry
);
18395 cooked_indexer::index_dies (cutu_reader
*reader
,
18396 const gdb_byte
*info_ptr
,
18397 const cooked_index_entry
*parent_entry
,
18400 const gdb_byte
*end_ptr
= (reader
->buffer
18401 + to_underlying (reader
->cu
->header
.sect_off
)
18402 + reader
->cu
->header
.get_length_with_initial ());
18404 while (info_ptr
< end_ptr
)
18406 sect_offset this_die
= (sect_offset
) (info_ptr
- reader
->buffer
);
18407 unsigned int bytes_read
;
18408 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
18410 info_ptr
+= bytes_read
;
18411 if (abbrev
== nullptr)
18414 if (abbrev
->tag
== DW_TAG_imported_unit
)
18416 info_ptr
= index_imported_unit (reader
, info_ptr
, abbrev
);
18420 if (!abbrev
->interesting
)
18422 info_ptr
= skip_one_die (reader
, info_ptr
, abbrev
, !fully
);
18423 if (fully
&& abbrev
->has_children
)
18424 info_ptr
= index_dies (reader
, info_ptr
, parent_entry
, fully
);
18428 const char *name
= nullptr;
18429 const char *linkage_name
= nullptr;
18430 CORE_ADDR defer
= 0;
18431 cooked_index_flag flags
= IS_STATIC
;
18432 sect_offset sibling
{};
18433 const cooked_index_entry
*this_parent_entry
= parent_entry
;
18434 info_ptr
= scan_attributes (reader
->cu
->per_cu
, reader
, info_ptr
,
18435 info_ptr
, abbrev
, &name
, &linkage_name
,
18436 &flags
, &sibling
, &this_parent_entry
,
18439 if (abbrev
->tag
== DW_TAG_namespace
18440 && m_language
== language_cplus
18441 && strcmp (name
, "::") == 0)
18443 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they
18444 generated bogus DW_TAG_namespace DIEs with a name of "::"
18445 for the global namespace. Work around this problem
18450 const cooked_index_entry
*this_entry
= nullptr;
18451 if (name
!= nullptr)
18454 m_deferred_entries
.push_back ({
18455 this_die
, name
, defer
, abbrev
->tag
, flags
18458 this_entry
= m_index_storage
->add (this_die
, abbrev
->tag
, flags
,
18459 name
, this_parent_entry
,
18463 if (linkage_name
!= nullptr)
18465 /* We only want this to be "main" if it has a linkage name
18466 but not an ordinary name. */
18467 if (name
!= nullptr)
18468 flags
= flags
& ~IS_MAIN
;
18469 /* Set the IS_LINKAGE on for everything except when functions
18470 have linkage name present but name is absent. */
18471 if (name
!= nullptr
18472 || (abbrev
->tag
!= DW_TAG_subprogram
18473 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18474 && abbrev
->tag
!= DW_TAG_entry_point
))
18475 flags
= flags
| IS_LINKAGE
;
18476 m_index_storage
->add (this_die
, abbrev
->tag
, flags
,
18477 linkage_name
, nullptr, m_per_cu
);
18480 if (abbrev
->has_children
)
18482 switch (abbrev
->tag
)
18484 case DW_TAG_class_type
:
18485 case DW_TAG_interface_type
:
18486 case DW_TAG_structure_type
:
18487 case DW_TAG_union_type
:
18488 if (m_language
!= language_c
&& this_entry
!= nullptr)
18490 info_ptr
= recurse (reader
, info_ptr
, this_entry
, fully
);
18495 case DW_TAG_enumeration_type
:
18496 /* We need to recurse even for an anonymous enumeration.
18497 Which scope we record as the parent scope depends on
18498 whether we're reading an "enum class". If so, we use
18499 the enum itself as the parent, yielding names like
18500 "enum_class::enumerator"; otherwise we inject the
18501 names into our own parent scope. */
18502 info_ptr
= recurse (reader
, info_ptr
,
18503 ((flags
& IS_ENUM_CLASS
) == 0)
18509 case DW_TAG_module
:
18510 if (this_entry
== nullptr)
18513 case DW_TAG_namespace
:
18514 /* We don't check THIS_ENTRY for a namespace, to handle
18515 the ancient G++ workaround pointed out above. */
18516 info_ptr
= recurse (reader
, info_ptr
, this_entry
, fully
);
18519 case DW_TAG_subprogram
:
18520 if ((m_language
== language_fortran
18521 || m_language
== language_ada
)
18522 && this_entry
!= nullptr)
18524 info_ptr
= recurse (reader
, info_ptr
, this_entry
, true);
18530 if (sibling
!= sect_offset (0))
18532 const gdb_byte
*sibling_ptr
18533 = reader
->buffer
+ to_underlying (sibling
);
18535 if (sibling_ptr
< info_ptr
)
18536 complaint (_("DW_AT_sibling points backwards"));
18537 else if (sibling_ptr
> reader
->buffer_end
)
18538 reader
->die_section
->overflow_complaint ();
18540 info_ptr
= sibling_ptr
;
18543 info_ptr
= skip_children (reader
, info_ptr
);
18551 cooked_indexer::make_index (cutu_reader
*reader
)
18553 check_bounds (reader
);
18554 find_file_and_directory (reader
->comp_unit_die
, reader
->cu
);
18555 if (!reader
->comp_unit_die
->has_children
)
18557 index_dies (reader
, reader
->info_ptr
, nullptr, false);
18559 for (const auto &entry
: m_deferred_entries
)
18561 CORE_ADDR key
= form_addr (entry
.die_offset
, m_per_cu
->is_dwz
);
18562 cooked_index_entry
*parent
18563 = (cooked_index_entry
*) m_die_range_map
.find (key
);
18564 m_index_storage
->add (entry
.die_offset
, entry
.tag
, entry
.flags
,
18565 entry
.name
, parent
, m_per_cu
);
18569 /* An implementation of quick_symbol_functions for the cooked DWARF
18572 struct cooked_index_functions
: public dwarf2_base_index_functions
18574 dwarf2_per_cu_data
*find_per_cu (dwarf2_per_bfd
*per_bfd
,
18575 CORE_ADDR adjusted_pc
) override
;
18577 struct compunit_symtab
*find_compunit_symtab_by_address
18578 (struct objfile
*objfile
, CORE_ADDR address
) override
;
18580 void dump (struct objfile
*objfile
) override
18582 gdb_printf ("Cooked index in use\n");
18585 void expand_matching_symbols
18587 const lookup_name_info
&lookup_name
,
18588 domain_enum domain
,
18590 symbol_compare_ftype
*ordered_compare
) override
;
18592 bool expand_symtabs_matching
18593 (struct objfile
*objfile
,
18594 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
18595 const lookup_name_info
*lookup_name
,
18596 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
18597 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
18598 block_search_flags search_flags
,
18599 domain_enum domain
,
18600 enum search_domain kind
) override
;
18602 bool can_lazily_read_symbols () override
18607 void read_partial_symbols (struct objfile
*objfile
) override
18609 if (dwarf2_has_info (objfile
, nullptr))
18610 dwarf2_build_psymtabs (objfile
);
18614 dwarf2_per_cu_data
*
18615 cooked_index_functions::find_per_cu (dwarf2_per_bfd
*per_bfd
,
18616 CORE_ADDR adjusted_pc
)
18618 if (per_bfd
->index_table
== nullptr)
18620 cooked_index_vector
*table
18621 = (gdb::checked_static_cast
<cooked_index_vector
*>
18622 (per_bfd
->index_table
.get ()));
18623 return table
->lookup (adjusted_pc
);
18626 struct compunit_symtab
*
18627 cooked_index_functions::find_compunit_symtab_by_address
18628 (struct objfile
*objfile
, CORE_ADDR address
)
18630 if (objfile
->sect_index_data
== -1)
18633 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
18634 if (per_objfile
->per_bfd
->index_table
== nullptr)
18637 CORE_ADDR baseaddr
= objfile
->data_section_offset ();
18638 cooked_index_vector
*table
18639 = (gdb::checked_static_cast
<cooked_index_vector
*>
18640 (per_objfile
->per_bfd
->index_table
.get ()));
18641 dwarf2_per_cu_data
*per_cu
= table
->lookup (address
- baseaddr
);
18642 if (per_cu
== nullptr)
18645 return dw2_instantiate_symtab (per_cu
, per_objfile
, false);
18649 cooked_index_functions::expand_matching_symbols
18650 (struct objfile
*objfile
,
18651 const lookup_name_info
&lookup_name
,
18652 domain_enum domain
,
18654 symbol_compare_ftype
*ordered_compare
)
18656 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
18657 if (per_objfile
->per_bfd
->index_table
== nullptr)
18659 const block_search_flags search_flags
= (global
18660 ? SEARCH_GLOBAL_BLOCK
18661 : SEARCH_STATIC_BLOCK
);
18662 const language_defn
*lang
= language_def (language_ada
);
18663 symbol_name_matcher_ftype
*name_match
18664 = lang
->get_symbol_name_matcher (lookup_name
);
18666 cooked_index_vector
*table
18667 = (gdb::checked_static_cast
<cooked_index_vector
*>
18668 (per_objfile
->per_bfd
->index_table
.get ()));
18669 for (const cooked_index_entry
*entry
: table
->all_entries ())
18673 if (entry
->parent_entry
!= nullptr)
18676 if (!entry
->matches (search_flags
)
18677 || !entry
->matches (domain
))
18680 if (name_match (entry
->canonical
, lookup_name
, nullptr))
18681 dw2_instantiate_symtab (entry
->per_cu
, per_objfile
, false);
18686 cooked_index_functions::expand_symtabs_matching
18687 (struct objfile
*objfile
,
18688 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
18689 const lookup_name_info
*lookup_name
,
18690 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
18691 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
18692 block_search_flags search_flags
,
18693 domain_enum domain
,
18694 enum search_domain kind
)
18696 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
18697 if (per_objfile
->per_bfd
->index_table
== nullptr)
18700 cooked_index_vector
*table
18701 = (gdb::checked_static_cast
<cooked_index_vector
*>
18702 (per_objfile
->per_bfd
->index_table
.get ()));
18705 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
18707 /* This invariant is documented in quick-functions.h. */
18708 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
18709 if (lookup_name
== nullptr)
18711 for (dwarf2_per_cu_data
*per_cu
18712 : all_units_range (per_objfile
->per_bfd
))
18716 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
18724 lookup_name_info lookup_name_without_params
18725 = lookup_name
->make_ignore_params ();
18726 bool completing
= lookup_name
->completion_mode ();
18728 /* Unique styles of language splitting. */
18729 static const enum language unique_styles
[] =
18731 /* No splitting is also a style. */
18733 /* This includes Rust. */
18735 /* This includes Go. */
18740 for (enum language lang
: unique_styles
)
18742 std::vector
<gdb::string_view
> name_vec
18743 = lookup_name_without_params
.split_name (lang
);
18745 for (const cooked_index_entry
*entry
: table
->find (name_vec
.back (),
18750 /* No need to consider symbols from expanded CUs. */
18751 if (per_objfile
->symtab_set_p (entry
->per_cu
))
18754 /* If file-matching was done, we don't need to consider
18755 symbols from unmarked CUs. */
18756 if (file_matcher
!= nullptr && !entry
->per_cu
->mark
)
18759 /* See if the symbol matches the type filter. */
18760 if (!entry
->matches (search_flags
)
18761 || !entry
->matches (domain
)
18762 || !entry
->matches (kind
))
18765 /* We've found the base name of the symbol; now walk its
18766 parentage chain, ensuring that each component
18770 const cooked_index_entry
*parent
= entry
->parent_entry
;
18771 for (int i
= name_vec
.size () - 1; i
> 0; --i
)
18773 /* If we ran out of entries, or if this segment doesn't
18774 match, this did not match. */
18775 if (parent
== nullptr
18776 || strncmp (parent
->name
, name_vec
[i
- 1].data (),
18777 name_vec
[i
- 1].length ()) != 0)
18783 parent
= parent
->parent_entry
;
18789 /* Might have been looking for "a::b" and found
18791 if (symbol_matcher
== nullptr)
18793 symbol_name_match_type match_type
18794 = lookup_name_without_params
.match_type ();
18795 if ((match_type
== symbol_name_match_type::FULL
18796 || (lang
!= language_ada
18797 && match_type
== symbol_name_match_type::EXPRESSION
))
18798 && parent
!= nullptr)
18803 auto_obstack temp_storage
;
18804 const char *full_name
= entry
->full_name (&temp_storage
);
18805 if (!symbol_matcher (full_name
))
18809 if (!dw2_expand_symtabs_matching_one (entry
->per_cu
, per_objfile
,
18819 /* Return a new cooked_index_functions object. */
18821 static quick_symbol_functions_up
18822 make_cooked_index_funcs ()
18824 return quick_symbol_functions_up (new cooked_index_functions
);
18827 quick_symbol_functions_up
18828 cooked_index_vector::make_quick_functions () const
18830 return make_cooked_index_funcs ();
18835 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
18836 contents from the given SECTION in the HEADER.
18838 HEADER_OFFSET is the offset of the header in the section. */
18840 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
18841 struct dwarf2_section_info
*section
,
18842 sect_offset header_offset
)
18844 unsigned int bytes_read
;
18845 bfd
*abfd
= section
->get_bfd_owner ();
18846 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
18848 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18849 info_ptr
+= bytes_read
;
18851 header
->version
= read_2_bytes (abfd
, info_ptr
);
18854 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18857 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18860 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18863 /* Return the DW_AT_loclists_base value for the CU. */
18865 lookup_loclist_base (struct dwarf2_cu
*cu
)
18867 /* For the .dwo unit, the loclist_base points to the first offset following
18868 the header. The header consists of the following entities-
18869 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18871 2. version (2 bytes)
18872 3. address size (1 byte)
18873 4. segment selector size (1 byte)
18874 5. offset entry count (4 bytes)
18875 These sizes are derived as per the DWARFv5 standard. */
18876 if (cu
->dwo_unit
!= nullptr)
18878 if (cu
->header
.initial_length_size
== 4)
18879 return LOCLIST_HEADER_SIZE32
;
18880 return LOCLIST_HEADER_SIZE64
;
18882 return cu
->loclist_base
;
18885 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18886 array of offsets in the .debug_loclists section. */
18889 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18891 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18892 struct objfile
*objfile
= per_objfile
->objfile
;
18893 bfd
*abfd
= objfile
->obfd
.get ();
18894 ULONGEST loclist_header_size
=
18895 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
18896 : LOCLIST_HEADER_SIZE64
);
18897 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18899 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
18900 ULONGEST start_offset
=
18901 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18903 /* Get loclists section. */
18904 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18906 /* Read the loclists section content. */
18907 section
->read (objfile
);
18908 if (section
->buffer
== NULL
)
18909 error (_("DW_FORM_loclistx used without .debug_loclists "
18910 "section [in module %s]"), objfile_name (objfile
));
18912 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
18913 so if loclist_base is smaller than the header size, we have a problem. */
18914 if (loclist_base
< loclist_header_size
)
18915 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
18916 objfile_name (objfile
));
18918 /* Read the header of the loclists contribution. */
18919 struct loclists_rnglists_header header
;
18920 read_loclists_rnglists_header (&header
, section
,
18921 (sect_offset
) (loclist_base
- loclist_header_size
));
18923 /* Verify the loclist index is valid. */
18924 if (loclist_index
>= header
.offset_entry_count
)
18925 error (_("DW_FORM_loclistx pointing outside of "
18926 ".debug_loclists offset array [in module %s]"),
18927 objfile_name (objfile
));
18929 /* Validate that reading won't go beyond the end of the section. */
18930 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
18931 error (_("Reading DW_FORM_loclistx index beyond end of"
18932 ".debug_loclists section [in module %s]"),
18933 objfile_name (objfile
));
18935 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
18937 if (cu
->header
.offset_size
== 4)
18938 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
18940 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
18943 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
18944 array of offsets in the .debug_rnglists section. */
18947 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
18950 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18951 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18952 bfd
*abfd
= objfile
->obfd
.get ();
18953 ULONGEST rnglist_header_size
=
18954 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
18955 : RNGLIST_HEADER_SIZE64
);
18957 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
18958 .debug_rnglists.dwo section. The rnglists base given in the skeleton
18960 ULONGEST rnglist_base
=
18961 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
18963 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
18964 ULONGEST start_offset
=
18965 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
18967 /* Get rnglists section. */
18968 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
18970 /* Read the rnglists section content. */
18971 section
->read (objfile
);
18972 if (section
->buffer
== nullptr)
18973 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
18975 objfile_name (objfile
));
18977 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
18978 so if rnglist_base is smaller than the header size, we have a problem. */
18979 if (rnglist_base
< rnglist_header_size
)
18980 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
18981 objfile_name (objfile
));
18983 /* Read the header of the rnglists contribution. */
18984 struct loclists_rnglists_header header
;
18985 read_loclists_rnglists_header (&header
, section
,
18986 (sect_offset
) (rnglist_base
- rnglist_header_size
));
18988 /* Verify the rnglist index is valid. */
18989 if (rnglist_index
>= header
.offset_entry_count
)
18990 error (_("DW_FORM_rnglistx index pointing outside of "
18991 ".debug_rnglists offset array [in module %s]"),
18992 objfile_name (objfile
));
18994 /* Validate that reading won't go beyond the end of the section. */
18995 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
18996 error (_("Reading DW_FORM_rnglistx index beyond end of"
18997 ".debug_rnglists section [in module %s]"),
18998 objfile_name (objfile
));
19000 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19002 if (cu
->header
.offset_size
== 4)
19003 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19005 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19008 /* Process the attributes that had to be skipped in the first round. These
19009 attributes are the ones that need str_offsets_base or addr_base attributes.
19010 They could not have been processed in the first round, because at the time
19011 the values of str_offsets_base or addr_base may not have been known. */
19013 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19014 struct attribute
*attr
, dwarf_tag tag
)
19016 struct dwarf2_cu
*cu
= reader
->cu
;
19017 switch (attr
->form
)
19019 case DW_FORM_addrx
:
19020 case DW_FORM_GNU_addr_index
:
19021 attr
->set_address (read_addr_index (cu
,
19022 attr
->as_unsigned_reprocess ()));
19024 case DW_FORM_loclistx
:
19026 sect_offset loclists_sect_off
19027 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19029 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19032 case DW_FORM_rnglistx
:
19034 sect_offset rnglists_sect_off
19035 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19037 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19041 case DW_FORM_strx1
:
19042 case DW_FORM_strx2
:
19043 case DW_FORM_strx3
:
19044 case DW_FORM_strx4
:
19045 case DW_FORM_GNU_str_index
:
19047 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19048 gdb_assert (!attr
->canonical_string_p ());
19049 if (reader
->dwo_file
!= NULL
)
19050 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19053 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19058 gdb_assert_not_reached ("Unexpected DWARF form.");
19062 /* Read an attribute value described by an attribute form. */
19064 static const gdb_byte
*
19065 read_attribute_value (const struct die_reader_specs
*reader
,
19066 struct attribute
*attr
, unsigned form
,
19067 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19069 struct dwarf2_cu
*cu
= reader
->cu
;
19070 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19071 struct objfile
*objfile
= per_objfile
->objfile
;
19072 bfd
*abfd
= reader
->abfd
;
19073 struct comp_unit_head
*cu_header
= &cu
->header
;
19074 unsigned int bytes_read
;
19075 struct dwarf_block
*blk
;
19077 attr
->form
= (enum dwarf_form
) form
;
19080 case DW_FORM_ref_addr
:
19081 if (cu_header
->version
== 2)
19082 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
19085 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19087 info_ptr
+= bytes_read
;
19089 case DW_FORM_GNU_ref_alt
:
19090 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19092 info_ptr
+= bytes_read
;
19096 struct gdbarch
*gdbarch
= objfile
->arch ();
19097 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
19098 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19099 attr
->set_address (addr
);
19100 info_ptr
+= bytes_read
;
19103 case DW_FORM_block2
:
19104 blk
= dwarf_alloc_block (cu
);
19105 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19107 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19108 info_ptr
+= blk
->size
;
19109 attr
->set_block (blk
);
19111 case DW_FORM_block4
:
19112 blk
= dwarf_alloc_block (cu
);
19113 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19115 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19116 info_ptr
+= blk
->size
;
19117 attr
->set_block (blk
);
19119 case DW_FORM_data2
:
19120 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
19123 case DW_FORM_data4
:
19124 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
19127 case DW_FORM_data8
:
19128 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
19131 case DW_FORM_data16
:
19132 blk
= dwarf_alloc_block (cu
);
19134 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19136 attr
->set_block (blk
);
19138 case DW_FORM_sec_offset
:
19139 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19141 info_ptr
+= bytes_read
;
19143 case DW_FORM_loclistx
:
19145 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19147 info_ptr
+= bytes_read
;
19150 case DW_FORM_string
:
19151 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
19153 info_ptr
+= bytes_read
;
19156 if (!cu
->per_cu
->is_dwz
)
19158 attr
->set_string_noncanonical
19159 (read_indirect_string (per_objfile
,
19160 abfd
, info_ptr
, cu_header
,
19162 info_ptr
+= bytes_read
;
19166 case DW_FORM_line_strp
:
19167 if (!cu
->per_cu
->is_dwz
)
19169 attr
->set_string_noncanonical
19170 (per_objfile
->read_line_string (info_ptr
, cu_header
,
19172 info_ptr
+= bytes_read
;
19176 case DW_FORM_GNU_strp_alt
:
19178 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
19179 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19182 attr
->set_string_noncanonical
19183 (dwz
->read_string (objfile
, str_offset
));
19184 info_ptr
+= bytes_read
;
19187 case DW_FORM_exprloc
:
19188 case DW_FORM_block
:
19189 blk
= dwarf_alloc_block (cu
);
19190 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19191 info_ptr
+= bytes_read
;
19192 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19193 info_ptr
+= blk
->size
;
19194 attr
->set_block (blk
);
19196 case DW_FORM_block1
:
19197 blk
= dwarf_alloc_block (cu
);
19198 blk
->size
= read_1_byte (abfd
, info_ptr
);
19200 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19201 info_ptr
+= blk
->size
;
19202 attr
->set_block (blk
);
19204 case DW_FORM_data1
:
19206 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
19209 case DW_FORM_flag_present
:
19210 attr
->set_unsigned (1);
19212 case DW_FORM_sdata
:
19213 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
19214 info_ptr
+= bytes_read
;
19216 case DW_FORM_rnglistx
:
19218 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19220 info_ptr
+= bytes_read
;
19223 case DW_FORM_udata
:
19224 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19225 info_ptr
+= bytes_read
;
19228 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19229 + read_1_byte (abfd
, info_ptr
)));
19233 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19234 + read_2_bytes (abfd
, info_ptr
)));
19238 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19239 + read_4_bytes (abfd
, info_ptr
)));
19243 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19244 + read_8_bytes (abfd
, info_ptr
)));
19247 case DW_FORM_ref_sig8
:
19248 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
19251 case DW_FORM_ref_udata
:
19252 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19253 + read_unsigned_leb128 (abfd
, info_ptr
,
19255 info_ptr
+= bytes_read
;
19257 case DW_FORM_indirect
:
19258 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19259 info_ptr
+= bytes_read
;
19260 if (form
== DW_FORM_implicit_const
)
19262 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19263 info_ptr
+= bytes_read
;
19265 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19268 case DW_FORM_implicit_const
:
19269 attr
->set_signed (implicit_const
);
19271 case DW_FORM_addrx
:
19272 case DW_FORM_GNU_addr_index
:
19273 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19275 info_ptr
+= bytes_read
;
19278 case DW_FORM_strx1
:
19279 case DW_FORM_strx2
:
19280 case DW_FORM_strx3
:
19281 case DW_FORM_strx4
:
19282 case DW_FORM_GNU_str_index
:
19284 ULONGEST str_index
;
19285 if (form
== DW_FORM_strx1
)
19287 str_index
= read_1_byte (abfd
, info_ptr
);
19290 else if (form
== DW_FORM_strx2
)
19292 str_index
= read_2_bytes (abfd
, info_ptr
);
19295 else if (form
== DW_FORM_strx3
)
19297 str_index
= read_3_bytes (abfd
, info_ptr
);
19300 else if (form
== DW_FORM_strx4
)
19302 str_index
= read_4_bytes (abfd
, info_ptr
);
19307 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19308 info_ptr
+= bytes_read
;
19310 attr
->set_unsigned_reprocess (str_index
);
19314 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19315 dwarf_form_name (form
),
19316 bfd_get_filename (abfd
));
19320 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19321 attr
->form
= DW_FORM_GNU_ref_alt
;
19323 /* We have seen instances where the compiler tried to emit a byte
19324 size attribute of -1 which ended up being encoded as an unsigned
19325 0xffffffff. Although 0xffffffff is technically a valid size value,
19326 an object of this size seems pretty unlikely so we can relatively
19327 safely treat these cases as if the size attribute was invalid and
19328 treat them as zero by default. */
19329 if (attr
->name
== DW_AT_byte_size
19330 && form
== DW_FORM_data4
19331 && attr
->as_unsigned () >= 0xffffffff)
19334 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19335 hex_string (attr
->as_unsigned ()));
19336 attr
->set_unsigned (0);
19342 /* Read an attribute described by an abbreviated attribute. */
19344 static const gdb_byte
*
19345 read_attribute (const struct die_reader_specs
*reader
,
19346 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
19347 const gdb_byte
*info_ptr
)
19349 attr
->name
= abbrev
->name
;
19350 attr
->string_is_canonical
= 0;
19351 attr
->requires_reprocessing
= 0;
19352 return read_attribute_value (reader
, attr
, abbrev
->form
,
19353 abbrev
->implicit_const
, info_ptr
);
19356 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19358 static const char *
19359 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
19360 LONGEST str_offset
)
19362 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
19363 str_offset
, "DW_FORM_strp");
19366 /* Return pointer to string at .debug_str offset as read from BUF.
19367 BUF is assumed to be in a compilation unit described by CU_HEADER.
19368 Return *BYTES_READ_PTR count of bytes read from BUF. */
19370 static const char *
19371 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
19372 const gdb_byte
*buf
,
19373 const struct comp_unit_head
*cu_header
,
19374 unsigned int *bytes_read_ptr
)
19376 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19378 return read_indirect_string_at_offset (per_objfile
, str_offset
);
19384 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19385 unsigned int offset_size
)
19387 bfd
*abfd
= objfile
->obfd
.get ();
19388 ULONGEST str_offset
= read_offset (abfd
, buf
, offset_size
);
19390 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19396 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19397 const struct comp_unit_head
*cu_header
,
19398 unsigned int *bytes_read_ptr
)
19400 bfd
*abfd
= objfile
->obfd
.get ();
19401 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19403 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19406 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19407 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19408 ADDR_SIZE is the size of addresses from the CU header. */
19411 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
19412 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
19414 struct objfile
*objfile
= per_objfile
->objfile
;
19415 bfd
*abfd
= objfile
->obfd
.get ();
19416 const gdb_byte
*info_ptr
;
19417 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19419 per_objfile
->per_bfd
->addr
.read (objfile
);
19420 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19421 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19422 objfile_name (objfile
));
19423 if (addr_base_or_zero
+ addr_index
* addr_size
19424 >= per_objfile
->per_bfd
->addr
.size
)
19425 error (_("DW_FORM_addr_index pointing outside of "
19426 ".debug_addr section [in module %s]"),
19427 objfile_name (objfile
));
19428 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
19429 + addr_index
* addr_size
);
19430 if (addr_size
== 4)
19431 return bfd_get_32 (abfd
, info_ptr
);
19433 return bfd_get_64 (abfd
, info_ptr
);
19436 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19439 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19441 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19442 cu
->addr_base
, cu
->header
.addr_size
);
19445 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19448 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19449 unsigned int *bytes_read
)
19451 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
.get ();
19452 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19454 return read_addr_index (cu
, addr_index
);
19460 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19461 dwarf2_per_objfile
*per_objfile
,
19462 unsigned int addr_index
)
19464 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
19465 gdb::optional
<ULONGEST
> addr_base
;
19468 /* We need addr_base and addr_size.
19469 If we don't have PER_CU->cu, we have to get it.
19470 Nasty, but the alternative is storing the needed info in PER_CU,
19471 which at this point doesn't seem justified: it's not clear how frequently
19472 it would get used and it would increase the size of every PER_CU.
19473 Entry points like dwarf2_per_cu_addr_size do a similar thing
19474 so we're not in uncharted territory here.
19475 Alas we need to be a bit more complicated as addr_base is contained
19478 We don't need to read the entire CU(/TU).
19479 We just need the header and top level die.
19481 IWBN to use the aging mechanism to let us lazily later discard the CU.
19482 For now we skip this optimization. */
19486 addr_base
= cu
->addr_base
;
19487 addr_size
= cu
->header
.addr_size
;
19491 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
19492 addr_base
= reader
.cu
->addr_base
;
19493 addr_size
= reader
.cu
->header
.addr_size
;
19496 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
19499 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19500 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19503 static const char *
19504 read_str_index (struct dwarf2_cu
*cu
,
19505 struct dwarf2_section_info
*str_section
,
19506 struct dwarf2_section_info
*str_offsets_section
,
19507 ULONGEST str_offsets_base
, ULONGEST str_index
,
19508 unsigned offset_size
)
19510 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19511 struct objfile
*objfile
= per_objfile
->objfile
;
19512 const char *objf_name
= objfile_name (objfile
);
19513 bfd
*abfd
= objfile
->obfd
.get ();
19514 const gdb_byte
*info_ptr
;
19515 ULONGEST str_offset
;
19516 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19518 str_section
->read (objfile
);
19519 str_offsets_section
->read (objfile
);
19520 if (str_section
->buffer
== NULL
)
19521 error (_("%s used without %s section"
19522 " in CU at offset %s [in module %s]"),
19523 form_name
, str_section
->get_name (),
19524 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19525 if (str_offsets_section
->buffer
== NULL
)
19526 error (_("%s used without %s section"
19527 " in CU at offset %s [in module %s]"),
19528 form_name
, str_section
->get_name (),
19529 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19530 info_ptr
= (str_offsets_section
->buffer
19532 + str_index
* offset_size
);
19533 if (offset_size
== 4)
19534 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19536 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19537 if (str_offset
>= str_section
->size
)
19538 error (_("Offset from %s pointing outside of"
19539 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19540 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19541 return (const char *) (str_section
->buffer
+ str_offset
);
19544 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19546 static const char *
19547 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19549 unsigned offset_size
;
19550 ULONGEST str_offsets_base
;
19551 if (reader
->cu
->header
.version
>= 5)
19553 /* We have a DWARF5 CU with a reference to a .debug_str_offsets section,
19554 so assume the .debug_str_offsets section is DWARF5 as well, and
19555 parse the header. FIXME: Parse the header only once. */
19556 unsigned int bytes_read
= 0;
19557 bfd
*abfd
= reader
->dwo_file
->sections
.str_offsets
.get_bfd_owner ();
19558 const gdb_byte
*p
= reader
->dwo_file
->sections
.str_offsets
.buffer
;
19560 /* Header: Initial length. */
19561 read_initial_length (abfd
, p
+ bytes_read
, &bytes_read
);
19563 /* Determine offset_size based on the .debug_str_offsets header. */
19564 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
19565 offset_size
= dwarf5_is_dwarf64
? 8 : 4;
19567 /* Header: Version. */
19568 unsigned version
= read_2_bytes (abfd
, p
+ bytes_read
);
19573 /* We'd like one warning here about ignoring the section, but
19574 because we parse the header more than once (see FIXME above)
19575 we'd have many warnings, so use a complaint instead, which at
19576 least has a limit. */
19577 complaint (_("Section .debug_str_offsets in %s has unsupported"
19578 " version %d, use empty string."),
19579 reader
->dwo_file
->dwo_name
, version
);
19583 /* Header: Padding. */
19586 str_offsets_base
= bytes_read
;
19590 /* We have a pre-DWARF5 CU with a reference to a .debug_str_offsets
19591 section, assume the .debug_str_offsets section is pre-DWARF5 as
19592 well, which doesn't have a header. */
19593 str_offsets_base
= 0;
19595 /* Determine offset_size based on the .debug_info header. */
19596 offset_size
= reader
->cu
->header
.offset_size
;
19599 return read_str_index (reader
->cu
,
19600 &reader
->dwo_file
->sections
.str
,
19601 &reader
->dwo_file
->sections
.str_offsets
,
19602 str_offsets_base
, str_index
, offset_size
);
19605 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19607 static const char *
19608 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19610 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19611 const char *objf_name
= objfile_name (objfile
);
19612 static const char form_name
[] = "DW_FORM_GNU_str_index";
19613 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19615 if (!cu
->str_offsets_base
.has_value ())
19616 error (_("%s used in Fission stub without %s"
19617 " in CU at offset 0x%lx [in module %s]"),
19618 form_name
, str_offsets_attr_name
,
19619 (long) cu
->header
.offset_size
, objf_name
);
19621 return read_str_index (cu
,
19622 &cu
->per_objfile
->per_bfd
->str
,
19623 &cu
->per_objfile
->per_bfd
->str_offsets
,
19624 *cu
->str_offsets_base
, str_index
,
19625 cu
->header
.offset_size
);
19628 /* Return the length of an LEB128 number in BUF. */
19631 leb128_size (const gdb_byte
*buf
)
19633 const gdb_byte
*begin
= buf
;
19639 if ((byte
& 128) == 0)
19640 return buf
- begin
;
19644 static enum language
19645 dwarf_lang_to_enum_language (unsigned int lang
)
19647 enum language language
;
19656 language
= language_c
;
19659 case DW_LANG_C_plus_plus
:
19660 case DW_LANG_C_plus_plus_11
:
19661 case DW_LANG_C_plus_plus_14
:
19662 language
= language_cplus
;
19665 language
= language_d
;
19667 case DW_LANG_Fortran77
:
19668 case DW_LANG_Fortran90
:
19669 case DW_LANG_Fortran95
:
19670 case DW_LANG_Fortran03
:
19671 case DW_LANG_Fortran08
:
19672 language
= language_fortran
;
19675 language
= language_go
;
19677 case DW_LANG_Mips_Assembler
:
19678 language
= language_asm
;
19680 case DW_LANG_Ada83
:
19681 case DW_LANG_Ada95
:
19682 language
= language_ada
;
19684 case DW_LANG_Modula2
:
19685 language
= language_m2
;
19687 case DW_LANG_Pascal83
:
19688 language
= language_pascal
;
19691 language
= language_objc
;
19694 case DW_LANG_Rust_old
:
19695 language
= language_rust
;
19697 case DW_LANG_OpenCL
:
19698 language
= language_opencl
;
19700 case DW_LANG_Cobol74
:
19701 case DW_LANG_Cobol85
:
19703 language
= language_minimal
;
19710 /* Return the named attribute or NULL if not there. */
19712 static struct attribute
*
19713 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19718 struct attribute
*spec
= NULL
;
19720 for (i
= 0; i
< die
->num_attrs
; ++i
)
19722 if (die
->attrs
[i
].name
== name
)
19723 return &die
->attrs
[i
];
19724 if (die
->attrs
[i
].name
== DW_AT_specification
19725 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19726 spec
= &die
->attrs
[i
];
19732 die
= follow_die_ref (die
, spec
, &cu
);
19738 /* Return the string associated with a string-typed attribute, or NULL if it
19739 is either not found or is of an incorrect type. */
19741 static const char *
19742 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19744 struct attribute
*attr
;
19745 const char *str
= NULL
;
19747 attr
= dwarf2_attr (die
, name
, cu
);
19751 str
= attr
->as_string ();
19752 if (str
== nullptr)
19753 complaint (_("string type expected for attribute %s for "
19754 "DIE at %s in module %s"),
19755 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19756 objfile_name (cu
->per_objfile
->objfile
));
19762 /* Return the dwo name or NULL if not present. If present, it is in either
19763 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19764 static const char *
19765 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19767 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19768 if (dwo_name
== nullptr)
19769 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19773 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19774 and holds a non-zero value. This function should only be used for
19775 DW_FORM_flag or DW_FORM_flag_present attributes. */
19778 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19780 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19782 return attr
!= nullptr && attr
->as_boolean ();
19786 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19788 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19789 which value is non-zero. However, we have to be careful with
19790 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19791 (via dwarf2_flag_true_p) follows this attribute. So we may
19792 end up accidently finding a declaration attribute that belongs
19793 to a different DIE referenced by the specification attribute,
19794 even though the given DIE does not have a declaration attribute. */
19795 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19796 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19799 /* Return the die giving the specification for DIE, if there is
19800 one. *SPEC_CU is the CU containing DIE on input, and the CU
19801 containing the return value on output. If there is no
19802 specification, but there is an abstract origin, that is
19805 static struct die_info
*
19806 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19808 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19811 if (spec_attr
== NULL
)
19812 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19814 if (spec_attr
== NULL
)
19817 return follow_die_ref (die
, spec_attr
, spec_cu
);
19820 /* A convenience function to find the proper .debug_line section for a CU. */
19822 static struct dwarf2_section_info
*
19823 get_debug_line_section (struct dwarf2_cu
*cu
)
19825 struct dwarf2_section_info
*section
;
19826 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19828 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19830 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19831 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19832 else if (cu
->per_cu
->is_dwz
)
19834 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
19836 section
= &dwz
->line
;
19839 section
= &per_objfile
->per_bfd
->line
;
19844 /* Read the statement program header starting at OFFSET in
19845 .debug_line, or .debug_line.dwo. Return a pointer
19846 to a struct line_header, allocated using xmalloc.
19847 Returns NULL if there is a problem reading the header, e.g., if it
19848 has a version we don't understand.
19850 NOTE: the strings in the include directory and file name tables of
19851 the returned object point into the dwarf line section buffer,
19852 and must not be freed. */
19854 static line_header_up
19855 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
,
19856 const char *comp_dir
)
19858 struct dwarf2_section_info
*section
;
19859 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19861 section
= get_debug_line_section (cu
);
19862 section
->read (per_objfile
->objfile
);
19863 if (section
->buffer
== NULL
)
19865 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19866 complaint (_("missing .debug_line.dwo section"));
19868 complaint (_("missing .debug_line section"));
19872 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19873 per_objfile
, section
, &cu
->header
,
19877 /* Subroutine of dwarf_decode_lines to simplify it.
19878 Return the file name for the given file_entry.
19879 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
19880 If space for the result is malloc'd, *NAME_HOLDER will be set.
19881 Returns NULL if FILE_INDEX should be ignored, i.e., it is
19882 equivalent to CU_INFO. */
19884 static const char *
19885 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19886 const file_and_directory
&cu_info
,
19887 std::string
&name_holder
)
19889 const char *include_name
= fe
.name
;
19890 const char *include_name_to_compare
= include_name
;
19892 const char *dir_name
= fe
.include_dir (lh
);
19894 std::string hold_compare
;
19895 if (!IS_ABSOLUTE_PATH (include_name
)
19896 && (dir_name
!= nullptr || cu_info
.get_comp_dir () != nullptr))
19898 /* Avoid creating a duplicate name for CU_INFO.
19899 We do this by comparing INCLUDE_NAME and CU_INFO.
19900 Before we do the comparison, however, we need to account
19901 for DIR_NAME and COMP_DIR.
19902 First prepend dir_name (if non-NULL). If we still don't
19903 have an absolute path prepend comp_dir (if non-NULL).
19904 However, the directory we record in the include-file's
19905 psymtab does not contain COMP_DIR (to match the
19906 corresponding symtab(s)).
19911 bash$ gcc -g ./hello.c
19912 include_name = "hello.c"
19914 DW_AT_comp_dir = comp_dir = "/tmp"
19915 DW_AT_name = "./hello.c"
19919 if (dir_name
!= NULL
)
19921 name_holder
= path_join (dir_name
, include_name
);
19922 include_name
= name_holder
.c_str ();
19923 include_name_to_compare
= include_name
;
19925 if (!IS_ABSOLUTE_PATH (include_name
)
19926 && cu_info
.get_comp_dir () != nullptr)
19928 hold_compare
= path_join (cu_info
.get_comp_dir (), include_name
);
19929 include_name_to_compare
= hold_compare
.c_str ();
19933 std::string copied_name
;
19934 const char *cu_filename
= cu_info
.get_name ();
19935 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.get_comp_dir () != nullptr)
19937 copied_name
= path_join (cu_info
.get_comp_dir (), cu_filename
);
19938 cu_filename
= copied_name
.c_str ();
19941 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
19943 return include_name
;
19946 /* State machine to track the state of the line number program. */
19948 class lnp_state_machine
19951 /* Initialize a machine state for the start of a line number
19953 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
);
19955 file_entry
*current_file ()
19957 /* lh->file_names is 0-based, but the file name numbers in the
19958 statement program are 1-based. */
19959 return m_line_header
->file_name_at (m_file
);
19962 /* Record the line in the state machine. END_SEQUENCE is true if
19963 we're processing the end of a sequence. */
19964 void record_line (bool end_sequence
);
19966 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
19967 nop-out rest of the lines in this sequence. */
19968 void check_line_address (struct dwarf2_cu
*cu
,
19969 const gdb_byte
*line_ptr
,
19970 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19972 void handle_set_discriminator (unsigned int discriminator
)
19974 m_discriminator
= discriminator
;
19975 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19978 /* Handle DW_LNE_set_address. */
19979 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19982 address
+= baseaddr
;
19983 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19986 /* Handle DW_LNS_advance_pc. */
19987 void handle_advance_pc (CORE_ADDR adjust
);
19989 /* Handle a special opcode. */
19990 void handle_special_opcode (unsigned char op_code
);
19992 /* Handle DW_LNS_advance_line. */
19993 void handle_advance_line (int line_delta
)
19995 advance_line (line_delta
);
19998 /* Handle DW_LNS_set_file. */
19999 void handle_set_file (file_name_index file
);
20001 /* Handle DW_LNS_negate_stmt. */
20002 void handle_negate_stmt ()
20004 m_flags
^= LEF_IS_STMT
;
20007 /* Handle DW_LNS_const_add_pc. */
20008 void handle_const_add_pc ();
20010 /* Handle DW_LNS_fixed_advance_pc. */
20011 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20013 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20017 /* Handle DW_LNS_copy. */
20018 void handle_copy ()
20020 record_line (false);
20021 m_discriminator
= 0;
20022 m_flags
&= ~LEF_PROLOGUE_END
;
20025 /* Handle DW_LNE_end_sequence. */
20026 void handle_end_sequence ()
20028 m_currently_recording_lines
= true;
20031 /* Handle DW_LNS_set_prologue_end. */
20032 void handle_set_prologue_end ()
20034 m_flags
|= LEF_PROLOGUE_END
;
20038 /* Advance the line by LINE_DELTA. */
20039 void advance_line (int line_delta
)
20041 m_line
+= line_delta
;
20043 if (line_delta
!= 0)
20044 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20047 struct dwarf2_cu
*m_cu
;
20049 gdbarch
*m_gdbarch
;
20051 /* The line number header. */
20052 line_header
*m_line_header
;
20054 /* These are part of the standard DWARF line number state machine,
20055 and initialized according to the DWARF spec. */
20057 unsigned char m_op_index
= 0;
20058 /* The line table index of the current file. */
20059 file_name_index m_file
= 1;
20060 unsigned int m_line
= 1;
20062 /* These are initialized in the constructor. */
20064 CORE_ADDR m_address
;
20065 linetable_entry_flags m_flags
;
20066 unsigned int m_discriminator
;
20068 /* Additional bits of state we need to track. */
20070 /* The last file that we called dwarf2_start_subfile for.
20071 This is only used for TLLs. */
20072 unsigned int m_last_file
= 0;
20073 /* The last file a line number was recorded for. */
20074 struct subfile
*m_last_subfile
= NULL
;
20076 /* The address of the last line entry. */
20077 CORE_ADDR m_last_address
;
20079 /* Set to true when a previous line at the same address (using
20080 m_last_address) had LEF_IS_STMT set in m_flags. This is reset to false
20081 when a line entry at a new address (m_address different to
20082 m_last_address) is processed. */
20083 bool m_stmt_at_address
= false;
20085 /* When true, record the lines we decode. */
20086 bool m_currently_recording_lines
= false;
20088 /* The last line number that was recorded, used to coalesce
20089 consecutive entries for the same line. This can happen, for
20090 example, when discriminators are present. PR 17276. */
20091 unsigned int m_last_line
= 0;
20092 bool m_line_has_non_zero_discriminator
= false;
20096 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20098 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20099 / m_line_header
->maximum_ops_per_instruction
)
20100 * m_line_header
->minimum_instruction_length
);
20101 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20102 m_op_index
= ((m_op_index
+ adjust
)
20103 % m_line_header
->maximum_ops_per_instruction
);
20107 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20109 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20110 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20111 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20112 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20113 / m_line_header
->maximum_ops_per_instruction
)
20114 * m_line_header
->minimum_instruction_length
);
20115 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20116 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20117 % m_line_header
->maximum_ops_per_instruction
);
20119 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20120 advance_line (line_delta
);
20121 record_line (false);
20122 m_discriminator
= 0;
20123 m_flags
&= ~LEF_PROLOGUE_END
;
20127 lnp_state_machine::handle_set_file (file_name_index file
)
20131 const file_entry
*fe
= current_file ();
20133 dwarf2_debug_line_missing_file_complaint ();
20136 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20137 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20138 dwarf2_start_subfile (m_cu
, *fe
, *m_line_header
);
20143 lnp_state_machine::handle_const_add_pc ()
20146 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20149 = (((m_op_index
+ adjust
)
20150 / m_line_header
->maximum_ops_per_instruction
)
20151 * m_line_header
->minimum_instruction_length
);
20153 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20154 m_op_index
= ((m_op_index
+ adjust
)
20155 % m_line_header
->maximum_ops_per_instruction
);
20158 /* Return non-zero if we should add LINE to the line number table.
20159 LINE is the line to add, LAST_LINE is the last line that was added,
20160 LAST_SUBFILE is the subfile for LAST_LINE.
20161 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20162 had a non-zero discriminator.
20164 We have to be careful in the presence of discriminators.
20165 E.g., for this line:
20167 for (i = 0; i < 100000; i++);
20169 clang can emit four line number entries for that one line,
20170 each with a different discriminator.
20171 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20173 However, we want gdb to coalesce all four entries into one.
20174 Otherwise the user could stepi into the middle of the line and
20175 gdb would get confused about whether the pc really was in the
20176 middle of the line.
20178 Things are further complicated by the fact that two consecutive
20179 line number entries for the same line is a heuristic used by gcc
20180 to denote the end of the prologue. So we can't just discard duplicate
20181 entries, we have to be selective about it. The heuristic we use is
20182 that we only collapse consecutive entries for the same line if at least
20183 one of those entries has a non-zero discriminator. PR 17276.
20185 Note: Addresses in the line number state machine can never go backwards
20186 within one sequence, thus this coalescing is ok. */
20189 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20190 unsigned int line
, unsigned int last_line
,
20191 int line_has_non_zero_discriminator
,
20192 struct subfile
*last_subfile
)
20194 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20196 if (line
!= last_line
)
20198 /* Same line for the same file that we've seen already.
20199 As a last check, for pr 17276, only record the line if the line
20200 has never had a non-zero discriminator. */
20201 if (!line_has_non_zero_discriminator
)
20206 /* Use the CU's builder to record line number LINE beginning at
20207 address ADDRESS in the line table of subfile SUBFILE. */
20210 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20211 unsigned int line
, CORE_ADDR address
,
20212 linetable_entry_flags flags
,
20213 struct dwarf2_cu
*cu
)
20215 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20217 if (dwarf_line_debug
)
20219 gdb_printf (gdb_stdlog
,
20220 "Recording line %u, file %s, address %s\n",
20221 line
, lbasename (subfile
->name
.c_str ()),
20222 paddress (gdbarch
, address
));
20226 cu
->get_builder ()->record_line (subfile
, line
, addr
, flags
);
20229 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20230 Mark the end of a set of line number records.
20231 The arguments are the same as for dwarf_record_line_1.
20232 If SUBFILE is NULL the request is ignored. */
20235 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20236 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20238 if (subfile
== NULL
)
20241 if (dwarf_line_debug
)
20243 gdb_printf (gdb_stdlog
,
20244 "Finishing current line, file %s, address %s\n",
20245 lbasename (subfile
->name
.c_str ()),
20246 paddress (gdbarch
, address
));
20249 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, LEF_IS_STMT
, cu
);
20253 lnp_state_machine::record_line (bool end_sequence
)
20255 if (dwarf_line_debug
)
20257 gdb_printf (gdb_stdlog
,
20258 "Processing actual line %u: file %u,"
20259 " address %s, is_stmt %u, prologue_end %u, discrim %u%s\n",
20261 paddress (m_gdbarch
, m_address
),
20262 (m_flags
& LEF_IS_STMT
) != 0,
20263 (m_flags
& LEF_PROLOGUE_END
) != 0,
20265 (end_sequence
? "\t(end sequence)" : ""));
20268 file_entry
*fe
= current_file ();
20271 dwarf2_debug_line_missing_file_complaint ();
20272 /* For now we ignore lines not starting on an instruction boundary.
20273 But not when processing end_sequence for compatibility with the
20274 previous version of the code. */
20275 else if (m_op_index
== 0 || end_sequence
)
20277 /* When we switch files we insert an end maker in the first file,
20278 switch to the second file and add a new line entry. The
20279 problem is that the end marker inserted in the first file will
20280 discard any previous line entries at the same address. If the
20281 line entries in the first file are marked as is-stmt, while
20282 the new line in the second file is non-stmt, then this means
20283 the end marker will discard is-stmt lines so we can have a
20284 non-stmt line. This means that there are less addresses at
20285 which the user can insert a breakpoint.
20287 To improve this we track the last address in m_last_address,
20288 and whether we have seen an is-stmt at this address. Then
20289 when switching files, if we have seen a stmt at the current
20290 address, and we are switching to create a non-stmt line, then
20291 discard the new line. */
20293 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
20294 bool ignore_this_line
20295 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
20296 && ((m_flags
& LEF_IS_STMT
) == 0)
20297 && m_stmt_at_address
)
20298 || (!end_sequence
&& m_line
== 0));
20300 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
20302 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20303 m_currently_recording_lines
? m_cu
: nullptr);
20306 if (!end_sequence
&& !ignore_this_line
)
20308 linetable_entry_flags lte_flags
= m_flags
;
20309 if (producer_is_codewarrior (m_cu
))
20310 lte_flags
|= LEF_IS_STMT
;
20312 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20313 m_line_has_non_zero_discriminator
,
20316 buildsym_compunit
*builder
= m_cu
->get_builder ();
20317 dwarf_record_line_1 (m_gdbarch
,
20318 builder
->get_current_subfile (),
20319 m_line
, m_address
, lte_flags
,
20320 m_currently_recording_lines
? m_cu
: nullptr);
20322 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20323 m_last_line
= m_line
;
20327 /* Track whether we have seen any IS_STMT true at m_address in case we
20328 have multiple line table entries all at m_address. */
20329 if (m_last_address
!= m_address
)
20331 m_stmt_at_address
= false;
20332 m_last_address
= m_address
;
20334 m_stmt_at_address
|= (m_flags
& LEF_IS_STMT
) != 0;
20337 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20342 m_line_header
= lh
;
20344 m_currently_recording_lines
= true;
20346 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20347 was a line entry for it so that the backend has a chance to adjust it
20348 and also record it in case it needs it. This is currently used by MIPS
20349 code, cf. `mips_adjust_dwarf2_line'. */
20350 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20352 if (lh
->default_is_stmt
)
20353 m_flags
|= LEF_IS_STMT
;
20354 m_discriminator
= 0;
20356 m_last_address
= m_address
;
20357 m_stmt_at_address
= false;
20361 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20362 const gdb_byte
*line_ptr
,
20363 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20365 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
20366 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
20367 located at 0x0. In this case, additionally check that if
20368 ADDRESS < UNRELOCATED_LOWPC. */
20370 if ((address
== 0 && address
< unrelocated_lowpc
)
20371 || address
== (CORE_ADDR
) -1)
20373 /* This line table is for a function which has been
20374 GCd by the linker. Ignore it. PR gdb/12528 */
20376 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20377 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20379 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20380 line_offset
, objfile_name (objfile
));
20381 m_currently_recording_lines
= false;
20382 /* Note: m_currently_recording_lines is left as false until we see
20383 DW_LNE_end_sequence. */
20387 /* Subroutine of dwarf_decode_lines to simplify it.
20388 Process the line number information in LH. */
20391 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20394 const gdb_byte
*line_ptr
, *extended_end
;
20395 const gdb_byte
*line_end
;
20396 unsigned int bytes_read
, extended_len
;
20397 unsigned char op_code
, extended_op
;
20398 CORE_ADDR baseaddr
;
20399 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20400 bfd
*abfd
= objfile
->obfd
.get ();
20401 struct gdbarch
*gdbarch
= objfile
->arch ();
20403 baseaddr
= objfile
->text_section_offset ();
20405 line_ptr
= lh
->statement_program_start
;
20406 line_end
= lh
->statement_program_end
;
20408 /* Read the statement sequences until there's nothing left. */
20409 while (line_ptr
< line_end
)
20411 /* The DWARF line number program state machine. Reset the state
20412 machine at the start of each sequence. */
20413 lnp_state_machine
state_machine (cu
, gdbarch
, lh
);
20414 bool end_sequence
= false;
20416 /* Start a subfile for the current file of the state
20418 const file_entry
*fe
= state_machine
.current_file ();
20421 dwarf2_start_subfile (cu
, *fe
, *lh
);
20423 /* Decode the table. */
20424 while (line_ptr
< line_end
&& !end_sequence
)
20426 op_code
= read_1_byte (abfd
, line_ptr
);
20429 if (op_code
>= lh
->opcode_base
)
20431 /* Special opcode. */
20432 state_machine
.handle_special_opcode (op_code
);
20434 else switch (op_code
)
20436 case DW_LNS_extended_op
:
20437 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20439 line_ptr
+= bytes_read
;
20440 extended_end
= line_ptr
+ extended_len
;
20441 extended_op
= read_1_byte (abfd
, line_ptr
);
20443 if (DW_LNE_lo_user
<= extended_op
20444 && extended_op
<= DW_LNE_hi_user
)
20446 /* Vendor extension, ignore. */
20447 line_ptr
= extended_end
;
20450 switch (extended_op
)
20452 case DW_LNE_end_sequence
:
20453 state_machine
.handle_end_sequence ();
20454 end_sequence
= true;
20456 case DW_LNE_set_address
:
20459 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20460 line_ptr
+= bytes_read
;
20462 state_machine
.check_line_address (cu
, line_ptr
,
20463 lowpc
- baseaddr
, address
);
20464 state_machine
.handle_set_address (baseaddr
, address
);
20467 case DW_LNE_define_file
:
20469 const char *cur_file
;
20470 unsigned int mod_time
, length
;
20473 cur_file
= read_direct_string (abfd
, line_ptr
,
20475 line_ptr
+= bytes_read
;
20476 dindex
= (dir_index
)
20477 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20478 line_ptr
+= bytes_read
;
20480 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20481 line_ptr
+= bytes_read
;
20483 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20484 line_ptr
+= bytes_read
;
20485 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20488 case DW_LNE_set_discriminator
:
20490 /* The discriminator is not interesting to the
20491 debugger; just ignore it. We still need to
20492 check its value though:
20493 if there are consecutive entries for the same
20494 (non-prologue) line we want to coalesce them.
20497 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20498 line_ptr
+= bytes_read
;
20500 state_machine
.handle_set_discriminator (discr
);
20504 complaint (_("mangled .debug_line section"));
20507 /* Make sure that we parsed the extended op correctly. If e.g.
20508 we expected a different address size than the producer used,
20509 we may have read the wrong number of bytes. */
20510 if (line_ptr
!= extended_end
)
20512 complaint (_("mangled .debug_line section"));
20517 state_machine
.handle_copy ();
20519 case DW_LNS_advance_pc
:
20522 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20523 line_ptr
+= bytes_read
;
20525 state_machine
.handle_advance_pc (adjust
);
20528 case DW_LNS_advance_line
:
20531 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20532 line_ptr
+= bytes_read
;
20534 state_machine
.handle_advance_line (line_delta
);
20537 case DW_LNS_set_file
:
20539 file_name_index file
20540 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20542 line_ptr
+= bytes_read
;
20544 state_machine
.handle_set_file (file
);
20547 case DW_LNS_set_column
:
20548 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20549 line_ptr
+= bytes_read
;
20551 case DW_LNS_negate_stmt
:
20552 state_machine
.handle_negate_stmt ();
20554 case DW_LNS_set_basic_block
:
20556 /* Add to the address register of the state machine the
20557 address increment value corresponding to special opcode
20558 255. I.e., this value is scaled by the minimum
20559 instruction length since special opcode 255 would have
20560 scaled the increment. */
20561 case DW_LNS_const_add_pc
:
20562 state_machine
.handle_const_add_pc ();
20564 case DW_LNS_fixed_advance_pc
:
20566 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20569 state_machine
.handle_fixed_advance_pc (addr_adj
);
20572 case DW_LNS_set_prologue_end
:
20573 state_machine
.handle_set_prologue_end ();
20577 /* Unknown standard opcode, ignore it. */
20580 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20582 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20583 line_ptr
+= bytes_read
;
20590 dwarf2_debug_line_missing_end_sequence_complaint ();
20592 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20593 in which case we still finish recording the last line). */
20594 state_machine
.record_line (true);
20598 /* Decode the Line Number Program (LNP) for the given line_header
20599 structure and CU. The actual information extracted and the type
20600 of structures created from the LNP depends on the value of PST.
20602 FND holds the CU file name and directory, if known.
20603 It is used for relative paths in the line table.
20605 NOTE: It is important that psymtabs have the same file name (via
20606 strcmp) as the corresponding symtab. Since the directory is not
20607 used in the name of the symtab we don't use it in the name of the
20608 psymtabs we create. E.g. expand_line_sal requires this when
20609 finding psymtabs to expand. A good testcase for this is
20612 LOWPC is the lowest address in CU (or 0 if not known).
20614 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20615 for its PC<->lines mapping information. Otherwise only the filename
20616 table is read in. */
20619 dwarf_decode_lines (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20620 CORE_ADDR lowpc
, int decode_mapping
)
20622 if (decode_mapping
)
20623 dwarf_decode_lines_1 (lh
, cu
, lowpc
);
20625 /* Make sure a symtab is created for every file, even files
20626 which contain only variables (i.e. no code with associated
20628 buildsym_compunit
*builder
= cu
->get_builder ();
20629 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20631 for (auto &fe
: lh
->file_names ())
20633 dwarf2_start_subfile (cu
, fe
, *lh
);
20634 subfile
*sf
= builder
->get_current_subfile ();
20636 if (sf
->symtab
== nullptr)
20637 sf
->symtab
= allocate_symtab (cust
, sf
->name
.c_str (),
20638 sf
->name_for_id
.c_str ());
20640 fe
.symtab
= sf
->symtab
;
20644 /* Start a subfile for DWARF. FILENAME is the name of the file and
20645 DIRNAME the name of the source directory which contains FILENAME
20646 or NULL if not known.
20647 This routine tries to keep line numbers from identical absolute and
20648 relative file names in a common subfile.
20650 Using the `list' example from the GDB testsuite, which resides in
20651 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20652 of /srcdir/list0.c yields the following debugging information for list0.c:
20654 DW_AT_name: /srcdir/list0.c
20655 DW_AT_comp_dir: /compdir
20656 files.files[0].name: list0.h
20657 files.files[0].dir: /srcdir
20658 files.files[1].name: list0.c
20659 files.files[1].dir: /srcdir
20661 The line number information for list0.c has to end up in a single
20662 subfile, so that `break /srcdir/list0.c:1' works as expected.
20663 start_subfile will ensure that this happens provided that we pass the
20664 concatenation of files.files[1].dir and files.files[1].name as the
20668 dwarf2_start_subfile (dwarf2_cu
*cu
, const file_entry
&fe
,
20669 const line_header
&lh
)
20671 std::string filename_holder
;
20672 const char *filename
= fe
.name
;
20673 const char *dirname
= lh
.include_dir_at (fe
.d_index
);
20675 /* In order not to lose the line information directory,
20676 we concatenate it to the filename when it makes sense.
20677 Note that the Dwarf3 standard says (speaking of filenames in line
20678 information): ``The directory index is ignored for file names
20679 that represent full path names''. Thus ignoring dirname in the
20680 `else' branch below isn't an issue. */
20682 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20684 filename_holder
= path_join (dirname
, filename
);
20685 filename
= filename_holder
.c_str ();
20688 std::string filename_for_id
= lh
.file_file_name (fe
);
20689 cu
->get_builder ()->start_subfile (filename
, filename_for_id
.c_str ());
20693 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20694 struct dwarf2_cu
*cu
)
20696 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20697 struct comp_unit_head
*cu_header
= &cu
->header
;
20699 /* NOTE drow/2003-01-30: There used to be a comment and some special
20700 code here to turn a symbol with DW_AT_external and a
20701 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20702 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20703 with some versions of binutils) where shared libraries could have
20704 relocations against symbols in their debug information - the
20705 minimal symbol would have the right address, but the debug info
20706 would not. It's no longer necessary, because we will explicitly
20707 apply relocations when we read in the debug information now. */
20709 /* A DW_AT_location attribute with no contents indicates that a
20710 variable has been optimized away. */
20711 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
20713 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
20717 /* Handle one degenerate form of location expression specially, to
20718 preserve GDB's previous behavior when section offsets are
20719 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20720 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20722 if (attr
->form_is_block ())
20724 struct dwarf_block
*block
= attr
->as_block ();
20726 if ((block
->data
[0] == DW_OP_addr
20727 && block
->size
== 1 + cu_header
->addr_size
)
20728 || ((block
->data
[0] == DW_OP_GNU_addr_index
20729 || block
->data
[0] == DW_OP_addrx
)
20731 == 1 + leb128_size (&block
->data
[1]))))
20733 unsigned int dummy
;
20735 if (block
->data
[0] == DW_OP_addr
)
20736 sym
->set_value_address
20737 (cu
->header
.read_address (objfile
->obfd
.get (), block
->data
+ 1,
20740 sym
->set_value_address
20741 (read_addr_index_from_leb128 (cu
, block
->data
+ 1, &dummy
));
20742 sym
->set_aclass_index (LOC_STATIC
);
20743 fixup_symbol_section (sym
, objfile
);
20744 sym
->set_value_address
20745 (sym
->value_address ()
20746 + objfile
->section_offsets
[sym
->section_index ()]);
20751 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20752 expression evaluator, and use LOC_COMPUTED only when necessary
20753 (i.e. when the value of a register or memory location is
20754 referenced, or a thread-local block, etc.). Then again, it might
20755 not be worthwhile. I'm assuming that it isn't unless performance
20756 or memory numbers show me otherwise. */
20758 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20760 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20761 cu
->has_loclist
= true;
20764 /* Given a pointer to a DWARF information entry, figure out if we need
20765 to make a symbol table entry for it, and if so, create a new entry
20766 and return a pointer to it.
20767 If TYPE is NULL, determine symbol type from the die, otherwise
20768 used the passed type.
20769 If SPACE is not NULL, use it to hold the new symbol. If it is
20770 NULL, allocate a new symbol on the objfile's obstack. */
20772 static struct symbol
*
20773 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20774 struct symbol
*space
)
20776 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20777 struct objfile
*objfile
= per_objfile
->objfile
;
20778 struct gdbarch
*gdbarch
= objfile
->arch ();
20779 struct symbol
*sym
= NULL
;
20781 struct attribute
*attr
= NULL
;
20782 struct attribute
*attr2
= NULL
;
20783 CORE_ADDR baseaddr
;
20784 struct pending
**list_to_add
= NULL
;
20786 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20788 baseaddr
= objfile
->text_section_offset ();
20790 name
= dwarf2_name (die
, cu
);
20791 if (name
== nullptr && (die
->tag
== DW_TAG_subprogram
20792 || die
->tag
== DW_TAG_inlined_subroutine
20793 || die
->tag
== DW_TAG_entry_point
))
20794 name
= dw2_linkage_name (die
, cu
);
20798 int suppress_add
= 0;
20803 sym
= new (&objfile
->objfile_obstack
) symbol
;
20804 OBJSTAT (objfile
, n_syms
++);
20806 /* Cache this symbol's name and the name's demangled form (if any). */
20807 sym
->set_language (cu
->lang (), &objfile
->objfile_obstack
);
20808 /* Fortran does not have mangling standard and the mangling does differ
20809 between gfortran, iFort etc. */
20810 const char *physname
20811 = (cu
->lang () == language_fortran
20812 ? dwarf2_full_name (name
, die
, cu
)
20813 : dwarf2_physname (name
, die
, cu
));
20814 const char *linkagename
= dw2_linkage_name (die
, cu
);
20816 if (linkagename
== nullptr || cu
->lang () == language_ada
)
20817 sym
->set_linkage_name (physname
);
20820 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20821 sym
->set_linkage_name (linkagename
);
20824 /* Handle DW_AT_artificial. */
20825 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
20826 if (attr
!= nullptr)
20827 sym
->set_is_artificial (attr
->as_boolean ());
20829 /* Default assumptions.
20830 Use the passed type or decode it from the die. */
20831 sym
->set_domain (VAR_DOMAIN
);
20832 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
20834 sym
->set_type (type
);
20836 sym
->set_type (die_type (die
, cu
));
20837 attr
= dwarf2_attr (die
,
20838 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20840 if (attr
!= nullptr)
20841 sym
->set_line (attr
->constant_value (0));
20843 attr
= dwarf2_attr (die
,
20844 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20846 if (attr
!= nullptr && attr
->is_nonnegative ())
20848 file_name_index file_index
20849 = (file_name_index
) attr
->as_nonnegative ();
20850 struct file_entry
*fe
;
20852 if (cu
->line_header
!= NULL
)
20853 fe
= cu
->line_header
->file_name_at (file_index
);
20858 complaint (_("file index out of range"));
20860 sym
->set_symtab (fe
->symtab
);
20866 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20867 if (attr
!= nullptr)
20871 addr
= attr
->as_address ();
20872 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20873 sym
->set_value_address (addr
);
20874 sym
->set_aclass_index (LOC_LABEL
);
20877 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
20878 sym
->set_type (objfile_type (objfile
)->builtin_core_addr
);
20879 sym
->set_domain (LABEL_DOMAIN
);
20880 add_symbol_to_list (sym
, cu
->list_in_scope
);
20882 case DW_TAG_subprogram
:
20883 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20885 sym
->set_aclass_index (LOC_BLOCK
);
20886 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20887 if ((attr2
!= nullptr && attr2
->as_boolean ())
20888 || cu
->lang () == language_ada
20889 || cu
->lang () == language_fortran
)
20891 /* Subprograms marked external are stored as a global symbol.
20892 Ada and Fortran subprograms, whether marked external or
20893 not, are always stored as a global symbol, because we want
20894 to be able to access them globally. For instance, we want
20895 to be able to break on a nested subprogram without having
20896 to specify the context. */
20897 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20901 list_to_add
= cu
->list_in_scope
;
20904 case DW_TAG_inlined_subroutine
:
20905 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20907 sym
->set_aclass_index (LOC_BLOCK
);
20908 sym
->set_is_inlined (1);
20909 list_to_add
= cu
->list_in_scope
;
20911 case DW_TAG_template_value_param
:
20913 /* Fall through. */
20914 case DW_TAG_constant
:
20915 case DW_TAG_variable
:
20916 case DW_TAG_member
:
20917 /* Compilation with minimal debug info may result in
20918 variables with missing type entries. Change the
20919 misleading `void' type to something sensible. */
20920 if (sym
->type ()->code () == TYPE_CODE_VOID
)
20921 sym
->set_type (objfile_type (objfile
)->builtin_int
);
20923 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20924 /* In the case of DW_TAG_member, we should only be called for
20925 static const members. */
20926 if (die
->tag
== DW_TAG_member
)
20928 /* dwarf2_add_field uses die_is_declaration,
20929 so we do the same. */
20930 gdb_assert (die_is_declaration (die
, cu
));
20933 if (attr
!= nullptr)
20935 dwarf2_const_value (attr
, sym
, cu
);
20936 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20939 if (attr2
!= nullptr && attr2
->as_boolean ())
20940 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20942 list_to_add
= cu
->list_in_scope
;
20946 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20947 if (attr
!= nullptr)
20949 var_decode_location (attr
, sym
, cu
);
20950 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20952 /* Fortran explicitly imports any global symbols to the local
20953 scope by DW_TAG_common_block. */
20954 if (cu
->lang () == language_fortran
&& die
->parent
20955 && die
->parent
->tag
== DW_TAG_common_block
)
20958 if (sym
->aclass () == LOC_STATIC
20959 && sym
->value_address () == 0
20960 && !per_objfile
->per_bfd
->has_section_at_zero
)
20962 /* When a static variable is eliminated by the linker,
20963 the corresponding debug information is not stripped
20964 out, but the variable address is set to null;
20965 do not add such variables into symbol table. */
20967 else if (attr2
!= nullptr && attr2
->as_boolean ())
20969 if (sym
->aclass () == LOC_STATIC
20970 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20971 && per_objfile
->per_bfd
->can_copy
)
20973 /* A global static variable might be subject to
20974 copy relocation. We first check for a local
20975 minsym, though, because maybe the symbol was
20976 marked hidden, in which case this would not
20978 bound_minimal_symbol found
20979 = (lookup_minimal_symbol_linkage
20980 (sym
->linkage_name (), objfile
));
20981 if (found
.minsym
!= nullptr)
20982 sym
->maybe_copied
= 1;
20985 /* A variable with DW_AT_external is never static,
20986 but it may be block-scoped. */
20988 = ((cu
->list_in_scope
20989 == cu
->get_builder ()->get_file_symbols ())
20990 ? cu
->get_builder ()->get_global_symbols ()
20991 : cu
->list_in_scope
);
20994 list_to_add
= cu
->list_in_scope
;
20998 /* We do not know the address of this symbol.
20999 If it is an external symbol and we have type information
21000 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21001 The address of the variable will then be determined from
21002 the minimal symbol table whenever the variable is
21004 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21006 /* Fortran explicitly imports any global symbols to the local
21007 scope by DW_TAG_common_block. */
21008 if (cu
->lang () == language_fortran
&& die
->parent
21009 && die
->parent
->tag
== DW_TAG_common_block
)
21011 /* SYMBOL_CLASS doesn't matter here because
21012 read_common_block is going to reset it. */
21014 list_to_add
= cu
->list_in_scope
;
21016 else if (attr2
!= nullptr && attr2
->as_boolean ()
21017 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21019 /* A variable with DW_AT_external is never static, but it
21020 may be block-scoped. */
21022 = ((cu
->list_in_scope
21023 == cu
->get_builder ()->get_file_symbols ())
21024 ? cu
->get_builder ()->get_global_symbols ()
21025 : cu
->list_in_scope
);
21027 sym
->set_aclass_index (LOC_UNRESOLVED
);
21029 else if (!die_is_declaration (die
, cu
))
21031 /* Use the default LOC_OPTIMIZED_OUT class. */
21032 gdb_assert (sym
->aclass () == LOC_OPTIMIZED_OUT
);
21034 list_to_add
= cu
->list_in_scope
;
21038 case DW_TAG_formal_parameter
:
21040 /* If we are inside a function, mark this as an argument. If
21041 not, we might be looking at an argument to an inlined function
21042 when we do not have enough information to show inlined frames;
21043 pretend it's a local variable in that case so that the user can
21045 struct context_stack
*curr
21046 = cu
->get_builder ()->get_current_context_stack ();
21047 if (curr
!= nullptr && curr
->name
!= nullptr)
21048 sym
->set_is_argument (1);
21049 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21050 if (attr
!= nullptr)
21052 var_decode_location (attr
, sym
, cu
);
21054 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21055 if (attr
!= nullptr)
21057 dwarf2_const_value (attr
, sym
, cu
);
21060 list_to_add
= cu
->list_in_scope
;
21063 case DW_TAG_unspecified_parameters
:
21064 /* From varargs functions; gdb doesn't seem to have any
21065 interest in this information, so just ignore it for now.
21068 case DW_TAG_template_type_param
:
21070 /* Fall through. */
21071 case DW_TAG_class_type
:
21072 case DW_TAG_interface_type
:
21073 case DW_TAG_structure_type
:
21074 case DW_TAG_union_type
:
21075 case DW_TAG_set_type
:
21076 case DW_TAG_enumeration_type
:
21077 case DW_TAG_namelist
:
21078 if (die
->tag
== DW_TAG_namelist
)
21080 sym
->set_aclass_index (LOC_STATIC
);
21081 sym
->set_domain (VAR_DOMAIN
);
21085 sym
->set_aclass_index (LOC_TYPEDEF
);
21086 sym
->set_domain (STRUCT_DOMAIN
);
21089 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21090 really ever be static objects: otherwise, if you try
21091 to, say, break of a class's method and you're in a file
21092 which doesn't mention that class, it won't work unless
21093 the check for all static symbols in lookup_symbol_aux
21094 saves you. See the OtherFileClass tests in
21095 gdb.c++/namespace.exp. */
21099 buildsym_compunit
*builder
= cu
->get_builder ();
21101 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21102 && cu
->lang () == language_cplus
21103 ? builder
->get_global_symbols ()
21104 : cu
->list_in_scope
);
21106 /* The semantics of C++ state that "struct foo {
21107 ... }" also defines a typedef for "foo". */
21108 if (cu
->lang () == language_cplus
21109 || cu
->lang () == language_ada
21110 || cu
->lang () == language_d
21111 || cu
->lang () == language_rust
)
21113 /* The symbol's name is already allocated along
21114 with this objfile, so we don't need to
21115 duplicate it for the type. */
21116 if (sym
->type ()->name () == 0)
21117 sym
->type ()->set_name (sym
->search_name ());
21122 case DW_TAG_typedef
:
21123 sym
->set_aclass_index (LOC_TYPEDEF
);
21124 sym
->set_domain (VAR_DOMAIN
);
21125 list_to_add
= cu
->list_in_scope
;
21127 case DW_TAG_array_type
:
21128 case DW_TAG_base_type
:
21129 case DW_TAG_subrange_type
:
21130 case DW_TAG_generic_subrange
:
21131 case DW_TAG_unspecified_type
:
21132 sym
->set_aclass_index (LOC_TYPEDEF
);
21133 sym
->set_domain (VAR_DOMAIN
);
21134 list_to_add
= cu
->list_in_scope
;
21136 case DW_TAG_enumerator
:
21137 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21138 if (attr
!= nullptr)
21140 dwarf2_const_value (attr
, sym
, cu
);
21143 /* NOTE: carlton/2003-11-10: See comment above in the
21144 DW_TAG_class_type, etc. block. */
21147 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21148 && cu
->lang () == language_cplus
21149 ? cu
->get_builder ()->get_global_symbols ()
21150 : cu
->list_in_scope
);
21153 case DW_TAG_imported_declaration
:
21154 case DW_TAG_namespace
:
21155 sym
->set_aclass_index (LOC_TYPEDEF
);
21156 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21158 case DW_TAG_module
:
21159 sym
->set_aclass_index (LOC_TYPEDEF
);
21160 sym
->set_domain (MODULE_DOMAIN
);
21161 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21163 case DW_TAG_common_block
:
21164 sym
->set_aclass_index (LOC_COMMON_BLOCK
);
21165 sym
->set_domain (COMMON_BLOCK_DOMAIN
);
21166 add_symbol_to_list (sym
, cu
->list_in_scope
);
21169 /* Not a tag we recognize. Hopefully we aren't processing
21170 trash data, but since we must specifically ignore things
21171 we don't recognize, there is nothing else we should do at
21173 complaint (_("unsupported tag: '%s'"),
21174 dwarf_tag_name (die
->tag
));
21180 sym
->hash_next
= objfile
->template_symbols
;
21181 objfile
->template_symbols
= sym
;
21182 list_to_add
= NULL
;
21185 if (list_to_add
!= NULL
)
21186 add_symbol_to_list (sym
, list_to_add
);
21188 /* For the benefit of old versions of GCC, check for anonymous
21189 namespaces based on the demangled name. */
21190 if (!cu
->processing_has_namespace_info
21191 && cu
->lang () == language_cplus
)
21192 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21197 /* Given an attr with a DW_FORM_dataN value in host byte order,
21198 zero-extend it as appropriate for the symbol's type. The DWARF
21199 standard (v4) is not entirely clear about the meaning of using
21200 DW_FORM_dataN for a constant with a signed type, where the type is
21201 wider than the data. The conclusion of a discussion on the DWARF
21202 list was that this is unspecified. We choose to always zero-extend
21203 because that is the interpretation long in use by GCC. */
21206 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21207 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21209 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21210 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
.get ()) ?
21211 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21212 LONGEST l
= attr
->constant_value (0);
21214 if (bits
< sizeof (*value
) * 8)
21216 l
&= ((LONGEST
) 1 << bits
) - 1;
21219 else if (bits
== sizeof (*value
) * 8)
21223 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21224 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21231 /* Read a constant value from an attribute. Either set *VALUE, or if
21232 the value does not fit in *VALUE, set *BYTES - either already
21233 allocated on the objfile obstack, or newly allocated on OBSTACK,
21234 or, set *BATON, if we translated the constant to a location
21238 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21239 const char *name
, struct obstack
*obstack
,
21240 struct dwarf2_cu
*cu
,
21241 LONGEST
*value
, const gdb_byte
**bytes
,
21242 struct dwarf2_locexpr_baton
**baton
)
21244 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21245 struct objfile
*objfile
= per_objfile
->objfile
;
21246 struct comp_unit_head
*cu_header
= &cu
->header
;
21247 struct dwarf_block
*blk
;
21248 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
.get ()) ?
21249 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21255 switch (attr
->form
)
21258 case DW_FORM_addrx
:
21259 case DW_FORM_GNU_addr_index
:
21263 if (type
->length () != cu_header
->addr_size
)
21264 dwarf2_const_value_length_mismatch_complaint (name
,
21265 cu_header
->addr_size
,
21267 /* Symbols of this form are reasonably rare, so we just
21268 piggyback on the existing location code rather than writing
21269 a new implementation of symbol_computed_ops. */
21270 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21271 (*baton
)->per_objfile
= per_objfile
;
21272 (*baton
)->per_cu
= cu
->per_cu
;
21273 gdb_assert ((*baton
)->per_cu
);
21275 (*baton
)->size
= 2 + cu_header
->addr_size
;
21276 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21277 (*baton
)->data
= data
;
21279 data
[0] = DW_OP_addr
;
21280 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21281 byte_order
, attr
->as_address ());
21282 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21285 case DW_FORM_string
:
21288 case DW_FORM_GNU_str_index
:
21289 case DW_FORM_GNU_strp_alt
:
21290 /* The string is already allocated on the objfile obstack, point
21292 *bytes
= (const gdb_byte
*) attr
->as_string ();
21294 case DW_FORM_block1
:
21295 case DW_FORM_block2
:
21296 case DW_FORM_block4
:
21297 case DW_FORM_block
:
21298 case DW_FORM_exprloc
:
21299 case DW_FORM_data16
:
21300 blk
= attr
->as_block ();
21301 if (type
->length () != blk
->size
)
21302 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21304 *bytes
= blk
->data
;
21307 /* The DW_AT_const_value attributes are supposed to carry the
21308 symbol's value "represented as it would be on the target
21309 architecture." By the time we get here, it's already been
21310 converted to host endianness, so we just need to sign- or
21311 zero-extend it as appropriate. */
21312 case DW_FORM_data1
:
21313 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21315 case DW_FORM_data2
:
21316 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21318 case DW_FORM_data4
:
21319 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21321 case DW_FORM_data8
:
21322 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21325 case DW_FORM_sdata
:
21326 case DW_FORM_implicit_const
:
21327 *value
= attr
->as_signed ();
21330 case DW_FORM_udata
:
21331 *value
= attr
->as_unsigned ();
21335 complaint (_("unsupported const value attribute form: '%s'"),
21336 dwarf_form_name (attr
->form
));
21343 /* Copy constant value from an attribute to a symbol. */
21346 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21347 struct dwarf2_cu
*cu
)
21349 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21351 const gdb_byte
*bytes
;
21352 struct dwarf2_locexpr_baton
*baton
;
21354 dwarf2_const_value_attr (attr
, sym
->type (),
21355 sym
->print_name (),
21356 &objfile
->objfile_obstack
, cu
,
21357 &value
, &bytes
, &baton
);
21361 SYMBOL_LOCATION_BATON (sym
) = baton
;
21362 sym
->set_aclass_index (dwarf2_locexpr_index
);
21364 else if (bytes
!= NULL
)
21366 sym
->set_value_bytes (bytes
);
21367 sym
->set_aclass_index (LOC_CONST_BYTES
);
21371 sym
->set_value_longest (value
);
21372 sym
->set_aclass_index (LOC_CONST
);
21376 /* Return the type of the die in question using its DW_AT_type attribute. */
21378 static struct type
*
21379 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21381 struct attribute
*type_attr
;
21383 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21386 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21387 /* A missing DW_AT_type represents a void type. */
21388 return objfile_type (objfile
)->builtin_void
;
21391 return lookup_die_type (die
, type_attr
, cu
);
21394 /* True iff CU's producer generates GNAT Ada auxiliary information
21395 that allows to find parallel types through that information instead
21396 of having to do expensive parallel lookups by type name. */
21399 need_gnat_info (struct dwarf2_cu
*cu
)
21401 /* Assume that the Ada compiler was GNAT, which always produces
21402 the auxiliary information. */
21403 return (cu
->lang () == language_ada
);
21406 /* Return the auxiliary type of the die in question using its
21407 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21408 attribute is not present. */
21410 static struct type
*
21411 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21413 struct attribute
*type_attr
;
21415 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21419 return lookup_die_type (die
, type_attr
, cu
);
21422 /* If DIE has a descriptive_type attribute, then set the TYPE's
21423 descriptive type accordingly. */
21426 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21427 struct dwarf2_cu
*cu
)
21429 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21431 if (descriptive_type
)
21433 ALLOCATE_GNAT_AUX_TYPE (type
);
21434 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21438 /* Return the containing type of the die in question using its
21439 DW_AT_containing_type attribute. */
21441 static struct type
*
21442 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21444 struct attribute
*type_attr
;
21445 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21447 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21449 error (_("Dwarf Error: Problem turning containing type into gdb type "
21450 "[in module %s]"), objfile_name (objfile
));
21452 return lookup_die_type (die
, type_attr
, cu
);
21455 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21457 static struct type
*
21458 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21460 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21461 struct objfile
*objfile
= per_objfile
->objfile
;
21464 std::string message
21465 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21466 objfile_name (objfile
),
21467 sect_offset_str (cu
->header
.sect_off
),
21468 sect_offset_str (die
->sect_off
));
21469 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21471 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21474 /* Look up the type of DIE in CU using its type attribute ATTR.
21475 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21476 DW_AT_containing_type.
21477 If there is no type substitute an error marker. */
21479 static struct type
*
21480 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21481 struct dwarf2_cu
*cu
)
21483 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21484 struct objfile
*objfile
= per_objfile
->objfile
;
21485 struct type
*this_type
;
21487 gdb_assert (attr
->name
== DW_AT_type
21488 || attr
->name
== DW_AT_GNAT_descriptive_type
21489 || attr
->name
== DW_AT_containing_type
);
21491 /* First see if we have it cached. */
21493 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21495 struct dwarf2_per_cu_data
*per_cu
;
21496 sect_offset sect_off
= attr
->get_ref_die_offset ();
21498 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21499 per_objfile
->per_bfd
);
21500 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
21502 else if (attr
->form_is_ref ())
21504 sect_offset sect_off
= attr
->get_ref_die_offset ();
21506 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
21508 else if (attr
->form
== DW_FORM_ref_sig8
)
21510 ULONGEST signature
= attr
->as_signature ();
21512 return get_signatured_type (die
, signature
, cu
);
21516 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21517 " at %s [in module %s]"),
21518 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21519 objfile_name (objfile
));
21520 return build_error_marker_type (cu
, die
);
21523 /* If not cached we need to read it in. */
21525 if (this_type
== NULL
)
21527 struct die_info
*type_die
= NULL
;
21528 struct dwarf2_cu
*type_cu
= cu
;
21530 if (attr
->form_is_ref ())
21531 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21532 if (type_die
== NULL
)
21533 return build_error_marker_type (cu
, die
);
21534 /* If we find the type now, it's probably because the type came
21535 from an inter-CU reference and the type's CU got expanded before
21537 this_type
= read_type_die (type_die
, type_cu
);
21540 /* If we still don't have a type use an error marker. */
21542 if (this_type
== NULL
)
21543 return build_error_marker_type (cu
, die
);
21548 /* Return the type in DIE, CU.
21549 Returns NULL for invalid types.
21551 This first does a lookup in die_type_hash,
21552 and only reads the die in if necessary.
21554 NOTE: This can be called when reading in partial or full symbols. */
21556 static struct type
*
21557 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21559 struct type
*this_type
;
21561 this_type
= get_die_type (die
, cu
);
21565 return read_type_die_1 (die
, cu
);
21568 /* Read the type in DIE, CU.
21569 Returns NULL for invalid types. */
21571 static struct type
*
21572 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21574 struct type
*this_type
= NULL
;
21578 case DW_TAG_class_type
:
21579 case DW_TAG_interface_type
:
21580 case DW_TAG_structure_type
:
21581 case DW_TAG_union_type
:
21582 this_type
= read_structure_type (die
, cu
);
21584 case DW_TAG_enumeration_type
:
21585 this_type
= read_enumeration_type (die
, cu
);
21587 case DW_TAG_subprogram
:
21588 case DW_TAG_subroutine_type
:
21589 case DW_TAG_inlined_subroutine
:
21590 this_type
= read_subroutine_type (die
, cu
);
21592 case DW_TAG_array_type
:
21593 this_type
= read_array_type (die
, cu
);
21595 case DW_TAG_set_type
:
21596 this_type
= read_set_type (die
, cu
);
21598 case DW_TAG_pointer_type
:
21599 this_type
= read_tag_pointer_type (die
, cu
);
21601 case DW_TAG_ptr_to_member_type
:
21602 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21604 case DW_TAG_reference_type
:
21605 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21607 case DW_TAG_rvalue_reference_type
:
21608 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21610 case DW_TAG_const_type
:
21611 this_type
= read_tag_const_type (die
, cu
);
21613 case DW_TAG_volatile_type
:
21614 this_type
= read_tag_volatile_type (die
, cu
);
21616 case DW_TAG_restrict_type
:
21617 this_type
= read_tag_restrict_type (die
, cu
);
21619 case DW_TAG_string_type
:
21620 this_type
= read_tag_string_type (die
, cu
);
21622 case DW_TAG_typedef
:
21623 this_type
= read_typedef (die
, cu
);
21625 case DW_TAG_generic_subrange
:
21626 case DW_TAG_subrange_type
:
21627 this_type
= read_subrange_type (die
, cu
);
21629 case DW_TAG_base_type
:
21630 this_type
= read_base_type (die
, cu
);
21632 case DW_TAG_unspecified_type
:
21633 this_type
= read_unspecified_type (die
, cu
);
21635 case DW_TAG_namespace
:
21636 this_type
= read_namespace_type (die
, cu
);
21638 case DW_TAG_module
:
21639 this_type
= read_module_type (die
, cu
);
21641 case DW_TAG_atomic_type
:
21642 this_type
= read_tag_atomic_type (die
, cu
);
21645 complaint (_("unexpected tag in read_type_die: '%s'"),
21646 dwarf_tag_name (die
->tag
));
21653 /* See if we can figure out if the class lives in a namespace. We do
21654 this by looking for a member function; its demangled name will
21655 contain namespace info, if there is any.
21656 Return the computed name or NULL.
21657 Space for the result is allocated on the objfile's obstack.
21658 This is the full-die version of guess_partial_die_structure_name.
21659 In this case we know DIE has no useful parent. */
21661 static const char *
21662 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21664 struct die_info
*spec_die
;
21665 struct dwarf2_cu
*spec_cu
;
21666 struct die_info
*child
;
21667 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21670 spec_die
= die_specification (die
, &spec_cu
);
21671 if (spec_die
!= NULL
)
21677 for (child
= die
->child
;
21679 child
= child
->sibling
)
21681 if (child
->tag
== DW_TAG_subprogram
)
21683 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21685 if (linkage_name
!= NULL
)
21687 gdb::unique_xmalloc_ptr
<char> actual_name
21688 (cu
->language_defn
->class_name_from_physname (linkage_name
));
21689 const char *name
= NULL
;
21691 if (actual_name
!= NULL
)
21693 const char *die_name
= dwarf2_name (die
, cu
);
21695 if (die_name
!= NULL
21696 && strcmp (die_name
, actual_name
.get ()) != 0)
21698 /* Strip off the class name from the full name.
21699 We want the prefix. */
21700 int die_name_len
= strlen (die_name
);
21701 int actual_name_len
= strlen (actual_name
.get ());
21702 const char *ptr
= actual_name
.get ();
21704 /* Test for '::' as a sanity check. */
21705 if (actual_name_len
> die_name_len
+ 2
21706 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21707 name
= obstack_strndup (
21708 &objfile
->per_bfd
->storage_obstack
,
21709 ptr
, actual_name_len
- die_name_len
- 2);
21720 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21721 prefix part in such case. See
21722 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21724 static const char *
21725 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21727 struct attribute
*attr
;
21730 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21731 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21734 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21737 attr
= dw2_linkage_name_attr (die
, cu
);
21738 const char *attr_name
= attr
->as_string ();
21739 if (attr
== NULL
|| attr_name
== NULL
)
21742 /* dwarf2_name had to be already called. */
21743 gdb_assert (attr
->canonical_string_p ());
21745 /* Strip the base name, keep any leading namespaces/classes. */
21746 base
= strrchr (attr_name
, ':');
21747 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
21750 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21751 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21753 &base
[-1] - attr_name
);
21756 /* Return the name of the namespace/class that DIE is defined within,
21757 or "" if we can't tell. The caller should not xfree the result.
21759 For example, if we're within the method foo() in the following
21769 then determine_prefix on foo's die will return "N::C". */
21771 static const char *
21772 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21774 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21775 struct die_info
*parent
, *spec_die
;
21776 struct dwarf2_cu
*spec_cu
;
21777 struct type
*parent_type
;
21778 const char *retval
;
21780 if (cu
->lang () != language_cplus
21781 && cu
->lang () != language_fortran
21782 && cu
->lang () != language_d
21783 && cu
->lang () != language_rust
)
21786 retval
= anonymous_struct_prefix (die
, cu
);
21790 /* We have to be careful in the presence of DW_AT_specification.
21791 For example, with GCC 3.4, given the code
21795 // Definition of N::foo.
21799 then we'll have a tree of DIEs like this:
21801 1: DW_TAG_compile_unit
21802 2: DW_TAG_namespace // N
21803 3: DW_TAG_subprogram // declaration of N::foo
21804 4: DW_TAG_subprogram // definition of N::foo
21805 DW_AT_specification // refers to die #3
21807 Thus, when processing die #4, we have to pretend that we're in
21808 the context of its DW_AT_specification, namely the contex of die
21811 spec_die
= die_specification (die
, &spec_cu
);
21812 if (spec_die
== NULL
)
21813 parent
= die
->parent
;
21816 parent
= spec_die
->parent
;
21820 if (parent
== NULL
)
21822 else if (parent
->building_fullname
)
21825 const char *parent_name
;
21827 /* It has been seen on RealView 2.2 built binaries,
21828 DW_TAG_template_type_param types actually _defined_ as
21829 children of the parent class:
21832 template class <class Enum> Class{};
21833 Class<enum E> class_e;
21835 1: DW_TAG_class_type (Class)
21836 2: DW_TAG_enumeration_type (E)
21837 3: DW_TAG_enumerator (enum1:0)
21838 3: DW_TAG_enumerator (enum2:1)
21840 2: DW_TAG_template_type_param
21841 DW_AT_type DW_FORM_ref_udata (E)
21843 Besides being broken debug info, it can put GDB into an
21844 infinite loop. Consider:
21846 When we're building the full name for Class<E>, we'll start
21847 at Class, and go look over its template type parameters,
21848 finding E. We'll then try to build the full name of E, and
21849 reach here. We're now trying to build the full name of E,
21850 and look over the parent DIE for containing scope. In the
21851 broken case, if we followed the parent DIE of E, we'd again
21852 find Class, and once again go look at its template type
21853 arguments, etc., etc. Simply don't consider such parent die
21854 as source-level parent of this die (it can't be, the language
21855 doesn't allow it), and break the loop here. */
21856 name
= dwarf2_name (die
, cu
);
21857 parent_name
= dwarf2_name (parent
, cu
);
21858 complaint (_("template param type '%s' defined within parent '%s'"),
21859 name
? name
: "<unknown>",
21860 parent_name
? parent_name
: "<unknown>");
21864 switch (parent
->tag
)
21866 case DW_TAG_namespace
:
21867 parent_type
= read_type_die (parent
, cu
);
21868 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21869 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21870 Work around this problem here. */
21871 if (cu
->lang () == language_cplus
21872 && strcmp (parent_type
->name (), "::") == 0)
21874 /* We give a name to even anonymous namespaces. */
21875 return parent_type
->name ();
21876 case DW_TAG_class_type
:
21877 case DW_TAG_interface_type
:
21878 case DW_TAG_structure_type
:
21879 case DW_TAG_union_type
:
21880 case DW_TAG_module
:
21881 parent_type
= read_type_die (parent
, cu
);
21882 if (parent_type
->name () != NULL
)
21883 return parent_type
->name ();
21885 /* An anonymous structure is only allowed non-static data
21886 members; no typedefs, no member functions, et cetera.
21887 So it does not need a prefix. */
21889 case DW_TAG_compile_unit
:
21890 case DW_TAG_partial_unit
:
21891 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21892 if (cu
->lang () == language_cplus
21893 && !per_objfile
->per_bfd
->types
.empty ()
21894 && die
->child
!= NULL
21895 && (die
->tag
== DW_TAG_class_type
21896 || die
->tag
== DW_TAG_structure_type
21897 || die
->tag
== DW_TAG_union_type
))
21899 const char *name
= guess_full_die_structure_name (die
, cu
);
21904 case DW_TAG_subprogram
:
21905 /* Nested subroutines in Fortran get a prefix with the name
21906 of the parent's subroutine. */
21907 if (cu
->lang () == language_fortran
)
21909 if ((die
->tag
== DW_TAG_subprogram
)
21910 && (dwarf2_name (parent
, cu
) != NULL
))
21911 return dwarf2_name (parent
, cu
);
21914 case DW_TAG_enumeration_type
:
21915 parent_type
= read_type_die (parent
, cu
);
21916 if (parent_type
->is_declared_class ())
21918 if (parent_type
->name () != NULL
)
21919 return parent_type
->name ();
21922 /* Fall through. */
21924 return determine_prefix (parent
, cu
);
21928 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21929 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21930 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21931 an obconcat, otherwise allocate storage for the result. The CU argument is
21932 used to determine the language and hence, the appropriate separator. */
21934 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21937 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21938 int physname
, struct dwarf2_cu
*cu
)
21940 const char *lead
= "";
21943 if (suffix
== NULL
|| suffix
[0] == '\0'
21944 || prefix
== NULL
|| prefix
[0] == '\0')
21946 else if (cu
->lang () == language_d
)
21948 /* For D, the 'main' function could be defined in any module, but it
21949 should never be prefixed. */
21950 if (strcmp (suffix
, "D main") == 0)
21958 else if (cu
->lang () == language_fortran
&& physname
)
21960 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21961 DW_AT_MIPS_linkage_name is preferred and used instead. */
21969 if (prefix
== NULL
)
21971 if (suffix
== NULL
)
21978 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21980 strcpy (retval
, lead
);
21981 strcat (retval
, prefix
);
21982 strcat (retval
, sep
);
21983 strcat (retval
, suffix
);
21988 /* We have an obstack. */
21989 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21993 /* Return a generic name for a DW_TAG_template_type_param or
21994 DW_TAG_template_value_param tag, missing a DW_AT_name attribute. We do this
21995 per parent, so each function/class/struct template will have their own set
21996 of template parameters named <unnnamed0>, <unnamed1>, ... where the
21997 enumeration starts at 0 and represents the position of the template tag in
21998 the list of unnamed template tags for this parent, counting both, type and
22001 static const char *
22002 unnamed_template_tag_name (die_info
*die
, dwarf2_cu
*cu
)
22004 if (die
->parent
== nullptr)
22007 /* Count the parent types unnamed template type and value children until, we
22008 arrive at our entry. */
22009 size_t nth_unnamed
= 0;
22011 die_info
*child
= die
->parent
->child
;
22012 while (child
!= die
)
22014 gdb_assert (child
!= nullptr);
22015 if (child
->tag
== DW_TAG_template_type_param
22016 || child
->tag
== DW_TAG_template_value_param
)
22018 if (dwarf2_attr (child
, DW_AT_name
, cu
) == nullptr)
22021 child
= child
->sibling
;
22024 const std::string name_str
= "<unnamed" + std::to_string (nth_unnamed
) + ">";
22025 return cu
->per_objfile
->objfile
->intern (name_str
.c_str ());
22028 /* Get name of a die, return NULL if not found. */
22030 static const char *
22031 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22032 struct objfile
*objfile
)
22034 if (name
== nullptr)
22037 if (cu
->lang () == language_cplus
)
22039 gdb::unique_xmalloc_ptr
<char> canon_name
22040 = cp_canonicalize_string (name
);
22042 if (canon_name
!= nullptr)
22043 name
= objfile
->intern (canon_name
.get ());
22045 else if (cu
->lang () == language_c
)
22047 gdb::unique_xmalloc_ptr
<char> canon_name
22048 = c_canonicalize_name (name
);
22050 if (canon_name
!= nullptr)
22051 name
= objfile
->intern (canon_name
.get ());
22057 /* Get name of a die, return NULL if not found.
22058 Anonymous namespaces are converted to their magic string. */
22060 static const char *
22061 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22063 struct attribute
*attr
;
22064 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22066 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22067 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22068 if (attr_name
== nullptr
22069 && die
->tag
!= DW_TAG_namespace
22070 && die
->tag
!= DW_TAG_class_type
22071 && die
->tag
!= DW_TAG_interface_type
22072 && die
->tag
!= DW_TAG_structure_type
22073 && die
->tag
!= DW_TAG_namelist
22074 && die
->tag
!= DW_TAG_union_type
22075 && die
->tag
!= DW_TAG_template_type_param
22076 && die
->tag
!= DW_TAG_template_value_param
)
22081 /* A member's name should not be canonicalized. This is a bit
22082 of a hack, in that normally it should not be possible to run
22083 into this situation; however, the dw2-unusual-field-names.exp
22084 test creates custom DWARF that does. */
22085 case DW_TAG_member
:
22086 case DW_TAG_compile_unit
:
22087 case DW_TAG_partial_unit
:
22088 /* Compilation units have a DW_AT_name that is a filename, not
22089 a source language identifier. */
22090 case DW_TAG_enumeration_type
:
22091 case DW_TAG_enumerator
:
22092 /* These tags always have simple identifiers already; no need
22093 to canonicalize them. */
22096 case DW_TAG_namespace
:
22097 if (attr_name
!= nullptr)
22099 return CP_ANONYMOUS_NAMESPACE_STR
;
22101 /* DWARF does not actually require template tags to have a name. */
22102 case DW_TAG_template_type_param
:
22103 case DW_TAG_template_value_param
:
22104 if (attr_name
== nullptr)
22105 return unnamed_template_tag_name (die
, cu
);
22107 case DW_TAG_class_type
:
22108 case DW_TAG_interface_type
:
22109 case DW_TAG_structure_type
:
22110 case DW_TAG_union_type
:
22111 case DW_TAG_namelist
:
22112 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22113 structures or unions. These were of the form "._%d" in GCC 4.1,
22114 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22115 and GCC 4.4. We work around this problem by ignoring these. */
22116 if (attr_name
!= nullptr
22117 && (startswith (attr_name
, "._")
22118 || startswith (attr_name
, "<anonymous")))
22121 /* GCC might emit a nameless typedef that has a linkage name. See
22122 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22123 if (!attr
|| attr_name
== NULL
)
22125 attr
= dw2_linkage_name_attr (die
, cu
);
22126 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22127 if (attr
== NULL
|| attr_name
== NULL
)
22130 /* Avoid demangling attr_name the second time on a second
22131 call for the same DIE. */
22132 if (!attr
->canonical_string_p ())
22134 gdb::unique_xmalloc_ptr
<char> demangled
22135 (gdb_demangle (attr_name
, DMGL_TYPES
));
22136 if (demangled
== nullptr)
22139 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22140 attr_name
= attr
->as_string ();
22143 /* Strip any leading namespaces/classes, keep only the
22144 base name. DW_AT_name for named DIEs does not
22145 contain the prefixes. */
22146 const char *base
= strrchr (attr_name
, ':');
22147 if (base
&& base
> attr_name
&& base
[-1] == ':')
22158 if (!attr
->canonical_string_p ())
22159 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22161 return attr
->as_string ();
22164 /* Return the die that this die in an extension of, or NULL if there
22165 is none. *EXT_CU is the CU containing DIE on input, and the CU
22166 containing the return value on output. */
22168 static struct die_info
*
22169 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22171 struct attribute
*attr
;
22173 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22177 return follow_die_ref (die
, attr
, ext_cu
);
22181 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22185 gdb_printf (f
, "%*sDie: %s (abbrev %d, offset %s)\n",
22187 dwarf_tag_name (die
->tag
), die
->abbrev
,
22188 sect_offset_str (die
->sect_off
));
22190 if (die
->parent
!= NULL
)
22191 gdb_printf (f
, "%*s parent at offset: %s\n",
22193 sect_offset_str (die
->parent
->sect_off
));
22195 gdb_printf (f
, "%*s has children: %s\n",
22197 dwarf_bool_name (die
->child
!= NULL
));
22199 gdb_printf (f
, "%*s attributes:\n", indent
, "");
22201 for (i
= 0; i
< die
->num_attrs
; ++i
)
22203 gdb_printf (f
, "%*s %s (%s) ",
22205 dwarf_attr_name (die
->attrs
[i
].name
),
22206 dwarf_form_name (die
->attrs
[i
].form
));
22208 switch (die
->attrs
[i
].form
)
22211 case DW_FORM_addrx
:
22212 case DW_FORM_GNU_addr_index
:
22213 gdb_printf (f
, "address: ");
22214 gdb_puts (hex_string (die
->attrs
[i
].as_address ()), f
);
22216 case DW_FORM_block2
:
22217 case DW_FORM_block4
:
22218 case DW_FORM_block
:
22219 case DW_FORM_block1
:
22220 gdb_printf (f
, "block: size %s",
22221 pulongest (die
->attrs
[i
].as_block ()->size
));
22223 case DW_FORM_exprloc
:
22224 gdb_printf (f
, "expression: size %s",
22225 pulongest (die
->attrs
[i
].as_block ()->size
));
22227 case DW_FORM_data16
:
22228 gdb_printf (f
, "constant of 16 bytes");
22230 case DW_FORM_ref_addr
:
22231 gdb_printf (f
, "ref address: ");
22232 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22234 case DW_FORM_GNU_ref_alt
:
22235 gdb_printf (f
, "alt ref address: ");
22236 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22242 case DW_FORM_ref_udata
:
22243 gdb_printf (f
, "constant ref: 0x%lx (adjusted)",
22244 (long) (die
->attrs
[i
].as_unsigned ()));
22246 case DW_FORM_data1
:
22247 case DW_FORM_data2
:
22248 case DW_FORM_data4
:
22249 case DW_FORM_data8
:
22250 case DW_FORM_udata
:
22251 gdb_printf (f
, "constant: %s",
22252 pulongest (die
->attrs
[i
].as_unsigned ()));
22254 case DW_FORM_sec_offset
:
22255 gdb_printf (f
, "section offset: %s",
22256 pulongest (die
->attrs
[i
].as_unsigned ()));
22258 case DW_FORM_ref_sig8
:
22259 gdb_printf (f
, "signature: %s",
22260 hex_string (die
->attrs
[i
].as_signature ()));
22262 case DW_FORM_string
:
22264 case DW_FORM_line_strp
:
22266 case DW_FORM_GNU_str_index
:
22267 case DW_FORM_GNU_strp_alt
:
22268 gdb_printf (f
, "string: \"%s\" (%s canonicalized)",
22269 die
->attrs
[i
].as_string ()
22270 ? die
->attrs
[i
].as_string () : "",
22271 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
22274 if (die
->attrs
[i
].as_boolean ())
22275 gdb_printf (f
, "flag: TRUE");
22277 gdb_printf (f
, "flag: FALSE");
22279 case DW_FORM_flag_present
:
22280 gdb_printf (f
, "flag: TRUE");
22282 case DW_FORM_indirect
:
22283 /* The reader will have reduced the indirect form to
22284 the "base form" so this form should not occur. */
22286 "unexpected attribute form: DW_FORM_indirect");
22288 case DW_FORM_sdata
:
22289 case DW_FORM_implicit_const
:
22290 gdb_printf (f
, "constant: %s",
22291 plongest (die
->attrs
[i
].as_signed ()));
22294 gdb_printf (f
, "unsupported attribute form: %d.",
22295 die
->attrs
[i
].form
);
22298 gdb_printf (f
, "\n");
22303 dump_die_for_error (struct die_info
*die
)
22305 dump_die_shallow (gdb_stderr
, 0, die
);
22309 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22311 int indent
= level
* 4;
22313 gdb_assert (die
!= NULL
);
22315 if (level
>= max_level
)
22318 dump_die_shallow (f
, indent
, die
);
22320 if (die
->child
!= NULL
)
22322 gdb_printf (f
, "%*s Children:", indent
, "");
22323 if (level
+ 1 < max_level
)
22325 gdb_printf (f
, "\n");
22326 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22331 " [not printed, max nesting level reached]\n");
22335 if (die
->sibling
!= NULL
&& level
> 0)
22337 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22341 /* This is called from the pdie macro in gdbinit.in.
22342 It's not static so gcc will keep a copy callable from gdb. */
22345 dump_die (struct die_info
*die
, int max_level
)
22347 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22351 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22355 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22356 to_underlying (die
->sect_off
),
22362 /* Follow reference or signature attribute ATTR of SRC_DIE.
22363 On entry *REF_CU is the CU of SRC_DIE.
22364 On exit *REF_CU is the CU of the result. */
22366 static struct die_info
*
22367 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22368 struct dwarf2_cu
**ref_cu
)
22370 struct die_info
*die
;
22372 if (attr
->form_is_ref ())
22373 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22374 else if (attr
->form
== DW_FORM_ref_sig8
)
22375 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22378 dump_die_for_error (src_die
);
22379 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22380 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22386 /* Follow reference OFFSET.
22387 On entry *REF_CU is the CU of the source die referencing OFFSET.
22388 On exit *REF_CU is the CU of the result.
22389 Returns NULL if OFFSET is invalid. */
22391 static struct die_info
*
22392 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22393 struct dwarf2_cu
**ref_cu
)
22395 struct die_info temp_die
;
22396 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22397 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22399 gdb_assert (cu
->per_cu
!= NULL
);
22403 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
22404 "source CU contains target offset: %d",
22405 sect_offset_str (cu
->per_cu
->sect_off
),
22406 sect_offset_str (sect_off
),
22407 cu
->header
.offset_in_cu_p (sect_off
));
22409 if (cu
->per_cu
->is_debug_types
)
22411 /* .debug_types CUs cannot reference anything outside their CU.
22412 If they need to, they have to reference a signatured type via
22413 DW_FORM_ref_sig8. */
22414 if (!cu
->header
.offset_in_cu_p (sect_off
))
22417 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22418 || !cu
->header
.offset_in_cu_p (sect_off
))
22420 struct dwarf2_per_cu_data
*per_cu
;
22422 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22423 per_objfile
->per_bfd
);
22425 dwarf_read_debug_printf_v ("target CU offset: %s, "
22426 "target CU DIEs loaded: %d",
22427 sect_offset_str (per_cu
->sect_off
),
22428 per_objfile
->get_cu (per_cu
) != nullptr);
22430 /* If necessary, add it to the queue and load its DIEs.
22432 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
22433 it doesn't mean they are currently loaded. Since we require them
22434 to be loaded, we must check for ourselves. */
22435 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->lang ())
22436 || per_objfile
->get_cu (per_cu
) == nullptr)
22437 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
22438 false, cu
->lang ());
22440 target_cu
= per_objfile
->get_cu (per_cu
);
22441 gdb_assert (target_cu
!= nullptr);
22443 else if (cu
->dies
== NULL
)
22445 /* We're loading full DIEs during partial symbol reading. */
22446 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
22450 *ref_cu
= target_cu
;
22451 temp_die
.sect_off
= sect_off
;
22453 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22455 to_underlying (sect_off
));
22458 /* Follow reference attribute ATTR of SRC_DIE.
22459 On entry *REF_CU is the CU of SRC_DIE.
22460 On exit *REF_CU is the CU of the result. */
22462 static struct die_info
*
22463 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22464 struct dwarf2_cu
**ref_cu
)
22466 sect_offset sect_off
= attr
->get_ref_die_offset ();
22467 struct dwarf2_cu
*cu
= *ref_cu
;
22468 struct die_info
*die
;
22470 die
= follow_die_offset (sect_off
,
22471 (attr
->form
== DW_FORM_GNU_ref_alt
22472 || cu
->per_cu
->is_dwz
),
22475 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22476 "at %s [in module %s]"),
22477 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22478 objfile_name (cu
->per_objfile
->objfile
));
22485 struct dwarf2_locexpr_baton
22486 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22487 dwarf2_per_cu_data
*per_cu
,
22488 dwarf2_per_objfile
*per_objfile
,
22489 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
22490 bool resolve_abstract_p
)
22492 struct die_info
*die
;
22493 struct attribute
*attr
;
22494 struct dwarf2_locexpr_baton retval
;
22495 struct objfile
*objfile
= per_objfile
->objfile
;
22497 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22499 cu
= load_cu (per_cu
, per_objfile
, false);
22503 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22504 Instead just throw an error, not much else we can do. */
22505 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22506 sect_offset_str (sect_off
), objfile_name (objfile
));
22509 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22511 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22512 sect_offset_str (sect_off
), objfile_name (objfile
));
22514 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22515 if (!attr
&& resolve_abstract_p
22516 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22517 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22519 CORE_ADDR pc
= get_frame_pc ();
22520 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22521 struct gdbarch
*gdbarch
= objfile
->arch ();
22523 for (const auto &cand_off
22524 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22526 struct dwarf2_cu
*cand_cu
= cu
;
22527 struct die_info
*cand
22528 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22531 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22534 CORE_ADDR pc_low
, pc_high
;
22535 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22536 if (pc_low
== ((CORE_ADDR
) -1))
22538 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22539 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22540 if (!(pc_low
<= pc
&& pc
< pc_high
))
22544 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22551 /* DWARF: "If there is no such attribute, then there is no effect.".
22552 DATA is ignored if SIZE is 0. */
22554 retval
.data
= NULL
;
22557 else if (attr
->form_is_section_offset ())
22559 struct dwarf2_loclist_baton loclist_baton
;
22560 CORE_ADDR pc
= get_frame_pc ();
22563 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22565 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22567 retval
.size
= size
;
22571 if (!attr
->form_is_block ())
22572 error (_("Dwarf Error: DIE at %s referenced in module %s "
22573 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22574 sect_offset_str (sect_off
), objfile_name (objfile
));
22576 struct dwarf_block
*block
= attr
->as_block ();
22577 retval
.data
= block
->data
;
22578 retval
.size
= block
->size
;
22580 retval
.per_objfile
= per_objfile
;
22581 retval
.per_cu
= cu
->per_cu
;
22583 per_objfile
->age_comp_units ();
22590 struct dwarf2_locexpr_baton
22591 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22592 dwarf2_per_cu_data
*per_cu
,
22593 dwarf2_per_objfile
*per_objfile
,
22594 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
22596 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22598 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22602 /* Write a constant of a given type as target-ordered bytes into
22605 static const gdb_byte
*
22606 write_constant_as_bytes (struct obstack
*obstack
,
22607 enum bfd_endian byte_order
,
22614 *len
= type
->length ();
22615 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22616 store_unsigned_integer (result
, *len
, byte_order
, value
);
22624 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22625 dwarf2_per_cu_data
*per_cu
,
22626 dwarf2_per_objfile
*per_objfile
,
22630 struct die_info
*die
;
22631 struct attribute
*attr
;
22632 const gdb_byte
*result
= NULL
;
22635 enum bfd_endian byte_order
;
22636 struct objfile
*objfile
= per_objfile
->objfile
;
22638 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22640 cu
= load_cu (per_cu
, per_objfile
, false);
22644 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22645 Instead just throw an error, not much else we can do. */
22646 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22647 sect_offset_str (sect_off
), objfile_name (objfile
));
22650 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22652 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22653 sect_offset_str (sect_off
), objfile_name (objfile
));
22655 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22659 byte_order
= (bfd_big_endian (objfile
->obfd
.get ())
22660 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22662 switch (attr
->form
)
22665 case DW_FORM_addrx
:
22666 case DW_FORM_GNU_addr_index
:
22670 *len
= cu
->header
.addr_size
;
22671 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22672 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
22676 case DW_FORM_string
:
22679 case DW_FORM_GNU_str_index
:
22680 case DW_FORM_GNU_strp_alt
:
22681 /* The string is already allocated on the objfile obstack, point
22684 const char *attr_name
= attr
->as_string ();
22685 result
= (const gdb_byte
*) attr_name
;
22686 *len
= strlen (attr_name
);
22689 case DW_FORM_block1
:
22690 case DW_FORM_block2
:
22691 case DW_FORM_block4
:
22692 case DW_FORM_block
:
22693 case DW_FORM_exprloc
:
22694 case DW_FORM_data16
:
22696 struct dwarf_block
*block
= attr
->as_block ();
22697 result
= block
->data
;
22698 *len
= block
->size
;
22702 /* The DW_AT_const_value attributes are supposed to carry the
22703 symbol's value "represented as it would be on the target
22704 architecture." By the time we get here, it's already been
22705 converted to host endianness, so we just need to sign- or
22706 zero-extend it as appropriate. */
22707 case DW_FORM_data1
:
22708 type
= die_type (die
, cu
);
22709 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22710 if (result
== NULL
)
22711 result
= write_constant_as_bytes (obstack
, byte_order
,
22714 case DW_FORM_data2
:
22715 type
= die_type (die
, cu
);
22716 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22717 if (result
== NULL
)
22718 result
= write_constant_as_bytes (obstack
, byte_order
,
22721 case DW_FORM_data4
:
22722 type
= die_type (die
, cu
);
22723 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22724 if (result
== NULL
)
22725 result
= write_constant_as_bytes (obstack
, byte_order
,
22728 case DW_FORM_data8
:
22729 type
= die_type (die
, cu
);
22730 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22731 if (result
== NULL
)
22732 result
= write_constant_as_bytes (obstack
, byte_order
,
22736 case DW_FORM_sdata
:
22737 case DW_FORM_implicit_const
:
22738 type
= die_type (die
, cu
);
22739 result
= write_constant_as_bytes (obstack
, byte_order
,
22740 type
, attr
->as_signed (), len
);
22743 case DW_FORM_udata
:
22744 type
= die_type (die
, cu
);
22745 result
= write_constant_as_bytes (obstack
, byte_order
,
22746 type
, attr
->as_unsigned (), len
);
22750 complaint (_("unsupported const value attribute form: '%s'"),
22751 dwarf_form_name (attr
->form
));
22761 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22762 dwarf2_per_cu_data
*per_cu
,
22763 dwarf2_per_objfile
*per_objfile
,
22764 const char **var_name
)
22766 struct die_info
*die
;
22768 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22770 cu
= load_cu (per_cu
, per_objfile
, false);
22775 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22779 if (var_name
!= nullptr)
22780 *var_name
= var_decl_name (die
, cu
);
22781 return die_type (die
, cu
);
22787 dwarf2_get_die_type (cu_offset die_offset
,
22788 dwarf2_per_cu_data
*per_cu
,
22789 dwarf2_per_objfile
*per_objfile
)
22791 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22792 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22795 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22796 On entry *REF_CU is the CU of SRC_DIE.
22797 On exit *REF_CU is the CU of the result.
22798 Returns NULL if the referenced DIE isn't found. */
22800 static struct die_info
*
22801 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22802 struct dwarf2_cu
**ref_cu
)
22804 struct die_info temp_die
;
22805 struct dwarf2_cu
*sig_cu
;
22806 struct die_info
*die
;
22807 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
22810 /* While it might be nice to assert sig_type->type == NULL here,
22811 we can get here for DW_AT_imported_declaration where we need
22812 the DIE not the type. */
22814 /* If necessary, add it to the queue and load its DIEs.
22816 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
22817 it doesn't mean they are currently loaded. Since we require them
22818 to be loaded, we must check for ourselves. */
22819 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
22821 || per_objfile
->get_cu (sig_type
) == nullptr)
22822 read_signatured_type (sig_type
, per_objfile
);
22824 sig_cu
= per_objfile
->get_cu (sig_type
);
22825 gdb_assert (sig_cu
!= NULL
);
22826 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22827 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22828 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22829 to_underlying (temp_die
.sect_off
));
22832 /* For .gdb_index version 7 keep track of included TUs.
22833 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22834 if (per_objfile
->per_bfd
->index_table
!= NULL
22835 && !per_objfile
->per_bfd
->index_table
->version_check ())
22837 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22847 /* Follow signatured type referenced by ATTR in SRC_DIE.
22848 On entry *REF_CU is the CU of SRC_DIE.
22849 On exit *REF_CU is the CU of the result.
22850 The result is the DIE of the type.
22851 If the referenced type cannot be found an error is thrown. */
22853 static struct die_info
*
22854 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22855 struct dwarf2_cu
**ref_cu
)
22857 ULONGEST signature
= attr
->as_signature ();
22858 struct signatured_type
*sig_type
;
22859 struct die_info
*die
;
22861 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22863 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22864 /* sig_type will be NULL if the signatured type is missing from
22866 if (sig_type
== NULL
)
22868 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22869 " from DIE at %s [in module %s]"),
22870 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22871 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22874 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22877 dump_die_for_error (src_die
);
22878 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22879 " from DIE at %s [in module %s]"),
22880 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22881 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22887 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22888 reading in and processing the type unit if necessary. */
22890 static struct type
*
22891 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22892 struct dwarf2_cu
*cu
)
22894 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22895 struct signatured_type
*sig_type
;
22896 struct dwarf2_cu
*type_cu
;
22897 struct die_info
*type_die
;
22900 sig_type
= lookup_signatured_type (cu
, signature
);
22901 /* sig_type will be NULL if the signatured type is missing from
22903 if (sig_type
== NULL
)
22905 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22906 " from DIE at %s [in module %s]"),
22907 hex_string (signature
), sect_offset_str (die
->sect_off
),
22908 objfile_name (per_objfile
->objfile
));
22909 return build_error_marker_type (cu
, die
);
22912 /* If we already know the type we're done. */
22913 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
22914 if (type
!= nullptr)
22918 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22919 if (type_die
!= NULL
)
22921 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22922 is created. This is important, for example, because for c++ classes
22923 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22924 type
= read_type_die (type_die
, type_cu
);
22927 complaint (_("Dwarf Error: Cannot build signatured type %s"
22928 " referenced from DIE at %s [in module %s]"),
22929 hex_string (signature
), sect_offset_str (die
->sect_off
),
22930 objfile_name (per_objfile
->objfile
));
22931 type
= build_error_marker_type (cu
, die
);
22936 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22937 " from DIE at %s [in module %s]"),
22938 hex_string (signature
), sect_offset_str (die
->sect_off
),
22939 objfile_name (per_objfile
->objfile
));
22940 type
= build_error_marker_type (cu
, die
);
22943 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22948 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22949 reading in and processing the type unit if necessary. */
22951 static struct type
*
22952 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22953 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22955 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22956 if (attr
->form_is_ref ())
22958 struct dwarf2_cu
*type_cu
= cu
;
22959 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22961 return read_type_die (type_die
, type_cu
);
22963 else if (attr
->form
== DW_FORM_ref_sig8
)
22965 return get_signatured_type (die
, attr
->as_signature (), cu
);
22969 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22971 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22972 " at %s [in module %s]"),
22973 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22974 objfile_name (per_objfile
->objfile
));
22975 return build_error_marker_type (cu
, die
);
22979 /* Load the DIEs associated with type unit PER_CU into memory. */
22982 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22983 dwarf2_per_objfile
*per_objfile
)
22985 struct signatured_type
*sig_type
;
22987 /* We have the per_cu, but we need the signatured_type.
22988 Fortunately this is an easy translation. */
22989 gdb_assert (per_cu
->is_debug_types
);
22990 sig_type
= (struct signatured_type
*) per_cu
;
22992 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22994 read_signatured_type (sig_type
, per_objfile
);
22996 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22999 /* Read in a signatured type and build its CU and DIEs.
23000 If the type is a stub for the real type in a DWO file,
23001 read in the real type from the DWO file as well. */
23004 read_signatured_type (signatured_type
*sig_type
,
23005 dwarf2_per_objfile
*per_objfile
)
23007 gdb_assert (sig_type
->is_debug_types
);
23008 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23010 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23012 if (!reader
.dummy_p
)
23014 struct dwarf2_cu
*cu
= reader
.cu
;
23015 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23017 gdb_assert (cu
->die_hash
== NULL
);
23019 htab_create_alloc_ex (cu
->header
.get_length_without_initial () / 12,
23023 &cu
->comp_unit_obstack
,
23024 hashtab_obstack_allocate
,
23025 dummy_obstack_deallocate
);
23027 if (reader
.comp_unit_die
->has_children
)
23028 reader
.comp_unit_die
->child
23029 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23030 reader
.comp_unit_die
);
23031 cu
->dies
= reader
.comp_unit_die
;
23032 /* comp_unit_die is not stored in die_hash, no need. */
23034 /* We try not to read any attributes in this function, because
23035 not all CUs needed for references have been loaded yet, and
23036 symbol table processing isn't initialized. But we have to
23037 set the CU language, or we won't be able to build types
23038 correctly. Similarly, if we do not read the producer, we can
23039 not apply producer-specific interpretation. */
23040 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23045 sig_type
->tu_read
= 1;
23048 /* Decode simple location descriptions.
23049 Given a pointer to a dwarf block that defines a location, compute
23050 the location and return the value. If COMPUTED is non-null, it is
23051 set to true to indicate that decoding was successful, and false
23052 otherwise. If COMPUTED is null, then this function may emit a
23056 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23058 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23060 size_t size
= blk
->size
;
23061 const gdb_byte
*data
= blk
->data
;
23062 CORE_ADDR stack
[64];
23064 unsigned int bytes_read
, unsnd
;
23067 if (computed
!= nullptr)
23073 stack
[++stacki
] = 0;
23112 stack
[++stacki
] = op
- DW_OP_lit0
;
23147 stack
[++stacki
] = op
- DW_OP_reg0
;
23150 if (computed
== nullptr)
23151 dwarf2_complex_location_expr_complaint ();
23158 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23160 stack
[++stacki
] = unsnd
;
23163 if (computed
== nullptr)
23164 dwarf2_complex_location_expr_complaint ();
23171 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
.get (),
23177 case DW_OP_const1u
:
23178 stack
[++stacki
] = read_1_byte (objfile
->obfd
.get (), &data
[i
]);
23182 case DW_OP_const1s
:
23183 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
.get (), &data
[i
]);
23187 case DW_OP_const2u
:
23188 stack
[++stacki
] = read_2_bytes (objfile
->obfd
.get (), &data
[i
]);
23192 case DW_OP_const2s
:
23193 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
.get (), &data
[i
]);
23197 case DW_OP_const4u
:
23198 stack
[++stacki
] = read_4_bytes (objfile
->obfd
.get (), &data
[i
]);
23202 case DW_OP_const4s
:
23203 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
.get (), &data
[i
]);
23207 case DW_OP_const8u
:
23208 stack
[++stacki
] = read_8_bytes (objfile
->obfd
.get (), &data
[i
]);
23213 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23219 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23224 stack
[stacki
+ 1] = stack
[stacki
];
23229 stack
[stacki
- 1] += stack
[stacki
];
23233 case DW_OP_plus_uconst
:
23234 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23240 stack
[stacki
- 1] -= stack
[stacki
];
23245 /* If we're not the last op, then we definitely can't encode
23246 this using GDB's address_class enum. This is valid for partial
23247 global symbols, although the variable's address will be bogus
23251 if (computed
== nullptr)
23252 dwarf2_complex_location_expr_complaint ();
23258 case DW_OP_GNU_push_tls_address
:
23259 case DW_OP_form_tls_address
:
23260 /* The top of the stack has the offset from the beginning
23261 of the thread control block at which the variable is located. */
23262 /* Nothing should follow this operator, so the top of stack would
23264 /* This is valid for partial global symbols, but the variable's
23265 address will be bogus in the psymtab. Make it always at least
23266 non-zero to not look as a variable garbage collected by linker
23267 which have DW_OP_addr 0. */
23270 if (computed
== nullptr)
23271 dwarf2_complex_location_expr_complaint ();
23278 case DW_OP_GNU_uninit
:
23279 if (computed
!= nullptr)
23284 case DW_OP_GNU_addr_index
:
23285 case DW_OP_GNU_const_index
:
23286 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23292 if (computed
== nullptr)
23294 const char *name
= get_DW_OP_name (op
);
23297 complaint (_("unsupported stack op: '%s'"),
23300 complaint (_("unsupported stack op: '%02x'"),
23304 return (stack
[stacki
]);
23307 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23308 outside of the allocated space. Also enforce minimum>0. */
23309 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23311 if (computed
== nullptr)
23312 complaint (_("location description stack overflow"));
23318 if (computed
== nullptr)
23319 complaint (_("location description stack underflow"));
23324 if (computed
!= nullptr)
23326 return (stack
[stacki
]);
23329 /* memory allocation interface */
23331 static struct dwarf_block
*
23332 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23334 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23337 static struct die_info
*
23338 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23340 struct die_info
*die
;
23341 size_t size
= sizeof (struct die_info
);
23344 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23346 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23347 memset (die
, 0, sizeof (struct die_info
));
23353 /* Macro support. */
23355 /* An overload of dwarf_decode_macros that finds the correct section
23356 and ensures it is read in before calling the other overload. */
23359 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23360 int section_is_gnu
)
23362 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23363 struct objfile
*objfile
= per_objfile
->objfile
;
23364 const struct line_header
*lh
= cu
->line_header
;
23365 unsigned int offset_size
= cu
->header
.offset_size
;
23366 struct dwarf2_section_info
*section
;
23367 const char *section_name
;
23369 if (cu
->dwo_unit
!= nullptr)
23371 if (section_is_gnu
)
23373 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23374 section_name
= ".debug_macro.dwo";
23378 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23379 section_name
= ".debug_macinfo.dwo";
23384 if (section_is_gnu
)
23386 section
= &per_objfile
->per_bfd
->macro
;
23387 section_name
= ".debug_macro";
23391 section
= &per_objfile
->per_bfd
->macinfo
;
23392 section_name
= ".debug_macinfo";
23396 section
->read (objfile
);
23397 if (section
->buffer
== nullptr)
23399 complaint (_("missing %s section"), section_name
);
23403 buildsym_compunit
*builder
= cu
->get_builder ();
23405 struct dwarf2_section_info
*str_offsets_section
;
23406 struct dwarf2_section_info
*str_section
;
23407 gdb::optional
<ULONGEST
> str_offsets_base
;
23409 if (cu
->dwo_unit
!= nullptr)
23411 str_offsets_section
= &cu
->dwo_unit
->dwo_file
23412 ->sections
.str_offsets
;
23413 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
23414 str_offsets_base
= cu
->header
.addr_size
;
23418 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
23419 str_section
= &per_objfile
->per_bfd
->str
;
23420 str_offsets_base
= cu
->str_offsets_base
;
23423 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
23424 offset_size
, offset
, str_section
, str_offsets_section
,
23425 str_offsets_base
, section_is_gnu
, cu
);
23428 /* Return the .debug_loc section to use for CU.
23429 For DWO files use .debug_loc.dwo. */
23431 static struct dwarf2_section_info
*
23432 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23434 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23438 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23440 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23442 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
23443 : &per_objfile
->per_bfd
->loc
);
23446 /* Return the .debug_rnglists section to use for CU. */
23447 static struct dwarf2_section_info
*
23448 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
23450 if (cu
->header
.version
< 5)
23451 error (_(".debug_rnglists section cannot be used in DWARF %d"),
23452 cu
->header
.version
);
23453 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23455 /* Make sure we read the .debug_rnglists section from the file that
23456 contains the DW_AT_ranges attribute we are reading. Normally that
23457 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
23458 or DW_TAG_skeleton unit, we always want to read from objfile/linked
23460 if (cu
->dwo_unit
!= nullptr
23461 && tag
!= DW_TAG_compile_unit
23462 && tag
!= DW_TAG_skeleton_unit
)
23464 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23466 if (sections
->rnglists
.size
> 0)
23467 return §ions
->rnglists
;
23469 error (_(".debug_rnglists section is missing from .dwo file."));
23471 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
23474 /* A helper function that fills in a dwarf2_loclist_baton. */
23477 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23478 struct dwarf2_loclist_baton
*baton
,
23479 const struct attribute
*attr
)
23481 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23482 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23484 section
->read (per_objfile
->objfile
);
23486 baton
->per_objfile
= per_objfile
;
23487 baton
->per_cu
= cu
->per_cu
;
23488 gdb_assert (baton
->per_cu
);
23489 /* We don't know how long the location list is, but make sure we
23490 don't run off the edge of the section. */
23491 baton
->size
= section
->size
- attr
->as_unsigned ();
23492 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
23493 if (cu
->base_address
.has_value ())
23494 baton
->base_address
= *cu
->base_address
;
23496 baton
->base_address
= 0;
23497 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23501 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23502 struct dwarf2_cu
*cu
, int is_block
)
23504 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23505 struct objfile
*objfile
= per_objfile
->objfile
;
23506 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23508 if (attr
->form_is_section_offset ()
23509 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23510 the section. If so, fall through to the complaint in the
23512 && attr
->as_unsigned () < section
->get_size (objfile
))
23514 struct dwarf2_loclist_baton
*baton
;
23516 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23518 fill_in_loclist_baton (cu
, baton
, attr
);
23520 if (!cu
->base_address
.has_value ())
23521 complaint (_("Location list used without "
23522 "specifying the CU base address."));
23524 sym
->set_aclass_index ((is_block
23525 ? dwarf2_loclist_block_index
23526 : dwarf2_loclist_index
));
23527 SYMBOL_LOCATION_BATON (sym
) = baton
;
23531 struct dwarf2_locexpr_baton
*baton
;
23533 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23534 baton
->per_objfile
= per_objfile
;
23535 baton
->per_cu
= cu
->per_cu
;
23536 gdb_assert (baton
->per_cu
);
23538 if (attr
->form_is_block ())
23540 /* Note that we're just copying the block's data pointer
23541 here, not the actual data. We're still pointing into the
23542 info_buffer for SYM's objfile; right now we never release
23543 that buffer, but when we do clean up properly this may
23545 struct dwarf_block
*block
= attr
->as_block ();
23546 baton
->size
= block
->size
;
23547 baton
->data
= block
->data
;
23551 dwarf2_invalid_attrib_class_complaint ("location description",
23552 sym
->natural_name ());
23556 sym
->set_aclass_index ((is_block
23557 ? dwarf2_locexpr_block_index
23558 : dwarf2_locexpr_index
));
23559 SYMBOL_LOCATION_BATON (sym
) = baton
;
23565 const comp_unit_head
*
23566 dwarf2_per_cu_data::get_header () const
23568 if (!m_header_read_in
)
23570 const gdb_byte
*info_ptr
23571 = this->section
->buffer
+ to_underlying (this->sect_off
);
23573 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23574 rcuh_kind::COMPILE
);
23576 m_header_read_in
= true;
23585 dwarf2_per_cu_data::addr_size () const
23587 return this->get_header ()->addr_size
;
23593 dwarf2_per_cu_data::offset_size () const
23595 return this->get_header ()->offset_size
;
23601 dwarf2_per_cu_data::ref_addr_size () const
23603 const comp_unit_head
*header
= this->get_header ();
23605 if (header
->version
== 2)
23606 return header
->addr_size
;
23608 return header
->offset_size
;
23611 /* A helper function for dwarf2_find_containing_comp_unit that returns
23612 the index of the result, and that searches a vector. It will
23613 return a result even if the offset in question does not actually
23614 occur in any CU. This is separate so that it can be unit
23618 dwarf2_find_containing_comp_unit
23619 (sect_offset sect_off
,
23620 unsigned int offset_in_dwz
,
23621 const std::vector
<dwarf2_per_cu_data_up
> &all_units
)
23626 high
= all_units
.size () - 1;
23629 struct dwarf2_per_cu_data
*mid_cu
;
23630 int mid
= low
+ (high
- low
) / 2;
23632 mid_cu
= all_units
[mid
].get ();
23633 if (mid_cu
->is_dwz
> offset_in_dwz
23634 || (mid_cu
->is_dwz
== offset_in_dwz
23635 && mid_cu
->sect_off
+ mid_cu
->length () > sect_off
))
23640 gdb_assert (low
== high
);
23644 /* Locate the .debug_info compilation unit from CU's objfile which contains
23645 the DIE at OFFSET. Raises an error on failure. */
23647 static struct dwarf2_per_cu_data
*
23648 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23649 unsigned int offset_in_dwz
,
23650 dwarf2_per_bfd
*per_bfd
)
23652 int low
= dwarf2_find_containing_comp_unit
23653 (sect_off
, offset_in_dwz
, per_bfd
->all_units
);
23654 dwarf2_per_cu_data
*this_cu
= per_bfd
->all_units
[low
].get ();
23656 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23658 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23659 error (_("Dwarf Error: could not find partial DIE containing "
23660 "offset %s [in module %s]"),
23661 sect_offset_str (sect_off
),
23662 bfd_get_filename (per_bfd
->obfd
));
23664 gdb_assert (per_bfd
->all_units
[low
-1]->sect_off
23666 return per_bfd
->all_units
[low
- 1].get ();
23670 if (low
== per_bfd
->all_units
.size () - 1
23671 && sect_off
>= this_cu
->sect_off
+ this_cu
->length ())
23672 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23673 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length ());
23680 namespace selftests
{
23681 namespace find_containing_comp_unit
{
23686 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
23687 dwarf2_per_cu_data
*one_ptr
= one
.get ();
23688 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
23689 dwarf2_per_cu_data
*two_ptr
= two
.get ();
23690 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
23691 dwarf2_per_cu_data
*three_ptr
= three
.get ();
23692 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
23693 dwarf2_per_cu_data
*four_ptr
= four
.get ();
23695 one
->set_length (5);
23696 two
->sect_off
= sect_offset (one
->length ());
23697 two
->set_length (7);
23699 three
->set_length (5);
23701 four
->sect_off
= sect_offset (three
->length ());
23702 four
->set_length (7);
23705 std::vector
<dwarf2_per_cu_data_up
> units
;
23706 units
.push_back (std::move (one
));
23707 units
.push_back (std::move (two
));
23708 units
.push_back (std::move (three
));
23709 units
.push_back (std::move (four
));
23713 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23714 SELF_CHECK (units
[result
].get () == one_ptr
);
23715 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23716 SELF_CHECK (units
[result
].get () == one_ptr
);
23717 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23718 SELF_CHECK (units
[result
].get () == two_ptr
);
23720 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23721 SELF_CHECK (units
[result
].get () == three_ptr
);
23722 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23723 SELF_CHECK (units
[result
].get () == three_ptr
);
23724 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23725 SELF_CHECK (units
[result
].get () == four_ptr
);
23731 #endif /* GDB_SELF_TEST */
23733 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23736 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23737 enum language pretend_language
)
23739 struct attribute
*attr
;
23741 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23743 /* Set the language we're debugging. */
23744 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23745 enum language lang
;
23746 if (cu
->producer
!= nullptr
23747 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
23749 /* The XLCL doesn't generate DW_LANG_OpenCL because this
23750 attribute is not standardised yet. As a workaround for the
23751 language detection we fall back to the DW_AT_producer
23753 lang
= language_opencl
;
23755 else if (cu
->producer
!= nullptr
23756 && strstr (cu
->producer
, "GNU Go ") != NULL
)
23758 /* Similar hack for Go. */
23759 lang
= language_go
;
23761 else if (attr
!= nullptr)
23762 lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
23764 lang
= pretend_language
;
23766 cu
->language_defn
= language_def (lang
);
23768 switch (comp_unit_die
->tag
)
23770 case DW_TAG_compile_unit
:
23771 cu
->per_cu
->set_unit_type (DW_UT_compile
);
23773 case DW_TAG_partial_unit
:
23774 cu
->per_cu
->set_unit_type (DW_UT_partial
);
23776 case DW_TAG_type_unit
:
23777 cu
->per_cu
->set_unit_type (DW_UT_type
);
23780 error (_("Dwarf Error: unexpected tag '%s' at offset %s"),
23781 dwarf_tag_name (comp_unit_die
->tag
),
23782 sect_offset_str (cu
->per_cu
->sect_off
));
23785 cu
->per_cu
->set_lang (lang
);
23791 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23793 auto it
= m_dwarf2_cus
.find (per_cu
);
23794 if (it
== m_dwarf2_cus
.end ())
23797 return it
->second
.get ();
23803 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
,
23804 std::unique_ptr
<dwarf2_cu
> cu
)
23806 gdb_assert (this->get_cu (per_cu
) == nullptr);
23808 m_dwarf2_cus
[per_cu
] = std::move (cu
);
23814 dwarf2_per_objfile::age_comp_units ()
23816 dwarf_read_debug_printf_v ("running");
23818 /* This is not expected to be called in the middle of CU expansion. There is
23819 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
23820 loaded in memory. Calling age_comp_units while the queue is in use could
23821 make us free the DIEs for a CU that is in the queue and therefore break
23823 gdb_assert (!queue
.has_value ());
23825 /* Start by clearing all marks. */
23826 for (const auto &pair
: m_dwarf2_cus
)
23827 pair
.second
->clear_mark ();
23829 /* Traverse all CUs, mark them and their dependencies if used recently
23831 for (const auto &pair
: m_dwarf2_cus
)
23833 dwarf2_cu
*cu
= pair
.second
.get ();
23836 if (cu
->last_used
<= dwarf_max_cache_age
)
23840 /* Delete all CUs still not marked. */
23841 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23843 dwarf2_cu
*cu
= it
->second
.get ();
23845 if (!cu
->is_marked ())
23847 dwarf_read_debug_printf_v ("deleting old CU %s",
23848 sect_offset_str (cu
->per_cu
->sect_off
));
23849 it
= m_dwarf2_cus
.erase (it
);
23859 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23861 auto it
= m_dwarf2_cus
.find (per_cu
);
23862 if (it
== m_dwarf2_cus
.end ())
23865 m_dwarf2_cus
.erase (it
);
23868 dwarf2_per_objfile::~dwarf2_per_objfile ()
23873 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23874 We store these in a hash table separate from the DIEs, and preserve them
23875 when the DIEs are flushed out of cache.
23877 The CU "per_cu" pointer is needed because offset alone is not enough to
23878 uniquely identify the type. A file may have multiple .debug_types sections,
23879 or the type may come from a DWO file. Furthermore, while it's more logical
23880 to use per_cu->section+offset, with Fission the section with the data is in
23881 the DWO file but we don't know that section at the point we need it.
23882 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23883 because we can enter the lookup routine, get_die_type_at_offset, from
23884 outside this file, and thus won't necessarily have PER_CU->cu.
23885 Fortunately, PER_CU is stable for the life of the objfile. */
23887 struct dwarf2_per_cu_offset_and_type
23889 const struct dwarf2_per_cu_data
*per_cu
;
23890 sect_offset sect_off
;
23894 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23897 per_cu_offset_and_type_hash (const void *item
)
23899 const struct dwarf2_per_cu_offset_and_type
*ofs
23900 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23902 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23905 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23908 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23910 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23911 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23912 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23913 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23915 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23916 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23919 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23920 table if necessary. For convenience, return TYPE.
23922 The DIEs reading must have careful ordering to:
23923 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23924 reading current DIE.
23925 * Not trying to dereference contents of still incompletely read in types
23926 while reading in other DIEs.
23927 * Enable referencing still incompletely read in types just by a pointer to
23928 the type without accessing its fields.
23930 Therefore caller should follow these rules:
23931 * Try to fetch any prerequisite types we may need to build this DIE type
23932 before building the type and calling set_die_type.
23933 * After building type call set_die_type for current DIE as soon as
23934 possible before fetching more types to complete the current type.
23935 * Make the type as complete as possible before fetching more types. */
23937 static struct type
*
23938 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
23939 bool skip_data_location
)
23941 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23942 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23943 struct objfile
*objfile
= per_objfile
->objfile
;
23944 struct attribute
*attr
;
23945 struct dynamic_prop prop
;
23947 /* For Ada types, make sure that the gnat-specific data is always
23948 initialized (if not already set). There are a few types where
23949 we should not be doing so, because the type-specific area is
23950 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23951 where the type-specific area is used to store the floatformat).
23952 But this is not a problem, because the gnat-specific information
23953 is actually not needed for these types. */
23954 if (need_gnat_info (cu
)
23955 && type
->code () != TYPE_CODE_FUNC
23956 && type
->code () != TYPE_CODE_FLT
23957 && type
->code () != TYPE_CODE_METHODPTR
23958 && type
->code () != TYPE_CODE_MEMBERPTR
23959 && type
->code () != TYPE_CODE_METHOD
23960 && type
->code () != TYPE_CODE_FIXED_POINT
23961 && !HAVE_GNAT_AUX_INFO (type
))
23962 INIT_GNAT_SPECIFIC (type
);
23964 /* Read DW_AT_allocated and set in type. */
23965 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23968 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23969 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23970 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23973 /* Read DW_AT_associated and set in type. */
23974 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23977 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23978 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23979 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23982 /* Read DW_AT_rank and set in type. */
23983 attr
= dwarf2_attr (die
, DW_AT_rank
, cu
);
23986 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23987 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23988 type
->add_dyn_prop (DYN_PROP_RANK
, prop
);
23991 /* Read DW_AT_data_location and set in type. */
23992 if (!skip_data_location
)
23994 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23995 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23996 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23999 if (per_objfile
->die_type_hash
== NULL
)
24000 per_objfile
->die_type_hash
24001 = htab_up (htab_create_alloc (127,
24002 per_cu_offset_and_type_hash
,
24003 per_cu_offset_and_type_eq
,
24004 NULL
, xcalloc
, xfree
));
24006 ofs
.per_cu
= cu
->per_cu
;
24007 ofs
.sect_off
= die
->sect_off
;
24009 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24010 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24012 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24013 sect_offset_str (die
->sect_off
));
24014 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24015 struct dwarf2_per_cu_offset_and_type
);
24020 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24021 or return NULL if the die does not have a saved type. */
24023 static struct type
*
24024 get_die_type_at_offset (sect_offset sect_off
,
24025 dwarf2_per_cu_data
*per_cu
,
24026 dwarf2_per_objfile
*per_objfile
)
24028 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24030 if (per_objfile
->die_type_hash
== NULL
)
24033 ofs
.per_cu
= per_cu
;
24034 ofs
.sect_off
= sect_off
;
24035 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24036 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24043 /* Look up the type for DIE in CU in die_type_hash,
24044 or return NULL if DIE does not have a saved type. */
24046 static struct type
*
24047 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24049 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24052 struct cmd_list_element
*set_dwarf_cmdlist
;
24053 struct cmd_list_element
*show_dwarf_cmdlist
;
24056 show_check_physname (struct ui_file
*file
, int from_tty
,
24057 struct cmd_list_element
*c
, const char *value
)
24060 _("Whether to check \"physname\" is %s.\n"),
24064 void _initialize_dwarf2_read ();
24066 _initialize_dwarf2_read ()
24068 add_setshow_prefix_cmd ("dwarf", class_maintenance
,
24070 Set DWARF specific variables.\n\
24071 Configure DWARF variables such as the cache size."),
24073 Show DWARF specific variables.\n\
24074 Show DWARF variables such as the cache size."),
24075 &set_dwarf_cmdlist
, &show_dwarf_cmdlist
,
24076 &maintenance_set_cmdlist
, &maintenance_show_cmdlist
);
24078 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24079 &dwarf_max_cache_age
, _("\
24080 Set the upper bound on the age of cached DWARF compilation units."), _("\
24081 Show the upper bound on the age of cached DWARF compilation units."), _("\
24082 A higher limit means that cached compilation units will be stored\n\
24083 in memory longer, and more total memory will be used. Zero disables\n\
24084 caching, which can slow down startup."),
24086 show_dwarf_max_cache_age
,
24087 &set_dwarf_cmdlist
,
24088 &show_dwarf_cmdlist
);
24090 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24091 Set debugging of the DWARF reader."), _("\
24092 Show debugging of the DWARF reader."), _("\
24093 When enabled (non-zero), debugging messages are printed during DWARF\n\
24094 reading and symtab expansion. A value of 1 (one) provides basic\n\
24095 information. A value greater than 1 provides more verbose information."),
24098 &setdebuglist
, &showdebuglist
);
24100 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24101 Set debugging of the DWARF DIE reader."), _("\
24102 Show debugging of the DWARF DIE reader."), _("\
24103 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24104 The value is the maximum depth to print."),
24107 &setdebuglist
, &showdebuglist
);
24109 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24110 Set debugging of the dwarf line reader."), _("\
24111 Show debugging of the dwarf line reader."), _("\
24112 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24113 A value of 1 (one) provides basic information.\n\
24114 A value greater than 1 provides more verbose information."),
24117 &setdebuglist
, &showdebuglist
);
24119 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24120 Set cross-checking of \"physname\" code against demangler."), _("\
24121 Show cross-checking of \"physname\" code against demangler."), _("\
24122 When enabled, GDB's internal \"physname\" code is checked against\n\
24124 NULL
, show_check_physname
,
24125 &setdebuglist
, &showdebuglist
);
24127 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24128 no_class
, &use_deprecated_index_sections
, _("\
24129 Set whether to use deprecated gdb_index sections."), _("\
24130 Show whether to use deprecated gdb_index sections."), _("\
24131 When enabled, deprecated .gdb_index sections are used anyway.\n\
24132 Normally they are ignored either because of a missing feature or\n\
24133 performance issue.\n\
24134 Warning: This option must be enabled before gdb reads the file."),
24137 &setlist
, &showlist
);
24139 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24140 &dwarf2_locexpr_funcs
);
24141 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24142 &dwarf2_loclist_funcs
);
24144 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24145 &dwarf2_block_frame_base_locexpr_funcs
);
24146 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24147 &dwarf2_block_frame_base_loclist_funcs
);
24150 selftests::register_test ("dw2_expand_symtabs_matching",
24151 selftests::dw2_expand_symtabs_matching::run_test
);
24152 selftests::register_test ("dwarf2_find_containing_comp_unit",
24153 selftests::find_containing_comp_unit::run_test
);