GDB (xrefs)
Loading...
Searching...
No Matches
read.c
Go to the documentation of this file.
1/* DWARF 2 debugging format support for GDB.
2
3 Copyright (C) 1994-2023 Free Software Foundation, Inc.
4
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
10 support.
11
12 This file is part of GDB.
13
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.
18
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.
23
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/>. */
26
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. */
30
31#include "defs.h"
32#include "dwarf2/read.h"
33#include "dwarf2/abbrev.h"
34#include "dwarf2/attribute.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"
47#include "bfd.h"
48#include "elf-bfd.h"
49#include "symtab.h"
50#include "gdbtypes.h"
51#include "objfiles.h"
52#include "dwarf2.h"
53#include "demangle.h"
54#include "gdb-demangle.h"
55#include "filenames.h" /* for DOSish file names */
56#include "language.h"
57#include "complaints.h"
58#include "dwarf2/expr.h"
59#include "dwarf2/loc.h"
60#include "cp-support.h"
61#include "hashtab.h"
62#include "command.h"
63#include "gdbcmd.h"
64#include "block.h"
65#include "addrmap.h"
66#include "typeprint.h"
67#include "c-lang.h"
68#include "go-lang.h"
69#include "valprint.h"
70#include "gdbcore.h" /* for gnutarget */
71#include "gdb/gdb-index.h"
72#include "gdb_bfd.h"
73#include "f-lang.h"
74#include "source.h"
75#include "build-id.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"
82#include "producer.h"
83#include <fcntl.h>
84#include <algorithm>
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"
96
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. */
100static unsigned int dwarf_read_debug = 0;
101
102/* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
103
104#define dwarf_read_debug_printf(fmt, ...) \
105 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
106 ##__VA_ARGS__)
107
108/* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
109
110#define dwarf_read_debug_printf_v(fmt, ...) \
111 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
112 ##__VA_ARGS__)
113
114/* When non-zero, dump DIEs after they are read in. */
115static unsigned int dwarf_die_debug = 0;
116
117/* When non-zero, dump line number entries as they are read in. */
118unsigned int dwarf_line_debug = 0;
119
120/* When true, cross-check physname against demangler. */
121static bool check_physname = false;
122
123/* When true, do not reject deprecated .gdb_index sections. */
125
126/* This is used to store the data that is always per objfile. */
129
130/* These are used to store the dwarf2_per_bfd objects.
131
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.
134
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
137 version. */
141
142/* The "aclass" indices for various kinds of computed DWARF symbols. */
143
148
149/* Size of .debug_loclists section header for 32-bit DWARF format. */
150#define LOCLIST_HEADER_SIZE32 12
151
152/* Size of .debug_loclists section header for 64-bit DWARF format. */
153#define LOCLIST_HEADER_SIZE64 20
154
155/* Size of .debug_rnglists section header for 32-bit DWARF format. */
156#define RNGLIST_HEADER_SIZE32 12
157
158/* Size of .debug_rnglists section header for 64-bit DWARF format. */
159#define RNGLIST_HEADER_SIZE64 20
160
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. */
164
166{
167public:
168 offset_view () = default;
169
170 explicit offset_view (gdb::array_view<const gdb_byte> bytes)
171 : m_bytes (bytes)
172 {
173 }
174
175 /* Extract the INDEXth offset_type from the array. */
176 offset_type operator[] (size_t index) const
177 {
178 const gdb_byte *bytes = &m_bytes[index * sizeof (offset_type)];
180 sizeof (offset_type),
181 BFD_ENDIAN_LITTLE);
182 }
183
184 /* Return the number of offset_types in this array. */
185 size_t size () const
186 {
187 return m_bytes.size () / sizeof (offset_type);
188 }
189
190 /* Return true if this view is empty. */
191 bool empty () const
192 {
193 return m_bytes.empty ();
194 }
195
196private:
197 /* The underlying bytes. */
198 gdb::array_view<const gdb_byte> m_bytes;
199};
200
201/* A description of the mapped index. The file format is described in
202 a comment by the code that writes the index. */
203struct mapped_index final : public mapped_index_base
204{
205 /* Index data format version. */
206 int version = 0;
207
208 /* The address table data. */
209 gdb::array_view<const gdb_byte> address_table;
210
211 /* The symbol table, implemented as a hash table. */
213
214 /* A pointer to the constant pool. */
215 gdb::array_view<const gdb_byte> constant_pool;
216
217 /* Return the index into the constant pool of the name of the IDXth
218 symbol in the symbol table. */
220 {
221 return symbol_table[2 * idx];
222 }
223
224 /* Return the index into the constant pool of the CU vector of the
225 IDXth symbol in the symbol table. */
227 {
228 return symbol_table[2 * idx + 1];
229 }
230
231 bool symbol_name_slot_invalid (offset_type idx) const override
232 {
233 return (symbol_name_index (idx) == 0
234 && symbol_vec_index (idx) == 0);
235 }
236
237 /* Convenience method to get at the name of the symbol at IDX in the
238 symbol table. */
239 const char *symbol_name_at
240 (offset_type idx, dwarf2_per_objfile *per_objfile) const override
241 {
242 return (const char *) (this->constant_pool.data ()
243 + symbol_name_index (idx));
244 }
245
246 size_t symbol_name_count () const override
247 { return this->symbol_table.size () / 2; }
248
250
251 bool version_check () const override
252 {
253 return version >= 8;
254 }
255};
256
257/* A description of the mapped .debug_names.
258 Uninitialized map has CU_COUNT 0. */
260{
264 uint8_t offset_size;
265 uint32_t cu_count = 0;
271 const gdb_byte *entry_pool;
272
274 {
275 ULONGEST dwarf_tag;
276 struct attr
277 {
278 /* Attribute name DW_IDX_*. */
279 ULONGEST dw_idx;
280
281 /* Attribute form DW_FORM_*. */
282 ULONGEST form;
283
284 /* Value if FORM is DW_FORM_implicit_const. */
286 };
287 std::vector<attr> attr_vec;
288 };
289
290 std::unordered_map<ULONGEST, index_val> abbrev_map;
291
292 const char *namei_to_name
293 (uint32_t namei, dwarf2_per_objfile *per_objfile) const;
294
295 /* Implementation of the mapped_index_base virtual interface, for
296 the name_components cache. */
297
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); }
301
302 size_t symbol_name_count () const override
303 { return this->name_count; }
304
306};
307
308/* See dwarf2/read.h. */
309
312{
314}
315
316/* Default names of the debugging sections. */
317
318/* Note that if the debugging section has been compressed, it might
319 have a name like .zdebug_info. */
320
322{
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" },
342 23
343};
344
345/* List of DWO/DWP sections. */
346
347static const struct dwop_section_names
348{
362}
364{
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" },
379
380/* local data types */
381
382/* The location list and range list sections (.debug_loclists & .debug_rnglists)
383 begin with a header, which contains the following information. */
385{
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. */
389 unsigned int length;
390
391 /* A 2-byte version identifier. */
392 short version;
393
394 /* A 1-byte unsigned integer containing the size in bytes of an address on
395 the target system. */
396 unsigned char addr_size;
397
398 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
399 on the target system. */
401
402 /* A 4-byte count of the number of offsets that follow the header. */
403 unsigned int offset_entry_count;
404};
405
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. */
408
410{
411 /* The DWO unit this table is from or NULL if there is none. */
413
414 /* Offset in .debug_line or .debug_line.dwo. */
415 sect_offset line_sect_off;
416};
417
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. */
422
424{
425 /* The data used to construct the hash key. */
427};
428
429/* These sections are what may appear in a (real or virtual) DWO file. */
430
432{
442 /* In the case of a virtual DWO file, these two are unused. */
444 std::vector<dwarf2_section_info> types;
445};
446
447/* CUs/TUs in DWP/DWO files. */
448
450{
451 /* Backlink to the containing struct dwo_file. */
453
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. */
457 ULONGEST signature;
458
459 /* The section this CU/TU lives in, in the DWO file. */
461
462 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
463 sect_offset sect_off;
464 unsigned int length;
465
466 /* For types, offset in the type's DIE of the type defined by this TU. */
468};
469
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. */
473
475{
476 DW_SECT_MIN = 1
478
479/* Data for one DWO file.
480
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). */
489
491{
492 dwo_file () = default;
494
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;
500
501 /* The DW_AT_comp_dir attribute. */
502 const char *comp_dir = nullptr;
503
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. */
507
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). */
512
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). */
517 htab_up cus;
518
519 /* Table of TUs in the file.
520 Each element is a struct dwo_unit. */
521 htab_up tus;
522};
523
524/* These sections are what may appear in a DWP file. */
525
527{
528 /* These are used by all DWP versions (1, 2 and 5). */
532
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?). */
551};
552
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. */
555
557{
564 /* Each DWP hash table entry records one CU or one TU.
565 That is recorded here, and copied to dwo_unit.section. */
567};
568
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. */
573
575{
576 bfd_size_type abbrev_offset;
577 bfd_size_type abbrev_size;
578
579 bfd_size_type line_offset;
580 bfd_size_type line_size;
581
582 bfd_size_type loc_offset;
583 bfd_size_type loc_size;
584
585 bfd_size_type loclists_offset;
586 bfd_size_type loclists_size;
587
588 bfd_size_type macinfo_offset;
589 bfd_size_type macinfo_size;
590
591 bfd_size_type macro_offset;
592 bfd_size_type macro_size;
593
594 bfd_size_type rnglists_offset;
595 bfd_size_type rnglists_size;
596
597 bfd_size_type str_offsets_offset;
598 bfd_size_type str_offsets_size;
599
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;
604};
605
606/* Contents of DWP hash tables. */
607
609{
612 const gdb_byte *hash_table, *unit_table;
613 union
614 {
615 struct
616 {
617 const gdb_byte *indices;
618 } v1;
619 struct
620 {
621 /* This is indexed by column number and gives the id of the section
622 in that column. */
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 */)
631 const gdb_byte *offsets;
632 const gdb_byte *sizes;
633 } v2;
634 struct
635 {
636 /* This is indexed by column number and gives the id of the section
637 in that column. */
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 */)
647 const gdb_byte *offsets;
648 const gdb_byte *sizes;
649 } v5;
651};
652
653/* Data for one DWP file. */
654
656{
657 dwp_file (const char *name_, gdb_bfd_ref_ptr &&abfd)
658 : name (name_),
659 dbfd (std::move (abfd))
660 {
661 }
662
663 /* Name of the file. */
664 const char *name;
665
666 /* File format version. */
667 int version = 0;
668
669 /* The bfd. */
671
672 /* Section info for this file. */
674
675 /* Table of CUs in the file. */
676 const struct dwp_hash_table *cus = nullptr;
677
678 /* Table of TUs in the file. */
679 const struct dwp_hash_table *tus = nullptr;
680
681 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
682 htab_up loaded_cus;
683 htab_up loaded_tus;
684
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;
689};
690
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. */
695
697{
698 /* The bfd of die_section. */
699 bfd *abfd;
700
701 /* The CU of the DIE we are parsing. */
702 struct dwarf2_cu *cu;
703
704 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
706
707 /* The section the die comes from.
708 This is either .debug_info or .debug_types, or the .dwo variants. */
710
711 /* die_section->buffer. */
712 const gdb_byte *buffer;
713
714 /* The end of the buffer. */
715 const gdb_byte *buffer_end;
716
717 /* The abbreviation table to use when reading the DIEs. */
719};
720
721/* A subclass of die_reader_specs that holds storage and has complex
722 constructor and destructor behavior. */
723
725{
726public:
727
729 dwarf2_per_objfile *per_objfile,
731 dwarf2_cu *existing_cu,
732 bool skip_partial,
733 abbrev_cache *cache = nullptr);
734
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);
739
741
742 cutu_reader (cutu_reader &&) = default;
743
744 const gdb_byte *info_ptr = nullptr;
745 struct die_info *comp_unit_die = nullptr;
746 bool dummy_p = false;
747
748 /* Release the new CU, putting it on the chain. This cannot be done
749 for dummy CUs. */
750 void keep ();
751
752 /* Release the abbrev table, transferring ownership to the
753 caller. */
755 {
756 return std::move (m_abbrev_table_holder);
757 }
758
759private:
761 dwarf2_per_objfile *per_objfile,
762 dwarf2_cu *existing_cu);
763
765 std::unique_ptr<dwarf2_cu> m_new_cu;
766
767 /* The ordinary abbreviation table. */
769
770 /* The DWO abbreviation table. */
772};
773
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
776 and friends. */
777static int bits_per_byte = 8;
778
780
781/* When reading a variant, we track a bit more information about the
782 field, and store it in an object of this type. */
783
785{
786 int first_field = -1;
787 int last_field = -1;
788
789 /* A variant can contain other variant parts. */
790 std::vector<variant_part_builder> variant_parts;
791
792 /* If we see a DW_TAG_variant, then this will be set if this is the
793 default branch. */
794 bool default_branch = false;
795 /* If we see a DW_AT_discr_value, then this will be the discriminant
796 value. */
797 ULONGEST discriminant_value = 0;
798 /* If we see a DW_AT_discr_list, then this is a pointer to the list
799 data. */
800 struct dwarf_block *discr_list_data = nullptr;
801};
802
803/* This represents a DW_TAG_variant_part. */
804
806{
807 /* The offset of the discriminant field. */
808 sect_offset discriminant_offset {};
809
810 /* Variants that are direct children of this variant part. */
811 std::vector<variant_field> variants;
812
813 /* True if we're currently reading a variant. */
814 bool processing_variant = false;
815};
816
818{
820 int virtuality = 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
823 this link. */
824 sect_offset offset;
825 struct field field {};
826};
827
829{
830 const char *name = nullptr;
831 std::vector<struct fn_field> fnfields;
832};
833
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. */
838{
839 /* List of data member and baseclasses fields. */
840 std::vector<struct nextfield> fields;
841 std::vector<struct nextfield> baseclasses;
842
843 /* Set if the accessibility of one of the fields is not public. */
844 bool non_public_fields = false;
845
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;
850
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;
854
855 /* Nested types defined by this class and the number of elements in this
856 list. */
857 std::vector<struct decl_field> nested_types_list;
858
859 /* If non-null, this is the variant part we are currently
860 reading. */
862 /* This holds all the top-level variant parts attached to the type
863 we're reading. */
864 std::vector<variant_part_builder> variant_parts;
865
866 /* Return the total number of fields (including baseclasses). */
867 int nfields () const
868 {
869 return fields.size () + baseclasses.size ();
870 }
871};
872
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. */
878static int dwarf_max_cache_age = 5;
879static void
880show_dwarf_max_cache_age (struct ui_file *file, int from_tty,
881 struct cmd_list_element *c, const char *value)
882{
883 gdb_printf (file, _("The upper bound on the age of cached "
884 "DWARF compilation units is %s.\n"),
885 value);
886}
887␌
888/* local function prototypes */
889
890static void dwarf2_find_base_address (struct die_info *die,
891 struct dwarf2_cu *cu);
892
894static void build_type_psymtabs_reader (cutu_reader *reader,
895 cooked_index_storage *storage);
896
897static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile);
898
899static void var_decode_location (struct attribute *attr,
900 struct symbol *sym,
901 struct dwarf2_cu *cu);
902
903static unsigned int peek_abbrev_code (bfd *, const gdb_byte *);
904
905static const gdb_byte *read_attribute (const struct die_reader_specs *,
906 struct attribute *,
907 const struct attr_abbrev *,
908 const gdb_byte *);
909
910static void read_attribute_reprocess (const struct die_reader_specs *reader,
911 struct attribute *attr, dwarf_tag tag);
912
913static CORE_ADDR read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index);
914
915static sect_offset read_abbrev_offset (dwarf2_per_objfile *per_objfile,
916 dwarf2_section_info *, sect_offset);
917
918static const char *read_indirect_string
919 (dwarf2_per_objfile *per_objfile, bfd *, const gdb_byte *,
920 const struct comp_unit_head *, unsigned int *);
921
922static const char *read_indirect_string_at_offset
923 (dwarf2_per_objfile *per_objfile, LONGEST str_offset);
924
925static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *,
926 const gdb_byte *,
927 unsigned int *);
928
929static const char *read_dwo_str_index (const struct die_reader_specs *reader,
930 ULONGEST str_index);
931
932static const char *read_stub_str_index (struct dwarf2_cu *cu,
933 ULONGEST str_index);
934
935static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
936 struct dwarf2_cu *);
937
938static const char *dwarf2_string_attr (struct die_info *die, unsigned int name,
939 struct dwarf2_cu *cu);
940
941static const char *dwarf2_dwo_name (struct die_info *die, struct dwarf2_cu *cu);
942
943static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
944 struct dwarf2_cu *cu);
945
946static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
947
948static struct die_info *die_specification (struct die_info *die,
949 struct dwarf2_cu **);
950
952 struct dwarf2_cu *cu,
953 const char *comp_dir);
954
955static void dwarf_decode_lines (struct line_header *,
956 struct dwarf2_cu *,
957 CORE_ADDR, int decode_mapping);
958
959static void dwarf2_start_subfile (dwarf2_cu *cu, const file_entry &fe,
960 const line_header &lh);
961
962static struct symbol *new_symbol (struct die_info *, struct type *,
963 struct dwarf2_cu *, struct symbol * = NULL);
964
965static void dwarf2_const_value (const struct attribute *, struct symbol *,
966 struct dwarf2_cu *);
967
968static void dwarf2_const_value_attr (const struct attribute *attr,
969 struct type *type,
970 const char *name,
971 struct obstack *obstack,
972 struct dwarf2_cu *cu, LONGEST *value,
973 const gdb_byte **bytes,
974 struct dwarf2_locexpr_baton **baton);
975
976static struct type *read_subrange_index_type (struct die_info *die,
977 struct dwarf2_cu *cu);
978
979static struct type *die_type (struct die_info *, struct dwarf2_cu *);
980
981static int need_gnat_info (struct dwarf2_cu *);
982
983static struct type *die_descriptive_type (struct die_info *,
984 struct dwarf2_cu *);
985
986static void set_descriptive_type (struct type *, struct die_info *,
987 struct dwarf2_cu *);
988
989static struct type *die_containing_type (struct die_info *,
990 struct dwarf2_cu *);
991
992static struct type *lookup_die_type (struct die_info *, const struct attribute *,
993 struct dwarf2_cu *);
994
995static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
996
997static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
998
999static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1000
1001static char *typename_concat (struct obstack *obs, const char *prefix,
1002 const char *suffix, int physname,
1003 struct dwarf2_cu *cu);
1004
1005static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1006
1007static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1008
1009static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1010
1011static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1012
1013static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
1014
1015static void read_variable (struct die_info *die, struct dwarf2_cu *cu);
1016
1017/* Return the .debug_loclists section to use for cu. */
1018static struct dwarf2_section_info *cu_debug_loc_section (struct dwarf2_cu *cu);
1019
1020/* Return the .debug_rnglists section to use for cu. */
1022 (struct dwarf2_cu *cu, dwarf_tag tag);
1023
1024/* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1025 values. Keep the items ordered with increasing constraints compliance. */
1027{
1028 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1030
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. */
1034
1035 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1037
1038 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1040};
1041
1042static enum pc_bounds_kind dwarf2_get_pc_bounds (struct die_info *,
1043 CORE_ADDR *, CORE_ADDR *,
1044 struct dwarf2_cu *,
1045 addrmap *,
1046 void *);
1047
1048static void get_scope_pc_bounds (struct die_info *,
1049 CORE_ADDR *, CORE_ADDR *,
1050 struct dwarf2_cu *);
1051
1052static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1053 CORE_ADDR, struct dwarf2_cu *);
1054
1055static void dwarf2_add_field (struct field_info *, struct die_info *,
1056 struct dwarf2_cu *);
1057
1058static void dwarf2_attach_fields_to_type (struct field_info *,
1059 struct type *, struct dwarf2_cu *);
1060
1061static void dwarf2_add_member_fn (struct field_info *,
1062 struct die_info *, struct type *,
1063 struct dwarf2_cu *);
1064
1065static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1066 struct type *,
1067 struct dwarf2_cu *);
1068
1069static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1070
1071static void read_common_block (struct die_info *, struct dwarf2_cu *);
1072
1073static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1074
1075static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1076
1077static struct using_direct **using_directives (struct dwarf2_cu *cu);
1078
1079static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1080
1081static bool read_alias (struct die_info *die, struct dwarf2_cu *cu);
1082
1083static struct type *read_module_type (struct die_info *die,
1084 struct dwarf2_cu *cu);
1085
1086static const char *namespace_name (struct die_info *die,
1087 int *is_anonymous, struct dwarf2_cu *);
1088
1089static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1090
1091static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *,
1092 bool * = nullptr);
1093
1094static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1095 struct dwarf2_cu *);
1096
1097static struct die_info *read_die_and_siblings_1
1098 (const struct die_reader_specs *, const gdb_byte *, const gdb_byte **,
1099 struct die_info *);
1100
1101static 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);
1105
1106static const gdb_byte *read_full_die_1 (const struct die_reader_specs *,
1107 struct die_info **, const gdb_byte *,
1108 int);
1109
1110static const gdb_byte *read_full_die (const struct die_reader_specs *,
1111 struct die_info **, const gdb_byte *);
1112
1113static void process_die (struct die_info *, struct dwarf2_cu *);
1114
1115static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu *,
1116 struct objfile *);
1117
1118static const char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1119
1120static const char *dwarf2_full_name (const char *name,
1121 struct die_info *die,
1122 struct dwarf2_cu *cu);
1123
1124static const char *dwarf2_physname (const char *name, struct die_info *die,
1125 struct dwarf2_cu *cu);
1126
1127static struct die_info *dwarf2_extension (struct die_info *die,
1128 struct dwarf2_cu **);
1129
1130static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1131
1132static void dump_die_for_error (struct die_info *);
1133
1134static void dump_die_1 (struct ui_file *, int level, int max_level,
1135 struct die_info *);
1136
1137/*static*/ void dump_die (struct die_info *, int max_level);
1138
1139static void store_in_ref_table (struct die_info *,
1140 struct dwarf2_cu *);
1141
1142static struct die_info *follow_die_ref_or_sig (struct die_info *,
1143 const struct attribute *,
1144 struct dwarf2_cu **);
1145
1146static struct die_info *follow_die_ref (struct die_info *,
1147 const struct attribute *,
1148 struct dwarf2_cu **);
1149
1150static struct die_info *follow_die_sig (struct die_info *,
1151 const struct attribute *,
1152 struct dwarf2_cu **);
1153
1154static struct type *get_signatured_type (struct die_info *, ULONGEST,
1155 struct dwarf2_cu *);
1156
1157static struct type *get_DW_AT_signature_type (struct die_info *,
1158 const struct attribute *,
1159 struct dwarf2_cu *);
1160
1161static void load_full_type_unit (dwarf2_per_cu_data *per_cu,
1162 dwarf2_per_objfile *per_objfile);
1163
1164static void read_signatured_type (signatured_type *sig_type,
1165 dwarf2_per_objfile *per_objfile);
1166
1167static 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);
1170
1171/* memory allocation interface */
1172
1173static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1174
1175static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1176
1177static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int, int);
1178
1179static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1180 struct dwarf2_loclist_baton *baton,
1181 const struct attribute *attr);
1182
1183static void dwarf2_symbol_mark_computed (const struct attribute *attr,
1184 struct symbol *sym,
1185 struct dwarf2_cu *cu,
1186 int is_block);
1187
1188static 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);
1192
1194 (sect_offset sect_off, unsigned int offset_in_dwz,
1196
1197static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1198 struct die_info *comp_unit_die,
1199 enum language pretend_language);
1200
1201static struct type *set_die_type (struct die_info *, struct type *,
1202 struct dwarf2_cu *, bool = false);
1203
1204static void create_all_units (dwarf2_per_objfile *per_objfile);
1205
1206static void load_full_comp_unit (dwarf2_per_cu_data *per_cu,
1207 dwarf2_per_objfile *per_objfile,
1208 dwarf2_cu *existing_cu,
1209 bool skip_partial,
1210 enum language pretend_language);
1211
1212static void process_full_comp_unit (dwarf2_cu *cu,
1213 enum language pretend_language);
1214
1215static void process_full_type_unit (dwarf2_cu *cu,
1216 enum language pretend_language);
1217
1218static struct type *get_die_type_at_offset (sect_offset,
1219 dwarf2_per_cu_data *per_cu,
1220 dwarf2_per_objfile *per_objfile);
1221
1222static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1223
1224static void queue_comp_unit (dwarf2_per_cu_data *per_cu,
1225 dwarf2_per_objfile *per_objfile,
1226 enum language pretend_language);
1227
1228static void process_queue (dwarf2_per_objfile *per_objfile);
1229
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. */
1234
1236{
1237public:
1239 : m_per_objfile (per_objfile)
1240 {
1241 gdb_assert (!m_per_objfile->queue.has_value ());
1242
1243 m_per_objfile->queue.emplace ();
1244 }
1245
1246 /* Free any entries remaining on the queue. There should only be
1247 entries left if we hit an error while processing the dwarf. */
1249 {
1250 gdb_assert (m_per_objfile->queue.has_value ());
1251
1252 m_per_objfile->queue.reset ();
1253 }
1254
1256
1257private:
1259};
1260
1262{
1263 /* Anything still marked queued is likely to be in an
1264 inconsistent state, so discard it. */
1265 if (per_cu->queued)
1266 {
1268 per_cu->queued = 0;
1269 }
1270}
1271
1272/* See dwarf2/read.h. */
1273
1274void
1276{
1277 if (data->is_debug_types)
1278 delete static_cast<signatured_type *> (data);
1279 else
1280 delete data;
1281}
1282
1284 (struct die_info *die, struct dwarf2_cu *cu);
1285
1286static 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);
1291
1292static htab_up allocate_signatured_type_table ();
1293
1294static htab_up allocate_dwo_unit_table ();
1295
1296static 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);
1299
1300static struct dwp_file *get_dwp_file (dwarf2_per_objfile *per_objfile);
1301
1302static struct dwo_unit *lookup_dwo_comp_unit
1303 (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
1304 ULONGEST signature);
1305
1306static struct dwo_unit *lookup_dwo_type_unit
1307 (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir);
1308
1309static void queue_and_load_all_dwo_tus (dwarf2_cu *cu);
1310
1311/* A unique pointer to a dwo_file. */
1312
1313typedef std::unique_ptr<struct dwo_file> dwo_file_up;
1314
1315static void process_cu_includes (dwarf2_per_objfile *per_objfile);
1316
1317static void check_producer (struct dwarf2_cu *cu);
1318␌
1319/* Various complaints about symbol reading that don't abort the process. */
1320
1321static void
1323{
1324 complaint (_(".debug_line section has line data without a file"));
1325}
1326
1327static void
1329{
1330 complaint (_(".debug_line section has line "
1331 "program sequence without an end"));
1332}
1333
1334static void
1336{
1337 complaint (_("location expression too complex"));
1338}
1339
1340static void
1342 int arg3)
1343{
1344 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1345 arg1, arg2, arg3);
1346}
1347
1348static void
1349dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
1350{
1351 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1352 arg1, arg2);
1353}
1354
1355/* Hash function for line_header_hash. */
1356
1357static hashval_t
1359{
1360 return to_underlying (ofs->sect_off) ^ ofs->offset_in_dwz;
1361}
1362
1363/* Hash function for htab_create_alloc_ex for line_header_hash. */
1364
1365static hashval_t
1366line_header_hash_voidp (const void *item)
1367{
1368 const struct line_header *ofs = (const struct line_header *) item;
1369
1370 return line_header_hash (ofs);
1371}
1372
1373/* Equality function for line_header_hash. */
1374
1375static int
1376line_header_eq_voidp (const void *item_lhs, const void *item_rhs)
1377{
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;
1380
1381 return (ofs_lhs->sect_off == ofs_rhs->sect_off
1382 && ofs_lhs->offset_in_dwz == ofs_rhs->offset_in_dwz);
1383}
1384
1385␌
1386
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. */
1390
1392{
1393public:
1394
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 ())
1398 {
1399 }
1400
1402 {
1403 ++m_index;
1404 return *this;
1405 }
1406
1408 {
1409 return m_per_bfd->get_cu (m_index);
1410 }
1411
1412 bool operator== (const all_units_iterator &other) const
1413 {
1414 return m_index == other.m_index;
1415 }
1416
1417
1418 bool operator!= (const all_units_iterator &other) const
1419 {
1420 return m_index != other.m_index;
1421 }
1422
1423private:
1424
1426 size_t m_index;
1427};
1428
1429/* A range adapter for the all_units_iterator. */
1431{
1432public:
1433
1435 : m_per_bfd (per_bfd)
1436 {
1437 }
1438
1440 {
1441 return all_units_iterator (m_per_bfd, true);
1442 }
1443
1445 {
1446 return all_units_iterator (m_per_bfd, false);
1447 }
1448
1449private:
1450
1452};
1453
1454/* See declaration. */
1455
1457 bool can_copy_)
1458 : obfd (obfd),
1459 can_copy (can_copy_)
1460{
1461 if (names == NULL)
1462 names = &dwarf2_elf_names;
1463
1464 for (asection *sec = obfd->sections; sec != NULL; sec = sec->next)
1465 locate_sections (obfd, sec, *names);
1466}
1467
1469{
1470 for (auto &per_cu : all_units)
1471 {
1472 per_cu->imported_symtabs_free ();
1473 per_cu->free_cached_file_names ();
1474 }
1475
1476 /* Everything else should be on this->obstack. */
1477}
1478
1479/* See read.h. */
1480
1481void
1483{
1484 gdb_assert (!queue.has_value ());
1485
1486 m_dwarf2_cus.clear ();
1487}
1488
1489/* A helper class that calls free_cached_comp_units on
1490 destruction. */
1491
1493{
1494public:
1495
1497 : m_per_objfile (per_objfile)
1498 {
1499 }
1500
1502 {
1504 }
1505
1507
1508private:
1509
1511};
1512
1513/* See read.h. */
1514
1515bool
1517{
1518 if (per_cu->index < this->m_symtabs.size ())
1519 return this->m_symtabs[per_cu->index] != nullptr;
1520 return false;
1521}
1522
1523/* See read.h. */
1524
1527{
1528 if (per_cu->index < this->m_symtabs.size ())
1529 return this->m_symtabs[per_cu->index];
1530 return nullptr;
1531}
1532
1533/* See read.h. */
1534
1535void
1538{
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;
1543}
1544
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. */
1551
1552int
1554 const struct dwarf2_debug_sections *names,
1555 bool can_copy)
1556{
1558 return 0;
1559
1561
1562 if (per_objfile == NULL)
1563 {
1564 dwarf2_per_bfd *per_bfd;
1565
1566 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1567 BFD doesn't require relocations.
1568
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. */
1573 && (objfile->flags & OBJF_READNOW) == 0)
1574 {
1575 /* See if one has been created for this BFD yet. */
1576 per_bfd = dwarf2_per_bfd_bfd_data_key.get (objfile->obfd.get ());
1577
1578 if (per_bfd == nullptr)
1579 {
1580 /* No, create it now. */
1581 per_bfd = new dwarf2_per_bfd (objfile->obfd.get (), names,
1582 can_copy);
1583 dwarf2_per_bfd_bfd_data_key.set (objfile->obfd.get (), per_bfd);
1584 }
1585 }
1586 else
1587 {
1588 /* No sharing possible, create one specifically for this objfile. */
1589 per_bfd = new dwarf2_per_bfd (objfile->obfd.get (), names, can_copy);
1591 }
1592
1593 per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile, per_bfd);
1594 }
1595
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);
1600}
1601
1602/* See declaration. */
1603
1604void
1605dwarf2_per_bfd::locate_sections (bfd *abfd, asection *sectp,
1606 const dwarf2_debug_sections &names)
1607{
1608 flagword aflag = bfd_section_flags (sectp);
1609
1610 if ((aflag & SEC_HAS_CONTENTS) == 0)
1611 {
1612 }
1613 else if (elf_section_data (sectp)->this_hdr.sh_size
1614 > bfd_get_file_size (abfd))
1615 {
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));
1621 }
1622 else if (names.info.matches (sectp->name))
1623 {
1624 this->info.s.section = sectp;
1625 this->info.size = bfd_section_size (sectp);
1626 }
1627 else if (names.abbrev.matches (sectp->name))
1628 {
1629 this->abbrev.s.section = sectp;
1630 this->abbrev.size = bfd_section_size (sectp);
1631 }
1632 else if (names.line.matches (sectp->name))
1633 {
1634 this->line.s.section = sectp;
1635 this->line.size = bfd_section_size (sectp);
1636 }
1637 else if (names.loc.matches (sectp->name))
1638 {
1639 this->loc.s.section = sectp;
1640 this->loc.size = bfd_section_size (sectp);
1641 }
1642 else if (names.loclists.matches (sectp->name))
1643 {
1644 this->loclists.s.section = sectp;
1645 this->loclists.size = bfd_section_size (sectp);
1646 }
1647 else if (names.macinfo.matches (sectp->name))
1648 {
1649 this->macinfo.s.section = sectp;
1650 this->macinfo.size = bfd_section_size (sectp);
1651 }
1652 else if (names.macro.matches (sectp->name))
1653 {
1654 this->macro.s.section = sectp;
1655 this->macro.size = bfd_section_size (sectp);
1656 }
1657 else if (names.str.matches (sectp->name))
1658 {
1659 this->str.s.section = sectp;
1660 this->str.size = bfd_section_size (sectp);
1661 }
1662 else if (names.str_offsets.matches (sectp->name))
1663 {
1664 this->str_offsets.s.section = sectp;
1665 this->str_offsets.size = bfd_section_size (sectp);
1666 }
1667 else if (names.line_str.matches (sectp->name))
1668 {
1669 this->line_str.s.section = sectp;
1670 this->line_str.size = bfd_section_size (sectp);
1671 }
1672 else if (names.addr.matches (sectp->name))
1673 {
1674 this->addr.s.section = sectp;
1675 this->addr.size = bfd_section_size (sectp);
1676 }
1677 else if (names.frame.matches (sectp->name))
1678 {
1679 this->frame.s.section = sectp;
1680 this->frame.size = bfd_section_size (sectp);
1681 }
1682 else if (names.eh_frame.matches (sectp->name))
1683 {
1684 this->eh_frame.s.section = sectp;
1685 this->eh_frame.size = bfd_section_size (sectp);
1686 }
1687 else if (names.ranges.matches (sectp->name))
1688 {
1689 this->ranges.s.section = sectp;
1690 this->ranges.size = bfd_section_size (sectp);
1691 }
1692 else if (names.rnglists.matches (sectp->name))
1693 {
1694 this->rnglists.s.section = sectp;
1695 this->rnglists.size = bfd_section_size (sectp);
1696 }
1697 else if (names.types.matches (sectp->name))
1698 {
1699 struct dwarf2_section_info type_section;
1700
1701 memset (&type_section, 0, sizeof (type_section));
1702 type_section.s.section = sectp;
1703 type_section.size = bfd_section_size (sectp);
1704
1705 this->types.push_back (type_section);
1706 }
1707 else if (names.gdb_index.matches (sectp->name))
1708 {
1709 this->gdb_index.s.section = sectp;
1710 this->gdb_index.size = bfd_section_size (sectp);
1711 }
1712 else if (names.debug_names.matches (sectp->name))
1713 {
1714 this->debug_names.s.section = sectp;
1715 this->debug_names.size = bfd_section_size (sectp);
1716 }
1717 else if (names.debug_aranges.matches (sectp->name))
1718 {
1719 this->debug_aranges.s.section = sectp;
1720 this->debug_aranges.size = bfd_section_size (sectp);
1721 }
1722
1723 if ((bfd_section_flags (sectp) & (SEC_LOAD | SEC_ALLOC))
1724 && bfd_section_vma (sectp) == 0)
1725 this->has_section_at_zero = true;
1726}
1727
1728/* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1729 SECTION_NAME. */
1730
1731void
1733 enum dwarf2_section_enum sect,
1734 asection **sectp, const gdb_byte **bufp,
1735 bfd_size_type *sizep)
1736{
1738 struct dwarf2_section_info *info;
1739
1740 /* We may see an objfile without any DWARF, in which case we just
1741 return nothing. */
1742 if (per_objfile == NULL)
1743 {
1744 *sectp = NULL;
1745 *bufp = NULL;
1746 *sizep = 0;
1747 return;
1748 }
1749 switch (sect)
1750 {
1751 case DWARF2_DEBUG_FRAME:
1752 info = &per_objfile->per_bfd->frame;
1753 break;
1754 case DWARF2_EH_FRAME:
1755 info = &per_objfile->per_bfd->eh_frame;
1756 break;
1757 default:
1758 gdb_assert_not_reached ("unexpected section");
1759 }
1760
1761 info->read (objfile);
1762
1763 *sectp = info->get_bfd_section ();
1764 *bufp = info->buffer;
1765 *sizep = info->size;
1766}
1767
1768/* See dwarf2/read.h. */
1769
1770void
1772{
1773 info.read (objfile);
1775 line.read (objfile);
1776 str.read (objfile);
1781 addr.read (objfile);
1782
1783 for (auto &section : types)
1784 section.read (objfile);
1785}
1786
1787␌
1788/* DWARF quick_symbol_functions support. */
1789
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. */
1796{
1797 /* The data used to construct the hash key. */
1799
1800 /* The number of entries in file_names, real_names. */
1801 unsigned int num_file_names;
1802
1803 /* The CU directory, as given by DW_AT_comp_dir. May be
1804 nullptr. */
1805 const char *comp_dir;
1806
1807 /* The file names from the line table, after being run through
1808 file_full_name. */
1809 const char **file_names;
1810
1811 /* The file names from the line table after being run through
1812 gdb_realpath. These are computed lazily. */
1813 const char **real_names;
1814};
1815
1817{
1818 bool has_symbols (struct objfile *objfile) override;
1819
1820 bool has_unexpanded_symtabs (struct objfile *objfile) override;
1821
1822 struct symtab *find_last_source_symtab (struct objfile *objfile) override;
1823
1824 void forget_cached_source_info (struct objfile *objfile) override;
1825
1827 const char *name,
1828 domain_enum domain,
1829 bool *symbol_found_p) override
1830 {
1831 *symbol_found_p = false;
1832 return language_unknown;
1833 }
1834
1835 void print_stats (struct objfile *objfile, bool print_bcache) override;
1836
1837 void expand_all_symtabs (struct objfile *objfile) override;
1838
1839 /* A helper function that finds the per-cu object from an "adjusted"
1840 PC -- a PC with the base text offset removed. */
1842 CORE_ADDR adjusted_pc);
1843
1845 (struct objfile *objfile, struct bound_minimal_symbol msymbol,
1846 CORE_ADDR pc, struct obj_section *section, int warn_if_readin)
1847 override final;
1848
1850 (struct objfile *objfile, CORE_ADDR address) override
1851 {
1852 return nullptr;
1853 }
1854
1855 void map_symbol_filenames (struct objfile *objfile,
1856 gdb::function_view<symbol_filename_ftype> fun,
1857 bool need_fullname) override;
1858};
1859
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
1863 code. */
1864
1866{
1867 void dump (struct objfile *objfile) override
1868 {
1869 }
1870
1872 (struct objfile *,
1873 const lookup_name_info &lookup_name,
1874 domain_enum domain,
1875 int global,
1876 symbol_compare_ftype *ordered_compare) override
1877 {
1878 }
1879
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,
1887 domain_enum domain,
1888 enum search_domain kind) override
1889 {
1890 return true;
1891 }
1892};
1893
1895{
1896 void dump (struct objfile *objfile) override;
1897
1899 (struct objfile *,
1900 const lookup_name_info &lookup_name,
1901 domain_enum domain,
1902 int global,
1903 symbol_compare_ftype *ordered_compare) override;
1904
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,
1912 domain_enum domain,
1913 enum search_domain kind) override;
1914};
1915
1917{
1918 void dump (struct objfile *objfile) override;
1919
1921 (struct objfile *,
1922 const lookup_name_info &lookup_name,
1923 domain_enum domain,
1924 int global,
1925 symbol_compare_ftype *ordered_compare) override;
1926
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,
1934 domain_enum domain,
1935 enum search_domain kind) override;
1936};
1937
1940{
1942}
1943
1946{
1948}
1949
1950/* Utility hash function for a stmt_list_hash. */
1951
1952static hashval_t
1954{
1955 hashval_t v = 0;
1956
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);
1960 return v;
1961}
1962
1963/* Utility equality function for a stmt_list_hash. */
1964
1965static int
1967 const struct stmt_list_hash *rhs)
1968{
1969 if ((lhs->dwo_unit != NULL) != (rhs->dwo_unit != NULL))
1970 return 0;
1971 if (lhs->dwo_unit != NULL
1972 && lhs->dwo_unit->dwo_file != rhs->dwo_unit->dwo_file)
1973 return 0;
1974
1975 return lhs->line_sect_off == rhs->line_sect_off;
1976}
1977
1978/* Hash function for a quick_file_names. */
1979
1980static hashval_t
1982{
1983 const struct quick_file_names *file_data
1984 = (const struct quick_file_names *) e;
1985
1986 return hash_stmt_list_entry (&file_data->hash);
1987}
1988
1989/* Equality function for a quick_file_names. */
1990
1991static int
1992eq_file_name_entry (const void *a, const void *b)
1993{
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;
1996
1997 return eq_stmt_list_entry (&ea->hash, &eb->hash);
1998}
1999
2000/* Create a quick_file_names hash table. */
2001
2002static htab_up
2003create_quick_file_names_table (unsigned int nr_initial_entries)
2004{
2005 return htab_up (htab_create_alloc (nr_initial_entries,
2007 nullptr, xcalloc, xfree));
2008}
2009
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. */
2013
2014static dwarf2_cu *
2016 bool skip_partial)
2017{
2018 if (per_cu->is_debug_types)
2019 load_full_type_unit (per_cu, per_objfile);
2020 else
2021 load_full_comp_unit (per_cu, per_objfile, per_objfile->get_cu (per_cu),
2022 skip_partial, language_minimal);
2023
2024 dwarf2_cu *cu = per_objfile->get_cu (per_cu);
2025 if (cu == nullptr)
2026 return nullptr; /* Dummy CU. */
2027
2029
2030 return cu;
2031}
2032
2033/* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2034
2035static void
2037 dwarf2_per_objfile *per_objfile, bool skip_partial)
2038{
2039 {
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);
2044
2045 if (!per_objfile->symtab_set_p (per_cu))
2046 {
2047 queue_comp_unit (per_cu, per_objfile, language_minimal);
2048 dwarf2_cu *cu = load_cu (per_cu, per_objfile, skip_partial);
2049
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
2054 && cu != NULL
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)
2061 }
2062
2063 process_queue (per_objfile);
2064 }
2065
2066 /* Age the cache, releasing compilation units that have not
2067 been used recently. */
2068 per_objfile->age_comp_units ();
2069}
2070
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.
2073
2074 Returns the resulting symbol table. */
2075
2076static struct compunit_symtab *
2078 dwarf2_per_objfile *per_objfile,
2079 bool skip_partial)
2080{
2081 if (!per_objfile->symtab_set_p (per_cu))
2082 {
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);
2087 }
2088
2089 return per_objfile->get_symtab (per_cu);
2090}
2091
2092/* See read.h. */
2093
2096{
2098 result->per_bfd = this;
2099 result->index = all_units.size ();
2100 return result;
2101}
2102
2103/* See read.h. */
2104
2107{
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;
2112 tu_stats.nr_tus++;
2113 return result;
2114}
2115
2116/* Return a new dwarf2_per_cu_data allocated on the per-bfd
2117 obstack, and constructed with the specified field values. */
2118
2121 struct dwarf2_section_info *section,
2122 int is_dwz,
2123 sect_offset sect_off, ULONGEST length)
2124{
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;
2130 return the_cu;
2131}
2132
2133/* A helper for create_cus_from_index that handles a given list of
2134 CUs. */
2135
2136static void
2138 const gdb_byte *cu_list, offset_type n_elements,
2139 struct dwarf2_section_info *section,
2140 int is_dwz)
2141{
2142 for (offset_type i = 0; i < n_elements; i += 2)
2143 {
2144 gdb_static_assert (sizeof (ULONGEST) >= 8);
2145
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);
2149 cu_list += 2 * 8;
2150
2152 = create_cu_from_index_list (per_bfd, section, is_dwz, sect_off,
2153 length);
2154 per_bfd->all_units.push_back (std::move (per_cu));
2155 }
2156}
2157
2158/* Read the CU list from the mapped index, and use it to create all
2159 the CU objects for PER_BFD. */
2160
2161static void
2163 const gdb_byte *cu_list, offset_type cu_list_elements,
2164 const gdb_byte *dwz_list, offset_type dwz_elements)
2165{
2166 gdb_assert (per_bfd->all_units.empty ());
2167 per_bfd->all_units.reserve ((cu_list_elements + dwz_elements) / 2);
2168
2169 create_cus_from_index_list (per_bfd, cu_list, cu_list_elements,
2170 &per_bfd->info, 0);
2171
2172 if (dwz_elements == 0)
2173 return;
2174
2175 dwz_file *dwz = dwarf2_get_dwz_file (per_bfd);
2176 create_cus_from_index_list (per_bfd, dwz_list, dwz_elements,
2177 &dwz->info, 1);
2178}
2179
2180/* Create the signatured type hash table from the index. */
2181
2182static void
2184 (dwarf2_per_bfd *per_bfd, struct dwarf2_section_info *section,
2185 const gdb_byte *bytes, offset_type elements)
2186{
2187 htab_up sig_types_hash = allocate_signatured_type_table ();
2188
2189 for (offset_type i = 0; i < elements; i += 3)
2190 {
2191 signatured_type_up sig_type;
2192 ULONGEST signature;
2193 void **slot;
2194 cu_offset type_offset_in_tu;
2195
2196 gdb_static_assert (sizeof (ULONGEST) >= 8);
2197 sect_offset sect_off
2198 = (sect_offset) extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
2199 type_offset_in_tu
2200 = (cu_offset) extract_unsigned_integer (bytes + 8, 8,
2201 BFD_ENDIAN_LITTLE);
2202 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
2203 bytes += 3 * 8;
2204
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;
2209
2210 slot = htab_find_slot (sig_types_hash.get (), sig_type.get (), INSERT);
2211 *slot = sig_type.get ();
2212
2213 per_bfd->all_units.emplace_back (sig_type.release ());
2214 }
2215
2216 per_bfd->signatured_types = std::move (sig_types_hash);
2217}
2218
2219/* Create the signatured type hash table from .debug_names. */
2220
2221static void
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)
2227{
2228 struct objfile *objfile = per_objfile->objfile;
2229
2230 section->read (objfile);
2231 abbrev_section->read (objfile);
2232
2233 htab_up sig_types_hash = allocate_signatured_type_table ();
2234
2235 for (uint32_t i = 0; i < map.tu_count; ++i)
2236 {
2237 signatured_type_up sig_type;
2238 void **slot;
2239
2240 sect_offset sect_off
2241 = (sect_offset) (extract_unsigned_integer
2242 (map.tu_table_reordered + i * map.offset_size,
2243 map.offset_size,
2244 map.dwarf5_byte_order));
2245
2246 comp_unit_head cu_header;
2247 read_and_check_comp_unit_head (per_objfile, &cu_header, section,
2248 abbrev_section,
2249 section->buffer + to_underlying (sect_off),
2251
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;
2257
2258 slot = htab_find_slot (sig_types_hash.get (), sig_type.get (), INSERT);
2259 *slot = sig_type.get ();
2260
2261 per_objfile->per_bfd->all_units.emplace_back (sig_type.release ());
2262 }
2263
2264 per_objfile->per_bfd->signatured_types = std::move (sig_types_hash);
2265}
2266
2267/* Read the address map data from the mapped index, and use it to
2268 populate the index_addrmap. */
2269
2270static void
2272 struct mapped_index *index)
2273{
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;
2278 CORE_ADDR baseaddr;
2279
2280 addrmap_mutable mutable_map;
2281
2282 iter = index->address_table.data ();
2283 end = iter + index->address_table.size ();
2284
2285 baseaddr = objfile->text_section_offset ();
2286
2287 while (iter < end)
2288 {
2289 ULONGEST hi, lo, cu_index;
2290 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2291 iter += 8;
2292 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2293 iter += 8;
2294 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
2295 iter += 4;
2296
2297 if (lo > hi)
2298 {
2299 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2300 hex_string (lo), hex_string (hi));
2301 continue;
2302 }
2303
2304 if (cu_index >= per_bfd->all_units.size ())
2305 {
2306 complaint (_(".gdb_index address table has invalid CU number %u"),
2307 (unsigned) cu_index);
2308 continue;
2309 }
2310
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));
2314 }
2315
2316 per_bfd->index_addrmap
2317 = new (&per_bfd->obstack) addrmap_fixed (&per_bfd->obstack, &mutable_map);
2318}
2319
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
2322 failure. */
2323
2324static bool
2326 struct dwarf2_section_info *section,
2327 addrmap *mutable_map)
2328{
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;
2334
2335 std::unordered_map<sect_offset,
2337 gdb::hash_enum<sect_offset>>
2338 debug_info_offset_to_per_cu;
2339 for (const auto &per_cu : per_bfd->all_units)
2340 {
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)
2346 continue;
2347
2348 const auto insertpair
2349 = debug_info_offset_to_per_cu.emplace (per_cu->sect_off,
2350 per_cu.get ());
2351
2352 /* Assume no duplicate offsets in all_units. */
2353 gdb_assert (insertpair.second);
2354 }
2355
2356 std::set<sect_offset> debug_info_offset_seen;
2357
2358 section->read (objfile);
2359
2360 const bfd_endian dwarf5_byte_order = gdbarch_byte_order (gdbarch);
2361
2362 const gdb_byte *addr = section->buffer;
2363
2364 while (addr < section->buffer + section->size)
2365 {
2366 const gdb_byte *const entry_addr = addr;
2367 unsigned int bytes_read;
2368
2369 const LONGEST entry_length = read_initial_length (abfd, addr,
2370 &bytes_read);
2371 addr += bytes_read;
2372
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)
2377 {
2378 warning (_("Section .debug_aranges in %s entry at offset %s "
2379 "length %s exceeds section length %s, "
2380 "ignoring .debug_aranges."),
2382 plongest (entry_addr - section->buffer),
2383 plongest (bytes_read + entry_length),
2384 pulongest (section->size));
2385 return false;
2386 }
2387
2388 /* The version number. */
2389 const uint16_t version = read_2_bytes (abfd, addr);
2390 addr += 2;
2391 if (version != 2)
2392 {
2393 warning (_("Section .debug_aranges in %s entry at offset %s "
2394 "has unsupported version %d, ignoring .debug_aranges."),
2396 plongest (entry_addr - section->buffer), version);
2397 return false;
2398 }
2399
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 ())
2406 {
2407 warning (_("Section .debug_aranges in %s entry at offset %s "
2408 "debug_info_offset %s does not exists, "
2409 "ignoring .debug_aranges."),
2411 plongest (entry_addr - section->buffer),
2412 pulongest (debug_info_offset));
2413 return false;
2414 }
2415 const auto insertpair
2416 = debug_info_offset_seen.insert (sect_offset (debug_info_offset));
2417 if (!insertpair.second)
2418 {
2419 warning (_("Section .debug_aranges in %s has duplicate "
2420 "debug_info_offset %s, ignoring .debug_aranges."),
2422 sect_offset_str (sect_offset (debug_info_offset)));
2423 return false;
2424 }
2425 dwarf2_per_cu_data *const per_cu = per_cu_it->second;
2426
2427 const uint8_t address_size = *addr++;
2428 if (address_size < 1 || address_size > 8)
2429 {
2430 warning (_("Section .debug_aranges in %s entry at offset %s "
2431 "address_size %u is invalid, ignoring .debug_aranges."),
2433 plongest (entry_addr - section->buffer), address_size);
2434 return false;
2435 }
2436
2437 const uint8_t segment_selector_size = *addr++;
2438 if (segment_selector_size != 0)
2439 {
2440 warning (_("Section .debug_aranges in %s entry at offset %s "
2441 "segment_selector_size %u is not supported, "
2442 "ignoring .debug_aranges."),
2444 plongest (entry_addr - section->buffer),
2445 segment_selector_size);
2446 return false;
2447 }
2448
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
2455 bytes. */
2456 addr += (entry_end - addr) % (2 * address_size);
2457
2458 while (addr < entry_end)
2459 {
2460 if (addr + 2 * address_size > entry_end)
2461 {
2462 warning (_("Section .debug_aranges in %s entry at offset %s "
2463 "address list is not properly terminated, "
2464 "ignoring .debug_aranges."),
2466 plongest (entry_addr - section->buffer));
2467 return false;
2468 }
2469 ULONGEST start = extract_unsigned_integer (addr, address_size,
2470 dwarf5_byte_order);
2471 addr += address_size;
2472 ULONGEST length = extract_unsigned_integer (addr, address_size,
2473 dwarf5_byte_order);
2474 addr += address_size;
2475 if (start == 0 && length == 0)
2476 {
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
2481 of the loop. */
2482 continue;
2483 }
2484 if (start == 0 && !per_bfd->has_section_at_zero)
2485 {
2486 /* Symbol was eliminated due to a COMDAT group. */
2487 continue;
2488 }
2489 ULONGEST end = start + length;
2490 start = (gdbarch_adjust_dwarf2_addr (gdbarch, start + baseaddr)
2491 - baseaddr);
2492 end = (gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr)
2493 - baseaddr);
2494 mutable_map->set_empty (start, end - 1, per_cu);
2495 }
2496
2497 per_cu->addresses_seen = true;
2498 }
2499
2500 return true;
2501}
2502
2503/* Read the address map data from DWARF-5 .debug_aranges, and use it to
2504 populate the index_addrmap. */
2505
2506static void
2508 struct dwarf2_section_info *section)
2509{
2510 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
2511
2512 addrmap_mutable mutable_map;
2513
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,
2517 &mutable_map);
2518}
2519
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.
2524
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.
2528
2529 Returns true if all went well, false otherwise. */
2530
2531static bool
2532read_gdb_index_from_buffer (const char *filename,
2533 bool deprecated_ok,
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)
2540{
2541 const gdb_byte *addr = &buffer[0];
2542 offset_view metadata (buffer);
2543
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
2549 indices. */
2550 if (version < 4)
2551 {
2552 static int warning_printed = 0;
2553 if (!warning_printed)
2554 {
2555 warning (_("Skipping obsolete .gdb_index section in %s."),
2556 filename);
2557 warning_printed = 1;
2558 }
2559 return 0;
2560 }
2561 /* Index version 4 uses a different hash function than index version
2562 5 and later.
2563
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)
2570 {
2571 static int warning_printed = 0;
2572 if (!warning_printed)
2573 {
2574 warning (_("\
2575Skipping deprecated .gdb_index section in %s.\n\
2576Do \"set use-deprecated-index-sections on\" before the file is read\n\
2577to use the section anyway."),
2578 filename);
2579 warning_printed = 1;
2580 }
2581 return 0;
2582 }
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. */
2590
2591 /* Indexes with higher version than the one supported by GDB may be no
2592 longer backward compatible. */
2593 if (version > 8)
2594 return 0;
2595
2596 map->version = version;
2597
2598 int i = 1;
2599 *cu_list = addr + metadata[i];
2600 *cu_list_elements = (metadata[i + 1] - metadata[i]) / 8;
2601 ++i;
2602
2603 *types_list = addr + metadata[i];
2604 *types_list_elements = (metadata[i + 1] - metadata[i]) / 8;
2605 ++i;
2606
2607 const gdb_byte *address_table = addr + metadata[i];
2608 const gdb_byte *address_table_end = addr + metadata[i + 1];
2609 map->address_table
2610 = gdb::array_view<const gdb_byte> (address_table, address_table_end);
2611 ++i;
2612
2613 const gdb_byte *symbol_table = addr + metadata[i];
2614 const gdb_byte *symbol_table_end = addr + metadata[i + 1];
2615 map->symbol_table
2616 = offset_view (gdb::array_view<const gdb_byte> (symbol_table,
2617 symbol_table_end));
2618
2619 ++i;
2620 map->constant_pool = buffer.slice (metadata[i]);
2621
2622 if (map->constant_pool.empty () && !map->symbol_table.empty ())
2623 {
2624 /* An empty constant pool implies that all symbol table entries are
2625 empty. Make map->symbol_table.empty () == true. */
2626 map->symbol_table
2627 = offset_view (gdb::array_view<const gdb_byte> (symbol_table,
2628 symbol_table));
2629 }
2630
2631 return 1;
2632}
2633
2634static void finalize_all_units (dwarf2_per_bfd *per_bfd);
2635
2636/* Callback types for dwarf2_read_gdb_index. */
2637
2638typedef gdb::function_view
2639 <gdb::array_view<const gdb_byte>(objfile *, dwarf2_per_bfd *)>
2641typedef gdb::function_view
2642 <gdb::array_view<const gdb_byte>(objfile *, dwz_file *)>
2644
2645/* Read .gdb_index. If everything went ok, initialize the "quick"
2646 elements of all the CUs and return 1. Otherwise, return 0. */
2647
2648static int
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)
2653{
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;
2659
2660 gdb::array_view<const gdb_byte> main_index_contents
2661 = get_gdb_index_contents (objfile, per_bfd);
2662
2663 if (main_index_contents.empty ())
2664 return 0;
2665
2666 std::unique_ptr<struct mapped_index> map (new struct mapped_index);
2669 main_index_contents, map.get (), &cu_list,
2670 &cu_list_elements, &types_list,
2671 &types_list_elements))
2672 return 0;
2673
2674 /* Don't use the index if it's empty. */
2675 if (map->symbol_table.empty ())
2676 return 0;
2677
2678 /* If there is a .dwz file, read it so we can get its CU list as
2679 well. */
2681 if (dwz != NULL)
2682 {
2683 struct mapped_index dwz_map;
2684 const gdb_byte *dwz_types_ignore;
2685 offset_type dwz_types_elements_ignore;
2686
2687 gdb::array_view<const gdb_byte> dwz_index_content
2688 = get_gdb_index_contents_dwz (objfile, dwz);
2689
2690 if (dwz_index_content.empty ())
2691 return 0;
2692
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,
2696 &dwz_types_ignore,
2697 &dwz_types_elements_ignore))
2698 {
2699 warning (_("could not read '.gdb_index' section from %s; skipping"),
2700 bfd_get_filename (dwz->dwz_bfd.get ()));
2701 return 0;
2702 }
2703 }
2704
2705 create_cus_from_index (per_bfd, cu_list, cu_list_elements, dwz_list,
2706 dwz_list_elements);
2707
2708 if (types_list_elements)
2709 {
2710 /* We can only handle a single .debug_types when we have an
2711 index. */
2712 if (per_bfd->types.size () > 1)
2713 {
2714 per_bfd->all_units.clear ();
2715 return 0;
2716 }
2717
2718 dwarf2_section_info *section
2719 = (per_bfd->types.size () == 1
2720 ? &per_bfd->types[0]
2721 : &per_bfd->info);
2722
2723 create_signatured_type_table_from_index (per_bfd, section, types_list,
2724 types_list_elements);
2725 }
2726
2727 finalize_all_units (per_bfd);
2728
2729 create_addrmap_from_index (per_objfile, map.get ());
2730
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 ());
2734
2735 return 1;
2736}
2737
2738/* die_reader_func for dw2_get_file_names. */
2739
2740static void
2742 struct die_info *comp_unit_die)
2743{
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;
2749 void **slot;
2750 struct quick_file_names *qfn;
2751
2752 gdb_assert (! this_cu->is_debug_types);
2753
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)
2758 return;
2759
2760 lh_cu = this_cu;
2761 slot = NULL;
2762
2763 line_header_up lh;
2764 sect_offset line_offset {};
2765
2766 file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu);
2767
2768 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu);
2769 if (attr != nullptr && attr->form_is_unsigned ())
2770 {
2772
2773 line_offset = (sect_offset) attr->as_unsigned ();
2774
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);
2781 if (*slot != NULL)
2782 {
2783 lh_cu->file_names = (struct quick_file_names *) *slot;
2784 return;
2785 }
2786
2788 }
2789
2790 int offset = 0;
2791 if (!fnd.is_unknown ())
2792 ++offset;
2793 else if (lh == nullptr)
2794 return;
2795
2796 qfn = XOBNEW (&per_objfile->per_bfd->obstack, struct quick_file_names);
2797 qfn->hash.dwo_unit = cu->dwo_unit;
2799 /* There may not be a DW_AT_stmt_list. */
2800 if (slot != nullptr)
2801 *slot = qfn;
2802
2803 std::vector<const char *> include_names;
2804 if (lh != nullptr)
2805 {
2806 for (const auto &entry : lh->file_names ())
2807 {
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)
2812 {
2813 include_name = per_objfile->objfile->intern (include_name);
2814 include_names.push_back (include_name);
2815 }
2816 }
2817 }
2818
2819 qfn->num_file_names = offset + include_names.size ();
2820 qfn->comp_dir = fnd.intern_comp_dir (per_objfile->objfile);
2821 qfn->file_names =
2822 XOBNEWVEC (&per_objfile->per_bfd->obstack, const char *,
2823 qfn->num_file_names);
2824 if (offset != 0)
2825 qfn->file_names[0] = per_objfile->objfile->intern (fnd.get_name ());
2826
2827 if (!include_names.empty ())
2828 memcpy (&qfn->file_names[offset], include_names.data (),
2829 include_names.size () * sizeof (const char *));
2830
2831 qfn->real_names = NULL;
2832
2833 lh_cu->file_names = qfn;
2834}
2835
2836/* A helper for the "quick" functions which attempts to read the line
2837 table for THIS_CU. */
2838
2839static struct quick_file_names *
2841 dwarf2_per_objfile *per_objfile)
2842{
2843 /* This should never be called for TUs. */
2844 gdb_assert (! this_cu->is_debug_types);
2845
2846 if (this_cu->files_read)
2847 return this_cu->file_names;
2848
2849 cutu_reader reader (this_cu, per_objfile);
2850 if (!reader.dummy_p)
2851 dw2_get_file_names_reader (&reader, reader.comp_unit_die);
2852
2853 return this_cu->file_names;
2854}
2855
2856/* A helper for the "quick" functions which computes and caches the
2857 real path for a given file name from the line table. */
2858
2859static const char *
2861 struct quick_file_names *qfn, int index)
2862{
2863 if (qfn->real_names == NULL)
2864 qfn->real_names = OBSTACK_CALLOC (&per_objfile->per_bfd->obstack,
2865 qfn->num_file_names, const char *);
2866
2867 if (qfn->real_names[index] == NULL)
2868 {
2869 const char *dirname = nullptr;
2870
2871 if (!IS_ABSOLUTE_PATH (qfn->file_names[index]))
2872 dirname = qfn->comp_dir;
2873
2874 gdb::unique_xmalloc_ptr<char> fullname;
2875 fullname = find_source_or_rewrite (qfn->file_names[index], dirname);
2876
2877 qfn->real_names[index] = fullname.release ();
2878 }
2879
2880 return qfn->real_names[index];
2881}
2882
2883struct symtab *
2885{
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);
2890
2891 if (cust == NULL)
2892 return NULL;
2893
2894 return cust->primary_filetab ();
2895}
2896
2897/* See read.h. */
2898
2899void
2901{
2902 if (fnd != nullptr)
2903 fnd->forget_fullname ();
2904
2905 if (per_bfd == nullptr)
2906 return;
2907
2908 struct quick_file_names *file_data = file_names;
2909 if (file_data != nullptr && file_data->real_names != nullptr)
2910 {
2911 for (int i = 0; i < file_data->num_file_names; ++i)
2912 {
2913 xfree ((void *) file_data->real_names[i]);
2914 file_data->real_names[i] = nullptr;
2915 }
2916 }
2917}
2918
2919void
2921 (struct objfile *objfile)
2922{
2924
2925 for (auto &per_cu : per_objfile->per_bfd->all_units)
2926 per_cu->free_cached_file_names ();
2927}
2928
2929/* Struct used to manage iterating over all CUs looking for a symbol. */
2930
2932{
2933 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
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. */
2944 int next;
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
2950 indices. */
2952};
2953
2954/* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
2955
2956static void
2958 dwarf2_per_objfile *per_objfile,
2959 gdb::optional<block_enum> block_index,
2960 domain_enum domain, offset_type namei,
2961 mapped_index &index)
2962{
2963 iter->per_objfile = per_objfile;
2964 iter->block_index = block_index;
2965 iter->domain = domain;
2966 iter->next = 0;
2967 iter->global_seen = 0;
2968 iter->vec = {};
2969 iter->length = 0;
2970
2971 gdb_assert (!index.symbol_name_slot_invalid (namei));
2972 offset_type vec_idx = index.symbol_vec_index (namei);
2973
2974 iter->vec = offset_view (index.constant_pool.slice (vec_idx));
2975 iter->length = iter->vec[0];
2976}
2977
2978/* Return the next matching CU or NULL if there are no more. */
2979
2980static struct dwarf2_per_cu_data *
2983{
2984 dwarf2_per_objfile *per_objfile = iter->per_objfile;
2985
2986 for ( ; iter->next < iter->length; ++iter->next)
2987 {
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);
2998
2999 /* Don't crash on bad data. */
3000 if (cu_index >= per_objfile->per_bfd->all_units.size ())
3001 {
3002 complaint (_(".gdb_index entry has bad CU index"
3003 " [in module %s]"), objfile_name (per_objfile->objfile));
3004 continue;
3005 }
3006
3007 dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cu (cu_index);
3008
3009 /* Skip if already read in. */
3010 if (per_objfile->symtab_set_p (per_cu))
3011 continue;
3012
3013 /* Check static vs global. */
3014 if (attrs_valid)
3015 {
3016 bool is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs);
3017
3018 if (iter->block_index.has_value ())
3019 {
3020 bool want_static = *iter->block_index == STATIC_BLOCK;
3021
3022 if (is_static != want_static)
3023 continue;
3024 }
3025
3026 /* Work around gold/15646. */
3027 if (!is_static
3028 && symbol_kind == GDB_INDEX_SYMBOL_KIND_TYPE)
3029 {
3030 if (iter->global_seen)
3031 continue;
3032
3033 iter->global_seen = 1;
3034 }
3035 }
3036
3037 /* Only check the symbol's kind if it has one. */
3038 if (attrs_valid)
3039 {
3040 switch (iter->domain)
3041 {
3042 case VAR_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)
3047 continue;
3048 break;
3049 case STRUCT_DOMAIN:
3050 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3051 continue;
3052 break;
3053 case LABEL_DOMAIN:
3054 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
3055 continue;
3056 break;
3057 case MODULE_DOMAIN:
3058 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
3059 continue;
3060 break;
3061 default:
3062 break;
3063 }
3064 }
3065
3066 ++iter->next;
3067 return per_cu;
3068 }
3069
3070 return NULL;
3071}
3072
3073void
3075 bool print_bcache)
3076{
3077 if (print_bcache)
3078 return;
3079
3081 int total = per_objfile->per_bfd->all_units.size ();
3082 int count = 0;
3083
3084 for (int i = 0; i < total; ++i)
3085 {
3086 dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cu (i);
3087
3088 if (!per_objfile->symtab_set_p (per_cu))
3089 ++count;
3090 }
3091 gdb_printf (_(" Number of read CUs: %d\n"), total - count);
3092 gdb_printf (_(" Number of unread CUs: %d\n"), count);
3093}
3094
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. */
3099
3100void
3102{
3104
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);
3108 gdb_printf ("\n");
3109}
3110
3111void
3113{
3115 int total_units = per_objfile->per_bfd->all_units.size ();
3116
3117 for (int i = 0; i < total_units; ++i)
3118 {
3119 dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cu (i);
3120
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);
3127 }
3128}
3129
3130static bool
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);
3137
3138static bool
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);
3144
3145void
3147 (struct objfile *objfile,
3148 const lookup_name_info &name, domain_enum domain,
3149 int global,
3150 symbol_compare_ftype *ordered_compare)
3151{
3152 /* Used for Ada. */
3154
3155 const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
3156
3157 mapped_index &index
3158 = *(gdb::checked_static_cast<mapped_index *>
3159 (per_objfile->per_bfd->index_table.get ()));
3160
3161 const char *match_name = name.ada ().lookup_name ().c_str ();
3162 auto matcher = [&] (const char *symname)
3163 {
3164 if (ordered_compare == nullptr)
3165 return true;
3166 return ordered_compare (symname, match_name) == 0;
3167 };
3168
3170 [&] (offset_type namei)
3171 {
3172 struct dw2_symtab_iterator iter;
3173 struct dwarf2_per_cu_data *per_cu;
3174
3175 dw2_symtab_iter_init (&iter, per_objfile, block_kind, domain, namei,
3176 index);
3177 while ((per_cu = dw2_symtab_iter_next (&iter, index)) != NULL)
3178 dw2_expand_symtabs_matching_one (per_cu, per_objfile, nullptr,
3179 nullptr);
3180 return true;
3181 }, per_objfile);
3182}
3183
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. */
3188
3189static std::string
3190make_sort_after_prefix_name (const char *search_name)
3191{
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
3209 string.
3210
3211 Some examples of this operation:
3212
3213 SEARCH_NAME => "+1" RESULT
3214
3215 "abc" => "abd"
3216 "ab\xff" => "ac"
3217 "\xff" "a" "\xff" => "\xff" "b"
3218 "\xff" => ""
3219 "\xff\xff" => ""
3220 "" => ""
3221
3222 Then, with these symbols for example:
3223
3224 func
3225 func1
3226 fund
3227
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".
3231
3232 And with:
3233
3234 funcÿ (Latin1 'ÿ' [0xff])
3235 funcÿ1
3236 fund
3237
3238 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3239 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3240
3241 And with:
3242
3243 ÿÿ (Latin1 'ÿ' [0xff])
3244 ÿÿ1
3245
3246 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3247 the end of the list.
3248 */
3249 std::string after = search_name;
3250 while (!after.empty () && (unsigned char) after.back () == 0xff)
3251 after.pop_back ();
3252 if (!after.empty ())
3253 after.back () = (unsigned char) after.back () + 1;
3254 return after;
3255}
3256
3257/* See declaration. */
3258
3259std::pair<std::vector<name_component>::const_iterator,
3260 std::vector<name_component>::const_iterator>
3262 (const lookup_name_info &lookup_name_without_params, language lang,
3263 dwarf2_per_objfile *per_objfile) const
3264{
3265 auto *name_cmp
3266 = this->name_components_casing == case_sensitive_on ? strcmp : strcasecmp;
3267
3268 const char *lang_name
3269 = lookup_name_without_params.language_lookup_name (lang);
3270
3271 /* Comparison function object for lower_bound that matches against a
3272 given symbol name. */
3273 auto lookup_compare_lower = [&] (const name_component &elem,
3274 const char *name)
3275 {
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;
3279 };
3280
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)
3285 {
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;
3289 };
3290
3291 auto begin = this->name_components.begin ();
3292 auto end = this->name_components.end ();
3293
3294 /* Find the lower bound. */
3295 auto lower = [&] ()
3296 {
3297 if (lookup_name_without_params.completion_mode () && lang_name[0] == '\0')
3298 return begin;
3299 else
3300 return std::lower_bound (begin, end, lang_name, lookup_compare_lower);
3301 } ();
3302
3303 /* Find the upper bound. */
3304 auto upper = [&] ()
3305 {
3306 if (lookup_name_without_params.completion_mode ())
3307 {
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":
3311
3312 function << lower bound
3313 function1
3314 other_function << upper bound
3315
3316 We find the upper bound by looking for the insertion
3317 point of "func"-with-last-character-incremented,
3318 i.e. "fund". */
3319 std::string after = make_sort_after_prefix_name (lang_name);
3320 if (after.empty ())
3321 return end;
3322 return std::lower_bound (lower, end, after.c_str (),
3323 lookup_compare_lower);
3324 }
3325 else
3326 return std::upper_bound (lower, end, lang_name, lookup_compare_upper);
3327 } ();
3328
3329 return {lower, upper};
3330}
3331
3332/* See declaration. */
3333
3334void
3336{
3337 if (!this->name_components.empty ())
3338 return;
3339
3341 auto *name_cmp
3342 = this->name_components_casing == case_sensitive_on ? strcmp : strcasecmp;
3343
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++)
3349 {
3350 if (this->symbol_name_slot_invalid (idx))
3351 continue;
3352
3353 const char *name = this->symbol_name_at (idx, per_objfile);
3354
3355 /* Add each name component to the name component table. */
3356 unsigned int previous_len = 0;
3357
3358 if (strstr (name, "::") != nullptr)
3359 {
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))
3363 {
3364 gdb_assert (name[current_len] == ':');
3365 this->name_components.push_back ({previous_len, idx});
3366 /* Skip the '::'. */
3367 current_len += 2;
3368 previous_len = current_len;
3369 }
3370 }
3371 else
3372 {
3373 /* Handle the Ada encoded (aka mangled) form here. */
3374 for (const char *iter = strstr (name, "__");
3375 iter != nullptr;
3376 iter = strstr (iter, "__"))
3377 {
3378 this->name_components.push_back ({previous_len, idx});
3379 iter += 2;
3380 previous_len = iter - name;
3381 }
3382 }
3383
3384 this->name_components.push_back ({previous_len, idx});
3385 }
3386
3387 /* Sort name_components elements by name. */
3388 auto name_comp_compare = [&] (const name_component &left,
3389 const name_component &right)
3390 {
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);
3395
3396 const char *left_name = left_qualified + left.name_offset;
3397 const char *right_name = right_qualified + right.name_offset;
3398
3399 return name_cmp (left_name, right_name) < 0;
3400 };
3401
3402 std::sort (this->name_components.begin (),
3403 this->name_components.end (),
3404 name_comp_compare);
3405}
3406
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. */
3413
3414static bool
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)
3421{
3422 lookup_name_info lookup_name_without_params
3423 = lookup_name_in.make_ignore_params ();
3424
3425 /* Build the symbol name component sorted vector, if we haven't
3426 yet. */
3427 index.build_name_components (per_objfile);
3428
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
3435 duplicates. */
3436 std::vector<offset_type> matches;
3437
3438 struct name_and_matcher
3439 {
3441 const char *name;
3442
3443 bool operator== (const name_and_matcher &other) const
3444 {
3445 return matcher == other.matcher && strcmp (name, other.name) == 0;
3446 }
3447 };
3448
3449 /* A vector holding all the different symbol name matchers, for all
3450 languages. */
3451 std::vector<name_and_matcher> matchers;
3452
3453 for (int i = 0; i < nr_languages; i++)
3454 {
3455 enum language lang_e = (enum language) i;
3456
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);
3460
3461 name_and_matcher key {
3462 name_matcher,
3463 lookup_name_without_params.language_lookup_name (lang_e)
3464 };
3465
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
3469 low. */
3470 if (std::find (matchers.begin (), matchers.end (), key)
3471 != matchers.end ())
3472 continue;
3473 matchers.push_back (std::move (key));
3474
3475 auto bounds
3476 = index.find_name_components_bounds (lookup_name_without_params,
3477 lang_e, per_objfile);
3478
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. */
3481
3482 for (; bounds.first != bounds.second; ++bounds.first)
3483 {
3484 const char *qualified
3485 = index.symbol_name_at (bounds.first->idx, per_objfile);
3486
3487 if (!name_matcher (qualified, lookup_name_without_params, NULL)
3488 || (symbol_matcher != NULL && !symbol_matcher (qualified)))
3489 continue;
3490
3491 matches.push_back (bounds.first->idx);
3492 }
3493 }
3494
3495 std::sort (matches.begin (), matches.end ());
3496
3497 /* Finally call the callback, once per match. */
3498 ULONGEST prev = -1;
3499 bool result = true;
3500 for (offset_type idx : matches)
3501 {
3502 if (prev != idx)
3503 {
3504 if (!match_callback (idx))
3505 {
3506 result = false;
3507 break;
3508 }
3509 prev = idx;
3510 }
3511 }
3512
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), "");
3516
3517 return result;
3518}
3519
3520#if GDB_SELF_TEST
3521
3522namespace selftests { namespace dw2_expand_symtabs_matching {
3523
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. */
3528class mock_mapped_index : public mapped_index_base
3529{
3530public:
3531 mock_mapped_index (gdb::array_view<const char *> symbols)
3532 : m_symbol_table (symbols)
3533 {}
3534
3535 DISABLE_COPY_AND_ASSIGN (mock_mapped_index);
3536
3537 /* Return the number of names in the symbol table. */
3538 size_t symbol_name_count () const override
3539 {
3540 return m_symbol_table.size ();
3541 }
3542
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
3546 {
3547 return m_symbol_table[idx];
3548 }
3549
3550 quick_symbol_functions_up make_quick_functions () const override
3551 {
3552 return nullptr;
3553 }
3554
3555private:
3556 gdb::array_view<const char *> m_symbol_table;
3557};
3558
3559/* Convenience function that converts a NULL pointer to a "<null>"
3560 string, to pass to print routines. */
3561
3562static const char *
3563string_or_null (const char *str)
3564{
3565 return str != NULL ? str : "<null>";
3566}
3567
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. */
3574
3575static bool
3576check_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)
3582{
3583 lookup_name_info lookup_name (name, match_type, completion_mode);
3584
3585 bool matched = true;
3586
3587 auto mismatch = [&] (const char *expected_str,
3588 const char *got)
3589 {
3590 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3591 "expected=\"%s\", got=\"%s\"\n"),
3592 file, line,
3593 (match_type == symbol_name_match_type::FULL
3594 ? "FULL" : "WILD"),
3595 name, string_or_null (expected_str), string_or_null (got));
3596 matched = false;
3597 };
3598
3599 auto expected_it = expected_list.begin ();
3600 auto expected_end = expected_list.end ();
3601
3602 dw2_expand_symtabs_matching_symbol (mock_index, lookup_name,
3603 nullptr,
3604 [&] (offset_type idx)
3605 {
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++;
3609
3610 if (expected_str == NULL || strcmp (expected_str, matched_name) != 0)
3611 mismatch (expected_str, matched_name);
3612 return true;
3613 }, per_objfile);
3614
3615 const char *expected_str
3616 = expected_it == expected_end ? NULL : *expected_it++;
3617 if (expected_str != NULL)
3618 mismatch (expected_str, NULL);
3619
3620 return matched;
3621}
3622
3623/* The symbols added to the mock mapped_index for testing (in
3624 canonical form). */
3625static const char *test_symbols[] = {
3626 "function",
3627 "std::bar",
3628 "std::zfunction",
3629 "std::zfunction2",
3630 "w1::w2",
3631 "ns::foo<char*>",
3632 "ns::foo<int>",
3633 "ns::foo<long>",
3634 "ns2::tmpl<int>::foo2",
3635 "(anonymous namespace)::A::B::C",
3636
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". */
3640 "t1_func",
3641 "t1_func1",
3642 "t1_fund",
3643 "t1_fund1",
3644
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). */
3648 u8"u8função",
3649
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. */
3658 "yfunc\377",
3659
3660 /* Some more symbols with \377 (0xff). See above. */
3661 "\377",
3662 "\377\377123",
3663
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>"
3670
3671 Z_SYM_NAME
3672};
3673
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. */
3677
3678static bool
3679check_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)
3683{
3684 lookup_name_info lookup_name (search_name,
3686
3687 auto bounds = index.find_name_components_bounds (lookup_name,
3689 per_objfile);
3690
3691 size_t distance = std::distance (bounds.first, bounds.second);
3692 if (distance != expected_syms.size ())
3693 return false;
3694
3695 for (size_t exp_elem = 0; exp_elem < distance; exp_elem++)
3696 {
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)
3700 return false;
3701 }
3702
3703 return true;
3704}
3705
3706/* Test the lower-level mapped_index::find_name_component_bounds
3707 method. */
3708
3709static void
3710test_mapped_index_find_name_component_bounds ()
3711{
3712 mock_mapped_index mock_index (test_symbols);
3713
3714 mock_index.build_name_components (NULL /* per_objfile */);
3715
3716 /* Test the lower-level mapped_index::find_name_component_bounds
3717 method in completion mode. */
3718 {
3719 static const char *expected_syms[] = {
3720 "t1_func",
3721 "t1_func1",
3722 };
3723
3724 SELF_CHECK (check_find_bounds_finds
3725 (mock_index, "t1_func", expected_syms,
3726 NULL /* per_objfile */));
3727 }
3728
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. */
3732 {
3733 static const char *expected_syms1[] = {
3734 "\377",
3735 "\377\377123",
3736 };
3737 SELF_CHECK (check_find_bounds_finds
3738 (mock_index, "\377", expected_syms1, NULL /* per_objfile */));
3739
3740 static const char *expected_syms2[] = {
3741 "\377\377123",
3742 };
3743 SELF_CHECK (check_find_bounds_finds
3744 (mock_index, "\377\377", expected_syms2,
3745 NULL /* per_objfile */));
3746 }
3747}
3748
3749/* Test dw2_expand_symtabs_matching_symbol. */
3750
3751static void
3752test_dw2_expand_symtabs_matching_symbol ()
3753{
3754 mock_mapped_index mock_index (test_symbols);
3755
3756 /* We let all tests run until the end even if some fails, for debug
3757 convenience. */
3758 bool any_mismatch = false;
3759
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__ }
3764
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__, \
3769 mock_index, \
3770 NAME, MATCH_TYPE, COMPLETION_MODE, \
3771 EXPECTED_LIST, NULL)
3772
3773 /* Identity checks. */
3774 for (const char *sym : test_symbols)
3775 {
3776 /* Should be able to match all existing symbols. */
3777 CHECK_MATCH (sym, symbol_name_match_type::FULL, false,
3778 EXPECT (sym));
3779
3780 /* Should be able to match all existing symbols with
3781 parameters. */
3782 std::string with_params = std::string (sym) + "(int)";
3783 CHECK_MATCH (with_params.c_str (), symbol_name_match_type::FULL, false,
3784 EXPECT (sym));
3785
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,
3790 EXPECT (sym));
3791
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,
3796 {});
3797 }
3798
3799 /* Check that the name matching algorithm for completion doesn't get
3800 confused with Latin1 'ÿ' / 0xff. See
3801 make_sort_after_prefix_name. */
3802 {
3803 static const char str[] = "\377";
3804 CHECK_MATCH (str, symbol_name_match_type::FULL, true,
3805 EXPECT ("\377", "\377\377123"));
3806 }
3807
3808 /* Check that the increment-last-char in the matching algorithm for
3809 completion doesn't match "t1_fund" when completing "t1_func". */
3810 {
3811 static const char str[] = "t1_func";
3812 CHECK_MATCH (str, symbol_name_match_type::FULL, true,
3813 EXPECT ("t1_func", "t1_func1"));
3814 }
3815
3816 /* Check that completion mode works at each prefix of the expected
3817 symbol name. */
3818 {
3819 static const char str[] = "function(int)";
3820 size_t len = strlen (str);
3821 std::string lookup;
3822
3823 for (size_t i = 1; i < len; i++)
3824 {
3825 lookup.assign (str, i);
3826 CHECK_MATCH (lookup.c_str (), symbol_name_match_type::FULL, true,
3827 EXPECT ("function"));
3828 }
3829 }
3830
3831 /* While "w" is a prefix of both components, the match function
3832 should still only be called once. */
3833 {
3834 CHECK_MATCH ("w", symbol_name_match_type::FULL, true,
3835 EXPECT ("w1::w2"));
3836 CHECK_MATCH ("w", symbol_name_match_type::WILD, true,
3837 EXPECT ("w1::w2"));
3838 }
3839
3840 /* Same, with a "complicated" symbol. */
3841 {
3842 static const char str[] = Z_SYM_NAME;
3843 size_t len = strlen (str);
3844 std::string lookup;
3845
3846 for (size_t i = 1; i < len; i++)
3847 {
3848 lookup.assign (str, i);
3849 CHECK_MATCH (lookup.c_str (), symbol_name_match_type::FULL, true,
3850 EXPECT (Z_SYM_NAME));
3851 }
3852 }
3853
3854 /* In FULL mode, an incomplete symbol doesn't match. */
3855 {
3856 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL, false,
3857 {});
3858 }
3859
3860 /* A complete symbol with parameters matches any overload, since the
3861 index has no overload info. */
3862 {
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"));
3869 }
3870
3871 /* Check that whitespace is ignored appropriately. A symbol with a
3872 template argument list. */
3873 {
3874 static const char expected[] = "ns::foo<int>";
3875 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL, false,
3876 EXPECT (expected));
3877 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD, false,
3878 EXPECT (expected));
3879 }
3880
3881 /* Check that whitespace is ignored appropriately. A symbol with a
3882 template argument list that includes a pointer. */
3883 {
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++)
3888 {
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));
3893
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));
3898 }
3899 }
3900
3901 {
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));
3912 }
3913
3914 /* Test lookup names that don't match anything. */
3915 {
3916 CHECK_MATCH ("bar2", symbol_name_match_type::WILD, false,
3917 {});
3918
3919 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL, false,
3920 {});
3921 }
3922
3923 /* Some wild matching tests, exercising "(anonymous namespace)",
3924 which should not be confused with a parameter list. */
3925 {
3926 static const char *syms[] = {
3927 "A::B::C",
3928 "B::C",
3929 "C",
3930 "A :: B :: C ( int )",
3931 "B :: C ( int )",
3932 "C ( int )",
3933 };
3934
3935 for (const char *s : syms)
3936 {
3937 CHECK_MATCH (s, symbol_name_match_type::WILD, false,
3938 EXPECT ("(anonymous namespace)::A::B::C"));
3939 }
3940 }
3941
3942 {
3943 static const char expected[] = "ns2::tmpl<int>::foo2";
3944 CHECK_MATCH ("tmp", symbol_name_match_type::WILD, true,
3945 EXPECT (expected));
3946 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD, true,
3947 EXPECT (expected));
3948 }
3949
3950 SELF_CHECK (!any_mismatch);
3951
3952#undef EXPECT
3953#undef CHECK_MATCH
3954}
3955
3956static void
3957run_test ()
3958{
3959 test_mapped_index_find_name_component_bounds ();
3960 test_dw2_expand_symtabs_matching_symbol ();
3961}
3962
3963}} // namespace selftests::dw2_expand_symtabs_matching
3964
3965#endif /* GDB_SELF_TEST */
3966
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. */
3971
3972static bool
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)
3978{
3979 if (file_matcher == NULL || per_cu->mark)
3980 {
3981 bool symtab_was_null = !per_objfile->symtab_set_p (per_cu);
3982
3984 = dw2_instantiate_symtab (per_cu, per_objfile, false);
3985 gdb_assert (symtab != nullptr);
3986
3987 if (expansion_notify != NULL && symtab_was_null)
3988 return expansion_notify (symtab);
3989 }
3990 return true;
3991}
3992
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. */
3996
3997static bool
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,
4003 search_domain kind)
4004{
4005 offset_type vec_len, vec_idx;
4006 bool global_seen = false;
4007 mapped_index &index
4008 = *(gdb::checked_static_cast<mapped_index *>
4009 (per_objfile->per_bfd->index_table.get ()));
4010
4011 offset_view vec (index.constant_pool.slice (index.symbol_vec_index (idx)));
4012 vec_len = vec[0];
4013 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
4014 {
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). */
4025 int attrs_valid =
4026 (index.version >= 7
4027 && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
4028
4029 /* Work around gold/15646. */
4030 if (attrs_valid
4031 && !is_static
4032 && symbol_kind == GDB_INDEX_SYMBOL_KIND_TYPE)
4033 {
4034 if (global_seen)
4035 continue;
4036
4037 global_seen = true;
4038 }
4039
4040 /* Only check the symbol's kind if it has one. */
4041 if (attrs_valid)
4042 {
4043 if (is_static)
4044 {
4045 if ((search_flags & SEARCH_STATIC_BLOCK) == 0)
4046 continue;
4047 }
4048 else
4049 {
4050 if ((search_flags & SEARCH_GLOBAL_BLOCK) == 0)
4051 continue;
4052 }
4053
4054 switch (kind)
4055 {
4056 case VARIABLES_DOMAIN:
4057 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE)
4058 continue;
4059 break;
4060 case FUNCTIONS_DOMAIN:
4061 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION)
4062 continue;
4063 break;
4064 case TYPES_DOMAIN:
4065 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
4066 continue;
4067 break;
4068 case MODULES_DOMAIN:
4069 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
4070 continue;
4071 break;
4072 default:
4073 break;
4074 }
4075 }
4076
4077 /* Don't crash on bad data. */
4078 if (cu_index >= per_objfile->per_bfd->all_units.size ())
4079 {
4080 complaint (_(".gdb_index entry has bad CU index"
4081 " [in module %s]"), objfile_name (per_objfile->objfile));
4082 continue;
4083 }
4084
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,
4087 expansion_notify))
4088 return false;
4089 }
4090
4091 return true;
4092}
4093
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. */
4097
4098static void
4100 (dwarf2_per_objfile *per_objfile,
4101 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher)
4102{
4103 if (file_matcher == NULL)
4104 return;
4105
4106 htab_up visited_found (htab_create_alloc (10, htab_hash_pointer,
4107 htab_eq_pointer,
4108 NULL, xcalloc, xfree));
4109 htab_up visited_not_found (htab_create_alloc (10, htab_hash_pointer,
4110 htab_eq_pointer,
4111 NULL, xcalloc, xfree));
4112
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. */
4115
4116 for (const auto &per_cu : per_objfile->per_bfd->all_units)
4117 {
4118 QUIT;
4119
4120 if (per_cu->is_debug_types)
4121 continue;
4122 per_cu->mark = 0;
4123
4124 /* We only need to look at symtabs not already expanded. */
4125 if (per_objfile->symtab_set_p (per_cu.get ()))
4126 continue;
4127
4128 if (per_cu->fnd != nullptr)
4129 {
4130 file_and_directory *fnd = per_cu->fnd.get ();
4131
4132 if (file_matcher (fnd->get_name (), false))
4133 {
4134 per_cu->mark = 1;
4135 continue;
4136 }
4137
4138 /* Before we invoke realpath, which can get expensive when many
4139 files are involved, do a quick comparison of the basenames. */
4141 || file_matcher (lbasename (fnd->get_name ()), true))
4142 && file_matcher (fnd->get_fullname (), false))
4143 {
4144 per_cu->mark = 1;
4145 continue;
4146 }
4147 }
4148
4149 quick_file_names *file_data = dw2_get_file_names (per_cu.get (),
4150 per_objfile);
4151 if (file_data == NULL)
4152 continue;
4153
4154 if (htab_find (visited_not_found.get (), file_data) != NULL)
4155 continue;
4156 else if (htab_find (visited_found.get (), file_data) != NULL)
4157 {
4158 per_cu->mark = 1;
4159 continue;
4160 }
4161
4162 for (int j = 0; j < file_data->num_file_names; ++j)
4163 {
4164 const char *this_real_name;
4165
4166 if (file_matcher (file_data->file_names[j], false))
4167 {
4168 per_cu->mark = 1;
4169 break;
4170 }
4171
4172 /* Before we invoke realpath, which can get expensive when many
4173 files are involved, do a quick comparison of the basenames. */
4175 && !file_matcher (lbasename (file_data->file_names[j]),
4176 true))
4177 continue;
4178
4179 this_real_name = dw2_get_real_path (per_objfile, file_data, j);
4180 if (file_matcher (this_real_name, false))
4181 {
4182 per_cu->mark = 1;
4183 break;
4184 }
4185 }
4186
4187 void **slot = htab_find_slot (per_cu->mark
4188 ? visited_found.get ()
4189 : visited_not_found.get (),
4190 file_data, INSERT);
4191 *slot = file_data;
4192 }
4193}
4194
4195bool
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,
4203 domain_enum domain,
4204 enum search_domain kind)
4205{
4207
4208 dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
4209
4210 /* This invariant is documented in quick-functions.h. */
4211 gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
4212 if (lookup_name == nullptr)
4213 {
4214 for (dwarf2_per_cu_data *per_cu
4215 : all_units_range (per_objfile->per_bfd))
4216 {
4217 QUIT;
4218
4219 if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
4220 file_matcher,
4221 expansion_notify))
4222 return false;
4223 }
4224 return true;
4225 }
4226
4227 mapped_index &index
4228 = *(gdb::checked_static_cast<mapped_index *>
4229 (per_objfile->per_bfd->index_table.get ()));
4230
4231 bool result
4232 = dw2_expand_symtabs_matching_symbol (index, *lookup_name,
4233 symbol_matcher,
4234 [&] (offset_type idx)
4235 {
4236 if (!dw2_expand_marked_cus (per_objfile, idx, file_matcher,
4237 expansion_notify, search_flags, kind))
4238 return false;
4239 return true;
4240 }, per_objfile);
4241
4242 return result;
4243}
4244
4245/* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4246 symtab. */
4247
4248static struct compunit_symtab *
4250 CORE_ADDR pc)
4251{
4252 int i;
4253
4254 if (cust->blockvector () != nullptr
4255 && blockvector_contains_pc (cust->blockvector (), pc))
4256 return cust;
4257
4258 if (cust->includes == NULL)
4259 return NULL;
4260
4261 for (i = 0; cust->includes[i]; ++i)
4262 {
4263 struct compunit_symtab *s = cust->includes[i];
4264
4266 if (s != NULL)
4267 return s;
4268 }
4269
4270 return NULL;
4271}
4272
4275 CORE_ADDR adjusted_pc)
4276{
4277 if (per_bfd->index_addrmap == nullptr)
4278 return nullptr;
4279 return ((struct dwarf2_per_cu_data *)
4280 per_bfd->index_addrmap->find (adjusted_pc));
4281}
4282
4283struct compunit_symtab *
4285 (struct objfile *objfile,
4286 struct bound_minimal_symbol msymbol,
4287 CORE_ADDR pc,
4288 struct obj_section *section,
4289 int warn_if_readin)
4290{
4291 struct compunit_symtab *result;
4292
4294
4295 CORE_ADDR baseaddr = objfile->text_section_offset ();
4296 struct dwarf2_per_cu_data *data = find_per_cu (per_objfile->per_bfd,
4297 pc - baseaddr);
4298 if (data == nullptr)
4299 return nullptr;
4300
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));
4304
4306 (dw2_instantiate_symtab (data, per_objfile, false), pc);
4307
4308 if (warn_if_readin && result == nullptr)
4309 warning (_("(Error: pc %s in address map, but not in symtab.)"),
4310 paddress (objfile->arch (), pc));
4311
4312 return result;
4313}
4314
4315void
4317 (struct objfile *objfile,
4318 gdb::function_view<symbol_filename_ftype> fun,
4319 bool need_fullname)
4320{
4322
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;
4326
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. */
4332
4333 for (const auto &per_cu : per_objfile->per_bfd->all_units)
4334 {
4335 if (!per_cu->is_debug_types
4336 && per_objfile->symtab_set_p (per_cu.get ()))
4337 {
4338 if (per_cu->file_names != nullptr)
4339 qfn_cache.insert (per_cu->file_names);
4340 }
4341 }
4342
4343 for (dwarf2_per_cu_data *per_cu
4344 : all_units_range (per_objfile->per_bfd))
4345 {
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))
4348 continue;
4349
4350 if (per_cu->fnd != nullptr)
4351 {
4352 file_and_directory *fnd = per_cu->fnd.get ();
4353
4354 const char *filename = fnd->get_name ();
4355 const char *key = filename;
4356 const char *fullname = nullptr;
4357
4358 if (need_fullname)
4359 {
4360 fullname = fnd->get_fullname ();
4361 key = fullname;
4362 }
4363
4364 if (!filenames_cache.seen (key))
4365 fun (filename, fullname);
4366 }
4367
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 ())
4371 continue;
4372
4373 for (int j = 0; j < file_data->num_file_names; ++j)
4374 {
4375 const char *filename = file_data->file_names[j];
4376 const char *key = filename;
4377 const char *fullname = nullptr;
4378
4379 if (need_fullname)
4380 {
4381 fullname = dw2_get_real_path (per_objfile, file_data, j);
4382 key = fullname;
4383 }
4384
4385 if (!filenames_cache.seen (key))
4386 fun (filename, fullname);
4387 }
4388 }
4389}
4390
4391bool
4393{
4394 return true;
4395}
4396
4397/* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
4398
4399bool
4401{
4403
4404 for (const auto &per_cu : per_objfile->per_bfd->all_units)
4405 {
4406 /* Is this already expanded? */
4407 if (per_objfile->symtab_set_p (per_cu.get ()))
4408 continue;
4409
4410 /* It has not yet been expanded. */
4411 return true;
4412 }
4413
4414 return false;
4415}
4416
4417/* DWARF-5 debug_names reader. */
4418
4419/* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4420static const gdb_byte dwarf5_augmentation[] = { 'G', 'D', 'B', 0 };
4421
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.
4425
4426 Returns true if all went well, false otherwise. */
4427
4428static bool
4430 const char *filename,
4432 mapped_debug_names &map)
4433{
4434 if (section->empty ())
4435 return false;
4436
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)
4440 return false;
4441
4442 section->read (objfile);
4443
4445
4446 const gdb_byte *addr = section->buffer;
4447
4448 bfd *const abfd = section->get_bfd_owner ();
4449
4450 unsigned int bytes_read;
4451 LONGEST length = read_initial_length (abfd, addr, &bytes_read);
4452 addr += bytes_read;
4453
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)
4457 {
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));
4463 return false;
4464 }
4465
4466 /* The version number. */
4467 uint16_t version = read_2_bytes (abfd, addr);
4468 addr += 2;
4469 if (version != 5)
4470 {
4471 warning (_("Section .debug_names in %s has unsupported version %d, "
4472 "ignoring .debug_names."),
4473 filename, version);
4474 return false;
4475 }
4476
4477 /* Padding. */
4478 uint16_t padding = read_2_bytes (abfd, addr);
4479 addr += 2;
4480 if (padding != 0)
4481 {
4482 warning (_("Section .debug_names in %s has unsupported padding %d, "
4483 "ignoring .debug_names."),
4484 filename, padding);
4485 return false;
4486 }
4487
4488 /* comp_unit_count - The number of CUs in the CU list. */
4489 map.cu_count = read_4_bytes (abfd, addr);
4490 addr += 4;
4491
4492 /* local_type_unit_count - The number of TUs in the local TU
4493 list. */
4494 map.tu_count = read_4_bytes (abfd, addr);
4495 addr += 4;
4496
4497 /* foreign_type_unit_count - The number of TUs in the foreign TU
4498 list. */
4499 uint32_t foreign_tu_count = read_4_bytes (abfd, addr);
4500 addr += 4;
4501 if (foreign_tu_count != 0)
4502 {
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));
4506 return false;
4507 }
4508
4509 /* bucket_count - The number of hash buckets in the hash lookup
4510 table. */
4511 map.bucket_count = read_4_bytes (abfd, addr);
4512 addr += 4;
4513
4514 /* name_count - The number of unique names in the index. */
4515 map.name_count = read_4_bytes (abfd, addr);
4516 addr += 4;
4517
4518 /* abbrev_table_size - The size in bytes of the abbreviations
4519 table. */
4520 uint32_t abbrev_table_size = read_4_bytes (abfd, addr);
4521 addr += 4;
4522
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);
4526 addr += 4;
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;
4533
4534 /* List of CUs */
4535 map.cu_table_reordered = addr;
4536 addr += map.cu_count * map.offset_size;
4537
4538 /* List of Local TUs */
4539 map.tu_table_reordered = addr;
4540 addr += map.tu_count * map.offset_size;
4541
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;
4547
4548 /* Name Table */
4550 addr += map.name_count * map.offset_size;
4552 addr += map.name_count * map.offset_size;
4553
4554 const gdb_byte *abbrev_table_start = addr;
4555 for (;;)
4556 {
4557 const ULONGEST index_num = read_unsigned_leb128 (abfd, addr, &bytes_read);
4558 addr += bytes_read;
4559 if (index_num == 0)
4560 break;
4561
4562 const auto insertpair
4563 = map.abbrev_map.emplace (index_num, mapped_debug_names::index_val ());
4564 if (!insertpair.second)
4565 {
4566 warning (_("Section .debug_names in %s has duplicate index %s, "
4567 "ignoring .debug_names."),
4568 filename, pulongest (index_num));
4569 return false;
4570 }
4571 mapped_debug_names::index_val &indexval = insertpair.first->second;
4572 indexval.dwarf_tag = read_unsigned_leb128 (abfd, addr, &bytes_read);
4573 addr += bytes_read;
4574
4575 for (;;)
4576 {
4578 attr.dw_idx = read_unsigned_leb128 (abfd, addr, &bytes_read);
4579 addr += bytes_read;
4580 attr.form = read_unsigned_leb128 (abfd, addr, &bytes_read);
4581 addr += bytes_read;
4582 if (attr.form == DW_FORM_implicit_const)
4583 {
4584 attr.implicit_const = read_signed_leb128 (abfd, addr,
4585 &bytes_read);
4586 addr += bytes_read;
4587 }
4588 if (attr.dw_idx == 0 && attr.form == 0)
4589 break;
4590 indexval.attr_vec.push_back (std::move (attr));
4591 }
4592 }
4593 if (addr != abbrev_table_start + abbrev_table_size)
4594 {
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),
4598 abbrev_table_size);
4599 return false;
4600 }
4601 map.entry_pool = addr;
4602
4603 return true;
4604}
4605
4606/* A helper for create_cus_from_debug_names that handles the MAP's CU
4607 list. */
4608
4609static bool
4611 const mapped_debug_names &map,
4613 bool is_dwz)
4614{
4615 if (!map.augmentation_is_gdb)
4616 {
4617 for (uint32_t i = 0; i < map.cu_count; ++i)
4618 {
4619 sect_offset sect_off
4620 = (sect_offset) (extract_unsigned_integer
4621 (map.cu_table_reordered + i * map.offset_size,
4622 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
4628 actual length. */
4631 sect_off, 0);
4632 per_bfd->all_units.push_back (std::move (per_cu));
4633 }
4634 return true;
4635 }
4636
4637 sect_offset sect_off_prev;
4638 for (uint32_t i = 0; i <= map.cu_count; ++i)
4639 {
4640 sect_offset sect_off_next;
4641 if (i < map.cu_count)
4642 {
4643 sect_off_next
4644 = (sect_offset) (extract_unsigned_integer
4645 (map.cu_table_reordered + i * map.offset_size,
4646 map.offset_size,
4647 map.dwarf5_byte_order));
4648 }
4649 else
4650 sect_off_next = (sect_offset) section.size;
4651 if (i >= 1)
4652 {
4653 if (sect_off_next == sect_off_prev)
4654 {
4655 warning (_("Section .debug_names has duplicate entry in CU table,"
4656 " ignoring .debug_names."));
4657 return false;
4658 }
4659 if (sect_off_next < sect_off_prev)
4660 {
4661 warning (_("Section .debug_names has non-ascending CU table,"
4662 " ignoring .debug_names."));
4663 return false;
4664 }
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;
4670 sect_off_prev, length);
4671 per_bfd->all_units.push_back (std::move (per_cu));
4672 }
4673 sect_off_prev = sect_off_next;
4674 }
4675
4676 return true;
4677}
4678
4679/* Read the CU list from the mapped index, and use it to create all
4680 the CU objects for this dwarf2_per_objfile. */
4681
4682static bool
4684 const mapped_debug_names &map,
4685 const mapped_debug_names &dwz_map)
4686{
4687 gdb_assert (per_bfd->all_units.empty ());
4688 per_bfd->all_units.reserve (map.cu_count + dwz_map.cu_count);
4689
4691 false /* is_dwz */))
4692 return false;
4693
4694 if (dwz_map.cu_count == 0)
4695 return true;
4696
4698 return create_cus_from_debug_names_list (per_bfd, dwz_map, dwz->info,
4699 true /* is_dwz */);
4700}
4701
4702/* Read .debug_names. If everything went ok, initialize the "quick"
4703 elements of all the CUs and return true. Otherwise, return false. */
4704
4705static bool
4707{
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;
4712
4714 &per_bfd->debug_names, *map))
4715 return false;
4716
4717 /* Don't use the index if it's empty. */
4718 if (map->name_count == 0)
4719 return false;
4720
4721 /* If there is a .dwz file, read it so we can get its CU list as
4722 well. */
4724 if (dwz != NULL)
4725 {
4727 bfd_get_filename (dwz->dwz_bfd.get ()),
4728 &dwz->debug_names, dwz_map))
4729 {
4730 warning (_("could not read '.debug_names' section from %s; skipping"),
4731 bfd_get_filename (dwz->dwz_bfd.get ()));
4732 return false;
4733 }
4734 }
4735
4736 if (!create_cus_from_debug_names (per_bfd, *map, dwz_map))
4737 {
4738 per_bfd->all_units.clear ();
4739 return false;
4740 }
4741
4742 if (map->tu_count != 0)
4743 {
4744 /* We can only handle a single .debug_types when we have an
4745 index. */
4746 if (per_bfd->types.size () > 1)
4747 {
4748 per_bfd->all_units.clear ();
4749 return false;
4750 }
4751
4752 dwarf2_section_info *section
4753 = (per_bfd->types.size () == 1
4754 ? &per_bfd->types[0]
4755 : &per_bfd->info);
4756
4758 (per_objfile, *map, section, &per_bfd->abbrev);
4759 }
4760
4762
4763 create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges);
4764
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 ());
4768
4769 return true;
4770}
4771
4772/* Type used to manage iterating over all CUs looking for a symbol for
4773 .debug_names. */
4774
4776{
4777public:
4779 block_search_flags block_index,
4780 domain_enum domain,
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)
4785 {}
4786
4788 search_domain search, uint32_t namei,
4789 dwarf2_per_objfile *per_objfile,
4790 domain_enum domain = UNDEF_DOMAIN)
4791 : m_map (map),
4792 m_domain (domain),
4793 m_search (search),
4794 m_addr (find_vec_in_debug_names (map, namei, per_objfile)),
4795 m_per_objfile (per_objfile)
4796 {}
4797
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)
4804 {}
4805
4806 /* Return the next matching CU or NULL if there are no more. */
4808
4809private:
4810 static const gdb_byte *find_vec_in_debug_names (const mapped_debug_names &map,
4811 const char *name,
4812 dwarf2_per_objfile *per_objfile);
4813 static const gdb_byte *find_vec_in_debug_names (const mapped_debug_names &map,
4814 uint32_t namei,
4815 dwarf2_per_objfile *per_objfile);
4816
4817 /* The internalized form of .debug_names. */
4819
4820 /* Restrict the search to these blocks. */
4823
4824 /* The kind of symbol we're looking for. */
4827
4828 /* The list of CUs from the index entry of the symbol, or NULL if
4829 not found. */
4830 const gdb_byte *m_addr;
4831
4833};
4834
4835const char *
4837 (uint32_t namei, dwarf2_per_objfile *per_objfile) const
4838{
4839 const ULONGEST namei_string_offs
4841 + namei * offset_size),
4844 return read_indirect_string_at_offset (per_objfile, namei_string_offs);
4845}
4846
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,
4849 return NULL. */
4850
4851const gdb_byte *
4853 (const mapped_debug_names &map, const char *name,
4854 dwarf2_per_objfile *per_objfile)
4855{
4856 int (*cmp) (const char *, const char *);
4857
4858 gdb::unique_xmalloc_ptr<char> without_params;
4862 {
4863 /* NAME is already canonical. Drop any qualifiers as
4864 .debug_names does not contain any. */
4865
4866 if (strchr (name, '(') != NULL)
4867 {
4868 without_params = cp_remove_params (name);
4869 if (without_params != NULL)
4870 name = without_params.get ();
4871 }
4872 }
4873
4874 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
4875
4876 const uint32_t full_hash = dwarf5_djb_hash (name);
4877 uint32_t namei
4878 = extract_unsigned_integer (reinterpret_cast<const gdb_byte *>
4880 + (full_hash % map.bucket_count)), 4,
4881 map.dwarf5_byte_order);
4882 if (namei == 0)
4883 return NULL;
4884 --namei;
4885 if (namei >= map.name_count)
4886 {
4887 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4888 "[in module %s]"),
4889 namei, map.name_count,
4890 objfile_name (per_objfile->objfile));
4891 return NULL;
4892 }
4893
4894 for (;;)
4895 {
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)
4901 return NULL;
4902
4903 if (full_hash == namei_full_hash)
4904 {
4905 const char *const namei_string = map.namei_to_name (namei, per_objfile);
4906
4907#if 0 /* An expensive sanity check. */
4908 if (namei_full_hash != dwarf5_djb_hash (namei_string))
4909 {
4910 complaint (_("Wrong .debug_names hash for string at index %u "
4911 "[in module %s]"),
4913 return NULL;
4914 }
4915#endif
4916
4917 if (cmp (namei_string, name) == 0)
4918 {
4919 const ULONGEST namei_entry_offs
4921 + namei * map.offset_size),
4923 return map.entry_pool + namei_entry_offs;
4924 }
4925 }
4926
4927 ++namei;
4928 if (namei >= map.name_count)
4929 return NULL;
4930 }
4931}
4932
4933const gdb_byte *
4935 (const mapped_debug_names &map, uint32_t namei, dwarf2_per_objfile *per_objfile)
4936{
4937 if (namei >= map.name_count)
4938 {
4939 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4940 "[in module %s]"),
4941 namei, map.name_count,
4942 objfile_name (per_objfile->objfile));
4943 return NULL;
4944 }
4945
4946 const ULONGEST namei_entry_offs
4948 + namei * map.offset_size),
4950 return map.entry_pool + namei_entry_offs;
4951}
4952
4953/* See dw2_debug_names_iterator. */
4954
4957{
4958 if (m_addr == NULL)
4959 return NULL;
4960
4963 bfd *const abfd = objfile->obfd.get ();
4964
4965 again:
4966
4967 unsigned int bytes_read;
4968 const ULONGEST abbrev = read_unsigned_leb128 (abfd, m_addr, &bytes_read);
4969 m_addr += bytes_read;
4970 if (abbrev == 0)
4971 return NULL;
4972
4973 const auto indexval_it = m_map.abbrev_map.find (abbrev);
4974 if (indexval_it == m_map.abbrev_map.cend ())
4975 {
4976 complaint (_("Wrong .debug_names undefined abbrev code %s "
4977 "[in module %s]"),
4978 pulongest (abbrev), objfile_name (objfile));
4979 return NULL;
4980 }
4981 const mapped_debug_names::index_val &indexval = indexval_it->second;
4982 enum class symbol_linkage {
4983 unknown,
4984 static_,
4985 extern_,
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)
4989 {
4990 ULONGEST ull;
4991 switch (attr.form)
4992 {
4993 case DW_FORM_implicit_const:
4994 ull = attr.implicit_const;
4995 break;
4996 case DW_FORM_flag_present:
4997 ull = 1;
4998 break;
4999 case DW_FORM_udata:
5000 ull = read_unsigned_leb128 (abfd, m_addr, &bytes_read);
5001 m_addr += bytes_read;
5002 break;
5003 case DW_FORM_ref4:
5004 ull = read_4_bytes (abfd, m_addr);
5005 m_addr += 4;
5006 break;
5007 case DW_FORM_ref8:
5008 ull = read_8_bytes (abfd, m_addr);
5009 m_addr += 8;
5010 break;
5011 case DW_FORM_ref_sig8:
5012 ull = read_8_bytes (abfd, m_addr);
5013 m_addr += 8;
5014 break;
5015 default:
5016 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5017 dwarf_form_name (attr.form),
5019 return NULL;
5020 }
5021 switch (attr.dw_idx)
5022 {
5023 case DW_IDX_compile_unit:
5024 {
5025 /* Don't crash on bad data. */
5026 if (ull >= per_bfd->all_comp_units.size ())
5027 {
5028 complaint (_(".debug_names entry has bad CU index %s"
5029 " [in module %s]"),
5030 pulongest (ull),
5032 continue;
5033 }
5034 }
5035 per_cu = per_bfd->get_cu (ull);
5036 break;
5037 case DW_IDX_type_unit:
5038 /* Don't crash on bad data. */
5039 if (ull >= per_bfd->all_type_units.size ())
5040 {
5041 complaint (_(".debug_names entry has bad TU index %s"
5042 " [in module %s]"),
5043 pulongest (ull),
5045 continue;
5046 }
5047 {
5048 int nr_cus = per_bfd->all_comp_units.size ();
5049 per_cu = per_bfd->get_cu (nr_cus + ull);
5050 }
5051 break;
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. */
5055 if (per_cu == NULL)
5056 per_cu = per_bfd->get_cu (0);
5057 break;
5058 case DW_IDX_GNU_internal:
5060 break;
5061 symbol_linkage_ = symbol_linkage::static_;
5062 break;
5063 case DW_IDX_GNU_external:
5065 break;
5066 symbol_linkage_ = symbol_linkage::extern_;
5067 break;
5068 }
5069 }
5070
5071 /* Skip if we couldn't find a valid CU/TU index. */
5072 if (per_cu == nullptr)
5073 goto again;
5074
5075 /* Skip if already read in. */
5076 if (m_per_objfile->symtab_set_p (per_cu))
5077 goto again;
5078
5079 /* Check static vs global. */
5080 if (symbol_linkage_ != symbol_linkage::unknown)
5081 {
5082 if (symbol_linkage_ == symbol_linkage::static_)
5083 {
5085 goto again;
5086 }
5087 else
5088 {
5090 goto again;
5091 }
5092 }
5093
5094 /* Match dw2_symtab_iter_next, symbol_kind
5095 and debug_names::psymbol_tag. */
5096 switch (m_domain)
5097 {
5098 case VAR_DOMAIN:
5099 switch (indexval.dwarf_tag)
5100 {
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:
5106 break;
5107 default:
5108 goto again;
5109 }
5110 break;
5111 case STRUCT_DOMAIN:
5112 switch (indexval.dwarf_tag)
5113 {
5114 case DW_TAG_typedef:
5115 case DW_TAG_structure_type:
5116 break;
5117 default:
5118 goto again;
5119 }
5120 break;
5121 case LABEL_DOMAIN:
5122 switch (indexval.dwarf_tag)
5123 {
5124 case 0:
5125 case DW_TAG_variable:
5126 break;
5127 default:
5128 goto again;
5129 }
5130 break;
5131 case MODULE_DOMAIN:
5132 switch (indexval.dwarf_tag)
5133 {
5134 case DW_TAG_module:
5135 break;
5136 default:
5137 goto again;
5138 }
5139 break;
5140 default:
5141 break;
5142 }
5143
5144 /* Match dw2_expand_symtabs_matching, symbol_kind and
5145 debug_names::psymbol_tag. */
5146 switch (m_search)
5147 {
5148 case VARIABLES_DOMAIN:
5149 switch (indexval.dwarf_tag)
5150 {
5151 case DW_TAG_variable:
5152 break;
5153 default:
5154 goto again;
5155 }
5156 break;
5157 case FUNCTIONS_DOMAIN:
5158 switch (indexval.dwarf_tag)
5159 {
5160 case DW_TAG_subprogram:
5161 break;
5162 default:
5163 goto again;
5164 }
5165 break;
5166 case TYPES_DOMAIN:
5167 switch (indexval.dwarf_tag)
5168 {
5169 case DW_TAG_typedef:
5170 case DW_TAG_structure_type:
5171 break;
5172 default:
5173 goto again;
5174 }
5175 break;
5176 case MODULES_DOMAIN:
5177 switch (indexval.dwarf_tag)
5178 {
5179 case DW_TAG_module:
5180 break;
5181 default:
5182 goto again;
5183 }
5184 default:
5185 break;
5186 }
5187
5188 return per_cu;
5189}
5190
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. */
5194
5195void
5197{
5198 gdb_printf (".debug_names: exists\n");
5199}
5200
5201void
5203 (struct objfile *objfile,
5204 const lookup_name_info &name, domain_enum domain,
5205 int global,
5206 symbol_compare_ftype *ordered_compare)
5207{
5209
5211 = *(gdb::checked_static_cast<mapped_debug_names *>
5212 (per_objfile->per_bfd->index_table.get ()));
5213 const block_search_flags block_flags
5215
5216 const char *match_name = name.ada ().lookup_name ().c_str ();
5217 auto matcher = [&] (const char *symname)
5218 {
5219 if (ordered_compare == nullptr)
5220 return true;
5221 return ordered_compare (symname, match_name) == 0;
5222 };
5223
5225 [&] (offset_type namei)
5226 {
5227 /* The name was matched, now expand corresponding CUs that were
5228 marked. */
5229 dw2_debug_names_iterator iter (map, block_flags, domain, namei,
5230 per_objfile);
5231
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,
5235 nullptr);
5236 return true;
5237 }, per_objfile);
5238}
5239
5240bool
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,
5248 domain_enum domain,
5249 enum search_domain kind)
5250{
5252
5253 dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
5254
5255 /* This invariant is documented in quick-functions.h. */
5256 gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
5257 if (lookup_name == nullptr)
5258 {
5259 for (dwarf2_per_cu_data *per_cu
5260 : all_units_range (per_objfile->per_bfd))
5261 {
5262 QUIT;
5263
5264 if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
5265 file_matcher,
5266 expansion_notify))
5267 return false;
5268 }
5269 return true;
5270 }
5271
5273 = *(gdb::checked_static_cast<mapped_debug_names *>
5274 (per_objfile->per_bfd->index_table.get ()));
5275
5276 bool result
5277 = dw2_expand_symtabs_matching_symbol (map, *lookup_name,
5278 symbol_matcher,
5279 [&] (offset_type namei)
5280 {
5281 /* The name was matched, now expand corresponding CUs that were
5282 marked. */
5283 dw2_debug_names_iterator iter (map, kind, namei, per_objfile, domain);
5284
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,
5288 file_matcher,
5289 expansion_notify))
5290 return false;
5291 return true;
5292 }, per_objfile);
5293
5294 return result;
5295}
5296
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. */
5299
5300template <typename T>
5301static gdb::array_view<const gdb_byte>
5303{
5304 dwarf2_section_info *section = &section_owner->gdb_index;
5305
5306 if (section->empty ())
5307 return {};
5308
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)
5312 return {};
5313
5314 section->read (obj);
5315
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);
5323}
5324
5325/* Lookup the index cache for the contents of the index associated to
5326 DWARF2_OBJ. */
5327
5328static gdb::array_view<const gdb_byte>
5330{
5331 const bfd_build_id *build_id = build_id_bfd_get (obj->obfd.get ());
5332 if (build_id == nullptr)
5333 return {};
5334
5335 return global_index_cache.lookup_gdb_index (build_id,
5337}
5338
5339/* Same as the above, but for DWZ. */
5340
5341static gdb::array_view<const gdb_byte>
5343{
5344 const bfd_build_id *build_id = build_id_bfd_get (dwz->dwz_bfd.get ());
5345 if (build_id == nullptr)
5346 return {};
5347
5348 return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res);
5349}
5350
5352
5353/* See dwarf2/public.h. */
5354
5355void
5357{
5359 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
5360
5361 dwarf_read_debug_printf ("called");
5362
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
5366 expanded anyway. */
5367 if ((objfile->flags & OBJF_READNOW))
5368 {
5369 dwarf_read_debug_printf ("readnow requested");
5370
5371 create_all_units (per_objfile);
5374
5375 objfile->qf.emplace_front (new readnow_functions);
5376 return;
5377 }
5378
5379 /* Was a GDB index already read when we processed an objfile sharing
5380 PER_BFD? */
5381 if (per_bfd->index_table != nullptr)
5382 {
5383 dwarf_read_debug_printf ("re-using symbols");
5384 objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
5385 return;
5386 }
5387
5388 if (dwarf2_read_debug_names (per_objfile))
5389 {
5390 dwarf_read_debug_printf ("found debug names");
5391 objfile->qf.push_front
5392 (per_bfd->index_table->make_quick_functions ());
5393 return;
5394 }
5395
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>))
5399 {
5400 dwarf_read_debug_printf ("found gdb index from file");
5401 objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
5402 return;
5403 }
5404
5405 /* ... otherwise, try to find the index in the index cache. */
5406 if (dwarf2_read_gdb_index (per_objfile,
5409 {
5410 dwarf_read_debug_printf ("found gdb index from cache");
5412 objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
5413 return;
5414 }
5415
5417 objfile->qf.push_front (make_cooked_index_funcs ());
5418}
5419
5420␌
5421
5422/* Build a partial symbol table. */
5423
5424static void
5426{
5428
5429 if (per_objfile->per_bfd->index_table != nullptr)
5430 return;
5431
5432 try
5433 {
5434 dwarf2_build_psymtabs_hard (per_objfile);
5435
5436 /* (maybe) store an index in the cache. */
5437 global_index_cache.store (per_objfile);
5438 }
5439 catch (const gdb_exception_error &except)
5440 {
5441 exception_print (gdb_stderr, except);
5442 }
5443}
5444
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. */
5450
5451static void
5453{
5454 struct attribute *attr;
5455
5456 cu->base_address.reset ();
5457
5458 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
5459 if (attr != nullptr)
5460 cu->base_address = attr->as_address ();
5461 else
5462 {
5463 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5464 if (attr != nullptr)
5465 cu->base_address = attr->as_address ();
5466 }
5467}
5468
5469/* Helper function that returns the proper abbrev section for
5470 THIS_CU. */
5471
5472static struct dwarf2_section_info *
5474{
5475 struct dwarf2_section_info *abbrev;
5476 dwarf2_per_bfd *per_bfd = this_cu->per_bfd;
5477
5478 if (this_cu->is_dwz)
5479 abbrev = &dwarf2_get_dwz_file (per_bfd, true)->abbrev;
5480 else
5481 abbrev = &per_bfd->abbrev;
5482
5483 return abbrev;
5484}
5485
5486/* Fetch the abbreviation table offset from a comp or type unit header. */
5487
5488static sect_offset
5491 sect_offset sect_off)
5492{
5493 bfd *abfd = section->get_bfd_owner ();
5494 const gdb_byte *info_ptr;
5495 unsigned int initial_length_size, offset_size;
5496 uint16_t version;
5497
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;
5503
5504 version = read_2_bytes (abfd, info_ptr);
5505 info_ptr += 2;
5506 if (version >= 5)
5507 {
5508 /* Skip unit type and address size. */
5509 info_ptr += 2;
5510 }
5511
5512 return (sect_offset) read_offset (abfd, info_ptr, offset_size);
5513}
5514
5515static hashval_t
5516hash_signatured_type (const void *item)
5517{
5518 const struct signatured_type *sig_type
5519 = (const struct signatured_type *) item;
5520
5521 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5522 return sig_type->signature;
5523}
5524
5525static int
5526eq_signatured_type (const void *item_lhs, const void *item_rhs)
5527{
5528 const struct signatured_type *lhs = (const struct signatured_type *) item_lhs;
5529 const struct signatured_type *rhs = (const struct signatured_type *) item_rhs;
5530
5531 return lhs->signature == rhs->signature;
5532}
5533
5534/* Allocate a hash table for signatured types. */
5535
5536static htab_up
5538{
5539 return htab_up (htab_create_alloc (41,
5542 NULL, xcalloc, xfree));
5543}
5544
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. */
5548
5549static void
5551 struct dwo_file *dwo_file,
5552 dwarf2_section_info *section, htab_up &types_htab,
5553 rcuh_kind section_kind)
5554{
5555 struct objfile *objfile = per_objfile->objfile;
5556 struct dwarf2_section_info *abbrev_section;
5557 bfd *abfd;
5558 const gdb_byte *info_ptr, *end_ptr;
5559
5560 abbrev_section = &dwo_file->sections.abbrev;
5561
5562 dwarf_read_debug_printf ("Reading %s for %s",
5563 section->get_name (),
5564 abbrev_section->get_file_name ());
5565
5566 section->read (objfile);
5567 info_ptr = section->buffer;
5568
5569 if (info_ptr == NULL)
5570 return;
5571
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 ();
5575
5576 /* We don't use cutu_reader here because we don't need to read
5577 any dies: the signature is in the header. */
5578
5579 end_ptr = info_ptr + section->size;
5580 while (info_ptr < end_ptr)
5581 {
5582 signatured_type_up sig_type;
5583 struct dwo_unit *dwo_tu;
5584 void **slot;
5585 const gdb_byte *ptr = info_ptr;
5586 struct comp_unit_head header;
5587 unsigned int length;
5588
5589 sect_offset sect_off = (sect_offset) (ptr - section->buffer);
5590
5591 /* Initialize it due to a false compiler warning. */
5592 header.signature = -1;
5593 header.type_cu_offset_in_tu = (cu_offset) -1;
5594
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. */
5597
5598 ptr = read_and_check_comp_unit_head (per_objfile, &header, section,
5599 abbrev_section, ptr, section_kind);
5600
5601 length = header.get_length ();
5602
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))
5608 {
5609 info_ptr += length;
5610 continue;
5611 }
5612
5613 if (types_htab == NULL)
5614 types_htab = allocate_dwo_unit_table ();
5615
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;
5623
5624 slot = htab_find_slot (types_htab.get (), dwo_tu, INSERT);
5625 gdb_assert (slot != NULL);
5626 if (*slot != NULL)
5627 complaint (_("debug type entry at offset %s is duplicate to"
5628 " the entry at offset %s, signature %s"),
5630 sect_offset_str (dwo_tu->sect_off),
5631 hex_string (header.signature));
5632 *slot = dwo_tu;
5633
5634 dwarf_read_debug_printf_v (" offset %s, signature %s",
5636 hex_string (header.signature));
5637
5638 info_ptr += length;
5639 }
5640}
5641
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.
5645
5646 The result is a pointer to the hash table or NULL if there are no types.
5647
5648 Note: This function processes DWO files only, not DWP files. */
5649
5650static void
5652 struct dwo_file *dwo_file,
5653 gdb::array_view<dwarf2_section_info> type_sections,
5654 htab_up &types_htab)
5655{
5656 for (dwarf2_section_info &section : type_sections)
5657 create_debug_type_hash_table (per_objfile, dwo_file, &section, types_htab,
5659}
5660
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. */
5664
5665static struct signatured_type *
5666add_type_unit (dwarf2_per_objfile *per_objfile, ULONGEST sig, void **slot)
5667{
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;
5671
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 ();
5675
5676 per_objfile->per_bfd->all_units.emplace_back
5677 (sig_type_holder.release ());
5678
5679 if (slot == NULL)
5680 {
5681 slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (),
5682 sig_type, INSERT);
5683 }
5684 gdb_assert (*slot == NULL);
5685 *slot = sig_type;
5686 /* The rest of sig_type must be filled in by the caller. */
5687 return sig_type;
5688}
5689
5690/* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5691 Fill in SIG_ENTRY with DWO_ENTRY. */
5692
5693static void
5695 struct signatured_type *sig_entry,
5696 struct dwo_unit *dwo_entry)
5697{
5698 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
5699
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);
5711
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;
5719}
5720
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. */
5732
5733static struct signatured_type *
5734lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
5735{
5736 dwarf2_per_objfile *per_objfile = cu->per_objfile;
5737 struct dwo_file *dwo_file;
5738 struct dwo_unit find_dwo_entry, *dwo_entry;
5739 void **slot;
5740
5741 gdb_assert (cu->dwo_unit);
5742
5743 /* If TU skeletons have been removed then we may not have read in any
5744 TUs yet. */
5745 if (per_objfile->per_bfd->signatured_types == NULL)
5747
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. */
5753
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;
5758
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. */
5764
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)
5769 return sig_entry;
5770
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;
5774
5775 /* Ok, this is the first time we're reading this TU. */
5776 if (dwo_file->tus == NULL)
5777 return NULL;
5778 find_dwo_entry.signature = sig;
5779 dwo_entry = (struct dwo_unit *) htab_find (dwo_file->tus.get (),
5780 &find_dwo_entry);
5781 if (dwo_entry == NULL)
5782 return NULL;
5783
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);
5787
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;
5791 return sig_entry;
5792}
5793
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. */
5798
5799static struct signatured_type *
5800lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
5801{
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;
5805 void **slot;
5806
5807 gdb_assert (cu->dwo_unit);
5808 gdb_assert (dwp_file != NULL);
5809
5810 /* If TU skeletons have been removed then we may not have read in any
5811 TUs yet. */
5812 if (per_objfile->per_bfd->signatured_types == NULL)
5814
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;
5819
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)
5824 return sig_entry;
5825
5826 if (dwp_file->tus == NULL)
5827 return 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)
5831 return NULL;
5832
5833 sig_entry = add_type_unit (per_objfile, sig, slot);
5834 fill_in_sig_entry_from_dwo_entry (per_objfile, sig_entry, dwo_entry);
5835
5836 return sig_entry;
5837}
5838
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. */
5842
5843static struct signatured_type *
5844lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
5845{
5846 dwarf2_per_objfile *per_objfile = cu->per_objfile;
5847
5848 if (cu->dwo_unit)
5849 {
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);
5854 else
5855 return lookup_dwp_signatured_type (cu, sig);
5856 }
5857 else
5858 {
5859 if (per_objfile->per_bfd->signatured_types == NULL)
5860 return NULL;
5862 return ((struct signatured_type *)
5863 htab_find (per_objfile->per_bfd->signatured_types.get (),
5864 &find_entry));
5865 }
5866}
5867
5868/* Low level DIE reading support. */
5869
5870/* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5871
5872static void
5874 struct dwarf2_cu *cu,
5876 struct dwo_file *dwo_file,
5877 struct abbrev_table *abbrev_table)
5878{
5879 gdb_assert (section->readin && section->buffer != NULL);
5880 reader->abfd = section->get_bfd_owner ();
5881 reader->cu = cu;
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;
5887}
5888
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
5892 already.
5893
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.
5905
5906 The result is non-zero if a valid (non-dummy) DIE was found. */
5907
5908static int
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)
5917{
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;
5921 bfd *abfd;
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;
5927
5928 /* At most one of these may be provided. */
5929 gdb_assert ((stub_comp_unit_die != NULL) + (stub_comp_dir != NULL) <= 1);
5930
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
5937 DWO CU/TU die. */
5938
5939 stmt_list = NULL;
5940 low_pc = NULL;
5941 high_pc = NULL;
5942 ranges = NULL;
5943 comp_dir = NULL;
5944
5945 if (stub_comp_unit_die != NULL)
5946 {
5947 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5948 DWO file. */
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);
5955
5956 cu->addr_base = stub_comp_unit_die->addr_base ();
5957
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
5960 DWO. */
5961 cu->gnu_ranges_base = stub_comp_unit_die->gnu_ranges_base ();
5962
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
5967 section. */
5968 cu->rnglists_base = stub_comp_unit_die->rnglists_base ();
5969 }
5970 else if (stub_comp_dir != NULL)
5971 {
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);
5977 }
5978
5979 /* Set up for reading the DWO CU/TU. */
5980 cu->dwo_unit = dwo_unit;
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;
5987
5988 if (per_cu->is_debug_types)
5989 {
5990 signatured_type *sig_type = (struct signatured_type *) per_cu;
5991
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)
5997 {
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),
6003 bfd_get_filename (abfd));
6004 }
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 ();
6009 dwo_unit->type_offset_in_tu = cu->header.type_cu_offset_in_tu;
6010
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);
6015 }
6016 else
6017 {
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
6023 until now. */
6024 dwo_unit->length = cu->header.get_length ();
6025 }
6026
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 ());
6032
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)
6038 + (low_pc != NULL)
6039 + (high_pc != NULL)
6040 + (ranges != NULL)
6041 + (comp_dir != NULL));
6042 info_ptr = read_full_die_1 (result_reader, result_comp_unit_die, info_ptr,
6043 num_extra_attrs);
6044
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;
6050 if (low_pc != NULL)
6051 comp_unit_die->attrs[i++] = *low_pc;
6052 if (high_pc != NULL)
6053 comp_unit_die->attrs[i++] = *high_pc;
6054 if (ranges != NULL)
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;
6059
6060 if (dwarf_die_debug)
6061 {
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);
6068 }
6069
6070 /* Skip dummy compilation units. */
6071 if (info_ptr >= begin_info_ptr + dwo_unit->length
6072 || peek_abbrev_code (abfd, info_ptr) == 0)
6073 return 0;
6074
6075 *result_info_ptr = info_ptr;
6076 return 1;
6077}
6078
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. */
6082static gdb::optional<ULONGEST>
6083lookup_dwo_id (struct dwarf2_cu *cu, struct die_info* comp_unit_die)
6084{
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 ();
6092}
6093
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. */
6097
6098static struct dwo_unit *
6099lookup_dwo_unit (dwarf2_cu *cu, die_info *comp_unit_die, const char *dwo_name)
6100{
6101#if CXX_STD_THREAD
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;
6105
6106 std::lock_guard<std::mutex> guard (dwo_lock);
6107#endif
6108
6109 dwarf2_per_cu_data *per_cu = cu->per_cu;
6110 struct dwo_unit *dwo_unit;
6111 const char *comp_dir;
6112
6113 gdb_assert (cu != NULL);
6114
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);
6118
6119 if (per_cu->is_debug_types)
6120 dwo_unit = lookup_dwo_type_unit (cu, dwo_name, comp_dir);
6121 else
6122 {
6123 gdb::optional<ULONGEST> signature = lookup_dwo_id (cu, comp_unit_die);
6124
6125 if (!signature.has_value ())
6126 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6127 " [in module %s]"),
6128 dwo_name, bfd_get_filename (per_cu->per_bfd->obfd));
6129
6130 dwo_unit = lookup_dwo_comp_unit (cu, dwo_name, comp_dir, *signature);
6131 }
6132
6133 return dwo_unit;
6134}
6135
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. */
6139
6140void
6142 dwarf2_per_objfile *per_objfile,
6143 dwarf2_cu *existing_cu)
6144{
6145 struct signatured_type *sig_type;
6146
6147 /* Verify we can do the following downcast, and that we have the
6148 data we need. */
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);
6152
6153 dwarf2_cu *cu;
6154
6155 if (existing_cu != nullptr)
6156 {
6157 cu = existing_cu;
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. */
6161 }
6162 else
6163 {
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 ();
6169 }
6170
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. */
6174
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,
6178 this, &info_ptr,
6180 &m_dwo_abbrev_table) == 0)
6181 {
6182 /* Dummy die. */
6183 dummy_p = true;
6184 }
6185}
6186
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.
6189
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.
6193
6194 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6195 allocated. */
6196
6198 dwarf2_per_objfile *per_objfile,
6199 struct abbrev_table *abbrev_table,
6200 dwarf2_cu *existing_cu,
6201 bool skip_partial,
6202 abbrev_cache *cache)
6203 : die_reader_specs {},
6204 m_this_cu (this_cu)
6205{
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;
6216
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));
6221
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)
6225 {
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);
6230 return;
6231 }
6232
6233 /* This is cheap if the section is already read in. */
6234 section->read (objfile);
6235
6236 begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off);
6237
6238 abbrev_section = get_abbrev_section_for_cu (this_cu);
6239
6240 dwarf2_cu *cu;
6241
6242 if (existing_cu != nullptr)
6243 {
6244 cu = existing_cu;
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
6250 optimization. */
6251 if (cu->dwo_unit != NULL)
6252 rereading_dwo_cu = 1;
6253 }
6254 else
6255 {
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
6261 thread-safe. */
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 ();
6266 }
6267
6268 /* Get the header. */
6269 if (to_underlying (cu->header.first_die_cu_offset) != 0 && !rereading_dwo_cu)
6270 {
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);
6273 }
6274 else
6275 {
6276 if (this_cu->is_debug_types)
6277 {
6279 section, abbrev_section,
6281
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);
6289
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 ());
6293
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);
6297
6298 this_cu->set_version (cu->header.version);
6299 }
6300 else
6301 {
6303 section, abbrev_section,
6304 info_ptr,
6306
6307 gdb_assert (this_cu->sect_off == cu->header.sect_off);
6308 this_cu->set_length (cu->header.get_length ());
6309 this_cu->set_version (cu->header.version);
6310 }
6311 }
6312
6313 /* Skip dummy compilation units. */
6314 if (info_ptr >= begin_info_ptr + this_cu->length ()
6315 || peek_abbrev_code (abfd, info_ptr) == 0)
6316 {
6317 dummy_p = true;
6318 return;
6319 }
6320
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
6323 done. */
6324 if (abbrev_table != NULL)
6325 gdb_assert (cu->header.abbrev_sect_off == abbrev_table->sect_off);
6326 else
6327 {
6328 if (cache != nullptr)
6329 abbrev_table = cache->find (abbrev_section,
6330 cu->header.abbrev_sect_off);
6331 if (abbrev_table == nullptr)
6332 {
6333 abbrev_section->read (objfile);
6335 = abbrev_table::read (abbrev_section, cu->header.abbrev_sect_off);
6337 }
6338 }
6339
6340 /* Read the top level CU/TU die. */
6341 init_cu_die_reader (this, cu, section, NULL, abbrev_table);
6343
6344 if (skip_partial && comp_unit_die->tag == DW_TAG_partial_unit)
6345 {
6346 dummy_p = true;
6347 return;
6348 }
6349
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
6354 with READER.
6355
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)
6360 {
6361 struct dwo_unit *dwo_unit;
6362 struct die_info *dwo_comp_unit_die;
6363
6365 {
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));
6370 }
6372 if (dwo_unit != NULL)
6373 {
6375 comp_unit_die, NULL,
6376 this, &info_ptr,
6377 &dwo_comp_unit_die,
6378 &m_dwo_abbrev_table) == 0)
6379 {
6380 /* Dummy die. */
6381 dummy_p = true;
6382 return;
6383 }
6384 comp_unit_die = dwo_comp_unit_die;
6385 }
6386 else
6387 {
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
6392 debug info. */
6393 }
6394 }
6395}
6396
6397void
6399{
6400 /* Done, clean up. */
6401 gdb_assert (!dummy_p);
6402 if (m_new_cu != NULL)
6403 {
6404 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6405 now. */
6406 dwarf2_per_objfile *per_objfile = m_new_cu->per_objfile;
6407 per_objfile->set_cu (m_this_cu, std::move (m_new_cu));
6408 }
6409}
6410
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).
6414
6415 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6416 THIS_CU->is_debug_types, but nothing else.
6417
6418 We fill in THIS_CU->length.
6419
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.
6423
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. */
6426
6428 dwarf2_per_objfile *per_objfile,
6429 struct dwarf2_cu *parent_cu,
6430 struct dwo_file *dwo_file)
6431 : die_reader_specs {},
6432 m_this_cu (this_cu)
6433{
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;
6439
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));
6444
6445 gdb_assert (per_objfile->get_cu (this_cu) == nullptr);
6446
6447 abbrev_section = (dwo_file != NULL
6448 ? &dwo_file->sections.abbrev
6449 : get_abbrev_section_for_cu (this_cu));
6450
6451 /* This is cheap if the section is already read in. */
6452 section->read (objfile);
6453
6454 m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile));
6455
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
6462
6463 if (parent_cu != nullptr)
6464 {
6465 m_new_cu->str_offsets_base = parent_cu->str_offsets_base;
6466 m_new_cu->addr_base = parent_cu->addr_base;
6467 }
6468 this_cu->set_length (m_new_cu->header.get_length ());
6469
6470 /* Skip dummy compilation units. */
6471 if (info_ptr >= begin_info_ptr + this_cu->length ()
6472 || peek_abbrev_code (abfd, info_ptr) == 0)
6473 {
6474 dummy_p = true;
6475 return;
6476 }
6477
6478 abbrev_section->read (objfile);
6480 = abbrev_table::read (abbrev_section, m_new_cu->header.abbrev_sect_off);
6481
6482 init_cu_die_reader (this, m_new_cu.get (), section, dwo_file,
6483 m_abbrev_table_holder.get ());
6485}
6486
6487␌
6488/* Type Unit Groups.
6489
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. */
6495
6496static hashval_t
6497hash_type_unit_group (const void *item)
6498{
6499 const struct type_unit_group *tu_group
6500 = (const struct type_unit_group *) item;
6501
6502 return hash_stmt_list_entry (&tu_group->hash);
6503}
6504
6505static int
6506eq_type_unit_group (const void *item_lhs, const void *item_rhs)
6507{
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;
6510
6511 return eq_stmt_list_entry (&lhs->hash, &rhs->hash);
6512}
6513
6514/* Allocate a hash table for type unit groups. */
6515
6516static htab_up
6518{
6519 return htab_up (htab_create_alloc (3,
6522 htab_delete_entry<type_unit_group>,
6523 xcalloc, xfree));
6524}
6525
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
6531
6532/* Helper routine for get_type_unit_group.
6533 Create the type_unit_group object used to hold one or more TUs. */
6534
6535static std::unique_ptr<type_unit_group>
6536create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
6537{
6538 std::unique_ptr<type_unit_group> tu_group (new type_unit_group);
6539
6540 tu_group->hash.dwo_unit = cu->dwo_unit;
6541 tu_group->hash.line_sect_off = line_offset_struct;
6542
6543 return tu_group;
6544}
6545
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. */
6548
6549static struct type_unit_group *
6550get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list)
6551{
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;
6555 void **slot;
6556 unsigned int line_offset;
6557 struct type_unit_group type_unit_group_for_lookup;
6558
6559 if (per_objfile->per_bfd->type_unit_groups == NULL)
6561
6562 /* Do we need to create a new group, or can we use an existing one? */
6563
6564 if (stmt_list != nullptr && stmt_list->form_is_unsigned ())
6565 {
6566 line_offset = stmt_list->as_unsigned ();
6568 }
6569 else
6570 {
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. */
6580 }
6581
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)
6587 {
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 ();
6593 }
6594
6595 tu_group = (struct type_unit_group *) *slot;
6596 gdb_assert (tu_group != nullptr);
6597 return tu_group;
6598}
6599␌
6600
6601/* An instance of this is created when scanning DWARF to create a
6602 cooked index. */
6603
6605{
6606public:
6607
6609 : m_reader_hash (htab_create_alloc (10, hash_cutu_reader,
6611 htab_delete_entry<cutu_reader>,
6612 xcalloc, xfree)),
6613 m_index (new cooked_index)
6614 {
6615 }
6616
6618
6619 /* Return the current abbrev cache. */
6621 {
6622 return &m_abbrev_cache;
6623 }
6624
6625 /* Return the DIE reader corresponding to PER_CU. If no such reader
6626 has been registered, return NULL. */
6628 {
6629 int index = per_cu->index;
6630 return (cutu_reader *) htab_find_with_hash (m_reader_hash.get (),
6631 &index, index);
6632 }
6633
6634 /* Preserve READER by storing it in the local hash table. */
6635 cutu_reader *preserve (std::unique_ptr<cutu_reader> reader)
6636 {
6637 m_abbrev_cache.add (reader->release_abbrev_table ());
6638
6639 int index = reader->cu->per_cu->index;
6640 void **slot = htab_find_slot_with_hash (m_reader_hash.get (), &index,
6641 index, INSERT);
6642 gdb_assert (*slot == nullptr);
6643 cutu_reader *result = reader.get ();
6644 *slot = reader.release ();
6645 return result;
6646 }
6647
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,
6652 const char *name,
6653 const cooked_index_entry *parent_entry,
6654 dwarf2_per_cu_data *per_cu)
6655 {
6656 return m_index->add (die_offset, tag, flags, name, parent_entry, per_cu);
6657 }
6658
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 ()
6662 {
6663 m_index->install_addrmap (&m_addrmap);
6664 return std::move (m_index);
6665 }
6666
6667 /* Return the mutable addrmap that is currently being created. */
6669 {
6670 return &m_addrmap;
6671 }
6672
6673private:
6674
6675 /* Hash function for a cutu_reader. */
6676 static hashval_t hash_cutu_reader (const void *a)
6677 {
6678 const cutu_reader *reader = (const cutu_reader *) a;
6679 return reader->cu->per_cu->index;
6680 }
6681
6682 /* Equality function for cutu_reader. */
6683 static int eq_cutu_reader (const void *a, const void *b)
6684 {
6685 const cutu_reader *ra = (const cutu_reader *) a;
6686 const int *rb = (const int *) b;
6687 return ra->cu->per_cu->index == *rb;
6688 }
6689
6690 /* The abbrev cache used by this indexer. */
6692 /* A hash table of cutu_reader objects. */
6694 /* The index that is being constructed. */
6695 std::unique_ptr<cooked_index> m_index;
6696
6697 /* A writeable addrmap being constructed by this scanner. */
6699};
6700
6701/* An instance of this is created to index a CU. */
6702
6704{
6705public:
6706
6708 dwarf2_per_cu_data *per_cu,
6709 enum language language)
6710 : m_index_storage (storage),
6711 m_per_cu (per_cu),
6713 {
6714 }
6715
6717
6718 /* Index the given CU. */
6719 void make_index (cutu_reader *reader);
6720
6721private:
6722
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)
6726 {
6727 CORE_ADDR value = to_underlying (offset);
6728 if (is_dwz)
6729 value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1);
6730 return value;
6731 }
6732
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);
6736
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. */
6742 dwarf2_per_objfile *per_objfile,
6743 sect_offset sect_off,
6744 bool is_dwz,
6745 bool for_scanning);
6746
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
6752 reading stopped. */
6753 const gdb_byte *index_dies (cutu_reader *reader,
6754 const gdb_byte *info_ptr,
6755 const cooked_index_entry *parent_entry,
6756 bool fully);
6757
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,
6765 const char **name,
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);
6772
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);
6779
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,
6785 bool fully);
6786
6787 /* The storage object, where the results are kept. */
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
6792 recorded here. */
6794 /* The language that we're assuming when reading. */
6796
6797 /* An addrmap that maps from section offsets (see the form_addr
6798 method) to newly-created entries. See m_deferred_entries to
6799 understand this. */
6801
6802 /* A single deferred entry. */
6804 {
6805 sect_offset die_offset;
6806 const char *name;
6807 CORE_ADDR spec_offset;
6808 dwarf_tag tag;
6809 cooked_index_flag flags;
6810 };
6811
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;
6820};
6821
6822/* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6823 Process compilation unit THIS_CU for a psymtab. */
6824
6825static void
6827 dwarf2_per_objfile *per_objfile,
6828 cooked_index_storage *storage)
6829{
6830 cutu_reader reader (this_cu, per_objfile, nullptr, nullptr, false,
6831 storage->get_abbrev_cache ());
6832
6833 if (reader.comp_unit_die == nullptr)
6834 return;
6835
6836 if (reader.dummy_p)
6837 {
6838 /* Nothing. */
6839 }
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)
6843 {
6844 bool nope = false;
6845 if (this_cu->scanned.compare_exchange_strong (nope, true))
6846 {
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);
6852 }
6853 }
6854}
6855
6856/* Reader function for build_type_psymtabs. */
6857
6858static void
6860 cooked_index_storage *storage)
6861{
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;
6865
6866 gdb_assert (per_cu->is_debug_types);
6867
6868 if (! type_unit_die->has_children)
6869 return;
6870
6871 prepare_one_comp_unit (cu, type_unit_die, language_minimal);
6872
6873 gdb_assert (storage != nullptr);
6874 cooked_indexer indexer (storage, per_cu, cu->lang ());
6875 indexer.make_index (reader);
6876}
6877
6878/* Struct used to sort TUs by their abbreviation table offset. */
6879
6881{
6882 tu_abbrev_offset (signatured_type *sig_type_, sect_offset abbrev_offset_)
6883 : sig_type (sig_type_), abbrev_offset (abbrev_offset_)
6884 {}
6885
6886 /* This is used when sorting. */
6887 bool operator< (const tu_abbrev_offset &other) const
6888 {
6889 return abbrev_offset < other.abbrev_offset;
6890 }
6891
6893 sect_offset abbrev_offset;
6894};
6895
6896/* Efficiently read all the type units.
6897
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.
6901
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.
6908
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. */
6912
6913static void
6915 cooked_index_storage *storage)
6916{
6917 struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats;
6919 sect_offset abbrev_offset;
6920
6921 /* It's up to the caller to not call us multiple times. */
6922 gdb_assert (per_objfile->per_bfd->type_unit_groups == NULL);
6923
6924 if (per_objfile->per_bfd->all_type_units.size () == 0)
6925 return;
6926
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.
6932
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.
6936
6937 The basic algorithm here is:
6938
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]
6944 call FUNC */
6945
6946 dwarf_read_debug_printf ("Building type unit groups ...");
6947
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 ());
6952
6953 for (const auto &cu : per_objfile->per_bfd->all_units)
6954 {
6955 if (cu->is_debug_types)
6956 {
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));
6961 }
6962 }
6963
6964 std::sort (sorted_by_abbrev.begin (), sorted_by_abbrev.end ());
6965
6966 abbrev_offset = (sect_offset) ~(unsigned) 0;
6967
6968 for (const tu_abbrev_offset &tu : sorted_by_abbrev)
6969 {
6970 /* Switch to the next abbrev table if necessary. */
6971 if (abbrev_table == NULL
6972 || tu.abbrev_offset != abbrev_offset)
6973 {
6974 abbrev_offset = tu.abbrev_offset;
6975 per_objfile->per_bfd->abbrev.read (per_objfile->objfile);
6976 abbrev_table =
6977 abbrev_table::read (&per_objfile->per_bfd->abbrev, abbrev_offset);
6979 }
6980
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);
6985 }
6986}
6987
6988/* Print collected type unit statistics. */
6989
6990static void
6992{
6993 struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats;
6994
6995 dwarf_read_debug_printf ("Type unit statistics:");
6997 dwarf_read_debug_printf (" %d uniq abbrev tables",
6999 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7001 dwarf_read_debug_printf (" %d symtab sharers",
7003 dwarf_read_debug_printf (" %d type units without a stmt_list",
7005 dwarf_read_debug_printf (" %d all_type_units reallocs",
7007}
7008
7010{
7013};
7014
7015/* Traversal function for process_skeletonless_type_unit.
7016 Read a TU in a DWO file and build partial symbols for it. */
7017
7018static int
7019process_skeletonless_type_unit (void **slot, void *info)
7020{
7021 struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot;
7022 skeleton_data *data = (skeleton_data *) info;
7023
7024 /* If this TU doesn't exist in the global table, add it and read it in. */
7025
7026 if (data->per_objfile->per_bfd->signatured_types == NULL)
7027 data->per_objfile->per_bfd->signatured_types
7029
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. */
7035 if (*slot != NULL)
7036 return 1;
7037
7038 /* This does the job that create_all_units would have done for
7039 this TU. */
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);
7043 *slot = entry;
7044
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);
7049
7050 return 1;
7051}
7052
7053/* Traversal function for process_skeletonless_type_units. */
7054
7055static int
7057{
7058 struct dwo_file *dwo_file = (struct dwo_file *) *slot;
7059
7060 if (dwo_file->tus != NULL)
7061 htab_traverse_noresize (dwo_file->tus.get (),
7063
7064 return 1;
7065}
7066
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. */
7070
7071static void
7073 cooked_index_storage *storage)
7074{
7075 skeleton_data data { per_objfile, storage };
7076
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)
7080 {
7081 htab_traverse_noresize (per_objfile->per_bfd->dwo_files.get (),
7083 &data);
7084 }
7085}
7086
7087/* Build the partial symbol table by doing a quick pass through the
7088 .debug_info and .debug_abbrev sections. */
7089
7090static void
7092{
7093 struct objfile *objfile = per_objfile->objfile;
7094 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
7095
7096 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7098
7099 per_bfd->map_info_sections (objfile);
7100
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;
7105
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 ());
7111
7112 {
7113 /* Ensure that complaints are handled correctly. */
7114 complaint_interceptor complaint_handler;
7115
7116 using iter_type = decltype (per_bfd->all_units.begin ());
7117
7118 auto task_size_ = [] (iter_type iter)
7119 {
7120 dwarf2_per_cu_data *per_cu = iter->get ();
7121 return (size_t)per_cu->length ();
7122 };
7123 auto task_size = gdb::make_function_view (task_size_);
7124
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)
7136 {
7137 std::vector<gdb_exception> errors;
7138 cooked_index_storage thread_storage;
7139 for (; iter != end; ++iter)
7140 {
7141 dwarf2_per_cu_data *per_cu = iter->get ();
7142 try
7143 {
7144 process_psymtab_comp_unit (per_cu, per_objfile,
7145 &thread_storage);
7146 }
7147 catch (gdb_exception &except)
7148 {
7149 errors.push_back (std::move (except));
7150 }
7151 }
7152 return result_type (thread_storage.release (), std::move (errors));
7153 }, task_size);
7154
7155 /* Only show a given exception a single time. */
7156 std::unordered_set<gdb_exception> seen_exceptions;
7157 for (auto &one_result : results)
7158 {
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);
7163 }
7164 }
7165
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);
7168
7169 if (dwarf_read_debug > 0)
7170 print_tu_stats (per_objfile);
7171
7172 indexes.push_back (index_storage.release ());
7173 /* Remove any NULL entries. This might happen if parallel-for
7174 decides to throttle the number of threads that were used. */
7175 indexes.erase
7176 (std::remove_if (indexes.begin (),
7177 indexes.end (),
7178 [] (const std::unique_ptr<cooked_index> &entry)
7179 {
7180 return entry == nullptr;
7181 }),
7182 indexes.end ());
7183 indexes.shrink_to_fit ();
7184
7185 cooked_index_vector *vec = new cooked_index_vector (std::move (indexes));
7186 per_bfd->index_table.reset (vec);
7187
7188 const cooked_index_entry *main_entry = vec->get_main ();
7189 if (main_entry != nullptr)
7190 {
7191 /* We only do this for names not requiring canonicalization. At
7192 this point in the process names have not been canonicalized.
7193 However, currently, languages that require this step also do
7194 not use DW_AT_main_subprogram. An assert is appropriate here
7195 because this filtering is done in get_main. */
7196 enum language lang = main_entry->per_cu->lang ();
7197 gdb_assert (!language_requires_canonicalization (lang));
7198 const char *full_name = main_entry->full_name (&per_bfd->obstack, true);
7199 set_objfile_main_name (objfile, full_name, lang);
7200 }
7201
7202 dwarf_read_debug_printf ("Done building psymtabs of %s",
7204}
7205
7206static void
7208 struct dwarf2_section_info *section,
7209 struct dwarf2_section_info *abbrev_section,
7210 unsigned int is_dwz,
7211 htab_up &types_htab,
7212 rcuh_kind section_kind)
7213{
7214 const gdb_byte *info_ptr;
7215 struct objfile *objfile = per_objfile->objfile;
7216
7217 dwarf_read_debug_printf ("Reading %s for %s",
7218 section->get_name (),
7219 section->get_file_name ());
7220
7221 section->read (objfile);
7222
7223 info_ptr = section->buffer;
7224
7225 while (info_ptr < section->buffer + section->size)
7226 {
7227 dwarf2_per_cu_data_up this_cu;
7228
7229 sect_offset sect_off = (sect_offset) (info_ptr - section->buffer);
7230
7231 comp_unit_head cu_header;
7232 read_and_check_comp_unit_head (per_objfile, &cu_header, section,
7233 abbrev_section, info_ptr,
7234 section_kind);
7235
7236 /* Save the compilation unit for later lookup. */
7237 if (cu_header.unit_type != DW_UT_type)
7238 this_cu = per_objfile->per_bfd->allocate_per_cu ();
7239 else
7240 {
7241 if (types_htab == nullptr)
7242 types_htab = allocate_signatured_type_table ();
7243
7244 auto sig_type = per_objfile->per_bfd->allocate_signatured_type
7245 (cu_header.signature);
7246 signatured_type *sig_ptr = sig_type.get ();
7247 sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
7248 this_cu.reset (sig_type.release ());
7249
7250 void **slot = htab_find_slot (types_htab.get (), sig_ptr, INSERT);
7251 gdb_assert (slot != nullptr);
7252 if (*slot != nullptr)
7253 complaint (_("debug type entry at offset %s is duplicate to"
7254 " the entry at offset %s, signature %s"),
7255 sect_offset_str (sect_off),
7256 sect_offset_str (sig_ptr->sect_off),
7257 hex_string (sig_ptr->signature));
7258 *slot = sig_ptr;
7259 }
7260 this_cu->sect_off = sect_off;
7261 this_cu->set_length (cu_header.get_length ());
7262 this_cu->is_dwz = is_dwz;
7263 this_cu->section = section;
7264 /* Init this asap, to avoid a data race in the set_version in
7265 cutu_reader::cutu_reader (which may be run in parallel for the cooked
7266 index case). */
7267 this_cu->set_version (cu_header.version);
7268
7269 info_ptr = info_ptr + this_cu->length ();
7270 per_objfile->per_bfd->all_units.push_back (std::move (this_cu));
7271 }
7272}
7273
7274/* Initialize the views on all_units. */
7275
7276static void
7278{
7279 size_t nr_tus = per_bfd->tu_stats.nr_tus;
7280 size_t nr_cus = per_bfd->all_units.size () - nr_tus;
7281 gdb::array_view<dwarf2_per_cu_data_up> tmp = per_bfd->all_units;
7282 per_bfd->all_comp_units = tmp.slice (0, nr_cus);
7283 per_bfd->all_type_units = tmp.slice (nr_cus, nr_tus);
7284}
7285
7286/* Create a list of all compilation units in OBJFILE.
7287 This is only done for -readnow and building partial symtabs. */
7288
7289static void
7291{
7292 htab_up types_htab;
7293 gdb_assert (per_objfile->per_bfd->all_units.empty ());
7294
7295 read_comp_units_from_section (per_objfile, &per_objfile->per_bfd->info,
7296 &per_objfile->per_bfd->abbrev, 0,
7297 types_htab, rcuh_kind::COMPILE);
7298 for (dwarf2_section_info &section : per_objfile->per_bfd->types)
7299 read_comp_units_from_section (per_objfile, &section,
7300 &per_objfile->per_bfd->abbrev, 0,
7301 types_htab, rcuh_kind::TYPE);
7302
7303 dwz_file *dwz;
7304 try
7305 {
7306 dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
7307 }
7308 catch (const gdb_exception_error &)
7309 {
7310 per_objfile->per_bfd->all_units.clear ();
7311 throw;
7312 }
7313 if (dwz != NULL)
7314 {
7315 /* Pre-read the sections we'll need to construct an index. */
7316 struct objfile *objfile = per_objfile->objfile;
7317 dwz->abbrev.read (objfile);
7318 dwz->info.read (objfile);
7319 dwz->str.read (objfile);
7320 dwz->line.read (objfile);
7321 read_comp_units_from_section (per_objfile, &dwz->info, &dwz->abbrev, 1,
7322 types_htab, rcuh_kind::COMPILE);
7323 }
7324
7325 per_objfile->per_bfd->signatured_types = std::move (types_htab);
7326
7327 finalize_all_units (per_objfile->per_bfd);
7328}
7329
7330/* Return the initial uleb128 in the die at INFO_PTR. */
7331
7332static unsigned int
7333peek_abbrev_code (bfd *abfd, const gdb_byte *info_ptr)
7334{
7335 unsigned int bytes_read;
7336
7337 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7338}
7339
7340/* Read the initial uleb128 in the die at INFO_PTR in compilation unit
7341 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
7342
7343 Return the corresponding abbrev, or NULL if the number is zero (indicating
7344 an empty DIE). In either case *BYTES_READ will be set to the length of
7345 the initial number. */
7346
7347static const struct abbrev_info *
7349 const gdb_byte *info_ptr, unsigned int *bytes_read)
7350{
7351 dwarf2_cu *cu = reader.cu;
7352 bfd *abfd = reader.abfd;
7353 unsigned int abbrev_number
7354 = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
7355
7356 if (abbrev_number == 0)
7357 return NULL;
7358
7359 const abbrev_info *abbrev
7360 = reader.abbrev_table->lookup_abbrev (abbrev_number);
7361 if (!abbrev)
7362 {
7363 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7364 " at offset %s [in module %s]"),
7365 abbrev_number, cu->per_cu->is_debug_types ? "TU" : "CU",
7366 sect_offset_str (cu->header.sect_off), bfd_get_filename (abfd));
7367 }
7368
7369 return abbrev;
7370}
7371
7372/* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7373 Returns a pointer to the end of a series of DIEs, terminated by an empty
7374 DIE. Any children of the skipped DIEs will also be skipped. */
7375
7376static const gdb_byte *
7377skip_children (const struct die_reader_specs *reader, const gdb_byte *info_ptr)
7378{
7379 while (1)
7380 {
7381 unsigned int bytes_read;
7382 const abbrev_info *abbrev = peek_die_abbrev (*reader, info_ptr,
7383 &bytes_read);
7384
7385 if (abbrev == NULL)
7386 return info_ptr + bytes_read;
7387 else
7388 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
7389 }
7390}
7391
7392/* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7393 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7394 abbrev corresponding to that skipped uleb128 should be passed in
7395 ABBREV.
7396
7397 If DO_SKIP_CHILDREN is true, or if the DIE has no children, this
7398 returns a pointer to this DIE's sibling, skipping any children.
7399 Otherwise, returns a pointer to the DIE's first child. */
7400
7401static const gdb_byte *
7402skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr,
7403 const struct abbrev_info *abbrev, bool do_skip_children)
7404{
7405 unsigned int bytes_read;
7406 struct attribute attr;
7407 bfd *abfd = reader->abfd;
7408 struct dwarf2_cu *cu = reader->cu;
7409 const gdb_byte *buffer = reader->buffer;
7410 const gdb_byte *buffer_end = reader->buffer_end;
7411 unsigned int form, i;
7412
7413 if (do_skip_children && abbrev->sibling_offset != (unsigned short) -1)
7414 {
7415 /* We only handle DW_FORM_ref4 here. */
7416 const gdb_byte *sibling_data = info_ptr + abbrev->sibling_offset;
7417 unsigned int offset = read_4_bytes (abfd, sibling_data);
7418 const gdb_byte *sibling_ptr
7419 = buffer + to_underlying (cu->header.sect_off) + offset;
7420 if (sibling_ptr >= info_ptr && sibling_ptr < reader->buffer_end)
7421 return sibling_ptr;
7422 /* Fall through to the slow way. */
7423 }
7424 else if (abbrev->size_if_constant != 0)
7425 {
7426 info_ptr += abbrev->size_if_constant;
7427 if (do_skip_children && abbrev->has_children)
7428 return skip_children (reader, info_ptr);
7429 return info_ptr;
7430 }
7431
7432 for (i = 0; i < abbrev->num_attrs; i++)
7433 {
7434 /* The only abbrev we care about is DW_AT_sibling. */
7435 if (do_skip_children && abbrev->attrs[i].name == DW_AT_sibling)
7436 {
7437 read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
7438 if (attr.form == DW_FORM_ref_addr)
7439 complaint (_("ignoring absolute DW_AT_sibling"));
7440 else
7441 {
7442 sect_offset off = attr.get_ref_die_offset ();
7443 const gdb_byte *sibling_ptr = buffer + to_underlying (off);
7444
7445 if (sibling_ptr < info_ptr)
7446 complaint (_("DW_AT_sibling points backwards"));
7447 else if (sibling_ptr > reader->buffer_end)
7448 reader->die_section->overflow_complaint ();
7449 else
7450 return sibling_ptr;
7451 }
7452 }
7453
7454 /* If it isn't DW_AT_sibling, skip this attribute. */
7455 form = abbrev->attrs[i].form;
7456 skip_attribute:
7457 switch (form)
7458 {
7459 case DW_FORM_ref_addr:
7460 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7461 and later it is offset sized. */
7462 if (cu->header.version == 2)
7463 info_ptr += cu->header.addr_size;
7464 else
7465 info_ptr += cu->header.offset_size;
7466 break;
7467 case DW_FORM_GNU_ref_alt:
7468 info_ptr += cu->header.offset_size;
7469 break;
7470 case DW_FORM_addr:
7471 info_ptr += cu->header.addr_size;
7472 break;
7473 case DW_FORM_data1:
7474 case DW_FORM_ref1:
7475 case DW_FORM_flag:
7476 case DW_FORM_strx1:
7477 info_ptr += 1;
7478 break;
7479 case DW_FORM_flag_present:
7480 case DW_FORM_implicit_const:
7481 break;
7482 case DW_FORM_data2:
7483 case DW_FORM_ref2:
7484 case DW_FORM_strx2:
7485 info_ptr += 2;
7486 break;
7487 case DW_FORM_strx3:
7488 info_ptr += 3;
7489 break;
7490 case DW_FORM_data4:
7491 case DW_FORM_ref4:
7492 case DW_FORM_strx4:
7493 info_ptr += 4;
7494 break;
7495 case DW_FORM_data8:
7496 case DW_FORM_ref8:
7497 case DW_FORM_ref_sig8:
7498 info_ptr += 8;
7499 break;
7500 case DW_FORM_data16:
7501 info_ptr += 16;
7502 break;
7503 case DW_FORM_string:
7504 read_direct_string (abfd, info_ptr, &bytes_read);
7505 info_ptr += bytes_read;
7506 break;
7507 case DW_FORM_sec_offset:
7508 case DW_FORM_strp:
7509 case DW_FORM_GNU_strp_alt:
7510 info_ptr += cu->header.offset_size;
7511 break;
7512 case DW_FORM_exprloc:
7513 case DW_FORM_block:
7514 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7515 info_ptr += bytes_read;
7516 break;
7517 case DW_FORM_block1:
7518 info_ptr += 1 + read_1_byte (abfd, info_ptr);
7519 break;
7520 case DW_FORM_block2:
7521 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
7522 break;
7523 case DW_FORM_block4:
7524 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
7525 break;
7526 case DW_FORM_addrx:
7527 case DW_FORM_strx:
7528 case DW_FORM_sdata:
7529 case DW_FORM_udata:
7530 case DW_FORM_ref_udata:
7531 case DW_FORM_GNU_addr_index:
7532 case DW_FORM_GNU_str_index:
7533 case DW_FORM_rnglistx:
7534 case DW_FORM_loclistx:
7535 info_ptr = safe_skip_leb128 (info_ptr, buffer_end);
7536 break;
7537 case DW_FORM_indirect:
7538 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
7539 info_ptr += bytes_read;
7540 /* We need to continue parsing from here, so just go back to
7541 the top. */
7542 goto skip_attribute;
7543
7544 default:
7545 error (_("Dwarf Error: Cannot handle %s "
7546 "in DWARF reader [in module %s]"),
7547 dwarf_form_name (form),
7548 bfd_get_filename (abfd));
7549 }
7550 }
7551
7552 if (do_skip_children && abbrev->has_children)
7553 return skip_children (reader, info_ptr);
7554 else
7555 return info_ptr;
7556}
7557␌
7558/* Reading in full CUs. */
7559
7560/* Add PER_CU to the queue. */
7561
7562static void
7565 enum language pretend_language)
7566{
7567 per_cu->queued = 1;
7568
7569 gdb_assert (per_objfile->queue.has_value ());
7570 per_objfile->queue->emplace (per_cu, per_objfile, pretend_language);
7571}
7572
7573/* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
7574
7575 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7576 dependency.
7577
7578 Return true if maybe_queue_comp_unit requires the caller to load the CU's
7579 DIEs, false otherwise.
7580
7581 Explanation: there is an invariant that if a CU is queued for expansion
7582 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
7583 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
7584 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
7585 are not yet loaded, the the caller must load the CU's DIEs to ensure the
7586 invariant is respected.
7587
7588 The caller is therefore not required to load the CU's DIEs (we return false)
7589 if:
7590
7591 - the CU is already expanded, and therefore does not get enqueued
7592 - the CU gets enqueued for expansion, but its DIEs are already loaded
7593
7594 Note that the caller should not use this function's return value as an
7595 indicator of whether the CU's DIEs are loaded right now, it should check
7596 that by calling `dwarf2_per_objfile::get_cu` instead. */
7597
7598static int
7599maybe_queue_comp_unit (struct dwarf2_cu *dependent_cu,
7602 enum language pretend_language)
7603{
7604 /* Mark the dependence relation so that we don't flush PER_CU
7605 too early. */
7606 if (dependent_cu != NULL)
7607 dependent_cu->add_dependence (per_cu);
7608
7609 /* If it's already on the queue, we have nothing to do. */
7610 if (per_cu->queued)
7611 {
7612 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
7613 loaded. */
7614 gdb_assert (per_objfile->get_cu (per_cu) != nullptr);
7615
7616 /* If the CU is queued for expansion, it should not already be
7617 expanded. */
7618 gdb_assert (!per_objfile->symtab_set_p (per_cu));
7619
7620 /* The DIEs are already loaded, the caller doesn't need to do it. */
7621 return 0;
7622 }
7623
7624 bool queued = false;
7626 {
7627 /* Add it to the queue. */
7628 queue_comp_unit (per_cu, per_objfile, pretend_language);
7629 queued = true;
7630 }
7631
7632 /* If the compilation unit is already loaded, just mark it as
7633 used. */
7635 if (cu != nullptr)
7636 cu->last_used = 0;
7637
7638 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
7639 and the DIEs are not already loaded. */
7640 return queued && cu == nullptr;
7641}
7642
7643/* Process the queue. */
7644
7645static void
7647{
7648 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
7650
7651 /* The queue starts out with one item, but following a DIE reference
7652 may load a new CU, adding it to the end of the queue. */
7653 while (!per_objfile->queue->empty ())
7654 {
7655 dwarf2_queue_item &item = per_objfile->queue->front ();
7657
7659 {
7661
7662 /* Skip dummy CUs. */
7663 if (cu != nullptr)
7664 {
7665 unsigned int debug_print_threshold;
7666 char buf[100];
7667
7669 {
7670 struct signatured_type *sig_type =
7671 (struct signatured_type *) per_cu;
7672
7673 sprintf (buf, "TU %s at offset %s",
7674 hex_string (sig_type->signature),
7675 sect_offset_str (per_cu->sect_off));
7676 /* There can be 100s of TUs.
7677 Only print them in verbose mode. */
7678 debug_print_threshold = 2;
7679 }
7680 else
7681 {
7682 sprintf (buf, "CU at offset %s",
7683 sect_offset_str (per_cu->sect_off));
7684 debug_print_threshold = 1;
7685 }
7686
7687 if (dwarf_read_debug >= debug_print_threshold)
7688 dwarf_read_debug_printf ("Expanding symtab of %s", buf);
7689
7690 if (per_cu->is_debug_types)
7692 else
7694
7695 if (dwarf_read_debug >= debug_print_threshold)
7696 dwarf_read_debug_printf ("Done expanding %s", buf);
7697 }
7698 }
7699
7700 per_cu->queued = 0;
7701 per_objfile->queue->pop ();
7702 }
7703
7704 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
7705 objfile_name (per_objfile->objfile));
7706}
7707
7708/* Trivial hash function for die_info: the hash value of a DIE
7709 is its offset in .debug_info for this objfile. */
7710
7711static hashval_t
7712die_hash (const void *item)
7713{
7714 const struct die_info *die = (const struct die_info *) item;
7715
7716 return to_underlying (die->sect_off);
7717}
7718
7719/* Trivial comparison function for die_info structures: two DIEs
7720 are equal if they have the same offset. */
7721
7722static int
7723die_eq (const void *item_lhs, const void *item_rhs)
7724{
7725 const struct die_info *die_lhs = (const struct die_info *) item_lhs;
7726 const struct die_info *die_rhs = (const struct die_info *) item_rhs;
7727
7728 return die_lhs->sect_off == die_rhs->sect_off;
7729}
7730
7731/* Load the DIEs associated with PER_CU into memory.
7732
7733 In some cases, the caller, while reading partial symbols, will need to load
7734 the full symbols for the CU for some reason. It will already have a
7735 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
7736 rather than creating a new one. */
7737
7738static void
7740 dwarf2_per_objfile *per_objfile,
7741 dwarf2_cu *existing_cu,
7742 bool skip_partial,
7743 enum language pretend_language)
7744{
7745 gdb_assert (! this_cu->is_debug_types);
7746
7747 cutu_reader reader (this_cu, per_objfile, NULL, existing_cu, skip_partial);
7748 if (reader.dummy_p)
7749 return;
7750
7751 struct dwarf2_cu *cu = reader.cu;
7752 const gdb_byte *info_ptr = reader.info_ptr;
7753
7754 gdb_assert (cu->die_hash == NULL);
7755 cu->die_hash =
7756 htab_create_alloc_ex (cu->header.length / 12,
7757 die_hash,
7758 die_eq,
7759 NULL,
7760 &cu->comp_unit_obstack,
7761 hashtab_obstack_allocate,
7762 dummy_obstack_deallocate);
7763
7764 if (reader.comp_unit_die->has_children)
7765 reader.comp_unit_die->child
7766 = read_die_and_siblings (&reader, reader.info_ptr,
7767 &info_ptr, reader.comp_unit_die);
7768 cu->dies = reader.comp_unit_die;
7769 /* comp_unit_die is not stored in die_hash, no need. */
7770
7771 /* We try not to read any attributes in this function, because not
7772 all CUs needed for references have been loaded yet, and symbol
7773 table processing isn't initialized. But we have to set the CU language,
7774 or we won't be able to build types correctly.
7775 Similarly, if we do not read the producer, we can not apply
7776 producer-specific interpretation. */
7777 prepare_one_comp_unit (cu, cu->dies, pretend_language);
7778
7779 reader.keep ();
7780}
7781
7782/* Add a DIE to the delayed physname list. */
7783
7784static void
7785add_to_method_list (struct type *type, int fnfield_index, int index,
7786 const char *name, struct die_info *die,
7787 struct dwarf2_cu *cu)
7788{
7789 struct delayed_method_info mi;
7790 mi.type = type;
7792 mi.index = index;
7793 mi.name = name;
7794 mi.die = die;
7795 cu->method_list.push_back (mi);
7796}
7797
7798/* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
7799 "const" / "volatile". If so, decrements LEN by the length of the
7800 modifier and return true. Otherwise return false. */
7801
7802template<size_t N>
7803static bool
7804check_modifier (const char *physname, size_t &len, const char (&mod)[N])
7805{
7806 size_t mod_len = sizeof (mod) - 1;
7807 if (len > mod_len && startswith (physname + (len - mod_len), mod))
7808 {
7809 len -= mod_len;
7810 return true;
7811 }
7812 return false;
7813}
7814
7815/* Compute the physnames of any methods on the CU's method list.
7816
7817 The computation of method physnames is delayed in order to avoid the
7818 (bad) condition that one of the method's formal parameters is of an as yet
7819 incomplete type. */
7820
7821static void
7823{
7824 /* Only C++ delays computing physnames. */
7825 if (cu->method_list.empty ())
7826 return;
7827 gdb_assert (cu->lang () == language_cplus);
7828
7829 for (const delayed_method_info &mi : cu->method_list)
7830 {
7831 const char *physname;
7832 struct fn_fieldlist *fn_flp
7833 = &TYPE_FN_FIELDLIST (mi.type, mi.fnfield_index);
7834 physname = dwarf2_physname (mi.name, mi.die, cu);
7835 TYPE_FN_FIELD_PHYSNAME (fn_flp->fn_fields, mi.index)
7836 = physname ? physname : "";
7837
7838 /* Since there's no tag to indicate whether a method is a
7839 const/volatile overload, extract that information out of the
7840 demangled name. */
7841 if (physname != NULL)
7842 {
7843 size_t len = strlen (physname);
7844
7845 while (1)
7846 {
7847 if (physname[len] == ')') /* shortcut */
7848 break;
7849 else if (check_modifier (physname, len, " const"))
7850 TYPE_FN_FIELD_CONST (fn_flp->fn_fields, mi.index) = 1;
7851 else if (check_modifier (physname, len, " volatile"))
7852 TYPE_FN_FIELD_VOLATILE (fn_flp->fn_fields, mi.index) = 1;
7853 else
7854 break;
7855 }
7856 }
7857 }
7858
7859 /* The list is no longer needed. */
7860 cu->method_list.clear ();
7861}
7862
7863/* Go objects should be embedded in a DW_TAG_module DIE,
7864 and it's not clear if/how imported objects will appear.
7865 To keep Go support simple until that's worked out,
7866 go back through what we've read and create something usable.
7867 We could do this while processing each DIE, and feels kinda cleaner,
7868 but that way is more invasive.
7869 This is to, for example, allow the user to type "p var" or "b main"
7870 without having to specify the package name, and allow lookups
7871 of module.object to work in contexts that use the expression
7872 parser. */
7873
7874static void
7876{
7877 gdb::unique_xmalloc_ptr<char> package_name;
7878 struct pending *list;
7879 int i;
7880
7881 for (list = *cu->get_builder ()->get_global_symbols ();
7882 list != NULL;
7883 list = list->next)
7884 {
7885 for (i = 0; i < list->nsyms; ++i)
7886 {
7887 struct symbol *sym = list->symbol[i];
7888
7889 if (sym->language () == language_go
7890 && sym->aclass () == LOC_BLOCK)
7891 {
7892 gdb::unique_xmalloc_ptr<char> this_package_name
7893 (go_symbol_package_name (sym));
7894
7895 if (this_package_name == NULL)
7896 continue;
7897 if (package_name == NULL)
7898 package_name = std::move (this_package_name);
7899 else
7900 {
7901 struct objfile *objfile = cu->per_objfile->objfile;
7902 if (strcmp (package_name.get (), this_package_name.get ()) != 0)
7903 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
7904 (sym->symtab () != NULL
7906 (sym->symtab ())
7907 : objfile_name (objfile)),
7908 this_package_name.get (), package_name.get ());
7909 }
7910 }
7911 }
7912 }
7913
7914 if (package_name != NULL)
7915 {
7916 struct objfile *objfile = cu->per_objfile->objfile;
7917 const char *saved_package_name = objfile->intern (package_name.get ());
7918 struct type *type = init_type (objfile, TYPE_CODE_MODULE, 0,
7919 saved_package_name);
7920 struct symbol *sym;
7921
7922 sym = new (&objfile->objfile_obstack) symbol;
7924 sym->compute_and_set_names (saved_package_name, false, objfile->per_bfd);
7925 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7926 e.g., "main" finds the "main" module and not C's main(). */
7929 sym->set_type (type);
7930
7932 }
7933}
7934
7935/* Allocate a fully-qualified name consisting of the two parts on the
7936 obstack. */
7937
7938static const char *
7939rust_fully_qualify (struct obstack *obstack, const char *p1, const char *p2)
7940{
7941 return obconcat (obstack, p1, "::", p2, (char *) NULL);
7942}
7943
7944/* A helper that allocates a variant part to attach to a Rust enum
7945 type. OBSTACK is where the results should be allocated. TYPE is
7946 the type we're processing. DISCRIMINANT_INDEX is the index of the
7947 discriminant. It must be the index of one of the fields of TYPE,
7948 or -1 to mean there is no discriminant (univariant enum).
7949 DEFAULT_INDEX is the index of the default field; or -1 if there is
7950 no default. RANGES is indexed by "effective" field number (the
7951 field index, but omitting the discriminant and default fields) and
7952 must hold the discriminant values used by the variants. Note that
7953 RANGES must have a lifetime at least as long as OBSTACK -- either
7954 already allocated on it, or static. */
7955
7956static void
7958 int discriminant_index, int default_index,
7959 gdb::array_view<discriminant_range> ranges)
7960{
7961 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
7962 gdb_assert (discriminant_index == -1
7963 || (discriminant_index >= 0
7964 && discriminant_index < type->num_fields ()));
7965 gdb_assert (default_index == -1
7966 || (default_index >= 0 && default_index < type->num_fields ()));
7967
7968 /* We have one variant for each non-discriminant field. */
7969 int n_variants = type->num_fields ();
7970 if (discriminant_index != -1)
7971 --n_variants;
7972
7973 variant *variants = new (obstack) variant[n_variants];
7974 int var_idx = 0;
7975 int range_idx = 0;
7976 for (int i = 0; i < type->num_fields (); ++i)
7977 {
7978 if (i == discriminant_index)
7979 continue;
7980
7981 variants[var_idx].first_field = i;
7982 variants[var_idx].last_field = i + 1;
7983
7984 /* The default field does not need a range, but other fields do.
7985 We skipped the discriminant above. */
7986 if (i != default_index)
7987 {
7988 variants[var_idx].discriminants = ranges.slice (range_idx, 1);
7989 ++range_idx;
7990 }
7991
7992 ++var_idx;
7993 }
7994
7995 gdb_assert (range_idx == ranges.size ());
7996 gdb_assert (var_idx == n_variants);
7997
7998 variant_part *part = new (obstack) variant_part;
7999 part->discriminant_index = discriminant_index;
8000 /* If there is no discriminant, then whether it is signed is of no
8001 consequence. */
8002 part->is_unsigned
8003 = (discriminant_index == -1
8004 ? false
8005 : type->field (discriminant_index).type ()->is_unsigned ());
8006 part->variants = gdb::array_view<variant> (variants, n_variants);
8007
8008 void *storage = obstack_alloc (obstack, sizeof (gdb::array_view<variant_part>));
8009 gdb::array_view<variant_part> *prop_value
8010 = new (storage) gdb::array_view<variant_part> (part, 1);
8011
8012 struct dynamic_prop prop;
8013 prop.set_variant_parts (prop_value);
8014
8016}
8017
8018/* Some versions of rustc emitted enums in an unusual way.
8019
8020 Ordinary enums were emitted as unions. The first element of each
8021 structure in the union was named "RUST$ENUM$DISR". This element
8022 held the discriminant.
8023
8024 These versions of Rust also implemented the "non-zero"
8025 optimization. When the enum had two values, and one is empty and
8026 the other holds a pointer that cannot be zero, the pointer is used
8027 as the discriminant, with a zero value meaning the empty variant.
8028 Here, the union's first member is of the form
8029 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
8030 where the fieldnos are the indices of the fields that should be
8031 traversed in order to find the field (which may be several fields deep)
8032 and the variantname is the name of the variant of the case when the
8033 field is zero.
8034
8035 This function recognizes whether TYPE is of one of these forms,
8036 and, if so, smashes it to be a variant type. */
8037
8038static void
8040{
8041 gdb_assert (type->code () == TYPE_CODE_UNION);
8042
8043 /* We don't need to deal with empty enums. */
8044 if (type->num_fields () == 0)
8045 return;
8046
8047#define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
8048 if (type->num_fields () == 1
8049 && startswith (type->field (0).name (), RUST_ENUM_PREFIX))
8050 {
8051 const char *name = type->field (0).name () + strlen (RUST_ENUM_PREFIX);
8052
8053 /* Decode the field name to find the offset of the
8054 discriminant. */
8055 ULONGEST bit_offset = 0;
8056 struct type *field_type = type->field (0).type ();
8057 while (name[0] >= '0' && name[0] <= '9')
8058 {
8059 char *tail;
8060 unsigned long index = strtoul (name, &tail, 10);
8061 name = tail;
8062 if (*name != '$'
8063 || index >= field_type->num_fields ()
8064 || (field_type->field (index).loc_kind ()
8066 {
8067 complaint (_("Could not parse Rust enum encoding string \"%s\""
8068 "[in module %s]"),
8069 type->field (0).name (),
8071 return;
8072 }
8073 ++name;
8074
8075 bit_offset += field_type->field (index).loc_bitpos ();
8076 field_type = field_type->field (index).type ();
8077 }
8078
8079 /* Smash this type to be a structure type. We have to do this
8080 because the type has already been recorded. */
8081 type->set_code (TYPE_CODE_STRUCT);
8082 type->set_num_fields (3);
8083 /* Save the field we care about. */
8084 struct field saved_field = type->field (0);
8086 ((struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field)));
8087
8088 /* Put the discriminant at index 0. */
8089 type->field (0).set_type (field_type);
8090 TYPE_FIELD_ARTIFICIAL (type, 0) = 1;
8091 type->field (0).set_name ("<<discriminant>>");
8092 type->field (0).set_loc_bitpos (bit_offset);
8093
8094 /* The order of fields doesn't really matter, so put the real
8095 field at index 1 and the data-less field at index 2. */
8096 type->field (1) = saved_field;
8097 type->field (1).set_name
8098 (rust_last_path_segment (type->field (1).type ()->name ()));
8099 type->field (1).type ()->set_name
8101 type->field (1).name ()));
8102
8103 const char *dataless_name
8105 name);
8106 struct type *dataless_type = init_type (objfile, TYPE_CODE_VOID, 0,
8107 dataless_name);
8108 type->field (2).set_type (dataless_type);
8109 /* NAME points into the original discriminant name, which
8110 already has the correct lifetime. */
8111 type->field (2).set_name (name);
8112 type->field (2).set_loc_bitpos (0);
8113
8114 /* Indicate that this is a variant type. */
8115 static discriminant_range ranges[1] = { { 0, 0 } };
8117 }
8118 /* A union with a single anonymous field is probably an old-style
8119 univariant enum. */
8120 else if (type->num_fields () == 1 && streq (type->field (0).name (), ""))
8121 {
8122 /* Smash this type to be a structure type. We have to do this
8123 because the type has already been recorded. */
8124 type->set_code (TYPE_CODE_STRUCT);
8125
8126 struct type *field_type = type->field (0).type ();
8127 const char *variant_name
8128 = rust_last_path_segment (field_type->name ());
8129 type->field (0).set_name (variant_name);
8130 field_type->set_name
8132 type->name (), variant_name));
8133
8135 }
8136 else
8137 {
8138 struct type *disr_type = nullptr;
8139 for (int i = 0; i < type->num_fields (); ++i)
8140 {
8141 disr_type = type->field (i).type ();
8142
8143 if (disr_type->code () != TYPE_CODE_STRUCT)
8144 {
8145 /* All fields of a true enum will be structs. */
8146 return;
8147 }
8148 else if (disr_type->num_fields () == 0)
8149 {
8150 /* Could be data-less variant, so keep going. */
8151 disr_type = nullptr;
8152 }
8153 else if (strcmp (disr_type->field (0).name (),
8154 "RUST$ENUM$DISR") != 0)
8155 {
8156 /* Not a Rust enum. */
8157 return;
8158 }
8159 else
8160 {
8161 /* Found one. */
8162 break;
8163 }
8164 }
8165
8166 /* If we got here without a discriminant, then it's probably
8167 just a union. */
8168 if (disr_type == nullptr)
8169 return;
8170
8171 /* Smash this type to be a structure type. We have to do this
8172 because the type has already been recorded. */
8173 type->set_code (TYPE_CODE_STRUCT);
8174
8175 /* Make space for the discriminant field. */
8176 struct field *disr_field = &disr_type->field (0);
8177 field *new_fields
8178 = (struct field *) TYPE_ZALLOC (type, ((type->num_fields () + 1)
8179 * sizeof (struct field)));
8180 memcpy (new_fields + 1, type->fields (),
8181 type->num_fields () * sizeof (struct field));
8182 type->set_fields (new_fields);
8184
8185 /* Install the discriminant at index 0 in the union. */
8186 type->field (0) = *disr_field;
8187 TYPE_FIELD_ARTIFICIAL (type, 0) = 1;
8188 type->field (0).set_name ("<<discriminant>>");
8189
8190 /* We need a way to find the correct discriminant given a
8191 variant name. For convenience we build a map here. */
8192 struct type *enum_type = disr_field->type ();
8193 std::unordered_map<std::string, ULONGEST> discriminant_map;
8194 for (int i = 0; i < enum_type->num_fields (); ++i)
8195 {
8196 if (enum_type->field (i).loc_kind () == FIELD_LOC_KIND_ENUMVAL)
8197 {
8198 const char *name
8199 = rust_last_path_segment (enum_type->field (i).name ());
8200 discriminant_map[name] = enum_type->field (i).loc_enumval ();
8201 }
8202 }
8203
8204 int n_fields = type->num_fields ();
8205 /* We don't need a range entry for the discriminant, but we do
8206 need one for every other field, as there is no default
8207 variant. */
8208 discriminant_range *ranges = XOBNEWVEC (&objfile->objfile_obstack,
8210 n_fields - 1);
8211 /* Skip the discriminant here. */
8212 for (int i = 1; i < n_fields; ++i)
8213 {
8214 /* Find the final word in the name of this variant's type.
8215 That name can be used to look up the correct
8216 discriminant. */
8217 const char *variant_name
8218 = rust_last_path_segment (type->field (i).type ()->name ());
8219
8220 auto iter = discriminant_map.find (variant_name);
8221 if (iter != discriminant_map.end ())
8222 {
8223 ranges[i - 1].low = iter->second;
8224 ranges[i - 1].high = iter->second;
8225 }
8226
8227 /* In Rust, each element should have the size of the
8228 enclosing enum. */
8229 type->field (i).type ()->set_length (type->length ());
8230
8231 /* Remove the discriminant field, if it exists. */
8232 struct type *sub_type = type->field (i).type ();
8233 if (sub_type->num_fields () > 0)
8234 {
8235 sub_type->set_num_fields (sub_type->num_fields () - 1);
8236 sub_type->set_fields (sub_type->fields () + 1);
8237 }
8238 type->field (i).set_name (variant_name);
8239 sub_type->set_name
8241 type->name (), variant_name));
8242 }
8243
8244 /* Indicate that this is a variant type. */
8246 gdb::array_view<discriminant_range> (ranges,
8247 n_fields - 1));
8248 }
8249}
8250
8251/* Rewrite some Rust unions to be structures with variants parts. */
8252
8253static void
8255{
8256 gdb_assert (cu->lang () == language_rust);
8257 for (type *type_ : cu->rust_unions)
8258 quirk_rust_enum (type_, cu->per_objfile->objfile);
8259 /* We don't need this any more. */
8260 cu->rust_unions.clear ();
8261}
8262
8263/* See read.h. */
8264
8267{
8268 auto iter = this->m_type_units.find (tu_group);
8269 if (iter != this->m_type_units.end ())
8270 return iter->second.get ();
8271
8273 type_unit_group_unshareable *result = uniq.get ();
8274 this->m_type_units[tu_group] = std::move (uniq);
8275 return result;
8276}
8277
8278struct type *
8280 (signatured_type *sig_type) const
8281{
8282 auto iter = this->m_type_map.find (sig_type);
8283 if (iter == this->m_type_map.end ())
8284 return nullptr;
8285
8286 return iter->second;
8287}
8288
8290 (signatured_type *sig_type, struct type *type)
8291{
8292 gdb_assert (this->m_type_map.find (sig_type) == this->m_type_map.end ());
8293
8294 this->m_type_map[sig_type] = type;
8295}
8296
8297/* A helper function for computing the list of all symbol tables
8298 included by PER_CU. */
8299
8300static void
8301recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
8302 htab_t all_children, htab_t all_type_symtabs,
8303 dwarf2_per_cu_data *per_cu,
8304 dwarf2_per_objfile *per_objfile,
8305 struct compunit_symtab *immediate_parent)
8306{
8307 void **slot = htab_find_slot (all_children, per_cu, INSERT);
8308 if (*slot != NULL)
8309 {
8310 /* This inclusion and its children have been processed. */
8311 return;
8312 }
8313
8314 *slot = per_cu;
8315
8316 /* Only add a CU if it has a symbol table. */
8317 compunit_symtab *cust = per_objfile->get_symtab (per_cu);
8318 if (cust != NULL)
8319 {
8320 /* If this is a type unit only add its symbol table if we haven't
8321 seen it yet (type unit per_cu's can share symtabs). */
8322 if (per_cu->is_debug_types)
8323 {
8324 slot = htab_find_slot (all_type_symtabs, cust, INSERT);
8325 if (*slot == NULL)
8326 {
8327 *slot = cust;
8328 result->push_back (cust);
8329 if (cust->user == NULL)
8330 cust->user = immediate_parent;
8331 }
8332 }
8333 else
8334 {
8335 result->push_back (cust);
8336 if (cust->user == NULL)
8337 cust->user = immediate_parent;
8338 }
8339 }
8340
8341 if (!per_cu->imported_symtabs_empty ())
8342 for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
8343 {
8344 recursively_compute_inclusions (result, all_children,
8345 all_type_symtabs, ptr, per_objfile,
8346 cust);
8347 }
8348}
8349
8350/* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
8351 PER_CU. */
8352
8353static void
8355 dwarf2_per_objfile *per_objfile)
8356{
8357 gdb_assert (! per_cu->is_debug_types);
8358
8359 if (!per_cu->imported_symtabs_empty ())
8360 {
8361 int len;
8362 std::vector<compunit_symtab *> result_symtabs;
8363 compunit_symtab *cust = per_objfile->get_symtab (per_cu);
8364
8365 /* If we don't have a symtab, we can just skip this case. */
8366 if (cust == NULL)
8367 return;
8368
8369 htab_up all_children (htab_create_alloc (1, htab_hash_pointer,
8370 htab_eq_pointer,
8371 NULL, xcalloc, xfree));
8372 htab_up all_type_symtabs (htab_create_alloc (1, htab_hash_pointer,
8373 htab_eq_pointer,
8374 NULL, xcalloc, xfree));
8375
8376 for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
8377 {
8378 recursively_compute_inclusions (&result_symtabs, all_children.get (),
8379 all_type_symtabs.get (), ptr,
8380 per_objfile, cust);
8381 }
8382
8383 /* Now we have a transitive closure of all the included symtabs. */
8384 len = result_symtabs.size ();
8385 cust->includes
8386 = XOBNEWVEC (&per_objfile->objfile->objfile_obstack,
8387 struct compunit_symtab *, len + 1);
8388 memcpy (cust->includes, result_symtabs.data (),
8389 len * sizeof (compunit_symtab *));
8390 cust->includes[len] = NULL;
8391 }
8392}
8393
8394/* Compute the 'includes' field for the symtabs of all the CUs we just
8395 read. */
8396
8397static void
8399{
8400 for (dwarf2_per_cu_data *iter : per_objfile->per_bfd->just_read_cus)
8401 {
8402 if (! iter->is_debug_types)
8403 compute_compunit_symtab_includes (iter, per_objfile);
8404 }
8405
8406 per_objfile->per_bfd->just_read_cus.clear ();
8407}
8408
8409/* Generate full symbol information for CU, whose DIEs have
8410 already been loaded into memory. */
8411
8412static void
8413process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
8414{
8415 dwarf2_per_objfile *per_objfile = cu->per_objfile;
8416 struct objfile *objfile = per_objfile->objfile;
8417 struct gdbarch *gdbarch = objfile->arch ();
8418 CORE_ADDR lowpc, highpc;
8419 struct compunit_symtab *cust;
8420 CORE_ADDR baseaddr;
8421 struct block *static_block;
8422 CORE_ADDR addr;
8423
8424 baseaddr = objfile->text_section_offset ();
8425
8426 /* Clear the list here in case something was left over. */
8427 cu->method_list.clear ();
8428
8430
8431 /* Before we start reading the top-level DIE, ensure it has a valid tag
8432 type. */
8433 switch (cu->dies->tag)
8434 {
8435 case DW_TAG_compile_unit:
8436 case DW_TAG_partial_unit:
8437 case DW_TAG_type_unit:
8438 break;
8439 default:
8440 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
8441 dwarf_tag_name (cu->dies->tag),
8443 objfile_name (per_objfile->objfile));
8444 }
8445
8446 /* Do line number decoding in read_file_scope () */
8447 process_die (cu->dies, cu);
8448
8449 /* For now fudge the Go package. */
8450 if (cu->lang () == language_go)
8451 fixup_go_packaging (cu);
8452
8453 /* Now that we have processed all the DIEs in the CU, all the types
8454 should be complete, and it should now be safe to compute all of the
8455 physnames. */
8457
8458 if (cu->lang () == language_rust)
8459 rust_union_quirks (cu);
8460
8461 /* Some compilers don't define a DW_AT_high_pc attribute for the
8462 compilation unit. If the DW_AT_high_pc is missing, synthesize
8463 it, by scanning the DIE's below the compilation unit. */
8464 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
8465
8466 addr = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
8467 static_block
8469
8470 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8471 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8472 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8473 addrmap to help ensure it has an accurate map of pc values belonging to
8474 this comp unit. */
8475 dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu);
8476
8478 (static_block, SECT_OFF_TEXT (objfile), 0);
8479
8480 if (cust != NULL)
8481 {
8482 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
8483
8484 /* Set symtab language to language from DW_AT_language. If the
8485 compilation is from a C file generated by language preprocessors, do
8486 not set the language if it was already deduced by start_subfile. */
8487 if (!(cu->lang () == language_c
8488 && cust->primary_filetab ()->language () != language_unknown))
8489 cust->primary_filetab ()->set_language (cu->lang ());
8490
8491 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8492 produce DW_AT_location with location lists but it can be possibly
8493 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8494 there were bugs in prologue debug info, fixed later in GCC-4.5
8495 by "unwind info for epilogues" patch (which is not directly related).
8496
8497 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8498 needed, it would be wrong due to missing DW_AT_producer there.
8499
8500 Still one can confuse GDB by using non-standard GCC compilation
8501 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8502 */
8503 if (cu->has_loclist && gcc_4_minor >= 5)
8504 cust->set_locations_valid (true);
8505
8506 if (gcc_4_minor >= 5)
8507 cust->set_epilogue_unwind_valid (true);
8508
8510 }
8511
8512 per_objfile->set_symtab (cu->per_cu, cust);
8513
8514 /* Push it for inclusion processing later. */
8515 per_objfile->per_bfd->just_read_cus.push_back (cu->per_cu);
8516
8517 /* Not needed any more. */
8518 cu->reset_builder ();
8519}
8520
8521/* Generate full symbol information for type unit CU, whose DIEs have
8522 already been loaded into memory. */
8523
8524static void
8526 enum language pretend_language)
8527{
8528 dwarf2_per_objfile *per_objfile = cu->per_objfile;
8529 struct objfile *objfile = per_objfile->objfile;
8530 struct compunit_symtab *cust;
8531 struct signatured_type *sig_type;
8532
8533 gdb_assert (cu->per_cu->is_debug_types);
8534 sig_type = (struct signatured_type *) cu->per_cu;
8535
8536 /* Clear the list here in case something was left over. */
8537 cu->method_list.clear ();
8538
8539 /* The symbol tables are set up in read_type_unit_scope. */
8540 process_die (cu->dies, cu);
8541
8542 /* For now fudge the Go package. */
8543 if (cu->lang () == language_go)
8544 fixup_go_packaging (cu);
8545
8546 /* Now that we have processed all the DIEs in the CU, all the types
8547 should be complete, and it should now be safe to compute all of the
8548 physnames. */
8550
8551 if (cu->lang () == language_rust)
8552 rust_union_quirks (cu);
8553
8554 /* TUs share symbol tables.
8555 If this is the first TU to use this symtab, complete the construction
8556 of it with end_expandable_symtab. Otherwise, complete the addition of
8557 this TU's symbols to the existing symtab. */
8558 type_unit_group_unshareable *tug_unshare =
8559 per_objfile->get_type_unit_group_unshareable (sig_type->type_unit_group);
8560 if (tug_unshare->compunit_symtab == NULL)
8561 {
8562 buildsym_compunit *builder = cu->get_builder ();
8563 cust = builder->end_expandable_symtab (0, SECT_OFF_TEXT (objfile));
8564 tug_unshare->compunit_symtab = cust;
8565
8566 if (cust != NULL)
8567 {
8568 /* Set symtab language to language from DW_AT_language. If the
8569 compilation is from a C file generated by language preprocessors,
8570 do not set the language if it was already deduced by
8571 start_subfile. */
8572 if (!(cu->lang () == language_c
8573 && cust->primary_filetab ()->language () != language_c))
8574 cust->primary_filetab ()->set_language (cu->lang ());
8575 }
8576 }
8577 else
8578 {
8580 cust = tug_unshare->compunit_symtab;
8581 }
8582
8583 per_objfile->set_symtab (cu->per_cu, cust);
8584
8585 /* Not needed any more. */
8586 cu->reset_builder ();
8587}
8588
8589/* Process an imported unit DIE. */
8590
8591static void
8593{
8594 struct attribute *attr;
8595
8596 /* For now we don't handle imported units in type units. */
8597 if (cu->per_cu->is_debug_types)
8598 {
8599 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8600 " supported in type units [in module %s]"),
8602 }
8603
8604 attr = dwarf2_attr (die, DW_AT_import, cu);
8605 if (attr != NULL)
8606 {
8607 sect_offset sect_off = attr->get_ref_die_offset ();
8608 bool is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
8609 dwarf2_per_objfile *per_objfile = cu->per_objfile;
8610 dwarf2_per_cu_data *per_cu
8611 = dwarf2_find_containing_comp_unit (sect_off, is_dwz,
8612 per_objfile->per_bfd);
8613
8614 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
8615 into another compilation unit, at root level. Regard this as a hint,
8616 and ignore it. This is a best effort, it only works if unit_type and
8617 lang are already set. */
8618 if (die->parent && die->parent->parent == NULL
8619 && per_cu->unit_type (false) == DW_UT_compile
8620 && per_cu->lang (false) == language_cplus)
8621 return;
8622
8623 /* If necessary, add it to the queue and load its DIEs. */
8624 if (maybe_queue_comp_unit (cu, per_cu, per_objfile,
8625 cu->lang ()))
8626 load_full_comp_unit (per_cu, per_objfile, per_objfile->get_cu (per_cu),
8627 false, cu->lang ());
8628
8629 cu->per_cu->imported_symtabs_push (per_cu);
8630 }
8631}
8632
8633/* RAII object that represents a process_die scope: i.e.,
8634 starts/finishes processing a DIE. */
8636{
8637public:
8639 : m_die (die), m_cu (cu)
8640 {
8641 /* We should only be processing DIEs not already in process. */
8642 gdb_assert (!m_die->in_process);
8643 m_die->in_process = true;
8644 }
8645
8647 {
8648 m_die->in_process = false;
8649
8650 /* If we're done processing the DIE for the CU that owns the line
8651 header, we don't need the line header anymore. */
8653 {
8654 delete m_cu->line_header;
8655 m_cu->line_header = NULL;
8657 }
8658 }
8659
8660private:
8663};
8664
8665/* Process a die and its children. */
8666
8667static void
8668process_die (struct die_info *die, struct dwarf2_cu *cu)
8669{
8670 process_die_scope scope (die, cu);
8671
8672 switch (die->tag)
8673 {
8674 case DW_TAG_padding:
8675 break;
8676 case DW_TAG_compile_unit:
8677 case DW_TAG_partial_unit:
8678 read_file_scope (die, cu);
8679 break;
8680 case DW_TAG_type_unit:
8681 read_type_unit_scope (die, cu);
8682 break;
8683 case DW_TAG_subprogram:
8684 /* Nested subprograms in Fortran get a prefix. */
8685 if (cu->lang () == language_fortran
8686 && die->parent != NULL
8687 && die->parent->tag == DW_TAG_subprogram)
8689 /* Fall through. */
8690 case DW_TAG_inlined_subroutine:
8691 read_func_scope (die, cu);
8692 break;
8693 case DW_TAG_lexical_block:
8694 case DW_TAG_try_block:
8695 case DW_TAG_catch_block:
8696 read_lexical_block_scope (die, cu);
8697 break;
8698 case DW_TAG_call_site:
8699 case DW_TAG_GNU_call_site:
8700 read_call_site_scope (die, cu);
8701 break;
8702 case DW_TAG_class_type:
8703 case DW_TAG_interface_type:
8704 case DW_TAG_structure_type:
8705 case DW_TAG_union_type:
8706 case DW_TAG_namelist:
8707 process_structure_scope (die, cu);
8708 break;
8709 case DW_TAG_enumeration_type:
8710 process_enumeration_scope (die, cu);
8711 break;
8712
8713 /* These dies have a type, but processing them does not create
8714 a symbol or recurse to process the children. Therefore we can
8715 read them on-demand through read_type_die. */
8716 case DW_TAG_subroutine_type:
8717 case DW_TAG_set_type:
8718 case DW_TAG_pointer_type:
8719 case DW_TAG_ptr_to_member_type:
8720 case DW_TAG_reference_type:
8721 case DW_TAG_rvalue_reference_type:
8722 case DW_TAG_string_type:
8723 break;
8724
8725 case DW_TAG_array_type:
8726 /* We only need to handle this case for Ada -- in other
8727 languages, it's normal for the compiler to emit a typedef
8728 instead. */
8729 if (cu->lang () != language_ada)
8730 break;
8731 /* FALLTHROUGH */
8732 case DW_TAG_base_type:
8733 case DW_TAG_subrange_type:
8734 case DW_TAG_generic_subrange:
8735 case DW_TAG_typedef:
8736 /* Add a typedef symbol for the type definition, if it has a
8737 DW_AT_name. */
8738 new_symbol (die, read_type_die (die, cu), cu);
8739 break;
8740 case DW_TAG_common_block:
8741 read_common_block (die, cu);
8742 break;
8743 case DW_TAG_common_inclusion:
8744 break;
8745 case DW_TAG_namespace:
8747 read_namespace (die, cu);
8748 break;
8749 case DW_TAG_module:
8751 read_module (die, cu);
8752 break;
8753 case DW_TAG_imported_declaration:
8755 if (read_alias (die, cu))
8756 break;
8757 /* The declaration is neither a global namespace nor a variable
8758 alias. */
8759 /* Fall through. */
8760 case DW_TAG_imported_module:
8762 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
8763 || cu->lang () != language_fortran))
8764 complaint (_("Tag '%s' has unexpected children"),
8765 dwarf_tag_name (die->tag));
8766 read_import_statement (die, cu);
8767 break;
8768
8769 case DW_TAG_imported_unit:
8770 process_imported_unit_die (die, cu);
8771 break;
8772
8773 case DW_TAG_variable:
8774 read_variable (die, cu);
8775 break;
8776
8777 default:
8778 new_symbol (die, NULL, cu);
8779 break;
8780 }
8781}
8782␌
8783/* DWARF name computation. */
8784
8785/* A helper function for dwarf2_compute_name which determines whether DIE
8786 needs to have the name of the scope prepended to the name listed in the
8787 die. */
8788
8789static int
8790die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
8791{
8792 struct attribute *attr;
8793
8794 switch (die->tag)
8795 {
8796 case DW_TAG_namespace:
8797 case DW_TAG_typedef:
8798 case DW_TAG_class_type:
8799 case DW_TAG_interface_type:
8800 case DW_TAG_structure_type:
8801 case DW_TAG_union_type:
8802 case DW_TAG_enumeration_type:
8803 case DW_TAG_enumerator:
8804 case DW_TAG_subprogram:
8805 case DW_TAG_inlined_subroutine:
8806 case DW_TAG_member:
8807 case DW_TAG_imported_declaration:
8808 return 1;
8809
8810 case DW_TAG_variable:
8811 case DW_TAG_constant:
8812 /* We only need to prefix "globally" visible variables. These include
8813 any variable marked with DW_AT_external or any variable that
8814 lives in a namespace. [Variables in anonymous namespaces
8815 require prefixing, but they are not DW_AT_external.] */
8816
8817 if (dwarf2_attr (die, DW_AT_specification, cu))
8818 {
8819 struct dwarf2_cu *spec_cu = cu;
8820
8821 return die_needs_namespace (die_specification (die, &spec_cu),
8822 spec_cu);
8823 }
8824
8825 attr = dwarf2_attr (die, DW_AT_external, cu);
8826 if (attr == NULL && die->parent->tag != DW_TAG_namespace
8827 && die->parent->tag != DW_TAG_module)
8828 return 0;
8829 /* A variable in a lexical block of some kind does not need a
8830 namespace, even though in C++ such variables may be external
8831 and have a mangled name. */
8832 if (die->parent->tag == DW_TAG_lexical_block
8833 || die->parent->tag == DW_TAG_try_block
8834 || die->parent->tag == DW_TAG_catch_block
8835 || die->parent->tag == DW_TAG_subprogram)
8836 return 0;
8837 return 1;
8838
8839 default:
8840 return 0;
8841 }
8842}
8843
8844/* Return the DIE's linkage name attribute, either DW_AT_linkage_name
8845 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
8846 defined for the given DIE. */
8847
8848static struct attribute *
8850{
8851 struct attribute *attr;
8852
8853 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
8854 if (attr == NULL)
8855 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
8856
8857 return attr;
8858}
8859
8860/* Return the DIE's linkage name as a string, either DW_AT_linkage_name
8861 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
8862 defined for the given DIE. */
8863
8864static const char *
8865dw2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
8866{
8867 const char *linkage_name;
8868
8869 linkage_name = dwarf2_string_attr (die, DW_AT_linkage_name, cu);
8870 if (linkage_name == NULL)
8871 linkage_name = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu);
8872
8873 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
8874 See https://github.com/rust-lang/rust/issues/32925. */
8875 if (cu->lang () == language_rust && linkage_name != NULL
8876 && strchr (linkage_name, '{') != NULL)
8877 linkage_name = NULL;
8878
8879 return linkage_name;
8880}
8881
8882/* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8883 compute the physname for the object, which include a method's:
8884 - formal parameters (C++),
8885 - receiver type (Go),
8886
8887 The term "physname" is a bit confusing.
8888 For C++, for example, it is the demangled name.
8889 For Go, for example, it's the mangled name.
8890
8891 For Ada, return the DIE's linkage name rather than the fully qualified
8892 name. PHYSNAME is ignored..
8893
8894 The result is allocated on the objfile->per_bfd's obstack and
8895 canonicalized. */
8896
8897static const char *
8899 struct die_info *die, struct dwarf2_cu *cu,
8900 int physname)
8901{
8902 struct objfile *objfile = cu->per_objfile->objfile;
8903
8904 if (name == NULL)
8905 name = dwarf2_name (die, cu);
8906
8907 enum language lang = cu->lang ();
8908
8909 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
8910 but otherwise compute it by typename_concat inside GDB.
8911 FIXME: Actually this is not really true, or at least not always true.
8912 It's all very confusing. compute_and_set_names doesn't try to demangle
8913 Fortran names because there is no mangling standard. So new_symbol
8914 will set the demangled name to the result of dwarf2_full_name, and it is
8915 the demangled name that GDB uses if it exists. */
8916 if (lang == language_ada
8917 || (lang == language_fortran && physname))
8918 {
8919 /* For Ada unit, we prefer the linkage name over the name, as
8920 the former contains the exported name, which the user expects
8921 to be able to reference. Ideally, we want the user to be able
8922 to reference this entity using either natural or linkage name,
8923 but we haven't started looking at this enhancement yet. */
8924 const char *linkage_name = dw2_linkage_name (die, cu);
8925
8926 if (linkage_name != NULL)
8927 return linkage_name;
8928 }
8929
8930 /* These are the only languages we know how to qualify names in. */
8931 if (name != NULL
8932 && (lang == language_cplus
8933 || lang == language_fortran || lang == language_d
8934 || lang == language_rust))
8935 {
8936 if (die_needs_namespace (die, cu))
8937 {
8938 const char *prefix;
8939
8940 string_file buf;
8941
8942 prefix = determine_prefix (die, cu);
8943 if (*prefix != '\0')
8944 {
8945 gdb::unique_xmalloc_ptr<char> prefixed_name
8946 (typename_concat (NULL, prefix, name, physname, cu));
8947
8948 buf.puts (prefixed_name.get ());
8949 }
8950 else
8951 buf.puts (name);
8952
8953 /* Template parameters may be specified in the DIE's DW_AT_name, or
8954 as children with DW_TAG_template_type_param or
8955 DW_TAG_value_type_param. If the latter, add them to the name
8956 here. If the name already has template parameters, then
8957 skip this step; some versions of GCC emit both, and
8958 it is more efficient to use the pre-computed name.
8959
8960 Something to keep in mind about this process: it is very
8961 unlikely, or in some cases downright impossible, to produce
8962 something that will match the mangled name of a function.
8963 If the definition of the function has the same debug info,
8964 we should be able to match up with it anyway. But fallbacks
8965 using the minimal symbol, for instance to find a method
8966 implemented in a stripped copy of libstdc++, will not work.
8967 If we do not have debug info for the definition, we will have to
8968 match them up some other way.
8969
8970 When we do name matching there is a related problem with function
8971 templates; two instantiated function templates are allowed to
8972 differ only by their return types, which we do not add here. */
8973
8974 if (lang == language_cplus && strchr (name, '<') == NULL)
8975 {
8976 struct attribute *attr;
8977 struct die_info *child;
8978 int first = 1;
8979
8980 die->building_fullname = 1;
8981
8982 for (child = die->child; child != NULL; child = child->sibling)
8983 {
8984 struct type *type;
8985 LONGEST value;
8986 const gdb_byte *bytes;
8987 struct dwarf2_locexpr_baton *baton;
8988 struct value *v;
8989
8990 if (child->tag != DW_TAG_template_type_param
8991 && child->tag != DW_TAG_template_value_param)
8992 continue;
8993
8994 if (first)
8995 {
8996 buf.puts ("<");
8997 first = 0;
8998 }
8999 else
9000 buf.puts (", ");
9001
9002 attr = dwarf2_attr (child, DW_AT_type, cu);
9003 if (attr == NULL)
9004 {
9005 complaint (_("template parameter missing DW_AT_type"));
9006 buf.puts ("UNKNOWN_TYPE");
9007 continue;
9008 }
9009 type = die_type (child, cu);
9010
9011 if (child->tag == DW_TAG_template_type_param)
9012 {
9013 cu->language_defn->print_type (type, "", &buf, -1, 0,
9015 continue;
9016 }
9017
9018 attr = dwarf2_attr (child, DW_AT_const_value, cu);
9019 if (attr == NULL)
9020 {
9021 complaint (_("template parameter missing "
9022 "DW_AT_const_value"));
9023 buf.puts ("UNKNOWN_VALUE");
9024 continue;
9025 }
9026
9028 &cu->comp_unit_obstack, cu,
9029 &value, &bytes, &baton);
9030
9031 if (type->has_no_signedness ())
9032 /* GDB prints characters as NUMBER 'CHAR'. If that's
9033 changed, this can use value_print instead. */
9034 cu->language_defn->printchar (value, type, &buf);
9035 else
9036 {
9037 struct value_print_options opts;
9038
9039 if (baton != NULL)
9040 v = dwarf2_evaluate_loc_desc (type, NULL,
9041 baton->data,
9042 baton->size,
9043 baton->per_cu,
9044 baton->per_objfile);
9045 else if (bytes != NULL)
9046 {
9047 v = allocate_value (type);
9048 memcpy (value_contents_writeable (v).data (), bytes,
9049 type->length ());
9050 }
9051 else
9053
9054 /* Specify decimal so that we do not depend on
9055 the radix. */
9056 get_formatted_print_options (&opts, 'd');
9057 opts.raw = 1;
9058 value_print (v, &buf, &opts);
9059 release_value (v);
9060 }
9061 }
9062
9063 die->building_fullname = 0;
9064
9065 if (!first)
9066 {
9067 /* Close the argument list, with a space if necessary
9068 (nested templates). */
9069 if (!buf.empty () && buf.string ().back () == '>')
9070 buf.puts (" >");
9071 else
9072 buf.puts (">");
9073 }
9074 }
9075
9076 /* For C++ methods, append formal parameter type
9077 information, if PHYSNAME. */
9078
9079 if (physname && die->tag == DW_TAG_subprogram
9080 && lang == language_cplus)
9081 {
9082 struct type *type = read_type_die (die, cu);
9083
9084 c_type_print_args (type, &buf, 1, lang,
9086
9087 if (lang == language_cplus)
9088 {
9089 /* Assume that an artificial first parameter is
9090 "this", but do not crash if it is not. RealView
9091 marks unnamed (and thus unused) parameters as
9092 artificial; there is no way to differentiate
9093 the two cases. */
9094 if (type->num_fields () > 0
9096 && type->field (0).type ()->code () == TYPE_CODE_PTR
9097 && TYPE_CONST (type->field (0).type ()->target_type ()))
9098 buf.puts (" const");
9099 }
9100 }
9101
9102 const std::string &intermediate_name = buf.string ();
9103
9104 const char *canonical_name
9105 = dwarf2_canonicalize_name (intermediate_name.c_str (), cu,
9106 objfile);
9107
9108 /* If we only computed INTERMEDIATE_NAME, or if
9109 INTERMEDIATE_NAME is already canonical, then we need to
9110 intern it. */
9111 if (canonical_name == NULL || canonical_name == intermediate_name.c_str ())
9112 name = objfile->intern (intermediate_name);
9113 else
9114 name = canonical_name;
9115 }
9116 }
9117
9118 return name;
9119}
9120
9121/* Return the fully qualified name of DIE, based on its DW_AT_name.
9122 If scope qualifiers are appropriate they will be added. The result
9123 will be allocated on the storage_obstack, or NULL if the DIE does
9124 not have a name. NAME may either be from a previous call to
9125 dwarf2_name or NULL.
9126
9127 The output string will be canonicalized (if C++). */
9128
9129static const char *
9130dwarf2_full_name (const char *name, struct die_info *die, struct dwarf2_cu *cu)
9131{
9132 return dwarf2_compute_name (name, die, cu, 0);
9133}
9134
9135/* Construct a physname for the given DIE in CU. NAME may either be
9136 from a previous call to dwarf2_name or NULL. The result will be
9137 allocated on the objfile_objstack or NULL if the DIE does not have a
9138 name.
9139
9140 The output string will be canonicalized (if C++). */
9141
9142static const char *
9143dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
9144{
9145 struct objfile *objfile = cu->per_objfile->objfile;
9146 const char *retval, *mangled = NULL, *canon = NULL;
9147 int need_copy = 1;
9148
9149 /* In this case dwarf2_compute_name is just a shortcut not building anything
9150 on its own. */
9151 if (!die_needs_namespace (die, cu))
9152 return dwarf2_compute_name (name, die, cu, 1);
9153
9154 if (cu->lang () != language_rust)
9155 mangled = dw2_linkage_name (die, cu);
9156
9157 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
9158 has computed. */
9159 gdb::unique_xmalloc_ptr<char> demangled;
9160 if (mangled != NULL)
9161 {
9163 {
9164 /* Do nothing (do not demangle the symbol name). */
9165 }
9166 else
9167 {
9168 /* Use DMGL_RET_DROP for C++ template functions to suppress
9169 their return type. It is easier for GDB users to search
9170 for such functions as `name(params)' than `long name(params)'.
9171 In such case the minimal symbol names do not match the full
9172 symbol names but for template functions there is never a need
9173 to look up their definition from their declaration so
9174 the only disadvantage remains the minimal symbol variant
9175 `long name(params)' does not have the proper inferior type. */
9176 demangled = gdb_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
9177 | DMGL_RET_DROP));
9178 }
9179 if (demangled)
9180 canon = demangled.get ();
9181 else
9182 {
9183 canon = mangled;
9184 need_copy = 0;
9185 }
9186 }
9187
9188 if (canon == NULL || check_physname)
9189 {
9190 const char *physname = dwarf2_compute_name (name, die, cu, 1);
9191
9192 if (canon != NULL && strcmp (physname, canon) != 0)
9193 {
9194 /* It may not mean a bug in GDB. The compiler could also
9195 compute DW_AT_linkage_name incorrectly. But in such case
9196 GDB would need to be bug-to-bug compatible. */
9197
9198 complaint (_("Computed physname <%s> does not match demangled <%s> "
9199 "(from linkage <%s>) - DIE at %s [in module %s]"),
9200 physname, canon, mangled, sect_offset_str (die->sect_off),
9202
9203 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
9204 is available here - over computed PHYSNAME. It is safer
9205 against both buggy GDB and buggy compilers. */
9206
9207 retval = canon;
9208 }
9209 else
9210 {
9211 retval = physname;
9212 need_copy = 0;
9213 }
9214 }
9215 else
9216 retval = canon;
9217
9218 if (need_copy)
9219 retval = objfile->intern (retval);
9220
9221 return retval;
9222}
9223
9224/* Inspect DIE in CU for a namespace alias or a variable with alias
9225 attribute. If one exists, record a new symbol for it.
9226
9227 Returns true if an alias was recorded, false otherwise. */
9228
9229static bool
9230read_alias (struct die_info *die, struct dwarf2_cu *cu)
9231{
9232 struct attribute *attr;
9233
9234 /* If the die does not have a name, this is neither a namespace
9235 alias nor a variable alias. */
9236 attr = dwarf2_attr (die, DW_AT_name, cu);
9237 if (attr != NULL)
9238 {
9239 int num;
9240 struct die_info *d = die;
9241 struct dwarf2_cu *imported_cu = cu;
9242
9243 /* If the compiler has nested DW_AT_imported_declaration DIEs,
9244 keep inspecting DIEs until we hit the underlying import. */
9245#define MAX_NESTED_IMPORTED_DECLARATIONS 100
9246 for (num = 0; num < MAX_NESTED_IMPORTED_DECLARATIONS; ++num)
9247 {
9248 attr = dwarf2_attr (d, DW_AT_import, cu);
9249 if (attr == NULL)
9250 break;
9251
9252 d = follow_die_ref (d, attr, &imported_cu);
9253 if (d->tag != DW_TAG_imported_declaration)
9254 break;
9255 }
9256
9258 {
9259 complaint (_("DIE at %s has too many recursively imported "
9260 "declarations"), sect_offset_str (d->sect_off));
9261 return false;
9262 }
9263
9264 if (attr != NULL)
9265 {
9266 struct type *type;
9267 if (d->tag == DW_TAG_variable)
9268 {
9269 /* This declaration is a C/C++ global variable alias.
9270 Add a symbol for it whose type is the same as the
9271 aliased variable's. */
9272 type = die_type (d, imported_cu);
9273 struct symbol *sym = new_symbol (die, type, cu);
9274 attr = dwarf2_attr (d, DW_AT_location, imported_cu);
9276 if (attr != nullptr)
9277 var_decode_location (attr, sym, cu);
9278 return true;
9279 }
9280 else
9281 {
9282 sect_offset sect_off = attr->get_ref_die_offset ();
9283 type = get_die_type_at_offset (sect_off, cu->per_cu,
9284 cu->per_objfile);
9285 if (type != nullptr && type->code () == TYPE_CODE_NAMESPACE)
9286 {
9287 /* This declaration is a global namespace alias. Add
9288 a symbol for it whose type is the aliased
9289 namespace. */
9290 new_symbol (die, type, cu);
9291 return true;
9292 }
9293 }
9294 }
9295 }
9296 return false;
9297}
9298
9299/* Return the using directives repository (global or local?) to use in the
9300 current context for CU.
9301
9302 For Ada, imported declarations can materialize renamings, which *may* be
9303 global. However it is impossible (for now?) in DWARF to distinguish
9304 "external" imported declarations and "static" ones. As all imported
9305 declarations seem to be static in all other languages, make them all CU-wide
9306 global only in Ada. */
9307
9308static struct using_direct **
9310{
9311 if (cu->lang () == language_ada
9312 && cu->get_builder ()->outermost_context_p ())
9313 return cu->get_builder ()->get_global_using_directives ();
9314 else
9315 return cu->get_builder ()->get_local_using_directives ();
9316}
9317
9318/* Read the import statement specified by the given die and record it. */
9319
9320static void
9322{
9323 struct objfile *objfile = cu->per_objfile->objfile;
9324 struct attribute *import_attr;
9325 struct die_info *imported_die, *child_die;
9326 struct dwarf2_cu *imported_cu;
9327 const char *imported_name;
9328 const char *imported_name_prefix;
9329 const char *canonical_name;
9330 const char *import_alias;
9331 const char *imported_declaration = NULL;
9332 const char *import_prefix;
9333 std::vector<const char *> excludes;
9334
9335 import_attr = dwarf2_attr (die, DW_AT_import, cu);
9336 if (import_attr == NULL)
9337 {
9338 complaint (_("Tag '%s' has no DW_AT_import"),
9339 dwarf_tag_name (die->tag));
9340 return;
9341 }
9342
9343 imported_cu = cu;
9344 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
9345 imported_name = dwarf2_name (imported_die, imported_cu);
9346 if (imported_name == NULL)
9347 {
9348 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
9349
9350 The import in the following code:
9351 namespace A
9352 {
9353 typedef int B;
9354 }
9355
9356 int main ()
9357 {
9358 using A::B;
9359 B b;
9360 return b;
9361 }
9362
9363 ...
9364 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
9365 <52> DW_AT_decl_file : 1
9366 <53> DW_AT_decl_line : 6
9367 <54> DW_AT_import : <0x75>
9368 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
9369 <59> DW_AT_name : B
9370 <5b> DW_AT_decl_file : 1
9371 <5c> DW_AT_decl_line : 2
9372 <5d> DW_AT_type : <0x6e>
9373 ...
9374 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
9375 <76> DW_AT_byte_size : 4
9376 <77> DW_AT_encoding : 5 (signed)
9377
9378 imports the wrong die ( 0x75 instead of 0x58 ).
9379 This case will be ignored until the gcc bug is fixed. */
9380 return;
9381 }
9382
9383 /* Figure out the local name after import. */
9384 import_alias = dwarf2_name (die, cu);
9385
9386 /* Figure out where the statement is being imported to. */
9387 import_prefix = determine_prefix (die, cu);
9388
9389 /* Figure out what the scope of the imported die is and prepend it
9390 to the name of the imported die. */
9391 imported_name_prefix = determine_prefix (imported_die, imported_cu);
9392
9393 if (imported_die->tag != DW_TAG_namespace
9394 && imported_die->tag != DW_TAG_module)
9395 {
9396 imported_declaration = imported_name;
9397 canonical_name = imported_name_prefix;
9398 }
9399 else if (strlen (imported_name_prefix) > 0)
9400 canonical_name = obconcat (&objfile->objfile_obstack,
9401 imported_name_prefix,
9402 (cu->lang () == language_d
9403 ? "."
9404 : "::"),
9405 imported_name, (char *) NULL);
9406 else
9407 canonical_name = imported_name;
9408
9409 if (die->tag == DW_TAG_imported_module
9410 && cu->lang () == language_fortran)
9411 for (child_die = die->child; child_die && child_die->tag;
9412 child_die = child_die->sibling)
9413 {
9414 /* DWARF-4: A Fortran use statement with a “rename list” may be
9415 represented by an imported module entry with an import attribute
9416 referring to the module and owned entries corresponding to those
9417 entities that are renamed as part of being imported. */
9418
9419 if (child_die->tag != DW_TAG_imported_declaration)
9420 {
9421 complaint (_("child DW_TAG_imported_declaration expected "
9422 "- DIE at %s [in module %s]"),
9423 sect_offset_str (child_die->sect_off),
9425 continue;
9426 }
9427
9428 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
9429 if (import_attr == NULL)
9430 {
9431 complaint (_("Tag '%s' has no DW_AT_import"),
9432 dwarf_tag_name (child_die->tag));
9433 continue;
9434 }
9435
9436 imported_cu = cu;
9437 imported_die = follow_die_ref_or_sig (child_die, import_attr,
9438 &imported_cu);
9439 imported_name = dwarf2_name (imported_die, imported_cu);
9440 if (imported_name == NULL)
9441 {
9442 complaint (_("child DW_TAG_imported_declaration has unknown "
9443 "imported name - DIE at %s [in module %s]"),
9444 sect_offset_str (child_die->sect_off),
9446 continue;
9447 }
9448
9449 excludes.push_back (imported_name);
9450
9451 process_die (child_die, cu);
9452 }
9453
9455 import_prefix,
9456 canonical_name,
9457 import_alias,
9458 imported_declaration,
9459 excludes,
9460 0,
9462}
9463
9464/* ICC<14 does not output the required DW_AT_declaration on incomplete
9465 types, but gives them a size of zero. Starting with version 14,
9466 ICC is compatible with GCC. */
9467
9468static bool
9470{
9471 if (!cu->checked_producer)
9472 check_producer (cu);
9473
9474 return cu->producer_is_icc_lt_14;
9475}
9476
9477/* ICC generates a DW_AT_type for C void functions. This was observed on
9478 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
9479 which says that void functions should not have a DW_AT_type. */
9480
9481static bool
9483{
9484 if (!cu->checked_producer)
9485 check_producer (cu);
9486
9487 return cu->producer_is_icc;
9488}
9489
9490/* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9491 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9492 this, it was first present in GCC release 4.3.0. */
9493
9494static bool
9496{
9497 if (!cu->checked_producer)
9498 check_producer (cu);
9499
9500 return cu->producer_is_gcc_lt_4_3;
9501}
9502
9503/* See dwarf2/read.h. */
9504bool
9506{
9507 if (!cu->checked_producer)
9508 check_producer (cu);
9509
9510 return cu->producer_is_clang;
9511}
9512
9513static file_and_directory &
9515{
9516 if (cu->per_cu->fnd != nullptr)
9517 return *cu->per_cu->fnd;
9518
9519 /* Find the filename. Do not use dwarf2_name here, since the filename
9520 is not a source language identifier. */
9521 file_and_directory res (dwarf2_string_attr (die, DW_AT_name, cu),
9522 dwarf2_string_attr (die, DW_AT_comp_dir, cu));
9523
9524 if (res.get_comp_dir () == nullptr
9526 && res.get_name () != nullptr
9527 && IS_ABSOLUTE_PATH (res.get_name ()))
9528 {
9529 res.set_comp_dir (ldirname (res.get_name ()));
9530 res.set_name (make_unique_xstrdup (lbasename (res.get_name ())));
9531 }
9532
9533 cu->per_cu->fnd.reset (new file_and_directory (std::move (res)));
9534 return *cu->per_cu->fnd;
9535}
9536
9537/* Handle DW_AT_stmt_list for a compilation unit.
9538 DIE is the DW_TAG_compile_unit die for CU.
9539 COMP_DIR is the compilation directory. LOWPC is passed to
9540 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9541
9542static void
9544 const file_and_directory &fnd, CORE_ADDR lowpc,
9545 bool have_code) /* ARI: editCase function */
9546{
9548 struct attribute *attr;
9549 hashval_t line_header_local_hash;
9550 void **slot;
9551 int decode_mapping;
9552
9553 gdb_assert (! cu->per_cu->is_debug_types);
9554
9555 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
9556 if (attr == NULL || !attr->form_is_unsigned ())
9557 return;
9558
9559 sect_offset line_offset = (sect_offset) attr->as_unsigned ();
9560
9561 /* The line header hash table is only created if needed (it exists to
9562 prevent redundant reading of the line table for partial_units).
9563 If we're given a partial_unit, we'll need it. If we're given a
9564 compile_unit, then use the line header hash table if it's already
9565 created, but don't create one just yet. */
9566
9567 if (per_objfile->line_header_hash == NULL
9568 && die->tag == DW_TAG_partial_unit)
9569 {
9570 per_objfile->line_header_hash
9571 .reset (htab_create_alloc (127, line_header_hash_voidp,
9573 htab_delete_entry<line_header>,
9574 xcalloc, xfree));
9575 }
9576
9577 line_header line_header_local (line_offset, cu->per_cu->is_dwz);
9578 line_header_local_hash = line_header_hash (&line_header_local);
9579 if (per_objfile->line_header_hash != NULL)
9580 {
9581 slot = htab_find_slot_with_hash (per_objfile->line_header_hash.get (),
9582 &line_header_local,
9583 line_header_local_hash, NO_INSERT);
9584
9585 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9586 is not present in *SLOT (since if there is something in *SLOT then
9587 it will be for a partial_unit). */
9588 if (die->tag == DW_TAG_partial_unit && slot != NULL)
9589 {
9590 gdb_assert (*slot != NULL);
9591 cu->line_header = (struct line_header *) *slot;
9592 return;
9593 }
9594 }
9595
9596 /* dwarf_decode_line_header does not yet provide sufficient information.
9597 We always have to call also dwarf_decode_lines for it. */
9599 fnd.get_comp_dir ());
9600 if (lh == NULL)
9601 return;
9602
9603 cu->line_header = lh.release ();
9604 cu->line_header_die_owner = die;
9605
9606 if (per_objfile->line_header_hash == NULL)
9607 slot = NULL;
9608 else
9609 {
9610 slot = htab_find_slot_with_hash (per_objfile->line_header_hash.get (),
9611 &line_header_local,
9612 line_header_local_hash, INSERT);
9613 gdb_assert (slot != NULL);
9614 }
9615 if (slot != NULL && *slot == NULL)
9616 {
9617 /* This newly decoded line number information unit will be owned
9618 by line_header_hash hash table. */
9619 *slot = cu->line_header;
9620 cu->line_header_die_owner = NULL;
9621 }
9622 else
9623 {
9624 /* We cannot free any current entry in (*slot) as that struct line_header
9625 may be already used by multiple CUs. Create only temporary decoded
9626 line_header for this CU - it may happen at most once for each line
9627 number information unit. And if we're not using line_header_hash
9628 then this is what we want as well. */
9629 gdb_assert (die->tag != DW_TAG_partial_unit);
9630 }
9631 decode_mapping = (die->tag != DW_TAG_partial_unit);
9632 /* The have_code check is here because, if LOWPC and HIGHPC are both 0x0,
9633 then there won't be any interesting code in the CU, but a check later on
9634 (in lnp_state_machine::check_line_address) will fail to properly exclude
9635 an entry that was removed via --gc-sections. */
9636 if (have_code)
9637 dwarf_decode_lines (cu->line_header, cu, lowpc, decode_mapping);
9638}
9639
9640/* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9641
9642static void
9643read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
9644{
9645 dwarf2_per_objfile *per_objfile = cu->per_objfile;
9646 struct objfile *objfile = per_objfile->objfile;
9647 struct gdbarch *gdbarch = objfile->arch ();
9648 CORE_ADDR lowpc = ((CORE_ADDR) -1);
9649 CORE_ADDR highpc = ((CORE_ADDR) 0);
9650 struct attribute *attr;
9651 struct die_info *child_die;
9652 CORE_ADDR baseaddr;
9653
9654 prepare_one_comp_unit (cu, die, cu->lang ());
9655 baseaddr = objfile->text_section_offset ();
9656
9657 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
9658
9659 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9660 from finish_block. */
9661 if (lowpc == ((CORE_ADDR) -1))
9662 lowpc = highpc;
9663 lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
9664
9666
9668 lowpc);
9669
9670 gdb_assert (per_objfile->sym_cu == nullptr);
9671 scoped_restore restore_sym_cu
9672 = make_scoped_restore (&per_objfile->sym_cu, cu);
9673
9674 /* Decode line number information if present. We do this before
9675 processing child DIEs, so that the line header table is available
9676 for DW_AT_decl_file. */
9677 handle_DW_AT_stmt_list (die, cu, fnd, lowpc, lowpc != highpc);
9678
9679 /* Process all dies in compilation unit. */
9680 if (die->child != NULL)
9681 {
9682 child_die = die->child;
9683 while (child_die && child_die->tag)
9684 {
9685 process_die (child_die, cu);
9686 child_die = child_die->sibling;
9687 }
9688 }
9689 per_objfile->sym_cu = nullptr;
9690
9691 /* Decode macro information, if present. Dwarf 2 macro information
9692 refers to information in the line number info statement program
9693 header, so we can only read it if we've read the header
9694 successfully. */
9695 attr = dwarf2_attr (die, DW_AT_macros, cu);
9696 if (attr == NULL)
9697 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
9698 if (attr != nullptr && attr->form_is_unsigned () && cu->line_header)
9699 {
9700 if (dwarf2_attr (die, DW_AT_macro_info, cu))
9701 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
9702
9704 }
9705 else
9706 {
9707 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
9708 if (attr != nullptr && attr->form_is_unsigned () && cu->line_header)
9709 {
9710 unsigned int macro_offset = attr->as_unsigned ();
9711
9712 dwarf_decode_macros (cu, macro_offset, 0);
9713 }
9714 }
9715}
9716
9717void
9719{
9720 struct type_unit_group *tu_group;
9721 int first_time;
9722 struct attribute *attr;
9723 unsigned int i;
9724 struct signatured_type *sig_type;
9725
9726 gdb_assert (per_cu->is_debug_types);
9727 sig_type = (struct signatured_type *) per_cu;
9728
9729 attr = dwarf2_attr (die, DW_AT_stmt_list, this);
9730
9731 /* If we're using .gdb_index (includes -readnow) then
9732 per_cu->type_unit_group may not have been set up yet. */
9733 if (sig_type->type_unit_group == NULL)
9734 sig_type->type_unit_group = get_type_unit_group (this, attr);
9735 tu_group = sig_type->type_unit_group;
9736
9737 /* If we've already processed this stmt_list there's no real need to
9738 do it again, we could fake it and just recreate the part we need
9739 (file name,index -> symtab mapping). If data shows this optimization
9740 is useful we can do it then. */
9741 type_unit_group_unshareable *tug_unshare
9743 first_time = tug_unshare->compunit_symtab == NULL;
9744
9745 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9746 debug info. */
9747 line_header_up lh;
9748 if (attr != NULL && attr->form_is_unsigned ())
9749 {
9750 sect_offset line_offset = (sect_offset) attr->as_unsigned ();
9751 lh = dwarf_decode_line_header (line_offset, this, nullptr);
9752 }
9753 if (lh == NULL)
9754 {
9755 if (first_time)
9756 start_compunit_symtab ("", NULL, 0);
9757 else
9758 {
9759 gdb_assert (tug_unshare->symtabs == NULL);
9760 gdb_assert (m_builder == nullptr);
9761 struct compunit_symtab *cust = tug_unshare->compunit_symtab;
9762 m_builder.reset (new struct buildsym_compunit
9763 (cust->objfile (), "",
9764 cust->dirname (),
9765 cust->language (),
9766 0, cust));
9768 }
9769 return;
9770 }
9771
9772 line_header = lh.release ();
9774
9775 if (first_time)
9776 {
9777 struct compunit_symtab *cust = start_compunit_symtab ("", NULL, 0);
9778
9779 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9780 still initializing it, and our caller (a few levels up)
9781 process_full_type_unit still needs to know if this is the first
9782 time. */
9783
9784 tug_unshare->symtabs
9785 = XOBNEWVEC (&cust->objfile ()->objfile_obstack,
9786 struct symtab *, line_header->file_names_size ());
9787
9788 auto &file_names = line_header->file_names ();
9789 for (i = 0; i < file_names.size (); ++i)
9790 {
9791 file_entry &fe = file_names[i];
9792 dwarf2_start_subfile (this, fe, *line_header);
9794 subfile *sf = b->get_current_subfile ();
9795
9796 if (sf->symtab == nullptr)
9797 {
9798 /* NOTE: start_subfile will recognize when it's been
9799 passed a file it has already seen. So we can't
9800 assume there's a simple mapping from
9801 cu->line_header->file_names to subfiles, plus
9802 cu->line_header->file_names may contain dups. */
9803 const char *name = sf->name.c_str ();
9804 const char *name_for_id = sf->name_for_id.c_str ();
9805 sf->symtab = allocate_symtab (cust, name, name_for_id);
9806 }
9807
9808 fe.symtab = b->get_current_subfile ()->symtab;
9809 tug_unshare->symtabs[i] = fe.symtab;
9810 }
9811 }
9812 else
9813 {
9814 gdb_assert (m_builder == nullptr);
9815 struct compunit_symtab *cust = tug_unshare->compunit_symtab;
9816 m_builder.reset (new struct buildsym_compunit
9817 (cust->objfile (), "",
9818 cust->dirname (),
9819 cust->language (),
9820 0, cust));
9822
9823 auto &file_names = line_header->file_names ();
9824 for (i = 0; i < file_names.size (); ++i)
9825 {
9826 file_entry &fe = file_names[i];
9827 fe.symtab = tug_unshare->symtabs[i];
9828 }
9829 }
9830
9831 /* The main symtab is allocated last. Type units don't have DW_AT_name
9832 so they don't have a "real" (so to speak) symtab anyway.
9833 There is later code that will assign the main symtab to all symbols
9834 that don't have one. We need to handle the case of a symbol with a
9835 missing symtab (DW_AT_decl_file) anyway. */
9836}
9837
9838/* Process DW_TAG_type_unit.
9839 For TUs we want to skip the first top level sibling if it's not the
9840 actual type being defined by this TU. In this case the first top
9841 level sibling is there to provide context only. */
9842
9843static void
9844read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
9845{
9846 struct die_info *child_die;
9847
9849
9850 /* Initialize (or reinitialize) the machinery for building symtabs.
9851 We do this before processing child DIEs, so that the line header table
9852 is available for DW_AT_decl_file. */
9853 cu->setup_type_unit_groups (die);
9854
9855 if (die->child != NULL)
9856 {
9857 child_die = die->child;
9858 while (child_die && child_die->tag)
9859 {
9860 process_die (child_die, cu);
9861 child_die = child_die->sibling;
9862 }
9863 }
9864}
9865␌
9866/* DWO/DWP files.
9867
9868 http://gcc.gnu.org/wiki/DebugFission
9869 http://gcc.gnu.org/wiki/DebugFissionDWP
9870
9871 To simplify handling of both DWO files ("object" files with the DWARF info)
9872 and DWP files (a file with the DWOs packaged up into one file), we treat
9873 DWP files as having a collection of virtual DWO files. */
9874
9875static hashval_t
9876hash_dwo_file (const void *item)
9877{
9878 const struct dwo_file *dwo_file = (const struct dwo_file *) item;
9879 hashval_t hash;
9880
9881 hash = htab_hash_string (dwo_file->dwo_name);
9882 if (dwo_file->comp_dir != NULL)
9883 hash += htab_hash_string (dwo_file->comp_dir);
9884 return hash;
9885}
9886
9887static int
9888eq_dwo_file (const void *item_lhs, const void *item_rhs)
9889{
9890 const struct dwo_file *lhs = (const struct dwo_file *) item_lhs;
9891 const struct dwo_file *rhs = (const struct dwo_file *) item_rhs;
9892
9893 if (strcmp (lhs->dwo_name, rhs->dwo_name) != 0)
9894 return 0;
9895 if (lhs->comp_dir == NULL || rhs->comp_dir == NULL)
9896 return lhs->comp_dir == rhs->comp_dir;
9897 return strcmp (lhs->comp_dir, rhs->comp_dir) == 0;
9898}
9899
9900/* Allocate a hash table for DWO files. */
9901
9902static htab_up
9904{
9905 return htab_up (htab_create_alloc (41,
9908 htab_delete_entry<dwo_file>,
9909 xcalloc, xfree));
9910}
9911
9912/* Lookup DWO file DWO_NAME. */
9913
9914static void **
9916 const char *dwo_name,
9917 const char *comp_dir)
9918{
9919 struct dwo_file find_entry;
9920 void **slot;
9921
9922 if (per_objfile->per_bfd->dwo_files == NULL)
9924
9925 find_entry.dwo_name = dwo_name;
9926 find_entry.comp_dir = comp_dir;
9927 slot = htab_find_slot (per_objfile->per_bfd->dwo_files.get (), &find_entry,
9928 INSERT);
9929
9930 return slot;
9931}
9932
9933static hashval_t
9934hash_dwo_unit (const void *item)
9935{
9936 const struct dwo_unit *dwo_unit = (const struct dwo_unit *) item;
9937
9938 /* This drops the top 32 bits of the id, but is ok for a hash. */
9939 return dwo_unit->signature;
9940}
9941
9942static int
9943eq_dwo_unit (const void *item_lhs, const void *item_rhs)
9944{
9945 const struct dwo_unit *lhs = (const struct dwo_unit *) item_lhs;
9946 const struct dwo_unit *rhs = (const struct dwo_unit *) item_rhs;
9947
9948 /* The signature is assumed to be unique within the DWO file.
9949 So while object file CU dwo_id's always have the value zero,
9950 that's OK, assuming each object file DWO file has only one CU,
9951 and that's the rule for now. */
9952 return lhs->signature == rhs->signature;
9953}
9954
9955/* Allocate a hash table for DWO CUs,TUs.
9956 There is one of these tables for each of CUs,TUs for each DWO file. */
9957
9958static htab_up
9960{
9961 /* Start out with a pretty small number.
9962 Generally DWO files contain only one CU and maybe some TUs. */
9963 return htab_up (htab_create_alloc (3,
9966 NULL, xcalloc, xfree));
9967}
9968
9969/* die_reader_func for create_dwo_cu. */
9970
9971static void
9973 const gdb_byte *info_ptr,
9974 struct die_info *comp_unit_die,
9975 struct dwo_file *dwo_file,
9976 struct dwo_unit *dwo_unit)
9977{
9978 struct dwarf2_cu *cu = reader->cu;
9979 sect_offset sect_off = cu->per_cu->sect_off;
9981
9982 gdb::optional<ULONGEST> signature = lookup_dwo_id (cu, comp_unit_die);
9983 if (!signature.has_value ())
9984 {
9985 complaint (_("Dwarf Error: debug entry at offset %s is missing"
9986 " its dwo_id [in module %s]"),
9987 sect_offset_str (sect_off), dwo_file->dwo_name);
9988 return;
9989 }
9990
9992 dwo_unit->signature = *signature;
9994 dwo_unit->sect_off = sect_off;
9995 dwo_unit->length = cu->per_cu->length ();
9996
9997 dwarf_read_debug_printf (" offset %s, dwo_id %s",
9998 sect_offset_str (sect_off),
9999 hex_string (dwo_unit->signature));
10000}
10001
10002/* Create the dwo_units for the CUs in a DWO_FILE.
10003 Note: This function processes DWO files only, not DWP files. */
10004
10005static void
10007 dwarf2_cu *cu, struct dwo_file &dwo_file,
10008 dwarf2_section_info &section, htab_up &cus_htab)
10009{
10010 struct objfile *objfile = per_objfile->objfile;
10011 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
10012 const gdb_byte *info_ptr, *end_ptr;
10013
10014 section.read (objfile);
10015 info_ptr = section.buffer;
10016
10017 if (info_ptr == NULL)
10018 return;
10019
10020 dwarf_read_debug_printf ("Reading %s for %s:",
10021 section.get_name (),
10022 section.get_file_name ());
10023
10024 end_ptr = info_ptr + section.size;
10025 while (info_ptr < end_ptr)
10026 {
10027 struct dwarf2_per_cu_data per_cu;
10028 struct dwo_unit read_unit {};
10029 struct dwo_unit *dwo_unit;
10030 void **slot;
10031 sect_offset sect_off = (sect_offset) (info_ptr - section.buffer);
10032
10033 per_cu.per_bfd = per_bfd;
10034 per_cu.is_debug_types = 0;
10035 per_cu.sect_off = sect_offset (info_ptr - section.buffer);
10036 per_cu.section = &section;
10037
10038 cutu_reader reader (&per_cu, per_objfile, cu, &dwo_file);
10039 if (!reader.dummy_p)
10040 create_dwo_cu_reader (&reader, reader.info_ptr, reader.comp_unit_die,
10041 &dwo_file, &read_unit);
10042 info_ptr += per_cu.length ();
10043
10044 // If the unit could not be parsed, skip it.
10045 if (read_unit.dwo_file == NULL)
10046 continue;
10047
10048 if (cus_htab == NULL)
10049 cus_htab = allocate_dwo_unit_table ();
10050
10051 dwo_unit = OBSTACK_ZALLOC (&per_bfd->obstack,
10052 struct dwo_unit);
10053 *dwo_unit = read_unit;
10054 slot = htab_find_slot (cus_htab.get (), dwo_unit, INSERT);
10055 gdb_assert (slot != NULL);
10056 if (*slot != NULL)
10057 {
10058 const struct dwo_unit *dup_cu = (const struct dwo_unit *)*slot;
10059 sect_offset dup_sect_off = dup_cu->sect_off;
10060
10061 complaint (_("debug cu entry at offset %s is duplicate to"
10062 " the entry at offset %s, signature %s"),
10063 sect_offset_str (sect_off), sect_offset_str (dup_sect_off),
10064 hex_string (dwo_unit->signature));
10065 }
10066 *slot = (void *)dwo_unit;
10067 }
10068}
10069
10070/* DWP file .debug_{cu,tu}_index section format:
10071 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10072 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
10073
10074 DWP Versions 1 & 2 are older, pre-standard format versions. The first
10075 officially standard DWP format was published with DWARF v5 and is called
10076 Version 5. There are no versions 3 or 4.
10077
10078 DWP Version 1:
10079
10080 Both index sections have the same format, and serve to map a 64-bit
10081 signature to a set of section numbers. Each section begins with a header,
10082 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10083 indexes, and a pool of 32-bit section numbers. The index sections will be
10084 aligned at 8-byte boundaries in the file.
10085
10086 The index section header consists of:
10087
10088 V, 32 bit version number
10089 -, 32 bits unused
10090 N, 32 bit number of compilation units or type units in the index
10091 M, 32 bit number of slots in the hash table
10092
10093 Numbers are recorded using the byte order of the application binary.
10094
10095 The hash table begins at offset 16 in the section, and consists of an array
10096 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
10097 order of the application binary). Unused slots in the hash table are 0.
10098 (We rely on the extreme unlikeliness of a signature being exactly 0.)
10099
10100 The parallel table begins immediately after the hash table
10101 (at offset 16 + 8 * M from the beginning of the section), and consists of an
10102 array of 32-bit indexes (using the byte order of the application binary),
10103 corresponding 1-1 with slots in the hash table. Each entry in the parallel
10104 table contains a 32-bit index into the pool of section numbers. For unused
10105 hash table slots, the corresponding entry in the parallel table will be 0.
10106
10107 The pool of section numbers begins immediately following the hash table
10108 (at offset 16 + 12 * M from the beginning of the section). The pool of
10109 section numbers consists of an array of 32-bit words (using the byte order
10110 of the application binary). Each item in the array is indexed starting
10111 from 0. The hash table entry provides the index of the first section
10112 number in the set. Additional section numbers in the set follow, and the
10113 set is terminated by a 0 entry (section number 0 is not used in ELF).
10114
10115 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
10116 section must be the first entry in the set, and the .debug_abbrev.dwo must
10117 be the second entry. Other members of the set may follow in any order.
10118
10119 ---
10120
10121 DWP Versions 2 and 5:
10122
10123 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
10124 and the entries in the index tables are now offsets into these sections.
10125 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
10126 section.
10127
10128 Index Section Contents:
10129 Header
10130 Hash Table of Signatures dwp_hash_table.hash_table
10131 Parallel Table of Indices dwp_hash_table.unit_table
10132 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
10133 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
10134
10135 The index section header consists of:
10136
10137 V, 32 bit version number
10138 L, 32 bit number of columns in the table of section offsets
10139 N, 32 bit number of compilation units or type units in the index
10140 M, 32 bit number of slots in the hash table
10141
10142 Numbers are recorded using the byte order of the application binary.
10143
10144 The hash table has the same format as version 1.
10145 The parallel table of indices has the same format as version 1,
10146 except that the entries are origin-1 indices into the table of sections
10147 offsets and the table of section sizes.
10148
10149 The table of offsets begins immediately following the parallel table
10150 (at offset 16 + 12 * M from the beginning of the section). The table is
10151 a two-dimensional array of 32-bit words (using the byte order of the
10152 application binary), with L columns and N+1 rows, in row-major order.
10153 Each row in the array is indexed starting from 0. The first row provides
10154 a key to the remaining rows: each column in this row provides an identifier
10155 for a debug section, and the offsets in the same column of subsequent rows
10156 refer to that section. The section identifiers for Version 2 are:
10157
10158 DW_SECT_INFO 1 .debug_info.dwo
10159 DW_SECT_TYPES 2 .debug_types.dwo
10160 DW_SECT_ABBREV 3 .debug_abbrev.dwo
10161 DW_SECT_LINE 4 .debug_line.dwo
10162 DW_SECT_LOC 5 .debug_loc.dwo
10163 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
10164 DW_SECT_MACINFO 7 .debug_macinfo.dwo
10165 DW_SECT_MACRO 8 .debug_macro.dwo
10166
10167 The section identifiers for Version 5 are:
10168
10169 DW_SECT_INFO_V5 1 .debug_info.dwo
10170 DW_SECT_RESERVED_V5 2 --
10171 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
10172 DW_SECT_LINE_V5 4 .debug_line.dwo
10173 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
10174 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
10175 DW_SECT_MACRO_V5 7 .debug_macro.dwo
10176 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
10177
10178 The offsets provided by the CU and TU index sections are the base offsets
10179 for the contributions made by each CU or TU to the corresponding section
10180 in the package file. Each CU and TU header contains an abbrev_offset
10181 field, used to find the abbreviations table for that CU or TU within the
10182 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
10183 be interpreted as relative to the base offset given in the index section.
10184 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
10185 should be interpreted as relative to the base offset for .debug_line.dwo,
10186 and offsets into other debug sections obtained from DWARF attributes should
10187 also be interpreted as relative to the corresponding base offset.
10188
10189 The table of sizes begins immediately following the table of offsets.
10190 Like the table of offsets, it is a two-dimensional array of 32-bit words,
10191 with L columns and N rows, in row-major order. Each row in the array is
10192 indexed starting from 1 (row 0 is shared by the two tables).
10193
10194 ---
10195
10196 Hash table lookup is handled the same in version 1 and 2:
10197
10198 We assume that N and M will not exceed 2^32 - 1.
10199 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
10200
10201 Given a 64-bit compilation unit signature or a type signature S, an entry
10202 in the hash table is located as follows:
10203
10204 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
10205 the low-order k bits all set to 1.
10206
10207 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
10208
10209 3) If the hash table entry at index H matches the signature, use that
10210 entry. If the hash table entry at index H is unused (all zeroes),
10211 terminate the search: the signature is not present in the table.
10212
10213 4) Let H = (H + H') modulo M. Repeat at Step 3.
10214
10215 Because M > N and H' and M are relatively prime, the search is guaranteed
10216 to stop at an unused slot or find the match. */
10217
10218/* Create a hash table to map DWO IDs to their CU/TU entry in
10219 .debug_{info,types}.dwo in DWP_FILE.
10220 Returns NULL if there isn't one.
10221 Note: This function processes DWP files only, not DWO files. */
10222
10223static struct dwp_hash_table *
10225 struct dwp_file *dwp_file, int is_debug_types)
10226{
10227 struct objfile *objfile = per_objfile->objfile;
10228 bfd *dbfd = dwp_file->dbfd.get ();
10229 const gdb_byte *index_ptr, *index_end;
10230 struct dwarf2_section_info *index;
10231 uint32_t version, nr_columns, nr_units, nr_slots;
10232 struct dwp_hash_table *htab;
10233
10234 if (is_debug_types)
10235 index = &dwp_file->sections.tu_index;
10236 else
10237 index = &dwp_file->sections.cu_index;
10238
10239 if (index->empty ())
10240 return NULL;
10241 index->read (objfile);
10242
10243 index_ptr = index->buffer;
10244 index_end = index_ptr + index->size;
10245
10246 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
10247 For now it's safe to just read 4 bytes (particularly as it's difficult to
10248 tell if you're dealing with Version 5 before you've read the version). */
10249 version = read_4_bytes (dbfd, index_ptr);
10250 index_ptr += 4;
10251 if (version == 2 || version == 5)
10252 nr_columns = read_4_bytes (dbfd, index_ptr);
10253 else
10254 nr_columns = 0;
10255 index_ptr += 4;
10256 nr_units = read_4_bytes (dbfd, index_ptr);
10257 index_ptr += 4;
10258 nr_slots = read_4_bytes (dbfd, index_ptr);
10259 index_ptr += 4;
10260
10261 if (version != 1 && version != 2 && version != 5)
10262 {
10263 error (_("Dwarf Error: unsupported DWP file version (%s)"
10264 " [in module %s]"),
10265 pulongest (version), dwp_file->name);
10266 }
10267 if (nr_slots != (nr_slots & -nr_slots))
10268 {
10269 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
10270 " is not power of 2 [in module %s]"),
10271 pulongest (nr_slots), dwp_file->name);
10272 }
10273
10274 htab = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwp_hash_table);
10275 htab->version = version;
10276 htab->nr_columns = nr_columns;
10277 htab->nr_units = nr_units;
10278 htab->nr_slots = nr_slots;
10279 htab->hash_table = index_ptr;
10280 htab->unit_table = htab->hash_table + sizeof (uint64_t) * nr_slots;
10281
10282 /* Exit early if the table is empty. */
10283 if (nr_slots == 0 || nr_units == 0
10284 || (version == 2 && nr_columns == 0)
10285 || (version == 5 && nr_columns == 0))
10286 {
10287 /* All must be zero. */
10288 if (nr_slots != 0 || nr_units != 0
10289 || (version == 2 && nr_columns != 0)
10290 || (version == 5 && nr_columns != 0))
10291 {
10292 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
10293 " all zero [in modules %s]"),
10294 dwp_file->name);
10295 }
10296 return htab;
10297 }
10298
10299 if (version == 1)
10300 {
10301 htab->section_pool.v1.indices =
10302 htab->unit_table + sizeof (uint32_t) * nr_slots;
10303 /* It's harder to decide whether the section is too small in v1.
10304 V1 is deprecated anyway so we punt. */
10305 }
10306 else if (version == 2)
10307 {
10308 const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots;
10309 int *ids = htab->section_pool.v2.section_ids;
10310 size_t sizeof_ids = sizeof (htab->section_pool.v2.section_ids);
10311 /* Reverse map for error checking. */
10312 int ids_seen[DW_SECT_MAX + 1];
10313 int i;
10314
10315 if (nr_columns < 2)
10316 {
10317 error (_("Dwarf Error: bad DWP hash table, too few columns"
10318 " in section table [in module %s]"),
10319 dwp_file->name);
10320 }
10322 {
10323 error (_("Dwarf Error: bad DWP hash table, too many columns"
10324 " in section table [in module %s]"),
10325 dwp_file->name);
10326 }
10327 memset (ids, 255, sizeof_ids);
10328 memset (ids_seen, 255, sizeof (ids_seen));
10329 for (i = 0; i < nr_columns; ++i)
10330 {
10331 int id = read_4_bytes (dbfd, ids_ptr + i * sizeof (uint32_t));
10332
10333 if (id < DW_SECT_MIN || id > DW_SECT_MAX)
10334 {
10335 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
10336 " in section table [in module %s]"),
10337 id, dwp_file->name);
10338 }
10339 if (ids_seen[id] != -1)
10340 {
10341 error (_("Dwarf Error: bad DWP hash table, duplicate section"
10342 " id %d in section table [in module %s]"),
10343 id, dwp_file->name);
10344 }
10345 ids_seen[id] = i;
10346 ids[i] = id;
10347 }
10348 /* Must have exactly one info or types section. */
10349 if (((ids_seen[DW_SECT_INFO] != -1)
10350 + (ids_seen[DW_SECT_TYPES] != -1))
10351 != 1)
10352 {
10353 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
10354 " DWO info/types section [in module %s]"),
10355 dwp_file->name);
10356 }
10357 /* Must have an abbrev section. */
10358 if (ids_seen[DW_SECT_ABBREV] == -1)
10359 {
10360 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
10361 " section [in module %s]"),
10362 dwp_file->name);
10363 }
10364 htab->section_pool.v2.offsets = ids_ptr + sizeof (uint32_t) * nr_columns;
10365 htab->section_pool.v2.sizes =
10366 htab->section_pool.v2.offsets + (sizeof (uint32_t)
10367 * nr_units * nr_columns);
10368 if ((htab->section_pool.v2.sizes + (sizeof (uint32_t)
10369 * nr_units * nr_columns))
10370 > index_end)
10371 {
10372 error (_("Dwarf Error: DWP index section is corrupt (too small)"
10373 " [in module %s]"),
10374 dwp_file->name);
10375 }
10376 }
10377 else /* version == 5 */
10378 {
10379 const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots;
10380 int *ids = htab->section_pool.v5.section_ids;
10381 size_t sizeof_ids = sizeof (htab->section_pool.v5.section_ids);
10382 /* Reverse map for error checking. */
10383 int ids_seen[DW_SECT_MAX_V5 + 1];
10384
10385 if (nr_columns < 2)
10386 {
10387 error (_("Dwarf Error: bad DWP hash table, too few columns"
10388 " in section table [in module %s]"),
10389 dwp_file->name);
10390 }
10392 {
10393 error (_("Dwarf Error: bad DWP hash table, too many columns"
10394 " in section table [in module %s]"),
10395 dwp_file->name);
10396 }
10397 memset (ids, 255, sizeof_ids);
10398 memset (ids_seen, 255, sizeof (ids_seen));
10399 for (int i = 0; i < nr_columns; ++i)
10400 {
10401 int id = read_4_bytes (dbfd, ids_ptr + i * sizeof (uint32_t));
10402
10403 if (id < DW_SECT_MIN || id > DW_SECT_MAX_V5)
10404 {
10405 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
10406 " in section table [in module %s]"),
10407 id, dwp_file->name);
10408 }
10409 if (ids_seen[id] != -1)
10410 {
10411 error (_("Dwarf Error: bad DWP hash table, duplicate section"
10412 " id %d in section table [in module %s]"),
10413 id, dwp_file->name);
10414 }
10415 ids_seen[id] = i;
10416 ids[i] = id;
10417 }
10418 /* Must have seen an info section. */
10419 if (ids_seen[DW_SECT_INFO_V5] == -1)
10420 {
10421 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
10422 " DWO info/types section [in module %s]"),
10423 dwp_file->name);
10424 }
10425 /* Must have an abbrev section. */
10426 if (ids_seen[DW_SECT_ABBREV_V5] == -1)
10427 {
10428 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
10429 " section [in module %s]"),
10430 dwp_file->name);
10431 }
10432 htab->section_pool.v5.offsets = ids_ptr + sizeof (uint32_t) * nr_columns;
10433 htab->section_pool.v5.sizes
10434 = htab->section_pool.v5.offsets + (sizeof (uint32_t)
10435 * nr_units * nr_columns);
10436 if ((htab->section_pool.v5.sizes + (sizeof (uint32_t)
10437 * nr_units * nr_columns))
10438 > index_end)
10439 {
10440 error (_("Dwarf Error: DWP index section is corrupt (too small)"
10441 " [in module %s]"),
10442 dwp_file->name);
10443 }
10444 }
10445
10446 return htab;
10447}
10448
10449/* Update SECTIONS with the data from SECTP.
10450
10451 This function is like the other "locate" section routines, but in
10452 this context the sections to read comes from the DWP V1 hash table,
10453 not the full ELF section table.
10454
10455 The result is non-zero for success, or zero if an error was found. */
10456
10457static int
10459 struct virtual_v1_dwo_sections *sections)
10460{
10461 const struct dwop_section_names *names = &dwop_section_names;
10462
10463 if (names->abbrev_dwo.matches (sectp->name))
10464 {
10465 /* There can be only one. */
10466 if (sections->abbrev.s.section != NULL)
10467 return 0;
10468 sections->abbrev.s.section = sectp;
10469 sections->abbrev.size = bfd_section_size (sectp);
10470 }
10471 else if (names->info_dwo.matches (sectp->name)
10472 || names->types_dwo.matches (sectp->name))
10473 {
10474 /* There can be only one. */
10475 if (sections->info_or_types.s.section != NULL)
10476 return 0;
10477 sections->info_or_types.s.section = sectp;
10478 sections->info_or_types.size = bfd_section_size (sectp);
10479 }
10480 else if (names->line_dwo.matches (sectp->name))
10481 {
10482 /* There can be only one. */
10483 if (sections->line.s.section != NULL)
10484 return 0;
10485 sections->line.s.section = sectp;
10486 sections->line.size = bfd_section_size (sectp);
10487 }
10488 else if (names->loc_dwo.matches (sectp->name))
10489 {
10490 /* There can be only one. */
10491 if (sections->loc.s.section != NULL)
10492 return 0;
10493 sections->loc.s.section = sectp;
10494 sections->loc.size = bfd_section_size (sectp);
10495 }
10496 else if (names->macinfo_dwo.matches (sectp->name))
10497 {
10498 /* There can be only one. */
10499 if (sections->macinfo.s.section != NULL)
10500 return 0;
10501 sections->macinfo.s.section = sectp;
10502 sections->macinfo.size = bfd_section_size (sectp);
10503 }
10504 else if (names->macro_dwo.matches (sectp->name))
10505 {
10506 /* There can be only one. */
10507 if (sections->macro.s.section != NULL)
10508 return 0;
10509 sections->macro.s.section = sectp;
10510 sections->macro.size = bfd_section_size (sectp);
10511 }
10512 else if (names->str_offsets_dwo.matches (sectp->name))
10513 {
10514 /* There can be only one. */
10515 if (sections->str_offsets.s.section != NULL)
10516 return 0;
10517 sections->str_offsets.s.section = sectp;
10518 sections->str_offsets.size = bfd_section_size (sectp);
10519 }
10520 else
10521 {
10522 /* No other kind of section is valid. */
10523 return 0;
10524 }
10525
10526 return 1;
10527}
10528
10529/* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10530 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10531 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10532 This is for DWP version 1 files. */
10533
10534static struct dwo_unit *
10536 struct dwp_file *dwp_file,
10537 uint32_t unit_index,
10538 const char *comp_dir,
10539 ULONGEST signature, int is_debug_types)
10540{
10541 const struct dwp_hash_table *dwp_htab =
10542 is_debug_types ? dwp_file->tus : dwp_file->cus;
10543 bfd *dbfd = dwp_file->dbfd.get ();
10544 const char *kind = is_debug_types ? "TU" : "CU";
10545 struct dwo_file *dwo_file;
10546 struct dwo_unit *dwo_unit;
10547 struct virtual_v1_dwo_sections sections;
10548 void **dwo_file_slot;
10549 int i;
10550
10551 gdb_assert (dwp_file->version == 1);
10552
10553 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
10554 kind, pulongest (unit_index), hex_string (signature),
10555 dwp_file->name);
10556
10557 /* Fetch the sections of this DWO unit.
10558 Put a limit on the number of sections we look for so that bad data
10559 doesn't cause us to loop forever. */
10560
10561#define MAX_NR_V1_DWO_SECTIONS \
10562 (1 /* .debug_info or .debug_types */ \
10563 + 1 /* .debug_abbrev */ \
10564 + 1 /* .debug_line */ \
10565 + 1 /* .debug_loc */ \
10566 + 1 /* .debug_str_offsets */ \
10567 + 1 /* .debug_macro or .debug_macinfo */ \
10568 + 1 /* trailing zero */)
10569
10570 memset (&sections, 0, sizeof (sections));
10571
10572 for (i = 0; i < MAX_NR_V1_DWO_SECTIONS; ++i)
10573 {
10574 asection *sectp;
10575 uint32_t section_nr =
10576 read_4_bytes (dbfd,
10577 dwp_htab->section_pool.v1.indices
10578 + (unit_index + i) * sizeof (uint32_t));
10579
10580 if (section_nr == 0)
10581 break;
10582 if (section_nr >= dwp_file->num_sections)
10583 {
10584 error (_("Dwarf Error: bad DWP hash table, section number too large"
10585 " [in module %s]"),
10586 dwp_file->name);
10587 }
10588
10589 sectp = dwp_file->elf_sections[section_nr];
10590 if (! locate_v1_virtual_dwo_sections (sectp, &sections))
10591 {
10592 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10593 " [in module %s]"),
10594 dwp_file->name);
10595 }
10596 }
10597
10598 if (i < 2
10599 || sections.info_or_types.empty ()
10600 || sections.abbrev.empty ())
10601 {
10602 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10603 " [in module %s]"),
10604 dwp_file->name);
10605 }
10606 if (i == MAX_NR_V1_DWO_SECTIONS)
10607 {
10608 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10609 " [in module %s]"),
10610 dwp_file->name);
10611 }
10612
10613 /* It's easier for the rest of the code if we fake a struct dwo_file and
10614 have dwo_unit "live" in that. At least for now.
10615
10616 The DWP file can be made up of a random collection of CUs and TUs.
10617 However, for each CU + set of TUs that came from the same original DWO
10618 file, we can combine them back into a virtual DWO file to save space
10619 (fewer struct dwo_file objects to allocate). Remember that for really
10620 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10621
10622 std::string virtual_dwo_name =
10623 string_printf ("virtual-dwo/%d-%d-%d-%d",
10624 sections.abbrev.get_id (),
10625 sections.line.get_id (),
10626 sections.loc.get_id (),
10627 sections.str_offsets.get_id ());
10628 /* Can we use an existing virtual DWO file? */
10629 dwo_file_slot = lookup_dwo_file_slot (per_objfile, virtual_dwo_name.c_str (),
10630 comp_dir);
10631 /* Create one if necessary. */
10632 if (*dwo_file_slot == NULL)
10633 {
10634 dwarf_read_debug_printf ("Creating virtual DWO: %s",
10635 virtual_dwo_name.c_str ());
10636
10637 dwo_file = new struct dwo_file;
10638 dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name);
10640 dwo_file->sections.abbrev = sections.abbrev;
10641 dwo_file->sections.line = sections.line;
10642 dwo_file->sections.loc = sections.loc;
10643 dwo_file->sections.macinfo = sections.macinfo;
10644 dwo_file->sections.macro = sections.macro;
10645 dwo_file->sections.str_offsets = sections.str_offsets;
10646 /* The "str" section is global to the entire DWP file. */
10647 dwo_file->sections.str = dwp_file->sections.str;
10648 /* The info or types section is assigned below to dwo_unit,
10649 there's no need to record it in dwo_file.
10650 Also, we can't simply record type sections in dwo_file because
10651 we record a pointer into the vector in dwo_unit. As we collect more
10652 types we'll grow the vector and eventually have to reallocate space
10653 for it, invalidating all copies of pointers into the previous
10654 contents. */
10655 *dwo_file_slot = dwo_file;
10656 }
10657 else
10658 {
10659 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
10660 virtual_dwo_name.c_str ());
10661
10662 dwo_file = (struct dwo_file *) *dwo_file_slot;
10663 }
10664
10665 dwo_unit = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwo_unit);
10667 dwo_unit->signature = signature;
10668 dwo_unit->section =
10669 XOBNEW (&per_objfile->per_bfd->obstack, struct dwarf2_section_info);
10670 *dwo_unit->section = sections.info_or_types;
10671 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10672
10673 return dwo_unit;
10674}
10675
10676/* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
10677 simplify them. Given a pointer to the containing section SECTION, and
10678 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
10679 virtual section of just that piece. */
10680
10681static struct dwarf2_section_info
10684 bfd_size_type offset, bfd_size_type size)
10685{
10686 struct dwarf2_section_info result;
10687 asection *sectp;
10688
10689 gdb_assert (section != NULL);
10690 gdb_assert (!section->is_virtual);
10691
10692 memset (&result, 0, sizeof (result));
10693 result.s.containing_section = section;
10694 result.is_virtual = true;
10695
10696 if (size == 0)
10697 return result;
10698
10699 sectp = section->get_bfd_section ();
10700
10701 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10702 bounds of the real section. This is a pretty-rare event, so just
10703 flag an error (easier) instead of a warning and trying to cope. */
10704 if (sectp == NULL
10705 || offset + size > bfd_section_size (sectp))
10706 {
10707 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
10708 " in section %s [in module %s]"),
10709 sectp ? bfd_section_name (sectp) : "<unknown>",
10710 objfile_name (per_objfile->objfile));
10711 }
10712
10713 result.virtual_offset = offset;
10714 result.size = size;
10715 return result;
10716}
10717
10718/* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10719 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10720 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10721 This is for DWP version 2 files. */
10722
10723static struct dwo_unit *
10725 struct dwp_file *dwp_file,
10726 uint32_t unit_index,
10727 const char *comp_dir,
10728 ULONGEST signature, int is_debug_types)
10729{
10730 const struct dwp_hash_table *dwp_htab =
10731 is_debug_types ? dwp_file->tus : dwp_file->cus;
10732 bfd *dbfd = dwp_file->dbfd.get ();
10733 const char *kind = is_debug_types ? "TU" : "CU";
10734 struct dwo_file *dwo_file;
10735 struct dwo_unit *dwo_unit;
10736 struct virtual_v2_or_v5_dwo_sections sections;
10737 void **dwo_file_slot;
10738 int i;
10739
10740 gdb_assert (dwp_file->version == 2);
10741
10742 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
10743 kind, pulongest (unit_index), hex_string (signature),
10744 dwp_file->name);
10745
10746 /* Fetch the section offsets of this DWO unit. */
10747
10748 memset (&sections, 0, sizeof (sections));
10749
10750 for (i = 0; i < dwp_htab->nr_columns; ++i)
10751 {
10752 uint32_t offset = read_4_bytes (dbfd,
10753 dwp_htab->section_pool.v2.offsets
10754 + (((unit_index - 1) * dwp_htab->nr_columns
10755 + i)
10756 * sizeof (uint32_t)));
10757 uint32_t size = read_4_bytes (dbfd,
10758 dwp_htab->section_pool.v2.sizes
10759 + (((unit_index - 1) * dwp_htab->nr_columns
10760 + i)
10761 * sizeof (uint32_t)));
10762
10763 switch (dwp_htab->section_pool.v2.section_ids[i])
10764 {
10765 case DW_SECT_INFO:
10766 case DW_SECT_TYPES:
10767 sections.info_or_types_offset = offset;
10768 sections.info_or_types_size = size;
10769 break;
10770 case DW_SECT_ABBREV:
10771 sections.abbrev_offset = offset;
10772 sections.abbrev_size = size;
10773 break;
10774 case DW_SECT_LINE:
10775 sections.line_offset = offset;
10776 sections.line_size = size;
10777 break;
10778 case DW_SECT_LOC:
10779 sections.loc_offset = offset;
10780 sections.loc_size = size;
10781 break;
10782 case DW_SECT_STR_OFFSETS:
10783 sections.str_offsets_offset = offset;
10784 sections.str_offsets_size = size;
10785 break;
10786 case DW_SECT_MACINFO:
10787 sections.macinfo_offset = offset;
10788 sections.macinfo_size = size;
10789 break;
10790 case DW_SECT_MACRO:
10791 sections.macro_offset = offset;
10792 sections.macro_size = size;
10793 break;
10794 }
10795 }
10796
10797 /* It's easier for the rest of the code if we fake a struct dwo_file and
10798 have dwo_unit "live" in that. At least for now.
10799
10800 The DWP file can be made up of a random collection of CUs and TUs.
10801 However, for each CU + set of TUs that came from the same original DWO
10802 file, we can combine them back into a virtual DWO file to save space
10803 (fewer struct dwo_file objects to allocate). Remember that for really
10804 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10805
10806 std::string virtual_dwo_name =
10807 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
10808 (long) (sections.abbrev_size ? sections.abbrev_offset : 0),
10809 (long) (sections.line_size ? sections.line_offset : 0),
10810 (long) (sections.loc_size ? sections.loc_offset : 0),
10811 (long) (sections.str_offsets_size
10812 ? sections.str_offsets_offset : 0));
10813 /* Can we use an existing virtual DWO file? */
10814 dwo_file_slot = lookup_dwo_file_slot (per_objfile, virtual_dwo_name.c_str (),
10815 comp_dir);
10816 /* Create one if necessary. */
10817 if (*dwo_file_slot == NULL)
10818 {
10819 dwarf_read_debug_printf ("Creating virtual DWO: %s",
10820 virtual_dwo_name.c_str ());
10821
10822 dwo_file = new struct dwo_file;
10823 dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name);
10825 dwo_file->sections.abbrev =
10826 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.abbrev,
10827 sections.abbrev_offset,
10828 sections.abbrev_size);
10829 dwo_file->sections.line =
10830 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.line,
10831 sections.line_offset,
10832 sections.line_size);
10833 dwo_file->sections.loc =
10834 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.loc,
10835 sections.loc_offset, sections.loc_size);
10836 dwo_file->sections.macinfo =
10837 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.macinfo,
10838 sections.macinfo_offset,
10839 sections.macinfo_size);
10840 dwo_file->sections.macro =
10841 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.macro,
10842 sections.macro_offset,
10843 sections.macro_size);
10844 dwo_file->sections.str_offsets =
10845 create_dwp_v2_or_v5_section (per_objfile,
10846 &dwp_file->sections.str_offsets,
10847 sections.str_offsets_offset,
10848 sections.str_offsets_size);
10849 /* The "str" section is global to the entire DWP file. */
10850 dwo_file->sections.str = dwp_file->sections.str;
10851 /* The info or types section is assigned below to dwo_unit,
10852 there's no need to record it in dwo_file.
10853 Also, we can't simply record type sections in dwo_file because
10854 we record a pointer into the vector in dwo_unit. As we collect more
10855 types we'll grow the vector and eventually have to reallocate space
10856 for it, invalidating all copies of pointers into the previous
10857 contents. */
10858 *dwo_file_slot = dwo_file;
10859 }
10860 else
10861 {
10862 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
10863 virtual_dwo_name.c_str ());
10864
10865 dwo_file = (struct dwo_file *) *dwo_file_slot;
10866 }
10867
10868 dwo_unit = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwo_unit);
10870 dwo_unit->signature = signature;
10871 dwo_unit->section =
10872 XOBNEW (&per_objfile->per_bfd->obstack, struct dwarf2_section_info);
10874 (per_objfile,
10875 is_debug_types
10876 ? &dwp_file->sections.types
10877 : &dwp_file->sections.info,
10878 sections.info_or_types_offset,
10879 sections.info_or_types_size);
10880 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10881
10882 return dwo_unit;
10883}
10884
10885/* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10886 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10887 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10888 This is for DWP version 5 files. */
10889
10890static struct dwo_unit *
10892 struct dwp_file *dwp_file,
10893 uint32_t unit_index,
10894 const char *comp_dir,
10895 ULONGEST signature, int is_debug_types)
10896{
10897 const struct dwp_hash_table *dwp_htab
10898 = is_debug_types ? dwp_file->tus : dwp_file->cus;
10899 bfd *dbfd = dwp_file->dbfd.get ();
10900 const char *kind = is_debug_types ? "TU" : "CU";
10901 struct dwo_file *dwo_file;
10902 struct dwo_unit *dwo_unit;
10903 struct virtual_v2_or_v5_dwo_sections sections {};
10904 void **dwo_file_slot;
10905
10906 gdb_assert (dwp_file->version == 5);
10907
10908 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
10909 kind, pulongest (unit_index), hex_string (signature),
10910 dwp_file->name);
10911
10912 /* Fetch the section offsets of this DWO unit. */
10913
10914 /* memset (&sections, 0, sizeof (sections)); */
10915
10916 for (int i = 0; i < dwp_htab->nr_columns; ++i)
10917 {
10918 uint32_t offset = read_4_bytes (dbfd,
10919 dwp_htab->section_pool.v5.offsets
10920 + (((unit_index - 1)
10921 * dwp_htab->nr_columns
10922 + i)
10923 * sizeof (uint32_t)));
10924 uint32_t size = read_4_bytes (dbfd,
10925 dwp_htab->section_pool.v5.sizes
10926 + (((unit_index - 1) * dwp_htab->nr_columns
10927 + i)
10928 * sizeof (uint32_t)));
10929
10930 switch (dwp_htab->section_pool.v5.section_ids[i])
10931 {
10932 case DW_SECT_ABBREV_V5:
10933 sections.abbrev_offset = offset;
10934 sections.abbrev_size = size;
10935 break;
10936 case DW_SECT_INFO_V5:
10937 sections.info_or_types_offset = offset;
10938 sections.info_or_types_size = size;
10939 break;
10940 case DW_SECT_LINE_V5:
10941 sections.line_offset = offset;
10942 sections.line_size = size;
10943 break;
10944 case DW_SECT_LOCLISTS_V5:
10945 sections.loclists_offset = offset;
10946 sections.loclists_size = size;
10947 break;
10948 case DW_SECT_MACRO_V5:
10949 sections.macro_offset = offset;
10950 sections.macro_size = size;
10951 break;
10952 case DW_SECT_RNGLISTS_V5:
10953 sections.rnglists_offset = offset;
10954 sections.rnglists_size = size;
10955 break;
10956 case DW_SECT_STR_OFFSETS_V5:
10957 sections.str_offsets_offset = offset;
10958 sections.str_offsets_size = size;
10959 break;
10960 case DW_SECT_RESERVED_V5:
10961 default:
10962 break;
10963 }
10964 }
10965
10966 /* It's easier for the rest of the code if we fake a struct dwo_file and
10967 have dwo_unit "live" in that. At least for now.
10968
10969 The DWP file can be made up of a random collection of CUs and TUs.
10970 However, for each CU + set of TUs that came from the same original DWO
10971 file, we can combine them back into a virtual DWO file to save space
10972 (fewer struct dwo_file objects to allocate). Remember that for really
10973 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10974
10975 std::string virtual_dwo_name =
10976 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
10977 (long) (sections.abbrev_size ? sections.abbrev_offset : 0),
10978 (long) (sections.line_size ? sections.line_offset : 0),
10979 (long) (sections.loclists_size ? sections.loclists_offset : 0),
10980 (long) (sections.str_offsets_size
10981 ? sections.str_offsets_offset : 0),
10982 (long) (sections.macro_size ? sections.macro_offset : 0),
10983 (long) (sections.rnglists_size ? sections.rnglists_offset: 0));
10984 /* Can we use an existing virtual DWO file? */
10985 dwo_file_slot = lookup_dwo_file_slot (per_objfile,
10986 virtual_dwo_name.c_str (),
10987 comp_dir);
10988 /* Create one if necessary. */
10989 if (*dwo_file_slot == NULL)
10990 {
10991 dwarf_read_debug_printf ("Creating virtual DWO: %s",
10992 virtual_dwo_name.c_str ());
10993
10994 dwo_file = new struct dwo_file;
10995 dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name);
10997 dwo_file->sections.abbrev =
10998 create_dwp_v2_or_v5_section (per_objfile,
10999 &dwp_file->sections.abbrev,
11000 sections.abbrev_offset,
11001 sections.abbrev_size);
11002 dwo_file->sections.line =
11003 create_dwp_v2_or_v5_section (per_objfile,
11004 &dwp_file->sections.line,
11005 sections.line_offset, sections.line_size);
11006 dwo_file->sections.macro =
11007 create_dwp_v2_or_v5_section (per_objfile,
11008 &dwp_file->sections.macro,
11009 sections.macro_offset,
11010 sections.macro_size);
11011 dwo_file->sections.loclists =
11012 create_dwp_v2_or_v5_section (per_objfile,
11013 &dwp_file->sections.loclists,
11014 sections.loclists_offset,
11015 sections.loclists_size);
11016 dwo_file->sections.rnglists =
11017 create_dwp_v2_or_v5_section (per_objfile,
11018 &dwp_file->sections.rnglists,
11019 sections.rnglists_offset,
11020 sections.rnglists_size);
11021 dwo_file->sections.str_offsets =
11022 create_dwp_v2_or_v5_section (per_objfile,
11023 &dwp_file->sections.str_offsets,
11024 sections.str_offsets_offset,
11025 sections.str_offsets_size);
11026 /* The "str" section is global to the entire DWP file. */
11027 dwo_file->sections.str = dwp_file->sections.str;
11028 /* The info or types section is assigned below to dwo_unit,
11029 there's no need to record it in dwo_file.
11030 Also, we can't simply record type sections in dwo_file because
11031 we record a pointer into the vector in dwo_unit. As we collect more
11032 types we'll grow the vector and eventually have to reallocate space
11033 for it, invalidating all copies of pointers into the previous
11034 contents. */
11035 *dwo_file_slot = dwo_file;
11036 }
11037 else
11038 {
11039 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11040 virtual_dwo_name.c_str ());
11041
11042 dwo_file = (struct dwo_file *) *dwo_file_slot;
11043 }
11044
11045 dwo_unit = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwo_unit);
11047 dwo_unit->signature = signature;
11049 = XOBNEW (&per_objfile->per_bfd->obstack, struct dwarf2_section_info);
11051 &dwp_file->sections.info,
11052 sections.info_or_types_offset,
11053 sections.info_or_types_size);
11054 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11055
11056 return dwo_unit;
11057}
11058
11059/* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11060 Returns NULL if the signature isn't found. */
11061
11062static struct dwo_unit *
11064 struct dwp_file *dwp_file, const char *comp_dir,
11065 ULONGEST signature, int is_debug_types)
11066{
11067 const struct dwp_hash_table *dwp_htab =
11068 is_debug_types ? dwp_file->tus : dwp_file->cus;
11069 bfd *dbfd = dwp_file->dbfd.get ();
11070 uint32_t mask = dwp_htab->nr_slots - 1;
11071 uint32_t hash = signature & mask;
11072 uint32_t hash2 = ((signature >> 32) & mask) | 1;
11073 unsigned int i;
11074 void **slot;
11075 struct dwo_unit find_dwo_cu;
11076
11077 memset (&find_dwo_cu, 0, sizeof (find_dwo_cu));
11078 find_dwo_cu.signature = signature;
11079 slot = htab_find_slot (is_debug_types
11080 ? dwp_file->loaded_tus.get ()
11081 : dwp_file->loaded_cus.get (),
11082 &find_dwo_cu, INSERT);
11083
11084 if (*slot != NULL)
11085 return (struct dwo_unit *) *slot;
11086
11087 /* Use a for loop so that we don't loop forever on bad debug info. */
11088 for (i = 0; i < dwp_htab->nr_slots; ++i)
11089 {
11090 ULONGEST signature_in_table;
11091
11092 signature_in_table =
11093 read_8_bytes (dbfd, dwp_htab->hash_table + hash * sizeof (uint64_t));
11094 if (signature_in_table == signature)
11095 {
11096 uint32_t unit_index =
11097 read_4_bytes (dbfd,
11098 dwp_htab->unit_table + hash * sizeof (uint32_t));
11099
11100 if (dwp_file->version == 1)
11101 {
11102 *slot = create_dwo_unit_in_dwp_v1 (per_objfile, dwp_file,
11103 unit_index, comp_dir,
11104 signature, is_debug_types);
11105 }
11106 else if (dwp_file->version == 2)
11107 {
11108 *slot = create_dwo_unit_in_dwp_v2 (per_objfile, dwp_file,
11109 unit_index, comp_dir,
11110 signature, is_debug_types);
11111 }
11112 else /* version == 5 */
11113 {
11114 *slot = create_dwo_unit_in_dwp_v5 (per_objfile, dwp_file,
11115 unit_index, comp_dir,
11116 signature, is_debug_types);
11117 }
11118 return (struct dwo_unit *) *slot;
11119 }
11120 if (signature_in_table == 0)
11121 return NULL;
11122 hash = (hash + hash2) & mask;
11123 }
11124
11125 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11126 " [in module %s]"),
11127 dwp_file->name);
11128}
11129
11130/* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11131 Open the file specified by FILE_NAME and hand it off to BFD for
11132 preliminary analysis. Return a newly initialized bfd *, which
11133 includes a canonicalized copy of FILE_NAME.
11134 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11135 SEARCH_CWD is true if the current directory is to be searched.
11136 It will be searched before debug-file-directory.
11137 If successful, the file is added to the bfd include table of the
11138 objfile's bfd (see gdb_bfd_record_inclusion).
11139 If unable to find/open the file, return NULL.
11140 NOTE: This function is derived from symfile_bfd_open. */
11141
11142static gdb_bfd_ref_ptr
11144 const char *file_name, int is_dwp, int search_cwd)
11145{
11146 int desc;
11147 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11148 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11149 to debug_file_directory. */
11150 const char *search_path;
11151 static const char dirname_separator_string[] = { DIRNAME_SEPARATOR, '\0' };
11152
11153 gdb::unique_xmalloc_ptr<char> search_path_holder;
11154 if (search_cwd)
11155 {
11156 if (!debug_file_directory.empty ())
11157 {
11158 search_path_holder.reset (concat (".", dirname_separator_string,
11159 debug_file_directory.c_str (),
11160 (char *) NULL));
11161 search_path = search_path_holder.get ();
11162 }
11163 else
11164 search_path = ".";
11165 }
11166 else
11167 search_path = debug_file_directory.c_str ();
11168
11169 /* Add the path for the executable binary to the list of search paths. */
11170 std::string objfile_dir = ldirname (objfile_name (per_objfile->objfile));
11171 search_path_holder.reset (concat (objfile_dir.c_str (),
11172 dirname_separator_string,
11173 search_path, nullptr));
11174 search_path = search_path_holder.get ();
11175
11176 openp_flags flags = OPF_RETURN_REALPATH;
11177 if (is_dwp)
11179
11180 gdb::unique_xmalloc_ptr<char> absolute_name;
11181 desc = openp (search_path, flags, file_name,
11182 O_RDONLY | O_BINARY, &absolute_name);
11183 if (desc < 0)
11184 return NULL;
11185
11186 gdb_bfd_ref_ptr sym_bfd (gdb_bfd_open (absolute_name.get (),
11187 gnutarget, desc));
11188 if (sym_bfd == NULL)
11189 return NULL;
11190 bfd_set_cacheable (sym_bfd.get (), 1);
11191
11192 if (!bfd_check_format (sym_bfd.get (), bfd_object))
11193 return NULL;
11194
11195 /* Success. Record the bfd as having been included by the objfile's bfd.
11196 This is important because things like demangled_names_hash lives in the
11197 objfile's per_bfd space and may have references to things like symbol
11198 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11199 gdb_bfd_record_inclusion (per_objfile->objfile->obfd.get (), sym_bfd.get ());
11200
11201 return sym_bfd;
11202}
11203
11204/* Try to open DWO file FILE_NAME.
11205 COMP_DIR is the DW_AT_comp_dir attribute.
11206 The result is the bfd handle of the file.
11207 If there is a problem finding or opening the file, return NULL.
11208 Upon success, the canonicalized path of the file is stored in the bfd,
11209 same as symfile_bfd_open. */
11210
11211static gdb_bfd_ref_ptr
11213 const char *file_name, const char *comp_dir)
11214{
11215 if (IS_ABSOLUTE_PATH (file_name))
11216 return try_open_dwop_file (per_objfile, file_name,
11217 0 /*is_dwp*/, 0 /*search_cwd*/);
11218
11219 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
11220
11221 if (comp_dir != NULL)
11222 {
11223 std::string path_to_try = path_join (comp_dir, file_name);
11224
11225 /* NOTE: If comp_dir is a relative path, this will also try the
11226 search path, which seems useful. */
11228 (per_objfile, path_to_try.c_str (), 0 /*is_dwp*/, 1 /*search_cwd*/));
11229
11230 if (abfd != NULL)
11231 return abfd;
11232 }
11233
11234 /* That didn't work, try debug-file-directory, which, despite its name,
11235 is a list of paths. */
11236
11237 if (debug_file_directory.empty ())
11238 return NULL;
11239
11240 return try_open_dwop_file (per_objfile, file_name,
11241 0 /*is_dwp*/, 1 /*search_cwd*/);
11242}
11243
11244/* This function is mapped across the sections and remembers the offset and
11245 size of each of the DWO debugging sections we are interested in. */
11246
11247static void
11249 asection *sectp, dwo_sections *dwo_sections)
11250{
11251 const struct dwop_section_names *names = &dwop_section_names;
11252
11253 struct dwarf2_section_info *dw_sect = nullptr;
11254
11255 if (names->abbrev_dwo.matches (sectp->name))
11256 dw_sect = &dwo_sections->abbrev;
11257 else if (names->info_dwo.matches (sectp->name))
11258 dw_sect = &dwo_sections->info;
11259 else if (names->line_dwo.matches (sectp->name))
11260 dw_sect = &dwo_sections->line;
11261 else if (names->loc_dwo.matches (sectp->name))
11262 dw_sect = &dwo_sections->loc;
11263 else if (names->loclists_dwo.matches (sectp->name))
11264 dw_sect = &dwo_sections->loclists;
11265 else if (names->macinfo_dwo.matches (sectp->name))
11266 dw_sect = &dwo_sections->macinfo;
11267 else if (names->macro_dwo.matches (sectp->name))
11268 dw_sect = &dwo_sections->macro;
11269 else if (names->rnglists_dwo.matches (sectp->name))
11270 dw_sect = &dwo_sections->rnglists;
11271 else if (names->str_dwo.matches (sectp->name))
11272 dw_sect = &dwo_sections->str;
11273 else if (names->str_offsets_dwo.matches (sectp->name))
11274 dw_sect = &dwo_sections->str_offsets;
11275 else if (names->types_dwo.matches (sectp->name))
11276 {
11277 struct dwarf2_section_info type_section;
11278
11279 memset (&type_section, 0, sizeof (type_section));
11280 dwo_sections->types.push_back (type_section);
11281 dw_sect = &dwo_sections->types.back ();
11282 }
11283
11284 if (dw_sect != nullptr)
11285 {
11286 dw_sect->s.section = sectp;
11287 dw_sect->size = bfd_section_size (sectp);
11288 dw_sect->read (objfile);
11289 }
11290}
11291
11292/* Initialize the use of the DWO file specified by DWO_NAME and referenced
11293 by PER_CU. This is for the non-DWP case.
11294 The result is NULL if DWO_NAME can't be found. */
11295
11296static struct dwo_file *
11298 const char *comp_dir)
11299{
11300 dwarf2_per_objfile *per_objfile = cu->per_objfile;
11301
11303 if (dbfd == NULL)
11304 {
11305 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name);
11306
11307 return NULL;
11308 }
11309
11310 dwo_file_up dwo_file (new struct dwo_file);
11313 dwo_file->dbfd = std::move (dbfd);
11314
11315 for (asection *sec : gdb_bfd_sections (dwo_file->dbfd))
11316 dwarf2_locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (),
11317 sec, &dwo_file->sections);
11318
11319 create_cus_hash_table (per_objfile, cu, *dwo_file, dwo_file->sections.info,
11320 dwo_file->cus);
11321
11322 if (cu->per_cu->version () < 5)
11323 {
11324 create_debug_types_hash_table (per_objfile, dwo_file.get (),
11325 dwo_file->sections.types, dwo_file->tus);
11326 }
11327 else
11328 {
11329 create_debug_type_hash_table (per_objfile, dwo_file.get (),
11330 &dwo_file->sections.info, dwo_file->tus,
11332 }
11333
11334 dwarf_read_debug_printf ("DWO file found: %s", dwo_name);
11335
11336 return dwo_file.release ();
11337}
11338
11339/* This function is mapped across the sections and remembers the offset and
11340 size of each of the DWP debugging sections common to version 1 and 2 that
11341 we are interested in. */
11342
11343static void
11345 asection *sectp, dwp_file *dwp_file)
11346{
11347 const struct dwop_section_names *names = &dwop_section_names;
11348 unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
11349
11350 /* Record the ELF section number for later lookup: this is what the
11351 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11352 gdb_assert (elf_section_nr < dwp_file->num_sections);
11353 dwp_file->elf_sections[elf_section_nr] = sectp;
11354
11355 /* Look for specific sections that we need. */
11356 struct dwarf2_section_info *dw_sect = nullptr;
11357 if (names->str_dwo.matches (sectp->name))
11358 dw_sect = &dwp_file->sections.str;
11359 else if (names->cu_index.matches (sectp->name))
11360 dw_sect = &dwp_file->sections.cu_index;
11361 else if (names->tu_index.matches (sectp->name))
11362 dw_sect = &dwp_file->sections.tu_index;
11363
11364 if (dw_sect != nullptr)
11365 {
11366 dw_sect->s.section = sectp;
11367 dw_sect->size = bfd_section_size (sectp);
11368 dw_sect->read (objfile);
11369 }
11370}
11371
11372/* This function is mapped across the sections and remembers the offset and
11373 size of each of the DWP version 2 debugging sections that we are interested
11374 in. This is split into a separate function because we don't know if we
11375 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
11376
11377static void
11379 asection *sectp, void *dwp_file_ptr)
11380{
11381 struct dwp_file *dwp_file = (struct dwp_file *) dwp_file_ptr;
11382 const struct dwop_section_names *names = &dwop_section_names;
11383 unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
11384
11385 /* Record the ELF section number for later lookup: this is what the
11386 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11387 gdb_assert (elf_section_nr < dwp_file->num_sections);
11388 dwp_file->elf_sections[elf_section_nr] = sectp;
11389
11390 /* Look for specific sections that we need. */
11391 struct dwarf2_section_info *dw_sect = nullptr;
11392 if (names->abbrev_dwo.matches (sectp->name))
11393 dw_sect = &dwp_file->sections.abbrev;
11394 else if (names->info_dwo.matches (sectp->name))
11395 dw_sect = &dwp_file->sections.info;
11396 else if (names->line_dwo.matches (sectp->name))
11397 dw_sect = &dwp_file->sections.line;
11398 else if (names->loc_dwo.matches (sectp->name))
11399 dw_sect = &dwp_file->sections.loc;
11400 else if (names->macinfo_dwo.matches (sectp->name))
11401 dw_sect = &dwp_file->sections.macinfo;
11402 else if (names->macro_dwo.matches (sectp->name))
11403 dw_sect = &dwp_file->sections.macro;
11404 else if (names->str_offsets_dwo.matches (sectp->name))
11405 dw_sect = &dwp_file->sections.str_offsets;
11406 else if (names->types_dwo.matches (sectp->name))
11407 dw_sect = &dwp_file->sections.types;
11408
11409 if (dw_sect != nullptr)
11410 {
11411 dw_sect->s.section = sectp;
11412 dw_sect->size = bfd_section_size (sectp);
11413 dw_sect->read (objfile);
11414 }
11415}
11416
11417/* This function is mapped across the sections and remembers the offset and
11418 size of each of the DWP version 5 debugging sections that we are interested
11419 in. This is split into a separate function because we don't know if we
11420 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
11421
11422static void
11424 asection *sectp, void *dwp_file_ptr)
11425{
11426 struct dwp_file *dwp_file = (struct dwp_file *) dwp_file_ptr;
11427 const struct dwop_section_names *names = &dwop_section_names;
11428 unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
11429
11430 /* Record the ELF section number for later lookup: this is what the
11431 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11432 gdb_assert (elf_section_nr < dwp_file->num_sections);
11433 dwp_file->elf_sections[elf_section_nr] = sectp;
11434
11435 /* Look for specific sections that we need. */
11436 struct dwarf2_section_info *dw_sect = nullptr;
11437 if (names->abbrev_dwo.matches (sectp->name))
11438 dw_sect = &dwp_file->sections.abbrev;
11439 else if (names->info_dwo.matches (sectp->name))
11440 dw_sect = &dwp_file->sections.info;
11441 else if (names->line_dwo.matches (sectp->name))
11442 dw_sect = &dwp_file->sections.line;
11443 else if (names->loclists_dwo.matches (sectp->name))
11444 dw_sect = &dwp_file->sections.loclists;
11445 else if (names->macro_dwo.matches (sectp->name))
11446 dw_sect = &dwp_file->sections.macro;
11447 else if (names->rnglists_dwo.matches (sectp->name))
11448 dw_sect = &dwp_file->sections.rnglists;
11449 else if (names->str_offsets_dwo.matches (sectp->name))
11450 dw_sect = &dwp_file->sections.str_offsets;
11451
11452 if (dw_sect != nullptr)
11453 {
11454 dw_sect->s.section = sectp;
11455 dw_sect->size = bfd_section_size (sectp);
11456 dw_sect->read (objfile);
11457 }
11458}
11459
11460/* Hash function for dwp_file loaded CUs/TUs. */
11461
11462static hashval_t
11463hash_dwp_loaded_cutus (const void *item)
11464{
11465 const struct dwo_unit *dwo_unit = (const struct dwo_unit *) item;
11466
11467 /* This drops the top 32 bits of the signature, but is ok for a hash. */
11468 return dwo_unit->signature;
11469}
11470
11471/* Equality function for dwp_file loaded CUs/TUs. */
11472
11473static int
11474eq_dwp_loaded_cutus (const void *a, const void *b)
11475{
11476 const struct dwo_unit *dua = (const struct dwo_unit *) a;
11477 const struct dwo_unit *dub = (const struct dwo_unit *) b;
11478
11479 return dua->signature == dub->signature;
11480}
11481
11482/* Allocate a hash table for dwp_file loaded CUs/TUs. */
11483
11484static htab_up
11486{
11487 return htab_up (htab_create_alloc (3,
11490 NULL, xcalloc, xfree));
11491}
11492
11493/* Try to open DWP file FILE_NAME.
11494 The result is the bfd handle of the file.
11495 If there is a problem finding or opening the file, return NULL.
11496 Upon success, the canonicalized path of the file is stored in the bfd,
11497 same as symfile_bfd_open. */
11498
11499static gdb_bfd_ref_ptr
11500open_dwp_file (dwarf2_per_objfile *per_objfile, const char *file_name)
11501{
11502 gdb_bfd_ref_ptr abfd (try_open_dwop_file (per_objfile, file_name,
11503 1 /*is_dwp*/,
11504 1 /*search_cwd*/));
11505 if (abfd != NULL)
11506 return abfd;
11507
11508 /* Work around upstream bug 15652.
11509 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
11510 [Whether that's a "bug" is debatable, but it is getting in our way.]
11511 We have no real idea where the dwp file is, because gdb's realpath-ing
11512 of the executable's path may have discarded the needed info.
11513 [IWBN if the dwp file name was recorded in the executable, akin to
11514 .gnu_debuglink, but that doesn't exist yet.]
11515 Strip the directory from FILE_NAME and search again. */
11516 if (!debug_file_directory.empty ())
11517 {
11518 /* Don't implicitly search the current directory here.
11519 If the user wants to search "." to handle this case,
11520 it must be added to debug-file-directory. */
11521 return try_open_dwop_file (per_objfile, lbasename (file_name),
11522 1 /*is_dwp*/,
11523 0 /*search_cwd*/);
11524 }
11525
11526 return NULL;
11527}
11528
11529/* Initialize the use of the DWP file for the current objfile.
11530 By convention the name of the DWP file is ${objfile}.dwp.
11531 The result is NULL if it can't be found. */
11532
11533static std::unique_ptr<struct dwp_file>
11535{
11536 struct objfile *objfile = per_objfile->objfile;
11537
11538 /* Try to find first .dwp for the binary file before any symbolic links
11539 resolving. */
11540
11541 /* If the objfile is a debug file, find the name of the real binary
11542 file and get the name of dwp file from there. */
11543 std::string dwp_name;
11545 {
11547 const char *backlink_basename = lbasename (backlink->original_name);
11548
11549 dwp_name = ldirname (objfile->original_name) + SLASH_STRING + backlink_basename;
11550 }
11551 else
11552 dwp_name = objfile->original_name;
11553
11554 dwp_name += ".dwp";
11555
11556 gdb_bfd_ref_ptr dbfd (open_dwp_file (per_objfile, dwp_name.c_str ()));
11557 if (dbfd == NULL
11558 && strcmp (objfile->original_name, objfile_name (objfile)) != 0)
11559 {
11560 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
11561 dwp_name = objfile_name (objfile);
11562 dwp_name += ".dwp";
11563 dbfd = open_dwp_file (per_objfile, dwp_name.c_str ());
11564 }
11565
11566 if (dbfd == NULL)
11567 {
11568 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name.c_str ());
11569
11570 return std::unique_ptr<dwp_file> ();
11571 }
11572
11573 const char *name = bfd_get_filename (dbfd.get ());
11574 std::unique_ptr<struct dwp_file> dwp_file
11575 (new struct dwp_file (name, std::move (dbfd)));
11576
11577 dwp_file->num_sections = elf_numsections (dwp_file->dbfd);
11579 OBSTACK_CALLOC (&per_objfile->per_bfd->obstack,
11580 dwp_file->num_sections, asection *);
11581
11582 for (asection *sec : gdb_bfd_sections (dwp_file->dbfd))
11584 dwp_file.get ());
11585
11586 dwp_file->cus = create_dwp_hash_table (per_objfile, dwp_file.get (), 0);
11587
11588 dwp_file->tus = create_dwp_hash_table (per_objfile, dwp_file.get (), 1);
11589
11590 /* The DWP file version is stored in the hash table. Oh well. */
11591 if (dwp_file->cus && dwp_file->tus
11593 {
11594 /* Technically speaking, we should try to limp along, but this is
11595 pretty bizarre. We use pulongest here because that's the established
11596 portability solution (e.g, we cannot use %u for uint32_t). */
11597 error (_("Dwarf Error: DWP file CU version %s doesn't match"
11598 " TU version %s [in DWP file %s]"),
11599 pulongest (dwp_file->cus->version),
11600 pulongest (dwp_file->tus->version), dwp_name.c_str ());
11601 }
11602
11603 if (dwp_file->cus)
11605 else if (dwp_file->tus)
11607 else
11608 dwp_file->version = 2;
11609
11610 for (asection *sec : gdb_bfd_sections (dwp_file->dbfd))
11611 {
11612 if (dwp_file->version == 2)
11614 dwp_file.get ());
11615 else
11617 dwp_file.get ());
11618 }
11619
11622
11623 dwarf_read_debug_printf ("DWP file found: %s", dwp_file->name);
11624 dwarf_read_debug_printf (" %s CUs, %s TUs",
11625 pulongest (dwp_file->cus ? dwp_file->cus->nr_units : 0),
11626 pulongest (dwp_file->tus ? dwp_file->tus->nr_units : 0));
11627
11628 return dwp_file;
11629}
11630
11631/* Wrapper around open_and_init_dwp_file, only open it once. */
11632
11633static struct dwp_file *
11635{
11636 if (!per_objfile->per_bfd->dwp_checked)
11637 {
11638 per_objfile->per_bfd->dwp_file = open_and_init_dwp_file (per_objfile);
11639 per_objfile->per_bfd->dwp_checked = 1;
11640 }
11641 return per_objfile->per_bfd->dwp_file.get ();
11642}
11643
11644/* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
11645 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
11646 or in the DWP file for the objfile, referenced by THIS_UNIT.
11647 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
11648 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
11649
11650 This is called, for example, when wanting to read a variable with a
11651 complex location. Therefore we don't want to do file i/o for every call.
11652 Therefore we don't want to look for a DWO file on every call.
11653 Therefore we first see if we've already seen SIGNATURE in a DWP file,
11654 then we check if we've already seen DWO_NAME, and only THEN do we check
11655 for a DWO file.
11656
11657 The result is a pointer to the dwo_unit object or NULL if we didn't find it
11658 (dwo_id mismatch or couldn't find the DWO/DWP file). */
11659
11660static struct dwo_unit *
11661lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
11662 ULONGEST signature, int is_debug_types)
11663{
11664 dwarf2_per_objfile *per_objfile = cu->per_objfile;
11665 struct objfile *objfile = per_objfile->objfile;
11666 const char *kind = is_debug_types ? "TU" : "CU";
11667 void **dwo_file_slot;
11668 struct dwo_file *dwo_file;
11669 struct dwp_file *dwp_file;
11670
11671 /* First see if there's a DWP file.
11672 If we have a DWP file but didn't find the DWO inside it, don't
11673 look for the original DWO file. It makes gdb behave differently
11674 depending on whether one is debugging in the build tree. */
11675
11676 dwp_file = get_dwp_file (per_objfile);
11677 if (dwp_file != NULL)
11678 {
11679 const struct dwp_hash_table *dwp_htab =
11680 is_debug_types ? dwp_file->tus : dwp_file->cus;
11681
11682 if (dwp_htab != NULL)
11683 {
11684 struct dwo_unit *dwo_cutu =
11685 lookup_dwo_unit_in_dwp (per_objfile, dwp_file, comp_dir, signature,
11686 is_debug_types);
11687
11688 if (dwo_cutu != NULL)
11689 {
11690 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
11691 kind, hex_string (signature),
11692 host_address_to_string (dwo_cutu));
11693
11694 return dwo_cutu;
11695 }
11696 }
11697 }
11698 else
11699 {
11700 /* No DWP file, look for the DWO file. */
11701
11702 dwo_file_slot = lookup_dwo_file_slot (per_objfile, dwo_name, comp_dir);
11703 if (*dwo_file_slot == NULL)
11704 {
11705 /* Read in the file and build a table of the CUs/TUs it contains. */
11706 *dwo_file_slot = open_and_init_dwo_file (cu, dwo_name, comp_dir);
11707 }
11708 /* NOTE: This will be NULL if unable to open the file. */
11709 dwo_file = (struct dwo_file *) *dwo_file_slot;
11710
11711 if (dwo_file != NULL)
11712 {
11713 struct dwo_unit *dwo_cutu = NULL;
11714
11715 if (is_debug_types && dwo_file->tus)
11716 {
11717 struct dwo_unit find_dwo_cutu;
11718
11719 memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
11720 find_dwo_cutu.signature = signature;
11721 dwo_cutu
11722 = (struct dwo_unit *) htab_find (dwo_file->tus.get (),
11723 &find_dwo_cutu);
11724 }
11725 else if (!is_debug_types && dwo_file->cus)
11726 {
11727 struct dwo_unit find_dwo_cutu;
11728
11729 memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
11730 find_dwo_cutu.signature = signature;
11731 dwo_cutu = (struct dwo_unit *)htab_find (dwo_file->cus.get (),
11732 &find_dwo_cutu);
11733 }
11734
11735 if (dwo_cutu != NULL)
11736 {
11737 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
11738 kind, dwo_name, hex_string (signature),
11739 host_address_to_string (dwo_cutu));
11740
11741 return dwo_cutu;
11742 }
11743 }
11744 }
11745
11746 /* We didn't find it. This could mean a dwo_id mismatch, or
11747 someone deleted the DWO/DWP file, or the search path isn't set up
11748 correctly to find the file. */
11749
11750 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
11751 kind, dwo_name, hex_string (signature));
11752
11753 /* This is a warning and not a complaint because it can be caused by
11754 pilot error (e.g., user accidentally deleting the DWO). */
11755 {
11756 /* Print the name of the DWP file if we looked there, helps the user
11757 better diagnose the problem. */
11758 std::string dwp_text;
11759
11760 if (dwp_file != NULL)
11761 dwp_text = string_printf (" [in DWP file %s]",
11762 lbasename (dwp_file->name));
11763
11764 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
11765 " [in module %s]"),
11766 kind, dwo_name, hex_string (signature), dwp_text.c_str (), kind,
11768 }
11769 return NULL;
11770}
11771
11772/* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11773 See lookup_dwo_cutu_unit for details. */
11774
11775static struct dwo_unit *
11776lookup_dwo_comp_unit (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
11777 ULONGEST signature)
11778{
11779 gdb_assert (!cu->per_cu->is_debug_types);
11780
11781 return lookup_dwo_cutu (cu, dwo_name, comp_dir, signature, 0);
11782}
11783
11784/* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11785 See lookup_dwo_cutu_unit for details. */
11786
11787static struct dwo_unit *
11788lookup_dwo_type_unit (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir)
11789{
11790 gdb_assert (cu->per_cu->is_debug_types);
11791
11792 signatured_type *sig_type = (signatured_type *) cu->per_cu;
11793
11794 return lookup_dwo_cutu (cu, dwo_name, comp_dir, sig_type->signature, 1);
11795}
11796
11797/* Traversal function for queue_and_load_all_dwo_tus. */
11798
11799static int
11800queue_and_load_dwo_tu (void **slot, void *info)
11801{
11802 struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot;
11803 dwarf2_cu *cu = (dwarf2_cu *) info;
11804 ULONGEST signature = dwo_unit->signature;
11806
11807 if (sig_type != NULL)
11808 {
11809 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11810 a real dependency of PER_CU on SIG_TYPE. That is detected later
11811 while processing PER_CU. */
11812 if (maybe_queue_comp_unit (NULL, sig_type, cu->per_objfile,
11813 cu->lang ()))
11814 load_full_type_unit (sig_type, cu->per_objfile);
11815 cu->per_cu->imported_symtabs_push (sig_type);
11816 }
11817
11818 return 1;
11819}
11820
11821/* Queue all TUs contained in the DWO of CU to be read in.
11822 The DWO may have the only definition of the type, though it may not be
11823 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11824 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11825
11826static void
11828{
11829 struct dwo_unit *dwo_unit;
11830 struct dwo_file *dwo_file;
11831
11832 gdb_assert (cu != nullptr);
11833 gdb_assert (!cu->per_cu->is_debug_types);
11834 gdb_assert (get_dwp_file (cu->per_objfile) == nullptr);
11835
11836 dwo_unit = cu->dwo_unit;
11837 gdb_assert (dwo_unit != NULL);
11838
11840 if (dwo_file->tus != NULL)
11841 htab_traverse_noresize (dwo_file->tus.get (), queue_and_load_dwo_tu, cu);
11842}
11843
11844/* Read in various DIEs. */
11845
11846/* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11847 Inherit only the children of the DW_AT_abstract_origin DIE not being
11848 already referenced by DW_AT_abstract_origin from the children of the
11849 current DIE. */
11850
11851static void
11853{
11854 attribute *attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
11855 if (attr == nullptr)
11856 return;
11857
11858 /* Note that following die references may follow to a die in a
11859 different CU. */
11860 dwarf2_cu *origin_cu = cu;
11861
11862 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11863 die_info *origin_die = follow_die_ref (die, attr, &origin_cu);
11864
11865 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11866 symbols in. */
11867 struct pending **origin_previous_list_in_scope = origin_cu->list_in_scope;
11868 origin_cu->list_in_scope = cu->list_in_scope;
11869
11870 if (die->tag != origin_die->tag
11871 && !(die->tag == DW_TAG_inlined_subroutine
11872 && origin_die->tag == DW_TAG_subprogram))
11873 complaint (_("DIE %s and its abstract origin %s have different tags"),
11875 sect_offset_str (origin_die->sect_off));
11876
11877 /* Find if the concrete and abstract trees are structurally the
11878 same. This is a shallow traversal and it is not bullet-proof;
11879 the compiler can trick the debugger into believing that the trees
11880 are isomorphic, whereas they actually are not. However, the
11881 likelyhood of this happening is pretty low, and a full-fledged
11882 check would be an overkill. */
11883 bool are_isomorphic = true;
11884 die_info *concrete_child = die->child;
11885 die_info *abstract_child = origin_die->child;
11886 while (concrete_child != nullptr || abstract_child != nullptr)
11887 {
11888 if (concrete_child == nullptr
11889 || abstract_child == nullptr
11890 || concrete_child->tag != abstract_child->tag)
11891 {
11892 are_isomorphic = false;
11893 break;
11894 }
11895
11896 concrete_child = concrete_child->sibling;
11897 abstract_child = abstract_child->sibling;
11898 }
11899
11900 /* Walk the origin's children in parallel to the concrete children.
11901 This helps match an origin child in case the debug info misses
11902 DW_AT_abstract_origin attributes. Keep in mind that the abstract
11903 origin tree may not have the same tree structure as the concrete
11904 DIE, though. */
11905 die_info *corresponding_abstract_child
11906 = are_isomorphic ? origin_die->child : nullptr;
11907
11908 std::vector<sect_offset> offsets;
11909
11910 for (die_info *child_die = die->child;
11911 child_die && child_die->tag;
11912 child_die = child_die->sibling)
11913 {
11914 /* We are trying to process concrete instance entries:
11915 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11916 it's not relevant to our analysis here. i.e. detecting DIEs that are
11917 present in the abstract instance but not referenced in the concrete
11918 one. */
11919 if (child_die->tag == DW_TAG_call_site
11920 || child_die->tag == DW_TAG_GNU_call_site)
11921 {
11922 if (are_isomorphic)
11923 corresponding_abstract_child
11924 = corresponding_abstract_child->sibling;
11925 continue;
11926 }
11927
11928 /* For each CHILD_DIE, find the corresponding child of
11929 ORIGIN_DIE. If there is more than one layer of
11930 DW_AT_abstract_origin, follow them all; there shouldn't be,
11931 but GCC versions at least through 4.4 generate this (GCC PR
11932 40573). */
11933 die_info *child_origin_die = child_die;
11934 dwarf2_cu *child_origin_cu = cu;
11935 while (true)
11936 {
11937 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
11938 child_origin_cu);
11939 if (attr == nullptr)
11940 break;
11941
11942 child_origin_die = follow_die_ref (child_origin_die, attr,
11943 &child_origin_cu);
11944 }
11945
11946 /* If missing DW_AT_abstract_origin, try the corresponding child
11947 of the origin. Clang emits such lexical scopes. */
11948 if (child_origin_die == child_die
11949 && dwarf2_attr (child_die, DW_AT_abstract_origin, cu) == nullptr
11950 && are_isomorphic
11951 && child_die->tag == DW_TAG_lexical_block)
11952 child_origin_die = corresponding_abstract_child;
11953
11954 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11955 counterpart may exist. */
11956 if (child_origin_die != child_die)
11957 {
11958 if (child_die->tag != child_origin_die->tag
11959 && !(child_die->tag == DW_TAG_inlined_subroutine
11960 && child_origin_die->tag == DW_TAG_subprogram))
11961 complaint (_("Child DIE %s and its abstract origin %s have "
11962 "different tags"),
11963 sect_offset_str (child_die->sect_off),
11964 sect_offset_str (child_origin_die->sect_off));
11965 if (child_origin_die->parent != origin_die)
11966 complaint (_("Child DIE %s and its abstract origin %s have "
11967 "different parents"),
11968 sect_offset_str (child_die->sect_off),
11969 sect_offset_str (child_origin_die->sect_off));
11970 else
11971 offsets.push_back (child_origin_die->sect_off);
11972 }
11973
11974 if (are_isomorphic)
11975 corresponding_abstract_child = corresponding_abstract_child->sibling;
11976 }
11977
11978 if (!offsets.empty ())
11979 {
11980 std::sort (offsets.begin (), offsets.end ());
11981
11982 for (auto offsets_it = offsets.begin () + 1;
11983 offsets_it < offsets.end ();
11984 ++offsets_it)
11985 if (*(offsets_it - 1) == *offsets_it)
11986 complaint (_("Multiple children of DIE %s refer "
11987 "to DIE %s as their abstract origin"),
11989 sect_offset_str (*offsets_it));
11990 }
11991
11992 auto offsets_it = offsets.begin ();
11993 die_info *origin_child_die = origin_die->child;
11994 while (origin_child_die != nullptr && origin_child_die->tag != 0)
11995 {
11996 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11997 while (offsets_it < offsets.end ()
11998 && *offsets_it < origin_child_die->sect_off)
11999 ++offsets_it;
12000
12001 if (offsets_it == offsets.end ()
12002 || *offsets_it > origin_child_die->sect_off)
12003 {
12004 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12005 Check whether we're already processing ORIGIN_CHILD_DIE.
12006 This can happen with mutually referenced abstract_origins.
12007 PR 16581. */
12008 if (!origin_child_die->in_process)
12009 process_die (origin_child_die, origin_cu);
12010 }
12011
12012 origin_child_die = origin_child_die->sibling;
12013 }
12014
12015 origin_cu->list_in_scope = origin_previous_list_in_scope;
12016
12017 if (cu != origin_cu)
12018 compute_delayed_physnames (origin_cu);
12019}
12020
12021static void
12022read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
12023{
12024 struct objfile *objfile = cu->per_objfile->objfile;
12025 struct gdbarch *gdbarch = objfile->arch ();
12026 struct context_stack *newobj;
12027 CORE_ADDR lowpc;
12028 CORE_ADDR highpc;
12029 struct die_info *child_die;
12030 struct attribute *attr, *call_line, *call_file;
12031 const char *name;
12032 CORE_ADDR baseaddr;
12033 struct block *block;
12034 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
12035 std::vector<struct symbol *> template_args;
12036 struct template_symbol *templ_func = NULL;
12037
12038 if (inlined_func)
12039 {
12040 /* If we do not have call site information, we can't show the
12041 caller of this inlined function. That's too confusing, so
12042 only use the scope for local variables. */
12043 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
12044 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
12045 if (call_line == NULL || call_file == NULL)
12046 {
12047 read_lexical_block_scope (die, cu);
12048 return;
12049 }
12050 }
12051
12052 baseaddr = objfile->text_section_offset ();
12053
12054 name = dwarf2_name (die, cu);
12055 if (name == nullptr)
12056 name = dw2_linkage_name (die, cu);
12057
12058 /* Ignore functions with missing or empty names. These are actually
12059 illegal according to the DWARF standard. */
12060 if (name == NULL)
12061 {
12062 complaint (_("missing name for subprogram DIE at %s"),
12063 sect_offset_str (die->sect_off));
12064 return;
12065 }
12066
12067 /* Ignore functions with missing or invalid low and high pc attributes. */
12068 if (dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, nullptr, nullptr)
12070 {
12071 if (have_complaint ())
12072 {
12073 attr = dwarf2_attr (die, DW_AT_external, cu);
12074 bool external_p = attr != nullptr && attr->as_boolean ();
12075 attr = dwarf2_attr (die, DW_AT_inline, cu);
12076 bool inlined_p
12077 = (attr != nullptr
12078 && attr->is_nonnegative ()
12079 && (attr->as_nonnegative () == DW_INL_inlined
12080 || attr->as_nonnegative () == DW_INL_declared_inlined));
12081 attr = dwarf2_attr (die, DW_AT_declaration, cu);
12082 bool decl_p = attr != nullptr && attr->as_boolean ();
12083 if (!external_p && !inlined_p && !decl_p)
12084 complaint (_("cannot get low and high bounds "
12085 "for subprogram DIE at %s"),
12086 sect_offset_str (die->sect_off));
12087 }
12088 return;
12089 }
12090
12091 lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
12092 highpc = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
12093
12094 /* If we have any template arguments, then we must allocate a
12095 different sort of symbol. */
12096 for (child_die = die->child; child_die; child_die = child_die->sibling)
12097 {
12098 if (child_die->tag == DW_TAG_template_type_param
12099 || child_die->tag == DW_TAG_template_value_param)
12100 {
12101 templ_func = new (&objfile->objfile_obstack) template_symbol;
12102 templ_func->subclass = SYMBOL_TEMPLATE;
12103 break;
12104 }
12105 }
12106
12107 gdb_assert (cu->get_builder () != nullptr);
12108 newobj = cu->get_builder ()->push_context (0, lowpc);
12109 newobj->name = new_symbol (die, read_type_die (die, cu), cu,
12110 (struct symbol *) templ_func);
12111
12112 if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu))
12114 cu->lang ());
12115
12116 /* If there is a location expression for DW_AT_frame_base, record
12117 it. */
12118 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
12119 if (attr != nullptr)
12120 dwarf2_symbol_mark_computed (attr, newobj->name, cu, 1);
12121
12122 /* If there is a location for the static link, record it. */
12123 newobj->static_link = NULL;
12124 attr = dwarf2_attr (die, DW_AT_static_link, cu);
12125 if (attr != nullptr)
12126 {
12127 newobj->static_link
12128 = XOBNEW (&objfile->objfile_obstack, struct dynamic_prop);
12129 attr_to_dynamic_prop (attr, die, cu, newobj->static_link,
12130 cu->addr_type ());
12131 }
12132
12134
12135 if (die->child != NULL)
12136 {
12137 child_die = die->child;
12138 while (child_die && child_die->tag)
12139 {
12140 if (child_die->tag == DW_TAG_template_type_param
12141 || child_die->tag == DW_TAG_template_value_param)
12142 {
12143 struct symbol *arg = new_symbol (child_die, NULL, cu);
12144
12145 if (arg != NULL)
12146 template_args.push_back (arg);
12147 }
12148 else
12149 process_die (child_die, cu);
12150 child_die = child_die->sibling;
12151 }
12152 }
12153
12154 inherit_abstract_dies (die, cu);
12155
12156 /* If we have a DW_AT_specification, we might need to import using
12157 directives from the context of the specification DIE. See the
12158 comment in determine_prefix. */
12159 if (cu->lang () == language_cplus
12160 && dwarf2_attr (die, DW_AT_specification, cu))
12161 {
12162 struct dwarf2_cu *spec_cu = cu;
12163 struct die_info *spec_die = die_specification (die, &spec_cu);
12164
12165 while (spec_die)
12166 {
12167 child_die = spec_die->child;
12168 while (child_die && child_die->tag)
12169 {
12170 if (child_die->tag == DW_TAG_imported_module)
12171 process_die (child_die, spec_cu);
12172 child_die = child_die->sibling;
12173 }
12174
12175 /* In some cases, GCC generates specification DIEs that
12176 themselves contain DW_AT_specification attributes. */
12177 spec_die = die_specification (spec_die, &spec_cu);
12178 }
12179 }
12180
12181 struct context_stack cstk = cu->get_builder ()->pop_context ();
12182 /* Make a block for the local symbols within. */
12183 block = cu->get_builder ()->finish_block (cstk.name, cstk.old_blocks,
12184 cstk.static_link, lowpc, highpc);
12185
12186 /* For C++, set the block's scope. */
12187 if ((cu->lang () == language_cplus
12188 || cu->lang () == language_fortran
12189 || cu->lang () == language_d
12190 || cu->lang () == language_rust)
12194
12195 /* If we have address ranges, record them. */
12196 dwarf2_record_block_ranges (die, block, baseaddr, cu);
12197
12199
12200 /* Attach template arguments to function. */
12201 if (!template_args.empty ())
12202 {
12203 gdb_assert (templ_func != NULL);
12204
12205 templ_func->n_template_arguments = template_args.size ();
12206 templ_func->template_arguments
12207 = XOBNEWVEC (&objfile->objfile_obstack, struct symbol *,
12208 templ_func->n_template_arguments);
12209 memcpy (templ_func->template_arguments,
12210 template_args.data (),
12211 (templ_func->n_template_arguments * sizeof (struct symbol *)));
12212
12213 /* Make sure that the symtab is set on the new symbols. Even
12214 though they don't appear in this symtab directly, other parts
12215 of gdb assume that symbols do, and this is reasonably
12216 true. */
12217 for (symbol *sym : template_args)
12218 sym->set_symtab (templ_func->symtab ());
12219 }
12220
12221 /* In C++, we can have functions nested inside functions (e.g., when
12222 a function declares a class that has methods). This means that
12223 when we finish processing a function scope, we may need to go
12224 back to building a containing block's symbol lists. */
12225 *cu->get_builder ()->get_local_symbols () = cstk.locals;
12227
12228 /* If we've finished processing a top-level function, subsequent
12229 symbols go in the file symbol list. */
12230 if (cu->get_builder ()->outermost_context_p ())
12232}
12233
12234/* Process all the DIES contained within a lexical block scope. Start
12235 a new scope, process the dies, and then close the scope. */
12236
12237static void
12239{
12240 struct objfile *objfile = cu->per_objfile->objfile;
12241 struct gdbarch *gdbarch = objfile->arch ();
12242 CORE_ADDR lowpc, highpc;
12243 struct die_info *child_die;
12244 CORE_ADDR baseaddr;
12245
12246 baseaddr = objfile->text_section_offset ();
12247
12248 /* Ignore blocks with missing or invalid low and high pc attributes. */
12249 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12250 as multiple lexical blocks? Handling children in a sane way would
12251 be nasty. Might be easier to properly extend generic blocks to
12252 describe ranges. */
12253 switch (dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, nullptr, nullptr))
12254 {
12256 /* DW_TAG_lexical_block has no attributes, process its children as if
12257 there was no wrapping by that DW_TAG_lexical_block.
12258 GCC does no longer produces such DWARF since GCC r224161. */
12259 for (child_die = die->child;
12260 child_die != NULL && child_die->tag;
12261 child_die = child_die->sibling)
12262 {
12263 /* We might already be processing this DIE. This can happen
12264 in an unusual circumstance -- where a subroutine A
12265 appears lexically in another subroutine B, but A actually
12266 inlines B. The recursion is broken here, rather than in
12267 inherit_abstract_dies, because it seems better to simply
12268 drop concrete children here. */
12269 if (!child_die->in_process)
12270 process_die (child_die, cu);
12271 }
12272 return;
12273 case PC_BOUNDS_INVALID:
12274 return;
12275 }
12276 lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
12277 highpc = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr);
12278
12279 cu->get_builder ()->push_context (0, lowpc);
12280 if (die->child != NULL)
12281 {
12282 child_die = die->child;
12283 while (child_die && child_die->tag)
12284 {
12285 process_die (child_die, cu);
12286 child_die = child_die->sibling;
12287 }
12288 }
12289 inherit_abstract_dies (die, cu);
12290 struct context_stack cstk = cu->get_builder ()->pop_context ();
12291
12292 if (*cu->get_builder ()->get_local_symbols () != NULL
12293 || (*cu->get_builder ()->get_local_using_directives ()) != NULL)
12294 {
12295 struct block *block
12296 = cu->get_builder ()->finish_block (0, cstk.old_blocks, NULL,
12297 cstk.start_addr, highpc);
12298
12299 /* Note that recording ranges after traversing children, as we
12300 do here, means that recording a parent's ranges entails
12301 walking across all its children's ranges as they appear in
12302 the address map, which is quadratic behavior.
12303
12304 It would be nicer to record the parent's ranges before
12305 traversing its children, simply overriding whatever you find
12306 there. But since we don't even decide whether to create a
12307 block until after we've traversed its children, that's hard
12308 to do. */
12309 dwarf2_record_block_ranges (die, block, baseaddr, cu);
12310 }
12311 *cu->get_builder ()->get_local_symbols () = cstk.locals;
12313}
12314
12315static void dwarf2_ranges_read_low_addrs (unsigned offset,
12316 struct dwarf2_cu *cu,
12317 dwarf_tag tag,
12318 std::vector<CORE_ADDR> &result);
12319
12320/* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
12321
12322static void
12323read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
12324{
12325 dwarf2_per_objfile *per_objfile = cu->per_objfile;
12326 struct objfile *objfile = per_objfile->objfile;
12327 struct gdbarch *gdbarch = objfile->arch ();
12328 CORE_ADDR pc, baseaddr;
12329 struct attribute *attr;
12330 void **slot;
12331 int nparams;
12332 struct die_info *child_die;
12333
12334 baseaddr = objfile->text_section_offset ();
12335
12336 attr = dwarf2_attr (die, DW_AT_call_return_pc, cu);
12337 if (attr == NULL)
12338 {
12339 /* This was a pre-DWARF-5 GNU extension alias
12340 for DW_AT_call_return_pc. */
12341 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
12342 }
12343 if (!attr)
12344 {
12345 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
12346 "DIE %s [in module %s]"),
12348 return;
12349 }
12350 pc = attr->as_address () + baseaddr;
12352 pc -= baseaddr;
12353
12354 if (cu->call_site_htab == NULL)
12355 cu->call_site_htab = htab_create_alloc_ex (16, call_site::hash,
12356 call_site::eq, NULL,
12358 hashtab_obstack_allocate, NULL);
12359 struct call_site call_site_local (pc, nullptr, nullptr);
12360 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
12361 if (*slot != NULL)
12362 {
12363 complaint (_("Duplicate PC %s for DW_TAG_call_site "
12364 "DIE %s [in module %s]"),
12367 return;
12368 }
12369
12370 /* Count parameters at the caller. */
12371
12372 nparams = 0;
12373 for (child_die = die->child; child_die && child_die->tag;
12374 child_die = child_die->sibling)
12375 {
12376 if (child_die->tag != DW_TAG_call_site_parameter
12377 && child_die->tag != DW_TAG_GNU_call_site_parameter)
12378 {
12379 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
12380 "DW_TAG_call_site child DIE %s [in module %s]"),
12381 child_die->tag, sect_offset_str (child_die->sect_off),
12383 continue;
12384 }
12385
12386 nparams++;
12387 }
12388
12389 struct call_site *call_site
12390 = new (XOBNEWVAR (&objfile->objfile_obstack,
12391 struct call_site,
12392 sizeof (*call_site) + sizeof (call_site->parameter[0]) * nparams))
12393 struct call_site (pc, cu->per_cu, per_objfile);
12394 *slot = call_site;
12395
12396 /* We never call the destructor of call_site, so we must ensure it is
12397 trivially destructible. */
12398 gdb_static_assert(std::is_trivially_destructible<struct call_site>::value);
12399
12400 if (dwarf2_flag_true_p (die, DW_AT_call_tail_call, cu)
12401 || dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
12402 {
12403 struct die_info *func_die;
12404
12405 /* Skip also over DW_TAG_inlined_subroutine. */
12406 for (func_die = die->parent;
12407 func_die && func_die->tag != DW_TAG_subprogram
12408 && func_die->tag != DW_TAG_subroutine_type;
12409 func_die = func_die->parent);
12410
12411 /* DW_AT_call_all_calls is a superset
12412 of DW_AT_call_all_tail_calls. */
12413 if (func_die
12414 && !dwarf2_flag_true_p (func_die, DW_AT_call_all_calls, cu)
12415 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
12416 && !dwarf2_flag_true_p (func_die, DW_AT_call_all_tail_calls, cu)
12417 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
12418 {
12419 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
12420 not complete. But keep CALL_SITE for look ups via call_site_htab,
12421 both the initial caller containing the real return address PC and
12422 the final callee containing the current PC of a chain of tail
12423 calls do not need to have the tail call list complete. But any
12424 function candidate for a virtual tail call frame searched via
12425 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
12426 determined unambiguously. */
12427 }
12428 else
12429 {
12430 struct type *func_type = NULL;
12431
12432 if (func_die)
12433 func_type = get_die_type (func_die, cu);
12434 if (func_type != NULL)
12435 {
12436 gdb_assert (func_type->code () == TYPE_CODE_FUNC);
12437
12438 /* Enlist this call site to the function. */
12441 }
12442 else
12443 complaint (_("Cannot find function owning DW_TAG_call_site "
12444 "DIE %s [in module %s]"),
12446 }
12447 }
12448
12449 attr = dwarf2_attr (die, DW_AT_call_target, cu);
12450 if (attr == NULL)
12451 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
12452 if (attr == NULL)
12453 attr = dwarf2_attr (die, DW_AT_call_origin, cu);
12454 if (attr == NULL)
12455 {
12456 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
12457 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
12458 }
12459
12460 call_site->target.set_loc_dwarf_block (nullptr);
12461 if (!attr || (attr->form_is_block () && attr->as_block ()->size == 0))
12462 /* Keep NULL DWARF_BLOCK. */;
12463 else if (attr->form_is_block ())
12464 {
12465 struct dwarf2_locexpr_baton *dlbaton;
12466 struct dwarf_block *block = attr->as_block ();
12467
12468 dlbaton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
12469 dlbaton->data = block->data;
12470 dlbaton->size = block->size;
12471 dlbaton->per_objfile = per_objfile;
12472 dlbaton->per_cu = cu->per_cu;
12473
12474 call_site->target.set_loc_dwarf_block (dlbaton);
12475 }
12476 else if (attr->form_is_ref ())
12477 {
12478 struct dwarf2_cu *target_cu = cu;
12479 struct die_info *target_die;
12480
12481 target_die = follow_die_ref (die, attr, &target_cu);
12482 gdb_assert (target_cu->per_objfile->objfile == objfile);
12483
12484 struct attribute *ranges_attr
12485 = dwarf2_attr (target_die, DW_AT_ranges, target_cu);
12486
12487 if (die_is_declaration (target_die, target_cu))
12488 {
12489 const char *target_physname;
12490
12491 /* Prefer the mangled name; otherwise compute the demangled one. */
12492 target_physname = dw2_linkage_name (target_die, target_cu);
12493 if (target_physname == NULL)
12494 target_physname = dwarf2_physname (NULL, target_die, target_cu);
12495 if (target_physname == NULL)
12496 complaint (_("DW_AT_call_target target DIE has invalid "
12497 "physname, for referencing DIE %s [in module %s]"),
12499 else
12500 call_site->target.set_loc_physname (target_physname);
12501 }
12502 else if (ranges_attr != nullptr && ranges_attr->form_is_unsigned ())
12503 {
12504 ULONGEST ranges_offset = (ranges_attr->as_unsigned ()
12505 + target_cu->gnu_ranges_base);
12506 std::vector<CORE_ADDR> addresses;
12507 dwarf2_ranges_read_low_addrs (ranges_offset, target_cu,
12508 target_die->tag, addresses);
12509 CORE_ADDR *saved = XOBNEWVAR (&objfile->objfile_obstack, CORE_ADDR,
12510 addresses.size ());
12511 std::copy (addresses.begin (), addresses.end (), saved);
12512 call_site->target.set_loc_array (addresses.size (), saved);
12513 }
12514 else
12515 {
12516 CORE_ADDR lowpc;
12517
12518 /* DW_AT_entry_pc should be preferred. */
12519 if (dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu,
12520 nullptr, nullptr)
12522 complaint (_("DW_AT_call_target target DIE has invalid "
12523 "low pc, for referencing DIE %s [in module %s]"),
12525 else
12526 {
12527 lowpc = (gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr)
12528 - baseaddr);
12529 call_site->target.set_loc_physaddr (lowpc);
12530 }
12531 }
12532 }
12533 else
12534 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
12535 "block nor reference, for DIE %s [in module %s]"),
12537
12538 for (child_die = die->child;
12539 child_die && child_die->tag;
12540 child_die = child_die->sibling)
12541 {
12542 struct call_site_parameter *parameter;
12543 struct attribute *loc, *origin;
12544
12545 if (child_die->tag != DW_TAG_call_site_parameter
12546 && child_die->tag != DW_TAG_GNU_call_site_parameter)
12547 {
12548 /* Already printed the complaint above. */
12549 continue;
12550 }
12551
12552 gdb_assert (call_site->parameter_count < nparams);
12554
12555 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
12556 specifies DW_TAG_formal_parameter. Value of the data assumed for the
12557 register is contained in DW_AT_call_value. */
12558
12559 loc = dwarf2_attr (child_die, DW_AT_location, cu);
12560 origin = dwarf2_attr (child_die, DW_AT_call_parameter, cu);
12561 if (origin == NULL)
12562 {
12563 /* This was a pre-DWARF-5 GNU extension alias
12564 for DW_AT_call_parameter. */
12565 origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu);
12566 }
12567 if (loc == NULL && origin != NULL && origin->form_is_ref ())
12568 {
12570
12571 sect_offset sect_off = origin->get_ref_die_offset ();
12572 if (!cu->header.offset_in_cu_p (sect_off))
12573 {
12574 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
12575 binding can be done only inside one CU. Such referenced DIE
12576 therefore cannot be even moved to DW_TAG_partial_unit. */
12577 complaint (_("DW_AT_call_parameter offset is not in CU for "
12578 "DW_TAG_call_site child DIE %s [in module %s]"),
12579 sect_offset_str (child_die->sect_off),
12581 continue;
12582 }
12583 parameter->u.param_cu_off
12584 = (cu_offset) (sect_off - cu->header.sect_off);
12585 }
12586 else if (loc == NULL || origin != NULL || !loc->form_is_block ())
12587 {
12588 complaint (_("No DW_FORM_block* DW_AT_location for "
12589 "DW_TAG_call_site child DIE %s [in module %s]"),
12591 continue;
12592 }
12593 else
12594 {
12595 struct dwarf_block *block = loc->as_block ();
12596
12598 (block->data, &block->data[block->size]);
12599 if (parameter->u.dwarf_reg != -1)
12601 else if (dwarf_block_to_sp_offset (gdbarch, block->data,
12602 &block->data[block->size],
12603 &parameter->u.fb_offset))
12605 else
12606 {
12607 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
12608 "for DW_FORM_block* DW_AT_location is supported for "
12609 "DW_TAG_call_site child DIE %s "
12610 "[in module %s]"),
12611 sect_offset_str (child_die->sect_off),
12613 continue;
12614 }
12615 }
12616
12617 attr = dwarf2_attr (child_die, DW_AT_call_value, cu);
12618 if (attr == NULL)
12619 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
12620 if (attr == NULL || !attr->form_is_block ())
12621 {
12622 complaint (_("No DW_FORM_block* DW_AT_call_value for "
12623 "DW_TAG_call_site child DIE %s [in module %s]"),
12624 sect_offset_str (child_die->sect_off),
12626 continue;
12627 }
12628
12629 struct dwarf_block *block = attr->as_block ();
12630 parameter->value = block->data;
12631 parameter->value_size = block->size;
12632
12633 /* Parameters are not pre-cleared by memset above. */
12634 parameter->data_value = NULL;
12635 parameter->data_value_size = 0;
12637
12638 attr = dwarf2_attr (child_die, DW_AT_call_data_value, cu);
12639 if (attr == NULL)
12640 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
12641 if (attr != nullptr)
12642 {
12643 if (!attr->form_is_block ())
12644 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
12645 "DW_TAG_call_site child DIE %s [in module %s]"),
12646 sect_offset_str (child_die->sect_off),
12648 else
12649 {
12650 block = attr->as_block ();
12651 parameter->data_value = block->data;
12652 parameter->data_value_size = block->size;
12653 }
12654 }
12655 }
12656}
12657
12658/* Helper function for read_variable. If DIE represents a virtual
12659 table, then return the type of the concrete object that is
12660 associated with the virtual table. Otherwise, return NULL. */
12661
12662static struct type *
12663rust_containing_type (struct die_info *die, struct dwarf2_cu *cu)
12664{
12665 struct attribute *attr = dwarf2_attr (die, DW_AT_type, cu);
12666 if (attr == NULL)
12667 return NULL;
12668
12669 /* Find the type DIE. */
12670 struct die_info *type_die = NULL;
12671 struct dwarf2_cu *type_cu = cu;
12672
12673 if (attr->form_is_ref ())
12674 type_die = follow_die_ref (die, attr, &type_cu);
12675 if (type_die == NULL)
12676 return NULL;
12677
12678 if (dwarf2_attr (type_die, DW_AT_containing_type, type_cu) == NULL)
12679 return NULL;
12680 return die_containing_type (type_die, type_cu);
12681}
12682
12683/* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
12684
12685static void
12686read_variable (struct die_info *die, struct dwarf2_cu *cu)
12687{
12688 struct rust_vtable_symbol *storage = NULL;
12689
12690 if (cu->lang () == language_rust)
12691 {
12692 struct type *containing_type = rust_containing_type (die, cu);
12693
12694 if (containing_type != NULL)
12695 {
12696 struct objfile *objfile = cu->per_objfile->objfile;
12697
12698 storage = new (&objfile->objfile_obstack) rust_vtable_symbol;
12699 storage->concrete_type = containing_type;
12700 storage->subclass = SYMBOL_RUST_VTABLE;
12701 }
12702 }
12703
12704 struct symbol *res = new_symbol (die, NULL, cu, storage);
12705 struct attribute *abstract_origin
12706 = dwarf2_attr (die, DW_AT_abstract_origin, cu);
12707 struct attribute *loc = dwarf2_attr (die, DW_AT_location, cu);
12708 if (res == NULL && loc && abstract_origin)
12709 {
12710 /* We have a variable without a name, but with a location and an abstract
12711 origin. This may be a concrete instance of an abstract variable
12712 referenced from an DW_OP_GNU_variable_value, so save it to find it back
12713 later. */
12714 struct dwarf2_cu *origin_cu = cu;
12715 struct die_info *origin_die
12716 = follow_die_ref (die, abstract_origin, &origin_cu);
12717 dwarf2_per_objfile *per_objfile = cu->per_objfile;
12718 per_objfile->per_bfd->abstract_to_concrete
12719 [origin_die->sect_off].push_back (die->sect_off);
12720 }
12721}
12722
12723/* Call CALLBACK from DW_AT_ranges attribute value OFFSET
12724 reading .debug_rnglists.
12725 Callback's type should be:
12726 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12727 Return true if the attributes are present and valid, otherwise,
12728 return false. */
12729
12730template <typename Callback>
12731static bool
12732dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
12733 dwarf_tag tag, Callback &&callback)
12734{
12735 dwarf2_per_objfile *per_objfile = cu->per_objfile;
12736 struct objfile *objfile = per_objfile->objfile;
12737 bfd *obfd = objfile->obfd.get ();
12738 /* Base address selection entry. */
12739 gdb::optional<CORE_ADDR> base;
12740 const gdb_byte *buffer;
12741 bool overflow = false;
12742 ULONGEST addr_index;
12743 struct dwarf2_section_info *rnglists_section;
12744
12745 base = cu->base_address;
12746 rnglists_section = cu_debug_rnglists_section (cu, tag);
12747 rnglists_section->read (objfile);
12748
12749 if (offset >= rnglists_section->size)
12750 {
12751 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
12752 offset);
12753 return false;
12754 }
12755 buffer = rnglists_section->buffer + offset;
12756
12757 while (1)
12758 {
12759 /* Initialize it due to a false compiler warning. */
12760 CORE_ADDR range_beginning = 0, range_end = 0;
12761 const gdb_byte *buf_end = (rnglists_section->buffer
12762 + rnglists_section->size);
12763 unsigned int bytes_read;
12764
12765 if (buffer == buf_end)
12766 {
12767 overflow = true;
12768 break;
12769 }
12770 const auto rlet = static_cast<enum dwarf_range_list_entry>(*buffer++);
12771 switch (rlet)
12772 {
12773 case DW_RLE_end_of_list:
12774 break;
12775 case DW_RLE_base_address:
12776 if (buffer + cu->header.addr_size > buf_end)
12777 {
12778 overflow = true;
12779 break;
12780 }
12781 base = cu->header.read_address (obfd, buffer, &bytes_read);
12782 buffer += bytes_read;
12783 break;
12784 case DW_RLE_base_addressx:
12785 addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
12786 buffer += bytes_read;
12787 base = read_addr_index (cu, addr_index);
12788 break;
12789 case DW_RLE_start_length:
12790 if (buffer + cu->header.addr_size > buf_end)
12791 {
12792 overflow = true;
12793 break;
12794 }
12795 range_beginning = cu->header.read_address (obfd, buffer,
12796 &bytes_read);
12797 buffer += bytes_read;
12798 range_end = (range_beginning
12799 + read_unsigned_leb128 (obfd, buffer, &bytes_read));
12800 buffer += bytes_read;
12801 if (buffer > buf_end)
12802 {
12803 overflow = true;
12804 break;
12805 }
12806 break;
12807 case DW_RLE_startx_length:
12808 addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
12809 buffer += bytes_read;
12810 range_beginning = read_addr_index (cu, addr_index);
12811 if (buffer > buf_end)
12812 {
12813 overflow = true;
12814 break;
12815 }
12816 range_end = (range_beginning
12817 + read_unsigned_leb128 (obfd, buffer, &bytes_read));
12818 buffer += bytes_read;
12819 break;
12820 case DW_RLE_offset_pair:
12821 range_beginning = read_unsigned_leb128 (obfd, buffer, &bytes_read);
12822 buffer += bytes_read;
12823 if (buffer > buf_end)
12824 {
12825 overflow = true;
12826 break;
12827 }
12828 range_end = read_unsigned_leb128 (obfd, buffer, &bytes_read);
12829 buffer += bytes_read;
12830 if (buffer > buf_end)
12831 {
12832 overflow = true;
12833 break;
12834 }
12835 break;
12836 case DW_RLE_start_end:
12837 if (buffer + 2 * cu->header.addr_size > buf_end)
12838 {
12839 overflow = true;
12840 break;
12841 }
12842 range_beginning = cu->header.read_address (obfd, buffer,
12843 &bytes_read);
12844 buffer += bytes_read;
12845 range_end = cu->header.read_address (obfd, buffer, &bytes_read);
12846 buffer += bytes_read;
12847 break;
12848 case DW_RLE_startx_endx:
12849 addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
12850 buffer += bytes_read;
12851 range_beginning = read_addr_index (cu, addr_index);
12852 if (buffer > buf_end)
12853 {
12854 overflow = true;
12855 break;
12856 }
12857 addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
12858 buffer += bytes_read;
12859 range_end = read_addr_index (cu, addr_index);
12860 break;
12861 default:
12862 complaint (_("Invalid .debug_rnglists data (no base address)"));
12863 return false;
12864 }
12865 if (rlet == DW_RLE_end_of_list || overflow)
12866 break;
12867 if (rlet == DW_RLE_base_address)
12868 continue;
12869
12870 if (range_beginning > range_end)
12871 {
12872 /* Inverted range entries are invalid. */
12873 complaint (_("Invalid .debug_rnglists data (inverted range)"));
12874 return false;
12875 }
12876
12877 /* Empty range entries have no effect. */
12878 if (range_beginning == range_end)
12879 continue;
12880
12881 /* Only DW_RLE_offset_pair needs the base address added. */
12882 if (rlet == DW_RLE_offset_pair)
12883 {
12884 if (!base.has_value ())
12885 {
12886 /* We have no valid base address for the DW_RLE_offset_pair. */
12887 complaint (_("Invalid .debug_rnglists data (no base address for "
12888 "DW_RLE_offset_pair)"));
12889 return false;
12890 }
12891
12892 range_beginning += *base;
12893 range_end += *base;
12894 }
12895
12896 /* A not-uncommon case of bad debug info.
12897 Don't pollute the addrmap with bad data. */
12898 if (range_beginning == 0
12899 && !per_objfile->per_bfd->has_section_at_zero)
12900 {
12901 complaint (_(".debug_rnglists entry has start address of zero"
12902 " [in module %s]"), objfile_name (objfile));
12903 continue;
12904 }
12905
12906 callback (range_beginning, range_end);
12907 }
12908
12909 if (overflow)
12910 {
12911 complaint (_("Offset %d is not terminated "
12912 "for DW_AT_ranges attribute"),
12913 offset);
12914 return false;
12915 }
12916
12917 return true;
12918}
12919
12920/* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
12921 Callback's type should be:
12922 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12923 Return 1 if the attributes are present and valid, otherwise, return 0. */
12924
12925template <typename Callback>
12926static int
12927dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag,
12928 Callback &&callback)
12929{
12930 dwarf2_per_objfile *per_objfile = cu->per_objfile;
12931 struct objfile *objfile = per_objfile->objfile;
12932 struct comp_unit_head *cu_header = &cu->header;
12933 bfd *obfd = objfile->obfd.get ();
12934 unsigned int addr_size = cu_header->addr_size;
12935 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
12936 /* Base address selection entry. */
12937 gdb::optional<CORE_ADDR> base;
12938 unsigned int dummy;
12939 const gdb_byte *buffer;
12940
12941 if (cu_header->version >= 5)
12942 return dwarf2_rnglists_process (offset, cu, tag, callback);
12943
12944 base = cu->base_address;
12945
12946 per_objfile->per_bfd->ranges.read (objfile);
12947 if (offset >= per_objfile->per_bfd->ranges.size)
12948 {
12949 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
12950 offset);
12951 return 0;
12952 }
12953 buffer = per_objfile->per_bfd->ranges.buffer + offset;
12954
12955 while (1)
12956 {
12957 CORE_ADDR range_beginning, range_end;
12958
12959 range_beginning = cu->header.read_address (obfd, buffer, &dummy);
12960 buffer += addr_size;
12961 range_end = cu->header.read_address (obfd, buffer, &dummy);
12962 buffer += addr_size;
12963 offset += 2 * addr_size;
12964
12965 /* An end of list marker is a pair of zero addresses. */
12966 if (range_beginning == 0 && range_end == 0)
12967 /* Found the end of list entry. */
12968 break;
12969
12970 /* Each base address selection entry is a pair of 2 values.
12971 The first is the largest possible address, the second is
12972 the base address. Check for a base address here. */
12973 if ((range_beginning & mask) == mask)
12974 {
12975 /* If we found the largest possible address, then we already
12976 have the base address in range_end. */
12977 base = range_end;
12978 continue;
12979 }
12980
12981 if (!base.has_value ())
12982 {
12983 /* We have no valid base address for the ranges
12984 data. */
12985 complaint (_("Invalid .debug_ranges data (no base address)"));
12986 return 0;
12987 }
12988
12989 if (range_beginning > range_end)
12990 {
12991 /* Inverted range entries are invalid. */
12992 complaint (_("Invalid .debug_ranges data (inverted range)"));
12993 return 0;
12994 }
12995
12996 /* Empty range entries have no effect. */
12997 if (range_beginning == range_end)
12998 continue;
12999
13000 range_beginning += *base;
13001 range_end += *base;
13002
13003 /* A not-uncommon case of bad debug info.
13004 Don't pollute the addrmap with bad data. */
13005 if (range_beginning == 0
13006 && !per_objfile->per_bfd->has_section_at_zero)
13007 {
13008 complaint (_(".debug_ranges entry has start address of zero"
13009 " [in module %s]"), objfile_name (objfile));
13010 continue;
13011 }
13012
13013 callback (range_beginning, range_end);
13014 }
13015
13016 return 1;
13017}
13018
13019/* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13020 Return 1 if the attributes are present and valid, otherwise, return 0.
13021 TAG is passed to dwarf2_ranges_process. If MAP is not NULL, then
13022 ranges in MAP are set, using DATUM as the value. */
13023
13024static int
13025dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
13026 CORE_ADDR *high_return, struct dwarf2_cu *cu,
13027 addrmap *map, void *datum, dwarf_tag tag)
13028{
13029 struct objfile *objfile = cu->per_objfile->objfile;
13030 struct gdbarch *gdbarch = objfile->arch ();
13031 const CORE_ADDR baseaddr = objfile->text_section_offset ();
13032 int low_set = 0;
13033 CORE_ADDR low = 0;
13034 CORE_ADDR high = 0;
13035 int retval;
13036
13037 retval = dwarf2_ranges_process (offset, cu, tag,
13038 [&] (CORE_ADDR range_beginning, CORE_ADDR range_end)
13039 {
13040 if (map != nullptr)
13041 {
13042 CORE_ADDR lowpc;
13043 CORE_ADDR highpc;
13044
13046 range_beginning + baseaddr)
13047 - baseaddr);
13049 range_end + baseaddr)
13050 - baseaddr);
13051 map->set_empty (lowpc, highpc - 1, datum);
13052 }
13053
13054 /* FIXME: This is recording everything as a low-high
13055 segment of consecutive addresses. We should have a
13056 data structure for discontiguous block ranges
13057 instead. */
13058 if (! low_set)
13059 {
13060 low = range_beginning;
13061 high = range_end;
13062 low_set = 1;
13063 }
13064 else
13065 {
13066 if (range_beginning < low)
13067 low = range_beginning;
13068 if (range_end > high)
13069 high = range_end;
13070 }
13071 });
13072 if (!retval)
13073 return 0;
13074
13075 if (! low_set)
13076 /* If the first entry is an end-of-list marker, the range
13077 describes an empty scope, i.e. no instructions. */
13078 return 0;
13079
13080 if (low_return)
13081 *low_return = low;
13082 if (high_return)
13083 *high_return = high;
13084 return 1;
13085}
13086
13087/* Process ranges and fill in a vector of the low PC values only. */
13088
13089static void
13090dwarf2_ranges_read_low_addrs (unsigned offset, struct dwarf2_cu *cu,
13091 dwarf_tag tag,
13092 std::vector<CORE_ADDR> &result)
13093{
13094 dwarf2_ranges_process (offset, cu, tag,
13095 [&] (CORE_ADDR start, CORE_ADDR end)
13096 {
13097 result.push_back (start);
13098 });
13099}
13100
13101/* Get low and high pc attributes from a die. See enum pc_bounds_kind
13102 definition for the return value. *LOWPC and *HIGHPC are set iff
13103 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13104
13105static enum pc_bounds_kind
13106dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
13107 CORE_ADDR *highpc, struct dwarf2_cu *cu,
13108 addrmap *map, void *datum)
13109{
13110 dwarf2_per_objfile *per_objfile = cu->per_objfile;
13111 struct attribute *attr;
13112 struct attribute *attr_high;
13113 CORE_ADDR low = 0;
13114 CORE_ADDR high = 0;
13115 enum pc_bounds_kind ret;
13116
13117 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
13118 if (attr_high)
13119 {
13120 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
13121 if (attr != nullptr)
13122 {
13123 low = attr->as_address ();
13124 high = attr_high->as_address ();
13125 if (cu->header.version >= 4 && attr_high->form_is_constant ())
13126 high += low;
13127 }
13128 else
13129 /* Found high w/o low attribute. */
13130 return PC_BOUNDS_INVALID;
13131
13132 /* Found consecutive range of addresses. */
13133 ret = PC_BOUNDS_HIGH_LOW;
13134 }
13135 else
13136 {
13137 attr = dwarf2_attr (die, DW_AT_ranges, cu);
13138 if (attr != nullptr && attr->form_is_unsigned ())
13139 {
13140 /* Offset in the .debug_ranges or .debug_rnglist section (depending
13141 on DWARF version). */
13142 ULONGEST ranges_offset = attr->as_unsigned ();
13143
13144 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
13145 this value. */
13146 if (die->tag != DW_TAG_compile_unit)
13147 ranges_offset += cu->gnu_ranges_base;
13148
13149 /* Value of the DW_AT_ranges attribute is the offset in the
13150 .debug_ranges section. */
13151 if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu,
13152 map, datum, die->tag))
13153 return PC_BOUNDS_INVALID;
13154 /* Found discontinuous range of addresses. */
13155 ret = PC_BOUNDS_RANGES;
13156 }
13157 else
13158 return PC_BOUNDS_NOT_PRESENT;
13159 }
13160
13161 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13162 if (high <= low)
13163 return PC_BOUNDS_INVALID;
13164
13165 /* When using the GNU linker, .gnu.linkonce. sections are used to
13166 eliminate duplicate copies of functions and vtables and such.
13167 The linker will arbitrarily choose one and discard the others.
13168 The AT_*_pc values for such functions refer to local labels in
13169 these sections. If the section from that file was discarded, the
13170 labels are not in the output, so the relocs get a value of 0.
13171 If this is a discarded function, mark the pc bounds as invalid,
13172 so that GDB will ignore it. */
13173 if (low == 0 && !per_objfile->per_bfd->has_section_at_zero)
13174 return PC_BOUNDS_INVALID;
13175
13176 *lowpc = low;
13177 if (highpc)
13178 *highpc = high;
13179 return ret;
13180}
13181
13182/* Assuming that DIE represents a subprogram DIE or a lexical block, get
13183 its low and high PC addresses. Do nothing if these addresses could not
13184 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13185 and HIGHPC to the high address if greater than HIGHPC. */
13186
13187static void
13189 CORE_ADDR *lowpc, CORE_ADDR *highpc,
13190 struct dwarf2_cu *cu)
13191{
13192 CORE_ADDR low, high;
13193 struct die_info *child = die->child;
13194
13195 if (dwarf2_get_pc_bounds (die, &low, &high, cu, nullptr, nullptr)
13197 {
13198 *lowpc = std::min (*lowpc, low);
13199 *highpc = std::max (*highpc, high);
13200 }
13201
13202 /* If the language does not allow nested subprograms (either inside
13203 subprograms or lexical blocks), we're done. */
13204 if (cu->lang () != language_ada)
13205 return;
13206
13207 /* Check all the children of the given DIE. If it contains nested
13208 subprograms, then check their pc bounds. Likewise, we need to
13209 check lexical blocks as well, as they may also contain subprogram
13210 definitions. */
13211 while (child && child->tag)
13212 {
13213 if (child->tag == DW_TAG_subprogram
13214 || child->tag == DW_TAG_lexical_block)
13215 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
13216 child = child->sibling;
13217 }
13218}
13219
13220/* Get the low and high pc's represented by the scope DIE, and store
13221 them in *LOWPC and *HIGHPC. If the correct values can't be
13222 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13223
13224static void
13226 CORE_ADDR *lowpc, CORE_ADDR *highpc,
13227 struct dwarf2_cu *cu)
13228{
13229 CORE_ADDR best_low = (CORE_ADDR) -1;
13230 CORE_ADDR best_high = (CORE_ADDR) 0;
13231 CORE_ADDR current_low, current_high;
13232
13233 if (dwarf2_get_pc_bounds (die, &current_low, &current_high, cu,
13234 nullptr, nullptr)
13236 {
13237 best_low = current_low;
13238 best_high = current_high;
13239 }
13240 else
13241 {
13242 struct die_info *child = die->child;
13243
13244 while (child && child->tag)
13245 {
13246 switch (child->tag) {
13247 case DW_TAG_subprogram:
13248 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
13249 break;
13250 case DW_TAG_namespace:
13251 case DW_TAG_module:
13252 /* FIXME: carlton/2004-01-16: Should we do this for
13253 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13254 that current GCC's always emit the DIEs corresponding
13255 to definitions of methods of classes as children of a
13256 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13257 the DIEs giving the declarations, which could be
13258 anywhere). But I don't see any reason why the
13259 standards says that they have to be there. */
13260 get_scope_pc_bounds (child, &current_low, &current_high, cu);
13261
13262 if (current_low != ((CORE_ADDR) -1))
13263 {
13264 best_low = std::min (best_low, current_low);
13265 best_high = std::max (best_high, current_high);
13266 }
13267 break;
13268 default:
13269 /* Ignore. */
13270 break;
13271 }
13272
13273 child = child->sibling;
13274 }
13275 }
13276
13277 *lowpc = best_low;
13278 *highpc = best_high;
13279}
13280
13281/* Record the address ranges for BLOCK, offset by BASEADDR, as given
13282 in DIE. */
13283
13284static void
13286 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
13287{
13288 struct objfile *objfile = cu->per_objfile->objfile;
13289 struct gdbarch *gdbarch = objfile->arch ();
13290 struct attribute *attr;
13291 struct attribute *attr_high;
13292
13293 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
13294 if (attr_high)
13295 {
13296 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
13297 if (attr != nullptr)
13298 {
13299 CORE_ADDR low = attr->as_address ();
13300 CORE_ADDR high = attr_high->as_address ();
13301
13302 if (cu->header.version >= 4 && attr_high->form_is_constant ())
13303 high += low;
13304
13305 low = gdbarch_adjust_dwarf2_addr (gdbarch, low + baseaddr);
13306 high = gdbarch_adjust_dwarf2_addr (gdbarch, high + baseaddr);
13307 cu->get_builder ()->record_block_range (block, low, high - 1);
13308 }
13309 }
13310
13311 attr = dwarf2_attr (die, DW_AT_ranges, cu);
13312 if (attr != nullptr && attr->form_is_unsigned ())
13313 {
13314 /* Offset in the .debug_ranges or .debug_rnglist section (depending
13315 on DWARF version). */
13316 ULONGEST ranges_offset = attr->as_unsigned ();
13317
13318 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
13319 this value. */
13320 if (die->tag != DW_TAG_compile_unit)
13321 ranges_offset += cu->gnu_ranges_base;
13322
13323 std::vector<blockrange> blockvec;
13324 dwarf2_ranges_process (ranges_offset, cu, die->tag,
13325 [&] (CORE_ADDR start, CORE_ADDR end)
13326 {
13327 start += baseaddr;
13328 end += baseaddr;
13329 start = gdbarch_adjust_dwarf2_addr (gdbarch, start);
13330 end = gdbarch_adjust_dwarf2_addr (gdbarch, end);
13331 cu->get_builder ()->record_block_range (block, start, end - 1);
13332 blockvec.emplace_back (start, end);
13333 });
13334
13336 }
13337}
13338
13339/* Check whether the producer field indicates either of GCC < 4.6, or the
13340 Intel C/C++ compiler, and cache the result in CU. */
13341
13342static void
13344{
13345 int major, minor;
13346
13347 if (cu->producer == NULL)
13348 {
13349 /* For unknown compilers expect their behavior is DWARF version
13350 compliant.
13351
13352 GCC started to support .debug_types sections by -gdwarf-4 since
13353 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
13354 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
13355 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
13356 interpreted incorrectly by GDB now - GCC PR debug/48229. */
13357 }
13358 else if (producer_is_gcc (cu->producer, &major, &minor))
13359 {
13360 cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
13361 cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
13362 cu->producer_is_gcc_11 = major == 11;
13363 }
13364 else if (producer_is_icc (cu->producer, &major, &minor))
13365 {
13366 cu->producer_is_icc = true;
13367 cu->producer_is_icc_lt_14 = major < 14;
13368 }
13369 else if (startswith (cu->producer, "CodeWarrior S12/L-ISA"))
13370 cu->producer_is_codewarrior = true;
13371 else if (producer_is_clang (cu->producer, &major, &minor))
13372 cu->producer_is_clang = true;
13373 else
13374 {
13375 /* For other non-GCC compilers, expect their behavior is DWARF version
13376 compliant. */
13377 }
13378
13379 cu->checked_producer = true;
13380}
13381
13382/* Check for GCC PR debug/45124 fix which is not present in any G++ version up
13383 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
13384 during 4.6.0 experimental. */
13385
13386static bool
13388{
13389 if (!cu->checked_producer)
13390 check_producer (cu);
13391
13392 return cu->producer_is_gxx_lt_4_6;
13393}
13394
13395
13396/* Codewarrior (at least as of version 5.0.40) generates dwarf line information
13397 with incorrect is_stmt attributes. */
13398
13399static bool
13401{
13402 if (!cu->checked_producer)
13403 check_producer (cu);
13404
13405 return cu->producer_is_codewarrior;
13406}
13407
13408/* Return the accessibility of DIE, as given by DW_AT_accessibility.
13409 If that attribute is not available, return the appropriate
13410 default. */
13411
13412static enum dwarf_access_attribute
13414{
13415 attribute *attr = dwarf2_attr (die, DW_AT_accessibility, cu);
13416 if (attr != nullptr)
13417 {
13418 LONGEST value = attr->constant_value (-1);
13419 if (value == DW_ACCESS_public
13420 || value == DW_ACCESS_protected
13421 || value == DW_ACCESS_private)
13422 return (dwarf_access_attribute) value;
13423 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
13424 plongest (value));
13425 }
13426
13427 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
13428 {
13429 /* The default DWARF 2 accessibility for members is public, the default
13430 accessibility for inheritance is private. */
13431
13432 if (die->tag != DW_TAG_inheritance)
13433 return DW_ACCESS_public;
13434 else
13435 return DW_ACCESS_private;
13436 }
13437 else
13438 {
13439 /* DWARF 3+ defines the default accessibility a different way. The same
13440 rules apply now for DW_TAG_inheritance as for the members and it only
13441 depends on the container kind. */
13442
13443 if (die->parent->tag == DW_TAG_class_type)
13444 return DW_ACCESS_private;
13445 else
13446 return DW_ACCESS_public;
13447 }
13448}
13449
13450/* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
13451 *OFFSET to the byte offset. If the attribute was not found return
13452 0, otherwise return 1. If it was found but could not properly be
13453 handled, set *OFFSET to 0. */
13454
13455static int
13457 LONGEST *offset)
13458{
13459 struct attribute *attr;
13460
13461 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
13462 if (attr != NULL)
13463 {
13464 *offset = 0;
13465
13466 /* Note that we do not check for a section offset first here.
13467 This is because DW_AT_data_member_location is new in DWARF 4,
13468 so if we see it, we can assume that a constant form is really
13469 a constant and not a section offset. */
13470 if (attr->form_is_constant ())
13471 *offset = attr->constant_value (0);
13472 else if (attr->form_is_section_offset ())
13474 else if (attr->form_is_block ())
13475 *offset = decode_locdesc (attr->as_block (), cu);
13476 else
13478
13479 return 1;
13480 }
13481 else
13482 {
13483 attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
13484 if (attr != nullptr)
13485 {
13486 *offset = attr->constant_value (0);
13487 return 1;
13488 }
13489 }
13490
13491 return 0;
13492}
13493
13494/* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
13495 store the results in FIELD. */
13496
13497static void
13499 struct field *field)
13500{
13501 struct attribute *attr;
13502
13503 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
13504 if (attr != NULL)
13505 {
13506 if (attr->form_is_constant ())
13507 {
13508 LONGEST offset = attr->constant_value (0);
13509
13510 /* Work around this GCC 11 bug, where it would erroneously use -1
13511 data member locations, instead of 0:
13512
13513 Negative DW_AT_data_member_location
13514 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
13515 */
13516 if (offset == -1 && cu->producer_is_gcc_11)
13517 {
13518 complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
13519 offset = 0;
13520 }
13521
13523 }
13524 else if (attr->form_is_section_offset ())
13526 else if (attr->form_is_block ())
13527 {
13528 bool handled;
13529 CORE_ADDR offset = decode_locdesc (attr->as_block (), cu, &handled);
13530 if (handled)
13532 else
13533 {
13534 dwarf2_per_objfile *per_objfile = cu->per_objfile;
13535 struct objfile *objfile = per_objfile->objfile;
13536 struct dwarf2_locexpr_baton *dlbaton
13537 = XOBNEW (&objfile->objfile_obstack,
13538 struct dwarf2_locexpr_baton);
13539 dlbaton->data = attr->as_block ()->data;
13540 dlbaton->size = attr->as_block ()->size;
13541 /* When using this baton, we want to compute the address
13542 of the field, not the value. This is why
13543 is_reference is set to false here. */
13544 dlbaton->is_reference = false;
13545 dlbaton->per_objfile = per_objfile;
13546 dlbaton->per_cu = cu->per_cu;
13547
13548 field->set_loc_dwarf_block (dlbaton);
13549 }
13550 }
13551 else
13553 }
13554 else
13555 {
13556 attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
13557 if (attr != nullptr)
13558 field->set_loc_bitpos (attr->constant_value (0));
13559 }
13560}
13561
13562/* Add an aggregate field to the field list. */
13563
13564static void
13565dwarf2_add_field (struct field_info *fip, struct die_info *die,
13566 struct dwarf2_cu *cu)
13567{
13568 struct objfile *objfile = cu->per_objfile->objfile;
13569 struct gdbarch *gdbarch = objfile->arch ();
13570 struct nextfield *new_field;
13571 struct attribute *attr;
13572 struct field *fp;
13573 const char *fieldname = "";
13574
13575 if (die->tag == DW_TAG_inheritance)
13576 {
13577 fip->baseclasses.emplace_back ();
13578 new_field = &fip->baseclasses.back ();
13579 }
13580 else
13581 {
13582 fip->fields.emplace_back ();
13583 new_field = &fip->fields.back ();
13584 }
13585
13586 new_field->offset = die->sect_off;
13587
13588 new_field->accessibility = dwarf2_access_attribute (die, cu);
13589 if (new_field->accessibility != DW_ACCESS_public)
13590 fip->non_public_fields = true;
13591
13592 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
13593 if (attr != nullptr)
13594 new_field->virtuality = attr->as_virtuality ();
13595 else
13596 new_field->virtuality = DW_VIRTUALITY_none;
13597
13598 fp = &new_field->field;
13599
13600 if ((die->tag == DW_TAG_member || die->tag == DW_TAG_namelist_item)
13601 && !die_is_declaration (die, cu))
13602 {
13603 if (die->tag == DW_TAG_namelist_item)
13604 {
13605 /* Typically, DW_TAG_namelist_item are references to namelist items.
13606 If so, follow that reference. */
13607 struct attribute *attr1 = dwarf2_attr (die, DW_AT_namelist_item, cu);
13608 struct die_info *item_die = nullptr;
13609 struct dwarf2_cu *item_cu = cu;
13610 if (attr1->form_is_ref ())
13611 item_die = follow_die_ref (die, attr1, &item_cu);
13612 if (item_die != nullptr)
13613 die = item_die;
13614 }
13615 /* Data member other than a C++ static data member. */
13616
13617 /* Get type of field. */
13618 fp->set_type (die_type (die, cu));
13619
13620 fp->set_loc_bitpos (0);
13621
13622 /* Get bit size of field (zero if none). */
13623 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
13624 if (attr != nullptr)
13625 {
13626 FIELD_BITSIZE (*fp) = attr->constant_value (0);
13627 }
13628 else
13629 {
13630 FIELD_BITSIZE (*fp) = 0;
13631 }
13632
13633 /* Get bit offset of field. */
13634 handle_member_location (die, cu, fp);
13635 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
13636 if (attr != nullptr && attr->form_is_constant ())
13637 {
13638 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
13639 {
13640 /* For big endian bits, the DW_AT_bit_offset gives the
13641 additional bit offset from the MSB of the containing
13642 anonymous object to the MSB of the field. We don't
13643 have to do anything special since we don't need to
13644 know the size of the anonymous object. */
13645 fp->set_loc_bitpos (fp->loc_bitpos () + attr->constant_value (0));
13646 }
13647 else
13648 {
13649 /* For little endian bits, compute the bit offset to the
13650 MSB of the anonymous object, subtract off the number of
13651 bits from the MSB of the field to the MSB of the
13652 object, and then subtract off the number of bits of
13653 the field itself. The result is the bit offset of
13654 the LSB of the field. */
13655 int anonymous_size;
13656 int bit_offset = attr->constant_value (0);
13657
13658 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
13659 if (attr != nullptr && attr->form_is_constant ())
13660 {
13661 /* The size of the anonymous object containing
13662 the bit field is explicit, so use the
13663 indicated size (in bytes). */
13664 anonymous_size = attr->constant_value (0);
13665 }
13666 else
13667 {
13668 /* The size of the anonymous object containing
13669 the bit field must be inferred from the type
13670 attribute of the data member containing the
13671 bit field. */
13672 anonymous_size = fp->type ()->length ();
13673 }
13674 fp->set_loc_bitpos (fp->loc_bitpos ()
13675 + anonymous_size * bits_per_byte
13676 - bit_offset - FIELD_BITSIZE (*fp));
13677 }
13678 }
13679
13680 /* Get name of field. */
13681 fieldname = dwarf2_name (die, cu);
13682 if (fieldname == NULL)
13683 fieldname = "";
13684
13685 /* The name is already allocated along with this objfile, so we don't
13686 need to duplicate it for the type. */
13687 fp->set_name (fieldname);
13688
13689 /* Change accessibility for artificial fields (e.g. virtual table
13690 pointer or virtual base class pointer) to private. */
13691 if (dwarf2_attr (die, DW_AT_artificial, cu))
13692 {
13693 FIELD_ARTIFICIAL (*fp) = 1;
13694 new_field->accessibility = DW_ACCESS_private;
13695 fip->non_public_fields = true;
13696 }
13697 }
13698 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
13699 {
13700 /* C++ static member. */
13701
13702 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
13703 is a declaration, but all versions of G++ as of this writing
13704 (so through at least 3.2.1) incorrectly generate
13705 DW_TAG_variable tags. */
13706
13707 const char *physname;
13708
13709 /* Get name of field. */
13710 fieldname = dwarf2_name (die, cu);
13711 if (fieldname == NULL)
13712 return;
13713
13714 attr = dwarf2_attr (die, DW_AT_const_value, cu);
13715 if (attr
13716 /* Only create a symbol if this is an external value.
13717 new_symbol checks this and puts the value in the global symbol
13718 table, which we want. If it is not external, new_symbol
13719 will try to put the value in cu->list_in_scope which is wrong. */
13720 && dwarf2_flag_true_p (die, DW_AT_external, cu))
13721 {
13722 /* A static const member, not much different than an enum as far as
13723 we're concerned, except that we can support more types. */
13724 new_symbol (die, NULL, cu);
13725 }
13726
13727 /* Get physical name. */
13728 physname = dwarf2_physname (fieldname, die, cu);
13729
13730 /* The name is already allocated along with this objfile, so we don't
13731 need to duplicate it for the type. */
13732 fp->set_loc_physname (physname ? physname : "");
13733 fp->set_type (die_type (die, cu));
13734 fp->set_name (fieldname);
13735 }
13736 else if (die->tag == DW_TAG_inheritance)
13737 {
13738 /* C++ base class field. */
13739 handle_member_location (die, cu, fp);
13740 FIELD_BITSIZE (*fp) = 0;
13741 fp->set_type (die_type (die, cu));
13742 fp->set_name (fp->type ()->name ());
13743 }
13744 else
13745 gdb_assert_not_reached ("missing case in dwarf2_add_field");
13746}
13747
13748/* Can the type given by DIE define another type? */
13749
13750static bool
13752{
13753 switch (die->tag)
13754 {
13755 case DW_TAG_typedef:
13756 case DW_TAG_class_type:
13757 case DW_TAG_structure_type:
13758 case DW_TAG_union_type:
13759 case DW_TAG_enumeration_type:
13760 return true;
13761
13762 default:
13763 return false;
13764 }
13765}
13766
13767/* Add a type definition defined in the scope of the FIP's class. */
13768
13769static void
13770dwarf2_add_type_defn (struct field_info *fip, struct die_info *die,
13771 struct dwarf2_cu *cu)
13772{
13773 struct decl_field fp;
13774 memset (&fp, 0, sizeof (fp));
13775
13776 gdb_assert (type_can_define_types (die));
13777
13778 /* Get name of field. NULL is okay here, meaning an anonymous type. */
13779 fp.name = dwarf2_name (die, cu);
13780 fp.type = read_type_die (die, cu);
13781
13782 /* Save accessibility. */
13783 dwarf_access_attribute accessibility = dwarf2_access_attribute (die, cu);
13784 switch (accessibility)
13785 {
13786 case DW_ACCESS_public:
13787 /* The assumed value if neither private nor protected. */
13788 break;
13789 case DW_ACCESS_private:
13790 fp.is_private = 1;
13791 break;
13792 case DW_ACCESS_protected:
13793 fp.is_protected = 1;
13794 break;
13795 }
13796
13797 if (die->tag == DW_TAG_typedef)
13798 fip->typedef_field_list.push_back (fp);
13799 else
13800 fip->nested_types_list.push_back (fp);
13801}
13802
13803/* A convenience typedef that's used when finding the discriminant
13804 field for a variant part. */
13805typedef std::unordered_map<sect_offset, int, gdb::hash_enum<sect_offset>>
13807
13808/* Compute the discriminant range for a given variant. OBSTACK is
13809 where the results will be stored. VARIANT is the variant to
13810 process. IS_UNSIGNED indicates whether the discriminant is signed
13811 or unsigned. */
13812
13813static const gdb::array_view<discriminant_range>
13814convert_variant_range (struct obstack *obstack, const variant_field &variant,
13815 bool is_unsigned)
13816{
13817 std::vector<discriminant_range> ranges;
13818
13819 if (variant.default_branch)
13820 return {};
13821
13822 if (variant.discr_list_data == nullptr)
13823 {
13825 = {variant.discriminant_value, variant.discriminant_value};
13826 ranges.push_back (r);
13827 }
13828 else
13829 {
13830 gdb::array_view<const gdb_byte> data (variant.discr_list_data->data,
13831 variant.discr_list_data->size);
13832 while (!data.empty ())
13833 {
13834 if (data[0] != DW_DSC_range && data[0] != DW_DSC_label)
13835 {
13836 complaint (_("invalid discriminant marker: %d"), data[0]);
13837 break;
13838 }
13839 bool is_range = data[0] == DW_DSC_range;
13840 data = data.slice (1);
13841
13842 ULONGEST low, high;
13843 unsigned int bytes_read;
13844
13845 if (data.empty ())
13846 {
13847 complaint (_("DW_AT_discr_list missing low value"));
13848 break;
13849 }
13850 if (is_unsigned)
13851 low = read_unsigned_leb128 (nullptr, data.data (), &bytes_read);
13852 else
13853 low = (ULONGEST) read_signed_leb128 (nullptr, data.data (),
13854 &bytes_read);
13855 data = data.slice (bytes_read);
13856
13857 if (is_range)
13858 {
13859 if (data.empty ())
13860 {
13861 complaint (_("DW_AT_discr_list missing high value"));
13862 break;
13863 }
13864 if (is_unsigned)
13865 high = read_unsigned_leb128 (nullptr, data.data (),
13866 &bytes_read);
13867 else
13868 high = (LONGEST) read_signed_leb128 (nullptr, data.data (),
13869 &bytes_read);
13870 data = data.slice (bytes_read);
13871 }
13872 else
13873 high = low;
13874
13875 ranges.push_back ({ low, high });
13876 }
13877 }
13878
13879 discriminant_range *result = XOBNEWVEC (obstack, discriminant_range,
13880 ranges.size ());
13881 std::copy (ranges.begin (), ranges.end (), result);
13882 return gdb::array_view<discriminant_range> (result, ranges.size ());
13883}
13884
13885static const gdb::array_view<variant_part> create_variant_parts
13886 (struct obstack *obstack,
13887 const offset_map_type &offset_map,
13888 struct field_info *fi,
13889 const std::vector<variant_part_builder> &variant_parts);
13890
13891/* Fill in a "struct variant" for a given variant field. RESULT is
13892 the variant to fill in. OBSTACK is where any needed allocations
13893 will be done. OFFSET_MAP holds the mapping from section offsets to
13894 fields for the type. FI describes the fields of the type we're
13895 processing. FIELD is the variant field we're converting. */
13896
13897static void
13898create_one_variant (variant &result, struct obstack *obstack,
13899 const offset_map_type &offset_map,
13900 struct field_info *fi, const variant_field &field)
13901{
13902 result.discriminants = convert_variant_range (obstack, field, false);
13903 result.first_field = field.first_field + fi->baseclasses.size ();
13904 result.last_field = field.last_field + fi->baseclasses.size ();
13905 result.parts = create_variant_parts (obstack, offset_map, fi,
13906 field.variant_parts);
13907}
13908
13909/* Fill in a "struct variant_part" for a given variant part. RESULT
13910 is the variant part to fill in. OBSTACK is where any needed
13911 allocations will be done. OFFSET_MAP holds the mapping from
13912 section offsets to fields for the type. FI describes the fields of
13913 the type we're processing. BUILDER is the variant part to be
13914 converted. */
13915
13916static void
13918 struct obstack *obstack,
13919 const offset_map_type &offset_map,
13920 struct field_info *fi,
13921 const variant_part_builder &builder)
13922{
13923 auto iter = offset_map.find (builder.discriminant_offset);
13924 if (iter == offset_map.end ())
13925 {
13926 result.discriminant_index = -1;
13927 /* Doesn't matter. */
13928 result.is_unsigned = false;
13929 }
13930 else
13931 {
13932 result.discriminant_index = iter->second;
13933 result.is_unsigned
13934 = fi->fields[result.discriminant_index].field.type ()->is_unsigned ();
13935 }
13936
13937 size_t n = builder.variants.size ();
13938 variant *output = new (obstack) variant[n];
13939 for (size_t i = 0; i < n; ++i)
13940 create_one_variant (output[i], obstack, offset_map, fi,
13941 builder.variants[i]);
13942
13943 result.variants = gdb::array_view<variant> (output, n);
13944}
13945
13946/* Create a vector of variant parts that can be attached to a type.
13947 OBSTACK is where any needed allocations will be done. OFFSET_MAP
13948 holds the mapping from section offsets to fields for the type. FI
13949 describes the fields of the type we're processing. VARIANT_PARTS
13950 is the vector to convert. */
13951
13952static const gdb::array_view<variant_part>
13953create_variant_parts (struct obstack *obstack,
13954 const offset_map_type &offset_map,
13955 struct field_info *fi,
13956 const std::vector<variant_part_builder> &variant_parts)
13957{
13958 if (variant_parts.empty ())
13959 return {};
13960
13961 size_t n = variant_parts.size ();
13962 variant_part *result = new (obstack) variant_part[n];
13963 for (size_t i = 0; i < n; ++i)
13964 create_one_variant_part (result[i], obstack, offset_map, fi,
13965 variant_parts[i]);
13966
13967 return gdb::array_view<variant_part> (result, n);
13968}
13969
13970/* Compute the variant part vector for FIP, attaching it to TYPE when
13971 done. */
13972
13973static void
13975 struct dwarf2_cu *cu)
13976{
13977 /* Map section offsets of fields to their field index. Note the
13978 field index here does not take the number of baseclasses into
13979 account. */
13980 offset_map_type offset_map;
13981 for (int i = 0; i < fip->fields.size (); ++i)
13982 offset_map[fip->fields[i].offset] = i;
13983
13984 struct objfile *objfile = cu->per_objfile->objfile;
13985 gdb::array_view<const variant_part> parts
13986 = create_variant_parts (&objfile->objfile_obstack, offset_map, fip,
13987 fip->variant_parts);
13988
13989 struct dynamic_prop prop;
13990 prop.set_variant_parts ((gdb::array_view<variant_part> *)
13991 obstack_copy (&objfile->objfile_obstack, &parts,
13992 sizeof (parts)));
13993
13995}
13996
13997/* Create the vector of fields, and attach it to the type. */
13998
13999static void
14001 struct dwarf2_cu *cu)
14002{
14003 int nfields = fip->nfields ();
14004
14005 /* Record the field count, allocate space for the array of fields,
14006 and create blank accessibility bitfields if necessary. */
14007 type->set_num_fields (nfields);
14009 ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields));
14010
14011 if (fip->non_public_fields && cu->lang () != language_ada)
14012 {
14014
14016 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
14018
14020 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
14022
14024 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
14026 }
14027
14028 /* If the type has baseclasses, allocate and clear a bit vector for
14029 TYPE_FIELD_VIRTUAL_BITS. */
14030 if (!fip->baseclasses.empty () && cu->lang () != language_ada)
14031 {
14032 int num_bytes = B_BYTES (fip->baseclasses.size ());
14033 unsigned char *pointer;
14034
14036 pointer = (unsigned char *) TYPE_ALLOC (type, num_bytes);
14037 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
14039 TYPE_N_BASECLASSES (type) = fip->baseclasses.size ();
14040 }
14041
14042 if (!fip->variant_parts.empty ())
14043 add_variant_property (fip, type, cu);
14044
14045 /* Copy the saved-up fields into the field vector. */
14046 for (int i = 0; i < nfields; ++i)
14047 {
14048 struct nextfield &field
14049 = ((i < fip->baseclasses.size ()) ? fip->baseclasses[i]
14050 : fip->fields[i - fip->baseclasses.size ()]);
14051
14052 type->field (i) = field.field;
14053 switch (field.accessibility)
14054 {
14055 case DW_ACCESS_private:
14056 if (cu->lang () != language_ada)
14058 break;
14059
14060 case DW_ACCESS_protected:
14061 if (cu->lang () != language_ada)
14063 break;
14064
14065 case DW_ACCESS_public:
14066 break;
14067
14068 default:
14069 /* Unknown accessibility. Complain and treat it as public. */
14070 {
14071 complaint (_("unsupported accessibility %d"),
14072 field.accessibility);
14073 }
14074 break;
14075 }
14076 if (i < fip->baseclasses.size ())
14077 {
14078 switch (field.virtuality)
14079 {
14080 case DW_VIRTUALITY_virtual:
14081 case DW_VIRTUALITY_pure_virtual:
14082 if (cu->lang () == language_ada)
14083 error (_("unexpected virtuality in component of Ada type"));
14085 break;
14086 }
14087 }
14088 }
14089}
14090
14091/* Return true if this member function is a constructor, false
14092 otherwise. */
14093
14094static int
14096{
14097 const char *fieldname;
14098 const char *type_name;
14099 int len;
14100
14101 if (die->parent == NULL)
14102 return 0;
14103
14104 if (die->parent->tag != DW_TAG_structure_type
14105 && die->parent->tag != DW_TAG_union_type
14106 && die->parent->tag != DW_TAG_class_type)
14107 return 0;
14108
14109 fieldname = dwarf2_name (die, cu);
14110 type_name = dwarf2_name (die->parent, cu);
14111 if (fieldname == NULL || type_name == NULL)
14112 return 0;
14113
14114 len = strlen (fieldname);
14115 return (strncmp (fieldname, type_name, len) == 0
14116 && (type_name[len] == '\0' || type_name[len] == '<'));
14117}
14118
14119/* Add a member function to the proper fieldlist. */
14120
14121static void
14122dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
14123 struct type *type, struct dwarf2_cu *cu)
14124{
14125 struct objfile *objfile = cu->per_objfile->objfile;
14126 struct attribute *attr;
14127 int i;
14128 struct fnfieldlist *flp = nullptr;
14129 struct fn_field *fnp;
14130 const char *fieldname;
14131 struct type *this_type;
14132
14133 if (cu->lang () == language_ada)
14134 error (_("unexpected member function in Ada type"));
14135
14136 /* Get name of member function. */
14137 fieldname = dwarf2_name (die, cu);
14138 if (fieldname == NULL)
14139 return;
14140
14141 /* Look up member function name in fieldlist. */
14142 for (i = 0; i < fip->fnfieldlists.size (); i++)
14143 {
14144 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
14145 {
14146 flp = &fip->fnfieldlists[i];
14147 break;
14148 }
14149 }
14150
14151 /* Create a new fnfieldlist if necessary. */
14152 if (flp == nullptr)
14153 {
14154 fip->fnfieldlists.emplace_back ();
14155 flp = &fip->fnfieldlists.back ();
14156 flp->name = fieldname;
14157 i = fip->fnfieldlists.size () - 1;
14158 }
14159
14160 /* Create a new member function field and add it to the vector of
14161 fnfieldlists. */
14162 flp->fnfields.emplace_back ();
14163 fnp = &flp->fnfields.back ();
14164
14165 /* Delay processing of the physname until later. */
14166 if (cu->lang () == language_cplus)
14167 add_to_method_list (type, i, flp->fnfields.size () - 1, fieldname,
14168 die, cu);
14169 else
14170 {
14171 const char *physname = dwarf2_physname (fieldname, die, cu);
14172 fnp->physname = physname ? physname : "";
14173 }
14174
14175 fnp->type = alloc_type (objfile);
14176 this_type = read_type_die (die, cu);
14177 if (this_type && this_type->code () == TYPE_CODE_FUNC)
14178 {
14179 int nparams = this_type->num_fields ();
14180
14181 /* TYPE is the domain of this method, and THIS_TYPE is the type
14182 of the method itself (TYPE_CODE_METHOD). */
14184 this_type->target_type (),
14185 this_type->fields (),
14186 this_type->num_fields (),
14187 this_type->has_varargs ());
14188
14189 /* Handle static member functions.
14190 Dwarf2 has no clean way to discern C++ static and non-static
14191 member functions. G++ helps GDB by marking the first
14192 parameter for non-static member functions (which is the this
14193 pointer) as artificial. We obtain this information from
14194 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14195 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
14196 fnp->voffset = VOFFSET_STATIC;
14197 }
14198 else
14199 complaint (_("member function type missing for '%s'"),
14200 dwarf2_full_name (fieldname, die, cu));
14201
14202 /* Get fcontext from DW_AT_containing_type if present. */
14203 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
14204 fnp->fcontext = die_containing_type (die, cu);
14205
14206 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14207 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14208
14209 /* Get accessibility. */
14210 dwarf_access_attribute accessibility = dwarf2_access_attribute (die, cu);
14211 switch (accessibility)
14212 {
14213 case DW_ACCESS_private:
14214 fnp->is_private = 1;
14215 break;
14216 case DW_ACCESS_protected:
14217 fnp->is_protected = 1;
14218 break;
14219 }
14220
14221 /* Check for artificial methods. */
14222 attr = dwarf2_attr (die, DW_AT_artificial, cu);
14223 if (attr && attr->as_boolean ())
14224 fnp->is_artificial = 1;
14225
14226 /* Check for defaulted methods. */
14227 attr = dwarf2_attr (die, DW_AT_defaulted, cu);
14228 if (attr != nullptr)
14229 fnp->defaulted = attr->defaulted ();
14230
14231 /* Check for deleted methods. */
14232 attr = dwarf2_attr (die, DW_AT_deleted, cu);
14233 if (attr != nullptr && attr->as_boolean ())
14234 fnp->is_deleted = 1;
14235
14236 fnp->is_constructor = dwarf2_is_constructor (die, cu);
14237
14238 /* Get index in virtual function table if it is a virtual member
14239 function. For older versions of GCC, this is an offset in the
14240 appropriate virtual table, as specified by DW_AT_containing_type.
14241 For everyone else, it is an expression to be evaluated relative
14242 to the object address. */
14243
14244 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
14245 if (attr != nullptr)
14246 {
14247 if (attr->form_is_block () && attr->as_block ()->size > 0)
14248 {
14249 struct dwarf_block *block = attr->as_block ();
14250
14251 if (block->data[0] == DW_OP_constu)
14252 {
14253 /* Old-style GCC. */
14254 fnp->voffset = decode_locdesc (block, cu) + 2;
14255 }
14256 else if (block->data[0] == DW_OP_deref
14257 || (block->size > 1
14258 && block->data[0] == DW_OP_deref_size
14259 && block->data[1] == cu->header.addr_size))
14260 {
14261 fnp->voffset = decode_locdesc (block, cu);
14262 if ((fnp->voffset % cu->header.addr_size) != 0)
14264 else
14265 fnp->voffset /= cu->header.addr_size;
14266 fnp->voffset += 2;
14267 }
14268 else
14270
14271 if (!fnp->fcontext)
14272 {
14273 /* If there is no `this' field and no DW_AT_containing_type,
14274 we cannot actually find a base class context for the
14275 vtable! */
14276 if (this_type->num_fields () == 0
14277 || !TYPE_FIELD_ARTIFICIAL (this_type, 0))
14278 {
14279 complaint (_("cannot determine context for virtual member "
14280 "function \"%s\" (offset %s)"),
14281 fieldname, sect_offset_str (die->sect_off));
14282 }
14283 else
14284 {
14285 fnp->fcontext = this_type->field (0).type ()->target_type ();
14286 }
14287 }
14288 }
14289 else if (attr->form_is_section_offset ())
14290 {
14292 }
14293 else
14294 {
14295 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14296 fieldname);
14297 }
14298 }
14299 else
14300 {
14301 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
14302 if (attr != nullptr && attr->as_virtuality () != DW_VIRTUALITY_none)
14303 {
14304 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14305 complaint (_("Member function \"%s\" (offset %s) is virtual "
14306 "but the vtable offset is not specified"),
14307 fieldname, sect_offset_str (die->sect_off));
14310 }
14311 }
14312}
14313
14314/* Create the vector of member function fields, and attach it to the type. */
14315
14316static void
14318 struct dwarf2_cu *cu)
14319{
14320 if (cu->lang () == language_ada)
14321 error (_("unexpected member functions in Ada type"));
14322
14324 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
14326 sizeof (struct fn_fieldlist) * fip->fnfieldlists.size ());
14327
14328 for (int i = 0; i < fip->fnfieldlists.size (); i++)
14329 {
14330 struct fnfieldlist &nf = fip->fnfieldlists[i];
14331 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
14332
14334 TYPE_FN_FIELDLIST_LENGTH (type, i) = nf.fnfields.size ();
14335 fn_flp->fn_fields = (struct fn_field *)
14336 TYPE_ALLOC (type, sizeof (struct fn_field) * nf.fnfields.size ());
14337
14338 for (int k = 0; k < nf.fnfields.size (); ++k)
14339 fn_flp->fn_fields[k] = nf.fnfields[k];
14340 }
14341
14342 TYPE_NFN_FIELDS (type) = fip->fnfieldlists.size ();
14343}
14344
14345/* Returns non-zero if NAME is the name of a vtable member in CU's
14346 language, zero otherwise. */
14347static int
14348is_vtable_name (const char *name, struct dwarf2_cu *cu)
14349{
14350 static const char vptr[] = "_vptr";
14351
14352 /* Look for the C++ form of the vtable. */
14353 if (startswith (name, vptr) && is_cplus_marker (name[sizeof (vptr) - 1]))
14354 return 1;
14355
14356 return 0;
14357}
14358
14359/* GCC outputs unnamed structures that are really pointers to member
14360 functions, with the ABI-specified layout. If TYPE describes
14361 such a structure, smash it into a member function type.
14362
14363 GCC shouldn't do this; it should just output pointer to member DIEs.
14364 This is GCC PR debug/28767. */
14365
14366static void
14368{
14369 struct type *pfn_type, *self_type, *new_type;
14370
14371 /* Check for a structure with no name and two children. */
14372 if (type->code () != TYPE_CODE_STRUCT || type->num_fields () != 2)
14373 return;
14374
14375 /* Check for __pfn and __delta members. */
14376 if (type->field (0).name () == NULL
14377 || strcmp (type->field (0).name (), "__pfn") != 0
14378 || type->field (1).name () == NULL
14379 || strcmp (type->field (1).name (), "__delta") != 0)
14380 return;
14381
14382 /* Find the type of the method. */
14383 pfn_type = type->field (0).type ();
14384 if (pfn_type == NULL
14385 || pfn_type->code () != TYPE_CODE_PTR
14386 || pfn_type->target_type ()->code () != TYPE_CODE_FUNC)
14387 return;
14388
14389 /* Look for the "this" argument. */
14390 pfn_type = pfn_type->target_type ();
14391 if (pfn_type->num_fields () == 0
14392 /* || pfn_type->field (0).type () == NULL */
14393 || pfn_type->field (0).type ()->code () != TYPE_CODE_PTR)
14394 return;
14395
14396 self_type = pfn_type->field (0).type ()->target_type ();
14398 smash_to_method_type (new_type, self_type, pfn_type->target_type (),
14399 pfn_type->fields (), pfn_type->num_fields (),
14400 pfn_type->has_varargs ());
14402}
14403
14404/* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
14405 requires rewriting, then copy it and return the updated copy.
14406 Otherwise return nullptr. */
14407
14408static struct type *
14410{
14411 if (type->code () != TYPE_CODE_ARRAY)
14412 return nullptr;
14413
14414 struct type *index_type = type->index_type ();
14415 range_bounds *current_bounds = index_type->bounds ();
14416
14417 /* Handle multi-dimensional arrays. */
14418 struct type *new_target = rewrite_array_type (type->target_type ());
14419 if (new_target == nullptr)
14420 {
14421 /* Maybe we don't need to rewrite this array. */
14422 if (current_bounds->low.kind () == PROP_CONST
14423 && current_bounds->high.kind () == PROP_CONST)
14424 return nullptr;
14425 }
14426
14427 /* Either the target type was rewritten, or the bounds have to be
14428 updated. Either way we want to copy the type and update
14429 everything. */
14430 struct type *copy = copy_type (type);
14431 int nfields = copy->num_fields ();
14432 field *new_fields
14433 = ((struct field *) TYPE_ZALLOC (copy,
14434 nfields * sizeof (struct field)));
14435 memcpy (new_fields, copy->fields (), nfields * sizeof (struct field));
14436 copy->set_fields (new_fields);
14437 if (new_target != nullptr)
14438 copy->set_target_type (new_target);
14439
14440 struct type *index_copy = copy_type (index_type);
14442 = (struct range_bounds *) TYPE_ZALLOC (index_copy,
14443 sizeof (range_bounds));
14444 *bounds = *current_bounds;
14445 bounds->low.set_const_val (1);
14446 bounds->high.set_const_val (0);
14447 index_copy->set_bounds (bounds);
14448 copy->set_index_type (index_copy);
14449
14450 return copy;
14451}
14452
14453/* While some versions of GCC will generate complicated DWARF for an
14454 array (see quirk_ada_thick_pointer), more recent versions were
14455 modified to emit an explicit thick pointer structure. However, in
14456 this case, the array still has DWARF expressions for its ranges,
14457 and these must be ignored. */
14458
14459static void
14461 struct type *type)
14462{
14463 gdb_assert (cu->lang () == language_ada);
14464
14465 /* Check for a structure with two children. */
14466 if (type->code () != TYPE_CODE_STRUCT || type->num_fields () != 2)
14467 return;
14468
14469 /* Check for P_ARRAY and P_BOUNDS members. */
14470 if (type->field (0).name () == NULL
14471 || strcmp (type->field (0).name (), "P_ARRAY") != 0
14472 || type->field (1).name () == NULL
14473 || strcmp (type->field (1).name (), "P_BOUNDS") != 0)
14474 return;
14475
14476 /* Make sure we're looking at a pointer to an array. */
14477 if (type->field (0).type ()->code () != TYPE_CODE_PTR)
14478 return;
14479
14480 /* The Ada code already knows how to handle these types, so all that
14481 we need to do is turn the bounds into static bounds. However, we
14482 don't want to rewrite existing array or index types in-place,
14483 because those may be referenced in other contexts where this
14484 rewriting is undesirable. */
14485 struct type *new_ary_type
14487 if (new_ary_type != nullptr)
14488 type->field (0).set_type (lookup_pointer_type (new_ary_type));
14489}
14490
14491/* If the DIE has a DW_AT_alignment attribute, return its value, doing
14492 appropriate error checking and issuing complaints if there is a
14493 problem. */
14494
14495static ULONGEST
14496get_alignment (struct dwarf2_cu *cu, struct die_info *die)
14497{
14498 struct attribute *attr = dwarf2_attr (die, DW_AT_alignment, cu);
14499
14500 if (attr == nullptr)
14501 return 0;
14502
14503 if (!attr->form_is_constant ())
14504 {
14505 complaint (_("DW_AT_alignment must have constant form"
14506 " - DIE at %s [in module %s]"),
14509 return 0;
14510 }
14511
14512 LONGEST val = attr->constant_value (0);
14513 if (val < 0)
14514 {
14515 complaint (_("DW_AT_alignment value must not be negative"
14516 " - DIE at %s [in module %s]"),
14519 return 0;
14520 }
14521 ULONGEST align = val;
14522
14523 if (align == 0)
14524 {
14525 complaint (_("DW_AT_alignment value must not be zero"
14526 " - DIE at %s [in module %s]"),
14529 return 0;
14530 }
14531 if ((align & (align - 1)) != 0)
14532 {
14533 complaint (_("DW_AT_alignment value must be a power of 2"
14534 " - DIE at %s [in module %s]"),
14537 return 0;
14538 }
14539
14540 return align;
14541}
14542
14543/* If the DIE has a DW_AT_alignment attribute, use its value to set
14544 the alignment for TYPE. */
14545
14546static void
14547maybe_set_alignment (struct dwarf2_cu *cu, struct die_info *die,
14548 struct type *type)
14549{
14550 if (!set_type_align (type, get_alignment (cu, die)))
14551 complaint (_("DW_AT_alignment value too large"
14552 " - DIE at %s [in module %s]"),
14555}
14556
14557/* Check if the given VALUE is a valid enum dwarf_calling_convention
14558 constant for a type, according to DWARF5 spec, Table 5.5. */
14559
14560static bool
14562{
14563 switch (value)
14564 {
14565 case DW_CC_normal:
14566 case DW_CC_pass_by_reference:
14567 case DW_CC_pass_by_value:
14568 return true;
14569
14570 default:
14571 complaint (_("unrecognized DW_AT_calling_convention value "
14572 "(%s) for a type"), pulongest (value));
14573 return false;
14574 }
14575}
14576
14577/* Check if the given VALUE is a valid enum dwarf_calling_convention
14578 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14579 also according to GNU-specific values (see include/dwarf2.h). */
14580
14581static bool
14583{
14584 switch (value)
14585 {
14586 case DW_CC_normal:
14587 case DW_CC_program:
14588 case DW_CC_nocall:
14589 return true;
14590
14591 case DW_CC_GNU_renesas_sh:
14592 case DW_CC_GNU_borland_fastcall_i386:
14593 case DW_CC_GDB_IBM_OpenCL:
14594 return true;
14595
14596 default:
14597 complaint (_("unrecognized DW_AT_calling_convention value "
14598 "(%s) for a subroutine"), pulongest (value));
14599 return false;
14600 }
14601}
14602
14603/* Called when we find the DIE that starts a structure or union scope
14604 (definition) to create a type for the structure or union. Fill in
14605 the type's name and general properties; the members will not be
14606 processed until process_structure_scope. A symbol table entry for
14607 the type will also not be done until process_structure_scope (assuming
14608 the type has a name).
14609
14610 NOTE: we need to call these functions regardless of whether or not the
14611 DIE has a DW_AT_name attribute, since it might be an anonymous
14612 structure or union. This gets the type entered into our set of
14613 user defined types. */
14614
14615static struct type *
14616read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
14617{
14618 struct objfile *objfile = cu->per_objfile->objfile;
14619 struct type *type;
14620 struct attribute *attr;
14621 const char *name;
14622
14623 /* If the definition of this type lives in .debug_types, read that type.
14624 Don't follow DW_AT_specification though, that will take us back up
14625 the chain and we want to go down. */
14626 attr = die->attr (DW_AT_signature);
14627 if (attr != nullptr)
14628 {
14629 type = get_DW_AT_signature_type (die, attr, cu);
14630
14631 /* The type's CU may not be the same as CU.
14632 Ensure TYPE is recorded with CU in die_type_hash. */
14633 return set_die_type (die, type, cu);
14634 }
14635
14638
14639 name = dwarf2_name (die, cu);
14640 if (name != NULL)
14641 {
14642 if (cu->lang () == language_cplus
14643 || cu->lang () == language_d
14644 || cu->lang () == language_rust)
14645 {
14646 const char *full_name = dwarf2_full_name (name, die, cu);
14647
14648 /* dwarf2_full_name might have already finished building the DIE's
14649 type. If so, there is no need to continue. */
14650 if (get_die_type (die, cu) != NULL)
14651 return get_die_type (die, cu);
14652
14653 type->set_name (full_name);
14654 }
14655 else
14656 {
14657 /* The name is already allocated along with this objfile, so
14658 we don't need to duplicate it for the type. */
14659 type->set_name (name);
14660 }
14661 }
14662
14663 if (die->tag == DW_TAG_structure_type)
14664 {
14665 type->set_code (TYPE_CODE_STRUCT);
14666 }
14667 else if (die->tag == DW_TAG_union_type)
14668 {
14669 type->set_code (TYPE_CODE_UNION);
14670 }
14671 else if (die->tag == DW_TAG_namelist)
14672 {
14673 type->set_code (TYPE_CODE_NAMELIST);
14674 }
14675 else
14676 {
14677 type->set_code (TYPE_CODE_STRUCT);
14678 }
14679
14680 if (cu->lang () == language_cplus && die->tag == DW_TAG_class_type)
14682
14683 /* Store the calling convention in the type if it's available in
14684 the die. Otherwise the calling convention remains set to
14685 the default value DW_CC_normal. */
14686 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
14687 if (attr != nullptr
14689 {
14692 = (enum dwarf_calling_convention) (attr->constant_value (0));
14693 }
14694
14695 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
14696 if (attr != nullptr)
14697 {
14698 if (attr->form_is_constant ())
14699 type->set_length (attr->constant_value (0));
14700 else
14701 {
14702 struct dynamic_prop prop;
14703 if (attr_to_dynamic_prop (attr, die, cu, &prop, cu->addr_type ()))
14705
14706 type->set_length (0);
14707 }
14708 }
14709 else
14710 type->set_length (0);
14711
14712 maybe_set_alignment (cu, die, type);
14713
14714 if (producer_is_icc_lt_14 (cu) && (type->length () == 0))
14715 {
14716 /* ICC<14 does not output the required DW_AT_declaration on
14717 incomplete types, but gives them a size of zero. */
14718 type->set_is_stub (true);
14719 }
14720 else
14722
14723 if (die_is_declaration (die, cu))
14724 type->set_is_stub (true);
14725 else if (attr == NULL && die->child == NULL
14727 /* RealView does not output the required DW_AT_declaration
14728 on incomplete types. */
14729 type->set_is_stub (true);
14730
14731 /* We need to add the type field to the die immediately so we don't
14732 infinitely recurse when dealing with pointers to the structure
14733 type within the structure itself. */
14734 set_die_type (die, type, cu);
14735
14736 /* set_die_type should be already done. */
14737 set_descriptive_type (type, die, cu);
14738
14739 return type;
14740}
14741
14742static void handle_struct_member_die
14743 (struct die_info *child_die,
14744 struct type *type,
14745 struct field_info *fi,
14746 std::vector<struct symbol *> *template_args,
14747 struct dwarf2_cu *cu);
14748
14749/* A helper for handle_struct_member_die that handles
14750 DW_TAG_variant_part. */
14751
14752static void
14754 struct field_info *fi,
14755 std::vector<struct symbol *> *template_args,
14756 struct dwarf2_cu *cu)
14757{
14758 variant_part_builder *new_part;
14759 if (fi->current_variant_part == nullptr)
14760 {
14761 fi->variant_parts.emplace_back ();
14762 new_part = &fi->variant_parts.back ();
14763 }
14765 {
14766 complaint (_("nested DW_TAG_variant_part seen "
14767 "- DIE at %s [in module %s]"),
14770 return;
14771 }
14772 else
14773 {
14774 variant_field &current = fi->current_variant_part->variants.back ();
14775 current.variant_parts.emplace_back ();
14776 new_part = &current.variant_parts.back ();
14777 }
14778
14779 /* When we recurse, we want callees to add to this new variant
14780 part. */
14781 scoped_restore save_current_variant_part
14782 = make_scoped_restore (&fi->current_variant_part, new_part);
14783
14784 struct attribute *discr = dwarf2_attr (die, DW_AT_discr, cu);
14785 if (discr == NULL)
14786 {
14787 /* It's a univariant form, an extension we support. */
14788 }
14789 else if (discr->form_is_ref ())
14790 {
14791 struct dwarf2_cu *target_cu = cu;
14792 struct die_info *target_die = follow_die_ref (die, discr, &target_cu);
14793
14794 new_part->discriminant_offset = target_die->sect_off;
14795 }
14796 else
14797 {
14798 complaint (_("DW_AT_discr does not have DIE reference form"
14799 " - DIE at %s [in module %s]"),
14802 }
14803
14804 for (die_info *child_die = die->child;
14805 child_die != NULL;
14806 child_die = child_die->sibling)
14807 handle_struct_member_die (child_die, type, fi, template_args, cu);
14808}
14809
14810/* A helper for handle_struct_member_die that handles
14811 DW_TAG_variant. */
14812
14813static void
14814handle_variant (struct die_info *die, struct type *type,
14815 struct field_info *fi,
14816 std::vector<struct symbol *> *template_args,
14817 struct dwarf2_cu *cu)
14818{
14819 if (fi->current_variant_part == nullptr)
14820 {
14821 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
14822 "- DIE at %s [in module %s]"),
14825 return;
14826 }
14828 {
14829 complaint (_("nested DW_TAG_variant seen "
14830 "- DIE at %s [in module %s]"),
14833 return;
14834 }
14835
14836 scoped_restore save_processing_variant
14837 = make_scoped_restore (&fi->current_variant_part->processing_variant,
14838 true);
14839
14840 fi->current_variant_part->variants.emplace_back ();
14842 variant.first_field = fi->fields.size ();
14843
14844 /* In a variant we want to get the discriminant and also add a
14845 field for our sole member child. */
14846 struct attribute *discr = dwarf2_attr (die, DW_AT_discr_value, cu);
14847 if (discr == nullptr || !discr->form_is_constant ())
14848 {
14849 discr = dwarf2_attr (die, DW_AT_discr_list, cu);
14850 if (discr == nullptr || discr->as_block ()->size == 0)
14851 variant.default_branch = true;
14852 else
14853 variant.discr_list_data = discr->as_block ();
14854 }
14855 else
14856 variant.discriminant_value = discr->constant_value (0);
14857
14858 for (die_info *variant_child = die->child;
14859 variant_child != NULL;
14860 variant_child = variant_child->sibling)
14861 handle_struct_member_die (variant_child, type, fi, template_args, cu);
14862
14863 variant.last_field = fi->fields.size ();
14864}
14865
14866/* A helper for process_structure_scope that handles a single member
14867 DIE. */
14868
14869static void
14870handle_struct_member_die (struct die_info *child_die, struct type *type,
14871 struct field_info *fi,
14872 std::vector<struct symbol *> *template_args,
14873 struct dwarf2_cu *cu)
14874{
14875 if (child_die->tag == DW_TAG_member
14876 || child_die->tag == DW_TAG_variable
14877 || child_die->tag == DW_TAG_namelist_item)
14878 {
14879 /* NOTE: carlton/2002-11-05: A C++ static data member
14880 should be a DW_TAG_member that is a declaration, but
14881 all versions of G++ as of this writing (so through at
14882 least 3.2.1) incorrectly generate DW_TAG_variable
14883 tags for them instead. */
14884 dwarf2_add_field (fi, child_die, cu);
14885 }
14886 else if (child_die->tag == DW_TAG_subprogram)
14887 {
14888 /* Rust doesn't have member functions in the C++ sense.
14889 However, it does emit ordinary functions as children
14890 of a struct DIE. */
14891 if (cu->lang () == language_rust)
14892 read_func_scope (child_die, cu);
14893 else
14894 {
14895 /* C++ member function. */
14896 dwarf2_add_member_fn (fi, child_die, type, cu);
14897 }
14898 }
14899 else if (child_die->tag == DW_TAG_inheritance)
14900 {
14901 /* C++ base class field. */
14902 dwarf2_add_field (fi, child_die, cu);
14903 }
14904 else if (type_can_define_types (child_die))
14905 dwarf2_add_type_defn (fi, child_die, cu);
14906 else if (child_die->tag == DW_TAG_template_type_param
14907 || child_die->tag == DW_TAG_template_value_param)
14908 {
14909 struct symbol *arg = new_symbol (child_die, NULL, cu);
14910
14911 if (arg != NULL)
14912 template_args->push_back (arg);
14913 }
14914 else if (child_die->tag == DW_TAG_variant_part)
14915 handle_variant_part (child_die, type, fi, template_args, cu);
14916 else if (child_die->tag == DW_TAG_variant)
14917 handle_variant (child_die, type, fi, template_args, cu);
14918}
14919
14920/* Finish creating a structure or union type, including filling in its
14921 members and creating a symbol for it. This function also handles Fortran
14922 namelist variables, their items or members and creating a symbol for
14923 them. */
14924
14925static void
14927{
14928 struct objfile *objfile = cu->per_objfile->objfile;
14929 struct die_info *child_die;
14930 struct type *type;
14931
14932 type = get_die_type (die, cu);
14933 if (type == NULL)
14934 type = read_structure_type (die, cu);
14935
14936 bool has_template_parameters = false;
14937 if (die->child != NULL && ! die_is_declaration (die, cu))
14938 {
14939 struct field_info fi;
14940 std::vector<struct symbol *> template_args;
14941
14942 child_die = die->child;
14943
14944 while (child_die && child_die->tag)
14945 {
14946 handle_struct_member_die (child_die, type, &fi, &template_args, cu);
14947 child_die = child_die->sibling;
14948 }
14949
14950 /* Attach template arguments to type. */
14951 if (!template_args.empty ())
14952 {
14953 has_template_parameters = true;
14955 TYPE_N_TEMPLATE_ARGUMENTS (type) = template_args.size ();
14957 = XOBNEWVEC (&objfile->objfile_obstack,
14958 struct symbol *,
14960 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
14961 template_args.data (),
14963 * sizeof (struct symbol *)));
14964 }
14965
14966 /* Attach fields and member functions to the type. */
14967 if (fi.nfields () > 0)
14969 if (!fi.fnfieldlists.empty ())
14970 {
14972
14973 /* Get the type which refers to the base class (possibly this
14974 class itself) which contains the vtable pointer for the current
14975 class from the DW_AT_containing_type attribute. This use of
14976 DW_AT_containing_type is a GNU extension. */
14977
14978 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
14979 {
14980 struct type *t = die_containing_type (die, cu);
14981
14983 if (type == t)
14984 {
14985 int i;
14986
14987 /* Our own class provides vtbl ptr. */
14988 for (i = t->num_fields () - 1;
14989 i >= TYPE_N_BASECLASSES (t);
14990 --i)
14991 {
14992 const char *fieldname = t->field (i).name ();
14993
14994 if (is_vtable_name (fieldname, cu))
14995 {
14997 break;
14998 }
14999 }
15000
15001 /* Complain if virtual function table field not found. */
15002 if (i < TYPE_N_BASECLASSES (t))
15003 complaint (_("virtual function table pointer "
15004 "not found when defining class '%s'"),
15005 type->name () ? type->name () : "");
15006 }
15007 else
15008 {
15010 }
15011 }
15012 else if (cu->producer
15013 && startswith (cu->producer, "IBM(R) XL C/C++ Advanced Edition"))
15014 {
15015 /* The IBM XLC compiler does not provide direct indication
15016 of the containing type, but the vtable pointer is
15017 always named __vfp. */
15018
15019 int i;
15020
15021 for (i = type->num_fields () - 1;
15022 i >= TYPE_N_BASECLASSES (type);
15023 --i)
15024 {
15025 if (strcmp (type->field (i).name (), "__vfp") == 0)
15026 {
15029 break;
15030 }
15031 }
15032 }
15033 }
15034
15035 /* Copy fi.typedef_field_list linked list elements content into the
15036 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15037 if (!fi.typedef_field_list.empty ())
15038 {
15039 int count = fi.typedef_field_list.size ();
15040
15043 = ((struct decl_field *)
15045 sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * count));
15047
15048 for (int i = 0; i < fi.typedef_field_list.size (); ++i)
15050 }
15051
15052 /* Copy fi.nested_types_list linked list elements content into the
15053 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15054 if (!fi.nested_types_list.empty ()
15055 && cu->lang () != language_ada)
15056 {
15057 int count = fi.nested_types_list.size ();
15058
15061 = ((struct decl_field *)
15062 TYPE_ALLOC (type, sizeof (struct decl_field) * count));
15063 TYPE_NESTED_TYPES_COUNT (type) = count;
15064
15065 for (int i = 0; i < fi.nested_types_list.size (); ++i)
15067 }
15068 }
15069
15071 if (cu->lang () == language_rust && die->tag == DW_TAG_union_type)
15072 cu->rust_unions.push_back (type);
15073 else if (cu->lang () == language_ada)
15075
15076 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15077 snapshots) has been known to create a die giving a declaration
15078 for a class that has, as a child, a die giving a definition for a
15079 nested class. So we have to process our children even if the
15080 current die is a declaration. Normally, of course, a declaration
15081 won't have any children at all. */
15082
15083 child_die = die->child;
15084
15085 while (child_die != NULL && child_die->tag)
15086 {
15087 if (child_die->tag == DW_TAG_member
15088 || child_die->tag == DW_TAG_variable
15089 || child_die->tag == DW_TAG_inheritance
15090 || child_die->tag == DW_TAG_template_value_param
15091 || child_die->tag == DW_TAG_template_type_param)
15092 {
15093 /* Do nothing. */
15094 }
15095 else
15096 process_die (child_die, cu);
15097
15098 child_die = child_die->sibling;
15099 }
15100
15101 /* Do not consider external references. According to the DWARF standard,
15102 these DIEs are identified by the fact that they have no byte_size
15103 attribute, and a declaration attribute. */
15104 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
15105 || !die_is_declaration (die, cu)
15106 || dwarf2_attr (die, DW_AT_signature, cu) != NULL)
15107 {
15108 struct symbol *sym = new_symbol (die, type, cu);
15109
15110 if (has_template_parameters)
15111 {
15112 struct symtab *symtab;
15113 if (sym != nullptr)
15114 symtab = sym->symtab ();
15115 else if (cu->line_header != nullptr)
15116 {
15117 /* Any related symtab will do. */
15118 symtab
15119 = cu->line_header->file_names ()[0].symtab;
15120 }
15121 else
15122 {
15123 symtab = nullptr;
15124 complaint (_("could not find suitable "
15125 "symtab for template parameter"
15126 " - DIE at %s [in module %s]"),
15129 }
15130
15131 if (symtab != nullptr)
15132 {
15133 /* Make sure that the symtab is set on the new symbols.
15134 Even though they don't appear in this symtab directly,
15135 other parts of gdb assume that symbols do, and this is
15136 reasonably true. */
15137 for (int i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
15138 TYPE_TEMPLATE_ARGUMENT (type, i)->set_symtab (symtab);
15139 }
15140 }
15141 }
15142}
15143
15144/* Assuming DIE is an enumeration type, and TYPE is its associated
15145 type, update TYPE using some information only available in DIE's
15146 children. In particular, the fields are computed. */
15147
15148static void
15150 struct type *type,
15151 struct dwarf2_cu *cu)
15152{
15153 struct die_info *child_die;
15154 int unsigned_enum = 1;
15155 int flag_enum = 1;
15156
15157 auto_obstack obstack;
15158 std::vector<struct field> fields;
15159
15160 for (child_die = die->child;
15161 child_die != NULL && child_die->tag;
15162 child_die = child_die->sibling)
15163 {
15164 struct attribute *attr;
15165 LONGEST value;
15166 const gdb_byte *bytes;
15167 struct dwarf2_locexpr_baton *baton;
15168 const char *name;
15169
15170 if (child_die->tag != DW_TAG_enumerator)
15171 continue;
15172
15173 attr = dwarf2_attr (child_die, DW_AT_const_value, cu);
15174 if (attr == NULL)
15175 continue;
15176
15177 name = dwarf2_name (child_die, cu);
15178 if (name == NULL)
15179 name = "<anonymous enumerator>";
15180
15181 dwarf2_const_value_attr (attr, type, name, &obstack, cu,
15182 &value, &bytes, &baton);
15183 if (value < 0)
15184 {
15185 unsigned_enum = 0;
15186 flag_enum = 0;
15187 }
15188 else
15189 {
15190 if (count_one_bits_ll (value) >= 2)
15191 flag_enum = 0;
15192 }
15193
15194 fields.emplace_back ();
15195 struct field &field = fields.back ();
15196 field.set_name (dwarf2_physname (name, child_die, cu));
15198 }
15199
15200 if (!fields.empty ())
15201 {
15202 type->set_num_fields (fields.size ());
15204 ((struct field *)
15205 TYPE_ALLOC (type, sizeof (struct field) * fields.size ()));
15206 memcpy (type->fields (), fields.data (),
15207 sizeof (struct field) * fields.size ());
15208 }
15209
15210 if (unsigned_enum)
15211 type->set_is_unsigned (true);
15212
15213 if (flag_enum)
15214 type->set_is_flag_enum (true);
15215}
15216
15217/* Given a DW_AT_enumeration_type die, set its type. We do not
15218 complete the type's fields yet, or create any symbols. */
15219
15220static struct type *
15222{
15223 struct objfile *objfile = cu->per_objfile->objfile;
15224 struct type *type;
15225 struct attribute *attr;
15226 const char *name;
15227
15228 /* If the definition of this type lives in .debug_types, read that type.
15229 Don't follow DW_AT_specification though, that will take us back up
15230 the chain and we want to go down. */
15231 attr = die->attr (DW_AT_signature);
15232 if (attr != nullptr)
15233 {
15234 type = get_DW_AT_signature_type (die, attr, cu);
15235
15236 /* The type's CU may not be the same as CU.
15237 Ensure TYPE is recorded with CU in die_type_hash. */
15238 return set_die_type (die, type, cu);
15239 }
15240
15242
15243 type->set_code (TYPE_CODE_ENUM);
15244 name = dwarf2_full_name (NULL, die, cu);
15245 if (name != NULL)
15246 type->set_name (name);
15247
15248 attr = dwarf2_attr (die, DW_AT_type, cu);
15249 if (attr != NULL)
15250 {
15251 struct type *underlying_type = die_type (die, cu);
15252
15253 type->set_target_type (underlying_type);
15254 }
15255
15256 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
15257 if (attr != nullptr)
15258 type->set_length (attr->constant_value (0));
15259 else
15260 type->set_length (0);
15261
15262 maybe_set_alignment (cu, die, type);
15263
15264 /* The enumeration DIE can be incomplete. In Ada, any type can be
15265 declared as private in the package spec, and then defined only
15266 inside the package body. Such types are known as Taft Amendment
15267 Types. When another package uses such a type, an incomplete DIE
15268 may be generated by the compiler. */
15269 if (die_is_declaration (die, cu))
15270 type->set_is_stub (true);
15271
15272 /* If this type has an underlying type that is not a stub, then we
15273 may use its attributes. We always use the "unsigned" attribute
15274 in this situation, because ordinarily we guess whether the type
15275 is unsigned -- but the guess can be wrong and the underlying type
15276 can tell us the reality. However, we defer to a local size
15277 attribute if one exists, because this lets the compiler override
15278 the underlying type if needed. */
15279 if (type->target_type () != NULL && !type->target_type ()->is_stub ())
15280 {
15281 struct type *underlying_type = type->target_type ();
15282 underlying_type = check_typedef (underlying_type);
15283
15284 type->set_is_unsigned (underlying_type->is_unsigned ());
15285
15286 if (type->length () == 0)
15287 type->set_length (underlying_type->length ());
15288
15289 if (TYPE_RAW_ALIGN (type) == 0
15290 && TYPE_RAW_ALIGN (underlying_type) != 0)
15291 set_type_align (type, TYPE_RAW_ALIGN (underlying_type));
15292 }
15293
15294 type->set_is_declared_class (dwarf2_flag_true_p (die, DW_AT_enum_class, cu));
15295
15296 set_die_type (die, type, cu);
15297
15298 /* Finish the creation of this type by using the enum's children.
15299 Note that, as usual, this must come after set_die_type to avoid
15300 infinite recursion when trying to compute the names of the
15301 enumerators. */
15303
15304 return type;
15305}
15306
15307/* Given a pointer to a die which begins an enumeration, process all
15308 the dies that define the members of the enumeration, and create the
15309 symbol for the enumeration type.
15310
15311 NOTE: We reverse the order of the element list. */
15312
15313static void
15315{
15316 struct type *this_type;
15317
15318 this_type = get_die_type (die, cu);
15319 if (this_type == NULL)
15320 this_type = read_enumeration_type (die, cu);
15321
15322 if (die->child != NULL)
15323 {
15324 struct die_info *child_die;
15325 const char *name;
15326
15327 child_die = die->child;
15328 while (child_die && child_die->tag)
15329 {
15330 if (child_die->tag != DW_TAG_enumerator)
15331 {
15332 process_die (child_die, cu);
15333 }
15334 else
15335 {
15336 name = dwarf2_name (child_die, cu);
15337 if (name)
15338 new_symbol (child_die, this_type, cu);
15339 }
15340
15341 child_die = child_die->sibling;
15342 }
15343 }
15344
15345 /* If we are reading an enum from a .debug_types unit, and the enum
15346 is a declaration, and the enum is not the signatured type in the
15347 unit, then we do not want to add a symbol for it. Adding a
15348 symbol would in some cases obscure the true definition of the
15349 enum, giving users an incomplete type when the definition is
15350 actually available. Note that we do not want to do this for all
15351 enums which are just declarations, because C++0x allows forward
15352 enum declarations. */
15353 if (cu->per_cu->is_debug_types
15354 && die_is_declaration (die, cu))
15355 {
15356 struct signatured_type *sig_type;
15357
15358 sig_type = (struct signatured_type *) cu->per_cu;
15359 gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
15360 if (sig_type->type_offset_in_section != die->sect_off)
15361 return;
15362 }
15363
15364 new_symbol (die, this_type, cu);
15365}
15366
15367/* Helper function for quirk_ada_thick_pointer that examines a bounds
15368 expression for an index type and finds the corresponding field
15369 offset in the hidden "P_BOUNDS" structure. Returns true on success
15370 and updates *FIELD, false if it fails to recognize an
15371 expression. */
15372
15373static bool
15374recognize_bound_expression (struct die_info *die, enum dwarf_attribute name,
15375 int *bounds_offset, struct field *field,
15376 struct dwarf2_cu *cu)
15377{
15378 struct attribute *attr = dwarf2_attr (die, name, cu);
15379 if (attr == nullptr || !attr->form_is_block ())
15380 return false;
15381
15382 const struct dwarf_block *block = attr->as_block ();
15383 const gdb_byte *start = block->data;
15384 const gdb_byte *end = block->data + block->size;
15385
15386 /* The expression to recognize generally looks like:
15387
15388 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
15389 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
15390
15391 However, the second "plus_uconst" may be missing:
15392
15393 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
15394 DW_OP_deref_size: 4)
15395
15396 This happens when the field is at the start of the structure.
15397
15398 Also, the final deref may not be sized:
15399
15400 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
15401 DW_OP_deref)
15402
15403 This happens when the size of the index type happens to be the
15404 same as the architecture's word size. This can occur with or
15405 without the second plus_uconst. */
15406
15407 if (end - start < 2)
15408 return false;
15409 if (*start++ != DW_OP_push_object_address)
15410 return false;
15411 if (*start++ != DW_OP_plus_uconst)
15412 return false;
15413
15414 uint64_t this_bound_off;
15415 start = gdb_read_uleb128 (start, end, &this_bound_off);
15416 if (start == nullptr || (int) this_bound_off != this_bound_off)
15417 return false;
15418 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
15419 is consistent among all bounds. */
15420 if (*bounds_offset == -1)
15421 *bounds_offset = this_bound_off;
15422 else if (*bounds_offset != this_bound_off)
15423 return false;
15424
15425 if (start == end || *start++ != DW_OP_deref)
15426 return false;
15427
15428 int offset = 0;
15429 if (start ==end)
15430 return false;
15431 else if (*start == DW_OP_deref_size || *start == DW_OP_deref)
15432 {
15433 /* This means an offset of 0. */
15434 }
15435 else if (*start++ != DW_OP_plus_uconst)
15436 return false;
15437 else
15438 {
15439 /* The size is the parameter to DW_OP_plus_uconst. */
15440 uint64_t val;
15441 start = gdb_read_uleb128 (start, end, &val);
15442 if (start == nullptr)
15443 return false;
15444 if ((int) val != val)
15445 return false;
15446 offset = val;
15447 }
15448
15449 if (start == end)
15450 return false;
15451
15452 uint64_t size;
15453 if (*start == DW_OP_deref_size)
15454 {
15455 start = gdb_read_uleb128 (start + 1, end, &size);
15456 if (start == nullptr)
15457 return false;
15458 }
15459 else if (*start == DW_OP_deref)
15460 {
15461 size = cu->header.addr_size;
15462 ++start;
15463 }
15464 else
15465 return false;
15466
15467 field->set_loc_bitpos (8 * offset);
15468 if (size != field->type ()->length ())
15469 FIELD_BITSIZE (*field) = 8 * size;
15470
15471 return true;
15472}
15473
15474/* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
15475 some kinds of Ada arrays:
15476
15477 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
15478 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
15479 <11e0> DW_AT_data_location: 2 byte block: 97 6
15480 (DW_OP_push_object_address; DW_OP_deref)
15481 <11e3> DW_AT_type : <0x1173>
15482 <11e7> DW_AT_sibling : <0x1201>
15483 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
15484 <11ec> DW_AT_type : <0x1206>
15485 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
15486 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
15487 DW_OP_deref_size: 4)
15488 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
15489 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
15490 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
15491
15492 This actually represents a "thick pointer", which is a structure
15493 with two elements: one that is a pointer to the array data, and one
15494 that is a pointer to another structure; this second structure holds
15495 the array bounds.
15496
15497 This returns a new type on success, or nullptr if this didn't
15498 recognize the type. */
15499
15500static struct type *
15502 struct type *type)
15503{
15504 struct attribute *attr = dwarf2_attr (die, DW_AT_data_location, cu);
15505 /* So far we've only seen this with block form. */
15506 if (attr == nullptr || !attr->form_is_block ())
15507 return nullptr;
15508
15509 /* Note that this will fail if the structure layout is changed by
15510 the compiler. However, we have no good way to recognize some
15511 other layout, because we don't know what expression the compiler
15512 might choose to emit should this happen. */
15513 struct dwarf_block *blk = attr->as_block ();
15514 if (blk->size != 2
15515 || blk->data[0] != DW_OP_push_object_address
15516 || blk->data[1] != DW_OP_deref)
15517 return nullptr;
15518
15519 int bounds_offset = -1;
15520 int max_align = -1;
15521 std::vector<struct field> range_fields;
15522 for (struct die_info *child_die = die->child;
15523 child_die;
15524 child_die = child_die->sibling)
15525 {
15526 if (child_die->tag == DW_TAG_subrange_type)
15527 {
15528 struct type *underlying = read_subrange_index_type (child_die, cu);
15529
15530 int this_align = type_align (underlying);
15531 if (this_align > max_align)
15532 max_align = this_align;
15533
15534 range_fields.emplace_back ();
15535 range_fields.emplace_back ();
15536
15537 struct field &lower = range_fields[range_fields.size () - 2];
15538 struct field &upper = range_fields[range_fields.size () - 1];
15539
15540 lower.set_type (underlying);
15541 FIELD_ARTIFICIAL (lower) = 1;
15542
15543 upper.set_type (underlying);
15544 FIELD_ARTIFICIAL (upper) = 1;
15545
15546 if (!recognize_bound_expression (child_die, DW_AT_lower_bound,
15547 &bounds_offset, &lower, cu)
15548 || !recognize_bound_expression (child_die, DW_AT_upper_bound,
15549 &bounds_offset, &upper, cu))
15550 return nullptr;
15551 }
15552 }
15553
15554 /* This shouldn't really happen, but double-check that we found
15555 where the bounds are stored. */
15556 if (bounds_offset == -1)
15557 return nullptr;
15558
15559 struct objfile *objfile = cu->per_objfile->objfile;
15560 for (int i = 0; i < range_fields.size (); i += 2)
15561 {
15562 char name[20];
15563
15564 /* Set the name of each field in the bounds. */
15565 xsnprintf (name, sizeof (name), "LB%d", i / 2);
15566 range_fields[i].set_name (objfile->intern (name));
15567 xsnprintf (name, sizeof (name), "UB%d", i / 2);
15568 range_fields[i + 1].set_name (objfile->intern (name));
15569 }
15570
15571 struct type *bounds = alloc_type (objfile);
15572 bounds->set_code (TYPE_CODE_STRUCT);
15573
15574 bounds->set_num_fields (range_fields.size ());
15575 bounds->set_fields
15576 ((struct field *) TYPE_ALLOC (bounds, (bounds->num_fields ()
15577 * sizeof (struct field))));
15578 memcpy (bounds->fields (), range_fields.data (),
15579 bounds->num_fields () * sizeof (struct field));
15580
15581 int last_fieldno = range_fields.size () - 1;
15582 int bounds_size = (bounds->field (last_fieldno).loc_bitpos () / 8
15583 + bounds->field (last_fieldno).type ()->length ());
15584 bounds->set_length (align_up (bounds_size, max_align));
15585
15586 /* Rewrite the existing array type in place. Specifically, we
15587 remove any dynamic properties we might have read, and we replace
15588 the index types. */
15589 struct type *iter = type;
15590 for (int i = 0; i < range_fields.size (); i += 2)
15591 {
15592 gdb_assert (iter->code () == TYPE_CODE_ARRAY);
15593 iter->main_type->dyn_prop_list = nullptr;
15594 iter->set_index_type
15595 (create_static_range_type (NULL, bounds->field (i).type (), 1, 0));
15596 iter = iter->target_type ();
15597 }
15598
15599 struct type *result = alloc_type (objfile);
15600 result->set_code (TYPE_CODE_STRUCT);
15601
15602 result->set_num_fields (2);
15603 result->set_fields
15604 ((struct field *) TYPE_ZALLOC (result, (result->num_fields ()
15605 * sizeof (struct field))));
15606
15607 /* The names are chosen to coincide with what the compiler does with
15608 -fgnat-encodings=all, which the Ada code in gdb already
15609 understands. */
15610 result->field (0).set_name ("P_ARRAY");
15611 result->field (0).set_type (lookup_pointer_type (type));
15612
15613 result->field (1).set_name ("P_BOUNDS");
15614 result->field (1).set_type (lookup_pointer_type (bounds));
15615 result->field (1).set_loc_bitpos (8 * bounds_offset);
15616
15617 result->set_name (type->name ());
15618 result->set_length (result->field (0).type ()->length ()
15619 + result->field (1).type ()->length ());
15620
15621 return result;
15622}
15623
15624/* Extract all information from a DW_TAG_array_type DIE and put it in
15625 the DIE's type field. For now, this only handles one dimensional
15626 arrays. */
15627
15628static struct type *
15629read_array_type (struct die_info *die, struct dwarf2_cu *cu)
15630{
15631 struct objfile *objfile = cu->per_objfile->objfile;
15632 struct die_info *child_die;
15633 struct type *type;
15634 struct type *element_type, *range_type, *index_type;
15635 struct attribute *attr;
15636 const char *name;
15637 struct dynamic_prop *byte_stride_prop = NULL;
15638 unsigned int bit_stride = 0;
15639
15640 element_type = die_type (die, cu);
15641
15642 /* The die_type call above may have already set the type for this DIE. */
15643 type = get_die_type (die, cu);
15644 if (type)
15645 return type;
15646
15647 attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
15648 if (attr != NULL)
15649 {
15650 int stride_ok;
15651 struct type *prop_type = cu->addr_sized_int_type (false);
15652
15653 byte_stride_prop
15654 = (struct dynamic_prop *) alloca (sizeof (struct dynamic_prop));
15655 stride_ok = attr_to_dynamic_prop (attr, die, cu, byte_stride_prop,
15656 prop_type);
15657 if (!stride_ok)
15658 {
15659 complaint (_("unable to read array DW_AT_byte_stride "
15660 " - DIE at %s [in module %s]"),
15663 /* Ignore this attribute. We will likely not be able to print
15664 arrays of this type correctly, but there is little we can do
15665 to help if we cannot read the attribute's value. */
15666 byte_stride_prop = NULL;
15667 }
15668 }
15669
15670 attr = dwarf2_attr (die, DW_AT_bit_stride, cu);
15671 if (attr != NULL)
15672 bit_stride = attr->constant_value (0);
15673
15674 /* Irix 6.2 native cc creates array types without children for
15675 arrays with unspecified length. */
15676 if (die->child == NULL)
15677 {
15678 index_type = objfile_type (objfile)->builtin_int;
15679 range_type = create_static_range_type (NULL, index_type, 0, -1);
15680 type = create_array_type_with_stride (NULL, element_type, range_type,
15681 byte_stride_prop, bit_stride);
15682 return set_die_type (die, type, cu);
15683 }
15684
15685 std::vector<struct type *> range_types;
15686 child_die = die->child;
15687 while (child_die && child_die->tag)
15688 {
15689 if (child_die->tag == DW_TAG_subrange_type
15690 || child_die->tag == DW_TAG_generic_subrange)
15691 {
15692 struct type *child_type = read_type_die (child_die, cu);
15693
15694 if (child_type != NULL)
15695 {
15696 /* The range type was succesfully read. Save it for the
15697 array type creation. */
15698 range_types.push_back (child_type);
15699 }
15700 }
15701 child_die = child_die->sibling;
15702 }
15703
15704 if (range_types.empty ())
15705 {
15706 complaint (_("unable to find array range - DIE at %s [in module %s]"),
15709 return NULL;
15710 }
15711
15712 /* Dwarf2 dimensions are output from left to right, create the
15713 necessary array types in backwards order. */
15714
15715 type = element_type;
15716
15717 if (read_array_order (die, cu) == DW_ORD_col_major)
15718 {
15719 int i = 0;
15720
15721 while (i < range_types.size ())
15722 {
15723 type = create_array_type_with_stride (NULL, type, range_types[i++],
15724 byte_stride_prop, bit_stride);
15726 bit_stride = 0;
15727 byte_stride_prop = nullptr;
15728 }
15729 }
15730 else
15731 {
15732 size_t ndim = range_types.size ();
15733 while (ndim-- > 0)
15734 {
15735 type = create_array_type_with_stride (NULL, type, range_types[ndim],
15736 byte_stride_prop, bit_stride);
15738 bit_stride = 0;
15739 byte_stride_prop = nullptr;
15740 }
15741 }
15742
15743 /* Clear the flag on the outermost array type. */
15745 gdb_assert (type != element_type);
15746
15747 /* Understand Dwarf2 support for vector types (like they occur on
15748 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15749 array type. This is not part of the Dwarf2/3 standard yet, but a
15750 custom vendor extension. The main difference between a regular
15751 array and the vector variant is that vectors are passed by value
15752 to functions. */
15753 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
15754 if (attr != nullptr)
15756
15757 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15758 implementation may choose to implement triple vectors using this
15759 attribute. */
15760 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
15761 if (attr != nullptr && attr->form_is_unsigned ())
15762 {
15763 if (attr->as_unsigned () >= type->length ())
15764 type->set_length (attr->as_unsigned ());
15765 else
15766 complaint (_("DW_AT_byte_size for array type smaller "
15767 "than the total size of elements"));
15768 }
15769
15770 name = dwarf2_name (die, cu);
15771 if (name)
15772 type->set_name (name);
15773
15774 maybe_set_alignment (cu, die, type);
15775
15776 struct type *replacement_type = nullptr;
15777 if (cu->lang () == language_ada)
15778 {
15779 replacement_type = quirk_ada_thick_pointer (die, cu, type);
15780 if (replacement_type != nullptr)
15781 type = replacement_type;
15782 }
15783
15784 /* Install the type in the die. */
15785 set_die_type (die, type, cu, replacement_type != nullptr);
15786
15787 /* set_die_type should be already done. */
15788 set_descriptive_type (type, die, cu);
15789
15790 return type;
15791}
15792
15793static enum dwarf_array_dim_ordering
15794read_array_order (struct die_info *die, struct dwarf2_cu *cu)
15795{
15796 struct attribute *attr;
15797
15798 attr = dwarf2_attr (die, DW_AT_ordering, cu);
15799
15800 if (attr != nullptr)
15801 {
15802 LONGEST val = attr->constant_value (-1);
15803 if (val == DW_ORD_row_major || val == DW_ORD_col_major)
15804 return (enum dwarf_array_dim_ordering) val;
15805 }
15806
15807 /* GNU F77 is a special case, as at 08/2004 array type info is the
15808 opposite order to the dwarf2 specification, but data is still
15809 laid out as per normal fortran.
15810
15811 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15812 version checking. */
15813
15814 if (cu->lang () == language_fortran
15815 && cu->producer && strstr (cu->producer, "GNU F77"))
15816 {
15817 return DW_ORD_row_major;
15818 }
15819
15820 switch (cu->language_defn->array_ordering ())
15821 {
15822 case array_column_major:
15823 return DW_ORD_col_major;
15824 case array_row_major:
15825 default:
15826 return DW_ORD_row_major;
15827 };
15828}
15829
15830/* Extract all information from a DW_TAG_set_type DIE and put it in
15831 the DIE's type field. */
15832
15833static struct type *
15834read_set_type (struct die_info *die, struct dwarf2_cu *cu)
15835{
15836 struct type *domain_type, *set_type;
15837 struct attribute *attr;
15838
15839 domain_type = die_type (die, cu);
15840
15841 /* The die_type call above may have already set the type for this DIE. */
15842 set_type = get_die_type (die, cu);
15843 if (set_type)
15844 return set_type;
15845
15846 set_type = create_set_type (NULL, domain_type);
15847
15848 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
15849 if (attr != nullptr && attr->form_is_unsigned ())
15850 set_type->set_length (attr->as_unsigned ());
15851
15852 maybe_set_alignment (cu, die, set_type);
15853
15854 return set_die_type (die, set_type, cu);
15855}
15856
15857/* A helper for read_common_block that creates a locexpr baton.
15858 SYM is the symbol which we are marking as computed.
15859 COMMON_DIE is the DIE for the common block.
15860 COMMON_LOC is the location expression attribute for the common
15861 block itself.
15862 MEMBER_LOC is the location expression attribute for the particular
15863 member of the common block that we are processing.
15864 CU is the CU from which the above come. */
15865
15866static void
15868 struct die_info *common_die,
15869 struct attribute *common_loc,
15870 struct attribute *member_loc,
15871 struct dwarf2_cu *cu)
15872{
15873 dwarf2_per_objfile *per_objfile = cu->per_objfile;
15874 struct objfile *objfile = per_objfile->objfile;
15875 struct dwarf2_locexpr_baton *baton;
15876 gdb_byte *ptr;
15877 unsigned int cu_off;
15878 enum bfd_endian byte_order = gdbarch_byte_order (objfile->arch ());
15879 LONGEST offset = 0;
15880
15881 gdb_assert (common_loc && member_loc);
15882 gdb_assert (common_loc->form_is_block ());
15883 gdb_assert (member_loc->form_is_block ()
15884 || member_loc->form_is_constant ());
15885
15886 baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
15887 baton->per_objfile = per_objfile;
15888 baton->per_cu = cu->per_cu;
15889 gdb_assert (baton->per_cu);
15890
15891 baton->size = 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15892
15893 if (member_loc->form_is_constant ())
15894 {
15895 offset = member_loc->constant_value (0);
15896 baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
15897 }
15898 else
15899 baton->size += member_loc->as_block ()->size;
15900
15901 ptr = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, baton->size);
15902 baton->data = ptr;
15903
15904 *ptr++ = DW_OP_call4;
15905 cu_off = common_die->sect_off - cu->per_cu->sect_off;
15906 store_unsigned_integer (ptr, 4, byte_order, cu_off);
15907 ptr += 4;
15908
15909 if (member_loc->form_is_constant ())
15910 {
15911 *ptr++ = DW_OP_addr;
15912 store_unsigned_integer (ptr, cu->header.addr_size, byte_order, offset);
15913 ptr += cu->header.addr_size;
15914 }
15915 else
15916 {
15917 /* We have to copy the data here, because DW_OP_call4 will only
15918 use a DW_AT_location attribute. */
15919 struct dwarf_block *block = member_loc->as_block ();
15920 memcpy (ptr, block->data, block->size);
15921 ptr += block->size;
15922 }
15923
15924 *ptr++ = DW_OP_plus;
15925 gdb_assert (ptr - baton->data == baton->size);
15926
15927 SYMBOL_LOCATION_BATON (sym) = baton;
15929}
15930
15931/* Create appropriate locally-scoped variables for all the
15932 DW_TAG_common_block entries. Also create a struct common_block
15933 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15934 is used to separate the common blocks name namespace from regular
15935 variable names. */
15936
15937static void
15938read_common_block (struct die_info *die, struct dwarf2_cu *cu)
15939{
15940 struct attribute *attr;
15941
15942 attr = dwarf2_attr (die, DW_AT_location, cu);
15943 if (attr != nullptr)
15944 {
15945 /* Support the .debug_loc offsets. */
15946 if (attr->form_is_block ())
15947 {
15948 /* Ok. */
15949 }
15950 else if (attr->form_is_section_offset ())
15951 {
15953 attr = NULL;
15954 }
15955 else
15956 {
15957 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15958 "common block member");
15959 attr = NULL;
15960 }
15961 }
15962
15963 if (die->child != NULL)
15964 {
15965 struct objfile *objfile = cu->per_objfile->objfile;
15966 struct die_info *child_die;
15967 size_t n_entries = 0, size;
15968 struct common_block *common_block;
15969 struct symbol *sym;
15970
15971 for (child_die = die->child;
15972 child_die && child_die->tag;
15973 child_die = child_die->sibling)
15974 ++n_entries;
15975
15976 size = (sizeof (struct common_block)
15977 + (n_entries - 1) * sizeof (struct symbol *));
15979 = (struct common_block *) obstack_alloc (&objfile->objfile_obstack,
15980 size);
15981 memset (common_block->contents, 0, n_entries * sizeof (struct symbol *));
15983
15984 for (child_die = die->child;
15985 child_die && child_die->tag;
15986 child_die = child_die->sibling)
15987 {
15988 /* Create the symbol in the DW_TAG_common_block block in the current
15989 symbol scope. */
15990 sym = new_symbol (child_die, NULL, cu);
15991 if (sym != NULL)
15992 {
15993 struct attribute *member_loc;
15994
15996
15997 member_loc = dwarf2_attr (child_die, DW_AT_data_member_location,
15998 cu);
15999 if (member_loc)
16000 {
16001 /* GDB has handled this for a long time, but it is
16002 not specified by DWARF. It seems to have been
16003 emitted by gfortran at least as recently as:
16004 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16005 complaint (_("Variable in common block has "
16006 "DW_AT_data_member_location "
16007 "- DIE at %s [in module %s]"),
16008 sect_offset_str (child_die->sect_off),
16010
16011 if (member_loc->form_is_section_offset ())
16013 else if (member_loc->form_is_constant ()
16014 || member_loc->form_is_block ())
16015 {
16016 if (attr != nullptr)
16017 mark_common_block_symbol_computed (sym, die, attr,
16018 member_loc, cu);
16019 }
16020 else
16022 }
16023 }
16024 }
16025
16026 sym = new_symbol (die, objfile_type (objfile)->builtin_void, cu);
16028 }
16029}
16030
16031/* Create a type for a C++ namespace. */
16032
16033static struct type *
16034read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
16035{
16036 struct objfile *objfile = cu->per_objfile->objfile;
16037 const char *previous_prefix, *name;
16038 int is_anonymous;
16039 struct type *type;
16040
16041 /* For extensions, reuse the type of the original namespace. */
16042 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
16043 {
16044 struct die_info *ext_die;
16045 struct dwarf2_cu *ext_cu = cu;
16046
16047 ext_die = dwarf2_extension (die, &ext_cu);
16048 type = read_type_die (ext_die, ext_cu);
16049
16050 /* EXT_CU may not be the same as CU.
16051 Ensure TYPE is recorded with CU in die_type_hash. */
16052 return set_die_type (die, type, cu);
16053 }
16054
16055 name = namespace_name (die, &is_anonymous, cu);
16056
16057 /* Now build the name of the current namespace. */
16058
16059 previous_prefix = determine_prefix (die, cu);
16060 if (previous_prefix[0] != '\0')
16062 previous_prefix, name, 0, cu);
16063
16064 /* Create the type. */
16065 type = init_type (objfile, TYPE_CODE_NAMESPACE, 0, name);
16066
16067 return set_die_type (die, type, cu);
16068}
16069
16070/* Read a namespace scope. */
16071
16072static void
16073read_namespace (struct die_info *die, struct dwarf2_cu *cu)
16074{
16075 struct objfile *objfile = cu->per_objfile->objfile;
16076 int is_anonymous;
16077
16078 /* Add a symbol associated to this if we haven't seen the namespace
16079 before. Also, add a using directive if it's an anonymous
16080 namespace. */
16081
16082 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
16083 {
16084 struct type *type;
16085
16086 type = read_type_die (die, cu);
16087 new_symbol (die, type, cu);
16088
16089 namespace_name (die, &is_anonymous, cu);
16090 if (is_anonymous)
16091 {
16092 const char *previous_prefix = determine_prefix (die, cu);
16093
16094 std::vector<const char *> excludes;
16096 previous_prefix, type->name (), NULL,
16097 NULL, excludes, 0, &objfile->objfile_obstack);
16098 }
16099 }
16100
16101 if (die->child != NULL)
16102 {
16103 struct die_info *child_die = die->child;
16104
16105 while (child_die && child_die->tag)
16106 {
16107 process_die (child_die, cu);
16108 child_die = child_die->sibling;
16109 }
16110 }
16111}
16112
16113/* Read a Fortran module as type. This DIE can be only a declaration used for
16114 imported module. Still we need that type as local Fortran "use ... only"
16115 declaration imports depend on the created type in determine_prefix. */
16116
16117static struct type *
16118read_module_type (struct die_info *die, struct dwarf2_cu *cu)
16119{
16120 struct objfile *objfile = cu->per_objfile->objfile;
16121 const char *module_name;
16122 struct type *type;
16123
16124 module_name = dwarf2_name (die, cu);
16125 type = init_type (objfile, TYPE_CODE_MODULE, 0, module_name);
16126
16127 return set_die_type (die, type, cu);
16128}
16129
16130/* Read a Fortran module. */
16131
16132static void
16133read_module (struct die_info *die, struct dwarf2_cu *cu)
16134{
16135 struct die_info *child_die = die->child;
16136 struct type *type;
16137
16138 type = read_type_die (die, cu);
16139 new_symbol (die, type, cu);
16140
16141 while (child_die && child_die->tag)
16142 {
16143 process_die (child_die, cu);
16144 child_die = child_die->sibling;
16145 }
16146}
16147
16148/* Return the name of the namespace represented by DIE. Set
16149 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16150 namespace. */
16151
16152static const char *
16153namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
16154{
16155 struct die_info *current_die;
16156 const char *name = NULL;
16157
16158 /* Loop through the extensions until we find a name. */
16159
16160 for (current_die = die;
16161 current_die != NULL;
16162 current_die = dwarf2_extension (die, &cu))
16163 {
16164 /* We don't use dwarf2_name here so that we can detect the absence
16165 of a name -> anonymous namespace. */
16166 name = dwarf2_string_attr (die, DW_AT_name, cu);
16167
16168 if (name != NULL)
16169 break;
16170 }
16171
16172 /* Is it an anonymous namespace? */
16173
16174 *is_anonymous = (name == NULL);
16175 if (*is_anonymous)
16177
16178 return name;
16179}
16180
16181/* Extract all information from a DW_TAG_pointer_type DIE and add to
16182 the user defined type vector. */
16183
16184static struct type *
16186{
16187 struct gdbarch *gdbarch = cu->per_objfile->objfile->arch ();
16188 struct comp_unit_head *cu_header = &cu->header;
16189 struct type *type;
16190 struct attribute *attr_byte_size;
16191 struct attribute *attr_address_class;
16192 int byte_size, addr_class;
16193 struct type *target_type;
16194
16195 target_type = die_type (die, cu);
16196
16197 /* The die_type call above may have already set the type for this DIE. */
16198 type = get_die_type (die, cu);
16199 if (type)
16200 return type;
16201
16203
16204 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
16205 if (attr_byte_size)
16206 byte_size = attr_byte_size->constant_value (cu_header->addr_size);
16207 else
16208 byte_size = cu_header->addr_size;
16209
16210 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
16211 if (attr_address_class)
16212 addr_class = attr_address_class->constant_value (DW_ADDR_none);
16213 else
16214 addr_class = DW_ADDR_none;
16215
16216 ULONGEST alignment = get_alignment (cu, die);
16217
16218 /* If the pointer size, alignment, or address class is different
16219 than the default, create a type variant marked as such and set
16220 the length accordingly. */
16221 if (type->length () != byte_size
16222 || (alignment != 0 && TYPE_RAW_ALIGN (type) != 0
16223 && alignment != TYPE_RAW_ALIGN (type))
16224 || addr_class != DW_ADDR_none)
16225 {
16227 {
16228 type_instance_flags type_flags
16230 addr_class);
16231 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
16232 == 0);
16233 type = make_type_with_address_space (type, type_flags);
16234 }
16235 else if (type->length () != byte_size)
16236 {
16237 complaint (_("invalid pointer size %d"), byte_size);
16238 }
16239 else if (TYPE_RAW_ALIGN (type) != alignment)
16240 {
16241 complaint (_("Invalid DW_AT_alignment"
16242 " - DIE at %s [in module %s]"),
16245 }
16246 else
16247 {
16248 /* Should we also complain about unhandled address classes? */
16249 }
16250 }
16251
16252 type->set_length (byte_size);
16253 set_type_align (type, alignment);
16254 return set_die_type (die, type, cu);
16255}
16256
16257/* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16258 the user defined type vector. */
16259
16260static struct type *
16262{
16263 struct type *type;
16264 struct type *to_type;
16265 struct type *domain;
16266
16267 to_type = die_type (die, cu);
16268 domain = die_containing_type (die, cu);
16269
16270 /* The calls above may have already set the type for this DIE. */
16271 type = get_die_type (die, cu);
16272 if (type)
16273 return type;
16274
16275 if (check_typedef (to_type)->code () == TYPE_CODE_METHOD)
16276 type = lookup_methodptr_type (to_type);
16277 else if (check_typedef (to_type)->code () == TYPE_CODE_FUNC)
16278 {
16279 struct type *new_type = alloc_type (cu->per_objfile->objfile);
16280
16281 smash_to_method_type (new_type, domain, to_type->target_type (),
16282 to_type->fields (), to_type->num_fields (),
16283 to_type->has_varargs ());
16285 }
16286 else
16287 type = lookup_memberptr_type (to_type, domain);
16288
16289 return set_die_type (die, type, cu);
16290}
16291
16292/* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16293 the user defined type vector. */
16294
16295static struct type *
16297 enum type_code refcode)
16298{
16299 struct comp_unit_head *cu_header = &cu->header;
16300 struct type *type, *target_type;
16301 struct attribute *attr;
16302
16303 gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
16304
16305 target_type = die_type (die, cu);
16306
16307 /* The die_type call above may have already set the type for this DIE. */
16308 type = get_die_type (die, cu);
16309 if (type)
16310 return type;
16311
16312 type = lookup_reference_type (target_type, refcode);
16313 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
16314 if (attr != nullptr)
16315 type->set_length (attr->constant_value (cu_header->addr_size));
16316 else
16317 type->set_length (cu_header->addr_size);
16318
16319 maybe_set_alignment (cu, die, type);
16320 return set_die_type (die, type, cu);
16321}
16322
16323/* Add the given cv-qualifiers to the element type of the array. GCC
16324 outputs DWARF type qualifiers that apply to an array, not the
16325 element type. But GDB relies on the array element type to carry
16326 the cv-qualifiers. This mimics section 6.7.3 of the C99
16327 specification. */
16328
16329static struct type *
16330add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
16331 struct type *base_type, int cnst, int voltl)
16332{
16333 struct type *el_type, *inner_array;
16334
16335 base_type = copy_type (base_type);
16336 inner_array = base_type;
16337
16338 while (inner_array->target_type ()->code () == TYPE_CODE_ARRAY)
16339 {
16340 inner_array->set_target_type (copy_type (inner_array->target_type ()));
16341 inner_array = inner_array->target_type ();
16342 }
16343
16344 el_type = inner_array->target_type ();
16345 cnst |= TYPE_CONST (el_type);
16346 voltl |= TYPE_VOLATILE (el_type);
16347 inner_array->set_target_type (make_cv_type (cnst, voltl, el_type, NULL));
16348
16349 return set_die_type (die, base_type, cu);
16350}
16351
16352static struct type *
16353read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
16354{
16355 struct type *base_type, *cv_type;
16356
16357 base_type = die_type (die, cu);
16358
16359 /* The die_type call above may have already set the type for this DIE. */
16360 cv_type = get_die_type (die, cu);
16361 if (cv_type)
16362 return cv_type;
16363
16364 /* In case the const qualifier is applied to an array type, the element type
16365 is so qualified, not the array type (section 6.7.3 of C99). */
16366 if (base_type->code () == TYPE_CODE_ARRAY)
16367 return add_array_cv_type (die, cu, base_type, 1, 0);
16368
16369 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
16370 return set_die_type (die, cv_type, cu);
16371}
16372
16373static struct type *
16375{
16376 struct type *base_type, *cv_type;
16377
16378 base_type = die_type (die, cu);
16379
16380 /* The die_type call above may have already set the type for this DIE. */
16381 cv_type = get_die_type (die, cu);
16382 if (cv_type)
16383 return cv_type;
16384
16385 /* In case the volatile qualifier is applied to an array type, the
16386 element type is so qualified, not the array type (section 6.7.3
16387 of C99). */
16388 if (base_type->code () == TYPE_CODE_ARRAY)
16389 return add_array_cv_type (die, cu, base_type, 0, 1);
16390
16391 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
16392 return set_die_type (die, cv_type, cu);
16393}
16394
16395/* Handle DW_TAG_restrict_type. */
16396
16397static struct type *
16399{
16400 struct type *base_type, *cv_type;
16401
16402 base_type = die_type (die, cu);
16403
16404 /* The die_type call above may have already set the type for this DIE. */
16405 cv_type = get_die_type (die, cu);
16406 if (cv_type)
16407 return cv_type;
16408
16409 cv_type = make_restrict_type (base_type);
16410 return set_die_type (die, cv_type, cu);
16411}
16412
16413/* Handle DW_TAG_atomic_type. */
16414
16415static struct type *
16416read_tag_atomic_type (struct die_info *die, struct dwarf2_cu *cu)
16417{
16418 struct type *base_type, *cv_type;
16419
16420 base_type = die_type (die, cu);
16421
16422 /* The die_type call above may have already set the type for this DIE. */
16423 cv_type = get_die_type (die, cu);
16424 if (cv_type)
16425 return cv_type;
16426
16427 cv_type = make_atomic_type (base_type);
16428 return set_die_type (die, cv_type, cu);
16429}
16430
16431/* Extract all information from a DW_TAG_string_type DIE and add to
16432 the user defined type vector. It isn't really a user defined type,
16433 but it behaves like one, with other DIE's using an AT_user_def_type
16434 attribute to reference it. */
16435
16436static struct type *
16437read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
16438{
16439 struct objfile *objfile = cu->per_objfile->objfile;
16440 struct gdbarch *gdbarch = objfile->arch ();
16441 struct type *type, *range_type, *index_type, *char_type;
16442 struct attribute *attr;
16443 struct dynamic_prop prop;
16444 bool length_is_constant = true;
16445 LONGEST length;
16446
16447 /* There are a couple of places where bit sizes might be made use of
16448 when parsing a DW_TAG_string_type, however, no producer that we know
16449 of make use of these. Handling bit sizes that are a multiple of the
16450 byte size is easy enough, but what about other bit sizes? Lets deal
16451 with that problem when we have to. Warn about these attributes being
16452 unsupported, then parse the type and ignore them like we always
16453 have. */
16454 if (dwarf2_attr (die, DW_AT_bit_size, cu) != nullptr
16455 || dwarf2_attr (die, DW_AT_string_length_bit_size, cu) != nullptr)
16456 {
16457 static bool warning_printed = false;
16458 if (!warning_printed)
16459 {
16460 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16461 "currently supported on DW_TAG_string_type."));
16462 warning_printed = true;
16463 }
16464 }
16465
16466 attr = dwarf2_attr (die, DW_AT_string_length, cu);
16467 if (attr != nullptr && !attr->form_is_constant ())
16468 {
16469 /* The string length describes the location at which the length of
16470 the string can be found. The size of the length field can be
16471 specified with one of the attributes below. */
16472 struct type *prop_type;
16473 struct attribute *len
16474 = dwarf2_attr (die, DW_AT_string_length_byte_size, cu);
16475 if (len == nullptr)
16476 len = dwarf2_attr (die, DW_AT_byte_size, cu);
16477 if (len != nullptr && len->form_is_constant ())
16478 {
16479 /* Pass 0 as the default as we know this attribute is constant
16480 and the default value will not be returned. */
16481 LONGEST sz = len->constant_value (0);
16482 prop_type = objfile_int_type (objfile, sz, true);
16483 }
16484 else
16485 {
16486 /* If the size is not specified then we assume it is the size of
16487 an address on this target. */
16488 prop_type = cu->addr_sized_int_type (true);
16489 }
16490
16491 /* Convert the attribute into a dynamic property. */
16492 if (!attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
16493 length = 1;
16494 else
16495 length_is_constant = false;
16496 }
16497 else if (attr != nullptr)
16498 {
16499 /* This DW_AT_string_length just contains the length with no
16500 indirection. There's no need to create a dynamic property in this
16501 case. Pass 0 for the default value as we know it will not be
16502 returned in this case. */
16503 length = attr->constant_value (0);
16504 }
16505 else if ((attr = dwarf2_attr (die, DW_AT_byte_size, cu)) != nullptr)
16506 {
16507 /* We don't currently support non-constant byte sizes for strings. */
16508 length = attr->constant_value (1);
16509 }
16510 else
16511 {
16512 /* Use 1 as a fallback length if we have nothing else. */
16513 length = 1;
16514 }
16515
16516 index_type = objfile_type (objfile)->builtin_int;
16517 if (length_is_constant)
16518 range_type = create_static_range_type (NULL, index_type, 1, length);
16519 else
16520 {
16521 struct dynamic_prop low_bound;
16522
16523 low_bound.set_const_val (1);
16524 range_type = create_range_type (NULL, index_type, &low_bound, &prop, 0);
16525 }
16527 type = create_string_type (NULL, char_type, range_type);
16528
16529 return set_die_type (die, type, cu);
16530}
16531
16532/* Assuming that DIE corresponds to a function, returns nonzero
16533 if the function is prototyped. */
16534
16535static int
16537{
16538 struct attribute *attr;
16539
16540 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
16541 if (attr && attr->as_boolean ())
16542 return 1;
16543
16544 /* The DWARF standard implies that the DW_AT_prototyped attribute
16545 is only meaningful for C, but the concept also extends to other
16546 languages that allow unprototyped functions (Eg: Objective C).
16547 For all other languages, assume that functions are always
16548 prototyped. */
16549 if (cu->lang () != language_c
16550 && cu->lang () != language_objc
16551 && cu->lang () != language_opencl)
16552 return 1;
16553
16554 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16555 prototyped and unprototyped functions; default to prototyped,
16556 since that is more common in modern code (and RealView warns
16557 about unprototyped functions). */
16559 return 1;
16560
16561 return 0;
16562}
16563
16564/* Handle DIES due to C code like:
16565
16566 struct foo
16567 {
16568 int (*funcp)(int a, long l);
16569 int b;
16570 };
16571
16572 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16573
16574static struct type *
16575read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
16576{
16577 struct objfile *objfile = cu->per_objfile->objfile;
16578 struct type *type; /* Type that this function returns. */
16579 struct type *ftype; /* Function that returns above type. */
16580 struct attribute *attr;
16581
16582 type = die_type (die, cu);
16583
16584 /* The die_type call above may have already set the type for this DIE. */
16585 ftype = get_die_type (die, cu);
16586 if (ftype)
16587 return ftype;
16588
16589 ftype = lookup_function_type (type);
16590
16591 if (prototyped_function_p (die, cu))
16592 ftype->set_is_prototyped (true);
16593
16594 /* Store the calling convention in the type if it's available in
16595 the subroutine die. Otherwise set the calling convention to
16596 the default value DW_CC_normal. */
16597 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
16598 if (attr != nullptr
16601 = (enum dwarf_calling_convention) attr->constant_value (0);
16602 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
16603 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
16604 else
16605 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
16606
16607 /* Record whether the function returns normally to its caller or not
16608 if the DWARF producer set that information. */
16609 attr = dwarf2_attr (die, DW_AT_noreturn, cu);
16610 if (attr && attr->as_boolean ())
16611 TYPE_NO_RETURN (ftype) = 1;
16612
16613 /* We need to add the subroutine type to the die immediately so
16614 we don't infinitely recurse when dealing with parameters
16615 declared as the same subroutine type. */
16616 set_die_type (die, ftype, cu);
16617
16618 if (die->child != NULL)
16619 {
16620 struct type *void_type = objfile_type (objfile)->builtin_void;
16621 struct die_info *child_die;
16622 int nparams, iparams;
16623
16624 /* Count the number of parameters.
16625 FIXME: GDB currently ignores vararg functions, but knows about
16626 vararg member functions. */
16627 nparams = 0;
16628 child_die = die->child;
16629 while (child_die && child_die->tag)
16630 {
16631 if (child_die->tag == DW_TAG_formal_parameter)
16632 nparams++;
16633 else if (child_die->tag == DW_TAG_unspecified_parameters)
16634 ftype->set_has_varargs (true);
16635
16636 child_die = child_die->sibling;
16637 }
16638
16639 /* Allocate storage for parameters and fill them in. */
16640 ftype->set_num_fields (nparams);
16641 ftype->set_fields
16642 ((struct field *) TYPE_ZALLOC (ftype, nparams * sizeof (struct field)));
16643
16644 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16645 even if we error out during the parameters reading below. */
16646 for (iparams = 0; iparams < nparams; iparams++)
16647 ftype->field (iparams).set_type (void_type);
16648
16649 iparams = 0;
16650 child_die = die->child;
16651 while (child_die && child_die->tag)
16652 {
16653 if (child_die->tag == DW_TAG_formal_parameter)
16654 {
16655 struct type *arg_type;
16656
16657 /* DWARF version 2 has no clean way to discern C++
16658 static and non-static member functions. G++ helps
16659 GDB by marking the first parameter for non-static
16660 member functions (which is the this pointer) as
16661 artificial. We pass this information to
16662 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16663
16664 DWARF version 3 added DW_AT_object_pointer, which GCC
16665 4.5 does not yet generate. */
16666 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
16667 if (attr != nullptr)
16668 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = attr->as_boolean ();
16669 else
16670 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
16671 arg_type = die_type (child_die, cu);
16672
16673 /* RealView does not mark THIS as const, which the testsuite
16674 expects. GCC marks THIS as const in method definitions,
16675 but not in the class specifications (GCC PR 43053). */
16676 if (cu->lang () == language_cplus
16677 && !TYPE_CONST (arg_type)
16678 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
16679 {
16680 int is_this = 0;
16681 struct dwarf2_cu *arg_cu = cu;
16682 const char *name = dwarf2_name (child_die, cu);
16683
16684 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
16685 if (attr != nullptr)
16686 {
16687 /* If the compiler emits this, use it. */
16688 if (follow_die_ref (die, attr, &arg_cu) == child_die)
16689 is_this = 1;
16690 }
16691 else if (name && strcmp (name, "this") == 0)
16692 /* Function definitions will have the argument names. */
16693 is_this = 1;
16694 else if (name == NULL && iparams == 0)
16695 /* Declarations may not have the names, so like
16696 elsewhere in GDB, assume an artificial first
16697 argument is "this". */
16698 is_this = 1;
16699
16700 if (is_this)
16701 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
16702 arg_type, 0);
16703 }
16704
16705 ftype->field (iparams).set_type (arg_type);
16706 iparams++;
16707 }
16708 child_die = child_die->sibling;
16709 }
16710 }
16711
16712 return ftype;
16713}
16714
16715static struct type *
16716read_typedef (struct die_info *die, struct dwarf2_cu *cu)
16717{
16718 struct objfile *objfile = cu->per_objfile->objfile;
16719 const char *name = NULL;
16720 struct type *this_type, *target_type;
16721
16722 name = dwarf2_full_name (NULL, die, cu);
16723 this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, name);
16724 this_type->set_target_is_stub (true);
16725 set_die_type (die, this_type, cu);
16726 target_type = die_type (die, cu);
16727 if (target_type != this_type)
16728 this_type->set_target_type (target_type);
16729 else
16730 {
16731 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16732 spec and cause infinite loops in GDB. */
16733 complaint (_("Self-referential DW_TAG_typedef "
16734 "- DIE at %s [in module %s]"),
16736 this_type->set_target_type (nullptr);
16737 }
16738 if (name == NULL)
16739 {
16740 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16741 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16742 Handle these by just returning the target type, rather than
16743 constructing an anonymous typedef type and trying to handle this
16744 elsewhere. */
16745 set_die_type (die, target_type, cu);
16746 return target_type;
16747 }
16748 return this_type;
16749}
16750
16751/* Helper for get_dwarf2_rational_constant that computes the value of
16752 a given gmp_mpz given an attribute. */
16753
16754static void
16755get_mpz (struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr)
16756{
16757 /* GCC will sometimes emit a 16-byte constant value as a DWARF
16758 location expression that pushes an implicit value. */
16759 if (attr->form == DW_FORM_exprloc)
16760 {
16761 dwarf_block *blk = attr->as_block ();
16762 if (blk->size > 0 && blk->data[0] == DW_OP_implicit_value)
16763 {
16764 uint64_t len;
16765 const gdb_byte *ptr = safe_read_uleb128 (blk->data + 1,
16766 blk->data + blk->size,
16767 &len);
16768 if (ptr - blk->data + len <= blk->size)
16769 {
16770 mpz_import (value->val, len,
16771 bfd_big_endian (cu->per_objfile->objfile->obfd.get ())
16772 ? 1 : -1,
16773 1, 0, 0, ptr);
16774 return;
16775 }
16776 }
16777
16778 /* On failure set it to 1. */
16779 *value = gdb_mpz (1);
16780 }
16781 else if (attr->form_is_block ())
16782 {
16783 dwarf_block *blk = attr->as_block ();
16784 mpz_import (value->val, blk->size,
16785 bfd_big_endian (cu->per_objfile->objfile->obfd.get ())
16786 ? 1 : -1,
16787 1, 0, 0, blk->data);
16788 }
16789 else
16790 *value = gdb_mpz (attr->constant_value (1));
16791}
16792
16793/* Assuming DIE is a rational DW_TAG_constant, read the DIE's
16794 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
16795
16796 If the numerator and/or numerator attribute is missing,
16797 a complaint is filed, and NUMERATOR and DENOMINATOR are left
16798 untouched. */
16799
16800static void
16802 gdb_mpz *numerator, gdb_mpz *denominator)
16803{
16804 struct attribute *num_attr, *denom_attr;
16805
16806 num_attr = dwarf2_attr (die, DW_AT_GNU_numerator, cu);
16807 if (num_attr == nullptr)
16808 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
16810
16811 denom_attr = dwarf2_attr (die, DW_AT_GNU_denominator, cu);
16812 if (denom_attr == nullptr)
16813 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
16815
16816 if (num_attr == nullptr || denom_attr == nullptr)
16817 return;
16818
16819 get_mpz (cu, numerator, num_attr);
16820 get_mpz (cu, denominator, denom_attr);
16821}
16822
16823/* Same as get_dwarf2_rational_constant, but extracting an unsigned
16824 rational constant, rather than a signed one.
16825
16826 If the rational constant has a negative value, a complaint
16827 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
16828
16829static void
16831 struct dwarf2_cu *cu,
16832 gdb_mpz *numerator,
16833 gdb_mpz *denominator)
16834{
16835 gdb_mpz num (1);
16836 gdb_mpz denom (1);
16837
16838 get_dwarf2_rational_constant (die, cu, &num, &denom);
16839 if (mpz_sgn (num.val) == -1 && mpz_sgn (denom.val) == -1)
16840 {
16841 mpz_neg (num.val, num.val);
16842 mpz_neg (denom.val, denom.val);
16843 }
16844 else if (mpz_sgn (num.val) == -1)
16845 {
16846 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
16847 " in DIE at %s"),
16848 sect_offset_str (die->sect_off));
16849 return;
16850 }
16851 else if (mpz_sgn (denom.val) == -1)
16852 {
16853 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
16854 " in DIE at %s"),
16855 sect_offset_str (die->sect_off));
16856 return;
16857 }
16858
16859 *numerator = std::move (num);
16860 *denominator = std::move (denom);
16861}
16862
16863/* Assuming that ENCODING is a string whose contents starting at the
16864 K'th character is "_nn" where "nn" is a decimal number, scan that
16865 number and set RESULT to the value. K is updated to point to the
16866 character immediately following the number.
16867
16868 If the string does not conform to the format described above, false
16869 is returned, and K may or may not be changed. */
16870
16871static bool
16872ada_get_gnat_encoded_number (const char *encoding, int &k, gdb_mpz *result)
16873{
16874 /* The next character should be an underscore ('_') followed
16875 by a digit. */
16876 if (encoding[k] != '_' || !isdigit (encoding[k + 1]))
16877 return false;
16878
16879 /* Skip the underscore. */
16880 k++;
16881 int start = k;
16882
16883 /* Determine the number of digits for our number. */
16884 while (isdigit (encoding[k]))
16885 k++;
16886 if (k == start)
16887 return false;
16888
16889 std::string copy (&encoding[start], k - start);
16890 if (mpz_set_str (result->val, copy.c_str (), 10) == -1)
16891 return false;
16892
16893 return true;
16894}
16895
16896/* Scan two numbers from ENCODING at OFFSET, assuming the string is of
16897 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
16898 DENOM, update OFFSET, and return true on success. Return false on
16899 failure. */
16900
16901static bool
16902ada_get_gnat_encoded_ratio (const char *encoding, int &offset,
16903 gdb_mpz *num, gdb_mpz *denom)
16904{
16905 if (!ada_get_gnat_encoded_number (encoding, offset, num))
16906 return false;
16907 return ada_get_gnat_encoded_number (encoding, offset, denom);
16908}
16909
16910/* Assuming DIE corresponds to a fixed point type, finish the creation
16911 of the corresponding TYPE by setting its type-specific data. CU is
16912 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
16913 encodings. It is nullptr if the GNAT encoding should be
16914 ignored. */
16915
16916static void
16917finish_fixed_point_type (struct type *type, const char *suffix,
16918 struct die_info *die, struct dwarf2_cu *cu)
16919{
16920 gdb_assert (type->code () == TYPE_CODE_FIXED_POINT
16922
16923 /* If GNAT encodings are preferred, don't examine the
16924 attributes. */
16925 struct attribute *attr = nullptr;
16926 if (suffix == nullptr)
16927 {
16928 attr = dwarf2_attr (die, DW_AT_binary_scale, cu);
16929 if (attr == nullptr)
16930 attr = dwarf2_attr (die, DW_AT_decimal_scale, cu);
16931 if (attr == nullptr)
16932 attr = dwarf2_attr (die, DW_AT_small, cu);
16933 }
16934
16935 /* Numerator and denominator of our fixed-point type's scaling factor.
16936 The default is a scaling factor of 1, which we use as a fallback
16937 when we are not able to decode it (problem with the debugging info,
16938 unsupported forms, bug in GDB, etc...). Using that as the default
16939 allows us to at least print the unscaled value, which might still
16940 be useful to a user. */
16941 gdb_mpz scale_num (1);
16942 gdb_mpz scale_denom (1);
16943
16944 if (attr == nullptr)
16945 {
16946 int offset = 0;
16947 if (suffix != nullptr
16948 && ada_get_gnat_encoded_ratio (suffix, offset, &scale_num,
16949 &scale_denom)
16950 /* The number might be encoded as _nn_dd_nn_dd, where the
16951 second ratio is the 'small value. In this situation, we
16952 want the second value. */
16953 && (suffix[offset] != '_'
16954 || ada_get_gnat_encoded_ratio (suffix, offset, &scale_num,
16955 &scale_denom)))
16956 {
16957 /* Found it. */
16958 }
16959 else
16960 {
16961 /* Scaling factor not found. Assume a scaling factor of 1,
16962 and hope for the best. At least the user will be able to
16963 see the encoded value. */
16964 scale_num = 1;
16965 scale_denom = 1;
16966 complaint (_("no scale found for fixed-point type (DIE at %s)"),
16967 sect_offset_str (die->sect_off));
16968 }
16969 }
16970 else if (attr->name == DW_AT_binary_scale)
16971 {
16972 LONGEST scale_exp = attr->constant_value (0);
16973 gdb_mpz *num_or_denom = scale_exp > 0 ? &scale_num : &scale_denom;
16974
16975 mpz_mul_2exp (num_or_denom->val, num_or_denom->val, std::abs (scale_exp));
16976 }
16977 else if (attr->name == DW_AT_decimal_scale)
16978 {
16979 LONGEST scale_exp = attr->constant_value (0);
16980 gdb_mpz *num_or_denom = scale_exp > 0 ? &scale_num : &scale_denom;
16981
16982 mpz_ui_pow_ui (num_or_denom->val, 10, std::abs (scale_exp));
16983 }
16984 else if (attr->name == DW_AT_small)
16985 {
16986 struct die_info *scale_die;
16987 struct dwarf2_cu *scale_cu = cu;
16988
16989 scale_die = follow_die_ref (die, attr, &scale_cu);
16990 if (scale_die->tag == DW_TAG_constant)
16991 get_dwarf2_unsigned_rational_constant (scale_die, scale_cu,
16992 &scale_num, &scale_denom);
16993 else
16994 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
16995 " (DIE at %s)"),
16997 }
16998 else
16999 {
17000 complaint (_("unsupported scale attribute %s for fixed-point type"
17001 " (DIE at %s)"),
17002 dwarf_attr_name (attr->name),
17003 sect_offset_str (die->sect_off));
17004 }
17005
17006 gdb_mpq &scaling_factor = type->fixed_point_info ().scaling_factor;
17007 mpz_set (mpq_numref (scaling_factor.val), scale_num.val);
17008 mpz_set (mpq_denref (scaling_factor.val), scale_denom.val);
17009 mpq_canonicalize (scaling_factor.val);
17010}
17011
17012/* The gnat-encoding suffix for fixed point. */
17013
17014#define GNAT_FIXED_POINT_SUFFIX "___XF_"
17015
17016/* If NAME encodes an Ada fixed-point type, return a pointer to the
17017 "XF" suffix of the name. The text after this is what encodes the
17018 'small and 'delta information. Otherwise, return nullptr. */
17019
17020static const char *
17022{
17023 return strstr (name, GNAT_FIXED_POINT_SUFFIX);
17024}
17025
17026/* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17027 (which may be different from NAME) to the architecture back-end to allow
17028 it to guess the correct format if necessary. */
17029
17030static struct type *
17032 const char *name_hint, enum bfd_endian byte_order)
17033{
17034 struct gdbarch *gdbarch = objfile->arch ();
17035 const struct floatformat **format;
17036 struct type *type;
17037
17038 format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
17039 if (format)
17040 type = init_float_type (objfile, bits, name, format, byte_order);
17041 else
17042 type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
17043
17044 return type;
17045}
17046
17047/* Allocate an integer type of size BITS and name NAME. */
17048
17049static struct type *
17051 int bits, int unsigned_p, const char *name)
17052{
17053 struct type *type;
17054
17055 /* Versions of Intel's C Compiler generate an integer type called "void"
17056 instead of using DW_TAG_unspecified_type. This has been seen on
17057 at least versions 14, 17, and 18. */
17058 if (bits == 0 && producer_is_icc (cu) && name != nullptr
17059 && strcmp (name, "void") == 0)
17061 else
17062 type = init_integer_type (objfile, bits, unsigned_p, name);
17063
17064 return type;
17065}
17066
17067/* Return true if DIE has a DW_AT_small attribute whose value is
17068 a constant rational, where both the numerator and denominator
17069 are equal to zero.
17070
17071 CU is the DIE's Compilation Unit. */
17072
17073static bool
17075 struct dwarf2_cu *cu)
17076{
17077 struct attribute *attr = dwarf2_attr (die, DW_AT_small, cu);
17078 if (attr == nullptr)
17079 return false;
17080
17081 struct dwarf2_cu *scale_cu = cu;
17082 struct die_info *scale_die
17083 = follow_die_ref (die, attr, &scale_cu);
17084
17085 if (scale_die->tag != DW_TAG_constant)
17086 return false;
17087
17088 gdb_mpz num (1), denom (1);
17089 get_dwarf2_rational_constant (scale_die, cu, &num, &denom);
17090 return mpz_sgn (num.val) == 0 && mpz_sgn (denom.val) == 0;
17091}
17092
17093/* Initialise and return a floating point type of size BITS suitable for
17094 use as a component of a complex number. The NAME_HINT is passed through
17095 when initialising the floating point type and is the name of the complex
17096 type.
17097
17098 As DWARF doesn't currently provide an explicit name for the components
17099 of a complex number, but it can be helpful to have these components
17100 named, we try to select a suitable name based on the size of the
17101 component. */
17102static struct type *
17104 struct objfile *objfile,
17105 int bits, const char *name_hint,
17106 enum bfd_endian byte_order)
17107{
17108 gdbarch *gdbarch = objfile->arch ();
17109 struct type *tt = nullptr;
17110
17111 /* Try to find a suitable floating point builtin type of size BITS.
17112 We're going to use the name of this type as the name for the complex
17113 target type that we are about to create. */
17114 switch (cu->lang ())
17115 {
17116 case language_fortran:
17117 switch (bits)
17118 {
17119 case 32:
17121 break;
17122 case 64:
17124 break;
17125 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17126 case 128:
17128 break;
17129 }
17130 break;
17131 default:
17132 switch (bits)
17133 {
17134 case 32:
17136 break;
17137 case 64:
17139 break;
17140 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17141 case 128:
17143 break;
17144 }
17145 break;
17146 }
17147
17148 /* If the type we found doesn't match the size we were looking for, then
17149 pretend we didn't find a type at all, the complex target type we
17150 create will then be nameless. */
17151 if (tt != nullptr && tt->length () * TARGET_CHAR_BIT != bits)
17152 tt = nullptr;
17153
17154 const char *name = (tt == nullptr) ? nullptr : tt->name ();
17155 return dwarf2_init_float_type (objfile, bits, name, name_hint, byte_order);
17156}
17157
17158/* Find a representation of a given base type and install
17159 it in the TYPE field of the die. */
17160
17161static struct type *
17162read_base_type (struct die_info *die, struct dwarf2_cu *cu)
17163{
17164 struct objfile *objfile = cu->per_objfile->objfile;
17165 struct type *type;
17166 struct attribute *attr;
17167 int encoding = 0, bits = 0;
17168 const char *name;
17169 gdbarch *arch;
17170
17171 attr = dwarf2_attr (die, DW_AT_encoding, cu);
17172 if (attr != nullptr && attr->form_is_constant ())
17173 encoding = attr->constant_value (0);
17174 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
17175 if (attr != nullptr)
17176 bits = attr->constant_value (0) * TARGET_CHAR_BIT;
17177 name = dwarf2_name (die, cu);
17178 if (!name)
17179 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17180
17181 arch = objfile->arch ();
17182 enum bfd_endian byte_order = gdbarch_byte_order (arch);
17183
17184 attr = dwarf2_attr (die, DW_AT_endianity, cu);
17185 if (attr != nullptr && attr->form_is_constant ())
17186 {
17187 int endianity = attr->constant_value (0);
17188
17189 switch (endianity)
17190 {
17191 case DW_END_big:
17192 byte_order = BFD_ENDIAN_BIG;
17193 break;
17194 case DW_END_little:
17195 byte_order = BFD_ENDIAN_LITTLE;
17196 break;
17197 default:
17198 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity);
17199 break;
17200 }
17201 }
17202
17203 if ((encoding == DW_ATE_signed_fixed || encoding == DW_ATE_unsigned_fixed)
17204 && cu->lang () == language_ada
17206 {
17207 /* brobecker/2018-02-24: This is a fixed point type for which
17208 the scaling factor is represented as fraction whose value
17209 does not make sense (zero divided by zero), so we should
17210 normally never see these. However, there is a small category
17211 of fixed point types for which GNAT is unable to provide
17212 the scaling factor via the standard DWARF mechanisms, and
17213 for which the info is provided via the GNAT encodings instead.
17214 This is likely what this DIE is about. */
17215 encoding = (encoding == DW_ATE_signed_fixed
17216 ? DW_ATE_signed
17217 : DW_ATE_unsigned);
17218 }
17219
17220 /* With GNAT encodings, fixed-point information will be encoded in
17221 the type name. Note that this can also occur with the above
17222 zero-over-zero case, which is why this is a separate "if" rather
17223 than an "else if". */
17224 const char *gnat_encoding_suffix = nullptr;
17225 if ((encoding == DW_ATE_signed || encoding == DW_ATE_unsigned)
17226 && cu->lang () == language_ada
17227 && name != nullptr)
17228 {
17229 gnat_encoding_suffix = gnat_encoded_fixed_point_type_info (name);
17230 if (gnat_encoding_suffix != nullptr)
17231 {
17232 gdb_assert (startswith (gnat_encoding_suffix,
17234 name = obstack_strndup (&cu->per_objfile->objfile->objfile_obstack,
17235 name, gnat_encoding_suffix - name);
17236 /* Use -1 here so that SUFFIX points at the "_" after the
17237 "XF". */
17238 gnat_encoding_suffix += strlen (GNAT_FIXED_POINT_SUFFIX) - 1;
17239
17240 encoding = (encoding == DW_ATE_signed
17241 ? DW_ATE_signed_fixed
17242 : DW_ATE_unsigned_fixed);
17243 }
17244 }
17245
17246 switch (encoding)
17247 {
17248 case DW_ATE_address:
17249 /* Turn DW_ATE_address into a void * pointer. */
17250 type = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
17252 break;
17253 case DW_ATE_boolean:
17255 break;
17256 case DW_ATE_complex_float:
17258 byte_order);
17259 if (type->code () == TYPE_CODE_ERROR)
17260 {
17261 if (name == nullptr)
17262 {
17263 struct obstack *obstack
17265 name = obconcat (obstack, "_Complex ", type->name (),
17266 nullptr);
17267 }
17268 type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
17269 }
17270 else
17272 break;
17273 case DW_ATE_decimal_float:
17275 break;
17276 case DW_ATE_float:
17277 type = dwarf2_init_float_type (objfile, bits, name, name, byte_order);
17278 break;
17279 case DW_ATE_signed:
17281 break;
17282 case DW_ATE_unsigned:
17283 if (cu->lang () == language_fortran
17284 && name
17285 && startswith (name, "character("))
17287 else
17289 break;
17290 case DW_ATE_signed_char:
17291 if (cu->lang () == language_ada
17292 || cu->lang () == language_m2
17293 || cu->lang () == language_pascal
17294 || cu->lang () == language_fortran)
17296 else
17298 break;
17299 case DW_ATE_unsigned_char:
17300 if (cu->lang () == language_ada
17301 || cu->lang () == language_m2
17302 || cu->lang () == language_pascal
17303 || cu->lang () == language_fortran
17304 || cu->lang () == language_rust)
17306 else
17308 break;
17309 case DW_ATE_UTF:
17310 {
17312 return set_die_type (die, type, cu);
17313 }
17314 break;
17315 case DW_ATE_signed_fixed:
17317 finish_fixed_point_type (type, gnat_encoding_suffix, die, cu);
17318 break;
17319 case DW_ATE_unsigned_fixed:
17321 finish_fixed_point_type (type, gnat_encoding_suffix, die, cu);
17322 break;
17323
17324 default:
17325 complaint (_("unsupported DW_AT_encoding: '%s'"),
17326 dwarf_type_encoding_name (encoding));
17327 type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
17328 break;
17329 }
17330
17331 if (type->code () == TYPE_CODE_INT
17332 && name != nullptr
17333 && strcmp (name, "char") == 0)
17335
17336 maybe_set_alignment (cu, die, type);
17337
17339
17341 {
17342 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
17343 if (attr != nullptr && attr->as_unsigned () <= 8 * type->length ())
17344 {
17345 unsigned real_bit_size = attr->as_unsigned ();
17346 attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
17347 /* Only use the attributes if they make sense together. */
17348 if (attr == nullptr
17349 || (attr->as_unsigned () + real_bit_size
17350 <= 8 * type->length ()))
17351 {
17352 TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size
17353 = real_bit_size;
17354 if (attr != nullptr)
17355 TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset
17356 = attr->as_unsigned ();
17357 }
17358 }
17359 }
17360
17361 return set_die_type (die, type, cu);
17362}
17363
17364/* A helper function that returns the name of DIE, if it refers to a
17365 variable declaration. */
17366
17367static const char *
17368var_decl_name (struct die_info *die, struct dwarf2_cu *cu)
17369{
17370 if (die->tag != DW_TAG_variable)
17371 return nullptr;
17372
17373 attribute *attr = dwarf2_attr (die, DW_AT_declaration, cu);
17374 if (attr == nullptr || !attr->as_boolean ())
17375 return nullptr;
17376
17377 attr = dwarf2_attr (die, DW_AT_name, cu);
17378 if (attr == nullptr)
17379 return nullptr;
17380 return attr->as_string ();
17381}
17382
17383/* Parse dwarf attribute if it's a block, reference or constant and put the
17384 resulting value of the attribute into struct bound_prop.
17385 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17386
17387static int
17388attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
17389 struct dwarf2_cu *cu, struct dynamic_prop *prop,
17390 struct type *default_type)
17391{
17392 struct dwarf2_property_baton *baton;
17393 dwarf2_per_objfile *per_objfile = cu->per_objfile;
17394 struct objfile *objfile = per_objfile->objfile;
17395 struct obstack *obstack = &objfile->objfile_obstack;
17396
17397 gdb_assert (default_type != NULL);
17398
17399 if (attr == NULL || prop == NULL)
17400 return 0;
17401
17402 if (attr->form_is_block ())
17403 {
17404 baton = XOBNEW (obstack, struct dwarf2_property_baton);
17405 baton->property_type = default_type;
17406 baton->locexpr.per_cu = cu->per_cu;
17407 baton->locexpr.per_objfile = per_objfile;
17408
17409 struct dwarf_block *block;
17410 if (attr->form == DW_FORM_data16)
17411 {
17412 size_t data_size = 16;
17413 block = XOBNEW (obstack, struct dwarf_block);
17414 block->size = (data_size
17415 + 2 /* Extra bytes for DW_OP and arg. */);
17416 gdb_byte *data = XOBNEWVEC (obstack, gdb_byte, block->size);
17417 data[0] = DW_OP_implicit_value;
17418 data[1] = data_size;
17419 memcpy (&data[2], attr->as_block ()->data, data_size);
17420 block->data = data;
17421 }
17422 else
17423 block = attr->as_block ();
17424
17425 baton->locexpr.size = block->size;
17426 baton->locexpr.data = block->data;
17427 switch (attr->name)
17428 {
17429 case DW_AT_string_length:
17430 baton->locexpr.is_reference = true;
17431 break;
17432 default:
17433 baton->locexpr.is_reference = false;
17434 break;
17435 }
17436
17437 prop->set_locexpr (baton);
17438 gdb_assert (prop->baton () != NULL);
17439 }
17440 else if (attr->form_is_ref ())
17441 {
17442 struct dwarf2_cu *target_cu = cu;
17443 struct die_info *target_die;
17444 struct attribute *target_attr;
17445
17446 target_die = follow_die_ref (die, attr, &target_cu);
17447 target_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
17448 if (target_attr == NULL)
17449 target_attr = dwarf2_attr (target_die, DW_AT_data_member_location,
17450 target_cu);
17451 if (target_attr == nullptr)
17452 target_attr = dwarf2_attr (target_die, DW_AT_data_bit_offset,
17453 target_cu);
17454 if (target_attr == NULL)
17455 {
17456 const char *name = var_decl_name (target_die, target_cu);
17457 if (name != nullptr)
17458 {
17459 prop->set_variable_name (name);
17460 return 1;
17461 }
17462 return 0;
17463 }
17464
17465 switch (target_attr->name)
17466 {
17467 case DW_AT_location:
17468 if (target_attr->form_is_section_offset ())
17469 {
17470 baton = XOBNEW (obstack, struct dwarf2_property_baton);
17471 baton->property_type = die_type (target_die, target_cu);
17472 fill_in_loclist_baton (cu, &baton->loclist, target_attr);
17473 prop->set_loclist (baton);
17474 gdb_assert (prop->baton () != NULL);
17475 }
17476 else if (target_attr->form_is_block ())
17477 {
17478 baton = XOBNEW (obstack, struct dwarf2_property_baton);
17479 baton->property_type = die_type (target_die, target_cu);
17480 baton->locexpr.per_cu = cu->per_cu;
17481 baton->locexpr.per_objfile = per_objfile;
17482 struct dwarf_block *block = target_attr->as_block ();
17483 baton->locexpr.size = block->size;
17484 baton->locexpr.data = block->data;
17485 baton->locexpr.is_reference = true;
17486 prop->set_locexpr (baton);
17487 gdb_assert (prop->baton () != NULL);
17488 }
17489 else
17490 {
17491 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17492 "dynamic property");
17493 return 0;
17494 }
17495 break;
17496 case DW_AT_data_member_location:
17497 case DW_AT_data_bit_offset:
17498 {
17499 LONGEST offset;
17500
17501 if (!handle_member_location (target_die, target_cu, &offset))
17502 return 0;
17503
17504 baton = XOBNEW (obstack, struct dwarf2_property_baton);
17505 baton->property_type = read_type_die (target_die->parent,
17506 target_cu);
17507 baton->offset_info.offset = offset;
17508 baton->offset_info.type = die_type (target_die, target_cu);
17509 prop->set_addr_offset (baton);
17510 break;
17511 }
17512 }
17513 }
17514 else if (attr->form_is_constant ())
17515 prop->set_const_val (attr->constant_value (0));
17516 else if (attr->form_is_section_offset ())
17517 {
17518 switch (attr->name)
17519 {
17520 case DW_AT_string_length:
17521 baton = XOBNEW (obstack, struct dwarf2_property_baton);
17522 baton->property_type = default_type;
17523 fill_in_loclist_baton (cu, &baton->loclist, attr);
17524 prop->set_loclist (baton);
17525 gdb_assert (prop->baton () != NULL);
17526 break;
17527 default:
17528 goto invalid;
17529 }
17530 }
17531 else
17532 goto invalid;
17533
17534 return 1;
17535
17536 invalid:
17538 dwarf2_name (die, cu));
17539 return 0;
17540}
17541
17542/* See read.h. */
17543
17544/* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17545 present (which is valid) then compute the default type based on the
17546 compilation units address size. */
17547
17548static struct type *
17550{
17551 struct type *index_type = die_type (die, cu);
17552
17553 /* Dwarf-2 specifications explicitly allows to create subrange types
17554 without specifying a base type.
17555 In that case, the base type must be set to the type of
17556 the lower bound, upper bound or count, in that order, if any of these
17557 three attributes references an object that has a type.
17558 If no base type is found, the Dwarf-2 specifications say that
17559 a signed integer type of size equal to the size of an address should
17560 be used.
17561 For the following C code: `extern char gdb_int [];'
17562 GCC produces an empty range DIE.
17563 FIXME: muller/2010-05-28: Possible references to object for low bound,
17564 high bound or count are not yet handled by this code. */
17565 if (index_type->code () == TYPE_CODE_VOID)
17566 index_type = cu->addr_sized_int_type (false);
17567
17568 return index_type;
17569}
17570
17571/* Read the given DW_AT_subrange DIE. */
17572
17573static struct type *
17574read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
17575{
17576 struct type *base_type, *orig_base_type;
17577 struct type *range_type;
17578 struct attribute *attr;
17579 struct dynamic_prop low, high;
17580 int low_default_is_valid;
17581 int high_bound_is_count = 0;
17582 const char *name;
17583 ULONGEST negative_mask;
17584
17585 orig_base_type = read_subrange_index_type (die, cu);
17586
17587 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17588 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17589 creating the range type, but we use the result of check_typedef
17590 when examining properties of the type. */
17591 base_type = check_typedef (orig_base_type);
17592
17593 /* The die_type call above may have already set the type for this DIE. */
17594 range_type = get_die_type (die, cu);
17595 if (range_type)
17596 return range_type;
17597
17598 high.set_const_val (0);
17599
17600 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17601 omitting DW_AT_lower_bound. */
17602 switch (cu->lang ())
17603 {
17604 case language_c:
17605 case language_cplus:
17606 low.set_const_val (0);
17607 low_default_is_valid = 1;
17608 break;
17609 case language_fortran:
17610 low.set_const_val (1);
17611 low_default_is_valid = 1;
17612 break;
17613 case language_d:
17614 case language_objc:
17615 case language_rust:
17616 low.set_const_val (0);
17617 low_default_is_valid = (cu->header.version >= 4);
17618 break;
17619 case language_ada:
17620 case language_m2:
17621 case language_pascal:
17622 low.set_const_val (1);
17623 low_default_is_valid = (cu->header.version >= 4);
17624 break;
17625 default:
17626 low.set_const_val (0);
17627 low_default_is_valid = 0;
17628 break;
17629 }
17630
17631 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
17632 if (attr != nullptr)
17633 attr_to_dynamic_prop (attr, die, cu, &low, base_type);
17634 else if (!low_default_is_valid)
17635 complaint (_("Missing DW_AT_lower_bound "
17636 "- DIE at %s [in module %s]"),
17639
17640 struct attribute *attr_ub, *attr_count;
17641 attr = attr_ub = dwarf2_attr (die, DW_AT_upper_bound, cu);
17642 if (!attr_to_dynamic_prop (attr, die, cu, &high, base_type))
17643 {
17644 attr = attr_count = dwarf2_attr (die, DW_AT_count, cu);
17645 if (attr_to_dynamic_prop (attr, die, cu, &high, base_type))
17646 {
17647 /* If bounds are constant do the final calculation here. */
17648 if (low.kind () == PROP_CONST && high.kind () == PROP_CONST)
17649 high.set_const_val (low.const_val () + high.const_val () - 1);
17650 else
17651 high_bound_is_count = 1;
17652 }
17653 else
17654 {
17655 if (attr_ub != NULL)
17656 complaint (_("Unresolved DW_AT_upper_bound "
17657 "- DIE at %s [in module %s]"),
17660 if (attr_count != NULL)
17661 complaint (_("Unresolved DW_AT_count "
17662 "- DIE at %s [in module %s]"),
17665 }
17666 }
17667
17668 LONGEST bias = 0;
17669 struct attribute *bias_attr = dwarf2_attr (die, DW_AT_GNU_bias, cu);
17670 if (bias_attr != nullptr && bias_attr->form_is_constant ())
17671 bias = bias_attr->constant_value (0);
17672
17673 /* Normally, the DWARF producers are expected to use a signed
17674 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17675 But this is unfortunately not always the case, as witnessed
17676 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17677 is used instead. To work around that ambiguity, we treat
17678 the bounds as signed, and thus sign-extend their values, when
17679 the base type is signed. */
17680 negative_mask =
17681 -((ULONGEST) 1 << (base_type->length () * TARGET_CHAR_BIT - 1));
17682 if (low.kind () == PROP_CONST
17683 && !base_type->is_unsigned () && (low.const_val () & negative_mask))
17684 low.set_const_val (low.const_val () | negative_mask);
17685 if (high.kind () == PROP_CONST
17686 && !base_type->is_unsigned () && (high.const_val () & negative_mask))
17687 high.set_const_val (high.const_val () | negative_mask);
17688
17689 /* Check for bit and byte strides. */
17690 struct dynamic_prop byte_stride_prop;
17691 attribute *attr_byte_stride = dwarf2_attr (die, DW_AT_byte_stride, cu);
17692 if (attr_byte_stride != nullptr)
17693 {
17694 struct type *prop_type = cu->addr_sized_int_type (false);
17695 attr_to_dynamic_prop (attr_byte_stride, die, cu, &byte_stride_prop,
17696 prop_type);
17697 }
17698
17699 struct dynamic_prop bit_stride_prop;
17700 attribute *attr_bit_stride = dwarf2_attr (die, DW_AT_bit_stride, cu);
17701 if (attr_bit_stride != nullptr)
17702 {
17703 /* It only makes sense to have either a bit or byte stride. */
17704 if (attr_byte_stride != nullptr)
17705 {
17706 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17707 "- DIE at %s [in module %s]"),
17710 attr_bit_stride = nullptr;
17711 }
17712 else
17713 {
17714 struct type *prop_type = cu->addr_sized_int_type (false);
17715 attr_to_dynamic_prop (attr_bit_stride, die, cu, &bit_stride_prop,
17716 prop_type);
17717 }
17718 }
17719
17720 if (attr_byte_stride != nullptr
17721 || attr_bit_stride != nullptr)
17722 {
17723 bool byte_stride_p = (attr_byte_stride != nullptr);
17724 struct dynamic_prop *stride
17725 = byte_stride_p ? &byte_stride_prop : &bit_stride_prop;
17726
17727 range_type
17728 = create_range_type_with_stride (NULL, orig_base_type, &low,
17729 &high, bias, stride, byte_stride_p);
17730 }
17731 else
17732 range_type = create_range_type (NULL, orig_base_type, &low, &high, bias);
17733
17734 if (high_bound_is_count)
17735 range_type->bounds ()->flag_upper_bound_is_count = 1;
17736
17737 /* Ada expects an empty array on no boundary attributes. */
17738 if (attr == NULL && cu->lang () != language_ada)
17739 range_type->bounds ()->high.set_undefined ();
17740
17741 name = dwarf2_name (die, cu);
17742 if (name)
17743 range_type->set_name (name);
17744
17745 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
17746 if (attr != nullptr)
17747 range_type->set_length (attr->constant_value (0));
17748
17749 maybe_set_alignment (cu, die, range_type);
17750
17751 set_die_type (die, range_type, cu);
17752
17753 /* set_die_type should be already done. */
17754 set_descriptive_type (range_type, die, cu);
17755
17756 return range_type;
17757}
17758
17759static struct type *
17761{
17762 struct type *type;
17763
17764 type = init_type (cu->per_objfile->objfile, TYPE_CODE_VOID, 0, NULL);
17765 type->set_name (dwarf2_name (die, cu));
17766
17767 /* In Ada, an unspecified type is typically used when the description
17768 of the type is deferred to a different unit. When encountering
17769 such a type, we treat it as a stub, and try to resolve it later on,
17770 when needed.
17771 Mark this as a stub type for all languages though. */
17772 type->set_is_stub (true);
17773
17774 return set_die_type (die, type, cu);
17775}
17776
17777/* Read a single die and all its descendents. Set the die's sibling
17778 field to NULL; set other fields in the die correctly, and set all
17779 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17780 location of the info_ptr after reading all of those dies. PARENT
17781 is the parent of the die in question. */
17782
17783static struct die_info *
17785 const gdb_byte *info_ptr,
17786 const gdb_byte **new_info_ptr,
17787 struct die_info *parent)
17788{
17789 struct die_info *die;
17790 const gdb_byte *cur_ptr;
17791
17792 cur_ptr = read_full_die_1 (reader, &die, info_ptr, 0);
17793 if (die == NULL)
17794 {
17795 *new_info_ptr = cur_ptr;
17796 return NULL;
17797 }
17798 store_in_ref_table (die, reader->cu);
17799
17800 if (die->has_children)
17801 die->child = read_die_and_siblings_1 (reader, cur_ptr, new_info_ptr, die);
17802 else
17803 {
17804 die->child = NULL;
17805 *new_info_ptr = cur_ptr;
17806 }
17807
17808 die->sibling = NULL;
17809 die->parent = parent;
17810 return die;
17811}
17812
17813/* Read a die, all of its descendents, and all of its siblings; set
17814 all of the fields of all of the dies correctly. Arguments are as
17815 in read_die_and_children. */
17816
17817static struct die_info *
17819 const gdb_byte *info_ptr,
17820 const gdb_byte **new_info_ptr,
17821 struct die_info *parent)
17822{
17823 struct die_info *first_die, *last_sibling;
17824 const gdb_byte *cur_ptr;
17825
17826 cur_ptr = info_ptr;
17827 first_die = last_sibling = NULL;
17828
17829 while (1)
17830 {
17831 struct die_info *die
17832 = read_die_and_children (reader, cur_ptr, &cur_ptr, parent);
17833
17834 if (die == NULL)
17835 {
17836 *new_info_ptr = cur_ptr;
17837 return first_die;
17838 }
17839
17840 if (!first_die)
17841 first_die = die;
17842 else
17843 last_sibling->sibling = die;
17844
17845 last_sibling = die;
17846 }
17847}
17848
17849/* Read a die, all of its descendents, and all of its siblings; set
17850 all of the fields of all of the dies correctly. Arguments are as
17851 in read_die_and_children.
17852 This the main entry point for reading a DIE and all its children. */
17853
17854static struct die_info *
17856 const gdb_byte *info_ptr,
17857 const gdb_byte **new_info_ptr,
17858 struct die_info *parent)
17859{
17860 struct die_info *die = read_die_and_siblings_1 (reader, info_ptr,
17861 new_info_ptr, parent);
17862
17863 if (dwarf_die_debug)
17864 {
17866 "Read die from %s@0x%x of %s:\n",
17867 reader->die_section->get_name (),
17868 (unsigned) (info_ptr - reader->die_section->buffer),
17869 bfd_get_filename (reader->abfd));
17871 }
17872
17873 return die;
17874}
17875
17876/* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17877 attributes.
17878 The caller is responsible for filling in the extra attributes
17879 and updating (*DIEP)->num_attrs.
17880 Set DIEP to point to a newly allocated die with its information,
17881 except for its child, sibling, and parent fields. */
17882
17883static const gdb_byte *
17884read_full_die_1 (const struct die_reader_specs *reader,
17885 struct die_info **diep, const gdb_byte *info_ptr,
17886 int num_extra_attrs)
17887{
17888 unsigned int abbrev_number, bytes_read, i;
17889 const struct abbrev_info *abbrev;
17890 struct die_info *die;
17891 struct dwarf2_cu *cu = reader->cu;
17892 bfd *abfd = reader->abfd;
17893
17894 sect_offset sect_off = (sect_offset) (info_ptr - reader->buffer);
17895 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
17896 info_ptr += bytes_read;
17897 if (!abbrev_number)
17898 {
17899 *diep = NULL;
17900 return info_ptr;
17901 }
17902
17903 abbrev = reader->abbrev_table->lookup_abbrev (abbrev_number);
17904 if (!abbrev)
17905 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17906 abbrev_number,
17907 bfd_get_filename (abfd));
17908
17909 die = dwarf_alloc_die (cu, abbrev->num_attrs + num_extra_attrs);
17910 die->sect_off = sect_off;
17911 die->tag = abbrev->tag;
17912 die->abbrev = abbrev_number;
17913 die->has_children = abbrev->has_children;
17914
17915 /* Make the result usable.
17916 The caller needs to update num_attrs after adding the extra
17917 attributes. */
17918 die->num_attrs = abbrev->num_attrs;
17919
17920 bool any_need_reprocess = false;
17921 for (i = 0; i < abbrev->num_attrs; ++i)
17922 {
17923 info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i],
17924 info_ptr);
17925 if (die->attrs[i].requires_reprocessing_p ())
17926 any_need_reprocess = true;
17927 }
17928
17929 struct attribute *attr = die->attr (DW_AT_str_offsets_base);
17930 if (attr != nullptr && attr->form_is_unsigned ())
17931 cu->str_offsets_base = attr->as_unsigned ();
17932
17933 attr = die->attr (DW_AT_loclists_base);
17934 if (attr != nullptr)
17935 cu->loclist_base = attr->as_unsigned ();
17936
17937 auto maybe_addr_base = die->addr_base ();
17938 if (maybe_addr_base.has_value ())
17939 cu->addr_base = *maybe_addr_base;
17940
17941 attr = die->attr (DW_AT_rnglists_base);
17942 if (attr != nullptr)
17943 cu->rnglists_base = attr->as_unsigned ();
17944
17945 if (any_need_reprocess)
17946 {
17947 for (i = 0; i < abbrev->num_attrs; ++i)
17948 {
17949 if (die->attrs[i].requires_reprocessing_p ())
17950 read_attribute_reprocess (reader, &die->attrs[i], die->tag);
17951 }
17952 }
17953 *diep = die;
17954 return info_ptr;
17955}
17956
17957/* Read a die and all its attributes.
17958 Set DIEP to point to a newly allocated die with its information,
17959 except for its child, sibling, and parent fields. */
17960
17961static const gdb_byte *
17962read_full_die (const struct die_reader_specs *reader,
17963 struct die_info **diep, const gdb_byte *info_ptr)
17964{
17965 const gdb_byte *result;
17966
17967 result = read_full_die_1 (reader, diep, info_ptr, 0);
17968
17969 if (dwarf_die_debug)
17970 {
17972 "Read die from %s@0x%x of %s:\n",
17973 reader->die_section->get_name (),
17974 (unsigned) (info_ptr - reader->die_section->buffer),
17975 bfd_get_filename (reader->abfd));
17976 dump_die (*diep, dwarf_die_debug);
17977 }
17978
17979 return result;
17980}
17981␌
17982
17983void
17985{
17986 if (reader->cu->per_cu->addresses_seen)
17987 return;
17988
17989 dwarf2_cu *cu = reader->cu;
17990
17991 CORE_ADDR best_lowpc = 0, best_highpc = 0;
17992 /* Possibly set the default values of LOWPC and HIGHPC from
17993 `DW_AT_ranges'. */
17995 enum pc_bounds_kind cu_bounds_kind
17996 = dwarf2_get_pc_bounds (reader->comp_unit_die, &best_lowpc, &best_highpc,
17997 cu, m_index_storage->get_addrmap (), cu->per_cu);
17998 if (cu_bounds_kind == PC_BOUNDS_HIGH_LOW && best_lowpc < best_highpc)
17999 {
18000 struct objfile *objfile = cu->per_objfile->objfile;
18001 CORE_ADDR baseaddr = objfile->text_section_offset ();
18002 struct gdbarch *gdbarch = objfile->arch ();
18003 CORE_ADDR low
18004 = (gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr)
18005 - baseaddr);
18006 CORE_ADDR high
18007 = (gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr)
18008 - baseaddr - 1);
18009 /* Store the contiguous range if it is not empty; it can be
18010 empty for CUs with no code. */
18011 m_index_storage->get_addrmap ()->set_empty (low, high, cu->per_cu);
18012
18013 cu->per_cu->addresses_seen = true;
18014 }
18015}
18016
18017/* Helper function that returns true if TAG can have a linkage
18018 name. */
18019
18020static bool
18021tag_can_have_linkage_name (enum dwarf_tag tag)
18022{
18023 switch (tag)
18024 {
18025 case DW_TAG_variable:
18026 case DW_TAG_subprogram:
18027 return true;
18028
18029 default:
18030 return false;
18031 }
18032}
18033
18036 dwarf2_per_objfile *per_objfile,
18037 sect_offset sect_off, bool is_dwz,
18038 bool for_scanning)
18039{
18040 /* Lookups for type unit references are always in the CU, and
18041 cross-CU references will crash. */
18042 if (reader->cu->per_cu->is_dwz == is_dwz
18043 && reader->cu->header.offset_in_cu_p (sect_off))
18044 return reader;
18045
18046 dwarf2_per_cu_data *per_cu
18047 = dwarf2_find_containing_comp_unit (sect_off, is_dwz,
18048 per_objfile->per_bfd);
18049
18050 /* When scanning, we only want to visit a given CU a single time.
18051 Doing this check here avoids self-imports as well. */
18052 if (for_scanning)
18053 {
18054 bool nope = false;
18055 if (!per_cu->scanned.compare_exchange_strong (nope, true))
18056 return nullptr;
18057 }
18058 if (per_cu == m_per_cu)
18059 return reader;
18060
18061 cutu_reader *result = m_index_storage->get_reader (per_cu);
18062 if (result == nullptr)
18063 {
18064 cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false,
18066
18067 prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die,
18069 std::unique_ptr<cutu_reader> copy
18070 (new cutu_reader (std::move (new_reader)));
18071 result = m_index_storage->preserve (std::move (copy));
18072 }
18073
18074 if (result->dummy_p || !result->comp_unit_die->has_children)
18075 return nullptr;
18076
18077 if (for_scanning)
18078 check_bounds (result);
18079
18080 return result;
18081}
18082
18083const gdb_byte *
18085 cutu_reader *reader,
18086 const gdb_byte *watermark_ptr,
18087 const gdb_byte *info_ptr,
18088 const abbrev_info *abbrev,
18089 const char **name,
18090 const char **linkage_name,
18091 cooked_index_flag *flags,
18092 sect_offset *sibling_offset,
18093 const cooked_index_entry **parent_entry,
18094 CORE_ADDR *maybe_defer,
18095 bool for_specification)
18096{
18097 bool origin_is_dwz = false;
18098 bool is_declaration = false;
18099 sect_offset origin_offset {};
18100
18101 gdb::optional<CORE_ADDR> low_pc;
18102 gdb::optional<CORE_ADDR> high_pc;
18103 bool high_pc_relative = false;
18104
18105 for (int i = 0; i < abbrev->num_attrs; ++i)
18106 {
18107 attribute attr;
18108 info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
18109 if (attr.requires_reprocessing_p ())
18110 read_attribute_reprocess (reader, &attr, abbrev->tag);
18111
18112 /* Store the data if it is of an attribute we want to keep in a
18113 partial symbol table. */
18114 switch (attr.name)
18115 {
18116 case DW_AT_name:
18117 switch (abbrev->tag)
18118 {
18119 case DW_TAG_compile_unit:
18120 case DW_TAG_partial_unit:
18121 case DW_TAG_type_unit:
18122 /* Compilation units have a DW_AT_name that is a filename, not
18123 a source language identifier. */
18124 break;
18125
18126 default:
18127 if (*name == nullptr)
18128 *name = attr.as_string ();
18129 break;
18130 }
18131 break;
18132
18133 case DW_AT_linkage_name:
18134 case DW_AT_MIPS_linkage_name:
18135 /* Note that both forms of linkage name might appear. We
18136 assume they will be the same, and we only store the last
18137 one we see. */
18138 if (*linkage_name == nullptr)
18139 *linkage_name = attr.as_string ();
18140 break;
18141
18142 case DW_AT_main_subprogram:
18143 if (attr.as_boolean ())
18144 *flags |= IS_MAIN;
18145 break;
18146
18147 case DW_AT_declaration:
18148 is_declaration = attr.as_boolean ();
18149 break;
18150
18151 case DW_AT_sibling:
18152 if (sibling_offset != nullptr)
18153 *sibling_offset = attr.get_ref_die_offset ();
18154 break;
18155
18156 case DW_AT_specification:
18157 case DW_AT_abstract_origin:
18158 case DW_AT_extension:
18159 origin_offset = attr.get_ref_die_offset ();
18160 origin_is_dwz = attr.form == DW_FORM_GNU_ref_alt;
18161 break;
18162
18163 case DW_AT_external:
18164 if (attr.as_boolean ())
18165 *flags &= ~IS_STATIC;
18166 break;
18167
18168 case DW_AT_enum_class:
18169 if (attr.as_boolean ())
18170 *flags |= IS_ENUM_CLASS;
18171 break;
18172
18173 case DW_AT_low_pc:
18174 low_pc = attr.as_address ();
18175 break;
18176
18177 case DW_AT_high_pc:
18178 high_pc = attr.as_address ();
18179 if (reader->cu->header.version >= 4 && attr.form_is_constant ())
18180 high_pc_relative = true;
18181 break;
18182
18183 case DW_AT_location:
18184 if (!scanning_per_cu->addresses_seen && attr.form_is_block ())
18185 {
18186 struct dwarf_block *locdesc = attr.as_block ();
18187 CORE_ADDR addr = decode_locdesc (locdesc, reader->cu);
18188 if (addr != 0
18190 {
18191 low_pc = addr;
18192 /* For variables, we don't want to try decoding the
18193 type just to find the size -- for gdb's purposes
18194 we only need the address of a variable. */
18195 high_pc = addr + 1;
18196 high_pc_relative = false;
18197 }
18198 }
18199 break;
18200
18201 case DW_AT_ranges:
18202 if (!scanning_per_cu->addresses_seen)
18203 {
18204 /* Offset in the .debug_ranges or .debug_rnglist section
18205 (depending on DWARF version). */
18206 ULONGEST ranges_offset = attr.as_unsigned ();
18207
18208 /* See dwarf2_cu::gnu_ranges_base's doc for why we might
18209 want to add this value. */
18210 ranges_offset += reader->cu->gnu_ranges_base;
18211
18212 CORE_ADDR lowpc, highpc;
18213 dwarf2_ranges_read (ranges_offset, &lowpc, &highpc, reader->cu,
18215 scanning_per_cu, abbrev->tag);
18216 }
18217 break;
18218 }
18219 }
18220
18221 /* We don't want to examine declarations, but if we found a
18222 declaration when handling DW_AT_specification or the like, then
18223 that is ok. Similarly, we allow an external variable without a
18224 location; those are resolved via minimal symbols. */
18225 if (is_declaration && !for_specification
18226 && !(abbrev->tag == DW_TAG_variable && (*flags & IS_STATIC) == 0))
18227 {
18228 /* We always want to recurse into some types, but we may not
18229 want to treat them as definitions. */
18230 if ((abbrev->tag == DW_TAG_class_type
18231 || abbrev->tag == DW_TAG_structure_type
18232 || abbrev->tag == DW_TAG_union_type)
18233 && abbrev->has_children)
18235 else
18236 {
18237 *linkage_name = nullptr;
18238 *name = nullptr;
18239 }
18240 }
18241 else if ((*name == nullptr
18242 || (*linkage_name == nullptr
18243 && tag_can_have_linkage_name (abbrev->tag))
18244 || (*parent_entry == nullptr && m_language != language_c))
18245 && origin_offset != sect_offset (0))
18246 {
18247 cutu_reader *new_reader
18248 = ensure_cu_exists (reader, reader->cu->per_objfile, origin_offset,
18249 origin_is_dwz, false);
18250 if (new_reader != nullptr)
18251 {
18252 const gdb_byte *new_info_ptr = (new_reader->buffer
18253 + to_underlying (origin_offset));
18254
18255 if (new_reader->cu == reader->cu
18256 && new_info_ptr > watermark_ptr
18257 && *parent_entry == nullptr)
18258 *maybe_defer = form_addr (origin_offset, origin_is_dwz);
18259 else if (*parent_entry == nullptr)
18260 {
18261 CORE_ADDR lookup = form_addr (origin_offset, origin_is_dwz);
18262 *parent_entry
18264 }
18265
18266 unsigned int bytes_read;
18267 const abbrev_info *new_abbrev = peek_die_abbrev (*new_reader,
18268 new_info_ptr,
18269 &bytes_read);
18270 new_info_ptr += bytes_read;
18271 scan_attributes (scanning_per_cu, new_reader, new_info_ptr, new_info_ptr,
18272 new_abbrev, name, linkage_name, flags, nullptr,
18273 parent_entry, maybe_defer, true);
18274 }
18275 }
18276
18277 if (!for_specification)
18278 {
18280 && *linkage_name == nullptr)
18281 *linkage_name = *name;
18282
18283 if (!scanning_per_cu->addresses_seen
18284 && low_pc.has_value ()
18286 || *low_pc != 0)
18287 && high_pc.has_value ())
18288 {
18289 if (high_pc_relative)
18290 high_pc = *high_pc + *low_pc;
18291
18292 if (*high_pc > *low_pc)
18293 {
18294 struct objfile *objfile = reader->cu->per_objfile->objfile;
18295 CORE_ADDR baseaddr = objfile->text_section_offset ();
18296 struct gdbarch *gdbarch = objfile->arch ();
18297 CORE_ADDR lo
18298 = (gdbarch_adjust_dwarf2_addr (gdbarch, *low_pc + baseaddr)
18299 - baseaddr);
18300 CORE_ADDR hi
18301 = (gdbarch_adjust_dwarf2_addr (gdbarch, *high_pc + baseaddr)
18302 - baseaddr);
18303 m_index_storage->get_addrmap ()->set_empty (lo, hi - 1,
18304 scanning_per_cu);
18305 }
18306 }
18307
18308 if (abbrev->tag == DW_TAG_module || abbrev->tag == DW_TAG_namespace)
18309 *flags &= ~IS_STATIC;
18310
18311 if (abbrev->tag == DW_TAG_namespace && *name == nullptr)
18312 *name = "(anonymous namespace)";
18313
18315 && (abbrev->tag == DW_TAG_class_type
18316 || abbrev->tag == DW_TAG_interface_type
18317 || abbrev->tag == DW_TAG_structure_type
18318 || abbrev->tag == DW_TAG_union_type
18319 || abbrev->tag == DW_TAG_enumeration_type
18320 || abbrev->tag == DW_TAG_enumerator))
18321 *flags &= ~IS_STATIC;
18322 }
18323
18324 return info_ptr;
18325}
18326
18327const gdb_byte *
18329 const gdb_byte *info_ptr,
18330 const abbrev_info *abbrev)
18331{
18332 sect_offset sect_off {};
18333 bool is_dwz = false;
18334
18335 for (int i = 0; i < abbrev->num_attrs; ++i)
18336 {
18337 /* Note that we never need to reprocess attributes here. */
18338 attribute attr;
18339 info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
18340
18341 if (attr.name == DW_AT_import)
18342 {
18343 sect_off = attr.get_ref_die_offset ();
18344 is_dwz = (attr.form == DW_FORM_GNU_ref_alt
18345 || reader->cu->per_cu->is_dwz);
18346 }
18347 }
18348
18349 /* Did not find DW_AT_import. */
18350 if (sect_off == sect_offset (0))
18351 return info_ptr;
18352
18353 dwarf2_per_objfile *per_objfile = reader->cu->per_objfile;
18354 cutu_reader *new_reader = ensure_cu_exists (reader, per_objfile, sect_off,
18355 is_dwz, true);
18356 if (new_reader != nullptr)
18357 {
18358 index_dies (new_reader, new_reader->info_ptr, nullptr, false);
18359
18360 reader->cu->add_dependence (new_reader->cu->per_cu);
18361 }
18362
18363 return info_ptr;
18364}
18365
18366const gdb_byte *
18368 const gdb_byte *info_ptr,
18369 const cooked_index_entry *parent_entry,
18370 bool fully)
18371{
18372 info_ptr = index_dies (reader, info_ptr, parent_entry, fully);
18373
18374 if (parent_entry != nullptr)
18375 {
18376 CORE_ADDR start = form_addr (parent_entry->die_offset,
18377 reader->cu->per_cu->is_dwz);
18378 CORE_ADDR end = form_addr (sect_offset (info_ptr - 1 - reader->buffer),
18379 reader->cu->per_cu->is_dwz);
18380 m_die_range_map.set_empty (start, end, (void *) parent_entry);
18381 }
18382
18383 return info_ptr;
18384}
18385
18386const gdb_byte *
18388 const gdb_byte *info_ptr,
18389 const cooked_index_entry *parent_entry,
18390 bool fully)
18391{
18392 const gdb_byte *end_ptr = (reader->buffer
18393 + to_underlying (reader->cu->header.sect_off)
18394 + reader->cu->header.get_length ());
18395
18396 while (info_ptr < end_ptr)
18397 {
18398 sect_offset this_die = (sect_offset) (info_ptr - reader->buffer);
18399 unsigned int bytes_read;
18400 const abbrev_info *abbrev = peek_die_abbrev (*reader, info_ptr,
18401 &bytes_read);
18402 info_ptr += bytes_read;
18403 if (abbrev == nullptr)
18404 break;
18405
18406 if (abbrev->tag == DW_TAG_imported_unit)
18407 {
18408 info_ptr = index_imported_unit (reader, info_ptr, abbrev);
18409 continue;
18410 }
18411
18412 if (!abbrev->interesting)
18413 {
18414 info_ptr = skip_one_die (reader, info_ptr, abbrev, !fully);
18415 if (fully && abbrev->has_children)
18416 info_ptr = index_dies (reader, info_ptr, parent_entry, fully);
18417 continue;
18418 }
18419
18420 const char *name = nullptr;
18421 const char *linkage_name = nullptr;
18422 CORE_ADDR defer = 0;
18423 cooked_index_flag flags = IS_STATIC;
18424 sect_offset sibling {};
18425 const cooked_index_entry *this_parent_entry = parent_entry;
18426 info_ptr = scan_attributes (reader->cu->per_cu, reader, info_ptr,
18427 info_ptr, abbrev, &name, &linkage_name,
18428 &flags, &sibling, &this_parent_entry,
18429 &defer, false);
18430
18431 if (abbrev->tag == DW_TAG_namespace
18433 && strcmp (name, "::") == 0)
18434 {
18435 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they
18436 generated bogus DW_TAG_namespace DIEs with a name of "::"
18437 for the global namespace. Work around this problem
18438 here. */
18439 name = nullptr;
18440 }
18441
18442 const cooked_index_entry *this_entry = nullptr;
18443 if (name != nullptr)
18444 {
18445 if (defer != 0)
18446 m_deferred_entries.push_back ({
18447 this_die, name, defer, abbrev->tag, flags
18448 });
18449 else
18450 this_entry = m_index_storage->add (this_die, abbrev->tag, flags,
18451 name, this_parent_entry,
18452 m_per_cu);
18453 }
18454
18455 if (linkage_name != nullptr)
18456 {
18457 /* We only want this to be "main" if it has a linkage name
18458 but not an ordinary name. */
18459 if (name != nullptr)
18460 flags = flags & ~IS_MAIN;
18461 /* Set the IS_LINKAGE on for everything except when functions
18462 have linkage name present but name is absent. */
18463 if (name != nullptr
18464 || (abbrev->tag != DW_TAG_subprogram
18465 && abbrev->tag != DW_TAG_inlined_subroutine
18466 && abbrev->tag != DW_TAG_entry_point))
18468 m_index_storage->add (this_die, abbrev->tag, flags,
18469 linkage_name, nullptr, m_per_cu);
18470 }
18471
18472 if (abbrev->has_children)
18473 {
18474 switch (abbrev->tag)
18475 {
18476 case DW_TAG_class_type:
18477 case DW_TAG_interface_type:
18478 case DW_TAG_structure_type:
18479 case DW_TAG_union_type:
18480 if (m_language != language_c && this_entry != nullptr)
18481 {
18482 info_ptr = recurse (reader, info_ptr, this_entry, fully);
18483 continue;
18484 }
18485 break;
18486
18487 case DW_TAG_enumeration_type:
18488 /* We need to recurse even for an anonymous enumeration.
18489 Which scope we record as the parent scope depends on
18490 whether we're reading an "enum class". If so, we use
18491 the enum itself as the parent, yielding names like
18492 "enum_class::enumerator"; otherwise we inject the
18493 names into our own parent scope. */
18494 info_ptr = recurse (reader, info_ptr,
18495 ((flags & IS_ENUM_CLASS) == 0)
18496 ? parent_entry
18497 : this_entry,
18498 fully);
18499 continue;
18500
18501 case DW_TAG_module:
18502 if (this_entry == nullptr)
18503 break;
18504 /* FALLTHROUGH */
18505 case DW_TAG_namespace:
18506 /* We don't check THIS_ENTRY for a namespace, to handle
18507 the ancient G++ workaround pointed out above. */
18508 info_ptr = recurse (reader, info_ptr, this_entry, fully);
18509 continue;
18510
18511 case DW_TAG_subprogram:
18514 && this_entry != nullptr)
18515 {
18516 info_ptr = recurse (reader, info_ptr, this_entry, true);
18517 continue;
18518 }
18519 break;
18520 }
18521
18522 if (sibling != sect_offset (0))
18523 {
18524 const gdb_byte *sibling_ptr
18525 = reader->buffer + to_underlying (sibling);
18526
18527 if (sibling_ptr < info_ptr)
18528 complaint (_("DW_AT_sibling points backwards"));
18529 else if (sibling_ptr > reader->buffer_end)
18530 reader->die_section->overflow_complaint ();
18531 else
18532 info_ptr = sibling_ptr;
18533 }
18534 else
18535 info_ptr = skip_children (reader, info_ptr);
18536 }
18537 }
18538
18539 return info_ptr;
18540}
18541
18542void
18544{
18545 check_bounds (reader);
18546 find_file_and_directory (reader->comp_unit_die, reader->cu);
18547 if (!reader->comp_unit_die->has_children)
18548 return;
18549 index_dies (reader, reader->info_ptr, nullptr, false);
18550
18551 for (const auto &entry : m_deferred_entries)
18552 {
18553 CORE_ADDR key = form_addr (entry.die_offset, m_per_cu->is_dwz);
18554 cooked_index_entry *parent
18556 m_index_storage->add (entry.die_offset, entry.tag, entry.flags,
18557 entry.name, parent, m_per_cu);
18558 }
18559}
18560
18561/* An implementation of quick_symbol_functions for the cooked DWARF
18562 index. */
18563
18565{
18567 CORE_ADDR adjusted_pc) override;
18568
18570 (struct objfile *objfile, CORE_ADDR address) override;
18571
18572 void dump (struct objfile *objfile) override
18573 {
18574 gdb_printf ("Cooked index in use\n");
18575 }
18576
18578 (struct objfile *,
18579 const lookup_name_info &lookup_name,
18580 domain_enum domain,
18581 int global,
18582 symbol_compare_ftype *ordered_compare) override;
18583
18585 (struct objfile *objfile,
18586 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
18587 const lookup_name_info *lookup_name,
18588 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
18589 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
18590 block_search_flags search_flags,
18591 domain_enum domain,
18592 enum search_domain kind) override;
18593
18595 {
18596 return true;
18597 }
18598
18599 void read_partial_symbols (struct objfile *objfile) override
18600 {
18601 if (dwarf2_has_info (objfile, nullptr))
18603 }
18604};
18605
18608 CORE_ADDR adjusted_pc)
18609{
18610 if (per_bfd->index_table == nullptr)
18611 return nullptr;
18612 cooked_index_vector *table
18613 = (gdb::checked_static_cast<cooked_index_vector *>
18614 (per_bfd->index_table.get ()));
18615 return table->lookup (adjusted_pc);
18616}
18617
18618struct compunit_symtab *
18620 (struct objfile *objfile, CORE_ADDR address)
18621{
18622 if (objfile->sect_index_data == -1)
18623 return nullptr;
18624
18626 if (per_objfile->per_bfd->index_table == nullptr)
18627 return nullptr;
18628
18629 CORE_ADDR baseaddr = objfile->data_section_offset ();
18630 cooked_index_vector *table
18631 = (gdb::checked_static_cast<cooked_index_vector *>
18632 (per_objfile->per_bfd->index_table.get ()));
18633 dwarf2_per_cu_data *per_cu = table->lookup (address - baseaddr);
18634 if (per_cu == nullptr)
18635 return nullptr;
18636
18637 return dw2_instantiate_symtab (per_cu, per_objfile, false);
18638}
18639
18640void
18642 (struct objfile *objfile,
18643 const lookup_name_info &lookup_name,
18644 domain_enum domain,
18645 int global,
18646 symbol_compare_ftype *ordered_compare)
18647{
18649 if (per_objfile->per_bfd->index_table == nullptr)
18650 return;
18651 const block_search_flags search_flags = (global
18654 const language_defn *lang = language_def (language_ada);
18655 symbol_name_matcher_ftype *name_match
18656 = lang->get_symbol_name_matcher (lookup_name);
18657
18658 cooked_index_vector *table
18659 = (gdb::checked_static_cast<cooked_index_vector *>
18660 (per_objfile->per_bfd->index_table.get ()));
18661 for (const cooked_index_entry *entry : table->all_entries ())
18662 {
18663 QUIT;
18664
18665 if (entry->parent_entry != nullptr)
18666 continue;
18667
18668 if (!entry->matches (search_flags)
18669 || !entry->matches (domain))
18670 continue;
18671
18672 if (name_match (entry->canonical, lookup_name, nullptr))
18673 dw2_instantiate_symtab (entry->per_cu, per_objfile, false);
18674 }
18675}
18676
18677bool
18679 (struct objfile *objfile,
18680 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
18681 const lookup_name_info *lookup_name,
18682 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
18683 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
18684 block_search_flags search_flags,
18685 domain_enum domain,
18686 enum search_domain kind)
18687{
18689 if (per_objfile->per_bfd->index_table == nullptr)
18690 return true;
18691
18692 cooked_index_vector *table
18693 = (gdb::checked_static_cast<cooked_index_vector *>
18694 (per_objfile->per_bfd->index_table.get ()));
18695 table->wait ();
18696
18697 dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
18698
18699 /* This invariant is documented in quick-functions.h. */
18700 gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
18701 if (lookup_name == nullptr)
18702 {
18703 for (dwarf2_per_cu_data *per_cu
18704 : all_units_range (per_objfile->per_bfd))
18705 {
18706 QUIT;
18707
18708 if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
18709 file_matcher,
18710 expansion_notify))
18711 return false;
18712 }
18713 return true;
18714 }
18715
18716 lookup_name_info lookup_name_without_params
18717 = lookup_name->make_ignore_params ();
18718 bool completing = lookup_name->completion_mode ();
18719
18720 /* Unique styles of language splitting. */
18721 static const enum language unique_styles[] =
18722 {
18723 /* No splitting is also a style. */
18724 language_c,
18725 /* This includes Rust. */
18727 /* This includes Go. */
18728 language_d,
18730 };
18731
18732 for (enum language lang : unique_styles)
18733 {
18734 std::vector<gdb::string_view> name_vec
18735 = lookup_name_without_params.split_name (lang);
18736 std::string last_name = gdb::to_string (name_vec.back ());
18737
18738 for (const cooked_index_entry *entry : table->find (last_name,
18739 completing))
18740 {
18741 QUIT;
18742
18743 /* No need to consider symbols from expanded CUs. */
18744 if (per_objfile->symtab_set_p (entry->per_cu))
18745 continue;
18746
18747 /* If file-matching was done, we don't need to consider
18748 symbols from unmarked CUs. */
18749 if (file_matcher != nullptr && !entry->per_cu->mark)
18750 continue;
18751
18752 /* See if the symbol matches the type filter. */
18753 if (!entry->matches (search_flags)
18754 || !entry->matches (domain)
18755 || !entry->matches (kind))
18756 continue;
18757
18758 /* We've found the base name of the symbol; now walk its
18759 parentage chain, ensuring that each component
18760 matches. */
18761 bool found = true;
18762
18763 const cooked_index_entry *parent = entry->parent_entry;
18764 for (int i = name_vec.size () - 1; i > 0; --i)
18765 {
18766 /* If we ran out of entries, or if this segment doesn't
18767 match, this did not match. */
18768 if (parent == nullptr
18769 || strncmp (parent->name, name_vec[i - 1].data (),
18770 name_vec[i - 1].length ()) != 0)
18771 {
18772 found = false;
18773 break;
18774 }
18775
18776 parent = parent->parent_entry;
18777 }
18778
18779 if (!found)
18780 continue;
18781
18782 /* Might have been looking for "a::b" and found
18783 "x::a::b". */
18784 if (symbol_matcher == nullptr)
18785 {
18786 symbol_name_match_type match_type
18787 = lookup_name_without_params.match_type ();
18788 if ((match_type == symbol_name_match_type::FULL
18789 || (lang != language_ada
18790 && match_type == symbol_name_match_type::EXPRESSION))
18791 && parent != nullptr)
18792 continue;
18793 }
18794 else
18795 {
18796 auto_obstack temp_storage;
18797 const char *full_name = entry->full_name (&temp_storage);
18798 if (!symbol_matcher (full_name))
18799 continue;
18800 }
18801
18802 if (!dw2_expand_symtabs_matching_one (entry->per_cu, per_objfile,
18803 file_matcher,
18804 expansion_notify))
18805 return false;
18806 }
18807 }
18808
18809 return true;
18810}
18811
18812/* Return a new cooked_index_functions object. */
18813
18816{
18818}
18819
18822{
18823 return make_cooked_index_funcs ();
18824}
18825
18826␌
18827
18828/* Read the .debug_loclists or .debug_rnglists header (they are the same format)
18829 contents from the given SECTION in the HEADER.
18830
18831 HEADER_OFFSET is the offset of the header in the section. */
18832static void
18834 struct dwarf2_section_info *section,
18835 sect_offset header_offset)
18836{
18837 unsigned int bytes_read;
18838 bfd *abfd = section->get_bfd_owner ();
18839 const gdb_byte *info_ptr = section->buffer + to_underlying (header_offset);
18840
18841 header->length = read_initial_length (abfd, info_ptr, &bytes_read);
18842 info_ptr += bytes_read;
18843
18844 header->version = read_2_bytes (abfd, info_ptr);
18845 info_ptr += 2;
18846
18847 header->addr_size = read_1_byte (abfd, info_ptr);
18848 info_ptr += 1;
18849
18850 header->segment_collector_size = read_1_byte (abfd, info_ptr);
18851 info_ptr += 1;
18852
18853 header->offset_entry_count = read_4_bytes (abfd, info_ptr);
18854}
18855
18856/* Return the DW_AT_loclists_base value for the CU. */
18857static ULONGEST
18859{
18860 /* For the .dwo unit, the loclist_base points to the first offset following
18861 the header. The header consists of the following entities-
18862 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18863 bit format)
18864 2. version (2 bytes)
18865 3. address size (1 byte)
18866 4. segment selector size (1 byte)
18867 5. offset entry count (4 bytes)
18868 These sizes are derived as per the DWARFv5 standard. */
18869 if (cu->dwo_unit != nullptr)
18870 {
18871 if (cu->header.initial_length_size == 4)
18872 return LOCLIST_HEADER_SIZE32;
18873 return LOCLIST_HEADER_SIZE64;
18874 }
18875 return cu->loclist_base;
18876}
18877
18878/* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18879 array of offsets in the .debug_loclists section. */
18880
18881static sect_offset
18882read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index)
18883{
18884 dwarf2_per_objfile *per_objfile = cu->per_objfile;
18885 struct objfile *objfile = per_objfile->objfile;
18886 bfd *abfd = objfile->obfd.get ();
18887 ULONGEST loclist_header_size =
18888 (cu->header.initial_length_size == 4 ? LOCLIST_HEADER_SIZE32
18890 ULONGEST loclist_base = lookup_loclist_base (cu);
18891
18892 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
18893 ULONGEST start_offset =
18894 loclist_base + loclist_index * cu->header.offset_size;
18895
18896 /* Get loclists section. */
18898
18899 /* Read the loclists section content. */
18900 section->read (objfile);
18901 if (section->buffer == NULL)
18902 error (_("DW_FORM_loclistx used without .debug_loclists "
18903 "section [in module %s]"), objfile_name (objfile));
18904
18905 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
18906 so if loclist_base is smaller than the header size, we have a problem. */
18907 if (loclist_base < loclist_header_size)
18908 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
18910
18911 /* Read the header of the loclists contribution. */
18912 struct loclists_rnglists_header header;
18913 read_loclists_rnglists_header (&header, section,
18914 (sect_offset) (loclist_base - loclist_header_size));
18915
18916 /* Verify the loclist index is valid. */
18917 if (loclist_index >= header.offset_entry_count)
18918 error (_("DW_FORM_loclistx pointing outside of "
18919 ".debug_loclists offset array [in module %s]"),
18921
18922 /* Validate that reading won't go beyond the end of the section. */
18923 if (start_offset + cu->header.offset_size > section->size)
18924 error (_("Reading DW_FORM_loclistx index beyond end of"
18925 ".debug_loclists section [in module %s]"),
18927
18928 const gdb_byte *info_ptr = section->buffer + start_offset;
18929
18930 if (cu->header.offset_size == 4)
18931 return (sect_offset) (bfd_get_32 (abfd, info_ptr) + loclist_base);
18932 else
18933 return (sect_offset) (bfd_get_64 (abfd, info_ptr) + loclist_base);
18934}
18935
18936/* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
18937 array of offsets in the .debug_rnglists section. */
18938
18939static sect_offset
18940read_rnglist_index (struct dwarf2_cu *cu, ULONGEST rnglist_index,
18941 dwarf_tag tag)
18942{
18945 bfd *abfd = objfile->obfd.get ();
18946 ULONGEST rnglist_header_size =
18947 (cu->header.initial_length_size == 4 ? RNGLIST_HEADER_SIZE32
18949
18950 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
18951 .debug_rnglists.dwo section. The rnglists base given in the skeleton
18952 doesn't apply. */
18953 ULONGEST rnglist_base =
18954 (cu->dwo_unit != nullptr) ? rnglist_header_size : cu->rnglists_base;
18955
18956 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
18957 ULONGEST start_offset =
18958 rnglist_base + rnglist_index * cu->header.offset_size;
18959
18960 /* Get rnglists section. */
18962
18963 /* Read the rnglists section content. */
18964 section->read (objfile);
18965 if (section->buffer == nullptr)
18966 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
18967 "[in module %s]"),
18969
18970 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
18971 so if rnglist_base is smaller than the header size, we have a problem. */
18972 if (rnglist_base < rnglist_header_size)
18973 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
18975
18976 /* Read the header of the rnglists contribution. */
18977 struct loclists_rnglists_header header;
18978 read_loclists_rnglists_header (&header, section,
18979 (sect_offset) (rnglist_base - rnglist_header_size));
18980
18981 /* Verify the rnglist index is valid. */
18982 if (rnglist_index >= header.offset_entry_count)
18983 error (_("DW_FORM_rnglistx index pointing outside of "
18984 ".debug_rnglists offset array [in module %s]"),
18986
18987 /* Validate that reading won't go beyond the end of the section. */
18988 if (start_offset + cu->header.offset_size > section->size)
18989 error (_("Reading DW_FORM_rnglistx index beyond end of"
18990 ".debug_rnglists section [in module %s]"),
18992
18993 const gdb_byte *info_ptr = section->buffer + start_offset;
18994
18995 if (cu->header.offset_size == 4)
18996 return (sect_offset) (read_4_bytes (abfd, info_ptr) + rnglist_base);
18997 else
18998 return (sect_offset) (read_8_bytes (abfd, info_ptr) + rnglist_base);
18999}
19000
19001/* Process the attributes that had to be skipped in the first round. These
19002 attributes are the ones that need str_offsets_base or addr_base attributes.
19003 They could not have been processed in the first round, because at the time
19004 the values of str_offsets_base or addr_base may not have been known. */
19005static void
19007 struct attribute *attr, dwarf_tag tag)
19008{
19009 struct dwarf2_cu *cu = reader->cu;
19010 switch (attr->form)
19011 {
19012 case DW_FORM_addrx:
19013 case DW_FORM_GNU_addr_index:
19014 attr->set_address (read_addr_index (cu,
19015 attr->as_unsigned_reprocess ()));
19016 break;
19017 case DW_FORM_loclistx:
19018 {
19019 sect_offset loclists_sect_off
19021
19022 attr->set_unsigned (to_underlying (loclists_sect_off));
19023 }
19024 break;
19025 case DW_FORM_rnglistx:
19026 {
19027 sect_offset rnglists_sect_off
19028 = read_rnglist_index (cu, attr->as_unsigned_reprocess (), tag);
19029
19030 attr->set_unsigned (to_underlying (rnglists_sect_off));
19031 }
19032 break;
19033 case DW_FORM_strx:
19034 case DW_FORM_strx1:
19035 case DW_FORM_strx2:
19036 case DW_FORM_strx3:
19037 case DW_FORM_strx4:
19038 case DW_FORM_GNU_str_index:
19039 {
19040 unsigned int str_index = attr->as_unsigned_reprocess ();
19041 gdb_assert (!attr->canonical_string_p ());
19042 if (reader->dwo_file != NULL)
19044 str_index));
19045 else
19047 str_index));
19048 break;
19049 }
19050 default:
19051 gdb_assert_not_reached ("Unexpected DWARF form.");
19052 }
19053}
19054
19055/* Read an attribute value described by an attribute form. */
19056
19057static const gdb_byte *
19059 struct attribute *attr, unsigned form,
19060 LONGEST implicit_const, const gdb_byte *info_ptr)
19061{
19062 struct dwarf2_cu *cu = reader->cu;
19064 struct objfile *objfile = per_objfile->objfile;
19065 bfd *abfd = reader->abfd;
19066 struct comp_unit_head *cu_header = &cu->header;
19067 unsigned int bytes_read;
19068 struct dwarf_block *blk;
19069
19070 attr->form = (enum dwarf_form) form;
19071 switch (form)
19072 {
19073 case DW_FORM_ref_addr:
19074 if (cu_header->version == 2)
19075 attr->set_unsigned (cu_header->read_address (abfd, info_ptr,
19076 &bytes_read));
19077 else
19078 attr->set_unsigned (cu_header->read_offset (abfd, info_ptr,
19079 &bytes_read));
19080 info_ptr += bytes_read;
19081 break;
19082 case DW_FORM_GNU_ref_alt:
19083 attr->set_unsigned (cu_header->read_offset (abfd, info_ptr,
19084 &bytes_read));
19085 info_ptr += bytes_read;
19086 break;
19087 case DW_FORM_addr:
19088 {
19089 struct gdbarch *gdbarch = objfile->arch ();
19090 CORE_ADDR addr = cu_header->read_address (abfd, info_ptr, &bytes_read);
19091 addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr);
19092 attr->set_address (addr);
19093 info_ptr += bytes_read;
19094 }
19095 break;
19096 case DW_FORM_block2:
19097 blk = dwarf_alloc_block (cu);
19098 blk->size = read_2_bytes (abfd, info_ptr);
19099 info_ptr += 2;
19100 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
19101 info_ptr += blk->size;
19102 attr->set_block (blk);
19103 break;
19104 case DW_FORM_block4:
19105 blk = dwarf_alloc_block (cu);
19106 blk->size = read_4_bytes (abfd, info_ptr);
19107 info_ptr += 4;
19108 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
19109 info_ptr += blk->size;
19110 attr->set_block (blk);
19111 break;
19112 case DW_FORM_data2:
19113 attr->set_unsigned (read_2_bytes (abfd, info_ptr));
19114 info_ptr += 2;
19115 break;
19116 case DW_FORM_data4:
19117 attr->set_unsigned (read_4_bytes (abfd, info_ptr));
19118 info_ptr += 4;
19119 break;
19120 case DW_FORM_data8:
19121 attr->set_unsigned (read_8_bytes (abfd, info_ptr));
19122 info_ptr += 8;
19123 break;
19124 case DW_FORM_data16:
19125 blk = dwarf_alloc_block (cu);
19126 blk->size = 16;
19127 blk->data = read_n_bytes (abfd, info_ptr, 16);
19128 info_ptr += 16;
19129 attr->set_block (blk);
19130 break;
19131 case DW_FORM_sec_offset:
19132 attr->set_unsigned (cu_header->read_offset (abfd, info_ptr,
19133 &bytes_read));
19134 info_ptr += bytes_read;
19135 break;
19136 case DW_FORM_loclistx:
19137 {
19138 attr->set_unsigned_reprocess (read_unsigned_leb128 (abfd, info_ptr,
19139 &bytes_read));
19140 info_ptr += bytes_read;
19141 }
19142 break;
19143 case DW_FORM_string:
19144 attr->set_string_noncanonical (read_direct_string (abfd, info_ptr,
19145 &bytes_read));
19146 info_ptr += bytes_read;
19147 break;
19148 case DW_FORM_strp:
19149 if (!cu->per_cu->is_dwz)
19150 {
19152 (read_indirect_string (per_objfile,
19153 abfd, info_ptr, cu_header,
19154 &bytes_read));
19155 info_ptr += bytes_read;
19156 break;
19157 }
19158 /* FALLTHROUGH */
19159 case DW_FORM_line_strp:
19160 if (!cu->per_cu->is_dwz)
19161 {
19163 (per_objfile->read_line_string (info_ptr, cu_header,
19164 &bytes_read));
19165 info_ptr += bytes_read;
19166 break;
19167 }
19168 /* FALLTHROUGH */
19169 case DW_FORM_GNU_strp_alt:
19170 {
19171 dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true);
19172 LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
19173 &bytes_read);
19174
19176 (dwz->read_string (objfile, str_offset));
19177 info_ptr += bytes_read;
19178 }
19179 break;
19180 case DW_FORM_exprloc:
19181 case DW_FORM_block:
19182 blk = dwarf_alloc_block (cu);
19183 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
19184 info_ptr += bytes_read;
19185 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
19186 info_ptr += blk->size;
19187 attr->set_block (blk);
19188 break;
19189 case DW_FORM_block1:
19190 blk = dwarf_alloc_block (cu);
19191 blk->size = read_1_byte (abfd, info_ptr);
19192 info_ptr += 1;
19193 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
19194 info_ptr += blk->size;
19195 attr->set_block (blk);
19196 break;
19197 case DW_FORM_data1:
19198 case DW_FORM_flag:
19199 attr->set_unsigned (read_1_byte (abfd, info_ptr));
19200 info_ptr += 1;
19201 break;
19202 case DW_FORM_flag_present:
19203 attr->set_unsigned (1);
19204 break;
19205 case DW_FORM_sdata:
19206 attr->set_signed (read_signed_leb128 (abfd, info_ptr, &bytes_read));
19207 info_ptr += bytes_read;
19208 break;
19209 case DW_FORM_rnglistx:
19210 {
19211 attr->set_unsigned_reprocess (read_unsigned_leb128 (abfd, info_ptr,
19212 &bytes_read));
19213 info_ptr += bytes_read;
19214 }
19215 break;
19216 case DW_FORM_udata:
19217 attr->set_unsigned (read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
19218 info_ptr += bytes_read;
19219 break;
19220 case DW_FORM_ref1:
19221 attr->set_unsigned ((to_underlying (cu_header->sect_off)
19222 + read_1_byte (abfd, info_ptr)));
19223 info_ptr += 1;
19224 break;
19225 case DW_FORM_ref2:
19226 attr->set_unsigned ((to_underlying (cu_header->sect_off)
19227 + read_2_bytes (abfd, info_ptr)));
19228 info_ptr += 2;
19229 break;
19230 case DW_FORM_ref4:
19231 attr->set_unsigned ((to_underlying (cu_header->sect_off)
19232 + read_4_bytes (abfd, info_ptr)));
19233 info_ptr += 4;
19234 break;
19235 case DW_FORM_ref8:
19236 attr->set_unsigned ((to_underlying (cu_header->sect_off)
19237 + read_8_bytes (abfd, info_ptr)));
19238 info_ptr += 8;
19239 break;
19240 case DW_FORM_ref_sig8:
19241 attr->set_signature (read_8_bytes (abfd, info_ptr));
19242 info_ptr += 8;
19243 break;
19244 case DW_FORM_ref_udata:
19245 attr->set_unsigned ((to_underlying (cu_header->sect_off)
19246 + read_unsigned_leb128 (abfd, info_ptr,
19247 &bytes_read)));
19248 info_ptr += bytes_read;
19249 break;
19250 case DW_FORM_indirect:
19251 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
19252 info_ptr += bytes_read;
19253 if (form == DW_FORM_implicit_const)
19254 {
19255 implicit_const = read_signed_leb128 (abfd, info_ptr, &bytes_read);
19256 info_ptr += bytes_read;
19257 }
19258 info_ptr = read_attribute_value (reader, attr, form, implicit_const,
19259 info_ptr);
19260 break;
19261 case DW_FORM_implicit_const:
19262 attr->set_signed (implicit_const);
19263 break;
19264 case DW_FORM_addrx:
19265 case DW_FORM_GNU_addr_index:
19266 attr->set_unsigned_reprocess (read_unsigned_leb128 (abfd, info_ptr,
19267 &bytes_read));
19268 info_ptr += bytes_read;
19269 break;
19270 case DW_FORM_strx:
19271 case DW_FORM_strx1:
19272 case DW_FORM_strx2:
19273 case DW_FORM_strx3:
19274 case DW_FORM_strx4:
19275 case DW_FORM_GNU_str_index:
19276 {
19277 ULONGEST str_index;
19278 if (form == DW_FORM_strx1)
19279 {
19280 str_index = read_1_byte (abfd, info_ptr);
19281 info_ptr += 1;
19282 }
19283 else if (form == DW_FORM_strx2)
19284 {
19285 str_index = read_2_bytes (abfd, info_ptr);
19286 info_ptr += 2;
19287 }
19288 else if (form == DW_FORM_strx3)
19289 {
19290 str_index = read_3_bytes (abfd, info_ptr);
19291 info_ptr += 3;
19292 }
19293 else if (form == DW_FORM_strx4)
19294 {
19295 str_index = read_4_bytes (abfd, info_ptr);
19296 info_ptr += 4;
19297 }
19298 else
19299 {
19300 str_index = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
19301 info_ptr += bytes_read;
19302 }
19303 attr->set_unsigned_reprocess (str_index);
19304 }
19305 break;
19306 default:
19307 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19308 dwarf_form_name (form),
19309 bfd_get_filename (abfd));
19310 }
19311
19312 /* Super hack. */
19313 if (cu->per_cu->is_dwz && attr->form_is_ref ())
19314 attr->form = DW_FORM_GNU_ref_alt;
19315
19316 /* We have seen instances where the compiler tried to emit a byte
19317 size attribute of -1 which ended up being encoded as an unsigned
19318 0xffffffff. Although 0xffffffff is technically a valid size value,
19319 an object of this size seems pretty unlikely so we can relatively
19320 safely treat these cases as if the size attribute was invalid and
19321 treat them as zero by default. */
19322 if (attr->name == DW_AT_byte_size
19323 && form == DW_FORM_data4
19324 && attr->as_unsigned () >= 0xffffffff)
19325 {
19326 complaint
19327 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19328 hex_string (attr->as_unsigned ()));
19329 attr->set_unsigned (0);
19330 }
19331
19332 return info_ptr;
19333}
19334
19335/* Read an attribute described by an abbreviated attribute. */
19336
19337static const gdb_byte *
19338read_attribute (const struct die_reader_specs *reader,
19339 struct attribute *attr, const struct attr_abbrev *abbrev,
19340 const gdb_byte *info_ptr)
19341{
19342 attr->name = abbrev->name;
19343 attr->string_is_canonical = 0;
19344 attr->requires_reprocessing = 0;
19345 return read_attribute_value (reader, attr, abbrev->form,
19346 abbrev->implicit_const, info_ptr);
19347}
19348
19349/* Return pointer to string at .debug_str offset STR_OFFSET. */
19350
19351static const char *
19353 LONGEST str_offset)
19354{
19355 return per_objfile->per_bfd->str.read_string (per_objfile->objfile,
19356 str_offset, "DW_FORM_strp");
19357}
19358
19359/* Return pointer to string at .debug_str offset as read from BUF.
19360 BUF is assumed to be in a compilation unit described by CU_HEADER.
19361 Return *BYTES_READ_PTR count of bytes read from BUF. */
19362
19363static const char *
19365 const gdb_byte *buf,
19366 const struct comp_unit_head *cu_header,
19367 unsigned int *bytes_read_ptr)
19368{
19369 LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr);
19370
19371 return read_indirect_string_at_offset (per_objfile, str_offset);
19372}
19373
19374/* See read.h. */
19375
19376const char *
19378 unsigned int offset_size)
19379{
19380 bfd *abfd = objfile->obfd.get ();
19381 ULONGEST str_offset = read_offset (abfd, buf, offset_size);
19382
19383 return per_bfd->line_str.read_string (objfile, str_offset, "DW_FORM_line_strp");
19384}
19385
19386/* See read.h. */
19387
19388const char *
19390 const struct comp_unit_head *cu_header,
19391 unsigned int *bytes_read_ptr)
19392{
19393 bfd *abfd = objfile->obfd.get ();
19394 LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr);
19395
19396 return per_bfd->line_str.read_string (objfile, str_offset, "DW_FORM_line_strp");
19397}
19398
19399/* Given index ADDR_INDEX in .debug_addr, fetch the value.
19400 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19401 ADDR_SIZE is the size of addresses from the CU header. */
19402
19403static CORE_ADDR
19404read_addr_index_1 (dwarf2_per_objfile *per_objfile, unsigned int addr_index,
19405 gdb::optional<ULONGEST> addr_base, int addr_size)
19406{
19407 struct objfile *objfile = per_objfile->objfile;
19408 bfd *abfd = objfile->obfd.get ();
19409 const gdb_byte *info_ptr;
19410 ULONGEST addr_base_or_zero = addr_base.has_value () ? *addr_base : 0;
19411
19412 per_objfile->per_bfd->addr.read (objfile);
19413 if (per_objfile->per_bfd->addr.buffer == NULL)
19414 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19416 if (addr_base_or_zero + addr_index * addr_size
19417 >= per_objfile->per_bfd->addr.size)
19418 error (_("DW_FORM_addr_index pointing outside of "
19419 ".debug_addr section [in module %s]"),
19421 info_ptr = (per_objfile->per_bfd->addr.buffer + addr_base_or_zero
19422 + addr_index * addr_size);
19423 if (addr_size == 4)
19424 return bfd_get_32 (abfd, info_ptr);
19425 else
19426 return bfd_get_64 (abfd, info_ptr);
19427}
19428
19429/* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19430
19431static CORE_ADDR
19432read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index)
19433{
19434 return read_addr_index_1 (cu->per_objfile, addr_index,
19435 cu->addr_base, cu->header.addr_size);
19436}
19437
19438/* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19439
19440static CORE_ADDR
19441read_addr_index_from_leb128 (struct dwarf2_cu *cu, const gdb_byte *info_ptr,
19442 unsigned int *bytes_read)
19443{
19444 bfd *abfd = cu->per_objfile->objfile->obfd.get ();
19445 unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
19446
19447 return read_addr_index (cu, addr_index);
19448}
19449
19450/* See read.h. */
19451
19452CORE_ADDR
19454 dwarf2_per_objfile *per_objfile,
19455 unsigned int addr_index)
19456{
19457 struct dwarf2_cu *cu = per_objfile->get_cu (per_cu);
19458 gdb::optional<ULONGEST> addr_base;
19459 int addr_size;
19460
19461 /* We need addr_base and addr_size.
19462 If we don't have PER_CU->cu, we have to get it.
19463 Nasty, but the alternative is storing the needed info in PER_CU,
19464 which at this point doesn't seem justified: it's not clear how frequently
19465 it would get used and it would increase the size of every PER_CU.
19466 Entry points like dwarf2_per_cu_addr_size do a similar thing
19467 so we're not in uncharted territory here.
19468 Alas we need to be a bit more complicated as addr_base is contained
19469 in the DIE.
19470
19471 We don't need to read the entire CU(/TU).
19472 We just need the header and top level die.
19473
19474 IWBN to use the aging mechanism to let us lazily later discard the CU.
19475 For now we skip this optimization. */
19476
19477 if (cu != NULL)
19478 {
19479 addr_base = cu->addr_base;
19480 addr_size = cu->header.addr_size;
19481 }
19482 else
19483 {
19484 cutu_reader reader (per_cu, per_objfile, nullptr, nullptr, false);
19485 addr_base = reader.cu->addr_base;
19486 addr_size = reader.cu->header.addr_size;
19487 }
19488
19489 return read_addr_index_1 (per_objfile, addr_index, addr_base, addr_size);
19490}
19491
19492/* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19493 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19494 DWO file. */
19495
19496static const char *
19498 struct dwarf2_section_info *str_section,
19499 struct dwarf2_section_info *str_offsets_section,
19500 ULONGEST str_offsets_base, ULONGEST str_index,
19501 unsigned offset_size)
19502{
19504 struct objfile *objfile = per_objfile->objfile;
19505 const char *objf_name = objfile_name (objfile);
19506 bfd *abfd = objfile->obfd.get ();
19507 const gdb_byte *info_ptr;
19508 ULONGEST str_offset;
19509 static const char form_name[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19510
19511 str_section->read (objfile);
19512 str_offsets_section->read (objfile);
19513 if (str_section->buffer == NULL)
19514 error (_("%s used without %s section"
19515 " in CU at offset %s [in module %s]"),
19516 form_name, str_section->get_name (),
19517 sect_offset_str (cu->header.sect_off), objf_name);
19518 if (str_offsets_section->buffer == NULL)
19519 error (_("%s used without %s section"
19520 " in CU at offset %s [in module %s]"),
19521 form_name, str_section->get_name (),
19522 sect_offset_str (cu->header.sect_off), objf_name);
19523 info_ptr = (str_offsets_section->buffer
19524 + str_offsets_base
19525 + str_index * offset_size);
19526 if (offset_size == 4)
19527 str_offset = bfd_get_32 (abfd, info_ptr);
19528 else
19529 str_offset = bfd_get_64 (abfd, info_ptr);
19530 if (str_offset >= str_section->size)
19531 error (_("Offset from %s pointing outside of"
19532 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19533 form_name, sect_offset_str (cu->header.sect_off), objf_name);
19534 return (const char *) (str_section->buffer + str_offset);
19535}
19536
19537/* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19538
19539static const char *
19540read_dwo_str_index (const struct die_reader_specs *reader, ULONGEST str_index)
19541{
19542 unsigned offset_size;
19543 ULONGEST str_offsets_base;
19544 if (reader->cu->header.version >= 5)
19545 {
19546 /* We have a DWARF5 CU with a reference to a .debug_str_offsets section,
19547 so assume the .debug_str_offsets section is DWARF5 as well, and
19548 parse the header. FIXME: Parse the header only once. */
19549 unsigned int bytes_read = 0;
19550 bfd *abfd = reader->dwo_file->sections.str_offsets.get_bfd_owner ();
19551 const gdb_byte *p = reader->dwo_file->sections.str_offsets.buffer;
19552
19553 /* Header: Initial length. */
19554 read_initial_length (abfd, p + bytes_read, &bytes_read);
19555
19556 /* Determine offset_size based on the .debug_str_offsets header. */
19557 const bool dwarf5_is_dwarf64 = bytes_read != 4;
19558 offset_size = dwarf5_is_dwarf64 ? 8 : 4;
19559
19560 /* Header: Version. */
19561 unsigned version = read_2_bytes (abfd, p + bytes_read);
19562 bytes_read += 2;
19563
19564 if (version <= 4)
19565 {
19566 /* We'd like one warning here about ignoring the section, but
19567 because we parse the header more than once (see FIXME above)
19568 we'd have many warnings, so use a complaint instead, which at
19569 least has a limit. */
19570 complaint (_("Section .debug_str_offsets in %s has unsupported"
19571 " version %d, use empty string."),
19572 reader->dwo_file->dwo_name, version);
19573 return "";
19574 }
19575
19576 /* Header: Padding. */
19577 bytes_read += 2;
19578
19579 str_offsets_base = bytes_read;
19580 }
19581 else
19582 {
19583 /* We have a pre-DWARF5 CU with a reference to a .debug_str_offsets
19584 section, assume the .debug_str_offsets section is pre-DWARF5 as
19585 well, which doesn't have a header. */
19586 str_offsets_base = 0;
19587
19588 /* Determine offset_size based on the .debug_info header. */
19589 offset_size = reader->cu->header.offset_size;
19590 }
19591
19592 return read_str_index (reader->cu,
19593 &reader->dwo_file->sections.str,
19594 &reader->dwo_file->sections.str_offsets,
19595 str_offsets_base, str_index, offset_size);
19596}
19597
19598/* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19599
19600static const char *
19601read_stub_str_index (struct dwarf2_cu *cu, ULONGEST str_index)
19602{
19603 struct objfile *objfile = cu->per_objfile->objfile;
19604 const char *objf_name = objfile_name (objfile);
19605 static const char form_name[] = "DW_FORM_GNU_str_index";
19606 static const char str_offsets_attr_name[] = "DW_AT_str_offsets";
19607
19608 if (!cu->str_offsets_base.has_value ())
19609 error (_("%s used in Fission stub without %s"
19610 " in CU at offset 0x%lx [in module %s]"),
19611 form_name, str_offsets_attr_name,
19612 (long) cu->header.offset_size, objf_name);
19613
19614 return read_str_index (cu,
19615 &cu->per_objfile->per_bfd->str,
19617 *cu->str_offsets_base, str_index,
19618 cu->header.offset_size);
19619}
19620
19621/* Return the length of an LEB128 number in BUF. */
19622
19623static int
19624leb128_size (const gdb_byte *buf)
19625{
19626 const gdb_byte *begin = buf;
19627 gdb_byte byte;
19628
19629 while (1)
19630 {
19631 byte = *buf++;
19632 if ((byte & 128) == 0)
19633 return buf - begin;
19634 }
19635}
19636
19637static enum language
19639{
19640 enum language language;
19641
19642 switch (lang)
19643 {
19644 case DW_LANG_C89:
19645 case DW_LANG_C99:
19646 case DW_LANG_C11:
19647 case DW_LANG_C:
19648 case DW_LANG_UPC:
19650 break;
19651 case DW_LANG_Java:
19652 case DW_LANG_C_plus_plus:
19653 case DW_LANG_C_plus_plus_11:
19654 case DW_LANG_C_plus_plus_14:
19656 break;
19657 case DW_LANG_D:
19659 break;
19660 case DW_LANG_Fortran77:
19661 case DW_LANG_Fortran90:
19662 case DW_LANG_Fortran95:
19663 case DW_LANG_Fortran03:
19664 case DW_LANG_Fortran08:
19666 break;
19667 case DW_LANG_Go:
19669 break;
19670 case DW_LANG_Mips_Assembler:
19672 break;
19673 case DW_LANG_Ada83:
19674 case DW_LANG_Ada95:
19676 break;
19677 case DW_LANG_Modula2:
19679 break;
19680 case DW_LANG_Pascal83:
19682 break;
19683 case DW_LANG_ObjC:
19685 break;
19686 case DW_LANG_Rust:
19687 case DW_LANG_Rust_old:
19689 break;
19690 case DW_LANG_OpenCL:
19692 break;
19693 case DW_LANG_Cobol74:
19694 case DW_LANG_Cobol85:
19695 default:
19697 break;
19698 }
19699
19700 return language;
19701}
19702
19703/* Return the named attribute or NULL if not there. */
19704
19705static struct attribute *
19706dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
19707{
19708 for (;;)
19709 {
19710 unsigned int i;
19711 struct attribute *spec = NULL;
19712
19713 for (i = 0; i < die->num_attrs; ++i)
19714 {
19715 if (die->attrs[i].name == name)
19716 return &die->attrs[i];
19717 if (die->attrs[i].name == DW_AT_specification
19718 || die->attrs[i].name == DW_AT_abstract_origin)
19719 spec = &die->attrs[i];
19720 }
19721
19722 if (!spec)
19723 break;
19724
19725 die = follow_die_ref (die, spec, &cu);
19726 }
19727
19728 return NULL;
19729}
19730
19731/* Return the string associated with a string-typed attribute, or NULL if it
19732 is either not found or is of an incorrect type. */
19733
19734static const char *
19735dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
19736{
19737 struct attribute *attr;
19738 const char *str = NULL;
19739
19740 attr = dwarf2_attr (die, name, cu);
19741
19742 if (attr != NULL)
19743 {
19744 str = attr->as_string ();
19745 if (str == nullptr)
19746 complaint (_("string type expected for attribute %s for "
19747 "DIE at %s in module %s"),
19750 }
19751
19752 return str;
19753}
19754
19755/* Return the dwo name or NULL if not present. If present, it is in either
19756 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19757static const char *
19758dwarf2_dwo_name (struct die_info *die, struct dwarf2_cu *cu)
19759{
19760 const char *dwo_name = dwarf2_string_attr (die, DW_AT_GNU_dwo_name, cu);
19761 if (dwo_name == nullptr)
19762 dwo_name = dwarf2_string_attr (die, DW_AT_dwo_name, cu);
19763 return dwo_name;
19764}
19765
19766/* Return non-zero iff the attribute NAME is defined for the given DIE,
19767 and holds a non-zero value. This function should only be used for
19768 DW_FORM_flag or DW_FORM_flag_present attributes. */
19769
19770static int
19771dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
19772{
19773 struct attribute *attr = dwarf2_attr (die, name, cu);
19774
19775 return attr != nullptr && attr->as_boolean ();
19776}
19777
19778static int
19779die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
19780{
19781 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19782 which value is non-zero. However, we have to be careful with
19783 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19784 (via dwarf2_flag_true_p) follows this attribute. So we may
19785 end up accidently finding a declaration attribute that belongs
19786 to a different DIE referenced by the specification attribute,
19787 even though the given DIE does not have a declaration attribute. */
19788 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
19789 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
19790}
19791
19792/* Return the die giving the specification for DIE, if there is
19793 one. *SPEC_CU is the CU containing DIE on input, and the CU
19794 containing the return value on output. If there is no
19795 specification, but there is an abstract origin, that is
19796 returned. */
19797
19798static struct die_info *
19799die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
19800{
19801 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
19802 *spec_cu);
19803
19804 if (spec_attr == NULL)
19805 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
19806
19807 if (spec_attr == NULL)
19808 return NULL;
19809 else
19810 return follow_die_ref (die, spec_attr, spec_cu);
19811}
19812
19813/* A convenience function to find the proper .debug_line section for a CU. */
19814
19815static struct dwarf2_section_info *
19817{
19819 dwarf2_per_objfile *per_objfile = cu->per_objfile;
19820
19821 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19822 DWO file. */
19823 if (cu->dwo_unit && cu->per_cu->is_debug_types)
19824 section = &cu->dwo_unit->dwo_file->sections.line;
19825 else if (cu->per_cu->is_dwz)
19826 {
19827 dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true);
19828
19829 section = &dwz->line;
19830 }
19831 else
19832 section = &per_objfile->per_bfd->line;
19833
19834 return section;
19835}
19836
19837/* Read the statement program header starting at OFFSET in
19838 .debug_line, or .debug_line.dwo. Return a pointer
19839 to a struct line_header, allocated using xmalloc.
19840 Returns NULL if there is a problem reading the header, e.g., if it
19841 has a version we don't understand.
19842
19843 NOTE: the strings in the include directory and file name tables of
19844 the returned object point into the dwarf line section buffer,
19845 and must not be freed. */
19846
19847static line_header_up
19848dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu,
19849 const char *comp_dir)
19850{
19852 dwarf2_per_objfile *per_objfile = cu->per_objfile;
19853
19855 section->read (per_objfile->objfile);
19856 if (section->buffer == NULL)
19857 {
19858 if (cu->dwo_unit && cu->per_cu->is_debug_types)
19859 complaint (_("missing .debug_line.dwo section"));
19860 else
19861 complaint (_("missing .debug_line section"));
19862 return 0;
19863 }
19864
19865 return dwarf_decode_line_header (sect_off, cu->per_cu->is_dwz,
19866 per_objfile, section, &cu->header,
19867 comp_dir);
19868}
19869
19870/* Subroutine of dwarf_decode_lines to simplify it.
19871 Return the file name for the given file_entry.
19872 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
19873 If space for the result is malloc'd, *NAME_HOLDER will be set.
19874 Returns NULL if FILE_INDEX should be ignored, i.e., it is
19875 equivalent to CU_INFO. */
19876
19877static const char *
19879 const file_and_directory &cu_info,
19880 std::string &name_holder)
19881{
19882 const char *include_name = fe.name;
19883 const char *include_name_to_compare = include_name;
19884
19885 const char *dir_name = fe.include_dir (lh);
19886
19887 std::string hold_compare;
19888 if (!IS_ABSOLUTE_PATH (include_name)
19889 && (dir_name != nullptr || cu_info.get_comp_dir () != nullptr))
19890 {
19891 /* Avoid creating a duplicate name for CU_INFO.
19892 We do this by comparing INCLUDE_NAME and CU_INFO.
19893 Before we do the comparison, however, we need to account
19894 for DIR_NAME and COMP_DIR.
19895 First prepend dir_name (if non-NULL). If we still don't
19896 have an absolute path prepend comp_dir (if non-NULL).
19897 However, the directory we record in the include-file's
19898 psymtab does not contain COMP_DIR (to match the
19899 corresponding symtab(s)).
19900
19901 Example:
19902
19903 bash$ cd /tmp
19904 bash$ gcc -g ./hello.c
19905 include_name = "hello.c"
19906 dir_name = "."
19907 DW_AT_comp_dir = comp_dir = "/tmp"
19908 DW_AT_name = "./hello.c"
19909
19910 */
19911
19912 if (dir_name != NULL)
19913 {
19914 name_holder = path_join (dir_name, include_name);
19915 include_name = name_holder.c_str ();
19916 include_name_to_compare = include_name;
19917 }
19918 if (!IS_ABSOLUTE_PATH (include_name)
19919 && cu_info.get_comp_dir () != nullptr)
19920 {
19921 hold_compare = path_join (cu_info.get_comp_dir (), include_name);
19922 include_name_to_compare = hold_compare.c_str ();
19923 }
19924 }
19925
19926 std::string copied_name;
19927 const char *cu_filename = cu_info.get_name ();
19928 if (!IS_ABSOLUTE_PATH (cu_filename) && cu_info.get_comp_dir () != nullptr)
19929 {
19930 copied_name = path_join (cu_info.get_comp_dir (), cu_filename);
19931 cu_filename = copied_name.c_str ();
19932 }
19933
19934 if (FILENAME_CMP (include_name_to_compare, cu_filename) == 0)
19935 return nullptr;
19936 return include_name;
19937}
19938
19939/* State machine to track the state of the line number program. */
19940
19942{
19943public:
19944 /* Initialize a machine state for the start of a line number
19945 program. */
19946 lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch, line_header *lh);
19947
19949 {
19950 /* lh->file_names is 0-based, but the file name numbers in the
19951 statement program are 1-based. */
19953 }
19954
19955 /* Record the line in the state machine. END_SEQUENCE is true if
19956 we're processing the end of a sequence. */
19957 void record_line (bool end_sequence);
19958
19959 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
19960 nop-out rest of the lines in this sequence. */
19961 void check_line_address (struct dwarf2_cu *cu,
19962 const gdb_byte *line_ptr,
19963 CORE_ADDR unrelocated_lowpc, CORE_ADDR address);
19964
19965 void handle_set_discriminator (unsigned int discriminator)
19966 {
19967 m_discriminator = discriminator;
19968 m_line_has_non_zero_discriminator |= discriminator != 0;
19969 }
19970
19971 /* Handle DW_LNE_set_address. */
19972 void handle_set_address (CORE_ADDR baseaddr, CORE_ADDR address)
19973 {
19974 m_op_index = 0;
19975 address += baseaddr;
19977 }
19978
19979 /* Handle DW_LNS_advance_pc. */
19980 void handle_advance_pc (CORE_ADDR adjust);
19981
19982 /* Handle a special opcode. */
19983 void handle_special_opcode (unsigned char op_code);
19984
19985 /* Handle DW_LNS_advance_line. */
19986 void handle_advance_line (int line_delta)
19987 {
19988 advance_line (line_delta);
19989 }
19990
19991 /* Handle DW_LNS_set_file. */
19992 void handle_set_file (file_name_index file);
19993
19994 /* Handle DW_LNS_negate_stmt. */
19996 {
19998 }
19999
20000 /* Handle DW_LNS_const_add_pc. */
20001 void handle_const_add_pc ();
20002
20003 /* Handle DW_LNS_fixed_advance_pc. */
20004 void handle_fixed_advance_pc (CORE_ADDR addr_adj)
20005 {
20006 m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
20007 m_op_index = 0;
20008 }
20009
20010 /* Handle DW_LNS_copy. */
20012 {
20013 record_line (false);
20014 m_discriminator = 0;
20015 m_flags &= ~LEF_PROLOGUE_END;
20016 }
20017
20018 /* Handle DW_LNE_end_sequence. */
20020 {
20022 }
20023
20024 /* Handle DW_LNS_set_prologue_end. */
20026 {
20028 }
20029
20030private:
20031 /* Advance the line by LINE_DELTA. */
20032 void advance_line (int line_delta)
20033 {
20034 m_line += line_delta;
20035
20036 if (line_delta != 0)
20038 }
20039
20041
20043
20044 /* The line number header. */
20046
20047 /* These are part of the standard DWARF line number state machine,
20048 and initialized according to the DWARF spec. */
20049
20050 unsigned char m_op_index = 0;
20051 /* The line table index of the current file. */
20053 unsigned int m_line = 1;
20054
20055 /* These are initialized in the constructor. */
20056
20057 CORE_ADDR m_address;
20058 linetable_entry_flags m_flags;
20059 unsigned int m_discriminator;
20060
20061 /* Additional bits of state we need to track. */
20062
20063 /* The last file that we called dwarf2_start_subfile for.
20064 This is only used for TLLs. */
20065 unsigned int m_last_file = 0;
20066 /* The last file a line number was recorded for. */
20067 struct subfile *m_last_subfile = NULL;
20068
20069 /* The address of the last line entry. */
20071
20072 /* Set to true when a previous line at the same address (using
20073 m_last_address) had LEF_IS_STMT set in m_flags. This is reset to false
20074 when a line entry at a new address (m_address different to
20075 m_last_address) is processed. */
20076 bool m_stmt_at_address = false;
20077
20078 /* When true, record the lines we decode. */
20080
20081 /* The last line number that was recorded, used to coalesce
20082 consecutive entries for the same line. This can happen, for
20083 example, when discriminators are present. PR 17276. */
20084 unsigned int m_last_line = 0;
20086};
20087
20088void
20090{
20091 CORE_ADDR addr_adj = (((m_op_index + adjust)
20094 m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
20095 m_op_index = ((m_op_index + adjust)
20097}
20098
20099void
20101{
20102 unsigned char adj_opcode = op_code - m_line_header->opcode_base;
20103 unsigned char adj_opcode_d = adj_opcode / m_line_header->line_range;
20104 unsigned char adj_opcode_r = adj_opcode % m_line_header->line_range;
20105 CORE_ADDR addr_adj = (((m_op_index + adj_opcode_d)
20108 m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
20109 m_op_index = ((m_op_index + adj_opcode_d)
20111
20112 int line_delta = m_line_header->line_base + adj_opcode_r;
20113 advance_line (line_delta);
20114 record_line (false);
20115 m_discriminator = 0;
20116 m_flags &= ~LEF_PROLOGUE_END;
20117}
20118
20119void
20121{
20122 m_file = file;
20123
20124 const file_entry *fe = current_file ();
20125 if (fe == NULL)
20127 else
20128 {
20132 }
20133}
20134
20135void
20137{
20138 CORE_ADDR adjust
20140
20141 CORE_ADDR addr_adj
20142 = (((m_op_index + adjust)
20145
20146 m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
20147 m_op_index = ((m_op_index + adjust)
20149}
20150
20151/* Return non-zero if we should add LINE to the line number table.
20152 LINE is the line to add, LAST_LINE is the last line that was added,
20153 LAST_SUBFILE is the subfile for LAST_LINE.
20154 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20155 had a non-zero discriminator.
20156
20157 We have to be careful in the presence of discriminators.
20158 E.g., for this line:
20159
20160 for (i = 0; i < 100000; i++);
20161
20162 clang can emit four line number entries for that one line,
20163 each with a different discriminator.
20164 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20165
20166 However, we want gdb to coalesce all four entries into one.
20167 Otherwise the user could stepi into the middle of the line and
20168 gdb would get confused about whether the pc really was in the
20169 middle of the line.
20170
20171 Things are further complicated by the fact that two consecutive
20172 line number entries for the same line is a heuristic used by gcc
20173 to denote the end of the prologue. So we can't just discard duplicate
20174 entries, we have to be selective about it. The heuristic we use is
20175 that we only collapse consecutive entries for the same line if at least
20176 one of those entries has a non-zero discriminator. PR 17276.
20177
20178 Note: Addresses in the line number state machine can never go backwards
20179 within one sequence, thus this coalescing is ok. */
20180
20181static int
20183 unsigned int line, unsigned int last_line,
20184 int line_has_non_zero_discriminator,
20185 struct subfile *last_subfile)
20186{
20187 if (cu->get_builder ()->get_current_subfile () != last_subfile)
20188 return 1;
20189 if (line != last_line)
20190 return 1;
20191 /* Same line for the same file that we've seen already.
20192 As a last check, for pr 17276, only record the line if the line
20193 has never had a non-zero discriminator. */
20194 if (!line_has_non_zero_discriminator)
20195 return 1;
20196 return 0;
20197}
20198
20199/* Use the CU's builder to record line number LINE beginning at
20200 address ADDRESS in the line table of subfile SUBFILE. */
20201
20202static void
20204 unsigned int line, CORE_ADDR address,
20205 linetable_entry_flags flags,
20206 struct dwarf2_cu *cu)
20207{
20208 CORE_ADDR addr = gdbarch_addr_bits_remove (gdbarch, address);
20209
20210 if (dwarf_line_debug)
20211 {
20213 "Recording line %u, file %s, address %s\n",
20214 line, lbasename (subfile->name.c_str ()),
20215 paddress (gdbarch, address));
20216 }
20217
20218 if (cu != nullptr)
20219 cu->get_builder ()->record_line (subfile, line, addr, flags);
20220}
20221
20222/* Subroutine of dwarf_decode_lines_1 to simplify it.
20223 Mark the end of a set of line number records.
20224 The arguments are the same as for dwarf_record_line_1.
20225 If SUBFILE is NULL the request is ignored. */
20226
20227static void
20229 CORE_ADDR address, struct dwarf2_cu *cu)
20230{
20231 if (subfile == NULL)
20232 return;
20233
20234 if (dwarf_line_debug)
20235 {
20237 "Finishing current line, file %s, address %s\n",
20238 lbasename (subfile->name.c_str ()),
20239 paddress (gdbarch, address));
20240 }
20241
20242 dwarf_record_line_1 (gdbarch, subfile, 0, address, LEF_IS_STMT, cu);
20243}
20244
20245void
20247{
20248 if (dwarf_line_debug)
20249 {
20251 "Processing actual line %u: file %u,"
20252 " address %s, is_stmt %u, prologue_end %u, discrim %u%s\n",
20253 m_line, m_file,
20255 (m_flags & LEF_IS_STMT) != 0,
20256 (m_flags & LEF_PROLOGUE_END) != 0,
20258 (end_sequence ? "\t(end sequence)" : ""));
20259 }
20260
20261 file_entry *fe = current_file ();
20262
20263 if (fe == NULL)
20265 /* For now we ignore lines not starting on an instruction boundary.
20266 But not when processing end_sequence for compatibility with the
20267 previous version of the code. */
20268 else if (m_op_index == 0 || end_sequence)
20269 {
20270 /* When we switch files we insert an end maker in the first file,
20271 switch to the second file and add a new line entry. The
20272 problem is that the end marker inserted in the first file will
20273 discard any previous line entries at the same address. If the
20274 line entries in the first file are marked as is-stmt, while
20275 the new line in the second file is non-stmt, then this means
20276 the end marker will discard is-stmt lines so we can have a
20277 non-stmt line. This means that there are less addresses at
20278 which the user can insert a breakpoint.
20279
20280 To improve this we track the last address in m_last_address,
20281 and whether we have seen an is-stmt at this address. Then
20282 when switching files, if we have seen a stmt at the current
20283 address, and we are switching to create a non-stmt line, then
20284 discard the new line. */
20285 bool file_changed
20287 bool ignore_this_line
20288 = ((file_changed && !end_sequence && m_last_address == m_address
20289 && ((m_flags & LEF_IS_STMT) == 0)
20291 || (!end_sequence && m_line == 0));
20292
20293 if ((file_changed && !ignore_this_line) || end_sequence)
20294 {
20296 m_currently_recording_lines ? m_cu : nullptr);
20297 }
20298
20299 if (!end_sequence && !ignore_this_line)
20300 {
20301 linetable_entry_flags lte_flags = m_flags;
20303 lte_flags |= LEF_IS_STMT;
20304
20308 {
20309 buildsym_compunit *builder = m_cu->get_builder ();
20311 builder->get_current_subfile (),
20312 m_line, m_address, lte_flags,
20313 m_currently_recording_lines ? m_cu : nullptr);
20314 }
20317 }
20318 }
20319
20320 /* Track whether we have seen any IS_STMT true at m_address in case we
20321 have multiple line table entries all at m_address. */
20323 {
20324 m_stmt_at_address = false;
20326 }
20328}
20329
20331 line_header *lh)
20332{
20333 m_cu = cu;
20334 m_gdbarch = arch;
20335 m_line_header = lh;
20336
20338
20339 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20340 was a line entry for it so that the backend has a chance to adjust it
20341 and also record it in case it needs it. This is currently used by MIPS
20342 code, cf. `mips_adjust_dwarf2_line'. */
20344 m_flags = 0;
20345 if (lh->default_is_stmt)
20347 m_discriminator = 0;
20348
20350 m_stmt_at_address = false;
20351}
20352
20353void
20355 const gdb_byte *line_ptr,
20356 CORE_ADDR unrelocated_lowpc, CORE_ADDR address)
20357{
20358 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
20359 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
20360 located at 0x0. In this case, additionally check that if
20361 ADDRESS < UNRELOCATED_LOWPC. */
20362
20363 if ((address == 0 && address < unrelocated_lowpc)
20364 || address == (CORE_ADDR) -1)
20365 {
20366 /* This line table is for a function which has been
20367 GCd by the linker. Ignore it. PR gdb/12528 */
20368
20369 struct objfile *objfile = cu->per_objfile->objfile;
20370 long line_offset = line_ptr - get_debug_line_section (cu)->buffer;
20371
20372 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20375 /* Note: m_currently_recording_lines is left as false until we see
20376 DW_LNE_end_sequence. */
20377 }
20378}
20379
20380/* Subroutine of dwarf_decode_lines to simplify it.
20381 Process the line number information in LH. */
20382
20383static void
20385 CORE_ADDR lowpc)
20386{
20387 const gdb_byte *line_ptr, *extended_end;
20388 const gdb_byte *line_end;
20389 unsigned int bytes_read, extended_len;
20390 unsigned char op_code, extended_op;
20391 CORE_ADDR baseaddr;
20392 struct objfile *objfile = cu->per_objfile->objfile;
20393 bfd *abfd = objfile->obfd.get ();
20394 struct gdbarch *gdbarch = objfile->arch ();
20395
20396 baseaddr = objfile->text_section_offset ();
20397
20398 line_ptr = lh->statement_program_start;
20399 line_end = lh->statement_program_end;
20400
20401 /* Read the statement sequences until there's nothing left. */
20402 while (line_ptr < line_end)
20403 {
20404 /* The DWARF line number program state machine. Reset the state
20405 machine at the start of each sequence. */
20406 lnp_state_machine state_machine (cu, gdbarch, lh);
20407 bool end_sequence = false;
20408
20409 /* Start a subfile for the current file of the state
20410 machine. */
20411 const file_entry *fe = state_machine.current_file ();
20412
20413 if (fe != NULL)
20414 dwarf2_start_subfile (cu, *fe, *lh);
20415
20416 /* Decode the table. */
20417 while (line_ptr < line_end && !end_sequence)
20418 {
20419 op_code = read_1_byte (abfd, line_ptr);
20420 line_ptr += 1;
20421
20422 if (op_code >= lh->opcode_base)
20423 {
20424 /* Special opcode. */
20425 state_machine.handle_special_opcode (op_code);
20426 }
20427 else switch (op_code)
20428 {
20429 case DW_LNS_extended_op:
20430 extended_len = read_unsigned_leb128 (abfd, line_ptr,
20431 &bytes_read);
20432 line_ptr += bytes_read;
20433 extended_end = line_ptr + extended_len;
20434 extended_op = read_1_byte (abfd, line_ptr);
20435 line_ptr += 1;
20436 if (DW_LNE_lo_user <= extended_op
20437 && extended_op <= DW_LNE_hi_user)
20438 {
20439 /* Vendor extension, ignore. */
20440 line_ptr = extended_end;
20441 break;
20442 }
20443 switch (extended_op)
20444 {
20445 case DW_LNE_end_sequence:
20446 state_machine.handle_end_sequence ();
20447 end_sequence = true;
20448 break;
20449 case DW_LNE_set_address:
20450 {
20451 CORE_ADDR address
20452 = cu->header.read_address (abfd, line_ptr, &bytes_read);
20453 line_ptr += bytes_read;
20454
20455 state_machine.check_line_address (cu, line_ptr,
20456 lowpc - baseaddr, address);
20457 state_machine.handle_set_address (baseaddr, address);
20458 }
20459 break;
20460 case DW_LNE_define_file:
20461 {
20462 const char *cur_file;
20463 unsigned int mod_time, length;
20464 dir_index dindex;
20465
20466 cur_file = read_direct_string (abfd, line_ptr,
20467 &bytes_read);
20468 line_ptr += bytes_read;
20469 dindex = (dir_index)
20470 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
20471 line_ptr += bytes_read;
20472 mod_time =
20473 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
20474 line_ptr += bytes_read;
20475 length =
20476 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
20477 line_ptr += bytes_read;
20478 lh->add_file_name (cur_file, dindex, mod_time, length);
20479 }
20480 break;
20481 case DW_LNE_set_discriminator:
20482 {
20483 /* The discriminator is not interesting to the
20484 debugger; just ignore it. We still need to
20485 check its value though:
20486 if there are consecutive entries for the same
20487 (non-prologue) line we want to coalesce them.
20488 PR 17276. */
20489 unsigned int discr
20490 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
20491 line_ptr += bytes_read;
20492
20493 state_machine.handle_set_discriminator (discr);
20494 }
20495 break;
20496 default:
20497 complaint (_("mangled .debug_line section"));
20498 return;
20499 }
20500 /* Make sure that we parsed the extended op correctly. If e.g.
20501 we expected a different address size than the producer used,
20502 we may have read the wrong number of bytes. */
20503 if (line_ptr != extended_end)
20504 {
20505 complaint (_("mangled .debug_line section"));
20506 return;
20507 }
20508 break;
20509 case DW_LNS_copy:
20510 state_machine.handle_copy ();
20511 break;
20512 case DW_LNS_advance_pc:
20513 {
20514 CORE_ADDR adjust
20515 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
20516 line_ptr += bytes_read;
20517
20518 state_machine.handle_advance_pc (adjust);
20519 }
20520 break;
20521 case DW_LNS_advance_line:
20522 {
20523 int line_delta
20524 = read_signed_leb128 (abfd, line_ptr, &bytes_read);
20525 line_ptr += bytes_read;
20526
20527 state_machine.handle_advance_line (line_delta);
20528 }
20529 break;
20530 case DW_LNS_set_file:
20531 {
20532 file_name_index file
20533 = (file_name_index) read_unsigned_leb128 (abfd, line_ptr,
20534 &bytes_read);
20535 line_ptr += bytes_read;
20536
20537 state_machine.handle_set_file (file);
20538 }
20539 break;
20540 case DW_LNS_set_column:
20541 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
20542 line_ptr += bytes_read;
20543 break;
20544 case DW_LNS_negate_stmt:
20545 state_machine.handle_negate_stmt ();
20546 break;
20547 case DW_LNS_set_basic_block:
20548 break;
20549 /* Add to the address register of the state machine the
20550 address increment value corresponding to special opcode
20551 255. I.e., this value is scaled by the minimum
20552 instruction length since special opcode 255 would have
20553 scaled the increment. */
20554 case DW_LNS_const_add_pc:
20555 state_machine.handle_const_add_pc ();
20556 break;
20557 case DW_LNS_fixed_advance_pc:
20558 {
20559 CORE_ADDR addr_adj = read_2_bytes (abfd, line_ptr);
20560 line_ptr += 2;
20561
20562 state_machine.handle_fixed_advance_pc (addr_adj);
20563 }
20564 break;
20565 case DW_LNS_set_prologue_end:
20566 state_machine.handle_set_prologue_end ();
20567 break;
20568 default:
20569 {
20570 /* Unknown standard opcode, ignore it. */
20571 int i;
20572
20573 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
20574 {
20575 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
20576 line_ptr += bytes_read;
20577 }
20578 }
20579 }
20580 }
20581
20582 if (!end_sequence)
20584
20585 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20586 in which case we still finish recording the last line). */
20587 state_machine.record_line (true);
20588 }
20589}
20590
20591/* Decode the Line Number Program (LNP) for the given line_header
20592 structure and CU. The actual information extracted and the type
20593 of structures created from the LNP depends on the value of PST.
20594
20595 FND holds the CU file name and directory, if known.
20596 It is used for relative paths in the line table.
20597
20598 NOTE: It is important that psymtabs have the same file name (via
20599 strcmp) as the corresponding symtab. Since the directory is not
20600 used in the name of the symtab we don't use it in the name of the
20601 psymtabs we create. E.g. expand_line_sal requires this when
20602 finding psymtabs to expand. A good testcase for this is
20603 mb-inline.exp.
20604
20605 LOWPC is the lowest address in CU (or 0 if not known).
20606
20607 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20608 for its PC<->lines mapping information. Otherwise only the filename
20609 table is read in. */
20610
20611static void
20613 CORE_ADDR lowpc, int decode_mapping)
20614{
20615 if (decode_mapping)
20616 dwarf_decode_lines_1 (lh, cu, lowpc);
20617
20618 /* Make sure a symtab is created for every file, even files
20619 which contain only variables (i.e. no code with associated
20620 line numbers). */
20621 buildsym_compunit *builder = cu->get_builder ();
20622 struct compunit_symtab *cust = builder->get_compunit_symtab ();
20623
20624 for (auto &fe : lh->file_names ())
20625 {
20626 dwarf2_start_subfile (cu, fe, *lh);
20627 subfile *sf = builder->get_current_subfile ();
20628
20629 if (sf->symtab == nullptr)
20630 sf->symtab = allocate_symtab (cust, sf->name.c_str (),
20631 sf->name_for_id.c_str ());
20632
20633 fe.symtab = sf->symtab;
20634 }
20635}
20636
20637/* Start a subfile for DWARF. FILENAME is the name of the file and
20638 DIRNAME the name of the source directory which contains FILENAME
20639 or NULL if not known.
20640 This routine tries to keep line numbers from identical absolute and
20641 relative file names in a common subfile.
20642
20643 Using the `list' example from the GDB testsuite, which resides in
20644 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20645 of /srcdir/list0.c yields the following debugging information for list0.c:
20646
20647 DW_AT_name: /srcdir/list0.c
20648 DW_AT_comp_dir: /compdir
20649 files.files[0].name: list0.h
20650 files.files[0].dir: /srcdir
20651 files.files[1].name: list0.c
20652 files.files[1].dir: /srcdir
20653
20654 The line number information for list0.c has to end up in a single
20655 subfile, so that `break /srcdir/list0.c:1' works as expected.
20656 start_subfile will ensure that this happens provided that we pass the
20657 concatenation of files.files[1].dir and files.files[1].name as the
20658 subfile's name. */
20659
20660static void
20662 const line_header &lh)
20663{
20664 std::string filename_holder;
20665 const char *filename = fe.name;
20666 const char *dirname = lh.include_dir_at (fe.d_index);
20667
20668 /* In order not to lose the line information directory,
20669 we concatenate it to the filename when it makes sense.
20670 Note that the Dwarf3 standard says (speaking of filenames in line
20671 information): ``The directory index is ignored for file names
20672 that represent full path names''. Thus ignoring dirname in the
20673 `else' branch below isn't an issue. */
20674
20675 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
20676 {
20677 filename_holder = path_join (dirname, filename);
20678 filename = filename_holder.c_str ();
20679 }
20680
20681 std::string filename_for_id = lh.file_file_name (fe);
20682 cu->get_builder ()->start_subfile (filename, filename_for_id.c_str ());
20683}
20684
20685static void
20686var_decode_location (struct attribute *attr, struct symbol *sym,
20687 struct dwarf2_cu *cu)
20688{
20689 struct objfile *objfile = cu->per_objfile->objfile;
20690 struct comp_unit_head *cu_header = &cu->header;
20691
20692 /* NOTE drow/2003-01-30: There used to be a comment and some special
20693 code here to turn a symbol with DW_AT_external and a
20694 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20695 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20696 with some versions of binutils) where shared libraries could have
20697 relocations against symbols in their debug information - the
20698 minimal symbol would have the right address, but the debug info
20699 would not. It's no longer necessary, because we will explicitly
20700 apply relocations when we read in the debug information now. */
20701
20702 /* A DW_AT_location attribute with no contents indicates that a
20703 variable has been optimized away. */
20704 if (attr->form_is_block () && attr->as_block ()->size == 0)
20705 {
20707 return;
20708 }
20709
20710 /* Handle one degenerate form of location expression specially, to
20711 preserve GDB's previous behavior when section offsets are
20712 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20713 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20714
20715 if (attr->form_is_block ())
20716 {
20717 struct dwarf_block *block = attr->as_block ();
20718
20719 if ((block->data[0] == DW_OP_addr
20720 && block->size == 1 + cu_header->addr_size)
20721 || ((block->data[0] == DW_OP_GNU_addr_index
20722 || block->data[0] == DW_OP_addrx)
20723 && (block->size
20724 == 1 + leb128_size (&block->data[1]))))
20725 {
20726 unsigned int dummy;
20727
20728 if (block->data[0] == DW_OP_addr)
20730 (cu->header.read_address (objfile->obfd.get (), block->data + 1,
20731 &dummy));
20732 else
20734 (read_addr_index_from_leb128 (cu, block->data + 1, &dummy));
20738 (sym->value_address ()
20740 return;
20741 }
20742 }
20743
20744 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20745 expression evaluator, and use LOC_COMPUTED only when necessary
20746 (i.e. when the value of a register or memory location is
20747 referenced, or a thread-local block, etc.). Then again, it might
20748 not be worthwhile. I'm assuming that it isn't unless performance
20749 or memory numbers show me otherwise. */
20750
20751 dwarf2_symbol_mark_computed (attr, sym, cu, 0);
20752
20753 if (SYMBOL_COMPUTED_OPS (sym)->location_has_loclist)
20754 cu->has_loclist = true;
20755}
20756
20757/* Given a pointer to a DWARF information entry, figure out if we need
20758 to make a symbol table entry for it, and if so, create a new entry
20759 and return a pointer to it.
20760 If TYPE is NULL, determine symbol type from the die, otherwise
20761 used the passed type.
20762 If SPACE is not NULL, use it to hold the new symbol. If it is
20763 NULL, allocate a new symbol on the objfile's obstack. */
20764
20765static struct symbol *
20766new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
20767 struct symbol *space)
20768{
20769 dwarf2_per_objfile *per_objfile = cu->per_objfile;
20770 struct objfile *objfile = per_objfile->objfile;
20771 struct gdbarch *gdbarch = objfile->arch ();
20772 struct symbol *sym = NULL;
20773 const char *name;
20774 struct attribute *attr = NULL;
20775 struct attribute *attr2 = NULL;
20776 CORE_ADDR baseaddr;
20777 struct pending **list_to_add = NULL;
20778
20779 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
20780
20781 baseaddr = objfile->text_section_offset ();
20782
20783 name = dwarf2_name (die, cu);
20784 if (name == nullptr && (die->tag == DW_TAG_subprogram
20785 || die->tag == DW_TAG_inlined_subroutine
20786 || die->tag == DW_TAG_entry_point))
20787 name = dw2_linkage_name (die, cu);
20788
20789 if (name)
20790 {
20791 int suppress_add = 0;
20792
20793 if (space)
20794 sym = space;
20795 else
20796 sym = new (&objfile->objfile_obstack) symbol;
20797 OBJSTAT (objfile, n_syms++);
20798
20799 /* Cache this symbol's name and the name's demangled form (if any). */
20800 sym->set_language (cu->lang (), &objfile->objfile_obstack);
20801 /* Fortran does not have mangling standard and the mangling does differ
20802 between gfortran, iFort etc. */
20803 const char *physname
20804 = (cu->lang () == language_fortran
20805 ? dwarf2_full_name (name, die, cu)
20806 : dwarf2_physname (name, die, cu));
20807 const char *linkagename = dw2_linkage_name (die, cu);
20808
20809 if (linkagename == nullptr || cu->lang () == language_ada)
20810 sym->set_linkage_name (physname);
20811 else
20812 {
20813 sym->set_demangled_name (physname, &objfile->objfile_obstack);
20814 sym->set_linkage_name (linkagename);
20815 }
20816
20817 /* Handle DW_AT_artificial. */
20818 attr = dwarf2_attr (die, DW_AT_artificial, cu);
20819 if (attr != nullptr)
20820 sym->set_is_artificial (attr->as_boolean ());
20821
20822 /* Default assumptions.
20823 Use the passed type or decode it from the die. */
20824 sym->set_domain (VAR_DOMAIN);
20826 if (type != NULL)
20827 sym->set_type (type);
20828 else
20829 sym->set_type (die_type (die, cu));
20830 attr = dwarf2_attr (die,
20831 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
20832 cu);
20833 if (attr != nullptr)
20834 sym->set_line (attr->constant_value (0));
20835
20836 attr = dwarf2_attr (die,
20837 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
20838 cu);
20839 if (attr != nullptr && attr->is_nonnegative ())
20840 {
20841 file_name_index file_index
20842 = (file_name_index) attr->as_nonnegative ();
20843 struct file_entry *fe;
20844
20845 if (cu->line_header != NULL)
20846 fe = cu->line_header->file_name_at (file_index);
20847 else
20848 fe = NULL;
20849
20850 if (fe == NULL)
20851 complaint (_("file index out of range"));
20852 else
20853 sym->set_symtab (fe->symtab);
20854 }
20855
20856 switch (die->tag)
20857 {
20858 case DW_TAG_label:
20859 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
20860 if (attr != nullptr)
20861 {
20862 CORE_ADDR addr;
20863
20864 addr = attr->as_address ();
20865 addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr);
20866 sym->set_value_address (addr);
20868 }
20869 else
20871 sym->set_type (objfile_type (objfile)->builtin_core_addr);
20872 sym->set_domain (LABEL_DOMAIN);
20874 break;
20875 case DW_TAG_subprogram:
20876 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20877 finish_block. */
20879 attr2 = dwarf2_attr (die, DW_AT_external, cu);
20880 if ((attr2 != nullptr && attr2->as_boolean ())
20881 || cu->lang () == language_ada
20882 || cu->lang () == language_fortran)
20883 {
20884 /* Subprograms marked external are stored as a global symbol.
20885 Ada and Fortran subprograms, whether marked external or
20886 not, are always stored as a global symbol, because we want
20887 to be able to access them globally. For instance, we want
20888 to be able to break on a nested subprogram without having
20889 to specify the context. */
20890 list_to_add = cu->get_builder ()->get_global_symbols ();
20891 }
20892 else
20893 {
20894 list_to_add = cu->list_in_scope;
20895 }
20896 break;
20897 case DW_TAG_inlined_subroutine:
20898 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20899 finish_block. */
20901 sym->set_is_inlined (1);
20902 list_to_add = cu->list_in_scope;
20903 break;
20904 case DW_TAG_template_value_param:
20905 suppress_add = 1;
20906 /* Fall through. */
20907 case DW_TAG_constant:
20908 case DW_TAG_variable:
20909 case DW_TAG_member:
20910 /* Compilation with minimal debug info may result in
20911 variables with missing type entries. Change the
20912 misleading `void' type to something sensible. */
20913 if (sym->type ()->code () == TYPE_CODE_VOID)
20914 sym->set_type (objfile_type (objfile)->builtin_int);
20915
20916 attr = dwarf2_attr (die, DW_AT_const_value, cu);
20917 /* In the case of DW_TAG_member, we should only be called for
20918 static const members. */
20919 if (die->tag == DW_TAG_member)
20920 {
20921 /* dwarf2_add_field uses die_is_declaration,
20922 so we do the same. */
20923 gdb_assert (die_is_declaration (die, cu));
20924 gdb_assert (attr);
20925 }
20926 if (attr != nullptr)
20927 {
20928 dwarf2_const_value (attr, sym, cu);
20929 attr2 = dwarf2_attr (die, DW_AT_external, cu);
20930 if (!suppress_add)
20931 {
20932 if (attr2 != nullptr && attr2->as_boolean ())
20933 list_to_add = cu->get_builder ()->get_global_symbols ();
20934 else
20935 list_to_add = cu->list_in_scope;
20936 }
20937 break;
20938 }
20939 attr = dwarf2_attr (die, DW_AT_location, cu);
20940 if (attr != nullptr)
20941 {
20942 var_decode_location (attr, sym, cu);
20943 attr2 = dwarf2_attr (die, DW_AT_external, cu);
20944
20945 /* Fortran explicitly imports any global symbols to the local
20946 scope by DW_TAG_common_block. */
20947 if (cu->lang () == language_fortran && die->parent
20948 && die->parent->tag == DW_TAG_common_block)
20949 attr2 = NULL;
20950
20951 if (sym->aclass () == LOC_STATIC
20952 && sym->value_address () == 0
20953 && !per_objfile->per_bfd->has_section_at_zero)
20954 {
20955 /* When a static variable is eliminated by the linker,
20956 the corresponding debug information is not stripped
20957 out, but the variable address is set to null;
20958 do not add such variables into symbol table. */
20959 }
20960 else if (attr2 != nullptr && attr2->as_boolean ())
20961 {
20962 if (sym->aclass () == LOC_STATIC
20963 && (objfile->flags & OBJF_MAINLINE) == 0
20964 && per_objfile->per_bfd->can_copy)
20965 {
20966 /* A global static variable might be subject to
20967 copy relocation. We first check for a local
20968 minsym, though, because maybe the symbol was
20969 marked hidden, in which case this would not
20970 apply. */
20973 (sym->linkage_name (), objfile));
20974 if (found.minsym != nullptr)
20975 sym->maybe_copied = 1;
20976 }
20977
20978 /* A variable with DW_AT_external is never static,
20979 but it may be block-scoped. */
20980 list_to_add
20981 = ((cu->list_in_scope
20982 == cu->get_builder ()->get_file_symbols ())
20983 ? cu->get_builder ()->get_global_symbols ()
20984 : cu->list_in_scope);
20985 }
20986 else
20987 list_to_add = cu->list_in_scope;
20988 }
20989 else
20990 {
20991 /* We do not know the address of this symbol.
20992 If it is an external symbol and we have type information
20993 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20994 The address of the variable will then be determined from
20995 the minimal symbol table whenever the variable is
20996 referenced. */
20997 attr2 = dwarf2_attr (die, DW_AT_external, cu);
20998
20999 /* Fortran explicitly imports any global symbols to the local
21000 scope by DW_TAG_common_block. */
21001 if (cu->lang () == language_fortran && die->parent
21002 && die->parent->tag == DW_TAG_common_block)
21003 {
21004 /* SYMBOL_CLASS doesn't matter here because
21005 read_common_block is going to reset it. */
21006 if (!suppress_add)
21007 list_to_add = cu->list_in_scope;
21008 }
21009 else if (attr2 != nullptr && attr2->as_boolean ()
21010 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
21011 {
21012 /* A variable with DW_AT_external is never static, but it
21013 may be block-scoped. */
21014 list_to_add
21015 = ((cu->list_in_scope
21016 == cu->get_builder ()->get_file_symbols ())
21017 ? cu->get_builder ()->get_global_symbols ()
21018 : cu->list_in_scope);
21019
21021 }
21022 else if (!die_is_declaration (die, cu))
21023 {
21024 /* Use the default LOC_OPTIMIZED_OUT class. */
21025 gdb_assert (sym->aclass () == LOC_OPTIMIZED_OUT);
21026 if (!suppress_add)
21027 list_to_add = cu->list_in_scope;
21028 }
21029 }
21030 break;
21031 case DW_TAG_formal_parameter:
21032 {
21033 /* If we are inside a function, mark this as an argument. If
21034 not, we might be looking at an argument to an inlined function
21035 when we do not have enough information to show inlined frames;
21036 pretend it's a local variable in that case so that the user can
21037 still see it. */
21038 struct context_stack *curr
21040 if (curr != nullptr && curr->name != nullptr)
21041 sym->set_is_argument (1);
21042 attr = dwarf2_attr (die, DW_AT_location, cu);
21043 if (attr != nullptr)
21044 {
21045 var_decode_location (attr, sym, cu);
21046 }
21047 attr = dwarf2_attr (die, DW_AT_const_value, cu);
21048 if (attr != nullptr)
21049 {
21050 dwarf2_const_value (attr, sym, cu);
21051 }
21052
21053 list_to_add = cu->list_in_scope;
21054 }
21055 break;
21056 case DW_TAG_unspecified_parameters:
21057 /* From varargs functions; gdb doesn't seem to have any
21058 interest in this information, so just ignore it for now.
21059 (FIXME?) */
21060 break;
21061 case DW_TAG_template_type_param:
21062 suppress_add = 1;
21063 /* Fall through. */
21064 case DW_TAG_class_type:
21065 case DW_TAG_interface_type:
21066 case DW_TAG_structure_type:
21067 case DW_TAG_union_type:
21068 case DW_TAG_set_type:
21069 case DW_TAG_enumeration_type:
21070 case DW_TAG_namelist:
21071 if (die->tag == DW_TAG_namelist)
21072 {
21074 sym->set_domain (VAR_DOMAIN);
21075 }
21076 else
21077 {
21080 }
21081 {
21082 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21083 really ever be static objects: otherwise, if you try
21084 to, say, break of a class's method and you're in a file
21085 which doesn't mention that class, it won't work unless
21086 the check for all static symbols in lookup_symbol_aux
21087 saves you. See the OtherFileClass tests in
21088 gdb.c++/namespace.exp. */
21089
21090 if (!suppress_add)
21091 {
21092 buildsym_compunit *builder = cu->get_builder ();
21093 list_to_add
21094 = (cu->list_in_scope == builder->get_file_symbols ()
21095 && cu->lang () == language_cplus
21096 ? builder->get_global_symbols ()
21097 : cu->list_in_scope);
21098
21099 /* The semantics of C++ state that "struct foo {
21100 ... }" also defines a typedef for "foo". */
21101 if (cu->lang () == language_cplus
21102 || cu->lang () == language_ada
21103 || cu->lang () == language_d
21104 || cu->lang () == language_rust)
21105 {
21106 /* The symbol's name is already allocated along
21107 with this objfile, so we don't need to
21108 duplicate it for the type. */
21109 if (sym->type ()->name () == 0)
21110 sym->type ()->set_name (sym->search_name ());
21111 }
21112 }
21113 }
21114 break;
21115 case DW_TAG_typedef:
21117 sym->set_domain (VAR_DOMAIN);
21118 list_to_add = cu->list_in_scope;
21119 break;
21120 case DW_TAG_array_type:
21121 case DW_TAG_base_type:
21122 case DW_TAG_subrange_type:
21123 case DW_TAG_generic_subrange:
21124 case DW_TAG_unspecified_type:
21126 sym->set_domain (VAR_DOMAIN);
21127 list_to_add = cu->list_in_scope;
21128 break;
21129 case DW_TAG_enumerator:
21130 attr = dwarf2_attr (die, DW_AT_const_value, cu);
21131 if (attr != nullptr)
21132 {
21133 dwarf2_const_value (attr, sym, cu);
21134 }
21135 {
21136 /* NOTE: carlton/2003-11-10: See comment above in the
21137 DW_TAG_class_type, etc. block. */
21138
21139 list_to_add
21140 = (cu->list_in_scope == cu->get_builder ()->get_file_symbols ()
21141 && cu->lang () == language_cplus
21142 ? cu->get_builder ()->get_global_symbols ()
21143 : cu->list_in_scope);
21144 }
21145 break;
21146 case DW_TAG_imported_declaration:
21147 case DW_TAG_namespace:
21149 list_to_add = cu->get_builder ()->get_global_symbols ();
21150 break;
21151 case DW_TAG_module:
21154 list_to_add = cu->get_builder ()->get_global_symbols ();
21155 break;
21156 case DW_TAG_common_block:
21160 break;
21161 default:
21162 /* Not a tag we recognize. Hopefully we aren't processing
21163 trash data, but since we must specifically ignore things
21164 we don't recognize, there is nothing else we should do at
21165 this point. */
21166 complaint (_("unsupported tag: '%s'"),
21167 dwarf_tag_name (die->tag));
21168 break;
21169 }
21170
21171 if (suppress_add)
21172 {
21175 list_to_add = NULL;
21176 }
21177
21178 if (list_to_add != NULL)
21179 add_symbol_to_list (sym, list_to_add);
21180
21181 /* For the benefit of old versions of GCC, check for anonymous
21182 namespaces based on the demangled name. */
21184 && cu->lang () == language_cplus)
21186 }
21187 return (sym);
21188}
21189
21190/* Given an attr with a DW_FORM_dataN value in host byte order,
21191 zero-extend it as appropriate for the symbol's type. The DWARF
21192 standard (v4) is not entirely clear about the meaning of using
21193 DW_FORM_dataN for a constant with a signed type, where the type is
21194 wider than the data. The conclusion of a discussion on the DWARF
21195 list was that this is unspecified. We choose to always zero-extend
21196 because that is the interpretation long in use by GCC. */
21197
21198static gdb_byte *
21199dwarf2_const_value_data (const struct attribute *attr, struct obstack *obstack,
21200 struct dwarf2_cu *cu, LONGEST *value, int bits)
21201{
21202 struct objfile *objfile = cu->per_objfile->objfile;
21203 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd.get ()) ?
21204 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
21205 LONGEST l = attr->constant_value (0);
21206
21207 if (bits < sizeof (*value) * 8)
21208 {
21209 l &= ((LONGEST) 1 << bits) - 1;
21210 *value = l;
21211 }
21212 else if (bits == sizeof (*value) * 8)
21213 *value = l;
21214 else
21215 {
21216 gdb_byte *bytes = (gdb_byte *) obstack_alloc (obstack, bits / 8);
21217 store_unsigned_integer (bytes, bits / 8, byte_order, l);
21218 return bytes;
21219 }
21220
21221 return NULL;
21222}
21223
21224/* Read a constant value from an attribute. Either set *VALUE, or if
21225 the value does not fit in *VALUE, set *BYTES - either already
21226 allocated on the objfile obstack, or newly allocated on OBSTACK,
21227 or, set *BATON, if we translated the constant to a location
21228 expression. */
21229
21230static void
21231dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
21232 const char *name, struct obstack *obstack,
21233 struct dwarf2_cu *cu,
21234 LONGEST *value, const gdb_byte **bytes,
21235 struct dwarf2_locexpr_baton **baton)
21236{
21237 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21238 struct objfile *objfile = per_objfile->objfile;
21239 struct comp_unit_head *cu_header = &cu->header;
21240 struct dwarf_block *blk;
21241 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd.get ()) ?
21242 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
21243
21244 *value = 0;
21245 *bytes = NULL;
21246 *baton = NULL;
21247
21248 switch (attr->form)
21249 {
21250 case DW_FORM_addr:
21251 case DW_FORM_addrx:
21252 case DW_FORM_GNU_addr_index:
21253 {
21254 gdb_byte *data;
21255
21256 if (type->length () != cu_header->addr_size)
21258 cu_header->addr_size,
21259 type->length ());
21260 /* Symbols of this form are reasonably rare, so we just
21261 piggyback on the existing location code rather than writing
21262 a new implementation of symbol_computed_ops. */
21263 *baton = XOBNEW (obstack, struct dwarf2_locexpr_baton);
21264 (*baton)->per_objfile = per_objfile;
21265 (*baton)->per_cu = cu->per_cu;
21266 gdb_assert ((*baton)->per_cu);
21267
21268 (*baton)->size = 2 + cu_header->addr_size;
21269 data = (gdb_byte *) obstack_alloc (obstack, (*baton)->size);
21270 (*baton)->data = data;
21271
21272 data[0] = DW_OP_addr;
21273 store_unsigned_integer (&data[1], cu_header->addr_size,
21274 byte_order, attr->as_address ());
21275 data[cu_header->addr_size + 1] = DW_OP_stack_value;
21276 }
21277 break;
21278 case DW_FORM_string:
21279 case DW_FORM_strp:
21280 case DW_FORM_strx:
21281 case DW_FORM_GNU_str_index:
21282 case DW_FORM_GNU_strp_alt:
21283 /* The string is already allocated on the objfile obstack, point
21284 directly to it. */
21285 *bytes = (const gdb_byte *) attr->as_string ();
21286 break;
21287 case DW_FORM_block1:
21288 case DW_FORM_block2:
21289 case DW_FORM_block4:
21290 case DW_FORM_block:
21291 case DW_FORM_exprloc:
21292 case DW_FORM_data16:
21293 blk = attr->as_block ();
21294 if (type->length () != blk->size)
21296 type->length ());
21297 *bytes = blk->data;
21298 break;
21299
21300 /* The DW_AT_const_value attributes are supposed to carry the
21301 symbol's value "represented as it would be on the target
21302 architecture." By the time we get here, it's already been
21303 converted to host endianness, so we just need to sign- or
21304 zero-extend it as appropriate. */
21305 case DW_FORM_data1:
21306 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 8);
21307 break;
21308 case DW_FORM_data2:
21309 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 16);
21310 break;
21311 case DW_FORM_data4:
21312 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 32);
21313 break;
21314 case DW_FORM_data8:
21315 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 64);
21316 break;
21317
21318 case DW_FORM_sdata:
21319 case DW_FORM_implicit_const:
21320 *value = attr->as_signed ();
21321 break;
21322
21323 case DW_FORM_udata:
21324 *value = attr->as_unsigned ();
21325 break;
21326
21327 default:
21328 complaint (_("unsupported const value attribute form: '%s'"),
21329 dwarf_form_name (attr->form));
21330 *value = 0;
21331 break;
21332 }
21333}
21334
21335
21336/* Copy constant value from an attribute to a symbol. */
21337
21338static void
21339dwarf2_const_value (const struct attribute *attr, struct symbol *sym,
21340 struct dwarf2_cu *cu)
21341{
21342 struct objfile *objfile = cu->per_objfile->objfile;
21343 LONGEST value;
21344 const gdb_byte *bytes;
21345 struct dwarf2_locexpr_baton *baton;
21346
21347 dwarf2_const_value_attr (attr, sym->type (),
21348 sym->print_name (),
21350 &value, &bytes, &baton);
21351
21352 if (baton != NULL)
21353 {
21354 SYMBOL_LOCATION_BATON (sym) = baton;
21356 }
21357 else if (bytes != NULL)
21358 {
21359 sym->set_value_bytes (bytes);
21361 }
21362 else
21363 {
21364 sym->set_value_longest (value);
21366 }
21367}
21368
21369/* Return the type of the die in question using its DW_AT_type attribute. */
21370
21371static struct type *
21372die_type (struct die_info *die, struct dwarf2_cu *cu)
21373{
21374 struct attribute *type_attr;
21375
21376 type_attr = dwarf2_attr (die, DW_AT_type, cu);
21377 if (!type_attr)
21378 {
21379 struct objfile *objfile = cu->per_objfile->objfile;
21380 /* A missing DW_AT_type represents a void type. */
21382 }
21383
21384 return lookup_die_type (die, type_attr, cu);
21385}
21386
21387/* True iff CU's producer generates GNAT Ada auxiliary information
21388 that allows to find parallel types through that information instead
21389 of having to do expensive parallel lookups by type name. */
21390
21391static int
21393{
21394 /* Assume that the Ada compiler was GNAT, which always produces
21395 the auxiliary information. */
21396 return (cu->lang () == language_ada);
21397}
21398
21399/* Return the auxiliary type of the die in question using its
21400 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21401 attribute is not present. */
21402
21403static struct type *
21404die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
21405{
21406 struct attribute *type_attr;
21407
21408 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
21409 if (!type_attr)
21410 return NULL;
21411
21412 return lookup_die_type (die, type_attr, cu);
21413}
21414
21415/* If DIE has a descriptive_type attribute, then set the TYPE's
21416 descriptive type accordingly. */
21417
21418static void
21420 struct dwarf2_cu *cu)
21421{
21422 struct type *descriptive_type = die_descriptive_type (die, cu);
21423
21424 if (descriptive_type)
21425 {
21427 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
21428 }
21429}
21430
21431/* Return the containing type of the die in question using its
21432 DW_AT_containing_type attribute. */
21433
21434static struct type *
21435die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
21436{
21437 struct attribute *type_attr;
21438 struct objfile *objfile = cu->per_objfile->objfile;
21439
21440 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
21441 if (!type_attr)
21442 error (_("Dwarf Error: Problem turning containing type into gdb type "
21443 "[in module %s]"), objfile_name (objfile));
21444
21445 return lookup_die_type (die, type_attr, cu);
21446}
21447
21448/* Return an error marker type to use for the ill formed type in DIE/CU. */
21449
21450static struct type *
21452{
21453 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21454 struct objfile *objfile = per_objfile->objfile;
21455 char *saved;
21456
21457 std::string message
21458 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21460 sect_offset_str (cu->header.sect_off),
21461 sect_offset_str (die->sect_off));
21462 saved = obstack_strdup (&objfile->objfile_obstack, message);
21463
21464 return init_type (objfile, TYPE_CODE_ERROR, 0, saved);
21465}
21466
21467/* Look up the type of DIE in CU using its type attribute ATTR.
21468 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21469 DW_AT_containing_type.
21470 If there is no type substitute an error marker. */
21471
21472static struct type *
21473lookup_die_type (struct die_info *die, const struct attribute *attr,
21474 struct dwarf2_cu *cu)
21475{
21476 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21477 struct objfile *objfile = per_objfile->objfile;
21478 struct type *this_type;
21479
21480 gdb_assert (attr->name == DW_AT_type
21481 || attr->name == DW_AT_GNAT_descriptive_type
21482 || attr->name == DW_AT_containing_type);
21483
21484 /* First see if we have it cached. */
21485
21486 if (attr->form == DW_FORM_GNU_ref_alt)
21487 {
21488 struct dwarf2_per_cu_data *per_cu;
21489 sect_offset sect_off = attr->get_ref_die_offset ();
21490
21492 per_objfile->per_bfd);
21493 this_type = get_die_type_at_offset (sect_off, per_cu, per_objfile);
21494 }
21495 else if (attr->form_is_ref ())
21496 {
21497 sect_offset sect_off = attr->get_ref_die_offset ();
21498
21499 this_type = get_die_type_at_offset (sect_off, cu->per_cu, per_objfile);
21500 }
21501 else if (attr->form == DW_FORM_ref_sig8)
21502 {
21503 ULONGEST signature = attr->as_signature ();
21504
21505 return get_signatured_type (die, signature, cu);
21506 }
21507 else
21508 {
21509 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21510 " at %s [in module %s]"),
21513 return build_error_marker_type (cu, die);
21514 }
21515
21516 /* If not cached we need to read it in. */
21517
21518 if (this_type == NULL)
21519 {
21520 struct die_info *type_die = NULL;
21521 struct dwarf2_cu *type_cu = cu;
21522
21523 if (attr->form_is_ref ())
21524 type_die = follow_die_ref (die, attr, &type_cu);
21525 if (type_die == NULL)
21526 return build_error_marker_type (cu, die);
21527 /* If we find the type now, it's probably because the type came
21528 from an inter-CU reference and the type's CU got expanded before
21529 ours. */
21530 this_type = read_type_die (type_die, type_cu);
21531 }
21532
21533 /* If we still don't have a type use an error marker. */
21534
21535 if (this_type == NULL)
21536 return build_error_marker_type (cu, die);
21537
21538 return this_type;
21539}
21540
21541/* Return the type in DIE, CU.
21542 Returns NULL for invalid types.
21543
21544 This first does a lookup in die_type_hash,
21545 and only reads the die in if necessary.
21546
21547 NOTE: This can be called when reading in partial or full symbols. */
21548
21549static struct type *
21550read_type_die (struct die_info *die, struct dwarf2_cu *cu)
21551{
21552 struct type *this_type;
21553
21554 this_type = get_die_type (die, cu);
21555 if (this_type)
21556 return this_type;
21557
21558 return read_type_die_1 (die, cu);
21559}
21560
21561/* Read the type in DIE, CU.
21562 Returns NULL for invalid types. */
21563
21564static struct type *
21565read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
21566{
21567 struct type *this_type = NULL;
21568
21569 switch (die->tag)
21570 {
21571 case DW_TAG_class_type:
21572 case DW_TAG_interface_type:
21573 case DW_TAG_structure_type:
21574 case DW_TAG_union_type:
21575 this_type = read_structure_type (die, cu);
21576 break;
21577 case DW_TAG_enumeration_type:
21578 this_type = read_enumeration_type (die, cu);
21579 break;
21580 case DW_TAG_subprogram:
21581 case DW_TAG_subroutine_type:
21582 case DW_TAG_inlined_subroutine:
21583 this_type = read_subroutine_type (die, cu);
21584 break;
21585 case DW_TAG_array_type:
21586 this_type = read_array_type (die, cu);
21587 break;
21588 case DW_TAG_set_type:
21589 this_type = read_set_type (die, cu);
21590 break;
21591 case DW_TAG_pointer_type:
21592 this_type = read_tag_pointer_type (die, cu);
21593 break;
21594 case DW_TAG_ptr_to_member_type:
21595 this_type = read_tag_ptr_to_member_type (die, cu);
21596 break;
21597 case DW_TAG_reference_type:
21598 this_type = read_tag_reference_type (die, cu, TYPE_CODE_REF);
21599 break;
21600 case DW_TAG_rvalue_reference_type:
21601 this_type = read_tag_reference_type (die, cu, TYPE_CODE_RVALUE_REF);
21602 break;
21603 case DW_TAG_const_type:
21604 this_type = read_tag_const_type (die, cu);
21605 break;
21606 case DW_TAG_volatile_type:
21607 this_type = read_tag_volatile_type (die, cu);
21608 break;
21609 case DW_TAG_restrict_type:
21610 this_type = read_tag_restrict_type (die, cu);
21611 break;
21612 case DW_TAG_string_type:
21613 this_type = read_tag_string_type (die, cu);
21614 break;
21615 case DW_TAG_typedef:
21616 this_type = read_typedef (die, cu);
21617 break;
21618 case DW_TAG_generic_subrange:
21619 case DW_TAG_subrange_type:
21620 this_type = read_subrange_type (die, cu);
21621 break;
21622 case DW_TAG_base_type:
21623 this_type = read_base_type (die, cu);
21624 break;
21625 case DW_TAG_unspecified_type:
21626 this_type = read_unspecified_type (die, cu);
21627 break;
21628 case DW_TAG_namespace:
21629 this_type = read_namespace_type (die, cu);
21630 break;
21631 case DW_TAG_module:
21632 this_type = read_module_type (die, cu);
21633 break;
21634 case DW_TAG_atomic_type:
21635 this_type = read_tag_atomic_type (die, cu);
21636 break;
21637 default:
21638 complaint (_("unexpected tag in read_type_die: '%s'"),
21639 dwarf_tag_name (die->tag));
21640 break;
21641 }
21642
21643 return this_type;
21644}
21645
21646/* See if we can figure out if the class lives in a namespace. We do
21647 this by looking for a member function; its demangled name will
21648 contain namespace info, if there is any.
21649 Return the computed name or NULL.
21650 Space for the result is allocated on the objfile's obstack.
21651 This is the full-die version of guess_partial_die_structure_name.
21652 In this case we know DIE has no useful parent. */
21653
21654static const char *
21656{
21657 struct die_info *spec_die;
21658 struct dwarf2_cu *spec_cu;
21659 struct die_info *child;
21660 struct objfile *objfile = cu->per_objfile->objfile;
21661
21662 spec_cu = cu;
21663 spec_die = die_specification (die, &spec_cu);
21664 if (spec_die != NULL)
21665 {
21666 die = spec_die;
21667 cu = spec_cu;
21668 }
21669
21670 for (child = die->child;
21671 child != NULL;
21672 child = child->sibling)
21673 {
21674 if (child->tag == DW_TAG_subprogram)
21675 {
21676 const char *linkage_name = dw2_linkage_name (child, cu);
21677
21678 if (linkage_name != NULL)
21679 {
21680 gdb::unique_xmalloc_ptr<char> actual_name
21681 (cu->language_defn->class_name_from_physname (linkage_name));
21682 const char *name = NULL;
21683
21684 if (actual_name != NULL)
21685 {
21686 const char *die_name = dwarf2_name (die, cu);
21687
21688 if (die_name != NULL
21689 && strcmp (die_name, actual_name.get ()) != 0)
21690 {
21691 /* Strip off the class name from the full name.
21692 We want the prefix. */
21693 int die_name_len = strlen (die_name);
21694 int actual_name_len = strlen (actual_name.get ());
21695 const char *ptr = actual_name.get ();
21696
21697 /* Test for '::' as a sanity check. */
21698 if (actual_name_len > die_name_len + 2
21699 && ptr[actual_name_len - die_name_len - 1] == ':')
21700 name = obstack_strndup (
21702 ptr, actual_name_len - die_name_len - 2);
21703 }
21704 }
21705 return name;
21706 }
21707 }
21708 }
21709
21710 return NULL;
21711}
21712
21713/* GCC might emit a nameless typedef that has a linkage name. Determine the
21714 prefix part in such case. See
21715 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21716
21717static const char *
21719{
21720 struct attribute *attr;
21721 const char *base;
21722
21723 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
21724 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
21725 return NULL;
21726
21727 if (dwarf2_string_attr (die, DW_AT_name, cu) != NULL)
21728 return NULL;
21729
21730 attr = dw2_linkage_name_attr (die, cu);
21731 const char *attr_name = attr->as_string ();
21732 if (attr == NULL || attr_name == NULL)
21733 return NULL;
21734
21735 /* dwarf2_name had to be already called. */
21736 gdb_assert (attr->canonical_string_p ());
21737
21738 /* Strip the base name, keep any leading namespaces/classes. */
21739 base = strrchr (attr_name, ':');
21740 if (base == NULL || base == attr_name || base[-1] != ':')
21741 return "";
21742
21743 struct objfile *objfile = cu->per_objfile->objfile;
21744 return obstack_strndup (&objfile->per_bfd->storage_obstack,
21745 attr_name,
21746 &base[-1] - attr_name);
21747}
21748
21749/* Return the name of the namespace/class that DIE is defined within,
21750 or "" if we can't tell. The caller should not xfree the result.
21751
21752 For example, if we're within the method foo() in the following
21753 code:
21754
21755 namespace N {
21756 class C {
21757 void foo () {
21758 }
21759 };
21760 }
21761
21762 then determine_prefix on foo's die will return "N::C". */
21763
21764static const char *
21765determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
21766{
21767 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21768 struct die_info *parent, *spec_die;
21769 struct dwarf2_cu *spec_cu;
21770 struct type *parent_type;
21771 const char *retval;
21772
21773 if (cu->lang () != language_cplus
21774 && cu->lang () != language_fortran
21775 && cu->lang () != language_d
21776 && cu->lang () != language_rust)
21777 return "";
21778
21779 retval = anonymous_struct_prefix (die, cu);
21780 if (retval)
21781 return retval;
21782
21783 /* We have to be careful in the presence of DW_AT_specification.
21784 For example, with GCC 3.4, given the code
21785
21786 namespace N {
21787 void foo() {
21788 // Definition of N::foo.
21789 }
21790 }
21791
21792 then we'll have a tree of DIEs like this:
21793
21794 1: DW_TAG_compile_unit
21795 2: DW_TAG_namespace // N
21796 3: DW_TAG_subprogram // declaration of N::foo
21797 4: DW_TAG_subprogram // definition of N::foo
21798 DW_AT_specification // refers to die #3
21799
21800 Thus, when processing die #4, we have to pretend that we're in
21801 the context of its DW_AT_specification, namely the contex of die
21802 #3. */
21803 spec_cu = cu;
21804 spec_die = die_specification (die, &spec_cu);
21805 if (spec_die == NULL)
21806 parent = die->parent;
21807 else
21808 {
21809 parent = spec_die->parent;
21810 cu = spec_cu;
21811 }
21812
21813 if (parent == NULL)
21814 return "";
21815 else if (parent->building_fullname)
21816 {
21817 const char *name;
21818 const char *parent_name;
21819
21820 /* It has been seen on RealView 2.2 built binaries,
21821 DW_TAG_template_type_param types actually _defined_ as
21822 children of the parent class:
21823
21824 enum E {};
21825 template class <class Enum> Class{};
21826 Class<enum E> class_e;
21827
21828 1: DW_TAG_class_type (Class)
21829 2: DW_TAG_enumeration_type (E)
21830 3: DW_TAG_enumerator (enum1:0)
21831 3: DW_TAG_enumerator (enum2:1)
21832 ...
21833 2: DW_TAG_template_type_param
21834 DW_AT_type DW_FORM_ref_udata (E)
21835
21836 Besides being broken debug info, it can put GDB into an
21837 infinite loop. Consider:
21838
21839 When we're building the full name for Class<E>, we'll start
21840 at Class, and go look over its template type parameters,
21841 finding E. We'll then try to build the full name of E, and
21842 reach here. We're now trying to build the full name of E,
21843 and look over the parent DIE for containing scope. In the
21844 broken case, if we followed the parent DIE of E, we'd again
21845 find Class, and once again go look at its template type
21846 arguments, etc., etc. Simply don't consider such parent die
21847 as source-level parent of this die (it can't be, the language
21848 doesn't allow it), and break the loop here. */
21849 name = dwarf2_name (die, cu);
21850 parent_name = dwarf2_name (parent, cu);
21851 complaint (_("template param type '%s' defined within parent '%s'"),
21852 name ? name : "<unknown>",
21853 parent_name ? parent_name : "<unknown>");
21854 return "";
21855 }
21856 else
21857 switch (parent->tag)
21858 {
21859 case DW_TAG_namespace:
21860 parent_type = read_type_die (parent, cu);
21861 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21862 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21863 Work around this problem here. */
21864 if (cu->lang () == language_cplus
21865 && strcmp (parent_type->name (), "::") == 0)
21866 return "";
21867 /* We give a name to even anonymous namespaces. */
21868 return parent_type->name ();
21869 case DW_TAG_class_type:
21870 case DW_TAG_interface_type:
21871 case DW_TAG_structure_type:
21872 case DW_TAG_union_type:
21873 case DW_TAG_module:
21874 parent_type = read_type_die (parent, cu);
21875 if (parent_type->name () != NULL)
21876 return parent_type->name ();
21877 else
21878 /* An anonymous structure is only allowed non-static data
21879 members; no typedefs, no member functions, et cetera.
21880 So it does not need a prefix. */
21881 return "";
21882 case DW_TAG_compile_unit:
21883 case DW_TAG_partial_unit:
21884 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21885 if (cu->lang () == language_cplus
21886 && !per_objfile->per_bfd->types.empty ()
21887 && die->child != NULL
21888 && (die->tag == DW_TAG_class_type
21889 || die->tag == DW_TAG_structure_type
21890 || die->tag == DW_TAG_union_type))
21891 {
21892 const char *name = guess_full_die_structure_name (die, cu);
21893 if (name != NULL)
21894 return name;
21895 }
21896 return "";
21897 case DW_TAG_subprogram:
21898 /* Nested subroutines in Fortran get a prefix with the name
21899 of the parent's subroutine. */
21900 if (cu->lang () == language_fortran)
21901 {
21902 if ((die->tag == DW_TAG_subprogram)
21903 && (dwarf2_name (parent, cu) != NULL))
21904 return dwarf2_name (parent, cu);
21905 }
21906 return "";
21907 case DW_TAG_enumeration_type:
21908 parent_type = read_type_die (parent, cu);
21909 if (parent_type->is_declared_class ())
21910 {
21911 if (parent_type->name () != NULL)
21912 return parent_type->name ();
21913 return "";
21914 }
21915 /* Fall through. */
21916 default:
21917 return determine_prefix (parent, cu);
21918 }
21919}
21920
21921/* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21922 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21923 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21924 an obconcat, otherwise allocate storage for the result. The CU argument is
21925 used to determine the language and hence, the appropriate separator. */
21926
21927#define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21928
21929static char *
21930typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
21931 int physname, struct dwarf2_cu *cu)
21932{
21933 const char *lead = "";
21934 const char *sep;
21935
21936 if (suffix == NULL || suffix[0] == '\0'
21937 || prefix == NULL || prefix[0] == '\0')
21938 sep = "";
21939 else if (cu->lang () == language_d)
21940 {
21941 /* For D, the 'main' function could be defined in any module, but it
21942 should never be prefixed. */
21943 if (strcmp (suffix, "D main") == 0)
21944 {
21945 prefix = "";
21946 sep = "";
21947 }
21948 else
21949 sep = ".";
21950 }
21951 else if (cu->lang () == language_fortran && physname)
21952 {
21953 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21954 DW_AT_MIPS_linkage_name is preferred and used instead. */
21955
21956 lead = "__";
21957 sep = "_MOD_";
21958 }
21959 else
21960 sep = "::";
21961
21962 if (prefix == NULL)
21963 prefix = "";
21964 if (suffix == NULL)
21965 suffix = "";
21966
21967 if (obs == NULL)
21968 {
21969 char *retval
21970 = ((char *)
21971 xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1));
21972
21973 strcpy (retval, lead);
21974 strcat (retval, prefix);
21975 strcat (retval, sep);
21976 strcat (retval, suffix);
21977 return retval;
21978 }
21979 else
21980 {
21981 /* We have an obstack. */
21982 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
21983 }
21984}
21985
21986/* Return a generic name for a DW_TAG_template_type_param or
21987 DW_TAG_template_value_param tag, missing a DW_AT_name attribute. We do this
21988 per parent, so each function/class/struct template will have their own set
21989 of template parameters named <unnnamed0>, <unnamed1>, ... where the
21990 enumeration starts at 0 and represents the position of the template tag in
21991 the list of unnamed template tags for this parent, counting both, type and
21992 value tags. */
21993
21994static const char *
21996{
21997 if (die->parent == nullptr)
21998 return nullptr;
21999
22000 /* Count the parent types unnamed template type and value children until, we
22001 arrive at our entry. */
22002 size_t nth_unnamed = 0;
22003
22004 die_info *child = die->parent->child;
22005 while (child != die)
22006 {
22007 gdb_assert (child != nullptr);
22008 if (child->tag == DW_TAG_template_type_param
22009 || child->tag == DW_TAG_template_value_param)
22010 {
22011 if (dwarf2_attr (child, DW_AT_name, cu) == nullptr)
22012 ++nth_unnamed;
22013 }
22014 child = child->sibling;
22015 }
22016
22017 const std::string name_str = "<unnamed" + std::to_string (nth_unnamed) + ">";
22018 return cu->per_objfile->objfile->intern (name_str.c_str ());
22019}
22020
22021/* Get name of a die, return NULL if not found. */
22022
22023static const char *
22024dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu,
22025 struct objfile *objfile)
22026{
22027 if (name == nullptr)
22028 return name;
22029
22030 if (cu->lang () == language_cplus)
22031 {
22032 gdb::unique_xmalloc_ptr<char> canon_name
22034
22035 if (canon_name != nullptr)
22036 name = objfile->intern (canon_name.get ());
22037 }
22038 else if (cu->lang () == language_c)
22039 {
22040 gdb::unique_xmalloc_ptr<char> canon_name
22042
22043 if (canon_name != nullptr)
22044 name = objfile->intern (canon_name.get ());
22045 }
22046
22047 return name;
22048}
22049
22050/* Get name of a die, return NULL if not found.
22051 Anonymous namespaces are converted to their magic string. */
22052
22053static const char *
22054dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
22055{
22056 struct attribute *attr;
22057 struct objfile *objfile = cu->per_objfile->objfile;
22058
22059 attr = dwarf2_attr (die, DW_AT_name, cu);
22060 const char *attr_name = attr == nullptr ? nullptr : attr->as_string ();
22061 if (attr_name == nullptr
22062 && die->tag != DW_TAG_namespace
22063 && die->tag != DW_TAG_class_type
22064 && die->tag != DW_TAG_interface_type
22065 && die->tag != DW_TAG_structure_type
22066 && die->tag != DW_TAG_namelist
22067 && die->tag != DW_TAG_union_type
22068 && die->tag != DW_TAG_template_type_param
22069 && die->tag != DW_TAG_template_value_param)
22070 return NULL;
22071
22072 switch (die->tag)
22073 {
22074 /* A member's name should not be canonicalized. This is a bit
22075 of a hack, in that normally it should not be possible to run
22076 into this situation; however, the dw2-unusual-field-names.exp
22077 test creates custom DWARF that does. */
22078 case DW_TAG_member:
22079 case DW_TAG_compile_unit:
22080 case DW_TAG_partial_unit:
22081 /* Compilation units have a DW_AT_name that is a filename, not
22082 a source language identifier. */
22083 case DW_TAG_enumeration_type:
22084 case DW_TAG_enumerator:
22085 /* These tags always have simple identifiers already; no need
22086 to canonicalize them. */
22087 return attr_name;
22088
22089 case DW_TAG_namespace:
22090 if (attr_name != nullptr)
22091 return attr_name;
22093
22094 /* DWARF does not actually require template tags to have a name. */
22095 case DW_TAG_template_type_param:
22096 case DW_TAG_template_value_param:
22097 if (attr_name == nullptr)
22098 return unnamed_template_tag_name (die, cu);
22099 /* FALLTHROUGH. */
22100 case DW_TAG_class_type:
22101 case DW_TAG_interface_type:
22102 case DW_TAG_structure_type:
22103 case DW_TAG_union_type:
22104 case DW_TAG_namelist:
22105 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22106 structures or unions. These were of the form "._%d" in GCC 4.1,
22107 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22108 and GCC 4.4. We work around this problem by ignoring these. */
22109 if (attr_name != nullptr
22110 && (startswith (attr_name, "._")
22111 || startswith (attr_name, "<anonymous")))
22112 return NULL;
22113
22114 /* GCC might emit a nameless typedef that has a linkage name. See
22115 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22116 if (!attr || attr_name == NULL)
22117 {
22118 attr = dw2_linkage_name_attr (die, cu);
22119 attr_name = attr == nullptr ? nullptr : attr->as_string ();
22120 if (attr == NULL || attr_name == NULL)
22121 return NULL;
22122
22123 /* Avoid demangling attr_name the second time on a second
22124 call for the same DIE. */
22125 if (!attr->canonical_string_p ())
22126 {
22127 gdb::unique_xmalloc_ptr<char> demangled
22128 (gdb_demangle (attr_name, DMGL_TYPES));
22129 if (demangled == nullptr)
22130 return nullptr;
22131
22132 attr->set_string_canonical (objfile->intern (demangled.get ()));
22133 attr_name = attr->as_string ();
22134 }
22135
22136 /* Strip any leading namespaces/classes, keep only the
22137 base name. DW_AT_name for named DIEs does not
22138 contain the prefixes. */
22139 const char *base = strrchr (attr_name, ':');
22140 if (base && base > attr_name && base[-1] == ':')
22141 return &base[1];
22142 else
22143 return attr_name;
22144 }
22145 break;
22146
22147 default:
22148 break;
22149 }
22150
22151 if (!attr->canonical_string_p ())
22152 attr->set_string_canonical (dwarf2_canonicalize_name (attr_name, cu,
22153 objfile));
22154 return attr->as_string ();
22155}
22156
22157/* Return the die that this die in an extension of, or NULL if there
22158 is none. *EXT_CU is the CU containing DIE on input, and the CU
22159 containing the return value on output. */
22160
22161static struct die_info *
22162dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
22163{
22164 struct attribute *attr;
22165
22166 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
22167 if (attr == NULL)
22168 return NULL;
22169
22170 return follow_die_ref (die, attr, ext_cu);
22171}
22172
22173static void
22174dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
22175{
22176 unsigned int i;
22177
22178 gdb_printf (f, "%*sDie: %s (abbrev %d, offset %s)\n",
22179 indent, "",
22180 dwarf_tag_name (die->tag), die->abbrev,
22181 sect_offset_str (die->sect_off));
22182
22183 if (die->parent != NULL)
22184 gdb_printf (f, "%*s parent at offset: %s\n",
22185 indent, "",
22187
22188 gdb_printf (f, "%*s has children: %s\n",
22189 indent, "",
22190 dwarf_bool_name (die->child != NULL));
22191
22192 gdb_printf (f, "%*s attributes:\n", indent, "");
22193
22194 for (i = 0; i < die->num_attrs; ++i)
22195 {
22196 gdb_printf (f, "%*s %s (%s) ",
22197 indent, "",
22198 dwarf_attr_name (die->attrs[i].name),
22199 dwarf_form_name (die->attrs[i].form));
22200
22201 switch (die->attrs[i].form)
22202 {
22203 case DW_FORM_addr:
22204 case DW_FORM_addrx:
22205 case DW_FORM_GNU_addr_index:
22206 gdb_printf (f, "address: ");
22207 gdb_puts (hex_string (die->attrs[i].as_address ()), f);
22208 break;
22209 case DW_FORM_block2:
22210 case DW_FORM_block4:
22211 case DW_FORM_block:
22212 case DW_FORM_block1:
22213 gdb_printf (f, "block: size %s",
22214 pulongest (die->attrs[i].as_block ()->size));
22215 break;
22216 case DW_FORM_exprloc:
22217 gdb_printf (f, "expression: size %s",
22218 pulongest (die->attrs[i].as_block ()->size));
22219 break;
22220 case DW_FORM_data16:
22221 gdb_printf (f, "constant of 16 bytes");
22222 break;
22223 case DW_FORM_ref_addr:
22224 gdb_printf (f, "ref address: ");
22225 gdb_puts (hex_string (die->attrs[i].as_unsigned ()), f);
22226 break;
22227 case DW_FORM_GNU_ref_alt:
22228 gdb_printf (f, "alt ref address: ");
22229 gdb_puts (hex_string (die->attrs[i].as_unsigned ()), f);
22230 break;
22231 case DW_FORM_ref1:
22232 case DW_FORM_ref2:
22233 case DW_FORM_ref4:
22234 case DW_FORM_ref8:
22235 case DW_FORM_ref_udata:
22236 gdb_printf (f, "constant ref: 0x%lx (adjusted)",
22237 (long) (die->attrs[i].as_unsigned ()));
22238 break;
22239 case DW_FORM_data1:
22240 case DW_FORM_data2:
22241 case DW_FORM_data4:
22242 case DW_FORM_data8:
22243 case DW_FORM_udata:
22244 gdb_printf (f, "constant: %s",
22245 pulongest (die->attrs[i].as_unsigned ()));
22246 break;
22247 case DW_FORM_sec_offset:
22248 gdb_printf (f, "section offset: %s",
22249 pulongest (die->attrs[i].as_unsigned ()));
22250 break;
22251 case DW_FORM_ref_sig8:
22252 gdb_printf (f, "signature: %s",
22253 hex_string (die->attrs[i].as_signature ()));
22254 break;
22255 case DW_FORM_string:
22256 case DW_FORM_strp:
22257 case DW_FORM_line_strp:
22258 case DW_FORM_strx:
22259 case DW_FORM_GNU_str_index:
22260 case DW_FORM_GNU_strp_alt:
22261 gdb_printf (f, "string: \"%s\" (%s canonicalized)",
22262 die->attrs[i].as_string ()
22263 ? die->attrs[i].as_string () : "",
22264 die->attrs[i].canonical_string_p () ? "is" : "not");
22265 break;
22266 case DW_FORM_flag:
22267 if (die->attrs[i].as_boolean ())
22268 gdb_printf (f, "flag: TRUE");
22269 else
22270 gdb_printf (f, "flag: FALSE");
22271 break;
22272 case DW_FORM_flag_present:
22273 gdb_printf (f, "flag: TRUE");
22274 break;
22275 case DW_FORM_indirect:
22276 /* The reader will have reduced the indirect form to
22277 the "base form" so this form should not occur. */
22278 gdb_printf (f,
22279 "unexpected attribute form: DW_FORM_indirect");
22280 break;
22281 case DW_FORM_sdata:
22282 case DW_FORM_implicit_const:
22283 gdb_printf (f, "constant: %s",
22284 plongest (die->attrs[i].as_signed ()));
22285 break;
22286 default:
22287 gdb_printf (f, "unsupported attribute form: %d.",
22288 die->attrs[i].form);
22289 break;
22290 }
22291 gdb_printf (f, "\n");
22292 }
22293}
22294
22295static void
22297{
22298 dump_die_shallow (gdb_stderr, 0, die);
22299}
22300
22301static void
22302dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
22303{
22304 int indent = level * 4;
22305
22306 gdb_assert (die != NULL);
22307
22308 if (level >= max_level)
22309 return;
22310
22311 dump_die_shallow (f, indent, die);
22312
22313 if (die->child != NULL)
22314 {
22315 gdb_printf (f, "%*s Children:", indent, "");
22316 if (level + 1 < max_level)
22317 {
22318 gdb_printf (f, "\n");
22319 dump_die_1 (f, level + 1, max_level, die->child);
22320 }
22321 else
22322 {
22323 gdb_printf (f,
22324 " [not printed, max nesting level reached]\n");
22325 }
22326 }
22327
22328 if (die->sibling != NULL && level > 0)
22329 {
22330 dump_die_1 (f, level, max_level, die->sibling);
22331 }
22332}
22333
22334/* This is called from the pdie macro in gdbinit.in.
22335 It's not static so gcc will keep a copy callable from gdb. */
22336
22337void
22338dump_die (struct die_info *die, int max_level)
22339{
22340 dump_die_1 (gdb_stdlog, 0, max_level, die);
22341}
22342
22343static void
22344store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
22345{
22346 void **slot;
22347
22348 slot = htab_find_slot_with_hash (cu->die_hash, die,
22349 to_underlying (die->sect_off),
22350 INSERT);
22351
22352 *slot = die;
22353}
22354
22355/* Follow reference or signature attribute ATTR of SRC_DIE.
22356 On entry *REF_CU is the CU of SRC_DIE.
22357 On exit *REF_CU is the CU of the result. */
22358
22359static struct die_info *
22360follow_die_ref_or_sig (struct die_info *src_die, const struct attribute *attr,
22361 struct dwarf2_cu **ref_cu)
22362{
22363 struct die_info *die;
22364
22365 if (attr->form_is_ref ())
22366 die = follow_die_ref (src_die, attr, ref_cu);
22367 else if (attr->form == DW_FORM_ref_sig8)
22368 die = follow_die_sig (src_die, attr, ref_cu);
22369 else
22370 {
22371 dump_die_for_error (src_die);
22372 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22373 objfile_name ((*ref_cu)->per_objfile->objfile));
22374 }
22375
22376 return die;
22377}
22378
22379/* Follow reference OFFSET.
22380 On entry *REF_CU is the CU of the source die referencing OFFSET.
22381 On exit *REF_CU is the CU of the result.
22382 Returns NULL if OFFSET is invalid. */
22383
22384static struct die_info *
22385follow_die_offset (sect_offset sect_off, int offset_in_dwz,
22386 struct dwarf2_cu **ref_cu)
22387{
22388 struct die_info temp_die;
22389 struct dwarf2_cu *target_cu, *cu = *ref_cu;
22391
22392 gdb_assert (cu->per_cu != NULL);
22393
22394 target_cu = cu;
22395
22396 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
22397 "source CU contains target offset: %d",
22399 sect_offset_str (sect_off),
22400 cu->header.offset_in_cu_p (sect_off));
22401
22402 if (cu->per_cu->is_debug_types)
22403 {
22404 /* .debug_types CUs cannot reference anything outside their CU.
22405 If they need to, they have to reference a signatured type via
22406 DW_FORM_ref_sig8. */
22407 if (!cu->header.offset_in_cu_p (sect_off))
22408 return NULL;
22409 }
22410 else if (offset_in_dwz != cu->per_cu->is_dwz
22411 || !cu->header.offset_in_cu_p (sect_off))
22412 {
22413 struct dwarf2_per_cu_data *per_cu;
22414
22415 per_cu = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz,
22416 per_objfile->per_bfd);
22417
22418 dwarf_read_debug_printf_v ("target CU offset: %s, "
22419 "target CU DIEs loaded: %d",
22420 sect_offset_str (per_cu->sect_off),
22421 per_objfile->get_cu (per_cu) != nullptr);
22422
22423 /* If necessary, add it to the queue and load its DIEs.
22424
22425 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
22426 it doesn't mean they are currently loaded. Since we require them
22427 to be loaded, we must check for ourselves. */
22428 if (maybe_queue_comp_unit (cu, per_cu, per_objfile, cu->lang ())
22429 || per_objfile->get_cu (per_cu) == nullptr)
22430 load_full_comp_unit (per_cu, per_objfile, per_objfile->get_cu (per_cu),
22431 false, cu->lang ());
22432
22433 target_cu = per_objfile->get_cu (per_cu);
22434 gdb_assert (target_cu != nullptr);
22435 }
22436 else if (cu->dies == NULL)
22437 {
22438 /* We're loading full DIEs during partial symbol reading. */
22439 load_full_comp_unit (cu->per_cu, per_objfile, cu, false,
22441 }
22442
22443 *ref_cu = target_cu;
22444 temp_die.sect_off = sect_off;
22445
22446 return (struct die_info *) htab_find_with_hash (target_cu->die_hash,
22447 &temp_die,
22448 to_underlying (sect_off));
22449}
22450
22451/* Follow reference attribute ATTR of SRC_DIE.
22452 On entry *REF_CU is the CU of SRC_DIE.
22453 On exit *REF_CU is the CU of the result. */
22454
22455static struct die_info *
22456follow_die_ref (struct die_info *src_die, const struct attribute *attr,
22457 struct dwarf2_cu **ref_cu)
22458{
22459 sect_offset sect_off = attr->get_ref_die_offset ();
22460 struct dwarf2_cu *cu = *ref_cu;
22461 struct die_info *die;
22462
22464 (attr->form == DW_FORM_GNU_ref_alt
22465 || cu->per_cu->is_dwz),
22466 ref_cu);
22467 if (!die)
22468 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22469 "at %s [in module %s]"),
22472
22473 return die;
22474}
22475
22476/* See read.h. */
22477
22479dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
22482 gdb::function_view<CORE_ADDR ()> get_frame_pc,
22483 bool resolve_abstract_p)
22484{
22485 struct die_info *die;
22486 struct attribute *attr;
22487 struct dwarf2_locexpr_baton retval;
22488 struct objfile *objfile = per_objfile->objfile;
22489
22490 dwarf2_cu *cu = per_objfile->get_cu (per_cu);
22491 if (cu == nullptr)
22492 cu = load_cu (per_cu, per_objfile, false);
22493
22494 if (cu == nullptr)
22495 {
22496 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22497 Instead just throw an error, not much else we can do. */
22498 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22499 sect_offset_str (sect_off), objfile_name (objfile));
22500 }
22501
22502 die = follow_die_offset (sect_off, per_cu->is_dwz, &cu);
22503 if (!die)
22504 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22505 sect_offset_str (sect_off), objfile_name (objfile));
22506
22507 attr = dwarf2_attr (die, DW_AT_location, cu);
22508 if (!attr && resolve_abstract_p
22509 && (per_objfile->per_bfd->abstract_to_concrete.find (die->sect_off)
22510 != per_objfile->per_bfd->abstract_to_concrete.end ()))
22511 {
22512 CORE_ADDR pc = get_frame_pc ();
22513 CORE_ADDR baseaddr = objfile->text_section_offset ();
22514 struct gdbarch *gdbarch = objfile->arch ();
22515
22516 for (const auto &cand_off
22517 : per_objfile->per_bfd->abstract_to_concrete[die->sect_off])
22518 {
22519 struct dwarf2_cu *cand_cu = cu;
22520 struct die_info *cand
22521 = follow_die_offset (cand_off, per_cu->is_dwz, &cand_cu);
22522 if (!cand
22523 || !cand->parent
22524 || cand->parent->tag != DW_TAG_subprogram)
22525 continue;
22526
22527 CORE_ADDR pc_low, pc_high;
22528 get_scope_pc_bounds (cand->parent, &pc_low, &pc_high, cu);
22529 if (pc_low == ((CORE_ADDR) -1))
22530 continue;
22531 pc_low = gdbarch_adjust_dwarf2_addr (gdbarch, pc_low + baseaddr);
22532 pc_high = gdbarch_adjust_dwarf2_addr (gdbarch, pc_high + baseaddr);
22533 if (!(pc_low <= pc && pc < pc_high))
22534 continue;
22535
22536 die = cand;
22537 attr = dwarf2_attr (die, DW_AT_location, cu);
22538 break;
22539 }
22540 }
22541
22542 if (!attr)
22543 {
22544 /* DWARF: "If there is no such attribute, then there is no effect.".
22545 DATA is ignored if SIZE is 0. */
22546
22547 retval.data = NULL;
22548 retval.size = 0;
22549 }
22550 else if (attr->form_is_section_offset ())
22551 {
22552 struct dwarf2_loclist_baton loclist_baton;
22553 CORE_ADDR pc = get_frame_pc ();
22554 size_t size;
22555
22556 fill_in_loclist_baton (cu, &loclist_baton, attr);
22557
22558 retval.data = dwarf2_find_location_expression (&loclist_baton,
22559 &size, pc);
22560 retval.size = size;
22561 }
22562 else
22563 {
22564 if (!attr->form_is_block ())
22565 error (_("Dwarf Error: DIE at %s referenced in module %s "
22566 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22567 sect_offset_str (sect_off), objfile_name (objfile));
22568
22569 struct dwarf_block *block = attr->as_block ();
22570 retval.data = block->data;
22571 retval.size = block->size;
22572 }
22573 retval.per_objfile = per_objfile;
22574 retval.per_cu = cu->per_cu;
22575
22576 per_objfile->age_comp_units ();
22577
22578 return retval;
22579}
22580
22581/* See read.h. */
22582
22584dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu,
22587 gdb::function_view<CORE_ADDR ()> get_frame_pc)
22588{
22589 sect_offset sect_off = per_cu->sect_off + to_underlying (offset_in_cu);
22590
22592 get_frame_pc);
22593}
22594
22595/* Write a constant of a given type as target-ordered bytes into
22596 OBSTACK. */
22597
22598static const gdb_byte *
22599write_constant_as_bytes (struct obstack *obstack,
22600 enum bfd_endian byte_order,
22601 struct type *type,
22602 ULONGEST value,
22603 LONGEST *len)
22604{
22605 gdb_byte *result;
22606
22607 *len = type->length ();
22608 result = (gdb_byte *) obstack_alloc (obstack, *len);
22609 store_unsigned_integer (result, *len, byte_order, value);
22610
22611 return result;
22612}
22613
22614/* See read.h. */
22615
22616const gdb_byte *
22617dwarf2_fetch_constant_bytes (sect_offset sect_off,
22620 obstack *obstack,
22621 LONGEST *len)
22622{
22623 struct die_info *die;
22624 struct attribute *attr;
22625 const gdb_byte *result = NULL;
22626 struct type *type;
22627 LONGEST value;
22628 enum bfd_endian byte_order;
22629 struct objfile *objfile = per_objfile->objfile;
22630
22631 dwarf2_cu *cu = per_objfile->get_cu (per_cu);
22632 if (cu == nullptr)
22633 cu = load_cu (per_cu, per_objfile, false);
22634
22635 if (cu == nullptr)
22636 {
22637 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22638 Instead just throw an error, not much else we can do. */
22639 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22640 sect_offset_str (sect_off), objfile_name (objfile));
22641 }
22642
22643 die = follow_die_offset (sect_off, per_cu->is_dwz, &cu);
22644 if (!die)
22645 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22646 sect_offset_str (sect_off), objfile_name (objfile));
22647
22648 attr = dwarf2_attr (die, DW_AT_const_value, cu);
22649 if (attr == NULL)
22650 return NULL;
22651
22652 byte_order = (bfd_big_endian (objfile->obfd.get ())
22653 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
22654
22655 switch (attr->form)
22656 {
22657 case DW_FORM_addr:
22658 case DW_FORM_addrx:
22659 case DW_FORM_GNU_addr_index:
22660 {
22661 gdb_byte *tem;
22662
22663 *len = cu->header.addr_size;
22664 tem = (gdb_byte *) obstack_alloc (obstack, *len);
22665 store_unsigned_integer (tem, *len, byte_order, attr->as_address ());
22666 result = tem;
22667 }
22668 break;
22669 case DW_FORM_string:
22670 case DW_FORM_strp:
22671 case DW_FORM_strx:
22672 case DW_FORM_GNU_str_index:
22673 case DW_FORM_GNU_strp_alt:
22674 /* The string is already allocated on the objfile obstack, point
22675 directly to it. */
22676 {
22677 const char *attr_name = attr->as_string ();
22678 result = (const gdb_byte *) attr_name;
22679 *len = strlen (attr_name);
22680 }
22681 break;
22682 case DW_FORM_block1:
22683 case DW_FORM_block2:
22684 case DW_FORM_block4:
22685 case DW_FORM_block:
22686 case DW_FORM_exprloc:
22687 case DW_FORM_data16:
22688 {
22689 struct dwarf_block *block = attr->as_block ();
22690 result = block->data;
22691 *len = block->size;
22692 }
22693 break;
22694
22695 /* The DW_AT_const_value attributes are supposed to carry the
22696 symbol's value "represented as it would be on the target
22697 architecture." By the time we get here, it's already been
22698 converted to host endianness, so we just need to sign- or
22699 zero-extend it as appropriate. */
22700 case DW_FORM_data1:
22701 type = die_type (die, cu);
22702 result = dwarf2_const_value_data (attr, obstack, cu, &value, 8);
22703 if (result == NULL)
22704 result = write_constant_as_bytes (obstack, byte_order,
22705 type, value, len);
22706 break;
22707 case DW_FORM_data2:
22708 type = die_type (die, cu);
22709 result = dwarf2_const_value_data (attr, obstack, cu, &value, 16);
22710 if (result == NULL)
22711 result = write_constant_as_bytes (obstack, byte_order,
22712 type, value, len);
22713 break;
22714 case DW_FORM_data4:
22715 type = die_type (die, cu);
22716 result = dwarf2_const_value_data (attr, obstack, cu, &value, 32);
22717 if (result == NULL)
22718 result = write_constant_as_bytes (obstack, byte_order,
22719 type, value, len);
22720 break;
22721 case DW_FORM_data8:
22722 type = die_type (die, cu);
22723 result = dwarf2_const_value_data (attr, obstack, cu, &value, 64);
22724 if (result == NULL)
22725 result = write_constant_as_bytes (obstack, byte_order,
22726 type, value, len);
22727 break;
22728
22729 case DW_FORM_sdata:
22730 case DW_FORM_implicit_const:
22731 type = die_type (die, cu);
22732 result = write_constant_as_bytes (obstack, byte_order,
22733 type, attr->as_signed (), len);
22734 break;
22735
22736 case DW_FORM_udata:
22737 type = die_type (die, cu);
22738 result = write_constant_as_bytes (obstack, byte_order,
22739 type, attr->as_unsigned (), len);
22740 break;
22741
22742 default:
22743 complaint (_("unsupported const value attribute form: '%s'"),
22744 dwarf_form_name (attr->form));
22745 break;
22746 }
22747
22748 return result;
22749}
22750
22751/* See read.h. */
22752
22753struct type *
22755 dwarf2_per_cu_data *per_cu,
22756 dwarf2_per_objfile *per_objfile,
22757 const char **var_name)
22758{
22759 struct die_info *die;
22760
22761 dwarf2_cu *cu = per_objfile->get_cu (per_cu);
22762 if (cu == nullptr)
22763 cu = load_cu (per_cu, per_objfile, false);
22764
22765 if (cu == nullptr)
22766 return nullptr;
22767
22768 die = follow_die_offset (sect_off, per_cu->is_dwz, &cu);
22769 if (!die)
22770 return NULL;
22771
22772 if (var_name != nullptr)
22773 *var_name = var_decl_name (die, cu);
22774 return die_type (die, cu);
22775}
22776
22777/* See read.h. */
22778
22779struct type *
22780dwarf2_get_die_type (cu_offset die_offset,
22781 dwarf2_per_cu_data *per_cu,
22782 dwarf2_per_objfile *per_objfile)
22783{
22784 sect_offset die_offset_sect = per_cu->sect_off + to_underlying (die_offset);
22785 return get_die_type_at_offset (die_offset_sect, per_cu, per_objfile);
22786}
22787
22788/* Follow type unit SIG_TYPE referenced by SRC_DIE.
22789 On entry *REF_CU is the CU of SRC_DIE.
22790 On exit *REF_CU is the CU of the result.
22791 Returns NULL if the referenced DIE isn't found. */
22792
22793static struct die_info *
22794follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
22795 struct dwarf2_cu **ref_cu)
22796{
22797 struct die_info temp_die;
22798 struct dwarf2_cu *sig_cu;
22799 struct die_info *die;
22800 dwarf2_per_objfile *per_objfile = (*ref_cu)->per_objfile;
22801
22802
22803 /* While it might be nice to assert sig_type->type == NULL here,
22804 we can get here for DW_AT_imported_declaration where we need
22805 the DIE not the type. */
22806
22807 /* If necessary, add it to the queue and load its DIEs.
22808
22809 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
22810 it doesn't mean they are currently loaded. Since we require them
22811 to be loaded, we must check for ourselves. */
22812 if (maybe_queue_comp_unit (*ref_cu, sig_type, per_objfile,
22814 || per_objfile->get_cu (sig_type) == nullptr)
22815 read_signatured_type (sig_type, per_objfile);
22816
22817 sig_cu = per_objfile->get_cu (sig_type);
22818 gdb_assert (sig_cu != NULL);
22819 gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
22820 temp_die.sect_off = sig_type->type_offset_in_section;
22821 die = (struct die_info *) htab_find_with_hash (sig_cu->die_hash, &temp_die,
22822 to_underlying (temp_die.sect_off));
22823 if (die)
22824 {
22825 /* For .gdb_index version 7 keep track of included TUs.
22826 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22827 if (per_objfile->per_bfd->index_table != NULL
22828 && !per_objfile->per_bfd->index_table->version_check ())
22829 {
22830 (*ref_cu)->per_cu->imported_symtabs_push (sig_cu->per_cu);
22831 }
22832
22833 *ref_cu = sig_cu;
22834 return die;
22835 }
22836
22837 return NULL;
22838}
22839
22840/* Follow signatured type referenced by ATTR in SRC_DIE.
22841 On entry *REF_CU is the CU of SRC_DIE.
22842 On exit *REF_CU is the CU of the result.
22843 The result is the DIE of the type.
22844 If the referenced type cannot be found an error is thrown. */
22845
22846static struct die_info *
22847follow_die_sig (struct die_info *src_die, const struct attribute *attr,
22848 struct dwarf2_cu **ref_cu)
22849{
22850 ULONGEST signature = attr->as_signature ();
22851 struct signatured_type *sig_type;
22852 struct die_info *die;
22853
22854 gdb_assert (attr->form == DW_FORM_ref_sig8);
22855
22856 sig_type = lookup_signatured_type (*ref_cu, signature);
22857 /* sig_type will be NULL if the signatured type is missing from
22858 the debug info. */
22859 if (sig_type == NULL)
22860 {
22861 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22862 " from DIE at %s [in module %s]"),
22863 hex_string (signature), sect_offset_str (src_die->sect_off),
22864 objfile_name ((*ref_cu)->per_objfile->objfile));
22865 }
22866
22867 die = follow_die_sig_1 (src_die, sig_type, ref_cu);
22868 if (die == NULL)
22869 {
22870 dump_die_for_error (src_die);
22871 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22872 " from DIE at %s [in module %s]"),
22873 hex_string (signature), sect_offset_str (src_die->sect_off),
22874 objfile_name ((*ref_cu)->per_objfile->objfile));
22875 }
22876
22877 return die;
22878}
22879
22880/* Get the type specified by SIGNATURE referenced in DIE/CU,
22881 reading in and processing the type unit if necessary. */
22882
22883static struct type *
22884get_signatured_type (struct die_info *die, ULONGEST signature,
22885 struct dwarf2_cu *cu)
22886{
22887 dwarf2_per_objfile *per_objfile = cu->per_objfile;
22888 struct signatured_type *sig_type;
22889 struct dwarf2_cu *type_cu;
22890 struct die_info *type_die;
22891 struct type *type;
22892
22893 sig_type = lookup_signatured_type (cu, signature);
22894 /* sig_type will be NULL if the signatured type is missing from
22895 the debug info. */
22896 if (sig_type == NULL)
22897 {
22898 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22899 " from DIE at %s [in module %s]"),
22900 hex_string (signature), sect_offset_str (die->sect_off),
22901 objfile_name (per_objfile->objfile));
22902 return build_error_marker_type (cu, die);
22903 }
22904
22905 /* If we already know the type we're done. */
22906 type = per_objfile->get_type_for_signatured_type (sig_type);
22907 if (type != nullptr)
22908 return type;
22909
22910 type_cu = cu;
22911 type_die = follow_die_sig_1 (die, sig_type, &type_cu);
22912 if (type_die != NULL)
22913 {
22914 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22915 is created. This is important, for example, because for c++ classes
22916 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22917 type = read_type_die (type_die, type_cu);
22918 if (type == NULL)
22919 {
22920 complaint (_("Dwarf Error: Cannot build signatured type %s"
22921 " referenced from DIE at %s [in module %s]"),
22922 hex_string (signature), sect_offset_str (die->sect_off),
22923 objfile_name (per_objfile->objfile));
22924 type = build_error_marker_type (cu, die);
22925 }
22926 }
22927 else
22928 {
22929 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22930 " from DIE at %s [in module %s]"),
22931 hex_string (signature), sect_offset_str (die->sect_off),
22932 objfile_name (per_objfile->objfile));
22933 type = build_error_marker_type (cu, die);
22934 }
22935
22936 per_objfile->set_type_for_signatured_type (sig_type, type);
22937
22938 return type;
22939}
22940
22941/* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22942 reading in and processing the type unit if necessary. */
22943
22944static struct type *
22945get_DW_AT_signature_type (struct die_info *die, const struct attribute *attr,
22946 struct dwarf2_cu *cu) /* ARI: editCase function */
22947{
22948 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22949 if (attr->form_is_ref ())
22950 {
22951 struct dwarf2_cu *type_cu = cu;
22952 struct die_info *type_die = follow_die_ref (die, attr, &type_cu);
22953
22954 return read_type_die (type_die, type_cu);
22955 }
22956 else if (attr->form == DW_FORM_ref_sig8)
22957 {
22958 return get_signatured_type (die, attr->as_signature (), cu);
22959 }
22960 else
22961 {
22962 dwarf2_per_objfile *per_objfile = cu->per_objfile;
22963
22964 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22965 " at %s [in module %s]"),
22967 objfile_name (per_objfile->objfile));
22968 return build_error_marker_type (cu, die);
22969 }
22970}
22971
22972/* Load the DIEs associated with type unit PER_CU into memory. */
22973
22974static void
22976 dwarf2_per_objfile *per_objfile)
22977{
22978 struct signatured_type *sig_type;
22979
22980 /* We have the per_cu, but we need the signatured_type.
22981 Fortunately this is an easy translation. */
22982 gdb_assert (per_cu->is_debug_types);
22983 sig_type = (struct signatured_type *) per_cu;
22984
22985 gdb_assert (per_objfile->get_cu (per_cu) == nullptr);
22986
22987 read_signatured_type (sig_type, per_objfile);
22988
22989 gdb_assert (per_objfile->get_cu (per_cu) != nullptr);
22990}
22991
22992/* Read in a signatured type and build its CU and DIEs.
22993 If the type is a stub for the real type in a DWO file,
22994 read in the real type from the DWO file as well. */
22995
22996static void
22998 dwarf2_per_objfile *per_objfile)
22999{
23000 gdb_assert (sig_type->is_debug_types);
23001 gdb_assert (per_objfile->get_cu (sig_type) == nullptr);
23002
23003 cutu_reader reader (sig_type, per_objfile, nullptr, nullptr, false);
23004
23005 if (!reader.dummy_p)
23006 {
23007 struct dwarf2_cu *cu = reader.cu;
23008 const gdb_byte *info_ptr = reader.info_ptr;
23009
23010 gdb_assert (cu->die_hash == NULL);
23011 cu->die_hash =
23012 htab_create_alloc_ex (cu->header.length / 12,
23013 die_hash,
23014 die_eq,
23015 NULL,
23016 &cu->comp_unit_obstack,
23017 hashtab_obstack_allocate,
23018 dummy_obstack_deallocate);
23019
23020 if (reader.comp_unit_die->has_children)
23021 reader.comp_unit_die->child
23022 = read_die_and_siblings (&reader, info_ptr, &info_ptr,
23023 reader.comp_unit_die);
23024 cu->dies = reader.comp_unit_die;
23025 /* comp_unit_die is not stored in die_hash, no need. */
23026
23027 /* We try not to read any attributes in this function, because
23028 not all CUs needed for references have been loaded yet, and
23029 symbol table processing isn't initialized. But we have to
23030 set the CU language, or we won't be able to build types
23031 correctly. Similarly, if we do not read the producer, we can
23032 not apply producer-specific interpretation. */
23034
23035 reader.keep ();
23036 }
23037
23038 sig_type->tu_read = 1;
23039}
23040
23041/* Decode simple location descriptions.
23042 Given a pointer to a dwarf block that defines a location, compute
23043 the location and return the value. If COMPUTED is non-null, it is
23044 set to true to indicate that decoding was successful, and false
23045 otherwise. If COMPUTED is null, then this function may emit a
23046 complaint. */
23047
23048static CORE_ADDR
23049decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu, bool *computed)
23050{
23051 struct objfile *objfile = cu->per_objfile->objfile;
23052 size_t i;
23053 size_t size = blk->size;
23054 const gdb_byte *data = blk->data;
23055 CORE_ADDR stack[64];
23056 int stacki;
23057 unsigned int bytes_read, unsnd;
23058 gdb_byte op;
23059
23060 if (computed != nullptr)
23061 *computed = false;
23062
23063 i = 0;
23064 stacki = 0;
23065 stack[stacki] = 0;
23066 stack[++stacki] = 0;
23067
23068 while (i < size)
23069 {
23070 op = data[i++];
23071 switch (op)
23072 {
23073 case DW_OP_lit0:
23074 case DW_OP_lit1:
23075 case DW_OP_lit2:
23076 case DW_OP_lit3:
23077 case DW_OP_lit4:
23078 case DW_OP_lit5:
23079 case DW_OP_lit6:
23080 case DW_OP_lit7:
23081 case DW_OP_lit8:
23082 case DW_OP_lit9:
23083 case DW_OP_lit10:
23084 case DW_OP_lit11:
23085 case DW_OP_lit12:
23086 case DW_OP_lit13:
23087 case DW_OP_lit14:
23088 case DW_OP_lit15:
23089 case DW_OP_lit16:
23090 case DW_OP_lit17:
23091 case DW_OP_lit18:
23092 case DW_OP_lit19:
23093 case DW_OP_lit20:
23094 case DW_OP_lit21:
23095 case DW_OP_lit22:
23096 case DW_OP_lit23:
23097 case DW_OP_lit24:
23098 case DW_OP_lit25:
23099 case DW_OP_lit26:
23100 case DW_OP_lit27:
23101 case DW_OP_lit28:
23102 case DW_OP_lit29:
23103 case DW_OP_lit30:
23104 case DW_OP_lit31:
23105 stack[++stacki] = op - DW_OP_lit0;
23106 break;
23107
23108 case DW_OP_reg0:
23109 case DW_OP_reg1:
23110 case DW_OP_reg2:
23111 case DW_OP_reg3:
23112 case DW_OP_reg4:
23113 case DW_OP_reg5:
23114 case DW_OP_reg6:
23115 case DW_OP_reg7:
23116 case DW_OP_reg8:
23117 case DW_OP_reg9:
23118 case DW_OP_reg10:
23119 case DW_OP_reg11:
23120 case DW_OP_reg12:
23121 case DW_OP_reg13:
23122 case DW_OP_reg14:
23123 case DW_OP_reg15:
23124 case DW_OP_reg16:
23125 case DW_OP_reg17:
23126 case DW_OP_reg18:
23127 case DW_OP_reg19:
23128 case DW_OP_reg20:
23129 case DW_OP_reg21:
23130 case DW_OP_reg22:
23131 case DW_OP_reg23:
23132 case DW_OP_reg24:
23133 case DW_OP_reg25:
23134 case DW_OP_reg26:
23135 case DW_OP_reg27:
23136 case DW_OP_reg28:
23137 case DW_OP_reg29:
23138 case DW_OP_reg30:
23139 case DW_OP_reg31:
23140 stack[++stacki] = op - DW_OP_reg0;
23141 if (i < size)
23142 {
23143 if (computed == nullptr)
23145 else
23146 return 0;
23147 }
23148 break;
23149
23150 case DW_OP_regx:
23151 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
23152 i += bytes_read;
23153 stack[++stacki] = unsnd;
23154 if (i < size)
23155 {
23156 if (computed == nullptr)
23158 else
23159 return 0;
23160 }
23161 break;
23162
23163 case DW_OP_addr:
23164 stack[++stacki] = cu->header.read_address (objfile->obfd.get (),
23165 &data[i],
23166 &bytes_read);
23167 i += bytes_read;
23168 break;
23169
23170 case DW_OP_const1u:
23171 stack[++stacki] = read_1_byte (objfile->obfd.get (), &data[i]);
23172 i += 1;
23173 break;
23174
23175 case DW_OP_const1s:
23176 stack[++stacki] = read_1_signed_byte (objfile->obfd.get (), &data[i]);
23177 i += 1;
23178 break;
23179
23180 case DW_OP_const2u:
23181 stack[++stacki] = read_2_bytes (objfile->obfd.get (), &data[i]);
23182 i += 2;
23183 break;
23184
23185 case DW_OP_const2s:
23186 stack[++stacki] = read_2_signed_bytes (objfile->obfd.get (), &data[i]);
23187 i += 2;
23188 break;
23189
23190 case DW_OP_const4u:
23191 stack[++stacki] = read_4_bytes (objfile->obfd.get (), &data[i]);
23192 i += 4;
23193 break;
23194
23195 case DW_OP_const4s:
23196 stack[++stacki] = read_4_signed_bytes (objfile->obfd.get (), &data[i]);
23197 i += 4;
23198 break;
23199
23200 case DW_OP_const8u:
23201 stack[++stacki] = read_8_bytes (objfile->obfd.get (), &data[i]);
23202 i += 8;
23203 break;
23204
23205 case DW_OP_constu:
23206 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
23207 &bytes_read);
23208 i += bytes_read;
23209 break;
23210
23211 case DW_OP_consts:
23212 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
23213 i += bytes_read;
23214 break;
23215
23216 case DW_OP_dup:
23217 stack[stacki + 1] = stack[stacki];
23218 stacki++;
23219 break;
23220
23221 case DW_OP_plus:
23222 stack[stacki - 1] += stack[stacki];
23223 stacki--;
23224 break;
23225
23226 case DW_OP_plus_uconst:
23227 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
23228 &bytes_read);
23229 i += bytes_read;
23230 break;
23231
23232 case DW_OP_minus:
23233 stack[stacki - 1] -= stack[stacki];
23234 stacki--;
23235 break;
23236
23237 case DW_OP_deref:
23238 /* If we're not the last op, then we definitely can't encode
23239 this using GDB's address_class enum. This is valid for partial
23240 global symbols, although the variable's address will be bogus
23241 in the psymtab. */
23242 if (i < size)
23243 {
23244 if (computed == nullptr)
23246 else
23247 return 0;
23248 }
23249 break;
23250
23251 case DW_OP_GNU_push_tls_address:
23252 case DW_OP_form_tls_address:
23253 /* The top of the stack has the offset from the beginning
23254 of the thread control block at which the variable is located. */
23255 /* Nothing should follow this operator, so the top of stack would
23256 be returned. */
23257 /* This is valid for partial global symbols, but the variable's
23258 address will be bogus in the psymtab. Make it always at least
23259 non-zero to not look as a variable garbage collected by linker
23260 which have DW_OP_addr 0. */
23261 if (i < size)
23262 {
23263 if (computed == nullptr)
23265 else
23266 return 0;
23267 }
23268 stack[stacki]++;
23269 break;
23270
23271 case DW_OP_GNU_uninit:
23272 if (computed != nullptr)
23273 return 0;
23274 break;
23275
23276 case DW_OP_addrx:
23277 case DW_OP_GNU_addr_index:
23278 case DW_OP_GNU_const_index:
23279 stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i],
23280 &bytes_read);
23281 i += bytes_read;
23282 break;
23283
23284 default:
23285 if (computed == nullptr)
23286 {
23287 const char *name = get_DW_OP_name (op);
23288
23289 if (name)
23290 complaint (_("unsupported stack op: '%s'"),
23291 name);
23292 else
23293 complaint (_("unsupported stack op: '%02x'"),
23294 op);
23295 }
23296
23297 return (stack[stacki]);
23298 }
23299
23300 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23301 outside of the allocated space. Also enforce minimum>0. */
23302 if (stacki >= ARRAY_SIZE (stack) - 1)
23303 {
23304 if (computed == nullptr)
23305 complaint (_("location description stack overflow"));
23306 return 0;
23307 }
23308
23309 if (stacki <= 0)
23310 {
23311 if (computed == nullptr)
23312 complaint (_("location description stack underflow"));
23313 return 0;
23314 }
23315 }
23316
23317 if (computed != nullptr)
23318 *computed = true;
23319 return (stack[stacki]);
23320}
23321
23322/* memory allocation interface */
23323
23324static struct dwarf_block *
23326{
23327 return XOBNEW (&cu->comp_unit_obstack, struct dwarf_block);
23328}
23329
23330static struct die_info *
23332{
23333 struct die_info *die;
23334 size_t size = sizeof (struct die_info);
23335
23336 if (num_attrs > 1)
23337 size += (num_attrs - 1) * sizeof (struct attribute);
23338
23339 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
23340 memset (die, 0, sizeof (struct die_info));
23341 return (die);
23342}
23343
23344␌
23345
23346/* Macro support. */
23347
23348/* An overload of dwarf_decode_macros that finds the correct section
23349 and ensures it is read in before calling the other overload. */
23350
23351static void
23352dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
23353 int section_is_gnu)
23354{
23355 dwarf2_per_objfile *per_objfile = cu->per_objfile;
23356 struct objfile *objfile = per_objfile->objfile;
23357 const struct line_header *lh = cu->line_header;
23358 unsigned int offset_size = cu->header.offset_size;
23360 const char *section_name;
23361
23362 if (cu->dwo_unit != nullptr)
23363 {
23364 if (section_is_gnu)
23365 {
23366 section = &cu->dwo_unit->dwo_file->sections.macro;
23367 section_name = ".debug_macro.dwo";
23368 }
23369 else
23370 {
23371 section = &cu->dwo_unit->dwo_file->sections.macinfo;
23372 section_name = ".debug_macinfo.dwo";
23373 }
23374 }
23375 else
23376 {
23377 if (section_is_gnu)
23378 {
23379 section = &per_objfile->per_bfd->macro;
23380 section_name = ".debug_macro";
23381 }
23382 else
23383 {
23384 section = &per_objfile->per_bfd->macinfo;
23385 section_name = ".debug_macinfo";
23386 }
23387 }
23388
23389 section->read (objfile);
23390 if (section->buffer == nullptr)
23391 {
23392 complaint (_("missing %s section"), section_name);
23393 return;
23394 }
23395
23396 buildsym_compunit *builder = cu->get_builder ();
23397
23398 struct dwarf2_section_info *str_offsets_section;
23399 struct dwarf2_section_info *str_section;
23400 gdb::optional<ULONGEST> str_offsets_base;
23401
23402 if (cu->dwo_unit != nullptr)
23403 {
23404 str_offsets_section = &cu->dwo_unit->dwo_file
23405 ->sections.str_offsets;
23406 str_section = &cu->dwo_unit->dwo_file->sections.str;
23407 str_offsets_base = cu->header.addr_size;
23408 }
23409 else
23410 {
23411 str_offsets_section = &per_objfile->per_bfd->str_offsets;
23412 str_section = &per_objfile->per_bfd->str;
23413 str_offsets_base = cu->str_offsets_base;
23414 }
23415
23416 dwarf_decode_macros (per_objfile, builder, section, lh,
23417 offset_size, offset, str_section, str_offsets_section,
23418 str_offsets_base, section_is_gnu, cu);
23419}
23420
23421/* Return the .debug_loc section to use for CU.
23422 For DWO files use .debug_loc.dwo. */
23423
23424static struct dwarf2_section_info *
23426{
23427 dwarf2_per_objfile *per_objfile = cu->per_objfile;
23428
23429 if (cu->dwo_unit)
23430 {
23431 struct dwo_sections *sections = &cu->dwo_unit->dwo_file->sections;
23432
23433 return cu->header.version >= 5 ? &sections->loclists : &sections->loc;
23434 }
23435 return (cu->header.version >= 5 ? &per_objfile->per_bfd->loclists
23436 : &per_objfile->per_bfd->loc);
23437}
23438
23439/* Return the .debug_rnglists section to use for CU. */
23440static struct dwarf2_section_info *
23441cu_debug_rnglists_section (struct dwarf2_cu *cu, dwarf_tag tag)
23442{
23443 if (cu->header.version < 5)
23444 error (_(".debug_rnglists section cannot be used in DWARF %d"),
23445 cu->header.version);
23447
23448 /* Make sure we read the .debug_rnglists section from the file that
23449 contains the DW_AT_ranges attribute we are reading. Normally that
23450 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
23451 or DW_TAG_skeleton unit, we always want to read from objfile/linked
23452 program. */
23453 if (cu->dwo_unit != nullptr
23454 && tag != DW_TAG_compile_unit
23455 && tag != DW_TAG_skeleton_unit)
23456 {
23457 struct dwo_sections *sections = &cu->dwo_unit->dwo_file->sections;
23458
23459 if (sections->rnglists.size > 0)
23460 return &sections->rnglists;
23461 else
23462 error (_(".debug_rnglists section is missing from .dwo file."));
23463 }
23465}
23466
23467/* A helper function that fills in a dwarf2_loclist_baton. */
23468
23469static void
23471 struct dwarf2_loclist_baton *baton,
23472 const struct attribute *attr)
23473{
23474 dwarf2_per_objfile *per_objfile = cu->per_objfile;
23476
23477 section->read (per_objfile->objfile);
23478
23479 baton->per_objfile = per_objfile;
23480 baton->per_cu = cu->per_cu;
23481 gdb_assert (baton->per_cu);
23482 /* We don't know how long the location list is, but make sure we
23483 don't run off the edge of the section. */
23484 baton->size = section->size - attr->as_unsigned ();
23485 baton->data = section->buffer + attr->as_unsigned ();
23486 if (cu->base_address.has_value ())
23487 baton->base_address = *cu->base_address;
23488 else
23489 baton->base_address = 0;
23490 baton->from_dwo = cu->dwo_unit != NULL;
23491}
23492
23493static void
23494dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
23495 struct dwarf2_cu *cu, int is_block)
23496{
23497 dwarf2_per_objfile *per_objfile = cu->per_objfile;
23498 struct objfile *objfile = per_objfile->objfile;
23500
23501 if (attr->form_is_section_offset ()
23502 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23503 the section. If so, fall through to the complaint in the
23504 other branch. */
23505 && attr->as_unsigned () < section->get_size (objfile))
23506 {
23507 struct dwarf2_loclist_baton *baton;
23508
23509 baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_loclist_baton);
23510
23511 fill_in_loclist_baton (cu, baton, attr);
23512
23513 if (!cu->base_address.has_value ())
23514 complaint (_("Location list used without "
23515 "specifying the CU base address."));
23516
23517 sym->set_aclass_index ((is_block
23520 SYMBOL_LOCATION_BATON (sym) = baton;
23521 }
23522 else
23523 {
23524 struct dwarf2_locexpr_baton *baton;
23525
23526 baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
23527 baton->per_objfile = per_objfile;
23528 baton->per_cu = cu->per_cu;
23529 gdb_assert (baton->per_cu);
23530
23531 if (attr->form_is_block ())
23532 {
23533 /* Note that we're just copying the block's data pointer
23534 here, not the actual data. We're still pointing into the
23535 info_buffer for SYM's objfile; right now we never release
23536 that buffer, but when we do clean up properly this may
23537 need to change. */
23538 struct dwarf_block *block = attr->as_block ();
23539 baton->size = block->size;
23540 baton->data = block->data;
23541 }
23542 else
23543 {
23544 dwarf2_invalid_attrib_class_complaint ("location description",
23545 sym->natural_name ());
23546 baton->size = 0;
23547 }
23548
23549 sym->set_aclass_index ((is_block
23552 SYMBOL_LOCATION_BATON (sym) = baton;
23553 }
23554}
23555
23556/* See read.h. */
23557
23558const comp_unit_head *
23560{
23561 if (!m_header_read_in)
23562 {
23563 const gdb_byte *info_ptr
23564 = this->section->buffer + to_underlying (this->sect_off);
23565
23566 memset (&m_header, 0, sizeof (m_header));
23567
23568 read_comp_unit_head (&m_header, info_ptr, this->section,
23570
23571 m_header_read_in = true;
23572 }
23573
23574 return &m_header;
23575}
23576
23577/* See read.h. */
23578
23579int
23581{
23582 return this->get_header ()->addr_size;
23583}
23584
23585/* See read.h. */
23586
23587int
23589{
23590 return this->get_header ()->offset_size;
23591}
23592
23593/* See read.h. */
23594
23595int
23597{
23598 const comp_unit_head *header = this->get_header ();
23599
23600 if (header->version == 2)
23601 return header->addr_size;
23602 else
23603 return header->offset_size;
23604}
23605
23606/* A helper function for dwarf2_find_containing_comp_unit that returns
23607 the index of the result, and that searches a vector. It will
23608 return a result even if the offset in question does not actually
23609 occur in any CU. This is separate so that it can be unit
23610 tested. */
23611
23612static int
23614 (sect_offset sect_off,
23615 unsigned int offset_in_dwz,
23616 const std::vector<dwarf2_per_cu_data_up> &all_units)
23617{
23618 int low, high;
23619
23620 low = 0;
23621 high = all_units.size () - 1;
23622 while (high > low)
23623 {
23624 struct dwarf2_per_cu_data *mid_cu;
23625 int mid = low + (high - low) / 2;
23626
23627 mid_cu = all_units[mid].get ();
23628 if (mid_cu->is_dwz > offset_in_dwz
23629 || (mid_cu->is_dwz == offset_in_dwz
23630 && mid_cu->sect_off + mid_cu->length () > sect_off))
23631 high = mid;
23632 else
23633 low = mid + 1;
23634 }
23635 gdb_assert (low == high);
23636 return low;
23637}
23638
23639/* Locate the .debug_info compilation unit from CU's objfile which contains
23640 the DIE at OFFSET. Raises an error on failure. */
23641
23642static struct dwarf2_per_cu_data *
23644 unsigned int offset_in_dwz,
23646{
23648 (sect_off, offset_in_dwz, per_bfd->all_units);
23649 dwarf2_per_cu_data *this_cu = per_bfd->all_units[low].get ();
23650
23651 if (this_cu->is_dwz != offset_in_dwz || this_cu->sect_off > sect_off)
23652 {
23653 if (low == 0 || this_cu->is_dwz != offset_in_dwz)
23654 error (_("Dwarf Error: could not find partial DIE containing "
23655 "offset %s [in module %s]"),
23657 bfd_get_filename (per_bfd->obfd));
23658
23659 gdb_assert (per_bfd->all_units[low-1]->sect_off
23660 <= sect_off);
23661 return per_bfd->all_units[low - 1].get ();
23662 }
23663 else
23664 {
23665 if (low == per_bfd->all_units.size () - 1
23666 && sect_off >= this_cu->sect_off + this_cu->length ())
23667 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off));
23668 gdb_assert (sect_off < this_cu->sect_off + this_cu->length ());
23669 return this_cu;
23670 }
23671}
23672
23673#if GDB_SELF_TEST
23674
23675namespace selftests {
23676namespace find_containing_comp_unit {
23677
23678static void
23679run_test ()
23680{
23682 dwarf2_per_cu_data *one_ptr = one.get ();
23684 dwarf2_per_cu_data *two_ptr = two.get ();
23686 dwarf2_per_cu_data *three_ptr = three.get ();
23688 dwarf2_per_cu_data *four_ptr = four.get ();
23689
23690 one->set_length (5);
23691 two->sect_off = sect_offset (one->length ());
23692 two->set_length (7);
23693
23694 three->set_length (5);
23695 three->is_dwz = 1;
23696 four->sect_off = sect_offset (three->length ());
23697 four->set_length (7);
23698 four->is_dwz = 1;
23699
23700 std::vector<dwarf2_per_cu_data_up> units;
23701 units.push_back (std::move (one));
23702 units.push_back (std::move (two));
23703 units.push_back (std::move (three));
23704 units.push_back (std::move (four));
23705
23706 int result;
23707
23708 result = dwarf2_find_containing_comp_unit (sect_offset (0), 0, units);
23709 SELF_CHECK (units[result].get () == one_ptr);
23710 result = dwarf2_find_containing_comp_unit (sect_offset (3), 0, units);
23711 SELF_CHECK (units[result].get () == one_ptr);
23712 result = dwarf2_find_containing_comp_unit (sect_offset (5), 0, units);
23713 SELF_CHECK (units[result].get () == two_ptr);
23714
23715 result = dwarf2_find_containing_comp_unit (sect_offset (0), 1, units);
23716 SELF_CHECK (units[result].get () == three_ptr);
23717 result = dwarf2_find_containing_comp_unit (sect_offset (3), 1, units);
23718 SELF_CHECK (units[result].get () == three_ptr);
23719 result = dwarf2_find_containing_comp_unit (sect_offset (5), 1, units);
23720 SELF_CHECK (units[result].get () == four_ptr);
23721}
23722
23723}
23724}
23725
23726#endif /* GDB_SELF_TEST */
23727
23728/* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23729
23730static void
23731prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
23732 enum language pretend_language)
23733{
23734 struct attribute *attr;
23735
23736 cu->producer = dwarf2_string_attr (comp_unit_die, DW_AT_producer, cu);
23737
23738 /* Set the language we're debugging. */
23739 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
23740 enum language lang;
23741 if (cu->producer != nullptr
23742 && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
23743 {
23744 /* The XLCL doesn't generate DW_LANG_OpenCL because this
23745 attribute is not standardised yet. As a workaround for the
23746 language detection we fall back to the DW_AT_producer
23747 string. */
23748 lang = language_opencl;
23749 }
23750 else if (cu->producer != nullptr
23751 && strstr (cu->producer, "GNU Go ") != NULL)
23752 {
23753 /* Similar hack for Go. */
23754 lang = language_go;
23755 }
23756 else if (attr != nullptr)
23758 else
23759 lang = pretend_language;
23760
23761 cu->language_defn = language_def (lang);
23762
23763 switch (comp_unit_die->tag)
23764 {
23765 case DW_TAG_compile_unit:
23766 cu->per_cu->set_unit_type (DW_UT_compile);
23767 break;
23768 case DW_TAG_partial_unit:
23769 cu->per_cu->set_unit_type (DW_UT_partial);
23770 break;
23771 case DW_TAG_type_unit:
23772 cu->per_cu->set_unit_type (DW_UT_type);
23773 break;
23774 default:
23775 error (_("Dwarf Error: unexpected tag '%s' at offset %s"),
23776 dwarf_tag_name (comp_unit_die->tag),
23778 }
23779
23780 cu->per_cu->set_lang (lang);
23781}
23782
23783/* See read.h. */
23784
23785dwarf2_cu *
23787{
23788 auto it = m_dwarf2_cus.find (per_cu);
23789 if (it == m_dwarf2_cus.end ())
23790 return nullptr;
23791
23792 return it->second.get ();
23793}
23794
23795/* See read.h. */
23796
23797void
23799 std::unique_ptr<dwarf2_cu> cu)
23800{
23801 gdb_assert (this->get_cu (per_cu) == nullptr);
23802
23803 m_dwarf2_cus[per_cu] = std::move (cu);
23804}
23805
23806/* See read.h. */
23807
23808void
23810{
23811 dwarf_read_debug_printf_v ("running");
23812
23813 /* This is not expected to be called in the middle of CU expansion. There is
23814 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
23815 loaded in memory. Calling age_comp_units while the queue is in use could
23816 make us free the DIEs for a CU that is in the queue and therefore break
23817 that invariant. */
23818 gdb_assert (!queue.has_value ());
23819
23820 /* Start by clearing all marks. */
23821 for (const auto &pair : m_dwarf2_cus)
23822 pair.second->clear_mark ();
23823
23824 /* Traverse all CUs, mark them and their dependencies if used recently
23825 enough. */
23826 for (const auto &pair : m_dwarf2_cus)
23827 {
23828 dwarf2_cu *cu = pair.second.get ();
23829
23830 cu->last_used++;
23831 if (cu->last_used <= dwarf_max_cache_age)
23832 cu->mark ();
23833 }
23834
23835 /* Delete all CUs still not marked. */
23836 for (auto it = m_dwarf2_cus.begin (); it != m_dwarf2_cus.end ();)
23837 {
23838 dwarf2_cu *cu = it->second.get ();
23839
23840 if (!cu->is_marked ())
23841 {
23842 dwarf_read_debug_printf_v ("deleting old CU %s",
23844 it = m_dwarf2_cus.erase (it);
23845 }
23846 else
23847 it++;
23848 }
23849}
23850
23851/* See read.h. */
23852
23853void
23855{
23856 auto it = m_dwarf2_cus.find (per_cu);
23857 if (it == m_dwarf2_cus.end ())
23858 return;
23859
23860 m_dwarf2_cus.erase (it);
23861}
23862
23864{
23865 remove_all_cus ();
23866}
23867
23868/* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23869 We store these in a hash table separate from the DIEs, and preserve them
23870 when the DIEs are flushed out of cache.
23871
23872 The CU "per_cu" pointer is needed because offset alone is not enough to
23873 uniquely identify the type. A file may have multiple .debug_types sections,
23874 or the type may come from a DWO file. Furthermore, while it's more logical
23875 to use per_cu->section+offset, with Fission the section with the data is in
23876 the DWO file but we don't know that section at the point we need it.
23877 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23878 because we can enter the lookup routine, get_die_type_at_offset, from
23879 outside this file, and thus won't necessarily have PER_CU->cu.
23880 Fortunately, PER_CU is stable for the life of the objfile. */
23881
23883{
23885 sect_offset sect_off;
23886 struct type *type;
23887};
23888
23889/* Hash function for a dwarf2_per_cu_offset_and_type. */
23890
23891static hashval_t
23893{
23894 const struct dwarf2_per_cu_offset_and_type *ofs
23895 = (const struct dwarf2_per_cu_offset_and_type *) item;
23896
23897 return (uintptr_t) ofs->per_cu + to_underlying (ofs->sect_off);
23898}
23899
23900/* Equality function for a dwarf2_per_cu_offset_and_type. */
23901
23902static int
23903per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
23904{
23905 const struct dwarf2_per_cu_offset_and_type *ofs_lhs
23906 = (const struct dwarf2_per_cu_offset_and_type *) item_lhs;
23907 const struct dwarf2_per_cu_offset_and_type *ofs_rhs
23908 = (const struct dwarf2_per_cu_offset_and_type *) item_rhs;
23909
23910 return (ofs_lhs->per_cu == ofs_rhs->per_cu
23911 && ofs_lhs->sect_off == ofs_rhs->sect_off);
23912}
23913
23914/* Set the type associated with DIE to TYPE. Save it in CU's hash
23915 table if necessary. For convenience, return TYPE.
23916
23917 The DIEs reading must have careful ordering to:
23918 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23919 reading current DIE.
23920 * Not trying to dereference contents of still incompletely read in types
23921 while reading in other DIEs.
23922 * Enable referencing still incompletely read in types just by a pointer to
23923 the type without accessing its fields.
23924
23925 Therefore caller should follow these rules:
23926 * Try to fetch any prerequisite types we may need to build this DIE type
23927 before building the type and calling set_die_type.
23928 * After building type call set_die_type for current DIE as soon as
23929 possible before fetching more types to complete the current type.
23930 * Make the type as complete as possible before fetching more types. */
23931
23932static struct type *
23933set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
23934 bool skip_data_location)
23935{
23936 dwarf2_per_objfile *per_objfile = cu->per_objfile;
23937 struct dwarf2_per_cu_offset_and_type **slot, ofs;
23938 struct objfile *objfile = per_objfile->objfile;
23939 struct attribute *attr;
23940 struct dynamic_prop prop;
23941
23942 /* For Ada types, make sure that the gnat-specific data is always
23943 initialized (if not already set). There are a few types where
23944 we should not be doing so, because the type-specific area is
23945 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23946 where the type-specific area is used to store the floatformat).
23947 But this is not a problem, because the gnat-specific information
23948 is actually not needed for these types. */
23949 if (need_gnat_info (cu)
23950 && type->code () != TYPE_CODE_FUNC
23951 && type->code () != TYPE_CODE_FLT
23952 && type->code () != TYPE_CODE_METHODPTR
23953 && type->code () != TYPE_CODE_MEMBERPTR
23954 && type->code () != TYPE_CODE_METHOD
23955 && type->code () != TYPE_CODE_FIXED_POINT
23958
23959 /* Read DW_AT_allocated and set in type. */
23960 attr = dwarf2_attr (die, DW_AT_allocated, cu);
23961 if (attr != NULL)
23962 {
23963 struct type *prop_type = cu->addr_sized_int_type (false);
23964 if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
23966 }
23967
23968 /* Read DW_AT_associated and set in type. */
23969 attr = dwarf2_attr (die, DW_AT_associated, cu);
23970 if (attr != NULL)
23971 {
23972 struct type *prop_type = cu->addr_sized_int_type (false);
23973 if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
23975 }
23976
23977 /* Read DW_AT_rank and set in type. */
23978 attr = dwarf2_attr (die, DW_AT_rank, cu);
23979 if (attr != NULL)
23980 {
23981 struct type *prop_type = cu->addr_sized_int_type (false);
23982 if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
23984 }
23985
23986 /* Read DW_AT_data_location and set in type. */
23987 if (!skip_data_location)
23988 {
23989 attr = dwarf2_attr (die, DW_AT_data_location, cu);
23990 if (attr_to_dynamic_prop (attr, die, cu, &prop, cu->addr_type ()))
23992 }
23993
23994 if (per_objfile->die_type_hash == NULL)
23995 per_objfile->die_type_hash
23996 = htab_up (htab_create_alloc (127,
23999 NULL, xcalloc, xfree));
24000
24001 ofs.per_cu = cu->per_cu;
24002 ofs.sect_off = die->sect_off;
24003 ofs.type = type;
24004 slot = (struct dwarf2_per_cu_offset_and_type **)
24005 htab_find_slot (per_objfile->die_type_hash.get (), &ofs, INSERT);
24006 if (*slot)
24007 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24008 sect_offset_str (die->sect_off));
24009 *slot = XOBNEW (&objfile->objfile_obstack,
24011 **slot = ofs;
24012 return type;
24013}
24014
24015/* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24016 or return NULL if the die does not have a saved type. */
24017
24018static struct type *
24019get_die_type_at_offset (sect_offset sect_off,
24020 dwarf2_per_cu_data *per_cu,
24021 dwarf2_per_objfile *per_objfile)
24022{
24023 struct dwarf2_per_cu_offset_and_type *slot, ofs;
24024
24025 if (per_objfile->die_type_hash == NULL)
24026 return NULL;
24027
24028 ofs.per_cu = per_cu;
24029 ofs.sect_off = sect_off;
24030 slot = ((struct dwarf2_per_cu_offset_and_type *)
24031 htab_find (per_objfile->die_type_hash.get (), &ofs));
24032 if (slot)
24033 return slot->type;
24034 else
24035 return NULL;
24036}
24037
24038/* Look up the type for DIE in CU in die_type_hash,
24039 or return NULL if DIE does not have a saved type. */
24040
24041static struct type *
24042get_die_type (struct die_info *die, struct dwarf2_cu *cu)
24043{
24044 return get_die_type_at_offset (die->sect_off, cu->per_cu, cu->per_objfile);
24045}
24046
24049
24050static void
24051show_check_physname (struct ui_file *file, int from_tty,
24052 struct cmd_list_element *c, const char *value)
24053{
24054 gdb_printf (file,
24055 _("Whether to check \"physname\" is %s.\n"),
24056 value);
24057}
24058
24060void
24062{
24064 _("\
24065Set DWARF specific variables.\n\
24066Configure DWARF variables such as the cache size."),
24067 _("\
24068Show DWARF specific variables.\n\
24069Show DWARF variables such as the cache size."),
24072
24073 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
24074 &dwarf_max_cache_age, _("\
24075Set the upper bound on the age of cached DWARF compilation units."), _("\
24076Show the upper bound on the age of cached DWARF compilation units."), _("\
24077A higher limit means that cached compilation units will be stored\n\
24078in memory longer, and more total memory will be used. Zero disables\n\
24079caching, which can slow down startup."),
24080 NULL,
24084
24086Set debugging of the DWARF reader."), _("\
24087Show debugging of the DWARF reader."), _("\
24088When enabled (non-zero), debugging messages are printed during DWARF\n\
24089reading and symtab expansion. A value of 1 (one) provides basic\n\
24090information. A value greater than 1 provides more verbose information."),
24091 NULL,
24092 NULL,
24094
24096Set debugging of the DWARF DIE reader."), _("\
24097Show debugging of the DWARF DIE reader."), _("\
24098When enabled (non-zero), DIEs are dumped after they are read in.\n\
24099The value is the maximum depth to print."),
24100 NULL,
24101 NULL,
24103
24105Set debugging of the dwarf line reader."), _("\
24106Show debugging of the dwarf line reader."), _("\
24107When enabled (non-zero), line number entries are dumped as they are read in.\n\
24108A value of 1 (one) provides basic information.\n\
24109A value greater than 1 provides more verbose information."),
24110 NULL,
24111 NULL,
24113
24114 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
24115Set cross-checking of \"physname\" code against demangler."), _("\
24116Show cross-checking of \"physname\" code against demangler."), _("\
24117When enabled, GDB's internal \"physname\" code is checked against\n\
24118the demangler."),
24119 NULL, show_check_physname,
24121
24122 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24124Set whether to use deprecated gdb_index sections."), _("\
24125Show whether to use deprecated gdb_index sections."), _("\
24126When enabled, deprecated .gdb_index sections are used anyway.\n\
24127Normally they are ignored either because of a missing feature or\n\
24128performance issue.\n\
24129Warning: This option must be enabled before gdb reads the file."),
24130 NULL,
24131 NULL,
24132 &setlist, &showlist);
24133
24138
24143
24144#if GDB_SELF_TEST
24145 selftests::register_test ("dw2_expand_symtabs_matching",
24146 selftests::dw2_expand_symtabs_matching::run_test);
24147 selftests::register_test ("dwarf2_find_containing_comp_unit",
24148 selftests::find_containing_comp_unit::run_test);
24149#endif
24150}
constexpr string_view get()
Definition 70483.cc:49
#define bits(obj, st, fn)
const char *const name
bool operator==(const aarch64_features &lhs, const aarch64_features &rhs)
Definition aarch64.h:41
std::unique_ptr< struct abbrev_table > abbrev_table_up
Definition abbrev.h:61
void * xmalloc(YYSIZE_T)
void xfree(void *)
static struct cache_entry ** find_entry(const char *name, domain_enum domain)
Definition ada-lang.c:4672
int code
Definition ada-lex.l:688
gdb_static_assert(sizeof(splay_tree_key) >=sizeof(CORE_ADDR *))
void * xcalloc(size_t number, size_t size)
Definition alloc.c:85
void f()
Definition 1.cc:36
struct blockranges * make_blockranges(struct objfile *objfile, const std::vector< blockrange > &rangevec)
Definition block.c:877
void block_set_scope(struct block *block, const char *scope, struct obstack *obstack)
Definition block.c:313
int blockvector_contains_pc(const struct blockvector *bv, CORE_ADDR pc)
Definition block.c:215
const struct bfd_build_id * build_id_bfd_get(bfd *abfd)
Definition build-id.c:33
void add_symbol_to_list(struct symbol *symbol, struct pending **listhead)
Definition buildsym.c:125
@ LEF_IS_STMT
Definition buildsym.h:129
@ LEF_PROLOGUE_END
Definition buildsym.h:133
gdb::unique_xmalloc_ptr< char > c_canonicalize_name(const char *name)
Definition c-lang.c:733
void c_type_print_args(struct type *type, struct ui_file *stream, int linkage_name, enum language language, const struct type_print_options *flags)
accessibility
Definition c-varobj.c:672
abbrev_table * find(struct dwarf2_section_info *section, sect_offset offset)
void add(abbrev_table_up table)
bool operator==(const all_units_iterator &other) const
Definition read.c:1412
dwarf2_per_cu_data * operator*() const
Definition read.c:1407
all_units_iterator & operator++()
Definition read.c:1401
dwarf2_per_bfd * m_per_bfd
Definition read.c:1425
bool operator!=(const all_units_iterator &other) const
Definition read.c:1418
all_units_iterator(dwarf2_per_bfd *per_bfd, bool start)
Definition read.c:1395
all_units_iterator end()
Definition read.c:1444
dwarf2_per_bfd * m_per_bfd
Definition read.c:1451
all_units_iterator begin()
Definition read.c:1439
all_units_range(dwarf2_per_bfd *per_bfd)
Definition read.c:1434
cutu_reader * preserve(std::unique_ptr< cutu_reader > reader)
Definition read.c:6635
DISABLE_COPY_AND_ASSIGN(cooked_index_storage)
static int eq_cutu_reader(const void *a, const void *b)
Definition read.c:6683
const cooked_index_entry * add(sect_offset die_offset, enum dwarf_tag tag, cooked_index_flag flags, const char *name, const cooked_index_entry *parent_entry, dwarf2_per_cu_data *per_cu)
Definition read.c:6650
addrmap_mutable * get_addrmap()
Definition read.c:6668
addrmap_mutable m_addrmap
Definition read.c:6698
static hashval_t hash_cutu_reader(const void *a)
Definition read.c:6676
htab_up m_reader_hash
Definition read.c:6693
abbrev_cache * get_abbrev_cache()
Definition read.c:6620
std::unique_ptr< cooked_index > m_index
Definition read.c:6695
abbrev_cache m_abbrev_cache
Definition read.c:6691
std::unique_ptr< cooked_index > release()
Definition read.c:6661
cutu_reader * get_reader(dwarf2_per_cu_data *per_cu)
Definition read.c:6627
dwarf2_per_cu_data * lookup(CORE_ADDR addr)
const cooked_index_entry * get_main() const
quick_symbol_functions_up make_quick_functions() const override
Definition read.c:18821
range find(const std::string &name, bool completing)
void check_bounds(cutu_reader *reader)
Definition read.c:17984
addrmap_mutable m_die_range_map
Definition read.c:6800
cutu_reader * ensure_cu_exists(cutu_reader *reader, dwarf2_per_objfile *per_objfile, sect_offset sect_off, bool is_dwz, bool for_scanning)
Definition read.c:18035
cooked_indexer(cooked_index_storage *storage, dwarf2_per_cu_data *per_cu, enum language language)
Definition read.c:6707
enum language m_language
Definition read.c:6795
const gdb_byte * scan_attributes(dwarf2_per_cu_data *scanning_per_cu, cutu_reader *reader, const gdb_byte *watermark_ptr, const gdb_byte *info_ptr, const abbrev_info *abbrev, const char **name, const char **linkage_name, cooked_index_flag *flags, sect_offset *sibling_offset, const cooked_index_entry **parent_entry, CORE_ADDR *maybe_defer, bool for_specification)
Definition read.c:18084
const gdb_byte * recurse(cutu_reader *reader, const gdb_byte *info_ptr, const cooked_index_entry *parent_entry, bool fully)
Definition read.c:18367
DISABLE_COPY_AND_ASSIGN(cooked_indexer)
dwarf2_per_cu_data * m_per_cu
Definition read.c:6793
const gdb_byte * index_imported_unit(cutu_reader *reader, const gdb_byte *info_ptr, const abbrev_info *abbrev)
Definition read.c:18328
std::vector< deferred_entry > m_deferred_entries
Definition read.c:6819
CORE_ADDR form_addr(sect_offset offset, bool is_dwz)
Definition read.c:6725
void make_index(cutu_reader *reader)
Definition read.c:18543
const gdb_byte * index_dies(cutu_reader *reader, const gdb_byte *info_ptr, const cooked_index_entry *parent_entry, bool fully)
Definition read.c:18387
cooked_index_storage * m_index_storage
Definition read.c:6788
std::unique_ptr< dwarf2_cu > m_new_cu
Definition read.c:765
struct die_info * comp_unit_die
Definition read.c:745
struct dwarf2_per_cu_data * m_this_cu
Definition read.c:764
void keep()
Definition read.c:6398
cutu_reader(dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile, struct abbrev_table *abbrev_table, dwarf2_cu *existing_cu, bool skip_partial, abbrev_cache *cache=nullptr)
Definition read.c:6197
abbrev_table_up m_abbrev_table_holder
Definition read.c:768
DISABLE_COPY_AND_ASSIGN(cutu_reader)
void init_tu_and_read_dwo_dies(dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile, dwarf2_cu *existing_cu)
Definition read.c:6141
const gdb_byte * info_ptr
Definition read.c:744
cutu_reader(cutu_reader &&)=default
abbrev_table_up m_dwo_abbrev_table
Definition read.c:771
abbrev_table_up release_abbrev_table()
Definition read.c:754
bool dummy_p
Definition read.c:746
const gdb_byte * m_addr
Definition read.c:4830
static const gdb_byte * find_vec_in_debug_names(const mapped_debug_names &map, const char *name, dwarf2_per_objfile *per_objfile)
Definition read.c:4853
dw2_debug_names_iterator(const mapped_debug_names &map, block_search_flags block_index, domain_enum domain, const char *name, dwarf2_per_objfile *per_objfile)
Definition read.c:4778
dwarf2_per_cu_data * next()
Definition read.c:4956
const search_domain m_search
Definition read.c:4826
block_search_flags m_block_index
Definition read.c:4821
dw2_debug_names_iterator(const mapped_debug_names &map, block_search_flags block_index, domain_enum domain, uint32_t namei, dwarf2_per_objfile *per_objfile)
Definition read.c:4798
const domain_enum m_domain
Definition read.c:4825
const mapped_debug_names & m_map
Definition read.c:4818
dwarf2_per_objfile * m_per_objfile
Definition read.c:4832
dw2_debug_names_iterator(const mapped_debug_names &map, search_domain search, uint32_t namei, dwarf2_per_objfile *per_objfile, domain_enum domain=UNDEF_DOMAIN)
Definition read.c:4787
dwarf2_queue_guard(dwarf2_per_objfile *per_objfile)
Definition read.c:1238
dwarf2_per_objfile * m_per_objfile
Definition read.c:1258
DISABLE_COPY_AND_ASSIGN(dwarf2_queue_guard)
bool seen(const char *file)
free_cached_comp_units(dwarf2_per_objfile *per_objfile)
Definition read.c:1496
DISABLE_COPY_AND_ASSIGN(free_cached_comp_units)
dwarf2_per_objfile * m_per_objfile
Definition read.c:1510
gdb::array_view< const gdb_byte > lookup_gdb_index(const bfd_build_id *build_id, std::unique_ptr< index_cache_resource > *resource)
void miss()
Definition index-cache.h:84
void store(dwarf2_per_objfile *per_objfile)
Definition index-cache.c:92
void handle_copy()
Definition read.c:20011
void handle_set_address(CORE_ADDR baseaddr, CORE_ADDR address)
Definition read.c:19972
struct dwarf2_cu * m_cu
Definition read.c:20040
unsigned int m_discriminator
Definition read.c:20059
void handle_set_prologue_end()
Definition read.c:20025
void check_line_address(struct dwarf2_cu *cu, const gdb_byte *line_ptr, CORE_ADDR unrelocated_lowpc, CORE_ADDR address)
Definition read.c:20354
lnp_state_machine(struct dwarf2_cu *cu, gdbarch *arch, line_header *lh)
Definition read.c:20330
bool m_line_has_non_zero_discriminator
Definition read.c:20085
bool m_stmt_at_address
Definition read.c:20076
file_name_index m_file
Definition read.c:20052
unsigned int m_line
Definition read.c:20053
unsigned int m_last_line
Definition read.c:20084
gdbarch * m_gdbarch
Definition read.c:20042
bool m_currently_recording_lines
Definition read.c:20079
void handle_advance_pc(CORE_ADDR adjust)
Definition read.c:20089
void handle_negate_stmt()
Definition read.c:19995
unsigned int m_last_file
Definition read.c:20065
void record_line(bool end_sequence)
Definition read.c:20246
linetable_entry_flags m_flags
Definition read.c:20058
void handle_set_discriminator(unsigned int discriminator)
Definition read.c:19965
void advance_line(int line_delta)
Definition read.c:20032
void handle_fixed_advance_pc(CORE_ADDR addr_adj)
Definition read.c:20004
struct subfile * m_last_subfile
Definition read.c:20067
void handle_special_opcode(unsigned char op_code)
Definition read.c:20100
unsigned char m_op_index
Definition read.c:20050
void handle_advance_line(int line_delta)
Definition read.c:19986
void handle_end_sequence()
Definition read.c:20019
line_header * m_line_header
Definition read.c:20045
void handle_set_file(file_name_index file)
Definition read.c:20120
file_entry * current_file()
Definition read.c:19948
CORE_ADDR m_last_address
Definition read.c:20070
void handle_const_add_pc()
Definition read.c:20136
CORE_ADDR m_address
Definition read.c:20057
std::vector< gdb::string_view > split_name(language lang) const
Definition symtab.h:294
const char * language_lookup_name(language lang) const
Definition symtab.h:275
symbol_name_match_type match_type() const
Definition symtab.h:238
lookup_name_info make_ignore_params() const
Definition symtab.h:255
bool completion_mode() const
Definition symtab.h:239
offset_view()=default
offset_type operator[](size_t index) const
Definition read.c:176
offset_view(gdb::array_view< const gdb_byte > bytes)
Definition read.c:170
size_t size() const
Definition read.c:185
bool empty() const
Definition read.c:191
gdb::array_view< const gdb_byte > m_bytes
Definition read.c:198
dwarf2_cu * m_cu
Definition read.c:8662
die_info * m_die
Definition read.c:8661
process_die_scope(die_info *die, dwarf2_cu *cu)
Definition read.c:8638
void set(unsigned key, void *datum)
Definition registry.h:204
void * get(unsigned key)
Definition registry.h:211
const std::string & string()
Definition ui-file.h:194
bool empty() const
Definition ui-file.h:220
virtual void puts(const char *str)
Definition ui-file.h:74
struct cmd_list_element * showlist
Definition cli-cmds.c:125
struct cmd_list_element * setlist
Definition cli-cmds.c:117
struct cmd_list_element * showdebuglist
Definition cli-cmds.c:165
struct cmd_list_element * setdebuglist
Definition cli-cmds.c:163
struct cmd_list_element * maintenance_show_cmdlist
Definition maint.c:752
struct cmd_list_element * maintenance_set_cmdlist
Definition maint.c:751
set_show_commands add_setshow_zinteger_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_prefix_cmd(const char *name, command_class theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, cmd_list_element **set_list, cmd_list_element **show_list)
Definition cli-decode.c:428
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:739
set_show_commands add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
@ class_obscure
Definition command.h:64
@ class_maintenance
Definition command.h:65
@ no_class
Definition command.h:53
const gdb_byte * read_and_check_comp_unit_head(dwarf2_per_objfile *per_objfile, struct comp_unit_head *header, struct dwarf2_section_info *section, struct dwarf2_section_info *abbrev_section, const gdb_byte *info_ptr, rcuh_kind section_kind)
const gdb_byte * read_comp_unit_head(struct comp_unit_head *cu_header, const gdb_byte *info_ptr, struct dwarf2_section_info *section, rcuh_kind section_kind)
rcuh_kind
#define complaint(FMT,...)
Definition complaints.h:47
static bool have_complaint()
Definition complaints.h:38
bool language_requires_canonicalization(enum language lang)
@ IS_TYPE_DECLARATION
@ IS_STATIC
@ IS_LINKAGE
@ IS_MAIN
@ IS_ENUM_CLASS
const char * gnutarget
Definition corefile.c:394
void cp_scan_for_anonymous_namespaces(struct buildsym_compunit *compunit, const struct symbol *const symbol, struct objfile *const objfile)
gdb::unique_xmalloc_ptr< char > gdb_demangle(const char *name, int options)
gdb::unique_xmalloc_ptr< char > cp_remove_params(const char *demangled_name)
Definition cp-support.c:958
unsigned int cp_find_first_component(const char *name)
gdb::unique_xmalloc_ptr< char > cp_canonicalize_string(const char *string)
Definition cp-support.c:626
#define CP_ANONYMOUS_NAMESPACE_STR
Definition cp-support.h:45
std::string debug_file_directory
Definition symfile.c:1355
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition defs.h:561
#define O_BINARY
Definition defs.h:116
block_enum
Definition defs.h:630
@ STATIC_BLOCK
Definition defs.h:632
@ GLOBAL_BLOCK
Definition defs.h:631
language
Definition defs.h:211
@ language_ada
Definition defs.h:226
@ language_m2
Definition defs.h:220
@ language_unknown
Definition defs.h:212
@ language_minimal
Definition defs.h:225
@ language_cplus
Definition defs.h:216
@ language_go
Definition defs.h:218
@ language_asm
Definition defs.h:221
@ language_fortran
Definition defs.h:219
@ language_opencl
Definition defs.h:223
@ language_pascal
Definition defs.h:222
@ language_rust
Definition defs.h:224
@ language_c
Definition defs.h:214
@ language_d
Definition defs.h:217
@ nr_languages
Definition defs.h:227
@ language_objc
Definition defs.h:215
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:526
#define QUIT
Definition defs.h:186
struct dwz_file * dwarf2_get_dwz_file(dwarf2_per_bfd *per_bfd, bool require)
Definition dwz.c:188
void exception_print(struct ui_file *file, const struct gdb_exception &e)
Definition exceptions.c:105
const gdb_byte * safe_skip_leb128(const gdb_byte *buf, const gdb_byte *buf_end)
Definition expr.c:1274
int dwarf_block_to_sp_offset(struct gdbarch *gdbarch, const gdb_byte *buf, const gdb_byte *buf_end, CORE_ADDR *sp_offset_return)
Definition expr.c:1446
const gdb_byte * safe_read_uleb128(const gdb_byte *buf, const gdb_byte *buf_end, uint64_t *r)
Definition expr.c:1252
int dwarf_block_to_dwarf_reg(const gdb_byte *buf, const gdb_byte *buf_end)
Definition expr.c:1317
static const gdb_byte * gdb_read_uleb128(const gdb_byte *buf, const gdb_byte *buf_end, uint64_t *r)
Definition expr.h:281
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2592
bool is_cplus_marker(int c)
int gdb_bfd_requires_relocations(bfd *abfd)
Definition gdb_bfd.c:1006
void gdb_bfd_record_inclusion(bfd *includer, bfd *includee)
Definition gdb_bfd.c:965
gdb_bfd_ref_ptr gdb_bfd_open(const char *name, const char *target, int fd, bool warn_if_slow)
Definition gdb_bfd.c:491
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
Definition gdb_bfd.h:78
static gdb_bfd_section_range gdb_bfd_sections(bfd *abfd)
Definition gdb_bfd.h:222
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1370
bool gdbarch_address_class_type_flags_p(struct gdbarch *gdbarch)
Definition gdbarch.c:3515
bfd * obfd
const struct floatformat ** gdbarch_floatformat_for_type(struct gdbarch *gdbarch, const char *name, int length)
Definition gdbarch.c:1674
void gdbarch_make_symbol_special(struct gdbarch *gdbarch, struct symbol *sym, struct objfile *objfile)
Definition gdbarch.c:3430
CORE_ADDR gdbarch_adjust_dwarf2_line(struct gdbarch *gdbarch, CORE_ADDR addr, int rel)
Definition gdbarch.c:3464
CORE_ADDR gdbarch_adjust_dwarf2_addr(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition gdbarch.c:3447
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition gdbarch.c:3087
type_instance_flags gdbarch_address_class_type_flags(struct gdbarch *gdbarch, int byte_size, int dwarf2_addr_class)
Definition gdbarch.c:3522
void set_type_vptr_basetype(struct type *type, struct type *basetype)
Definition gdbtypes.c:2001
void set_type_vptr_fieldno(struct type *type, int fieldno)
Definition gdbtypes.c:1975
struct type * create_string_type(struct type *result_type, struct type *string_char_type, struct type *range_type)
Definition gdbtypes.c:1461
struct type * make_restrict_type(struct type *type)
Definition gdbtypes.c:759
struct type * lookup_pointer_type(struct type *type)
Definition gdbtypes.c:402
struct type * lookup_methodptr_type(struct type *to_type)
Definition gdbtypes.c:855
bool set_type_align(struct type *type, ULONGEST align)
Definition gdbtypes.c:3737
struct type * init_decfloat_type(struct objfile *objfile, int bit, const char *name)
Definition gdbtypes.c:3545
struct type * create_array_type_with_stride(struct type *result_type, struct type *element_type, struct type *range_type, struct dynamic_prop *byte_stride_prop, unsigned int bit_stride)
Definition gdbtypes.c:1368
struct type * init_type(struct objfile *objfile, enum type_code code, int bit, const char *name)
Definition gdbtypes.c:3430
struct type * init_fixed_point_type(struct objfile *objfile, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3620
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
Definition gdbtypes.c:714
struct type * lookup_function_type(struct type *type)
Definition gdbtypes.c:539
struct type * make_type_with_address_space(struct type *type, type_instance_flags space_flag)
Definition gdbtypes.c:689
struct type * lookup_reference_type(struct type *type, enum type_code refcode)
Definition gdbtypes.c:482
void smash_to_method_type(struct type *type, struct type *self_type, struct type *to_type, struct field *args, int nargs, int varargs)
Definition gdbtypes.c:1652
void smash_to_methodptr_type(struct type *type, struct type *to_type)
Definition gdbtypes.c:1635
struct type * lookup_memberptr_type(struct type *type, struct type *domain)
Definition gdbtypes.c:843
struct type * init_pointer_type(struct objfile *objfile, int bit, const char *name, struct type *target_type)
Definition gdbtypes.c:3603
unsigned type_align(struct type *type)
Definition gdbtypes.c:3645
struct type * create_range_type_with_stride(struct type *result_type, struct type *index_type, const struct dynamic_prop *low_bound, const struct dynamic_prop *high_bound, LONGEST bias, const struct dynamic_prop *stride, bool byte_stride_p)
Definition gdbtypes.c:994
struct type * alloc_type(struct objfile *objfile)
Definition gdbtypes.c:181
struct type * init_complex_type(const char *name, struct type *target_type)
Definition gdbtypes.c:3566
struct type * init_float_type(struct objfile *objfile, int bit, const char *name, const struct floatformat **floatformats, enum bfd_endian byte_order)
Definition gdbtypes.c:3521
struct type * create_static_range_type(struct type *result_type, struct type *index_type, LONGEST low_bound, LONGEST high_bound)
Definition gdbtypes.c:1025
struct type * init_character_type(struct objfile *objfile, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3480
struct type * create_set_type(struct type *result_type, struct type *domain_type)
Definition gdbtypes.c:1485
struct type * init_boolean_type(struct objfile *objfile, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3497
struct type * make_atomic_type(struct type *type)
Definition gdbtypes.c:783
struct type * create_range_type(struct type *result_type, struct type *index_type, const struct dynamic_prop *low_bound, const struct dynamic_prop *high_bound, LONGEST bias)
Definition gdbtypes.c:931
struct type * init_integer_type(struct objfile *objfile, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3459
struct type * copy_type(const struct type *type)
Definition gdbtypes.c:5790
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:3010
void make_vector_type(struct type *array_type)
Definition gdbtypes.c:1517
@ TYPE_SPECIFIC_FIXED_POINT
Definition gdbtypes.h:521
@ TYPE_SPECIFIC_INT
Definition gdbtypes.h:520
#define TYPE_ZALLOC(t, size)
Definition gdbtypes.h:2415
#define TYPE_FN_FIELD_PHYSNAME(thisfn, n)
Definition gdbtypes.h:2169
#define TYPE_NFN_FIELDS(thistype)
Definition gdbtypes.h:2086
#define TYPE_CPLUS_DYNAMIC(thistype)
Definition gdbtypes.h:2113
#define TYPE_DESCRIPTIVE_TYPE(thistype)
Definition gdbtypes.h:2103
@ PROP_CONST
Definition gdbtypes.h:293
#define TYPE_FN_FIELDLIST(thistype, n)
Definition gdbtypes.h:2156
#define TYPE_TEMPLATE_ARGUMENTS(thistype)
Definition gdbtypes.h:2163
#define TYPE_NESTED_TYPES_COUNT(thistype)
Definition gdbtypes.h:2210
#define B_BYTES(x)
Definition gdbtypes.h:92
#define TYPE_FIELD_VIRTUAL_BITS(thistype)
Definition gdbtypes.h:2132
#define ALLOCATE_CPLUS_STRUCT_TYPE(type)
Definition gdbtypes.h:1985
#define TYPE_FIELD_PRIVATE_BITS(thistype)
Definition gdbtypes.h:2126
@ FIELD_LOC_KIND_BITPOS
Definition gdbtypes.h:493
@ FIELD_LOC_KIND_ENUMVAL
Definition gdbtypes.h:494
#define SET_TYPE_FIELD_PROTECTED(thistype, n)
Definition gdbtypes.h:2136
#define B_TYPE
Definition gdbtypes.h:91
#define B_CLRALL(a, x)
Definition gdbtypes.h:93
#define TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
Definition gdbtypes.h:207
#define TYPE_MAIN_TYPE(thistype)
Definition gdbtypes.h:2027
#define FIELD_ARTIFICIAL(thisfld)
Definition gdbtypes.h:2119
#define TYPE_FN_FIELDLISTS(thistype)
Definition gdbtypes.h:2155
#define TYPE_NESTED_TYPES_FIELD(thistype, n)
Definition gdbtypes.h:2204
#define TYPE_FN_FIELD_VOLATILE(thisfn, n)
Definition gdbtypes.h:2173
#define ALLOCATE_GNAT_AUX_TYPE(type)
Definition gdbtypes.h:2002
#define TYPE_CALLING_CONVENTION(thistype)
Definition gdbtypes.h:2104
static char * sect_offset_str(sect_offset offset)
Definition gdbtypes.h:81
#define TYPE_CONST(t)
Definition gdbtypes.h:134
#define TYPE_VOLATILE(t)
Definition gdbtypes.h:139
#define VOFFSET_STATIC
Definition gdbtypes.h:1548
type_code
Definition gdbtypes.h:99
#define TYPE_FN_FIELDLIST_LENGTH(thistype, n)
Definition gdbtypes.h:2159
#define TYPE_N_TEMPLATE_ARGUMENTS(thistype)
Definition gdbtypes.h:2161
#define TYPE_VPTR_FIELDNO(thistype)
Definition gdbtypes.h:2083
#define TYPE_FIELD_ARTIFICIAL(thistype, n)
Definition gdbtypes.h:2122
#define TYPE_TAIL_CALL_LIST(thistype)
Definition gdbtypes.h:2106
#define TYPE_RAW_ALIGN(thistype)
Definition gdbtypes.h:2035
#define TYPE_SPECIFIC_FIELD(thistype)
Definition gdbtypes.h:2087
#define TYPE_NO_RETURN(thistype)
Definition gdbtypes.h:2105
#define TYPE_TEMPLATE_ARGUMENT(thistype, n)
Definition gdbtypes.h:2165
#define TYPE_TYPEDEF_FIELD(thistype, n)
Definition gdbtypes.h:2189
#define INIT_GNAT_SPECIFIC(type)
Definition gdbtypes.h:1999
@ CALL_SITE_PARAMETER_FB_OFFSET
Definition gdbtypes.h:1762
@ CALL_SITE_PARAMETER_DWARF_REG
Definition gdbtypes.h:1759
@ CALL_SITE_PARAMETER_PARAM_OFFSET
Definition gdbtypes.h:1765
#define INIT_CPLUS_SPECIFIC(type)
Definition gdbtypes.h:1980
#define TYPE_CPLUS_CALLING_CONVENTION(thistype)
Definition gdbtypes.h:2099
#define TYPE_TYPEDEF_FIELD_COUNT(thistype)
Definition gdbtypes.h:2195
#define TYPE_FN_FIELDLIST_NAME(thistype, n)
Definition gdbtypes.h:2158
#define TYPE_NESTED_TYPES_ARRAY(thistype)
Definition gdbtypes.h:2202
#define TYPE_FIELD_PROTECTED_BITS(thistype)
Definition gdbtypes.h:2128
#define TYPE_ALLOC(t, size)
Definition gdbtypes.h:2406
#define TYPE_TYPEDEF_FIELD_ARRAY(thistype)
Definition gdbtypes.h:2187
#define SET_TYPE_FIELD_PRIVATE(thistype, n)
Definition gdbtypes.h:2134
#define TYPE_N_BASECLASSES(thistype)
Definition gdbtypes.h:2108
@ DYN_PROP_VARIANT_PARTS
Definition gdbtypes.h:465
@ DYN_PROP_ASSOCIATED
Definition gdbtypes.h:459
@ DYN_PROP_RANK
Definition gdbtypes.h:469
@ DYN_PROP_BYTE_SIZE
Definition gdbtypes.h:472
@ DYN_PROP_DATA_LOCATION
Definition gdbtypes.h:451
@ DYN_PROP_ALLOCATED
Definition gdbtypes.h:455
#define HAVE_GNAT_AUX_INFO(type)
Definition gdbtypes.h:2005
#define TYPE_FN_FIELD_CONST(thisfn, n)
Definition gdbtypes.h:2172
#define SET_TYPE_FIELD_VIRTUAL(thistype, n)
Definition gdbtypes.h:2140
#define TYPE_FIELD_IGNORE_BITS(thistype)
Definition gdbtypes.h:2130
#define FIELD_BITSIZE(thisfld)
Definition gdbtypes.h:2120
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1862
char * go_symbol_package_name(const struct symbol *sym)
Definition go-lang.c:388
unsigned dummy
Definition go32-nat.c:8
size_t size
Definition go32-nat.c:241
index_cache global_index_cache
Definition index-cache.c:48
uint32_t dwarf5_djb_hash(const char *str_)
uint32_t offset_type
const struct language_defn * language_def(enum language lang)
Definition language.c:442
const struct language_defn * current_language
Definition language.c:83
struct type * language_string_char_type(const struct language_defn *la, struct gdbarch *gdbarch)
Definition language.c:925
@ array_row_major
Definition language.h:62
@ array_column_major
Definition language.h:62
case_sensitivity
Definition language.h:72
@ case_sensitive_on
Definition language.h:73
LONGEST read_signed_leb128(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read_ptr)
Definition leb.c:59
LONGEST read_initial_length(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read, bool handle_nonstd)
Definition leb.c:90
ULONGEST read_unsigned_leb128(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read_ptr)
Definition leb.c:31
LONGEST read_offset(bfd *abfd, const gdb_byte *buf, unsigned int offset_size)
Definition leb.c:117
static unsigned int read_4_bytes(bfd *abfd, const gdb_byte *buf)
Definition leb.h:64
static const char * read_direct_string(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read_ptr)
Definition leb.h:141
static int read_4_signed_bytes(bfd *abfd, const gdb_byte *buf)
Definition leb.h:70
static unsigned int read_1_byte(bfd *abfd, const gdb_byte *buf)
Definition leb.h:33
static unsigned int read_3_bytes(bfd *abfd, const gdb_byte *buf)
Definition leb.h:58
static int read_1_signed_byte(bfd *abfd, const gdb_byte *buf)
Definition leb.h:39
static unsigned int read_2_bytes(bfd *abfd, const gdb_byte *buf)
Definition leb.h:45
static int read_2_signed_bytes(bfd *abfd, const gdb_byte *buf)
Definition leb.h:51
static const gdb_byte * read_n_bytes(bfd *abfd, const gdb_byte *buf, unsigned int size)
Definition leb.h:131
static ULONGEST read_8_bytes(bfd *abfd, const gdb_byte *buf)
Definition leb.h:76
line_header_up dwarf_decode_line_header(sect_offset sect_off, bool is_dwz, dwarf2_per_objfile *per_objfile, struct dwarf2_section_info *section, const struct comp_unit_head *cu_header, const char *comp_dir)
int file_name_index
Definition line-header.h:31
std::unique_ptr< line_header > line_header_up
int dir_index
Definition line-header.h:27
struct value * dwarf2_evaluate_loc_desc(struct type *type, frame_info_ptr frame, const gdb_byte *data, size_t size, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, bool as_lval)
Definition loc.c:1552
const gdb_byte * dwarf2_find_location_expression(struct dwarf2_loclist_baton *baton, size_t *locexpr_length, CORE_ADDR pc)
Definition loc.c:350
const struct symbol_computed_ops dwarf2_loclist_funcs
Definition loc.c:4098
const struct symbol_computed_ops dwarf2_locexpr_funcs
Definition loc.c:3857
const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
Definition loc.c:525
const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
Definition loc.c:582
static struct type * new_type(char *)
bound_minimal_symbol lookup_minimal_symbol_linkage(const char *name, struct objfile *objf)
Definition minsyms.c:573
void add_using_directive(struct using_direct **using_directives, const char *dest, const char *src, const char *alias, const char *declaration, const std::vector< const char * > &excludes, int copy_names, struct obstack *obstack)
Definition namespace.c:37
Definition aarch64.h:50
@ OBJF_READNEVER
@ OBJF_MAINLINE
@ OBJF_READNOW
void set_objfile_main_name(struct objfile *objfile, const char *name, enum language lang)
Definition objfiles.c:152
struct type * objfile_int_type(struct objfile *of, int size_in_bytes, bool unsigned_p)
Definition objfiles.c:1348
const char * objfile_name(const struct objfile *objfile)
Definition objfiles.c:1308
#define SECT_OFF_TEXT(objfile)
Definition objfiles.h:148
#define OBJSTAT(objfile, expr)
Definition objfiles.h:178
#define prefix(a, b, R, do)
Definition ppc64-tdep.c:52
int producer_is_gcc(const char *producer, int *major, int *minor)
Definition producer.c:44
int producer_is_gcc_ge_4(const char *producer)
Definition producer.c:28
static void set_type(type_object *obj, struct type *type)
Definition py-type.c:1123
int() symbol_compare_ftype(const char *string1, const char *string2)
@ SEARCH_GLOBAL_BLOCK
@ SEARCH_STATIC_BLOCK
std::unique_ptr< quick_symbol_functions > quick_symbol_functions_up
static struct dwo_unit * lookup_dwo_unit(dwarf2_cu *cu, die_info *comp_unit_die, const char *dwo_name)
Definition read.c:6099
static int eq_dwo_unit(const void *item_lhs, const void *item_rhs)
Definition read.c:9943
static void dwarf2_attach_fn_fields_to_type(struct field_info *, struct type *, struct dwarf2_cu *)
Definition read.c:14317
static void create_signatured_type_table_from_debug_names(dwarf2_per_objfile *per_objfile, const mapped_debug_names &map, struct dwarf2_section_info *section, struct dwarf2_section_info *abbrev_section)
Definition read.c:2223
static const char * dwarf2_full_name(const char *name, struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:9130
static struct dwp_hash_table * create_dwp_hash_table(dwarf2_per_objfile *per_objfile, struct dwp_file *dwp_file, int is_debug_types)
Definition read.c:10224
static void process_full_type_unit(dwarf2_cu *cu, enum language pretend_language)
Definition read.c:8525
static void queue_comp_unit(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, enum language pretend_language)
Definition read.c:7563
static void dw2_get_file_names_reader(const struct die_reader_specs *reader, struct die_info *comp_unit_die)
Definition read.c:2741
#define RUST_ENUM_PREFIX
static struct die_info * follow_die_ref(struct die_info *, const struct attribute *, struct dwarf2_cu **)
Definition read.c:22456
static int handle_member_location(struct die_info *die, struct dwarf2_cu *cu, LONGEST *offset)
Definition read.c:13456
static void dwarf2_build_psymtabs_hard(dwarf2_per_objfile *per_objfile)
Definition read.c:7091
static const registry< bfd >::key< dwarf2_per_bfd > dwarf2_per_bfd_bfd_data_key
Definition read.c:138
static void dwarf2_symbol_mark_computed(const struct attribute *attr, struct symbol *sym, struct dwarf2_cu *cu, int is_block)
Definition read.c:23494
static void dwarf2_get_subprogram_pc_bounds(struct die_info *die, CORE_ADDR *lowpc, CORE_ADDR *highpc, struct dwarf2_cu *cu)
Definition read.c:13188
static int queue_and_load_dwo_tu(void **slot, void *info)
Definition read.c:11800
static void compute_delayed_physnames(struct dwarf2_cu *cu)
Definition read.c:7822
static int eq_file_name_entry(const void *a, const void *b)
Definition read.c:1992
gdb::function_view< gdb::array_view< const gdb_byte >(objfile *, dwarf2_per_bfd *)> get_gdb_index_contents_ftype
Definition read.c:2640
static struct using_direct ** using_directives(struct dwarf2_cu *cu)
Definition read.c:9309
static void process_structure_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:14926
CORE_ADDR dwarf2_read_addr_index(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, unsigned int addr_index)
Definition read.c:19453
static ULONGEST lookup_loclist_base(struct dwarf2_cu *cu)
Definition read.c:18858
static void process_die(struct die_info *, struct dwarf2_cu *)
Definition read.c:8668
static void dwarf2_invalid_attrib_class_complaint(const char *arg1, const char *arg2)
Definition read.c:1349
static const gdb_byte * read_attribute_value(const struct die_reader_specs *reader, struct attribute *attr, unsigned form, LONGEST implicit_const, const gdb_byte *info_ptr)
Definition read.c:19058
static struct dwo_unit * lookup_dwo_unit_in_dwp(dwarf2_per_objfile *per_objfile, struct dwp_file *dwp_file, const char *comp_dir, ULONGEST signature, int is_debug_types)
Definition read.c:11063
pc_bounds_kind
Definition read.c:1027
@ PC_BOUNDS_RANGES
Definition read.c:1036
@ PC_BOUNDS_INVALID
Definition read.c:1033
@ PC_BOUNDS_NOT_PRESENT
Definition read.c:1029
@ PC_BOUNDS_HIGH_LOW
Definition read.c:1039
static bool ada_get_gnat_encoded_ratio(const char *encoding, int &offset, gdb_mpz *num, gdb_mpz *denom)
Definition read.c:16902
static bool dw2_expand_symtabs_matching_symbol(mapped_index_base &index, const lookup_name_info &lookup_name_in, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< bool(offset_type)> match_callback, dwarf2_per_objfile *per_objfile)
Definition read.c:3416
static void create_debug_types_hash_table(dwarf2_per_objfile *per_objfile, struct dwo_file *dwo_file, gdb::array_view< dwarf2_section_info > type_sections, htab_up &types_htab)
Definition read.c:5651
static const char * read_dwo_str_index(const struct die_reader_specs *reader, ULONGEST str_index)
Definition read.c:19540
static void rust_union_quirks(struct dwarf2_cu *cu)
Definition read.c:8254
gdb::function_view< gdb::array_view< const gdb_byte >(objfile *, dwz_file *)> get_gdb_index_contents_dwz_ftype
Definition read.c:2643
static void process_full_comp_unit(dwarf2_cu *cu, enum language pretend_language)
Definition read.c:8413
static hashval_t hash_dwo_file(const void *item)
Definition read.c:9876
static bool producer_is_gcc_lt_4_3(struct dwarf2_cu *cu)
Definition read.c:9495
static struct type * get_die_type_at_offset(sect_offset, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:24019
static bool producer_is_icc(struct dwarf2_cu *cu)
Definition read.c:9482
static struct die_info * follow_die_offset(sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu **ref_cu)
Definition read.c:22385
static struct signatured_type * lookup_dwo_signatured_type(struct dwarf2_cu *cu, ULONGEST sig)
Definition read.c:5734
#define MAX_NR_V2_DWO_SECTIONS
Definition read.c:623
static void read_lexical_block_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:12238
static struct type * read_tag_atomic_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16416
static void dwarf2_add_member_fn(struct field_info *, struct die_info *, struct type *, struct dwarf2_cu *)
Definition read.c:14122
static struct dwo_unit * create_dwo_unit_in_dwp_v2(dwarf2_per_objfile *per_objfile, struct dwp_file *dwp_file, uint32_t unit_index, const char *comp_dir, ULONGEST signature, int is_debug_types)
Definition read.c:10724
static enum language dwarf_lang_to_enum_language(unsigned int lang)
Definition read.c:19638
static struct type * read_structure_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14616
static gdb::array_view< const gdb_byte > get_gdb_index_contents_from_cache(objfile *obj, dwarf2_per_bfd *dwarf2_per_bfd)
Definition read.c:5329
static bool create_cus_from_debug_names_list(dwarf2_per_bfd *per_bfd, const mapped_debug_names &map, dwarf2_section_info &section, bool is_dwz)
Definition read.c:4610
static bool type_can_define_types(const struct die_info *die)
Definition read.c:13751
static struct type * read_tag_reference_type(struct die_info *die, struct dwarf2_cu *cu, enum type_code refcode)
Definition read.c:16296
static struct compunit_symtab * dw2_instantiate_symtab(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, bool skip_partial)
Definition read.c:2077
static void read_loclists_rnglists_header(struct loclists_rnglists_header *header, struct dwarf2_section_info *section, sect_offset header_offset)
Definition read.c:18833
static gdb_byte * dwarf2_const_value_data(const struct attribute *attr, struct obstack *obstack, struct dwarf2_cu *cu, LONGEST *value, int bits)
Definition read.c:21199
#define LOCLIST_HEADER_SIZE64
Definition read.c:153
static void dwarf2_const_value_length_mismatch_complaint(const char *arg1, int arg2, int arg3)
Definition read.c:1341
static struct dwo_unit * lookup_dwo_type_unit(dwarf2_cu *cu, const char *dwo_name, const char *comp_dir)
Definition read.c:11788
static gdb_bfd_ref_ptr open_dwp_file(dwarf2_per_objfile *per_objfile, const char *file_name)
Definition read.c:11500
static struct compunit_symtab * recursively_find_pc_sect_compunit_symtab(struct compunit_symtab *cust, CORE_ADDR pc)
Definition read.c:4249
static const char * determine_prefix(struct die_info *die, struct dwarf2_cu *)
Definition read.c:21765
static void load_full_comp_unit(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, dwarf2_cu *existing_cu, bool skip_partial, enum language pretend_language)
Definition read.c:7739
static struct type * set_die_type(struct die_info *, struct type *, struct dwarf2_cu *, bool=false)
Definition read.c:23933
static struct attribute * dw2_linkage_name_attr(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:8849
static void show_dwarf_max_cache_age(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition read.c:880
static hashval_t die_hash(const void *item)
Definition read.c:7712
dwp_v2_section_ids
Definition read.c:475
@ DW_SECT_MIN
Definition read.c:476
static dwarf2_cu * load_cu(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, bool skip_partial)
Definition read.c:2015
static void maybe_set_alignment(struct dwarf2_cu *cu, struct die_info *die, struct type *type)
Definition read.c:14547
static const gdb_byte * write_constant_as_bytes(struct obstack *obstack, enum bfd_endian byte_order, struct type *type, ULONGEST value, LONGEST *len)
Definition read.c:22599
static const gdb_byte * skip_one_die(const struct die_reader_specs *reader, const gdb_byte *info_ptr, const struct abbrev_info *abbrev, bool do_skip_children=true)
Definition read.c:7402
static void read_comp_units_from_section(dwarf2_per_objfile *per_objfile, struct dwarf2_section_info *section, struct dwarf2_section_info *abbrev_section, unsigned int is_dwz, htab_up &types_htab, rcuh_kind section_kind)
Definition read.c:7207
static void dwarf2_add_field(struct field_info *, struct die_info *, struct dwarf2_cu *)
Definition read.c:13565
static hashval_t hash_dwp_loaded_cutus(const void *item)
Definition read.c:11463
static void dwarf2_locate_dwo_sections(struct objfile *objfile, bfd *abfd, asection *sectp, dwo_sections *dwo_sections)
Definition read.c:11248
static struct dwo_unit * create_dwo_unit_in_dwp_v1(dwarf2_per_objfile *per_objfile, struct dwp_file *dwp_file, uint32_t unit_index, const char *comp_dir, ULONGEST signature, int is_debug_types)
Definition read.c:10535
static sect_offset read_abbrev_offset(dwarf2_per_objfile *per_objfile, dwarf2_section_info *, sect_offset)
Definition read.c:5489
static struct type * die_containing_type(struct die_info *, struct dwarf2_cu *)
Definition read.c:21435
static struct type * read_module_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16118
static void ** lookup_dwo_file_slot(dwarf2_per_objfile *per_objfile, const char *dwo_name, const char *comp_dir)
Definition read.c:9915
static struct type * get_die_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:24042
static void dwarf2_add_type_defn(struct field_info *fip, struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:13770
static gdb_bfd_ref_ptr try_open_dwop_file(dwarf2_per_objfile *per_objfile, const char *file_name, int is_dwp, int search_cwd)
Definition read.c:11143
static struct dwarf2_per_cu_data * dw2_symtab_iter_next(struct dw2_symtab_iterator *iter, mapped_index &index)
Definition read.c:2981
static int line_header_eq_voidp(const void *item_lhs, const void *item_rhs)
Definition read.c:1376
static bool read_debug_names_from_section(struct objfile *objfile, const char *filename, struct dwarf2_section_info *section, mapped_debug_names &map)
Definition read.c:4429
static std::unique_ptr< type_unit_group > create_type_unit_group(struct dwarf2_cu *cu, sect_offset line_offset_struct)
Definition read.c:6536
static struct dwo_unit * lookup_dwo_cutu(dwarf2_cu *cu, const char *dwo_name, const char *comp_dir, ULONGEST signature, int is_debug_types)
Definition read.c:11661
static void show_check_physname(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition read.c:24051
static void read_import_statement(struct die_info *die, struct dwarf2_cu *)
Definition read.c:9321
static std::string make_sort_after_prefix_name(const char *search_name)
Definition read.c:3190
static struct type * rust_containing_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:12663
static hashval_t hash_type_unit_group(const void *item)
Definition read.c:6497
static ULONGEST get_alignment(struct dwarf2_cu *cu, struct die_info *die)
Definition read.c:14496
static void dwarf2_ranges_read_low_addrs(unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag, std::vector< CORE_ADDR > &result)
Definition read.c:13090
static int leb128_size(const gdb_byte *buf)
Definition read.c:19624
static sect_offset read_rnglist_index(struct dwarf2_cu *cu, ULONGEST rnglist_index, dwarf_tag tag)
Definition read.c:18940
static int eq_type_unit_group(const void *item_lhs, const void *item_rhs)
Definition read.c:6506
const gdb_byte * dwarf2_fetch_constant_bytes(sect_offset sect_off, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, obstack *obstack, LONGEST *len)
Definition read.c:22617
static void inherit_abstract_dies(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:11852
static void handle_DW_AT_stmt_list(struct die_info *die, struct dwarf2_cu *cu, const file_and_directory &fnd, CORE_ADDR lowpc, bool have_code)
Definition read.c:9543
static struct type * read_type_die(struct die_info *, struct dwarf2_cu *)
Definition read.c:21550
static struct type * read_subroutine_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16575
static int dwarf2_loclist_index
Definition read.c:145
static bool producer_is_codewarrior(struct dwarf2_cu *cu)
Definition read.c:13400
#define MAX_NESTED_IMPORTED_DECLARATIONS
static void read_type_unit_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:9844
static bool read_addrmap_from_aranges(dwarf2_per_objfile *per_objfile, struct dwarf2_section_info *section, addrmap *mutable_map)
Definition read.c:2325
static void check_producer(struct dwarf2_cu *cu)
Definition read.c:13343
static void fixup_go_packaging(struct dwarf2_cu *cu)
Definition read.c:7875
bool producer_is_clang(struct dwarf2_cu *cu)
Definition read.c:9505
static struct attribute * dwarf2_attr(struct die_info *, unsigned int, struct dwarf2_cu *)
Definition read.c:19706
static struct dwarf2_section_info create_dwp_v2_or_v5_section(dwarf2_per_objfile *per_objfile, struct dwarf2_section_info *section, bfd_size_type offset, bfd_size_type size)
Definition read.c:10682
static htab_up create_quick_file_names_table(unsigned int nr_initial_entries)
Definition read.c:2003
static struct type * read_enumeration_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:15221
static struct die_info * follow_die_ref_or_sig(struct die_info *, const struct attribute *, struct dwarf2_cu **)
Definition read.c:22360
static void process_skeletonless_type_units(dwarf2_per_objfile *per_objfile, cooked_index_storage *storage)
Definition read.c:7072
static bool create_cus_from_debug_names(dwarf2_per_bfd *per_bfd, const mapped_debug_names &map, const mapped_debug_names &dwz_map)
Definition read.c:4683
static struct type * read_tag_restrict_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16398
static struct symbol * new_symbol(struct die_info *, struct type *, struct dwarf2_cu *, struct symbol *=NULL)
Definition read.c:20766
static struct type * dwarf2_init_integer_type(struct dwarf2_cu *cu, struct objfile *objfile, int bits, int unsigned_p, const char *name)
Definition read.c:17050
static int dwarf2_locexpr_block_index
Definition read.c:146
static bool dw2_expand_marked_cus(dwarf2_per_objfile *per_objfile, offset_type idx, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, search_domain kind)
Definition read.c:3999
static const gdb_byte * read_attribute(const struct die_reader_specs *, struct attribute *, const struct attr_abbrev *, const gdb_byte *)
Definition read.c:19338
static void handle_struct_member_die(struct die_info *child_die, struct type *type, struct field_info *fi, std::vector< struct symbol * > *template_args, struct dwarf2_cu *cu)
Definition read.c:14870
static const char * dw2_get_real_path(dwarf2_per_objfile *per_objfile, struct quick_file_names *qfn, int index)
Definition read.c:2860
static void get_dwarf2_rational_constant(struct die_info *die, struct dwarf2_cu *cu, gdb_mpz *numerator, gdb_mpz *denominator)
Definition read.c:16801
static int dwarf2_locexpr_index
Definition read.c:144
static struct dwo_unit * lookup_dwo_comp_unit(dwarf2_cu *cu, const char *dwo_name, const char *comp_dir, ULONGEST signature)
Definition read.c:11776
static bool check_modifier(const char *physname, size_t &len, const char(&mod)[N])
Definition read.c:7804
static struct dwarf2_section_info * get_debug_line_section(struct dwarf2_cu *cu)
Definition read.c:19816
#define RNGLIST_HEADER_SIZE64
Definition read.c:159
static struct type * add_array_cv_type(struct die_info *die, struct dwarf2_cu *cu, struct type *base_type, int cnst, int voltl)
Definition read.c:16330
static struct type * read_tag_ptr_to_member_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16261
static const char * anonymous_struct_prefix(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:21718
static void create_one_variant_part(variant_part &result, struct obstack *obstack, const offset_map_type &offset_map, struct field_info *fi, const variant_part_builder &builder)
Definition read.c:13917
static const char * dwarf2_dwo_name(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:19758
static void create_addrmap_from_aranges(dwarf2_per_objfile *per_objfile, struct dwarf2_section_info *section)
Definition read.c:2507
static int dwarf2_loclist_block_index
Definition read.c:147
static struct type * die_type(struct die_info *, struct dwarf2_cu *)
Definition read.c:21372
static enum dwarf_access_attribute dwarf2_access_attribute(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:13413
static int eq_signatured_type(const void *item_lhs, const void *item_rhs)
Definition read.c:5526
static struct type_unit_group * get_type_unit_group(struct dwarf2_cu *cu, const struct attribute *stmt_list)
Definition read.c:6550
static CORE_ADDR read_addr_index_from_leb128(struct dwarf2_cu *, const gdb_byte *, unsigned int *)
Definition read.c:19441
static htab_up allocate_dwo_file_hash_table()
Definition read.c:9903
static unsigned int dwarf_die_debug
Definition read.c:115
static void build_type_psymtabs_reader(cutu_reader *reader, cooked_index_storage *storage)
Definition read.c:6859
static const struct abbrev_info * peek_die_abbrev(const die_reader_specs &reader, const gdb_byte *info_ptr, unsigned int *bytes_read)
Definition read.c:7348
static bool recognize_bound_expression(struct die_info *die, enum dwarf_attribute name, int *bounds_offset, struct field *field, struct dwarf2_cu *cu)
Definition read.c:15374
static struct type * read_array_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:15629
#define LOCLIST_HEADER_SIZE32
Definition read.c:150
static const char * dwarf2_string_attr(struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
Definition read.c:19735
static void create_one_variant(variant &result, struct obstack *obstack, const offset_map_type &offset_map, struct field_info *fi, const variant_field &field)
Definition read.c:13898
static htab_up allocate_signatured_type_table()
Definition read.c:5537
static void create_signatured_type_table_from_index(dwarf2_per_bfd *per_bfd, struct dwarf2_section_info *section, const gdb_byte *bytes, offset_type elements)
Definition read.c:2184
static char * typename_concat(struct obstack *obs, const char *prefix, const char *suffix, int physname, struct dwarf2_cu *cu)
Definition read.c:21930
static void dw_expand_symtabs_matching_file_matcher(dwarf2_per_objfile *per_objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher)
Definition read.c:4100
static int eq_dwo_file(const void *item_lhs, const void *item_rhs)
Definition read.c:9888
static void dump_die_for_error(struct die_info *)
Definition read.c:22296
static enum pc_bounds_kind dwarf2_get_pc_bounds(struct die_info *, CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, addrmap *, void *)
Definition read.c:13106
static int attr_to_dynamic_prop(const struct attribute *attr, struct die_info *die, struct dwarf2_cu *cu, struct dynamic_prop *prop, struct type *type)
Definition read.c:17388
static CORE_ADDR read_addr_index_1(dwarf2_per_objfile *per_objfile, unsigned int addr_index, gdb::optional< ULONGEST > addr_base, int addr_size)
Definition read.c:19404
static void store_in_ref_table(struct die_info *, struct dwarf2_cu *)
Definition read.c:22344
static struct type * get_signatured_type(struct die_info *, ULONGEST, struct dwarf2_cu *)
Definition read.c:22884
static unsigned int peek_abbrev_code(bfd *, const gdb_byte *)
Definition read.c:7333
static void read_call_site_scope(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:12323
static void get_dwarf2_unsigned_rational_constant(struct die_info *die, struct dwarf2_cu *cu, gdb_mpz *numerator, gdb_mpz *denominator)
Definition read.c:16830
static const gdb_byte * skip_children(const struct die_reader_specs *reader, const gdb_byte *info_ptr)
Definition read.c:7377
struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_sect_off(sect_offset sect_off, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, gdb::function_view< CORE_ADDR()> get_frame_pc, bool resolve_abstract_p)
Definition read.c:22479
static struct dwarf2_per_cu_data * dwarf2_find_containing_comp_unit(sect_offset sect_off, unsigned int offset_in_dwz, dwarf2_per_bfd *per_bfd)
Definition read.c:23643
static hashval_t line_header_hash_voidp(const void *item)
Definition read.c:1366
static void process_psymtab_comp_unit(dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile, cooked_index_storage *storage)
Definition read.c:6826
static struct die_info * read_die_and_children(const struct die_reader_specs *reader, const gdb_byte *info_ptr, const gdb_byte **new_info_ptr, struct die_info *parent)
Definition read.c:17784
static struct die_info * read_die_and_siblings(const struct die_reader_specs *, const gdb_byte *info_ptr, const gdb_byte **new_info_ptr, struct die_info *parent)
Definition read.c:17855
static struct type * read_subrange_index_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:17549
static void prepare_one_comp_unit(struct dwarf2_cu *cu, struct die_info *comp_unit_die, enum language pretend_language)
Definition read.c:23731
static bool dwarf2_rnglists_process(unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag, Callback &&callback)
Definition read.c:12732
static const char * dw2_linkage_name(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:8865
static int eq_dwp_loaded_cutus(const void *a, const void *b)
Definition read.c:11474
static void dump_die_shallow(struct ui_file *, int indent, struct die_info *)
Definition read.c:22174
#define MAX_SEP_LEN
Definition read.c:21927
#define MAX_NR_V1_DWO_SECTIONS
static void mark_common_block_symbol_computed(struct symbol *sym, struct die_info *common_die, struct attribute *common_loc, struct attribute *member_loc, struct dwarf2_cu *cu)
Definition read.c:15867
static int dwarf2_ranges_read(unsigned offset, CORE_ADDR *low_return, CORE_ADDR *high_return, struct dwarf2_cu *cu, addrmap *map, void *datum, dwarf_tag tag)
Definition read.c:13025
static const char * compute_include_file_name(const struct line_header *lh, const file_entry &fe, const file_and_directory &cu_info, std::string &name_holder)
Definition read.c:19878
static const gdb::array_view< discriminant_range > convert_variant_range(struct obstack *obstack, const variant_field &variant, bool is_unsigned)
Definition read.c:13814
static void alloc_rust_variant(struct obstack *obstack, struct type *type, int discriminant_index, int default_index, gdb::array_view< discriminant_range > ranges)
Definition read.c:7957
static void process_cu_includes(dwarf2_per_objfile *per_objfile)
Definition read.c:8398
static const char * gnat_encoded_fixed_point_type_info(const char *name)
Definition read.c:17021
static htab_up allocate_type_unit_groups_table()
Definition read.c:6517
static struct die_info * dwarf2_extension(struct die_info *die, struct dwarf2_cu **)
Definition read.c:22162
static const char * read_str_index(struct dwarf2_cu *cu, struct dwarf2_section_info *str_section, struct dwarf2_section_info *str_offsets_section, ULONGEST str_offsets_base, ULONGEST str_index, unsigned offset_size)
Definition read.c:19497
#define GNAT_FIXED_POINT_SUFFIX
Definition read.c:17014
static void get_mpz(struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr)
Definition read.c:16755
static void dwarf2_locate_v5_dwp_sections(struct objfile *objfile, bfd *abfd, asection *sectp, void *dwp_file_ptr)
Definition read.c:11423
#define dwarf_read_debug_printf_v(fmt,...)
Definition read.c:110
static void dwarf2_build_psymtabs(struct objfile *objfile)
Definition read.c:5425
#define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
Definition read.c:6530
static void finish_fixed_point_type(struct type *type, const char *suffix, struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16917
static struct die_info * die_specification(struct die_info *die, struct dwarf2_cu **)
Definition read.c:19799
struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_cu_off(cu_offset offset_in_cu, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, gdb::function_view< CORE_ADDR()> get_frame_pc)
Definition read.c:22584
static void dwarf2_const_value(const struct attribute *, struct symbol *, struct dwarf2_cu *)
Definition read.c:21339
static void dwarf2_start_subfile(dwarf2_cu *cu, const file_entry &fe, const line_header &lh)
Definition read.c:20661
static void read_func_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:12022
#define RNGLIST_HEADER_SIZE32
Definition read.c:156
static void dwarf2_complex_location_expr_complaint(void)
Definition read.c:1335
static gdb::array_view< const gdb_byte > get_gdb_index_contents_from_cache_dwz(objfile *obj, dwz_file *dwz)
Definition read.c:5342
static bool ada_get_gnat_encoded_number(const char *encoding, int &k, gdb_mpz *result)
Definition read.c:16872
static const char * read_indirect_string_at_offset(dwarf2_per_objfile *per_objfile, LONGEST str_offset)
Definition read.c:19352
static quick_symbol_functions_up make_cooked_index_funcs()
Definition read.c:18815
static void quirk_ada_thick_pointer_struct(struct die_info *die, struct dwarf2_cu *cu, struct type *type)
Definition read.c:14460
static const gdb_byte * read_full_die(const struct die_reader_specs *, struct die_info **, const gdb_byte *)
Definition read.c:17962
void _initialize_dwarf2_read()
Definition read.c:24061
#define dwarf_read_debug_printf(fmt,...)
Definition read.c:104
static void process_imported_unit_die(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:8592
static const registry< objfile >::key< dwarf2_per_bfd > dwarf2_per_bfd_objfile_data_key
Definition read.c:140
static struct type * rewrite_array_type(struct type *type)
Definition read.c:14409
static void read_file_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:9643
static bool producer_is_gxx_lt_4_6(struct dwarf2_cu *cu)
Definition read.c:13387
static struct dwo_unit * create_dwo_unit_in_dwp_v5(dwarf2_per_objfile *per_objfile, struct dwp_file *dwp_file, uint32_t unit_index, const char *comp_dir, ULONGEST signature, int is_debug_types)
Definition read.c:10891
static unsigned int dwarf_read_debug
Definition read.c:100
static const char * dwarf2_physname(const char *name, struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:9143
static void create_addrmap_from_index(dwarf2_per_objfile *per_objfile, struct mapped_index *index)
Definition read.c:2271
static hashval_t hash_signatured_type(const void *item)
Definition read.c:5516
static bool producer_is_icc_lt_14(struct dwarf2_cu *cu)
Definition read.c:9469
static bool has_zero_over_zero_small_attribute(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:17074
static const char * dwarf2_compute_name(const char *name, struct die_info *die, struct dwarf2_cu *cu, int physname)
Definition read.c:8898
static struct type * read_tag_const_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16353
static void print_tu_stats(dwarf2_per_objfile *per_objfile)
Definition read.c:6991
static struct die_info * read_die_and_siblings_1(const struct die_reader_specs *, const gdb_byte *, const gdb_byte **, struct die_info *)
Definition read.c:17818
static int eq_stmt_list_entry(const struct stmt_list_hash *lhs, const struct stmt_list_hash *rhs)
Definition read.c:1966
static void create_all_units(dwarf2_per_objfile *per_objfile)
Definition read.c:7290
static void dw2_symtab_iter_init(struct dw2_symtab_iterator *iter, dwarf2_per_objfile *per_objfile, gdb::optional< block_enum > block_index, domain_enum domain, offset_type namei, mapped_index &index)
Definition read.c:2957
static void dwarf2_debug_line_missing_file_complaint(void)
Definition read.c:1322
static struct type * read_tag_volatile_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16374
static struct dwarf2_section_info * cu_debug_rnglists_section(struct dwarf2_cu *cu, dwarf_tag tag)
Definition read.c:23441
static void dwarf2_attach_fields_to_type(struct field_info *, struct type *, struct dwarf2_cu *)
Definition read.c:14000
static void queue_and_load_all_dwo_tus(dwarf2_cu *cu)
Definition read.c:11827
static void create_debug_type_hash_table(dwarf2_per_objfile *per_objfile, struct dwo_file *dwo_file, dwarf2_section_info *section, htab_up &types_htab, rcuh_kind section_kind)
Definition read.c:5550
static const char * unnamed_template_tag_name(die_info *die, dwarf2_cu *cu)
Definition read.c:21995
static void read_attribute_reprocess(const struct die_reader_specs *reader, struct attribute *attr, dwarf_tag tag)
Definition read.c:19006
static void dump_die_1(struct ui_file *, int level, int max_level, struct die_info *)
Definition read.c:22302
int dwarf2_has_info(struct objfile *objfile, const struct dwarf2_debug_sections *names, bool can_copy)
Definition read.c:1553
static struct dwp_file * get_dwp_file(dwarf2_per_objfile *per_objfile)
Definition read.c:11634
static void read_module(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16133
static void compute_compunit_symtab_includes(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:8354
void dump_die(struct die_info *, int max_level)
Definition read.c:22338
static void quirk_rust_enum(struct type *type, struct objfile *objfile)
Definition read.c:8039
static void var_decode_location(struct attribute *attr, struct symbol *sym, struct dwarf2_cu *cu)
Definition read.c:20686
static CORE_ADDR decode_locdesc(struct dwarf_block *, struct dwarf2_cu *, bool *=nullptr)
Definition read.c:23049
static const char * namespace_name(struct die_info *die, int *is_anonymous, struct dwarf2_cu *)
Definition read.c:16153
static htab_up allocate_dwo_unit_table()
Definition read.c:9959
static struct quick_file_names * dw2_get_file_names(dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:2840
static void init_cu_die_reader(struct die_reader_specs *reader, struct dwarf2_cu *cu, struct dwarf2_section_info *section, struct dwo_file *dwo_file, struct abbrev_table *abbrev_table)
Definition read.c:5873
static struct type * read_namespace_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16034
static void dwarf_decode_lines_1(struct line_header *lh, struct dwarf2_cu *cu, CORE_ADDR lowpc)
Definition read.c:20384
static int maybe_queue_comp_unit(struct dwarf2_cu *dependent_cu, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, enum language pretend_language)
Definition read.c:7599
static hashval_t hash_dwo_unit(const void *item)
Definition read.c:9934
static int need_gnat_info(struct dwarf2_cu *)
Definition read.c:21392
static hashval_t hash_file_name_entry(const void *e)
Definition read.c:1981
static int locate_v1_virtual_dwo_sections(asection *sectp, struct virtual_v1_dwo_sections *sections)
Definition read.c:10458
static int bits_per_byte
Definition read.c:777
static void get_scope_pc_bounds(struct die_info *, CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *)
Definition read.c:13225
static hashval_t per_cu_offset_and_type_hash(const void *item)
Definition read.c:23892
static struct type * read_tag_string_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16437
static int die_is_declaration(struct die_info *, struct dwarf2_cu *cu)
Definition read.c:19779
static const char * guess_full_die_structure_name(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:21655
static struct signatured_type * lookup_dwp_signatured_type(struct dwarf2_cu *cu, ULONGEST sig)
Definition read.c:5800
static gdb_bfd_ref_ptr open_dwo_file(dwarf2_per_objfile *per_objfile, const char *file_name, const char *comp_dir)
Definition read.c:11212
struct cmd_list_element * set_dwarf_cmdlist
Definition read.c:24047
static void dwarf2_debug_line_missing_end_sequence_complaint(void)
Definition read.c:1328
static const char * rust_fully_qualify(struct obstack *obstack, const char *p1, const char *p2)
Definition read.c:7939
static gdb::array_view< const gdb_byte > get_gdb_index_contents_from_section(objfile *obj, T *section_owner)
Definition read.c:5302
static int is_vtable_name(const char *name, struct dwarf2_cu *cu)
Definition read.c:14348
static bool read_alias(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:9230
static bool is_valid_DW_AT_calling_convention_for_subroutine(ULONGEST value)
Definition read.c:14582
static int die_eq(const void *item_lhs, const void *item_rhs)
Definition read.c:7723
static void dwarf2_locate_common_dwp_sections(struct objfile *objfile, bfd *abfd, asection *sectp, dwp_file *dwp_file)
Definition read.c:11344
static bool tag_can_have_linkage_name(enum dwarf_tag tag)
Definition read.c:18021
static void dwarf2_locate_v2_dwp_sections(struct objfile *objfile, bfd *abfd, asection *sectp, void *dwp_file_ptr)
Definition read.c:11378
static void recursively_compute_inclusions(std::vector< compunit_symtab * > *result, htab_t all_children, htab_t all_type_symtabs, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, struct compunit_symtab *immediate_parent)
Definition read.c:8301
static void create_cus_hash_table(dwarf2_per_objfile *per_objfile, dwarf2_cu *cu, struct dwo_file &dwo_file, dwarf2_section_info &section, htab_up &cus_htab)
Definition read.c:10006
static void update_enumeration_type_from_children(struct die_info *die, struct type *type, struct dwarf2_cu *cu)
Definition read.c:15149
static void build_type_psymtabs(dwarf2_per_objfile *per_objfile, cooked_index_storage *storage)
Definition read.c:6914
static void read_common_block(struct die_info *, struct dwarf2_cu *)
Definition read.c:15938
static void dwarf_decode_macros(struct dwarf2_cu *, unsigned int, int)
Definition read.c:23352
static file_and_directory & find_file_and_directory(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:9514
static struct dwarf2_section_info * get_abbrev_section_for_cu(struct dwarf2_per_cu_data *this_cu)
Definition read.c:5473
static struct type * read_tag_pointer_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16185
static int dwarf_record_line_p(struct dwarf2_cu *cu, unsigned int line, unsigned int last_line, int line_has_non_zero_discriminator, struct subfile *last_subfile)
Definition read.c:20182
static gdb::optional< ULONGEST > lookup_dwo_id(struct dwarf2_cu *cu, struct die_info *comp_unit_die)
Definition read.c:6083
static struct dwo_file * open_and_init_dwo_file(dwarf2_cu *cu, const char *dwo_name, const char *comp_dir)
Definition read.c:11297
static struct type * read_subrange_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:17574
static void set_descriptive_type(struct type *, struct die_info *, struct dwarf2_cu *)
Definition read.c:21419
static struct type * read_set_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:15834
static int prototyped_function_p(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16536
static struct type * read_typedef(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:16716
static struct dwarf2_section_info * cu_debug_loc_section(struct dwarf2_cu *cu)
Definition read.c:23425
static void handle_variant(struct die_info *die, struct type *type, struct field_info *fi, std::vector< struct symbol * > *template_args, struct dwarf2_cu *cu)
Definition read.c:14814
static int dwarf_max_cache_age
Definition read.c:878
static const gdb_byte * read_full_die_1(const struct die_reader_specs *, struct die_info **, const gdb_byte *, int)
Definition read.c:17884
static const char * dwarf2_name(struct die_info *die, struct dwarf2_cu *)
Definition read.c:22054
struct cmd_list_element * show_dwarf_cmdlist
Definition read.c:24048
static struct signatured_type * add_type_unit(dwarf2_per_objfile *per_objfile, ULONGEST sig, void **slot)
Definition read.c:5666
static void add_variant_property(struct field_info *fip, struct type *type, struct dwarf2_cu *cu)
Definition read.c:13974
static bool is_valid_DW_AT_calling_convention_for_type(ULONGEST value)
Definition read.c:14561
static enum dwarf_array_dim_ordering read_array_order(struct die_info *, struct dwarf2_cu *)
Definition read.c:15794
static struct die_info * dwarf_alloc_die(struct dwarf2_cu *, int)
Definition read.c:23331
static const char * read_indirect_string(dwarf2_per_objfile *per_objfile, bfd *, const gdb_byte *, const struct comp_unit_head *, unsigned int *)
Definition read.c:19364
static struct type * build_error_marker_type(struct dwarf2_cu *cu, struct die_info *die)
Definition read.c:21451
static void fill_in_loclist_baton(struct dwarf2_cu *cu, struct dwarf2_loclist_baton *baton, const struct attribute *attr)
Definition read.c:23470
static struct type * get_DW_AT_signature_type(struct die_info *, const struct attribute *, struct dwarf2_cu *)
Definition read.c:22945
static int dwarf2_is_constructor(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14095
struct type * dwarf2_get_die_type(cu_offset die_offset, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:22780
void dwarf2_get_section_info(struct objfile *objfile, enum dwarf2_section_enum sect, asection **sectp, const gdb_byte **bufp, bfd_size_type *sizep)
Definition read.c:1732
static void finalize_all_units(dwarf2_per_bfd *per_bfd)
Definition read.c:7277
static int dwarf2_ranges_process(unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag, Callback &&callback)
Definition read.c:12927
static void create_cus_from_index_list(dwarf2_per_bfd *per_bfd, const gdb_byte *cu_list, offset_type n_elements, struct dwarf2_section_info *section, int is_dwz)
Definition read.c:2137
static const gdb::array_view< variant_part > create_variant_parts(struct obstack *obstack, const offset_map_type &offset_map, struct field_info *fi, const std::vector< variant_part_builder > &variant_parts)
Definition read.c:13953
static void read_signatured_type(signatured_type *sig_type, dwarf2_per_objfile *per_objfile)
Definition read.c:22997
static line_header_up dwarf_decode_line_header(sect_offset sect_off, struct dwarf2_cu *cu, const char *comp_dir)
Definition read.c:19848
static struct dwarf_block * dwarf_alloc_block(struct dwarf2_cu *)
Definition read.c:23325
static int process_skeletonless_type_unit(void **slot, void *info)
Definition read.c:7019
static int process_dwo_file_for_skeletonless_type_units(void **slot, void *info)
Definition read.c:7056
static int die_needs_namespace(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:8790
static dwarf2_per_cu_data_up create_cu_from_index_list(dwarf2_per_bfd *per_bfd, struct dwarf2_section_info *section, int is_dwz, sect_offset sect_off, ULONGEST length)
Definition read.c:2120
static int read_cutu_die_from_dwo(dwarf2_cu *cu, struct dwo_unit *dwo_unit, struct die_info *stub_comp_unit_die, const char *stub_comp_dir, struct die_reader_specs *result_reader, const gdb_byte **result_info_ptr, struct die_info **result_comp_unit_die, abbrev_table_up *result_dwo_abbrev_table)
Definition read.c:5909
static sect_offset read_loclist_index(struct dwarf2_cu *cu, ULONGEST loclist_index)
Definition read.c:18882
static bool check_physname
Definition read.c:121
static struct die_info * follow_die_sig(struct die_info *, const struct attribute *, struct dwarf2_cu **)
Definition read.c:22847
static void dw2_do_instantiate_symtab(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, bool skip_partial)
Definition read.c:2036
static struct type * read_base_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:17162
static CORE_ADDR read_addr_index(struct dwarf2_cu *cu, unsigned int addr_index)
Definition read.c:19432
static bool dwarf2_read_debug_names(dwarf2_per_objfile *per_objfile)
Definition read.c:4706
static struct type * dwarf2_init_float_type(struct objfile *objfile, int bits, const char *name, const char *name_hint, enum bfd_endian byte_order)
Definition read.c:17031
static const char * read_stub_str_index(struct dwarf2_cu *cu, ULONGEST str_index)
Definition read.c:19601
static void quirk_gcc_member_function_pointer(struct type *type, struct objfile *objfile)
Definition read.c:14367
#define NO_STMT_LIST_TYPE_UNIT_PSYMTAB
Definition read.c:6529
static void add_to_method_list(struct type *type, int fnfield_index, int index, const char *name, struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:7785
static struct type * read_type_die_1(struct die_info *, struct dwarf2_cu *)
Definition read.c:21565
static void read_variable(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:12686
static htab_up allocate_dwp_loaded_cutus_table()
Definition read.c:11485
static void process_queue(dwarf2_per_objfile *per_objfile)
Definition read.c:7646
static hashval_t hash_stmt_list_entry(const struct stmt_list_hash *stmt_list_hash)
Definition read.c:1953
static bool dw2_expand_symtabs_matching_one(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify)
Definition read.c:3974
static bool use_deprecated_index_sections
Definition read.c:124
static void fill_in_sig_entry_from_dwo_entry(dwarf2_per_objfile *per_objfile, struct signatured_type *sig_entry, struct dwo_unit *dwo_entry)
Definition read.c:5694
void dwarf2_initialize_objfile(struct objfile *objfile)
Definition read.c:5356
dwarf2_per_objfile * get_dwarf2_per_objfile(struct objfile *objfile)
Definition read.c:311
static struct die_info * follow_die_sig_1(struct die_info *src_die, struct signatured_type *sig_type, struct dwarf2_cu **ref_cu)
Definition read.c:22794
static bool read_gdb_index_from_buffer(const char *filename, bool deprecated_ok, gdb::array_view< const gdb_byte > buffer, struct mapped_index *map, const gdb_byte **cu_list, offset_type *cu_list_elements, const gdb_byte **types_list, offset_type *types_list_elements)
Definition read.c:2532
static struct type * quirk_ada_thick_pointer(struct die_info *die, struct dwarf2_cu *cu, struct type *type)
Definition read.c:15501
static int dwarf2_flag_true_p(struct die_info *die, unsigned name, struct dwarf2_cu *cu)
Definition read.c:19771
static const char * var_decl_name(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:17368
static struct type * dwarf2_init_complex_target_type(struct dwarf2_cu *cu, struct objfile *objfile, int bits, const char *name_hint, enum bfd_endian byte_order)
Definition read.c:17103
static void load_full_type_unit(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:22975
static int per_cu_offset_and_type_eq(const void *item_lhs, const void *item_rhs)
Definition read.c:23903
unsigned int dwarf_line_debug
Definition read.c:118
static int dwarf2_read_gdb_index(dwarf2_per_objfile *per_objfile, get_gdb_index_contents_ftype get_gdb_index_contents, get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz)
Definition read.c:2650
static void process_enumeration_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:15314
static struct signatured_type * lookup_signatured_type(struct dwarf2_cu *cu, ULONGEST sig)
Definition read.c:5844
static struct type * read_unspecified_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:17760
static const gdb_byte dwarf5_augmentation[]
Definition read.c:4420
struct type * dwarf2_fetch_die_type_sect_off(sect_offset sect_off, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, const char **var_name)
Definition read.c:22754
static void dwarf_decode_lines(struct line_header *, struct dwarf2_cu *, CORE_ADDR, int decode_mapping)
Definition read.c:20612
static void dwarf_record_line_1(struct gdbarch *gdbarch, struct subfile *subfile, unsigned int line, CORE_ADDR address, linetable_entry_flags flags, struct dwarf2_cu *cu)
Definition read.c:20203
static void dwarf2_find_base_address(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:5452
static struct type * lookup_die_type(struct die_info *, const struct attribute *, struct dwarf2_cu *)
Definition read.c:21473
static hashval_t line_header_hash(const struct line_header *ofs)
Definition read.c:1358
const struct dwarf2_debug_sections dwarf2_elf_names
Definition read.c:321
static void dwarf2_const_value_attr(const struct attribute *attr, struct type *type, const char *name, struct obstack *obstack, struct dwarf2_cu *cu, LONGEST *value, const gdb_byte **bytes, struct dwarf2_locexpr_baton **baton)
Definition read.c:21231
static const registry< objfile >::key< dwarf2_per_objfile > dwarf2_objfile_data_key
Definition read.c:128
std::unordered_map< sect_offset, int, gdb::hash_enum< sect_offset > > offset_map_type
Definition read.c:13806
#define MAX_NR_V5_DWO_SECTIONS
Definition read.c:638
static void handle_variant_part(struct die_info *die, struct type *type, struct field_info *fi, std::vector< struct symbol * > *template_args, struct dwarf2_cu *cu)
Definition read.c:14753
static void create_dwo_cu_reader(const struct die_reader_specs *reader, const gdb_byte *info_ptr, struct die_info *comp_unit_die, struct dwo_file *dwo_file, struct dwo_unit *dwo_unit)
Definition read.c:9972
static void dwarf2_record_block_ranges(struct die_info *, struct block *, CORE_ADDR, struct dwarf2_cu *)
Definition read.c:13285
static void create_cus_from_index(dwarf2_per_bfd *per_bfd, const gdb_byte *cu_list, offset_type cu_list_elements, const gdb_byte *dwz_list, offset_type dwz_elements)
Definition read.c:2162
static const char * dwarf2_canonicalize_name(const char *, struct dwarf2_cu *, struct objfile *)
Definition read.c:22024
static std::unique_ptr< struct dwp_file > open_and_init_dwp_file(dwarf2_per_objfile *per_objfile)
Definition read.c:11534
static void dwarf_finish_line(struct gdbarch *gdbarch, struct subfile *subfile, CORE_ADDR address, struct dwarf2_cu *cu)
Definition read.c:20228
std::unique_ptr< struct dwo_file > dwo_file_up
Definition read.c:1313
static void read_namespace(struct die_info *die, struct dwarf2_cu *)
Definition read.c:16073
static struct type * die_descriptive_type(struct die_info *, struct dwarf2_cu *)
Definition read.c:21404
std::unique_ptr< signatured_type > signatured_type_up
Definition read.h:411
dwarf2_section_enum
Definition read.h:754
@ DWARF2_EH_FRAME
Definition read.h:756
@ DWARF2_DEBUG_FRAME
Definition read.h:755
std::unique_ptr< dwarf2_per_cu_data, dwarf2_per_cu_data_deleter > dwarf2_per_cu_data_up
Definition read.h:94
static struct ppc_variant variants[]
const char * rust_last_path_segment(const char *path)
Definition rust-lang.c:47
int openp(const char *path, openp_flags opts, const char *string, int mode, gdb::unique_xmalloc_ptr< char > *filename_opened)
Definition source.c:805
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition source.c:1287
void forget_cached_source_info(void)
Definition source.c:444
gdb::unique_xmalloc_ptr< char > find_source_or_rewrite(const char *filename, const char *dirname)
Definition source.c:1217
@ OPF_SEARCH_IN_PATH
Definition source.h:31
@ OPF_RETURN_REALPATH
Definition source.h:32
const char * dwarf_bool_name(unsigned mybool)
Definition stringify.c:95
const char * dwarf_attr_name(unsigned attr)
Definition stringify.c:59
const char * dwarf_tag_name(unsigned tag)
Definition stringify.c:46
const char * dwarf_form_name(unsigned form)
Definition stringify.c:82
const char * dwarf_type_encoding_name(unsigned enc)
Definition stringify.c:106
Definition 1.cc:26
__extension__ enum dwarf_tag tag
Definition abbrev.h:47
unsigned short num_attrs
Definition abbrev.h:54
struct attr_abbrev attrs[1]
Definition abbrev.h:57
unsigned short sibling_offset
Definition abbrev.h:52
unsigned short size_if_constant
Definition abbrev.h:51
bool interesting
Definition abbrev.h:50
bool has_children
Definition abbrev.h:49
const sect_offset sect_off
Definition abbrev.h:89
static abbrev_table_up read(struct dwarf2_section_info *section, sect_offset sect_off)
Definition abbrev.c:120
const struct abbrev_info * lookup_abbrev(unsigned int abbrev_number) const
Definition abbrev.h:77
void * find(CORE_ADDR addr) const override
Definition addrmap.c:243
void set_empty(CORE_ADDR start, CORE_ADDR end_inclusive, void *obj) override
Definition addrmap.c:191
virtual void * find(CORE_ADDR addr) const =0
virtual void set_empty(CORE_ADDR start, CORE_ADDR end_inclusive, void *obj)=0
LONGEST implicit_const
Definition abbrev.h:38
__extension__ enum dwarf_attribute name
Definition abbrev.h:34
__extension__ enum dwarf_form form
Definition abbrev.h:35
bool is_nonnegative() const
Definition attribute.h:97
sect_offset get_ref_die_offset() const
Definition attribute.h:182
void set_signature(ULONGEST signature)
Definition attribute.h:233
ULONGEST as_unsigned() const
Definition attribute.h:88
void set_unsigned(ULONGEST unsnd)
Definition attribute.h:247
bool as_boolean() const
Definition attribute.c:264
bool canonical_string_p() const
Definition attribute.h:201
LONGEST constant_value(int default_value) const
Definition attribute.c:147
CORE_ADDR as_address() const
Definition attribute.c:35
bool form_is_constant() const
Definition attribute.c:118
__extension__ enum dwarf_attribute name
Definition attribute.h:296
const char * str
Definition attribute.h:318
void set_string_noncanonical(const char *str)
Definition attribute.h:209
void set_address(CORE_ADDR addr)
Definition attribute.h:264
ULONGEST as_nonnegative() const
Definition attribute.h:108
const char * as_string() const
Definition attribute.c:83
bool requires_reprocessing_p() const
Definition attribute.h:275
void set_unsigned_reprocess(ULONGEST unsnd)
Definition attribute.h:256
dwarf_defaulted_attribute defaulted() const
Definition attribute.c:218
dwarf_block * as_block() const
Definition attribute.h:55
bool form_is_block() const
Definition attribute.c:94
void set_block(dwarf_block *blk)
Definition attribute.h:226
void set_string_canonical(const char *str)
Definition attribute.h:218
__extension__ enum dwarf_form form
Definition attribute.h:309
bool form_is_unsigned() const
Definition attribute.c:169
bool form_is_ref() const
Definition attribute.h:150
LONGEST as_signed() const
Definition attribute.h:71
unsigned int string_is_canonical
Definition attribute.h:314
ULONGEST as_unsigned_reprocess() const
Definition attribute.h:79
void set_signed(LONGEST snd)
Definition attribute.h:240
unsigned int requires_reprocessing
Definition attribute.h:307
ULONGEST as_signature() const
Definition attribute.h:63
dwarf_virtuality_attribute as_virtuality() const
Definition attribute.c:241
bool form_is_section_offset() const
Definition attribute.c:107
Definition block.h:109
void set_ranges(blockranges *ranges)
Definition block.h:177
struct minimal_symbol * minsym
Definition minsyms.h:49
struct compunit_symtab * get_compunit_symtab()
Definition buildsym.h:245
struct pending ** get_local_symbols()
Definition buildsym.h:297
void set_local_using_directives(struct using_direct *new_local)
Definition buildsym.h:265
struct using_direct ** get_local_using_directives()
Definition buildsym.h:260
void start_subfile(const char *name, const char *name_for_id)
Definition buildsym.c:491
struct context_stack * get_current_context_stack()
Definition buildsym.h:280
struct block * finish_block(struct symbol *symbol, struct pending_block *old_blocks, const struct dynamic_prop *static_link, CORE_ADDR start, CORE_ADDR end)
Definition buildsym.c:390
bool outermost_context_p() const
Definition buildsym.h:275
struct compunit_symtab * end_compunit_symtab_from_static_block(struct block *static_block, int section, int expandable)
Definition buildsym.c:1025
struct block * end_compunit_symtab_get_static_block(CORE_ADDR end_addr, int expandable, int required)
Definition buildsym.c:764
void augment_type_symtab()
Definition buildsym.c:1116
struct pending ** get_file_symbols()
Definition buildsym.h:302
void record_line(struct subfile *subfile, int line, CORE_ADDR pc, linetable_entry_flags flags)
Definition buildsym.c:630
struct context_stack pop_context()
Definition buildsym.c:1180
struct pending ** get_global_symbols()
Definition buildsym.h:307
struct subfile * get_current_subfile()
Definition buildsym.h:292
struct compunit_symtab * end_expandable_symtab(CORE_ADDR end_addr, int section)
Definition buildsym.c:1082
void record_block_range(struct block *block, CORE_ADDR start, CORE_ADDR end_inclusive)
Definition buildsym.c:408
struct context_stack * push_context(int desc, CORE_ADDR valu)
Definition buildsym.c:1158
struct using_direct ** get_global_using_directives()
Definition buildsym.h:270
struct type * builtin_real
Definition f-lang.h:329
struct type * builtin_real_s8
Definition f-lang.h:330
struct type * builtin_real_s16
Definition f-lang.h:331
struct type * builtin_double
Definition gdbtypes.h:2258
struct type * builtin_long_double
Definition gdbtypes.h:2259
struct type * builtin_float
Definition gdbtypes.h:2257
__extension__ enum call_site_parameter_kind kind
Definition gdbtypes.h:1866
const gdb_byte * value
Definition gdbtypes.h:1872
union call_site_parameter_u u
Definition gdbtypes.h:1868
const gdb_byte * data_value
Definition gdbtypes.h:1878
unsigned parameter_count
Definition gdbtypes.h:1944
static hashval_t hash(const call_site *a)
Definition gdbtypes.h:1899
struct call_site_parameter parameter[]
Definition gdbtypes.h:1962
CORE_ADDR pc() const
Definition gdbtypes.c:6437
static int eq(const call_site *a, const call_site *b)
Definition gdbtypes.h:1893
struct call_site * tail_call_next
Definition gdbtypes.h:1935
dwarf2_per_objfile *const per_objfile
Definition gdbtypes.h:1953
struct symbol * contents[1]
Definition f-lang.h:307
size_t n_entries
Definition f-lang.h:303
CORE_ADDR read_address(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read) const
unsigned char addr_size
unsigned char version
unsigned int length
unsigned int get_length() const
cu_offset type_cu_offset_in_tu
sect_offset sect_off
enum dwarf_unit_type unit_type
LONGEST read_offset(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read) const
unsigned int offset_size
void set_epilogue_unwind_valid(bool epilogue_unwind_valid)
Definition symtab.h:1813
symtab * primary_filetab() const
Definition symtab.c:397
enum language language() const
Definition symtab.c:408
struct blockvector * blockvector()
Definition symtab.h:1773
struct compunit_symtab * user
Definition symtab.h:1921
void set_locations_valid(bool locations_valid)
Definition symtab.h:1803
void set_call_site_htab(htab_t call_site_htab)
Definition symtab.c:360
struct compunit_symtab ** includes
Definition symtab.h:1915
struct objfile * objfile() const
Definition symtab.h:1714
const char * dirname() const
Definition symtab.h:1763
struct dynamic_prop * static_link
Definition buildsym.h:108
struct pending * locals
Definition buildsym.h:91
struct using_direct * local_using_directives
Definition buildsym.h:95
struct pending_block * old_blocks
Definition buildsym.h:99
CORE_ADDR start_addr
Definition buildsym.h:112
struct symbol * name
Definition buildsym.h:103
dwarf2_per_cu_data * per_cu
sect_offset die_offset
const char * name
const char * full_name(struct obstack *storage, bool for_main=false) const
const cooked_index_entry * parent_entry
struct compunit_symtab * find_compunit_symtab_by_address(struct objfile *objfile, CORE_ADDR address) override
Definition read.c:18620
void dump(struct objfile *objfile) override
Definition read.c:18572
void read_partial_symbols(struct objfile *objfile) override
Definition read.c:18599
dwarf2_per_cu_data * find_per_cu(dwarf2_per_bfd *per_bfd, CORE_ADDR adjusted_pc) override
Definition read.c:18607
bool can_lazily_read_symbols() override
Definition read.c:18594
bool expand_symtabs_matching(struct objfile *objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info *lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, domain_enum domain, enum search_domain kind) override
Definition read.c:18679
void expand_matching_symbols(struct objfile *, const lookup_name_info &lookup_name, domain_enum domain, int global, symbol_compare_ftype *ordered_compare) override
Definition read.c:18642
Definition read.c:6804
sect_offset die_offset
Definition read.c:6805
cooked_index_flag flags
Definition read.c:6809
dwarf_tag tag
Definition read.c:6808
CORE_ADDR spec_offset
Definition read.c:6807
const char * name
Definition read.c:6806
const char * name
Definition gdbtypes.h:1557
unsigned int is_private
Definition gdbtypes.h:1567
struct type * type
Definition gdbtypes.h:1561
unsigned int is_protected
Definition gdbtypes.h:1564
struct die_info * die
Definition cu.h:45
int fnfield_index
Definition cu.h:36
struct type * type
Definition cu.h:33
const char * name
Definition cu.h:42
Definition die.h:27
struct die_info * child
Definition die.h:119
unsigned char building_fullname
Definition die.h:101
unsigned char in_process
Definition die.h:104
struct attribute attrs[1]
Definition die.h:126
struct attribute * attr(dwarf_attribute name)
Definition die.h:30
ULONGEST gnu_ranges_base()
Definition die.h:61
unsigned int abbrev
Definition die.h:110
unsigned char has_children
Definition die.h:107
sect_offset sect_off
Definition die.h:113
struct die_info * parent
Definition die.h:121
__extension__ enum dwarf_tag tag
Definition die.h:94
ULONGEST rnglists_base()
Definition die.h:78
struct die_info * sibling
Definition die.h:120
gdb::optional< ULONGEST > addr_base()
Definition die.h:41
unsigned char num_attrs
Definition die.h:97
struct dwarf2_cu * cu
Definition read.c:702
struct abbrev_table * abbrev_table
Definition read.c:718
struct dwarf2_section_info * die_section
Definition read.c:709
struct dwo_file * dwo_file
Definition read.c:705
const gdb_byte * buffer
Definition read.c:712
const gdb_byte * buffer_end
Definition read.c:715
gdb::optional< block_enum > block_index
Definition read.c:2937
offset_view vec
Definition read.c:2942
domain_enum domain
Definition read.c:2939
dwarf2_per_objfile * per_objfile
Definition read.c:2934
struct compunit_symtab * find_compunit_symtab_by_address(struct objfile *objfile, CORE_ADDR address) override
Definition read.c:1850
void print_stats(struct objfile *objfile, bool print_bcache) override
Definition read.c:3074
struct symtab * find_last_source_symtab(struct objfile *objfile) override
Definition read.c:2884
void expand_all_symtabs(struct objfile *objfile) override
Definition read.c:3112
void map_symbol_filenames(struct objfile *objfile, gdb::function_view< symbol_filename_ftype > fun, bool need_fullname) override
Definition read.c:4317
void forget_cached_source_info(struct objfile *objfile) override
Definition read.c:2921
bool has_unexpanded_symtabs(struct objfile *objfile) override
Definition read.c:4400
enum language lookup_global_symbol_language(struct objfile *objfile, const char *name, domain_enum domain, bool *symbol_found_p) override
Definition read.c:1826
bool has_symbols(struct objfile *objfile) override
Definition read.c:4392
struct compunit_symtab * find_pc_sect_compunit_symtab(struct objfile *objfile, struct bound_minimal_symbol msymbol, CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override final
Definition read.c:4285
virtual dwarf2_per_cu_data * find_per_cu(dwarf2_per_bfd *per_bfd, CORE_ADDR adjusted_pc)
Definition read.c:4274
Definition cu.h:50
bool producer_is_gcc_11
Definition cu.h:263
bool producer_is_gcc_lt_4_3
Definition cu.h:262
htab_t call_site_htab
Definition cu.h:177
gdb::optional< ULONGEST > str_offsets_base
Definition cu.h:245
die_info * line_header_die_owner
Definition cu.h:170
bool producer_is_icc
Definition cu.h:264
bool is_marked() const
Definition cu.h:92
ULONGEST gnu_ranges_base
Definition cu.h:220
bool producer_is_clang
Definition cu.h:267
bool processing_has_namespace_info
Definition cu.h:273
const struct language_defn * language_defn
Definition cu.h:107
void setup_type_unit_groups(struct die_info *die)
Definition read.c:9718
struct type * addr_type() const
Definition cu.c:107
bool producer_is_codewarrior
Definition cu.h:266
dwarf2_per_objfile * per_objfile
Definition cu.h:151
std::vector< struct type * > rust_unions
Definition cu.h:239
ULONGEST rnglists_base
Definition cu.h:228
bool producer_is_icc_lt_14
Definition cu.h:265
gdb::optional< CORE_ADDR > base_address
Definition cu.h:104
gdb::optional< ULONGEST > addr_base
Definition cu.h:192
htab_t die_hash
Definition cu.h:158
struct dwo_unit * dwo_unit
Definition cu.h:188
void reset_builder()
Definition cu.h:70
enum language lang() const
Definition cu.h:109
struct compunit_symtab * start_compunit_symtab(const char *name, const char *comp_dir, CORE_ADDR low_pc)
Definition cu.c:61
buildsym_compunit * get_builder()
Definition cu.c:174
struct pending ** list_in_scope
Definition cu.h:137
struct line_header * line_header
Definition cu.h:164
void mark()
Definition cu.c:142
struct dwarf2_per_cu_data * per_cu
Definition cu.h:148
std::unique_ptr< buildsym_compunit > m_builder
Definition cu.h:120
bool has_loclist
Definition cu.h:254
struct die_info * dies
Definition cu.h:161
const char * producer
Definition cu.h:115
bool checked_producer
Definition cu.h:260
auto_obstack comp_unit_obstack
Definition cu.h:145
int last_used
Definition cu.h:154
ULONGEST loclist_base
Definition cu.h:231
struct type * addr_sized_int_type(bool unsigned_p) const
Definition cu.c:51
bool producer_is_gxx_lt_4_6
Definition cu.h:261
std::vector< delayed_method_info > method_list
Definition cu.h:174
void add_dependence(struct dwarf2_per_cu_data *ref_per_cu)
Definition cu.c:155
void expand_matching_symbols(struct objfile *, const lookup_name_info &lookup_name, domain_enum domain, int global, symbol_compare_ftype *ordered_compare) override
Definition read.c:5203
bool expand_symtabs_matching(struct objfile *objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info *lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, domain_enum domain, enum search_domain kind) override
Definition read.c:5242
void dump(struct objfile *objfile) override
Definition read.c:5196
struct dwarf2_section_names line_str
Definition sect-names.h:60
struct dwarf2_section_names ranges
Definition sect-names.h:61
struct dwarf2_section_names rnglists
Definition sect-names.h:62
struct dwarf2_section_names frame
Definition sect-names.h:65
struct dwarf2_section_names loc
Definition sect-names.h:54
struct dwarf2_section_names types
Definition sect-names.h:63
struct dwarf2_section_names eh_frame
Definition sect-names.h:66
struct dwarf2_section_names str_offsets
Definition sect-names.h:59
struct dwarf2_section_names debug_aranges
Definition sect-names.h:69
struct dwarf2_section_names loclists
Definition sect-names.h:55
struct dwarf2_section_names gdb_index
Definition sect-names.h:67
struct dwarf2_section_names addr
Definition sect-names.h:64
struct dwarf2_section_names debug_names
Definition sect-names.h:68
struct dwarf2_section_names macro
Definition sect-names.h:57
struct dwarf2_section_names info
Definition sect-names.h:51
struct dwarf2_section_names str
Definition sect-names.h:58
struct dwarf2_section_names macinfo
Definition sect-names.h:56
struct dwarf2_section_names abbrev
Definition sect-names.h:52
struct dwarf2_section_names line
Definition sect-names.h:53
bool expand_symtabs_matching(struct objfile *objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info *lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, domain_enum domain, enum search_domain kind) override
Definition read.c:4197
void expand_matching_symbols(struct objfile *, const lookup_name_info &lookup_name, domain_enum domain, int global, symbol_compare_ftype *ordered_compare) override
Definition read.c:3147
void dump(struct objfile *objfile) override
Definition read.c:3101
struct dwarf2_per_cu_data * per_cu
Definition loc.h:176
const gdb_byte * data
Definition loc.h:159
dwarf2_per_objfile * per_objfile
Definition loc.h:172
struct dwarf2_per_cu_data * per_cu
Definition loc.h:196
CORE_ADDR base_address
Definition loc.h:183
unsigned char from_dwo
Definition loc.h:200
dwarf2_per_objfile * per_objfile
Definition loc.h:192
const gdb_byte * data
Definition loc.h:186
LONGEST offset
Definition loc.h:213
struct type * type
Definition loc.h:217
dwarf2_section_info rnglists
Definition read.h:480
dwarf2_section_info loclists
Definition read.h:473
dwarf2_section_info macro
Definition read.h:475
htab_up type_unit_groups
Definition read.h:501
htab_up quick_file_names_table
Definition read.h:542
auto_obstack obstack
Definition read.h:467
struct addrmap * index_addrmap
Definition read.h:558
dwarf2_per_cu_data_up allocate_per_cu()
Definition read.c:2095
bool has_section_at_zero
Definition read.h:530
dwarf2_section_info str
Definition read.h:476
dwarf2_section_info macinfo
Definition read.h:474
bfd * obfd
Definition read.h:462
htab_up signatured_types
Definition read.h:505
gdb::array_view< dwarf2_per_cu_data_up > all_comp_units
Definition read.h:496
dwarf2_per_cu_data * get_cu(int index) const
Definition read.h:434
void map_info_sections(struct objfile *objfile)
Definition read.c:1771
void locate_sections(bfd *abfd, asection *sectp, const dwarf2_debug_sections &names)
Definition read.c:1605
bool can_copy
Definition read.h:526
dwarf2_section_info ranges
Definition read.h:479
std::unique_ptr< dwarf_scanner_base > index_table
Definition read.h:533
htab_up dwo_files
Definition read.h:513
bool dwp_checked
Definition read.h:516
gdb::array_view< dwarf2_per_cu_data_up > all_type_units
Definition read.h:497
dwarf2_section_info str_offsets
Definition read.h:477
dwarf2_per_bfd(bfd *obfd, const dwarf2_debug_sections *names, bool can_copy)
Definition read.c:1456
std::vector< dwarf2_section_info > types
Definition read.h:488
dwarf2_section_info addr
Definition read.h:481
dwarf2_section_info line_str
Definition read.h:478
dwarf2_section_info frame
Definition read.h:482
signatured_type_up allocate_signatured_type(ULONGEST signature)
Definition read.c:2106
dwarf2_section_info eh_frame
Definition read.h:483
dwarf2_section_info debug_aranges
Definition read.h:486
std::unordered_map< sect_offset, std::vector< sect_offset >, gdb::hash_enum< sect_offset > > abstract_to_concrete
Definition read.h:555
std::unique_ptr< struct dwp_file > dwp_file
Definition read.h:519
dwarf2_section_info abbrev
Definition read.h:470
dwarf2_section_info gdb_index
Definition read.h:484
std::unique_ptr< index_cache_resource > index_cache_res
Definition read.h:549
~dwarf2_per_bfd()
Definition read.c:1468
dwarf2_section_info loc
Definition read.h:472
dwarf2_section_info line
Definition read.h:471
dwarf2_section_info info
Definition read.h:469
std::vector< dwarf2_per_cu_data_up > all_units
Definition read.h:492
std::vector< dwarf2_per_cu_data * > just_read_cus
Definition read.h:545
void operator()(dwarf2_per_cu_data *data)
Definition read.c:1275
unsigned index
Definition read.h:192
std::atomic< bool > scanned
Definition read.h:189
struct dwarf2_section_info * section
Definition read.h:197
bool imported_symtabs_empty() const
Definition read.h:249
unsigned int queued
Definition read.h:131
unsigned int reading_dwo_directly
Definition read.h:145
sect_offset sect_off
Definition read.h:120
bool m_header_read_in
Definition read.h:161
short version() const
Definition read.h:313
void set_version(short version)
Definition read.h:320
void set_lang(enum language lang)
Definition read.h:360
unsigned int is_dwz
Definition read.h:139
std::unique_ptr< file_and_directory > fnd
Definition read.h:215
int offset_size() const
Definition read.c:23588
struct quick_file_names * file_names
Definition read.h:220
const comp_unit_head * get_header() const
Definition read.c:23559
dwarf_unit_type unit_type(bool strict_p=true) const
Definition read.h:330
void set_length(unsigned int length, bool strict_p=true)
Definition read.h:302
std::vector< dwarf2_per_cu_data * > * imported_symtabs
Definition read.h:246
void imported_symtabs_push(dwarf2_per_cu_data *p)
Definition read.h:256
enum language lang(bool strict_p=true) const
Definition read.h:352
dwarf2_per_bfd * per_bfd
Definition read.h:200
packed< bool, 1 > addresses_seen
Definition read.h:177
comp_unit_head m_header
Definition read.h:209
void free_cached_file_names()
Definition read.c:2900
unsigned int mark
Definition read.h:165
int addr_size() const
Definition read.c:23580
unsigned int is_debug_types
Definition read.h:136
int ref_addr_size() const
Definition read.c:23596
unsigned int tu_read
Definition read.h:155
unsigned int length() const
Definition read.h:295
void set_unit_type(dwarf_unit_type unit_type)
Definition read.h:338
const struct dwarf2_per_cu_data * per_cu
Definition read.c:23884
struct objfile * objfile
Definition read.h:648
std::unordered_map< type_unit_group *, type_unit_group_unshareable_up > m_type_units
Definition read.h:680
std::unordered_map< signatured_type *, struct type * > m_type_map
Definition read.h:683
compunit_symtab * get_symtab(const dwarf2_per_cu_data *per_cu) const
Definition read.c:1526
type_unit_group_unshareable * get_type_unit_group_unshareable(type_unit_group *tu_group)
Definition read.c:8266
void remove_cu(dwarf2_per_cu_data *per_cu)
Definition read.c:23854
const char * read_line_string(const gdb_byte *buf, const struct comp_unit_head *cu_header, unsigned int *bytes_read_ptr)
Definition read.c:19389
void age_comp_units()
Definition read.c:23809
dwarf2_cu * sym_cu
Definition read.h:663
std::unique_ptr< type_unit_group_unshareable > type_unit_group_unshareable_up
Definition read.h:677
void set_type_for_signatured_type(signatured_type *sig_type, struct type *type)
Definition read.c:8290
void set_cu(dwarf2_per_cu_data *per_cu, std::unique_ptr< dwarf2_cu > cu)
Definition read.c:23798
struct type * get_type_for_signatured_type(signatured_type *sig_type) const
Definition read.c:8280
gdb::optional< std::queue< dwarf2_queue_item > > queue
Definition read.h:666
std::unordered_map< dwarf2_per_cu_data *, std::unique_ptr< dwarf2_cu > > m_dwarf2_cus
Definition read.h:688
htab_up die_type_hash
Definition read.h:657
void set_symtab(const dwarf2_per_cu_data *per_cu, compunit_symtab *symtab)
Definition read.c:1536
struct dwarf2_per_bfd * per_bfd
Definition read.h:652
void remove_all_cus()
Definition read.c:1482
htab_up line_header_hash
Definition read.h:660
bool symtab_set_p(const dwarf2_per_cu_data *per_cu) const
Definition read.c:1516
std::vector< compunit_symtab * > m_symtabs
Definition read.h:672
dwarf2_cu * get_cu(dwarf2_per_cu_data *per_cu)
Definition read.c:23786
struct dwarf2_offset_baton offset_info
Definition loc.h:243
struct dwarf2_locexpr_baton locexpr
Definition loc.h:237
struct dwarf2_loclist_baton loclist
Definition loc.h:240
struct type * property_type
Definition loc.h:232
dwarf2_per_objfile * per_objfile
Definition read.h:78
enum language pretend_language
Definition read.h:79
dwarf2_per_cu_data * per_cu
Definition read.h:77
void read(struct objfile *objfile)
Definition section.c:119
bool empty() const
Definition section.c:111
union dwarf2_section_info::@50 s
bfd_size_type virtual_offset
Definition section.h:120
const char * get_name() const
Definition section.c:74
void overflow_complaint() const
Definition section.c:34
const char * read_string(struct objfile *objfile, LONGEST str_offset, const char *form_name)
Definition section.c:194
struct dwarf2_section_info * containing_section
Definition section.h:112
const gdb_byte * buffer
Definition section.h:115
const char * get_file_name() const
Definition section.c:83
bfd_size_type size
Definition section.h:117
int get_id() const
Definition section.c:92
struct bfd * get_bfd_owner() const
Definition section.c:49
int get_flags() const
Definition section.c:102
asection * section
Definition section.h:109
bool matches(const char *name) const
Definition sect-names.h:36
size_t size
Definition attribute.h:37
const gdb_byte * data
Definition attribute.h:40
gdb_bfd_ref_ptr dbfd
Definition read.c:506
htab_up tus
Definition read.c:521
DISABLE_COPY_AND_ASSIGN(dwo_file)
const char * dwo_name
Definition read.c:499
const char * comp_dir
Definition read.c:502
dwo_file()=default
htab_up cus
Definition read.c:517
struct dwarf2_section_info rnglists
Definition read.c:439
std::vector< dwarf2_section_info > types
Definition read.c:444
struct dwarf2_section_info abbrev
Definition read.c:433
struct dwarf2_section_info str_offsets
Definition read.c:441
struct dwarf2_section_info loclists
Definition read.c:436
struct dwarf2_section_info macro
Definition read.c:438
struct dwarf2_section_info loc
Definition read.c:435
struct dwarf2_section_info info
Definition read.c:443
struct dwarf2_section_info macinfo
Definition read.c:437
struct dwarf2_section_info str
Definition read.c:440
struct dwarf2_section_info line
Definition read.c:434
ULONGEST signature
Definition read.c:457
sect_offset sect_off
Definition read.c:463
struct dwarf2_section_info * section
Definition read.c:460
cu_offset type_offset_in_tu
Definition read.c:467
struct dwo_file * dwo_file
Definition read.c:452
unsigned int length
Definition read.c:464
struct dwarf2_section_names str_dwo
Definition read.c:357
struct dwarf2_section_names types_dwo
Definition read.c:359
struct dwarf2_section_names loclists_dwo
Definition read.c:353
struct dwarf2_section_names str_offsets_dwo
Definition read.c:358
struct dwarf2_section_names line_dwo
Definition read.c:351
struct dwarf2_section_names cu_index
Definition read.c:360
struct dwarf2_section_names tu_index
Definition read.c:361
struct dwarf2_section_names macinfo_dwo
Definition read.c:354
struct dwarf2_section_names rnglists_dwo
Definition read.c:356
struct dwarf2_section_names info_dwo
Definition read.c:350
struct dwarf2_section_names macro_dwo
Definition read.c:355
struct dwarf2_section_names loc_dwo
Definition read.c:352
struct dwarf2_section_names abbrev_dwo
Definition read.c:349
int version
Definition read.c:667
unsigned int num_sections
Definition read.c:687
asection ** elf_sections
Definition read.c:688
htab_up loaded_tus
Definition read.c:683
const char * name
Definition read.c:664
gdb_bfd_ref_ptr dbfd
Definition read.c:670
htab_up loaded_cus
Definition read.c:682
const struct dwp_hash_table * tus
Definition read.c:679
const struct dwp_hash_table * cus
Definition read.c:676
dwp_file(const char *name_, gdb_bfd_ref_ptr &&abfd)
Definition read.c:657
int section_ids[MAX_NR_V2_DWO_SECTIONS]
Definition read.c:630
const gdb_byte * indices
Definition read.c:617
const gdb_byte * sizes
Definition read.c:632
const gdb_byte * unit_table
Definition read.c:612
union dwp_hash_table::@46 section_pool
const gdb_byte * hash_table
Definition read.c:612
uint32_t nr_units
Definition read.c:611
const gdb_byte * offsets
Definition read.c:631
struct dwp_hash_table::@46::@49 v5
uint32_t nr_slots
Definition read.c:611
uint32_t version
Definition read.c:610
struct dwp_hash_table::@46::@47 v1
struct dwp_hash_table::@46::@48 v2
uint32_t nr_columns
Definition read.c:610
struct dwarf2_section_info loc
Definition read.c:544
struct dwarf2_section_info cu_index
Definition read.c:530
struct dwarf2_section_info rnglists
Definition read.c:548
struct dwarf2_section_info str
Definition read.c:529
struct dwarf2_section_info line
Definition read.c:543
struct dwarf2_section_info info
Definition read.c:542
struct dwarf2_section_info macro
Definition read.c:547
struct dwarf2_section_info tu_index
Definition read.c:531
struct dwarf2_section_info str_offsets
Definition read.c:549
struct dwarf2_section_info types
Definition read.c:550
struct dwarf2_section_info macinfo
Definition read.c:546
struct dwarf2_section_info loclists
Definition read.c:545
struct dwarf2_section_info abbrev
Definition read.c:541
Definition dwz.h:32
const char * read_string(struct objfile *objfile, LONGEST str_offset)
Definition dwz.c:34
gdb_bfd_ref_ptr dwz_bfd
Definition dwz.h:53
std::unique_ptr< index_cache_resource > index_cache_res
Definition dwz.h:57
LONGEST const_val() const
Definition gdbtypes.h:347
dynamic_prop_kind kind() const
Definition gdbtypes.h:337
void set_loclist(void *baton)
Definition gdbtypes.h:375
void set_variable_name(const char *name)
Definition gdbtypes.h:423
void set_undefined()
Definition gdbtypes.h:342
void * baton() const
Definition gdbtypes.h:360
void set_addr_offset(void *baton)
Definition gdbtypes.h:381
void set_locexpr(void *baton)
Definition gdbtypes.h:369
void set_variant_parts(gdb::array_view< variant_part > *variant_parts)
Definition gdbtypes.h:394
void set_const_val(LONGEST const_val)
Definition gdbtypes.h:354
std::vector< struct nextfield > fields
Definition read.c:840
std::vector< struct fnfieldlist > fnfieldlists
Definition read.c:849
std::vector< variant_part_builder > variant_parts
Definition read.c:864
bool non_public_fields
Definition read.c:844
std::vector< struct decl_field > typedef_field_list
Definition read.c:853
std::vector< struct decl_field > nested_types_list
Definition read.c:857
variant_part_builder * current_variant_part
Definition read.c:861
int nfields() const
Definition read.c:867
std::vector< struct nextfield > baseclasses
Definition read.c:841
void set_type(struct type *type)
Definition gdbtypes.h:564
void set_loc_bitpos(LONGEST bitpos)
Definition gdbtypes.h:592
LONGEST loc_bitpos() const
Definition gdbtypes.h:586
void set_loc_dwarf_block(dwarf2_locexpr_baton *dwarf_block)
Definition gdbtypes.h:640
void set_loc_physname(const char *physname)
Definition gdbtypes.h:628
field_loc_kind loc_kind() const
Definition gdbtypes.h:581
LONGEST loc_enumval() const
Definition gdbtypes.h:598
void set_loc_enumval(LONGEST enumval)
Definition gdbtypes.h:604
void set_name(const char *name)
Definition gdbtypes.h:574
const char * name() const
Definition gdbtypes.h:569
struct type * type() const
Definition gdbtypes.h:559
const char * get_name() const
bool is_unknown() const
void set_name(gdb::unique_xmalloc_ptr< char > name)
const char * get_comp_dir() const
void set_comp_dir(std::string &&dir)
const char * get_fullname()
const char * intern_comp_dir(struct objfile *objfile)
Definition line-header.h:36
dir_index d_index
Definition line-header.h:60
struct symtab * symtab
Definition line-header.h:67
const char * name
Definition line-header.h:54
const char * include_dir(const line_header *lh) const
unsigned int is_private
Definition gdbtypes.h:1517
unsigned int is_artificial
Definition gdbtypes.h:1519
__extension__ enum dwarf_defaulted_attribute defaulted
Definition gdbtypes.h:1537
struct type * type
Definition gdbtypes.h:1506
const char * physname
Definition gdbtypes.h:1498
unsigned int voffset
Definition gdbtypes.h:1546
struct type * fcontext
Definition gdbtypes.h:1511
unsigned int is_constructor
Definition gdbtypes.h:1528
unsigned int is_protected
Definition gdbtypes.h:1518
unsigned int is_deleted
Definition gdbtypes.h:1532
struct fn_field * fn_fields
Definition gdbtypes.h:1481
std::vector< struct fn_field > fnfields
Definition read.c:831
const char * name
Definition read.c:830
mpq_t val
Definition gmp-utils.h:148
mpz_t val
Definition gmp-utils.h:40
void set_demangled_name(const char *name, struct obstack *obstack)
Definition symtab.c:746
struct obstack * obstack
Definition symtab.h:568
const char * natural_name() const
Definition symtab.c:1027
const gdb_byte * bytes
Definition symtab.h:546
const char * print_name() const
Definition symtab.h:474
void compute_and_set_names(gdb::string_view linkage_name, bool copy_name, struct objfile_per_bfd_storage *per_bfd, gdb::optional< hashval_t > hash=gdb::optional< hashval_t >())
Definition symtab.c:914
const char * search_name() const
Definition symtab.c:1077
enum language language() const
Definition symtab.h:501
void set_language(enum language language, struct obstack *obstack)
Definition symtab.c:771
short section_index() const
Definition symtab.h:604
const char * linkage_name() const
Definition symtab.h:459
void set_linkage_name(const char *linkage_name)
Definition symtab.h:493
enum language la_language
Definition language.h:275
virtual void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const =0
symbol_name_matcher_ftype * get_symbol_name_matcher(const lookup_name_info &lookup_name) const
Definition language.c:686
virtual char * class_name_from_physname(const char *physname) const
Definition language.h:480
virtual bool store_sym_names_in_linkage_form_p() const
Definition language.h:623
virtual void printchar(int ch, struct type *chtype, struct ui_file *stream) const
Definition c-lang.c:159
virtual enum array_ordering array_ordering() const
Definition language.h:643
unsigned char minimum_instruction_length
const gdb_byte * statement_program_end
file_entry * file_name_at(file_name_index index)
unsigned offset_in_dwz
const gdb_byte * statement_program_start
unsigned char line_range
std::string file_file_name(const file_entry &fe) const
Definition line-header.c:61
void add_file_name(const char *name, dir_index d_index, unsigned int mod_time, unsigned int length)
Definition line-header.c:46
unsigned char default_is_stmt
std::unique_ptr< unsigned char[]> standard_opcode_lengths
sect_offset sect_off
std::vector< file_entry > & file_names()
unsigned char maximum_ops_per_instruction
const char * include_dir_at(dir_index index) const
Definition line-header.h:98
unsigned char opcode_base
int file_names_size() const
unsigned char addr_size
Definition read.c:396
unsigned char segment_collector_size
Definition read.c:400
unsigned int offset_entry_count
Definition read.c:403
unsigned int length
Definition read.c:389
struct dynamic_prop_list * dyn_prop_list
Definition gdbtypes.h:911
std::vector< attr > attr_vec
Definition read.c:287
uint32_t cu_count
Definition read.c:265
bool dwarf5_is_dwarf64
Definition read.c:262
const char * namei_to_name(uint32_t namei, dwarf2_per_objfile *per_objfile) const
Definition read.c:4837
const gdb_byte * tu_table_reordered
Definition read.c:267
uint8_t offset_size
Definition read.c:264
quick_symbol_functions_up make_quick_functions() const override
Definition read.c:1945
bool augmentation_is_gdb
Definition read.c:263
const gdb_byte * name_table_string_offs_reordered
Definition read.c:269
bfd_endian dwarf5_byte_order
Definition read.c:261
const gdb_byte * entry_pool
Definition read.c:271
const uint32_t * hash_table_reordered
Definition read.c:268
const gdb_byte * cu_table_reordered
Definition read.c:267
uint32_t bucket_count
Definition read.c:266
size_t symbol_name_count() const override
Definition read.c:302
const uint32_t * bucket_table_reordered
Definition read.c:268
std::unordered_map< ULONGEST, index_val > abbrev_map
Definition read.c:290
uint32_t name_count
Definition read.c:266
const char * symbol_name_at(offset_type idx, dwarf2_per_objfile *per_objfile) const override
Definition read.c:299
uint32_t tu_count
Definition read.c:266
const gdb_byte * name_table_entry_offs_reordered
Definition read.c:270
virtual size_t symbol_name_count() const =0
enum case_sensitivity name_components_casing
std::pair< std::vector< name_component >::const_iterator, std::vector< name_component >::const_iterator > find_name_components_bounds(const lookup_name_info &ln_no_params, enum language lang, dwarf2_per_objfile *per_objfile) const
Definition read.c:3262
void build_name_components(dwarf2_per_objfile *per_objfile)
Definition read.c:3335
std::vector< name_component > name_components
virtual const char * symbol_name_at(offset_type idx, dwarf2_per_objfile *per_objfile) const =0
virtual bool symbol_name_slot_invalid(offset_type idx) const
offset_type symbol_name_index(offset_type idx) const
Definition read.c:219
gdb::array_view< const gdb_byte > constant_pool
Definition read.c:215
int version
Definition read.c:206
gdb::array_view< const gdb_byte > address_table
Definition read.c:209
size_t symbol_name_count() const override
Definition read.c:246
const char * symbol_name_at(offset_type idx, dwarf2_per_objfile *per_objfile) const override
Definition read.c:240
offset_view symbol_table
Definition read.c:212
bool symbol_name_slot_invalid(offset_type idx) const override
Definition read.c:231
offset_type symbol_vec_index(offset_type idx) const
Definition read.c:226
bool version_check() const override
Definition read.c:251
quick_symbol_functions_up make_quick_functions() const override
Definition read.c:1939
offset_type name_offset
offset_type idx
int virtuality
Definition read.c:820
int accessibility
Definition read.c:819
sect_offset offset
Definition read.c:824
auto_obstack storage_obstack
Definition objfiles.h:265
struct type * builtin_int
Definition gdbtypes.h:2343
struct type * builtin_void
Definition gdbtypes.h:2340
const char * original_name
Definition objfiles.h:631
struct objfile * separate_debug_objfile_backlink
Definition objfiles.h:743
int sect_index_data
Definition objfiles.h:712
struct gdbarch * arch() const
Definition objfiles.h:482
struct objfile_per_bfd_storage * per_bfd
Definition objfiles.h:657
gdb_bfd_ref_ptr obfd
Definition objfiles.h:653
CORE_ADDR text_section_offset() const
Definition objfiles.h:457
const char * intern(const char *str)
Definition objfiles.h:469
objfile_flags flags
Definition objfiles.h:637
auto_obstack objfile_obstack
Definition objfiles.h:673
std::forward_list< quick_symbol_functions_up > qf
Definition objfiles.h:685
CORE_ADDR data_section_offset() const
Definition objfiles.h:462
struct symbol * template_symbols
Definition objfiles.h:759
::section_offsets section_offsets
Definition objfiles.h:699
int nsyms
Definition buildsym.h:80
struct symbol * symbol[PENDINGSIZE]
Definition buildsym.h:81
struct pending * next
Definition buildsym.h:79
const char ** real_names
Definition read.c:1813
const char * comp_dir
Definition read.c:1805
unsigned int num_file_names
Definition read.c:1801
const char ** file_names
Definition read.c:1809
struct stmt_list_hash hash
Definition read.c:1798
struct dynamic_prop high
Definition gdbtypes.h:696
unsigned int flag_upper_bound_is_count
Definition gdbtypes.h:713
struct dynamic_prop low
Definition gdbtypes.h:692
bool expand_symtabs_matching(struct objfile *objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info *lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, domain_enum domain, enum search_domain kind) override
Definition read.c:1881
void expand_matching_symbols(struct objfile *, const lookup_name_info &lookup_name, domain_enum domain, int global, symbol_compare_ftype *ordered_compare) override
Definition read.c:1872
void dump(struct objfile *objfile) override
Definition read.c:1867
struct type * concrete_type
Definition symtab.h:1538
ULONGEST signature
Definition read.h:388
struct dwo_unit * dwo_unit
Definition read.h:408
sect_offset type_offset_in_section
Definition read.h:400
struct type_unit_group * type_unit_group
Definition read.h:404
cu_offset type_offset_in_tu
Definition read.h:393
dwarf2_per_objfile * per_objfile
Definition read.c:7011
cooked_index_storage * storage
Definition read.c:7012
struct dwo_unit * dwo_unit
Definition read.c:412
sect_offset line_sect_off
Definition read.c:415
std::string name
Definition buildsym.h:57
std::string name_for_id
Definition buildsym.h:62
struct symtab * symtab
Definition buildsym.h:66
address_class aclass() const
Definition symtab.h:1235
unsigned maybe_copied
Definition symtab.h:1448
struct type * type() const
Definition symtab.h:1285
void set_line(unsigned short line)
Definition symtab.h:1300
void set_aclass_index(unsigned int aclass_index)
Definition symtab.h:1225
void set_is_artificial(bool artificial)
Definition symtab.h:1375
__extension__ enum symbol_subclass_kind subclass
Definition symtab.h:1452
void set_type(struct type *type)
Definition symtab.h:1290
void set_is_argument(bool is_argument)
Definition symtab.h:1265
void set_value_address(CORE_ADDR address)
Definition symtab.h:1323
CORE_ADDR value_address() const
Definition symtab.h:1315
void set_value_bytes(const gdb_byte *bytes)
Definition symtab.h:1333
struct symtab * symtab
Definition symtab.h:1414
void set_is_inlined(bool is_inlined)
Definition symtab.h:1275
void set_value_longest(LONGEST value)
Definition symtab.h:1310
struct symbol * hash_next
Definition symtab.h:1485
void set_domain(domain_enum domain)
Definition symtab.h:1245
void set_symtab(struct symtab *symtab)
Definition symtab.c:6505
void set_value_common_block(const common_block *common_block)
Definition symtab.h:1343
enum language language() const
Definition symtab.h:1623
void set_language(enum language language)
Definition symtab.h:1628
int n_template_arguments
Definition symtab.h:1525
struct symbol ** template_arguments
Definition symtab.h:1529
tu_abbrev_offset(signatured_type *sig_type_, sect_offset abbrev_offset_)
Definition read.c:6882
signatured_type * sig_type
Definition read.c:6892
sect_offset abbrev_offset
Definition read.c:6893
bool operator<(const tu_abbrev_offset &other) const
Definition read.c:6887
int nr_stmt_less_type_units
Definition read.h:47
int nr_all_type_units_reallocs
Definition read.h:48
int nr_tus
Definition read.h:49
int nr_uniq_abbrev_tables
Definition read.h:44
int nr_symtabs
Definition read.h:45
int nr_symtab_sharers
Definition read.h:46
struct symtab ** symtabs
Definition read.h:582
struct compunit_symtab * compunit_symtab
Definition read.h:568
struct type * target_type() const
Definition gdbtypes.h:1000
type_code code() const
Definition gdbtypes.h:927
void set_is_prototyped(bool is_prototyped)
Definition gdbtypes.h:1127
void set_code(type_code code)
Definition gdbtypes.h:933
ULONGEST length() const
Definition gdbtypes.h:954
void set_is_multi_dimensional(bool value)
Definition gdbtypes.h:1261
bool has_varargs() const
Definition gdbtypes.h:1135
void set_endianity_is_not_default(bool endianity_is_not_default)
Definition gdbtypes.h:1218
struct field & field(int idx) const
Definition gdbtypes.h:983
void set_has_no_signedness(bool has_no_signedness)
Definition gdbtypes.h:1082
void set_index_type(type *index_type)
Definition gdbtypes.h:1010
void set_target_type(struct type *target_type)
Definition gdbtypes.h:1005
bool is_unsigned() const
Definition gdbtypes.h:1063
struct main_type * main_type
Definition gdbtypes.h:1463
void set_is_unsigned(bool is_unsigned)
Definition gdbtypes.h:1068
void set_is_stub(bool is_stub)
Definition gdbtypes.h:1096
void set_is_declared_class(bool is_declared_class) const
Definition gdbtypes.h:1235
void set_has_varargs(bool has_varargs)
Definition gdbtypes.h:1140
void set_is_flag_enum(bool is_flag_enum)
Definition gdbtypes.h:1249
void set_bounds(range_bounds *bounds)
Definition gdbtypes.h:1046
void set_num_fields(int num_fields)
Definition gdbtypes.h:971
bool is_declared_class() const
Definition gdbtypes.h:1230
int num_fields() const
Definition gdbtypes.h:965
bool is_stub() const
Definition gdbtypes.h:1091
bool has_no_signedness() const
Definition gdbtypes.h:1077
void add_dyn_prop(dynamic_prop_node_kind kind, dynamic_prop prop)
Definition gdbtypes.c:2935
void set_name(const char *name)
Definition gdbtypes.h:945
struct fixed_point_type_info & fixed_point_info() const
Definition gdbtypes.h:1269
ULONGEST bit_stride() const
Definition gdbtypes.h:1053
void set_length(ULONGEST length)
Definition gdbtypes.h:959
struct field * fields() const
Definition gdbtypes.h:977
range_bounds * bounds() const
Definition gdbtypes.h:1028
const char * name() const
Definition gdbtypes.h:939
type * index_type() const
Definition gdbtypes.h:995
void set_stub_is_supported(bool stub_is_supported)
Definition gdbtypes.h:1169
unsigned short bit_offset() const
Definition gdbtypes.h:1387
void set_fields(struct field *fields)
Definition gdbtypes.h:990
void set_target_is_stub(bool target_is_stub)
Definition gdbtypes.h:1112
Definition value.c:181
int last_field
Definition read.c:787
struct dwarf_block * discr_list_data
Definition read.c:800
std::vector< variant_part_builder > variant_parts
Definition read.c:790
ULONGEST discriminant_value
Definition read.c:797
int first_field
Definition read.c:786
bool default_branch
Definition read.c:794
bool processing_variant
Definition read.c:814
sect_offset discriminant_offset
Definition read.c:808
std::vector< variant_field > variants
Definition read.c:811
int discriminant_index
Definition gdbtypes.h:278
gdb::array_view< variant > variants
Definition gdbtypes.h:286
bool is_unsigned
Definition gdbtypes.h:282
int last_field
Definition gdbtypes.h:250
gdb::array_view< variant_part > parts
Definition gdbtypes.h:253
int first_field
Definition gdbtypes.h:249
gdb::array_view< discriminant_range > discriminants
Definition gdbtypes.h:243
struct dwarf2_section_info info_or_types
Definition read.c:566
struct dwarf2_section_info abbrev
Definition read.c:558
struct dwarf2_section_info macro
Definition read.c:562
struct dwarf2_section_info str_offsets
Definition read.c:563
struct dwarf2_section_info macinfo
Definition read.c:561
struct dwarf2_section_info line
Definition read.c:559
struct dwarf2_section_info loc
Definition read.c:560
bfd_size_type loc_offset
Definition read.c:582
bfd_size_type abbrev_offset
Definition read.c:576
bfd_size_type abbrev_size
Definition read.c:577
bfd_size_type macro_offset
Definition read.c:591
bfd_size_type str_offsets_offset
Definition read.c:597
bfd_size_type loclists_offset
Definition read.c:585
bfd_size_type rnglists_size
Definition read.c:595
bfd_size_type str_offsets_size
Definition read.c:598
bfd_size_type macinfo_offset
Definition read.c:588
bfd_size_type macinfo_size
Definition read.c:589
bfd_size_type line_size
Definition read.c:580
bfd_size_type rnglists_offset
Definition read.c:594
bfd_size_type loc_size
Definition read.c:583
bfd_size_type line_offset
Definition read.c:579
bfd_size_type info_or_types_size
Definition read.c:603
bfd_size_type info_or_types_offset
Definition read.c:602
bfd_size_type macro_size
Definition read.c:592
bfd_size_type loclists_size
Definition read.c:586
struct symtab * allocate_symtab(struct compunit_symtab *cust, const char *filename, const char *filename_for_id)
Definition symfile.c:2778
scoped_restore_tmpl< int > increment_reading_symtab(void)
Definition symfile.c:187
int register_symbol_block_impl(enum address_class aclass, const struct symbol_block_ops *ops)
Definition symtab.c:6424
int register_symbol_computed_impl(enum address_class aclass, const struct symbol_computed_ops *ops)
Definition symtab.c:6398
bool producer_is_realview(const char *producer)
Definition symtab.c:6346
struct symbol * fixup_symbol_section(struct symbol *sym, struct objfile *objfile)
Definition symtab.c:1788
bool basenames_may_differ
Definition symtab.c:273
search_domain
Definition symtab.h:916
@ VARIABLES_DOMAIN
Definition symtab.h:919
@ FUNCTIONS_DOMAIN
Definition symtab.h:922
@ TYPES_DOMAIN
Definition symtab.h:925
@ MODULES_DOMAIN
Definition symtab.h:928
@ ALL_DOMAIN
Definition symtab.h:931
symbol_name_match_type
Definition symtab.h:62
bool() symbol_name_matcher_ftype(const char *symbol_search_name, const lookup_name_info &lookup_name, completion_match_result *comp_match_res)
Definition symtab.h:398
@ LOC_STATIC
Definition symtab.h:950
@ LOC_BLOCK
Definition symtab.h:999
@ LOC_LABEL
Definition symtab.h:993
@ LOC_UNRESOLVED
Definition symtab.h:1028
@ LOC_CONST
Definition symtab.h:946
@ LOC_CONST_BYTES
Definition symtab.h:1004
@ LOC_OPTIMIZED_OUT
Definition symtab.h:1033
@ LOC_TYPEDEF
Definition symtab.h:989
@ LOC_COMMON_BLOCK
Definition symtab.h:1041
@ LOC_COMPUTED
Definition symtab.h:1037
@ SYMBOL_RUST_VTABLE
Definition symtab.h:1189
@ SYMBOL_TEMPLATE
Definition symtab.h:1186
#define SYMBOL_COMPUTED_OPS(symbol)
Definition symtab.h:1504
domain_enum
Definition symtab.h:871
@ VAR_DOMAIN
Definition symtab.h:881
@ STRUCT_DOMAIN
Definition symtab.h:887
@ LABEL_DOMAIN
Definition symtab.h:895
@ COMMON_BLOCK_DOMAIN
Definition symtab.h:899
@ UNDEF_DOMAIN
Definition symtab.h:876
@ MODULE_DOMAIN
Definition symtab.h:891
#define SYMBOL_LOCATION_BATON(symbol)
Definition symtab.h:1507
const struct type_print_options type_print_raw_options
Definition typeprint.c:41
std::string ldirname(const char *filename)
Definition utils.c:3254
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition utils.c:3114
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1865
void gdb_puts(const char *linebuffer, struct ui_file *stream)
Definition utils.c:1788
#define gdb_stderr
Definition utils.h:193
#define gdb_stdlog
Definition utils.h:196
void get_formatted_print_options(struct value_print_options *opts, char format)
Definition valprint.c:145
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:1172
struct value * allocate_value(struct type *type)
Definition value.c:1053
struct value * value_from_longest(struct type *type, LONGEST num)
Definition value.c:3625
gdb::array_view< gdb_byte > value_contents_writeable(struct value *value)
Definition value.c:1473
value_ref_ptr release_value(struct value *val)
Definition value.c:1714
const char version[]
Definition version.c:2