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"
46#include "dwarf2/sect-names.h"
47#include "dwarf2/stringify.h"
48#include "dwarf2/public.h"
49#include "bfd.h"
50#include "elf-bfd.h"
51#include "symtab.h"
52#include "gdbtypes.h"
53#include "objfiles.h"
54#include "dwarf2.h"
55#include "demangle.h"
56#include "gdb-demangle.h"
57#include "filenames.h"
58#include "language.h"
59#include "complaints.h"
60#include "dwarf2/expr.h"
61#include "dwarf2/loc.h"
62#include "cp-support.h"
63#include "hashtab.h"
64#include "command.h"
65#include "gdbcmd.h"
66#include "block.h"
67#include "addrmap.h"
68#include "typeprint.h"
69#include "c-lang.h"
70#include "go-lang.h"
71#include "valprint.h"
72#include "gdbcore.h"
73#include "gdb/gdb-index.h"
74#include "gdb_bfd.h"
75#include "f-lang.h"
76#include "source.h"
77#include "build-id.h"
78#include "namespace.h"
79#include "gdbsupport/function-view.h"
80#include "gdbsupport/gdb_optional.h"
81#include "gdbsupport/underlying.h"
82#include "gdbsupport/hash_enum.h"
83#include "filename-seen-cache.h"
84#include "producer.h"
85#include <fcntl.h>
86#include <algorithm>
87#include <unordered_map>
88#include "gdbsupport/selftest.h"
89#include "rust-lang.h"
90#include "gdbsupport/pathstuff.h"
91#include "count-one-bits.h"
92#include <unordered_set>
93#include "dwarf2/abbrev-cache.h"
94#include "cooked-index.h"
95#include "split-name.h"
96#include "gdbsupport/parallel-for.h"
97#include "gdbsupport/thread-pool.h"
98
99/* When == 1, print basic high level tracing messages.
100 When > 1, be more verbose.
101 This is in contrast to the low level DIE reading of dwarf_die_debug. */
102static unsigned int dwarf_read_debug = 0;
103
104/* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
105
106#define dwarf_read_debug_printf(fmt, ...) \
107 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
108 ##__VA_ARGS__)
109
110/* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
111
112#define dwarf_read_debug_printf_v(fmt, ...) \
113 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
114 ##__VA_ARGS__)
115
116/* When non-zero, dump DIEs after they are read in. */
117static unsigned int dwarf_die_debug = 0;
118
119/* When non-zero, dump line number entries as they are read in. */
120unsigned int dwarf_line_debug = 0;
121
122/* When true, cross-check physname against demangler. */
123static bool check_physname = false;
124
125/* This is used to store the data that is always per objfile. */
128
129/* These are used to store the dwarf2_per_bfd objects.
130
131 objfiles having the same BFD, which doesn't require relocations, are going to
132 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
133
134 Other objfiles are not going to share a dwarf2_per_bfd with any other
135 objfiles, so they'll have their own version kept in the _objfile_data_key
136 version. */
140
141/* The "aclass" indices for various kinds of computed DWARF symbols. */
142
149
150/* Size of .debug_loclists section header for 32-bit DWARF format. */
151#define LOCLIST_HEADER_SIZE32 12
152
153/* Size of .debug_loclists section header for 64-bit DWARF format. */
154#define LOCLIST_HEADER_SIZE64 20
155
156/* Size of .debug_rnglists section header for 32-bit DWARF format. */
157#define RNGLIST_HEADER_SIZE32 12
158
159/* Size of .debug_rnglists section header for 64-bit DWARF format. */
160#define RNGLIST_HEADER_SIZE64 20
161
162/* See dwarf2/read.h. */
163
169
170/* Default names of the debugging sections. */
171
172/* Note that if the debugging section has been compressed, it might
173 have a name like .zdebug_info. */
174
176{
177 { ".debug_info", ".zdebug_info" },
178 { ".debug_abbrev", ".zdebug_abbrev" },
179 { ".debug_line", ".zdebug_line" },
180 { ".debug_loc", ".zdebug_loc" },
181 { ".debug_loclists", ".zdebug_loclists" },
182 { ".debug_macinfo", ".zdebug_macinfo" },
183 { ".debug_macro", ".zdebug_macro" },
184 { ".debug_str", ".zdebug_str" },
185 { ".debug_str_offsets", ".zdebug_str_offsets" },
186 { ".debug_line_str", ".zdebug_line_str" },
187 { ".debug_ranges", ".zdebug_ranges" },
188 { ".debug_rnglists", ".zdebug_rnglists" },
189 { ".debug_types", ".zdebug_types" },
190 { ".debug_addr", ".zdebug_addr" },
191 { ".debug_frame", ".zdebug_frame" },
192 { ".eh_frame", NULL },
193 { ".gdb_index", ".zgdb_index" },
194 { ".debug_names", ".zdebug_names" },
195 { ".debug_aranges", ".zdebug_aranges" },
196 23
197};
198
199/* List of DWO/DWP sections. */
200
218{
219 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
220 { ".debug_info.dwo", ".zdebug_info.dwo" },
221 { ".debug_line.dwo", ".zdebug_line.dwo" },
222 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
223 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
224 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
225 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
226 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
227 { ".debug_str.dwo", ".zdebug_str.dwo" },
228 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
229 { ".debug_types.dwo", ".zdebug_types.dwo" },
230 { ".debug_cu_index", ".zdebug_cu_index" },
231 { ".debug_tu_index", ".zdebug_tu_index" },
233
234/* local data types */
235
236/* The location list and range list sections (.debug_loclists & .debug_rnglists)
237 begin with a header, which contains the following information. */
239{
240 /* A 4-byte or 12-byte length containing the length of the
241 set of entries for this compilation unit, not including the
242 length field itself. */
243 unsigned int length;
244
245 /* A 2-byte version identifier. */
246 short version;
247
248 /* A 1-byte unsigned integer containing the size in bytes of an address on
249 the target system. */
250 unsigned char addr_size;
251
252 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
253 on the target system. */
255
256 /* A 4-byte count of the number of offsets that follow the header. */
257 unsigned int offset_entry_count;
258};
259
260/* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
261 This includes type_unit_group and quick_file_names. */
262
264{
265 /* The DWO unit this table is from or NULL if there is none. */
267
268 /* Offset in .debug_line or .debug_line.dwo. */
269 sect_offset line_sect_off;
270};
271
272/* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
273 an object of this type. This contains elements of type unit groups
274 that can be shared across objfiles. The non-shareable parts are in
275 type_unit_group_unshareable. */
276
278{
279 /* The data used to construct the hash key. */
281};
282
283/* These sections are what may appear in a (real or virtual) DWO file. */
284
286{
296 /* In the case of a virtual DWO file, these two are unused. */
298 std::vector<dwarf2_section_info> types;
299};
300
301/* CUs/TUs in DWP/DWO files. */
302
304{
305 /* Backlink to the containing struct dwo_file. */
307
308 /* The "id" that distinguishes this CU/TU.
309 .debug_info calls this "dwo_id", .debug_types calls this "signature".
310 Since signatures came first, we stick with it for consistency. */
311 ULONGEST signature;
312
313 /* The section this CU/TU lives in, in the DWO file. */
315
316 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
317 sect_offset sect_off;
318 unsigned int length;
319
320 /* For types, offset in the type's DIE of the type defined by this TU. */
322};
323
324/* include/dwarf2.h defines the DWP section codes.
325 It defines a max value but it doesn't define a min value, which we
326 use for error checking, so provide one. */
327
332
333/* Data for one DWO file.
334
335 This includes virtual DWO files (a virtual DWO file is a DWO file as it
336 appears in a DWP file). DWP files don't really have DWO files per se -
337 comdat folding of types "loses" the DWO file they came from, and from
338 a high level view DWP files appear to contain a mass of random types.
339 However, to maintain consistency with the non-DWP case we pretend DWP
340 files contain virtual DWO files, and we assign each TU with one virtual
341 DWO file (generally based on the line and abbrev section offsets -
342 a heuristic that seems to work in practice). */
343
345{
346 dwo_file () = default;
348
349 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
350 For virtual DWO files the name is constructed from the section offsets
351 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
352 from related CU+TUs. */
353 const char *dwo_name = nullptr;
354
355 /* The DW_AT_comp_dir attribute. */
356 const char *comp_dir = nullptr;
357
358 /* The bfd, when the file is open. Otherwise this is NULL.
359 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
361
362 /* The sections that make up this DWO file.
363 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
364 sections (for lack of a better name). */
366
367 /* The CUs in the file.
368 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
369 an extension to handle LLVM's Link Time Optimization output (where
370 multiple source files may be compiled into a single object/dwo pair). */
371 htab_up cus;
372
373 /* Table of TUs in the file.
374 Each element is a struct dwo_unit. */
375 htab_up tus;
376};
377
378/* These sections are what may appear in a DWP file. */
379
381{
382 /* These are used by all DWP versions (1, 2 and 5). */
386
387 /* These are only used by DWP version 2 and version 5 files.
388 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
389 sections are referenced by section number, and are not recorded here.
390 In DWP version 2 or 5 there is at most one copy of all these sections,
391 each section being (effectively) comprised of the concatenation of all of
392 the individual sections that exist in the version 1 format.
393 To keep the code simple we treat each of these concatenated pieces as a
394 section itself (a virtual section?). */
405};
406
407/* These sections are what may appear in a virtual DWO file in DWP version 1.
408 A virtual DWO file is a DWO file as it appears in a DWP file. */
409
411{
418 /* Each DWP hash table entry records one CU or one TU.
419 That is recorded here, and copied to dwo_unit.section. */
421};
422
423/* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
424 In version 2, the sections of the DWO files are concatenated together
425 and stored in one section of that name. Thus each ELF section contains
426 several "virtual" sections. */
427
429{
430 bfd_size_type abbrev_offset;
431 bfd_size_type abbrev_size;
432
433 bfd_size_type line_offset;
434 bfd_size_type line_size;
435
436 bfd_size_type loc_offset;
437 bfd_size_type loc_size;
438
439 bfd_size_type loclists_offset;
440 bfd_size_type loclists_size;
441
442 bfd_size_type macinfo_offset;
443 bfd_size_type macinfo_size;
444
445 bfd_size_type macro_offset;
446 bfd_size_type macro_size;
447
448 bfd_size_type rnglists_offset;
449 bfd_size_type rnglists_size;
450
451 bfd_size_type str_offsets_offset;
452 bfd_size_type str_offsets_size;
453
454 /* Each DWP hash table entry records one CU or one TU.
455 That is recorded here, and copied to dwo_unit.section. */
456 bfd_size_type info_or_types_offset;
457 bfd_size_type info_or_types_size;
458};
459
460/* Contents of DWP hash tables. */
461
463{
466 const gdb_byte *hash_table, *unit_table;
467 union
468 {
469 struct
470 {
471 const gdb_byte *indices;
472 } v1;
473 struct
474 {
475 /* This is indexed by column number and gives the id of the section
476 in that column. */
477#define MAX_NR_V2_DWO_SECTIONS \
478 (1 /* .debug_info or .debug_types */ \
479 + 1 /* .debug_abbrev */ \
480 + 1 /* .debug_line */ \
481 + 1 /* .debug_loc */ \
482 + 1 /* .debug_str_offsets */ \
483 + 1 /* .debug_macro or .debug_macinfo */)
485 const gdb_byte *offsets;
486 const gdb_byte *sizes;
487 } v2;
488 struct
489 {
490 /* This is indexed by column number and gives the id of the section
491 in that column. */
492#define MAX_NR_V5_DWO_SECTIONS \
493 (1 /* .debug_info */ \
494 + 1 /* .debug_abbrev */ \
495 + 1 /* .debug_line */ \
496 + 1 /* .debug_loclists */ \
497 + 1 /* .debug_str_offsets */ \
498 + 1 /* .debug_macro */ \
499 + 1 /* .debug_rnglists */)
501 const gdb_byte *offsets;
502 const gdb_byte *sizes;
503 } v5;
505};
506
507/* Data for one DWP file. */
508
510{
511 dwp_file (const char *name_, gdb_bfd_ref_ptr &&abfd)
512 : name (name_),
513 dbfd (std::move (abfd))
514 {
515 }
516
517 /* Name of the file. */
518 const char *name;
519
520 /* File format version. */
521 int version = 0;
522
523 /* The bfd. */
525
526 /* Section info for this file. */
528
529 /* Table of CUs in the file. */
530 const struct dwp_hash_table *cus = nullptr;
531
532 /* Table of TUs in the file. */
533 const struct dwp_hash_table *tus = nullptr;
534
535 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
536 htab_up loaded_cus;
537 htab_up loaded_tus;
538
539 /* Table to map ELF section numbers to their sections.
540 This is only needed for the DWP V1 file format. */
541 unsigned int num_sections = 0;
542 asection **elf_sections = nullptr;
543};
544
545/* Struct used to pass misc. parameters to read_die_and_children, et
546 al. which are used for both .debug_info and .debug_types dies.
547 All parameters here are unchanging for the life of the call. This
548 struct exists to abstract away the constant parameters of die reading. */
549
551{
552 /* The bfd of die_section. */
553 bfd *abfd;
554
555 /* The CU of the DIE we are parsing. */
556 struct dwarf2_cu *cu;
557
558 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
560
561 /* The section the die comes from.
562 This is either .debug_info or .debug_types, or the .dwo variants. */
564
565 /* die_section->buffer. */
566 const gdb_byte *buffer;
567
568 /* The end of the buffer. */
569 const gdb_byte *buffer_end;
570
571 /* The abbreviation table to use when reading the DIEs. */
573};
574
575/* A subclass of die_reader_specs that holds storage and has complex
576 constructor and destructor behavior. */
577
579{
580public:
581
583 dwarf2_per_objfile *per_objfile,
585 dwarf2_cu *existing_cu,
586 bool skip_partial,
587 abbrev_cache *cache = nullptr);
588
589 explicit cutu_reader (struct dwarf2_per_cu_data *this_cu,
590 dwarf2_per_objfile *per_objfile,
591 struct dwarf2_cu *parent_cu = nullptr,
592 struct dwo_file *dwo_file = nullptr);
593
595
596 cutu_reader (cutu_reader &&) = default;
597
598 const gdb_byte *info_ptr = nullptr;
599 struct die_info *comp_unit_die = nullptr;
600 bool dummy_p = false;
601
602 /* Release the new CU, putting it on the chain. This cannot be done
603 for dummy CUs. */
604 void keep ();
605
606 /* Release the abbrev table, transferring ownership to the
607 caller. */
609 {
610 return std::move (m_abbrev_table_holder);
611 }
612
613private:
615 dwarf2_per_objfile *per_objfile,
616 dwarf2_cu *existing_cu);
617
619 std::unique_ptr<dwarf2_cu> m_new_cu;
620
621 /* The ordinary abbreviation table. */
623
624 /* The DWO abbreviation table. */
626};
627
628/* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
629 but this would require a corresponding change in unpack_field_as_long
630 and friends. */
631static int bits_per_byte = 8;
632
634
635/* When reading a variant, we track a bit more information about the
636 field, and store it in an object of this type. */
637
639{
640 int first_field = -1;
641 int last_field = -1;
642
643 /* A variant can contain other variant parts. */
644 std::vector<variant_part_builder> variant_parts;
645
646 /* If we see a DW_TAG_variant, then this will be set if this is the
647 default branch. */
648 bool default_branch = false;
649 /* If we see a DW_AT_discr_value, then this will be the discriminant
650 value. */
651 ULONGEST discriminant_value = 0;
652 /* If we see a DW_AT_discr_list, then this is a pointer to the list
653 data. */
654 struct dwarf_block *discr_list_data = nullptr;
655};
656
657/* This represents a DW_TAG_variant_part. */
658
660{
661 /* The offset of the discriminant field. */
662 sect_offset discriminant_offset {};
663
664 /* Variants that are direct children of this variant part. */
665 std::vector<variant_field> variants;
666
667 /* True if we're currently reading a variant. */
668 bool processing_variant = false;
669};
670
672{
674 int virtuality = 0;
675 /* Variant parts need to find the discriminant, which is a DIE
676 reference. We track the section offset of each field to make
677 this link. */
678 sect_offset offset;
679 struct field field {};
680};
681
683{
684 const char *name = nullptr;
685 std::vector<struct fn_field> fnfields;
686};
687
688/* The routines that read and process dies for a C struct or C++ class
689 pass lists of data member fields and lists of member function fields
690 in an instance of a field_info structure, as defined below. */
692{
693 /* List of data member and baseclasses fields. */
694 std::vector<struct nextfield> fields;
695 std::vector<struct nextfield> baseclasses;
696
697 /* Set if the accessibility of one of the fields is not public. */
698 bool non_public_fields = false;
699
700 /* Member function fieldlist array, contains name of possibly overloaded
701 member function, number of overloaded member functions and a pointer
702 to the head of the member function field chain. */
703 std::vector<struct fnfieldlist> fnfieldlists;
704
705 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
706 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
707 std::vector<struct decl_field> typedef_field_list;
708
709 /* Nested types defined by this class and the number of elements in this
710 list. */
711 std::vector<struct decl_field> nested_types_list;
712
713 /* If non-null, this is the variant part we are currently
714 reading. */
716 /* This holds all the top-level variant parts attached to the type
717 we're reading. */
718 std::vector<variant_part_builder> variant_parts;
719
720 /* Return the total number of fields (including baseclasses). */
721 int nfields () const
722 {
723 return fields.size () + baseclasses.size ();
724 }
725};
726
727/* Loaded secondary compilation units are kept in memory until they
728 have not been referenced for the processing of this many
729 compilation units. Set this to zero to disable caching. Cache
730 sizes of up to at least twenty will improve startup time for
731 typical inter-CU-reference binaries, at an obvious memory cost. */
732static int dwarf_max_cache_age = 5;
733static void
734show_dwarf_max_cache_age (struct ui_file *file, int from_tty,
735 struct cmd_list_element *c, const char *value)
736{
737 gdb_printf (file, _("The upper bound on the age of cached "
738 "DWARF compilation units is %s.\n"),
739 value);
740}
741
742/* local function prototypes */
743
744static void dwarf2_find_base_address (struct die_info *die,
745 struct dwarf2_cu *cu);
746
748static void build_type_psymtabs_reader (cutu_reader *reader,
749 cooked_index_storage *storage);
750
751static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile);
752
753static void var_decode_location (struct attribute *attr,
754 struct symbol *sym,
755 struct dwarf2_cu *cu);
756
757static unsigned int peek_abbrev_code (bfd *, const gdb_byte *);
758
759static const gdb_byte *read_attribute (const struct die_reader_specs *,
760 struct attribute *,
761 const struct attr_abbrev *,
762 const gdb_byte *,
763 bool allow_reprocess = true);
764
765/* Note that the default for TAG is chosen because it only matters
766 when reading the top-level DIE, and that function is careful to
767 pass the correct tag. */
768static void read_attribute_reprocess (const struct die_reader_specs *reader,
769 struct attribute *attr,
770 dwarf_tag tag = DW_TAG_padding);
771
772static unrelocated_addr read_addr_index (struct dwarf2_cu *cu,
773 unsigned int addr_index);
774
775static sect_offset read_abbrev_offset (dwarf2_per_objfile *per_objfile,
776 dwarf2_section_info *, sect_offset);
777
778static const char *read_indirect_string
779 (dwarf2_per_objfile *per_objfile, bfd *, const gdb_byte *,
780 const struct comp_unit_head *, unsigned int *);
781
782static unrelocated_addr read_addr_index_from_leb128 (struct dwarf2_cu *,
783 const gdb_byte *,
784 unsigned int *);
785
786static const char *read_dwo_str_index (const struct die_reader_specs *reader,
787 ULONGEST str_index);
788
789static const char *read_stub_str_index (struct dwarf2_cu *cu,
790 ULONGEST str_index);
791
792static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
793 struct dwarf2_cu *);
794
795static const char *dwarf2_string_attr (struct die_info *die, unsigned int name,
796 struct dwarf2_cu *cu);
797
798static const char *dwarf2_dwo_name (struct die_info *die, struct dwarf2_cu *cu);
799
800static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
801 struct dwarf2_cu *cu);
802
803static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
804
805static struct die_info *die_specification (struct die_info *die,
806 struct dwarf2_cu **);
807
809 struct dwarf2_cu *cu,
810 const char *comp_dir);
811
812static void dwarf_decode_lines (struct line_header *,
813 struct dwarf2_cu *,
814 unrelocated_addr, int decode_mapping);
815
816static void dwarf2_start_subfile (dwarf2_cu *cu, const file_entry &fe,
817 const line_header &lh);
818
819static struct symbol *new_symbol (struct die_info *, struct type *,
820 struct dwarf2_cu *, struct symbol * = NULL);
821
822static void dwarf2_const_value (const struct attribute *, struct symbol *,
823 struct dwarf2_cu *);
824
825static void dwarf2_const_value_attr (const struct attribute *attr,
826 struct type *type,
827 const char *name,
828 struct obstack *obstack,
829 struct dwarf2_cu *cu, LONGEST *value,
830 const gdb_byte **bytes,
831 struct dwarf2_locexpr_baton **baton);
832
833static struct type *read_subrange_index_type (struct die_info *die,
834 struct dwarf2_cu *cu);
835
836static struct type *die_type (struct die_info *, struct dwarf2_cu *);
837
838static int need_gnat_info (struct dwarf2_cu *);
839
840static struct type *die_descriptive_type (struct die_info *,
841 struct dwarf2_cu *);
842
843static void set_descriptive_type (struct type *, struct die_info *,
844 struct dwarf2_cu *);
845
846static struct type *die_containing_type (struct die_info *,
847 struct dwarf2_cu *);
848
849static struct type *lookup_die_type (struct die_info *, const struct attribute *,
850 struct dwarf2_cu *);
851
852static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
853
854static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
855
856static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
857
858static char *typename_concat (struct obstack *obs, const char *prefix,
859 const char *suffix, int physname,
860 struct dwarf2_cu *cu);
861
862static void read_file_scope (struct die_info *, struct dwarf2_cu *);
863
864static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
865
866static void read_func_scope (struct die_info *, struct dwarf2_cu *);
867
868static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
869
870static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
871
872static void read_variable (struct die_info *die, struct dwarf2_cu *cu);
873
874/* Return the .debug_loclists section to use for cu. */
875static struct dwarf2_section_info *cu_debug_loc_section (struct dwarf2_cu *cu);
876
877/* Return the .debug_rnglists section to use for cu. */
879 (struct dwarf2_cu *cu, dwarf_tag tag);
880
881/* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
882 values. Keep the items ordered with increasing constraints compliance. */
884{
885 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
887
888 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
889 were present but they do not form a valid range of PC addresses. */
891
892 /* Discontiguous range was found - that is DW_AT_ranges was found. */
894
895 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
897};
898
899static enum pc_bounds_kind dwarf2_get_pc_bounds (struct die_info *,
900 unrelocated_addr *,
901 unrelocated_addr *,
902 struct dwarf2_cu *,
903 addrmap *,
904 void *);
905
906static void get_scope_pc_bounds (struct die_info *,
907 unrelocated_addr *, unrelocated_addr *,
908 struct dwarf2_cu *);
909
910static void dwarf2_record_block_ranges (struct die_info *, struct block *,
911 struct dwarf2_cu *);
912
913static void dwarf2_add_field (struct field_info *, struct die_info *,
914 struct dwarf2_cu *);
915
916static void dwarf2_attach_fields_to_type (struct field_info *,
917 struct type *, struct dwarf2_cu *);
918
919static void dwarf2_add_member_fn (struct field_info *,
920 struct die_info *, struct type *,
921 struct dwarf2_cu *);
922
923static void dwarf2_attach_fn_fields_to_type (struct field_info *,
924 struct type *,
925 struct dwarf2_cu *);
926
927static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
928
929static void read_common_block (struct die_info *, struct dwarf2_cu *);
930
931static void read_namespace (struct die_info *die, struct dwarf2_cu *);
932
933static void read_module (struct die_info *die, struct dwarf2_cu *cu);
934
935static struct using_direct **using_directives (struct dwarf2_cu *cu);
936
937static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
938
939static bool read_alias (struct die_info *die, struct dwarf2_cu *cu);
940
941static struct type *read_module_type (struct die_info *die,
942 struct dwarf2_cu *cu);
943
944static const char *namespace_name (struct die_info *die,
945 int *is_anonymous, struct dwarf2_cu *);
946
947static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
948
949static bool decode_locdesc (struct dwarf_block *, struct dwarf2_cu *,
950 CORE_ADDR *addr);
951
952static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
953 struct dwarf2_cu *);
954
956 (const struct die_reader_specs *, const gdb_byte *, const gdb_byte **,
957 struct die_info *);
958
959static struct die_info *read_die_and_siblings (const struct die_reader_specs *,
960 const gdb_byte *info_ptr,
961 const gdb_byte **new_info_ptr,
962 struct die_info *parent);
963
964static const gdb_byte *read_full_die_1 (const struct die_reader_specs *,
965 struct die_info **, const gdb_byte *,
966 int, bool);
967
968static const gdb_byte *read_toplevel_die (const struct die_reader_specs *,
969 struct die_info **,
970 const gdb_byte *,
971 gdb::array_view<attribute *> = {});
972
973static void process_die (struct die_info *, struct dwarf2_cu *);
974
975static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu *,
976 struct objfile *);
977
978static const char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
979
980static const char *dwarf2_full_name (const char *name,
981 struct die_info *die,
982 struct dwarf2_cu *cu);
983
984static const char *dwarf2_physname (const char *name, struct die_info *die,
985 struct dwarf2_cu *cu);
986
987static struct die_info *dwarf2_extension (struct die_info *die,
988 struct dwarf2_cu **);
989
990static void store_in_ref_table (struct die_info *,
991 struct dwarf2_cu *);
992
993static struct die_info *follow_die_ref_or_sig (struct die_info *,
994 const struct attribute *,
995 struct dwarf2_cu **);
996
997static struct die_info *follow_die_ref (struct die_info *,
998 const struct attribute *,
999 struct dwarf2_cu **);
1000
1001static struct die_info *follow_die_sig (struct die_info *,
1002 const struct attribute *,
1003 struct dwarf2_cu **);
1004
1005static struct type *get_signatured_type (struct die_info *, ULONGEST,
1006 struct dwarf2_cu *);
1007
1008static struct type *get_DW_AT_signature_type (struct die_info *,
1009 const struct attribute *,
1010 struct dwarf2_cu *);
1011
1012static void load_full_type_unit (dwarf2_per_cu_data *per_cu,
1013 dwarf2_per_objfile *per_objfile);
1014
1015static void read_signatured_type (signatured_type *sig_type,
1016 dwarf2_per_objfile *per_objfile);
1017
1018static int attr_to_dynamic_prop (const struct attribute *attr,
1019 struct die_info *die, struct dwarf2_cu *cu,
1020 struct dynamic_prop *prop, struct type *type);
1021
1022/* memory allocation interface */
1023
1024static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1025
1026static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int, int);
1027
1028static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1029 struct dwarf2_loclist_baton *baton,
1030 const struct attribute *attr);
1031
1032static void dwarf2_symbol_mark_computed (const struct attribute *attr,
1033 struct symbol *sym,
1034 struct dwarf2_cu *cu,
1035 int is_block);
1036
1037static const gdb_byte *skip_one_die (const struct die_reader_specs *reader,
1038 const gdb_byte *info_ptr,
1039 const struct abbrev_info *abbrev,
1040 bool do_skip_children = true);
1041
1043 (sect_offset sect_off, unsigned int offset_in_dwz,
1045
1046static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1047 struct die_info *comp_unit_die,
1048 enum language pretend_language);
1049
1050static struct type *set_die_type (struct die_info *, struct type *,
1051 struct dwarf2_cu *, bool = false);
1052
1053static void create_all_units (dwarf2_per_objfile *per_objfile);
1054
1055static void load_full_comp_unit (dwarf2_per_cu_data *per_cu,
1056 dwarf2_per_objfile *per_objfile,
1057 dwarf2_cu *existing_cu,
1058 bool skip_partial,
1059 enum language pretend_language);
1060
1061static void process_full_comp_unit (dwarf2_cu *cu,
1062 enum language pretend_language);
1063
1064static void process_full_type_unit (dwarf2_cu *cu,
1065 enum language pretend_language);
1066
1067static struct type *get_die_type_at_offset (sect_offset,
1068 dwarf2_per_cu_data *per_cu,
1069 dwarf2_per_objfile *per_objfile);
1070
1071static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1072
1073static void queue_comp_unit (dwarf2_per_cu_data *per_cu,
1074 dwarf2_per_objfile *per_objfile,
1075 enum language pretend_language);
1076
1077static void process_queue (dwarf2_per_objfile *per_objfile);
1078
1079static bool is_ada_import_or_export (dwarf2_cu *cu, const char *name,
1080 const char *linkagename);
1081
1082/* Class, the destructor of which frees all allocated queue entries. This
1083 will only have work to do if an error was thrown while processing the
1084 dwarf. If no error was thrown then the queue entries should have all
1085 been processed, and freed, as we went along. */
1086
1088{
1089public:
1091 : m_per_objfile (per_objfile)
1092 {
1093 gdb_assert (!m_per_objfile->queue.has_value ());
1094
1095 m_per_objfile->queue.emplace ();
1096 }
1097
1098 /* Free any entries remaining on the queue. There should only be
1099 entries left if we hit an error while processing the dwarf. */
1101 {
1102 gdb_assert (m_per_objfile->queue.has_value ());
1103
1104 m_per_objfile->queue.reset ();
1105 }
1106
1108
1109private:
1111};
1112
1114{
1115 /* Anything still marked queued is likely to be in an
1116 inconsistent state, so discard it. */
1117 if (per_cu->queued)
1118 {
1120 per_cu->queued = 0;
1121 }
1122}
1123
1124/* See dwarf2/read.h. */
1125
1126void
1128{
1129 if (data->is_debug_types)
1130 delete static_cast<signatured_type *> (data);
1131 else
1132 delete data;
1133}
1134
1136 (struct die_info *die, struct dwarf2_cu *cu);
1137
1138static const char *compute_include_file_name
1139 (const struct line_header *lh,
1140 const file_entry &fe,
1141 const file_and_directory &cu_info,
1142 std::string &name_holder);
1143
1144static htab_up allocate_dwo_unit_table ();
1145
1146static struct dwo_unit *lookup_dwo_unit_in_dwp
1147 (dwarf2_per_objfile *per_objfile, struct dwp_file *dwp_file,
1148 const char *comp_dir, ULONGEST signature, int is_debug_types);
1149
1150static struct dwp_file *get_dwp_file (dwarf2_per_objfile *per_objfile);
1151
1152static struct dwo_unit *lookup_dwo_comp_unit
1153 (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
1154 ULONGEST signature);
1155
1156static struct dwo_unit *lookup_dwo_type_unit
1157 (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir);
1158
1159static void queue_and_load_all_dwo_tus (dwarf2_cu *cu);
1160
1161/* A unique pointer to a dwo_file. */
1162
1163typedef std::unique_ptr<struct dwo_file> dwo_file_up;
1164
1165static void process_cu_includes (dwarf2_per_objfile *per_objfile);
1166
1167static void check_producer (struct dwarf2_cu *cu);
1168
1169/* Various complaints about symbol reading that don't abort the process. */
1170
1171static void
1173{
1174 complaint (_(".debug_line section has line data without a file"));
1175}
1176
1177static void
1179{
1180 complaint (_(".debug_line section has line "
1181 "program sequence without an end"));
1182}
1183
1184static void
1186{
1187 complaint (_("location expression too complex"));
1188}
1189
1190static void
1192 int arg3)
1193{
1194 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1195 arg1, arg2, arg3);
1196}
1197
1198static void
1199dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
1200{
1201 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1202 arg1, arg2);
1203}
1204
1205/* See read.h. */
1206
1207unrelocated_addr
1208dwarf2_per_objfile::adjust (unrelocated_addr addr)
1209{
1210 CORE_ADDR baseaddr = objfile->text_section_offset ();
1211 CORE_ADDR tem = (CORE_ADDR) addr + baseaddr;
1212 tem = gdbarch_adjust_dwarf2_addr (objfile->arch (), tem);
1213 return (unrelocated_addr) (tem - baseaddr);
1214}
1215
1216/* See read.h. */
1217
1218CORE_ADDR
1219dwarf2_per_objfile::relocate (unrelocated_addr addr)
1220{
1221 CORE_ADDR baseaddr = objfile->text_section_offset ();
1222 CORE_ADDR tem = (CORE_ADDR) addr + baseaddr;
1223 return gdbarch_adjust_dwarf2_addr (objfile->arch (), tem);
1224}
1225
1226/* Hash function for line_header_hash. */
1227
1228static hashval_t
1230{
1231 return to_underlying (ofs->sect_off) ^ ofs->offset_in_dwz;
1232}
1233
1234/* Hash function for htab_create_alloc_ex for line_header_hash. */
1235
1236static hashval_t
1237line_header_hash_voidp (const void *item)
1238{
1239 const struct line_header *ofs = (const struct line_header *) item;
1240
1241 return line_header_hash (ofs);
1242}
1243
1244/* Equality function for line_header_hash. */
1245
1246static int
1247line_header_eq_voidp (const void *item_lhs, const void *item_rhs)
1248{
1249 const struct line_header *ofs_lhs = (const struct line_header *) item_lhs;
1250 const struct line_header *ofs_rhs = (const struct line_header *) item_rhs;
1251
1252 return (ofs_lhs->sect_off == ofs_rhs->sect_off
1253 && ofs_lhs->offset_in_dwz == ofs_rhs->offset_in_dwz);
1254}
1255
1256/* See declaration. */
1257
1259 bool can_copy_)
1260 : obfd (obfd),
1261 can_copy (can_copy_)
1262{
1263 if (names == NULL)
1264 names = &dwarf2_elf_names;
1265
1266 for (asection *sec = obfd->sections; sec != NULL; sec = sec->next)
1267 locate_sections (obfd, sec, *names);
1268}
1269
1271{
1272 /* Data from the per-BFD may be needed when finalizing the cooked
1273 index table, so wait here while this happens. */
1274 if (index_table != nullptr)
1275 index_table->wait_completely ();
1276
1277 for (auto &per_cu : all_units)
1278 {
1279 per_cu->imported_symtabs_free ();
1280 per_cu->free_cached_file_names ();
1281 }
1282
1283 /* Everything else should be on this->obstack. */
1284}
1285
1286/* See read.h. */
1287
1288void
1290{
1291 gdb_assert (!queue.has_value ());
1292
1293 m_dwarf2_cus.clear ();
1294}
1295
1296/* A helper class that calls free_cached_comp_units on
1297 destruction. */
1298
1300{
1301public:
1302
1304 : m_per_objfile (per_objfile)
1305 {
1306 }
1307
1312
1314
1315private:
1316
1318};
1319
1320/* See read.h. */
1321
1322bool
1324{
1325 if (per_cu->index < this->m_symtabs.size ())
1326 return this->m_symtabs[per_cu->index] != nullptr;
1327 return false;
1328}
1329
1330/* See read.h. */
1331
1334{
1335 if (per_cu->index < this->m_symtabs.size ())
1336 return this->m_symtabs[per_cu->index];
1337 return nullptr;
1338}
1339
1340/* See read.h. */
1341
1342void
1345{
1346 if (per_cu->index >= this->m_symtabs.size ())
1347 this->m_symtabs.resize (per_cu->index + 1);
1348 gdb_assert (this->m_symtabs[per_cu->index] == nullptr);
1349 this->m_symtabs[per_cu->index] = symtab;
1350}
1351
1352/* Try to locate the sections we need for DWARF 2 debugging
1353 information and return true if we have enough to do something.
1354 NAMES points to the dwarf2 section names, or is NULL if the standard
1355 ELF names are used. CAN_COPY is true for formats where symbol
1356 interposition is possible and so symbol values must follow copy
1357 relocation rules. */
1358
1359bool
1361 const struct dwarf2_debug_sections *names,
1362 bool can_copy)
1363{
1365 return false;
1366
1368
1369 if (per_objfile == NULL)
1370 {
1371 dwarf2_per_bfd *per_bfd;
1372
1373 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1374 BFD doesn't require relocations.
1375
1376 We don't share with objfiles for which -readnow was requested,
1377 because it would complicate things when loading the same BFD with
1378 -readnow and then without -readnow. */
1380 && (objfile->flags & OBJF_READNOW) == 0)
1381 {
1382 /* See if one has been created for this BFD yet. */
1383 per_bfd = dwarf2_per_bfd_bfd_data_key.get (objfile->obfd.get ());
1384
1385 if (per_bfd == nullptr)
1386 {
1387 /* No, create it now. */
1388 per_bfd = new dwarf2_per_bfd (objfile->obfd.get (), names,
1389 can_copy);
1390 dwarf2_per_bfd_bfd_data_key.set (objfile->obfd.get (), per_bfd);
1391 }
1392 }
1393 else
1394 {
1395 /* No sharing possible, create one specifically for this objfile. */
1396 per_bfd = new dwarf2_per_bfd (objfile->obfd.get (), names, can_copy);
1398 }
1399
1400 per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile, per_bfd);
1401 }
1402
1403 return (!per_objfile->per_bfd->info.is_virtual
1404 && per_objfile->per_bfd->info.s.section != NULL
1405 && !per_objfile->per_bfd->abbrev.is_virtual
1406 && per_objfile->per_bfd->abbrev.s.section != NULL);
1407}
1408
1409/* See declaration. */
1410
1411void
1412dwarf2_per_bfd::locate_sections (bfd *abfd, asection *sectp,
1413 const dwarf2_debug_sections &names)
1414{
1415 flagword aflag = bfd_section_flags (sectp);
1416
1417 if ((aflag & SEC_HAS_CONTENTS) == 0)
1418 {
1419 }
1420 else if (elf_section_data (sectp)->this_hdr.sh_size
1421 > bfd_get_file_size (abfd))
1422 {
1423 bfd_size_type size = elf_section_data (sectp)->this_hdr.sh_size;
1424 warning (_("Discarding section %s which has a section size (%s"
1425 ") larger than the file size [in module %s]"),
1426 bfd_section_name (sectp), phex_nz (size, sizeof (size)),
1427 bfd_get_filename (abfd));
1428 }
1429 else if (names.info.matches (sectp->name))
1430 {
1431 this->info.s.section = sectp;
1432 this->info.size = bfd_section_size (sectp);
1433 }
1434 else if (names.abbrev.matches (sectp->name))
1435 {
1436 this->abbrev.s.section = sectp;
1437 this->abbrev.size = bfd_section_size (sectp);
1438 }
1439 else if (names.line.matches (sectp->name))
1440 {
1441 this->line.s.section = sectp;
1442 this->line.size = bfd_section_size (sectp);
1443 }
1444 else if (names.loc.matches (sectp->name))
1445 {
1446 this->loc.s.section = sectp;
1447 this->loc.size = bfd_section_size (sectp);
1448 }
1449 else if (names.loclists.matches (sectp->name))
1450 {
1451 this->loclists.s.section = sectp;
1452 this->loclists.size = bfd_section_size (sectp);
1453 }
1454 else if (names.macinfo.matches (sectp->name))
1455 {
1456 this->macinfo.s.section = sectp;
1457 this->macinfo.size = bfd_section_size (sectp);
1458 }
1459 else if (names.macro.matches (sectp->name))
1460 {
1461 this->macro.s.section = sectp;
1462 this->macro.size = bfd_section_size (sectp);
1463 }
1464 else if (names.str.matches (sectp->name))
1465 {
1466 this->str.s.section = sectp;
1467 this->str.size = bfd_section_size (sectp);
1468 }
1469 else if (names.str_offsets.matches (sectp->name))
1470 {
1471 this->str_offsets.s.section = sectp;
1472 this->str_offsets.size = bfd_section_size (sectp);
1473 }
1474 else if (names.line_str.matches (sectp->name))
1475 {
1476 this->line_str.s.section = sectp;
1477 this->line_str.size = bfd_section_size (sectp);
1478 }
1479 else if (names.addr.matches (sectp->name))
1480 {
1481 this->addr.s.section = sectp;
1482 this->addr.size = bfd_section_size (sectp);
1483 }
1484 else if (names.frame.matches (sectp->name))
1485 {
1486 this->frame.s.section = sectp;
1487 this->frame.size = bfd_section_size (sectp);
1488 }
1489 else if (names.eh_frame.matches (sectp->name))
1490 {
1491 this->eh_frame.s.section = sectp;
1492 this->eh_frame.size = bfd_section_size (sectp);
1493 }
1494 else if (names.ranges.matches (sectp->name))
1495 {
1496 this->ranges.s.section = sectp;
1497 this->ranges.size = bfd_section_size (sectp);
1498 }
1499 else if (names.rnglists.matches (sectp->name))
1500 {
1501 this->rnglists.s.section = sectp;
1502 this->rnglists.size = bfd_section_size (sectp);
1503 }
1504 else if (names.types.matches (sectp->name))
1505 {
1506 struct dwarf2_section_info type_section;
1507
1508 memset (&type_section, 0, sizeof (type_section));
1509 type_section.s.section = sectp;
1510 type_section.size = bfd_section_size (sectp);
1511
1512 this->types.push_back (type_section);
1513 }
1514 else if (names.gdb_index.matches (sectp->name))
1515 {
1516 this->gdb_index.s.section = sectp;
1517 this->gdb_index.size = bfd_section_size (sectp);
1518 }
1519 else if (names.debug_names.matches (sectp->name))
1520 {
1521 this->debug_names.s.section = sectp;
1522 this->debug_names.size = bfd_section_size (sectp);
1523 }
1524 else if (names.debug_aranges.matches (sectp->name))
1525 {
1526 this->debug_aranges.s.section = sectp;
1527 this->debug_aranges.size = bfd_section_size (sectp);
1528 }
1529
1530 if ((bfd_section_flags (sectp) & (SEC_LOAD | SEC_ALLOC))
1531 && bfd_section_vma (sectp) == 0)
1532 this->has_section_at_zero = true;
1533}
1534
1535/* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1536 SECTION_NAME. */
1537
1538void
1540 enum dwarf2_section_enum sect,
1541 asection **sectp, const gdb_byte **bufp,
1542 bfd_size_type *sizep)
1543{
1545 struct dwarf2_section_info *info;
1546
1547 /* We may see an objfile without any DWARF, in which case we just
1548 return nothing. */
1549 if (per_objfile == NULL)
1550 {
1551 *sectp = NULL;
1552 *bufp = NULL;
1553 *sizep = 0;
1554 return;
1555 }
1556 switch (sect)
1557 {
1558 case DWARF2_DEBUG_FRAME:
1559 info = &per_objfile->per_bfd->frame;
1560 break;
1561 case DWARF2_EH_FRAME:
1562 info = &per_objfile->per_bfd->eh_frame;
1563 break;
1564 default:
1565 gdb_assert_not_reached ("unexpected section");
1566 }
1567
1568 info->read (objfile);
1569
1570 *sectp = info->get_bfd_section ();
1571 *bufp = info->buffer;
1572 *sizep = info->size;
1573}
1574
1575/* See dwarf2/read.h. */
1576
1577void
1579{
1580 info.read (objfile);
1582 line.read (objfile);
1583 str.read (objfile);
1588 addr.read (objfile);
1589
1590 for (auto &section : types)
1591 section.read (objfile);
1592}
1593
1594
1595/* DWARF quick_symbol_functions support. */
1596
1597/* TUs can share .debug_line entries, and there can be a lot more TUs than
1598 unique line tables, so we maintain a separate table of all .debug_line
1599 derived entries to support the sharing.
1600 All the quick functions need is the list of file names. We discard the
1601 line_header when we're done and don't need to record it here. */
1603{
1604 /* The data used to construct the hash key. */
1606
1607 /* The number of entries in file_names, real_names. */
1608 unsigned int num_file_names;
1609
1610 /* The CU directory, as given by DW_AT_comp_dir. May be
1611 nullptr. */
1612 const char *comp_dir;
1613
1614 /* The file names from the line table, after being run through
1615 file_full_name. */
1616 const char **file_names;
1617
1618 /* The file names from the line table after being run through
1619 gdb_realpath. These are computed lazily. */
1620 const char **real_names;
1621};
1622
1623/* With OBJF_READNOW, the DWARF reader expands all CUs immediately.
1624 It's handy in this case to have an empty implementation of the
1625 quick symbol functions, to avoid special cases in the rest of the
1626 code. */
1627
1629{
1630 void dump (struct objfile *objfile) override
1631 {
1632 }
1633
1635 (struct objfile *,
1636 const lookup_name_info &lookup_name,
1637 domain_enum domain,
1638 int global,
1639 symbol_compare_ftype *ordered_compare) override
1640 {
1641 }
1642
1644 (struct objfile *objfile,
1645 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
1646 const lookup_name_info *lookup_name,
1647 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
1648 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
1649 block_search_flags search_flags,
1650 domain_enum domain,
1651 enum search_domain kind) override
1652 {
1653 return true;
1654 }
1655};
1656
1657/* Utility hash function for a stmt_list_hash. */
1658
1659static hashval_t
1661{
1662 hashval_t v = 0;
1663
1664 if (stmt_list_hash->dwo_unit != NULL)
1665 v += (uintptr_t) stmt_list_hash->dwo_unit->dwo_file;
1666 v += to_underlying (stmt_list_hash->line_sect_off);
1667 return v;
1668}
1669
1670/* Utility equality function for a stmt_list_hash. */
1671
1672static int
1674 const struct stmt_list_hash *rhs)
1675{
1676 if ((lhs->dwo_unit != NULL) != (rhs->dwo_unit != NULL))
1677 return 0;
1678 if (lhs->dwo_unit != NULL
1679 && lhs->dwo_unit->dwo_file != rhs->dwo_unit->dwo_file)
1680 return 0;
1681
1682 return lhs->line_sect_off == rhs->line_sect_off;
1683}
1684
1685/* Hash function for a quick_file_names. */
1686
1687static hashval_t
1689{
1690 const struct quick_file_names *file_data
1691 = (const struct quick_file_names *) e;
1692
1693 return hash_stmt_list_entry (&file_data->hash);
1694}
1695
1696/* Equality function for a quick_file_names. */
1697
1698static int
1699eq_file_name_entry (const void *a, const void *b)
1700{
1701 const struct quick_file_names *ea = (const struct quick_file_names *) a;
1702 const struct quick_file_names *eb = (const struct quick_file_names *) b;
1703
1704 return eq_stmt_list_entry (&ea->hash, &eb->hash);
1705}
1706
1707/* See read.h. */
1708
1709htab_up
1710create_quick_file_names_table (unsigned int nr_initial_entries)
1711{
1712 return htab_up (htab_create_alloc (nr_initial_entries,
1714 nullptr, xcalloc, xfree));
1715}
1716
1717/* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
1718 function is unrelated to symtabs, symtab would have to be created afterwards.
1719 You should call age_cached_comp_units after processing the CU. */
1720
1721static dwarf2_cu *
1723 bool skip_partial)
1724{
1725 if (per_cu->is_debug_types)
1726 load_full_type_unit (per_cu, per_objfile);
1727 else
1728 load_full_comp_unit (per_cu, per_objfile, per_objfile->get_cu (per_cu),
1729 skip_partial, language_minimal);
1730
1731 dwarf2_cu *cu = per_objfile->get_cu (per_cu);
1732 if (cu == nullptr)
1733 return nullptr; /* Dummy CU. */
1734
1736
1737 return cu;
1738}
1739
1740/* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
1741
1742static void
1744 dwarf2_per_objfile *per_objfile, bool skip_partial)
1745{
1746 {
1747 /* The destructor of dwarf2_queue_guard frees any entries left on
1748 the queue. After this point we're guaranteed to leave this function
1749 with the dwarf queue empty. */
1750 dwarf2_queue_guard q_guard (per_objfile);
1751
1752 if (!per_objfile->symtab_set_p (per_cu))
1753 {
1754 queue_comp_unit (per_cu, per_objfile, language_minimal);
1755 dwarf2_cu *cu = load_cu (per_cu, per_objfile, skip_partial);
1756
1757 /* If we just loaded a CU from a DWO, and we're working with an index
1758 that may badly handle TUs, load all the TUs in that DWO as well.
1759 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
1760 if (!per_cu->is_debug_types
1761 && cu != NULL
1762 && cu->dwo_unit != NULL
1763 && per_objfile->per_bfd->index_table != NULL
1764 && !per_objfile->per_bfd->index_table->version_check ()
1765 /* DWP files aren't supported yet. */
1766 && get_dwp_file (per_objfile) == NULL)
1768 }
1769
1770 process_queue (per_objfile);
1771 }
1772
1773 /* Age the cache, releasing compilation units that have not
1774 been used recently. */
1775 per_objfile->age_comp_units ();
1776}
1777
1778/* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
1779 the per-objfile for which this symtab is instantiated.
1780
1781 Returns the resulting symbol table. */
1782
1783static struct compunit_symtab *
1785 dwarf2_per_objfile *per_objfile,
1786 bool skip_partial)
1787{
1788 if (!per_objfile->symtab_set_p (per_cu))
1789 {
1790 free_cached_comp_units freer (per_objfile);
1791 scoped_restore decrementer = increment_reading_symtab ();
1792 dw2_do_instantiate_symtab (per_cu, per_objfile, skip_partial);
1793 process_cu_includes (per_objfile);
1794 }
1795
1796 return per_objfile->get_symtab (per_cu);
1797}
1798
1799/* See read.h. */
1800
1803{
1805 result->per_bfd = this;
1806 result->index = all_units.size ();
1807 return result;
1808}
1809
1810/* See read.h. */
1811
1814{
1815 signatured_type_up result (new signatured_type (signature));
1816 result->per_bfd = this;
1817 result->index = all_units.size ();
1818 result->is_debug_types = true;
1819 tu_stats.nr_tus++;
1820 return result;
1821}
1822
1823/* See read.h. */
1824
1827 struct dwarf2_section_info *section,
1828 int is_dwz,
1829 sect_offset sect_off, ULONGEST length)
1830{
1831 dwarf2_per_cu_data_up the_cu = per_bfd->allocate_per_cu ();
1832 the_cu->sect_off = sect_off;
1833 the_cu->set_length (length);
1834 the_cu->section = section;
1835 the_cu->is_dwz = is_dwz;
1836 return the_cu;
1837}
1838
1839/* See read.h. */
1840
1841bool
1843 dwarf2_section_info *section,
1844 addrmap *mutable_map)
1845{
1846 struct objfile *objfile = per_objfile->objfile;
1847 bfd *abfd = objfile->obfd.get ();
1848 struct gdbarch *gdbarch = objfile->arch ();
1849 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
1850
1851 std::unordered_map<sect_offset,
1853 gdb::hash_enum<sect_offset>>
1854 debug_info_offset_to_per_cu;
1855 for (const auto &per_cu : per_bfd->all_units)
1856 {
1857 /* A TU will not need aranges, and skipping them here is an easy
1858 way of ignoring .debug_types -- and possibly seeing a
1859 duplicate section offset -- entirely. The same applies to
1860 units coming from a dwz file. */
1861 if (per_cu->is_debug_types || per_cu->is_dwz)
1862 continue;
1863
1864 const auto insertpair
1865 = debug_info_offset_to_per_cu.emplace (per_cu->sect_off,
1866 per_cu.get ());
1867
1868 /* Assume no duplicate offsets in all_units. */
1869 gdb_assert (insertpair.second);
1870 }
1871
1872 std::set<sect_offset> debug_info_offset_seen;
1873
1874 section->read (objfile);
1875
1876 const bfd_endian dwarf5_byte_order = gdbarch_byte_order (gdbarch);
1877
1878 const gdb_byte *addr = section->buffer;
1879
1880 while (addr < section->buffer + section->size)
1881 {
1882 const gdb_byte *const entry_addr = addr;
1883 unsigned int bytes_read;
1884
1885 const LONGEST entry_length = read_initial_length (abfd, addr,
1886 &bytes_read);
1887 addr += bytes_read;
1888
1889 const gdb_byte *const entry_end = addr + entry_length;
1890 const bool dwarf5_is_dwarf64 = bytes_read != 4;
1891 const uint8_t offset_size = dwarf5_is_dwarf64 ? 8 : 4;
1892 if (addr + entry_length > section->buffer + section->size)
1893 {
1894 warning (_("Section .debug_aranges in %s entry at offset %s "
1895 "length %s exceeds section length %s, "
1896 "ignoring .debug_aranges."),
1898 plongest (entry_addr - section->buffer),
1899 plongest (bytes_read + entry_length),
1900 pulongest (section->size));
1901 return false;
1902 }
1903
1904 /* The version number. */
1905 const uint16_t version = read_2_bytes (abfd, addr);
1906 addr += 2;
1907 if (version != 2)
1908 {
1909 warning (_("Section .debug_aranges in %s entry at offset %s "
1910 "has unsupported version %d, ignoring .debug_aranges."),
1912 plongest (entry_addr - section->buffer), version);
1913 return false;
1914 }
1915
1916 const uint64_t debug_info_offset
1917 = extract_unsigned_integer (addr, offset_size, dwarf5_byte_order);
1918 addr += offset_size;
1919 const auto per_cu_it
1920 = debug_info_offset_to_per_cu.find (sect_offset (debug_info_offset));
1921 if (per_cu_it == debug_info_offset_to_per_cu.cend ())
1922 {
1923 warning (_("Section .debug_aranges in %s entry at offset %s "
1924 "debug_info_offset %s does not exists, "
1925 "ignoring .debug_aranges."),
1927 plongest (entry_addr - section->buffer),
1928 pulongest (debug_info_offset));
1929 return false;
1930 }
1931 const auto insertpair
1932 = debug_info_offset_seen.insert (sect_offset (debug_info_offset));
1933 if (!insertpair.second)
1934 {
1935 warning (_("Section .debug_aranges in %s has duplicate "
1936 "debug_info_offset %s, ignoring .debug_aranges."),
1938 sect_offset_str (sect_offset (debug_info_offset)));
1939 return false;
1940 }
1941 dwarf2_per_cu_data *const per_cu = per_cu_it->second;
1942
1943 const uint8_t address_size = *addr++;
1944 if (address_size < 1 || address_size > 8)
1945 {
1946 warning (_("Section .debug_aranges in %s entry at offset %s "
1947 "address_size %u is invalid, ignoring .debug_aranges."),
1949 plongest (entry_addr - section->buffer), address_size);
1950 return false;
1951 }
1952
1953 const uint8_t segment_selector_size = *addr++;
1954 if (segment_selector_size != 0)
1955 {
1956 warning (_("Section .debug_aranges in %s entry at offset %s "
1957 "segment_selector_size %u is not supported, "
1958 "ignoring .debug_aranges."),
1960 plongest (entry_addr - section->buffer),
1961 segment_selector_size);
1962 return false;
1963 }
1964
1965 /* Must pad to an alignment boundary that is twice the address
1966 size. It is undocumented by the DWARF standard but GCC does
1967 use it. However, not every compiler does this. We can see
1968 whether it has happened by looking at the total length of the
1969 contents of the aranges for this CU -- it if isn't a multiple
1970 of twice the address size, then we skip any leftover
1971 bytes. */
1972 addr += (entry_end - addr) % (2 * address_size);
1973
1974 while (addr < entry_end)
1975 {
1976 if (addr + 2 * address_size > entry_end)
1977 {
1978 warning (_("Section .debug_aranges in %s entry at offset %s "
1979 "address list is not properly terminated, "
1980 "ignoring .debug_aranges."),
1982 plongest (entry_addr - section->buffer));
1983 return false;
1984 }
1985 ULONGEST start = extract_unsigned_integer (addr, address_size,
1986 dwarf5_byte_order);
1987 addr += address_size;
1988 ULONGEST length = extract_unsigned_integer (addr, address_size,
1989 dwarf5_byte_order);
1990 addr += address_size;
1991 if (start == 0 && length == 0)
1992 {
1993 /* This can happen on some targets with --gc-sections.
1994 This pair of values is also used to mark the end of
1995 the entries for a given CU, but we ignore it and
1996 instead handle termination using the check at the top
1997 of the loop. */
1998 continue;
1999 }
2000 if (start == 0 && !per_bfd->has_section_at_zero)
2001 {
2002 /* Symbol was eliminated due to a COMDAT group. */
2003 continue;
2004 }
2005 ULONGEST end = start + length;
2006 start = (ULONGEST) per_objfile->adjust ((unrelocated_addr) start);
2007 end = (ULONGEST) per_objfile->adjust ((unrelocated_addr) end);
2008 mutable_map->set_empty (start, end - 1, per_cu);
2009 }
2010
2011 per_cu->addresses_seen = true;
2012 }
2013
2014 return true;
2015}
2016
2017/* die_reader_func for dw2_get_file_names. */
2018
2019static void
2021 struct die_info *comp_unit_die)
2022{
2023 struct dwarf2_cu *cu = reader->cu;
2024 struct dwarf2_per_cu_data *this_cu = cu->per_cu;
2025 dwarf2_per_objfile *per_objfile = cu->per_objfile;
2026 struct dwarf2_per_cu_data *lh_cu;
2027 struct attribute *attr;
2028 void **slot;
2029 struct quick_file_names *qfn;
2030
2031 gdb_assert (! this_cu->is_debug_types);
2032
2033 this_cu->files_read = true;
2034 /* Our callers never want to match partial units -- instead they
2035 will match the enclosing full CU. */
2036 if (comp_unit_die->tag == DW_TAG_partial_unit)
2037 return;
2038
2039 lh_cu = this_cu;
2040 slot = NULL;
2041
2042 line_header_up lh;
2043 sect_offset line_offset {};
2044
2045 file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu);
2046
2047 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu);
2048 if (attr != nullptr && attr->form_is_unsigned ())
2049 {
2050 struct quick_file_names find_entry;
2051
2052 line_offset = (sect_offset) attr->as_unsigned ();
2053
2054 /* We may have already read in this line header (TU line header sharing).
2055 If we have we're done. */
2056 find_entry.hash.dwo_unit = cu->dwo_unit;
2057 find_entry.hash.line_sect_off = line_offset;
2058 slot = htab_find_slot (per_objfile->per_bfd->quick_file_names_table.get (),
2059 &find_entry, INSERT);
2060 if (*slot != NULL)
2061 {
2062 lh_cu->file_names = (struct quick_file_names *) *slot;
2063 return;
2064 }
2065
2067 }
2068
2069 int offset = 0;
2070 if (!fnd.is_unknown ())
2071 ++offset;
2072 else if (lh == nullptr)
2073 return;
2074
2075 qfn = XOBNEW (&per_objfile->per_bfd->obstack, struct quick_file_names);
2076 qfn->hash.dwo_unit = cu->dwo_unit;
2078 /* There may not be a DW_AT_stmt_list. */
2079 if (slot != nullptr)
2080 *slot = qfn;
2081
2082 std::vector<const char *> include_names;
2083 if (lh != nullptr)
2084 {
2085 for (const auto &entry : lh->file_names ())
2086 {
2087 std::string name_holder;
2088 const char *include_name =
2089 compute_include_file_name (lh.get (), entry, fnd, name_holder);
2090 if (include_name != nullptr)
2091 {
2092 include_name = per_objfile->objfile->intern (include_name);
2093 include_names.push_back (include_name);
2094 }
2095 }
2096 }
2097
2098 qfn->num_file_names = offset + include_names.size ();
2099 qfn->comp_dir = fnd.intern_comp_dir (per_objfile->objfile);
2100 qfn->file_names =
2101 XOBNEWVEC (&per_objfile->per_bfd->obstack, const char *,
2102 qfn->num_file_names);
2103 if (offset != 0)
2104 qfn->file_names[0] = per_objfile->objfile->intern (fnd.get_name ());
2105
2106 if (!include_names.empty ())
2107 memcpy (&qfn->file_names[offset], include_names.data (),
2108 include_names.size () * sizeof (const char *));
2109
2110 qfn->real_names = NULL;
2111
2112 lh_cu->file_names = qfn;
2113}
2114
2115/* A helper for the "quick" functions which attempts to read the line
2116 table for THIS_CU. */
2117
2118static struct quick_file_names *
2120 dwarf2_per_objfile *per_objfile)
2121{
2122 /* This should never be called for TUs. */
2123 gdb_assert (! this_cu->is_debug_types);
2124
2125 if (this_cu->files_read)
2126 return this_cu->file_names;
2127
2128 cutu_reader reader (this_cu, per_objfile);
2129 if (!reader.dummy_p)
2130 dw2_get_file_names_reader (&reader, reader.comp_unit_die);
2131
2132 return this_cu->file_names;
2133}
2134
2135/* A helper for the "quick" functions which computes and caches the
2136 real path for a given file name from the line table. */
2137
2138static const char *
2140 struct quick_file_names *qfn, int index)
2141{
2142 if (qfn->real_names == NULL)
2143 qfn->real_names = OBSTACK_CALLOC (&per_objfile->per_bfd->obstack,
2144 qfn->num_file_names, const char *);
2145
2146 if (qfn->real_names[index] == NULL)
2147 {
2148 const char *dirname = nullptr;
2149
2150 if (!IS_ABSOLUTE_PATH (qfn->file_names[index]))
2151 dirname = qfn->comp_dir;
2152
2153 gdb::unique_xmalloc_ptr<char> fullname;
2154 fullname = find_source_or_rewrite (qfn->file_names[index], dirname);
2155
2156 qfn->real_names[index] = fullname.release ();
2157 }
2158
2159 return qfn->real_names[index];
2160}
2161
2162struct symtab *
2164{
2166 dwarf2_per_cu_data *dwarf_cu
2167 = per_objfile->per_bfd->all_units.back ().get ();
2168 compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu, per_objfile, false);
2169
2170 if (cust == NULL)
2171 return NULL;
2172
2173 return cust->primary_filetab ();
2174}
2175
2176/* See read.h. */
2177
2178void
2180{
2181 if (fnd != nullptr)
2182 fnd->forget_fullname ();
2183
2184 if (per_bfd == nullptr)
2185 return;
2186
2187 struct quick_file_names *file_data = file_names;
2188 if (file_data != nullptr && file_data->real_names != nullptr)
2189 {
2190 for (int i = 0; i < file_data->num_file_names; ++i)
2191 {
2192 xfree ((void *) file_data->real_names[i]);
2193 file_data->real_names[i] = nullptr;
2194 }
2195 }
2196}
2197
2198void
2200 (struct objfile *objfile)
2201{
2203
2204 for (auto &per_cu : per_objfile->per_bfd->all_units)
2205 per_cu->free_cached_file_names ();
2206}
2207
2208void
2210 bool print_bcache)
2211{
2212 if (print_bcache)
2213 return;
2214
2216 int total = per_objfile->per_bfd->all_units.size ();
2217 int count = 0;
2218
2219 for (int i = 0; i < total; ++i)
2220 {
2221 dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cu (i);
2222
2223 if (!per_objfile->symtab_set_p (per_cu))
2224 ++count;
2225 }
2226 gdb_printf (_(" Number of read CUs: %d\n"), total - count);
2227 gdb_printf (_(" Number of unread CUs: %d\n"), count);
2228}
2229
2230void
2232{
2234 int total_units = per_objfile->per_bfd->all_units.size ();
2235
2236 for (int i = 0; i < total_units; ++i)
2237 {
2238 dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->get_cu (i);
2239
2240 /* We don't want to directly expand a partial CU, because if we
2241 read it with the wrong language, then assertion failures can
2242 be triggered later on. See PR symtab/23010. So, tell
2243 dw2_instantiate_symtab to skip partial CUs -- any important
2244 partial CU will be read via DW_TAG_imported_unit anyway. */
2245 dw2_instantiate_symtab (per_cu, per_objfile, true);
2246 }
2247}
2248
2249
2250/* Starting from a search name, return the string that finds the upper
2251 bound of all strings that start with SEARCH_NAME in a sorted name
2252 list. Returns the empty string to indicate that the upper bound is
2253 the end of the list. */
2254
2255static std::string
2256make_sort_after_prefix_name (const char *search_name)
2257{
2258 /* When looking to complete "func", we find the upper bound of all
2259 symbols that start with "func" by looking for where we'd insert
2260 the closest string that would follow "func" in lexicographical
2261 order. Usually, that's "func"-with-last-character-incremented,
2262 i.e. "fund". Mind non-ASCII characters, though. Usually those
2263 will be UTF-8 multi-byte sequences, but we can't be certain.
2264 Especially mind the 0xff character, which is a valid character in
2265 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
2266 rule out compilers allowing it in identifiers. Note that
2267 conveniently, strcmp/strcasecmp are specified to compare
2268 characters interpreted as unsigned char. So what we do is treat
2269 the whole string as a base 256 number composed of a sequence of
2270 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
2271 to 0, and carries 1 to the following more-significant position.
2272 If the very first character in SEARCH_NAME ends up incremented
2273 and carries/overflows, then the upper bound is the end of the
2274 list. The string after the empty string is also the empty
2275 string.
2276
2277 Some examples of this operation:
2278
2279 SEARCH_NAME => "+1" RESULT
2280
2281 "abc" => "abd"
2282 "ab\xff" => "ac"
2283 "\xff" "a" "\xff" => "\xff" "b"
2284 "\xff" => ""
2285 "\xff\xff" => ""
2286 "" => ""
2287
2288 Then, with these symbols for example:
2289
2290 func
2291 func1
2292 fund
2293
2294 completing "func" looks for symbols between "func" and
2295 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
2296 which finds "func" and "func1", but not "fund".
2297
2298 And with:
2299
2300 funcÿ (Latin1 'ÿ' [0xff])
2301 funcÿ1
2302 fund
2303
2304 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
2305 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
2306
2307 And with:
2308
2309 ÿÿ (Latin1 'ÿ' [0xff])
2310 ÿÿ1
2311
2312 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
2313 the end of the list.
2314 */
2315 std::string after = search_name;
2316 while (!after.empty () && (unsigned char) after.back () == 0xff)
2317 after.pop_back ();
2318 if (!after.empty ())
2319 after.back () = (unsigned char) after.back () + 1;
2320 return after;
2321}
2322
2323/* See declaration. */
2324
2325std::pair<std::vector<name_component>::const_iterator,
2326 std::vector<name_component>::const_iterator>
2328 (const lookup_name_info &lookup_name_without_params, language lang,
2329 dwarf2_per_objfile *per_objfile) const
2330{
2331 auto *name_cmp
2332 = this->name_components_casing == case_sensitive_on ? strcmp : strcasecmp;
2333
2334 const char *lang_name
2335 = lookup_name_without_params.language_lookup_name (lang);
2336
2337 /* Comparison function object for lower_bound that matches against a
2338 given symbol name. */
2339 auto lookup_compare_lower = [&] (const name_component &elem,
2340 const char *name)
2341 {
2342 const char *elem_qualified = this->symbol_name_at (elem.idx, per_objfile);
2343 const char *elem_name = elem_qualified + elem.name_offset;
2344 return name_cmp (elem_name, name) < 0;
2345 };
2346
2347 /* Comparison function object for upper_bound that matches against a
2348 given symbol name. */
2349 auto lookup_compare_upper = [&] (const char *name,
2350 const name_component &elem)
2351 {
2352 const char *elem_qualified = this->symbol_name_at (elem.idx, per_objfile);
2353 const char *elem_name = elem_qualified + elem.name_offset;
2354 return name_cmp (name, elem_name) < 0;
2355 };
2356
2357 auto begin = this->name_components.begin ();
2358 auto end = this->name_components.end ();
2359
2360 /* Find the lower bound. */
2361 auto lower = [&] ()
2362 {
2363 if (lookup_name_without_params.completion_mode () && lang_name[0] == '\0')
2364 return begin;
2365 else
2366 return std::lower_bound (begin, end, lang_name, lookup_compare_lower);
2367 } ();
2368
2369 /* Find the upper bound. */
2370 auto upper = [&] ()
2371 {
2372 if (lookup_name_without_params.completion_mode ())
2373 {
2374 /* In completion mode, we want UPPER to point past all
2375 symbols names that have the same prefix. I.e., with
2376 these symbols, and completing "func":
2377
2378 function << lower bound
2379 function1
2380 other_function << upper bound
2381
2382 We find the upper bound by looking for the insertion
2383 point of "func"-with-last-character-incremented,
2384 i.e. "fund". */
2385 std::string after = make_sort_after_prefix_name (lang_name);
2386 if (after.empty ())
2387 return end;
2388 return std::lower_bound (lower, end, after.c_str (),
2389 lookup_compare_lower);
2390 }
2391 else
2392 return std::upper_bound (lower, end, lang_name, lookup_compare_upper);
2393 } ();
2394
2395 return {lower, upper};
2396}
2397
2398/* See declaration. */
2399
2400void
2402{
2403 if (!this->name_components.empty ())
2404 return;
2405
2407 auto *name_cmp
2408 = this->name_components_casing == case_sensitive_on ? strcmp : strcasecmp;
2409
2410 /* The code below only knows how to break apart components of C++
2411 symbol names (and other languages that use '::' as
2412 namespace/module separator) and Ada symbol names. */
2413 auto count = this->symbol_name_count ();
2414 for (offset_type idx = 0; idx < count; idx++)
2415 {
2416 if (this->symbol_name_slot_invalid (idx))
2417 continue;
2418
2419 const char *name = this->symbol_name_at (idx, per_objfile);
2420
2421 /* Add each name component to the name component table. */
2422 unsigned int previous_len = 0;
2423
2424 if (strstr (name, "::") != nullptr)
2425 {
2426 for (unsigned int current_len = cp_find_first_component (name);
2427 name[current_len] != '\0';
2428 current_len += cp_find_first_component (name + current_len))
2429 {
2430 gdb_assert (name[current_len] == ':');
2431 this->name_components.push_back ({previous_len, idx});
2432 /* Skip the '::'. */
2433 current_len += 2;
2434 previous_len = current_len;
2435 }
2436 }
2437 else
2438 {
2439 /* Handle the Ada encoded (aka mangled) form here. */
2440 for (const char *iter = strstr (name, "__");
2441 iter != nullptr;
2442 iter = strstr (iter, "__"))
2443 {
2444 this->name_components.push_back ({previous_len, idx});
2445 iter += 2;
2446 previous_len = iter - name;
2447 }
2448 }
2449
2450 this->name_components.push_back ({previous_len, idx});
2451 }
2452
2453 /* Sort name_components elements by name. */
2454 auto name_comp_compare = [&] (const name_component &left,
2455 const name_component &right)
2456 {
2457 const char *left_qualified
2458 = this->symbol_name_at (left.idx, per_objfile);
2459 const char *right_qualified
2460 = this->symbol_name_at (right.idx, per_objfile);
2461
2462 const char *left_name = left_qualified + left.name_offset;
2463 const char *right_name = right_qualified + right.name_offset;
2464
2465 return name_cmp (left_name, right_name) < 0;
2466 };
2467
2468 std::sort (this->name_components.begin (),
2469 this->name_components.end (),
2470 name_comp_compare);
2471}
2472
2473/* See read.h. */
2474
2475bool
2477 (mapped_index_base &index,
2478 const lookup_name_info &lookup_name_in,
2479 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
2480 gdb::function_view<bool (offset_type)> match_callback,
2481 dwarf2_per_objfile *per_objfile)
2482{
2483 lookup_name_info lookup_name_without_params
2484 = lookup_name_in.make_ignore_params ();
2485
2486 /* Build the symbol name component sorted vector, if we haven't
2487 yet. */
2488 index.build_name_components (per_objfile);
2489
2490 /* The same symbol may appear more than once in the range though.
2491 E.g., if we're looking for symbols that complete "w", and we have
2492 a symbol named "w1::w2", we'll find the two name components for
2493 that same symbol in the range. To be sure we only call the
2494 callback once per symbol, we first collect the symbol name
2495 indexes that matched in a temporary vector and ignore
2496 duplicates. */
2497 std::vector<offset_type> matches;
2498
2499 struct name_and_matcher
2500 {
2502 const char *name;
2503
2504 bool operator== (const name_and_matcher &other) const
2505 {
2506 return matcher == other.matcher && strcmp (name, other.name) == 0;
2507 }
2508 };
2509
2510 /* A vector holding all the different symbol name matchers, for all
2511 languages. */
2512 std::vector<name_and_matcher> matchers;
2513
2514 for (int i = 0; i < nr_languages; i++)
2515 {
2516 enum language lang_e = (enum language) i;
2517
2518 const language_defn *lang = language_def (lang_e);
2519 symbol_name_matcher_ftype *name_matcher
2520 = lang->get_symbol_name_matcher (lookup_name_without_params);
2521
2522 name_and_matcher key {
2523 name_matcher,
2524 lookup_name_without_params.language_lookup_name (lang_e)
2525 };
2526
2527 /* Don't insert the same comparison routine more than once.
2528 Note that we do this linear walk. This is not a problem in
2529 practice because the number of supported languages is
2530 low. */
2531 if (std::find (matchers.begin (), matchers.end (), key)
2532 != matchers.end ())
2533 continue;
2534 matchers.push_back (std::move (key));
2535
2536 auto bounds
2537 = index.find_name_components_bounds (lookup_name_without_params,
2538 lang_e, per_objfile);
2539
2540 /* Now for each symbol name in range, check to see if we have a name
2541 match, and if so, call the MATCH_CALLBACK callback. */
2542
2543 for (; bounds.first != bounds.second; ++bounds.first)
2544 {
2545 const char *qualified
2546 = index.symbol_name_at (bounds.first->idx, per_objfile);
2547
2548 if (!name_matcher (qualified, lookup_name_without_params, NULL)
2549 || (symbol_matcher != NULL && !symbol_matcher (qualified)))
2550 continue;
2551
2552 matches.push_back (bounds.first->idx);
2553 }
2554 }
2555
2556 std::sort (matches.begin (), matches.end ());
2557
2558 /* Finally call the callback, once per match. */
2559 ULONGEST prev = -1;
2560 bool result = true;
2561 for (offset_type idx : matches)
2562 {
2563 if (prev != idx)
2564 {
2565 if (!match_callback (idx))
2566 {
2567 result = false;
2568 break;
2569 }
2570 prev = idx;
2571 }
2572 }
2573
2574 /* Above we use a type wider than idx's for 'prev', since 0 and
2575 (offset_type)-1 are both possible values. */
2576 static_assert (sizeof (prev) > sizeof (offset_type), "");
2577
2578 return result;
2579}
2580
2581#if GDB_SELF_TEST
2582
2583namespace selftests { namespace dw2_expand_symtabs_matching {
2584
2585/* A mock .gdb_index/.debug_names-like name index table, enough to
2586 exercise dw2_expand_symtabs_matching_symbol, which works with the
2587 mapped_index_base interface. Builds an index from the symbol list
2588 passed as parameter to the constructor. */
2589class mock_mapped_index : public mapped_index_base
2590{
2591public:
2592 mock_mapped_index (gdb::array_view<const char *> symbols)
2593 : m_symbol_table (symbols)
2594 {}
2595
2596 DISABLE_COPY_AND_ASSIGN (mock_mapped_index);
2597
2598 /* Return the number of names in the symbol table. */
2599 size_t symbol_name_count () const override
2600 {
2601 return m_symbol_table.size ();
2602 }
2603
2604 /* Get the name of the symbol at IDX in the symbol table. */
2605 const char *symbol_name_at
2606 (offset_type idx, dwarf2_per_objfile *per_objfile) const override
2607 {
2608 return m_symbol_table[idx];
2609 }
2610
2611 quick_symbol_functions_up make_quick_functions () const override
2612 {
2613 return nullptr;
2614 }
2615
2616private:
2617 gdb::array_view<const char *> m_symbol_table;
2618};
2619
2620/* Convenience function that converts a NULL pointer to a "<null>"
2621 string, to pass to print routines. */
2622
2623static const char *
2624string_or_null (const char *str)
2625{
2626 return str != NULL ? str : "<null>";
2627}
2628
2629/* Check if a lookup_name_info built from
2630 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
2631 index. EXPECTED_LIST is the list of expected matches, in expected
2632 matching order. If no match expected, then an empty list is
2633 specified. Returns true on success. On failure prints a warning
2634 indicating the file:line that failed, and returns false. */
2635
2636static bool
2637check_match (const char *file, int line,
2638 mock_mapped_index &mock_index,
2639 const char *name, symbol_name_match_type match_type,
2640 bool completion_mode,
2641 std::initializer_list<const char *> expected_list,
2642 dwarf2_per_objfile *per_objfile)
2643{
2644 lookup_name_info lookup_name (name, match_type, completion_mode);
2645
2646 bool matched = true;
2647
2648 auto mismatch = [&] (const char *expected_str,
2649 const char *got)
2650 {
2651 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
2652 "expected=\"%s\", got=\"%s\"\n"),
2653 file, line,
2654 (match_type == symbol_name_match_type::FULL
2655 ? "FULL" : "WILD"),
2656 name, string_or_null (expected_str), string_or_null (got));
2657 matched = false;
2658 };
2659
2660 auto expected_it = expected_list.begin ();
2661 auto expected_end = expected_list.end ();
2662
2663 dw2_expand_symtabs_matching_symbol (mock_index, lookup_name,
2664 nullptr,
2665 [&] (offset_type idx)
2666 {
2667 const char *matched_name = mock_index.symbol_name_at (idx, per_objfile);
2668 const char *expected_str
2669 = expected_it == expected_end ? NULL : *expected_it++;
2670
2671 if (expected_str == NULL || strcmp (expected_str, matched_name) != 0)
2672 mismatch (expected_str, matched_name);
2673 return true;
2674 }, per_objfile);
2675
2676 const char *expected_str
2677 = expected_it == expected_end ? NULL : *expected_it++;
2678 if (expected_str != NULL)
2679 mismatch (expected_str, NULL);
2680
2681 return matched;
2682}
2683
2684/* The symbols added to the mock mapped_index for testing (in
2685 canonical form). */
2686static const char *test_symbols[] = {
2687 "function",
2688 "std::bar",
2689 "std::zfunction",
2690 "std::zfunction2",
2691 "w1::w2",
2692 "ns::foo<char*>",
2693 "ns::foo<int>",
2694 "ns::foo<long>",
2695 "ns2::tmpl<int>::foo2",
2696 "(anonymous namespace)::A::B::C",
2697
2698 /* These are used to check that the increment-last-char in the
2699 matching algorithm for completion doesn't match "t1_fund" when
2700 completing "t1_func". */
2701 "t1_func",
2702 "t1_func1",
2703 "t1_fund",
2704 "t1_fund1",
2705
2706 /* A UTF-8 name with multi-byte sequences to make sure that
2707 cp-name-parser understands this as a single identifier ("função"
2708 is "function" in PT). */
2709 (const char *)u8"u8função",
2710
2711 /* Test a symbol name that ends with a 0xff character, which is a
2712 valid character in non-UTF-8 source character sets (e.g. Latin1
2713 'ÿ'), and we can't rule out compilers allowing it in identifiers.
2714 We test this because the completion algorithm finds the upper
2715 bound of symbols by looking for the insertion point of
2716 "func"-with-last-character-incremented, i.e. "fund", and adding 1
2717 to 0xff should wraparound and carry to the previous character.
2718 See comments in make_sort_after_prefix_name. */
2719 "yfunc\377",
2720
2721 /* Some more symbols with \377 (0xff). See above. */
2722 "\377",
2723 "\377\377123",
2724
2725 /* A name with all sorts of complications. Starts with "z" to make
2726 it easier for the completion tests below. */
2727#define Z_SYM_NAME \
2728 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
2729 "::tuple<(anonymous namespace)::ui*, " \
2730 "std::default_delete<(anonymous namespace)::ui>, void>"
2731
2732 Z_SYM_NAME
2733};
2734
2735/* Returns true if the mapped_index_base::find_name_component_bounds
2736 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
2737 in completion mode. */
2738
2739static bool
2740check_find_bounds_finds (mapped_index_base &index,
2741 const char *search_name,
2742 gdb::array_view<const char *> expected_syms,
2743 dwarf2_per_objfile *per_objfile)
2744{
2745 lookup_name_info lookup_name (search_name,
2747
2748 auto bounds = index.find_name_components_bounds (lookup_name,
2750 per_objfile);
2751
2752 size_t distance = std::distance (bounds.first, bounds.second);
2753 if (distance != expected_syms.size ())
2754 return false;
2755
2756 for (size_t exp_elem = 0; exp_elem < distance; exp_elem++)
2757 {
2758 auto nc_elem = bounds.first + exp_elem;
2759 const char *qualified = index.symbol_name_at (nc_elem->idx, per_objfile);
2760 if (strcmp (qualified, expected_syms[exp_elem]) != 0)
2761 return false;
2762 }
2763
2764 return true;
2765}
2766
2767/* Test the lower-level mapped_index::find_name_component_bounds
2768 method. */
2769
2770static void
2771test_mapped_index_find_name_component_bounds ()
2772{
2773 mock_mapped_index mock_index (test_symbols);
2774
2775 mock_index.build_name_components (NULL /* per_objfile */);
2776
2777 /* Test the lower-level mapped_index::find_name_component_bounds
2778 method in completion mode. */
2779 {
2780 static const char *expected_syms[] = {
2781 "t1_func",
2782 "t1_func1",
2783 };
2784
2785 SELF_CHECK (check_find_bounds_finds
2786 (mock_index, "t1_func", expected_syms,
2787 NULL /* per_objfile */));
2788 }
2789
2790 /* Check that the increment-last-char in the name matching algorithm
2791 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. See
2792 make_sort_after_prefix_name. */
2793 {
2794 static const char *expected_syms1[] = {
2795 "\377",
2796 "\377\377123",
2797 };
2798 SELF_CHECK (check_find_bounds_finds
2799 (mock_index, "\377", expected_syms1, NULL /* per_objfile */));
2800
2801 static const char *expected_syms2[] = {
2802 "\377\377123",
2803 };
2804 SELF_CHECK (check_find_bounds_finds
2805 (mock_index, "\377\377", expected_syms2,
2806 NULL /* per_objfile */));
2807 }
2808}
2809
2810/* Test dw2_expand_symtabs_matching_symbol. */
2811
2812static void
2813test_dw2_expand_symtabs_matching_symbol ()
2814{
2815 mock_mapped_index mock_index (test_symbols);
2816
2817 /* We let all tests run until the end even if some fails, for debug
2818 convenience. */
2819 bool any_mismatch = false;
2820
2821 /* Create the expected symbols list (an initializer_list). Needed
2822 because lists have commas, and we need to pass them to CHECK,
2823 which is a macro. */
2824#define EXPECT(...) { __VA_ARGS__ }
2825
2826 /* Wrapper for check_match that passes down the current
2827 __FILE__/__LINE__. */
2828#define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
2829 any_mismatch |= !check_match (__FILE__, __LINE__, \
2830 mock_index, \
2831 NAME, MATCH_TYPE, COMPLETION_MODE, \
2832 EXPECTED_LIST, NULL)
2833
2834 /* Identity checks. */
2835 for (const char *sym : test_symbols)
2836 {
2837 /* Should be able to match all existing symbols. */
2838 CHECK_MATCH (sym, symbol_name_match_type::FULL, false,
2839 EXPECT (sym));
2840
2841 /* Should be able to match all existing symbols with
2842 parameters. */
2843 std::string with_params = std::string (sym) + "(int)";
2844 CHECK_MATCH (with_params.c_str (), symbol_name_match_type::FULL, false,
2845 EXPECT (sym));
2846
2847 /* Should be able to match all existing symbols with
2848 parameters and qualifiers. */
2849 with_params = std::string (sym) + " ( int ) const";
2850 CHECK_MATCH (with_params.c_str (), symbol_name_match_type::FULL, false,
2851 EXPECT (sym));
2852
2853 /* This should really find sym, but cp-name-parser.y doesn't
2854 know about lvalue/rvalue qualifiers yet. */
2855 with_params = std::string (sym) + " ( int ) &&";
2856 CHECK_MATCH (with_params.c_str (), symbol_name_match_type::FULL, false,
2857 {});
2858 }
2859
2860 /* Check that the name matching algorithm for completion doesn't get
2861 confused with Latin1 'ÿ' / 0xff. See
2862 make_sort_after_prefix_name. */
2863 {
2864 static const char str[] = "\377";
2865 CHECK_MATCH (str, symbol_name_match_type::FULL, true,
2866 EXPECT ("\377", "\377\377123"));
2867 }
2868
2869 /* Check that the increment-last-char in the matching algorithm for
2870 completion doesn't match "t1_fund" when completing "t1_func". */
2871 {
2872 static const char str[] = "t1_func";
2873 CHECK_MATCH (str, symbol_name_match_type::FULL, true,
2874 EXPECT ("t1_func", "t1_func1"));
2875 }
2876
2877 /* Check that completion mode works at each prefix of the expected
2878 symbol name. */
2879 {
2880 static const char str[] = "function(int)";
2881 size_t len = strlen (str);
2882 std::string lookup;
2883
2884 for (size_t i = 1; i < len; i++)
2885 {
2886 lookup.assign (str, i);
2887 CHECK_MATCH (lookup.c_str (), symbol_name_match_type::FULL, true,
2888 EXPECT ("function"));
2889 }
2890 }
2891
2892 /* While "w" is a prefix of both components, the match function
2893 should still only be called once. */
2894 {
2895 CHECK_MATCH ("w", symbol_name_match_type::FULL, true,
2896 EXPECT ("w1::w2"));
2897 CHECK_MATCH ("w", symbol_name_match_type::WILD, true,
2898 EXPECT ("w1::w2"));
2899 }
2900
2901 /* Same, with a "complicated" symbol. */
2902 {
2903 static const char str[] = Z_SYM_NAME;
2904 size_t len = strlen (str);
2905 std::string lookup;
2906
2907 for (size_t i = 1; i < len; i++)
2908 {
2909 lookup.assign (str, i);
2910 CHECK_MATCH (lookup.c_str (), symbol_name_match_type::FULL, true,
2911 EXPECT (Z_SYM_NAME));
2912 }
2913 }
2914
2915 /* In FULL mode, an incomplete symbol doesn't match. */
2916 {
2917 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL, false,
2918 {});
2919 }
2920
2921 /* A complete symbol with parameters matches any overload, since the
2922 index has no overload info. */
2923 {
2924 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL, true,
2925 EXPECT ("std::zfunction", "std::zfunction2"));
2926 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD, true,
2927 EXPECT ("std::zfunction", "std::zfunction2"));
2928 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD, true,
2929 EXPECT ("std::zfunction", "std::zfunction2"));
2930 }
2931
2932 /* Check that whitespace is ignored appropriately. A symbol with a
2933 template argument list. */
2934 {
2935 static const char expected[] = "ns::foo<int>";
2936 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL, false,
2937 EXPECT (expected));
2938 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD, false,
2939 EXPECT (expected));
2940 }
2941
2942 /* Check that whitespace is ignored appropriately. A symbol with a
2943 template argument list that includes a pointer. */
2944 {
2945 static const char expected[] = "ns::foo<char*>";
2946 /* Try both completion and non-completion modes. */
2947 static const bool completion_mode[2] = {false, true};
2948 for (size_t i = 0; i < 2; i++)
2949 {
2950 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL,
2951 completion_mode[i], EXPECT (expected));
2952 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD,
2953 completion_mode[i], EXPECT (expected));
2954
2955 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL,
2956 completion_mode[i], EXPECT (expected));
2957 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD,
2958 completion_mode[i], EXPECT (expected));
2959 }
2960 }
2961
2962 {
2963 /* Check method qualifiers are ignored. */
2964 static const char expected[] = "ns::foo<char*>";
2965 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
2966 symbol_name_match_type::FULL, true, EXPECT (expected));
2967 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
2968 symbol_name_match_type::FULL, true, EXPECT (expected));
2969 CHECK_MATCH ("foo < char * > ( int ) const",
2970 symbol_name_match_type::WILD, true, EXPECT (expected));
2971 CHECK_MATCH ("foo < char * > ( int ) &&",
2972 symbol_name_match_type::WILD, true, EXPECT (expected));
2973 }
2974
2975 /* Test lookup names that don't match anything. */
2976 {
2977 CHECK_MATCH ("bar2", symbol_name_match_type::WILD, false,
2978 {});
2979
2980 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL, false,
2981 {});
2982 }
2983
2984 /* Some wild matching tests, exercising "(anonymous namespace)",
2985 which should not be confused with a parameter list. */
2986 {
2987 static const char *syms[] = {
2988 "A::B::C",
2989 "B::C",
2990 "C",
2991 "A :: B :: C ( int )",
2992 "B :: C ( int )",
2993 "C ( int )",
2994 };
2995
2996 for (const char *s : syms)
2997 {
2998 CHECK_MATCH (s, symbol_name_match_type::WILD, false,
2999 EXPECT ("(anonymous namespace)::A::B::C"));
3000 }
3001 }
3002
3003 {
3004 static const char expected[] = "ns2::tmpl<int>::foo2";
3005 CHECK_MATCH ("tmp", symbol_name_match_type::WILD, true,
3006 EXPECT (expected));
3007 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD, true,
3008 EXPECT (expected));
3009 }
3010
3011 SELF_CHECK (!any_mismatch);
3012
3013#undef EXPECT
3014#undef CHECK_MATCH
3015}
3016
3017static void
3018run_test ()
3019{
3020 test_mapped_index_find_name_component_bounds ();
3021 test_dw2_expand_symtabs_matching_symbol ();
3022}
3023
3024}} // namespace selftests::dw2_expand_symtabs_matching
3025
3026#endif /* GDB_SELF_TEST */
3027
3028/* See read.h. */
3029
3030bool
3032 (dwarf2_per_cu_data *per_cu,
3033 dwarf2_per_objfile *per_objfile,
3034 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
3035 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify)
3036{
3037 if (file_matcher == NULL || per_cu->mark)
3038 {
3039 bool symtab_was_null = !per_objfile->symtab_set_p (per_cu);
3040
3042 = dw2_instantiate_symtab (per_cu, per_objfile, false);
3043 gdb_assert (symtab != nullptr);
3044
3045 if (expansion_notify != NULL && symtab_was_null)
3046 return expansion_notify (symtab);
3047 }
3048 return true;
3049}
3050
3051/* See read.h. */
3052
3053void
3055 (dwarf2_per_objfile *per_objfile,
3056 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher)
3057{
3058 if (file_matcher == NULL)
3059 return;
3060
3061 htab_up visited_found (htab_create_alloc (10, htab_hash_pointer,
3062 htab_eq_pointer,
3063 NULL, xcalloc, xfree));
3064 htab_up visited_not_found (htab_create_alloc (10, htab_hash_pointer,
3065 htab_eq_pointer,
3066 NULL, xcalloc, xfree));
3067
3068 /* The rule is CUs specify all the files, including those used by
3069 any TU, so there's no need to scan TUs here. */
3070
3071 for (const auto &per_cu : per_objfile->per_bfd->all_units)
3072 {
3073 QUIT;
3074
3075 if (per_cu->is_debug_types)
3076 continue;
3077 per_cu->mark = 0;
3078
3079 /* We only need to look at symtabs not already expanded. */
3080 if (per_objfile->symtab_set_p (per_cu.get ()))
3081 continue;
3082
3083 if (per_cu->fnd != nullptr)
3084 {
3085 file_and_directory *fnd = per_cu->fnd.get ();
3086
3087 if (file_matcher (fnd->get_name (), false))
3088 {
3089 per_cu->mark = 1;
3090 continue;
3091 }
3092
3093 /* Before we invoke realpath, which can get expensive when many
3094 files are involved, do a quick comparison of the basenames. */
3096 || file_matcher (lbasename (fnd->get_name ()), true))
3097 && file_matcher (fnd->get_fullname (), false))
3098 {
3099 per_cu->mark = 1;
3100 continue;
3101 }
3102 }
3103
3104 quick_file_names *file_data = dw2_get_file_names (per_cu.get (),
3105 per_objfile);
3106 if (file_data == NULL)
3107 continue;
3108
3109 if (htab_find (visited_not_found.get (), file_data) != NULL)
3110 continue;
3111 else if (htab_find (visited_found.get (), file_data) != NULL)
3112 {
3113 per_cu->mark = 1;
3114 continue;
3115 }
3116
3117 for (int j = 0; j < file_data->num_file_names; ++j)
3118 {
3119 const char *this_real_name;
3120
3121 if (file_matcher (file_data->file_names[j], false))
3122 {
3123 per_cu->mark = 1;
3124 break;
3125 }
3126
3127 /* Before we invoke realpath, which can get expensive when many
3128 files are involved, do a quick comparison of the basenames. */
3130 && !file_matcher (lbasename (file_data->file_names[j]),
3131 true))
3132 continue;
3133
3134 this_real_name = dw2_get_real_path (per_objfile, file_data, j);
3135 if (file_matcher (this_real_name, false))
3136 {
3137 per_cu->mark = 1;
3138 break;
3139 }
3140 }
3141
3142 void **slot = htab_find_slot (per_cu->mark
3143 ? visited_found.get ()
3144 : visited_not_found.get (),
3145 file_data, INSERT);
3146 *slot = file_data;
3147 }
3148}
3149
3150
3151/* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
3152 symtab. */
3153
3154static struct compunit_symtab *
3156 CORE_ADDR pc)
3157{
3158 int i;
3159
3160 if (cust->blockvector () != nullptr
3161 && blockvector_contains_pc (cust->blockvector (), pc))
3162 return cust;
3163
3164 if (cust->includes == NULL)
3165 return NULL;
3166
3167 for (i = 0; cust->includes[i]; ++i)
3168 {
3169 struct compunit_symtab *s = cust->includes[i];
3170
3172 if (s != NULL)
3173 return s;
3174 }
3175
3176 return NULL;
3177}
3178
3181 CORE_ADDR adjusted_pc)
3182{
3183 if (per_bfd->index_addrmap == nullptr)
3184 return nullptr;
3185
3186 void *obj = per_bfd->index_addrmap->find (adjusted_pc);
3187 return static_cast<dwarf2_per_cu_data *> (obj);
3188}
3189
3190struct compunit_symtab *
3192 (struct objfile *objfile,
3193 struct bound_minimal_symbol msymbol,
3194 CORE_ADDR pc,
3195 struct obj_section *section,
3196 int warn_if_readin)
3197{
3198 struct compunit_symtab *result;
3199
3201
3202 CORE_ADDR baseaddr = objfile->text_section_offset ();
3203 struct dwarf2_per_cu_data *data = find_per_cu (per_objfile->per_bfd,
3204 pc - baseaddr);
3205 if (data == nullptr)
3206 return nullptr;
3207
3208 if (warn_if_readin && per_objfile->symtab_set_p (data))
3209 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3210 paddress (objfile->arch (), pc));
3211
3213 (dw2_instantiate_symtab (data, per_objfile, false), pc);
3214
3215 if (warn_if_readin && result == nullptr)
3216 warning (_("(Error: pc %s in address map, but not in symtab.)"),
3217 paddress (objfile->arch (), pc));
3218
3219 return result;
3220}
3221
3222void
3224 (struct objfile *objfile,
3225 gdb::function_view<symbol_filename_ftype> fun,
3226 bool need_fullname)
3227{
3229
3230 /* Use caches to ensure we only call FUN once for each filename. */
3231 filename_seen_cache filenames_cache;
3232 std::unordered_set<quick_file_names *> qfn_cache;
3233
3234 /* The rule is CUs specify all the files, including those used by any TU,
3235 so there's no need to scan TUs here. We can ignore file names coming
3236 from already-expanded CUs. It is possible that an expanded CU might
3237 reuse the file names data from a currently unexpanded CU, in this
3238 case we don't want to report the files from the unexpanded CU. */
3239
3240 for (const auto &per_cu : per_objfile->per_bfd->all_units)
3241 {
3242 if (!per_cu->is_debug_types
3243 && per_objfile->symtab_set_p (per_cu.get ()))
3244 {
3245 if (per_cu->file_names != nullptr)
3246 qfn_cache.insert (per_cu->file_names);
3247 }
3248 }
3249
3250 for (dwarf2_per_cu_data *per_cu
3251 : all_units_range (per_objfile->per_bfd))
3252 {
3253 /* We only need to look at symtabs not already expanded. */
3254 if (per_cu->is_debug_types || per_objfile->symtab_set_p (per_cu))
3255 continue;
3256
3257 if (per_cu->fnd != nullptr)
3258 {
3259 file_and_directory *fnd = per_cu->fnd.get ();
3260
3261 const char *filename = fnd->get_name ();
3262 const char *key = filename;
3263 const char *fullname = nullptr;
3264
3265 if (need_fullname)
3266 {
3267 fullname = fnd->get_fullname ();
3268 key = fullname;
3269 }
3270
3271 if (!filenames_cache.seen (key))
3272 fun (filename, fullname);
3273 }
3274
3275 quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile);
3276 if (file_data == nullptr
3277 || qfn_cache.find (file_data) != qfn_cache.end ())
3278 continue;
3279
3280 for (int j = 0; j < file_data->num_file_names; ++j)
3281 {
3282 const char *filename = file_data->file_names[j];
3283 const char *key = filename;
3284 const char *fullname = nullptr;
3285
3286 if (need_fullname)
3287 {
3288 fullname = dw2_get_real_path (per_objfile, file_data, j);
3289 key = fullname;
3290 }
3291
3292 if (!filenames_cache.seen (key))
3293 fun (filename, fullname);
3294 }
3295 }
3296}
3297
3298bool
3300{
3301 return true;
3302}
3303
3304/* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
3305
3306bool
3308{
3310
3311 for (const auto &per_cu : per_objfile->per_bfd->all_units)
3312 {
3313 /* Is this already expanded? */
3314 if (per_objfile->symtab_set_p (per_cu.get ()))
3315 continue;
3316
3317 /* It has not yet been expanded. */
3318 return true;
3319 }
3320
3321 return false;
3322}
3323
3324/* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
3325 to either a dwarf2_per_bfd or dwz_file object. */
3326
3327template <typename T>
3328static gdb::array_view<const gdb_byte>
3330{
3331 dwarf2_section_info *section = &section_owner->gdb_index;
3332
3333 if (section->empty ())
3334 return {};
3335
3336 /* Older elfutils strip versions could keep the section in the main
3337 executable while splitting it for the separate debug info file. */
3338 if ((section->get_flags () & SEC_HAS_CONTENTS) == 0)
3339 return {};
3340
3341 section->read (obj);
3342
3343 /* dwarf2_section_info::size is a bfd_size_type, while
3344 gdb::array_view works with size_t. On 32-bit hosts, with
3345 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
3346 is 32-bit. So we need an explicit narrowing conversion here.
3347 This is fine, because it's impossible to allocate or mmap an
3348 array/buffer larger than what size_t can represent. */
3349 return gdb::make_array_view (section->buffer, section->size);
3350}
3351
3352/* Lookup the index cache for the contents of the index associated to
3353 DWARF2_OBJ. */
3354
3355static gdb::array_view<const gdb_byte>
3357{
3358 const bfd_build_id *build_id = build_id_bfd_get (obj->obfd.get ());
3359 if (build_id == nullptr)
3360 return {};
3361
3362 return global_index_cache.lookup_gdb_index (build_id,
3364}
3365
3366/* Same as the above, but for DWZ. */
3367
3368static gdb::array_view<const gdb_byte>
3370{
3371 const bfd_build_id *build_id = build_id_bfd_get (dwz->dwz_bfd.get ());
3372 if (build_id == nullptr)
3373 return {};
3374
3375 return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res);
3376}
3377
3379
3380/* See dwarf2/public.h. */
3381
3382void
3384{
3386 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
3387
3388 dwarf_read_debug_printf ("called");
3389
3390 /* If we're about to read full symbols, don't bother with the
3391 indices. In this case we also don't care if some other debug
3392 format is making psymtabs, because they are all about to be
3393 expanded anyway. */
3394 if ((objfile->flags & OBJF_READNOW))
3395 {
3396 dwarf_read_debug_printf ("readnow requested");
3397
3398 create_all_units (per_objfile);
3401
3402 objfile->qf.emplace_front (new readnow_functions);
3403 return;
3404 }
3405
3406 /* Was a GDB index already read when we processed an objfile sharing
3407 PER_BFD? */
3408 if (per_bfd->index_table != nullptr)
3409 {
3410 dwarf_read_debug_printf ("re-using symbols");
3411 objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
3412 return;
3413 }
3414
3415 if (dwarf2_read_debug_names (per_objfile))
3416 {
3417 dwarf_read_debug_printf ("found debug names");
3418 objfile->qf.push_front
3419 (per_bfd->index_table->make_quick_functions ());
3420 return;
3421 }
3422
3423 if (dwarf2_read_gdb_index (per_objfile,
3424 get_gdb_index_contents_from_section<struct dwarf2_per_bfd>,
3425 get_gdb_index_contents_from_section<dwz_file>))
3426 {
3427 dwarf_read_debug_printf ("found gdb index from file");
3428 objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
3429 return;
3430 }
3431
3432 /* ... otherwise, try to find the index in the index cache. */
3433 if (dwarf2_read_gdb_index (per_objfile,
3436 {
3437 dwarf_read_debug_printf ("found gdb index from cache");
3439 objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
3440 return;
3441 }
3442
3444 objfile->qf.push_front (make_cooked_index_funcs ());
3445}
3446
3447
3448
3449/* Build a partial symbol table. */
3450
3451static void
3453{
3455
3456 if (per_objfile->per_bfd->index_table != nullptr)
3457 return;
3458
3459 try
3460 {
3461 dwarf2_build_psymtabs_hard (per_objfile);
3462 }
3463 catch (const gdb_exception_error &except)
3464 {
3465 exception_print (gdb_stderr, except);
3466 }
3467}
3468
3469/* Find the base address of the compilation unit for range lists and
3470 location lists. It will normally be specified by DW_AT_low_pc.
3471 In DWARF-3 draft 4, the base address could be overridden by
3472 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3473 compilation units with discontinuous ranges. */
3474
3475static void
3477{
3478 struct attribute *attr;
3479
3480 cu->base_address.reset ();
3481
3482 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3483 if (attr != nullptr)
3484 cu->base_address = attr->as_address ();
3485 else
3486 {
3487 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3488 if (attr != nullptr)
3489 cu->base_address = attr->as_address ();
3490 }
3491}
3492
3493/* Helper function that returns the proper abbrev section for
3494 THIS_CU. */
3495
3496static struct dwarf2_section_info *
3498{
3499 struct dwarf2_section_info *abbrev;
3500 dwarf2_per_bfd *per_bfd = this_cu->per_bfd;
3501
3502 if (this_cu->is_dwz)
3503 abbrev = &dwarf2_get_dwz_file (per_bfd, true)->abbrev;
3504 else
3505 abbrev = &per_bfd->abbrev;
3506
3507 return abbrev;
3508}
3509
3510/* Fetch the abbreviation table offset from a comp or type unit header. */
3511
3512static sect_offset
3515 sect_offset sect_off)
3516{
3517 bfd *abfd = section->get_bfd_owner ();
3518 const gdb_byte *info_ptr;
3519 unsigned int initial_length_size, offset_size;
3520 uint16_t version;
3521
3522 section->read (per_objfile->objfile);
3523 info_ptr = section->buffer + to_underlying (sect_off);
3524 read_initial_length (abfd, info_ptr, &initial_length_size);
3525 offset_size = initial_length_size == 4 ? 4 : 8;
3526 info_ptr += initial_length_size;
3527
3528 version = read_2_bytes (abfd, info_ptr);
3529 info_ptr += 2;
3530 if (version >= 5)
3531 {
3532 /* Skip unit type and address size. */
3533 info_ptr += 2;
3534 }
3535
3536 return (sect_offset) read_offset (abfd, info_ptr, offset_size);
3537}
3538
3539static hashval_t
3540hash_signatured_type (const void *item)
3541{
3542 const struct signatured_type *sig_type
3543 = (const struct signatured_type *) item;
3544
3545 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3546 return sig_type->signature;
3547}
3548
3549static int
3550eq_signatured_type (const void *item_lhs, const void *item_rhs)
3551{
3552 const struct signatured_type *lhs = (const struct signatured_type *) item_lhs;
3553 const struct signatured_type *rhs = (const struct signatured_type *) item_rhs;
3554
3555 return lhs->signature == rhs->signature;
3556}
3557
3558/* See read.h. */
3559
3560htab_up
3562{
3563 return htab_up (htab_create_alloc (41,
3566 NULL, xcalloc, xfree));
3567}
3568
3569/* A helper for create_debug_types_hash_table. Read types from SECTION
3570 and fill them into TYPES_HTAB. It will process only type units,
3571 therefore DW_UT_type. */
3572
3573static void
3575 struct dwo_file *dwo_file,
3576 dwarf2_section_info *section, htab_up &types_htab,
3577 rcuh_kind section_kind)
3578{
3579 struct objfile *objfile = per_objfile->objfile;
3580 struct dwarf2_section_info *abbrev_section;
3581 bfd *abfd;
3582 const gdb_byte *info_ptr, *end_ptr;
3583
3584 abbrev_section = &dwo_file->sections.abbrev;
3585
3586 dwarf_read_debug_printf ("Reading %s for %s",
3587 section->get_name (),
3588 abbrev_section->get_file_name ());
3589
3590 section->read (objfile);
3591 info_ptr = section->buffer;
3592
3593 if (info_ptr == NULL)
3594 return;
3595
3596 /* We can't set abfd until now because the section may be empty or
3597 not present, in which case the bfd is unknown. */
3598 abfd = section->get_bfd_owner ();
3599
3600 /* We don't use cutu_reader here because we don't need to read
3601 any dies: the signature is in the header. */
3602
3603 end_ptr = info_ptr + section->size;
3604 while (info_ptr < end_ptr)
3605 {
3606 signatured_type_up sig_type;
3607 struct dwo_unit *dwo_tu;
3608 void **slot;
3609 const gdb_byte *ptr = info_ptr;
3610 struct comp_unit_head header;
3611 unsigned int length;
3612
3613 sect_offset sect_off = (sect_offset) (ptr - section->buffer);
3614
3615 /* Initialize it due to a false compiler warning. */
3616 header.signature = -1;
3617 header.type_cu_offset_in_tu = (cu_offset) -1;
3618
3619 /* We need to read the type's signature in order to build the hash
3620 table, but we don't need anything else just yet. */
3621
3622 ptr = read_and_check_comp_unit_head (per_objfile, &header, section,
3623 abbrev_section, ptr, section_kind);
3624
3625 length = header.get_length_with_initial ();
3626
3627 /* Skip dummy type units. */
3628 if (ptr >= info_ptr + length
3629 || peek_abbrev_code (abfd, ptr) == 0
3630 || (header.unit_type != DW_UT_type
3631 && header.unit_type != DW_UT_split_type))
3632 {
3633 info_ptr += length;
3634 continue;
3635 }
3636
3637 if (types_htab == NULL)
3638 types_htab = allocate_dwo_unit_table ();
3639
3640 dwo_tu = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, dwo_unit);
3641 dwo_tu->dwo_file = dwo_file;
3642 dwo_tu->signature = header.signature;
3643 dwo_tu->type_offset_in_tu = header.type_cu_offset_in_tu;
3644 dwo_tu->section = section;
3645 dwo_tu->sect_off = sect_off;
3646 dwo_tu->length = length;
3647
3648 slot = htab_find_slot (types_htab.get (), dwo_tu, INSERT);
3649 gdb_assert (slot != NULL);
3650 if (*slot != NULL)
3651 complaint (_("debug type entry at offset %s is duplicate to"
3652 " the entry at offset %s, signature %s"),
3654 sect_offset_str (dwo_tu->sect_off),
3655 hex_string (header.signature));
3656 *slot = dwo_tu;
3657
3658 dwarf_read_debug_printf_v (" offset %s, signature %s",
3660 hex_string (header.signature));
3661
3662 info_ptr += length;
3663 }
3664}
3665
3666/* Create the hash table of all entries in the .debug_types
3667 (or .debug_types.dwo) section(s).
3668 DWO_FILE is a pointer to the DWO file object.
3669
3670 The result is a pointer to the hash table or NULL if there are no types.
3671
3672 Note: This function processes DWO files only, not DWP files. */
3673
3674static void
3676 struct dwo_file *dwo_file,
3677 gdb::array_view<dwarf2_section_info> type_sections,
3678 htab_up &types_htab)
3679{
3680 for (dwarf2_section_info &section : type_sections)
3681 create_debug_type_hash_table (per_objfile, dwo_file, &section, types_htab,
3683}
3684
3685/* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
3686 If SLOT is non-NULL, it is the entry to use in the hash table.
3687 Otherwise we find one. */
3688
3689static struct signatured_type *
3690add_type_unit (dwarf2_per_objfile *per_objfile, ULONGEST sig, void **slot)
3691{
3692 if (per_objfile->per_bfd->all_units.size ()
3693 == per_objfile->per_bfd->all_units.capacity ())
3694 ++per_objfile->per_bfd->tu_stats.nr_all_type_units_reallocs;
3695
3696 signatured_type_up sig_type_holder
3697 = per_objfile->per_bfd->allocate_signatured_type (sig);
3698 signatured_type *sig_type = sig_type_holder.get ();
3699
3700 per_objfile->per_bfd->all_units.emplace_back
3701 (sig_type_holder.release ());
3702
3703 if (slot == NULL)
3704 {
3705 slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (),
3706 sig_type, INSERT);
3707 }
3708 gdb_assert (*slot == NULL);
3709 *slot = sig_type;
3710 /* The rest of sig_type must be filled in by the caller. */
3711 return sig_type;
3712}
3713
3714/* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
3715 Fill in SIG_ENTRY with DWO_ENTRY. */
3716
3717static void
3719 struct signatured_type *sig_entry,
3720 struct dwo_unit *dwo_entry)
3721{
3722 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
3723
3724 /* Make sure we're not clobbering something we don't expect to. */
3725 gdb_assert (! sig_entry->queued);
3726 gdb_assert (per_objfile->get_cu (sig_entry) == NULL);
3727 gdb_assert (!per_objfile->symtab_set_p (sig_entry));
3728 gdb_assert (sig_entry->signature == dwo_entry->signature);
3729 gdb_assert (to_underlying (sig_entry->type_offset_in_section) == 0
3730 || (to_underlying (sig_entry->type_offset_in_section)
3731 == to_underlying (dwo_entry->type_offset_in_tu)));
3732 gdb_assert (sig_entry->type_unit_group == NULL);
3733 gdb_assert (sig_entry->dwo_unit == NULL
3734 || sig_entry->dwo_unit == dwo_entry);
3735
3736 sig_entry->section = dwo_entry->section;
3737 sig_entry->sect_off = dwo_entry->sect_off;
3738 sig_entry->set_length (dwo_entry->length, false);
3739 sig_entry->reading_dwo_directly = 1;
3740 sig_entry->per_bfd = per_bfd;
3741 sig_entry->type_offset_in_tu = dwo_entry->type_offset_in_tu;
3742 sig_entry->dwo_unit = dwo_entry;
3743}
3744
3745/* Subroutine of lookup_signatured_type.
3746 If we haven't read the TU yet, create the signatured_type data structure
3747 for a TU to be read in directly from a DWO file, bypassing the stub.
3748 This is the "Stay in DWO Optimization": When there is no DWP file and we're
3749 using .gdb_index, then when reading a CU we want to stay in the DWO file
3750 containing that CU. Otherwise we could end up reading several other DWO
3751 files (due to comdat folding) to process the transitive closure of all the
3752 mentioned TUs, and that can be slow. The current DWO file will have every
3753 type signature that it needs.
3754 We only do this for .gdb_index because in the psymtab case we already have
3755 to read all the DWOs to build the type unit groups. */
3756
3757static struct signatured_type *
3758lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
3759{
3760 dwarf2_per_objfile *per_objfile = cu->per_objfile;
3761 struct dwo_file *dwo_file;
3762 struct dwo_unit find_dwo_entry, *dwo_entry;
3763 void **slot;
3764
3765 gdb_assert (cu->dwo_unit);
3766
3767 /* If TU skeletons have been removed then we may not have read in any
3768 TUs yet. */
3769 if (per_objfile->per_bfd->signatured_types == NULL)
3771
3772 /* We only ever need to read in one copy of a signatured type.
3773 Use the global signatured_types array to do our own comdat-folding
3774 of types. If this is the first time we're reading this TU, and
3775 the TU has an entry in .gdb_index, replace the recorded data from
3776 .gdb_index with this TU. */
3777
3778 signatured_type find_sig_entry (sig);
3779 slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (),
3780 &find_sig_entry, INSERT);
3781 signatured_type *sig_entry = (struct signatured_type *) *slot;
3782
3783 /* We can get here with the TU already read, *or* in the process of being
3784 read. Don't reassign the global entry to point to this DWO if that's
3785 the case. Also note that if the TU is already being read, it may not
3786 have come from a DWO, the program may be a mix of Fission-compiled
3787 code and non-Fission-compiled code. */
3788
3789 /* Have we already tried to read this TU?
3790 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
3791 needn't exist in the global table yet). */
3792 if (sig_entry != NULL && sig_entry->tu_read)
3793 return sig_entry;
3794
3795 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
3796 dwo_unit of the TU itself. */
3797 dwo_file = cu->dwo_unit->dwo_file;
3798
3799 /* Ok, this is the first time we're reading this TU. */
3800 if (dwo_file->tus == NULL)
3801 return NULL;
3802 find_dwo_entry.signature = sig;
3803 dwo_entry = (struct dwo_unit *) htab_find (dwo_file->tus.get (),
3804 &find_dwo_entry);
3805 if (dwo_entry == NULL)
3806 return NULL;
3807
3808 /* If the global table doesn't have an entry for this TU, add one. */
3809 if (sig_entry == NULL)
3810 sig_entry = add_type_unit (per_objfile, sig, slot);
3811
3812 if (sig_entry->dwo_unit == nullptr)
3813 fill_in_sig_entry_from_dwo_entry (per_objfile, sig_entry, dwo_entry);
3814 sig_entry->tu_read = 1;
3815 return sig_entry;
3816}
3817
3818/* Subroutine of lookup_signatured_type.
3819 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
3820 then try the DWP file. If the TU stub (skeleton) has been removed then
3821 it won't be in .gdb_index. */
3822
3823static struct signatured_type *
3824lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
3825{
3826 dwarf2_per_objfile *per_objfile = cu->per_objfile;
3827 struct dwp_file *dwp_file = get_dwp_file (per_objfile);
3828 struct dwo_unit *dwo_entry;
3829 void **slot;
3830
3831 gdb_assert (cu->dwo_unit);
3832 gdb_assert (dwp_file != NULL);
3833
3834 /* If TU skeletons have been removed then we may not have read in any
3835 TUs yet. */
3836 if (per_objfile->per_bfd->signatured_types == NULL)
3838
3839 signatured_type find_sig_entry (sig);
3840 slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (),
3841 &find_sig_entry, INSERT);
3842 signatured_type *sig_entry = (struct signatured_type *) *slot;
3843
3844 /* Have we already tried to read this TU?
3845 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
3846 needn't exist in the global table yet). */
3847 if (sig_entry != NULL)
3848 return sig_entry;
3849
3850 if (dwp_file->tus == NULL)
3851 return NULL;
3852 dwo_entry = lookup_dwo_unit_in_dwp (per_objfile, dwp_file, NULL, sig,
3853 1 /* is_debug_types */);
3854 if (dwo_entry == NULL)
3855 return NULL;
3856
3857 sig_entry = add_type_unit (per_objfile, sig, slot);
3858 fill_in_sig_entry_from_dwo_entry (per_objfile, sig_entry, dwo_entry);
3859
3860 return sig_entry;
3861}
3862
3863/* Lookup a signature based type for DW_FORM_ref_sig8.
3864 Returns NULL if signature SIG is not present in the table.
3865 It is up to the caller to complain about this. */
3866
3867static struct signatured_type *
3868lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
3869{
3870 dwarf2_per_objfile *per_objfile = cu->per_objfile;
3871
3872 if (cu->dwo_unit)
3873 {
3874 /* We're in a DWO/DWP file, and we're using .gdb_index.
3875 These cases require special processing. */
3876 if (get_dwp_file (per_objfile) == NULL)
3877 return lookup_dwo_signatured_type (cu, sig);
3878 else
3879 return lookup_dwp_signatured_type (cu, sig);
3880 }
3881 else
3882 {
3883 if (per_objfile->per_bfd->signatured_types == NULL)
3884 return NULL;
3885 signatured_type find_entry (sig);
3886 return ((struct signatured_type *)
3887 htab_find (per_objfile->per_bfd->signatured_types.get (),
3888 &find_entry));
3889 }
3890}
3891
3892/* Low level DIE reading support. */
3893
3894/* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3895
3896static void
3898 struct dwarf2_cu *cu,
3900 struct dwo_file *dwo_file,
3901 struct abbrev_table *abbrev_table)
3902{
3903 gdb_assert (section->readin && section->buffer != NULL);
3904 reader->abfd = section->get_bfd_owner ();
3905 reader->cu = cu;
3906 reader->dwo_file = dwo_file;
3907 reader->die_section = section;
3908 reader->buffer = section->buffer;
3909 reader->buffer_end = section->buffer + section->size;
3910 reader->abbrev_table = abbrev_table;
3911}
3912
3913/* Subroutine of cutu_reader to simplify it.
3914 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
3915 There's just a lot of work to do, and cutu_reader is big enough
3916 already.
3917
3918 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
3919 from it to the DIE in the DWO. If NULL we are skipping the stub.
3920 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
3921 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
3922 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
3923 STUB_COMP_DIR may be non-NULL.
3924 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
3925 are filled in with the info of the DIE from the DWO file.
3926 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
3927 from the dwo. Since *RESULT_READER references this abbrev table, it must be
3928 kept around for at least as long as *RESULT_READER.
3929
3930 The result is non-zero if a valid (non-dummy) DIE was found. */
3931
3932static int
3934 struct dwo_unit *dwo_unit,
3935 struct die_info *stub_comp_unit_die,
3936 const char *stub_comp_dir,
3937 struct die_reader_specs *result_reader,
3938 const gdb_byte **result_info_ptr,
3939 struct die_info **result_comp_unit_die,
3940 abbrev_table_up *result_dwo_abbrev_table)
3941{
3942 dwarf2_per_objfile *per_objfile = cu->per_objfile;
3943 dwarf2_per_cu_data *per_cu = cu->per_cu;
3944 struct objfile *objfile = per_objfile->objfile;
3945 bfd *abfd;
3946 const gdb_byte *begin_info_ptr, *info_ptr;
3947 struct dwarf2_section_info *dwo_abbrev_section;
3948
3949 /* At most one of these may be provided. */
3950 gdb_assert ((stub_comp_unit_die != NULL) + (stub_comp_dir != NULL) <= 1);
3951
3952 /* These attributes aren't processed until later: DW_AT_stmt_list,
3953 DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_comp_dir.
3954 However, these attributes are found in the stub which we won't
3955 have later. In order to not impose this complication on the rest
3956 of the code, we read them here and copy them to the DWO CU/TU
3957 die. */
3958
3959 /* We store them all in an array. */
3960 struct attribute *attributes[5] {};
3961 /* Next available element of the attributes array. */
3962 int next_attr_idx = 0;
3963
3964 /* Push an element into ATTRIBUTES. */
3965 auto push_back = [&] (struct attribute *attr)
3966 {
3967 gdb_assert (next_attr_idx < ARRAY_SIZE (attributes));
3968 if (attr != nullptr)
3969 attributes[next_attr_idx++] = attr;
3970 };
3971
3972 if (stub_comp_unit_die != NULL)
3973 {
3974 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3975 DWO file. */
3976 if (!per_cu->is_debug_types)
3977 push_back (dwarf2_attr (stub_comp_unit_die, DW_AT_stmt_list, cu));
3978 push_back (dwarf2_attr (stub_comp_unit_die, DW_AT_low_pc, cu));
3979 push_back (dwarf2_attr (stub_comp_unit_die, DW_AT_high_pc, cu));
3980 push_back (dwarf2_attr (stub_comp_unit_die, DW_AT_ranges, cu));
3981 push_back (dwarf2_attr (stub_comp_unit_die, DW_AT_comp_dir, cu));
3982
3983 cu->addr_base = stub_comp_unit_die->addr_base ();
3984
3985 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
3986 We need the value before we can process DW_AT_ranges values from the
3987 DWO. */
3988 cu->gnu_ranges_base = stub_comp_unit_die->gnu_ranges_base ();
3989
3990 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
3991 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
3992 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
3993 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
3994 section. */
3995 cu->rnglists_base = stub_comp_unit_die->rnglists_base ();
3996 }
3997 else if (stub_comp_dir != NULL)
3998 {
3999 /* Reconstruct the comp_dir attribute to simplify the code below. */
4000 struct attribute *comp_dir = OBSTACK_ZALLOC (&cu->comp_unit_obstack,
4001 struct attribute);
4002 comp_dir->name = DW_AT_comp_dir;
4003 comp_dir->form = DW_FORM_string;
4004 comp_dir->set_string_noncanonical (stub_comp_dir);
4005 push_back (comp_dir);
4006 }
4007
4008 /* Set up for reading the DWO CU/TU. */
4009 cu->dwo_unit = dwo_unit;
4011 section->read (objfile);
4012 abfd = section->get_bfd_owner ();
4013 begin_info_ptr = info_ptr = (section->buffer
4014 + to_underlying (dwo_unit->sect_off));
4015 dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev;
4016
4017 if (per_cu->is_debug_types)
4018 {
4019 signatured_type *sig_type = (struct signatured_type *) per_cu;
4020
4021 info_ptr = read_and_check_comp_unit_head (per_objfile, &cu->header,
4022 section, dwo_abbrev_section,
4023 info_ptr, rcuh_kind::TYPE);
4024 /* This is not an assert because it can be caused by bad debug info. */
4025 if (sig_type->signature != cu->header.signature)
4026 {
4027 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
4028 " TU at offset %s [in module %s]"),
4029 hex_string (sig_type->signature),
4030 hex_string (cu->header.signature),
4032 bfd_get_filename (abfd));
4033 }
4034 gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
4035 /* For DWOs coming from DWP files, we don't know the CU length
4036 nor the type's offset in the TU until now. */
4039
4040 /* Establish the type offset that can be used to lookup the type.
4041 For DWO files, we don't know it until now. */
4042 sig_type->type_offset_in_section
4043 = dwo_unit->sect_off + to_underlying (dwo_unit->type_offset_in_tu);
4044 }
4045 else
4046 {
4047 info_ptr = read_and_check_comp_unit_head (per_objfile, &cu->header,
4048 section, dwo_abbrev_section,
4049 info_ptr, rcuh_kind::COMPILE);
4050 gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
4051 /* For DWOs coming from DWP files, we don't know the CU length
4052 until now. */
4054 }
4055
4056 dwo_abbrev_section->read (objfile);
4057 *result_dwo_abbrev_table
4058 = abbrev_table::read (dwo_abbrev_section, cu->header.abbrev_sect_off);
4059 init_cu_die_reader (result_reader, cu, section, dwo_unit->dwo_file,
4060 result_dwo_abbrev_table->get ());
4061
4062 /* Read in the die, filling in the attributes from the stub. This
4063 has the benefit of simplifying the rest of the code - all the
4064 work to maintain the illusion of a single
4065 DW_TAG_{compile,type}_unit DIE is done here. */
4066 info_ptr = read_toplevel_die (result_reader, result_comp_unit_die, info_ptr,
4067 gdb::make_array_view (attributes,
4068 next_attr_idx));
4069
4070 /* Skip dummy compilation units. */
4071 if (info_ptr >= begin_info_ptr + dwo_unit->length
4072 || peek_abbrev_code (abfd, info_ptr) == 0)
4073 return 0;
4074
4075 *result_info_ptr = info_ptr;
4076 return 1;
4077}
4078
4079/* Return the signature of the compile unit, if found. In DWARF 4 and before,
4080 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
4081 signature is part of the header. */
4082static gdb::optional<ULONGEST>
4083lookup_dwo_id (struct dwarf2_cu *cu, struct die_info* comp_unit_die)
4084{
4085 if (cu->header.version >= 5)
4086 return cu->header.signature;
4087 struct attribute *attr;
4088 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
4089 if (attr == nullptr || !attr->form_is_unsigned ())
4090 return gdb::optional<ULONGEST> ();
4091 return attr->as_unsigned ();
4092}
4093
4094/* Subroutine of cutu_reader to simplify it.
4095 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
4096 Returns NULL if the specified DWO unit cannot be found. */
4097
4098static struct dwo_unit *
4099lookup_dwo_unit (dwarf2_cu *cu, die_info *comp_unit_die, const char *dwo_name)
4100{
4101#if CXX_STD_THREAD
4102 /* We need a lock here both to handle the DWO hash table, and BFD,
4103 which is not thread-safe. */
4104 static std::mutex dwo_lock;
4105
4106 std::lock_guard<std::mutex> guard (dwo_lock);
4107#endif
4108
4109 dwarf2_per_cu_data *per_cu = cu->per_cu;
4110 struct dwo_unit *dwo_unit;
4111 const char *comp_dir;
4112
4113 gdb_assert (cu != NULL);
4114
4115 /* Yeah, we look dwo_name up again, but it simplifies the code. */
4116 dwo_name = dwarf2_dwo_name (comp_unit_die, cu);
4117 comp_dir = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu);
4118
4119 if (per_cu->is_debug_types)
4120 dwo_unit = lookup_dwo_type_unit (cu, dwo_name, comp_dir);
4121 else
4122 {
4123 gdb::optional<ULONGEST> signature = lookup_dwo_id (cu, comp_unit_die);
4124
4125 if (!signature.has_value ())
4126 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
4127 " [in module %s]"),
4128 dwo_name, bfd_get_filename (per_cu->per_bfd->obfd));
4129
4130 dwo_unit = lookup_dwo_comp_unit (cu, dwo_name, comp_dir, *signature);
4131 }
4132
4133 return dwo_unit;
4134}
4135
4136/* Subroutine of cutu_reader to simplify it.
4137 See it for a description of the parameters.
4138 Read a TU directly from a DWO file, bypassing the stub. */
4139
4140void
4142 dwarf2_per_objfile *per_objfile,
4143 dwarf2_cu *existing_cu)
4144{
4145 struct signatured_type *sig_type;
4146
4147 /* Verify we can do the following downcast, and that we have the
4148 data we need. */
4149 gdb_assert (this_cu->is_debug_types && this_cu->reading_dwo_directly);
4150 sig_type = (struct signatured_type *) this_cu;
4151 gdb_assert (sig_type->dwo_unit != NULL);
4152
4153 dwarf2_cu *cu;
4154
4155 if (existing_cu != nullptr)
4156 {
4157 cu = existing_cu;
4158 gdb_assert (cu->dwo_unit == sig_type->dwo_unit);
4159 /* There's no need to do the rereading_dwo_cu handling that
4160 cutu_reader does since we don't read the stub. */
4161 }
4162 else
4163 {
4164 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
4165 in per_objfile yet. */
4166 gdb_assert (per_objfile->get_cu (this_cu) == nullptr);
4167 m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile));
4168 cu = m_new_cu.get ();
4169 }
4170
4171 /* A future optimization, if needed, would be to use an existing
4172 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
4173 could share abbrev tables. */
4174
4175 if (read_cutu_die_from_dwo (cu, sig_type->dwo_unit,
4176 NULL /* stub_comp_unit_die */,
4177 sig_type->dwo_unit->dwo_file->comp_dir,
4178 this, &info_ptr,
4180 &m_dwo_abbrev_table) == 0)
4181 {
4182 /* Dummy die. */
4183 dummy_p = true;
4184 }
4185}
4186
4187/* Initialize a CU (or TU) and read its DIEs.
4188 If the CU defers to a DWO file, read the DWO file as well.
4189
4190 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4191 Otherwise the table specified in the comp unit header is read in and used.
4192 This is an optimization for when we already have the abbrev table.
4193
4194 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
4195 allocated. */
4196
4198 dwarf2_per_objfile *per_objfile,
4199 struct abbrev_table *abbrev_table,
4200 dwarf2_cu *existing_cu,
4201 bool skip_partial,
4202 abbrev_cache *cache)
4203 : die_reader_specs {},
4204 m_this_cu (this_cu)
4205{
4206 struct objfile *objfile = per_objfile->objfile;
4207 struct dwarf2_section_info *section = this_cu->section;
4208 bfd *abfd = section->get_bfd_owner ();
4209 const gdb_byte *begin_info_ptr;
4210 struct signatured_type *sig_type = NULL;
4211 struct dwarf2_section_info *abbrev_section;
4212 /* Non-zero if CU currently points to a DWO file and we need to
4213 reread it. When this happens we need to reread the skeleton die
4214 before we can reread the DWO file (this only applies to CUs, not TUs). */
4215 int rereading_dwo_cu = 0;
4216
4217 if (dwarf_die_debug)
4218 gdb_printf (gdb_stdlog, "Reading %s unit at offset %s\n",
4219 this_cu->is_debug_types ? "type" : "comp",
4220 sect_offset_str (this_cu->sect_off));
4221
4222 /* If we're reading a TU directly from a DWO file, including a virtual DWO
4223 file (instead of going through the stub), short-circuit all of this. */
4224 if (this_cu->reading_dwo_directly)
4225 {
4226 /* Narrow down the scope of possibilities to have to understand. */
4227 gdb_assert (this_cu->is_debug_types);
4228 gdb_assert (abbrev_table == NULL);
4229 init_tu_and_read_dwo_dies (this_cu, per_objfile, existing_cu);
4230 return;
4231 }
4232
4233 /* This is cheap if the section is already read in. */
4234 section->read (objfile);
4235
4236 begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off);
4237
4238 abbrev_section = get_abbrev_section_for_cu (this_cu);
4239
4240 dwarf2_cu *cu;
4241
4242 if (existing_cu != nullptr)
4243 {
4244 cu = existing_cu;
4245 /* If this CU is from a DWO file we need to start over, we need to
4246 refetch the attributes from the skeleton CU.
4247 This could be optimized by retrieving those attributes from when we
4248 were here the first time: the previous comp_unit_die was stored in
4249 comp_unit_obstack. But there's no data yet that we need this
4250 optimization. */
4251 if (cu->dwo_unit != NULL)
4252 rereading_dwo_cu = 1;
4253 }
4254 else
4255 {
4256 /* If an existing_cu is provided, a dwarf2_cu must not exist for
4257 this_cu in per_objfile yet. Here, CACHE doubles as a flag to
4258 let us know that the CU is being scanned using the parallel
4259 indexer. This assert is avoided in this case because (1) it
4260 is irrelevant, and (2) the get_cu method is not
4261 thread-safe. */
4262 gdb_assert (cache != nullptr
4263 || per_objfile->get_cu (this_cu) == nullptr);
4264 m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile));
4265 cu = m_new_cu.get ();
4266 }
4267
4268 /* Get the header. */
4269 if (to_underlying (cu->header.first_die_cu_offset) != 0 && !rereading_dwo_cu)
4270 {
4271 /* We already have the header, there's no need to read it in again. */
4272 info_ptr += to_underlying (cu->header.first_die_cu_offset);
4273 }
4274 else
4275 {
4276 if (this_cu->is_debug_types)
4277 {
4279 section, abbrev_section,
4281
4282 /* Since per_cu is the first member of struct signatured_type,
4283 we can go from a pointer to one to a pointer to the other. */
4284 sig_type = (struct signatured_type *) this_cu;
4285 gdb_assert (sig_type->signature == cu->header.signature);
4286 gdb_assert (sig_type->type_offset_in_tu
4288 gdb_assert (this_cu->sect_off == cu->header.sect_off);
4289
4290 /* LENGTH has not been set yet for type units if we're
4291 using .gdb_index. */
4293
4294 /* Establish the type offset that can be used to lookup the type. */
4295 sig_type->type_offset_in_section =
4296 this_cu->sect_off + to_underlying (sig_type->type_offset_in_tu);
4297
4298 this_cu->set_version (cu->header.version);
4299 }
4300 else
4301 {
4303 section, abbrev_section,
4304 info_ptr,
4306
4307 gdb_assert (this_cu->sect_off == cu->header.sect_off);
4309 this_cu->set_version (cu->header.version);
4310 }
4311 }
4312
4313 /* Skip dummy compilation units. */
4314 if (info_ptr >= begin_info_ptr + this_cu->length ()
4315 || peek_abbrev_code (abfd, info_ptr) == 0)
4316 {
4317 dummy_p = true;
4318 return;
4319 }
4320
4321 /* If we don't have them yet, read the abbrevs for this compilation unit.
4322 And if we need to read them now, make sure they're freed when we're
4323 done. */
4324 if (abbrev_table != NULL)
4325 gdb_assert (cu->header.abbrev_sect_off == abbrev_table->sect_off);
4326 else
4327 {
4328 if (cache != nullptr)
4329 abbrev_table = cache->find (abbrev_section,
4331 if (abbrev_table == nullptr)
4332 {
4333 abbrev_section->read (objfile);
4335 = abbrev_table::read (abbrev_section, cu->header.abbrev_sect_off);
4337 }
4338 }
4339
4340 /* Read the top level CU/TU die. */
4341 init_cu_die_reader (this, cu, section, NULL, abbrev_table);
4343
4344 if (skip_partial && comp_unit_die->tag == DW_TAG_partial_unit)
4345 {
4346 dummy_p = true;
4347 return;
4348 }
4349
4350 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
4351 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
4352 table from the DWO file and pass the ownership over to us. It will be
4353 referenced from READER, so we must make sure to free it after we're done
4354 with READER.
4355
4356 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
4357 DWO CU, that this test will fail (the attribute will not be present). */
4358 const char *dwo_name = dwarf2_dwo_name (comp_unit_die, cu);
4359 if (dwo_name != nullptr)
4360 {
4361 struct dwo_unit *dwo_unit;
4362 struct die_info *dwo_comp_unit_die;
4363
4365 {
4366 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
4367 " has children (offset %s) [in module %s]"),
4368 sect_offset_str (this_cu->sect_off),
4369 bfd_get_filename (abfd));
4370 }
4372 if (dwo_unit != NULL)
4373 {
4375 comp_unit_die, NULL,
4376 this, &info_ptr,
4377 &dwo_comp_unit_die,
4378 &m_dwo_abbrev_table) == 0)
4379 {
4380 /* Dummy die. */
4381 dummy_p = true;
4382 return;
4383 }
4384 comp_unit_die = dwo_comp_unit_die;
4385 }
4386 else
4387 {
4388 /* Yikes, we couldn't find the rest of the DIE, we only have
4389 the stub. A complaint has already been logged. There's
4390 not much more we can do except pass on the stub DIE to
4391 die_reader_func. We don't want to throw an error on bad
4392 debug info. */
4393 }
4394 }
4395}
4396
4397void
4399{
4400 /* Done, clean up. */
4401 gdb_assert (!dummy_p);
4402 if (m_new_cu != NULL)
4403 {
4404 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
4405 now. */
4406 dwarf2_per_objfile *per_objfile = m_new_cu->per_objfile;
4407 per_objfile->set_cu (m_this_cu, std::move (m_new_cu));
4408 }
4409}
4410
4411/* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
4412 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
4413 assumed to have already done the lookup to find the DWO file).
4414
4415 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4416 THIS_CU->is_debug_types, but nothing else.
4417
4418 We fill in THIS_CU->length.
4419
4420 THIS_CU->cu is always freed when done.
4421 This is done in order to not leave THIS_CU->cu in a state where we have
4422 to care whether it refers to the "main" CU or the DWO CU.
4423
4424 When parent_cu is passed, it is used to provide a default value for
4425 str_offsets_base and addr_base from the parent. */
4426
4428 dwarf2_per_objfile *per_objfile,
4429 struct dwarf2_cu *parent_cu,
4430 struct dwo_file *dwo_file)
4431 : die_reader_specs {},
4432 m_this_cu (this_cu)
4433{
4434 struct objfile *objfile = per_objfile->objfile;
4435 struct dwarf2_section_info *section = this_cu->section;
4436 bfd *abfd = section->get_bfd_owner ();
4437 struct dwarf2_section_info *abbrev_section;
4438 const gdb_byte *begin_info_ptr, *info_ptr;
4439
4440 if (dwarf_die_debug)
4441 gdb_printf (gdb_stdlog, "Reading %s unit at offset %s\n",
4442 this_cu->is_debug_types ? "type" : "comp",
4443 sect_offset_str (this_cu->sect_off));
4444
4445 gdb_assert (per_objfile->get_cu (this_cu) == nullptr);
4446
4447 abbrev_section = (dwo_file != NULL
4448 ? &dwo_file->sections.abbrev
4449 : get_abbrev_section_for_cu (this_cu));
4450
4451 /* This is cheap if the section is already read in. */
4452 section->read (objfile);
4453
4454 m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile));
4455
4456 begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off);
4457 info_ptr = read_and_check_comp_unit_head (per_objfile, &m_new_cu->header,
4458 section, abbrev_section, info_ptr,
4459 (this_cu->is_debug_types
4462
4463 if (parent_cu != nullptr)
4464 {
4465 m_new_cu->str_offsets_base = parent_cu->str_offsets_base;
4466 m_new_cu->addr_base = parent_cu->addr_base;
4467 }
4468 this_cu->set_length (m_new_cu->header.get_length_with_initial ());
4469
4470 /* Skip dummy compilation units. */
4471 if (info_ptr >= begin_info_ptr + this_cu->length ()
4472 || peek_abbrev_code (abfd, info_ptr) == 0)
4473 {
4474 dummy_p = true;
4475 return;
4476 }
4477
4478 abbrev_section->read (objfile);
4480 = abbrev_table::read (abbrev_section, m_new_cu->header.abbrev_sect_off);
4481
4482 init_cu_die_reader (this, m_new_cu.get (), section, dwo_file,
4483 m_abbrev_table_holder.get ());
4485}
4486
4487
4488/* Type Unit Groups.
4489
4490 Type Unit Groups are a way to collapse the set of all TUs (type units) into
4491 a more manageable set. The grouping is done by DW_AT_stmt_list entry
4492 so that all types coming from the same compilation (.o file) are grouped
4493 together. A future step could be to put the types in the same symtab as
4494 the CU the types ultimately came from. */
4495
4496static hashval_t
4497hash_type_unit_group (const void *item)
4498{
4499 const struct type_unit_group *tu_group
4500 = (const struct type_unit_group *) item;
4501
4502 return hash_stmt_list_entry (&tu_group->hash);
4503}
4504
4505static int
4506eq_type_unit_group (const void *item_lhs, const void *item_rhs)
4507{
4508 const struct type_unit_group *lhs = (const struct type_unit_group *) item_lhs;
4509 const struct type_unit_group *rhs = (const struct type_unit_group *) item_rhs;
4510
4511 return eq_stmt_list_entry (&lhs->hash, &rhs->hash);
4512}
4513
4514/* Allocate a hash table for type unit groups. */
4515
4516static htab_up
4518{
4519 return htab_up (htab_create_alloc (3,
4522 htab_delete_entry<type_unit_group>,
4523 xcalloc, xfree));
4524}
4525
4526/* Type units that don't have DW_AT_stmt_list are grouped into their own
4527 partial symtabs. We combine several TUs per psymtab to not let the size
4528 of any one psymtab grow too big. */
4529#define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4530#define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4531
4532/* Helper routine for get_type_unit_group.
4533 Create the type_unit_group object used to hold one or more TUs. */
4534
4535static std::unique_ptr<type_unit_group>
4536create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
4537{
4538 auto tu_group = gdb::make_unique<type_unit_group> ();
4539
4540 tu_group->hash.dwo_unit = cu->dwo_unit;
4541 tu_group->hash.line_sect_off = line_offset_struct;
4542
4543 return tu_group;
4544}
4545
4546/* Look up the type_unit_group for type unit CU, and create it if necessary.
4547 STMT_LIST is a DW_AT_stmt_list attribute. */
4548
4549static struct type_unit_group *
4550get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list)
4551{
4552 dwarf2_per_objfile *per_objfile = cu->per_objfile;
4553 struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats;
4554 struct type_unit_group *tu_group;
4555 void **slot;
4556 unsigned int line_offset;
4557 struct type_unit_group type_unit_group_for_lookup;
4558
4559 if (per_objfile->per_bfd->type_unit_groups == NULL)
4561
4562 /* Do we need to create a new group, or can we use an existing one? */
4563
4564 if (stmt_list != nullptr && stmt_list->form_is_unsigned ())
4565 {
4566 line_offset = stmt_list->as_unsigned ();
4568 }
4569 else
4570 {
4571 /* Ugh, no stmt_list. Rare, but we have to handle it.
4572 We can do various things here like create one group per TU or
4573 spread them over multiple groups to split up the expansion work.
4574 To avoid worst case scenarios (too many groups or too large groups)
4575 we, umm, group them in bunches. */
4580 }
4581
4582 type_unit_group_for_lookup.hash.dwo_unit = cu->dwo_unit;
4583 type_unit_group_for_lookup.hash.line_sect_off = (sect_offset) line_offset;
4584 slot = htab_find_slot (per_objfile->per_bfd->type_unit_groups.get (),
4585 &type_unit_group_for_lookup, INSERT);
4586 if (*slot == nullptr)
4587 {
4588 sect_offset line_offset_struct = (sect_offset) line_offset;
4589 std::unique_ptr<type_unit_group> grp
4590 = create_type_unit_group (cu, line_offset_struct);
4591 *slot = grp.release ();
4593 }
4594
4595 tu_group = (struct type_unit_group *) *slot;
4596 gdb_assert (tu_group != nullptr);
4597 return tu_group;
4598}
4599
4600
4601/* An instance of this is created when scanning DWARF to create a
4602 cooked index. */
4603
4605{
4606public:
4607
4609 : m_reader_hash (htab_create_alloc (10, hash_cutu_reader,
4611 htab_delete_entry<cutu_reader>,
4612 xcalloc, xfree)),
4614 {
4615 }
4616
4618
4619 /* Return the current abbrev cache. */
4621 {
4622 return &m_abbrev_cache;
4623 }
4624
4625 /* Return the DIE reader corresponding to PER_CU. If no such reader
4626 has been registered, return NULL. */
4628 {
4629 int index = per_cu->index;
4630 return (cutu_reader *) htab_find_with_hash (m_reader_hash.get (),
4631 &index, index);
4632 }
4633
4634 /* Preserve READER by storing it in the local hash table. */
4635 cutu_reader *preserve (std::unique_ptr<cutu_reader> reader)
4636 {
4637 m_abbrev_cache.add (reader->release_abbrev_table ());
4638
4639 int index = reader->cu->per_cu->index;
4640 void **slot = htab_find_slot_with_hash (m_reader_hash.get (), &index,
4641 index, INSERT);
4642 gdb_assert (*slot == nullptr);
4643 cutu_reader *result = reader.get ();
4644 *slot = reader.release ();
4645 return result;
4646 }
4647
4648 /* Add an entry to the index. The arguments describe the entry; see
4649 cooked-index.h. The new entry is returned. */
4650 const cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag,
4651 cooked_index_flag flags,
4652 const char *name,
4653 const cooked_index_entry *parent_entry,
4654 dwarf2_per_cu_data *per_cu)
4655 {
4656 return m_index->add (die_offset, tag, flags, name, parent_entry, per_cu);
4657 }
4658
4659 /* Install the current addrmap into the index shard being constructed,
4660 then transfer ownership of the index to the caller. */
4661 std::unique_ptr<cooked_index_shard> release ()
4662 {
4663 m_index->install_addrmap (&m_addrmap);
4664 return std::move (m_index);
4665 }
4666
4667 /* Return the mutable addrmap that is currently being created. */
4669 {
4670 return &m_addrmap;
4671 }
4672
4673private:
4674
4675 /* Hash function for a cutu_reader. */
4676 static hashval_t hash_cutu_reader (const void *a)
4677 {
4678 const cutu_reader *reader = (const cutu_reader *) a;
4679 return reader->cu->per_cu->index;
4680 }
4681
4682 /* Equality function for cutu_reader. */
4683 static int eq_cutu_reader (const void *a, const void *b)
4684 {
4685 const cutu_reader *ra = (const cutu_reader *) a;
4686 const int *rb = (const int *) b;
4687 return ra->cu->per_cu->index == *rb;
4688 }
4689
4690 /* The abbrev cache used by this indexer. */
4692 /* A hash table of cutu_reader objects. */
4694 /* The index shard that is being constructed. */
4695 std::unique_ptr<cooked_index_shard> m_index;
4696
4697 /* A writeable addrmap being constructed by this scanner. */
4699};
4700
4701/* An instance of this is created to index a CU. */
4702
4704{
4705public:
4706
4708 dwarf2_per_cu_data *per_cu,
4709 enum language language)
4710 : m_index_storage (storage),
4711 m_per_cu (per_cu),
4713 {
4714 }
4715
4717
4718 /* Index the given CU. */
4719 void make_index (cutu_reader *reader);
4720
4721private:
4722
4723 /* A helper function to turn a section offset into an address that
4724 can be used in an addrmap. */
4725 CORE_ADDR form_addr (sect_offset offset, bool is_dwz)
4726 {
4727 CORE_ADDR value = to_underlying (offset);
4728 if (is_dwz)
4729 value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1);
4730 return value;
4731 }
4732
4733 /* A helper function to scan the PC bounds of READER and record them
4734 in the storage's addrmap. */
4735 void check_bounds (cutu_reader *reader);
4736
4737 /* Ensure that the indicated CU exists. The cutu_reader for it is
4738 returned. FOR_SCANNING is true if the caller intends to scan all
4739 the DIEs in the CU; when false, this use is assumed to be to look
4740 up just a single DIE. */
4742 dwarf2_per_objfile *per_objfile,
4743 sect_offset sect_off,
4744 bool is_dwz,
4745 bool for_scanning);
4746
4747 /* Index DIEs in the READER starting at INFO_PTR. PARENT_ENTRY is
4748 the entry for the enclosing scope (nullptr at top level). FULLY
4749 is true when a full scan must be done -- in some languages,
4750 function scopes must be fully explored in order to find nested
4751 functions. This returns a pointer to just after the spot where
4752 reading stopped. */
4753 const gdb_byte *index_dies (cutu_reader *reader,
4754 const gdb_byte *info_ptr,
4755 const cooked_index_entry *parent_entry,
4756 bool fully);
4757
4758 /* Scan the attributes for a given DIE and update the out
4759 parameters. Returns a pointer to the byte after the DIE. */
4760 const gdb_byte *scan_attributes (dwarf2_per_cu_data *scanning_per_cu,
4761 cutu_reader *reader,
4762 const gdb_byte *watermark_ptr,
4763 const gdb_byte *info_ptr,
4764 const abbrev_info *abbrev,
4765 const char **name,
4766 const char **linkage_name,
4767 cooked_index_flag *flags,
4768 sect_offset *sibling_offset,
4769 const cooked_index_entry **parent_entry,
4770 CORE_ADDR *maybe_defer,
4771 bool for_specification);
4772
4773 /* Handle DW_TAG_imported_unit, by scanning the DIE to find
4774 DW_AT_import, and then scanning the referenced CU. Returns a
4775 pointer to the byte after the DIE. */
4776 const gdb_byte *index_imported_unit (cutu_reader *reader,
4777 const gdb_byte *info_ptr,
4778 const abbrev_info *abbrev);
4779
4780 /* Recursively read DIEs, recording the section offsets in
4781 m_die_range_map and then calling index_dies. */
4782 const gdb_byte *recurse (cutu_reader *reader,
4783 const gdb_byte *info_ptr,
4784 const cooked_index_entry *parent_entry,
4785 bool fully);
4786
4787 /* The storage object, where the results are kept. */
4789 /* The CU that we are reading on behalf of. This object might be
4790 asked to index one CU but to treat the results as if they come
4791 from some including CU; in this case the including CU would be
4792 recorded here. */
4794 /* The language that we're assuming when reading. */
4796
4797 /* An addrmap that maps from section offsets (see the form_addr
4798 method) to newly-created entries. See m_deferred_entries to
4799 understand this. */
4801
4802 /* A single deferred entry. */
4804 {
4805 sect_offset die_offset;
4806 const char *name;
4807 CORE_ADDR spec_offset;
4808 dwarf_tag tag;
4809 cooked_index_flag flags;
4810 };
4811
4812 /* The generated DWARF can sometimes have the declaration for a
4813 method in a class (or perhaps namespace) scope, with the
4814 definition appearing outside this scope... just one of the many
4815 bad things about DWARF. In order to handle this situation, we
4816 defer certain entries until the end of scanning, at which point
4817 we'll know the containing context of all the DIEs that we might
4818 have scanned. This vector stores these deferred entries. */
4819 std::vector<deferred_entry> m_deferred_entries;
4820};
4821
4822/* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4823 Process compilation unit THIS_CU for a psymtab. */
4824
4825static void
4827 dwarf2_per_objfile *per_objfile,
4828 cooked_index_storage *storage)
4829{
4830 cutu_reader reader (this_cu, per_objfile, nullptr, nullptr, false,
4831 storage->get_abbrev_cache ());
4832
4833 if (reader.comp_unit_die == nullptr)
4834 return;
4835
4836 if (reader.dummy_p)
4837 {
4838 /* Nothing. */
4839 }
4840 else if (this_cu->is_debug_types)
4841 build_type_psymtabs_reader (&reader, storage);
4842 else if (reader.comp_unit_die->tag != DW_TAG_partial_unit)
4843 {
4844 bool nope = false;
4845 if (this_cu->scanned.compare_exchange_strong (nope, true))
4846 {
4847 prepare_one_comp_unit (reader.cu, reader.comp_unit_die,
4849 gdb_assert (storage != nullptr);
4850 cooked_indexer indexer (storage, this_cu, reader.cu->lang ());
4851 indexer.make_index (&reader);
4852 }
4853 }
4854}
4855
4856/* Reader function for build_type_psymtabs. */
4857
4858static void
4860 cooked_index_storage *storage)
4861{
4862 struct dwarf2_cu *cu = reader->cu;
4863 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
4864 struct die_info *type_unit_die = reader->comp_unit_die;
4865
4866 gdb_assert (per_cu->is_debug_types);
4867
4868 if (! type_unit_die->has_children)
4869 return;
4870
4871 prepare_one_comp_unit (cu, type_unit_die, language_minimal);
4872
4873 gdb_assert (storage != nullptr);
4874 cooked_indexer indexer (storage, per_cu, cu->lang ());
4875 indexer.make_index (reader);
4876}
4877
4878/* Struct used to sort TUs by their abbreviation table offset. */
4879
4881{
4882 tu_abbrev_offset (signatured_type *sig_type_, sect_offset abbrev_offset_)
4883 : sig_type (sig_type_), abbrev_offset (abbrev_offset_)
4884 {}
4885
4886 /* This is used when sorting. */
4887 bool operator< (const tu_abbrev_offset &other) const
4888 {
4889 return abbrev_offset < other.abbrev_offset;
4890 }
4891
4893 sect_offset abbrev_offset;
4894};
4895
4896/* Efficiently read all the type units.
4897
4898 The efficiency is because we sort TUs by the abbrev table they use and
4899 only read each abbrev table once. In one program there are 200K TUs
4900 sharing 8K abbrev tables.
4901
4902 The main purpose of this function is to support building the
4903 dwarf2_per_objfile->per_bfd->type_unit_groups table.
4904 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
4905 can collapse the search space by grouping them by stmt_list.
4906 The savings can be significant, in the same program from above the 200K TUs
4907 share 8K stmt_list tables.
4908
4909 FUNC is expected to call get_type_unit_group, which will create the
4910 struct type_unit_group if necessary and add it to
4911 dwarf2_per_objfile->per_bfd->type_unit_groups. */
4912
4913static void
4915 cooked_index_storage *storage)
4916{
4917 struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats;
4919 sect_offset abbrev_offset;
4920
4921 /* It's up to the caller to not call us multiple times. */
4922 gdb_assert (per_objfile->per_bfd->type_unit_groups == NULL);
4923
4924 if (per_objfile->per_bfd->all_type_units.size () == 0)
4925 return;
4926
4927 /* TUs typically share abbrev tables, and there can be way more TUs than
4928 abbrev tables. Sort by abbrev table to reduce the number of times we
4929 read each abbrev table in.
4930 Alternatives are to punt or to maintain a cache of abbrev tables.
4931 This is simpler and efficient enough for now.
4932
4933 Later we group TUs by their DW_AT_stmt_list value (as this defines the
4934 symtab to use). Typically TUs with the same abbrev offset have the same
4935 stmt_list value too so in practice this should work well.
4936
4937 The basic algorithm here is:
4938
4939 sort TUs by abbrev table
4940 for each TU with same abbrev table:
4941 read abbrev table if first user
4942 read TU top level DIE
4943 [IWBN if DWO skeletons had DW_AT_stmt_list]
4944 call FUNC */
4945
4946 dwarf_read_debug_printf ("Building type unit groups ...");
4947
4948 /* Sort in a separate table to maintain the order of all_units
4949 for .gdb_index: TU indices directly index all_type_units. */
4950 std::vector<tu_abbrev_offset> sorted_by_abbrev;
4951 sorted_by_abbrev.reserve (per_objfile->per_bfd->all_type_units.size ());
4952
4953 for (const auto &cu : per_objfile->per_bfd->all_units)
4954 {
4955 if (cu->is_debug_types)
4956 {
4957 auto sig_type = static_cast<signatured_type *> (cu.get ());
4958 sorted_by_abbrev.emplace_back
4959 (sig_type, read_abbrev_offset (per_objfile, sig_type->section,
4960 sig_type->sect_off));
4961 }
4962 }
4963
4964 std::sort (sorted_by_abbrev.begin (), sorted_by_abbrev.end ());
4965
4966 abbrev_offset = (sect_offset) ~(unsigned) 0;
4967
4968 for (const tu_abbrev_offset &tu : sorted_by_abbrev)
4969 {
4970 /* Switch to the next abbrev table if necessary. */
4971 if (abbrev_table == NULL
4972 || tu.abbrev_offset != abbrev_offset)
4973 {
4974 abbrev_offset = tu.abbrev_offset;
4975 per_objfile->per_bfd->abbrev.read (per_objfile->objfile);
4976 abbrev_table =
4977 abbrev_table::read (&per_objfile->per_bfd->abbrev, abbrev_offset);
4979 }
4980
4981 cutu_reader reader (tu.sig_type, per_objfile,
4982 abbrev_table.get (), nullptr, false);
4983 if (!reader.dummy_p)
4984 build_type_psymtabs_reader (&reader, storage);
4985 }
4986}
4987
4988/* Print collected type unit statistics. */
4989
4990static void
4992{
4993 struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats;
4994
4995 dwarf_read_debug_printf ("Type unit statistics:");
4997 dwarf_read_debug_printf (" %d uniq abbrev tables",
4999 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
5001 dwarf_read_debug_printf (" %d symtab sharers",
5003 dwarf_read_debug_printf (" %d type units without a stmt_list",
5005 dwarf_read_debug_printf (" %d all_type_units reallocs",
5007}
5008
5014
5015/* Traversal function for process_skeletonless_type_unit.
5016 Read a TU in a DWO file and build partial symbols for it. */
5017
5018static int
5019process_skeletonless_type_unit (void **slot, void *info)
5020{
5021 struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot;
5022 skeleton_data *data = (skeleton_data *) info;
5023
5024 /* If this TU doesn't exist in the global table, add it and read it in. */
5025
5026 if (data->per_objfile->per_bfd->signatured_types == NULL)
5027 data->per_objfile->per_bfd->signatured_types
5029
5030 signatured_type find_entry (dwo_unit->signature);
5031 slot = htab_find_slot (data->per_objfile->per_bfd->signatured_types.get (),
5032 &find_entry, INSERT);
5033 /* If we've already seen this type there's nothing to do. What's happening
5034 is we're doing our own version of comdat-folding here. */
5035 if (*slot != NULL)
5036 return 1;
5037
5038 /* This does the job that create_all_units would have done for
5039 this TU. */
5040 signatured_type *entry
5041 = add_type_unit (data->per_objfile, dwo_unit->signature, slot);
5042 fill_in_sig_entry_from_dwo_entry (data->per_objfile, entry, dwo_unit);
5043 *slot = entry;
5044
5045 /* This does the job that build_type_psymtabs would have done. */
5046 cutu_reader reader (entry, data->per_objfile, nullptr, nullptr, false);
5047 if (!reader.dummy_p)
5048 build_type_psymtabs_reader (&reader, data->storage);
5049
5050 return 1;
5051}
5052
5053/* Traversal function for process_skeletonless_type_units. */
5054
5055static int
5057{
5058 struct dwo_file *dwo_file = (struct dwo_file *) *slot;
5059
5060 if (dwo_file->tus != NULL)
5061 htab_traverse_noresize (dwo_file->tus.get (),
5063
5064 return 1;
5065}
5066
5067/* Scan all TUs of DWO files, verifying we've processed them.
5068 This is needed in case a TU was emitted without its skeleton.
5069 Note: This can't be done until we know what all the DWO files are. */
5070
5071static void
5073 cooked_index_storage *storage)
5074{
5075 skeleton_data data { per_objfile, storage };
5076
5077 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
5078 if (get_dwp_file (per_objfile) == NULL
5079 && per_objfile->per_bfd->dwo_files != NULL)
5080 {
5081 htab_traverse_noresize (per_objfile->per_bfd->dwo_files.get (),
5083 &data);
5084 }
5085}
5086
5087/* Build the partial symbol table by doing a quick pass through the
5088 .debug_info and .debug_abbrev sections. */
5089
5090static void
5092{
5093 struct objfile *objfile = per_objfile->objfile;
5094 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
5095
5096 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
5098
5099 per_bfd->map_info_sections (objfile);
5100
5101 cooked_index_storage index_storage;
5102 create_all_units (per_objfile);
5103 build_type_psymtabs (per_objfile, &index_storage);
5104 std::vector<std::unique_ptr<cooked_index_shard>> indexes;
5105
5106 per_bfd->quick_file_names_table
5107 = create_quick_file_names_table (per_bfd->all_units.size ());
5108 if (!per_bfd->debug_aranges.empty ())
5109 read_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges,
5110 index_storage.get_addrmap ());
5111
5112 {
5113 /* Ensure that complaints are handled correctly. */
5114 complaint_interceptor complaint_handler;
5115
5116 using iter_type = decltype (per_bfd->all_units.begin ());
5117
5118 auto task_size_ = [] (iter_type iter)
5119 {
5120 dwarf2_per_cu_data *per_cu = iter->get ();
5121 return (size_t)per_cu->length ();
5122 };
5123 auto task_size = gdb::make_function_view (task_size_);
5124
5125 /* Each thread returns a pair holding a cooked index, and a vector
5126 of errors that should be printed. The latter is done because
5127 GDB's I/O system is not thread-safe. run_on_main_thread could be
5128 used, but that would mean the messages are printed after the
5129 prompt, which looks weird. */
5130 using result_type = std::pair<std::unique_ptr<cooked_index_shard>,
5131 std::vector<gdb_exception>>;
5132 std::vector<result_type> results
5133 = gdb::parallel_for_each (1, per_bfd->all_units.begin (),
5134 per_bfd->all_units.end (),
5135 [=] (iter_type iter, iter_type end)
5136 {
5137 std::vector<gdb_exception> errors;
5138 cooked_index_storage thread_storage;
5139 for (; iter != end; ++iter)
5140 {
5141 dwarf2_per_cu_data *per_cu = iter->get ();
5142 try
5143 {
5144 process_psymtab_comp_unit (per_cu, per_objfile,
5145 &thread_storage);
5146 }
5147 catch (gdb_exception &except)
5148 {
5149 errors.push_back (std::move (except));
5150 }
5151 }
5152 return result_type (thread_storage.release (), std::move (errors));
5153 }, task_size);
5154
5155 /* Only show a given exception a single time. */
5156 std::unordered_set<gdb_exception> seen_exceptions;
5157 for (auto &one_result : results)
5158 {
5159 indexes.push_back (std::move (one_result.first));
5160 for (auto &one_exc : one_result.second)
5161 if (seen_exceptions.insert (one_exc).second)
5162 exception_print (gdb_stderr, one_exc);
5163 }
5164 }
5165
5166 /* This has to wait until we read the CUs, we need the list of DWOs. */
5167 process_skeletonless_type_units (per_objfile, &index_storage);
5168
5169 if (dwarf_read_debug > 0)
5170 print_tu_stats (per_objfile);
5171
5172 indexes.push_back (index_storage.release ());
5173 indexes.shrink_to_fit ();
5174
5175 cooked_index *vec = new cooked_index (std::move (indexes));
5176 per_bfd->index_table.reset (vec);
5177
5178 /* Cannot start writing the index entry until after the
5179 'index_table' member has been set. */
5181
5182 const cooked_index_entry *main_entry = vec->get_main ();
5183 if (main_entry != nullptr)
5184 {
5185 /* We only do this for names not requiring canonicalization. At
5186 this point in the process names have not been canonicalized.
5187 However, currently, languages that require this step also do
5188 not use DW_AT_main_subprogram. An assert is appropriate here
5189 because this filtering is done in get_main. */
5190 enum language lang = main_entry->per_cu->lang ();
5191 gdb_assert (!language_requires_canonicalization (lang));
5192 const char *full_name = main_entry->full_name (&per_bfd->obstack, true);
5193 set_objfile_main_name (objfile, full_name, lang);
5194 }
5195
5196 dwarf_read_debug_printf ("Done building psymtabs of %s",
5198}
5199
5200static void
5202 struct dwarf2_section_info *section,
5203 struct dwarf2_section_info *abbrev_section,
5204 unsigned int is_dwz,
5205 htab_up &types_htab,
5206 rcuh_kind section_kind)
5207{
5208 const gdb_byte *info_ptr;
5209 struct objfile *objfile = per_objfile->objfile;
5210
5211 dwarf_read_debug_printf ("Reading %s for %s",
5212 section->get_name (),
5213 section->get_file_name ());
5214
5215 section->read (objfile);
5216
5217 info_ptr = section->buffer;
5218
5219 while (info_ptr < section->buffer + section->size)
5220 {
5221 dwarf2_per_cu_data_up this_cu;
5222
5223 sect_offset sect_off = (sect_offset) (info_ptr - section->buffer);
5224
5225 comp_unit_head cu_header;
5226 read_and_check_comp_unit_head (per_objfile, &cu_header, section,
5227 abbrev_section, info_ptr,
5228 section_kind);
5229
5230 /* Save the compilation unit for later lookup. */
5231 if (cu_header.unit_type != DW_UT_type)
5232 this_cu = per_objfile->per_bfd->allocate_per_cu ();
5233 else
5234 {
5235 if (types_htab == nullptr)
5236 types_htab = allocate_signatured_type_table ();
5237
5238 auto sig_type = per_objfile->per_bfd->allocate_signatured_type
5239 (cu_header.signature);
5240 signatured_type *sig_ptr = sig_type.get ();
5241 sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
5242 this_cu.reset (sig_type.release ());
5243
5244 void **slot = htab_find_slot (types_htab.get (), sig_ptr, INSERT);
5245 gdb_assert (slot != nullptr);
5246 if (*slot != nullptr)
5247 complaint (_("debug type entry at offset %s is duplicate to"
5248 " the entry at offset %s, signature %s"),
5249 sect_offset_str (sect_off),
5250 sect_offset_str (sig_ptr->sect_off),
5251 hex_string (sig_ptr->signature));
5252 *slot = sig_ptr;
5253 }
5254 this_cu->sect_off = sect_off;
5255 this_cu->set_length (cu_header.get_length_with_initial ());
5256 this_cu->is_dwz = is_dwz;
5257 this_cu->section = section;
5258 /* Init this asap, to avoid a data race in the set_version in
5259 cutu_reader::cutu_reader (which may be run in parallel for the cooked
5260 index case). */
5261 this_cu->set_version (cu_header.version);
5262
5263 info_ptr = info_ptr + this_cu->length ();
5264 per_objfile->per_bfd->all_units.push_back (std::move (this_cu));
5265 }
5266}
5267
5268/* Initialize the views on all_units. */
5269
5270void
5272{
5273 size_t nr_tus = per_bfd->tu_stats.nr_tus;
5274 size_t nr_cus = per_bfd->all_units.size () - nr_tus;
5275 gdb::array_view<dwarf2_per_cu_data_up> tmp = per_bfd->all_units;
5276 per_bfd->all_comp_units = tmp.slice (0, nr_cus);
5277 per_bfd->all_type_units = tmp.slice (nr_cus, nr_tus);
5278}
5279
5280/* Create a list of all compilation units in OBJFILE.
5281 This is only done for -readnow and building partial symtabs. */
5282
5283static void
5285{
5286 htab_up types_htab;
5287 gdb_assert (per_objfile->per_bfd->all_units.empty ());
5288
5289 read_comp_units_from_section (per_objfile, &per_objfile->per_bfd->info,
5290 &per_objfile->per_bfd->abbrev, 0,
5291 types_htab, rcuh_kind::COMPILE);
5292 for (dwarf2_section_info &section : per_objfile->per_bfd->types)
5293 read_comp_units_from_section (per_objfile, &section,
5294 &per_objfile->per_bfd->abbrev, 0,
5295 types_htab, rcuh_kind::TYPE);
5296
5297 dwz_file *dwz;
5298 try
5299 {
5300 dwz = dwarf2_get_dwz_file (per_objfile->per_bfd);
5301 }
5302 catch (const gdb_exception_error &)
5303 {
5304 per_objfile->per_bfd->all_units.clear ();
5305 throw;
5306 }
5307 if (dwz != NULL)
5308 {
5309 /* Pre-read the sections we'll need to construct an index. */
5310 struct objfile *objfile = per_objfile->objfile;
5311 dwz->abbrev.read (objfile);
5312 dwz->info.read (objfile);
5313 dwz->str.read (objfile);
5314 dwz->line.read (objfile);
5315 read_comp_units_from_section (per_objfile, &dwz->info, &dwz->abbrev, 1,
5316 types_htab, rcuh_kind::COMPILE);
5317
5318 if (!dwz->types.empty ())
5319 {
5320 /* See enhancement PR symtab/30838. */
5321 error (_("Dwarf Error: .debug_types section not supported in dwz file"));
5322 }
5323 }
5324
5325 per_objfile->per_bfd->signatured_types = std::move (types_htab);
5326
5327 finalize_all_units (per_objfile->per_bfd);
5328}
5329
5330/* Return the initial uleb128 in the die at INFO_PTR. */
5331
5332static unsigned int
5333peek_abbrev_code (bfd *abfd, const gdb_byte *info_ptr)
5334{
5335 unsigned int bytes_read;
5336
5337 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5338}
5339
5340/* Read the initial uleb128 in the die at INFO_PTR in compilation unit
5341 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
5342
5343 Return the corresponding abbrev, or NULL if the number is zero (indicating
5344 an empty DIE). In either case *BYTES_READ will be set to the length of
5345 the initial number. */
5346
5347static const struct abbrev_info *
5349 const gdb_byte *info_ptr, unsigned int *bytes_read)
5350{
5351 dwarf2_cu *cu = reader.cu;
5352 bfd *abfd = reader.abfd;
5353 unsigned int abbrev_number
5354 = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
5355
5356 if (abbrev_number == 0)
5357 return NULL;
5358
5359 const abbrev_info *abbrev
5360 = reader.abbrev_table->lookup_abbrev (abbrev_number);
5361 if (!abbrev)
5362 {
5363 error (_("Dwarf Error: Could not find abbrev number %d in %s"
5364 " at offset %s [in module %s]"),
5365 abbrev_number, cu->per_cu->is_debug_types ? "TU" : "CU",
5366 sect_offset_str (cu->header.sect_off), bfd_get_filename (abfd));
5367 }
5368
5369 return abbrev;
5370}
5371
5372/* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5373 Returns a pointer to the end of a series of DIEs, terminated by an empty
5374 DIE. Any children of the skipped DIEs will also be skipped. */
5375
5376static const gdb_byte *
5377skip_children (const struct die_reader_specs *reader, const gdb_byte *info_ptr)
5378{
5379 while (1)
5380 {
5381 unsigned int bytes_read;
5382 const abbrev_info *abbrev = peek_die_abbrev (*reader, info_ptr,
5383 &bytes_read);
5384
5385 if (abbrev == NULL)
5386 return info_ptr + bytes_read;
5387 else
5388 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
5389 }
5390}
5391
5392/* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5393 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5394 abbrev corresponding to that skipped uleb128 should be passed in
5395 ABBREV.
5396
5397 If DO_SKIP_CHILDREN is true, or if the DIE has no children, this
5398 returns a pointer to this DIE's sibling, skipping any children.
5399 Otherwise, returns a pointer to the DIE's first child. */
5400
5401static const gdb_byte *
5402skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr,
5403 const struct abbrev_info *abbrev, bool do_skip_children)
5404{
5405 unsigned int bytes_read;
5406 struct attribute attr;
5407 bfd *abfd = reader->abfd;
5408 struct dwarf2_cu *cu = reader->cu;
5409 const gdb_byte *buffer = reader->buffer;
5410 const gdb_byte *buffer_end = reader->buffer_end;
5411 unsigned int form, i;
5412
5413 if (do_skip_children && abbrev->sibling_offset != (unsigned short) -1)
5414 {
5415 /* We only handle DW_FORM_ref4 here. */
5416 const gdb_byte *sibling_data = info_ptr + abbrev->sibling_offset;
5417 unsigned int offset = read_4_bytes (abfd, sibling_data);
5418 const gdb_byte *sibling_ptr
5419 = buffer + to_underlying (cu->header.sect_off) + offset;
5420 if (sibling_ptr >= info_ptr && sibling_ptr < reader->buffer_end)
5421 return sibling_ptr;
5422 /* Fall through to the slow way. */
5423 }
5424 else if (abbrev->size_if_constant != 0)
5425 {
5426 info_ptr += abbrev->size_if_constant;
5427 if (do_skip_children && abbrev->has_children)
5428 return skip_children (reader, info_ptr);
5429 return info_ptr;
5430 }
5431
5432 for (i = 0; i < abbrev->num_attrs; i++)
5433 {
5434 /* The only abbrev we care about is DW_AT_sibling. */
5435 if (do_skip_children && abbrev->attrs[i].name == DW_AT_sibling)
5436 {
5437 /* Note there is no need for the extra work of
5438 "reprocessing" here, so we pass false for that
5439 argument. */
5440 read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr, false);
5441 if (attr.form == DW_FORM_ref_addr)
5442 complaint (_("ignoring absolute DW_AT_sibling"));
5443 else
5444 {
5445 sect_offset off = attr.get_ref_die_offset ();
5446 const gdb_byte *sibling_ptr = buffer + to_underlying (off);
5447
5448 if (sibling_ptr < info_ptr)
5449 complaint (_("DW_AT_sibling points backwards"));
5450 else if (sibling_ptr > reader->buffer_end)
5451 reader->die_section->overflow_complaint ();
5452 else
5453 return sibling_ptr;
5454 }
5455 }
5456
5457 /* If it isn't DW_AT_sibling, skip this attribute. */
5458 form = abbrev->attrs[i].form;
5459 skip_attribute:
5460 switch (form)
5461 {
5462 case DW_FORM_ref_addr:
5463 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5464 and later it is offset sized. */
5465 if (cu->header.version == 2)
5466 info_ptr += cu->header.addr_size;
5467 else
5468 info_ptr += cu->header.offset_size;
5469 break;
5470 case DW_FORM_GNU_ref_alt:
5471 info_ptr += cu->header.offset_size;
5472 break;
5473 case DW_FORM_addr:
5474 info_ptr += cu->header.addr_size;
5475 break;
5476 case DW_FORM_data1:
5477 case DW_FORM_ref1:
5478 case DW_FORM_flag:
5479 case DW_FORM_strx1:
5480 info_ptr += 1;
5481 break;
5482 case DW_FORM_flag_present:
5483 case DW_FORM_implicit_const:
5484 break;
5485 case DW_FORM_data2:
5486 case DW_FORM_ref2:
5487 case DW_FORM_strx2:
5488 info_ptr += 2;
5489 break;
5490 case DW_FORM_strx3:
5491 info_ptr += 3;
5492 break;
5493 case DW_FORM_data4:
5494 case DW_FORM_ref4:
5495 case DW_FORM_strx4:
5496 info_ptr += 4;
5497 break;
5498 case DW_FORM_data8:
5499 case DW_FORM_ref8:
5500 case DW_FORM_ref_sig8:
5501 info_ptr += 8;
5502 break;
5503 case DW_FORM_data16:
5504 info_ptr += 16;
5505 break;
5506 case DW_FORM_string:
5507 read_direct_string (abfd, info_ptr, &bytes_read);
5508 info_ptr += bytes_read;
5509 break;
5510 case DW_FORM_sec_offset:
5511 case DW_FORM_strp:
5512 case DW_FORM_GNU_strp_alt:
5513 info_ptr += cu->header.offset_size;
5514 break;
5515 case DW_FORM_exprloc:
5516 case DW_FORM_block:
5517 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5518 info_ptr += bytes_read;
5519 break;
5520 case DW_FORM_block1:
5521 info_ptr += 1 + read_1_byte (abfd, info_ptr);
5522 break;
5523 case DW_FORM_block2:
5524 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
5525 break;
5526 case DW_FORM_block4:
5527 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
5528 break;
5529 case DW_FORM_addrx:
5530 case DW_FORM_strx:
5531 case DW_FORM_sdata:
5532 case DW_FORM_udata:
5533 case DW_FORM_ref_udata:
5534 case DW_FORM_GNU_addr_index:
5535 case DW_FORM_GNU_str_index:
5536 case DW_FORM_rnglistx:
5537 case DW_FORM_loclistx:
5538 info_ptr = safe_skip_leb128 (info_ptr, buffer_end);
5539 break;
5540 case DW_FORM_indirect:
5541 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5542 info_ptr += bytes_read;
5543 /* We need to continue parsing from here, so just go back to
5544 the top. */
5545 goto skip_attribute;
5546
5547 default:
5548 error (_("Dwarf Error: Cannot handle %s "
5549 "in DWARF reader [in module %s]"),
5550 dwarf_form_name (form),
5551 bfd_get_filename (abfd));
5552 }
5553 }
5554
5555 if (do_skip_children && abbrev->has_children)
5556 return skip_children (reader, info_ptr);
5557 else
5558 return info_ptr;
5559}
5560
5561/* Reading in full CUs. */
5562
5563/* Add PER_CU to the queue. */
5564
5565static void
5568 enum language pretend_language)
5569{
5570 per_cu->queued = 1;
5571
5572 gdb_assert (per_objfile->queue.has_value ());
5573 per_objfile->queue->emplace (per_cu, per_objfile, pretend_language);
5574}
5575
5576/* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
5577
5578 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
5579 dependency.
5580
5581 Return true if maybe_queue_comp_unit requires the caller to load the CU's
5582 DIEs, false otherwise.
5583
5584 Explanation: there is an invariant that if a CU is queued for expansion
5585 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
5586 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
5587 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
5588 are not yet loaded, the the caller must load the CU's DIEs to ensure the
5589 invariant is respected.
5590
5591 The caller is therefore not required to load the CU's DIEs (we return false)
5592 if:
5593
5594 - the CU is already expanded, and therefore does not get enqueued
5595 - the CU gets enqueued for expansion, but its DIEs are already loaded
5596
5597 Note that the caller should not use this function's return value as an
5598 indicator of whether the CU's DIEs are loaded right now, it should check
5599 that by calling `dwarf2_per_objfile::get_cu` instead. */
5600
5601static int
5602maybe_queue_comp_unit (struct dwarf2_cu *dependent_cu,
5605 enum language pretend_language)
5606{
5607 /* Mark the dependence relation so that we don't flush PER_CU
5608 too early. */
5609 if (dependent_cu != NULL)
5610 dependent_cu->add_dependence (per_cu);
5611
5612 /* If it's already on the queue, we have nothing to do. */
5613 if (per_cu->queued)
5614 {
5615 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
5616 loaded. */
5617 gdb_assert (per_objfile->get_cu (per_cu) != nullptr);
5618
5619 /* If the CU is queued for expansion, it should not already be
5620 expanded. */
5621 gdb_assert (!per_objfile->symtab_set_p (per_cu));
5622
5623 /* The DIEs are already loaded, the caller doesn't need to do it. */
5624 return 0;
5625 }
5626
5627 bool queued = false;
5629 {
5630 /* Add it to the queue. */
5631 queue_comp_unit (per_cu, per_objfile, pretend_language);
5632 queued = true;
5633 }
5634
5635 /* If the compilation unit is already loaded, just mark it as
5636 used. */
5638 if (cu != nullptr)
5639 cu->last_used = 0;
5640
5641 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
5642 and the DIEs are not already loaded. */
5643 return queued && cu == nullptr;
5644}
5645
5646/* Process the queue. */
5647
5648static void
5650{
5651 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
5653
5654 /* The queue starts out with one item, but following a DIE reference
5655 may load a new CU, adding it to the end of the queue. */
5656 while (!per_objfile->queue->empty ())
5657 {
5658 dwarf2_queue_item &item = per_objfile->queue->front ();
5660
5662 {
5664
5665 /* Skip dummy CUs. */
5666 if (cu != nullptr)
5667 {
5668 unsigned int debug_print_threshold;
5669 char buf[100];
5670
5672 {
5673 struct signatured_type *sig_type =
5674 (struct signatured_type *) per_cu;
5675
5676 sprintf (buf, "TU %s at offset %s",
5677 hex_string (sig_type->signature),
5678 sect_offset_str (per_cu->sect_off));
5679 /* There can be 100s of TUs.
5680 Only print them in verbose mode. */
5681 debug_print_threshold = 2;
5682 }
5683 else
5684 {
5685 sprintf (buf, "CU at offset %s",
5686 sect_offset_str (per_cu->sect_off));
5687 debug_print_threshold = 1;
5688 }
5689
5690 if (dwarf_read_debug >= debug_print_threshold)
5691 dwarf_read_debug_printf ("Expanding symtab of %s", buf);
5692
5693 if (per_cu->is_debug_types)
5695 else
5697
5698 if (dwarf_read_debug >= debug_print_threshold)
5699 dwarf_read_debug_printf ("Done expanding %s", buf);
5700 }
5701 }
5702
5703 per_cu->queued = 0;
5704 per_objfile->queue->pop ();
5705 }
5706
5707 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
5708 objfile_name (per_objfile->objfile));
5709}
5710
5711/* Load the DIEs associated with PER_CU into memory.
5712
5713 In some cases, the caller, while reading partial symbols, will need to load
5714 the full symbols for the CU for some reason. It will already have a
5715 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
5716 rather than creating a new one. */
5717
5718static void
5720 dwarf2_per_objfile *per_objfile,
5721 dwarf2_cu *existing_cu,
5722 bool skip_partial,
5723 enum language pretend_language)
5724{
5725 gdb_assert (! this_cu->is_debug_types);
5726
5727 cutu_reader reader (this_cu, per_objfile, NULL, existing_cu, skip_partial);
5728 if (reader.dummy_p)
5729 return;
5730
5731 struct dwarf2_cu *cu = reader.cu;
5732 const gdb_byte *info_ptr = reader.info_ptr;
5733
5734 gdb_assert (cu->die_hash == NULL);
5735 cu->die_hash =
5736 htab_create_alloc_ex (cu->header.get_length_without_initial () / 12,
5739 NULL,
5740 &cu->comp_unit_obstack,
5741 hashtab_obstack_allocate,
5742 dummy_obstack_deallocate);
5743
5744 if (reader.comp_unit_die->has_children)
5745 reader.comp_unit_die->child
5746 = read_die_and_siblings (&reader, reader.info_ptr,
5747 &info_ptr, reader.comp_unit_die);
5748 cu->dies = reader.comp_unit_die;
5749 /* comp_unit_die is not stored in die_hash, no need. */
5750
5751 /* We try not to read any attributes in this function, because not
5752 all CUs needed for references have been loaded yet, and symbol
5753 table processing isn't initialized. But we have to set the CU language,
5754 or we won't be able to build types correctly.
5755 Similarly, if we do not read the producer, we can not apply
5756 producer-specific interpretation. */
5757 prepare_one_comp_unit (cu, cu->dies, pretend_language);
5758
5759 reader.keep ();
5760}
5761
5762/* Add a DIE to the delayed physname list. */
5763
5764static void
5765add_to_method_list (struct type *type, int fnfield_index, int index,
5766 const char *name, struct die_info *die,
5767 struct dwarf2_cu *cu)
5768{
5769 struct delayed_method_info mi;
5770 mi.type = type;
5772 mi.index = index;
5773 mi.name = name;
5774 mi.die = die;
5775 cu->method_list.push_back (mi);
5776}
5777
5778/* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
5779 "const" / "volatile". If so, decrements LEN by the length of the
5780 modifier and return true. Otherwise return false. */
5781
5782template<size_t N>
5783static bool
5784check_modifier (const char *physname, size_t &len, const char (&mod)[N])
5785{
5786 size_t mod_len = sizeof (mod) - 1;
5787 if (len > mod_len && startswith (physname + (len - mod_len), mod))
5788 {
5789 len -= mod_len;
5790 return true;
5791 }
5792 return false;
5793}
5794
5795/* Compute the physnames of any methods on the CU's method list.
5796
5797 The computation of method physnames is delayed in order to avoid the
5798 (bad) condition that one of the method's formal parameters is of an as yet
5799 incomplete type. */
5800
5801static void
5803{
5804 /* Only C++ delays computing physnames. */
5805 if (cu->method_list.empty ())
5806 return;
5807 gdb_assert (cu->lang () == language_cplus);
5808
5809 for (const delayed_method_info &mi : cu->method_list)
5810 {
5811 const char *physname;
5812 struct fn_fieldlist *fn_flp
5813 = &TYPE_FN_FIELDLIST (mi.type, mi.fnfield_index);
5814 physname = dwarf2_physname (mi.name, mi.die, cu);
5815 TYPE_FN_FIELD_PHYSNAME (fn_flp->fn_fields, mi.index)
5816 = physname ? physname : "";
5817
5818 /* Since there's no tag to indicate whether a method is a
5819 const/volatile overload, extract that information out of the
5820 demangled name. */
5821 if (physname != NULL)
5822 {
5823 size_t len = strlen (physname);
5824
5825 while (1)
5826 {
5827 if (physname[len] == ')') /* shortcut */
5828 break;
5829 else if (check_modifier (physname, len, " const"))
5830 TYPE_FN_FIELD_CONST (fn_flp->fn_fields, mi.index) = 1;
5831 else if (check_modifier (physname, len, " volatile"))
5832 TYPE_FN_FIELD_VOLATILE (fn_flp->fn_fields, mi.index) = 1;
5833 else
5834 break;
5835 }
5836 }
5837 }
5838
5839 /* The list is no longer needed. */
5840 cu->method_list.clear ();
5841}
5842
5843/* Go objects should be embedded in a DW_TAG_module DIE,
5844 and it's not clear if/how imported objects will appear.
5845 To keep Go support simple until that's worked out,
5846 go back through what we've read and create something usable.
5847 We could do this while processing each DIE, and feels kinda cleaner,
5848 but that way is more invasive.
5849 This is to, for example, allow the user to type "p var" or "b main"
5850 without having to specify the package name, and allow lookups
5851 of module.object to work in contexts that use the expression
5852 parser. */
5853
5854static void
5856{
5857 gdb::unique_xmalloc_ptr<char> package_name;
5858 struct pending *list;
5859 int i;
5860
5861 for (list = *cu->get_builder ()->get_global_symbols ();
5862 list != NULL;
5863 list = list->next)
5864 {
5865 for (i = 0; i < list->nsyms; ++i)
5866 {
5867 struct symbol *sym = list->symbol[i];
5868
5869 if (sym->language () == language_go
5870 && sym->aclass () == LOC_BLOCK)
5871 {
5872 gdb::unique_xmalloc_ptr<char> this_package_name
5873 = go_symbol_package_name (sym);
5874
5875 if (this_package_name == NULL)
5876 continue;
5877 if (package_name == NULL)
5878 package_name = std::move (this_package_name);
5879 else
5880 {
5881 struct objfile *objfile = cu->per_objfile->objfile;
5882 if (strcmp (package_name.get (), this_package_name.get ()) != 0)
5883 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
5884 (sym->symtab () != NULL
5886 (sym->symtab ())
5887 : objfile_name (objfile)),
5888 this_package_name.get (), package_name.get ());
5889 }
5890 }
5891 }
5892 }
5893
5894 if (package_name != NULL)
5895 {
5896 struct objfile *objfile = cu->per_objfile->objfile;
5897 const char *saved_package_name = objfile->intern (package_name.get ());
5898 struct type *type
5899 = type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_MODULE, 0,
5900 saved_package_name);
5901 struct symbol *sym;
5902
5903 sym = new (&objfile->objfile_obstack) symbol;
5905 sym->compute_and_set_names (saved_package_name, false, objfile->per_bfd);
5906 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5907 e.g., "main" finds the "main" module and not C's main(). */
5910 sym->set_type (type);
5911
5913 }
5914}
5915
5916/* Allocate a fully-qualified name consisting of the two parts on the
5917 obstack. */
5918
5919static const char *
5920rust_fully_qualify (struct obstack *obstack, const char *p1, const char *p2)
5921{
5922 return obconcat (obstack, p1, "::", p2, (char *) NULL);
5923}
5924
5925/* A helper that allocates a variant part to attach to a Rust enum
5926 type. OBSTACK is where the results should be allocated. TYPE is
5927 the type we're processing. DISCRIMINANT_INDEX is the index of the
5928 discriminant. It must be the index of one of the fields of TYPE,
5929 or -1 to mean there is no discriminant (univariant enum).
5930 DEFAULT_INDEX is the index of the default field; or -1 if there is
5931 no default. RANGES is indexed by "effective" field number (the
5932 field index, but omitting the discriminant and default fields) and
5933 must hold the discriminant values used by the variants. Note that
5934 RANGES must have a lifetime at least as long as OBSTACK -- either
5935 already allocated on it, or static. */
5936
5937static void
5939 int discriminant_index, int default_index,
5940 gdb::array_view<discriminant_range> ranges)
5941{
5942 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
5943 gdb_assert (discriminant_index == -1
5944 || (discriminant_index >= 0
5945 && discriminant_index < type->num_fields ()));
5946 gdb_assert (default_index == -1
5947 || (default_index >= 0 && default_index < type->num_fields ()));
5948
5949 /* We have one variant for each non-discriminant field. */
5950 int n_variants = type->num_fields ();
5951 if (discriminant_index != -1)
5952 --n_variants;
5953
5954 variant *variants = new (obstack) variant[n_variants];
5955 int var_idx = 0;
5956 int range_idx = 0;
5957 for (int i = 0; i < type->num_fields (); ++i)
5958 {
5959 if (i == discriminant_index)
5960 continue;
5961
5962 variants[var_idx].first_field = i;
5963 variants[var_idx].last_field = i + 1;
5964
5965 /* The default field does not need a range, but other fields do.
5966 We skipped the discriminant above. */
5967 if (i != default_index)
5968 {
5969 variants[var_idx].discriminants = ranges.slice (range_idx, 1);
5970 ++range_idx;
5971 }
5972
5973 ++var_idx;
5974 }
5975
5976 gdb_assert (range_idx == ranges.size ());
5977 gdb_assert (var_idx == n_variants);
5978
5979 variant_part *part = new (obstack) variant_part;
5980 part->discriminant_index = discriminant_index;
5981 /* If there is no discriminant, then whether it is signed is of no
5982 consequence. */
5983 part->is_unsigned
5984 = (discriminant_index == -1
5985 ? false
5986 : type->field (discriminant_index).type ()->is_unsigned ());
5987 part->variants = gdb::array_view<variant> (variants, n_variants);
5988
5989 void *storage = obstack_alloc (obstack, sizeof (gdb::array_view<variant_part>));
5990 gdb::array_view<variant_part> *prop_value
5991 = new (storage) gdb::array_view<variant_part> (part, 1);
5992
5993 struct dynamic_prop prop;
5994 prop.set_variant_parts (prop_value);
5995
5997}
5998
5999/* Some versions of rustc emitted enums in an unusual way.
6000
6001 Ordinary enums were emitted as unions. The first element of each
6002 structure in the union was named "RUST$ENUM$DISR". This element
6003 held the discriminant.
6004
6005 These versions of Rust also implemented the "non-zero"
6006 optimization. When the enum had two values, and one is empty and
6007 the other holds a pointer that cannot be zero, the pointer is used
6008 as the discriminant, with a zero value meaning the empty variant.
6009 Here, the union's first member is of the form
6010 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
6011 where the fieldnos are the indices of the fields that should be
6012 traversed in order to find the field (which may be several fields deep)
6013 and the variantname is the name of the variant of the case when the
6014 field is zero.
6015
6016 This function recognizes whether TYPE is of one of these forms,
6017 and, if so, smashes it to be a variant type. */
6018
6019static void
6021{
6022 gdb_assert (type->code () == TYPE_CODE_UNION);
6023
6024 /* We don't need to deal with empty enums. */
6025 if (type->num_fields () == 0)
6026 return;
6027
6028#define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
6029 if (type->num_fields () == 1
6030 && startswith (type->field (0).name (), RUST_ENUM_PREFIX))
6031 {
6032 const char *name = type->field (0).name () + strlen (RUST_ENUM_PREFIX);
6033
6034 /* Decode the field name to find the offset of the
6035 discriminant. */
6036 ULONGEST bit_offset = 0;
6037 struct type *field_type = type->field (0).type ();
6038 while (name[0] >= '0' && name[0] <= '9')
6039 {
6040 char *tail;
6041 unsigned long index = strtoul (name, &tail, 10);
6042 name = tail;
6043 if (*name != '$'
6044 || index >= field_type->num_fields ()
6045 || (field_type->field (index).loc_kind ()
6047 {
6048 complaint (_("Could not parse Rust enum encoding string \"%s\""
6049 "[in module %s]"),
6050 type->field (0).name (),
6052 return;
6053 }
6054 ++name;
6055
6056 bit_offset += field_type->field (index).loc_bitpos ();
6057 field_type = field_type->field (index).type ();
6058 }
6059
6060 /* Smash this type to be a structure type. We have to do this
6061 because the type has already been recorded. */
6062 type->set_code (TYPE_CODE_STRUCT);
6063 /* Save the field we care about. */
6064 struct field saved_field = type->field (0);
6065 type->alloc_fields (3);
6066
6067 /* Put the discriminant at index 0. */
6068 type->field (0).set_type (field_type);
6069 type->field (0).set_is_artificial (true);
6070 type->field (0).set_name ("<<discriminant>>");
6071 type->field (0).set_loc_bitpos (bit_offset);
6072
6073 /* The order of fields doesn't really matter, so put the real
6074 field at index 1 and the data-less field at index 2. */
6075 type->field (1) = saved_field;
6076 type->field (1).set_name
6077 (rust_last_path_segment (type->field (1).type ()->name ()));
6078 type->field (1).type ()->set_name
6080 type->field (1).name ()));
6081
6082 const char *dataless_name
6084 name);
6085 struct type *dataless_type
6086 = type_allocator (type).new_type (TYPE_CODE_VOID, 0,
6087 dataless_name);
6088 type->field (2).set_type (dataless_type);
6089 /* NAME points into the original discriminant name, which
6090 already has the correct lifetime. */
6091 type->field (2).set_name (name);
6092 type->field (2).set_loc_bitpos (0);
6093
6094 /* Indicate that this is a variant type. */
6095 static discriminant_range ranges[1] = { { 0, 0 } };
6097 }
6098 /* A union with a single anonymous field is probably an old-style
6099 univariant enum. */
6100 else if (type->num_fields () == 1 && streq (type->field (0).name (), ""))
6101 {
6102 /* Smash this type to be a structure type. We have to do this
6103 because the type has already been recorded. */
6104 type->set_code (TYPE_CODE_STRUCT);
6105
6106 struct type *field_type = type->field (0).type ();
6107 const char *variant_name
6108 = rust_last_path_segment (field_type->name ());
6109 type->field (0).set_name (variant_name);
6110 field_type->set_name
6112 type->name (), variant_name));
6113
6115 }
6116 else
6117 {
6118 struct type *disr_type = nullptr;
6119 for (int i = 0; i < type->num_fields (); ++i)
6120 {
6121 disr_type = type->field (i).type ();
6122
6123 if (disr_type->code () != TYPE_CODE_STRUCT)
6124 {
6125 /* All fields of a true enum will be structs. */
6126 return;
6127 }
6128 else if (disr_type->num_fields () == 0)
6129 {
6130 /* Could be data-less variant, so keep going. */
6131 disr_type = nullptr;
6132 }
6133 else if (strcmp (disr_type->field (0).name (),
6134 "RUST$ENUM$DISR") != 0)
6135 {
6136 /* Not a Rust enum. */
6137 return;
6138 }
6139 else
6140 {
6141 /* Found one. */
6142 break;
6143 }
6144 }
6145
6146 /* If we got here without a discriminant, then it's probably
6147 just a union. */
6148 if (disr_type == nullptr)
6149 return;
6150
6151 /* Smash this type to be a structure type. We have to do this
6152 because the type has already been recorded. */
6153 type->set_code (TYPE_CODE_STRUCT);
6154
6155 /* Make space for the discriminant field. */
6156 struct field *disr_field = &disr_type->field (0);
6157 field *new_fields
6158 = (struct field *) TYPE_ZALLOC (type, ((type->num_fields () + 1)
6159 * sizeof (struct field)));
6160 memcpy (new_fields + 1, type->fields (),
6161 type->num_fields () * sizeof (struct field));
6162 type->set_fields (new_fields);
6164
6165 /* Install the discriminant at index 0 in the union. */
6166 type->field (0) = *disr_field;
6167 type->field (0).set_is_artificial (true);
6168 type->field (0).set_name ("<<discriminant>>");
6169
6170 /* We need a way to find the correct discriminant given a
6171 variant name. For convenience we build a map here. */
6172 struct type *enum_type = disr_field->type ();
6173 std::unordered_map<std::string, ULONGEST> discriminant_map;
6174 for (int i = 0; i < enum_type->num_fields (); ++i)
6175 {
6176 if (enum_type->field (i).loc_kind () == FIELD_LOC_KIND_ENUMVAL)
6177 {
6178 const char *name
6179 = rust_last_path_segment (enum_type->field (i).name ());
6180 discriminant_map[name] = enum_type->field (i).loc_enumval ();
6181 }
6182 }
6183
6184 int n_fields = type->num_fields ();
6185 /* We don't need a range entry for the discriminant, but we do
6186 need one for every other field, as there is no default
6187 variant. */
6188 discriminant_range *ranges = XOBNEWVEC (&objfile->objfile_obstack,
6190 n_fields - 1);
6191 /* Skip the discriminant here. */
6192 for (int i = 1; i < n_fields; ++i)
6193 {
6194 /* Find the final word in the name of this variant's type.
6195 That name can be used to look up the correct
6196 discriminant. */
6197 const char *variant_name
6198 = rust_last_path_segment (type->field (i).type ()->name ());
6199
6200 auto iter = discriminant_map.find (variant_name);
6201 if (iter != discriminant_map.end ())
6202 {
6203 ranges[i - 1].low = iter->second;
6204 ranges[i - 1].high = iter->second;
6205 }
6206
6207 /* In Rust, each element should have the size of the
6208 enclosing enum. */
6209 type->field (i).type ()->set_length (type->length ());
6210
6211 /* Remove the discriminant field, if it exists. */
6212 struct type *sub_type = type->field (i).type ();
6213 if (sub_type->num_fields () > 0)
6214 {
6215 sub_type->set_num_fields (sub_type->num_fields () - 1);
6216 sub_type->set_fields (sub_type->fields () + 1);
6217 }
6218 type->field (i).set_name (variant_name);
6219 sub_type->set_name
6221 type->name (), variant_name));
6222 }
6223
6224 /* Indicate that this is a variant type. */
6226 gdb::array_view<discriminant_range> (ranges,
6227 n_fields - 1));
6228 }
6229}
6230
6231/* Rewrite some Rust unions to be structures with variants parts. */
6232
6233static void
6235{
6236 gdb_assert (cu->lang () == language_rust);
6237 for (type *type_ : cu->rust_unions)
6238 quirk_rust_enum (type_, cu->per_objfile->objfile);
6239 /* We don't need this any more. */
6240 cu->rust_unions.clear ();
6241}
6242
6243/* See read.h. */
6244
6247{
6248 auto iter = this->m_type_units.find (tu_group);
6249 if (iter != this->m_type_units.end ())
6250 return iter->second.get ();
6251
6253 type_unit_group_unshareable *result = uniq.get ();
6254 this->m_type_units[tu_group] = std::move (uniq);
6255 return result;
6256}
6257
6258struct type *
6260 (signatured_type *sig_type) const
6261{
6262 auto iter = this->m_type_map.find (sig_type);
6263 if (iter == this->m_type_map.end ())
6264 return nullptr;
6265
6266 return iter->second;
6267}
6268
6270 (signatured_type *sig_type, struct type *type)
6271{
6272 gdb_assert (this->m_type_map.find (sig_type) == this->m_type_map.end ());
6273
6274 this->m_type_map[sig_type] = type;
6275}
6276
6277/* A helper function for computing the list of all symbol tables
6278 included by PER_CU. */
6279
6280static void
6281recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
6282 htab_t all_children, htab_t all_type_symtabs,
6283 dwarf2_per_cu_data *per_cu,
6284 dwarf2_per_objfile *per_objfile,
6285 struct compunit_symtab *immediate_parent)
6286{
6287 void **slot = htab_find_slot (all_children, per_cu, INSERT);
6288 if (*slot != NULL)
6289 {
6290 /* This inclusion and its children have been processed. */
6291 return;
6292 }
6293
6294 *slot = per_cu;
6295
6296 /* Only add a CU if it has a symbol table. */
6297 compunit_symtab *cust = per_objfile->get_symtab (per_cu);
6298 if (cust != NULL)
6299 {
6300 /* If this is a type unit only add its symbol table if we haven't
6301 seen it yet (type unit per_cu's can share symtabs). */
6302 if (per_cu->is_debug_types)
6303 {
6304 slot = htab_find_slot (all_type_symtabs, cust, INSERT);
6305 if (*slot == NULL)
6306 {
6307 *slot = cust;
6308 result->push_back (cust);
6309 if (cust->user == NULL)
6310 cust->user = immediate_parent;
6311 }
6312 }
6313 else
6314 {
6315 result->push_back (cust);
6316 if (cust->user == NULL)
6317 cust->user = immediate_parent;
6318 }
6319 }
6320
6321 if (!per_cu->imported_symtabs_empty ())
6322 for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
6323 {
6324 recursively_compute_inclusions (result, all_children,
6325 all_type_symtabs, ptr, per_objfile,
6326 cust);
6327 }
6328}
6329
6330/* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
6331 PER_CU. */
6332
6333static void
6335 dwarf2_per_objfile *per_objfile)
6336{
6337 gdb_assert (! per_cu->is_debug_types);
6338
6339 if (!per_cu->imported_symtabs_empty ())
6340 {
6341 int len;
6342 std::vector<compunit_symtab *> result_symtabs;
6343 compunit_symtab *cust = per_objfile->get_symtab (per_cu);
6344
6345 /* If we don't have a symtab, we can just skip this case. */
6346 if (cust == NULL)
6347 return;
6348
6349 htab_up all_children (htab_create_alloc (1, htab_hash_pointer,
6350 htab_eq_pointer,
6351 NULL, xcalloc, xfree));
6352 htab_up all_type_symtabs (htab_create_alloc (1, htab_hash_pointer,
6353 htab_eq_pointer,
6354 NULL, xcalloc, xfree));
6355
6356 for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
6357 {
6358 recursively_compute_inclusions (&result_symtabs, all_children.get (),
6359 all_type_symtabs.get (), ptr,
6360 per_objfile, cust);
6361 }
6362
6363 /* Now we have a transitive closure of all the included symtabs. */
6364 len = result_symtabs.size ();
6365 cust->includes
6366 = XOBNEWVEC (&per_objfile->objfile->objfile_obstack,
6367 struct compunit_symtab *, len + 1);
6368 memcpy (cust->includes, result_symtabs.data (),
6369 len * sizeof (compunit_symtab *));
6370 cust->includes[len] = NULL;
6371 }
6372}
6373
6374/* Compute the 'includes' field for the symtabs of all the CUs we just
6375 read. */
6376
6377static void
6379{
6380 for (dwarf2_per_cu_data *iter : per_objfile->per_bfd->just_read_cus)
6381 {
6382 if (! iter->is_debug_types)
6383 compute_compunit_symtab_includes (iter, per_objfile);
6384 }
6385
6386 per_objfile->per_bfd->just_read_cus.clear ();
6387}
6388
6389/* Generate full symbol information for CU, whose DIEs have
6390 already been loaded into memory. */
6391
6392static void
6393process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
6394{
6395 dwarf2_per_objfile *per_objfile = cu->per_objfile;
6396 unrelocated_addr lowpc, highpc;
6397 struct compunit_symtab *cust;
6398 struct block *static_block;
6399 CORE_ADDR addr;
6400
6401 /* Clear the list here in case something was left over. */
6402 cu->method_list.clear ();
6403
6405
6406 /* Before we start reading the top-level DIE, ensure it has a valid tag
6407 type. */
6408 switch (cu->dies->tag)
6409 {
6410 case DW_TAG_compile_unit:
6411 case DW_TAG_partial_unit:
6412 case DW_TAG_type_unit:
6413 break;
6414 default:
6415 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
6416 dwarf_tag_name (cu->dies->tag),
6418 objfile_name (per_objfile->objfile));
6419 }
6420
6421 /* Do line number decoding in read_file_scope () */
6422 process_die (cu->dies, cu);
6423
6424 /* For now fudge the Go package. */
6425 if (cu->lang () == language_go)
6426 fixup_go_packaging (cu);
6427
6428 /* Now that we have processed all the DIEs in the CU, all the types
6429 should be complete, and it should now be safe to compute all of the
6430 physnames. */
6432
6433 if (cu->lang () == language_rust)
6434 rust_union_quirks (cu);
6435
6436 /* Some compilers don't define a DW_AT_high_pc attribute for the
6437 compilation unit. If the DW_AT_high_pc is missing, synthesize
6438 it, by scanning the DIE's below the compilation unit. */
6439 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
6440
6441 addr = per_objfile->relocate (highpc);
6444
6445 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6446 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6447 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6448 addrmap to help ensure it has an accurate map of pc values belonging to
6449 this comp unit. */
6451
6453 (static_block, 0);
6454
6455 if (cust != NULL)
6456 {
6457 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
6458
6459 /* Set symtab language to language from DW_AT_language. If the
6460 compilation is from a C file generated by language preprocessors, do
6461 not set the language if it was already deduced by start_subfile. */
6462 if (!(cu->lang () == language_c
6463 && cust->primary_filetab ()->language () != language_unknown))
6464 cust->primary_filetab ()->set_language (cu->lang ());
6465
6466 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6467 produce DW_AT_location with location lists but it can be possibly
6468 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6469 there were bugs in prologue debug info, fixed later in GCC-4.5
6470 by "unwind info for epilogues" patch (which is not directly related).
6471
6472 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6473 needed, it would be wrong due to missing DW_AT_producer there.
6474
6475 Still one can confuse GDB by using non-standard GCC compilation
6476 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6477 */
6478 if (cu->has_loclist && gcc_4_minor >= 5)
6479 cust->set_locations_valid (true);
6480
6481 int major, minor;
6482 if (cu->producer != nullptr
6483 && producer_is_gcc (cu->producer, &major, &minor)
6484 && (major < 4 || (major == 4 && minor < 5)))
6485 /* Don't trust gcc < 4.5.x. */
6486 cust->set_epilogue_unwind_valid (false);
6487 else
6488 cust->set_epilogue_unwind_valid (true);
6489
6491 }
6492
6493 per_objfile->set_symtab (cu->per_cu, cust);
6494
6495 /* Push it for inclusion processing later. */
6496 per_objfile->per_bfd->just_read_cus.push_back (cu->per_cu);
6497
6498 /* Not needed any more. */
6499 cu->reset_builder ();
6500}
6501
6502/* Generate full symbol information for type unit CU, whose DIEs have
6503 already been loaded into memory. */
6504
6505static void
6507 enum language pretend_language)
6508{
6509 dwarf2_per_objfile *per_objfile = cu->per_objfile;
6510 struct compunit_symtab *cust;
6511 struct signatured_type *sig_type;
6512
6513 gdb_assert (cu->per_cu->is_debug_types);
6514 sig_type = (struct signatured_type *) cu->per_cu;
6515
6516 /* Clear the list here in case something was left over. */
6517 cu->method_list.clear ();
6518
6519 /* The symbol tables are set up in read_type_unit_scope. */
6520 process_die (cu->dies, cu);
6521
6522 /* For now fudge the Go package. */
6523 if (cu->lang () == language_go)
6524 fixup_go_packaging (cu);
6525
6526 /* Now that we have processed all the DIEs in the CU, all the types
6527 should be complete, and it should now be safe to compute all of the
6528 physnames. */
6530
6531 if (cu->lang () == language_rust)
6532 rust_union_quirks (cu);
6533
6534 /* TUs share symbol tables.
6535 If this is the first TU to use this symtab, complete the construction
6536 of it with end_expandable_symtab. Otherwise, complete the addition of
6537 this TU's symbols to the existing symtab. */
6538 type_unit_group_unshareable *tug_unshare =
6539 per_objfile->get_type_unit_group_unshareable (sig_type->type_unit_group);
6540 if (tug_unshare->compunit_symtab == NULL)
6541 {
6542 buildsym_compunit *builder = cu->get_builder ();
6543 cust = builder->end_expandable_symtab (0);
6544 tug_unshare->compunit_symtab = cust;
6545
6546 if (cust != NULL)
6547 {
6548 /* Set symtab language to language from DW_AT_language. If the
6549 compilation is from a C file generated by language preprocessors,
6550 do not set the language if it was already deduced by
6551 start_subfile. */
6552 if (!(cu->lang () == language_c
6553 && cust->primary_filetab ()->language () != language_c))
6554 cust->primary_filetab ()->set_language (cu->lang ());
6555 }
6556 }
6557 else
6558 {
6560 cust = tug_unshare->compunit_symtab;
6561 }
6562
6563 per_objfile->set_symtab (cu->per_cu, cust);
6564
6565 /* Not needed any more. */
6566 cu->reset_builder ();
6567}
6568
6569/* Process an imported unit DIE. */
6570
6571static void
6573{
6574 struct attribute *attr;
6575
6576 /* For now we don't handle imported units in type units. */
6577 if (cu->per_cu->is_debug_types)
6578 {
6579 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6580 " supported in type units [in module %s]"),
6582 }
6583
6584 attr = dwarf2_attr (die, DW_AT_import, cu);
6585 if (attr != NULL)
6586 {
6587 sect_offset sect_off = attr->get_ref_die_offset ();
6588 bool is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
6589 dwarf2_per_objfile *per_objfile = cu->per_objfile;
6590 dwarf2_per_cu_data *per_cu
6591 = dwarf2_find_containing_comp_unit (sect_off, is_dwz,
6592 per_objfile->per_bfd);
6593
6594 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
6595 into another compilation unit, at root level. Regard this as a hint,
6596 and ignore it. This is a best effort, it only works if unit_type and
6597 lang are already set. */
6598 if (die->parent && die->parent->parent == NULL
6599 && per_cu->unit_type (false) == DW_UT_compile
6600 && per_cu->lang (false) == language_cplus)
6601 return;
6602
6603 /* If necessary, add it to the queue and load its DIEs. */
6604 if (maybe_queue_comp_unit (cu, per_cu, per_objfile,
6605 cu->lang ()))
6606 load_full_comp_unit (per_cu, per_objfile, per_objfile->get_cu (per_cu),
6607 false, cu->lang ());
6608
6609 cu->per_cu->imported_symtabs_push (per_cu);
6610 }
6611}
6612
6613/* RAII object that represents a process_die scope: i.e.,
6614 starts/finishes processing a DIE. */
6616{
6617public:
6619 : m_die (die), m_cu (cu)
6620 {
6621 /* We should only be processing DIEs not already in process. */
6622 gdb_assert (!m_die->in_process);
6623 m_die->in_process = true;
6624 }
6625
6627 {
6628 m_die->in_process = false;
6629
6630 /* If we're done processing the DIE for the CU that owns the line
6631 header, we don't need the line header anymore. */
6633 {
6634 delete m_cu->line_header;
6635 m_cu->line_header = NULL;
6637 }
6638 }
6639
6640private:
6643};
6644
6645/* Process a die and its children. */
6646
6647static void
6648process_die (struct die_info *die, struct dwarf2_cu *cu)
6649{
6650 process_die_scope scope (die, cu);
6651
6652 switch (die->tag)
6653 {
6654 case DW_TAG_padding:
6655 break;
6656 case DW_TAG_compile_unit:
6657 case DW_TAG_partial_unit:
6658 read_file_scope (die, cu);
6659 break;
6660 case DW_TAG_type_unit:
6661 read_type_unit_scope (die, cu);
6662 break;
6663 case DW_TAG_subprogram:
6664 /* Nested subprograms in Fortran get a prefix. */
6665 if (cu->lang () == language_fortran
6666 && die->parent != NULL
6667 && die->parent->tag == DW_TAG_subprogram)
6669 /* Fall through. */
6670 case DW_TAG_inlined_subroutine:
6671 read_func_scope (die, cu);
6672 break;
6673 case DW_TAG_lexical_block:
6674 case DW_TAG_try_block:
6675 case DW_TAG_catch_block:
6676 read_lexical_block_scope (die, cu);
6677 break;
6678 case DW_TAG_call_site:
6679 case DW_TAG_GNU_call_site:
6680 read_call_site_scope (die, cu);
6681 break;
6682 case DW_TAG_class_type:
6683 case DW_TAG_interface_type:
6684 case DW_TAG_structure_type:
6685 case DW_TAG_union_type:
6686 case DW_TAG_namelist:
6687 process_structure_scope (die, cu);
6688 break;
6689 case DW_TAG_enumeration_type:
6690 process_enumeration_scope (die, cu);
6691 break;
6692
6693 /* These dies have a type, but processing them does not create
6694 a symbol or recurse to process the children. Therefore we can
6695 read them on-demand through read_type_die. */
6696 case DW_TAG_subroutine_type:
6697 case DW_TAG_set_type:
6698 case DW_TAG_pointer_type:
6699 case DW_TAG_ptr_to_member_type:
6700 case DW_TAG_reference_type:
6701 case DW_TAG_rvalue_reference_type:
6702 case DW_TAG_string_type:
6703 break;
6704
6705 case DW_TAG_array_type:
6706 /* We only need to handle this case for Ada -- in other
6707 languages, it's normal for the compiler to emit a typedef
6708 instead. */
6709 if (cu->lang () != language_ada)
6710 break;
6711 /* FALLTHROUGH */
6712 case DW_TAG_base_type:
6713 case DW_TAG_subrange_type:
6714 case DW_TAG_generic_subrange:
6715 case DW_TAG_typedef:
6716 /* Add a typedef symbol for the type definition, if it has a
6717 DW_AT_name. */
6718 new_symbol (die, read_type_die (die, cu), cu);
6719 break;
6720 case DW_TAG_common_block:
6721 read_common_block (die, cu);
6722 break;
6723 case DW_TAG_common_inclusion:
6724 break;
6725 case DW_TAG_namespace:
6727 read_namespace (die, cu);
6728 break;
6729 case DW_TAG_module:
6731 read_module (die, cu);
6732 break;
6733 case DW_TAG_imported_declaration:
6735 if (read_alias (die, cu))
6736 break;
6737 /* The declaration is neither a global namespace nor a variable
6738 alias. */
6739 /* Fall through. */
6740 case DW_TAG_imported_module:
6742 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
6743 || cu->lang () != language_fortran))
6744 complaint (_("Tag '%s' has unexpected children"),
6745 dwarf_tag_name (die->tag));
6746 read_import_statement (die, cu);
6747 break;
6748
6749 case DW_TAG_imported_unit:
6750 process_imported_unit_die (die, cu);
6751 break;
6752
6753 case DW_TAG_variable:
6754 read_variable (die, cu);
6755 break;
6756
6757 default:
6758 new_symbol (die, NULL, cu);
6759 break;
6760 }
6761}
6762
6763/* DWARF name computation. */
6764
6765/* A helper function for dwarf2_compute_name which determines whether DIE
6766 needs to have the name of the scope prepended to the name listed in the
6767 die. */
6768
6769static int
6770die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
6771{
6772 struct attribute *attr;
6773
6774 switch (die->tag)
6775 {
6776 case DW_TAG_namespace:
6777 case DW_TAG_typedef:
6778 case DW_TAG_class_type:
6779 case DW_TAG_interface_type:
6780 case DW_TAG_structure_type:
6781 case DW_TAG_union_type:
6782 case DW_TAG_enumeration_type:
6783 case DW_TAG_enumerator:
6784 case DW_TAG_subprogram:
6785 case DW_TAG_inlined_subroutine:
6786 case DW_TAG_member:
6787 case DW_TAG_imported_declaration:
6788 return 1;
6789
6790 case DW_TAG_variable:
6791 case DW_TAG_constant:
6792 /* We only need to prefix "globally" visible variables. These include
6793 any variable marked with DW_AT_external or any variable that
6794 lives in a namespace. [Variables in anonymous namespaces
6795 require prefixing, but they are not DW_AT_external.] */
6796
6797 if (dwarf2_attr (die, DW_AT_specification, cu))
6798 {
6799 struct dwarf2_cu *spec_cu = cu;
6800
6801 return die_needs_namespace (die_specification (die, &spec_cu),
6802 spec_cu);
6803 }
6804
6805 attr = dwarf2_attr (die, DW_AT_external, cu);
6806 if (attr == NULL && die->parent->tag != DW_TAG_namespace
6807 && die->parent->tag != DW_TAG_module)
6808 return 0;
6809 /* A variable in a lexical block of some kind does not need a
6810 namespace, even though in C++ such variables may be external
6811 and have a mangled name. */
6812 if (die->parent->tag == DW_TAG_lexical_block
6813 || die->parent->tag == DW_TAG_try_block
6814 || die->parent->tag == DW_TAG_catch_block
6815 || die->parent->tag == DW_TAG_subprogram)
6816 return 0;
6817 return 1;
6818
6819 default:
6820 return 0;
6821 }
6822}
6823
6824/* Return the DIE's linkage name attribute, either DW_AT_linkage_name
6825 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
6826 defined for the given DIE. */
6827
6828static struct attribute *
6830{
6831 struct attribute *attr;
6832
6833 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
6834 if (attr == NULL)
6835 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
6836
6837 return attr;
6838}
6839
6840/* Return the DIE's linkage name as a string, either DW_AT_linkage_name
6841 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
6842 defined for the given DIE. */
6843
6844static const char *
6845dw2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
6846{
6847 const char *linkage_name;
6848
6849 linkage_name = dwarf2_string_attr (die, DW_AT_linkage_name, cu);
6850 if (linkage_name == NULL)
6851 linkage_name = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu);
6852
6853 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
6854 See https://github.com/rust-lang/rust/issues/32925. */
6855 if (cu->lang () == language_rust && linkage_name != NULL
6856 && strchr (linkage_name, '{') != NULL)
6857 linkage_name = NULL;
6858
6859 return linkage_name;
6860}
6861
6862/* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6863 compute the physname for the object, which include a method's:
6864 - formal parameters (C++),
6865 - receiver type (Go),
6866
6867 The term "physname" is a bit confusing.
6868 For C++, for example, it is the demangled name.
6869 For Go, for example, it's the mangled name.
6870
6871 For Ada, return the DIE's linkage name rather than the fully qualified
6872 name. PHYSNAME is ignored..
6873
6874 The result is allocated on the objfile->per_bfd's obstack and
6875 canonicalized. */
6876
6877static const char *
6879 struct die_info *die, struct dwarf2_cu *cu,
6880 int physname)
6881{
6882 struct objfile *objfile = cu->per_objfile->objfile;
6883
6884 if (name == NULL)
6885 name = dwarf2_name (die, cu);
6886
6887 enum language lang = cu->lang ();
6888
6889 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
6890 but otherwise compute it by typename_concat inside GDB.
6891 FIXME: Actually this is not really true, or at least not always true.
6892 It's all very confusing. compute_and_set_names doesn't try to demangle
6893 Fortran names because there is no mangling standard. So new_symbol
6894 will set the demangled name to the result of dwarf2_full_name, and it is
6895 the demangled name that GDB uses if it exists. */
6896 if (lang == language_ada
6897 || (lang == language_fortran && physname))
6898 {
6899 /* For Ada unit, we prefer the linkage name over the name, as
6900 the former contains the exported name, which the user expects
6901 to be able to reference. Ideally, we want the user to be able
6902 to reference this entity using either natural or linkage name,
6903 but we haven't started looking at this enhancement yet. */
6904 const char *linkage_name = dw2_linkage_name (die, cu);
6905
6906 if (linkage_name != NULL)
6907 return linkage_name;
6908 }
6909
6910 /* These are the only languages we know how to qualify names in. */
6911 if (name != NULL
6912 && (lang == language_cplus
6913 || lang == language_fortran || lang == language_d
6914 || lang == language_rust))
6915 {
6916 if (die_needs_namespace (die, cu))
6917 {
6918 const char *prefix;
6919
6920 string_file buf;
6921
6922 prefix = determine_prefix (die, cu);
6923 if (*prefix != '\0')
6924 {
6925 gdb::unique_xmalloc_ptr<char> prefixed_name
6926 (typename_concat (NULL, prefix, name, physname, cu));
6927
6928 buf.puts (prefixed_name.get ());
6929 }
6930 else
6931 buf.puts (name);
6932
6933 /* Template parameters may be specified in the DIE's DW_AT_name, or
6934 as children with DW_TAG_template_type_param or
6935 DW_TAG_value_type_param. If the latter, add them to the name
6936 here. If the name already has template parameters, then
6937 skip this step; some versions of GCC emit both, and
6938 it is more efficient to use the pre-computed name.
6939
6940 Something to keep in mind about this process: it is very
6941 unlikely, or in some cases downright impossible, to produce
6942 something that will match the mangled name of a function.
6943 If the definition of the function has the same debug info,
6944 we should be able to match up with it anyway. But fallbacks
6945 using the minimal symbol, for instance to find a method
6946 implemented in a stripped copy of libstdc++, will not work.
6947 If we do not have debug info for the definition, we will have to
6948 match them up some other way.
6949
6950 When we do name matching there is a related problem with function
6951 templates; two instantiated function templates are allowed to
6952 differ only by their return types, which we do not add here. */
6953
6954 if (lang == language_cplus && strchr (name, '<') == NULL)
6955 {
6956 struct attribute *attr;
6957 struct die_info *child;
6958 int first = 1;
6959
6960 die->building_fullname = 1;
6961
6962 for (child = die->child; child != NULL; child = child->sibling)
6963 {
6964 struct type *type;
6965 LONGEST value;
6966 const gdb_byte *bytes;
6967 struct dwarf2_locexpr_baton *baton;
6968 struct value *v;
6969
6970 if (child->tag != DW_TAG_template_type_param
6971 && child->tag != DW_TAG_template_value_param)
6972 continue;
6973
6974 if (first)
6975 {
6976 buf.puts ("<");
6977 first = 0;
6978 }
6979 else
6980 buf.puts (", ");
6981
6982 attr = dwarf2_attr (child, DW_AT_type, cu);
6983 if (attr == NULL)
6984 {
6985 complaint (_("template parameter missing DW_AT_type"));
6986 buf.puts ("UNKNOWN_TYPE");
6987 continue;
6988 }
6989 type = die_type (child, cu);
6990
6991 if (child->tag == DW_TAG_template_type_param)
6992 {
6993 cu->language_defn->print_type (type, "", &buf, -1, 0,
6995 continue;
6996 }
6997
6998 attr = dwarf2_attr (child, DW_AT_const_value, cu);
6999 if (attr == NULL)
7000 {
7001 complaint (_("template parameter missing "
7002 "DW_AT_const_value"));
7003 buf.puts ("UNKNOWN_VALUE");
7004 continue;
7005 }
7006
7008 &cu->comp_unit_obstack, cu,
7009 &value, &bytes, &baton);
7010
7011 if (type->has_no_signedness ())
7012 /* GDB prints characters as NUMBER 'CHAR'. If that's
7013 changed, this can use value_print instead. */
7014 cu->language_defn->printchar (value, type, &buf);
7015 else
7016 {
7017 struct value_print_options opts;
7018
7019 if (baton != NULL)
7020 v = dwarf2_evaluate_loc_desc (type, NULL,
7021 baton->data,
7022 baton->size,
7023 baton->per_cu,
7024 baton->per_objfile);
7025 else if (bytes != NULL)
7026 {
7027 v = value::allocate (type);
7028 memcpy (v->contents_writeable ().data (), bytes,
7029 type->length ());
7030 }
7031 else
7033
7034 /* Specify decimal so that we do not depend on
7035 the radix. */
7036 get_formatted_print_options (&opts, 'd');
7037 opts.raw = true;
7038 value_print (v, &buf, &opts);
7039 release_value (v);
7040 }
7041 }
7042
7043 die->building_fullname = 0;
7044
7045 if (!first)
7046 {
7047 /* Close the argument list, with a space if necessary
7048 (nested templates). */
7049 if (!buf.empty () && buf.string ().back () == '>')
7050 buf.puts (" >");
7051 else
7052 buf.puts (">");
7053 }
7054 }
7055
7056 /* For C++ methods, append formal parameter type
7057 information, if PHYSNAME. */
7058
7059 if (physname && die->tag == DW_TAG_subprogram
7060 && lang == language_cplus)
7061 {
7062 struct type *type = read_type_die (die, cu);
7063
7064 c_type_print_args (type, &buf, 1, lang,
7066
7067 if (lang == language_cplus)
7068 {
7069 /* Assume that an artificial first parameter is
7070 "this", but do not crash if it is not. RealView
7071 marks unnamed (and thus unused) parameters as
7072 artificial; there is no way to differentiate
7073 the two cases. */
7074 if (type->num_fields () > 0
7075 && type->field (0).is_artificial ()
7076 && type->field (0).type ()->code () == TYPE_CODE_PTR
7077 && TYPE_CONST (type->field (0).type ()->target_type ()))
7078 buf.puts (" const");
7079 }
7080 }
7081
7082 const std::string &intermediate_name = buf.string ();
7083
7084 const char *canonical_name
7085 = dwarf2_canonicalize_name (intermediate_name.c_str (), cu,
7086 objfile);
7087
7088 /* If we only computed INTERMEDIATE_NAME, or if
7089 INTERMEDIATE_NAME is already canonical, then we need to
7090 intern it. */
7091 if (canonical_name == NULL || canonical_name == intermediate_name.c_str ())
7092 name = objfile->intern (intermediate_name);
7093 else
7094 name = canonical_name;
7095 }
7096 }
7097
7098 return name;
7099}
7100
7101/* Return the fully qualified name of DIE, based on its DW_AT_name.
7102 If scope qualifiers are appropriate they will be added. The result
7103 will be allocated on the storage_obstack, or NULL if the DIE does
7104 not have a name. NAME may either be from a previous call to
7105 dwarf2_name or NULL.
7106
7107 The output string will be canonicalized (if C++). */
7108
7109static const char *
7110dwarf2_full_name (const char *name, struct die_info *die, struct dwarf2_cu *cu)
7111{
7112 return dwarf2_compute_name (name, die, cu, 0);
7113}
7114
7115/* Construct a physname for the given DIE in CU. NAME may either be
7116 from a previous call to dwarf2_name or NULL. The result will be
7117 allocated on the objfile_objstack or NULL if the DIE does not have a
7118 name.
7119
7120 The output string will be canonicalized (if C++). */
7121
7122static const char *
7123dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
7124{
7125 struct objfile *objfile = cu->per_objfile->objfile;
7126 const char *retval, *mangled = NULL, *canon = NULL;
7127 int need_copy = 1;
7128
7129 /* In this case dwarf2_compute_name is just a shortcut not building anything
7130 on its own. */
7131 if (!die_needs_namespace (die, cu))
7132 return dwarf2_compute_name (name, die, cu, 1);
7133
7134 if (cu->lang () != language_rust)
7135 mangled = dw2_linkage_name (die, cu);
7136
7137 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7138 has computed. */
7139 gdb::unique_xmalloc_ptr<char> demangled;
7140 if (mangled != NULL)
7141 {
7143 {
7144 /* Do nothing (do not demangle the symbol name). */
7145 }
7146 else
7147 {
7148 /* Use DMGL_RET_DROP for C++ template functions to suppress
7149 their return type. It is easier for GDB users to search
7150 for such functions as `name(params)' than `long name(params)'.
7151 In such case the minimal symbol names do not match the full
7152 symbol names but for template functions there is never a need
7153 to look up their definition from their declaration so
7154 the only disadvantage remains the minimal symbol variant
7155 `long name(params)' does not have the proper inferior type. */
7156 demangled = gdb_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
7157 | DMGL_RET_DROP));
7158 }
7159 if (demangled)
7160 canon = demangled.get ();
7161 else
7162 {
7163 canon = mangled;
7164 need_copy = 0;
7165 }
7166 }
7167
7168 if (canon == NULL || check_physname)
7169 {
7170 const char *physname = dwarf2_compute_name (name, die, cu, 1);
7171
7172 if (canon != NULL && strcmp (physname, canon) != 0)
7173 {
7174 /* It may not mean a bug in GDB. The compiler could also
7175 compute DW_AT_linkage_name incorrectly. But in such case
7176 GDB would need to be bug-to-bug compatible. */
7177
7178 complaint (_("Computed physname <%s> does not match demangled <%s> "
7179 "(from linkage <%s>) - DIE at %s [in module %s]"),
7180 physname, canon, mangled, sect_offset_str (die->sect_off),
7182
7183 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7184 is available here - over computed PHYSNAME. It is safer
7185 against both buggy GDB and buggy compilers. */
7186
7187 retval = canon;
7188 }
7189 else
7190 {
7191 retval = physname;
7192 need_copy = 0;
7193 }
7194 }
7195 else
7196 retval = canon;
7197
7198 if (need_copy)
7199 retval = objfile->intern (retval);
7200
7201 return retval;
7202}
7203
7204/* Inspect DIE in CU for a namespace alias or a variable with alias
7205 attribute. If one exists, record a new symbol for it.
7206
7207 Returns true if an alias was recorded, false otherwise. */
7208
7209static bool
7210read_alias (struct die_info *die, struct dwarf2_cu *cu)
7211{
7212 struct attribute *attr;
7213
7214 /* If the die does not have a name, this is neither a namespace
7215 alias nor a variable alias. */
7216 attr = dwarf2_attr (die, DW_AT_name, cu);
7217 if (attr != NULL)
7218 {
7219 int num;
7220 struct die_info *d = die;
7221 struct dwarf2_cu *imported_cu = cu;
7222
7223 /* If the compiler has nested DW_AT_imported_declaration DIEs,
7224 keep inspecting DIEs until we hit the underlying import. */
7225#define MAX_NESTED_IMPORTED_DECLARATIONS 100
7226 for (num = 0; num < MAX_NESTED_IMPORTED_DECLARATIONS; ++num)
7227 {
7228 attr = dwarf2_attr (d, DW_AT_import, cu);
7229 if (attr == NULL)
7230 break;
7231
7232 d = follow_die_ref (d, attr, &imported_cu);
7233 if (d->tag != DW_TAG_imported_declaration)
7234 break;
7235 }
7236
7238 {
7239 complaint (_("DIE at %s has too many recursively imported "
7240 "declarations"), sect_offset_str (d->sect_off));
7241 return false;
7242 }
7243
7244 if (attr != NULL)
7245 {
7246 struct type *type;
7247 if (d->tag == DW_TAG_variable)
7248 {
7249 /* This declaration is a C/C++ global variable alias.
7250 Add a symbol for it whose type is the same as the
7251 aliased variable's. */
7252 type = die_type (d, imported_cu);
7253 struct symbol *sym = new_symbol (die, type, cu);
7254 attr = dwarf2_attr (d, DW_AT_location, imported_cu);
7256 if (attr != nullptr)
7257 var_decode_location (attr, sym, cu);
7258 return true;
7259 }
7260 else
7261 {
7262 sect_offset sect_off = attr->get_ref_die_offset ();
7263 type = get_die_type_at_offset (sect_off, cu->per_cu,
7264 cu->per_objfile);
7265 if (type != nullptr && type->code () == TYPE_CODE_NAMESPACE)
7266 {
7267 /* This declaration is a global namespace alias. Add
7268 a symbol for it whose type is the aliased
7269 namespace. */
7270 new_symbol (die, type, cu);
7271 return true;
7272 }
7273 }
7274 }
7275 }
7276 return false;
7277}
7278
7279/* Return the using directives repository (global or local?) to use in the
7280 current context for CU.
7281
7282 For Ada, imported declarations can materialize renamings, which *may* be
7283 global. However it is impossible (for now?) in DWARF to distinguish
7284 "external" imported declarations and "static" ones. As all imported
7285 declarations seem to be static in all other languages, make them all CU-wide
7286 global only in Ada. */
7287
7288static struct using_direct **
7290{
7291 if (cu->lang () == language_ada
7292 && cu->get_builder ()->outermost_context_p ())
7293 return cu->get_builder ()->get_global_using_directives ();
7294 else
7295 return cu->get_builder ()->get_local_using_directives ();
7296}
7297
7298/* Read the DW_ATTR_decl_line attribute for the given DIE in the
7299 given CU. If the format is not recognized or the attribute is
7300 not present, set it to 0. */
7301
7302static unsigned int
7303read_decl_line (struct die_info *die, struct dwarf2_cu *cu)
7304{
7305 struct attribute *decl_line = dwarf2_attr (die, DW_AT_decl_line, cu);
7306 if (decl_line == nullptr)
7307 return 0;
7308 if (decl_line->form_is_constant ())
7309 {
7310 LONGEST val = decl_line->constant_value (0);
7311 if (0 <= val && val <= UINT_MAX)
7312 return (unsigned int) val;
7313
7314 complaint (_("Declared line for using directive is too large"));
7315 return 0;
7316 }
7317
7318 complaint (_("Declared line for using directive is of incorrect format"));
7319 return 0;
7320}
7321
7322/* Read the import statement specified by the given die and record it. */
7323
7324static void
7326{
7327 struct objfile *objfile = cu->per_objfile->objfile;
7328 struct attribute *import_attr;
7329 struct die_info *imported_die, *child_die;
7330 struct dwarf2_cu *imported_cu;
7331 const char *imported_name;
7332 const char *imported_name_prefix;
7333 const char *canonical_name;
7334 const char *import_alias;
7335 const char *imported_declaration = NULL;
7336 const char *import_prefix;
7337 std::vector<const char *> excludes;
7338
7339 import_attr = dwarf2_attr (die, DW_AT_import, cu);
7340 if (import_attr == NULL)
7341 {
7342 complaint (_("Tag '%s' has no DW_AT_import"),
7343 dwarf_tag_name (die->tag));
7344 return;
7345 }
7346
7347 imported_cu = cu;
7348 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
7349 imported_name = dwarf2_name (imported_die, imported_cu);
7350 if (imported_name == NULL)
7351 {
7352 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7353
7354 The import in the following code:
7355 namespace A
7356 {
7357 typedef int B;
7358 }
7359
7360 int main ()
7361 {
7362 using A::B;
7363 B b;
7364 return b;
7365 }
7366
7367 ...
7368 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7369 <52> DW_AT_decl_file : 1
7370 <53> DW_AT_decl_line : 6
7371 <54> DW_AT_import : <0x75>
7372 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7373 <59> DW_AT_name : B
7374 <5b> DW_AT_decl_file : 1
7375 <5c> DW_AT_decl_line : 2
7376 <5d> DW_AT_type : <0x6e>
7377 ...
7378 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7379 <76> DW_AT_byte_size : 4
7380 <77> DW_AT_encoding : 5 (signed)
7381
7382 imports the wrong die ( 0x75 instead of 0x58 ).
7383 This case will be ignored until the gcc bug is fixed. */
7384 return;
7385 }
7386
7387 /* Figure out the local name after import. */
7388 import_alias = dwarf2_name (die, cu);
7389
7390 /* Figure out where the statement is being imported to. */
7391 import_prefix = determine_prefix (die, cu);
7392
7393 /* Figure out what the scope of the imported die is and prepend it
7394 to the name of the imported die. */
7395 imported_name_prefix = determine_prefix (imported_die, imported_cu);
7396
7397 if (imported_die->tag != DW_TAG_namespace
7398 && imported_die->tag != DW_TAG_module)
7399 {
7400 imported_declaration = imported_name;
7401 canonical_name = imported_name_prefix;
7402 }
7403 else if (strlen (imported_name_prefix) > 0)
7404 canonical_name = obconcat (&objfile->objfile_obstack,
7405 imported_name_prefix,
7406 (cu->lang () == language_d
7407 ? "."
7408 : "::"),
7409 imported_name, (char *) NULL);
7410 else
7411 canonical_name = imported_name;
7412
7413 if (die->tag == DW_TAG_imported_module
7414 && cu->lang () == language_fortran)
7415 for (child_die = die->child; child_die && child_die->tag;
7416 child_die = child_die->sibling)
7417 {
7418 /* DWARF-4: A Fortran use statement with a “rename list” may be
7419 represented by an imported module entry with an import attribute
7420 referring to the module and owned entries corresponding to those
7421 entities that are renamed as part of being imported. */
7422
7423 if (child_die->tag != DW_TAG_imported_declaration)
7424 {
7425 complaint (_("child DW_TAG_imported_declaration expected "
7426 "- DIE at %s [in module %s]"),
7427 sect_offset_str (child_die->sect_off),
7429 continue;
7430 }
7431
7432 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
7433 if (import_attr == NULL)
7434 {
7435 complaint (_("Tag '%s' has no DW_AT_import"),
7436 dwarf_tag_name (child_die->tag));
7437 continue;
7438 }
7439
7440 imported_cu = cu;
7441 imported_die = follow_die_ref_or_sig (child_die, import_attr,
7442 &imported_cu);
7443 imported_name = dwarf2_name (imported_die, imported_cu);
7444 if (imported_name == NULL)
7445 {
7446 complaint (_("child DW_TAG_imported_declaration has unknown "
7447 "imported name - DIE at %s [in module %s]"),
7448 sect_offset_str (child_die->sect_off),
7450 continue;
7451 }
7452
7453 excludes.push_back (imported_name);
7454
7455 process_die (child_die, cu);
7456 }
7457
7459 import_prefix,
7460 canonical_name,
7461 import_alias,
7462 imported_declaration,
7463 excludes,
7464 read_decl_line (die, cu),
7465 0,
7467}
7468
7469/* ICC<14 does not output the required DW_AT_declaration on incomplete
7470 types, but gives them a size of zero. Starting with version 14,
7471 ICC is compatible with GCC. */
7472
7473static bool
7475{
7476 if (!cu->checked_producer)
7477 check_producer (cu);
7478
7479 return cu->producer_is_icc_lt_14;
7480}
7481
7482/* ICC generates a DW_AT_type for C void functions. This was observed on
7483 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
7484 which says that void functions should not have a DW_AT_type. */
7485
7486static bool
7488{
7489 if (!cu->checked_producer)
7490 check_producer (cu);
7491
7492 return cu->producer_is_icc;
7493}
7494
7495/* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7496 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7497 this, it was first present in GCC release 4.3.0. */
7498
7499static bool
7501{
7502 if (!cu->checked_producer)
7503 check_producer (cu);
7504
7505 return cu->producer_is_gcc_lt_4_3;
7506}
7507
7508/* See dwarf2/read.h. */
7509bool
7511{
7512 if (!cu->checked_producer)
7513 check_producer (cu);
7514
7515 return cu->producer_is_clang;
7516}
7517
7518static file_and_directory &
7520{
7521 if (cu->per_cu->fnd != nullptr)
7522 return *cu->per_cu->fnd;
7523
7524 /* Find the filename. Do not use dwarf2_name here, since the filename
7525 is not a source language identifier. */
7526 file_and_directory res (dwarf2_string_attr (die, DW_AT_name, cu),
7527 dwarf2_string_attr (die, DW_AT_comp_dir, cu));
7528
7529 if (res.get_comp_dir () == nullptr
7531 && res.get_name () != nullptr
7532 && IS_ABSOLUTE_PATH (res.get_name ()))
7533 {
7534 res.set_comp_dir (ldirname (res.get_name ()));
7535 res.set_name (make_unique_xstrdup (lbasename (res.get_name ())));
7536 }
7537
7538 cu->per_cu->fnd.reset (new file_and_directory (std::move (res)));
7539 return *cu->per_cu->fnd;
7540}
7541
7542/* Handle DW_AT_stmt_list for a compilation unit.
7543 DIE is the DW_TAG_compile_unit die for CU.
7544 COMP_DIR is the compilation directory. LOWPC is passed to
7545 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
7546
7547static void
7549 const file_and_directory &fnd, unrelocated_addr lowpc,
7550 bool have_code) /* ARI: editCase function */
7551{
7553 struct attribute *attr;
7554 hashval_t line_header_local_hash;
7555 void **slot;
7556 int decode_mapping;
7557
7558 gdb_assert (! cu->per_cu->is_debug_types);
7559
7560 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
7561 if (attr == NULL || !attr->form_is_unsigned ())
7562 return;
7563
7564 sect_offset line_offset = (sect_offset) attr->as_unsigned ();
7565
7566 /* The line header hash table is only created if needed (it exists to
7567 prevent redundant reading of the line table for partial_units).
7568 If we're given a partial_unit, we'll need it. If we're given a
7569 compile_unit, then use the line header hash table if it's already
7570 created, but don't create one just yet. */
7571
7572 if (per_objfile->line_header_hash == NULL
7573 && die->tag == DW_TAG_partial_unit)
7574 {
7575 per_objfile->line_header_hash
7576 .reset (htab_create_alloc (127, line_header_hash_voidp,
7578 htab_delete_entry<line_header>,
7579 xcalloc, xfree));
7580 }
7581
7582 line_header line_header_local (line_offset, cu->per_cu->is_dwz);
7583 line_header_local_hash = line_header_hash (&line_header_local);
7584 if (per_objfile->line_header_hash != NULL)
7585 {
7586 slot = htab_find_slot_with_hash (per_objfile->line_header_hash.get (),
7587 &line_header_local,
7588 line_header_local_hash, NO_INSERT);
7589
7590 /* For DW_TAG_compile_unit we need info like symtab::linetable which
7591 is not present in *SLOT (since if there is something in *SLOT then
7592 it will be for a partial_unit). */
7593 if (die->tag == DW_TAG_partial_unit && slot != NULL)
7594 {
7595 gdb_assert (*slot != NULL);
7596 cu->line_header = (struct line_header *) *slot;
7597 return;
7598 }
7599 }
7600
7601 /* dwarf_decode_line_header does not yet provide sufficient information.
7602 We always have to call also dwarf_decode_lines for it. */
7604 fnd.get_comp_dir ());
7605 if (lh == NULL)
7606 return;
7607
7608 cu->line_header = lh.release ();
7609 cu->line_header_die_owner = die;
7610
7611 if (per_objfile->line_header_hash == NULL)
7612 slot = NULL;
7613 else
7614 {
7615 slot = htab_find_slot_with_hash (per_objfile->line_header_hash.get (),
7616 &line_header_local,
7617 line_header_local_hash, INSERT);
7618 gdb_assert (slot != NULL);
7619 }
7620 if (slot != NULL && *slot == NULL)
7621 {
7622 /* This newly decoded line number information unit will be owned
7623 by line_header_hash hash table. */
7624 *slot = cu->line_header;
7625 cu->line_header_die_owner = NULL;
7626 }
7627 else
7628 {
7629 /* We cannot free any current entry in (*slot) as that struct line_header
7630 may be already used by multiple CUs. Create only temporary decoded
7631 line_header for this CU - it may happen at most once for each line
7632 number information unit. And if we're not using line_header_hash
7633 then this is what we want as well. */
7634 gdb_assert (die->tag != DW_TAG_partial_unit);
7635 }
7636 decode_mapping = (die->tag != DW_TAG_partial_unit);
7637 /* The have_code check is here because, if LOWPC and HIGHPC are both 0x0,
7638 then there won't be any interesting code in the CU, but a check later on
7639 (in lnp_state_machine::check_line_address) will fail to properly exclude
7640 an entry that was removed via --gc-sections. */
7641 dwarf_decode_lines (cu->line_header, cu, lowpc, decode_mapping && have_code);
7642}
7643
7644/* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7645
7646static void
7647read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
7648{
7649 dwarf2_per_objfile *per_objfile = cu->per_objfile;
7650 struct objfile *objfile = per_objfile->objfile;
7651 CORE_ADDR lowpc;
7652 struct attribute *attr;
7653 struct die_info *child_die;
7654
7655 prepare_one_comp_unit (cu, die, cu->lang ());
7656
7657 unrelocated_addr unrel_low, unrel_high;
7658 get_scope_pc_bounds (die, &unrel_low, &unrel_high, cu);
7659
7660 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7661 from finish_block. */
7662 if (unrel_low == ((unrelocated_addr) -1))
7663 unrel_low = unrel_high;
7664 lowpc = per_objfile->relocate (unrel_low);
7665
7667
7669 lowpc);
7670
7671 gdb_assert (per_objfile->sym_cu == nullptr);
7672 scoped_restore restore_sym_cu
7673 = make_scoped_restore (&per_objfile->sym_cu, cu);
7674
7675 /* Decode line number information if present. We do this before
7676 processing child DIEs, so that the line header table is available
7677 for DW_AT_decl_file. */
7678 handle_DW_AT_stmt_list (die, cu, fnd, unrel_low, unrel_low != unrel_high);
7679
7680 /* Process all dies in compilation unit. */
7681 if (die->child != NULL)
7682 {
7683 child_die = die->child;
7684 while (child_die && child_die->tag)
7685 {
7686 process_die (child_die, cu);
7687 child_die = child_die->sibling;
7688 }
7689 }
7690 per_objfile->sym_cu = nullptr;
7691
7692 /* Decode macro information, if present. Dwarf 2 macro information
7693 refers to information in the line number info statement program
7694 header, so we can only read it if we've read the header
7695 successfully. */
7696 attr = dwarf2_attr (die, DW_AT_macros, cu);
7697 if (attr == NULL)
7698 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
7699 if (attr != nullptr && attr->form_is_unsigned () && cu->line_header)
7700 {
7701 if (dwarf2_attr (die, DW_AT_macro_info, cu))
7702 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
7703
7705 }
7706 else
7707 {
7708 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
7709 if (attr != nullptr && attr->form_is_unsigned () && cu->line_header)
7710 {
7711 unsigned int macro_offset = attr->as_unsigned ();
7712
7713 dwarf_decode_macros (cu, macro_offset, 0);
7714 }
7715 }
7716}
7717
7718void
7720{
7721 struct type_unit_group *tu_group;
7722 int first_time;
7723 struct attribute *attr;
7724 unsigned int i;
7725 struct signatured_type *sig_type;
7726
7727 gdb_assert (per_cu->is_debug_types);
7728 sig_type = (struct signatured_type *) per_cu;
7729
7730 attr = dwarf2_attr (die, DW_AT_stmt_list, this);
7731
7732 /* If we're using .gdb_index (includes -readnow) then
7733 per_cu->type_unit_group may not have been set up yet. */
7734 if (sig_type->type_unit_group == NULL)
7735 sig_type->type_unit_group = get_type_unit_group (this, attr);
7736 tu_group = sig_type->type_unit_group;
7737
7738 /* If we've already processed this stmt_list there's no real need to
7739 do it again, we could fake it and just recreate the part we need
7740 (file name,index -> symtab mapping). If data shows this optimization
7741 is useful we can do it then. */
7742 type_unit_group_unshareable *tug_unshare
7744 first_time = tug_unshare->compunit_symtab == NULL;
7745
7746 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7747 debug info. */
7748 line_header_up lh;
7749 if (attr != NULL && attr->form_is_unsigned ())
7750 {
7751 sect_offset line_offset = (sect_offset) attr->as_unsigned ();
7752 lh = dwarf_decode_line_header (line_offset, this, nullptr);
7753 }
7754 if (lh == NULL)
7755 {
7756 if (first_time)
7757 start_compunit_symtab ("", NULL, 0);
7758 else
7759 {
7760 gdb_assert (tug_unshare->symtabs == NULL);
7761 gdb_assert (m_builder == nullptr);
7762 struct compunit_symtab *cust = tug_unshare->compunit_symtab;
7763 m_builder.reset (new struct buildsym_compunit
7764 (cust->objfile (), "",
7765 cust->dirname (),
7766 cust->language (),
7767 0, cust));
7769 }
7770 return;
7771 }
7772
7773 line_header = lh.release ();
7775
7776 if (first_time)
7777 {
7778 struct compunit_symtab *cust = start_compunit_symtab ("", NULL, 0);
7779
7780 /* Note: We don't assign tu_group->compunit_symtab yet because we're
7781 still initializing it, and our caller (a few levels up)
7782 process_full_type_unit still needs to know if this is the first
7783 time. */
7784
7785 tug_unshare->symtabs
7786 = XOBNEWVEC (&cust->objfile ()->objfile_obstack,
7787 struct symtab *, line_header->file_names_size ());
7788
7789 auto &file_names = line_header->file_names ();
7790 for (i = 0; i < file_names.size (); ++i)
7791 {
7792 file_entry &fe = file_names[i];
7793 dwarf2_start_subfile (this, fe, *line_header);
7795 subfile *sf = b->get_current_subfile ();
7796
7797 if (sf->symtab == nullptr)
7798 {
7799 /* NOTE: start_subfile will recognize when it's been
7800 passed a file it has already seen. So we can't
7801 assume there's a simple mapping from
7802 cu->line_header->file_names to subfiles, plus
7803 cu->line_header->file_names may contain dups. */
7804 const char *name = sf->name.c_str ();
7805 const char *name_for_id = sf->name_for_id.c_str ();
7806 sf->symtab = allocate_symtab (cust, name, name_for_id);
7807 }
7808
7809 fe.symtab = b->get_current_subfile ()->symtab;
7810 tug_unshare->symtabs[i] = fe.symtab;
7811 }
7812 }
7813 else
7814 {
7815 gdb_assert (m_builder == nullptr);
7816 struct compunit_symtab *cust = tug_unshare->compunit_symtab;
7817 m_builder.reset (new struct buildsym_compunit
7818 (cust->objfile (), "",
7819 cust->dirname (),
7820 cust->language (),
7821 0, cust));
7823
7824 auto &file_names = line_header->file_names ();
7825 for (i = 0; i < file_names.size (); ++i)
7826 {
7827 file_entry &fe = file_names[i];
7828 fe.symtab = tug_unshare->symtabs[i];
7829 }
7830 }
7831
7832 /* The main symtab is allocated last. Type units don't have DW_AT_name
7833 so they don't have a "real" (so to speak) symtab anyway.
7834 There is later code that will assign the main symtab to all symbols
7835 that don't have one. We need to handle the case of a symbol with a
7836 missing symtab (DW_AT_decl_file) anyway. */
7837}
7838
7839/* Process DW_TAG_type_unit.
7840 For TUs we want to skip the first top level sibling if it's not the
7841 actual type being defined by this TU. In this case the first top
7842 level sibling is there to provide context only. */
7843
7844static void
7845read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
7846{
7847 struct die_info *child_die;
7848
7850
7851 /* Initialize (or reinitialize) the machinery for building symtabs.
7852 We do this before processing child DIEs, so that the line header table
7853 is available for DW_AT_decl_file. */
7854 cu->setup_type_unit_groups (die);
7855
7856 if (die->child != NULL)
7857 {
7858 child_die = die->child;
7859 while (child_die && child_die->tag)
7860 {
7861 process_die (child_die, cu);
7862 child_die = child_die->sibling;
7863 }
7864 }
7865}
7866
7867/* DWO/DWP files.
7868
7869 http://gcc.gnu.org/wiki/DebugFission
7870 http://gcc.gnu.org/wiki/DebugFissionDWP
7871
7872 To simplify handling of both DWO files ("object" files with the DWARF info)
7873 and DWP files (a file with the DWOs packaged up into one file), we treat
7874 DWP files as having a collection of virtual DWO files. */
7875
7876static hashval_t
7877hash_dwo_file (const void *item)
7878{
7879 const struct dwo_file *dwo_file = (const struct dwo_file *) item;
7880 hashval_t hash;
7881
7882 hash = htab_hash_string (dwo_file->dwo_name);
7883 if (dwo_file->comp_dir != NULL)
7884 hash += htab_hash_string (dwo_file->comp_dir);
7885 return hash;
7886}
7887
7888static int
7889eq_dwo_file (const void *item_lhs, const void *item_rhs)
7890{
7891 const struct dwo_file *lhs = (const struct dwo_file *) item_lhs;
7892 const struct dwo_file *rhs = (const struct dwo_file *) item_rhs;
7893
7894 if (strcmp (lhs->dwo_name, rhs->dwo_name) != 0)
7895 return 0;
7896 if (lhs->comp_dir == NULL || rhs->comp_dir == NULL)
7897 return lhs->comp_dir == rhs->comp_dir;
7898 return strcmp (lhs->comp_dir, rhs->comp_dir) == 0;
7899}
7900
7901/* Allocate a hash table for DWO files. */
7902
7903static htab_up
7905{
7906 return htab_up (htab_create_alloc (41,
7909 htab_delete_entry<dwo_file>,
7910 xcalloc, xfree));
7911}
7912
7913/* Lookup DWO file DWO_NAME. */
7914
7915static void **
7917 const char *dwo_name,
7918 const char *comp_dir)
7919{
7920 struct dwo_file find_entry;
7921 void **slot;
7922
7923 if (per_objfile->per_bfd->dwo_files == NULL)
7925
7926 find_entry.dwo_name = dwo_name;
7927 find_entry.comp_dir = comp_dir;
7928 slot = htab_find_slot (per_objfile->per_bfd->dwo_files.get (), &find_entry,
7929 INSERT);
7930
7931 return slot;
7932}
7933
7934static hashval_t
7935hash_dwo_unit (const void *item)
7936{
7937 const struct dwo_unit *dwo_unit = (const struct dwo_unit *) item;
7938
7939 /* This drops the top 32 bits of the id, but is ok for a hash. */
7940 return dwo_unit->signature;
7941}
7942
7943static int
7944eq_dwo_unit (const void *item_lhs, const void *item_rhs)
7945{
7946 const struct dwo_unit *lhs = (const struct dwo_unit *) item_lhs;
7947 const struct dwo_unit *rhs = (const struct dwo_unit *) item_rhs;
7948
7949 /* The signature is assumed to be unique within the DWO file.
7950 So while object file CU dwo_id's always have the value zero,
7951 that's OK, assuming each object file DWO file has only one CU,
7952 and that's the rule for now. */
7953 return lhs->signature == rhs->signature;
7954}
7955
7956/* Allocate a hash table for DWO CUs,TUs.
7957 There is one of these tables for each of CUs,TUs for each DWO file. */
7958
7959static htab_up
7961{
7962 /* Start out with a pretty small number.
7963 Generally DWO files contain only one CU and maybe some TUs. */
7964 return htab_up (htab_create_alloc (3,
7967 NULL, xcalloc, xfree));
7968}
7969
7970/* die_reader_func for create_dwo_cu. */
7971
7972static void
7974 const gdb_byte *info_ptr,
7975 struct die_info *comp_unit_die,
7976 struct dwo_file *dwo_file,
7977 struct dwo_unit *dwo_unit)
7978{
7979 struct dwarf2_cu *cu = reader->cu;
7980 sect_offset sect_off = cu->per_cu->sect_off;
7982
7983 gdb::optional<ULONGEST> signature = lookup_dwo_id (cu, comp_unit_die);
7984 if (!signature.has_value ())
7985 {
7986 complaint (_("Dwarf Error: debug entry at offset %s is missing"
7987 " its dwo_id [in module %s]"),
7988 sect_offset_str (sect_off), dwo_file->dwo_name);
7989 return;
7990 }
7991
7993 dwo_unit->signature = *signature;
7995 dwo_unit->sect_off = sect_off;
7996 dwo_unit->length = cu->per_cu->length ();
7997
7998 dwarf_read_debug_printf (" offset %s, dwo_id %s",
7999 sect_offset_str (sect_off),
8000 hex_string (dwo_unit->signature));
8001}
8002
8003/* Create the dwo_units for the CUs in a DWO_FILE.
8004 Note: This function processes DWO files only, not DWP files. */
8005
8006static void
8008 dwarf2_cu *cu, struct dwo_file &dwo_file,
8009 dwarf2_section_info &section, htab_up &cus_htab)
8010{
8011 struct objfile *objfile = per_objfile->objfile;
8012 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
8013 const gdb_byte *info_ptr, *end_ptr;
8014
8015 section.read (objfile);
8016 info_ptr = section.buffer;
8017
8018 if (info_ptr == NULL)
8019 return;
8020
8021 dwarf_read_debug_printf ("Reading %s for %s:",
8022 section.get_name (),
8023 section.get_file_name ());
8024
8025 end_ptr = info_ptr + section.size;
8026 while (info_ptr < end_ptr)
8027 {
8028 struct dwarf2_per_cu_data per_cu;
8029 struct dwo_unit read_unit {};
8030 struct dwo_unit *dwo_unit;
8031 void **slot;
8032 sect_offset sect_off = (sect_offset) (info_ptr - section.buffer);
8033
8034 per_cu.per_bfd = per_bfd;
8035 per_cu.is_debug_types = 0;
8036 per_cu.sect_off = sect_offset (info_ptr - section.buffer);
8037 per_cu.section = &section;
8038
8039 cutu_reader reader (&per_cu, per_objfile, cu, &dwo_file);
8040 if (!reader.dummy_p)
8041 create_dwo_cu_reader (&reader, reader.info_ptr, reader.comp_unit_die,
8042 &dwo_file, &read_unit);
8043 info_ptr += per_cu.length ();
8044
8045 // If the unit could not be parsed, skip it.
8046 if (read_unit.dwo_file == NULL)
8047 continue;
8048
8049 if (cus_htab == NULL)
8050 cus_htab = allocate_dwo_unit_table ();
8051
8052 dwo_unit = OBSTACK_ZALLOC (&per_bfd->obstack,
8053 struct dwo_unit);
8054 *dwo_unit = read_unit;
8055 slot = htab_find_slot (cus_htab.get (), dwo_unit, INSERT);
8056 gdb_assert (slot != NULL);
8057 if (*slot != NULL)
8058 {
8059 const struct dwo_unit *dup_cu = (const struct dwo_unit *)*slot;
8060 sect_offset dup_sect_off = dup_cu->sect_off;
8061
8062 complaint (_("debug cu entry at offset %s is duplicate to"
8063 " the entry at offset %s, signature %s"),
8064 sect_offset_str (sect_off), sect_offset_str (dup_sect_off),
8065 hex_string (dwo_unit->signature));
8066 }
8067 *slot = (void *)dwo_unit;
8068 }
8069}
8070
8071/* DWP file .debug_{cu,tu}_index section format:
8072 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8073 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
8074
8075 DWP Versions 1 & 2 are older, pre-standard format versions. The first
8076 officially standard DWP format was published with DWARF v5 and is called
8077 Version 5. There are no versions 3 or 4.
8078
8079 DWP Version 1:
8080
8081 Both index sections have the same format, and serve to map a 64-bit
8082 signature to a set of section numbers. Each section begins with a header,
8083 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8084 indexes, and a pool of 32-bit section numbers. The index sections will be
8085 aligned at 8-byte boundaries in the file.
8086
8087 The index section header consists of:
8088
8089 V, 32 bit version number
8090 -, 32 bits unused
8091 N, 32 bit number of compilation units or type units in the index
8092 M, 32 bit number of slots in the hash table
8093
8094 Numbers are recorded using the byte order of the application binary.
8095
8096 The hash table begins at offset 16 in the section, and consists of an array
8097 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8098 order of the application binary). Unused slots in the hash table are 0.
8099 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8100
8101 The parallel table begins immediately after the hash table
8102 (at offset 16 + 8 * M from the beginning of the section), and consists of an
8103 array of 32-bit indexes (using the byte order of the application binary),
8104 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8105 table contains a 32-bit index into the pool of section numbers. For unused
8106 hash table slots, the corresponding entry in the parallel table will be 0.
8107
8108 The pool of section numbers begins immediately following the hash table
8109 (at offset 16 + 12 * M from the beginning of the section). The pool of
8110 section numbers consists of an array of 32-bit words (using the byte order
8111 of the application binary). Each item in the array is indexed starting
8112 from 0. The hash table entry provides the index of the first section
8113 number in the set. Additional section numbers in the set follow, and the
8114 set is terminated by a 0 entry (section number 0 is not used in ELF).
8115
8116 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8117 section must be the first entry in the set, and the .debug_abbrev.dwo must
8118 be the second entry. Other members of the set may follow in any order.
8119
8120 ---
8121
8122 DWP Versions 2 and 5:
8123
8124 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
8125 and the entries in the index tables are now offsets into these sections.
8126 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
8127 section.
8128
8129 Index Section Contents:
8130 Header
8131 Hash Table of Signatures dwp_hash_table.hash_table
8132 Parallel Table of Indices dwp_hash_table.unit_table
8133 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
8134 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
8135
8136 The index section header consists of:
8137
8138 V, 32 bit version number
8139 L, 32 bit number of columns in the table of section offsets
8140 N, 32 bit number of compilation units or type units in the index
8141 M, 32 bit number of slots in the hash table
8142
8143 Numbers are recorded using the byte order of the application binary.
8144
8145 The hash table has the same format as version 1.
8146 The parallel table of indices has the same format as version 1,
8147 except that the entries are origin-1 indices into the table of sections
8148 offsets and the table of section sizes.
8149
8150 The table of offsets begins immediately following the parallel table
8151 (at offset 16 + 12 * M from the beginning of the section). The table is
8152 a two-dimensional array of 32-bit words (using the byte order of the
8153 application binary), with L columns and N+1 rows, in row-major order.
8154 Each row in the array is indexed starting from 0. The first row provides
8155 a key to the remaining rows: each column in this row provides an identifier
8156 for a debug section, and the offsets in the same column of subsequent rows
8157 refer to that section. The section identifiers for Version 2 are:
8158
8159 DW_SECT_INFO 1 .debug_info.dwo
8160 DW_SECT_TYPES 2 .debug_types.dwo
8161 DW_SECT_ABBREV 3 .debug_abbrev.dwo
8162 DW_SECT_LINE 4 .debug_line.dwo
8163 DW_SECT_LOC 5 .debug_loc.dwo
8164 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
8165 DW_SECT_MACINFO 7 .debug_macinfo.dwo
8166 DW_SECT_MACRO 8 .debug_macro.dwo
8167
8168 The section identifiers for Version 5 are:
8169
8170 DW_SECT_INFO_V5 1 .debug_info.dwo
8171 DW_SECT_RESERVED_V5 2 --
8172 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
8173 DW_SECT_LINE_V5 4 .debug_line.dwo
8174 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
8175 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
8176 DW_SECT_MACRO_V5 7 .debug_macro.dwo
8177 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
8178
8179 The offsets provided by the CU and TU index sections are the base offsets
8180 for the contributions made by each CU or TU to the corresponding section
8181 in the package file. Each CU and TU header contains an abbrev_offset
8182 field, used to find the abbreviations table for that CU or TU within the
8183 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
8184 be interpreted as relative to the base offset given in the index section.
8185 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
8186 should be interpreted as relative to the base offset for .debug_line.dwo,
8187 and offsets into other debug sections obtained from DWARF attributes should
8188 also be interpreted as relative to the corresponding base offset.
8189
8190 The table of sizes begins immediately following the table of offsets.
8191 Like the table of offsets, it is a two-dimensional array of 32-bit words,
8192 with L columns and N rows, in row-major order. Each row in the array is
8193 indexed starting from 1 (row 0 is shared by the two tables).
8194
8195 ---
8196
8197 Hash table lookup is handled the same in version 1 and 2:
8198
8199 We assume that N and M will not exceed 2^32 - 1.
8200 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8201
8202 Given a 64-bit compilation unit signature or a type signature S, an entry
8203 in the hash table is located as follows:
8204
8205 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8206 the low-order k bits all set to 1.
8207
8208 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8209
8210 3) If the hash table entry at index H matches the signature, use that
8211 entry. If the hash table entry at index H is unused (all zeroes),
8212 terminate the search: the signature is not present in the table.
8213
8214 4) Let H = (H + H') modulo M. Repeat at Step 3.
8215
8216 Because M > N and H' and M are relatively prime, the search is guaranteed
8217 to stop at an unused slot or find the match. */
8218
8219/* Create a hash table to map DWO IDs to their CU/TU entry in
8220 .debug_{info,types}.dwo in DWP_FILE.
8221 Returns NULL if there isn't one.
8222 Note: This function processes DWP files only, not DWO files. */
8223
8224static struct dwp_hash_table *
8226 struct dwp_file *dwp_file, int is_debug_types)
8227{
8228 struct objfile *objfile = per_objfile->objfile;
8229 bfd *dbfd = dwp_file->dbfd.get ();
8230 const gdb_byte *index_ptr, *index_end;
8231 struct dwarf2_section_info *index;
8232 uint32_t version, nr_columns, nr_units, nr_slots;
8233 struct dwp_hash_table *htab;
8234
8235 if (is_debug_types)
8236 index = &dwp_file->sections.tu_index;
8237 else
8238 index = &dwp_file->sections.cu_index;
8239
8240 if (index->empty ())
8241 return NULL;
8242 index->read (objfile);
8243
8244 index_ptr = index->buffer;
8245 index_end = index_ptr + index->size;
8246
8247 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
8248 For now it's safe to just read 4 bytes (particularly as it's difficult to
8249 tell if you're dealing with Version 5 before you've read the version). */
8250 version = read_4_bytes (dbfd, index_ptr);
8251 index_ptr += 4;
8252 if (version == 2 || version == 5)
8253 nr_columns = read_4_bytes (dbfd, index_ptr);
8254 else
8255 nr_columns = 0;
8256 index_ptr += 4;
8257 nr_units = read_4_bytes (dbfd, index_ptr);
8258 index_ptr += 4;
8259 nr_slots = read_4_bytes (dbfd, index_ptr);
8260 index_ptr += 4;
8261
8262 if (version != 1 && version != 2 && version != 5)
8263 {
8264 error (_("Dwarf Error: unsupported DWP file version (%s)"
8265 " [in module %s]"),
8266 pulongest (version), dwp_file->name);
8267 }
8268 if (nr_slots != (nr_slots & -nr_slots))
8269 {
8270 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
8271 " is not power of 2 [in module %s]"),
8272 pulongest (nr_slots), dwp_file->name);
8273 }
8274
8275 htab = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwp_hash_table);
8276 htab->version = version;
8277 htab->nr_columns = nr_columns;
8278 htab->nr_units = nr_units;
8279 htab->nr_slots = nr_slots;
8280 htab->hash_table = index_ptr;
8281 htab->unit_table = htab->hash_table + sizeof (uint64_t) * nr_slots;
8282
8283 /* Exit early if the table is empty. */
8284 if (nr_slots == 0 || nr_units == 0
8285 || (version == 2 && nr_columns == 0)
8286 || (version == 5 && nr_columns == 0))
8287 {
8288 /* All must be zero. */
8289 if (nr_slots != 0 || nr_units != 0
8290 || (version == 2 && nr_columns != 0)
8291 || (version == 5 && nr_columns != 0))
8292 {
8293 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
8294 " all zero [in modules %s]"),
8295 dwp_file->name);
8296 }
8297 return htab;
8298 }
8299
8300 if (version == 1)
8301 {
8302 htab->section_pool.v1.indices =
8303 htab->unit_table + sizeof (uint32_t) * nr_slots;
8304 /* It's harder to decide whether the section is too small in v1.
8305 V1 is deprecated anyway so we punt. */
8306 }
8307 else if (version == 2)
8308 {
8309 const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots;
8310 int *ids = htab->section_pool.v2.section_ids;
8311 size_t sizeof_ids = sizeof (htab->section_pool.v2.section_ids);
8312 /* Reverse map for error checking. */
8313 int ids_seen[DW_SECT_MAX + 1];
8314 int i;
8315
8316 if (nr_columns < 2)
8317 {
8318 error (_("Dwarf Error: bad DWP hash table, too few columns"
8319 " in section table [in module %s]"),
8320 dwp_file->name);
8321 }
8323 {
8324 error (_("Dwarf Error: bad DWP hash table, too many columns"
8325 " in section table [in module %s]"),
8326 dwp_file->name);
8327 }
8328 memset (ids, 255, sizeof_ids);
8329 memset (ids_seen, 255, sizeof (ids_seen));
8330 for (i = 0; i < nr_columns; ++i)
8331 {
8332 int id = read_4_bytes (dbfd, ids_ptr + i * sizeof (uint32_t));
8333
8334 if (id < DW_SECT_MIN || id > DW_SECT_MAX)
8335 {
8336 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
8337 " in section table [in module %s]"),
8338 id, dwp_file->name);
8339 }
8340 if (ids_seen[id] != -1)
8341 {
8342 error (_("Dwarf Error: bad DWP hash table, duplicate section"
8343 " id %d in section table [in module %s]"),
8344 id, dwp_file->name);
8345 }
8346 ids_seen[id] = i;
8347 ids[i] = id;
8348 }
8349 /* Must have exactly one info or types section. */
8350 if (((ids_seen[DW_SECT_INFO] != -1)
8351 + (ids_seen[DW_SECT_TYPES] != -1))
8352 != 1)
8353 {
8354 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
8355 " DWO info/types section [in module %s]"),
8356 dwp_file->name);
8357 }
8358 /* Must have an abbrev section. */
8359 if (ids_seen[DW_SECT_ABBREV] == -1)
8360 {
8361 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
8362 " section [in module %s]"),
8363 dwp_file->name);
8364 }
8365 htab->section_pool.v2.offsets = ids_ptr + sizeof (uint32_t) * nr_columns;
8366 htab->section_pool.v2.sizes =
8367 htab->section_pool.v2.offsets + (sizeof (uint32_t)
8368 * nr_units * nr_columns);
8369 if ((htab->section_pool.v2.sizes + (sizeof (uint32_t)
8370 * nr_units * nr_columns))
8371 > index_end)
8372 {
8373 error (_("Dwarf Error: DWP index section is corrupt (too small)"
8374 " [in module %s]"),
8375 dwp_file->name);
8376 }
8377 }
8378 else /* version == 5 */
8379 {
8380 const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots;
8381 int *ids = htab->section_pool.v5.section_ids;
8382 size_t sizeof_ids = sizeof (htab->section_pool.v5.section_ids);
8383 /* Reverse map for error checking. */
8384 int ids_seen[DW_SECT_MAX_V5 + 1];
8385
8386 if (nr_columns < 2)
8387 {
8388 error (_("Dwarf Error: bad DWP hash table, too few columns"
8389 " in section table [in module %s]"),
8390 dwp_file->name);
8391 }
8393 {
8394 error (_("Dwarf Error: bad DWP hash table, too many columns"
8395 " in section table [in module %s]"),
8396 dwp_file->name);
8397 }
8398 memset (ids, 255, sizeof_ids);
8399 memset (ids_seen, 255, sizeof (ids_seen));
8400 for (int i = 0; i < nr_columns; ++i)
8401 {
8402 int id = read_4_bytes (dbfd, ids_ptr + i * sizeof (uint32_t));
8403
8404 if (id < DW_SECT_MIN || id > DW_SECT_MAX_V5)
8405 {
8406 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
8407 " in section table [in module %s]"),
8408 id, dwp_file->name);
8409 }
8410 if (ids_seen[id] != -1)
8411 {
8412 error (_("Dwarf Error: bad DWP hash table, duplicate section"
8413 " id %d in section table [in module %s]"),
8414 id, dwp_file->name);
8415 }
8416 ids_seen[id] = i;
8417 ids[i] = id;
8418 }
8419 /* Must have seen an info section. */
8420 if (ids_seen[DW_SECT_INFO_V5] == -1)
8421 {
8422 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
8423 " DWO info/types section [in module %s]"),
8424 dwp_file->name);
8425 }
8426 /* Must have an abbrev section. */
8427 if (ids_seen[DW_SECT_ABBREV_V5] == -1)
8428 {
8429 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
8430 " section [in module %s]"),
8431 dwp_file->name);
8432 }
8433 htab->section_pool.v5.offsets = ids_ptr + sizeof (uint32_t) * nr_columns;
8434 htab->section_pool.v5.sizes
8435 = htab->section_pool.v5.offsets + (sizeof (uint32_t)
8436 * nr_units * nr_columns);
8437 if ((htab->section_pool.v5.sizes + (sizeof (uint32_t)
8438 * nr_units * nr_columns))
8439 > index_end)
8440 {
8441 error (_("Dwarf Error: DWP index section is corrupt (too small)"
8442 " [in module %s]"),
8443 dwp_file->name);
8444 }
8445 }
8446
8447 return htab;
8448}
8449
8450/* Update SECTIONS with the data from SECTP.
8451
8452 This function is like the other "locate" section routines, but in
8453 this context the sections to read comes from the DWP V1 hash table,
8454 not the full ELF section table.
8455
8456 The result is non-zero for success, or zero if an error was found. */
8457
8458static int
8460 struct virtual_v1_dwo_sections *sections)
8461{
8462 const struct dwop_section_names *names = &dwop_section_names;
8463
8464 if (names->abbrev_dwo.matches (sectp->name))
8465 {
8466 /* There can be only one. */
8467 if (sections->abbrev.s.section != NULL)
8468 return 0;
8469 sections->abbrev.s.section = sectp;
8470 sections->abbrev.size = bfd_section_size (sectp);
8471 }
8472 else if (names->info_dwo.matches (sectp->name)
8473 || names->types_dwo.matches (sectp->name))
8474 {
8475 /* There can be only one. */
8476 if (sections->info_or_types.s.section != NULL)
8477 return 0;
8478 sections->info_or_types.s.section = sectp;
8479 sections->info_or_types.size = bfd_section_size (sectp);
8480 }
8481 else if (names->line_dwo.matches (sectp->name))
8482 {
8483 /* There can be only one. */
8484 if (sections->line.s.section != NULL)
8485 return 0;
8486 sections->line.s.section = sectp;
8487 sections->line.size = bfd_section_size (sectp);
8488 }
8489 else if (names->loc_dwo.matches (sectp->name))
8490 {
8491 /* There can be only one. */
8492 if (sections->loc.s.section != NULL)
8493 return 0;
8494 sections->loc.s.section = sectp;
8495 sections->loc.size = bfd_section_size (sectp);
8496 }
8497 else if (names->macinfo_dwo.matches (sectp->name))
8498 {
8499 /* There can be only one. */
8500 if (sections->macinfo.s.section != NULL)
8501 return 0;
8502 sections->macinfo.s.section = sectp;
8503 sections->macinfo.size = bfd_section_size (sectp);
8504 }
8505 else if (names->macro_dwo.matches (sectp->name))
8506 {
8507 /* There can be only one. */
8508 if (sections->macro.s.section != NULL)
8509 return 0;
8510 sections->macro.s.section = sectp;
8511 sections->macro.size = bfd_section_size (sectp);
8512 }
8513 else if (names->str_offsets_dwo.matches (sectp->name))
8514 {
8515 /* There can be only one. */
8516 if (sections->str_offsets.s.section != NULL)
8517 return 0;
8518 sections->str_offsets.s.section = sectp;
8519 sections->str_offsets.size = bfd_section_size (sectp);
8520 }
8521 else
8522 {
8523 /* No other kind of section is valid. */
8524 return 0;
8525 }
8526
8527 return 1;
8528}
8529
8530/* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
8531 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
8532 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
8533 This is for DWP version 1 files. */
8534
8535static struct dwo_unit *
8537 struct dwp_file *dwp_file,
8538 uint32_t unit_index,
8539 const char *comp_dir,
8540 ULONGEST signature, int is_debug_types)
8541{
8542 const struct dwp_hash_table *dwp_htab =
8543 is_debug_types ? dwp_file->tus : dwp_file->cus;
8544 bfd *dbfd = dwp_file->dbfd.get ();
8545 const char *kind = is_debug_types ? "TU" : "CU";
8546 struct dwo_file *dwo_file;
8547 struct dwo_unit *dwo_unit;
8548 struct virtual_v1_dwo_sections sections;
8549 void **dwo_file_slot;
8550 int i;
8551
8552 gdb_assert (dwp_file->version == 1);
8553
8554 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
8555 kind, pulongest (unit_index), hex_string (signature),
8556 dwp_file->name);
8557
8558 /* Fetch the sections of this DWO unit.
8559 Put a limit on the number of sections we look for so that bad data
8560 doesn't cause us to loop forever. */
8561
8562#define MAX_NR_V1_DWO_SECTIONS \
8563 (1 /* .debug_info or .debug_types */ \
8564 + 1 /* .debug_abbrev */ \
8565 + 1 /* .debug_line */ \
8566 + 1 /* .debug_loc */ \
8567 + 1 /* .debug_str_offsets */ \
8568 + 1 /* .debug_macro or .debug_macinfo */ \
8569 + 1 /* trailing zero */)
8570
8571 memset (&sections, 0, sizeof (sections));
8572
8573 for (i = 0; i < MAX_NR_V1_DWO_SECTIONS; ++i)
8574 {
8575 asection *sectp;
8576 uint32_t section_nr =
8577 read_4_bytes (dbfd,
8578 dwp_htab->section_pool.v1.indices
8579 + (unit_index + i) * sizeof (uint32_t));
8580
8581 if (section_nr == 0)
8582 break;
8583 if (section_nr >= dwp_file->num_sections)
8584 {
8585 error (_("Dwarf Error: bad DWP hash table, section number too large"
8586 " [in module %s]"),
8587 dwp_file->name);
8588 }
8589
8590 sectp = dwp_file->elf_sections[section_nr];
8591 if (! locate_v1_virtual_dwo_sections (sectp, &sections))
8592 {
8593 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8594 " [in module %s]"),
8595 dwp_file->name);
8596 }
8597 }
8598
8599 if (i < 2
8600 || sections.info_or_types.empty ()
8601 || sections.abbrev.empty ())
8602 {
8603 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8604 " [in module %s]"),
8605 dwp_file->name);
8606 }
8607 if (i == MAX_NR_V1_DWO_SECTIONS)
8608 {
8609 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8610 " [in module %s]"),
8611 dwp_file->name);
8612 }
8613
8614 /* It's easier for the rest of the code if we fake a struct dwo_file and
8615 have dwo_unit "live" in that. At least for now.
8616
8617 The DWP file can be made up of a random collection of CUs and TUs.
8618 However, for each CU + set of TUs that came from the same original DWO
8619 file, we can combine them back into a virtual DWO file to save space
8620 (fewer struct dwo_file objects to allocate). Remember that for really
8621 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8622
8623 std::string virtual_dwo_name =
8624 string_printf ("virtual-dwo/%d-%d-%d-%d",
8625 sections.abbrev.get_id (),
8626 sections.line.get_id (),
8627 sections.loc.get_id (),
8628 sections.str_offsets.get_id ());
8629 /* Can we use an existing virtual DWO file? */
8630 dwo_file_slot = lookup_dwo_file_slot (per_objfile, virtual_dwo_name.c_str (),
8631 comp_dir);
8632 /* Create one if necessary. */
8633 if (*dwo_file_slot == NULL)
8634 {
8635 dwarf_read_debug_printf ("Creating virtual DWO: %s",
8636 virtual_dwo_name.c_str ());
8637
8638 dwo_file = new struct dwo_file;
8639 dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name);
8641 dwo_file->sections.abbrev = sections.abbrev;
8642 dwo_file->sections.line = sections.line;
8643 dwo_file->sections.loc = sections.loc;
8644 dwo_file->sections.macinfo = sections.macinfo;
8645 dwo_file->sections.macro = sections.macro;
8646 dwo_file->sections.str_offsets = sections.str_offsets;
8647 /* The "str" section is global to the entire DWP file. */
8648 dwo_file->sections.str = dwp_file->sections.str;
8649 /* The info or types section is assigned below to dwo_unit,
8650 there's no need to record it in dwo_file.
8651 Also, we can't simply record type sections in dwo_file because
8652 we record a pointer into the vector in dwo_unit. As we collect more
8653 types we'll grow the vector and eventually have to reallocate space
8654 for it, invalidating all copies of pointers into the previous
8655 contents. */
8656 *dwo_file_slot = dwo_file;
8657 }
8658 else
8659 {
8660 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
8661 virtual_dwo_name.c_str ());
8662
8663 dwo_file = (struct dwo_file *) *dwo_file_slot;
8664 }
8665
8666 dwo_unit = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwo_unit);
8668 dwo_unit->signature = signature;
8669 dwo_unit->section =
8670 XOBNEW (&per_objfile->per_bfd->obstack, struct dwarf2_section_info);
8671 *dwo_unit->section = sections.info_or_types;
8672 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
8673
8674 return dwo_unit;
8675}
8676
8677/* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
8678 simplify them. Given a pointer to the containing section SECTION, and
8679 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
8680 virtual section of just that piece. */
8681
8682static struct dwarf2_section_info
8685 bfd_size_type offset, bfd_size_type size)
8686{
8687 struct dwarf2_section_info result;
8688 asection *sectp;
8689
8690 gdb_assert (section != NULL);
8691 gdb_assert (!section->is_virtual);
8692
8693 memset (&result, 0, sizeof (result));
8694 result.s.containing_section = section;
8695 result.is_virtual = true;
8696
8697 if (size == 0)
8698 return result;
8699
8700 sectp = section->get_bfd_section ();
8701
8702 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
8703 bounds of the real section. This is a pretty-rare event, so just
8704 flag an error (easier) instead of a warning and trying to cope. */
8705 if (sectp == NULL
8706 || offset + size > bfd_section_size (sectp))
8707 {
8708 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
8709 " in section %s [in module %s]"),
8710 sectp ? bfd_section_name (sectp) : "<unknown>",
8711 objfile_name (per_objfile->objfile));
8712 }
8713
8714 result.virtual_offset = offset;
8715 result.size = size;
8716 return result;
8717}
8718
8719/* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
8720 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
8721 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
8722 This is for DWP version 2 files. */
8723
8724static struct dwo_unit *
8726 struct dwp_file *dwp_file,
8727 uint32_t unit_index,
8728 const char *comp_dir,
8729 ULONGEST signature, int is_debug_types)
8730{
8731 const struct dwp_hash_table *dwp_htab =
8732 is_debug_types ? dwp_file->tus : dwp_file->cus;
8733 bfd *dbfd = dwp_file->dbfd.get ();
8734 const char *kind = is_debug_types ? "TU" : "CU";
8735 struct dwo_file *dwo_file;
8736 struct dwo_unit *dwo_unit;
8737 struct virtual_v2_or_v5_dwo_sections sections;
8738 void **dwo_file_slot;
8739 int i;
8740
8741 gdb_assert (dwp_file->version == 2);
8742
8743 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
8744 kind, pulongest (unit_index), hex_string (signature),
8745 dwp_file->name);
8746
8747 /* Fetch the section offsets of this DWO unit. */
8748
8749 memset (&sections, 0, sizeof (sections));
8750
8751 for (i = 0; i < dwp_htab->nr_columns; ++i)
8752 {
8753 uint32_t offset = read_4_bytes (dbfd,
8754 dwp_htab->section_pool.v2.offsets
8755 + (((unit_index - 1) * dwp_htab->nr_columns
8756 + i)
8757 * sizeof (uint32_t)));
8758 uint32_t size = read_4_bytes (dbfd,
8759 dwp_htab->section_pool.v2.sizes
8760 + (((unit_index - 1) * dwp_htab->nr_columns
8761 + i)
8762 * sizeof (uint32_t)));
8763
8764 switch (dwp_htab->section_pool.v2.section_ids[i])
8765 {
8766 case DW_SECT_INFO:
8767 case DW_SECT_TYPES:
8768 sections.info_or_types_offset = offset;
8769 sections.info_or_types_size = size;
8770 break;
8771 case DW_SECT_ABBREV:
8772 sections.abbrev_offset = offset;
8773 sections.abbrev_size = size;
8774 break;
8775 case DW_SECT_LINE:
8776 sections.line_offset = offset;
8777 sections.line_size = size;
8778 break;
8779 case DW_SECT_LOC:
8780 sections.loc_offset = offset;
8781 sections.loc_size = size;
8782 break;
8783 case DW_SECT_STR_OFFSETS:
8784 sections.str_offsets_offset = offset;
8785 sections.str_offsets_size = size;
8786 break;
8787 case DW_SECT_MACINFO:
8788 sections.macinfo_offset = offset;
8789 sections.macinfo_size = size;
8790 break;
8791 case DW_SECT_MACRO:
8792 sections.macro_offset = offset;
8793 sections.macro_size = size;
8794 break;
8795 }
8796 }
8797
8798 /* It's easier for the rest of the code if we fake a struct dwo_file and
8799 have dwo_unit "live" in that. At least for now.
8800
8801 The DWP file can be made up of a random collection of CUs and TUs.
8802 However, for each CU + set of TUs that came from the same original DWO
8803 file, we can combine them back into a virtual DWO file to save space
8804 (fewer struct dwo_file objects to allocate). Remember that for really
8805 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8806
8807 std::string virtual_dwo_name =
8808 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
8809 (long) (sections.abbrev_size ? sections.abbrev_offset : 0),
8810 (long) (sections.line_size ? sections.line_offset : 0),
8811 (long) (sections.loc_size ? sections.loc_offset : 0),
8812 (long) (sections.str_offsets_size
8813 ? sections.str_offsets_offset : 0));
8814 /* Can we use an existing virtual DWO file? */
8815 dwo_file_slot = lookup_dwo_file_slot (per_objfile, virtual_dwo_name.c_str (),
8816 comp_dir);
8817 /* Create one if necessary. */
8818 if (*dwo_file_slot == NULL)
8819 {
8820 dwarf_read_debug_printf ("Creating virtual DWO: %s",
8821 virtual_dwo_name.c_str ());
8822
8823 dwo_file = new struct dwo_file;
8824 dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name);
8826 dwo_file->sections.abbrev =
8827 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.abbrev,
8828 sections.abbrev_offset,
8829 sections.abbrev_size);
8830 dwo_file->sections.line =
8831 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.line,
8832 sections.line_offset,
8833 sections.line_size);
8834 dwo_file->sections.loc =
8835 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.loc,
8836 sections.loc_offset, sections.loc_size);
8837 dwo_file->sections.macinfo =
8838 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.macinfo,
8839 sections.macinfo_offset,
8840 sections.macinfo_size);
8841 dwo_file->sections.macro =
8842 create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.macro,
8843 sections.macro_offset,
8844 sections.macro_size);
8845 dwo_file->sections.str_offsets =
8846 create_dwp_v2_or_v5_section (per_objfile,
8847 &dwp_file->sections.str_offsets,
8848 sections.str_offsets_offset,
8849 sections.str_offsets_size);
8850 /* The "str" section is global to the entire DWP file. */
8851 dwo_file->sections.str = dwp_file->sections.str;
8852 /* The info or types section is assigned below to dwo_unit,
8853 there's no need to record it in dwo_file.
8854 Also, we can't simply record type sections in dwo_file because
8855 we record a pointer into the vector in dwo_unit. As we collect more
8856 types we'll grow the vector and eventually have to reallocate space
8857 for it, invalidating all copies of pointers into the previous
8858 contents. */
8859 *dwo_file_slot = dwo_file;
8860 }
8861 else
8862 {
8863 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
8864 virtual_dwo_name.c_str ());
8865
8866 dwo_file = (struct dwo_file *) *dwo_file_slot;
8867 }
8868
8869 dwo_unit = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwo_unit);
8871 dwo_unit->signature = signature;
8872 dwo_unit->section =
8873 XOBNEW (&per_objfile->per_bfd->obstack, struct dwarf2_section_info);
8875 (per_objfile,
8876 is_debug_types
8877 ? &dwp_file->sections.types
8878 : &dwp_file->sections.info,
8879 sections.info_or_types_offset,
8880 sections.info_or_types_size);
8881 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
8882
8883 return dwo_unit;
8884}
8885
8886/* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
8887 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
8888 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
8889 This is for DWP version 5 files. */
8890
8891static struct dwo_unit *
8893 struct dwp_file *dwp_file,
8894 uint32_t unit_index,
8895 const char *comp_dir,
8896 ULONGEST signature, int is_debug_types)
8897{
8898 const struct dwp_hash_table *dwp_htab
8899 = is_debug_types ? dwp_file->tus : dwp_file->cus;
8900 bfd *dbfd = dwp_file->dbfd.get ();
8901 const char *kind = is_debug_types ? "TU" : "CU";
8902 struct dwo_file *dwo_file;
8903 struct dwo_unit *dwo_unit;
8904 struct virtual_v2_or_v5_dwo_sections sections {};
8905 void **dwo_file_slot;
8906
8907 gdb_assert (dwp_file->version == 5);
8908
8909 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
8910 kind, pulongest (unit_index), hex_string (signature),
8911 dwp_file->name);
8912
8913 /* Fetch the section offsets of this DWO unit. */
8914
8915 /* memset (&sections, 0, sizeof (sections)); */
8916
8917 for (int i = 0; i < dwp_htab->nr_columns; ++i)
8918 {
8919 uint32_t offset = read_4_bytes (dbfd,
8920 dwp_htab->section_pool.v5.offsets
8921 + (((unit_index - 1)
8922 * dwp_htab->nr_columns
8923 + i)
8924 * sizeof (uint32_t)));
8925 uint32_t size = read_4_bytes (dbfd,
8926 dwp_htab->section_pool.v5.sizes
8927 + (((unit_index - 1) * dwp_htab->nr_columns
8928 + i)
8929 * sizeof (uint32_t)));
8930
8931 switch (dwp_htab->section_pool.v5.section_ids[i])
8932 {
8933 case DW_SECT_ABBREV_V5:
8934 sections.abbrev_offset = offset;
8935 sections.abbrev_size = size;
8936 break;
8937 case DW_SECT_INFO_V5:
8938 sections.info_or_types_offset = offset;
8939 sections.info_or_types_size = size;
8940 break;
8941 case DW_SECT_LINE_V5:
8942 sections.line_offset = offset;
8943 sections.line_size = size;
8944 break;
8945 case DW_SECT_LOCLISTS_V5:
8946 sections.loclists_offset = offset;
8947 sections.loclists_size = size;
8948 break;
8949 case DW_SECT_MACRO_V5:
8950 sections.macro_offset = offset;
8951 sections.macro_size = size;
8952 break;
8953 case DW_SECT_RNGLISTS_V5:
8954 sections.rnglists_offset = offset;
8955 sections.rnglists_size = size;
8956 break;
8957 case DW_SECT_STR_OFFSETS_V5:
8958 sections.str_offsets_offset = offset;
8959 sections.str_offsets_size = size;
8960 break;
8961 case DW_SECT_RESERVED_V5:
8962 default:
8963 break;
8964 }
8965 }
8966
8967 /* It's easier for the rest of the code if we fake a struct dwo_file and
8968 have dwo_unit "live" in that. At least for now.
8969
8970 The DWP file can be made up of a random collection of CUs and TUs.
8971 However, for each CU + set of TUs that came from the same original DWO
8972 file, we can combine them back into a virtual DWO file to save space
8973 (fewer struct dwo_file objects to allocate). Remember that for really
8974 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8975
8976 std::string virtual_dwo_name =
8977 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
8978 (long) (sections.abbrev_size ? sections.abbrev_offset : 0),
8979 (long) (sections.line_size ? sections.line_offset : 0),
8980 (long) (sections.loclists_size ? sections.loclists_offset : 0),
8981 (long) (sections.str_offsets_size
8982 ? sections.str_offsets_offset : 0),
8983 (long) (sections.macro_size ? sections.macro_offset : 0),
8984 (long) (sections.rnglists_size ? sections.rnglists_offset: 0));
8985 /* Can we use an existing virtual DWO file? */
8986 dwo_file_slot = lookup_dwo_file_slot (per_objfile,
8987 virtual_dwo_name.c_str (),
8988 comp_dir);
8989 /* Create one if necessary. */
8990 if (*dwo_file_slot == NULL)
8991 {
8992 dwarf_read_debug_printf ("Creating virtual DWO: %s",
8993 virtual_dwo_name.c_str ());
8994
8995 dwo_file = new struct dwo_file;
8996 dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name);
8998 dwo_file->sections.abbrev =
8999 create_dwp_v2_or_v5_section (per_objfile,
9000 &dwp_file->sections.abbrev,
9001 sections.abbrev_offset,
9002 sections.abbrev_size);
9003 dwo_file->sections.line =
9004 create_dwp_v2_or_v5_section (per_objfile,
9005 &dwp_file->sections.line,
9006 sections.line_offset, sections.line_size);
9007 dwo_file->sections.macro =
9008 create_dwp_v2_or_v5_section (per_objfile,
9009 &dwp_file->sections.macro,
9010 sections.macro_offset,
9011 sections.macro_size);
9012 dwo_file->sections.loclists =
9013 create_dwp_v2_or_v5_section (per_objfile,
9014 &dwp_file->sections.loclists,
9015 sections.loclists_offset,
9016 sections.loclists_size);
9017 dwo_file->sections.rnglists =
9018 create_dwp_v2_or_v5_section (per_objfile,
9019 &dwp_file->sections.rnglists,
9020 sections.rnglists_offset,
9021 sections.rnglists_size);
9022 dwo_file->sections.str_offsets =
9023 create_dwp_v2_or_v5_section (per_objfile,
9024 &dwp_file->sections.str_offsets,
9025 sections.str_offsets_offset,
9026 sections.str_offsets_size);
9027 /* The "str" section is global to the entire DWP file. */
9028 dwo_file->sections.str = dwp_file->sections.str;
9029 /* The info or types section is assigned below to dwo_unit,
9030 there's no need to record it in dwo_file.
9031 Also, we can't simply record type sections in dwo_file because
9032 we record a pointer into the vector in dwo_unit. As we collect more
9033 types we'll grow the vector and eventually have to reallocate space
9034 for it, invalidating all copies of pointers into the previous
9035 contents. */
9036 *dwo_file_slot = dwo_file;
9037 }
9038 else
9039 {
9040 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
9041 virtual_dwo_name.c_str ());
9042
9043 dwo_file = (struct dwo_file *) *dwo_file_slot;
9044 }
9045
9046 dwo_unit = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwo_unit);
9048 dwo_unit->signature = signature;
9050 = XOBNEW (&per_objfile->per_bfd->obstack, struct dwarf2_section_info);
9052 &dwp_file->sections.info,
9053 sections.info_or_types_offset,
9054 sections.info_or_types_size);
9055 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
9056
9057 return dwo_unit;
9058}
9059
9060/* Lookup the DWO unit with SIGNATURE in DWP_FILE.
9061 Returns NULL if the signature isn't found. */
9062
9063static struct dwo_unit *
9065 struct dwp_file *dwp_file, const char *comp_dir,
9066 ULONGEST signature, int is_debug_types)
9067{
9068 const struct dwp_hash_table *dwp_htab =
9069 is_debug_types ? dwp_file->tus : dwp_file->cus;
9070 bfd *dbfd = dwp_file->dbfd.get ();
9071 uint32_t mask = dwp_htab->nr_slots - 1;
9072 uint32_t hash = signature & mask;
9073 uint32_t hash2 = ((signature >> 32) & mask) | 1;
9074 unsigned int i;
9075 void **slot;
9076 struct dwo_unit find_dwo_cu;
9077
9078 memset (&find_dwo_cu, 0, sizeof (find_dwo_cu));
9079 find_dwo_cu.signature = signature;
9080 slot = htab_find_slot (is_debug_types
9081 ? dwp_file->loaded_tus.get ()
9082 : dwp_file->loaded_cus.get (),
9083 &find_dwo_cu, INSERT);
9084
9085 if (*slot != NULL)
9086 return (struct dwo_unit *) *slot;
9087
9088 /* Use a for loop so that we don't loop forever on bad debug info. */
9089 for (i = 0; i < dwp_htab->nr_slots; ++i)
9090 {
9091 ULONGEST signature_in_table;
9092
9093 signature_in_table =
9094 read_8_bytes (dbfd, dwp_htab->hash_table + hash * sizeof (uint64_t));
9095 if (signature_in_table == signature)
9096 {
9097 uint32_t unit_index =
9098 read_4_bytes (dbfd,
9099 dwp_htab->unit_table + hash * sizeof (uint32_t));
9100
9101 if (dwp_file->version == 1)
9102 {
9103 *slot = create_dwo_unit_in_dwp_v1 (per_objfile, dwp_file,
9104 unit_index, comp_dir,
9105 signature, is_debug_types);
9106 }
9107 else if (dwp_file->version == 2)
9108 {
9109 *slot = create_dwo_unit_in_dwp_v2 (per_objfile, dwp_file,
9110 unit_index, comp_dir,
9111 signature, is_debug_types);
9112 }
9113 else /* version == 5 */
9114 {
9115 *slot = create_dwo_unit_in_dwp_v5 (per_objfile, dwp_file,
9116 unit_index, comp_dir,
9117 signature, is_debug_types);
9118 }
9119 return (struct dwo_unit *) *slot;
9120 }
9121 if (signature_in_table == 0)
9122 return NULL;
9123 hash = (hash + hash2) & mask;
9124 }
9125
9126 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
9127 " [in module %s]"),
9128 dwp_file->name);
9129}
9130
9131/* Subroutine of open_dwo_file,open_dwp_file to simplify them.
9132 Open the file specified by FILE_NAME and hand it off to BFD for
9133 preliminary analysis. Return a newly initialized bfd *, which
9134 includes a canonicalized copy of FILE_NAME.
9135 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
9136 SEARCH_CWD is true if the current directory is to be searched.
9137 It will be searched before debug-file-directory.
9138 If successful, the file is added to the bfd include table of the
9139 objfile's bfd (see gdb_bfd_record_inclusion).
9140 If unable to find/open the file, return NULL.
9141 NOTE: This function is derived from symfile_bfd_open. */
9142
9143static gdb_bfd_ref_ptr
9145 const char *file_name, int is_dwp, int search_cwd)
9146{
9147 int desc;
9148 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
9149 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
9150 to debug_file_directory. */
9151 const char *search_path;
9152 static const char dirname_separator_string[] = { DIRNAME_SEPARATOR, '\0' };
9153
9154 gdb::unique_xmalloc_ptr<char> search_path_holder;
9155 if (search_cwd)
9156 {
9157 if (!debug_file_directory.empty ())
9158 {
9159 search_path_holder.reset (concat (".", dirname_separator_string,
9160 debug_file_directory.c_str (),
9161 (char *) NULL));
9162 search_path = search_path_holder.get ();
9163 }
9164 else
9165 search_path = ".";
9166 }
9167 else
9168 search_path = debug_file_directory.c_str ();
9169
9170 /* Add the path for the executable binary to the list of search paths. */
9171 std::string objfile_dir = ldirname (objfile_name (per_objfile->objfile));
9172 search_path_holder.reset (concat (objfile_dir.c_str (),
9173 dirname_separator_string,
9174 search_path, nullptr));
9175 search_path = search_path_holder.get ();
9176
9177 openp_flags flags = OPF_RETURN_REALPATH;
9178 if (is_dwp)
9180
9181 gdb::unique_xmalloc_ptr<char> absolute_name;
9182 desc = openp (search_path, flags, file_name,
9183 O_RDONLY | O_BINARY, &absolute_name);
9184 if (desc < 0)
9185 return NULL;
9186
9187 gdb_bfd_ref_ptr sym_bfd (gdb_bfd_open (absolute_name.get (),
9188 gnutarget, desc));
9189 if (sym_bfd == NULL)
9190 return NULL;
9191
9192 if (!bfd_check_format (sym_bfd.get (), bfd_object))
9193 return NULL;
9194
9195 /* Success. Record the bfd as having been included by the objfile's bfd.
9196 This is important because things like demangled_names_hash lives in the
9197 objfile's per_bfd space and may have references to things like symbol
9198 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
9199 gdb_bfd_record_inclusion (per_objfile->objfile->obfd.get (), sym_bfd.get ());
9200
9201 return sym_bfd;
9202}
9203
9204/* Try to open DWO file FILE_NAME.
9205 COMP_DIR is the DW_AT_comp_dir attribute.
9206 The result is the bfd handle of the file.
9207 If there is a problem finding or opening the file, return NULL.
9208 Upon success, the canonicalized path of the file is stored in the bfd,
9209 same as symfile_bfd_open. */
9210
9211static gdb_bfd_ref_ptr
9213 const char *file_name, const char *comp_dir)
9214{
9215 if (IS_ABSOLUTE_PATH (file_name))
9216 return try_open_dwop_file (per_objfile, file_name,
9217 0 /*is_dwp*/, 0 /*search_cwd*/);
9218
9219 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
9220
9221 if (comp_dir != NULL)
9222 {
9223 std::string path_to_try = path_join (comp_dir, file_name);
9224
9225 /* NOTE: If comp_dir is a relative path, this will also try the
9226 search path, which seems useful. */
9228 (per_objfile, path_to_try.c_str (), 0 /*is_dwp*/, 1 /*search_cwd*/));
9229
9230 if (abfd != NULL)
9231 return abfd;
9232 }
9233
9234 /* That didn't work, try debug-file-directory, which, despite its name,
9235 is a list of paths. */
9236
9237 if (debug_file_directory.empty ())
9238 return NULL;
9239
9240 return try_open_dwop_file (per_objfile, file_name,
9241 0 /*is_dwp*/, 1 /*search_cwd*/);
9242}
9243
9244/* This function is mapped across the sections and remembers the offset and
9245 size of each of the DWO debugging sections we are interested in. */
9246
9247static void
9249 asection *sectp, dwo_sections *dwo_sections)
9250{
9251 const struct dwop_section_names *names = &dwop_section_names;
9252
9253 struct dwarf2_section_info *dw_sect = nullptr;
9254
9255 if (names->abbrev_dwo.matches (sectp->name))
9256 dw_sect = &dwo_sections->abbrev;
9257 else if (names->info_dwo.matches (sectp->name))
9258 dw_sect = &dwo_sections->info;
9259 else if (names->line_dwo.matches (sectp->name))
9260 dw_sect = &dwo_sections->line;
9261 else if (names->loc_dwo.matches (sectp->name))
9262 dw_sect = &dwo_sections->loc;
9263 else if (names->loclists_dwo.matches (sectp->name))
9264 dw_sect = &dwo_sections->loclists;
9265 else if (names->macinfo_dwo.matches (sectp->name))
9266 dw_sect = &dwo_sections->macinfo;
9267 else if (names->macro_dwo.matches (sectp->name))
9268 dw_sect = &dwo_sections->macro;
9269 else if (names->rnglists_dwo.matches (sectp->name))
9270 dw_sect = &dwo_sections->rnglists;
9271 else if (names->str_dwo.matches (sectp->name))
9272 dw_sect = &dwo_sections->str;
9273 else if (names->str_offsets_dwo.matches (sectp->name))
9274 dw_sect = &dwo_sections->str_offsets;
9275 else if (names->types_dwo.matches (sectp->name))
9276 {
9277 struct dwarf2_section_info type_section;
9278
9279 memset (&type_section, 0, sizeof (type_section));
9280 dwo_sections->types.push_back (type_section);
9281 dw_sect = &dwo_sections->types.back ();
9282 }
9283
9284 if (dw_sect != nullptr)
9285 {
9286 dw_sect->s.section = sectp;
9287 dw_sect->size = bfd_section_size (sectp);
9288 dw_sect->read (objfile);
9289 }
9290}
9291
9292/* Initialize the use of the DWO file specified by DWO_NAME and referenced
9293 by PER_CU. This is for the non-DWP case.
9294 The result is NULL if DWO_NAME can't be found. */
9295
9296static struct dwo_file *
9298 const char *comp_dir)
9299{
9300 dwarf2_per_objfile *per_objfile = cu->per_objfile;
9301
9303 if (dbfd == NULL)
9304 {
9305 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name);
9306
9307 return NULL;
9308 }
9309
9310 dwo_file_up dwo_file (new struct dwo_file);
9313 dwo_file->dbfd = std::move (dbfd);
9314
9315 for (asection *sec : gdb_bfd_sections (dwo_file->dbfd))
9316 dwarf2_locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (),
9317 sec, &dwo_file->sections);
9318
9319 create_cus_hash_table (per_objfile, cu, *dwo_file, dwo_file->sections.info,
9320 dwo_file->cus);
9321
9322 if (cu->per_cu->version () < 5)
9323 {
9324 create_debug_types_hash_table (per_objfile, dwo_file.get (),
9325 dwo_file->sections.types, dwo_file->tus);
9326 }
9327 else
9328 {
9329 create_debug_type_hash_table (per_objfile, dwo_file.get (),
9330 &dwo_file->sections.info, dwo_file->tus,
9332 }
9333
9334 dwarf_read_debug_printf ("DWO file found: %s", dwo_name);
9335
9336 return dwo_file.release ();
9337}
9338
9339/* This function is mapped across the sections and remembers the offset and
9340 size of each of the DWP debugging sections common to version 1 and 2 that
9341 we are interested in. */
9342
9343static void
9345 asection *sectp, dwp_file *dwp_file)
9346{
9347 const struct dwop_section_names *names = &dwop_section_names;
9348 unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
9349
9350 /* Record the ELF section number for later lookup: this is what the
9351 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
9352 gdb_assert (elf_section_nr < dwp_file->num_sections);
9353 dwp_file->elf_sections[elf_section_nr] = sectp;
9354
9355 /* Look for specific sections that we need. */
9356 struct dwarf2_section_info *dw_sect = nullptr;
9357 if (names->str_dwo.matches (sectp->name))
9358 dw_sect = &dwp_file->sections.str;
9359 else if (names->cu_index.matches (sectp->name))
9360 dw_sect = &dwp_file->sections.cu_index;
9361 else if (names->tu_index.matches (sectp->name))
9362 dw_sect = &dwp_file->sections.tu_index;
9363
9364 if (dw_sect != nullptr)
9365 {
9366 dw_sect->s.section = sectp;
9367 dw_sect->size = bfd_section_size (sectp);
9368 dw_sect->read (objfile);
9369 }
9370}
9371
9372/* This function is mapped across the sections and remembers the offset and
9373 size of each of the DWP version 2 debugging sections that we are interested
9374 in. This is split into a separate function because we don't know if we
9375 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
9376
9377static void
9379 asection *sectp, void *dwp_file_ptr)
9380{
9381 struct dwp_file *dwp_file = (struct dwp_file *) dwp_file_ptr;
9382 const struct dwop_section_names *names = &dwop_section_names;
9383 unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
9384
9385 /* Record the ELF section number for later lookup: this is what the
9386 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
9387 gdb_assert (elf_section_nr < dwp_file->num_sections);
9388 dwp_file->elf_sections[elf_section_nr] = sectp;
9389
9390 /* Look for specific sections that we need. */
9391 struct dwarf2_section_info *dw_sect = nullptr;
9392 if (names->abbrev_dwo.matches (sectp->name))
9393 dw_sect = &dwp_file->sections.abbrev;
9394 else if (names->info_dwo.matches (sectp->name))
9395 dw_sect = &dwp_file->sections.info;
9396 else if (names->line_dwo.matches (sectp->name))
9397 dw_sect = &dwp_file->sections.line;
9398 else if (names->loc_dwo.matches (sectp->name))
9399 dw_sect = &dwp_file->sections.loc;
9400 else if (names->macinfo_dwo.matches (sectp->name))
9401 dw_sect = &dwp_file->sections.macinfo;
9402 else if (names->macro_dwo.matches (sectp->name))
9403 dw_sect = &dwp_file->sections.macro;
9404 else if (names->str_offsets_dwo.matches (sectp->name))
9405 dw_sect = &dwp_file->sections.str_offsets;
9406 else if (names->types_dwo.matches (sectp->name))
9407 dw_sect = &dwp_file->sections.types;
9408
9409 if (dw_sect != nullptr)
9410 {
9411 dw_sect->s.section = sectp;
9412 dw_sect->size = bfd_section_size (sectp);
9413 dw_sect->read (objfile);
9414 }
9415}
9416
9417/* This function is mapped across the sections and remembers the offset and
9418 size of each of the DWP version 5 debugging sections that we are interested
9419 in. This is split into a separate function because we don't know if we
9420 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
9421
9422static void
9424 asection *sectp, void *dwp_file_ptr)
9425{
9426 struct dwp_file *dwp_file = (struct dwp_file *) dwp_file_ptr;
9427 const struct dwop_section_names *names = &dwop_section_names;
9428 unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
9429
9430 /* Record the ELF section number for later lookup: this is what the
9431 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
9432 gdb_assert (elf_section_nr < dwp_file->num_sections);
9433 dwp_file->elf_sections[elf_section_nr] = sectp;
9434
9435 /* Look for specific sections that we need. */
9436 struct dwarf2_section_info *dw_sect = nullptr;
9437 if (names->abbrev_dwo.matches (sectp->name))
9438 dw_sect = &dwp_file->sections.abbrev;
9439 else if (names->info_dwo.matches (sectp->name))
9440 dw_sect = &dwp_file->sections.info;
9441 else if (names->line_dwo.matches (sectp->name))
9442 dw_sect = &dwp_file->sections.line;
9443 else if (names->loclists_dwo.matches (sectp->name))
9444 dw_sect = &dwp_file->sections.loclists;
9445 else if (names->macro_dwo.matches (sectp->name))
9446 dw_sect = &dwp_file->sections.macro;
9447 else if (names->rnglists_dwo.matches (sectp->name))
9448 dw_sect = &dwp_file->sections.rnglists;
9449 else if (names->str_offsets_dwo.matches (sectp->name))
9450 dw_sect = &dwp_file->sections.str_offsets;
9451
9452 if (dw_sect != nullptr)
9453 {
9454 dw_sect->s.section = sectp;
9455 dw_sect->size = bfd_section_size (sectp);
9456 dw_sect->read (objfile);
9457 }
9458}
9459
9460/* Hash function for dwp_file loaded CUs/TUs. */
9461
9462static hashval_t
9463hash_dwp_loaded_cutus (const void *item)
9464{
9465 const struct dwo_unit *dwo_unit = (const struct dwo_unit *) item;
9466
9467 /* This drops the top 32 bits of the signature, but is ok for a hash. */
9468 return dwo_unit->signature;
9469}
9470
9471/* Equality function for dwp_file loaded CUs/TUs. */
9472
9473static int
9474eq_dwp_loaded_cutus (const void *a, const void *b)
9475{
9476 const struct dwo_unit *dua = (const struct dwo_unit *) a;
9477 const struct dwo_unit *dub = (const struct dwo_unit *) b;
9478
9479 return dua->signature == dub->signature;
9480}
9481
9482/* Allocate a hash table for dwp_file loaded CUs/TUs. */
9483
9484static htab_up
9486{
9487 return htab_up (htab_create_alloc (3,
9490 NULL, xcalloc, xfree));
9491}
9492
9493/* Try to open DWP file FILE_NAME.
9494 The result is the bfd handle of the file.
9495 If there is a problem finding or opening the file, return NULL.
9496 Upon success, the canonicalized path of the file is stored in the bfd,
9497 same as symfile_bfd_open. */
9498
9499static gdb_bfd_ref_ptr
9500open_dwp_file (dwarf2_per_objfile *per_objfile, const char *file_name)
9501{
9502 gdb_bfd_ref_ptr abfd (try_open_dwop_file (per_objfile, file_name,
9503 1 /*is_dwp*/,
9504 1 /*search_cwd*/));
9505 if (abfd != NULL)
9506 return abfd;
9507
9508 /* Work around upstream bug 15652.
9509 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
9510 [Whether that's a "bug" is debatable, but it is getting in our way.]
9511 We have no real idea where the dwp file is, because gdb's realpath-ing
9512 of the executable's path may have discarded the needed info.
9513 [IWBN if the dwp file name was recorded in the executable, akin to
9514 .gnu_debuglink, but that doesn't exist yet.]
9515 Strip the directory from FILE_NAME and search again. */
9516 if (!debug_file_directory.empty ())
9517 {
9518 /* Don't implicitly search the current directory here.
9519 If the user wants to search "." to handle this case,
9520 it must be added to debug-file-directory. */
9521 return try_open_dwop_file (per_objfile, lbasename (file_name),
9522 1 /*is_dwp*/,
9523 0 /*search_cwd*/);
9524 }
9525
9526 return NULL;
9527}
9528
9529/* Initialize the use of the DWP file for the current objfile.
9530 By convention the name of the DWP file is ${objfile}.dwp.
9531 The result is NULL if it can't be found. */
9532
9533static std::unique_ptr<struct dwp_file>
9535{
9536 struct objfile *objfile = per_objfile->objfile;
9537
9538 /* Try to find first .dwp for the binary file before any symbolic links
9539 resolving. */
9540
9541 /* If the objfile is a debug file, find the name of the real binary
9542 file and get the name of dwp file from there. */
9543 std::string dwp_name;
9545 {
9547 const char *backlink_basename = lbasename (backlink->original_name);
9548
9549 dwp_name = ldirname (objfile->original_name) + SLASH_STRING + backlink_basename;
9550 }
9551 else
9552 dwp_name = objfile->original_name;
9553
9554 dwp_name += ".dwp";
9555
9556 gdb_bfd_ref_ptr dbfd (open_dwp_file (per_objfile, dwp_name.c_str ()));
9557 if (dbfd == NULL
9558 && strcmp (objfile->original_name, objfile_name (objfile)) != 0)
9559 {
9560 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
9561 dwp_name = objfile_name (objfile);
9562 dwp_name += ".dwp";
9563 dbfd = open_dwp_file (per_objfile, dwp_name.c_str ());
9564 }
9565
9566 if (dbfd == NULL)
9567 {
9568 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name.c_str ());
9569
9570 return std::unique_ptr<dwp_file> ();
9571 }
9572
9573 const char *name = bfd_get_filename (dbfd.get ());
9574 std::unique_ptr<struct dwp_file> dwp_file
9575 (new struct dwp_file (name, std::move (dbfd)));
9576
9577 dwp_file->num_sections = elf_numsections (dwp_file->dbfd);
9579 OBSTACK_CALLOC (&per_objfile->per_bfd->obstack,
9580 dwp_file->num_sections, asection *);
9581
9582 for (asection *sec : gdb_bfd_sections (dwp_file->dbfd))
9584 dwp_file.get ());
9585
9586 dwp_file->cus = create_dwp_hash_table (per_objfile, dwp_file.get (), 0);
9587
9588 dwp_file->tus = create_dwp_hash_table (per_objfile, dwp_file.get (), 1);
9589
9590 /* The DWP file version is stored in the hash table. Oh well. */
9591 if (dwp_file->cus && dwp_file->tus
9593 {
9594 /* Technically speaking, we should try to limp along, but this is
9595 pretty bizarre. We use pulongest here because that's the established
9596 portability solution (e.g, we cannot use %u for uint32_t). */
9597 error (_("Dwarf Error: DWP file CU version %s doesn't match"
9598 " TU version %s [in DWP file %s]"),
9599 pulongest (dwp_file->cus->version),
9600 pulongest (dwp_file->tus->version), dwp_name.c_str ());
9601 }
9602
9603 if (dwp_file->cus)
9605 else if (dwp_file->tus)
9607 else
9608 dwp_file->version = 2;
9609
9610 for (asection *sec : gdb_bfd_sections (dwp_file->dbfd))
9611 {
9612 if (dwp_file->version == 2)
9614 dwp_file.get ());
9615 else
9617 dwp_file.get ());
9618 }
9619
9622
9623 dwarf_read_debug_printf ("DWP file found: %s", dwp_file->name);
9624 dwarf_read_debug_printf (" %s CUs, %s TUs",
9625 pulongest (dwp_file->cus ? dwp_file->cus->nr_units : 0),
9626 pulongest (dwp_file->tus ? dwp_file->tus->nr_units : 0));
9627
9628 return dwp_file;
9629}
9630
9631/* Wrapper around open_and_init_dwp_file, only open it once. */
9632
9633static struct dwp_file *
9635{
9636 if (!per_objfile->per_bfd->dwp_checked)
9637 {
9638 per_objfile->per_bfd->dwp_file = open_and_init_dwp_file (per_objfile);
9639 per_objfile->per_bfd->dwp_checked = 1;
9640 }
9641 return per_objfile->per_bfd->dwp_file.get ();
9642}
9643
9644/* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9645 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9646 or in the DWP file for the objfile, referenced by THIS_UNIT.
9647 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9648 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9649
9650 This is called, for example, when wanting to read a variable with a
9651 complex location. Therefore we don't want to do file i/o for every call.
9652 Therefore we don't want to look for a DWO file on every call.
9653 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9654 then we check if we've already seen DWO_NAME, and only THEN do we check
9655 for a DWO file.
9656
9657 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9658 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9659
9660static struct dwo_unit *
9661lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
9662 ULONGEST signature, int is_debug_types)
9663{
9664 dwarf2_per_objfile *per_objfile = cu->per_objfile;
9665 struct objfile *objfile = per_objfile->objfile;
9666 const char *kind = is_debug_types ? "TU" : "CU";
9667 void **dwo_file_slot;
9668 struct dwo_file *dwo_file;
9669 struct dwp_file *dwp_file;
9670
9671 /* First see if there's a DWP file.
9672 If we have a DWP file but didn't find the DWO inside it, don't
9673 look for the original DWO file. It makes gdb behave differently
9674 depending on whether one is debugging in the build tree. */
9675
9676 dwp_file = get_dwp_file (per_objfile);
9677 if (dwp_file != NULL)
9678 {
9679 const struct dwp_hash_table *dwp_htab =
9680 is_debug_types ? dwp_file->tus : dwp_file->cus;
9681
9682 if (dwp_htab != NULL)
9683 {
9684 struct dwo_unit *dwo_cutu =
9685 lookup_dwo_unit_in_dwp (per_objfile, dwp_file, comp_dir, signature,
9686 is_debug_types);
9687
9688 if (dwo_cutu != NULL)
9689 {
9690 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
9691 kind, hex_string (signature),
9692 host_address_to_string (dwo_cutu));
9693
9694 return dwo_cutu;
9695 }
9696 }
9697 }
9698 else
9699 {
9700 /* No DWP file, look for the DWO file. */
9701
9702 dwo_file_slot = lookup_dwo_file_slot (per_objfile, dwo_name, comp_dir);
9703 if (*dwo_file_slot == NULL)
9704 {
9705 /* Read in the file and build a table of the CUs/TUs it contains. */
9706 *dwo_file_slot = open_and_init_dwo_file (cu, dwo_name, comp_dir);
9707 }
9708 /* NOTE: This will be NULL if unable to open the file. */
9709 dwo_file = (struct dwo_file *) *dwo_file_slot;
9710
9711 if (dwo_file != NULL)
9712 {
9713 struct dwo_unit *dwo_cutu = NULL;
9714
9715 if (is_debug_types && dwo_file->tus)
9716 {
9717 struct dwo_unit find_dwo_cutu;
9718
9719 memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
9720 find_dwo_cutu.signature = signature;
9721 dwo_cutu
9722 = (struct dwo_unit *) htab_find (dwo_file->tus.get (),
9723 &find_dwo_cutu);
9724 }
9725 else if (!is_debug_types && dwo_file->cus)
9726 {
9727 struct dwo_unit find_dwo_cutu;
9728
9729 memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
9730 find_dwo_cutu.signature = signature;
9731 dwo_cutu = (struct dwo_unit *)htab_find (dwo_file->cus.get (),
9732 &find_dwo_cutu);
9733 }
9734
9735 if (dwo_cutu != NULL)
9736 {
9737 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
9738 kind, dwo_name, hex_string (signature),
9739 host_address_to_string (dwo_cutu));
9740
9741 return dwo_cutu;
9742 }
9743 }
9744 }
9745
9746 /* We didn't find it. This could mean a dwo_id mismatch, or
9747 someone deleted the DWO/DWP file, or the search path isn't set up
9748 correctly to find the file. */
9749
9750 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
9751 kind, dwo_name, hex_string (signature));
9752
9753 /* This is a warning and not a complaint because it can be caused by
9754 pilot error (e.g., user accidentally deleting the DWO). */
9755 {
9756 /* Print the name of the DWP file if we looked there, helps the user
9757 better diagnose the problem. */
9758 std::string dwp_text;
9759
9760 if (dwp_file != NULL)
9761 dwp_text = string_printf (" [in DWP file %s]",
9762 lbasename (dwp_file->name));
9763
9764 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
9765 " [in module %s]"),
9766 kind, dwo_name, hex_string (signature), dwp_text.c_str (), kind,
9768 }
9769 return NULL;
9770}
9771
9772/* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9773 See lookup_dwo_cutu_unit for details. */
9774
9775static struct dwo_unit *
9776lookup_dwo_comp_unit (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
9777 ULONGEST signature)
9778{
9779 gdb_assert (!cu->per_cu->is_debug_types);
9780
9781 return lookup_dwo_cutu (cu, dwo_name, comp_dir, signature, 0);
9782}
9783
9784/* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9785 See lookup_dwo_cutu_unit for details. */
9786
9787static struct dwo_unit *
9788lookup_dwo_type_unit (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir)
9789{
9790 gdb_assert (cu->per_cu->is_debug_types);
9791
9792 signatured_type *sig_type = (signatured_type *) cu->per_cu;
9793
9794 return lookup_dwo_cutu (cu, dwo_name, comp_dir, sig_type->signature, 1);
9795}
9796
9797/* Traversal function for queue_and_load_all_dwo_tus. */
9798
9799static int
9800queue_and_load_dwo_tu (void **slot, void *info)
9801{
9802 struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot;
9803 dwarf2_cu *cu = (dwarf2_cu *) info;
9804 ULONGEST signature = dwo_unit->signature;
9806
9807 if (sig_type != NULL)
9808 {
9809 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
9810 a real dependency of PER_CU on SIG_TYPE. That is detected later
9811 while processing PER_CU. */
9812 if (maybe_queue_comp_unit (NULL, sig_type, cu->per_objfile,
9813 cu->lang ()))
9814 load_full_type_unit (sig_type, cu->per_objfile);
9815 cu->per_cu->imported_symtabs_push (sig_type);
9816 }
9817
9818 return 1;
9819}
9820
9821/* Queue all TUs contained in the DWO of CU to be read in.
9822 The DWO may have the only definition of the type, though it may not be
9823 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
9824 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
9825
9826static void
9828{
9829 struct dwo_unit *dwo_unit;
9830 struct dwo_file *dwo_file;
9831
9832 gdb_assert (cu != nullptr);
9833 gdb_assert (!cu->per_cu->is_debug_types);
9834 gdb_assert (get_dwp_file (cu->per_objfile) == nullptr);
9835
9836 dwo_unit = cu->dwo_unit;
9837 gdb_assert (dwo_unit != NULL);
9838
9840 if (dwo_file->tus != NULL)
9841 htab_traverse_noresize (dwo_file->tus.get (), queue_and_load_dwo_tu, cu);
9842}
9843
9844/* Read in various DIEs. */
9845
9846/* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9847 Inherit only the children of the DW_AT_abstract_origin DIE not being
9848 already referenced by DW_AT_abstract_origin from the children of the
9849 current DIE. */
9850
9851static void
9853{
9854 attribute *attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
9855 if (attr == nullptr)
9856 return;
9857
9858 /* Note that following die references may follow to a die in a
9859 different CU. */
9860 dwarf2_cu *origin_cu = cu;
9861
9862 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9863 die_info *origin_die = follow_die_ref (die, attr, &origin_cu);
9864
9865 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9866 symbols in. */
9867 struct pending **origin_previous_list_in_scope = origin_cu->list_in_scope;
9868 origin_cu->list_in_scope = cu->list_in_scope;
9869
9870 if (die->tag != origin_die->tag
9871 && !(die->tag == DW_TAG_inlined_subroutine
9872 && origin_die->tag == DW_TAG_subprogram))
9873 complaint (_("DIE %s and its abstract origin %s have different tags"),
9875 sect_offset_str (origin_die->sect_off));
9876
9877 /* Find if the concrete and abstract trees are structurally the
9878 same. This is a shallow traversal and it is not bullet-proof;
9879 the compiler can trick the debugger into believing that the trees
9880 are isomorphic, whereas they actually are not. However, the
9881 likelihood of this happening is pretty low, and a full-fledged
9882 check would be an overkill. */
9883 bool are_isomorphic = true;
9884 die_info *concrete_child = die->child;
9885 die_info *abstract_child = origin_die->child;
9886 while (concrete_child != nullptr || abstract_child != nullptr)
9887 {
9888 if (concrete_child == nullptr
9889 || abstract_child == nullptr
9890 || concrete_child->tag != abstract_child->tag)
9891 {
9892 are_isomorphic = false;
9893 break;
9894 }
9895
9896 concrete_child = concrete_child->sibling;
9897 abstract_child = abstract_child->sibling;
9898 }
9899
9900 /* Walk the origin's children in parallel to the concrete children.
9901 This helps match an origin child in case the debug info misses
9902 DW_AT_abstract_origin attributes. Keep in mind that the abstract
9903 origin tree may not have the same tree structure as the concrete
9904 DIE, though. */
9905 die_info *corresponding_abstract_child
9906 = are_isomorphic ? origin_die->child : nullptr;
9907
9908 std::vector<sect_offset> offsets;
9909
9910 for (die_info *child_die = die->child;
9911 child_die && child_die->tag;
9912 child_die = child_die->sibling)
9913 {
9914 /* We are trying to process concrete instance entries:
9915 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
9916 it's not relevant to our analysis here. i.e. detecting DIEs that are
9917 present in the abstract instance but not referenced in the concrete
9918 one. */
9919 if (child_die->tag == DW_TAG_call_site
9920 || child_die->tag == DW_TAG_GNU_call_site)
9921 {
9922 if (are_isomorphic)
9923 corresponding_abstract_child
9924 = corresponding_abstract_child->sibling;
9925 continue;
9926 }
9927
9928 /* For each CHILD_DIE, find the corresponding child of
9929 ORIGIN_DIE. If there is more than one layer of
9930 DW_AT_abstract_origin, follow them all; there shouldn't be,
9931 but GCC versions at least through 4.4 generate this (GCC PR
9932 40573). */
9933 die_info *child_origin_die = child_die;
9934 dwarf2_cu *child_origin_cu = cu;
9935 while (true)
9936 {
9937 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
9938 child_origin_cu);
9939 if (attr == nullptr)
9940 break;
9941
9942 die_info *prev_child_origin_die = child_origin_die;
9943 child_origin_die = follow_die_ref (child_origin_die, attr,
9944 &child_origin_cu);
9945
9946 if (prev_child_origin_die == child_origin_die)
9947 {
9948 /* Handle DIE with self-reference. */
9949 break;
9950 }
9951 }
9952
9953 /* If missing DW_AT_abstract_origin, try the corresponding child
9954 of the origin. Clang emits such lexical scopes. */
9955 if (child_origin_die == child_die
9956 && dwarf2_attr (child_die, DW_AT_abstract_origin, cu) == nullptr
9957 && are_isomorphic
9958 && child_die->tag == DW_TAG_lexical_block)
9959 child_origin_die = corresponding_abstract_child;
9960
9961 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9962 counterpart may exist. */
9963 if (child_origin_die != child_die)
9964 {
9965 if (child_die->tag != child_origin_die->tag
9966 && !(child_die->tag == DW_TAG_inlined_subroutine
9967 && child_origin_die->tag == DW_TAG_subprogram))
9968 complaint (_("Child DIE %s and its abstract origin %s have "
9969 "different tags"),
9970 sect_offset_str (child_die->sect_off),
9971 sect_offset_str (child_origin_die->sect_off));
9972 if (child_origin_die->parent != origin_die)
9973 complaint (_("Child DIE %s and its abstract origin %s have "
9974 "different parents"),
9975 sect_offset_str (child_die->sect_off),
9976 sect_offset_str (child_origin_die->sect_off));
9977 else
9978 offsets.push_back (child_origin_die->sect_off);
9979 }
9980
9981 if (are_isomorphic)
9982 corresponding_abstract_child = corresponding_abstract_child->sibling;
9983 }
9984
9985 if (!offsets.empty ())
9986 {
9987 std::sort (offsets.begin (), offsets.end ());
9988
9989 for (auto offsets_it = offsets.begin () + 1;
9990 offsets_it < offsets.end ();
9991 ++offsets_it)
9992 if (*(offsets_it - 1) == *offsets_it)
9993 complaint (_("Multiple children of DIE %s refer "
9994 "to DIE %s as their abstract origin"),
9996 sect_offset_str (*offsets_it));
9997 }
9998
9999 auto offsets_it = offsets.begin ();
10000 die_info *origin_child_die = origin_die->child;
10001 while (origin_child_die != nullptr && origin_child_die->tag != 0)
10002 {
10003 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
10004 while (offsets_it < offsets.end ()
10005 && *offsets_it < origin_child_die->sect_off)
10006 ++offsets_it;
10007
10008 if (offsets_it == offsets.end ()
10009 || *offsets_it > origin_child_die->sect_off)
10010 {
10011 /* Found that ORIGIN_CHILD_DIE is really not referenced.
10012 Check whether we're already processing ORIGIN_CHILD_DIE.
10013 This can happen with mutually referenced abstract_origins.
10014 PR 16581. */
10015 if (!origin_child_die->in_process)
10016 process_die (origin_child_die, origin_cu);
10017 }
10018
10019 origin_child_die = origin_child_die->sibling;
10020 }
10021
10022 origin_cu->list_in_scope = origin_previous_list_in_scope;
10023
10024 if (cu != origin_cu)
10025 compute_delayed_physnames (origin_cu);
10026}
10027
10028/* Return TRUE if the given DIE is the program's "main". DWARF 4 has
10029 defined a dedicated DW_AT_main_subprogram attribute to indicate the
10030 starting function of the program, however with older versions the
10031 DW_CC_program value of the DW_AT_calling_convention attribute was
10032 used instead as the only means available. We handle both variants. */
10033
10034static bool
10036{
10037 if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu))
10038 return true;
10039 struct attribute *attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
10040 return (attr != nullptr
10041 && attr->constant_value (DW_CC_normal) == DW_CC_program);
10042}
10043
10044/* A helper to handle Ada's "Pragma Import" feature when it is applied
10045 to a function. */
10046
10047static bool
10049{
10050 /* A Pragma Import will have both a name and a linkage name. */
10051 const char *name = dwarf2_name (die, cu);
10052 if (name == nullptr)
10053 return false;
10054
10055 const char *linkage_name = dw2_linkage_name (die, cu);
10056 /* Disallow the special Ada symbols. */
10057 if (!is_ada_import_or_export (cu, name, linkage_name))
10058 return false;
10059
10060 /* A Pragma Import will be a declaration, while a Pragma Export will
10061 not be. */
10062 if (!die_is_declaration (die, cu))
10063 return false;
10064
10065 new_symbol (die, read_type_die (die, cu), cu);
10066 return true;
10067}
10068
10069static void
10070read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
10071{
10072 dwarf2_per_objfile *per_objfile = cu->per_objfile;
10073 struct objfile *objfile = per_objfile->objfile;
10074 struct gdbarch *gdbarch = objfile->arch ();
10075 struct context_stack *newobj;
10076 CORE_ADDR lowpc;
10077 CORE_ADDR highpc;
10078 struct die_info *child_die;
10079 struct attribute *attr, *call_line, *call_file;
10080 const char *name;
10081 struct block *block;
10082 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
10083 std::vector<struct symbol *> template_args;
10084 struct template_symbol *templ_func = NULL;
10085
10086 if (inlined_func)
10087 {
10088 /* If we do not have call site information, we can't show the
10089 caller of this inlined function. That's too confusing, so
10090 only use the scope for local variables. */
10091 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
10092 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
10093 if (call_line == NULL || call_file == NULL)
10094 {
10095 read_lexical_block_scope (die, cu);
10096 return;
10097 }
10098 }
10099
10100 name = dwarf2_name (die, cu);
10101 if (name == nullptr)
10102 name = dw2_linkage_name (die, cu);
10103
10104 /* Ignore functions with missing or empty names. These are actually
10105 illegal according to the DWARF standard. */
10106 if (name == NULL)
10107 {
10108 complaint (_("missing name for subprogram DIE at %s"),
10109 sect_offset_str (die->sect_off));
10110 return;
10111 }
10112
10113 if (check_ada_pragma_import (die, cu))
10114 {
10115 /* We already made the symbol for the Pragma Import, and because
10116 it is a declaration, we know it won't have any other
10117 important information, so we can simply return. */
10118 return;
10119 }
10120
10121 /* Ignore functions with missing or invalid low and high pc attributes. */
10122 unrelocated_addr unrel_low, unrel_high;
10123 if (dwarf2_get_pc_bounds (die, &unrel_low, &unrel_high, cu, nullptr, nullptr)
10125 {
10126 if (have_complaint ())
10127 {
10128 attr = dwarf2_attr (die, DW_AT_external, cu);
10129 bool external_p = attr != nullptr && attr->as_boolean ();
10130 attr = dwarf2_attr (die, DW_AT_inline, cu);
10131 bool inlined_p
10132 = (attr != nullptr
10133 && attr->is_nonnegative ()
10134 && (attr->as_nonnegative () == DW_INL_inlined
10135 || attr->as_nonnegative () == DW_INL_declared_inlined));
10136 attr = dwarf2_attr (die, DW_AT_declaration, cu);
10137 bool decl_p = attr != nullptr && attr->as_boolean ();
10138 if (!external_p && !inlined_p && !decl_p)
10139 complaint (_("cannot get low and high bounds "
10140 "for subprogram DIE at %s"),
10141 sect_offset_str (die->sect_off));
10142 }
10143 return;
10144 }
10145
10146 lowpc = per_objfile->relocate (unrel_low);
10147 highpc = per_objfile->relocate (unrel_high);
10148
10149 /* If we have any template arguments, then we must allocate a
10150 different sort of symbol. */
10151 for (child_die = die->child; child_die; child_die = child_die->sibling)
10152 {
10153 if (child_die->tag == DW_TAG_template_type_param
10154 || child_die->tag == DW_TAG_template_value_param)
10155 {
10156 templ_func = new (&objfile->objfile_obstack) template_symbol;
10157 templ_func->subclass = SYMBOL_TEMPLATE;
10158 break;
10159 }
10160 }
10161
10162 gdb_assert (cu->get_builder () != nullptr);
10163 newobj = cu->get_builder ()->push_context (0, lowpc);
10164 newobj->name = new_symbol (die, read_type_die (die, cu), cu, templ_func);
10165
10166 if (dwarf2_func_is_main_p (die, cu))
10168 cu->lang ());
10169
10170 /* If there is a location expression for DW_AT_frame_base, record
10171 it. */
10172 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
10173 if (attr != nullptr)
10174 dwarf2_symbol_mark_computed (attr, newobj->name, cu, 1);
10175
10176 /* If there is a location for the static link, record it. */
10177 newobj->static_link = NULL;
10178 attr = dwarf2_attr (die, DW_AT_static_link, cu);
10179 if (attr != nullptr)
10180 {
10181 newobj->static_link
10182 = XOBNEW (&objfile->objfile_obstack, struct dynamic_prop);
10183 attr_to_dynamic_prop (attr, die, cu, newobj->static_link,
10184 cu->addr_type ());
10185 }
10186
10188
10189 if (die->child != NULL)
10190 {
10191 child_die = die->child;
10192 while (child_die && child_die->tag)
10193 {
10194 if (child_die->tag == DW_TAG_template_type_param
10195 || child_die->tag == DW_TAG_template_value_param)
10196 {
10197 struct symbol *arg = new_symbol (child_die, NULL, cu);
10198
10199 if (arg != NULL)
10200 template_args.push_back (arg);
10201 }
10202 else
10203 process_die (child_die, cu);
10204 child_die = child_die->sibling;
10205 }
10206 }
10207
10208 inherit_abstract_dies (die, cu);
10209
10210 /* If we have a DW_AT_specification, we might need to import using
10211 directives from the context of the specification DIE. See the
10212 comment in determine_prefix. */
10213 if (cu->lang () == language_cplus
10214 && dwarf2_attr (die, DW_AT_specification, cu))
10215 {
10216 struct dwarf2_cu *spec_cu = cu;
10217 struct die_info *spec_die = die_specification (die, &spec_cu);
10218
10219 while (spec_die)
10220 {
10221 child_die = spec_die->child;
10222 while (child_die && child_die->tag)
10223 {
10224 if (child_die->tag == DW_TAG_imported_module)
10225 process_die (child_die, spec_cu);
10226 child_die = child_die->sibling;
10227 }
10228
10229 /* In some cases, GCC generates specification DIEs that
10230 themselves contain DW_AT_specification attributes. */
10231 spec_die = die_specification (spec_die, &spec_cu);
10232 }
10233 }
10234
10235 struct context_stack cstk = cu->get_builder ()->pop_context ();
10236 /* Make a block for the local symbols within. */
10237 block = cu->get_builder ()->finish_block (cstk.name, cstk.old_blocks,
10238 cstk.static_link, lowpc, highpc);
10239
10240 /* For C++, set the block's scope. */
10241 if ((cu->lang () == language_cplus
10242 || cu->lang () == language_fortran
10243 || cu->lang () == language_d
10244 || cu->lang () == language_rust)
10246 block->set_scope (determine_prefix (die, cu),
10248
10249 /* If we have address ranges, record them. */
10251
10253
10254 /* Attach template arguments to function. */
10255 if (!template_args.empty ())
10256 {
10257 gdb_assert (templ_func != NULL);
10258
10259 templ_func->n_template_arguments = template_args.size ();
10260 templ_func->template_arguments
10261 = XOBNEWVEC (&objfile->objfile_obstack, struct symbol *,
10262 templ_func->n_template_arguments);
10263 memcpy (templ_func->template_arguments,
10264 template_args.data (),
10265 (templ_func->n_template_arguments * sizeof (struct symbol *)));
10266
10267 /* Make sure that the symtab is set on the new symbols. Even
10268 though they don't appear in this symtab directly, other parts
10269 of gdb assume that symbols do, and this is reasonably
10270 true. */
10271 for (symbol *sym : template_args)
10272 sym->set_symtab (templ_func->symtab ());
10273 }
10274
10275 /* In C++, we can have functions nested inside functions (e.g., when
10276 a function declares a class that has methods). This means that
10277 when we finish processing a function scope, we may need to go
10278 back to building a containing block's symbol lists. */
10279 *cu->get_builder ()->get_local_symbols () = cstk.locals;
10281
10282 /* If we've finished processing a top-level function, subsequent
10283 symbols go in the file symbol list. */
10284 if (cu->get_builder ()->outermost_context_p ())
10286}
10287
10288/* Process all the DIES contained within a lexical block scope. Start
10289 a new scope, process the dies, and then close the scope. */
10290
10291static void
10293{
10294 dwarf2_per_objfile *per_objfile = cu->per_objfile;
10295 CORE_ADDR lowpc, highpc;
10296 struct die_info *child_die;
10297
10298 /* Ignore blocks with missing or invalid low and high pc attributes. */
10299 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
10300 as multiple lexical blocks? Handling children in a sane way would
10301 be nasty. Might be easier to properly extend generic blocks to
10302 describe ranges. */
10303 unrelocated_addr unrel_low, unrel_high;
10304 switch (dwarf2_get_pc_bounds (die, &unrel_low, &unrel_high, cu,
10305 nullptr, nullptr))
10306 {
10308 /* DW_TAG_lexical_block has no attributes, process its children as if
10309 there was no wrapping by that DW_TAG_lexical_block.
10310 GCC does no longer produces such DWARF since GCC r224161. */
10311 for (child_die = die->child;
10312 child_die != NULL && child_die->tag;
10313 child_die = child_die->sibling)
10314 {
10315 /* We might already be processing this DIE. This can happen
10316 in an unusual circumstance -- where a subroutine A
10317 appears lexically in another subroutine B, but A actually
10318 inlines B. The recursion is broken here, rather than in
10319 inherit_abstract_dies, because it seems better to simply
10320 drop concrete children here. */
10321 if (!child_die->in_process)
10322 process_die (child_die, cu);
10323 }
10324 return;
10325 case PC_BOUNDS_INVALID:
10326 return;
10327 }
10328 lowpc = per_objfile->relocate (unrel_low);
10329 highpc = per_objfile->relocate (unrel_high);
10330
10331 cu->get_builder ()->push_context (0, lowpc);
10332 if (die->child != NULL)
10333 {
10334 child_die = die->child;
10335 while (child_die && child_die->tag)
10336 {
10337 process_die (child_die, cu);
10338 child_die = child_die->sibling;
10339 }
10340 }
10341 inherit_abstract_dies (die, cu);
10342 struct context_stack cstk = cu->get_builder ()->pop_context ();
10343
10344 if (*cu->get_builder ()->get_local_symbols () != NULL
10345 || (*cu->get_builder ()->get_local_using_directives ()) != NULL)
10346 {
10347 struct block *block
10348 = cu->get_builder ()->finish_block (0, cstk.old_blocks, NULL,
10349 cstk.start_addr, highpc);
10350
10351 /* Note that recording ranges after traversing children, as we
10352 do here, means that recording a parent's ranges entails
10353 walking across all its children's ranges as they appear in
10354 the address map, which is quadratic behavior.
10355
10356 It would be nicer to record the parent's ranges before
10357 traversing its children, simply overriding whatever you find
10358 there. But since we don't even decide whether to create a
10359 block until after we've traversed its children, that's hard
10360 to do. */
10362 }
10363 *cu->get_builder ()->get_local_symbols () = cstk.locals;
10365}
10366
10368 (unsigned offset,
10369 struct dwarf2_cu *cu,
10370 dwarf_tag tag,
10371 std::vector<unrelocated_addr> &result);
10372
10373/* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
10374
10375static void
10376read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
10377{
10378 dwarf2_per_objfile *per_objfile = cu->per_objfile;
10379 struct objfile *objfile = per_objfile->objfile;
10380 struct gdbarch *gdbarch = objfile->arch ();
10381 struct attribute *attr;
10382 void **slot;
10383 int nparams;
10384 struct die_info *child_die;
10385
10386 attr = dwarf2_attr (die, DW_AT_call_return_pc, cu);
10387 if (attr == NULL)
10388 {
10389 /* This was a pre-DWARF-5 GNU extension alias
10390 for DW_AT_call_return_pc. */
10391 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
10392 }
10393 if (!attr)
10394 {
10395 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
10396 "DIE %s [in module %s]"),
10398 return;
10399 }
10400 unrelocated_addr pc = per_objfile->adjust (attr->as_address ());
10401
10402 if (cu->call_site_htab == NULL)
10403 cu->call_site_htab = htab_create_alloc_ex (16, call_site::hash,
10404 call_site::eq, NULL,
10406 hashtab_obstack_allocate, NULL);
10407 struct call_site call_site_local (pc, nullptr, nullptr);
10408 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
10409 if (*slot != NULL)
10410 {
10411 complaint (_("Duplicate PC %s for DW_TAG_call_site "
10412 "DIE %s [in module %s]"),
10413 paddress (gdbarch, (CORE_ADDR) pc), sect_offset_str (die->sect_off),
10415 return;
10416 }
10417
10418 /* Count parameters at the caller. */
10419
10420 nparams = 0;
10421 for (child_die = die->child; child_die && child_die->tag;
10422 child_die = child_die->sibling)
10423 {
10424 if (child_die->tag != DW_TAG_call_site_parameter
10425 && child_die->tag != DW_TAG_GNU_call_site_parameter)
10426 {
10427 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
10428 "DW_TAG_call_site child DIE %s [in module %s]"),
10429 child_die->tag, sect_offset_str (child_die->sect_off),
10431 continue;
10432 }
10433
10434 nparams++;
10435 }
10436
10437 struct call_site *call_site
10438 = new (XOBNEWVAR (&objfile->objfile_obstack,
10439 struct call_site,
10440 sizeof (*call_site) + sizeof (call_site->parameter[0]) * nparams))
10441 struct call_site (pc, cu->per_cu, per_objfile);
10442 *slot = call_site;
10443
10444 /* We never call the destructor of call_site, so we must ensure it is
10445 trivially destructible. */
10446 gdb_static_assert(std::is_trivially_destructible<struct call_site>::value);
10447
10448 if (dwarf2_flag_true_p (die, DW_AT_call_tail_call, cu)
10449 || dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
10450 {
10451 struct die_info *func_die;
10452
10453 /* Skip also over DW_TAG_inlined_subroutine. */
10454 for (func_die = die->parent;
10455 func_die && func_die->tag != DW_TAG_subprogram
10456 && func_die->tag != DW_TAG_subroutine_type;
10457 func_die = func_die->parent);
10458
10459 /* DW_AT_call_all_calls is a superset
10460 of DW_AT_call_all_tail_calls. */
10461 if (func_die
10462 && !dwarf2_flag_true_p (func_die, DW_AT_call_all_calls, cu)
10463 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
10464 && !dwarf2_flag_true_p (func_die, DW_AT_call_all_tail_calls, cu)
10465 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
10466 {
10467 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
10468 not complete. But keep CALL_SITE for look ups via call_site_htab,
10469 both the initial caller containing the real return address PC and
10470 the final callee containing the current PC of a chain of tail
10471 calls do not need to have the tail call list complete. But any
10472 function candidate for a virtual tail call frame searched via
10473 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
10474 determined unambiguously. */
10475 }
10476 else
10477 {
10478 struct type *func_type = NULL;
10479
10480 if (func_die)
10481 func_type = get_die_type (func_die, cu);
10482 if (func_type != NULL)
10483 {
10484 gdb_assert (func_type->code () == TYPE_CODE_FUNC);
10485
10486 /* Enlist this call site to the function. */
10489 }
10490 else
10491 complaint (_("Cannot find function owning DW_TAG_call_site "
10492 "DIE %s [in module %s]"),
10494 }
10495 }
10496
10497 attr = dwarf2_attr (die, DW_AT_call_target, cu);
10498 if (attr == NULL)
10499 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
10500 if (attr == NULL)
10501 attr = dwarf2_attr (die, DW_AT_call_origin, cu);
10502 if (attr == NULL)
10503 {
10504 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
10505 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
10506 }
10507
10508 call_site->target.set_loc_dwarf_block (nullptr);
10509 if (!attr || (attr->form_is_block () && attr->as_block ()->size == 0))
10510 /* Keep NULL DWARF_BLOCK. */;
10511 else if (attr->form_is_block ())
10512 {
10513 struct dwarf2_locexpr_baton *dlbaton;
10514 struct dwarf_block *block = attr->as_block ();
10515
10516 dlbaton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
10517 dlbaton->data = block->data;
10518 dlbaton->size = block->size;
10519 dlbaton->per_objfile = per_objfile;
10520 dlbaton->per_cu = cu->per_cu;
10521
10522 call_site->target.set_loc_dwarf_block (dlbaton);
10523 }
10524 else if (attr->form_is_ref ())
10525 {
10526 struct dwarf2_cu *target_cu = cu;
10527 struct die_info *target_die;
10528
10529 target_die = follow_die_ref (die, attr, &target_cu);
10530 gdb_assert (target_cu->per_objfile->objfile == objfile);
10531
10532 struct attribute *ranges_attr
10533 = dwarf2_attr (target_die, DW_AT_ranges, target_cu);
10534
10535 if (die_is_declaration (target_die, target_cu))
10536 {
10537 const char *target_physname;
10538
10539 /* Prefer the mangled name; otherwise compute the demangled one. */
10540 target_physname = dw2_linkage_name (target_die, target_cu);
10541 if (target_physname == NULL)
10542 target_physname = dwarf2_physname (NULL, target_die, target_cu);
10543 if (target_physname == NULL)
10544 complaint (_("DW_AT_call_target target DIE has invalid "
10545 "physname, for referencing DIE %s [in module %s]"),
10547 else
10548 call_site->target.set_loc_physname (target_physname);
10549 }
10550 else if (ranges_attr != nullptr && ranges_attr->form_is_unsigned ())
10551 {
10552 ULONGEST ranges_offset = (ranges_attr->as_unsigned ()
10553 + target_cu->gnu_ranges_base);
10554 std::vector<unrelocated_addr> addresses;
10555 dwarf2_ranges_read_low_addrs (ranges_offset, target_cu,
10556 target_die->tag, addresses);
10557 unrelocated_addr *saved = XOBNEWVEC (&objfile->objfile_obstack,
10558 unrelocated_addr,
10559 addresses.size ());
10560 std::copy (addresses.begin (), addresses.end (), saved);
10561 call_site->target.set_loc_array (addresses.size (), saved);
10562 }
10563 else
10564 {
10565 unrelocated_addr lowpc;
10566
10567 /* DW_AT_entry_pc should be preferred. */
10568 if (dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu,
10569 nullptr, nullptr)
10571 complaint (_("DW_AT_call_target target DIE has invalid "
10572 "low pc, for referencing DIE %s [in module %s]"),
10574 else
10575 {
10576 lowpc = per_objfile->adjust (lowpc);
10577 call_site->target.set_loc_physaddr (lowpc);
10578 }
10579 }
10580 }
10581 else
10582 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
10583 "block nor reference, for DIE %s [in module %s]"),
10585
10586 for (child_die = die->child;
10587 child_die && child_die->tag;
10588 child_die = child_die->sibling)
10589 {
10590 struct call_site_parameter *parameter;
10591 struct attribute *loc, *origin;
10592
10593 if (child_die->tag != DW_TAG_call_site_parameter
10594 && child_die->tag != DW_TAG_GNU_call_site_parameter)
10595 {
10596 /* Already printed the complaint above. */
10597 continue;
10598 }
10599
10600 gdb_assert (call_site->parameter_count < nparams);
10602
10603 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
10604 specifies DW_TAG_formal_parameter. Value of the data assumed for the
10605 register is contained in DW_AT_call_value. */
10606
10607 loc = dwarf2_attr (child_die, DW_AT_location, cu);
10608 origin = dwarf2_attr (child_die, DW_AT_call_parameter, cu);
10609 if (origin == NULL)
10610 {
10611 /* This was a pre-DWARF-5 GNU extension alias
10612 for DW_AT_call_parameter. */
10613 origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu);
10614 }
10615 if (loc == NULL && origin != NULL && origin->form_is_ref ())
10616 {
10618
10619 sect_offset sect_off = origin->get_ref_die_offset ();
10620 if (!cu->header.offset_in_cu_p (sect_off))
10621 {
10622 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
10623 binding can be done only inside one CU. Such referenced DIE
10624 therefore cannot be even moved to DW_TAG_partial_unit. */
10625 complaint (_("DW_AT_call_parameter offset is not in CU for "
10626 "DW_TAG_call_site child DIE %s [in module %s]"),
10627 sect_offset_str (child_die->sect_off),
10629 continue;
10630 }
10631 parameter->u.param_cu_off
10632 = (cu_offset) (sect_off - cu->header.sect_off);
10633 }
10634 else if (loc == NULL || origin != NULL || !loc->form_is_block ())
10635 {
10636 complaint (_("No DW_FORM_block* DW_AT_location for "
10637 "DW_TAG_call_site child DIE %s [in module %s]"),
10639 continue;
10640 }
10641 else
10642 {
10643 struct dwarf_block *block = loc->as_block ();
10644
10646 (block->data, &block->data[block->size]);
10647 if (parameter->u.dwarf_reg != -1)
10649 else if (dwarf_block_to_sp_offset (gdbarch, block->data,
10650 &block->data[block->size],
10651 &parameter->u.fb_offset))
10653 else
10654 {
10655 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
10656 "for DW_FORM_block* DW_AT_location is supported for "
10657 "DW_TAG_call_site child DIE %s "
10658 "[in module %s]"),
10659 sect_offset_str (child_die->sect_off),
10661 continue;
10662 }
10663 }
10664
10665 attr = dwarf2_attr (child_die, DW_AT_call_value, cu);
10666 if (attr == NULL)
10667 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
10668 if (attr == NULL || !attr->form_is_block ())
10669 {
10670 complaint (_("No DW_FORM_block* DW_AT_call_value for "
10671 "DW_TAG_call_site child DIE %s [in module %s]"),
10672 sect_offset_str (child_die->sect_off),
10674 continue;
10675 }
10676
10677 struct dwarf_block *block = attr->as_block ();
10678 parameter->value = block->data;
10679 parameter->value_size = block->size;
10680
10681 /* Parameters are not pre-cleared by memset above. */
10682 parameter->data_value = NULL;
10683 parameter->data_value_size = 0;
10685
10686 attr = dwarf2_attr (child_die, DW_AT_call_data_value, cu);
10687 if (attr == NULL)
10688 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
10689 if (attr != nullptr)
10690 {
10691 if (!attr->form_is_block ())
10692 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
10693 "DW_TAG_call_site child DIE %s [in module %s]"),
10694 sect_offset_str (child_die->sect_off),
10696 else
10697 {
10698 block = attr->as_block ();
10699 parameter->data_value = block->data;
10700 parameter->data_value_size = block->size;
10701 }
10702 }
10703 }
10704}
10705
10706/* Helper function for read_variable. If DIE represents a virtual
10707 table, then return the type of the concrete object that is
10708 associated with the virtual table. Otherwise, return NULL. */
10709
10710static struct type *
10711rust_containing_type (struct die_info *die, struct dwarf2_cu *cu)
10712{
10713 struct attribute *attr = dwarf2_attr (die, DW_AT_type, cu);
10714 if (attr == NULL)
10715 return NULL;
10716
10717 /* Find the type DIE. */
10718 struct die_info *type_die = NULL;
10719 struct dwarf2_cu *type_cu = cu;
10720
10721 if (attr->form_is_ref ())
10722 type_die = follow_die_ref (die, attr, &type_cu);
10723 if (type_die == NULL)
10724 return NULL;
10725
10726 if (dwarf2_attr (type_die, DW_AT_containing_type, type_cu) == NULL)
10727 return NULL;
10728 return die_containing_type (type_die, type_cu);
10729}
10730
10731/* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
10732
10733static void
10734read_variable (struct die_info *die, struct dwarf2_cu *cu)
10735{
10736 struct rust_vtable_symbol *storage = NULL;
10737
10738 if (cu->lang () == language_rust)
10739 {
10740 struct type *containing_type = rust_containing_type (die, cu);
10741
10742 if (containing_type != NULL)
10743 {
10744 struct objfile *objfile = cu->per_objfile->objfile;
10745
10746 storage = new (&objfile->objfile_obstack) rust_vtable_symbol;
10747 storage->concrete_type = containing_type;
10748 storage->subclass = SYMBOL_RUST_VTABLE;
10749 }
10750 }
10751
10752 struct symbol *res = new_symbol (die, NULL, cu, storage);
10753 struct attribute *abstract_origin
10754 = dwarf2_attr (die, DW_AT_abstract_origin, cu);
10755 struct attribute *loc = dwarf2_attr (die, DW_AT_location, cu);
10756 if (res == NULL && loc && abstract_origin)
10757 {
10758 /* We have a variable without a name, but with a location and an abstract
10759 origin. This may be a concrete instance of an abstract variable
10760 referenced from an DW_OP_GNU_variable_value, so save it to find it back
10761 later. */
10762 struct dwarf2_cu *origin_cu = cu;
10763 struct die_info *origin_die
10764 = follow_die_ref (die, abstract_origin, &origin_cu);
10765 dwarf2_per_objfile *per_objfile = cu->per_objfile;
10766 per_objfile->per_bfd->abstract_to_concrete
10767 [origin_die->sect_off].push_back (die->sect_off);
10768 }
10769}
10770
10771/* Call CALLBACK from DW_AT_ranges attribute value OFFSET
10772 reading .debug_rnglists.
10773 Callback's type should be:
10774 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
10775 Return true if the attributes are present and valid, otherwise,
10776 return false. */
10777
10778template <typename Callback>
10779static bool
10780dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
10781 dwarf_tag tag, Callback &&callback)
10782{
10783 dwarf2_per_objfile *per_objfile = cu->per_objfile;
10784 struct objfile *objfile = per_objfile->objfile;
10785 bfd *obfd = objfile->obfd.get ();
10786 /* Base address selection entry. */
10787 gdb::optional<unrelocated_addr> base;
10788 const gdb_byte *buffer;
10789 bool overflow = false;
10790 ULONGEST addr_index;
10791 struct dwarf2_section_info *rnglists_section;
10792
10793 base = cu->base_address;
10794 rnglists_section = cu_debug_rnglists_section (cu, tag);
10795 rnglists_section->read (objfile);
10796
10797 if (offset >= rnglists_section->size)
10798 {
10799 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
10800 offset);
10801 return false;
10802 }
10803 buffer = rnglists_section->buffer + offset;
10804
10805 while (1)
10806 {
10807 /* Initialize it due to a false compiler warning. */
10808 unrelocated_addr range_beginning = {}, range_end = {};
10809 const gdb_byte *buf_end = (rnglists_section->buffer
10810 + rnglists_section->size);
10811 unsigned int bytes_read;
10812
10813 if (buffer == buf_end)
10814 {
10815 overflow = true;
10816 break;
10817 }
10818 const auto rlet = static_cast<enum dwarf_range_list_entry>(*buffer++);
10819 switch (rlet)
10820 {
10821 case DW_RLE_end_of_list:
10822 break;
10823 case DW_RLE_base_address:
10824 if (buffer + cu->header.addr_size > buf_end)
10825 {
10826 overflow = true;
10827 break;
10828 }
10829 base = cu->header.read_address (obfd, buffer, &bytes_read);
10830 buffer += bytes_read;
10831 break;
10832 case DW_RLE_base_addressx:
10833 addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
10834 buffer += bytes_read;
10835 base = read_addr_index (cu, addr_index);
10836 break;
10837 case DW_RLE_start_length:
10838 if (buffer + cu->header.addr_size > buf_end)
10839 {
10840 overflow = true;
10841 break;
10842 }
10843 range_beginning = cu->header.read_address (obfd, buffer,
10844 &bytes_read);
10845 buffer += bytes_read;
10846 range_end
10847 = (unrelocated_addr) ((CORE_ADDR) range_beginning
10849 &bytes_read));
10850 buffer += bytes_read;
10851 if (buffer > buf_end)
10852 {
10853 overflow = true;
10854 break;
10855 }
10856 break;
10857 case DW_RLE_startx_length:
10858 addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
10859 buffer += bytes_read;
10860 range_beginning = read_addr_index (cu, addr_index);
10861 if (buffer > buf_end)
10862 {
10863 overflow = true;
10864 break;
10865 }
10866 range_end
10867 = (unrelocated_addr) ((CORE_ADDR) range_beginning
10869 &bytes_read));
10870 buffer += bytes_read;
10871 break;
10872 case DW_RLE_offset_pair:
10873 range_beginning = (unrelocated_addr) read_unsigned_leb128 (obfd, buffer,
10874 &bytes_read);
10875 buffer += bytes_read;
10876 if (buffer > buf_end)
10877 {
10878 overflow = true;
10879 break;
10880 }
10881 range_end = (unrelocated_addr) read_unsigned_leb128 (obfd, buffer,
10882 &bytes_read);
10883 buffer += bytes_read;
10884 if (buffer > buf_end)
10885 {
10886 overflow = true;
10887 break;
10888 }
10889 break;
10890 case DW_RLE_start_end:
10891 if (buffer + 2 * cu->header.addr_size > buf_end)
10892 {
10893 overflow = true;
10894 break;
10895 }
10896 range_beginning = cu->header.read_address (obfd, buffer,
10897 &bytes_read);
10898 buffer += bytes_read;
10899 range_end = cu->header.read_address (obfd, buffer, &bytes_read);
10900 buffer += bytes_read;
10901 break;
10902 case DW_RLE_startx_endx:
10903 addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
10904 buffer += bytes_read;
10905 range_beginning = read_addr_index (cu, addr_index);
10906 if (buffer > buf_end)
10907 {
10908 overflow = true;
10909 break;
10910 }
10911 addr_index = read_unsigned_leb128 (obfd, buffer, &bytes_read);
10912 buffer += bytes_read;
10913 range_end = read_addr_index (cu, addr_index);
10914 break;
10915 default:
10916 complaint (_("Invalid .debug_rnglists data (no base address)"));
10917 return false;
10918 }
10919 if (rlet == DW_RLE_end_of_list || overflow)
10920 break;
10921 if (rlet == DW_RLE_base_address)
10922 continue;
10923
10924 if (range_beginning > range_end)
10925 {
10926 /* Inverted range entries are invalid. */
10927 complaint (_("Invalid .debug_rnglists data (inverted range)"));
10928 return false;
10929 }
10930
10931 /* Empty range entries have no effect. */
10932 if (range_beginning == range_end)
10933 continue;
10934
10935 /* Only DW_RLE_offset_pair needs the base address added. */
10936 if (rlet == DW_RLE_offset_pair)
10937 {
10938 if (!base.has_value ())
10939 {
10940 /* We have no valid base address for the DW_RLE_offset_pair. */
10941 complaint (_("Invalid .debug_rnglists data (no base address for "
10942 "DW_RLE_offset_pair)"));
10943 return false;
10944 }
10945
10946 range_beginning = (unrelocated_addr) ((CORE_ADDR) range_beginning
10947 + (CORE_ADDR) *base);
10948 range_end = (unrelocated_addr) ((CORE_ADDR) range_end
10949 + (CORE_ADDR) *base);
10950 }
10951
10952 /* A not-uncommon case of bad debug info.
10953 Don't pollute the addrmap with bad data. */
10954 if (range_beginning == (unrelocated_addr) 0
10955 && !per_objfile->per_bfd->has_section_at_zero)
10956 {
10957 complaint (_(".debug_rnglists entry has start address of zero"
10958 " [in module %s]"), objfile_name (objfile));
10959 continue;
10960 }
10961
10962 callback (range_beginning, range_end);
10963 }
10964
10965 if (overflow)
10966 {
10967 complaint (_("Offset %d is not terminated "
10968 "for DW_AT_ranges attribute"),
10969 offset);
10970 return false;
10971 }
10972
10973 return true;
10974}
10975
10976/* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
10977 Callback's type should be:
10978 void (unrelocated_addr range_beginning, unrelocated_addr range_end)
10979 Return 1 if the attributes are present and valid, otherwise, return 0. */
10980
10981template <typename Callback>
10982static int
10983dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag,
10984 Callback &&callback)
10985{
10986 dwarf2_per_objfile *per_objfile = cu->per_objfile;
10987 struct objfile *objfile = per_objfile->objfile;
10988 struct comp_unit_head *cu_header = &cu->header;
10989 bfd *obfd = objfile->obfd.get ();
10990 unsigned int addr_size = cu_header->addr_size;
10991 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
10992 /* Base address selection entry. */
10993 gdb::optional<unrelocated_addr> base;
10994 unsigned int dummy;
10995 const gdb_byte *buffer;
10996
10997 if (cu_header->version >= 5)
10998 return dwarf2_rnglists_process (offset, cu, tag, callback);
10999
11000 base = cu->base_address;
11001
11002 per_objfile->per_bfd->ranges.read (objfile);
11003 if (offset >= per_objfile->per_bfd->ranges.size)
11004 {
11005 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
11006 offset);
11007 return 0;
11008 }
11009 buffer = per_objfile->per_bfd->ranges.buffer + offset;
11010
11011 while (1)
11012 {
11013 unrelocated_addr range_beginning, range_end;
11014
11015 range_beginning = cu->header.read_address (obfd, buffer, &dummy);
11016 buffer += addr_size;
11017 range_end = cu->header.read_address (obfd, buffer, &dummy);
11018 buffer += addr_size;
11019 offset += 2 * addr_size;
11020
11021 /* An end of list marker is a pair of zero addresses. */
11022 if (range_beginning == (unrelocated_addr) 0
11023 && range_end == (unrelocated_addr) 0)
11024 /* Found the end of list entry. */
11025 break;
11026
11027 /* Each base address selection entry is a pair of 2 values.
11028 The first is the largest possible address, the second is
11029 the base address. Check for a base address here. */
11030 if (((CORE_ADDR) range_beginning & mask) == mask)
11031 {
11032 /* If we found the largest possible address, then we already
11033 have the base address in range_end. */
11034 base = range_end;
11035 continue;
11036 }
11037
11038 if (!base.has_value ())
11039 {
11040 /* We have no valid base address for the ranges
11041 data. */
11042 complaint (_("Invalid .debug_ranges data (no base address)"));
11043 return 0;
11044 }
11045
11046 if (range_beginning > range_end)
11047 {
11048 /* Inverted range entries are invalid. */
11049 complaint (_("Invalid .debug_ranges data (inverted range)"));
11050 return 0;
11051 }
11052
11053 /* Empty range entries have no effect. */
11054 if (range_beginning == range_end)
11055 continue;
11056
11057 range_beginning = (unrelocated_addr) ((CORE_ADDR) range_beginning
11058 + (CORE_ADDR) *base);
11059 range_end = (unrelocated_addr) ((CORE_ADDR) range_end
11060 + (CORE_ADDR) *base);
11061
11062 /* A not-uncommon case of bad debug info.
11063 Don't pollute the addrmap with bad data. */
11064 if (range_beginning == (unrelocated_addr) 0
11065 && !per_objfile->per_bfd->has_section_at_zero)
11066 {
11067 complaint (_(".debug_ranges entry has start address of zero"
11068 " [in module %s]"), objfile_name (objfile));
11069 continue;
11070 }
11071
11072 callback (range_beginning, range_end);
11073 }
11074
11075 return 1;
11076}
11077
11078/* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
11079 Return 1 if the attributes are present and valid, otherwise, return 0.
11080 TAG is passed to dwarf2_ranges_process. If MAP is not NULL, then
11081 ranges in MAP are set, using DATUM as the value. */
11082
11083static int
11084dwarf2_ranges_read (unsigned offset, unrelocated_addr *low_return,
11085 unrelocated_addr *high_return, struct dwarf2_cu *cu,
11086 addrmap *map, void *datum, dwarf_tag tag)
11087{
11088 dwarf2_per_objfile *per_objfile = cu->per_objfile;
11089 int low_set = 0;
11090 unrelocated_addr low = {};
11091 unrelocated_addr high = {};
11092 int retval;
11093
11094 retval = dwarf2_ranges_process (offset, cu, tag,
11095 [&] (unrelocated_addr range_beginning, unrelocated_addr range_end)
11096 {
11097 if (map != nullptr)
11098 {
11099 unrelocated_addr lowpc;
11100 unrelocated_addr highpc;
11101
11102 lowpc = per_objfile->adjust (range_beginning);
11103 highpc = per_objfile->adjust (range_end);
11104 /* addrmap only accepts CORE_ADDR, so we must cast here. */
11105 map->set_empty ((CORE_ADDR) lowpc, (CORE_ADDR) highpc - 1, datum);
11106 }
11107
11108 /* FIXME: This is recording everything as a low-high
11109 segment of consecutive addresses. We should have a
11110 data structure for discontiguous block ranges
11111 instead. */
11112 if (! low_set)
11113 {
11114 low = range_beginning;
11115 high = range_end;
11116 low_set = 1;
11117 }
11118 else
11119 {
11120 if (range_beginning < low)
11121 low = range_beginning;
11122 if (range_end > high)
11123 high = range_end;
11124 }
11125 });
11126 if (!retval)
11127 return 0;
11128
11129 if (! low_set)
11130 /* If the first entry is an end-of-list marker, the range
11131 describes an empty scope, i.e. no instructions. */
11132 return 0;
11133
11134 if (low_return)
11135 *low_return = low;
11136 if (high_return)
11137 *high_return = high;
11138 return 1;
11139}
11140
11141/* Process ranges and fill in a vector of the low PC values only. */
11142
11143static void
11144dwarf2_ranges_read_low_addrs (unsigned offset, struct dwarf2_cu *cu,
11145 dwarf_tag tag,
11146 std::vector<unrelocated_addr> &result)
11147{
11148 dwarf2_ranges_process (offset, cu, tag,
11149 [&] (unrelocated_addr start, unrelocated_addr end)
11150 {
11151 result.push_back (start);
11152 });
11153}
11154
11155/* Get low and high pc attributes from a die. See enum pc_bounds_kind
11156 definition for the return value. *LOWPC and *HIGHPC are set iff
11157 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
11158
11159static enum pc_bounds_kind
11160dwarf2_get_pc_bounds (struct die_info *die, unrelocated_addr *lowpc,
11161 unrelocated_addr *highpc, struct dwarf2_cu *cu,
11162 addrmap *map, void *datum)
11163{
11164 dwarf2_per_objfile *per_objfile = cu->per_objfile;
11165 struct attribute *attr;
11166 struct attribute *attr_high;
11167 unrelocated_addr low = {};
11168 unrelocated_addr high = {};
11169 enum pc_bounds_kind ret;
11170
11171 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
11172 if (attr_high)
11173 {
11174 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11175 if (attr != nullptr)
11176 {
11177 low = attr->as_address ();
11178 high = attr_high->as_address ();
11179 if (cu->header.version >= 4 && attr_high->form_is_constant ())
11180 high = (unrelocated_addr) ((ULONGEST) high + (ULONGEST) low);
11181 }
11182 else
11183 /* Found high w/o low attribute. */
11184 return PC_BOUNDS_INVALID;
11185
11186 /* Found consecutive range of addresses. */
11187 ret = PC_BOUNDS_HIGH_LOW;
11188 }
11189 else
11190 {
11191 attr = dwarf2_attr (die, DW_AT_ranges, cu);
11192 if (attr != nullptr && attr->form_is_unsigned ())
11193 {
11194 /* Offset in the .debug_ranges or .debug_rnglist section (depending
11195 on DWARF version). */
11196 ULONGEST ranges_offset = attr->as_unsigned ();
11197
11198 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
11199 this value. */
11200 if (die->tag != DW_TAG_compile_unit)
11201 ranges_offset += cu->gnu_ranges_base;
11202
11203 /* Value of the DW_AT_ranges attribute is the offset in the
11204 .debug_ranges section. */
11205 if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu,
11206 map, datum, die->tag))
11207 return PC_BOUNDS_INVALID;
11208 /* Found discontinuous range of addresses. */
11209 ret = PC_BOUNDS_RANGES;
11210 }
11211 else
11212 return PC_BOUNDS_NOT_PRESENT;
11213 }
11214
11215 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
11216 if (high <= low)
11217 return PC_BOUNDS_INVALID;
11218
11219 /* When using the GNU linker, .gnu.linkonce. sections are used to
11220 eliminate duplicate copies of functions and vtables and such.
11221 The linker will arbitrarily choose one and discard the others.
11222 The AT_*_pc values for such functions refer to local labels in
11223 these sections. If the section from that file was discarded, the
11224 labels are not in the output, so the relocs get a value of 0.
11225 If this is a discarded function, mark the pc bounds as invalid,
11226 so that GDB will ignore it. */
11227 if (low == (unrelocated_addr) 0
11228 && !per_objfile->per_bfd->has_section_at_zero)
11229 return PC_BOUNDS_INVALID;
11230
11231 *lowpc = low;
11232 if (highpc)
11233 *highpc = high;
11234 return ret;
11235}
11236
11237/* Assuming that DIE represents a subprogram DIE or a lexical block, get
11238 its low and high PC addresses. Do nothing if these addresses could not
11239 be determined. Otherwise, set LOWPC to the low address if it is smaller,
11240 and HIGHPC to the high address if greater than HIGHPC. */
11241
11242static void
11244 unrelocated_addr *lowpc,
11245 unrelocated_addr *highpc,
11246 struct dwarf2_cu *cu)
11247{
11248 unrelocated_addr low, high;
11249 struct die_info *child = die->child;
11250
11251 if (dwarf2_get_pc_bounds (die, &low, &high, cu, nullptr, nullptr)
11253 {
11254 *lowpc = std::min (*lowpc, low);
11255 *highpc = std::max (*highpc, high);
11256 }
11257
11258 /* If the language does not allow nested subprograms (either inside
11259 subprograms or lexical blocks), we're done. */
11260 if (cu->lang () != language_ada)
11261 return;
11262
11263 /* Check all the children of the given DIE. If it contains nested
11264 subprograms, then check their pc bounds. Likewise, we need to
11265 check lexical blocks as well, as they may also contain subprogram
11266 definitions. */
11267 while (child && child->tag)
11268 {
11269 if (child->tag == DW_TAG_subprogram
11270 || child->tag == DW_TAG_lexical_block)
11271 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
11272 child = child->sibling;
11273 }
11274}
11275
11276/* Get the low and high pc's represented by the scope DIE, and store
11277 them in *LOWPC and *HIGHPC. If the correct values can't be
11278 determined, set *LOWPC to -1 and *HIGHPC to 0. */
11279
11280static void
11282 unrelocated_addr *lowpc, unrelocated_addr *highpc,
11283 struct dwarf2_cu *cu)
11284{
11285 unrelocated_addr best_low = (unrelocated_addr) -1;
11286 unrelocated_addr best_high = {};
11287 unrelocated_addr current_low, current_high;
11288
11289 if (dwarf2_get_pc_bounds (die, &current_low, &current_high, cu,
11290 nullptr, nullptr)
11292 {
11293 best_low = current_low;
11294 best_high = current_high;
11295 }
11296 else
11297 {
11298 struct die_info *child = die->child;
11299
11300 while (child && child->tag)
11301 {
11302 switch (child->tag) {
11303 case DW_TAG_subprogram:
11304 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
11305 break;
11306 case DW_TAG_namespace:
11307 case DW_TAG_module:
11308 /* FIXME: carlton/2004-01-16: Should we do this for
11309 DW_TAG_class_type/DW_TAG_structure_type, too? I think
11310 that current GCC's always emit the DIEs corresponding
11311 to definitions of methods of classes as children of a
11312 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
11313 the DIEs giving the declarations, which could be
11314 anywhere). But I don't see any reason why the
11315 standards says that they have to be there. */
11316 get_scope_pc_bounds (child, &current_low, &current_high, cu);
11317
11318 if (current_low != ((unrelocated_addr) -1))
11319 {
11320 best_low = std::min (best_low, current_low);
11321 best_high = std::max (best_high, current_high);
11322 }
11323 break;
11324 default:
11325 /* Ignore. */
11326 break;
11327 }
11328
11329 child = child->sibling;
11330 }
11331 }
11332
11333 *lowpc = best_low;
11334 *highpc = best_high;
11335}
11336
11337/* Record the address ranges for BLOCK, offset by BASEADDR, as given
11338 in DIE. */
11339
11340static void
11342 struct dwarf2_cu *cu)
11343{
11344 dwarf2_per_objfile *per_objfile = cu->per_objfile;
11345 struct objfile *objfile = per_objfile->objfile;
11346 struct attribute *attr;
11347 struct attribute *attr_high;
11348
11349 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
11350 if (attr_high)
11351 {
11352 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11353 if (attr != nullptr)
11354 {
11355 unrelocated_addr unrel_low = attr->as_address ();
11356 unrelocated_addr unrel_high = attr_high->as_address ();
11357
11358 if (cu->header.version >= 4 && attr_high->form_is_constant ())
11359 unrel_high = (unrelocated_addr) ((ULONGEST) unrel_high
11360 + (ULONGEST) unrel_low);
11361
11362 CORE_ADDR low = per_objfile->relocate (unrel_low);
11363 CORE_ADDR high = per_objfile->relocate (unrel_high);
11364 cu->get_builder ()->record_block_range (block, low, high - 1);
11365 }
11366 }
11367
11368 attr = dwarf2_attr (die, DW_AT_ranges, cu);
11369 if (attr != nullptr && attr->form_is_unsigned ())
11370 {
11371 /* Offset in the .debug_ranges or .debug_rnglist section (depending
11372 on DWARF version). */
11373 ULONGEST ranges_offset = attr->as_unsigned ();
11374
11375 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
11376 this value. */
11377 if (die->tag != DW_TAG_compile_unit)
11378 ranges_offset += cu->gnu_ranges_base;
11379
11380 std::vector<blockrange> blockvec;
11381 dwarf2_ranges_process (ranges_offset, cu, die->tag,
11382 [&] (unrelocated_addr start, unrelocated_addr end)
11383 {
11384 CORE_ADDR abs_start = per_objfile->relocate (start);
11385 CORE_ADDR abs_end = per_objfile->relocate (end);
11386 cu->get_builder ()->record_block_range (block, abs_start,
11387 abs_end - 1);
11388 blockvec.emplace_back (abs_start, abs_end);
11389 });
11390
11392 }
11393}
11394
11395/* Check whether the producer field indicates either of GCC < 4.6, or the
11396 Intel C/C++ compiler, and cache the result in CU. */
11397
11398static void
11400{
11401 int major, minor;
11402
11403 if (cu->producer == NULL)
11404 {
11405 /* For unknown compilers expect their behavior is DWARF version
11406 compliant.
11407
11408 GCC started to support .debug_types sections by -gdwarf-4 since
11409 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
11410 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
11411 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
11412 interpreted incorrectly by GDB now - GCC PR debug/48229. */
11413 }
11414 else if (producer_is_gcc (cu->producer, &major, &minor))
11415 {
11416 cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
11417 cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
11418 cu->producer_is_gcc_11 = major == 11;
11419 }
11420 else if (producer_is_icc (cu->producer, &major, &minor))
11421 {
11422 cu->producer_is_icc = true;
11423 cu->producer_is_icc_lt_14 = major < 14;
11424 }
11425 else if (startswith (cu->producer, "CodeWarrior S12/L-ISA"))
11426 cu->producer_is_codewarrior = true;
11427 else if (producer_is_clang (cu->producer, &major, &minor))
11428 cu->producer_is_clang = true;
11429 else
11430 {
11431 /* For other non-GCC compilers, expect their behavior is DWARF version
11432 compliant. */
11433 }
11434
11435 cu->checked_producer = true;
11436}
11437
11438/* Check for GCC PR debug/45124 fix which is not present in any G++ version up
11439 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
11440 during 4.6.0 experimental. */
11441
11442static bool
11444{
11445 if (!cu->checked_producer)
11446 check_producer (cu);
11447
11448 return cu->producer_is_gxx_lt_4_6;
11449}
11450
11451
11452/* Codewarrior (at least as of version 5.0.40) generates dwarf line information
11453 with incorrect is_stmt attributes. */
11454
11455static bool
11457{
11458 if (!cu->checked_producer)
11459 check_producer (cu);
11460
11461 return cu->producer_is_codewarrior;
11462}
11463
11464/* Return the accessibility of DIE, as given by DW_AT_accessibility.
11465 If that attribute is not available, return the appropriate
11466 default. */
11467
11468static enum dwarf_access_attribute
11470{
11471 attribute *attr = dwarf2_attr (die, DW_AT_accessibility, cu);
11472 if (attr != nullptr)
11473 {
11474 LONGEST value = attr->constant_value (-1);
11475 if (value == DW_ACCESS_public
11476 || value == DW_ACCESS_protected
11477 || value == DW_ACCESS_private)
11478 return (dwarf_access_attribute) value;
11479 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
11480 plongest (value));
11481 }
11482
11483 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
11484 {
11485 /* The default DWARF 2 accessibility for members is public, the default
11486 accessibility for inheritance is private. */
11487
11488 if (die->tag != DW_TAG_inheritance)
11489 return DW_ACCESS_public;
11490 else
11491 return DW_ACCESS_private;
11492 }
11493 else
11494 {
11495 /* DWARF 3+ defines the default accessibility a different way. The same
11496 rules apply now for DW_TAG_inheritance as for the members and it only
11497 depends on the container kind. */
11498
11499 if (die->parent->tag == DW_TAG_class_type)
11500 return DW_ACCESS_private;
11501 else
11502 return DW_ACCESS_public;
11503 }
11504}
11505
11506/* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
11507 *OFFSET to the byte offset. If the attribute was not found return
11508 0, otherwise return 1. If it was found but could not properly be
11509 handled, set *OFFSET to 0. */
11510
11511static int
11513 LONGEST *offset)
11514{
11515 struct attribute *attr;
11516
11517 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
11518 if (attr != NULL)
11519 {
11520 *offset = 0;
11521 CORE_ADDR temp;
11522
11523 /* Note that we do not check for a section offset first here.
11524 This is because DW_AT_data_member_location is new in DWARF 4,
11525 so if we see it, we can assume that a constant form is really
11526 a constant and not a section offset. */
11527 if (attr->form_is_constant ())
11528 *offset = attr->constant_value (0);
11529 else if (attr->form_is_section_offset ())
11531 else if (attr->form_is_block ()
11532 && decode_locdesc (attr->as_block (), cu, &temp))
11533 {
11534 *offset = temp;
11535 }
11536 else
11538
11539 return 1;
11540 }
11541 else
11542 {
11543 attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
11544 if (attr != nullptr)
11545 {
11546 *offset = attr->constant_value (0);
11547 return 1;
11548 }
11549 }
11550
11551 return 0;
11552}
11553
11554/* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
11555 store the results in FIELD. */
11556
11557static void
11559 struct field *field)
11560{
11561 struct attribute *attr;
11562
11563 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
11564 if (attr != NULL)
11565 {
11566 if (attr->form_is_constant ())
11567 {
11568 LONGEST offset = attr->constant_value (0);
11569
11570 /* Work around this GCC 11 bug, where it would erroneously use -1
11571 data member locations, instead of 0:
11572
11573 Negative DW_AT_data_member_location
11574 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
11575 */
11576 if (offset == -1 && cu->producer_is_gcc_11)
11577 {
11578 complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
11579 offset = 0;
11580 }
11581
11583 }
11584 else if (attr->form_is_section_offset ())
11586 else if (attr->form_is_block ())
11587 {
11588 CORE_ADDR offset;
11589 if (decode_locdesc (attr->as_block (), cu, &offset))
11591 else
11592 {
11593 dwarf2_per_objfile *per_objfile = cu->per_objfile;
11594 struct objfile *objfile = per_objfile->objfile;
11595 struct dwarf2_locexpr_baton *dlbaton
11596 = XOBNEW (&objfile->objfile_obstack,
11597 struct dwarf2_locexpr_baton);
11598 dlbaton->data = attr->as_block ()->data;
11599 dlbaton->size = attr->as_block ()->size;
11600 /* When using this baton, we want to compute the address
11601 of the field, not the value. This is why
11602 is_reference is set to false here. */
11603 dlbaton->is_reference = false;
11604 dlbaton->per_objfile = per_objfile;
11605 dlbaton->per_cu = cu->per_cu;
11606
11607 field->set_loc_dwarf_block (dlbaton);
11608 }
11609 }
11610 else
11612 }
11613 else
11614 {
11615 attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
11616 if (attr != nullptr)
11617 field->set_loc_bitpos (attr->constant_value (0));
11618 }
11619}
11620
11621/* Add an aggregate field to the field list. */
11622
11623static void
11624dwarf2_add_field (struct field_info *fip, struct die_info *die,
11625 struct dwarf2_cu *cu)
11626{
11627 struct objfile *objfile = cu->per_objfile->objfile;
11628 struct gdbarch *gdbarch = objfile->arch ();
11629 struct nextfield *new_field;
11630 struct attribute *attr;
11631 struct field *fp;
11632 const char *fieldname = "";
11633
11634 if (die->tag == DW_TAG_inheritance)
11635 {
11636 fip->baseclasses.emplace_back ();
11637 new_field = &fip->baseclasses.back ();
11638 }
11639 else
11640 {
11641 fip->fields.emplace_back ();
11642 new_field = &fip->fields.back ();
11643 }
11644
11645 new_field->offset = die->sect_off;
11646
11647 new_field->accessibility = dwarf2_access_attribute (die, cu);
11648 if (new_field->accessibility != DW_ACCESS_public)
11649 fip->non_public_fields = true;
11650
11651 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
11652 if (attr != nullptr)
11653 new_field->virtuality = attr->as_virtuality ();
11654 else
11655 new_field->virtuality = DW_VIRTUALITY_none;
11656
11657 fp = &new_field->field;
11658
11659 if ((die->tag == DW_TAG_member || die->tag == DW_TAG_namelist_item)
11660 && !die_is_declaration (die, cu))
11661 {
11662 if (die->tag == DW_TAG_namelist_item)
11663 {
11664 /* Typically, DW_TAG_namelist_item are references to namelist items.
11665 If so, follow that reference. */
11666 struct attribute *attr1 = dwarf2_attr (die, DW_AT_namelist_item, cu);
11667 struct die_info *item_die = nullptr;
11668 struct dwarf2_cu *item_cu = cu;
11669 if (attr1->form_is_ref ())
11670 item_die = follow_die_ref (die, attr1, &item_cu);
11671 if (item_die != nullptr)
11672 die = item_die;
11673 }
11674 /* Data member other than a C++ static data member. */
11675
11676 /* Get type of field. */
11677 fp->set_type (die_type (die, cu));
11678
11679 fp->set_loc_bitpos (0);
11680
11681 /* Get bit size of field (zero if none). */
11682 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
11683 if (attr != nullptr)
11684 fp->set_bitsize (attr->constant_value (0));
11685 else
11686 fp->set_bitsize (0);
11687
11688 /* Get bit offset of field. */
11689 handle_member_location (die, cu, fp);
11690 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
11691 if (attr != nullptr && attr->form_is_constant ())
11692 {
11693 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
11694 {
11695 /* For big endian bits, the DW_AT_bit_offset gives the
11696 additional bit offset from the MSB of the containing
11697 anonymous object to the MSB of the field. We don't
11698 have to do anything special since we don't need to
11699 know the size of the anonymous object. */
11700 fp->set_loc_bitpos (fp->loc_bitpos () + attr->constant_value (0));
11701 }
11702 else
11703 {
11704 /* For little endian bits, compute the bit offset to the
11705 MSB of the anonymous object, subtract off the number of
11706 bits from the MSB of the field to the MSB of the
11707 object, and then subtract off the number of bits of
11708 the field itself. The result is the bit offset of
11709 the LSB of the field. */
11710 int anonymous_size;
11711 int bit_offset = attr->constant_value (0);
11712
11713 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11714 if (attr != nullptr && attr->form_is_constant ())
11715 {
11716 /* The size of the anonymous object containing
11717 the bit field is explicit, so use the
11718 indicated size (in bytes). */
11719 anonymous_size = attr->constant_value (0);
11720 }
11721 else
11722 {
11723 /* The size of the anonymous object containing
11724 the bit field must be inferred from the type
11725 attribute of the data member containing the
11726 bit field. */
11727 anonymous_size = fp->type ()->length ();
11728 }
11729 fp->set_loc_bitpos (fp->loc_bitpos ()
11730 + anonymous_size * bits_per_byte
11731 - bit_offset - fp->bitsize ());
11732 }
11733 }
11734
11735 /* Get name of field. */
11736 fieldname = dwarf2_name (die, cu);
11737 if (fieldname == NULL)
11738 fieldname = "";
11739
11740 /* The name is already allocated along with this objfile, so we don't
11741 need to duplicate it for the type. */
11742 fp->set_name (fieldname);
11743
11744 /* Change accessibility for artificial fields (e.g. virtual table
11745 pointer or virtual base class pointer) to private. */
11746 if (dwarf2_attr (die, DW_AT_artificial, cu))
11747 {
11748 fp->set_is_artificial (true);
11749 new_field->accessibility = DW_ACCESS_private;
11750 fip->non_public_fields = true;
11751 }
11752 }
11753 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
11754 {
11755 /* C++ static member. */
11756
11757 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
11758 is a declaration, but all versions of G++ as of this writing
11759 (so through at least 3.2.1) incorrectly generate
11760 DW_TAG_variable tags. */
11761
11762 const char *physname;
11763
11764 /* Get name of field. */
11765 fieldname = dwarf2_name (die, cu);
11766 if (fieldname == NULL)
11767 return;
11768
11769 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11770 if (attr
11771 /* Only create a symbol if this is an external value.
11772 new_symbol checks this and puts the value in the global symbol
11773 table, which we want. If it is not external, new_symbol
11774 will try to put the value in cu->list_in_scope which is wrong. */
11775 && dwarf2_flag_true_p (die, DW_AT_external, cu))
11776 {
11777 /* A static const member, not much different than an enum as far as
11778 we're concerned, except that we can support more types. */
11779 new_symbol (die, NULL, cu);
11780 }
11781
11782 /* Get physical name. */
11783 physname = dwarf2_physname (fieldname, die, cu);
11784
11785 /* The name is already allocated along with this objfile, so we don't
11786 need to duplicate it for the type. */
11787 fp->set_loc_physname (physname ? physname : "");
11788 fp->set_type (die_type (die, cu));
11789 fp->set_name (fieldname);
11790 }
11791 else if (die->tag == DW_TAG_inheritance)
11792 {
11793 /* C++ base class field. */
11794 handle_member_location (die, cu, fp);
11795 fp->set_bitsize (0);
11796 fp->set_type (die_type (die, cu));
11797 fp->set_name (fp->type ()->name ());
11798 }
11799 else
11800 gdb_assert_not_reached ("missing case in dwarf2_add_field");
11801}
11802
11803/* Can the type given by DIE define another type? */
11804
11805static bool
11807{
11808 switch (die->tag)
11809 {
11810 case DW_TAG_typedef:
11811 case DW_TAG_class_type:
11812 case DW_TAG_structure_type:
11813 case DW_TAG_union_type:
11814 case DW_TAG_enumeration_type:
11815 return true;
11816
11817 default:
11818 return false;
11819 }
11820}
11821
11822/* Add a type definition defined in the scope of the FIP's class. */
11823
11824static void
11825dwarf2_add_type_defn (struct field_info *fip, struct die_info *die,
11826 struct dwarf2_cu *cu)
11827{
11828 struct decl_field fp;
11829 memset (&fp, 0, sizeof (fp));
11830
11831 gdb_assert (type_can_define_types (die));
11832
11833 /* Get name of field. NULL is okay here, meaning an anonymous type. */
11834 fp.name = dwarf2_name (die, cu);
11835 fp.type = read_type_die (die, cu);
11836
11837 /* Save accessibility. */
11838 dwarf_access_attribute accessibility = dwarf2_access_attribute (die, cu);
11839 switch (accessibility)
11840 {
11841 case DW_ACCESS_public:
11842 /* The assumed value if neither private nor protected. */
11843 break;
11844 case DW_ACCESS_private:
11845 fp.is_private = 1;
11846 break;
11847 case DW_ACCESS_protected:
11848 fp.is_protected = 1;
11849 break;
11850 }
11851
11852 if (die->tag == DW_TAG_typedef)
11853 fip->typedef_field_list.push_back (fp);
11854 else
11855 fip->nested_types_list.push_back (fp);
11856}
11857
11858/* A convenience typedef that's used when finding the discriminant
11859 field for a variant part. */
11860typedef std::unordered_map<sect_offset, int, gdb::hash_enum<sect_offset>>
11862
11863/* Compute the discriminant range for a given variant. OBSTACK is
11864 where the results will be stored. VARIANT is the variant to
11865 process. IS_UNSIGNED indicates whether the discriminant is signed
11866 or unsigned. */
11867
11868static const gdb::array_view<discriminant_range>
11869convert_variant_range (struct obstack *obstack, const variant_field &variant,
11870 bool is_unsigned)
11871{
11872 std::vector<discriminant_range> ranges;
11873
11874 if (variant.default_branch)
11875 return {};
11876
11877 if (variant.discr_list_data == nullptr)
11878 {
11880 = {variant.discriminant_value, variant.discriminant_value};
11881 ranges.push_back (r);
11882 }
11883 else
11884 {
11885 gdb::array_view<const gdb_byte> data (variant.discr_list_data->data,
11886 variant.discr_list_data->size);
11887 while (!data.empty ())
11888 {
11889 if (data[0] != DW_DSC_range && data[0] != DW_DSC_label)
11890 {
11891 complaint (_("invalid discriminant marker: %d"), data[0]);
11892 break;
11893 }
11894 bool is_range = data[0] == DW_DSC_range;
11895 data = data.slice (1);
11896
11897 ULONGEST low, high;
11898 unsigned int bytes_read;
11899
11900 if (data.empty ())
11901 {
11902 complaint (_("DW_AT_discr_list missing low value"));
11903 break;
11904 }
11905 if (is_unsigned)
11906 low = read_unsigned_leb128 (nullptr, data.data (), &bytes_read);
11907 else
11908 low = (ULONGEST) read_signed_leb128 (nullptr, data.data (),
11909 &bytes_read);
11910 data = data.slice (bytes_read);
11911
11912 if (is_range)
11913 {
11914 if (data.empty ())
11915 {
11916 complaint (_("DW_AT_discr_list missing high value"));
11917 break;
11918 }
11919 if (is_unsigned)
11920 high = read_unsigned_leb128 (nullptr, data.data (),
11921 &bytes_read);
11922 else
11923 high = (LONGEST) read_signed_leb128 (nullptr, data.data (),
11924 &bytes_read);
11925 data = data.slice (bytes_read);
11926 }
11927 else
11928 high = low;
11929
11930 ranges.push_back ({ low, high });
11931 }
11932 }
11933
11934 discriminant_range *result = XOBNEWVEC (obstack, discriminant_range,
11935 ranges.size ());
11936 std::copy (ranges.begin (), ranges.end (), result);
11937 return gdb::array_view<discriminant_range> (result, ranges.size ());
11938}
11939
11940static const gdb::array_view<variant_part> create_variant_parts
11941 (struct obstack *obstack,
11942 const offset_map_type &offset_map,
11943 struct field_info *fi,
11944 const std::vector<variant_part_builder> &variant_parts);
11945
11946/* Fill in a "struct variant" for a given variant field. RESULT is
11947 the variant to fill in. OBSTACK is where any needed allocations
11948 will be done. OFFSET_MAP holds the mapping from section offsets to
11949 fields for the type. FI describes the fields of the type we're
11950 processing. FIELD is the variant field we're converting. */
11951
11952static void
11953create_one_variant (variant &result, struct obstack *obstack,
11954 const offset_map_type &offset_map,
11955 struct field_info *fi, const variant_field &field)
11956{
11957 result.discriminants = convert_variant_range (obstack, field, false);
11958 result.first_field = field.first_field + fi->baseclasses.size ();
11959 result.last_field = field.last_field + fi->baseclasses.size ();
11960 result.parts = create_variant_parts (obstack, offset_map, fi,
11961 field.variant_parts);
11962}
11963
11964/* Fill in a "struct variant_part" for a given variant part. RESULT
11965 is the variant part to fill in. OBSTACK is where any needed
11966 allocations will be done. OFFSET_MAP holds the mapping from
11967 section offsets to fields for the type. FI describes the fields of
11968 the type we're processing. BUILDER is the variant part to be
11969 converted. */
11970
11971static void
11973 struct obstack *obstack,
11974 const offset_map_type &offset_map,
11975 struct field_info *fi,
11976 const variant_part_builder &builder)
11977{
11978 auto iter = offset_map.find (builder.discriminant_offset);
11979 if (iter == offset_map.end ())
11980 {
11981 result.discriminant_index = -1;
11982 /* Doesn't matter. */
11983 result.is_unsigned = false;
11984 }
11985 else
11986 {
11987 result.discriminant_index = iter->second;
11988 result.is_unsigned
11989 = fi->fields[result.discriminant_index].field.type ()->is_unsigned ();
11990 }
11991
11992 size_t n = builder.variants.size ();
11993 variant *output = new (obstack) variant[n];
11994 for (size_t i = 0; i < n; ++i)
11995 create_one_variant (output[i], obstack, offset_map, fi,
11996 builder.variants[i]);
11997
11998 result.variants = gdb::array_view<variant> (output, n);
11999}
12000
12001/* Create a vector of variant parts that can be attached to a type.
12002 OBSTACK is where any needed allocations will be done. OFFSET_MAP
12003 holds the mapping from section offsets to fields for the type. FI
12004 describes the fields of the type we're processing. VARIANT_PARTS
12005 is the vector to convert. */
12006
12007static const gdb::array_view<variant_part>
12008create_variant_parts (struct obstack *obstack,
12009 const offset_map_type &offset_map,
12010 struct field_info *fi,
12011 const std::vector<variant_part_builder> &variant_parts)
12012{
12013 if (variant_parts.empty ())
12014 return {};
12015
12016 size_t n = variant_parts.size ();
12017 variant_part *result = new (obstack) variant_part[n];
12018 for (size_t i = 0; i < n; ++i)
12019 create_one_variant_part (result[i], obstack, offset_map, fi,
12020 variant_parts[i]);
12021
12022 return gdb::array_view<variant_part> (result, n);
12023}
12024
12025/* Compute the variant part vector for FIP, attaching it to TYPE when
12026 done. */
12027
12028static void
12030 struct dwarf2_cu *cu)
12031{
12032 /* Map section offsets of fields to their field index. Note the
12033 field index here does not take the number of baseclasses into
12034 account. */
12035 offset_map_type offset_map;
12036 for (int i = 0; i < fip->fields.size (); ++i)
12037 offset_map[fip->fields[i].offset] = i;
12038
12039 struct objfile *objfile = cu->per_objfile->objfile;
12040 gdb::array_view<const variant_part> parts
12041 = create_variant_parts (&objfile->objfile_obstack, offset_map, fip,
12042 fip->variant_parts);
12043
12044 struct dynamic_prop prop;
12045 prop.set_variant_parts ((gdb::array_view<variant_part> *)
12046 obstack_copy (&objfile->objfile_obstack, &parts,
12047 sizeof (parts)));
12048
12050}
12051
12052/* Create the vector of fields, and attach it to the type. */
12053
12054static void
12056 struct dwarf2_cu *cu)
12057{
12058 int nfields = fip->nfields ();
12059
12060 /* Record the field count, allocate space for the array of fields,
12061 and create blank accessibility bitfields if necessary. */
12062 type->alloc_fields (nfields);
12063
12064 if (fip->non_public_fields && cu->lang () != language_ada)
12065 {
12067
12069 (B_TYPE *) TYPE_ZALLOC (type, B_BYTES (nfields));
12070
12072 (B_TYPE *) TYPE_ZALLOC (type, B_BYTES (nfields));
12073
12075 (B_TYPE *) TYPE_ZALLOC (type, B_BYTES (nfields));
12076 }
12077
12078 /* If the type has baseclasses, allocate and clear a bit vector for
12079 TYPE_FIELD_VIRTUAL_BITS. */
12080 if (!fip->baseclasses.empty () && cu->lang () != language_ada)
12081 {
12082 int num_bytes = B_BYTES (fip->baseclasses.size ());
12083 unsigned char *pointer;
12084
12086 pointer = (unsigned char *) TYPE_ZALLOC (type, num_bytes);
12087 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
12088 TYPE_N_BASECLASSES (type) = fip->baseclasses.size ();
12089 }
12090
12091 if (!fip->variant_parts.empty ())
12092 add_variant_property (fip, type, cu);
12093
12094 /* Copy the saved-up fields into the field vector. */
12095 for (int i = 0; i < nfields; ++i)
12096 {
12097 struct nextfield &field
12098 = ((i < fip->baseclasses.size ()) ? fip->baseclasses[i]
12099 : fip->fields[i - fip->baseclasses.size ()]);
12100
12101 type->field (i) = field.field;
12102 switch (field.accessibility)
12103 {
12104 case DW_ACCESS_private:
12105 if (cu->lang () != language_ada)
12107 break;
12108
12109 case DW_ACCESS_protected:
12110 if (cu->lang () != language_ada)
12112 break;
12113
12114 case DW_ACCESS_public:
12115 break;
12116
12117 default:
12118 /* Unknown accessibility. Complain and treat it as public. */
12119 {
12120 complaint (_("unsupported accessibility %d"),
12121 field.accessibility);
12122 }
12123 break;
12124 }
12125 if (i < fip->baseclasses.size ())
12126 {
12127 switch (field.virtuality)
12128 {
12129 case DW_VIRTUALITY_virtual:
12130 case DW_VIRTUALITY_pure_virtual:
12131 if (cu->lang () == language_ada)
12132 error (_("unexpected virtuality in component of Ada type"));
12134 break;
12135 }
12136 }
12137 }
12138}
12139
12140/* Return true if this member function is a constructor, false
12141 otherwise. */
12142
12143static int
12145{
12146 const char *fieldname;
12147 const char *type_name;
12148 int len;
12149
12150 if (die->parent == NULL)
12151 return 0;
12152
12153 if (die->parent->tag != DW_TAG_structure_type
12154 && die->parent->tag != DW_TAG_union_type
12155 && die->parent->tag != DW_TAG_class_type)
12156 return 0;
12157
12158 fieldname = dwarf2_name (die, cu);
12159 type_name = dwarf2_name (die->parent, cu);
12160 if (fieldname == NULL || type_name == NULL)
12161 return 0;
12162
12163 len = strlen (fieldname);
12164 return (strncmp (fieldname, type_name, len) == 0
12165 && (type_name[len] == '\0' || type_name[len] == '<'));
12166}
12167
12168/* Add a member function to the proper fieldlist. */
12169
12170static void
12171dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
12172 struct type *type, struct dwarf2_cu *cu)
12173{
12174 struct objfile *objfile = cu->per_objfile->objfile;
12175 struct attribute *attr;
12176 int i;
12177 struct fnfieldlist *flp = nullptr;
12178 struct fn_field *fnp;
12179 const char *fieldname;
12180 struct type *this_type;
12181
12182 if (cu->lang () == language_ada)
12183 error (_("unexpected member function in Ada type"));
12184
12185 /* Get name of member function. */
12186 fieldname = dwarf2_name (die, cu);
12187 if (fieldname == NULL)
12188 return;
12189
12190 /* Look up member function name in fieldlist. */
12191 for (i = 0; i < fip->fnfieldlists.size (); i++)
12192 {
12193 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
12194 {
12195 flp = &fip->fnfieldlists[i];
12196 break;
12197 }
12198 }
12199
12200 /* Create a new fnfieldlist if necessary. */
12201 if (flp == nullptr)
12202 {
12203 fip->fnfieldlists.emplace_back ();
12204 flp = &fip->fnfieldlists.back ();
12205 flp->name = fieldname;
12206 i = fip->fnfieldlists.size () - 1;
12207 }
12208
12209 /* Create a new member function field and add it to the vector of
12210 fnfieldlists. */
12211 flp->fnfields.emplace_back ();
12212 fnp = &flp->fnfields.back ();
12213
12214 /* Delay processing of the physname until later. */
12215 if (cu->lang () == language_cplus)
12216 add_to_method_list (type, i, flp->fnfields.size () - 1, fieldname,
12217 die, cu);
12218 else
12219 {
12220 const char *physname = dwarf2_physname (fieldname, die, cu);
12221 fnp->physname = physname ? physname : "";
12222 }
12223
12224 fnp->type = type_allocator (objfile, cu->lang ()).new_type ();
12225 this_type = read_type_die (die, cu);
12226 if (this_type && this_type->code () == TYPE_CODE_FUNC)
12227 {
12228 int nparams = this_type->num_fields ();
12229
12230 /* TYPE is the domain of this method, and THIS_TYPE is the type
12231 of the method itself (TYPE_CODE_METHOD). */
12233 this_type->target_type (),
12234 this_type->fields (),
12235 this_type->num_fields (),
12236 this_type->has_varargs ());
12237
12238 /* Handle static member functions.
12239 Dwarf2 has no clean way to discern C++ static and non-static
12240 member functions. G++ helps GDB by marking the first
12241 parameter for non-static member functions (which is the this
12242 pointer) as artificial. We obtain this information from
12243 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
12244 if (nparams == 0 || this_type->field (0).is_artificial () == 0)
12245 fnp->voffset = VOFFSET_STATIC;
12246 }
12247 else
12248 complaint (_("member function type missing for '%s'"),
12249 dwarf2_full_name (fieldname, die, cu));
12250
12251 /* Get fcontext from DW_AT_containing_type if present. */
12252 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
12253 fnp->fcontext = die_containing_type (die, cu);
12254
12255 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
12256 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
12257
12258 /* Get accessibility. */
12259 dwarf_access_attribute accessibility = dwarf2_access_attribute (die, cu);
12260 switch (accessibility)
12261 {
12262 case DW_ACCESS_private:
12263 fnp->is_private = 1;
12264 break;
12265 case DW_ACCESS_protected:
12266 fnp->is_protected = 1;
12267 break;
12268 }
12269
12270 /* Check for artificial methods. */
12271 attr = dwarf2_attr (die, DW_AT_artificial, cu);
12272 if (attr && attr->as_boolean ())
12273 fnp->is_artificial = 1;
12274
12275 /* Check for defaulted methods. */
12276 attr = dwarf2_attr (die, DW_AT_defaulted, cu);
12277 if (attr != nullptr)
12278 fnp->defaulted = attr->defaulted ();
12279
12280 /* Check for deleted methods. */
12281 attr = dwarf2_attr (die, DW_AT_deleted, cu);
12282 if (attr != nullptr && attr->as_boolean ())
12283 fnp->is_deleted = 1;
12284
12285 fnp->is_constructor = dwarf2_is_constructor (die, cu);
12286
12287 /* Get index in virtual function table if it is a virtual member
12288 function. For older versions of GCC, this is an offset in the
12289 appropriate virtual table, as specified by DW_AT_containing_type.
12290 For everyone else, it is an expression to be evaluated relative
12291 to the object address. */
12292
12293 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
12294 if (attr != nullptr)
12295 {
12296 if (attr->form_is_block () && attr->as_block ()->size > 0)
12297 {
12298 struct dwarf_block *block = attr->as_block ();
12299 CORE_ADDR offset;
12300
12301 if (block->data[0] == DW_OP_constu
12302 && decode_locdesc (block, cu, &offset))
12303 {
12304 /* "Old"-style GCC. See
12305 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44126
12306 for discussion. This was known and a patch available
12307 in 2010, but as of 2023, both GCC and clang still
12308 emit this. */
12309 fnp->voffset = offset + 2;
12310 }
12311 else if ((block->data[0] == DW_OP_deref
12312 || (block->size > 1
12313 && block->data[0] == DW_OP_deref_size
12314 && block->data[1] == cu->header.addr_size))
12315 && decode_locdesc (block, cu, &offset))
12316 {
12317 fnp->voffset = offset;
12318 if ((fnp->voffset % cu->header.addr_size) != 0)
12320 else
12321 fnp->voffset /= cu->header.addr_size;
12322 fnp->voffset += 2;
12323 }
12324 else
12326
12327 if (!fnp->fcontext)
12328 {
12329 /* If there is no `this' field and no DW_AT_containing_type,
12330 we cannot actually find a base class context for the
12331 vtable! */
12332 if (this_type->num_fields () == 0
12333 || !this_type->field (0).is_artificial ())
12334 {
12335 complaint (_("cannot determine context for virtual member "
12336 "function \"%s\" (offset %s)"),
12337 fieldname, sect_offset_str (die->sect_off));
12338 }
12339 else
12340 {
12341 fnp->fcontext = this_type->field (0).type ()->target_type ();
12342 }
12343 }
12344 }
12345 else if (attr->form_is_section_offset ())
12346 {
12348 }
12349 else
12350 {
12351 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
12352 fieldname);
12353 }
12354 }
12355 else
12356 {
12357 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
12358 if (attr != nullptr && attr->as_virtuality () != DW_VIRTUALITY_none)
12359 {
12360 /* GCC does this, as of 2008-08-25; PR debug/37237. */
12361 complaint (_("Member function \"%s\" (offset %s) is virtual "
12362 "but the vtable offset is not specified"),
12363 fieldname, sect_offset_str (die->sect_off));
12366 }
12367 }
12368}
12369
12370/* Create the vector of member function fields, and attach it to the type. */
12371
12372static void
12374 struct dwarf2_cu *cu)
12375{
12376 if (cu->lang () == language_ada)
12377 error (_("unexpected member functions in Ada type"));
12378
12380 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
12382 sizeof (struct fn_fieldlist) * fip->fnfieldlists.size ());
12383
12384 for (int i = 0; i < fip->fnfieldlists.size (); i++)
12385 {
12386 struct fnfieldlist &nf = fip->fnfieldlists[i];
12387 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
12388
12390 TYPE_FN_FIELDLIST_LENGTH (type, i) = nf.fnfields.size ();
12391 /* No need to zero-initialize, initialization is done by the copy in
12392 the loop below. */
12393 fn_flp->fn_fields = (struct fn_field *)
12394 TYPE_ALLOC (type, sizeof (struct fn_field) * nf.fnfields.size ());
12395
12396 for (int k = 0; k < nf.fnfields.size (); ++k)
12397 fn_flp->fn_fields[k] = nf.fnfields[k];
12398 }
12399
12400 TYPE_NFN_FIELDS (type) = fip->fnfieldlists.size ();
12401}
12402
12403/* Returns non-zero if NAME is the name of a vtable member in CU's
12404 language, zero otherwise. */
12405static int
12406is_vtable_name (const char *name, struct dwarf2_cu *cu)
12407{
12408 static const char vptr[] = "_vptr";
12409
12410 /* Look for the C++ form of the vtable. */
12411 if (startswith (name, vptr) && is_cplus_marker (name[sizeof (vptr) - 1]))
12412 return 1;
12413
12414 return 0;
12415}
12416
12417/* GCC outputs unnamed structures that are really pointers to member
12418 functions, with the ABI-specified layout. If TYPE describes
12419 such a structure, smash it into a member function type.
12420
12421 GCC shouldn't do this; it should just output pointer to member DIEs.
12422 This is GCC PR debug/28767. */
12423
12424static void
12426{
12427 struct type *pfn_type, *self_type, *new_type;
12428
12429 /* Check for a structure with no name and two children. */
12430 if (type->code () != TYPE_CODE_STRUCT || type->num_fields () != 2)
12431 return;
12432
12433 /* Check for __pfn and __delta members. */
12434 if (type->field (0).name () == NULL
12435 || strcmp (type->field (0).name (), "__pfn") != 0
12436 || type->field (1).name () == NULL
12437 || strcmp (type->field (1).name (), "__delta") != 0)
12438 return;
12439
12440 /* Find the type of the method. */
12441 pfn_type = type->field (0).type ();
12442 if (pfn_type == NULL
12443 || pfn_type->code () != TYPE_CODE_PTR
12444 || pfn_type->target_type ()->code () != TYPE_CODE_FUNC)
12445 return;
12446
12447 /* Look for the "this" argument. */
12448 pfn_type = pfn_type->target_type ();
12449 if (pfn_type->num_fields () == 0
12450 /* || pfn_type->field (0).type () == NULL */
12451 || pfn_type->field (0).type ()->code () != TYPE_CODE_PTR)
12452 return;
12453
12454 self_type = pfn_type->field (0).type ()->target_type ();
12456 smash_to_method_type (new_type, self_type, pfn_type->target_type (),
12457 pfn_type->fields (), pfn_type->num_fields (),
12458 pfn_type->has_varargs ());
12460}
12461
12462/* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
12463 requires rewriting, then copy it and return the updated copy.
12464 Otherwise return nullptr. */
12465
12466static struct type *
12468{
12469 if (type->code () != TYPE_CODE_ARRAY)
12470 return nullptr;
12471
12472 struct type *index_type = type->index_type ();
12473 range_bounds *current_bounds = index_type->bounds ();
12474
12475 /* Handle multi-dimensional arrays. */
12476 struct type *new_target = rewrite_array_type (type->target_type ());
12477 if (new_target == nullptr)
12478 {
12479 /* Maybe we don't need to rewrite this array. */
12480 if (current_bounds->low.is_constant ()
12481 && current_bounds->high.is_constant ())
12482 return nullptr;
12483 }
12484
12485 /* Either the target type was rewritten, or the bounds have to be
12486 updated. Either way we want to copy the type and update
12487 everything. */
12488 struct type *copy = copy_type (type);
12489 copy->copy_fields (type);
12490 if (new_target != nullptr)
12491 copy->set_target_type (new_target);
12492
12493 struct type *index_copy = copy_type (index_type);
12495 = (struct range_bounds *) TYPE_ZALLOC (index_copy,
12496 sizeof (range_bounds));
12497 *bounds = *current_bounds;
12498 bounds->low.set_const_val (1);
12499 bounds->high.set_const_val (0);
12500 index_copy->set_bounds (bounds);
12501 copy->set_index_type (index_copy);
12502
12503 return copy;
12504}
12505
12506/* While some versions of GCC will generate complicated DWARF for an
12507 array (see quirk_ada_thick_pointer), more recent versions were
12508 modified to emit an explicit thick pointer structure. However, in
12509 this case, the array still has DWARF expressions for its ranges,
12510 and these must be ignored. */
12511
12512static void
12514 struct type *type)
12515{
12516 gdb_assert (cu->lang () == language_ada);
12517
12518 /* Check for a structure with two children. */
12519 if (type->code () != TYPE_CODE_STRUCT || type->num_fields () != 2)
12520 return;
12521
12522 /* Check for P_ARRAY and P_BOUNDS members. */
12523 if (type->field (0).name () == NULL
12524 || strcmp (type->field (0).name (), "P_ARRAY") != 0
12525 || type->field (1).name () == NULL
12526 || strcmp (type->field (1).name (), "P_BOUNDS") != 0)
12527 return;
12528
12529 /* Make sure we're looking at a pointer to an array. */
12530 if (type->field (0).type ()->code () != TYPE_CODE_PTR)
12531 return;
12532
12533 /* The Ada code already knows how to handle these types, so all that
12534 we need to do is turn the bounds into static bounds. However, we
12535 don't want to rewrite existing array or index types in-place,
12536 because those may be referenced in other contexts where this
12537 rewriting is undesirable. */
12538 struct type *new_ary_type
12540 if (new_ary_type != nullptr)
12541 type->field (0).set_type (lookup_pointer_type (new_ary_type));
12542}
12543
12544/* If the DIE has a DW_AT_alignment attribute, return its value, doing
12545 appropriate error checking and issuing complaints if there is a
12546 problem. */
12547
12548static ULONGEST
12549get_alignment (struct dwarf2_cu *cu, struct die_info *die)
12550{
12551 struct attribute *attr = dwarf2_attr (die, DW_AT_alignment, cu);
12552
12553 if (attr == nullptr)
12554 return 0;
12555
12556 if (!attr->form_is_constant ())
12557 {
12558 complaint (_("DW_AT_alignment must have constant form"
12559 " - DIE at %s [in module %s]"),
12562 return 0;
12563 }
12564
12565 LONGEST val = attr->constant_value (0);
12566 if (val < 0)
12567 {
12568 complaint (_("DW_AT_alignment value must not be negative"
12569 " - DIE at %s [in module %s]"),
12572 return 0;
12573 }
12574 ULONGEST align = val;
12575
12576 if (align == 0)
12577 {
12578 complaint (_("DW_AT_alignment value must not be zero"
12579 " - DIE at %s [in module %s]"),
12582 return 0;
12583 }
12584 if ((align & (align - 1)) != 0)
12585 {
12586 complaint (_("DW_AT_alignment value must be a power of 2"
12587 " - DIE at %s [in module %s]"),
12590 return 0;
12591 }
12592
12593 return align;
12594}
12595
12596/* If the DIE has a DW_AT_alignment attribute, use its value to set
12597 the alignment for TYPE. */
12598
12599static void
12600maybe_set_alignment (struct dwarf2_cu *cu, struct die_info *die,
12601 struct type *type)
12602{
12603 if (!set_type_align (type, get_alignment (cu, die)))
12604 complaint (_("DW_AT_alignment value too large"
12605 " - DIE at %s [in module %s]"),
12608}
12609
12610/* Check if the given VALUE is a valid enum dwarf_calling_convention
12611 constant for a type, according to DWARF5 spec, Table 5.5. */
12612
12613static bool
12615{
12616 switch (value)
12617 {
12618 case DW_CC_normal:
12619 case DW_CC_pass_by_reference:
12620 case DW_CC_pass_by_value:
12621 return true;
12622
12623 default:
12624 complaint (_("unrecognized DW_AT_calling_convention value "
12625 "(%s) for a type"), pulongest (value));
12626 return false;
12627 }
12628}
12629
12630/* Check if the given VALUE is a valid enum dwarf_calling_convention
12631 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
12632 also according to GNU-specific values (see include/dwarf2.h). */
12633
12634static bool
12636{
12637 switch (value)
12638 {
12639 case DW_CC_normal:
12640 case DW_CC_program:
12641 case DW_CC_nocall:
12642 return true;
12643
12644 case DW_CC_GNU_renesas_sh:
12645 case DW_CC_GNU_borland_fastcall_i386:
12646 case DW_CC_GDB_IBM_OpenCL:
12647 return true;
12648
12649 default:
12650 complaint (_("unrecognized DW_AT_calling_convention value "
12651 "(%s) for a subroutine"), pulongest (value));
12652 return false;
12653 }
12654}
12655
12656/* Called when we find the DIE that starts a structure or union scope
12657 (definition) to create a type for the structure or union. Fill in
12658 the type's name and general properties; the members will not be
12659 processed until process_structure_scope. A symbol table entry for
12660 the type will also not be done until process_structure_scope (assuming
12661 the type has a name).
12662
12663 NOTE: we need to call these functions regardless of whether or not the
12664 DIE has a DW_AT_name attribute, since it might be an anonymous
12665 structure or union. This gets the type entered into our set of
12666 user defined types. */
12667
12668static struct type *
12669read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
12670{
12671 struct objfile *objfile = cu->per_objfile->objfile;
12672 struct type *type;
12673 struct attribute *attr;
12674 const char *name;
12675
12676 /* If the definition of this type lives in .debug_types, read that type.
12677 Don't follow DW_AT_specification though, that will take us back up
12678 the chain and we want to go down. */
12679 attr = die->attr (DW_AT_signature);
12680 if (attr != nullptr)
12681 {
12682 type = get_DW_AT_signature_type (die, attr, cu);
12683
12684 /* The type's CU may not be the same as CU.
12685 Ensure TYPE is recorded with CU in die_type_hash. */
12686 return set_die_type (die, type, cu);
12687 }
12688
12689 type = type_allocator (objfile, cu->lang ()).new_type ();
12691
12692 name = dwarf2_name (die, cu);
12693 if (name != NULL)
12694 {
12695 if (cu->lang () == language_cplus
12696 || cu->lang () == language_d
12697 || cu->lang () == language_rust)
12698 {
12699 const char *full_name = dwarf2_full_name (name, die, cu);
12700
12701 /* dwarf2_full_name might have already finished building the DIE's
12702 type. If so, there is no need to continue. */
12703 if (get_die_type (die, cu) != NULL)
12704 return get_die_type (die, cu);
12705
12706 type->set_name (full_name);
12707 }
12708 else
12709 {
12710 /* The name is already allocated along with this objfile, so
12711 we don't need to duplicate it for the type. */
12712 type->set_name (name);
12713 }
12714 }
12715
12716 if (die->tag == DW_TAG_structure_type)
12717 {
12718 type->set_code (TYPE_CODE_STRUCT);
12719 }
12720 else if (die->tag == DW_TAG_union_type)
12721 {
12722 type->set_code (TYPE_CODE_UNION);
12723 }
12724 else if (die->tag == DW_TAG_namelist)
12725 {
12726 type->set_code (TYPE_CODE_NAMELIST);
12727 }
12728 else
12729 {
12730 type->set_code (TYPE_CODE_STRUCT);
12731 }
12732
12733 if (cu->lang () == language_cplus && die->tag == DW_TAG_class_type)
12735
12736 /* Store the calling convention in the type if it's available in
12737 the die. Otherwise the calling convention remains set to
12738 the default value DW_CC_normal. */
12739 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
12740 if (attr != nullptr
12742 {
12745 = (enum dwarf_calling_convention) (attr->constant_value (0));
12746 }
12747
12748 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12749 if (attr != nullptr)
12750 {
12751 if (attr->form_is_constant ())
12752 type->set_length (attr->constant_value (0));
12753 else
12754 {
12755 struct dynamic_prop prop;
12756 if (attr_to_dynamic_prop (attr, die, cu, &prop, cu->addr_type ()))
12758
12759 type->set_length (0);
12760 }
12761 }
12762 else
12763 type->set_length (0);
12764
12765 maybe_set_alignment (cu, die, type);
12766
12767 if (producer_is_icc_lt_14 (cu) && (type->length () == 0))
12768 {
12769 /* ICC<14 does not output the required DW_AT_declaration on
12770 incomplete types, but gives them a size of zero. */
12771 type->set_is_stub (true);
12772 }
12773 else
12775
12776 if (die_is_declaration (die, cu))
12777 type->set_is_stub (true);
12778 else if (attr == NULL && die->child == NULL
12780 /* RealView does not output the required DW_AT_declaration
12781 on incomplete types. */
12782 type->set_is_stub (true);
12783
12784 /* We need to add the type field to the die immediately so we don't
12785 infinitely recurse when dealing with pointers to the structure
12786 type within the structure itself. */
12787 set_die_type (die, type, cu);
12788
12789 /* set_die_type should be already done. */
12790 set_descriptive_type (type, die, cu);
12791
12792 return type;
12793}
12794
12795static void handle_struct_member_die
12796 (struct die_info *child_die,
12797 struct type *type,
12798 struct field_info *fi,
12799 std::vector<struct symbol *> *template_args,
12800 struct dwarf2_cu *cu);
12801
12802/* A helper for handle_struct_member_die that handles
12803 DW_TAG_variant_part. */
12804
12805static void
12807 struct field_info *fi,
12808 std::vector<struct symbol *> *template_args,
12809 struct dwarf2_cu *cu)
12810{
12811 variant_part_builder *new_part;
12812 if (fi->current_variant_part == nullptr)
12813 {
12814 fi->variant_parts.emplace_back ();
12815 new_part = &fi->variant_parts.back ();
12816 }
12818 {
12819 complaint (_("nested DW_TAG_variant_part seen "
12820 "- DIE at %s [in module %s]"),
12823 return;
12824 }
12825 else
12826 {
12827 variant_field &current = fi->current_variant_part->variants.back ();
12828 current.variant_parts.emplace_back ();
12829 new_part = &current.variant_parts.back ();
12830 }
12831
12832 /* When we recurse, we want callees to add to this new variant
12833 part. */
12834 scoped_restore save_current_variant_part
12835 = make_scoped_restore (&fi->current_variant_part, new_part);
12836
12837 struct attribute *discr = dwarf2_attr (die, DW_AT_discr, cu);
12838 if (discr == NULL)
12839 {
12840 /* It's a univariant form, an extension we support. */
12841 }
12842 else if (discr->form_is_ref ())
12843 {
12844 struct dwarf2_cu *target_cu = cu;
12845 struct die_info *target_die = follow_die_ref (die, discr, &target_cu);
12846
12847 new_part->discriminant_offset = target_die->sect_off;
12848 }
12849 else
12850 {
12851 complaint (_("DW_AT_discr does not have DIE reference form"
12852 " - DIE at %s [in module %s]"),
12855 }
12856
12857 for (die_info *child_die = die->child;
12858 child_die != NULL;
12859 child_die = child_die->sibling)
12860 handle_struct_member_die (child_die, type, fi, template_args, cu);
12861}
12862
12863/* A helper for handle_struct_member_die that handles
12864 DW_TAG_variant. */
12865
12866static void
12867handle_variant (struct die_info *die, struct type *type,
12868 struct field_info *fi,
12869 std::vector<struct symbol *> *template_args,
12870 struct dwarf2_cu *cu)
12871{
12872 if (fi->current_variant_part == nullptr)
12873 {
12874 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
12875 "- DIE at %s [in module %s]"),
12878 return;
12879 }
12881 {
12882 complaint (_("nested DW_TAG_variant seen "
12883 "- DIE at %s [in module %s]"),
12886 return;
12887 }
12888
12889 scoped_restore save_processing_variant
12890 = make_scoped_restore (&fi->current_variant_part->processing_variant,
12891 true);
12892
12893 fi->current_variant_part->variants.emplace_back ();
12895 variant.first_field = fi->fields.size ();
12896
12897 /* In a variant we want to get the discriminant and also add a
12898 field for our sole member child. */
12899 struct attribute *discr = dwarf2_attr (die, DW_AT_discr_value, cu);
12900 if (discr == nullptr || !discr->form_is_constant ())
12901 {
12902 discr = dwarf2_attr (die, DW_AT_discr_list, cu);
12903 if (discr == nullptr || discr->as_block ()->size == 0)
12904 variant.default_branch = true;
12905 else
12906 variant.discr_list_data = discr->as_block ();
12907 }
12908 else
12909 variant.discriminant_value = discr->constant_value (0);
12910
12911 for (die_info *variant_child = die->child;
12912 variant_child != NULL;
12913 variant_child = variant_child->sibling)
12914 handle_struct_member_die (variant_child, type, fi, template_args, cu);
12915
12916 variant.last_field = fi->fields.size ();
12917}
12918
12919/* A helper for process_structure_scope that handles a single member
12920 DIE. */
12921
12922static void
12923handle_struct_member_die (struct die_info *child_die, struct type *type,
12924 struct field_info *fi,
12925 std::vector<struct symbol *> *template_args,
12926 struct dwarf2_cu *cu)
12927{
12928 if (child_die->tag == DW_TAG_member
12929 || child_die->tag == DW_TAG_variable
12930 || child_die->tag == DW_TAG_namelist_item)
12931 {
12932 /* NOTE: carlton/2002-11-05: A C++ static data member
12933 should be a DW_TAG_member that is a declaration, but
12934 all versions of G++ as of this writing (so through at
12935 least 3.2.1) incorrectly generate DW_TAG_variable
12936 tags for them instead. */
12937 dwarf2_add_field (fi, child_die, cu);
12938 }
12939 else if (child_die->tag == DW_TAG_subprogram)
12940 {
12941 /* Rust doesn't have member functions in the C++ sense.
12942 However, it does emit ordinary functions as children
12943 of a struct DIE. */
12944 if (cu->lang () == language_rust)
12945 read_func_scope (child_die, cu);
12946 else
12947 {
12948 /* C++ member function. */
12949 dwarf2_add_member_fn (fi, child_die, type, cu);
12950 }
12951 }
12952 else if (child_die->tag == DW_TAG_inheritance)
12953 {
12954 /* C++ base class field. */
12955 dwarf2_add_field (fi, child_die, cu);
12956 }
12957 else if (type_can_define_types (child_die))
12958 dwarf2_add_type_defn (fi, child_die, cu);
12959 else if (child_die->tag == DW_TAG_template_type_param
12960 || child_die->tag == DW_TAG_template_value_param)
12961 {
12962 struct symbol *arg = new_symbol (child_die, NULL, cu);
12963
12964 if (arg != NULL)
12965 template_args->push_back (arg);
12966 }
12967 else if (child_die->tag == DW_TAG_variant_part)
12968 handle_variant_part (child_die, type, fi, template_args, cu);
12969 else if (child_die->tag == DW_TAG_variant)
12970 handle_variant (child_die, type, fi, template_args, cu);
12971}
12972
12973/* Finish creating a structure or union type, including filling in its
12974 members and creating a symbol for it. This function also handles Fortran
12975 namelist variables, their items or members and creating a symbol for
12976 them. */
12977
12978static void
12980{
12981 struct objfile *objfile = cu->per_objfile->objfile;
12982 struct die_info *child_die;
12983 struct type *type;
12984
12985 type = get_die_type (die, cu);
12986 if (type == NULL)
12987 type = read_structure_type (die, cu);
12988
12989 bool has_template_parameters = false;
12990 if (die->child != NULL && ! die_is_declaration (die, cu))
12991 {
12992 struct field_info fi;
12993 std::vector<struct symbol *> template_args;
12994
12995 child_die = die->child;
12996
12997 while (child_die && child_die->tag)
12998 {
12999 handle_struct_member_die (child_die, type, &fi, &template_args, cu);
13000 child_die = child_die->sibling;
13001 }
13002
13003 /* Attach template arguments to type. */
13004 if (!template_args.empty ())
13005 {
13006 has_template_parameters = true;
13008 TYPE_N_TEMPLATE_ARGUMENTS (type) = template_args.size ();
13010 = XOBNEWVEC (&objfile->objfile_obstack,
13011 struct symbol *,
13013 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
13014 template_args.data (),
13016 * sizeof (struct symbol *)));
13017 }
13018
13019 /* Attach fields and member functions to the type. */
13020 if (fi.nfields () > 0)
13022 if (!fi.fnfieldlists.empty ())
13023 {
13025
13026 /* Get the type which refers to the base class (possibly this
13027 class itself) which contains the vtable pointer for the current
13028 class from the DW_AT_containing_type attribute. This use of
13029 DW_AT_containing_type is a GNU extension. */
13030
13031 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
13032 {
13033 struct type *t = die_containing_type (die, cu);
13034
13036 if (type == t)
13037 {
13038 int i;
13039
13040 /* Our own class provides vtbl ptr. */
13041 for (i = t->num_fields () - 1;
13042 i >= TYPE_N_BASECLASSES (t);
13043 --i)
13044 {
13045 const char *fieldname = t->field (i).name ();
13046
13047 if (is_vtable_name (fieldname, cu))
13048 {
13050 break;
13051 }
13052 }
13053
13054 /* Complain if virtual function table field not found. */
13055 if (i < TYPE_N_BASECLASSES (t))
13056 complaint (_("virtual function table pointer "
13057 "not found when defining class '%s'"),
13058 type->name () ? type->name () : "");
13059 }
13060 else
13061 {
13063 }
13064 }
13065 else if (cu->producer
13066 && startswith (cu->producer, "IBM(R) XL C/C++ Advanced Edition"))
13067 {
13068 /* The IBM XLC compiler does not provide direct indication
13069 of the containing type, but the vtable pointer is
13070 always named __vfp. */
13071
13072 int i;
13073
13074 for (i = type->num_fields () - 1;
13075 i >= TYPE_N_BASECLASSES (type);
13076 --i)
13077 {
13078 if (strcmp (type->field (i).name (), "__vfp") == 0)
13079 {
13082 break;
13083 }
13084 }
13085 }
13086 }
13087
13088 /* Copy fi.typedef_field_list linked list elements content into the
13089 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13090 if (!fi.typedef_field_list.empty ())
13091 {
13092 int count = fi.typedef_field_list.size ();
13093
13095 /* No zero-initialization is needed, the elements are initialized by
13096 the copy in the loop below. */
13098 = ((struct decl_field *)
13100 sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * count));
13102
13103 for (int i = 0; i < fi.typedef_field_list.size (); ++i)
13105 }
13106
13107 /* Copy fi.nested_types_list linked list elements content into the
13108 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
13109 if (!fi.nested_types_list.empty ()
13110 && cu->lang () != language_ada)
13111 {
13112 int count = fi.nested_types_list.size ();
13113
13115 /* No zero-initialization is needed, the elements are initialized by
13116 the copy in the loop below. */
13118 = ((struct decl_field *)
13119 TYPE_ALLOC (type, sizeof (struct decl_field) * count));
13120 TYPE_NESTED_TYPES_COUNT (type) = count;
13121
13122 for (int i = 0; i < fi.nested_types_list.size (); ++i)
13124 }
13125 }
13126
13128 if (cu->lang () == language_rust && die->tag == DW_TAG_union_type)
13129 cu->rust_unions.push_back (type);
13130 else if (cu->lang () == language_ada)
13132
13133 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13134 snapshots) has been known to create a die giving a declaration
13135 for a class that has, as a child, a die giving a definition for a
13136 nested class. So we have to process our children even if the
13137 current die is a declaration. Normally, of course, a declaration
13138 won't have any children at all. */
13139
13140 child_die = die->child;
13141
13142 while (child_die != NULL && child_die->tag)
13143 {
13144 if (child_die->tag == DW_TAG_member
13145 || child_die->tag == DW_TAG_variable
13146 || child_die->tag == DW_TAG_inheritance
13147 || child_die->tag == DW_TAG_template_value_param
13148 || child_die->tag == DW_TAG_template_type_param)
13149 {
13150 /* Do nothing. */
13151 }
13152 else
13153 process_die (child_die, cu);
13154
13155 child_die = child_die->sibling;
13156 }
13157
13158 /* Do not consider external references. According to the DWARF standard,
13159 these DIEs are identified by the fact that they have no byte_size
13160 attribute, and a declaration attribute. */
13161 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
13162 || !die_is_declaration (die, cu)
13163 || dwarf2_attr (die, DW_AT_signature, cu) != NULL)
13164 {
13165 struct symbol *sym = new_symbol (die, type, cu);
13166
13167 if (has_template_parameters)
13168 {
13169 struct symtab *symtab;
13170 if (sym != nullptr)
13171 symtab = sym->symtab ();
13172 else if (cu->line_header != nullptr)
13173 {
13174 /* Any related symtab will do. */
13175 symtab
13176 = cu->line_header->file_names ()[0].symtab;
13177 }
13178 else
13179 {
13180 symtab = nullptr;
13181 complaint (_("could not find suitable "
13182 "symtab for template parameter"
13183 " - DIE at %s [in module %s]"),
13186 }
13187
13188 if (symtab != nullptr)
13189 {
13190 /* Make sure that the symtab is set on the new symbols.
13191 Even though they don't appear in this symtab directly,
13192 other parts of gdb assume that symbols do, and this is
13193 reasonably true. */
13194 for (int i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
13195 TYPE_TEMPLATE_ARGUMENT (type, i)->set_symtab (symtab);
13196 }
13197 }
13198 }
13199}
13200
13201/* Assuming DIE is an enumeration type, and TYPE is its associated
13202 type, update TYPE using some information only available in DIE's
13203 children. In particular, the fields are computed. */
13204
13205static void
13207 struct type *type,
13208 struct dwarf2_cu *cu)
13209{
13210 struct die_info *child_die;
13211 int unsigned_enum = 1;
13212 int flag_enum = 1;
13213
13214 auto_obstack obstack;
13215 std::vector<struct field> fields;
13216
13217 for (child_die = die->child;
13218 child_die != NULL && child_die->tag;
13219 child_die = child_die->sibling)
13220 {
13221 struct attribute *attr;
13222 LONGEST value;
13223 const gdb_byte *bytes;
13224 struct dwarf2_locexpr_baton *baton;
13225 const char *name;
13226
13227 if (child_die->tag != DW_TAG_enumerator)
13228 continue;
13229
13230 attr = dwarf2_attr (child_die, DW_AT_const_value, cu);
13231 if (attr == NULL)
13232 continue;
13233
13234 name = dwarf2_name (child_die, cu);
13235 if (name == NULL)
13236 name = "<anonymous enumerator>";
13237
13238 dwarf2_const_value_attr (attr, type, name, &obstack, cu,
13239 &value, &bytes, &baton);
13240 if (value < 0)
13241 {
13242 unsigned_enum = 0;
13243 flag_enum = 0;
13244 }
13245 else
13246 {
13247 if (count_one_bits_ll (value) >= 2)
13248 flag_enum = 0;
13249 }
13250
13251 fields.emplace_back ();
13252 struct field &field = fields.back ();
13253 field.set_name (dwarf2_physname (name, child_die, cu));
13255 }
13256
13257 if (!fields.empty ())
13258 type->copy_fields (fields);
13259 else
13260 flag_enum = 0;
13261
13262 if (unsigned_enum)
13263 type->set_is_unsigned (true);
13264
13265 if (flag_enum)
13266 type->set_is_flag_enum (true);
13267}
13268
13269/* Given a DW_AT_enumeration_type die, set its type. We do not
13270 complete the type's fields yet, or create any symbols. */
13271
13272static struct type *
13274{
13275 struct objfile *objfile = cu->per_objfile->objfile;
13276 struct type *type;
13277 struct attribute *attr;
13278 const char *name;
13279
13280 /* If the definition of this type lives in .debug_types, read that type.
13281 Don't follow DW_AT_specification though, that will take us back up
13282 the chain and we want to go down. */
13283 attr = die->attr (DW_AT_signature);
13284 if (attr != nullptr)
13285 {
13286 type = get_DW_AT_signature_type (die, attr, cu);
13287
13288 /* The type's CU may not be the same as CU.
13289 Ensure TYPE is recorded with CU in die_type_hash. */
13290 return set_die_type (die, type, cu);
13291 }
13292
13293 type = type_allocator (objfile, cu->lang ()).new_type ();
13294
13295 type->set_code (TYPE_CODE_ENUM);
13296 name = dwarf2_full_name (NULL, die, cu);
13297 if (name != NULL)
13298 type->set_name (name);
13299
13300 attr = dwarf2_attr (die, DW_AT_type, cu);
13301 if (attr != NULL)
13302 {
13303 struct type *underlying_type = die_type (die, cu);
13304
13305 type->set_target_type (underlying_type);
13306 }
13307
13308 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
13309 if (attr != nullptr)
13310 type->set_length (attr->constant_value (0));
13311 else
13312 type->set_length (0);
13313
13314 maybe_set_alignment (cu, die, type);
13315
13316 /* The enumeration DIE can be incomplete. In Ada, any type can be
13317 declared as private in the package spec, and then defined only
13318 inside the package body. Such types are known as Taft Amendment
13319 Types. When another package uses such a type, an incomplete DIE
13320 may be generated by the compiler. */
13321 if (die_is_declaration (die, cu))
13322 type->set_is_stub (true);
13323
13324 /* If this type has an underlying type that is not a stub, then we
13325 may use its attributes. We always use the "unsigned" attribute
13326 in this situation, because ordinarily we guess whether the type
13327 is unsigned -- but the guess can be wrong and the underlying type
13328 can tell us the reality. However, we defer to a local size
13329 attribute if one exists, because this lets the compiler override
13330 the underlying type if needed. */
13331 if (type->target_type () != NULL && !type->target_type ()->is_stub ())
13332 {
13333 struct type *underlying_type = type->target_type ();
13334 underlying_type = check_typedef (underlying_type);
13335
13336 type->set_is_unsigned (underlying_type->is_unsigned ());
13337
13338 if (type->length () == 0)
13339 type->set_length (underlying_type->length ());
13340
13341 if (TYPE_RAW_ALIGN (type) == 0
13342 && TYPE_RAW_ALIGN (underlying_type) != 0)
13343 set_type_align (type, TYPE_RAW_ALIGN (underlying_type));
13344 }
13345
13346 type->set_is_declared_class (dwarf2_flag_true_p (die, DW_AT_enum_class, cu));
13347
13348 set_die_type (die, type, cu);
13349
13350 /* Finish the creation of this type by using the enum's children.
13351 Note that, as usual, this must come after set_die_type to avoid
13352 infinite recursion when trying to compute the names of the
13353 enumerators. */
13355
13356 return type;
13357}
13358
13359/* Given a pointer to a die which begins an enumeration, process all
13360 the dies that define the members of the enumeration, and create the
13361 symbol for the enumeration type.
13362
13363 NOTE: We reverse the order of the element list. */
13364
13365static void
13367{
13368 struct type *this_type;
13369
13370 this_type = get_die_type (die, cu);
13371 if (this_type == NULL)
13372 this_type = read_enumeration_type (die, cu);
13373
13374 if (die->child != NULL)
13375 {
13376 struct die_info *child_die;
13377 const char *name;
13378
13379 child_die = die->child;
13380 while (child_die && child_die->tag)
13381 {
13382 if (child_die->tag != DW_TAG_enumerator)
13383 {
13384 process_die (child_die, cu);
13385 }
13386 else
13387 {
13388 name = dwarf2_name (child_die, cu);
13389 if (name)
13390 new_symbol (child_die, this_type, cu);
13391 }
13392
13393 child_die = child_die->sibling;
13394 }
13395 }
13396
13397 /* If we are reading an enum from a .debug_types unit, and the enum
13398 is a declaration, and the enum is not the signatured type in the
13399 unit, then we do not want to add a symbol for it. Adding a
13400 symbol would in some cases obscure the true definition of the
13401 enum, giving users an incomplete type when the definition is
13402 actually available. Note that we do not want to do this for all
13403 enums which are just declarations, because C++0x allows forward
13404 enum declarations. */
13405 if (cu->per_cu->is_debug_types
13406 && die_is_declaration (die, cu))
13407 {
13408 struct signatured_type *sig_type;
13409
13410 sig_type = (struct signatured_type *) cu->per_cu;
13411 gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
13412 if (sig_type->type_offset_in_section != die->sect_off)
13413 return;
13414 }
13415
13416 new_symbol (die, this_type, cu);
13417}
13418
13419/* Helper function for quirk_ada_thick_pointer that examines a bounds
13420 expression for an index type and finds the corresponding field
13421 offset in the hidden "P_BOUNDS" structure. Returns true on success
13422 and updates *FIELD, false if it fails to recognize an
13423 expression. */
13424
13425static bool
13426recognize_bound_expression (struct die_info *die, enum dwarf_attribute name,
13427 int *bounds_offset, struct field *field,
13428 struct dwarf2_cu *cu)
13429{
13430 struct attribute *attr = dwarf2_attr (die, name, cu);
13431 if (attr == nullptr || !attr->form_is_block ())
13432 return false;
13433
13434 const struct dwarf_block *block = attr->as_block ();
13435 const gdb_byte *start = block->data;
13436 const gdb_byte *end = block->data + block->size;
13437
13438 /* The expression to recognize generally looks like:
13439
13440 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13441 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
13442
13443 However, the second "plus_uconst" may be missing:
13444
13445 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13446 DW_OP_deref_size: 4)
13447
13448 This happens when the field is at the start of the structure.
13449
13450 Also, the final deref may not be sized:
13451
13452 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
13453 DW_OP_deref)
13454
13455 This happens when the size of the index type happens to be the
13456 same as the architecture's word size. This can occur with or
13457 without the second plus_uconst. */
13458
13459 if (end - start < 2)
13460 return false;
13461 if (*start++ != DW_OP_push_object_address)
13462 return false;
13463 if (*start++ != DW_OP_plus_uconst)
13464 return false;
13465
13466 uint64_t this_bound_off;
13467 start = gdb_read_uleb128 (start, end, &this_bound_off);
13468 if (start == nullptr || (int) this_bound_off != this_bound_off)
13469 return false;
13470 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
13471 is consistent among all bounds. */
13472 if (*bounds_offset == -1)
13473 *bounds_offset = this_bound_off;
13474 else if (*bounds_offset != this_bound_off)
13475 return false;
13476
13477 if (start == end || *start++ != DW_OP_deref)
13478 return false;
13479
13480 int offset = 0;
13481 if (start ==end)
13482 return false;
13483 else if (*start == DW_OP_deref_size || *start == DW_OP_deref)
13484 {
13485 /* This means an offset of 0. */
13486 }
13487 else if (*start++ != DW_OP_plus_uconst)
13488 return false;
13489 else
13490 {
13491 /* The size is the parameter to DW_OP_plus_uconst. */
13492 uint64_t val;
13493 start = gdb_read_uleb128 (start, end, &val);
13494 if (start == nullptr)
13495 return false;
13496 if ((int) val != val)
13497 return false;
13498 offset = val;
13499 }
13500
13501 if (start == end)
13502 return false;
13503
13504 uint64_t size;
13505 if (*start == DW_OP_deref_size)
13506 {
13507 start = gdb_read_uleb128 (start + 1, end, &size);
13508 if (start == nullptr)
13509 return false;
13510 }
13511 else if (*start == DW_OP_deref)
13512 {
13513 size = cu->header.addr_size;
13514 ++start;
13515 }
13516 else
13517 return false;
13518
13519 field->set_loc_bitpos (8 * offset);
13520 if (size != field->type ()->length ())
13521 field->set_bitsize (8 * size);
13522
13523 return true;
13524}
13525
13526/* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
13527 some kinds of Ada arrays:
13528
13529 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
13530 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
13531 <11e0> DW_AT_data_location: 2 byte block: 97 6
13532 (DW_OP_push_object_address; DW_OP_deref)
13533 <11e3> DW_AT_type : <0x1173>
13534 <11e7> DW_AT_sibling : <0x1201>
13535 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
13536 <11ec> DW_AT_type : <0x1206>
13537 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
13538 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13539 DW_OP_deref_size: 4)
13540 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
13541 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13542 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
13543
13544 This actually represents a "thick pointer", which is a structure
13545 with two elements: one that is a pointer to the array data, and one
13546 that is a pointer to another structure; this second structure holds
13547 the array bounds.
13548
13549 This returns a new type on success, or nullptr if this didn't
13550 recognize the type. */
13551
13552static struct type *
13554 struct type *type)
13555{
13556 struct attribute *attr = dwarf2_attr (die, DW_AT_data_location, cu);
13557 /* So far we've only seen this with block form. */
13558 if (attr == nullptr || !attr->form_is_block ())
13559 return nullptr;
13560
13561 /* Note that this will fail if the structure layout is changed by
13562 the compiler. However, we have no good way to recognize some
13563 other layout, because we don't know what expression the compiler
13564 might choose to emit should this happen. */
13565 struct dwarf_block *blk = attr->as_block ();
13566 if (blk->size != 2
13567 || blk->data[0] != DW_OP_push_object_address
13568 || blk->data[1] != DW_OP_deref)
13569 return nullptr;
13570
13571 int bounds_offset = -1;
13572 int max_align = -1;
13573 std::vector<struct field> range_fields;
13574 for (struct die_info *child_die = die->child;
13575 child_die;
13576 child_die = child_die->sibling)
13577 {
13578 if (child_die->tag == DW_TAG_subrange_type)
13579 {
13580 struct type *underlying = read_subrange_index_type (child_die, cu);
13581
13582 int this_align = type_align (underlying);
13583 if (this_align > max_align)
13584 max_align = this_align;
13585
13586 range_fields.emplace_back ();
13587 range_fields.emplace_back ();
13588
13589 struct field &lower = range_fields[range_fields.size () - 2];
13590 struct field &upper = range_fields[range_fields.size () - 1];
13591
13592 lower.set_type (underlying);
13593 lower.set_is_artificial (true);
13594
13595 upper.set_type (underlying);
13596 upper.set_is_artificial (true);
13597
13598 if (!recognize_bound_expression (child_die, DW_AT_lower_bound,
13599 &bounds_offset, &lower, cu)
13600 || !recognize_bound_expression (child_die, DW_AT_upper_bound,
13601 &bounds_offset, &upper, cu))
13602 return nullptr;
13603 }
13604 }
13605
13606 /* This shouldn't really happen, but double-check that we found
13607 where the bounds are stored. */
13608 if (bounds_offset == -1)
13609 return nullptr;
13610
13611 struct objfile *objfile = cu->per_objfile->objfile;
13612 for (int i = 0; i < range_fields.size (); i += 2)
13613 {
13614 char name[20];
13615
13616 /* Set the name of each field in the bounds. */
13617 xsnprintf (name, sizeof (name), "LB%d", i / 2);
13618 range_fields[i].set_name (objfile->intern (name));
13619 xsnprintf (name, sizeof (name), "UB%d", i / 2);
13620 range_fields[i + 1].set_name (objfile->intern (name));
13621 }
13622
13623 type_allocator alloc (objfile, cu->lang ());
13624 struct type *bounds = alloc.new_type ();
13625 bounds->set_code (TYPE_CODE_STRUCT);
13626
13627 bounds->copy_fields (range_fields);
13628
13629 int last_fieldno = range_fields.size () - 1;
13630 int bounds_size = (bounds->field (last_fieldno).loc_bitpos () / 8
13631 + bounds->field (last_fieldno).type ()->length ());
13632 bounds->set_length (align_up (bounds_size, max_align));
13633
13634 /* Rewrite the existing array type in place. Specifically, we
13635 remove any dynamic properties we might have read, and we replace
13636 the index types. */
13637 struct type *iter = type;
13638 for (int i = 0; i < range_fields.size (); i += 2)
13639 {
13640 gdb_assert (iter->code () == TYPE_CODE_ARRAY);
13641 iter->main_type->dyn_prop_list = nullptr;
13642 iter->set_index_type
13643 (create_static_range_type (alloc, bounds->field (i).type (), 1, 0));
13644 iter = iter->target_type ();
13645 }
13646
13647 struct type *result = type_allocator (objfile, cu->lang ()).new_type ();
13648 result->set_code (TYPE_CODE_STRUCT);
13649
13650 result->alloc_fields (2);
13651
13652 /* The names are chosen to coincide with what the compiler does with
13653 -fgnat-encodings=all, which the Ada code in gdb already
13654 understands. */
13655 result->field (0).set_name ("P_ARRAY");
13656 result->field (0).set_type (lookup_pointer_type (type));
13657
13658 result->field (1).set_name ("P_BOUNDS");
13659 result->field (1).set_type (lookup_pointer_type (bounds));
13660 result->field (1).set_loc_bitpos (8 * bounds_offset);
13661
13662 result->set_name (type->name ());
13663 result->set_length (result->field (0).type ()->length ()
13664 + result->field (1).type ()->length ());
13665
13666 return result;
13667}
13668
13669/* Extract all information from a DW_TAG_array_type DIE and put it in
13670 the DIE's type field. For now, this only handles one dimensional
13671 arrays. */
13672
13673static struct type *
13674read_array_type (struct die_info *die, struct dwarf2_cu *cu)
13675{
13676 struct objfile *objfile = cu->per_objfile->objfile;
13677 struct die_info *child_die;
13678 struct type *type;
13679 struct type *element_type, *range_type, *index_type;
13680 struct attribute *attr;
13681 const char *name;
13682 struct dynamic_prop *byte_stride_prop = NULL;
13683 unsigned int bit_stride = 0;
13684
13685 element_type = die_type (die, cu);
13686
13687 /* The die_type call above may have already set the type for this DIE. */
13688 type = get_die_type (die, cu);
13689 if (type)
13690 return type;
13691
13692 attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
13693 if (attr != NULL)
13694 {
13695 int stride_ok;
13696 struct type *prop_type = cu->addr_sized_int_type (false);
13697
13698 byte_stride_prop
13699 = (struct dynamic_prop *) alloca (sizeof (struct dynamic_prop));
13700 stride_ok = attr_to_dynamic_prop (attr, die, cu, byte_stride_prop,
13701 prop_type);
13702 if (!stride_ok)
13703 {
13704 complaint (_("unable to read array DW_AT_byte_stride "
13705 " - DIE at %s [in module %s]"),
13708 /* Ignore this attribute. We will likely not be able to print
13709 arrays of this type correctly, but there is little we can do
13710 to help if we cannot read the attribute's value. */
13711 byte_stride_prop = NULL;
13712 }
13713 }
13714
13715 attr = dwarf2_attr (die, DW_AT_bit_stride, cu);
13716 if (attr != NULL)
13717 bit_stride = attr->constant_value (0);
13718
13719 /* Irix 6.2 native cc creates array types without children for
13720 arrays with unspecified length. */
13721 if (die->child == NULL)
13722 {
13723 index_type = builtin_type (objfile)->builtin_int;
13724 type_allocator alloc (objfile, cu->lang ());
13725 range_type = create_static_range_type (alloc, index_type, 0, -1);
13726 type = create_array_type_with_stride (alloc, element_type, range_type,
13727 byte_stride_prop, bit_stride);
13728 return set_die_type (die, type, cu);
13729 }
13730
13731 std::vector<struct type *> range_types;
13732 child_die = die->child;
13733 while (child_die && child_die->tag)
13734 {
13735 if (child_die->tag == DW_TAG_subrange_type
13736 || child_die->tag == DW_TAG_generic_subrange)
13737 {
13738 struct type *child_type = read_type_die (child_die, cu);
13739
13740 if (child_type != NULL)
13741 {
13742 /* The range type was successfully read. Save it for the
13743 array type creation. */
13744 range_types.push_back (child_type);
13745 }
13746 }
13747 child_die = child_die->sibling;
13748 }
13749
13750 if (range_types.empty ())
13751 {
13752 complaint (_("unable to find array range - DIE at %s [in module %s]"),
13755 return NULL;
13756 }
13757
13758 /* Dwarf2 dimensions are output from left to right, create the
13759 necessary array types in backwards order. */
13760
13761 type = element_type;
13762
13763 type_allocator alloc (cu->per_objfile->objfile, cu->lang ());
13764 if (read_array_order (die, cu) == DW_ORD_col_major)
13765 {
13766 int i = 0;
13767
13768 while (i < range_types.size ())
13769 {
13770 type = create_array_type_with_stride (alloc, type, range_types[i++],
13771 byte_stride_prop, bit_stride);
13773 bit_stride = 0;
13774 byte_stride_prop = nullptr;
13775 }
13776 }
13777 else
13778 {
13779 size_t ndim = range_types.size ();
13780 while (ndim-- > 0)
13781 {
13782 type = create_array_type_with_stride (alloc, type, range_types[ndim],
13783 byte_stride_prop, bit_stride);
13785 bit_stride = 0;
13786 byte_stride_prop = nullptr;
13787 }
13788 }
13789
13790 /* Clear the flag on the outermost array type. */
13792 gdb_assert (type != element_type);
13793
13794 /* Understand Dwarf2 support for vector types (like they occur on
13795 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
13796 array type. This is not part of the Dwarf2/3 standard yet, but a
13797 custom vendor extension. The main difference between a regular
13798 array and the vector variant is that vectors are passed by value
13799 to functions. */
13800 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
13801 if (attr != nullptr)
13803
13804 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
13805 implementation may choose to implement triple vectors using this
13806 attribute. */
13807 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
13808 if (attr != nullptr && attr->form_is_unsigned ())
13809 {
13810 if (attr->as_unsigned () >= type->length ())
13811 type->set_length (attr->as_unsigned ());
13812 else
13813 complaint (_("DW_AT_byte_size for array type smaller "
13814 "than the total size of elements"));
13815 }
13816
13817 name = dwarf2_name (die, cu);
13818 if (name)
13819 type->set_name (name);
13820
13821 maybe_set_alignment (cu, die, type);
13822
13823 struct type *replacement_type = nullptr;
13824 if (cu->lang () == language_ada)
13825 {
13826 replacement_type = quirk_ada_thick_pointer (die, cu, type);
13827 if (replacement_type != nullptr)
13828 type = replacement_type;
13829 }
13830
13831 /* Install the type in the die. */
13832 set_die_type (die, type, cu, replacement_type != nullptr);
13833
13834 /* set_die_type should be already done. */
13835 set_descriptive_type (type, die, cu);
13836
13837 return type;
13838}
13839
13840static enum dwarf_array_dim_ordering
13841read_array_order (struct die_info *die, struct dwarf2_cu *cu)
13842{
13843 struct attribute *attr;
13844
13845 attr = dwarf2_attr (die, DW_AT_ordering, cu);
13846
13847 if (attr != nullptr)
13848 {
13849 LONGEST val = attr->constant_value (-1);
13850 if (val == DW_ORD_row_major || val == DW_ORD_col_major)
13851 return (enum dwarf_array_dim_ordering) val;
13852 }
13853
13854 /* GNU F77 is a special case, as at 08/2004 array type info is the
13855 opposite order to the dwarf2 specification, but data is still
13856 laid out as per normal fortran.
13857
13858 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
13859 version checking. */
13860
13861 if (cu->lang () == language_fortran
13862 && cu->producer && strstr (cu->producer, "GNU F77"))
13863 {
13864 return DW_ORD_row_major;
13865 }
13866
13867 switch (cu->language_defn->array_ordering ())
13868 {
13869 case array_column_major:
13870 return DW_ORD_col_major;
13871 case array_row_major:
13872 default:
13873 return DW_ORD_row_major;
13874 };
13875}
13876
13877/* Extract all information from a DW_TAG_set_type DIE and put it in
13878 the DIE's type field. */
13879
13880static struct type *
13881read_set_type (struct die_info *die, struct dwarf2_cu *cu)
13882{
13883 struct type *domain_type, *set_type;
13884 struct attribute *attr;
13885
13886 domain_type = die_type (die, cu);
13887
13888 /* The die_type call above may have already set the type for this DIE. */
13889 set_type = get_die_type (die, cu);
13890 if (set_type)
13891 return set_type;
13892
13893 type_allocator alloc (cu->per_objfile->objfile, cu->lang ());
13894 set_type = create_set_type (alloc, domain_type);
13895
13896 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
13897 if (attr != nullptr && attr->form_is_unsigned ())
13898 set_type->set_length (attr->as_unsigned ());
13899
13900 maybe_set_alignment (cu, die, set_type);
13901
13902 return set_die_type (die, set_type, cu);
13903}
13904
13905/* A helper for read_common_block that creates a locexpr baton.
13906 SYM is the symbol which we are marking as computed.
13907 COMMON_DIE is the DIE for the common block.
13908 COMMON_LOC is the location expression attribute for the common
13909 block itself.
13910 MEMBER_LOC is the location expression attribute for the particular
13911 member of the common block that we are processing.
13912 CU is the CU from which the above come. */
13913
13914static void
13916 struct die_info *common_die,
13917 struct attribute *common_loc,
13918 struct attribute *member_loc,
13919 struct dwarf2_cu *cu)
13920{
13921 dwarf2_per_objfile *per_objfile = cu->per_objfile;
13922 struct objfile *objfile = per_objfile->objfile;
13923 struct dwarf2_locexpr_baton *baton;
13924 gdb_byte *ptr;
13925 unsigned int cu_off;
13926 enum bfd_endian byte_order = gdbarch_byte_order (objfile->arch ());
13927 LONGEST offset = 0;
13928
13929 gdb_assert (common_loc && member_loc);
13930 gdb_assert (common_loc->form_is_block ());
13931 gdb_assert (member_loc->form_is_block ()
13932 || member_loc->form_is_constant ());
13933
13934 baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
13935 baton->per_objfile = per_objfile;
13936 baton->per_cu = cu->per_cu;
13937 gdb_assert (baton->per_cu);
13938
13939 baton->size = 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
13940
13941 if (member_loc->form_is_constant ())
13942 {
13943 offset = member_loc->constant_value (0);
13944 baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
13945 }
13946 else
13947 baton->size += member_loc->as_block ()->size;
13948
13949 ptr = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, baton->size);
13950 baton->data = ptr;
13951
13952 *ptr++ = DW_OP_call4;
13953 cu_off = common_die->sect_off - cu->per_cu->sect_off;
13954 store_unsigned_integer (ptr, 4, byte_order, cu_off);
13955 ptr += 4;
13956
13957 if (member_loc->form_is_constant ())
13958 {
13959 *ptr++ = DW_OP_addr;
13960 store_unsigned_integer (ptr, cu->header.addr_size, byte_order, offset);
13961 ptr += cu->header.addr_size;
13962 }
13963 else
13964 {
13965 /* We have to copy the data here, because DW_OP_call4 will only
13966 use a DW_AT_location attribute. */
13967 struct dwarf_block *block = member_loc->as_block ();
13968 memcpy (ptr, block->data, block->size);
13969 ptr += block->size;
13970 }
13971
13972 *ptr++ = DW_OP_plus;
13973 gdb_assert (ptr - baton->data == baton->size);
13974
13975 SYMBOL_LOCATION_BATON (sym) = baton;
13977}
13978
13979/* Create appropriate locally-scoped variables for all the
13980 DW_TAG_common_block entries. Also create a struct common_block
13981 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
13982 is used to separate the common blocks name namespace from regular
13983 variable names. */
13984
13985static void
13986read_common_block (struct die_info *die, struct dwarf2_cu *cu)
13987{
13988 struct attribute *attr;
13989
13990 attr = dwarf2_attr (die, DW_AT_location, cu);
13991 if (attr != nullptr)
13992 {
13993 /* Support the .debug_loc offsets. */
13994 if (attr->form_is_block ())
13995 {
13996 /* Ok. */
13997 }
13998 else if (attr->form_is_section_offset ())
13999 {
14001 attr = NULL;
14002 }
14003 else
14004 {
14005 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14006 "common block member");
14007 attr = NULL;
14008 }
14009 }
14010
14011 if (die->child != NULL)
14012 {
14013 struct objfile *objfile = cu->per_objfile->objfile;
14014 struct die_info *child_die;
14015 size_t n_entries = 0, size;
14016 struct common_block *common_block;
14017 struct symbol *sym;
14018
14019 for (child_die = die->child;
14020 child_die && child_die->tag;
14021 child_die = child_die->sibling)
14022 ++n_entries;
14023
14024 size = (sizeof (struct common_block)
14025 + (n_entries - 1) * sizeof (struct symbol *));
14027 = (struct common_block *) obstack_alloc (&objfile->objfile_obstack,
14028 size);
14029 memset (common_block->contents, 0, n_entries * sizeof (struct symbol *));
14031
14032 for (child_die = die->child;
14033 child_die && child_die->tag;
14034 child_die = child_die->sibling)
14035 {
14036 /* Create the symbol in the DW_TAG_common_block block in the current
14037 symbol scope. */
14038 sym = new_symbol (child_die, NULL, cu);
14039 if (sym != NULL)
14040 {
14041 struct attribute *member_loc;
14042
14044
14045 member_loc = dwarf2_attr (child_die, DW_AT_data_member_location,
14046 cu);
14047 if (member_loc)
14048 {
14049 /* GDB has handled this for a long time, but it is
14050 not specified by DWARF. It seems to have been
14051 emitted by gfortran at least as recently as:
14052 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14053 complaint (_("Variable in common block has "
14054 "DW_AT_data_member_location "
14055 "- DIE at %s [in module %s]"),
14056 sect_offset_str (child_die->sect_off),
14058
14059 if (member_loc->form_is_section_offset ())
14061 else if (member_loc->form_is_constant ()
14062 || member_loc->form_is_block ())
14063 {
14064 if (attr != nullptr)
14065 mark_common_block_symbol_computed (sym, die, attr,
14066 member_loc, cu);
14067 }
14068 else
14070 }
14071 }
14072 }
14073
14074 sym = new_symbol (die, builtin_type (objfile)->builtin_void, cu);
14076 }
14077}
14078
14079/* Create a type for a C++ namespace. */
14080
14081static struct type *
14082read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
14083{
14084 struct objfile *objfile = cu->per_objfile->objfile;
14085 const char *previous_prefix, *name;
14086 int is_anonymous;
14087 struct type *type;
14088
14089 /* For extensions, reuse the type of the original namespace. */
14090 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
14091 {
14092 struct die_info *ext_die;
14093 struct dwarf2_cu *ext_cu = cu;
14094
14095 ext_die = dwarf2_extension (die, &ext_cu);
14096 type = read_type_die (ext_die, ext_cu);
14097
14098 /* EXT_CU may not be the same as CU.
14099 Ensure TYPE is recorded with CU in die_type_hash. */
14100 return set_die_type (die, type, cu);
14101 }
14102
14103 name = namespace_name (die, &is_anonymous, cu);
14104
14105 /* Now build the name of the current namespace. */
14106
14107 previous_prefix = determine_prefix (die, cu);
14108 if (previous_prefix[0] != '\0')
14110 previous_prefix, name, 0, cu);
14111
14112 /* Create the type. */
14113 type = type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_NAMESPACE,
14114 0, name);
14115
14116 return set_die_type (die, type, cu);
14117}
14118
14119/* Read a namespace scope. */
14120
14121static void
14122read_namespace (struct die_info *die, struct dwarf2_cu *cu)
14123{
14124 struct objfile *objfile = cu->per_objfile->objfile;
14125 int is_anonymous;
14126
14127 /* Add a symbol associated to this if we haven't seen the namespace
14128 before. Also, add a using directive if it's an anonymous
14129 namespace. */
14130
14131 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
14132 {
14133 struct type *type;
14134
14135 type = read_type_die (die, cu);
14136 new_symbol (die, type, cu);
14137
14138 namespace_name (die, &is_anonymous, cu);
14139 if (is_anonymous)
14140 {
14141 const char *previous_prefix = determine_prefix (die, cu);
14142
14143 std::vector<const char *> excludes;
14145 previous_prefix, type->name (), NULL,
14146 NULL, excludes,
14147 read_decl_line (die, cu),
14149 }
14150 }
14151
14152 if (die->child != NULL)
14153 {
14154 struct die_info *child_die = die->child;
14155
14156 while (child_die && child_die->tag)
14157 {
14158 process_die (child_die, cu);
14159 child_die = child_die->sibling;
14160 }
14161 }
14162}
14163
14164/* Read a Fortran module as type. This DIE can be only a declaration used for
14165 imported module. Still we need that type as local Fortran "use ... only"
14166 declaration imports depend on the created type in determine_prefix. */
14167
14168static struct type *
14169read_module_type (struct die_info *die, struct dwarf2_cu *cu)
14170{
14171 struct objfile *objfile = cu->per_objfile->objfile;
14172 const char *module_name;
14173 struct type *type;
14174
14175 module_name = dwarf2_name (die, cu);
14176 type = type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_MODULE,
14177 0, module_name);
14178
14179 return set_die_type (die, type, cu);
14180}
14181
14182/* Read a Fortran module. */
14183
14184static void
14185read_module (struct die_info *die, struct dwarf2_cu *cu)
14186{
14187 struct die_info *child_die = die->child;
14188 struct type *type;
14189
14190 type = read_type_die (die, cu);
14191 new_symbol (die, type, cu);
14192
14193 while (child_die && child_die->tag)
14194 {
14195 process_die (child_die, cu);
14196 child_die = child_die->sibling;
14197 }
14198}
14199
14200/* Return the name of the namespace represented by DIE. Set
14201 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14202 namespace. */
14203
14204static const char *
14205namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
14206{
14207 struct die_info *current_die;
14208 const char *name = NULL;
14209
14210 /* Loop through the extensions until we find a name. */
14211
14212 for (current_die = die;
14213 current_die != NULL;
14214 current_die = dwarf2_extension (die, &cu))
14215 {
14216 /* We don't use dwarf2_name here so that we can detect the absence
14217 of a name -> anonymous namespace. */
14218 name = dwarf2_string_attr (die, DW_AT_name, cu);
14219
14220 if (name != NULL)
14221 break;
14222 }
14223
14224 /* Is it an anonymous namespace? */
14225
14226 *is_anonymous = (name == NULL);
14227 if (*is_anonymous)
14229
14230 return name;
14231}
14232
14233/* Extract all information from a DW_TAG_pointer_type DIE and add to
14234 the user defined type vector. */
14235
14236static struct type *
14238{
14239 struct gdbarch *gdbarch = cu->per_objfile->objfile->arch ();
14240 struct comp_unit_head *cu_header = &cu->header;
14241 struct type *type;
14242 struct attribute *attr_byte_size;
14243 struct attribute *attr_address_class;
14244 int byte_size, addr_class;
14245 struct type *target_type;
14246
14247 target_type = die_type (die, cu);
14248
14249 /* The die_type call above may have already set the type for this DIE. */
14250 type = get_die_type (die, cu);
14251 if (type)
14252 return type;
14253
14255
14256 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
14257 if (attr_byte_size)
14258 byte_size = attr_byte_size->constant_value (cu_header->addr_size);
14259 else
14260 byte_size = cu_header->addr_size;
14261
14262 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
14263 if (attr_address_class)
14264 addr_class = attr_address_class->constant_value (DW_ADDR_none);
14265 else
14266 addr_class = DW_ADDR_none;
14267
14268 ULONGEST alignment = get_alignment (cu, die);
14269
14270 /* If the pointer size, alignment, or address class is different
14271 than the default, create a type variant marked as such and set
14272 the length accordingly. */
14273 if (type->length () != byte_size
14274 || (alignment != 0 && TYPE_RAW_ALIGN (type) != 0
14275 && alignment != TYPE_RAW_ALIGN (type))
14276 || addr_class != DW_ADDR_none)
14277 {
14279 {
14280 type_instance_flags type_flags
14282 addr_class);
14283 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
14284 == 0);
14285 type = make_type_with_address_space (type, type_flags);
14286 }
14287 else if (type->length () != byte_size)
14288 {
14289 complaint (_("invalid pointer size %d"), byte_size);
14290 }
14291 else if (TYPE_RAW_ALIGN (type) != alignment)
14292 {
14293 complaint (_("Invalid DW_AT_alignment"
14294 " - DIE at %s [in module %s]"),
14297 }
14298 else
14299 {
14300 /* Should we also complain about unhandled address classes? */
14301 }
14302 }
14303
14304 type->set_length (byte_size);
14305 set_type_align (type, alignment);
14306 return set_die_type (die, type, cu);
14307}
14308
14309/* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14310 the user defined type vector. */
14311
14312static struct type *
14314{
14315 struct type *type;
14316 struct type *to_type;
14317 struct type *domain;
14318
14319 to_type = die_type (die, cu);
14320 domain = die_containing_type (die, cu);
14321
14322 /* The calls above may have already set the type for this DIE. */
14323 type = get_die_type (die, cu);
14324 if (type)
14325 return type;
14326
14327 if (check_typedef (to_type)->code () == TYPE_CODE_METHOD)
14328 type = lookup_methodptr_type (to_type);
14329 else if (check_typedef (to_type)->code () == TYPE_CODE_FUNC)
14330 {
14331 struct type *new_type
14332 = type_allocator (cu->per_objfile->objfile, cu->lang ()).new_type ();
14333
14334 smash_to_method_type (new_type, domain, to_type->target_type (),
14335 to_type->fields (), to_type->num_fields (),
14336 to_type->has_varargs ());
14338 }
14339 else
14340 type = lookup_memberptr_type (to_type, domain);
14341
14342 return set_die_type (die, type, cu);
14343}
14344
14345/* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
14346 the user defined type vector. */
14347
14348static struct type *
14350 enum type_code refcode)
14351{
14352 struct comp_unit_head *cu_header = &cu->header;
14353 struct type *type, *target_type;
14354 struct attribute *attr;
14355
14356 gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
14357
14358 target_type = die_type (die, cu);
14359
14360 /* The die_type call above may have already set the type for this DIE. */
14361 type = get_die_type (die, cu);
14362 if (type)
14363 return type;
14364
14365 type = lookup_reference_type (target_type, refcode);
14366 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
14367 if (attr != nullptr)
14368 type->set_length (attr->constant_value (cu_header->addr_size));
14369 else
14370 type->set_length (cu_header->addr_size);
14371
14372 maybe_set_alignment (cu, die, type);
14373 return set_die_type (die, type, cu);
14374}
14375
14376/* Add the given cv-qualifiers to the element type of the array. GCC
14377 outputs DWARF type qualifiers that apply to an array, not the
14378 element type. But GDB relies on the array element type to carry
14379 the cv-qualifiers. This mimics section 6.7.3 of the C99
14380 specification. */
14381
14382static struct type *
14383add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
14384 struct type *base_type, int cnst, int voltl)
14385{
14386 struct type *el_type, *inner_array;
14387
14388 base_type = copy_type (base_type);
14389 inner_array = base_type;
14390
14391 while (inner_array->target_type ()->code () == TYPE_CODE_ARRAY)
14392 {
14393 inner_array->set_target_type (copy_type (inner_array->target_type ()));
14394 inner_array = inner_array->target_type ();
14395 }
14396
14397 el_type = inner_array->target_type ();
14398 cnst |= TYPE_CONST (el_type);
14399 voltl |= TYPE_VOLATILE (el_type);
14400 inner_array->set_target_type (make_cv_type (cnst, voltl, el_type, NULL));
14401
14402 return set_die_type (die, base_type, cu);
14403}
14404
14405static struct type *
14406read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
14407{
14408 struct type *base_type, *cv_type;
14409
14410 base_type = die_type (die, cu);
14411
14412 /* The die_type call above may have already set the type for this DIE. */
14413 cv_type = get_die_type (die, cu);
14414 if (cv_type)
14415 return cv_type;
14416
14417 /* In case the const qualifier is applied to an array type, the element type
14418 is so qualified, not the array type (section 6.7.3 of C99). */
14419 if (base_type->code () == TYPE_CODE_ARRAY)
14420 return add_array_cv_type (die, cu, base_type, 1, 0);
14421
14422 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
14423 return set_die_type (die, cv_type, cu);
14424}
14425
14426static struct type *
14428{
14429 struct type *base_type, *cv_type;
14430
14431 base_type = die_type (die, cu);
14432
14433 /* The die_type call above may have already set the type for this DIE. */
14434 cv_type = get_die_type (die, cu);
14435 if (cv_type)
14436 return cv_type;
14437
14438 /* In case the volatile qualifier is applied to an array type, the
14439 element type is so qualified, not the array type (section 6.7.3
14440 of C99). */
14441 if (base_type->code () == TYPE_CODE_ARRAY)
14442 return add_array_cv_type (die, cu, base_type, 0, 1);
14443
14444 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
14445 return set_die_type (die, cv_type, cu);
14446}
14447
14448/* Handle DW_TAG_restrict_type. */
14449
14450static struct type *
14452{
14453 struct type *base_type, *cv_type;
14454
14455 base_type = die_type (die, cu);
14456
14457 /* The die_type call above may have already set the type for this DIE. */
14458 cv_type = get_die_type (die, cu);
14459 if (cv_type)
14460 return cv_type;
14461
14462 cv_type = make_restrict_type (base_type);
14463 return set_die_type (die, cv_type, cu);
14464}
14465
14466/* Handle DW_TAG_atomic_type. */
14467
14468static struct type *
14469read_tag_atomic_type (struct die_info *die, struct dwarf2_cu *cu)
14470{
14471 struct type *base_type, *cv_type;
14472
14473 base_type = die_type (die, cu);
14474
14475 /* The die_type call above may have already set the type for this DIE. */
14476 cv_type = get_die_type (die, cu);
14477 if (cv_type)
14478 return cv_type;
14479
14480 cv_type = make_atomic_type (base_type);
14481 return set_die_type (die, cv_type, cu);
14482}
14483
14484/* Extract all information from a DW_TAG_string_type DIE and add to
14485 the user defined type vector. It isn't really a user defined type,
14486 but it behaves like one, with other DIE's using an AT_user_def_type
14487 attribute to reference it. */
14488
14489static struct type *
14490read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
14491{
14492 struct objfile *objfile = cu->per_objfile->objfile;
14493 struct gdbarch *gdbarch = objfile->arch ();
14494 struct type *type, *range_type, *index_type, *char_type;
14495 struct attribute *attr;
14496 struct dynamic_prop prop;
14497 bool length_is_constant = true;
14498 LONGEST length;
14499
14500 /* There are a couple of places where bit sizes might be made use of
14501 when parsing a DW_TAG_string_type, however, no producer that we know
14502 of make use of these. Handling bit sizes that are a multiple of the
14503 byte size is easy enough, but what about other bit sizes? Lets deal
14504 with that problem when we have to. Warn about these attributes being
14505 unsupported, then parse the type and ignore them like we always
14506 have. */
14507 if (dwarf2_attr (die, DW_AT_bit_size, cu) != nullptr
14508 || dwarf2_attr (die, DW_AT_string_length_bit_size, cu) != nullptr)
14509 {
14510 static bool warning_printed = false;
14511 if (!warning_printed)
14512 {
14513 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
14514 "currently supported on DW_TAG_string_type."));
14515 warning_printed = true;
14516 }
14517 }
14518
14519 attr = dwarf2_attr (die, DW_AT_string_length, cu);
14520 if (attr != nullptr && !attr->form_is_constant ())
14521 {
14522 /* The string length describes the location at which the length of
14523 the string can be found. The size of the length field can be
14524 specified with one of the attributes below. */
14525 struct type *prop_type;
14526 struct attribute *len
14527 = dwarf2_attr (die, DW_AT_string_length_byte_size, cu);
14528 if (len == nullptr)
14529 len = dwarf2_attr (die, DW_AT_byte_size, cu);
14530 if (len != nullptr && len->form_is_constant ())
14531 {
14532 /* Pass 0 as the default as we know this attribute is constant
14533 and the default value will not be returned. */
14534 LONGEST sz = len->constant_value (0);
14535 prop_type = objfile_int_type (objfile, sz, true);
14536 }
14537 else
14538 {
14539 /* If the size is not specified then we assume it is the size of
14540 an address on this target. */
14541 prop_type = cu->addr_sized_int_type (true);
14542 }
14543
14544 /* Convert the attribute into a dynamic property. */
14545 if (!attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
14546 length = 1;
14547 else
14548 length_is_constant = false;
14549 }
14550 else if (attr != nullptr)
14551 {
14552 /* This DW_AT_string_length just contains the length with no
14553 indirection. There's no need to create a dynamic property in this
14554 case. Pass 0 for the default value as we know it will not be
14555 returned in this case. */
14556 length = attr->constant_value (0);
14557 }
14558 else if ((attr = dwarf2_attr (die, DW_AT_byte_size, cu)) != nullptr)
14559 {
14560 /* We don't currently support non-constant byte sizes for strings. */
14561 length = attr->constant_value (1);
14562 }
14563 else
14564 {
14565 /* Use 1 as a fallback length if we have nothing else. */
14566 length = 1;
14567 }
14568
14569 index_type = builtin_type (objfile)->builtin_int;
14570 type_allocator alloc (objfile, cu->lang ());
14571 if (length_is_constant)
14572 range_type = create_static_range_type (alloc, index_type, 1, length);
14573 else
14574 {
14575 struct dynamic_prop low_bound;
14576
14577 low_bound.set_const_val (1);
14578 range_type = create_range_type (alloc, index_type, &low_bound, &prop, 0);
14579 }
14581 type = create_string_type (alloc, char_type, range_type);
14582
14583 return set_die_type (die, type, cu);
14584}
14585
14586/* Assuming that DIE corresponds to a function, returns nonzero
14587 if the function is prototyped. */
14588
14589static int
14591{
14592 struct attribute *attr;
14593
14594 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
14595 if (attr && attr->as_boolean ())
14596 return 1;
14597
14598 /* The DWARF standard implies that the DW_AT_prototyped attribute
14599 is only meaningful for C, but the concept also extends to other
14600 languages that allow unprototyped functions (Eg: Objective C).
14601 For all other languages, assume that functions are always
14602 prototyped. */
14603 if (cu->lang () != language_c
14604 && cu->lang () != language_objc
14605 && cu->lang () != language_opencl)
14606 return 1;
14607
14608 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14609 prototyped and unprototyped functions; default to prototyped,
14610 since that is more common in modern code (and RealView warns
14611 about unprototyped functions). */
14613 return 1;
14614
14615 return 0;
14616}
14617
14618/* Handle DIES due to C code like:
14619
14620 struct foo
14621 {
14622 int (*funcp)(int a, long l);
14623 int b;
14624 };
14625
14626 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14627
14628static struct type *
14629read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
14630{
14631 struct objfile *objfile = cu->per_objfile->objfile;
14632 struct type *type; /* Type that this function returns. */
14633 struct type *ftype; /* Function that returns above type. */
14634 struct attribute *attr;
14635
14636 type = die_type (die, cu);
14637
14638 /* The die_type call above may have already set the type for this DIE. */
14639 ftype = get_die_type (die, cu);
14640 if (ftype)
14641 return ftype;
14642
14643 ftype = lookup_function_type (type);
14644
14645 if (prototyped_function_p (die, cu))
14646 ftype->set_is_prototyped (true);
14647
14648 /* Store the calling convention in the type if it's available in
14649 the subroutine die. Otherwise set the calling convention to
14650 the default value DW_CC_normal. */
14651 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
14652 if (attr != nullptr
14655 = (enum dwarf_calling_convention) attr->constant_value (0);
14656 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
14657 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
14658 else
14659 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
14660
14661 /* Record whether the function returns normally to its caller or not
14662 if the DWARF producer set that information. */
14663 attr = dwarf2_attr (die, DW_AT_noreturn, cu);
14664 if (attr && attr->as_boolean ())
14665 TYPE_NO_RETURN (ftype) = 1;
14666
14667 /* We need to add the subroutine type to the die immediately so
14668 we don't infinitely recurse when dealing with parameters
14669 declared as the same subroutine type. */
14670 set_die_type (die, ftype, cu);
14671
14672 if (die->child != NULL)
14673 {
14674 struct type *void_type = builtin_type (objfile)->builtin_void;
14675 struct die_info *child_die;
14676 int nparams, iparams;
14677
14678 /* Count the number of parameters.
14679 FIXME: GDB currently ignores vararg functions, but knows about
14680 vararg member functions. */
14681 nparams = 0;
14682 child_die = die->child;
14683 while (child_die && child_die->tag)
14684 {
14685 if (child_die->tag == DW_TAG_formal_parameter)
14686 nparams++;
14687 else if (child_die->tag == DW_TAG_unspecified_parameters)
14688 ftype->set_has_varargs (true);
14689
14690 child_die = child_die->sibling;
14691 }
14692
14693 /* Allocate storage for parameters and fill them in. */
14694 ftype->alloc_fields (nparams);
14695
14696 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14697 even if we error out during the parameters reading below. */
14698 for (iparams = 0; iparams < nparams; iparams++)
14699 ftype->field (iparams).set_type (void_type);
14700
14701 iparams = 0;
14702 child_die = die->child;
14703 while (child_die && child_die->tag)
14704 {
14705 if (child_die->tag == DW_TAG_formal_parameter)
14706 {
14707 struct type *arg_type;
14708
14709 /* DWARF version 2 has no clean way to discern C++
14710 static and non-static member functions. G++ helps
14711 GDB by marking the first parameter for non-static
14712 member functions (which is the this pointer) as
14713 artificial. We pass this information to
14714 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14715
14716 DWARF version 3 added DW_AT_object_pointer, which GCC
14717 4.5 does not yet generate. */
14718 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
14719 if (attr != nullptr)
14720 ftype->field (iparams).set_is_artificial (attr->as_boolean ());
14721 else
14722 ftype->field (iparams).set_is_artificial (false);
14723 arg_type = die_type (child_die, cu);
14724
14725 /* RealView does not mark THIS as const, which the testsuite
14726 expects. GCC marks THIS as const in method definitions,
14727 but not in the class specifications (GCC PR 43053). */
14728 if (cu->lang () == language_cplus
14729 && !TYPE_CONST (arg_type)
14730 && ftype->field (iparams).is_artificial ())
14731 {
14732 int is_this = 0;
14733 struct dwarf2_cu *arg_cu = cu;
14734 const char *name = dwarf2_name (child_die, cu);
14735
14736 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
14737 if (attr != nullptr)
14738 {
14739 /* If the compiler emits this, use it. */
14740 if (follow_die_ref (die, attr, &arg_cu) == child_die)
14741 is_this = 1;
14742 }
14743 else if (name && strcmp (name, "this") == 0)
14744 /* Function definitions will have the argument names. */
14745 is_this = 1;
14746 else if (name == NULL && iparams == 0)
14747 /* Declarations may not have the names, so like
14748 elsewhere in GDB, assume an artificial first
14749 argument is "this". */
14750 is_this = 1;
14751
14752 if (is_this)
14753 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
14754 arg_type, 0);
14755 }
14756
14757 ftype->field (iparams).set_type (arg_type);
14758 iparams++;
14759 }
14760 child_die = child_die->sibling;
14761 }
14762 }
14763
14764 return ftype;
14765}
14766
14767static struct type *
14768read_typedef (struct die_info *die, struct dwarf2_cu *cu)
14769{
14770 struct objfile *objfile = cu->per_objfile->objfile;
14771 const char *name = dwarf2_full_name (NULL, die, cu);
14772 struct type *this_type;
14773 struct gdbarch *gdbarch = objfile->arch ();
14774 struct type *target_type = die_type (die, cu);
14775
14777 {
14778 /* The long double is defined as a base type in C. GCC creates a long
14779 double typedef with target-type _Float128 for the long double to
14780 identify it as the IEEE Float128 value. This is a GCC hack since the
14781 DWARF doesn't distinguish between the IBM long double and IEEE
14782 128-bit float. Replace the GCC workaround for the long double
14783 typedef with the actual type information copied from the target-type
14784 with the correct long double base type name. */
14785 this_type = copy_type (target_type);
14786 this_type->set_name (name);
14787 set_die_type (die, this_type, cu);
14788 return this_type;
14789 }
14790
14791 type_allocator alloc (objfile, cu->lang ());
14792 this_type = alloc.new_type (TYPE_CODE_TYPEDEF, 0, name);
14793 this_type->set_target_is_stub (true);
14794 set_die_type (die, this_type, cu);
14795 if (target_type != this_type)
14796 this_type->set_target_type (target_type);
14797 else
14798 {
14799 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14800 spec and cause infinite loops in GDB. */
14801 complaint (_("Self-referential DW_TAG_typedef "
14802 "- DIE at %s [in module %s]"),
14804 this_type->set_target_type (nullptr);
14805 }
14806 if (name == NULL)
14807 {
14808 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
14809 anonymous typedefs, which is, strictly speaking, invalid DWARF.
14810 Handle these by just returning the target type, rather than
14811 constructing an anonymous typedef type and trying to handle this
14812 elsewhere. */
14813 set_die_type (die, target_type, cu);
14814 return target_type;
14815 }
14816 return this_type;
14817}
14818
14819/* Helper for get_dwarf2_rational_constant that computes the value of
14820 a given gmp_mpz given an attribute. */
14821
14822static void
14823get_mpz (struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr)
14824{
14825 /* GCC will sometimes emit a 16-byte constant value as a DWARF
14826 location expression that pushes an implicit value. */
14827 if (attr->form == DW_FORM_exprloc)
14828 {
14829 dwarf_block *blk = attr->as_block ();
14830 if (blk->size > 0 && blk->data[0] == DW_OP_implicit_value)
14831 {
14832 uint64_t len;
14833 const gdb_byte *ptr = safe_read_uleb128 (blk->data + 1,
14834 blk->data + blk->size,
14835 &len);
14836 if (ptr - blk->data + len <= blk->size)
14837 {
14838 value->read (gdb::make_array_view (ptr, len),
14839 bfd_big_endian (cu->per_objfile->objfile->obfd.get ())
14840 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE,
14841 true);
14842 return;
14843 }
14844 }
14845
14846 /* On failure set it to 1. */
14847 *value = gdb_mpz (1);
14848 }
14849 else if (attr->form_is_block ())
14850 {
14851 dwarf_block *blk = attr->as_block ();
14852 value->read (gdb::make_array_view (blk->data, blk->size),
14853 bfd_big_endian (cu->per_objfile->objfile->obfd.get ())
14854 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE,
14855 true);
14856 }
14857 else if (attr->form_is_unsigned ())
14858 *value = gdb_mpz (attr->as_unsigned ());
14859 else
14860 *value = gdb_mpz (attr->constant_value (1));
14861}
14862
14863/* Assuming DIE is a rational DW_TAG_constant, read the DIE's
14864 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
14865
14866 If the numerator and/or numerator attribute is missing,
14867 a complaint is filed, and NUMERATOR and DENOMINATOR are left
14868 untouched. */
14869
14870static void
14872 gdb_mpz *numerator, gdb_mpz *denominator)
14873{
14874 struct attribute *num_attr, *denom_attr;
14875
14876 num_attr = dwarf2_attr (die, DW_AT_GNU_numerator, cu);
14877 if (num_attr == nullptr)
14878 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
14880
14881 denom_attr = dwarf2_attr (die, DW_AT_GNU_denominator, cu);
14882 if (denom_attr == nullptr)
14883 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
14885
14886 if (num_attr == nullptr || denom_attr == nullptr)
14887 return;
14888
14889 get_mpz (cu, numerator, num_attr);
14890 get_mpz (cu, denominator, denom_attr);
14891}
14892
14893/* Same as get_dwarf2_rational_constant, but extracting an unsigned
14894 rational constant, rather than a signed one.
14895
14896 If the rational constant has a negative value, a complaint
14897 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
14898
14899static void
14901 struct dwarf2_cu *cu,
14902 gdb_mpz *numerator,
14903 gdb_mpz *denominator)
14904{
14905 gdb_mpz num (1);
14906 gdb_mpz denom (1);
14907
14908 get_dwarf2_rational_constant (die, cu, &num, &denom);
14909 if (num < 0 && denom < 0)
14910 {
14911 num.negate ();
14912 denom.negate ();
14913 }
14914 else if (num < 0)
14915 {
14916 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
14917 " in DIE at %s"),
14918 sect_offset_str (die->sect_off));
14919 return;
14920 }
14921 else if (denom < 0)
14922 {
14923 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
14924 " in DIE at %s"),
14925 sect_offset_str (die->sect_off));
14926 return;
14927 }
14928
14929 *numerator = std::move (num);
14930 *denominator = std::move (denom);
14931}
14932
14933/* Assuming that ENCODING is a string whose contents starting at the
14934 K'th character is "_nn" where "nn" is a decimal number, scan that
14935 number and set RESULT to the value. K is updated to point to the
14936 character immediately following the number.
14937
14938 If the string does not conform to the format described above, false
14939 is returned, and K may or may not be changed. */
14940
14941static bool
14942ada_get_gnat_encoded_number (const char *encoding, int &k, gdb_mpz *result)
14943{
14944 /* The next character should be an underscore ('_') followed
14945 by a digit. */
14946 if (encoding[k] != '_' || !isdigit (encoding[k + 1]))
14947 return false;
14948
14949 /* Skip the underscore. */
14950 k++;
14951 int start = k;
14952
14953 /* Determine the number of digits for our number. */
14954 while (isdigit (encoding[k]))
14955 k++;
14956 if (k == start)
14957 return false;
14958
14959 std::string copy (&encoding[start], k - start);
14960 return result->set (copy.c_str (), 10);
14961}
14962
14963/* Scan two numbers from ENCODING at OFFSET, assuming the string is of
14964 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
14965 DENOM, update OFFSET, and return true on success. Return false on
14966 failure. */
14967
14968static bool
14969ada_get_gnat_encoded_ratio (const char *encoding, int &offset,
14970 gdb_mpz *num, gdb_mpz *denom)
14971{
14972 if (!ada_get_gnat_encoded_number (encoding, offset, num))
14973 return false;
14974 return ada_get_gnat_encoded_number (encoding, offset, denom);
14975}
14976
14977/* Assuming DIE corresponds to a fixed point type, finish the creation
14978 of the corresponding TYPE by setting its type-specific data. CU is
14979 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
14980 encodings. It is nullptr if the GNAT encoding should be
14981 ignored. */
14982
14983static void
14984finish_fixed_point_type (struct type *type, const char *suffix,
14985 struct die_info *die, struct dwarf2_cu *cu)
14986{
14987 gdb_assert (type->code () == TYPE_CODE_FIXED_POINT
14989
14990 /* If GNAT encodings are preferred, don't examine the
14991 attributes. */
14992 struct attribute *attr = nullptr;
14993 if (suffix == nullptr)
14994 {
14995 attr = dwarf2_attr (die, DW_AT_binary_scale, cu);
14996 if (attr == nullptr)
14997 attr = dwarf2_attr (die, DW_AT_decimal_scale, cu);
14998 if (attr == nullptr)
14999 attr = dwarf2_attr (die, DW_AT_small, cu);
15000 }
15001
15002 /* Numerator and denominator of our fixed-point type's scaling factor.
15003 The default is a scaling factor of 1, which we use as a fallback
15004 when we are not able to decode it (problem with the debugging info,
15005 unsupported forms, bug in GDB, etc...). Using that as the default
15006 allows us to at least print the unscaled value, which might still
15007 be useful to a user. */
15008 gdb_mpz scale_num (1);
15009 gdb_mpz scale_denom (1);
15010
15011 if (attr == nullptr)
15012 {
15013 int offset = 0;
15014 if (suffix != nullptr
15015 && ada_get_gnat_encoded_ratio (suffix, offset, &scale_num,
15016 &scale_denom)
15017 /* The number might be encoded as _nn_dd_nn_dd, where the
15018 second ratio is the 'small value. In this situation, we
15019 want the second value. */
15020 && (suffix[offset] != '_'
15021 || ada_get_gnat_encoded_ratio (suffix, offset, &scale_num,
15022 &scale_denom)))
15023 {
15024 /* Found it. */
15025 }
15026 else
15027 {
15028 /* Scaling factor not found. Assume a scaling factor of 1,
15029 and hope for the best. At least the user will be able to
15030 see the encoded value. */
15031 scale_num = 1;
15032 scale_denom = 1;
15033 complaint (_("no scale found for fixed-point type (DIE at %s)"),
15034 sect_offset_str (die->sect_off));
15035 }
15036 }
15037 else if (attr->name == DW_AT_binary_scale)
15038 {
15039 LONGEST scale_exp = attr->constant_value (0);
15040 gdb_mpz &num_or_denom = scale_exp > 0 ? scale_num : scale_denom;
15041
15042 num_or_denom <<= std::abs (scale_exp);
15043 }
15044 else if (attr->name == DW_AT_decimal_scale)
15045 {
15046 LONGEST scale_exp = attr->constant_value (0);
15047 gdb_mpz &num_or_denom = scale_exp > 0 ? scale_num : scale_denom;
15048
15049 num_or_denom = gdb_mpz::pow (10, std::abs (scale_exp));
15050 }
15051 else if (attr->name == DW_AT_small)
15052 {
15053 struct die_info *scale_die;
15054 struct dwarf2_cu *scale_cu = cu;
15055
15056 scale_die = follow_die_ref (die, attr, &scale_cu);
15057 if (scale_die->tag == DW_TAG_constant)
15058 get_dwarf2_unsigned_rational_constant (scale_die, scale_cu,
15059 &scale_num, &scale_denom);
15060 else
15061 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
15062 " (DIE at %s)"),
15064 }
15065 else
15066 {
15067 complaint (_("unsupported scale attribute %s for fixed-point type"
15068 " (DIE at %s)"),
15069 dwarf_attr_name (attr->name),
15070 sect_offset_str (die->sect_off));
15071 }
15072
15073 type->fixed_point_info ().scaling_factor = gdb_mpq (scale_num, scale_denom);
15074}
15075
15076/* The gnat-encoding suffix for fixed point. */
15077
15078#define GNAT_FIXED_POINT_SUFFIX "___XF_"
15079
15080/* If NAME encodes an Ada fixed-point type, return a pointer to the
15081 "XF" suffix of the name. The text after this is what encodes the
15082 'small and 'delta information. Otherwise, return nullptr. */
15083
15084static const char *
15086{
15087 return strstr (name, GNAT_FIXED_POINT_SUFFIX);
15088}
15089
15090/* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
15091 (which may be different from NAME) to the architecture back-end to allow
15092 it to guess the correct format if necessary. */
15093
15094static struct type *
15095dwarf2_init_float_type (struct dwarf2_cu *cu, int bits, const char *name,
15096 const char *name_hint, enum bfd_endian byte_order)
15097{
15098 struct objfile *objfile = cu->per_objfile->objfile;
15099 struct gdbarch *gdbarch = objfile->arch ();
15100 const struct floatformat **format;
15101 struct type *type;
15102
15103 type_allocator alloc (objfile, cu->lang ());
15104 format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
15105 if (format)
15106 type = init_float_type (alloc, bits, name, format, byte_order);
15107 else
15108 type = alloc.new_type (TYPE_CODE_ERROR, bits, name);
15109
15110 return type;
15111}
15112
15113/* Allocate an integer type of size BITS and name NAME. */
15114
15115static struct type *
15116dwarf2_init_integer_type (struct dwarf2_cu *cu, int bits, int unsigned_p,
15117 const char *name)
15118{
15119 struct type *type;
15120 struct objfile *objfile = cu->per_objfile->objfile;
15121
15122 /* Versions of Intel's C Compiler generate an integer type called "void"
15123 instead of using DW_TAG_unspecified_type. This has been seen on
15124 at least versions 14, 17, and 18. */
15125 if (bits == 0 && producer_is_icc (cu) && name != nullptr
15126 && strcmp (name, "void") == 0)
15128 else
15129 {
15130 type_allocator alloc (objfile, cu->lang ());
15131 type = init_integer_type (alloc, bits, unsigned_p, name);
15132 }
15133
15134 return type;
15135}
15136
15137/* Return true if DIE has a DW_AT_small attribute whose value is
15138 a constant rational, where both the numerator and denominator
15139 are equal to zero.
15140
15141 CU is the DIE's Compilation Unit. */
15142
15143static bool
15145 struct dwarf2_cu *cu)
15146{
15147 struct attribute *attr = dwarf2_attr (die, DW_AT_small, cu);
15148 if (attr == nullptr)
15149 return false;
15150
15151 struct dwarf2_cu *scale_cu = cu;
15152 struct die_info *scale_die
15153 = follow_die_ref (die, attr, &scale_cu);
15154
15155 if (scale_die->tag != DW_TAG_constant)
15156 return false;
15157
15158 gdb_mpz num (1), denom (1);
15159 get_dwarf2_rational_constant (scale_die, cu, &num, &denom);
15160 return num == 0 && denom == 0;
15161}
15162
15163/* Initialise and return a floating point type of size BITS suitable for
15164 use as a component of a complex number. The NAME_HINT is passed through
15165 when initialising the floating point type and is the name of the complex
15166 type.
15167
15168 As DWARF doesn't currently provide an explicit name for the components
15169 of a complex number, but it can be helpful to have these components
15170 named, we try to select a suitable name based on the size of the
15171 component. */
15172static struct type *
15174 int bits, const char *name_hint,
15175 enum bfd_endian byte_order)
15176{
15177 struct objfile *objfile = cu->per_objfile->objfile;
15178 gdbarch *gdbarch = objfile->arch ();
15179 struct type *tt = nullptr;
15180
15181 /* Try to find a suitable floating point builtin type of size BITS.
15182 We're going to use the name of this type as the name for the complex
15183 target type that we are about to create. */
15184 switch (cu->lang ())
15185 {
15186 case language_fortran:
15187 switch (bits)
15188 {
15189 case 32:
15191 break;
15192 case 64:
15194 break;
15195 case 96: /* The x86-32 ABI specifies 96-bit long double. */
15196 case 128:
15198 break;
15199 }
15200 break;
15201 default:
15202 switch (bits)
15203 {
15204 case 32:
15206 break;
15207 case 64:
15209 break;
15210 case 96: /* The x86-32 ABI specifies 96-bit long double. */
15211 case 128:
15213 break;
15214 }
15215 break;
15216 }
15217
15218 /* If the type we found doesn't match the size we were looking for, then
15219 pretend we didn't find a type at all, the complex target type we
15220 create will then be nameless. */
15221 if (tt != nullptr && tt->length () * TARGET_CHAR_BIT != bits)
15222 tt = nullptr;
15223
15224 const char *name = (tt == nullptr) ? nullptr : tt->name ();
15225 return dwarf2_init_float_type (cu, bits, name, name_hint, byte_order);
15226}
15227
15228/* Find a representation of a given base type and install
15229 it in the TYPE field of the die. */
15230
15231static struct type *
15232read_base_type (struct die_info *die, struct dwarf2_cu *cu)
15233{
15234 struct objfile *objfile = cu->per_objfile->objfile;
15235 struct type *type;
15236 struct attribute *attr;
15237 int encoding = 0, bits = 0;
15238 const char *name;
15239 gdbarch *arch;
15240
15241 attr = dwarf2_attr (die, DW_AT_encoding, cu);
15242 if (attr != nullptr && attr->form_is_constant ())
15243 encoding = attr->constant_value (0);
15244 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
15245 if (attr != nullptr)
15246 bits = attr->constant_value (0) * TARGET_CHAR_BIT;
15247 name = dwarf2_name (die, cu);
15248 if (!name)
15249 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
15250
15251 arch = objfile->arch ();
15252 enum bfd_endian byte_order = gdbarch_byte_order (arch);
15253
15254 attr = dwarf2_attr (die, DW_AT_endianity, cu);
15255 if (attr != nullptr && attr->form_is_constant ())
15256 {
15257 int endianity = attr->constant_value (0);
15258
15259 switch (endianity)
15260 {
15261 case DW_END_big:
15262 byte_order = BFD_ENDIAN_BIG;
15263 break;
15264 case DW_END_little:
15265 byte_order = BFD_ENDIAN_LITTLE;
15266 break;
15267 default:
15268 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity);
15269 break;
15270 }
15271 }
15272
15273 if ((encoding == DW_ATE_signed_fixed || encoding == DW_ATE_unsigned_fixed)
15274 && cu->lang () == language_ada
15276 {
15277 /* brobecker/2018-02-24: This is a fixed point type for which
15278 the scaling factor is represented as fraction whose value
15279 does not make sense (zero divided by zero), so we should
15280 normally never see these. However, there is a small category
15281 of fixed point types for which GNAT is unable to provide
15282 the scaling factor via the standard DWARF mechanisms, and
15283 for which the info is provided via the GNAT encodings instead.
15284 This is likely what this DIE is about. */
15285 encoding = (encoding == DW_ATE_signed_fixed
15286 ? DW_ATE_signed
15287 : DW_ATE_unsigned);
15288 }
15289
15290 /* With GNAT encodings, fixed-point information will be encoded in
15291 the type name. Note that this can also occur with the above
15292 zero-over-zero case, which is why this is a separate "if" rather
15293 than an "else if". */
15294 const char *gnat_encoding_suffix = nullptr;
15295 if ((encoding == DW_ATE_signed || encoding == DW_ATE_unsigned)
15296 && cu->lang () == language_ada
15297 && name != nullptr)
15298 {
15299 gnat_encoding_suffix = gnat_encoded_fixed_point_type_info (name);
15300 if (gnat_encoding_suffix != nullptr)
15301 {
15302 gdb_assert (startswith (gnat_encoding_suffix,
15304 name = obstack_strndup (&cu->per_objfile->objfile->objfile_obstack,
15305 name, gnat_encoding_suffix - name);
15306 /* Use -1 here so that SUFFIX points at the "_" after the
15307 "XF". */
15308 gnat_encoding_suffix += strlen (GNAT_FIXED_POINT_SUFFIX) - 1;
15309
15310 encoding = (encoding == DW_ATE_signed
15311 ? DW_ATE_signed_fixed
15312 : DW_ATE_unsigned_fixed);
15313 }
15314 }
15315
15316 type_allocator alloc (objfile, cu->lang ());
15317 switch (encoding)
15318 {
15319 case DW_ATE_address:
15320 /* Turn DW_ATE_address into a void * pointer. */
15321 type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
15322 type = init_pointer_type (alloc, bits, name, type);
15323 break;
15324 case DW_ATE_boolean:
15325 type = init_boolean_type (alloc, bits, 1, name);
15326 break;
15327 case DW_ATE_complex_float:
15329 byte_order);
15330 if (type->code () == TYPE_CODE_ERROR)
15331 {
15332 if (name == nullptr)
15333 {
15334 struct obstack *obstack
15336 name = obconcat (obstack, "_Complex ", type->name (),
15337 nullptr);
15338 }
15339 type = alloc.new_type (TYPE_CODE_ERROR, bits, name);
15340 }
15341 else
15343 break;
15344 case DW_ATE_decimal_float:
15345 type = init_decfloat_type (alloc, bits, name);
15346 break;
15347 case DW_ATE_float:
15348 type = dwarf2_init_float_type (cu, bits, name, name, byte_order);
15349 break;
15350 case DW_ATE_signed:
15352 break;
15353 case DW_ATE_unsigned:
15354 if (cu->lang () == language_fortran
15355 && name
15356 && startswith (name, "character("))
15357 type = init_character_type (alloc, bits, 1, name);
15358 else
15360 break;
15361 case DW_ATE_signed_char:
15362 if (cu->lang () == language_ada
15363 || cu->lang () == language_m2
15364 || cu->lang () == language_pascal
15365 || cu->lang () == language_fortran)
15366 type = init_character_type (alloc, bits, 0, name);
15367 else
15369 break;
15370 case DW_ATE_unsigned_char:
15371 if (cu->lang () == language_ada
15372 || cu->lang () == language_m2
15373 || cu->lang () == language_pascal
15374 || cu->lang () == language_fortran
15375 || cu->lang () == language_rust)
15376 type = init_character_type (alloc, bits, 1, name);
15377 else
15379 break;
15380 case DW_ATE_UTF:
15381 {
15382 type = init_character_type (alloc, bits, 1, name);
15383 return set_die_type (die, type, cu);
15384 }
15385 break;
15386 case DW_ATE_signed_fixed:
15387 type = init_fixed_point_type (alloc, bits, 0, name);
15388 finish_fixed_point_type (type, gnat_encoding_suffix, die, cu);
15389 break;
15390 case DW_ATE_unsigned_fixed:
15391 type = init_fixed_point_type (alloc, bits, 1, name);
15392 finish_fixed_point_type (type, gnat_encoding_suffix, die, cu);
15393 break;
15394
15395 default:
15396 complaint (_("unsupported DW_AT_encoding: '%s'"),
15397 dwarf_type_encoding_name (encoding));
15398 type = alloc.new_type (TYPE_CODE_ERROR, bits, name);
15399 break;
15400 }
15401
15402 if (type->code () == TYPE_CODE_INT
15403 && name != nullptr
15404 && strcmp (name, "char") == 0)
15406
15407 maybe_set_alignment (cu, die, type);
15408
15410
15412 {
15413 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
15414 if (attr != nullptr && attr->form_is_constant ())
15415 {
15416 unsigned real_bit_size = attr->constant_value (0);
15417 if (real_bit_size >= 0 && real_bit_size <= 8 * type->length ())
15418 {
15419 attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
15420 /* Only use the attributes if they make sense together. */
15421 if (attr == nullptr
15422 || (attr->form_is_constant ()
15423 && attr->constant_value (0) >= 0
15424 && (attr->constant_value (0) + real_bit_size
15425 <= 8 * type->length ())))
15426 {
15427 TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size
15428 = real_bit_size;
15429 if (attr != nullptr)
15430 TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset
15431 = attr->constant_value (0);
15432 }
15433 }
15434 }
15435 }
15436
15437 return set_die_type (die, type, cu);
15438}
15439
15440/* A helper function that returns the name of DIE, if it refers to a
15441 variable declaration. */
15442
15443static const char *
15444var_decl_name (struct die_info *die, struct dwarf2_cu *cu)
15445{
15446 if (die->tag != DW_TAG_variable)
15447 return nullptr;
15448
15449 attribute *attr = dwarf2_attr (die, DW_AT_declaration, cu);
15450 if (attr == nullptr || !attr->as_boolean ())
15451 return nullptr;
15452
15453 attr = dwarf2_attr (die, DW_AT_name, cu);
15454 if (attr == nullptr)
15455 return nullptr;
15456 return attr->as_string ();
15457}
15458
15459/* Parse dwarf attribute if it's a block, reference or constant and put the
15460 resulting value of the attribute into struct bound_prop.
15461 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15462
15463static int
15464attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
15465 struct dwarf2_cu *cu, struct dynamic_prop *prop,
15466 struct type *default_type)
15467{
15468 struct dwarf2_property_baton *baton;
15469 dwarf2_per_objfile *per_objfile = cu->per_objfile;
15470 struct objfile *objfile = per_objfile->objfile;
15471 struct obstack *obstack = &objfile->objfile_obstack;
15472
15473 gdb_assert (default_type != NULL);
15474
15475 if (attr == NULL || prop == NULL)
15476 return 0;
15477
15478 if (attr->form_is_block ())
15479 {
15480 baton = XOBNEW (obstack, struct dwarf2_property_baton);
15481 baton->property_type = default_type;
15482 baton->locexpr.per_cu = cu->per_cu;
15483 baton->locexpr.per_objfile = per_objfile;
15484
15485 struct dwarf_block *block;
15486 if (attr->form == DW_FORM_data16)
15487 {
15488 size_t data_size = 16;
15489 block = XOBNEW (obstack, struct dwarf_block);
15490 block->size = (data_size
15491 + 2 /* Extra bytes for DW_OP and arg. */);
15492 gdb_byte *data = XOBNEWVEC (obstack, gdb_byte, block->size);
15493 data[0] = DW_OP_implicit_value;
15494 data[1] = data_size;
15495 memcpy (&data[2], attr->as_block ()->data, data_size);
15496 block->data = data;
15497 }
15498 else
15499 block = attr->as_block ();
15500
15501 baton->locexpr.size = block->size;
15502 baton->locexpr.data = block->data;
15503 switch (attr->name)
15504 {
15505 case DW_AT_string_length:
15506 baton->locexpr.is_reference = true;
15507 break;
15508 default:
15509 baton->locexpr.is_reference = false;
15510 break;
15511 }
15512
15513 prop->set_locexpr (baton);
15514 gdb_assert (prop->baton () != NULL);
15515 }
15516 else if (attr->form_is_ref ())
15517 {
15518 struct dwarf2_cu *target_cu = cu;
15519 struct die_info *target_die;
15520 struct attribute *target_attr;
15521
15522 target_die = follow_die_ref (die, attr, &target_cu);
15523 target_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
15524 if (target_attr == NULL)
15525 target_attr = dwarf2_attr (target_die, DW_AT_data_member_location,
15526 target_cu);
15527 if (target_attr == nullptr)
15528 target_attr = dwarf2_attr (target_die, DW_AT_data_bit_offset,
15529 target_cu);
15530 if (target_attr == NULL)
15531 {
15532 const char *name = var_decl_name (target_die, target_cu);
15533 if (name != nullptr)
15534 {
15535 prop->set_variable_name (name);
15536 return 1;
15537 }
15538 return 0;
15539 }
15540
15541 switch (target_attr->name)
15542 {
15543 case DW_AT_location:
15544 if (target_attr->form_is_section_offset ())
15545 {
15546 baton = XOBNEW (obstack, struct dwarf2_property_baton);
15547 baton->property_type = die_type (target_die, target_cu);
15548 fill_in_loclist_baton (cu, &baton->loclist, target_attr);
15549 prop->set_loclist (baton);
15550 gdb_assert (prop->baton () != NULL);
15551 }
15552 else if (target_attr->form_is_block ())
15553 {
15554 baton = XOBNEW (obstack, struct dwarf2_property_baton);
15555 baton->property_type = die_type (target_die, target_cu);
15556 baton->locexpr.per_cu = cu->per_cu;
15557 baton->locexpr.per_objfile = per_objfile;
15558 struct dwarf_block *block = target_attr->as_block ();
15559 baton->locexpr.size = block->size;
15560 baton->locexpr.data = block->data;
15561 baton->locexpr.is_reference = true;
15562 prop->set_locexpr (baton);
15563 gdb_assert (prop->baton () != NULL);
15564 }
15565 else
15566 {
15567 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15568 "dynamic property");
15569 return 0;
15570 }
15571 break;
15572 case DW_AT_data_member_location:
15573 case DW_AT_data_bit_offset:
15574 {
15575 LONGEST offset;
15576
15577 if (!handle_member_location (target_die, target_cu, &offset))
15578 return 0;
15579
15580 baton = XOBNEW (obstack, struct dwarf2_property_baton);
15581 baton->property_type = read_type_die (target_die->parent,
15582 target_cu);
15583 baton->offset_info.offset = offset;
15584 baton->offset_info.type = die_type (target_die, target_cu);
15585 prop->set_addr_offset (baton);
15586 break;
15587 }
15588 }
15589 }
15590 else if (attr->form_is_constant ())
15591 prop->set_const_val (attr->constant_value (0));
15592 else if (attr->form_is_section_offset ())
15593 {
15594 switch (attr->name)
15595 {
15596 case DW_AT_string_length:
15597 baton = XOBNEW (obstack, struct dwarf2_property_baton);
15598 baton->property_type = default_type;
15599 fill_in_loclist_baton (cu, &baton->loclist, attr);
15600 prop->set_loclist (baton);
15601 gdb_assert (prop->baton () != NULL);
15602 break;
15603 default:
15604 goto invalid;
15605 }
15606 }
15607 else
15608 goto invalid;
15609
15610 return 1;
15611
15612 invalid:
15614 dwarf2_name (die, cu));
15615 return 0;
15616}
15617
15618/* See read.h. */
15619
15620/* Read the DW_AT_type attribute for a sub-range. If this attribute is not
15621 present (which is valid) then compute the default type based on the
15622 compilation units address size. */
15623
15624static struct type *
15626{
15627 struct type *index_type = die_type (die, cu);
15628
15629 /* Dwarf-2 specifications explicitly allows to create subrange types
15630 without specifying a base type.
15631 In that case, the base type must be set to the type of
15632 the lower bound, upper bound or count, in that order, if any of these
15633 three attributes references an object that has a type.
15634 If no base type is found, the Dwarf-2 specifications say that
15635 a signed integer type of size equal to the size of an address should
15636 be used.
15637 For the following C code: `extern char gdb_int [];'
15638 GCC produces an empty range DIE.
15639 FIXME: muller/2010-05-28: Possible references to object for low bound,
15640 high bound or count are not yet handled by this code. */
15641 if (index_type->code () == TYPE_CODE_VOID)
15642 index_type = cu->addr_sized_int_type (false);
15643
15644 return index_type;
15645}
15646
15647/* Read the given DW_AT_subrange DIE. */
15648
15649static struct type *
15650read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
15651{
15652 struct type *base_type, *orig_base_type;
15653 struct type *range_type;
15654 struct attribute *attr;
15655 struct dynamic_prop low, high;
15656 int low_default_is_valid;
15657 int high_bound_is_count = 0;
15658 const char *name;
15659
15660 orig_base_type = read_subrange_index_type (die, cu);
15661
15662 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15663 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15664 creating the range type, but we use the result of check_typedef
15665 when examining properties of the type. */
15666 base_type = check_typedef (orig_base_type);
15667
15668 /* The die_type call above may have already set the type for this DIE. */
15669 range_type = get_die_type (die, cu);
15670 if (range_type)
15671 return range_type;
15672
15673 high.set_const_val (0);
15674
15675 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15676 omitting DW_AT_lower_bound. */
15677 switch (cu->lang ())
15678 {
15679 case language_c:
15680 case language_cplus:
15681 low.set_const_val (0);
15682 low_default_is_valid = 1;
15683 break;
15684 case language_fortran:
15685 low.set_const_val (1);
15686 low_default_is_valid = 1;
15687 break;
15688 case language_d:
15689 case language_objc:
15690 case language_rust:
15691 low.set_const_val (0);
15692 low_default_is_valid = (cu->header.version >= 4);
15693 break;
15694 case language_ada:
15695 case language_m2:
15696 case language_pascal:
15697 low.set_const_val (1);
15698 low_default_is_valid = (cu->header.version >= 4);
15699 break;
15700 default:
15701 low.set_const_val (0);
15702 low_default_is_valid = 0;
15703 break;
15704 }
15705
15706 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
15707 if (attr != nullptr)
15708 attr_to_dynamic_prop (attr, die, cu, &low, base_type);
15709 else if (!low_default_is_valid)
15710 complaint (_("Missing DW_AT_lower_bound "
15711 "- DIE at %s [in module %s]"),
15714
15715 struct attribute *attr_ub, *attr_count;
15716 attr = attr_ub = dwarf2_attr (die, DW_AT_upper_bound, cu);
15717 if (!attr_to_dynamic_prop (attr, die, cu, &high, base_type))
15718 {
15719 attr = attr_count = dwarf2_attr (die, DW_AT_count, cu);
15720 if (attr_to_dynamic_prop (attr, die, cu, &high, base_type))
15721 {
15722 /* If bounds are constant do the final calculation here. */
15723 if (low.is_constant () && high.is_constant ())
15724 high.set_const_val (low.const_val () + high.const_val () - 1);
15725 else
15726 high_bound_is_count = 1;
15727 }
15728 else
15729 {
15730 if (attr_ub != NULL)
15731 complaint (_("Unresolved DW_AT_upper_bound "
15732 "- DIE at %s [in module %s]"),
15735 if (attr_count != NULL)
15736 complaint (_("Unresolved DW_AT_count "
15737 "- DIE at %s [in module %s]"),
15740 }
15741 }
15742
15743 LONGEST bias = 0;
15744 struct attribute *bias_attr = dwarf2_attr (die, DW_AT_GNU_bias, cu);
15745 if (bias_attr != nullptr && bias_attr->form_is_constant ())
15746 bias = bias_attr->constant_value (0);
15747
15748 /* Normally, the DWARF producers are expected to use a signed
15749 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15750 But this is unfortunately not always the case, as witnessed
15751 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15752 is used instead. To work around that ambiguity, we treat
15753 the bounds as signed, and thus sign-extend their values, when
15754 the base type is signed.
15755
15756 Skip it if the base type's length is larger than ULONGEST, to avoid
15757 the undefined behavior of a too large left shift. We don't really handle
15758 constants larger than 8 bytes anyway, at the moment. */
15759
15760 if (base_type->length () <= sizeof (ULONGEST))
15761 {
15762 ULONGEST negative_mask
15763 = -((ULONGEST) 1 << (base_type->length () * TARGET_CHAR_BIT - 1));
15764
15765 if (low.is_constant ()
15766 && !base_type->is_unsigned () && (low.const_val () & negative_mask))
15767 low.set_const_val (low.const_val () | negative_mask);
15768
15769 if (high.is_constant ()
15770 && !base_type->is_unsigned () && (high.const_val () & negative_mask))
15771 high.set_const_val (high.const_val () | negative_mask);
15772 }
15773
15774 /* Check for bit and byte strides. */
15775 struct dynamic_prop byte_stride_prop;
15776 attribute *attr_byte_stride = dwarf2_attr (die, DW_AT_byte_stride, cu);
15777 if (attr_byte_stride != nullptr)
15778 {
15779 struct type *prop_type = cu->addr_sized_int_type (false);
15780 attr_to_dynamic_prop (attr_byte_stride, die, cu, &byte_stride_prop,
15781 prop_type);
15782 }
15783
15784 struct dynamic_prop bit_stride_prop;
15785 attribute *attr_bit_stride = dwarf2_attr (die, DW_AT_bit_stride, cu);
15786 if (attr_bit_stride != nullptr)
15787 {
15788 /* It only makes sense to have either a bit or byte stride. */
15789 if (attr_byte_stride != nullptr)
15790 {
15791 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
15792 "- DIE at %s [in module %s]"),
15795 attr_bit_stride = nullptr;
15796 }
15797 else
15798 {
15799 struct type *prop_type = cu->addr_sized_int_type (false);
15800 attr_to_dynamic_prop (attr_bit_stride, die, cu, &bit_stride_prop,
15801 prop_type);
15802 }
15803 }
15804
15805 type_allocator alloc (cu->per_objfile->objfile, cu->lang ());
15806 if (attr_byte_stride != nullptr
15807 || attr_bit_stride != nullptr)
15808 {
15809 bool byte_stride_p = (attr_byte_stride != nullptr);
15810 struct dynamic_prop *stride
15811 = byte_stride_p ? &byte_stride_prop : &bit_stride_prop;
15812
15813 range_type
15814 = create_range_type_with_stride (alloc, orig_base_type, &low,
15815 &high, bias, stride, byte_stride_p);
15816 }
15817 else
15818 range_type = create_range_type (alloc, orig_base_type, &low, &high, bias);
15819
15820 if (high_bound_is_count)
15821 range_type->bounds ()->flag_upper_bound_is_count = 1;
15822
15823 /* Ada expects an empty array on no boundary attributes. */
15824 if (attr == NULL && cu->lang () != language_ada)
15825 range_type->bounds ()->high.set_undefined ();
15826
15827 name = dwarf2_name (die, cu);
15828 if (name)
15829 range_type->set_name (name);
15830
15831 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
15832 if (attr != nullptr)
15833 range_type->set_length (attr->constant_value (0));
15834
15835 maybe_set_alignment (cu, die, range_type);
15836
15837 set_die_type (die, range_type, cu);
15838
15839 /* set_die_type should be already done. */
15840 set_descriptive_type (range_type, die, cu);
15841
15842 return range_type;
15843}
15844
15845static struct type *
15847{
15848 struct type *type;
15849
15850 type = (type_allocator (cu->per_objfile->objfile, cu->lang ())
15851 .new_type (TYPE_CODE_VOID, 0, nullptr));
15852 type->set_name (dwarf2_name (die, cu));
15853
15854 /* In Ada, an unspecified type is typically used when the description
15855 of the type is deferred to a different unit. When encountering
15856 such a type, we treat it as a stub, and try to resolve it later on,
15857 when needed.
15858 Mark this as a stub type for all languages though. */
15859 type->set_is_stub (true);
15860
15861 return set_die_type (die, type, cu);
15862}
15863
15864/* Read a single die and all its descendents. Set the die's sibling
15865 field to NULL; set other fields in the die correctly, and set all
15866 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15867 location of the info_ptr after reading all of those dies. PARENT
15868 is the parent of the die in question. */
15869
15870static struct die_info *
15872 const gdb_byte *info_ptr,
15873 const gdb_byte **new_info_ptr,
15874 struct die_info *parent)
15875{
15876 struct die_info *die;
15877 const gdb_byte *cur_ptr;
15878
15879 cur_ptr = read_full_die_1 (reader, &die, info_ptr, 0, true);
15880 if (die == NULL)
15881 {
15882 *new_info_ptr = cur_ptr;
15883 return NULL;
15884 }
15885 store_in_ref_table (die, reader->cu);
15886
15887 if (die->has_children)
15888 die->child = read_die_and_siblings_1 (reader, cur_ptr, new_info_ptr, die);
15889 else
15890 {
15891 die->child = NULL;
15892 *new_info_ptr = cur_ptr;
15893 }
15894
15895 die->sibling = NULL;
15896 die->parent = parent;
15897 return die;
15898}
15899
15900/* Read a die, all of its descendents, and all of its siblings; set
15901 all of the fields of all of the dies correctly. Arguments are as
15902 in read_die_and_children. */
15903
15904static struct die_info *
15906 const gdb_byte *info_ptr,
15907 const gdb_byte **new_info_ptr,
15908 struct die_info *parent)
15909{
15910 struct die_info *first_die, *last_sibling;
15911 const gdb_byte *cur_ptr;
15912
15913 cur_ptr = info_ptr;
15914 first_die = last_sibling = NULL;
15915
15916 while (1)
15917 {
15918 struct die_info *die
15919 = read_die_and_children (reader, cur_ptr, &cur_ptr, parent);
15920
15921 if (die == NULL)
15922 {
15923 *new_info_ptr = cur_ptr;
15924 return first_die;
15925 }
15926
15927 if (!first_die)
15928 first_die = die;
15929 else
15930 last_sibling->sibling = die;
15931
15932 last_sibling = die;
15933 }
15934}
15935
15936/* Read a die, all of its descendents, and all of its siblings; set
15937 all of the fields of all of the dies correctly. Arguments are as
15938 in read_die_and_children.
15939 This the main entry point for reading a DIE and all its children. */
15940
15941static struct die_info *
15943 const gdb_byte *info_ptr,
15944 const gdb_byte **new_info_ptr,
15945 struct die_info *parent)
15946{
15947 struct die_info *die = read_die_and_siblings_1 (reader, info_ptr,
15948 new_info_ptr, parent);
15949
15950 if (dwarf_die_debug)
15951 {
15953 "Read die from %s@0x%x of %s:\n",
15954 reader->die_section->get_name (),
15955 (unsigned) (info_ptr - reader->die_section->buffer),
15956 bfd_get_filename (reader->abfd));
15957 die->dump (dwarf_die_debug);
15958 }
15959
15960 return die;
15961}
15962
15963/* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15964 attributes.
15965 The caller is responsible for filling in the extra attributes
15966 and updating (*DIEP)->num_attrs.
15967 Set DIEP to point to a newly allocated die with its information,
15968 except for its child, sibling, and parent fields. */
15969
15970static const gdb_byte *
15971read_full_die_1 (const struct die_reader_specs *reader,
15972 struct die_info **diep, const gdb_byte *info_ptr,
15973 int num_extra_attrs, bool allow_reprocess)
15974{
15975 unsigned int abbrev_number, bytes_read, i;
15976 const struct abbrev_info *abbrev;
15977 struct die_info *die;
15978 struct dwarf2_cu *cu = reader->cu;
15979 bfd *abfd = reader->abfd;
15980
15981 sect_offset sect_off = (sect_offset) (info_ptr - reader->buffer);
15982 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
15983 info_ptr += bytes_read;
15984 if (!abbrev_number)
15985 {
15986 *diep = NULL;
15987 return info_ptr;
15988 }
15989
15990 abbrev = reader->abbrev_table->lookup_abbrev (abbrev_number);
15991 if (!abbrev)
15992 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15993 abbrev_number,
15994 bfd_get_filename (abfd));
15995
15997 abbrev->num_attrs + num_extra_attrs);
15998 die->sect_off = sect_off;
15999 die->tag = abbrev->tag;
16000 die->abbrev = abbrev_number;
16001 die->has_children = abbrev->has_children;
16002
16003 /* Make the result usable.
16004 The caller needs to update num_attrs after adding the extra
16005 attributes. */
16006 die->num_attrs = abbrev->num_attrs;
16007
16008 for (i = 0; i < abbrev->num_attrs; ++i)
16009 info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i],
16010 info_ptr, allow_reprocess);
16011
16012 *diep = die;
16013 return info_ptr;
16014}
16015
16016/* Read a die and all its attributes.
16017 Set DIEP to point to a newly allocated die with its information,
16018 except for its child, sibling, and parent fields. */
16019
16020static const gdb_byte *
16022 struct die_info **diep, const gdb_byte *info_ptr,
16023 gdb::array_view<attribute *> extra_attrs)
16024{
16025 const gdb_byte *result;
16026 struct dwarf2_cu *cu = reader->cu;
16027
16028 result = read_full_die_1 (reader, diep, info_ptr, extra_attrs.size (),
16029 false);
16030
16031 /* Copy in the extra attributes, if any. */
16032 attribute *next = &(*diep)->attrs[(*diep)->num_attrs];
16033 for (attribute *extra : extra_attrs)
16034 *next++ = *extra;
16035
16036 struct attribute *attr = (*diep)->attr (DW_AT_str_offsets_base);
16037 if (attr != nullptr && attr->form_is_unsigned ())
16038 cu->str_offsets_base = attr->as_unsigned ();
16039
16040 attr = (*diep)->attr (DW_AT_loclists_base);
16041 if (attr != nullptr)
16042 cu->loclist_base = attr->as_unsigned ();
16043
16044 auto maybe_addr_base = (*diep)->addr_base ();
16045 if (maybe_addr_base.has_value ())
16046 cu->addr_base = *maybe_addr_base;
16047
16048 attr = (*diep)->attr (DW_AT_rnglists_base);
16049 if (attr != nullptr)
16050 cu->rnglists_base = attr->as_unsigned ();
16051
16052 for (int i = 0; i < (*diep)->num_attrs; ++i)
16053 {
16054 if ((*diep)->attrs[i].form_requires_reprocessing ())
16055 read_attribute_reprocess (reader, &(*diep)->attrs[i], (*diep)->tag);
16056 }
16057
16058 (*diep)->num_attrs += extra_attrs.size ();
16059
16060 if (dwarf_die_debug)
16061 {
16063 "Read die from %s@0x%x of %s:\n",
16064 reader->die_section->get_name (),
16065 (unsigned) (info_ptr - reader->die_section->buffer),
16066 bfd_get_filename (reader->abfd));
16067 (*diep)->dump (dwarf_die_debug);
16068 }
16069
16070 return result;
16071}
16072
16073
16074void
16076{
16077 if (reader->cu->per_cu->addresses_seen)
16078 return;
16079
16080 dwarf2_cu *cu = reader->cu;
16081
16082 unrelocated_addr best_lowpc = {}, best_highpc = {};
16083 /* Possibly set the default values of LOWPC and HIGHPC from
16084 `DW_AT_ranges'. */
16086 enum pc_bounds_kind cu_bounds_kind
16087 = dwarf2_get_pc_bounds (reader->comp_unit_die, &best_lowpc, &best_highpc,
16088 cu, m_index_storage->get_addrmap (), cu->per_cu);
16089 if (cu_bounds_kind == PC_BOUNDS_HIGH_LOW && best_lowpc < best_highpc)
16090 {
16091 dwarf2_per_objfile *per_objfile = cu->per_objfile;
16092 unrelocated_addr low = per_objfile->adjust (best_lowpc);
16093 unrelocated_addr high = per_objfile->adjust (best_highpc);
16094 /* Store the contiguous range if it is not empty; it can be
16095 empty for CUs with no code. addrmap requires CORE_ADDR, so
16096 we cast here. */
16097 m_index_storage->get_addrmap ()->set_empty ((CORE_ADDR) low,
16098 (CORE_ADDR) high - 1,
16099 cu->per_cu);
16100
16101 cu->per_cu->addresses_seen = true;
16102 }
16103}
16104
16105/* Helper function that returns true if TAG can have a linkage
16106 name. */
16107
16108static bool
16109tag_can_have_linkage_name (enum dwarf_tag tag)
16110{
16111 switch (tag)
16112 {
16113 case DW_TAG_variable:
16114 case DW_TAG_subprogram:
16115 return true;
16116
16117 default:
16118 return false;
16119 }
16120}
16121
16124 dwarf2_per_objfile *per_objfile,
16125 sect_offset sect_off, bool is_dwz,
16126 bool for_scanning)
16127{
16128 /* Lookups for type unit references are always in the CU, and
16129 cross-CU references will crash. */
16130 if (reader->cu->per_cu->is_dwz == is_dwz
16131 && reader->cu->header.offset_in_cu_p (sect_off))
16132 return reader;
16133
16134 dwarf2_per_cu_data *per_cu
16135 = dwarf2_find_containing_comp_unit (sect_off, is_dwz,
16136 per_objfile->per_bfd);
16137
16138 /* When scanning, we only want to visit a given CU a single time.
16139 Doing this check here avoids self-imports as well. */
16140 if (for_scanning)
16141 {
16142 bool nope = false;
16143 if (!per_cu->scanned.compare_exchange_strong (nope, true))
16144 return nullptr;
16145 }
16146 if (per_cu == m_per_cu)
16147 return reader;
16148
16149 cutu_reader *result = m_index_storage->get_reader (per_cu);
16150 if (result == nullptr)
16151 {
16152 cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false,
16154
16155 prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die,
16157 std::unique_ptr<cutu_reader> copy
16158 (new cutu_reader (std::move (new_reader)));
16159 result = m_index_storage->preserve (std::move (copy));
16160 }
16161
16162 if (result->dummy_p || !result->comp_unit_die->has_children)
16163 return nullptr;
16164
16165 if (for_scanning)
16166 check_bounds (result);
16167
16168 return result;
16169}
16170
16171const gdb_byte *
16173 cutu_reader *reader,
16174 const gdb_byte *watermark_ptr,
16175 const gdb_byte *info_ptr,
16176 const abbrev_info *abbrev,
16177 const char **name,
16178 const char **linkage_name,
16179 cooked_index_flag *flags,
16180 sect_offset *sibling_offset,
16181 const cooked_index_entry **parent_entry,
16182 CORE_ADDR *maybe_defer,
16183 bool for_specification)
16184{
16185 bool origin_is_dwz = false;
16186 bool is_declaration = false;
16187 sect_offset origin_offset {};
16188
16189 gdb::optional<unrelocated_addr> low_pc;
16190 gdb::optional<unrelocated_addr> high_pc;
16191 bool high_pc_relative = false;
16192
16193 for (int i = 0; i < abbrev->num_attrs; ++i)
16194 {
16195 attribute attr;
16196 info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
16197
16198 /* Store the data if it is of an attribute we want to keep in a
16199 partial symbol table. */
16200 switch (attr.name)
16201 {
16202 case DW_AT_name:
16203 switch (abbrev->tag)
16204 {
16205 case DW_TAG_compile_unit:
16206 case DW_TAG_partial_unit:
16207 case DW_TAG_type_unit:
16208 /* Compilation units have a DW_AT_name that is a filename, not
16209 a source language identifier. */
16210 break;
16211
16212 default:
16213 if (*name == nullptr)
16214 *name = attr.as_string ();
16215 break;
16216 }
16217 break;
16218
16219 case DW_AT_linkage_name:
16220 case DW_AT_MIPS_linkage_name:
16221 /* Note that both forms of linkage name might appear. We
16222 assume they will be the same, and we only store the last
16223 one we see. */
16224 if (*linkage_name == nullptr)
16225 *linkage_name = attr.as_string ();
16226 break;
16227
16228 /* DWARF 4 has defined a dedicated DW_AT_main_subprogram
16229 attribute to indicate the starting function of the program... */
16230 case DW_AT_main_subprogram:
16231 if (attr.as_boolean ())
16232 *flags |= IS_MAIN;
16233 break;
16234
16235 /* ... however with older versions the DW_CC_program value of
16236 the DW_AT_calling_convention attribute was used instead as
16237 the only means available. We handle both variants then. */
16238 case DW_AT_calling_convention:
16239 if (attr.constant_value (DW_CC_normal) == DW_CC_program)
16240 *flags |= IS_MAIN;
16241 break;
16242
16243 case DW_AT_declaration:
16244 is_declaration = attr.as_boolean ();
16245 break;
16246
16247 case DW_AT_sibling:
16248 if (sibling_offset != nullptr)
16249 *sibling_offset = attr.get_ref_die_offset ();
16250 break;
16251
16252 case DW_AT_specification:
16253 case DW_AT_abstract_origin:
16254 case DW_AT_extension:
16255 origin_offset = attr.get_ref_die_offset ();
16256 origin_is_dwz = attr.form == DW_FORM_GNU_ref_alt;
16257 break;
16258
16259 case DW_AT_external:
16260 if (attr.as_boolean ())
16261 *flags &= ~IS_STATIC;
16262 break;
16263
16264 case DW_AT_enum_class:
16265 if (attr.as_boolean ())
16266 *flags |= IS_ENUM_CLASS;
16267 break;
16268
16269 case DW_AT_low_pc:
16270 low_pc = attr.as_address ();
16271 break;
16272
16273 case DW_AT_high_pc:
16274 high_pc = attr.as_address ();
16275 if (reader->cu->header.version >= 4 && attr.form_is_constant ())
16276 high_pc_relative = true;
16277 break;
16278
16279 case DW_AT_location:
16280 if (!scanning_per_cu->addresses_seen && attr.form_is_block ())
16281 {
16282 struct dwarf_block *locdesc = attr.as_block ();
16283 CORE_ADDR addr;
16284 if (decode_locdesc (locdesc, reader->cu, &addr)
16285 && (addr != 0
16287 {
16288 low_pc = (unrelocated_addr) addr;
16289 /* For variables, we don't want to try decoding the
16290 type just to find the size -- for gdb's purposes
16291 we only need the address of a variable. */
16292 high_pc = (unrelocated_addr) (addr + 1);
16293 high_pc_relative = false;
16294 }
16295 }
16296 break;
16297
16298 case DW_AT_ranges:
16299 if (!scanning_per_cu->addresses_seen)
16300 {
16301 /* Offset in the .debug_ranges or .debug_rnglist section
16302 (depending on DWARF version). */
16303 ULONGEST ranges_offset = attr.as_unsigned ();
16304
16305 /* See dwarf2_cu::gnu_ranges_base's doc for why we might
16306 want to add this value. */
16307 ranges_offset += reader->cu->gnu_ranges_base;
16308
16309 unrelocated_addr lowpc, highpc;
16310 dwarf2_ranges_read (ranges_offset, &lowpc, &highpc, reader->cu,
16312 scanning_per_cu, abbrev->tag);
16313 }
16314 break;
16315 }
16316 }
16317
16318 /* We don't want to examine declarations, but if we found a
16319 declaration when handling DW_AT_specification or the like, then
16320 that is ok. Similarly, we allow an external variable without a
16321 location; those are resolved via minimal symbols. */
16322 if (is_declaration && !for_specification
16323 && !(abbrev->tag == DW_TAG_variable && (*flags & IS_STATIC) == 0))
16324 {
16325 /* We always want to recurse into some types, but we may not
16326 want to treat them as definitions. */
16327 if ((abbrev->tag == DW_TAG_class_type
16328 || abbrev->tag == DW_TAG_structure_type
16329 || abbrev->tag == DW_TAG_union_type)
16330 && abbrev->has_children)
16332 else
16333 {
16334 *linkage_name = nullptr;
16335 *name = nullptr;
16336 }
16337 }
16338 else if ((*name == nullptr
16339 || (*linkage_name == nullptr
16340 && tag_can_have_linkage_name (abbrev->tag))
16341 || (*parent_entry == nullptr && m_language != language_c))
16342 && origin_offset != sect_offset (0))
16343 {
16344 cutu_reader *new_reader
16345 = ensure_cu_exists (reader, reader->cu->per_objfile, origin_offset,
16346 origin_is_dwz, false);
16347 if (new_reader != nullptr)
16348 {
16349 const gdb_byte *new_info_ptr = (new_reader->buffer
16350 + to_underlying (origin_offset));
16351
16352 if (new_reader->cu == reader->cu
16353 && new_info_ptr > watermark_ptr
16354 && *parent_entry == nullptr)
16355 *maybe_defer = form_addr (origin_offset, origin_is_dwz);
16356 else if (*parent_entry == nullptr)
16357 {
16358 CORE_ADDR lookup = form_addr (origin_offset, origin_is_dwz);
16359 void *obj = m_die_range_map.find (lookup);
16360 *parent_entry = static_cast <cooked_index_entry *> (obj);
16361 }
16362
16363 unsigned int bytes_read;
16364 const abbrev_info *new_abbrev = peek_die_abbrev (*new_reader,
16365 new_info_ptr,
16366 &bytes_read);
16367 new_info_ptr += bytes_read;
16368
16369 if (new_reader->cu == reader->cu && new_info_ptr == watermark_ptr)
16370 {
16371 /* Self-reference, we're done. */
16372 }
16373 else
16374 scan_attributes (scanning_per_cu, new_reader, new_info_ptr,
16375 new_info_ptr, new_abbrev, name, linkage_name,
16376 flags, nullptr, parent_entry, maybe_defer, true);
16377 }
16378 }
16379
16380 if (!for_specification)
16381 {
16383 && *linkage_name == nullptr)
16384 *linkage_name = *name;
16385
16386 if (!scanning_per_cu->addresses_seen
16387 && low_pc.has_value ()
16389 || *low_pc != (unrelocated_addr) 0)
16390 && high_pc.has_value ())
16391 {
16392 if (high_pc_relative)
16393 high_pc = (unrelocated_addr) ((ULONGEST) *high_pc
16394 + (ULONGEST) *low_pc);
16395
16396 if (*high_pc > *low_pc)
16397 {
16398 dwarf2_per_objfile *per_objfile = reader->cu->per_objfile;
16399 unrelocated_addr lo = per_objfile->adjust (*low_pc);
16400 unrelocated_addr hi = per_objfile->adjust (*high_pc);
16401 /* Need CORE_ADDR casts for addrmap. */
16402 m_index_storage->get_addrmap ()->set_empty ((CORE_ADDR) lo,
16403 (CORE_ADDR) hi - 1,
16404 scanning_per_cu);
16405 }
16406 }
16407
16408 if (abbrev->tag == DW_TAG_module || abbrev->tag == DW_TAG_namespace)
16409 *flags &= ~IS_STATIC;
16410
16411 if (abbrev->tag == DW_TAG_namespace && *name == nullptr)
16412 *name = "(anonymous namespace)";
16413
16415 && (abbrev->tag == DW_TAG_class_type
16416 || abbrev->tag == DW_TAG_interface_type
16417 || abbrev->tag == DW_TAG_structure_type
16418 || abbrev->tag == DW_TAG_union_type
16419 || abbrev->tag == DW_TAG_enumeration_type
16420 || abbrev->tag == DW_TAG_enumerator))
16421 *flags &= ~IS_STATIC;
16422 }
16423
16424 return info_ptr;
16425}
16426
16427const gdb_byte *
16429 const gdb_byte *info_ptr,
16430 const abbrev_info *abbrev)
16431{
16432 sect_offset sect_off {};
16433 bool is_dwz = false;
16434
16435 for (int i = 0; i < abbrev->num_attrs; ++i)
16436 {
16437 /* Note that we never need to reprocess attributes here. */
16438 attribute attr;
16439 info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
16440
16441 if (attr.name == DW_AT_import)
16442 {
16443 sect_off = attr.get_ref_die_offset ();
16444 is_dwz = (attr.form == DW_FORM_GNU_ref_alt
16445 || reader->cu->per_cu->is_dwz);
16446 }
16447 }
16448
16449 /* Did not find DW_AT_import. */
16450 if (sect_off == sect_offset (0))
16451 return info_ptr;
16452
16453 dwarf2_per_objfile *per_objfile = reader->cu->per_objfile;
16454 cutu_reader *new_reader = ensure_cu_exists (reader, per_objfile, sect_off,
16455 is_dwz, true);
16456 if (new_reader != nullptr)
16457 {
16458 index_dies (new_reader, new_reader->info_ptr, nullptr, false);
16459
16460 reader->cu->add_dependence (new_reader->cu->per_cu);
16461 }
16462
16463 return info_ptr;
16464}
16465
16466const gdb_byte *
16468 const gdb_byte *info_ptr,
16469 const cooked_index_entry *parent_entry,
16470 bool fully)
16471{
16472 info_ptr = index_dies (reader, info_ptr, parent_entry, fully);
16473
16474 if (parent_entry != nullptr)
16475 {
16476 /* Both start and end are inclusive, so use both "+ 1" and "- 1" to
16477 limit the range to the children of parent_entry. */
16478 CORE_ADDR start = form_addr (parent_entry->die_offset + 1,
16479 reader->cu->per_cu->is_dwz);
16480 CORE_ADDR end = form_addr (sect_offset (info_ptr - 1 - reader->buffer),
16481 reader->cu->per_cu->is_dwz);
16482 m_die_range_map.set_empty (start, end, (void *) parent_entry);
16483 }
16484
16485 return info_ptr;
16486}
16487
16488const gdb_byte *
16490 const gdb_byte *info_ptr,
16491 const cooked_index_entry *parent_entry,
16492 bool fully)
16493{
16494 const gdb_byte *end_ptr = (reader->buffer
16495 + to_underlying (reader->cu->header.sect_off)
16496 + reader->cu->header.get_length_with_initial ());
16497
16498 while (info_ptr < end_ptr)
16499 {
16500 sect_offset this_die = (sect_offset) (info_ptr - reader->buffer);
16501 unsigned int bytes_read;
16502 const abbrev_info *abbrev = peek_die_abbrev (*reader, info_ptr,
16503 &bytes_read);
16504 info_ptr += bytes_read;
16505 if (abbrev == nullptr)
16506 break;
16507
16508 if (abbrev->tag == DW_TAG_imported_unit)
16509 {
16510 info_ptr = index_imported_unit (reader, info_ptr, abbrev);
16511 continue;
16512 }
16513
16514 if (!abbrev->interesting)
16515 {
16516 info_ptr = skip_one_die (reader, info_ptr, abbrev, !fully);
16517 if (fully && abbrev->has_children)
16518 info_ptr = index_dies (reader, info_ptr, parent_entry, fully);
16519 continue;
16520 }
16521
16522 const char *name = nullptr;
16523 const char *linkage_name = nullptr;
16524 CORE_ADDR defer = 0;
16525 cooked_index_flag flags = IS_STATIC;
16526 sect_offset sibling {};
16527 const cooked_index_entry *this_parent_entry = parent_entry;
16528 info_ptr = scan_attributes (reader->cu->per_cu, reader, info_ptr,
16529 info_ptr, abbrev, &name, &linkage_name,
16530 &flags, &sibling, &this_parent_entry,
16531 &defer, false);
16532
16533 if (abbrev->tag == DW_TAG_namespace
16535 && strcmp (name, "::") == 0)
16536 {
16537 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they
16538 generated bogus DW_TAG_namespace DIEs with a name of "::"
16539 for the global namespace. Work around this problem
16540 here. */
16541 name = nullptr;
16542 }
16543
16544 const cooked_index_entry *this_entry = nullptr;
16545 if (name != nullptr)
16546 {
16547 if (defer != 0)
16548 m_deferred_entries.push_back ({
16549 this_die, name, defer, abbrev->tag, flags
16550 });
16551 else
16552 this_entry = m_index_storage->add (this_die, abbrev->tag, flags,
16553 name, this_parent_entry,
16554 m_per_cu);
16555 }
16556
16557 if (linkage_name != nullptr)
16558 {
16559 /* We only want this to be "main" if it has a linkage name
16560 but not an ordinary name. */
16561 if (name != nullptr)
16562 flags = flags & ~IS_MAIN;
16563 /* Set the IS_LINKAGE on for everything except when functions
16564 have linkage name present but name is absent. */
16565 if (name != nullptr
16566 || (abbrev->tag != DW_TAG_subprogram
16567 && abbrev->tag != DW_TAG_inlined_subroutine
16568 && abbrev->tag != DW_TAG_entry_point))
16570 m_index_storage->add (this_die, abbrev->tag, flags,
16571 linkage_name, nullptr, m_per_cu);
16572 }
16573
16574 if (abbrev->has_children)
16575 {
16576 switch (abbrev->tag)
16577 {
16578 case DW_TAG_class_type:
16579 case DW_TAG_interface_type:
16580 case DW_TAG_structure_type:
16581 case DW_TAG_union_type:
16582 if (m_language != language_c && this_entry != nullptr)
16583 {
16584 info_ptr = recurse (reader, info_ptr, this_entry, fully);
16585 continue;
16586 }
16587 break;
16588
16589 case DW_TAG_enumeration_type:
16590 /* We need to recurse even for an anonymous enumeration.
16591 Which scope we record as the parent scope depends on
16592 whether we're reading an "enum class". If so, we use
16593 the enum itself as the parent, yielding names like
16594 "enum_class::enumerator"; otherwise we inject the
16595 names into our own parent scope. */
16596 info_ptr = recurse (reader, info_ptr,
16597 ((flags & IS_ENUM_CLASS) == 0)
16598 ? parent_entry
16599 : this_entry,
16600 fully);
16601 continue;
16602
16603 case DW_TAG_module:
16604 if (this_entry == nullptr)
16605 break;
16606 /* FALLTHROUGH */
16607 case DW_TAG_namespace:
16608 /* We don't check THIS_ENTRY for a namespace, to handle
16609 the ancient G++ workaround pointed out above. */
16610 info_ptr = recurse (reader, info_ptr, this_entry, fully);
16611 continue;
16612
16613 case DW_TAG_subprogram:
16616 && this_entry != nullptr)
16617 {
16618 info_ptr = recurse (reader, info_ptr, this_entry, true);
16619 continue;
16620 }
16621 break;
16622 }
16623
16624 if (sibling != sect_offset (0))
16625 {
16626 const gdb_byte *sibling_ptr
16627 = reader->buffer + to_underlying (sibling);
16628
16629 if (sibling_ptr < info_ptr)
16630 complaint (_("DW_AT_sibling points backwards"));
16631 else if (sibling_ptr > reader->buffer_end)
16632 reader->die_section->overflow_complaint ();
16633 else
16634 info_ptr = sibling_ptr;
16635 }
16636 else
16637 info_ptr = skip_children (reader, info_ptr);
16638 }
16639 }
16640
16641 return info_ptr;
16642}
16643
16644void
16646{
16647 check_bounds (reader);
16648 find_file_and_directory (reader->comp_unit_die, reader->cu);
16649 if (!reader->comp_unit_die->has_children)
16650 return;
16651 index_dies (reader, reader->info_ptr, nullptr, false);
16652
16653 for (const auto &entry : m_deferred_entries)
16654 {
16655 void *obj = m_die_range_map.find (entry.spec_offset);
16656 cooked_index_entry *parent = static_cast<cooked_index_entry *> (obj);
16657 m_index_storage->add (entry.die_offset, entry.tag, entry.flags,
16658 entry.name, parent, m_per_cu);
16659 }
16660}
16661
16662/* An implementation of quick_symbol_functions for the cooked DWARF
16663 index. */
16664
16666{
16668 CORE_ADDR adjusted_pc) override;
16669
16671 (struct objfile *objfile, CORE_ADDR address) override;
16672
16673 void dump (struct objfile *objfile) override
16674 {
16676 cooked_index *index
16677 = (gdb::checked_static_cast<cooked_index *>
16678 (per_objfile->per_bfd->index_table.get ()));
16679 if (index == nullptr)
16680 return;
16681
16682 gdb_printf ("Cooked index in use:\n");
16683 gdb_printf ("\n");
16684 index->dump (objfile->arch ());
16685 }
16686
16688 (struct objfile *,
16689 const lookup_name_info &lookup_name,
16690 domain_enum domain,
16691 int global,
16692 symbol_compare_ftype *ordered_compare) override;
16693
16695 (struct objfile *objfile,
16696 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
16697 const lookup_name_info *lookup_name,
16698 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
16699 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
16700 block_search_flags search_flags,
16701 domain_enum domain,
16702 enum search_domain kind) override;
16703
16705 {
16706 return true;
16707 }
16708
16709 void read_partial_symbols (struct objfile *objfile) override
16710 {
16711 if (dwarf2_has_info (objfile, nullptr))
16713 }
16714
16716 const char *name,
16717 domain_enum domain,
16718 bool *symbol_found_p) override
16719 {
16720 *symbol_found_p = false;
16721
16722 if (!(domain == VAR_DOMAIN && streq (name, "main")))
16723 return language_unknown;
16724
16726 struct dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
16727 if (per_bfd->index_table == nullptr)
16728 return language_unknown;
16729
16730 /* Expansion of large CUs can be slow. By returning the language of main
16731 here for C and C++, we avoid CU expansion during set_initial_language.
16732 But by doing a symbol lookup in the cooked index, we are forced to wait
16733 for finalization to complete. See PR symtab/30174 for ideas how to
16734 bypass that as well. */
16735 cooked_index *table
16736 = (gdb::checked_static_cast<cooked_index *>
16737 (per_bfd->index_table.get ()));
16738
16739 for (const cooked_index_entry *entry : table->find (name, false))
16740 {
16741 if (entry->tag != DW_TAG_subprogram)
16742 continue;
16743
16744 enum language lang = entry->per_cu->lang ();
16745 if (!(lang == language_c || lang == language_cplus))
16746 continue;
16747
16748 *symbol_found_p = true;
16749 return lang;
16750 }
16751
16752 return language_unknown;
16753 }
16754};
16755
16758 CORE_ADDR adjusted_pc)
16759{
16760 cooked_index *table
16761 = (gdb::checked_static_cast<cooked_index *>
16762 (per_bfd->index_table.get ()));
16763 if (table == nullptr)
16764 return nullptr;
16765 return table->lookup (adjusted_pc);
16766}
16767
16768struct compunit_symtab *
16770 (struct objfile *objfile, CORE_ADDR address)
16771{
16772 if (objfile->sect_index_data == -1)
16773 return nullptr;
16774
16776 cooked_index *table
16777 = (gdb::checked_static_cast<cooked_index *>
16778 (per_objfile->per_bfd->index_table.get ()));
16779 if (table == nullptr)
16780 return nullptr;
16781
16782 CORE_ADDR baseaddr = objfile->data_section_offset ();
16783 dwarf2_per_cu_data *per_cu = table->lookup (address - baseaddr);
16784 if (per_cu == nullptr)
16785 return nullptr;
16786
16787 return dw2_instantiate_symtab (per_cu, per_objfile, false);
16788}
16789
16790void
16792 (struct objfile *objfile,
16793 const lookup_name_info &lookup_name,
16794 domain_enum domain,
16795 int global,
16796 symbol_compare_ftype *ordered_compare)
16797{
16799 cooked_index *table
16800 = (gdb::checked_static_cast<cooked_index *>
16801 (per_objfile->per_bfd->index_table.get ()));
16802 if (table == nullptr)
16803 return;
16804
16805 const block_search_flags search_flags = (global
16808 const language_defn *lang = language_def (language_ada);
16809 symbol_name_matcher_ftype *name_match
16810 = lang->get_symbol_name_matcher (lookup_name);
16811
16812 for (const cooked_index_entry *entry : table->all_entries ())
16813 {
16814 QUIT;
16815
16816 if (entry->parent_entry != nullptr)
16817 continue;
16818
16819 if (!entry->matches (search_flags)
16820 || !entry->matches (domain))
16821 continue;
16822
16823 if (name_match (entry->canonical, lookup_name, nullptr))
16824 dw2_instantiate_symtab (entry->per_cu, per_objfile, false);
16825 }
16826}
16827
16828bool
16830 (struct objfile *objfile,
16831 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
16832 const lookup_name_info *lookup_name,
16833 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
16834 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
16835 block_search_flags search_flags,
16836 domain_enum domain,
16837 enum search_domain kind)
16838{
16840
16841 cooked_index *table
16842 = (gdb::checked_static_cast<cooked_index *>
16843 (per_objfile->per_bfd->index_table.get ()));
16844 if (table == nullptr)
16845 return true;
16846
16847 table->wait ();
16848
16849 dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
16850
16851 /* This invariant is documented in quick-functions.h. */
16852 gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
16853 if (lookup_name == nullptr)
16854 {
16855 for (dwarf2_per_cu_data *per_cu
16856 : all_units_range (per_objfile->per_bfd))
16857 {
16858 QUIT;
16859
16860 if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
16861 file_matcher,
16862 expansion_notify))
16863 return false;
16864 }
16865 return true;
16866 }
16867
16868 lookup_name_info lookup_name_without_params
16869 = lookup_name->make_ignore_params ();
16870 bool completing = lookup_name->completion_mode ();
16871
16872 /* Unique styles of language splitting. */
16873 static const enum language unique_styles[] =
16874 {
16875 /* No splitting is also a style. */
16876 language_c,
16877 /* This includes Rust. */
16879 /* This includes Go. */
16880 language_d,
16882 };
16883
16884 for (enum language lang : unique_styles)
16885 {
16886 std::vector<gdb::string_view> name_vec
16887 = lookup_name_without_params.split_name (lang);
16888 std::string last_name = gdb::to_string (name_vec.back ());
16889
16890 for (const cooked_index_entry *entry : table->find (last_name,
16891 completing))
16892 {
16893 QUIT;
16894
16895 /* No need to consider symbols from expanded CUs. */
16896 if (per_objfile->symtab_set_p (entry->per_cu))
16897 continue;
16898
16899 /* If file-matching was done, we don't need to consider
16900 symbols from unmarked CUs. */
16901 if (file_matcher != nullptr && !entry->per_cu->mark)
16902 continue;
16903
16904 /* See if the symbol matches the type filter. */
16905 if (!entry->matches (search_flags)
16906 || !entry->matches (domain)
16907 || !entry->matches (kind))
16908 continue;
16909
16910 /* We've found the base name of the symbol; now walk its
16911 parentage chain, ensuring that each component
16912 matches. */
16913 bool found = true;
16914
16915 const cooked_index_entry *parent = entry->parent_entry;
16916 for (int i = name_vec.size () - 1; i > 0; --i)
16917 {
16918 /* If we ran out of entries, or if this segment doesn't
16919 match, this did not match. */
16920 if (parent == nullptr
16921 || strncmp (parent->name, name_vec[i - 1].data (),
16922 name_vec[i - 1].length ()) != 0)
16923 {
16924 found = false;
16925 break;
16926 }
16927
16928 parent = parent->parent_entry;
16929 }
16930
16931 if (!found)
16932 continue;
16933
16934 /* Might have been looking for "a::b" and found
16935 "x::a::b". */
16936 if (symbol_matcher == nullptr)
16937 {
16938 symbol_name_match_type match_type
16939 = lookup_name_without_params.match_type ();
16940 if ((match_type == symbol_name_match_type::FULL
16941 || (lang != language_ada
16942 && match_type == symbol_name_match_type::EXPRESSION))
16943 && parent != nullptr)
16944 continue;
16945 }
16946 else
16947 {
16948 auto_obstack temp_storage;
16949 const char *full_name = entry->full_name (&temp_storage);
16950 if (!symbol_matcher (full_name))
16951 continue;
16952 }
16953
16954 if (!dw2_expand_symtabs_matching_one (entry->per_cu, per_objfile,
16955 file_matcher,
16956 expansion_notify))
16957 return false;
16958 }
16959 }
16960
16961 return true;
16962}
16963
16964/* Return a new cooked_index_functions object. */
16965
16971
16974{
16975 return make_cooked_index_funcs ();
16976}
16977
16978
16979
16980/* Read the .debug_loclists or .debug_rnglists header (they are the same format)
16981 contents from the given SECTION in the HEADER.
16982
16983 HEADER_OFFSET is the offset of the header in the section. */
16984static void
16986 struct dwarf2_section_info *section,
16987 sect_offset header_offset)
16988{
16989 unsigned int bytes_read;
16990 bfd *abfd = section->get_bfd_owner ();
16991 const gdb_byte *info_ptr = section->buffer + to_underlying (header_offset);
16992
16993 header->length = read_initial_length (abfd, info_ptr, &bytes_read);
16994 info_ptr += bytes_read;
16995
16996 header->version = read_2_bytes (abfd, info_ptr);
16997 info_ptr += 2;
16998
16999 header->addr_size = read_1_byte (abfd, info_ptr);
17000 info_ptr += 1;
17001
17002 header->segment_collector_size = read_1_byte (abfd, info_ptr);
17003 info_ptr += 1;
17004
17005 header->offset_entry_count = read_4_bytes (abfd, info_ptr);
17006}
17007
17008/* Return the DW_AT_loclists_base value for the CU. */
17009static ULONGEST
17011{
17012 /* For the .dwo unit, the loclist_base points to the first offset following
17013 the header. The header consists of the following entities-
17014 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
17015 bit format)
17016 2. version (2 bytes)
17017 3. address size (1 byte)
17018 4. segment selector size (1 byte)
17019 5. offset entry count (4 bytes)
17020 These sizes are derived as per the DWARFv5 standard. */
17021 if (cu->dwo_unit != nullptr)
17022 {
17023 if (cu->header.initial_length_size == 4)
17024 return LOCLIST_HEADER_SIZE32;
17025 return LOCLIST_HEADER_SIZE64;
17026 }
17027 return cu->loclist_base;
17028}
17029
17030/* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
17031 array of offsets in the .debug_loclists section. */
17032
17033static sect_offset
17034read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index)
17035{
17036 dwarf2_per_objfile *per_objfile = cu->per_objfile;
17037 struct objfile *objfile = per_objfile->objfile;
17038 bfd *abfd = objfile->obfd.get ();
17039 ULONGEST loclist_header_size =
17042 ULONGEST loclist_base = lookup_loclist_base (cu);
17043
17044 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
17045 ULONGEST start_offset =
17046 loclist_base + loclist_index * cu->header.offset_size;
17047
17048 /* Get loclists section. */
17050
17051 /* Read the loclists section content. */
17052 section->read (objfile);
17053 if (section->buffer == NULL)
17054 error (_("DW_FORM_loclistx used without .debug_loclists "
17055 "section [in module %s]"), objfile_name (objfile));
17056
17057 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
17058 so if loclist_base is smaller than the header size, we have a problem. */
17059 if (loclist_base < loclist_header_size)
17060 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
17062
17063 /* Read the header of the loclists contribution. */
17064 struct loclists_rnglists_header header;
17065 read_loclists_rnglists_header (&header, section,
17066 (sect_offset) (loclist_base - loclist_header_size));
17067
17068 /* Verify the loclist index is valid. */
17069 if (loclist_index >= header.offset_entry_count)
17070 error (_("DW_FORM_loclistx pointing outside of "
17071 ".debug_loclists offset array [in module %s]"),
17073
17074 /* Validate that reading won't go beyond the end of the section. */
17075 if (start_offset + cu->header.offset_size > section->size)
17076 error (_("Reading DW_FORM_loclistx index beyond end of"
17077 ".debug_loclists section [in module %s]"),
17079
17080 const gdb_byte *info_ptr = section->buffer + start_offset;
17081
17082 if (cu->header.offset_size == 4)
17083 return (sect_offset) (bfd_get_32 (abfd, info_ptr) + loclist_base);
17084 else
17085 return (sect_offset) (bfd_get_64 (abfd, info_ptr) + loclist_base);
17086}
17087
17088/* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
17089 array of offsets in the .debug_rnglists section. */
17090
17091static sect_offset
17092read_rnglist_index (struct dwarf2_cu *cu, ULONGEST rnglist_index,
17093 dwarf_tag tag)
17094{
17097 bfd *abfd = objfile->obfd.get ();
17098 ULONGEST rnglist_header_size =
17101
17102 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
17103 .debug_rnglists.dwo section. The rnglists base given in the skeleton
17104 doesn't apply. */
17105 ULONGEST rnglist_base =
17106 (cu->dwo_unit != nullptr) ? rnglist_header_size : cu->rnglists_base;
17107
17108 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
17109 ULONGEST start_offset =
17110 rnglist_base + rnglist_index * cu->header.offset_size;
17111
17112 /* Get rnglists section. */
17114
17115 /* Read the rnglists section content. */
17116 section->read (objfile);
17117 if (section->buffer == nullptr)
17118 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
17119 "[in module %s]"),
17121
17122 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
17123 so if rnglist_base is smaller than the header size, we have a problem. */
17124 if (rnglist_base < rnglist_header_size)
17125 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
17127
17128 /* Read the header of the rnglists contribution. */
17129 struct loclists_rnglists_header header;
17130 read_loclists_rnglists_header (&header, section,
17131 (sect_offset) (rnglist_base - rnglist_header_size));
17132
17133 /* Verify the rnglist index is valid. */
17134 if (rnglist_index >= header.offset_entry_count)
17135 error (_("DW_FORM_rnglistx index pointing outside of "
17136 ".debug_rnglists offset array [in module %s]"),
17138
17139 /* Validate that reading won't go beyond the end of the section. */
17140 if (start_offset + cu->header.offset_size > section->size)
17141 error (_("Reading DW_FORM_rnglistx index beyond end of"
17142 ".debug_rnglists section [in module %s]"),
17144
17145 const gdb_byte *info_ptr = section->buffer + start_offset;
17146
17147 if (cu->header.offset_size == 4)
17148 return (sect_offset) (read_4_bytes (abfd, info_ptr) + rnglist_base);
17149 else
17150 return (sect_offset) (read_8_bytes (abfd, info_ptr) + rnglist_base);
17151}
17152
17153/* Process the attributes that had to be skipped in the first round. These
17154 attributes are the ones that need str_offsets_base or addr_base attributes.
17155 They could not have been processed in the first round, because at the time
17156 the values of str_offsets_base or addr_base may not have been known. */
17157static void
17159 struct attribute *attr, dwarf_tag tag)
17160{
17161 struct dwarf2_cu *cu = reader->cu;
17162 switch (attr->form)
17163 {
17164 case DW_FORM_addrx:
17165 case DW_FORM_GNU_addr_index:
17166 attr->set_address (read_addr_index (cu,
17167 attr->as_unsigned_reprocess ()));
17168 break;
17169 case DW_FORM_loclistx:
17170 {
17171 sect_offset loclists_sect_off
17173
17174 attr->set_unsigned (to_underlying (loclists_sect_off));
17175 }
17176 break;
17177 case DW_FORM_rnglistx:
17178 {
17179 sect_offset rnglists_sect_off
17180 = read_rnglist_index (cu, attr->as_unsigned_reprocess (), tag);
17181
17182 attr->set_unsigned (to_underlying (rnglists_sect_off));
17183 }
17184 break;
17185 case DW_FORM_strx:
17186 case DW_FORM_strx1:
17187 case DW_FORM_strx2:
17188 case DW_FORM_strx3:
17189 case DW_FORM_strx4:
17190 case DW_FORM_GNU_str_index:
17191 {
17192 unsigned int str_index = attr->as_unsigned_reprocess ();
17193 gdb_assert (!attr->canonical_string_p ());
17194 if (reader->dwo_file != NULL)
17196 str_index));
17197 else
17199 str_index));
17200 break;
17201 }
17202 default:
17203 gdb_assert_not_reached ("Unexpected DWARF form.");
17204 }
17205}
17206
17207/* Read an attribute value described by an attribute form. */
17208
17209static const gdb_byte *
17211 struct attribute *attr, unsigned form,
17212 LONGEST implicit_const, const gdb_byte *info_ptr,
17213 bool allow_reprocess)
17214{
17215 struct dwarf2_cu *cu = reader->cu;
17217 struct objfile *objfile = per_objfile->objfile;
17218 bfd *abfd = reader->abfd;
17219 struct comp_unit_head *cu_header = &cu->header;
17220 unsigned int bytes_read;
17221 struct dwarf_block *blk;
17222
17223 attr->form = (enum dwarf_form) form;
17224 switch (form)
17225 {
17226 case DW_FORM_ref_addr:
17227 if (cu_header->version == 2)
17228 attr->set_unsigned ((ULONGEST) cu_header->read_address (abfd, info_ptr,
17229 &bytes_read));
17230 else
17231 attr->set_unsigned (cu_header->read_offset (abfd, info_ptr,
17232 &bytes_read));
17233 info_ptr += bytes_read;
17234 break;
17235 case DW_FORM_GNU_ref_alt:
17236 attr->set_unsigned (cu_header->read_offset (abfd, info_ptr,
17237 &bytes_read));
17238 info_ptr += bytes_read;
17239 break;
17240 case DW_FORM_addr:
17241 {
17242 unrelocated_addr addr = cu_header->read_address (abfd, info_ptr,
17243 &bytes_read);
17244 addr = per_objfile->adjust (addr);
17245 attr->set_address (addr);
17246 info_ptr += bytes_read;
17247 }
17248 break;
17249 case DW_FORM_block2:
17250 blk = dwarf_alloc_block (cu);
17251 blk->size = read_2_bytes (abfd, info_ptr);
17252 info_ptr += 2;
17253 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
17254 info_ptr += blk->size;
17255 attr->set_block (blk);
17256 break;
17257 case DW_FORM_block4:
17258 blk = dwarf_alloc_block (cu);
17259 blk->size = read_4_bytes (abfd, info_ptr);
17260 info_ptr += 4;
17261 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
17262 info_ptr += blk->size;
17263 attr->set_block (blk);
17264 break;
17265 case DW_FORM_data2:
17266 attr->set_unsigned (read_2_bytes (abfd, info_ptr));
17267 info_ptr += 2;
17268 break;
17269 case DW_FORM_data4:
17270 attr->set_unsigned (read_4_bytes (abfd, info_ptr));
17271 info_ptr += 4;
17272 break;
17273 case DW_FORM_data8:
17274 attr->set_unsigned (read_8_bytes (abfd, info_ptr));
17275 info_ptr += 8;
17276 break;
17277 case DW_FORM_data16:
17278 blk = dwarf_alloc_block (cu);
17279 blk->size = 16;
17280 blk->data = read_n_bytes (abfd, info_ptr, 16);
17281 info_ptr += 16;
17282 attr->set_block (blk);
17283 break;
17284 case DW_FORM_sec_offset:
17285 attr->set_unsigned (cu_header->read_offset (abfd, info_ptr,
17286 &bytes_read));
17287 info_ptr += bytes_read;
17288 break;
17289 case DW_FORM_loclistx:
17290 {
17291 attr->set_unsigned_reprocess (read_unsigned_leb128 (abfd, info_ptr,
17292 &bytes_read));
17293 info_ptr += bytes_read;
17294 if (allow_reprocess)
17295 read_attribute_reprocess (reader, attr);
17296 }
17297 break;
17298 case DW_FORM_string:
17299 attr->set_string_noncanonical (read_direct_string (abfd, info_ptr,
17300 &bytes_read));
17301 info_ptr += bytes_read;
17302 break;
17303 case DW_FORM_strp:
17304 if (!cu->per_cu->is_dwz)
17305 {
17307 (read_indirect_string (per_objfile,
17308 abfd, info_ptr, cu_header,
17309 &bytes_read));
17310 info_ptr += bytes_read;
17311 break;
17312 }
17313 /* FALLTHROUGH */
17314 case DW_FORM_line_strp:
17315 if (!cu->per_cu->is_dwz)
17316 {
17318 (per_objfile->read_line_string (info_ptr, cu_header,
17319 &bytes_read));
17320 info_ptr += bytes_read;
17321 break;
17322 }
17323 /* FALLTHROUGH */
17324 case DW_FORM_GNU_strp_alt:
17325 {
17326 dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true);
17327 LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
17328 &bytes_read);
17329
17331 (dwz->read_string (objfile, str_offset));
17332 info_ptr += bytes_read;
17333 }
17334 break;
17335 case DW_FORM_exprloc:
17336 case DW_FORM_block:
17337 blk = dwarf_alloc_block (cu);
17338 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
17339 info_ptr += bytes_read;
17340 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
17341 info_ptr += blk->size;
17342 attr->set_block (blk);
17343 break;
17344 case DW_FORM_block1:
17345 blk = dwarf_alloc_block (cu);
17346 blk->size = read_1_byte (abfd, info_ptr);
17347 info_ptr += 1;
17348 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
17349 info_ptr += blk->size;
17350 attr->set_block (blk);
17351 break;
17352 case DW_FORM_data1:
17353 case DW_FORM_flag:
17354 attr->set_unsigned (read_1_byte (abfd, info_ptr));
17355 info_ptr += 1;
17356 break;
17357 case DW_FORM_flag_present:
17358 attr->set_unsigned (1);
17359 break;
17360 case DW_FORM_sdata:
17361 attr->set_signed (read_signed_leb128 (abfd, info_ptr, &bytes_read));
17362 info_ptr += bytes_read;
17363 break;
17364 case DW_FORM_rnglistx:
17365 {
17366 attr->set_unsigned_reprocess (read_unsigned_leb128 (abfd, info_ptr,
17367 &bytes_read));
17368 info_ptr += bytes_read;
17369 if (allow_reprocess)
17370 read_attribute_reprocess (reader, attr);
17371 }
17372 break;
17373 case DW_FORM_udata:
17374 attr->set_unsigned (read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
17375 info_ptr += bytes_read;
17376 break;
17377 case DW_FORM_ref1:
17378 attr->set_unsigned ((to_underlying (cu_header->sect_off)
17379 + read_1_byte (abfd, info_ptr)));
17380 info_ptr += 1;
17381 break;
17382 case DW_FORM_ref2:
17383 attr->set_unsigned ((to_underlying (cu_header->sect_off)
17384 + read_2_bytes (abfd, info_ptr)));
17385 info_ptr += 2;
17386 break;
17387 case DW_FORM_ref4:
17388 attr->set_unsigned ((to_underlying (cu_header->sect_off)
17389 + read_4_bytes (abfd, info_ptr)));
17390 info_ptr += 4;
17391 break;
17392 case DW_FORM_ref8:
17393 attr->set_unsigned ((to_underlying (cu_header->sect_off)
17394 + read_8_bytes (abfd, info_ptr)));
17395 info_ptr += 8;
17396 break;
17397 case DW_FORM_ref_sig8:
17398 attr->set_signature (read_8_bytes (abfd, info_ptr));
17399 info_ptr += 8;
17400 break;
17401 case DW_FORM_ref_udata:
17402 attr->set_unsigned ((to_underlying (cu_header->sect_off)
17403 + read_unsigned_leb128 (abfd, info_ptr,
17404 &bytes_read)));
17405 info_ptr += bytes_read;
17406 break;
17407 case DW_FORM_indirect:
17408 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
17409 info_ptr += bytes_read;
17410 if (form == DW_FORM_implicit_const)
17411 {
17412 implicit_const = read_signed_leb128 (abfd, info_ptr, &bytes_read);
17413 info_ptr += bytes_read;
17414 }
17415 info_ptr = read_attribute_value (reader, attr, form, implicit_const,
17416 info_ptr, allow_reprocess);
17417 break;
17418 case DW_FORM_implicit_const:
17419 attr->set_signed (implicit_const);
17420 break;
17421 case DW_FORM_addrx:
17422 case DW_FORM_GNU_addr_index:
17423 attr->set_unsigned_reprocess (read_unsigned_leb128 (abfd, info_ptr,
17424 &bytes_read));
17425 info_ptr += bytes_read;
17426 if (allow_reprocess)
17427 read_attribute_reprocess (reader, attr);
17428 break;
17429 case DW_FORM_strx:
17430 case DW_FORM_strx1:
17431 case DW_FORM_strx2:
17432 case DW_FORM_strx3:
17433 case DW_FORM_strx4:
17434 case DW_FORM_GNU_str_index:
17435 {
17436 ULONGEST str_index;
17437 if (form == DW_FORM_strx1)
17438 {
17439 str_index = read_1_byte (abfd, info_ptr);
17440 info_ptr += 1;
17441 }
17442 else if (form == DW_FORM_strx2)
17443 {
17444 str_index = read_2_bytes (abfd, info_ptr);
17445 info_ptr += 2;
17446 }
17447 else if (form == DW_FORM_strx3)
17448 {
17449 str_index = read_3_bytes (abfd, info_ptr);
17450 info_ptr += 3;
17451 }
17452 else if (form == DW_FORM_strx4)
17453 {
17454 str_index = read_4_bytes (abfd, info_ptr);
17455 info_ptr += 4;
17456 }
17457 else
17458 {
17459 str_index = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
17460 info_ptr += bytes_read;
17461 }
17462 attr->set_unsigned_reprocess (str_index);
17463 if (allow_reprocess)
17464 read_attribute_reprocess (reader, attr);
17465 }
17466 break;
17467 default:
17468 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
17469 dwarf_form_name (form),
17470 bfd_get_filename (abfd));
17471 }
17472
17473 /* Super hack. */
17474 if (cu->per_cu->is_dwz && attr->form_is_ref ())
17475 attr->form = DW_FORM_GNU_ref_alt;
17476
17477 /* We have seen instances where the compiler tried to emit a byte
17478 size attribute of -1 which ended up being encoded as an unsigned
17479 0xffffffff. Although 0xffffffff is technically a valid size value,
17480 an object of this size seems pretty unlikely so we can relatively
17481 safely treat these cases as if the size attribute was invalid and
17482 treat them as zero by default. */
17483 if (attr->name == DW_AT_byte_size
17484 && form == DW_FORM_data4
17485 && attr->as_unsigned () >= 0xffffffff)
17486 {
17487 complaint
17488 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
17489 hex_string (attr->as_unsigned ()));
17490 attr->set_unsigned (0);
17491 }
17492
17493 return info_ptr;
17494}
17495
17496/* Read an attribute described by an abbreviated attribute. */
17497
17498static const gdb_byte *
17499read_attribute (const struct die_reader_specs *reader,
17500 struct attribute *attr, const struct attr_abbrev *abbrev,
17501 const gdb_byte *info_ptr,
17502 bool allow_reprocess)
17503{
17504 attr->name = abbrev->name;
17505 attr->string_is_canonical = 0;
17506 return read_attribute_value (reader, attr, abbrev->form,
17507 abbrev->implicit_const, info_ptr,
17508 allow_reprocess);
17509}
17510
17511/* See read.h. */
17512
17513const char *
17515 LONGEST str_offset)
17516{
17517 return per_objfile->per_bfd->str.read_string (per_objfile->objfile,
17518 str_offset, "DW_FORM_strp");
17519}
17520
17521/* Return pointer to string at .debug_str offset as read from BUF.
17522 BUF is assumed to be in a compilation unit described by CU_HEADER.
17523 Return *BYTES_READ_PTR count of bytes read from BUF. */
17524
17525static const char *
17527 const gdb_byte *buf,
17528 const struct comp_unit_head *cu_header,
17529 unsigned int *bytes_read_ptr)
17530{
17531 LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr);
17532
17533 return read_indirect_string_at_offset (per_objfile, str_offset);
17534}
17535
17536/* See read.h. */
17537
17538const char *
17540 unsigned int offset_size)
17541{
17542 bfd *abfd = objfile->obfd.get ();
17543 ULONGEST str_offset = read_offset (abfd, buf, offset_size);
17544
17545 return per_bfd->line_str.read_string (objfile, str_offset, "DW_FORM_line_strp");
17546}
17547
17548/* See read.h. */
17549
17550const char *
17552 const struct comp_unit_head *cu_header,
17553 unsigned int *bytes_read_ptr)
17554{
17555 bfd *abfd = objfile->obfd.get ();
17556 LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr);
17557
17558 return per_bfd->line_str.read_string (objfile, str_offset, "DW_FORM_line_strp");
17559}
17560
17561/* Given index ADDR_INDEX in .debug_addr, fetch the value.
17562 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
17563 ADDR_SIZE is the size of addresses from the CU header. */
17564
17565static unrelocated_addr
17566read_addr_index_1 (dwarf2_per_objfile *per_objfile, unsigned int addr_index,
17567 gdb::optional<ULONGEST> addr_base, int addr_size)
17568{
17569 struct objfile *objfile = per_objfile->objfile;
17570 bfd *abfd = objfile->obfd.get ();
17571 const gdb_byte *info_ptr;
17572 ULONGEST addr_base_or_zero = addr_base.has_value () ? *addr_base : 0;
17573
17574 per_objfile->per_bfd->addr.read (objfile);
17575 if (per_objfile->per_bfd->addr.buffer == NULL)
17576 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17578 if (addr_base_or_zero + addr_index * addr_size
17579 >= per_objfile->per_bfd->addr.size)
17580 error (_("DW_FORM_addr_index pointing outside of "
17581 ".debug_addr section [in module %s]"),
17583 info_ptr = (per_objfile->per_bfd->addr.buffer + addr_base_or_zero
17584 + addr_index * addr_size);
17585 if (addr_size == 4)
17586 return (unrelocated_addr) bfd_get_32 (abfd, info_ptr);
17587 else
17588 return (unrelocated_addr) bfd_get_64 (abfd, info_ptr);
17589}
17590
17591/* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17592
17593static unrelocated_addr
17594read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index)
17595{
17596 return read_addr_index_1 (cu->per_objfile, addr_index,
17597 cu->addr_base, cu->header.addr_size);
17598}
17599
17600/* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17601
17602static unrelocated_addr
17603read_addr_index_from_leb128 (struct dwarf2_cu *cu, const gdb_byte *info_ptr,
17604 unsigned int *bytes_read)
17605{
17606 bfd *abfd = cu->per_objfile->objfile->obfd.get ();
17607 unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
17608
17609 return read_addr_index (cu, addr_index);
17610}
17611
17612/* See read.h. */
17613
17614unrelocated_addr
17616 dwarf2_per_objfile *per_objfile,
17617 unsigned int addr_index)
17618{
17619 struct dwarf2_cu *cu = per_objfile->get_cu (per_cu);
17620 gdb::optional<ULONGEST> addr_base;
17621 int addr_size;
17622
17623 /* We need addr_base and addr_size.
17624 If we don't have PER_CU->cu, we have to get it.
17625 Nasty, but the alternative is storing the needed info in PER_CU,
17626 which at this point doesn't seem justified: it's not clear how frequently
17627 it would get used and it would increase the size of every PER_CU.
17628 Entry points like dwarf2_per_cu_addr_size do a similar thing
17629 so we're not in uncharted territory here.
17630 Alas we need to be a bit more complicated as addr_base is contained
17631 in the DIE.
17632
17633 We don't need to read the entire CU(/TU).
17634 We just need the header and top level die.
17635
17636 IWBN to use the aging mechanism to let us lazily later discard the CU.
17637 For now we skip this optimization. */
17638
17639 if (cu != NULL)
17640 {
17641 addr_base = cu->addr_base;
17642 addr_size = cu->header.addr_size;
17643 }
17644 else
17645 {
17646 cutu_reader reader (per_cu, per_objfile, nullptr, nullptr, false);
17647 addr_base = reader.cu->addr_base;
17648 addr_size = reader.cu->header.addr_size;
17649 }
17650
17651 return read_addr_index_1 (per_objfile, addr_index, addr_base, addr_size);
17652}
17653
17654/* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
17655 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
17656 DWO file. */
17657
17658static const char *
17660 struct dwarf2_section_info *str_section,
17661 struct dwarf2_section_info *str_offsets_section,
17662 ULONGEST str_offsets_base, ULONGEST str_index,
17663 unsigned offset_size)
17664{
17666 struct objfile *objfile = per_objfile->objfile;
17667 const char *objf_name = objfile_name (objfile);
17668 bfd *abfd = objfile->obfd.get ();
17669 const gdb_byte *info_ptr;
17670 ULONGEST str_offset;
17671 static const char form_name[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
17672
17673 str_section->read (objfile);
17674 str_offsets_section->read (objfile);
17675 if (str_section->buffer == NULL)
17676 error (_("%s used without %s section"
17677 " in CU at offset %s [in module %s]"),
17678 form_name, str_section->get_name (),
17679 sect_offset_str (cu->header.sect_off), objf_name);
17680 if (str_offsets_section->buffer == NULL)
17681 error (_("%s used without %s section"
17682 " in CU at offset %s [in module %s]"),
17683 form_name, str_section->get_name (),
17684 sect_offset_str (cu->header.sect_off), objf_name);
17685 info_ptr = (str_offsets_section->buffer
17686 + str_offsets_base
17687 + str_index * offset_size);
17688 if (offset_size == 4)
17689 str_offset = bfd_get_32 (abfd, info_ptr);
17690 else
17691 str_offset = bfd_get_64 (abfd, info_ptr);
17692 if (str_offset >= str_section->size)
17693 error (_("Offset from %s pointing outside of"
17694 " .debug_str.dwo section in CU at offset %s [in module %s]"),
17695 form_name, sect_offset_str (cu->header.sect_off), objf_name);
17696 return (const char *) (str_section->buffer + str_offset);
17697}
17698
17699/* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
17700
17701static const char *
17702read_dwo_str_index (const struct die_reader_specs *reader, ULONGEST str_index)
17703{
17704 unsigned offset_size;
17705 ULONGEST str_offsets_base;
17706 if (reader->cu->header.version >= 5)
17707 {
17708 /* We have a DWARF5 CU with a reference to a .debug_str_offsets section,
17709 so assume the .debug_str_offsets section is DWARF5 as well, and
17710 parse the header. FIXME: Parse the header only once. */
17711 unsigned int bytes_read = 0;
17712 bfd *abfd = reader->dwo_file->sections.str_offsets.get_bfd_owner ();
17713 const gdb_byte *p = reader->dwo_file->sections.str_offsets.buffer;
17714
17715 /* Header: Initial length. */
17716 read_initial_length (abfd, p + bytes_read, &bytes_read);
17717
17718 /* Determine offset_size based on the .debug_str_offsets header. */
17719 const bool dwarf5_is_dwarf64 = bytes_read != 4;
17720 offset_size = dwarf5_is_dwarf64 ? 8 : 4;
17721
17722 /* Header: Version. */
17723 unsigned version = read_2_bytes (abfd, p + bytes_read);
17724 bytes_read += 2;
17725
17726 if (version <= 4)
17727 {
17728 /* We'd like one warning here about ignoring the section, but
17729 because we parse the header more than once (see FIXME above)
17730 we'd have many warnings, so use a complaint instead, which at
17731 least has a limit. */
17732 complaint (_("Section .debug_str_offsets in %s has unsupported"
17733 " version %d, use empty string."),
17734 reader->dwo_file->dwo_name, version);
17735 return "";
17736 }
17737
17738 /* Header: Padding. */
17739 bytes_read += 2;
17740
17741 str_offsets_base = bytes_read;
17742 }
17743 else
17744 {
17745 /* We have a pre-DWARF5 CU with a reference to a .debug_str_offsets
17746 section, assume the .debug_str_offsets section is pre-DWARF5 as
17747 well, which doesn't have a header. */
17748 str_offsets_base = 0;
17749
17750 /* Determine offset_size based on the .debug_info header. */
17751 offset_size = reader->cu->header.offset_size;
17752 }
17753
17754 return read_str_index (reader->cu,
17755 &reader->dwo_file->sections.str,
17756 &reader->dwo_file->sections.str_offsets,
17757 str_offsets_base, str_index, offset_size);
17758}
17759
17760/* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
17761
17762static const char *
17763read_stub_str_index (struct dwarf2_cu *cu, ULONGEST str_index)
17764{
17765 struct objfile *objfile = cu->per_objfile->objfile;
17766 const char *objf_name = objfile_name (objfile);
17767 static const char form_name[] = "DW_FORM_GNU_str_index";
17768 static const char str_offsets_attr_name[] = "DW_AT_str_offsets";
17769
17770 if (!cu->str_offsets_base.has_value ())
17771 error (_("%s used in Fission stub without %s"
17772 " in CU at offset 0x%lx [in module %s]"),
17773 form_name, str_offsets_attr_name,
17774 (long) cu->header.offset_size, objf_name);
17775
17776 return read_str_index (cu,
17777 &cu->per_objfile->per_bfd->str,
17779 *cu->str_offsets_base, str_index,
17780 cu->header.offset_size);
17781}
17782
17783/* Return the length of an LEB128 number in BUF. */
17784
17785static int
17786leb128_size (const gdb_byte *buf)
17787{
17788 const gdb_byte *begin = buf;
17789 gdb_byte byte;
17790
17791 while (1)
17792 {
17793 byte = *buf++;
17794 if ((byte & 128) == 0)
17795 return buf - begin;
17796 }
17797}
17798
17799static enum language
17801{
17802 enum language language;
17803
17804 switch (lang)
17805 {
17806 case DW_LANG_C89:
17807 case DW_LANG_C99:
17808 case DW_LANG_C11:
17809 case DW_LANG_C:
17810 case DW_LANG_UPC:
17812 break;
17813 case DW_LANG_Java:
17814 case DW_LANG_C_plus_plus:
17815 case DW_LANG_C_plus_plus_11:
17816 case DW_LANG_C_plus_plus_14:
17818 break;
17819 case DW_LANG_D:
17821 break;
17822 case DW_LANG_Fortran77:
17823 case DW_LANG_Fortran90:
17824 case DW_LANG_Fortran95:
17825 case DW_LANG_Fortran03:
17826 case DW_LANG_Fortran08:
17828 break;
17829 case DW_LANG_Go:
17831 break;
17832 case DW_LANG_Mips_Assembler:
17834 break;
17835 case DW_LANG_Ada83:
17836 case DW_LANG_Ada95:
17838 break;
17839 case DW_LANG_Modula2:
17841 break;
17842 case DW_LANG_Pascal83:
17844 break;
17845 case DW_LANG_ObjC:
17847 break;
17848 case DW_LANG_Rust:
17849 case DW_LANG_Rust_old:
17851 break;
17852 case DW_LANG_OpenCL:
17854 break;
17855 case DW_LANG_Cobol74:
17856 case DW_LANG_Cobol85:
17857 default:
17859 break;
17860 }
17861
17862 return language;
17863}
17864
17865/* Return the named attribute or NULL if not there. */
17866
17867static struct attribute *
17868dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
17869{
17870 for (;;)
17871 {
17872 unsigned int i;
17873 struct attribute *spec = NULL;
17874
17875 for (i = 0; i < die->num_attrs; ++i)
17876 {
17877 if (die->attrs[i].name == name)
17878 return &die->attrs[i];
17879 if (die->attrs[i].name == DW_AT_specification
17880 || die->attrs[i].name == DW_AT_abstract_origin)
17881 spec = &die->attrs[i];
17882 }
17883
17884 if (!spec)
17885 break;
17886
17887 struct die_info *prev_die = die;
17888 die = follow_die_ref (die, spec, &cu);
17889 if (die == prev_die)
17890 /* Self-reference, we're done. */
17891 break;
17892 }
17893
17894 return NULL;
17895}
17896
17897/* Return the string associated with a string-typed attribute, or NULL if it
17898 is either not found or is of an incorrect type. */
17899
17900static const char *
17901dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
17902{
17903 struct attribute *attr;
17904 const char *str = NULL;
17905
17906 attr = dwarf2_attr (die, name, cu);
17907
17908 if (attr != NULL)
17909 {
17910 str = attr->as_string ();
17911 if (str == nullptr)
17912 complaint (_("string type expected for attribute %s for "
17913 "DIE at %s in module %s"),
17916 }
17917
17918 return str;
17919}
17920
17921/* Return the dwo name or NULL if not present. If present, it is in either
17922 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
17923static const char *
17924dwarf2_dwo_name (struct die_info *die, struct dwarf2_cu *cu)
17925{
17926 const char *dwo_name = dwarf2_string_attr (die, DW_AT_GNU_dwo_name, cu);
17927 if (dwo_name == nullptr)
17928 dwo_name = dwarf2_string_attr (die, DW_AT_dwo_name, cu);
17929 return dwo_name;
17930}
17931
17932/* Return non-zero iff the attribute NAME is defined for the given DIE,
17933 and holds a non-zero value. This function should only be used for
17934 DW_FORM_flag or DW_FORM_flag_present attributes. */
17935
17936static int
17937dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
17938{
17939 struct attribute *attr = dwarf2_attr (die, name, cu);
17940
17941 return attr != nullptr && attr->as_boolean ();
17942}
17943
17944static int
17945die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
17946{
17947 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17948 which value is non-zero. However, we have to be careful with
17949 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17950 (via dwarf2_flag_true_p) follows this attribute. So we may
17951 end up accidently finding a declaration attribute that belongs
17952 to a different DIE referenced by the specification attribute,
17953 even though the given DIE does not have a declaration attribute. */
17954 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
17955 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
17956}
17957
17958/* Return the die giving the specification for DIE, if there is
17959 one. *SPEC_CU is the CU containing DIE on input, and the CU
17960 containing the return value on output. If there is no
17961 specification, but there is an abstract origin, that is
17962 returned. */
17963
17964static struct die_info *
17965die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
17966{
17967 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
17968 *spec_cu);
17969
17970 if (spec_attr == NULL)
17971 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
17972
17973 if (spec_attr == NULL)
17974 return NULL;
17975 else
17976 return follow_die_ref (die, spec_attr, spec_cu);
17977}
17978
17979/* A convenience function to find the proper .debug_line section for a CU. */
17980
17981static struct dwarf2_section_info *
17983{
17985 dwarf2_per_objfile *per_objfile = cu->per_objfile;
17986
17987 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17988 DWO file. */
17989 if (cu->dwo_unit && cu->per_cu->is_debug_types)
17990 section = &cu->dwo_unit->dwo_file->sections.line;
17991 else if (cu->per_cu->is_dwz)
17992 {
17993 dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd, true);
17994
17995 section = &dwz->line;
17996 }
17997 else
17998 section = &per_objfile->per_bfd->line;
17999
18000 return section;
18001}
18002
18003/* Read the statement program header starting at OFFSET in
18004 .debug_line, or .debug_line.dwo. Return a pointer
18005 to a struct line_header, allocated using xmalloc.
18006 Returns NULL if there is a problem reading the header, e.g., if it
18007 has a version we don't understand.
18008
18009 NOTE: the strings in the include directory and file name tables of
18010 the returned object point into the dwarf line section buffer,
18011 and must not be freed. */
18012
18013static line_header_up
18014dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu,
18015 const char *comp_dir)
18016{
18018 dwarf2_per_objfile *per_objfile = cu->per_objfile;
18019
18021 section->read (per_objfile->objfile);
18022 if (section->buffer == NULL)
18023 {
18024 if (cu->dwo_unit && cu->per_cu->is_debug_types)
18025 complaint (_("missing .debug_line.dwo section"));
18026 else
18027 complaint (_("missing .debug_line section"));
18028 return 0;
18029 }
18030
18031 return dwarf_decode_line_header (sect_off, cu->per_cu->is_dwz,
18032 per_objfile, section, &cu->header,
18033 comp_dir);
18034}
18035
18036/* Subroutine of dwarf_decode_lines to simplify it.
18037 Return the file name for the given file_entry.
18038 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
18039 If space for the result is malloc'd, *NAME_HOLDER will be set.
18040 Returns NULL if FILE_INDEX should be ignored, i.e., it is
18041 equivalent to CU_INFO. */
18042
18043static const char *
18045 const file_and_directory &cu_info,
18046 std::string &name_holder)
18047{
18048 const char *include_name = fe.name;
18049 const char *include_name_to_compare = include_name;
18050
18051 const char *dir_name = fe.include_dir (lh);
18052
18053 std::string hold_compare;
18054 if (!IS_ABSOLUTE_PATH (include_name)
18055 && (dir_name != nullptr || cu_info.get_comp_dir () != nullptr))
18056 {
18057 /* Avoid creating a duplicate name for CU_INFO.
18058 We do this by comparing INCLUDE_NAME and CU_INFO.
18059 Before we do the comparison, however, we need to account
18060 for DIR_NAME and COMP_DIR.
18061 First prepend dir_name (if non-NULL). If we still don't
18062 have an absolute path prepend comp_dir (if non-NULL).
18063 However, the directory we record in the include-file's
18064 psymtab does not contain COMP_DIR (to match the
18065 corresponding symtab(s)).
18066
18067 Example:
18068
18069 bash$ cd /tmp
18070 bash$ gcc -g ./hello.c
18071 include_name = "hello.c"
18072 dir_name = "."
18073 DW_AT_comp_dir = comp_dir = "/tmp"
18074 DW_AT_name = "./hello.c"
18075
18076 */
18077
18078 if (dir_name != NULL)
18079 {
18080 name_holder = path_join (dir_name, include_name);
18081 include_name = name_holder.c_str ();
18082 include_name_to_compare = include_name;
18083 }
18084 if (!IS_ABSOLUTE_PATH (include_name)
18085 && cu_info.get_comp_dir () != nullptr)
18086 {
18087 hold_compare = path_join (cu_info.get_comp_dir (), include_name);
18088 include_name_to_compare = hold_compare.c_str ();
18089 }
18090 }
18091
18092 std::string copied_name;
18093 const char *cu_filename = cu_info.get_name ();
18094 if (!IS_ABSOLUTE_PATH (cu_filename) && cu_info.get_comp_dir () != nullptr)
18095 {
18096 copied_name = path_join (cu_info.get_comp_dir (), cu_filename);
18097 cu_filename = copied_name.c_str ();
18098 }
18099
18100 if (FILENAME_CMP (include_name_to_compare, cu_filename) == 0)
18101 return nullptr;
18102 return include_name;
18103}
18104
18105/* State machine to track the state of the line number program. */
18106
18108{
18109public:
18110 /* Initialize a machine state for the start of a line number
18111 program. */
18112 lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch, line_header *lh);
18113
18115 {
18116 /* lh->file_names is 0-based, but the file name numbers in the
18117 statement program are 1-based. */
18119 }
18120
18121 /* Record the line in the state machine. END_SEQUENCE is true if
18122 we're processing the end of a sequence. */
18123 void record_line (bool end_sequence);
18124
18125 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
18126 nop-out rest of the lines in this sequence. */
18127 void check_line_address (struct dwarf2_cu *cu,
18128 const gdb_byte *line_ptr,
18129 unrelocated_addr unrelocated_lowpc,
18130 unrelocated_addr address);
18131
18132 void handle_set_discriminator (unsigned int discriminator)
18133 {
18134 m_discriminator = discriminator;
18135 m_line_has_non_zero_discriminator |= discriminator != 0;
18136 }
18137
18138 /* Handle DW_LNE_set_address. */
18139 void handle_set_address (unrelocated_addr address)
18140 {
18141 m_op_index = 0;
18142 m_address
18143 = (unrelocated_addr) gdbarch_adjust_dwarf2_line (m_gdbarch,
18144 (CORE_ADDR) address,
18145 false);
18146 }
18147
18148 /* Handle DW_LNS_advance_pc. */
18149 void handle_advance_pc (CORE_ADDR adjust);
18150
18151 /* Handle a special opcode. */
18152 void handle_special_opcode (unsigned char op_code);
18153
18154 /* Handle DW_LNS_advance_line. */
18155 void handle_advance_line (int line_delta)
18156 {
18157 advance_line (line_delta);
18158 }
18159
18160 /* Handle DW_LNS_set_file. */
18161 void handle_set_file (file_name_index file);
18162
18163 /* Handle DW_LNS_negate_stmt. */
18165 {
18167 }
18168
18169 /* Handle DW_LNS_const_add_pc. */
18170 void handle_const_add_pc ();
18171
18172 /* Handle DW_LNS_fixed_advance_pc. */
18173 void handle_fixed_advance_pc (CORE_ADDR addr_adj)
18174 {
18175 addr_adj = gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
18176 m_address = (unrelocated_addr) ((CORE_ADDR) m_address + addr_adj);
18177 m_op_index = 0;
18178 }
18179
18180 /* Handle DW_LNS_copy. */
18182 {
18183 record_line (false);
18184 m_discriminator = 0;
18185 m_flags &= ~LEF_PROLOGUE_END;
18186 }
18187
18188 /* Handle DW_LNE_end_sequence. */
18190 {
18192 }
18193
18194 /* Handle DW_LNS_set_prologue_end. */
18196 {
18198 }
18199
18200private:
18201 /* Advance the line by LINE_DELTA. */
18202 void advance_line (int line_delta)
18203 {
18204 m_line += line_delta;
18205
18206 if (line_delta != 0)
18208 }
18209
18211
18213
18214 /* The line number header. */
18216
18217 /* These are part of the standard DWARF line number state machine,
18218 and initialized according to the DWARF spec. */
18219
18220 unsigned char m_op_index = 0;
18221 /* The line table index of the current file. */
18223 unsigned int m_line = 1;
18224
18225 /* These are initialized in the constructor. */
18226
18227 unrelocated_addr m_address;
18228 linetable_entry_flags m_flags;
18229 unsigned int m_discriminator = 0;
18230
18231 /* Additional bits of state we need to track. */
18232
18233 /* The last file that we called dwarf2_start_subfile for.
18234 This is only used for TLLs. */
18235 unsigned int m_last_file = 0;
18236 /* The last file a line number was recorded for. */
18237 struct subfile *m_last_subfile = NULL;
18238
18239 /* The address of the last line entry. */
18240 unrelocated_addr m_last_address;
18241
18242 /* Set to true when a previous line at the same address (using
18243 m_last_address) had LEF_IS_STMT set in m_flags. This is reset to false
18244 when a line entry at a new address (m_address different to
18245 m_last_address) is processed. */
18246 bool m_stmt_at_address = false;
18247
18248 /* When true, record the lines we decode. */
18250
18251 /* The last line number that was recorded, used to coalesce
18252 consecutive entries for the same line. This can happen, for
18253 example, when discriminators are present. PR 17276. */
18254 unsigned int m_last_line = 0;
18256};
18257
18258void
18260{
18261 CORE_ADDR addr_adj = (((m_op_index + adjust)
18264 addr_adj = gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
18265 m_address = (unrelocated_addr) ((CORE_ADDR) m_address + addr_adj);
18266 m_op_index = ((m_op_index + adjust)
18268}
18269
18270void
18272{
18273 unsigned char adj_opcode = op_code - m_line_header->opcode_base;
18274 unsigned char adj_opcode_d = adj_opcode / m_line_header->line_range;
18275 unsigned char adj_opcode_r = adj_opcode % m_line_header->line_range;
18276 CORE_ADDR addr_adj = (((m_op_index + adj_opcode_d)
18279 addr_adj = gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
18280 m_address = (unrelocated_addr) ((CORE_ADDR) m_address + addr_adj);
18281 m_op_index = ((m_op_index + adj_opcode_d)
18283
18284 int line_delta = m_line_header->line_base + adj_opcode_r;
18285 advance_line (line_delta);
18286 record_line (false);
18287 m_discriminator = 0;
18288 m_flags &= ~LEF_PROLOGUE_END;
18289}
18290
18291void
18293{
18294 m_file = file;
18295
18296 const file_entry *fe = current_file ();
18297 if (fe == NULL)
18299 else
18300 {
18304 }
18305}
18306
18307void
18309{
18310 CORE_ADDR adjust
18312
18313 CORE_ADDR addr_adj
18314 = (((m_op_index + adjust)
18317
18318 addr_adj = gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true);
18319 m_address = (unrelocated_addr) ((CORE_ADDR) m_address + addr_adj);
18320 m_op_index = ((m_op_index + adjust)
18322}
18323
18324/* Return non-zero if we should add LINE to the line number table.
18325 LINE is the line to add, LAST_LINE is the last line that was added,
18326 LAST_SUBFILE is the subfile for LAST_LINE.
18327 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18328 had a non-zero discriminator.
18329
18330 We have to be careful in the presence of discriminators.
18331 E.g., for this line:
18332
18333 for (i = 0; i < 100000; i++);
18334
18335 clang can emit four line number entries for that one line,
18336 each with a different discriminator.
18337 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
18338
18339 However, we want gdb to coalesce all four entries into one.
18340 Otherwise the user could stepi into the middle of the line and
18341 gdb would get confused about whether the pc really was in the
18342 middle of the line.
18343
18344 Things are further complicated by the fact that two consecutive
18345 line number entries for the same line is a heuristic used by gcc
18346 to denote the end of the prologue. So we can't just discard duplicate
18347 entries, we have to be selective about it. The heuristic we use is
18348 that we only collapse consecutive entries for the same line if at least
18349 one of those entries has a non-zero discriminator. PR 17276.
18350
18351 Note: Addresses in the line number state machine can never go backwards
18352 within one sequence, thus this coalescing is ok. */
18353
18354static int
18356 unsigned int line, unsigned int last_line,
18357 int line_has_non_zero_discriminator,
18358 struct subfile *last_subfile)
18359{
18360 if (cu->get_builder ()->get_current_subfile () != last_subfile)
18361 return 1;
18362 if (line != last_line)
18363 return 1;
18364 /* Same line for the same file that we've seen already.
18365 As a last check, for pr 17276, only record the line if the line
18366 has never had a non-zero discriminator. */
18367 if (!line_has_non_zero_discriminator)
18368 return 1;
18369 return 0;
18370}
18371
18372/* Use the CU's builder to record line number LINE beginning at
18373 address ADDRESS in the line table of subfile SUBFILE. */
18374
18375static void
18377 unsigned int line, unrelocated_addr address,
18378 linetable_entry_flags flags,
18379 struct dwarf2_cu *cu)
18380{
18381 unrelocated_addr addr
18382 = unrelocated_addr (gdbarch_addr_bits_remove (gdbarch,
18383 (CORE_ADDR) address));
18384
18385 if (dwarf_line_debug)
18386 {
18388 "Recording line %u, file %s, address %s\n",
18389 line, lbasename (subfile->name.c_str ()),
18390 paddress (gdbarch, (CORE_ADDR) address));
18391 }
18392
18393 if (cu != nullptr)
18394 cu->get_builder ()->record_line (subfile, line, addr, flags);
18395}
18396
18397/* Subroutine of dwarf_decode_lines_1 to simplify it.
18398 Mark the end of a set of line number records.
18399 The arguments are the same as for dwarf_record_line_1.
18400 If SUBFILE is NULL the request is ignored. */
18401
18402static void
18404 unrelocated_addr address, struct dwarf2_cu *cu)
18405{
18406 if (subfile == NULL)
18407 return;
18408
18409 if (dwarf_line_debug)
18410 {
18412 "Finishing current line, file %s, address %s\n",
18413 lbasename (subfile->name.c_str ()),
18414 paddress (gdbarch, (CORE_ADDR) address));
18415 }
18416
18417 dwarf_record_line_1 (gdbarch, subfile, 0, address, LEF_IS_STMT, cu);
18418}
18419
18420void
18422{
18423 if (dwarf_line_debug)
18424 {
18426 "Processing actual line %u: file %u,"
18427 " address %s, is_stmt %u, prologue_end %u, discrim %u%s\n",
18428 m_line, m_file,
18429 paddress (m_gdbarch, (CORE_ADDR) m_address),
18430 (m_flags & LEF_IS_STMT) != 0,
18431 (m_flags & LEF_PROLOGUE_END) != 0,
18433 (end_sequence ? "\t(end sequence)" : ""));
18434 }
18435
18436 file_entry *fe = current_file ();
18437
18438 if (fe == NULL)
18440 /* For now we ignore lines not starting on an instruction boundary.
18441 But not when processing end_sequence for compatibility with the
18442 previous version of the code. */
18443 else if (m_op_index == 0 || end_sequence)
18444 {
18445 /* When we switch files we insert an end maker in the first file,
18446 switch to the second file and add a new line entry. The
18447 problem is that the end marker inserted in the first file will
18448 discard any previous line entries at the same address. If the
18449 line entries in the first file are marked as is-stmt, while
18450 the new line in the second file is non-stmt, then this means
18451 the end marker will discard is-stmt lines so we can have a
18452 non-stmt line. This means that there are less addresses at
18453 which the user can insert a breakpoint.
18454
18455 To improve this we track the last address in m_last_address,
18456 and whether we have seen an is-stmt at this address. Then
18457 when switching files, if we have seen a stmt at the current
18458 address, and we are switching to create a non-stmt line, then
18459 discard the new line. */
18460 bool file_changed
18462 bool ignore_this_line
18463 = ((file_changed && !end_sequence && m_last_address == m_address
18464 && ((m_flags & LEF_IS_STMT) == 0)
18466 || (!end_sequence && m_line == 0));
18467
18468 if ((file_changed && !ignore_this_line) || end_sequence)
18469 {
18471 m_currently_recording_lines ? m_cu : nullptr);
18472 }
18473
18474 if (!end_sequence && !ignore_this_line)
18475 {
18476 linetable_entry_flags lte_flags = m_flags;
18478 lte_flags |= LEF_IS_STMT;
18479
18483 {
18484 buildsym_compunit *builder = m_cu->get_builder ();
18486 builder->get_current_subfile (),
18487 m_line, m_address, lte_flags,
18488 m_currently_recording_lines ? m_cu : nullptr);
18489 }
18492 }
18493 }
18494
18495 /* Track whether we have seen any IS_STMT true at m_address in case we
18496 have multiple line table entries all at m_address. */
18498 {
18499 m_stmt_at_address = false;
18501 }
18503}
18504
18506 line_header *lh)
18507 : m_cu (cu),
18508 m_gdbarch (arch),
18509 m_line_header (lh),
18510 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as
18511 if there was a line entry for it so that the backend has a
18512 chance to adjust it and also record it in case it needs it.
18513 This is currently used by MIPS code,
18514 cf. `mips_adjust_dwarf2_line'. */
18515 m_address ((unrelocated_addr) gdbarch_adjust_dwarf2_line (arch, 0, 0)),
18516 m_flags (lh->default_is_stmt ? LEF_IS_STMT : (linetable_entry_flags) 0),
18517 m_last_address (m_address)
18518{
18519}
18520
18521void
18523 const gdb_byte *line_ptr,
18524 unrelocated_addr unrelocated_lowpc,
18525 unrelocated_addr address)
18526{
18527 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
18528 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
18529 located at 0x0. In this case, additionally check that if
18530 ADDRESS < UNRELOCATED_LOWPC. */
18531
18532 if ((address == (unrelocated_addr) 0 && address < unrelocated_lowpc)
18533 || address == (unrelocated_addr) -1)
18534 {
18535 /* This line table is for a function which has been
18536 GCd by the linker. Ignore it. PR gdb/12528 */
18537
18538 struct objfile *objfile = cu->per_objfile->objfile;
18539 long line_offset = line_ptr - get_debug_line_section (cu)->buffer;
18540
18541 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
18544 /* Note: m_currently_recording_lines is left as false until we see
18545 DW_LNE_end_sequence. */
18546 }
18547}
18548
18549/* Subroutine of dwarf_decode_lines to simplify it.
18550 Process the line number information in LH. */
18551
18552static void
18554 unrelocated_addr lowpc)
18555{
18556 const gdb_byte *line_ptr, *extended_end;
18557 const gdb_byte *line_end;
18558 unsigned int bytes_read, extended_len;
18559 unsigned char op_code, extended_op;
18560 struct objfile *objfile = cu->per_objfile->objfile;
18561 bfd *abfd = objfile->obfd.get ();
18562 struct gdbarch *gdbarch = objfile->arch ();
18563
18564 line_ptr = lh->statement_program_start;
18565 line_end = lh->statement_program_end;
18566
18567 /* Read the statement sequences until there's nothing left. */
18568 while (line_ptr < line_end)
18569 {
18570 /* The DWARF line number program state machine. Reset the state
18571 machine at the start of each sequence. */
18572 lnp_state_machine state_machine (cu, gdbarch, lh);
18573 bool end_sequence = false;
18574
18575 /* Start a subfile for the current file of the state
18576 machine. */
18577 const file_entry *fe = state_machine.current_file ();
18578
18579 if (fe != NULL)
18580 dwarf2_start_subfile (cu, *fe, *lh);
18581
18582 /* Decode the table. */
18583 while (line_ptr < line_end && !end_sequence)
18584 {
18585 op_code = read_1_byte (abfd, line_ptr);
18586 line_ptr += 1;
18587
18588 if (op_code >= lh->opcode_base)
18589 {
18590 /* Special opcode. */
18591 state_machine.handle_special_opcode (op_code);
18592 }
18593 else switch (op_code)
18594 {
18595 case DW_LNS_extended_op:
18596 extended_len = read_unsigned_leb128 (abfd, line_ptr,
18597 &bytes_read);
18598 line_ptr += bytes_read;
18599 extended_end = line_ptr + extended_len;
18600 extended_op = read_1_byte (abfd, line_ptr);
18601 line_ptr += 1;
18602 if (DW_LNE_lo_user <= extended_op
18603 && extended_op <= DW_LNE_hi_user)
18604 {
18605 /* Vendor extension, ignore. */
18606 line_ptr = extended_end;
18607 break;
18608 }
18609 switch (extended_op)
18610 {
18611 case DW_LNE_end_sequence:
18612 state_machine.handle_end_sequence ();
18613 end_sequence = true;
18614 break;
18615 case DW_LNE_set_address:
18616 {
18617 unrelocated_addr address
18618 = cu->header.read_address (abfd, line_ptr, &bytes_read);
18619 line_ptr += bytes_read;
18620
18621 state_machine.check_line_address (cu, line_ptr, lowpc,
18622 address);
18623 state_machine.handle_set_address (address);
18624 }
18625 break;
18626 case DW_LNE_define_file:
18627 {
18628 const char *cur_file;
18629 unsigned int mod_time, length;
18630 dir_index dindex;
18631
18632 cur_file = read_direct_string (abfd, line_ptr,
18633 &bytes_read);
18634 line_ptr += bytes_read;
18635 dindex = (dir_index)
18636 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
18637 line_ptr += bytes_read;
18638 mod_time =
18639 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
18640 line_ptr += bytes_read;
18641 length =
18642 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
18643 line_ptr += bytes_read;
18644 lh->add_file_name (cur_file, dindex, mod_time, length);
18645 }
18646 break;
18647 case DW_LNE_set_discriminator:
18648 {
18649 /* The discriminator is not interesting to the
18650 debugger; just ignore it. We still need to
18651 check its value though:
18652 if there are consecutive entries for the same
18653 (non-prologue) line we want to coalesce them.
18654 PR 17276. */
18655 unsigned int discr
18656 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
18657 line_ptr += bytes_read;
18658
18659 state_machine.handle_set_discriminator (discr);
18660 }
18661 break;
18662 default:
18663 complaint (_("mangled .debug_line section"));
18664 return;
18665 }
18666 /* Make sure that we parsed the extended op correctly. If e.g.
18667 we expected a different address size than the producer used,
18668 we may have read the wrong number of bytes. */
18669 if (line_ptr != extended_end)
18670 {
18671 complaint (_("mangled .debug_line section"));
18672 return;
18673 }
18674 break;
18675 case DW_LNS_copy:
18676 state_machine.handle_copy ();
18677 break;
18678 case DW_LNS_advance_pc:
18679 {
18680 CORE_ADDR adjust
18681 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
18682 line_ptr += bytes_read;
18683
18684 state_machine.handle_advance_pc (adjust);
18685 }
18686 break;
18687 case DW_LNS_advance_line:
18688 {
18689 int line_delta
18690 = read_signed_leb128 (abfd, line_ptr, &bytes_read);
18691 line_ptr += bytes_read;
18692
18693 state_machine.handle_advance_line (line_delta);
18694 }
18695 break;
18696 case DW_LNS_set_file:
18697 {
18698 file_name_index file
18699 = (file_name_index) read_unsigned_leb128 (abfd, line_ptr,
18700 &bytes_read);
18701 line_ptr += bytes_read;
18702
18703 state_machine.handle_set_file (file);
18704 }
18705 break;
18706 case DW_LNS_set_column:
18707 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
18708 line_ptr += bytes_read;
18709 break;
18710 case DW_LNS_negate_stmt:
18711 state_machine.handle_negate_stmt ();
18712 break;
18713 case DW_LNS_set_basic_block:
18714 break;
18715 /* Add to the address register of the state machine the
18716 address increment value corresponding to special opcode
18717 255. I.e., this value is scaled by the minimum
18718 instruction length since special opcode 255 would have
18719 scaled the increment. */
18720 case DW_LNS_const_add_pc:
18721 state_machine.handle_const_add_pc ();
18722 break;
18723 case DW_LNS_fixed_advance_pc:
18724 {
18725 CORE_ADDR addr_adj = read_2_bytes (abfd, line_ptr);
18726 line_ptr += 2;
18727
18728 state_machine.handle_fixed_advance_pc (addr_adj);
18729 }
18730 break;
18731 case DW_LNS_set_prologue_end:
18732 state_machine.handle_set_prologue_end ();
18733 break;
18734 default:
18735 {
18736 /* Unknown standard opcode, ignore it. */
18737 int i;
18738
18739 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
18740 {
18741 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
18742 line_ptr += bytes_read;
18743 }
18744 }
18745 }
18746 }
18747
18748 if (!end_sequence)
18750
18751 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18752 in which case we still finish recording the last line). */
18753 state_machine.record_line (true);
18754 }
18755}
18756
18757/* Decode the Line Number Program (LNP) for the given line_header
18758 structure and CU. The actual information extracted and the type
18759 of structures created from the LNP depends on the value of PST.
18760
18761 FND holds the CU file name and directory, if known.
18762 It is used for relative paths in the line table.
18763
18764 NOTE: It is important that psymtabs have the same file name (via
18765 strcmp) as the corresponding symtab. Since the directory is not
18766 used in the name of the symtab we don't use it in the name of the
18767 psymtabs we create. E.g. expand_line_sal requires this when
18768 finding psymtabs to expand. A good testcase for this is
18769 mb-inline.exp.
18770
18771 LOWPC is the lowest address in CU (or 0 if not known).
18772
18773 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18774 for its PC<->lines mapping information. Otherwise only the filename
18775 table is read in. */
18776
18777static void
18779 unrelocated_addr lowpc, int decode_mapping)
18780{
18781 if (decode_mapping)
18782 dwarf_decode_lines_1 (lh, cu, lowpc);
18783
18784 /* Make sure a symtab is created for every file, even files
18785 which contain only variables (i.e. no code with associated
18786 line numbers). */
18787 buildsym_compunit *builder = cu->get_builder ();
18788 struct compunit_symtab *cust = builder->get_compunit_symtab ();
18789
18790 for (auto &fe : lh->file_names ())
18791 {
18792 dwarf2_start_subfile (cu, fe, *lh);
18793 subfile *sf = builder->get_current_subfile ();
18794
18795 if (sf->symtab == nullptr)
18796 sf->symtab = allocate_symtab (cust, sf->name.c_str (),
18797 sf->name_for_id.c_str ());
18798
18799 fe.symtab = sf->symtab;
18800 }
18801}
18802
18803/* Start a subfile for DWARF. FILENAME is the name of the file and
18804 DIRNAME the name of the source directory which contains FILENAME
18805 or NULL if not known.
18806 This routine tries to keep line numbers from identical absolute and
18807 relative file names in a common subfile.
18808
18809 Using the `list' example from the GDB testsuite, which resides in
18810 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18811 of /srcdir/list0.c yields the following debugging information for list0.c:
18812
18813 DW_AT_name: /srcdir/list0.c
18814 DW_AT_comp_dir: /compdir
18815 files.files[0].name: list0.h
18816 files.files[0].dir: /srcdir
18817 files.files[1].name: list0.c
18818 files.files[1].dir: /srcdir
18819
18820 The line number information for list0.c has to end up in a single
18821 subfile, so that `break /srcdir/list0.c:1' works as expected.
18822 start_subfile will ensure that this happens provided that we pass the
18823 concatenation of files.files[1].dir and files.files[1].name as the
18824 subfile's name. */
18825
18826static void
18828 const line_header &lh)
18829{
18830 std::string filename_holder;
18831 const char *filename = fe.name;
18832 const char *dirname = lh.include_dir_at (fe.d_index);
18833
18834 /* In order not to lose the line information directory,
18835 we concatenate it to the filename when it makes sense.
18836 Note that the Dwarf3 standard says (speaking of filenames in line
18837 information): ``The directory index is ignored for file names
18838 that represent full path names''. Thus ignoring dirname in the
18839 `else' branch below isn't an issue. */
18840
18841 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
18842 {
18843 filename_holder = path_join (dirname, filename);
18844 filename = filename_holder.c_str ();
18845 }
18846
18847 std::string filename_for_id = lh.file_file_name (fe);
18848 cu->get_builder ()->start_subfile (filename, filename_for_id.c_str ());
18849}
18850
18851static void
18852var_decode_location (struct attribute *attr, struct symbol *sym,
18853 struct dwarf2_cu *cu)
18854{
18855 struct objfile *objfile = cu->per_objfile->objfile;
18856 struct comp_unit_head *cu_header = &cu->header;
18857
18858 /* NOTE drow/2003-01-30: There used to be a comment and some special
18859 code here to turn a symbol with DW_AT_external and a
18860 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18861 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18862 with some versions of binutils) where shared libraries could have
18863 relocations against symbols in their debug information - the
18864 minimal symbol would have the right address, but the debug info
18865 would not. It's no longer necessary, because we will explicitly
18866 apply relocations when we read in the debug information now. */
18867
18868 /* A DW_AT_location attribute with no contents indicates that a
18869 variable has been optimized away. */
18870 if (attr->form_is_block () && attr->as_block ()->size == 0)
18871 {
18873 return;
18874 }
18875
18876 /* Handle one degenerate form of location expression specially, to
18877 preserve GDB's previous behavior when section offsets are
18878 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
18879 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
18880
18881 if (attr->form_is_block ())
18882 {
18883 struct dwarf_block *block = attr->as_block ();
18884
18885 if ((block->data[0] == DW_OP_addr
18886 && block->size == 1 + cu_header->addr_size)
18887 || ((block->data[0] == DW_OP_GNU_addr_index
18888 || block->data[0] == DW_OP_addrx)
18889 && (block->size
18890 == 1 + leb128_size (&block->data[1]))))
18891 {
18892 unsigned int dummy;
18893
18894 unrelocated_addr tem;
18895 if (block->data[0] == DW_OP_addr)
18896 tem = cu->header.read_address (objfile->obfd.get (),
18897 block->data + 1,
18898 &dummy);
18899 else
18900 tem = read_addr_index_from_leb128 (cu, block->data + 1, &dummy);
18901 sym->set_value_address ((CORE_ADDR) tem);
18905 (sym->value_address ()
18907 return;
18908 }
18909 }
18910
18911 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18912 expression evaluator, and use LOC_COMPUTED only when necessary
18913 (i.e. when the value of a register or memory location is
18914 referenced, or a thread-local block, etc.). Then again, it might
18915 not be worthwhile. I'm assuming that it isn't unless performance
18916 or memory numbers show me otherwise. */
18917
18918 dwarf2_symbol_mark_computed (attr, sym, cu, 0);
18919
18920 if (SYMBOL_COMPUTED_OPS (sym)->location_has_loclist)
18921 cu->has_loclist = true;
18922}
18923
18924/* A helper function to add an "export" symbol. The new symbol starts
18925 as a clone of ORIG, but is modified to defer to the symbol named
18926 ORIG_NAME. The original symbol uses the name given in the source
18927 code, and the symbol that is created here uses the linkage name as
18928 its name. See ada-imported.c. */
18929
18930static void
18931add_ada_export_symbol (struct symbol *orig, const char *new_name,
18932 const char *orig_name, struct dwarf2_cu *cu,
18933 struct pending **list_to_add)
18934{
18935 struct symbol *copy
18936 = new (&cu->per_objfile->objfile->objfile_obstack) symbol (*orig);
18937 copy->set_linkage_name (new_name);
18938 SYMBOL_LOCATION_BATON (copy) = (void *) orig_name;
18939 copy->set_aclass_index (copy->aclass () == LOC_BLOCK
18942 add_symbol_to_list (copy, list_to_add);
18943}
18944
18945/* A helper function that decides if a given symbol is an Ada Pragma
18946 Import or Pragma Export. */
18947
18948static bool
18950 const char *linkagename)
18951{
18952 return (cu->lang () == language_ada
18953 && linkagename != nullptr
18954 && !streq (name, linkagename)
18955 /* The following exclusions are necessary because symbols
18956 with names or linkage names that match here will meet the
18957 other criteria but are not in fact caused by Pragma
18958 Import or Pragma Export, and applying the import/export
18959 treatment to them will introduce problems. Some of these
18960 checks only apply to functions, but it is simpler and
18961 harmless to always do them all. */
18962 && !startswith (name, "__builtin")
18963 && !startswith (linkagename, "___ghost_")
18964 && !startswith (linkagename, "__gnat")
18965 && !startswith (linkagename, "_ada_")
18966 && !streq (linkagename, "adainit"));
18967}
18968
18969/* Given a pointer to a DWARF information entry, figure out if we need
18970 to make a symbol table entry for it, and if so, create a new entry
18971 and return a pointer to it.
18972 If TYPE is NULL, determine symbol type from the die, otherwise
18973 used the passed type.
18974 If SPACE is not NULL, use it to hold the new symbol. If it is
18975 NULL, allocate a new symbol on the objfile's obstack. */
18976
18977static struct symbol *
18978new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
18979 struct symbol *space)
18980{
18981 dwarf2_per_objfile *per_objfile = cu->per_objfile;
18982 struct objfile *objfile = per_objfile->objfile;
18983 struct symbol *sym = NULL;
18984 const char *name;
18985 struct attribute *attr = NULL;
18986 struct attribute *attr2 = NULL;
18987 struct pending **list_to_add = NULL;
18988
18989 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
18990
18991 name = dwarf2_name (die, cu);
18992 if (name == nullptr && (die->tag == DW_TAG_subprogram
18993 || die->tag == DW_TAG_inlined_subroutine
18994 || die->tag == DW_TAG_entry_point))
18995 name = dw2_linkage_name (die, cu);
18996
18997 if (name)
18998 {
18999 int suppress_add = 0;
19000
19001 if (space)
19002 sym = space;
19003 else
19004 sym = new (&objfile->objfile_obstack) symbol;
19005 OBJSTAT (objfile, n_syms++);
19006
19007 /* Cache this symbol's name and the name's demangled form (if any). */
19008 sym->set_language (cu->lang (), &objfile->objfile_obstack);
19009 /* Fortran does not have mangling standard and the mangling does differ
19010 between gfortran, iFort etc. */
19011 const char *physname
19012 = (cu->lang () == language_fortran
19013 ? dwarf2_full_name (name, die, cu)
19014 : dwarf2_physname (name, die, cu));
19015 const char *linkagename = dw2_linkage_name (die, cu);
19016
19017 if (linkagename == nullptr || cu->lang () == language_ada)
19018 sym->set_linkage_name (physname);
19019 else
19020 {
19021 sym->set_demangled_name (physname, &objfile->objfile_obstack);
19022 sym->set_linkage_name (linkagename);
19023 }
19024
19025 /* Handle DW_AT_artificial. */
19026 attr = dwarf2_attr (die, DW_AT_artificial, cu);
19027 if (attr != nullptr)
19028 sym->set_is_artificial (attr->as_boolean ());
19029
19030 /* Default assumptions.
19031 Use the passed type or decode it from the die. */
19032 sym->set_domain (VAR_DOMAIN);
19034 if (type != NULL)
19035 sym->set_type (type);
19036 else
19037 sym->set_type (die_type (die, cu));
19038 attr = dwarf2_attr (die,
19039 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
19040 cu);
19041 if (attr != nullptr)
19042 sym->set_line (attr->constant_value (0));
19043
19044 attr = dwarf2_attr (die,
19045 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
19046 cu);
19047 if (attr != nullptr && attr->is_nonnegative ())
19048 {
19049 file_name_index file_index
19050 = (file_name_index) attr->as_nonnegative ();
19051 struct file_entry *fe;
19052
19053 if (cu->line_header != NULL)
19054 fe = cu->line_header->file_name_at (file_index);
19055 else
19056 fe = NULL;
19057
19058 if (fe == NULL)
19059 complaint (_("file index out of range"));
19060 else
19061 sym->set_symtab (fe->symtab);
19062 }
19063
19064 switch (die->tag)
19065 {
19066 case DW_TAG_label:
19067 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
19068 if (attr != nullptr)
19069 {
19070 CORE_ADDR addr = per_objfile->relocate (attr->as_address ());
19072 sym->set_value_address (addr);
19074 }
19075 else
19077 sym->set_type (builtin_type (objfile)->builtin_core_addr);
19078 sym->set_domain (LABEL_DOMAIN);
19080 break;
19081 case DW_TAG_subprogram:
19082 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19083 finish_block. */
19085 attr2 = dwarf2_attr (die, DW_AT_external, cu);
19086 if ((attr2 != nullptr && attr2->as_boolean ())
19087 || cu->lang () == language_ada
19088 || cu->lang () == language_fortran)
19089 {
19090 /* Subprograms marked external are stored as a global symbol.
19091 Ada and Fortran subprograms, whether marked external or
19092 not, are always stored as a global symbol, because we want
19093 to be able to access them globally. For instance, we want
19094 to be able to break on a nested subprogram without having
19095 to specify the context. */
19096 list_to_add = cu->get_builder ()->get_global_symbols ();
19097 }
19098 else
19099 {
19100 list_to_add = cu->list_in_scope;
19101 }
19102
19103 if (is_ada_import_or_export (cu, name, linkagename))
19104 {
19105 /* This is either a Pragma Import or Export. They can
19106 be distinguished by the declaration flag. */
19107 sym->set_linkage_name (name);
19108 if (die_is_declaration (die, cu))
19109 {
19110 /* For Import, create a symbol using the source
19111 name, and have it refer to the linkage name. */
19112 SYMBOL_LOCATION_BATON (sym) = (void *) linkagename;
19114 }
19115 else
19116 {
19117 /* For Export, create a symbol using the source
19118 name, then create a second symbol that refers
19119 back to it. */
19120 add_ada_export_symbol (sym, linkagename, name, cu,
19121 list_to_add);
19122 }
19123 }
19124 break;
19125 case DW_TAG_inlined_subroutine:
19126 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19127 finish_block. */
19129 sym->set_is_inlined (1);
19130 list_to_add = cu->list_in_scope;
19131 break;
19132 case DW_TAG_template_value_param:
19133 suppress_add = 1;
19134 /* Fall through. */
19135 case DW_TAG_constant:
19136 case DW_TAG_variable:
19137 case DW_TAG_member:
19138 /* Compilation with minimal debug info may result in
19139 variables with missing type entries. Change the
19140 misleading `void' type to something sensible. */
19141 if (sym->type ()->code () == TYPE_CODE_VOID)
19142 sym->set_type (builtin_type (objfile)->builtin_int);
19143
19144 attr = dwarf2_attr (die, DW_AT_const_value, cu);
19145 /* In the case of DW_TAG_member, we should only be called for
19146 static const members. */
19147 if (die->tag == DW_TAG_member)
19148 {
19149 /* dwarf2_add_field uses die_is_declaration,
19150 so we do the same. */
19151 gdb_assert (die_is_declaration (die, cu));
19152 gdb_assert (attr);
19153 }
19154 if (attr != nullptr)
19155 {
19156 dwarf2_const_value (attr, sym, cu);
19157 attr2 = dwarf2_attr (die, DW_AT_external, cu);
19158 if (!suppress_add)
19159 {
19160 if (attr2 != nullptr && attr2->as_boolean ())
19161 list_to_add = cu->get_builder ()->get_global_symbols ();
19162 else
19163 list_to_add = cu->list_in_scope;
19164 }
19165 break;
19166 }
19167 attr = dwarf2_attr (die, DW_AT_location, cu);
19168 if (attr != nullptr)
19169 {
19170 var_decode_location (attr, sym, cu);
19171 attr2 = dwarf2_attr (die, DW_AT_external, cu);
19172
19173 /* Fortran explicitly imports any global symbols to the local
19174 scope by DW_TAG_common_block. */
19175 if (cu->lang () == language_fortran && die->parent
19176 && die->parent->tag == DW_TAG_common_block)
19177 attr2 = NULL;
19178
19179 if (sym->aclass () == LOC_STATIC
19180 && sym->value_address () == 0
19181 && !per_objfile->per_bfd->has_section_at_zero)
19182 {
19183 /* When a static variable is eliminated by the linker,
19184 the corresponding debug information is not stripped
19185 out, but the variable address is set to null;
19186 do not add such variables into symbol table. */
19187 }
19188 else if (attr2 != nullptr && attr2->as_boolean ())
19189 {
19190 if (sym->aclass () == LOC_STATIC
19191 && (objfile->flags & OBJF_MAINLINE) == 0
19192 && per_objfile->per_bfd->can_copy)
19193 {
19194 /* A global static variable might be subject to
19195 copy relocation. We first check for a local
19196 minsym, though, because maybe the symbol was
19197 marked hidden, in which case this would not
19198 apply. */
19201 (sym->linkage_name (), objfile));
19202 if (found.minsym != nullptr)
19203 sym->maybe_copied = 1;
19204 }
19205
19206 /* A variable with DW_AT_external is never static,
19207 but it may be block-scoped. */
19208 list_to_add
19209 = ((cu->list_in_scope
19210 == cu->get_builder ()->get_file_symbols ())
19211 ? cu->get_builder ()->get_global_symbols ()
19212 : cu->list_in_scope);
19213 }
19214 else
19215 list_to_add = cu->list_in_scope;
19216
19217 if (list_to_add != nullptr
19218 && is_ada_import_or_export (cu, name, linkagename))
19219 {
19220 /* This is a Pragma Export. A Pragma Import won't
19221 be seen here, because it will not have a location
19222 and so will be handled below. */
19223 add_ada_export_symbol (sym, name, linkagename, cu,
19224 list_to_add);
19225 }
19226 }
19227 else
19228 {
19229 /* We do not know the address of this symbol.
19230 If it is an external symbol and we have type information
19231 for it, enter the symbol as a LOC_UNRESOLVED symbol.
19232 The address of the variable will then be determined from
19233 the minimal symbol table whenever the variable is
19234 referenced. */
19235 attr2 = dwarf2_attr (die, DW_AT_external, cu);
19236
19237 /* Fortran explicitly imports any global symbols to the local
19238 scope by DW_TAG_common_block. */
19239 if (cu->lang () == language_fortran && die->parent
19240 && die->parent->tag == DW_TAG_common_block)
19241 {
19242 /* SYMBOL_CLASS doesn't matter here because
19243 read_common_block is going to reset it. */
19244 if (!suppress_add)
19245 list_to_add = cu->list_in_scope;
19246 }
19247 else if (is_ada_import_or_export (cu, name, linkagename))
19248 {
19249 /* This is a Pragma Import. A Pragma Export won't
19250 be seen here, because it will have a location and
19251 so will be handled above. */
19252 sym->set_linkage_name (name);
19253 list_to_add = cu->list_in_scope;
19254 SYMBOL_LOCATION_BATON (sym) = (void *) linkagename;
19256 }
19257 else if (attr2 != nullptr && attr2->as_boolean ()
19258 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
19259 {
19260 /* A variable with DW_AT_external is never static, but it
19261 may be block-scoped. */
19262 list_to_add
19263 = ((cu->list_in_scope
19264 == cu->get_builder ()->get_file_symbols ())
19265 ? cu->get_builder ()->get_global_symbols ()
19266 : cu->list_in_scope);
19267
19269 }
19270 else if (!die_is_declaration (die, cu))
19271 {
19272 /* Use the default LOC_OPTIMIZED_OUT class. */
19273 gdb_assert (sym->aclass () == LOC_OPTIMIZED_OUT);
19274 if (!suppress_add)
19275 list_to_add = cu->list_in_scope;
19276 }
19277 }
19278 break;
19279 case DW_TAG_formal_parameter:
19280 {
19281 /* If we are inside a function, mark this as an argument. If
19282 not, we might be looking at an argument to an inlined function
19283 when we do not have enough information to show inlined frames;
19284 pretend it's a local variable in that case so that the user can
19285 still see it. */
19286 struct context_stack *curr
19288 if (curr != nullptr && curr->name != nullptr)
19289 sym->set_is_argument (1);
19290 attr = dwarf2_attr (die, DW_AT_location, cu);
19291 if (attr != nullptr)
19292 {
19293 var_decode_location (attr, sym, cu);
19294 }
19295 attr = dwarf2_attr (die, DW_AT_const_value, cu);
19296 if (attr != nullptr)
19297 {
19298 dwarf2_const_value (attr, sym, cu);
19299 }
19300
19301 list_to_add = cu->list_in_scope;
19302 }
19303 break;
19304 case DW_TAG_unspecified_parameters:
19305 /* From varargs functions; gdb doesn't seem to have any
19306 interest in this information, so just ignore it for now.
19307 (FIXME?) */
19308 break;
19309 case DW_TAG_template_type_param:
19310 suppress_add = 1;
19311 /* Fall through. */
19312 case DW_TAG_class_type:
19313 case DW_TAG_interface_type:
19314 case DW_TAG_structure_type:
19315 case DW_TAG_union_type:
19316 case DW_TAG_set_type:
19317 case DW_TAG_enumeration_type:
19318 case DW_TAG_namelist:
19319 if (die->tag == DW_TAG_namelist)
19320 {
19322 sym->set_domain (VAR_DOMAIN);
19323 }
19324 else
19325 {
19328 }
19329 {
19330 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19331 really ever be static objects: otherwise, if you try
19332 to, say, break of a class's method and you're in a file
19333 which doesn't mention that class, it won't work unless
19334 the check for all static symbols in lookup_symbol_aux
19335 saves you. See the OtherFileClass tests in
19336 gdb.c++/namespace.exp. */
19337
19338 if (!suppress_add)
19339 {
19340 buildsym_compunit *builder = cu->get_builder ();
19341 list_to_add
19342 = (cu->list_in_scope == builder->get_file_symbols ()
19343 && cu->lang () == language_cplus
19344 ? builder->get_global_symbols ()
19345 : cu->list_in_scope);
19346
19347 /* The semantics of C++ state that "struct foo {
19348 ... }" also defines a typedef for "foo". */
19349 if (cu->lang () == language_cplus
19350 || cu->lang () == language_ada
19351 || cu->lang () == language_d
19352 || cu->lang () == language_rust)
19353 {
19354 /* The symbol's name is already allocated along
19355 with this objfile, so we don't need to
19356 duplicate it for the type. */
19357 if (sym->type ()->name () == 0)
19358 sym->type ()->set_name (sym->search_name ());
19359 }
19360 }
19361 }
19362 break;
19363 case DW_TAG_unspecified_type:
19364 if (cu->lang () == language_ada)
19365 break;
19366 /* FALLTHROUGH */
19367 case DW_TAG_typedef:
19368 case DW_TAG_array_type:
19369 case DW_TAG_base_type:
19370 case DW_TAG_subrange_type:
19371 case DW_TAG_generic_subrange:
19373 sym->set_domain (VAR_DOMAIN);
19374 list_to_add = cu->list_in_scope;
19375 break;
19376 case DW_TAG_enumerator:
19377 attr = dwarf2_attr (die, DW_AT_const_value, cu);
19378 if (attr != nullptr)
19379 {
19380 dwarf2_const_value (attr, sym, cu);
19381 }
19382 {
19383 /* NOTE: carlton/2003-11-10: See comment above in the
19384 DW_TAG_class_type, etc. block. */
19385
19386 list_to_add
19387 = (cu->list_in_scope == cu->get_builder ()->get_file_symbols ()
19388 && cu->lang () == language_cplus
19389 ? cu->get_builder ()->get_global_symbols ()
19390 : cu->list_in_scope);
19391 }
19392 break;
19393 case DW_TAG_imported_declaration:
19394 case DW_TAG_namespace:
19396 list_to_add = cu->get_builder ()->get_global_symbols ();
19397 break;
19398 case DW_TAG_module:
19401 list_to_add = cu->get_builder ()->get_global_symbols ();
19402 break;
19403 case DW_TAG_common_block:
19407 break;
19408 default:
19409 /* Not a tag we recognize. Hopefully we aren't processing
19410 trash data, but since we must specifically ignore things
19411 we don't recognize, there is nothing else we should do at
19412 this point. */
19413 complaint (_("unsupported tag: '%s'"),
19414 dwarf_tag_name (die->tag));
19415 break;
19416 }
19417
19418 if (suppress_add)
19419 {
19422 list_to_add = NULL;
19423 }
19424
19425 if (list_to_add != NULL)
19426 add_symbol_to_list (sym, list_to_add);
19427
19428 /* For the benefit of old versions of GCC, check for anonymous
19429 namespaces based on the demangled name. */
19431 && cu->lang () == language_cplus)
19433 }
19434 return (sym);
19435}
19436
19437/* Given an attr with a DW_FORM_dataN value in host byte order,
19438 zero-extend it as appropriate for the symbol's type. The DWARF
19439 standard (v4) is not entirely clear about the meaning of using
19440 DW_FORM_dataN for a constant with a signed type, where the type is
19441 wider than the data. The conclusion of a discussion on the DWARF
19442 list was that this is unspecified. We choose to always zero-extend
19443 because that is the interpretation long in use by GCC. */
19444
19445static gdb_byte *
19446dwarf2_const_value_data (const struct attribute *attr, struct obstack *obstack,
19447 struct dwarf2_cu *cu, LONGEST *value, int bits)
19448{
19449 struct objfile *objfile = cu->per_objfile->objfile;
19450 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd.get ()) ?
19451 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
19452 LONGEST l = attr->constant_value (0);
19453
19454 if (bits < sizeof (*value) * 8)
19455 {
19456 l &= ((LONGEST) 1 << bits) - 1;
19457 *value = l;
19458 }
19459 else if (bits == sizeof (*value) * 8)
19460 *value = l;
19461 else
19462 {
19463 gdb_byte *bytes = (gdb_byte *) obstack_alloc (obstack, bits / 8);
19464 store_unsigned_integer (bytes, bits / 8, byte_order, l);
19465 return bytes;
19466 }
19467
19468 return NULL;
19469}
19470
19471/* Read a constant value from an attribute. Either set *VALUE, or if
19472 the value does not fit in *VALUE, set *BYTES - either already
19473 allocated on the objfile obstack, or newly allocated on OBSTACK,
19474 or, set *BATON, if we translated the constant to a location
19475 expression. */
19476
19477static void
19478dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
19479 const char *name, struct obstack *obstack,
19480 struct dwarf2_cu *cu,
19481 LONGEST *value, const gdb_byte **bytes,
19482 struct dwarf2_locexpr_baton **baton)
19483{
19484 dwarf2_per_objfile *per_objfile = cu->per_objfile;
19485 struct objfile *objfile = per_objfile->objfile;
19486 struct comp_unit_head *cu_header = &cu->header;
19487 struct dwarf_block *blk;
19488 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd.get ()) ?
19489 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
19490
19491 *value = 0;
19492 *bytes = NULL;
19493 *baton = NULL;
19494
19495 switch (attr->form)
19496 {
19497 case DW_FORM_addr:
19498 case DW_FORM_addrx:
19499 case DW_FORM_GNU_addr_index:
19500 {
19501 gdb_byte *data;
19502
19503 if (type->length () != cu_header->addr_size)
19505 cu_header->addr_size,
19506 type->length ());
19507 /* Symbols of this form are reasonably rare, so we just
19508 piggyback on the existing location code rather than writing
19509 a new implementation of symbol_computed_ops. */
19510 *baton = XOBNEW (obstack, struct dwarf2_locexpr_baton);
19511 (*baton)->per_objfile = per_objfile;
19512 (*baton)->per_cu = cu->per_cu;
19513 gdb_assert ((*baton)->per_cu);
19514
19515 (*baton)->size = 2 + cu_header->addr_size;
19516 data = (gdb_byte *) obstack_alloc (obstack, (*baton)->size);
19517 (*baton)->data = data;
19518
19519 data[0] = DW_OP_addr;
19520 store_unsigned_integer (&data[1], cu_header->addr_size,
19521 byte_order, (ULONGEST) attr->as_address ());
19522 data[cu_header->addr_size + 1] = DW_OP_stack_value;
19523 }
19524 break;
19525 case DW_FORM_string:
19526 case DW_FORM_strp:
19527 case DW_FORM_strx:
19528 case DW_FORM_GNU_str_index:
19529 case DW_FORM_GNU_strp_alt:
19530 /* The string is already allocated on the objfile obstack, point
19531 directly to it. */
19532 *bytes = (const gdb_byte *) attr->as_string ();
19533 break;
19534 case DW_FORM_block1:
19535 case DW_FORM_block2:
19536 case DW_FORM_block4:
19537 case DW_FORM_block:
19538 case DW_FORM_exprloc:
19539 case DW_FORM_data16:
19540 blk = attr->as_block ();
19541 if (type->length () != blk->size)
19543 type->length ());
19544 *bytes = blk->data;
19545 break;
19546
19547 /* The DW_AT_const_value attributes are supposed to carry the
19548 symbol's value "represented as it would be on the target
19549 architecture." By the time we get here, it's already been
19550 converted to host endianness, so we just need to sign- or
19551 zero-extend it as appropriate. */
19552 case DW_FORM_data1:
19553 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 8);
19554 break;
19555 case DW_FORM_data2:
19556 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 16);
19557 break;
19558 case DW_FORM_data4:
19559 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 32);
19560 break;
19561 case DW_FORM_data8:
19562 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 64);
19563 break;
19564
19565 case DW_FORM_sdata:
19566 case DW_FORM_implicit_const:
19567 *value = attr->as_signed ();
19568 break;
19569
19570 case DW_FORM_udata:
19571 *value = attr->as_unsigned ();
19572 break;
19573
19574 default:
19575 complaint (_("unsupported const value attribute form: '%s'"),
19576 dwarf_form_name (attr->form));
19577 *value = 0;
19578 break;
19579 }
19580}
19581
19582
19583/* Copy constant value from an attribute to a symbol. */
19584
19585static void
19586dwarf2_const_value (const struct attribute *attr, struct symbol *sym,
19587 struct dwarf2_cu *cu)
19588{
19589 struct objfile *objfile = cu->per_objfile->objfile;
19590 LONGEST value;
19591 const gdb_byte *bytes;
19592 struct dwarf2_locexpr_baton *baton;
19593
19594 dwarf2_const_value_attr (attr, sym->type (),
19595 sym->print_name (),
19597 &value, &bytes, &baton);
19598
19599 if (baton != NULL)
19600 {
19601 SYMBOL_LOCATION_BATON (sym) = baton;
19603 }
19604 else if (bytes != NULL)
19605 {
19606 sym->set_value_bytes (bytes);
19608 }
19609 else
19610 {
19611 sym->set_value_longest (value);
19613 }
19614}
19615
19616/* Return the type of the die in question using its DW_AT_type attribute. */
19617
19618static struct type *
19619die_type (struct die_info *die, struct dwarf2_cu *cu)
19620{
19621 struct attribute *type_attr;
19622
19623 type_attr = dwarf2_attr (die, DW_AT_type, cu);
19624 if (!type_attr)
19625 {
19626 struct objfile *objfile = cu->per_objfile->objfile;
19627 /* A missing DW_AT_type represents a void type. */
19629 }
19630
19631 return lookup_die_type (die, type_attr, cu);
19632}
19633
19634/* True iff CU's producer generates GNAT Ada auxiliary information
19635 that allows to find parallel types through that information instead
19636 of having to do expensive parallel lookups by type name. */
19637
19638static int
19640{
19641 /* Assume that the Ada compiler was GNAT, which always produces
19642 the auxiliary information. */
19643 return (cu->lang () == language_ada);
19644}
19645
19646/* Return the auxiliary type of the die in question using its
19647 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
19648 attribute is not present. */
19649
19650static struct type *
19651die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
19652{
19653 struct attribute *type_attr;
19654
19655 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
19656 if (!type_attr)
19657 return NULL;
19658
19659 return lookup_die_type (die, type_attr, cu);
19660}
19661
19662/* If DIE has a descriptive_type attribute, then set the TYPE's
19663 descriptive type accordingly. */
19664
19665static void
19667 struct dwarf2_cu *cu)
19668{
19669 struct type *descriptive_type = die_descriptive_type (die, cu);
19670
19671 if (descriptive_type)
19672 {
19674 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
19675 }
19676}
19677
19678/* Return the containing type of the die in question using its
19679 DW_AT_containing_type attribute. */
19680
19681static struct type *
19682die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
19683{
19684 struct attribute *type_attr;
19685 struct objfile *objfile = cu->per_objfile->objfile;
19686
19687 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
19688 if (!type_attr)
19689 error (_("Dwarf Error: Problem turning containing type into gdb type "
19690 "[in module %s]"), objfile_name (objfile));
19691
19692 return lookup_die_type (die, type_attr, cu);
19693}
19694
19695/* Return an error marker type to use for the ill formed type in DIE/CU. */
19696
19697static struct type *
19699{
19700 dwarf2_per_objfile *per_objfile = cu->per_objfile;
19701 struct objfile *objfile = per_objfile->objfile;
19702 char *saved;
19703
19704 std::string message
19705 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
19708 sect_offset_str (die->sect_off));
19709 saved = obstack_strdup (&objfile->objfile_obstack, message);
19710
19711 return type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_ERROR,
19712 0, saved);
19713}
19714
19715/* Look up the type of DIE in CU using its type attribute ATTR.
19716 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
19717 DW_AT_containing_type.
19718 If there is no type substitute an error marker. */
19719
19720static struct type *
19721lookup_die_type (struct die_info *die, const struct attribute *attr,
19722 struct dwarf2_cu *cu)
19723{
19724 dwarf2_per_objfile *per_objfile = cu->per_objfile;
19725 struct objfile *objfile = per_objfile->objfile;
19726 struct type *this_type;
19727
19728 gdb_assert (attr->name == DW_AT_type
19729 || attr->name == DW_AT_GNAT_descriptive_type
19730 || attr->name == DW_AT_containing_type);
19731
19732 /* First see if we have it cached. */
19733
19734 if (attr->form == DW_FORM_GNU_ref_alt)
19735 {
19736 struct dwarf2_per_cu_data *per_cu;
19737 sect_offset sect_off = attr->get_ref_die_offset ();
19738
19740 per_objfile->per_bfd);
19741 this_type = get_die_type_at_offset (sect_off, per_cu, per_objfile);
19742 }
19743 else if (attr->form_is_ref ())
19744 {
19745 sect_offset sect_off = attr->get_ref_die_offset ();
19746
19747 this_type = get_die_type_at_offset (sect_off, cu->per_cu, per_objfile);
19748 }
19749 else if (attr->form == DW_FORM_ref_sig8)
19750 {
19751 ULONGEST signature = attr->as_signature ();
19752
19753 return get_signatured_type (die, signature, cu);
19754 }
19755 else
19756 {
19757 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
19758 " at %s [in module %s]"),
19761 return build_error_marker_type (cu, die);
19762 }
19763
19764 /* If not cached we need to read it in. */
19765
19766 if (this_type == NULL)
19767 {
19768 struct die_info *type_die = NULL;
19769 struct dwarf2_cu *type_cu = cu;
19770
19771 if (attr->form_is_ref ())
19772 type_die = follow_die_ref (die, attr, &type_cu);
19773 if (type_die == NULL)
19774 return build_error_marker_type (cu, die);
19775 /* If we find the type now, it's probably because the type came
19776 from an inter-CU reference and the type's CU got expanded before
19777 ours. */
19778 this_type = read_type_die (type_die, type_cu);
19779 }
19780
19781 /* If we still don't have a type use an error marker. */
19782
19783 if (this_type == NULL)
19784 return build_error_marker_type (cu, die);
19785
19786 return this_type;
19787}
19788
19789/* Return the type in DIE, CU.
19790 Returns NULL for invalid types.
19791
19792 This first does a lookup in die_type_hash,
19793 and only reads the die in if necessary.
19794
19795 NOTE: This can be called when reading in partial or full symbols. */
19796
19797static struct type *
19798read_type_die (struct die_info *die, struct dwarf2_cu *cu)
19799{
19800 struct type *this_type;
19801
19802 this_type = get_die_type (die, cu);
19803 if (this_type)
19804 return this_type;
19805
19806 return read_type_die_1 (die, cu);
19807}
19808
19809/* Read the type in DIE, CU.
19810 Returns NULL for invalid types. */
19811
19812static struct type *
19813read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
19814{
19815 struct type *this_type = NULL;
19816
19817 switch (die->tag)
19818 {
19819 case DW_TAG_class_type:
19820 case DW_TAG_interface_type:
19821 case DW_TAG_structure_type:
19822 case DW_TAG_union_type:
19823 this_type = read_structure_type (die, cu);
19824 break;
19825 case DW_TAG_enumeration_type:
19826 this_type = read_enumeration_type (die, cu);
19827 break;
19828 case DW_TAG_subprogram:
19829 case DW_TAG_subroutine_type:
19830 case DW_TAG_inlined_subroutine:
19831 this_type = read_subroutine_type (die, cu);
19832 break;
19833 case DW_TAG_array_type:
19834 this_type = read_array_type (die, cu);
19835 break;
19836 case DW_TAG_set_type:
19837 this_type = read_set_type (die, cu);
19838 break;
19839 case DW_TAG_pointer_type:
19840 this_type = read_tag_pointer_type (die, cu);
19841 break;
19842 case DW_TAG_ptr_to_member_type:
19843 this_type = read_tag_ptr_to_member_type (die, cu);
19844 break;
19845 case DW_TAG_reference_type:
19846 this_type = read_tag_reference_type (die, cu, TYPE_CODE_REF);
19847 break;
19848 case DW_TAG_rvalue_reference_type:
19849 this_type = read_tag_reference_type (die, cu, TYPE_CODE_RVALUE_REF);
19850 break;
19851 case DW_TAG_const_type:
19852 this_type = read_tag_const_type (die, cu);
19853 break;
19854 case DW_TAG_volatile_type:
19855 this_type = read_tag_volatile_type (die, cu);
19856 break;
19857 case DW_TAG_restrict_type:
19858 this_type = read_tag_restrict_type (die, cu);
19859 break;
19860 case DW_TAG_string_type:
19861 this_type = read_tag_string_type (die, cu);
19862 break;
19863 case DW_TAG_typedef:
19864 this_type = read_typedef (die, cu);
19865 break;
19866 case DW_TAG_generic_subrange:
19867 case DW_TAG_subrange_type:
19868 this_type = read_subrange_type (die, cu);
19869 break;
19870 case DW_TAG_base_type:
19871 this_type = read_base_type (die, cu);
19872 break;
19873 case DW_TAG_unspecified_type:
19874 this_type = read_unspecified_type (die, cu);
19875 break;
19876 case DW_TAG_namespace:
19877 this_type = read_namespace_type (die, cu);
19878 break;
19879 case DW_TAG_module:
19880 this_type = read_module_type (die, cu);
19881 break;
19882 case DW_TAG_atomic_type:
19883 this_type = read_tag_atomic_type (die, cu);
19884 break;
19885 default:
19886 complaint (_("unexpected tag in read_type_die: '%s'"),
19887 dwarf_tag_name (die->tag));
19888 break;
19889 }
19890
19891 return this_type;
19892}
19893
19894/* See if we can figure out if the class lives in a namespace. We do
19895 this by looking for a member function; its demangled name will
19896 contain namespace info, if there is any.
19897 Return the computed name or NULL.
19898 Space for the result is allocated on the objfile's obstack.
19899 This is the full-die version of guess_partial_die_structure_name.
19900 In this case we know DIE has no useful parent. */
19901
19902static const char *
19904{
19905 struct die_info *spec_die;
19906 struct dwarf2_cu *spec_cu;
19907 struct die_info *child;
19908 struct objfile *objfile = cu->per_objfile->objfile;
19909
19910 spec_cu = cu;
19911 spec_die = die_specification (die, &spec_cu);
19912 if (spec_die != NULL)
19913 {
19914 die = spec_die;
19915 cu = spec_cu;
19916 }
19917
19918 for (child = die->child;
19919 child != NULL;
19920 child = child->sibling)
19921 {
19922 if (child->tag == DW_TAG_subprogram)
19923 {
19924 const char *linkage_name = dw2_linkage_name (child, cu);
19925
19926 if (linkage_name != NULL)
19927 {
19928 gdb::unique_xmalloc_ptr<char> actual_name
19929 (cu->language_defn->class_name_from_physname (linkage_name));
19930 const char *name = NULL;
19931
19932 if (actual_name != NULL)
19933 {
19934 const char *die_name = dwarf2_name (die, cu);
19935
19936 if (die_name != NULL
19937 && strcmp (die_name, actual_name.get ()) != 0)
19938 {
19939 /* Strip off the class name from the full name.
19940 We want the prefix. */
19941 int die_name_len = strlen (die_name);
19942 int actual_name_len = strlen (actual_name.get ());
19943 const char *ptr = actual_name.get ();
19944
19945 /* Test for '::' as a sanity check. */
19946 if (actual_name_len > die_name_len + 2
19947 && ptr[actual_name_len - die_name_len - 1] == ':')
19948 name = obstack_strndup (
19950 ptr, actual_name_len - die_name_len - 2);
19951 }
19952 }
19953 return name;
19954 }
19955 }
19956 }
19957
19958 return NULL;
19959}
19960
19961/* GCC might emit a nameless typedef that has a linkage name. Determine the
19962 prefix part in such case. See
19963 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19964
19965static const char *
19967{
19968 struct attribute *attr;
19969 const char *base;
19970
19971 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
19972 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
19973 return NULL;
19974
19975 if (dwarf2_string_attr (die, DW_AT_name, cu) != NULL)
19976 return NULL;
19977
19978 attr = dw2_linkage_name_attr (die, cu);
19979 const char *attr_name = attr->as_string ();
19980 if (attr == NULL || attr_name == NULL)
19981 return NULL;
19982
19983 /* dwarf2_name had to be already called. */
19984 gdb_assert (attr->canonical_string_p ());
19985
19986 /* Strip the base name, keep any leading namespaces/classes. */
19987 base = strrchr (attr_name, ':');
19988 if (base == NULL || base == attr_name || base[-1] != ':')
19989 return "";
19990
19991 struct objfile *objfile = cu->per_objfile->objfile;
19992 return obstack_strndup (&objfile->per_bfd->storage_obstack,
19993 attr_name,
19994 &base[-1] - attr_name);
19995}
19996
19997/* Return the name of the namespace/class that DIE is defined within,
19998 or "" if we can't tell. The caller should not xfree the result.
19999
20000 For example, if we're within the method foo() in the following
20001 code:
20002
20003 namespace N {
20004 class C {
20005 void foo () {
20006 }
20007 };
20008 }
20009
20010 then determine_prefix on foo's die will return "N::C". */
20011
20012static const char *
20013determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
20014{
20015 dwarf2_per_objfile *per_objfile = cu->per_objfile;
20016 struct die_info *parent, *spec_die;
20017 struct dwarf2_cu *spec_cu;
20018 struct type *parent_type;
20019 const char *retval;
20020
20021 if (cu->lang () != language_cplus
20022 && cu->lang () != language_fortran
20023 && cu->lang () != language_d
20024 && cu->lang () != language_rust)
20025 return "";
20026
20027 retval = anonymous_struct_prefix (die, cu);
20028 if (retval)
20029 return retval;
20030
20031 /* We have to be careful in the presence of DW_AT_specification.
20032 For example, with GCC 3.4, given the code
20033
20034 namespace N {
20035 void foo() {
20036 // Definition of N::foo.
20037 }
20038 }
20039
20040 then we'll have a tree of DIEs like this:
20041
20042 1: DW_TAG_compile_unit
20043 2: DW_TAG_namespace // N
20044 3: DW_TAG_subprogram // declaration of N::foo
20045 4: DW_TAG_subprogram // definition of N::foo
20046 DW_AT_specification // refers to die #3
20047
20048 Thus, when processing die #4, we have to pretend that we're in
20049 the context of its DW_AT_specification, namely the context of die
20050 #3. */
20051 spec_cu = cu;
20052 spec_die = die_specification (die, &spec_cu);
20053 if (spec_die == NULL)
20054 parent = die->parent;
20055 else
20056 {
20057 parent = spec_die->parent;
20058 cu = spec_cu;
20059 }
20060
20061 if (parent == NULL)
20062 return "";
20063 else if (parent->building_fullname)
20064 {
20065 const char *name;
20066 const char *parent_name;
20067
20068 /* It has been seen on RealView 2.2 built binaries,
20069 DW_TAG_template_type_param types actually _defined_ as
20070 children of the parent class:
20071
20072 enum E {};
20073 template class <class Enum> Class{};
20074 Class<enum E> class_e;
20075
20076 1: DW_TAG_class_type (Class)
20077 2: DW_TAG_enumeration_type (E)
20078 3: DW_TAG_enumerator (enum1:0)
20079 3: DW_TAG_enumerator (enum2:1)
20080 ...
20081 2: DW_TAG_template_type_param
20082 DW_AT_type DW_FORM_ref_udata (E)
20083
20084 Besides being broken debug info, it can put GDB into an
20085 infinite loop. Consider:
20086
20087 When we're building the full name for Class<E>, we'll start
20088 at Class, and go look over its template type parameters,
20089 finding E. We'll then try to build the full name of E, and
20090 reach here. We're now trying to build the full name of E,
20091 and look over the parent DIE for containing scope. In the
20092 broken case, if we followed the parent DIE of E, we'd again
20093 find Class, and once again go look at its template type
20094 arguments, etc., etc. Simply don't consider such parent die
20095 as source-level parent of this die (it can't be, the language
20096 doesn't allow it), and break the loop here. */
20097 name = dwarf2_name (die, cu);
20098 parent_name = dwarf2_name (parent, cu);
20099 complaint (_("template param type '%s' defined within parent '%s'"),
20100 name ? name : "<unknown>",
20101 parent_name ? parent_name : "<unknown>");
20102 return "";
20103 }
20104 else
20105 switch (parent->tag)
20106 {
20107 case DW_TAG_namespace:
20108 parent_type = read_type_die (parent, cu);
20109 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
20110 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
20111 Work around this problem here. */
20112 if (cu->lang () == language_cplus
20113 && strcmp (parent_type->name (), "::") == 0)
20114 return "";
20115 /* We give a name to even anonymous namespaces. */
20116 return parent_type->name ();
20117 case DW_TAG_class_type:
20118 case DW_TAG_interface_type:
20119 case DW_TAG_structure_type:
20120 case DW_TAG_union_type:
20121 case DW_TAG_module:
20122 parent_type = read_type_die (parent, cu);
20123 if (parent_type->name () != NULL)
20124 return parent_type->name ();
20125 else
20126 /* An anonymous structure is only allowed non-static data
20127 members; no typedefs, no member functions, et cetera.
20128 So it does not need a prefix. */
20129 return "";
20130 case DW_TAG_compile_unit:
20131 case DW_TAG_partial_unit:
20132 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
20133 if (cu->lang () == language_cplus
20134 && !per_objfile->per_bfd->types.empty ()
20135 && die->child != NULL
20136 && (die->tag == DW_TAG_class_type
20137 || die->tag == DW_TAG_structure_type
20138 || die->tag == DW_TAG_union_type))
20139 {
20140 const char *name = guess_full_die_structure_name (die, cu);
20141 if (name != NULL)
20142 return name;
20143 }
20144 return "";
20145 case DW_TAG_subprogram:
20146 /* Nested subroutines in Fortran get a prefix with the name
20147 of the parent's subroutine. */
20148 if (cu->lang () == language_fortran)
20149 {
20150 if ((die->tag == DW_TAG_subprogram)
20151 && (dwarf2_name (parent, cu) != NULL))
20152 return dwarf2_name (parent, cu);
20153 }
20154 return "";
20155 case DW_TAG_enumeration_type:
20156 parent_type = read_type_die (parent, cu);
20157 if (parent_type->is_declared_class ())
20158 {
20159 if (parent_type->name () != NULL)
20160 return parent_type->name ();
20161 return "";
20162 }
20163 /* Fall through. */
20164 default:
20165 return determine_prefix (parent, cu);
20166 }
20167}
20168
20169/* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
20170 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
20171 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
20172 an obconcat, otherwise allocate storage for the result. The CU argument is
20173 used to determine the language and hence, the appropriate separator. */
20174
20175#define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
20176
20177static char *
20178typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
20179 int physname, struct dwarf2_cu *cu)
20180{
20181 const char *lead = "";
20182 const char *sep;
20183
20184 if (suffix == NULL || suffix[0] == '\0'
20185 || prefix == NULL || prefix[0] == '\0')
20186 sep = "";
20187 else if (cu->lang () == language_d)
20188 {
20189 /* For D, the 'main' function could be defined in any module, but it
20190 should never be prefixed. */
20191 if (strcmp (suffix, "D main") == 0)
20192 {
20193 prefix = "";
20194 sep = "";
20195 }
20196 else
20197 sep = ".";
20198 }
20199 else if (cu->lang () == language_fortran && physname)
20200 {
20201 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
20202 DW_AT_MIPS_linkage_name is preferred and used instead. */
20203
20204 lead = "__";
20205 sep = "_MOD_";
20206 }
20207 else
20208 sep = "::";
20209
20210 if (prefix == NULL)
20211 prefix = "";
20212 if (suffix == NULL)
20213 suffix = "";
20214
20215 if (obs == NULL)
20216 {
20217 char *retval
20218 = ((char *)
20219 xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1));
20220
20221 strcpy (retval, lead);
20222 strcat (retval, prefix);
20223 strcat (retval, sep);
20224 strcat (retval, suffix);
20225 return retval;
20226 }
20227 else
20228 {
20229 /* We have an obstack. */
20230 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
20231 }
20232}
20233
20234/* Return a generic name for a DW_TAG_template_type_param or
20235 DW_TAG_template_value_param tag, missing a DW_AT_name attribute. We do this
20236 per parent, so each function/class/struct template will have their own set
20237 of template parameters named <unnnamed0>, <unnamed1>, ... where the
20238 enumeration starts at 0 and represents the position of the template tag in
20239 the list of unnamed template tags for this parent, counting both, type and
20240 value tags. */
20241
20242static const char *
20244{
20245 if (die->parent == nullptr)
20246 return nullptr;
20247
20248 /* Count the parent types unnamed template type and value children until, we
20249 arrive at our entry. */
20250 size_t nth_unnamed = 0;
20251
20252 die_info *child = die->parent->child;
20253 while (child != die)
20254 {
20255 gdb_assert (child != nullptr);
20256 if (child->tag == DW_TAG_template_type_param
20257 || child->tag == DW_TAG_template_value_param)
20258 {
20259 if (dwarf2_attr (child, DW_AT_name, cu) == nullptr)
20260 ++nth_unnamed;
20261 }
20262 child = child->sibling;
20263 }
20264
20265 const std::string name_str = "<unnamed" + std::to_string (nth_unnamed) + ">";
20266 return cu->per_objfile->objfile->intern (name_str.c_str ());
20267}
20268
20269/* Get name of a die, return NULL if not found. */
20270
20271static const char *
20272dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu,
20273 struct objfile *objfile)
20274{
20275 if (name == nullptr)
20276 return name;
20277
20278 if (cu->lang () == language_cplus)
20279 {
20280 gdb::unique_xmalloc_ptr<char> canon_name
20282
20283 if (canon_name != nullptr)
20284 name = objfile->intern (canon_name.get ());
20285 }
20286 else if (cu->lang () == language_c)
20287 {
20288 gdb::unique_xmalloc_ptr<char> canon_name
20290
20291 if (canon_name != nullptr)
20292 name = objfile->intern (canon_name.get ());
20293 }
20294
20295 return name;
20296}
20297
20298/* Get name of a die, return NULL if not found.
20299 Anonymous namespaces are converted to their magic string. */
20300
20301static const char *
20302dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
20303{
20304 struct attribute *attr;
20305 struct objfile *objfile = cu->per_objfile->objfile;
20306
20307 attr = dwarf2_attr (die, DW_AT_name, cu);
20308 const char *attr_name = attr == nullptr ? nullptr : attr->as_string ();
20309 if (attr_name == nullptr
20310 && die->tag != DW_TAG_namespace
20311 && die->tag != DW_TAG_class_type
20312 && die->tag != DW_TAG_interface_type
20313 && die->tag != DW_TAG_structure_type
20314 && die->tag != DW_TAG_namelist
20315 && die->tag != DW_TAG_union_type
20316 && die->tag != DW_TAG_template_type_param
20317 && die->tag != DW_TAG_template_value_param)
20318 return NULL;
20319
20320 switch (die->tag)
20321 {
20322 /* A member's name should not be canonicalized. This is a bit
20323 of a hack, in that normally it should not be possible to run
20324 into this situation; however, the dw2-unusual-field-names.exp
20325 test creates custom DWARF that does. */
20326 case DW_TAG_member:
20327 case DW_TAG_compile_unit:
20328 case DW_TAG_partial_unit:
20329 /* Compilation units have a DW_AT_name that is a filename, not
20330 a source language identifier. */
20331 case DW_TAG_enumeration_type:
20332 case DW_TAG_enumerator:
20333 /* These tags always have simple identifiers already; no need
20334 to canonicalize them. */
20335 return attr_name;
20336
20337 case DW_TAG_namespace:
20338 if (attr_name != nullptr)
20339 return attr_name;
20341
20342 /* DWARF does not actually require template tags to have a name. */
20343 case DW_TAG_template_type_param:
20344 case DW_TAG_template_value_param:
20345 if (attr_name == nullptr)
20346 return unnamed_template_tag_name (die, cu);
20347 /* FALLTHROUGH. */
20348 case DW_TAG_class_type:
20349 case DW_TAG_interface_type:
20350 case DW_TAG_structure_type:
20351 case DW_TAG_union_type:
20352 case DW_TAG_namelist:
20353 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20354 structures or unions. These were of the form "._%d" in GCC 4.1,
20355 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20356 and GCC 4.4. We work around this problem by ignoring these. */
20357 if (attr_name != nullptr
20358 && (startswith (attr_name, "._")
20359 || startswith (attr_name, "<anonymous")))
20360 return NULL;
20361
20362 /* GCC might emit a nameless typedef that has a linkage name. See
20363 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20364 if (!attr || attr_name == NULL)
20365 {
20366 attr = dw2_linkage_name_attr (die, cu);
20367 attr_name = attr == nullptr ? nullptr : attr->as_string ();
20368 if (attr == NULL || attr_name == NULL)
20369 return NULL;
20370
20371 /* Avoid demangling attr_name the second time on a second
20372 call for the same DIE. */
20373 if (!attr->canonical_string_p ())
20374 {
20375 gdb::unique_xmalloc_ptr<char> demangled
20376 (gdb_demangle (attr_name, DMGL_TYPES));
20377 if (demangled == nullptr)
20378 return nullptr;
20379
20380 attr->set_string_canonical (objfile->intern (demangled.get ()));
20381 attr_name = attr->as_string ();
20382 }
20383
20384 /* Strip any leading namespaces/classes, keep only the
20385 base name. DW_AT_name for named DIEs does not
20386 contain the prefixes. */
20387 const char *base = strrchr (attr_name, ':');
20388 if (base && base > attr_name && base[-1] == ':')
20389 return &base[1];
20390 else
20391 return attr_name;
20392 }
20393 break;
20394
20395 default:
20396 break;
20397 }
20398
20399 if (!attr->canonical_string_p ())
20400 attr->set_string_canonical (dwarf2_canonicalize_name (attr_name, cu,
20401 objfile));
20402 return attr->as_string ();
20403}
20404
20405/* Return the die that this die in an extension of, or NULL if there
20406 is none. *EXT_CU is the CU containing DIE on input, and the CU
20407 containing the return value on output. */
20408
20409static struct die_info *
20410dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
20411{
20412 struct attribute *attr;
20413
20414 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
20415 if (attr == NULL)
20416 return NULL;
20417
20418 return follow_die_ref (die, attr, ext_cu);
20419}
20420
20421static void
20422store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
20423{
20424 void **slot;
20425
20426 slot = htab_find_slot_with_hash (cu->die_hash, die,
20427 to_underlying (die->sect_off),
20428 INSERT);
20429
20430 *slot = die;
20431}
20432
20433/* Follow reference or signature attribute ATTR of SRC_DIE.
20434 On entry *REF_CU is the CU of SRC_DIE.
20435 On exit *REF_CU is the CU of the result. */
20436
20437static struct die_info *
20438follow_die_ref_or_sig (struct die_info *src_die, const struct attribute *attr,
20439 struct dwarf2_cu **ref_cu)
20440{
20441 struct die_info *die;
20442
20443 if (attr->form_is_ref ())
20444 die = follow_die_ref (src_die, attr, ref_cu);
20445 else if (attr->form == DW_FORM_ref_sig8)
20446 die = follow_die_sig (src_die, attr, ref_cu);
20447 else
20448 {
20449 src_die->error_dump ();
20450 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20451 objfile_name ((*ref_cu)->per_objfile->objfile));
20452 }
20453
20454 return die;
20455}
20456
20457/* Follow reference OFFSET.
20458 On entry *REF_CU is the CU of the source die referencing OFFSET.
20459 On exit *REF_CU is the CU of the result.
20460 Returns NULL if OFFSET is invalid. */
20461
20462static struct die_info *
20463follow_die_offset (sect_offset sect_off, int offset_in_dwz,
20464 struct dwarf2_cu **ref_cu)
20465{
20466 struct die_info temp_die;
20467 struct dwarf2_cu *target_cu, *cu = *ref_cu;
20469
20470 gdb_assert (cu->per_cu != NULL);
20471
20472 target_cu = cu;
20473
20474 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
20475 "source CU contains target offset: %d",
20477 sect_offset_str (sect_off),
20478 cu->header.offset_in_cu_p (sect_off));
20479
20480 if (cu->per_cu->is_debug_types)
20481 {
20482 /* .debug_types CUs cannot reference anything outside their CU.
20483 If they need to, they have to reference a signatured type via
20484 DW_FORM_ref_sig8. */
20485 if (!cu->header.offset_in_cu_p (sect_off))
20486 return NULL;
20487 }
20488 else if (offset_in_dwz != cu->per_cu->is_dwz
20489 || !cu->header.offset_in_cu_p (sect_off))
20490 {
20491 struct dwarf2_per_cu_data *per_cu;
20492
20493 per_cu = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz,
20494 per_objfile->per_bfd);
20495
20496 dwarf_read_debug_printf_v ("target CU offset: %s, "
20497 "target CU DIEs loaded: %d",
20498 sect_offset_str (per_cu->sect_off),
20499 per_objfile->get_cu (per_cu) != nullptr);
20500
20501 /* If necessary, add it to the queue and load its DIEs.
20502
20503 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
20504 it doesn't mean they are currently loaded. Since we require them
20505 to be loaded, we must check for ourselves. */
20506 if (maybe_queue_comp_unit (cu, per_cu, per_objfile, cu->lang ())
20507 || per_objfile->get_cu (per_cu) == nullptr)
20508 load_full_comp_unit (per_cu, per_objfile, per_objfile->get_cu (per_cu),
20509 false, cu->lang ());
20510
20511 target_cu = per_objfile->get_cu (per_cu);
20512 gdb_assert (target_cu != nullptr);
20513 }
20514 else if (cu->dies == NULL)
20515 {
20516 /* We're loading full DIEs during partial symbol reading. */
20517 load_full_comp_unit (cu->per_cu, per_objfile, cu, false,
20519 }
20520
20521 *ref_cu = target_cu;
20522 temp_die.sect_off = sect_off;
20523
20524 return (struct die_info *) htab_find_with_hash (target_cu->die_hash,
20525 &temp_die,
20526 to_underlying (sect_off));
20527}
20528
20529/* Follow reference attribute ATTR of SRC_DIE.
20530 On entry *REF_CU is the CU of SRC_DIE.
20531 On exit *REF_CU is the CU of the result. */
20532
20533static struct die_info *
20534follow_die_ref (struct die_info *src_die, const struct attribute *attr,
20535 struct dwarf2_cu **ref_cu)
20536{
20537 sect_offset sect_off = attr->get_ref_die_offset ();
20538 struct dwarf2_cu *cu = *ref_cu;
20539 struct die_info *die;
20540
20541 if (attr->form != DW_FORM_GNU_ref_alt && src_die->sect_off == sect_off)
20542 {
20543 /* Self-reference, we're done. */
20544 return src_die;
20545 }
20546
20548 (attr->form == DW_FORM_GNU_ref_alt
20549 || cu->per_cu->is_dwz),
20550 ref_cu);
20551 if (!die)
20552 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
20553 "at %s [in module %s]"),
20556
20557 return die;
20558}
20559
20560/* See read.h. */
20561
20563dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
20566 gdb::function_view<CORE_ADDR ()> get_frame_pc,
20567 bool resolve_abstract_p)
20568{
20569 struct die_info *die;
20570 struct attribute *attr;
20571 struct dwarf2_locexpr_baton retval;
20572 struct objfile *objfile = per_objfile->objfile;
20573
20574 dwarf2_cu *cu = per_objfile->get_cu (per_cu);
20575 if (cu == nullptr)
20576 cu = load_cu (per_cu, per_objfile, false);
20577
20578 if (cu == nullptr)
20579 {
20580 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20581 Instead just throw an error, not much else we can do. */
20582 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
20583 sect_offset_str (sect_off), objfile_name (objfile));
20584 }
20585
20586 die = follow_die_offset (sect_off, per_cu->is_dwz, &cu);
20587 if (!die)
20588 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
20589 sect_offset_str (sect_off), objfile_name (objfile));
20590
20591 attr = dwarf2_attr (die, DW_AT_location, cu);
20592 if (!attr && resolve_abstract_p
20593 && (per_objfile->per_bfd->abstract_to_concrete.find (die->sect_off)
20594 != per_objfile->per_bfd->abstract_to_concrete.end ()))
20595 {
20596 CORE_ADDR pc = get_frame_pc ();
20597
20598 for (const auto &cand_off
20599 : per_objfile->per_bfd->abstract_to_concrete[die->sect_off])
20600 {
20601 struct dwarf2_cu *cand_cu = cu;
20602 struct die_info *cand
20603 = follow_die_offset (cand_off, per_cu->is_dwz, &cand_cu);
20604 if (!cand
20605 || !cand->parent
20606 || cand->parent->tag != DW_TAG_subprogram)
20607 continue;
20608
20609 unrelocated_addr unrel_low, unrel_high;
20610 get_scope_pc_bounds (cand->parent, &unrel_low, &unrel_high, cu);
20611 if (unrel_low == ((unrelocated_addr) -1))
20612 continue;
20613 CORE_ADDR pc_low = per_objfile->relocate (unrel_low);
20614 CORE_ADDR pc_high = per_objfile->relocate (unrel_high);
20615 if (!(pc_low <= pc && pc < pc_high))
20616 continue;
20617
20618 die = cand;
20619 attr = dwarf2_attr (die, DW_AT_location, cu);
20620 break;
20621 }
20622 }
20623
20624 if (!attr)
20625 {
20626 /* DWARF: "If there is no such attribute, then there is no effect.".
20627 DATA is ignored if SIZE is 0. */
20628
20629 retval.data = NULL;
20630 retval.size = 0;
20631 }
20632 else if (attr->form_is_section_offset ())
20633 {
20634 struct dwarf2_loclist_baton loclist_baton;
20635 CORE_ADDR pc = get_frame_pc ();
20636 size_t size;
20637
20638 fill_in_loclist_baton (cu, &loclist_baton, attr);
20639
20640 retval.data = dwarf2_find_location_expression (&loclist_baton,
20641 &size, pc);
20642 retval.size = size;
20643 }
20644 else
20645 {
20646 if (!attr->form_is_block ())
20647 error (_("Dwarf Error: DIE at %s referenced in module %s "
20648 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20649 sect_offset_str (sect_off), objfile_name (objfile));
20650
20651 struct dwarf_block *block = attr->as_block ();
20652 retval.data = block->data;
20653 retval.size = block->size;
20654 }
20655 retval.per_objfile = per_objfile;
20656 retval.per_cu = cu->per_cu;
20657
20658 per_objfile->age_comp_units ();
20659
20660 return retval;
20661}
20662
20663/* See read.h. */
20664
20666dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu,
20669 gdb::function_view<CORE_ADDR ()> get_frame_pc)
20670{
20671 sect_offset sect_off = per_cu->sect_off + to_underlying (offset_in_cu);
20672
20674 get_frame_pc);
20675}
20676
20677/* Write a constant of a given type as target-ordered bytes into
20678 OBSTACK. */
20679
20680static const gdb_byte *
20681write_constant_as_bytes (struct obstack *obstack,
20682 enum bfd_endian byte_order,
20683 struct type *type,
20684 ULONGEST value,
20685 LONGEST *len)
20686{
20687 gdb_byte *result;
20688
20689 *len = type->length ();
20690 result = (gdb_byte *) obstack_alloc (obstack, *len);
20691 store_unsigned_integer (result, *len, byte_order, value);
20692
20693 return result;
20694}
20695
20696/* See read.h. */
20697
20698const gdb_byte *
20699dwarf2_fetch_constant_bytes (sect_offset sect_off,
20702 obstack *obstack,
20703 LONGEST *len)
20704{
20705 struct die_info *die;
20706 struct attribute *attr;
20707 const gdb_byte *result = NULL;
20708 struct type *type;
20709 LONGEST value;
20710 enum bfd_endian byte_order;
20711 struct objfile *objfile = per_objfile->objfile;
20712
20713 dwarf2_cu *cu = per_objfile->get_cu (per_cu);
20714 if (cu == nullptr)
20715 cu = load_cu (per_cu, per_objfile, false);
20716
20717 if (cu == nullptr)
20718 {
20719 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20720 Instead just throw an error, not much else we can do. */
20721 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
20722 sect_offset_str (sect_off), objfile_name (objfile));
20723 }
20724
20725 die = follow_die_offset (sect_off, per_cu->is_dwz, &cu);
20726 if (!die)
20727 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
20728 sect_offset_str (sect_off), objfile_name (objfile));
20729
20730 attr = dwarf2_attr (die, DW_AT_const_value, cu);
20731 if (attr == NULL)
20732 return NULL;
20733
20734 byte_order = (bfd_big_endian (objfile->obfd.get ())
20735 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
20736
20737 switch (attr->form)
20738 {
20739 case DW_FORM_addr:
20740 case DW_FORM_addrx:
20741 case DW_FORM_GNU_addr_index:
20742 {
20743 gdb_byte *tem;
20744
20745 *len = cu->header.addr_size;
20746 tem = (gdb_byte *) obstack_alloc (obstack, *len);
20747 store_unsigned_integer (tem, *len, byte_order,
20748 (ULONGEST) attr->as_address ());
20749 result = tem;
20750 }
20751 break;
20752 case DW_FORM_string:
20753 case DW_FORM_strp:
20754 case DW_FORM_strx:
20755 case DW_FORM_GNU_str_index:
20756 case DW_FORM_GNU_strp_alt:
20757 /* The string is already allocated on the objfile obstack, point
20758 directly to it. */
20759 {
20760 const char *attr_name = attr->as_string ();
20761 result = (const gdb_byte *) attr_name;
20762 *len = strlen (attr_name);
20763 }
20764 break;
20765 case DW_FORM_block1:
20766 case DW_FORM_block2:
20767 case DW_FORM_block4:
20768 case DW_FORM_block:
20769 case DW_FORM_exprloc:
20770 case DW_FORM_data16:
20771 {
20772 struct dwarf_block *block = attr->as_block ();
20773 result = block->data;
20774 *len = block->size;
20775 }
20776 break;
20777
20778 /* The DW_AT_const_value attributes are supposed to carry the
20779 symbol's value "represented as it would be on the target
20780 architecture." By the time we get here, it's already been
20781 converted to host endianness, so we just need to sign- or
20782 zero-extend it as appropriate. */
20783 case DW_FORM_data1:
20784 type = die_type (die, cu);
20785 result = dwarf2_const_value_data (attr, obstack, cu, &value, 8);
20786 if (result == NULL)
20787 result = write_constant_as_bytes (obstack, byte_order,
20788 type, value, len);
20789 break;
20790 case DW_FORM_data2:
20791 type = die_type (die, cu);
20792 result = dwarf2_const_value_data (attr, obstack, cu, &value, 16);
20793 if (result == NULL)
20794 result = write_constant_as_bytes (obstack, byte_order,
20795 type, value, len);
20796 break;
20797 case DW_FORM_data4:
20798 type = die_type (die, cu);
20799 result = dwarf2_const_value_data (attr, obstack, cu, &value, 32);
20800 if (result == NULL)
20801 result = write_constant_as_bytes (obstack, byte_order,
20802 type, value, len);
20803 break;
20804 case DW_FORM_data8:
20805 type = die_type (die, cu);
20806 result = dwarf2_const_value_data (attr, obstack, cu, &value, 64);
20807 if (result == NULL)
20808 result = write_constant_as_bytes (obstack, byte_order,
20809 type, value, len);
20810 break;
20811
20812 case DW_FORM_sdata:
20813 case DW_FORM_implicit_const:
20814 type = die_type (die, cu);
20815 result = write_constant_as_bytes (obstack, byte_order,
20816 type, attr->as_signed (), len);
20817 break;
20818
20819 case DW_FORM_udata:
20820 type = die_type (die, cu);
20821 result = write_constant_as_bytes (obstack, byte_order,
20822 type, attr->as_unsigned (), len);
20823 break;
20824
20825 default:
20826 complaint (_("unsupported const value attribute form: '%s'"),
20827 dwarf_form_name (attr->form));
20828 break;
20829 }
20830
20831 return result;
20832}
20833
20834/* See read.h. */
20835
20836struct type *
20838 dwarf2_per_cu_data *per_cu,
20839 dwarf2_per_objfile *per_objfile,
20840 const char **var_name)
20841{
20842 struct die_info *die;
20843
20844 dwarf2_cu *cu = per_objfile->get_cu (per_cu);
20845 if (cu == nullptr)
20846 cu = load_cu (per_cu, per_objfile, false);
20847
20848 if (cu == nullptr)
20849 return nullptr;
20850
20851 die = follow_die_offset (sect_off, per_cu->is_dwz, &cu);
20852 if (!die)
20853 return NULL;
20854
20855 if (var_name != nullptr)
20856 *var_name = var_decl_name (die, cu);
20857 return die_type (die, cu);
20858}
20859
20860/* See read.h. */
20861
20862struct type *
20863dwarf2_get_die_type (cu_offset die_offset,
20864 dwarf2_per_cu_data *per_cu,
20865 dwarf2_per_objfile *per_objfile)
20866{
20867 sect_offset die_offset_sect = per_cu->sect_off + to_underlying (die_offset);
20868 return get_die_type_at_offset (die_offset_sect, per_cu, per_objfile);
20869}
20870
20871/* Follow type unit SIG_TYPE referenced by SRC_DIE.
20872 On entry *REF_CU is the CU of SRC_DIE.
20873 On exit *REF_CU is the CU of the result.
20874 Returns NULL if the referenced DIE isn't found. */
20875
20876static struct die_info *
20877follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
20878 struct dwarf2_cu **ref_cu)
20879{
20880 struct die_info temp_die;
20881 struct dwarf2_cu *sig_cu;
20882 struct die_info *die;
20883 dwarf2_per_objfile *per_objfile = (*ref_cu)->per_objfile;
20884
20885
20886 /* While it might be nice to assert sig_type->type == NULL here,
20887 we can get here for DW_AT_imported_declaration where we need
20888 the DIE not the type. */
20889
20890 /* If necessary, add it to the queue and load its DIEs.
20891
20892 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
20893 it doesn't mean they are currently loaded. Since we require them
20894 to be loaded, we must check for ourselves. */
20895 if (maybe_queue_comp_unit (*ref_cu, sig_type, per_objfile,
20897 || per_objfile->get_cu (sig_type) == nullptr)
20898 read_signatured_type (sig_type, per_objfile);
20899
20900 sig_cu = per_objfile->get_cu (sig_type);
20901 gdb_assert (sig_cu != NULL);
20902 gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
20903 temp_die.sect_off = sig_type->type_offset_in_section;
20904 die = (struct die_info *) htab_find_with_hash (sig_cu->die_hash, &temp_die,
20905 to_underlying (temp_die.sect_off));
20906 if (die)
20907 {
20908 /* For .gdb_index version 7 keep track of included TUs.
20909 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20910 if (per_objfile->per_bfd->index_table != NULL
20911 && !per_objfile->per_bfd->index_table->version_check ())
20912 {
20913 (*ref_cu)->per_cu->imported_symtabs_push (sig_cu->per_cu);
20914 }
20915
20916 *ref_cu = sig_cu;
20917 return die;
20918 }
20919
20920 return NULL;
20921}
20922
20923/* Follow signatured type referenced by ATTR in SRC_DIE.
20924 On entry *REF_CU is the CU of SRC_DIE.
20925 On exit *REF_CU is the CU of the result.
20926 The result is the DIE of the type.
20927 If the referenced type cannot be found an error is thrown. */
20928
20929static struct die_info *
20930follow_die_sig (struct die_info *src_die, const struct attribute *attr,
20931 struct dwarf2_cu **ref_cu)
20932{
20933 ULONGEST signature = attr->as_signature ();
20934 struct signatured_type *sig_type;
20935 struct die_info *die;
20936
20937 gdb_assert (attr->form == DW_FORM_ref_sig8);
20938
20939 sig_type = lookup_signatured_type (*ref_cu, signature);
20940 /* sig_type will be NULL if the signatured type is missing from
20941 the debug info. */
20942 if (sig_type == NULL)
20943 {
20944 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20945 " from DIE at %s [in module %s]"),
20946 hex_string (signature), sect_offset_str (src_die->sect_off),
20947 objfile_name ((*ref_cu)->per_objfile->objfile));
20948 }
20949
20950 die = follow_die_sig_1 (src_die, sig_type, ref_cu);
20951 if (die == NULL)
20952 {
20953 src_die->error_dump ();
20954 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20955 " from DIE at %s [in module %s]"),
20956 hex_string (signature), sect_offset_str (src_die->sect_off),
20957 objfile_name ((*ref_cu)->per_objfile->objfile));
20958 }
20959
20960 return die;
20961}
20962
20963/* Get the type specified by SIGNATURE referenced in DIE/CU,
20964 reading in and processing the type unit if necessary. */
20965
20966static struct type *
20967get_signatured_type (struct die_info *die, ULONGEST signature,
20968 struct dwarf2_cu *cu)
20969{
20970 dwarf2_per_objfile *per_objfile = cu->per_objfile;
20971 struct signatured_type *sig_type;
20972 struct dwarf2_cu *type_cu;
20973 struct die_info *type_die;
20974 struct type *type;
20975
20976 sig_type = lookup_signatured_type (cu, signature);
20977 /* sig_type will be NULL if the signatured type is missing from
20978 the debug info. */
20979 if (sig_type == NULL)
20980 {
20981 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20982 " from DIE at %s [in module %s]"),
20983 hex_string (signature), sect_offset_str (die->sect_off),
20984 objfile_name (per_objfile->objfile));
20985 return build_error_marker_type (cu, die);
20986 }
20987
20988 /* If we already know the type we're done. */
20989 type = per_objfile->get_type_for_signatured_type (sig_type);
20990 if (type != nullptr)
20991 return type;
20992
20993 type_cu = cu;
20994 type_die = follow_die_sig_1 (die, sig_type, &type_cu);
20995 if (type_die != NULL)
20996 {
20997 /* N.B. We need to call get_die_type to ensure only one type for this DIE
20998 is created. This is important, for example, because for c++ classes
20999 we need TYPE_NAME set which is only done by new_symbol. Blech. */
21000 type = read_type_die (type_die, type_cu);
21001 if (type == NULL)
21002 {
21003 complaint (_("Dwarf Error: Cannot build signatured type %s"
21004 " referenced from DIE at %s [in module %s]"),
21005 hex_string (signature), sect_offset_str (die->sect_off),
21006 objfile_name (per_objfile->objfile));
21007 type = build_error_marker_type (cu, die);
21008 }
21009 }
21010 else
21011 {
21012 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
21013 " from DIE at %s [in module %s]"),
21014 hex_string (signature), sect_offset_str (die->sect_off),
21015 objfile_name (per_objfile->objfile));
21016 type = build_error_marker_type (cu, die);
21017 }
21018
21019 per_objfile->set_type_for_signatured_type (sig_type, type);
21020
21021 return type;
21022}
21023
21024/* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
21025 reading in and processing the type unit if necessary. */
21026
21027static struct type *
21028get_DW_AT_signature_type (struct die_info *die, const struct attribute *attr,
21029 struct dwarf2_cu *cu) /* ARI: editCase function */
21030{
21031 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
21032 if (attr->form_is_ref ())
21033 {
21034 struct dwarf2_cu *type_cu = cu;
21035 struct die_info *type_die = follow_die_ref (die, attr, &type_cu);
21036
21037 return read_type_die (type_die, type_cu);
21038 }
21039 else if (attr->form == DW_FORM_ref_sig8)
21040 {
21041 return get_signatured_type (die, attr->as_signature (), cu);
21042 }
21043 else
21044 {
21045 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21046
21047 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
21048 " at %s [in module %s]"),
21050 objfile_name (per_objfile->objfile));
21051 return build_error_marker_type (cu, die);
21052 }
21053}
21054
21055/* Load the DIEs associated with type unit PER_CU into memory. */
21056
21057static void
21059 dwarf2_per_objfile *per_objfile)
21060{
21061 struct signatured_type *sig_type;
21062
21063 /* We have the per_cu, but we need the signatured_type.
21064 Fortunately this is an easy translation. */
21065 gdb_assert (per_cu->is_debug_types);
21066 sig_type = (struct signatured_type *) per_cu;
21067
21068 gdb_assert (per_objfile->get_cu (per_cu) == nullptr);
21069
21070 read_signatured_type (sig_type, per_objfile);
21071
21072 gdb_assert (per_objfile->get_cu (per_cu) != nullptr);
21073}
21074
21075/* Read in a signatured type and build its CU and DIEs.
21076 If the type is a stub for the real type in a DWO file,
21077 read in the real type from the DWO file as well. */
21078
21079static void
21081 dwarf2_per_objfile *per_objfile)
21082{
21083 gdb_assert (sig_type->is_debug_types);
21084 gdb_assert (per_objfile->get_cu (sig_type) == nullptr);
21085
21086 cutu_reader reader (sig_type, per_objfile, nullptr, nullptr, false);
21087
21088 if (!reader.dummy_p)
21089 {
21090 struct dwarf2_cu *cu = reader.cu;
21091 const gdb_byte *info_ptr = reader.info_ptr;
21092
21093 gdb_assert (cu->die_hash == NULL);
21094 cu->die_hash =
21095 htab_create_alloc_ex (cu->header.get_length_without_initial () / 12,
21098 NULL,
21099 &cu->comp_unit_obstack,
21100 hashtab_obstack_allocate,
21101 dummy_obstack_deallocate);
21102
21103 if (reader.comp_unit_die->has_children)
21104 reader.comp_unit_die->child
21105 = read_die_and_siblings (&reader, info_ptr, &info_ptr,
21106 reader.comp_unit_die);
21107 cu->dies = reader.comp_unit_die;
21108 /* comp_unit_die is not stored in die_hash, no need. */
21109
21110 /* We try not to read any attributes in this function, because
21111 not all CUs needed for references have been loaded yet, and
21112 symbol table processing isn't initialized. But we have to
21113 set the CU language, or we won't be able to build types
21114 correctly. Similarly, if we do not read the producer, we can
21115 not apply producer-specific interpretation. */
21117
21118 reader.keep ();
21119 }
21120
21121 sig_type->tu_read = 1;
21122}
21123
21124/* Decode simple location descriptions.
21125
21126 Given a pointer to a DWARF block that defines a location, compute
21127 the location. Returns true if the expression was computable by
21128 this function, false otherwise. On a true return, *RESULT is set.
21129
21130 Note that this function does not implement a full DWARF expression
21131 evaluator. Instead, it is used for a few limited purposes:
21132
21133 - Getting the address of a symbol that has a constant address. For
21134 example, if a symbol has a location like "DW_OP_addr", the address
21135 can be extracted.
21136
21137 - Getting the offset of a virtual function in its vtable. There
21138 are two forms of this, one of which involves DW_OP_deref -- so this
21139 function handles derefs in a peculiar way to make this 'work'.
21140 (Probably this area should be rewritten.)
21141
21142 - Getting the offset of a field, when it is constant.
21143
21144 Opcodes that cannot be part of a constant expression, for example
21145 those involving registers, simply result in a return of
21146 'false'.
21147
21148 This function may emit a complaint. */
21149
21150static bool
21151decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu,
21152 CORE_ADDR *result)
21153{
21154 struct objfile *objfile = cu->per_objfile->objfile;
21155 size_t i;
21156 size_t size = blk->size;
21157 const gdb_byte *data = blk->data;
21158 CORE_ADDR stack[64];
21159 int stacki;
21160 unsigned int bytes_read;
21161 gdb_byte op;
21162
21163 *result = 0;
21164 i = 0;
21165 stacki = 0;
21166 stack[stacki] = 0;
21167 stack[++stacki] = 0;
21168
21169 while (i < size)
21170 {
21171 op = data[i++];
21172 switch (op)
21173 {
21174 case DW_OP_lit0:
21175 case DW_OP_lit1:
21176 case DW_OP_lit2:
21177 case DW_OP_lit3:
21178 case DW_OP_lit4:
21179 case DW_OP_lit5:
21180 case DW_OP_lit6:
21181 case DW_OP_lit7:
21182 case DW_OP_lit8:
21183 case DW_OP_lit9:
21184 case DW_OP_lit10:
21185 case DW_OP_lit11:
21186 case DW_OP_lit12:
21187 case DW_OP_lit13:
21188 case DW_OP_lit14:
21189 case DW_OP_lit15:
21190 case DW_OP_lit16:
21191 case DW_OP_lit17:
21192 case DW_OP_lit18:
21193 case DW_OP_lit19:
21194 case DW_OP_lit20:
21195 case DW_OP_lit21:
21196 case DW_OP_lit22:
21197 case DW_OP_lit23:
21198 case DW_OP_lit24:
21199 case DW_OP_lit25:
21200 case DW_OP_lit26:
21201 case DW_OP_lit27:
21202 case DW_OP_lit28:
21203 case DW_OP_lit29:
21204 case DW_OP_lit30:
21205 case DW_OP_lit31:
21206 stack[++stacki] = op - DW_OP_lit0;
21207 break;
21208
21209 case DW_OP_addr:
21210 stack[++stacki]
21211 = (CORE_ADDR) cu->header.read_address (objfile->obfd.get (),
21212 &data[i],
21213 &bytes_read);
21214 i += bytes_read;
21215 break;
21216
21217 case DW_OP_const1u:
21218 stack[++stacki] = read_1_byte (objfile->obfd.get (), &data[i]);
21219 i += 1;
21220 break;
21221
21222 case DW_OP_const1s:
21223 stack[++stacki] = read_1_signed_byte (objfile->obfd.get (), &data[i]);
21224 i += 1;
21225 break;
21226
21227 case DW_OP_const2u:
21228 stack[++stacki] = read_2_bytes (objfile->obfd.get (), &data[i]);
21229 i += 2;
21230 break;
21231
21232 case DW_OP_const2s:
21233 stack[++stacki] = read_2_signed_bytes (objfile->obfd.get (), &data[i]);
21234 i += 2;
21235 break;
21236
21237 case DW_OP_const4u:
21238 stack[++stacki] = read_4_bytes (objfile->obfd.get (), &data[i]);
21239 i += 4;
21240 break;
21241
21242 case DW_OP_const4s:
21243 stack[++stacki] = read_4_signed_bytes (objfile->obfd.get (), &data[i]);
21244 i += 4;
21245 break;
21246
21247 case DW_OP_const8u:
21248 stack[++stacki] = read_8_bytes (objfile->obfd.get (), &data[i]);
21249 i += 8;
21250 break;
21251
21252 case DW_OP_constu:
21253 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
21254 &bytes_read);
21255 i += bytes_read;
21256 break;
21257
21258 case DW_OP_consts:
21259 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
21260 i += bytes_read;
21261 break;
21262
21263 case DW_OP_dup:
21264 stack[stacki + 1] = stack[stacki];
21265 stacki++;
21266 break;
21267
21268 case DW_OP_plus:
21269 stack[stacki - 1] += stack[stacki];
21270 stacki--;
21271 break;
21272
21273 case DW_OP_plus_uconst:
21274 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
21275 &bytes_read);
21276 i += bytes_read;
21277 break;
21278
21279 case DW_OP_minus:
21280 stack[stacki - 1] -= stack[stacki];
21281 stacki--;
21282 break;
21283
21284 case DW_OP_deref:
21285 /* If we're not the last op, then we definitely can't encode
21286 this using GDB's address_class enum. This is valid for partial
21287 global symbols, although the variable's address will be bogus
21288 in the psymtab. */
21289 if (i < size)
21290 return false;
21291 break;
21292
21293 case DW_OP_addrx:
21294 case DW_OP_GNU_addr_index:
21295 case DW_OP_GNU_const_index:
21296 stack[++stacki]
21297 = (CORE_ADDR) read_addr_index_from_leb128 (cu, &data[i],
21298 &bytes_read);
21299 i += bytes_read;
21300 break;
21301
21302 default:
21303 return false;
21304 }
21305
21306 /* Enforce maximum stack depth of SIZE-1 to avoid writing
21307 outside of the allocated space. Also enforce minimum>0. */
21308 if (stacki >= ARRAY_SIZE (stack) - 1)
21309 {
21310 complaint (_("location description stack overflow"));
21311 return false;
21312 }
21313
21314 if (stacki <= 0)
21315 {
21316 complaint (_("location description stack underflow"));
21317 return false;
21318 }
21319 }
21320
21321 *result = stack[stacki];
21322 return true;
21323}
21324
21325/* memory allocation interface */
21326
21327static struct dwarf_block *
21329{
21330 return XOBNEW (&cu->comp_unit_obstack, struct dwarf_block);
21331}
21332
21333
21334
21335/* Macro support. */
21336
21337/* An overload of dwarf_decode_macros that finds the correct section
21338 and ensures it is read in before calling the other overload. */
21339
21340static void
21341dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
21342 int section_is_gnu)
21343{
21344 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21345 struct objfile *objfile = per_objfile->objfile;
21346 const struct line_header *lh = cu->line_header;
21347 unsigned int offset_size = cu->header.offset_size;
21349 const char *section_name;
21350
21351 if (cu->dwo_unit != nullptr)
21352 {
21353 if (section_is_gnu)
21354 {
21355 section = &cu->dwo_unit->dwo_file->sections.macro;
21356 section_name = ".debug_macro.dwo";
21357 }
21358 else
21359 {
21360 section = &cu->dwo_unit->dwo_file->sections.macinfo;
21361 section_name = ".debug_macinfo.dwo";
21362 }
21363 }
21364 else
21365 {
21366 if (section_is_gnu)
21367 {
21368 section = &per_objfile->per_bfd->macro;
21369 section_name = ".debug_macro";
21370 }
21371 else
21372 {
21373 section = &per_objfile->per_bfd->macinfo;
21374 section_name = ".debug_macinfo";
21375 }
21376 }
21377
21378 section->read (objfile);
21379 if (section->buffer == nullptr)
21380 {
21381 complaint (_("missing %s section"), section_name);
21382 return;
21383 }
21384
21385 buildsym_compunit *builder = cu->get_builder ();
21386
21387 struct dwarf2_section_info *str_offsets_section;
21388 struct dwarf2_section_info *str_section;
21389 gdb::optional<ULONGEST> str_offsets_base;
21390
21391 if (cu->dwo_unit != nullptr)
21392 {
21393 str_offsets_section = &cu->dwo_unit->dwo_file
21394 ->sections.str_offsets;
21395 str_section = &cu->dwo_unit->dwo_file->sections.str;
21396 str_offsets_base = cu->header.addr_size;
21397 }
21398 else
21399 {
21400 str_offsets_section = &per_objfile->per_bfd->str_offsets;
21401 str_section = &per_objfile->per_bfd->str;
21402 str_offsets_base = cu->str_offsets_base;
21403 }
21404
21405 dwarf_decode_macros (per_objfile, builder, section, lh,
21406 offset_size, offset, str_section, str_offsets_section,
21407 str_offsets_base, section_is_gnu, cu);
21408}
21409
21410/* Return the .debug_loc section to use for CU.
21411 For DWO files use .debug_loc.dwo. */
21412
21413static struct dwarf2_section_info *
21415{
21416 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21417
21418 if (cu->dwo_unit)
21419 {
21420 struct dwo_sections *sections = &cu->dwo_unit->dwo_file->sections;
21421
21422 return cu->header.version >= 5 ? &sections->loclists : &sections->loc;
21423 }
21424 return (cu->header.version >= 5 ? &per_objfile->per_bfd->loclists
21425 : &per_objfile->per_bfd->loc);
21426}
21427
21428/* Return the .debug_rnglists section to use for CU. */
21429static struct dwarf2_section_info *
21430cu_debug_rnglists_section (struct dwarf2_cu *cu, dwarf_tag tag)
21431{
21432 if (cu->header.version < 5)
21433 error (_(".debug_rnglists section cannot be used in DWARF %d"),
21434 cu->header.version);
21436
21437 /* Make sure we read the .debug_rnglists section from the file that
21438 contains the DW_AT_ranges attribute we are reading. Normally that
21439 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
21440 or DW_TAG_skeleton unit, we always want to read from objfile/linked
21441 program. */
21442 if (cu->dwo_unit != nullptr
21443 && tag != DW_TAG_compile_unit
21444 && tag != DW_TAG_skeleton_unit)
21445 {
21446 struct dwo_sections *sections = &cu->dwo_unit->dwo_file->sections;
21447
21448 if (sections->rnglists.size > 0)
21449 return &sections->rnglists;
21450 else
21451 error (_(".debug_rnglists section is missing from .dwo file."));
21452 }
21454}
21455
21456/* A helper function that fills in a dwarf2_loclist_baton. */
21457
21458static void
21460 struct dwarf2_loclist_baton *baton,
21461 const struct attribute *attr)
21462{
21463 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21465
21466 section->read (per_objfile->objfile);
21467
21468 baton->per_objfile = per_objfile;
21469 baton->per_cu = cu->per_cu;
21470 gdb_assert (baton->per_cu);
21471 /* We don't know how long the location list is, but make sure we
21472 don't run off the edge of the section. */
21473 baton->size = section->size - attr->as_unsigned ();
21474 baton->data = section->buffer + attr->as_unsigned ();
21475 if (cu->base_address.has_value ())
21476 baton->base_address = *cu->base_address;
21477 else
21478 baton->base_address = {};
21479 baton->from_dwo = cu->dwo_unit != NULL;
21480}
21481
21482static void
21483dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
21484 struct dwarf2_cu *cu, int is_block)
21485{
21486 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21487 struct objfile *objfile = per_objfile->objfile;
21489
21490 if (attr->form_is_section_offset ()
21491 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
21492 the section. If so, fall through to the complaint in the
21493 other branch. */
21494 && attr->as_unsigned () < section->get_size (objfile))
21495 {
21496 struct dwarf2_loclist_baton *baton;
21497
21498 baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_loclist_baton);
21499
21500 fill_in_loclist_baton (cu, baton, attr);
21501
21502 if (!cu->base_address.has_value ())
21503 complaint (_("Location list used without "
21504 "specifying the CU base address."));
21505
21506 sym->set_aclass_index ((is_block
21509 SYMBOL_LOCATION_BATON (sym) = baton;
21510 }
21511 else
21512 {
21513 struct dwarf2_locexpr_baton *baton;
21514
21515 baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
21516 baton->per_objfile = per_objfile;
21517 baton->per_cu = cu->per_cu;
21518 gdb_assert (baton->per_cu);
21519
21520 if (attr->form_is_block ())
21521 {
21522 /* Note that we're just copying the block's data pointer
21523 here, not the actual data. We're still pointing into the
21524 info_buffer for SYM's objfile; right now we never release
21525 that buffer, but when we do clean up properly this may
21526 need to change. */
21527 struct dwarf_block *block = attr->as_block ();
21528 baton->size = block->size;
21529 baton->data = block->data;
21530 }
21531 else
21532 {
21533 dwarf2_invalid_attrib_class_complaint ("location description",
21534 sym->natural_name ());
21535 baton->size = 0;
21536 }
21537
21538 sym->set_aclass_index ((is_block
21541 SYMBOL_LOCATION_BATON (sym) = baton;
21542 }
21543}
21544
21545/* See read.h. */
21546
21547const comp_unit_head *
21549{
21550 if (!m_header_read_in)
21551 {
21552 const gdb_byte *info_ptr
21553 = this->section->buffer + to_underlying (this->sect_off);
21554
21555 read_comp_unit_head (&m_header, info_ptr, this->section,
21557
21558 m_header_read_in = true;
21559 }
21560
21561 return &m_header;
21562}
21563
21564/* See read.h. */
21565
21566int
21568{
21569 return this->get_header ()->addr_size;
21570}
21571
21572/* See read.h. */
21573
21574int
21576{
21577 return this->get_header ()->offset_size;
21578}
21579
21580/* See read.h. */
21581
21582int
21584{
21585 const comp_unit_head *header = this->get_header ();
21586
21587 if (header->version == 2)
21588 return header->addr_size;
21589 else
21590 return header->offset_size;
21591}
21592
21593/* A helper function for dwarf2_find_containing_comp_unit that returns
21594 the index of the result, and that searches a vector. It will
21595 return a result even if the offset in question does not actually
21596 occur in any CU. This is separate so that it can be unit
21597 tested. */
21598
21599static int
21601 (sect_offset sect_off,
21602 unsigned int offset_in_dwz,
21603 const std::vector<dwarf2_per_cu_data_up> &all_units)
21604{
21605 int low, high;
21606
21607 low = 0;
21608 high = all_units.size () - 1;
21609 while (high > low)
21610 {
21611 struct dwarf2_per_cu_data *mid_cu;
21612 int mid = low + (high - low) / 2;
21613
21614 mid_cu = all_units[mid].get ();
21615 if (mid_cu->is_dwz > offset_in_dwz
21616 || (mid_cu->is_dwz == offset_in_dwz
21617 && mid_cu->sect_off + mid_cu->length () > sect_off))
21618 high = mid;
21619 else
21620 low = mid + 1;
21621 }
21622 gdb_assert (low == high);
21623 return low;
21624}
21625
21626/* Locate the .debug_info compilation unit from CU's objfile which contains
21627 the DIE at OFFSET. Raises an error on failure. */
21628
21629static struct dwarf2_per_cu_data *
21631 unsigned int offset_in_dwz,
21633{
21635 (sect_off, offset_in_dwz, per_bfd->all_units);
21636 dwarf2_per_cu_data *this_cu = per_bfd->all_units[low].get ();
21637
21638 if (this_cu->is_dwz != offset_in_dwz || this_cu->sect_off > sect_off)
21639 {
21640 if (low == 0 || this_cu->is_dwz != offset_in_dwz)
21641 error (_("Dwarf Error: could not find partial DIE containing "
21642 "offset %s [in module %s]"),
21644 bfd_get_filename (per_bfd->obfd));
21645
21646 gdb_assert (per_bfd->all_units[low-1]->sect_off
21647 <= sect_off);
21648 return per_bfd->all_units[low - 1].get ();
21649 }
21650 else
21651 {
21652 if (low == per_bfd->all_units.size () - 1
21653 && sect_off >= this_cu->sect_off + this_cu->length ())
21654 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off));
21655 gdb_assert (sect_off < this_cu->sect_off + this_cu->length ());
21656 return this_cu;
21657 }
21658}
21659
21660#if GDB_SELF_TEST
21661
21662namespace selftests {
21663namespace find_containing_comp_unit {
21664
21665static void
21666run_test ()
21667{
21669 dwarf2_per_cu_data *one_ptr = one.get ();
21671 dwarf2_per_cu_data *two_ptr = two.get ();
21673 dwarf2_per_cu_data *three_ptr = three.get ();
21675 dwarf2_per_cu_data *four_ptr = four.get ();
21676
21677 one->set_length (5);
21678 two->sect_off = sect_offset (one->length ());
21679 two->set_length (7);
21680
21681 three->set_length (5);
21682 three->is_dwz = 1;
21683 four->sect_off = sect_offset (three->length ());
21684 four->set_length (7);
21685 four->is_dwz = 1;
21686
21687 std::vector<dwarf2_per_cu_data_up> units;
21688 units.push_back (std::move (one));
21689 units.push_back (std::move (two));
21690 units.push_back (std::move (three));
21691 units.push_back (std::move (four));
21692
21693 int result;
21694
21695 result = dwarf2_find_containing_comp_unit (sect_offset (0), 0, units);
21696 SELF_CHECK (units[result].get () == one_ptr);
21697 result = dwarf2_find_containing_comp_unit (sect_offset (3), 0, units);
21698 SELF_CHECK (units[result].get () == one_ptr);
21699 result = dwarf2_find_containing_comp_unit (sect_offset (5), 0, units);
21700 SELF_CHECK (units[result].get () == two_ptr);
21701
21702 result = dwarf2_find_containing_comp_unit (sect_offset (0), 1, units);
21703 SELF_CHECK (units[result].get () == three_ptr);
21704 result = dwarf2_find_containing_comp_unit (sect_offset (3), 1, units);
21705 SELF_CHECK (units[result].get () == three_ptr);
21706 result = dwarf2_find_containing_comp_unit (sect_offset (5), 1, units);
21707 SELF_CHECK (units[result].get () == four_ptr);
21708}
21709
21710}
21711}
21712
21713#endif /* GDB_SELF_TEST */
21714
21715/* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
21716
21717static void
21718prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
21719 enum language pretend_language)
21720{
21721 struct attribute *attr;
21722
21723 cu->producer = dwarf2_string_attr (comp_unit_die, DW_AT_producer, cu);
21724
21725 /* Set the language we're debugging. */
21726 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
21727 enum language lang;
21728 if (cu->producer != nullptr
21729 && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
21730 {
21731 /* The XLCL doesn't generate DW_LANG_OpenCL because this
21732 attribute is not standardised yet. As a workaround for the
21733 language detection we fall back to the DW_AT_producer
21734 string. */
21735 lang = language_opencl;
21736 }
21737 else if (cu->producer != nullptr
21738 && strstr (cu->producer, "GNU Go ") != NULL)
21739 {
21740 /* Similar hack for Go. */
21741 lang = language_go;
21742 }
21743 else if (attr != nullptr)
21745 else
21746 lang = pretend_language;
21747
21748 cu->language_defn = language_def (lang);
21749
21750 switch (comp_unit_die->tag)
21751 {
21752 case DW_TAG_compile_unit:
21753 cu->per_cu->set_unit_type (DW_UT_compile);
21754 break;
21755 case DW_TAG_partial_unit:
21756 cu->per_cu->set_unit_type (DW_UT_partial);
21757 break;
21758 case DW_TAG_type_unit:
21759 cu->per_cu->set_unit_type (DW_UT_type);
21760 break;
21761 default:
21762 error (_("Dwarf Error: unexpected tag '%s' at offset %s"),
21763 dwarf_tag_name (comp_unit_die->tag),
21765 }
21766
21767 cu->per_cu->set_lang (lang);
21768}
21769
21770/* See read.h. */
21771
21772dwarf2_cu *
21774{
21775 auto it = m_dwarf2_cus.find (per_cu);
21776 if (it == m_dwarf2_cus.end ())
21777 return nullptr;
21778
21779 return it->second.get ();
21780}
21781
21782/* See read.h. */
21783
21784void
21786 std::unique_ptr<dwarf2_cu> cu)
21787{
21788 gdb_assert (this->get_cu (per_cu) == nullptr);
21789
21790 m_dwarf2_cus[per_cu] = std::move (cu);
21791}
21792
21793/* See read.h. */
21794
21795void
21797{
21798 dwarf_read_debug_printf_v ("running");
21799
21800 /* This is not expected to be called in the middle of CU expansion. There is
21801 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
21802 loaded in memory. Calling age_comp_units while the queue is in use could
21803 make us free the DIEs for a CU that is in the queue and therefore break
21804 that invariant. */
21805 gdb_assert (!queue.has_value ());
21806
21807 /* Start by clearing all marks. */
21808 for (const auto &pair : m_dwarf2_cus)
21809 pair.second->clear_mark ();
21810
21811 /* Traverse all CUs, mark them and their dependencies if used recently
21812 enough. */
21813 for (const auto &pair : m_dwarf2_cus)
21814 {
21815 dwarf2_cu *cu = pair.second.get ();
21816
21817 cu->last_used++;
21818 if (cu->last_used <= dwarf_max_cache_age)
21819 cu->mark ();
21820 }
21821
21822 /* Delete all CUs still not marked. */
21823 for (auto it = m_dwarf2_cus.begin (); it != m_dwarf2_cus.end ();)
21824 {
21825 dwarf2_cu *cu = it->second.get ();
21826
21827 if (!cu->is_marked ())
21828 {
21829 dwarf_read_debug_printf_v ("deleting old CU %s",
21831 it = m_dwarf2_cus.erase (it);
21832 }
21833 else
21834 it++;
21835 }
21836}
21837
21838/* See read.h. */
21839
21840void
21842{
21843 auto it = m_dwarf2_cus.find (per_cu);
21844 if (it == m_dwarf2_cus.end ())
21845 return;
21846
21847 m_dwarf2_cus.erase (it);
21848}
21849
21854
21855/* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
21856 We store these in a hash table separate from the DIEs, and preserve them
21857 when the DIEs are flushed out of cache.
21858
21859 The CU "per_cu" pointer is needed because offset alone is not enough to
21860 uniquely identify the type. A file may have multiple .debug_types sections,
21861 or the type may come from a DWO file. Furthermore, while it's more logical
21862 to use per_cu->section+offset, with Fission the section with the data is in
21863 the DWO file but we don't know that section at the point we need it.
21864 We have to use something in dwarf2_per_cu_data (or the pointer to it)
21865 because we can enter the lookup routine, get_die_type_at_offset, from
21866 outside this file, and thus won't necessarily have PER_CU->cu.
21867 Fortunately, PER_CU is stable for the life of the objfile. */
21868
21870{
21872 sect_offset sect_off;
21873 struct type *type;
21874};
21875
21876/* Hash function for a dwarf2_per_cu_offset_and_type. */
21877
21878static hashval_t
21880{
21881 const struct dwarf2_per_cu_offset_and_type *ofs
21882 = (const struct dwarf2_per_cu_offset_and_type *) item;
21883
21884 return (uintptr_t) ofs->per_cu + to_underlying (ofs->sect_off);
21885}
21886
21887/* Equality function for a dwarf2_per_cu_offset_and_type. */
21888
21889static int
21890per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
21891{
21892 const struct dwarf2_per_cu_offset_and_type *ofs_lhs
21893 = (const struct dwarf2_per_cu_offset_and_type *) item_lhs;
21894 const struct dwarf2_per_cu_offset_and_type *ofs_rhs
21895 = (const struct dwarf2_per_cu_offset_and_type *) item_rhs;
21896
21897 return (ofs_lhs->per_cu == ofs_rhs->per_cu
21898 && ofs_lhs->sect_off == ofs_rhs->sect_off);
21899}
21900
21901/* Set the type associated with DIE to TYPE. Save it in CU's hash
21902 table if necessary. For convenience, return TYPE.
21903
21904 The DIEs reading must have careful ordering to:
21905 * Not cause infinite loops trying to read in DIEs as a prerequisite for
21906 reading current DIE.
21907 * Not trying to dereference contents of still incompletely read in types
21908 while reading in other DIEs.
21909 * Enable referencing still incompletely read in types just by a pointer to
21910 the type without accessing its fields.
21911
21912 Therefore caller should follow these rules:
21913 * Try to fetch any prerequisite types we may need to build this DIE type
21914 before building the type and calling set_die_type.
21915 * After building type call set_die_type for current DIE as soon as
21916 possible before fetching more types to complete the current type.
21917 * Make the type as complete as possible before fetching more types. */
21918
21919static struct type *
21920set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
21921 bool skip_data_location)
21922{
21923 dwarf2_per_objfile *per_objfile = cu->per_objfile;
21924 struct dwarf2_per_cu_offset_and_type **slot, ofs;
21925 struct objfile *objfile = per_objfile->objfile;
21926 struct attribute *attr;
21927 struct dynamic_prop prop;
21928
21929 /* For Ada types, make sure that the gnat-specific data is always
21930 initialized (if not already set). There are a few types where
21931 we should not be doing so, because the type-specific area is
21932 already used to hold some other piece of info (eg: TYPE_CODE_FLT
21933 where the type-specific area is used to store the floatformat).
21934 But this is not a problem, because the gnat-specific information
21935 is actually not needed for these types. */
21936 if (need_gnat_info (cu)
21937 && type->code () != TYPE_CODE_FUNC
21938 && type->code () != TYPE_CODE_FLT
21939 && type->code () != TYPE_CODE_METHODPTR
21940 && type->code () != TYPE_CODE_MEMBERPTR
21941 && type->code () != TYPE_CODE_METHOD
21942 && type->code () != TYPE_CODE_FIXED_POINT
21945
21946 /* Read DW_AT_allocated and set in type. */
21947 attr = dwarf2_attr (die, DW_AT_allocated, cu);
21948 if (attr != NULL)
21949 {
21950 struct type *prop_type = cu->addr_sized_int_type (false);
21951 if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
21953 }
21954
21955 /* Read DW_AT_associated and set in type. */
21956 attr = dwarf2_attr (die, DW_AT_associated, cu);
21957 if (attr != NULL)
21958 {
21959 struct type *prop_type = cu->addr_sized_int_type (false);
21960 if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
21962 }
21963
21964 /* Read DW_AT_rank and set in type. */
21965 attr = dwarf2_attr (die, DW_AT_rank, cu);
21966 if (attr != NULL)
21967 {
21968 struct type *prop_type = cu->addr_sized_int_type (false);
21969 if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
21971 }
21972
21973 /* Read DW_AT_data_location and set in type. */
21974 if (!skip_data_location)
21975 {
21976 attr = dwarf2_attr (die, DW_AT_data_location, cu);
21977 if (attr_to_dynamic_prop (attr, die, cu, &prop, cu->addr_type ()))
21979 }
21980
21981 if (per_objfile->die_type_hash == NULL)
21982 per_objfile->die_type_hash
21983 = htab_up (htab_create_alloc (127,
21986 NULL, xcalloc, xfree));
21987
21988 ofs.per_cu = cu->per_cu;
21989 ofs.sect_off = die->sect_off;
21990 ofs.type = type;
21991 slot = (struct dwarf2_per_cu_offset_and_type **)
21992 htab_find_slot (per_objfile->die_type_hash.get (), &ofs, INSERT);
21993 if (*slot)
21994 complaint (_("A problem internal to GDB: DIE %s has type already set"),
21995 sect_offset_str (die->sect_off));
21996 *slot = XOBNEW (&objfile->objfile_obstack,
21998 **slot = ofs;
21999 return type;
22000}
22001
22002/* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
22003 or return NULL if the die does not have a saved type. */
22004
22005static struct type *
22006get_die_type_at_offset (sect_offset sect_off,
22007 dwarf2_per_cu_data *per_cu,
22008 dwarf2_per_objfile *per_objfile)
22009{
22010 struct dwarf2_per_cu_offset_and_type *slot, ofs;
22011
22012 if (per_objfile->die_type_hash == NULL)
22013 return NULL;
22014
22015 ofs.per_cu = per_cu;
22016 ofs.sect_off = sect_off;
22017 slot = ((struct dwarf2_per_cu_offset_and_type *)
22018 htab_find (per_objfile->die_type_hash.get (), &ofs));
22019 if (slot)
22020 return slot->type;
22021 else
22022 return NULL;
22023}
22024
22025/* Look up the type for DIE in CU in die_type_hash,
22026 or return NULL if DIE does not have a saved type. */
22027
22028static struct type *
22029get_die_type (struct die_info *die, struct dwarf2_cu *cu)
22030{
22031 return get_die_type_at_offset (die->sect_off, cu->per_cu, cu->per_objfile);
22032}
22033
22036
22037static void
22038show_check_physname (struct ui_file *file, int from_tty,
22039 struct cmd_list_element *c, const char *value)
22040{
22041 gdb_printf (file,
22042 _("Whether to check \"physname\" is %s.\n"),
22043 value);
22044}
22045
22047void
22049{
22051 _("\
22052Set DWARF specific variables.\n\
22053Configure DWARF variables such as the cache size."),
22054 _("\
22055Show DWARF specific variables.\n\
22056Show DWARF variables such as the cache size."),
22059
22060 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
22061 &dwarf_max_cache_age, _("\
22062Set the upper bound on the age of cached DWARF compilation units."), _("\
22063Show the upper bound on the age of cached DWARF compilation units."), _("\
22064A higher limit means that cached compilation units will be stored\n\
22065in memory longer, and more total memory will be used. Zero disables\n\
22066caching, which can slow down startup."),
22067 NULL,
22071
22073Set debugging of the DWARF reader."), _("\
22074Show debugging of the DWARF reader."), _("\
22075When enabled (non-zero), debugging messages are printed during DWARF\n\
22076reading and symtab expansion. A value of 1 (one) provides basic\n\
22077information. A value greater than 1 provides more verbose information."),
22078 NULL,
22079 NULL,
22081
22083Set debugging of the DWARF DIE reader."), _("\
22084Show debugging of the DWARF DIE reader."), _("\
22085When enabled (non-zero), DIEs are dumped after they are read in.\n\
22086The value is the maximum depth to print."),
22087 NULL,
22088 NULL,
22090
22092Set debugging of the dwarf line reader."), _("\
22093Show debugging of the dwarf line reader."), _("\
22094When enabled (non-zero), line number entries are dumped as they are read in.\n\
22095A value of 1 (one) provides basic information.\n\
22096A value greater than 1 provides more verbose information."),
22097 NULL,
22098 NULL,
22100
22101 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
22102Set cross-checking of \"physname\" code against demangler."), _("\
22103Show cross-checking of \"physname\" code against demangler."), _("\
22104When enabled, GDB's internal \"physname\" code is checked against\n\
22105the demangler."),
22106 NULL, show_check_physname,
22108
22115
22122
22123#if GDB_SELF_TEST
22124 selftests::register_test ("dw2_expand_symtabs_matching",
22125 selftests::dw2_expand_symtabs_matching::run_test);
22126 selftests::register_test ("dwarf2_find_containing_comp_unit",
22127 selftests::find_containing_comp_unit::run_test);
22128#endif
22129}
constexpr string_view get()
Definition 70483.cc:49
#define bits(obj, st, fn)
const char *const name
std::unique_ptr< struct abbrev_table > abbrev_table_up
Definition abbrev.h:61
void * xmalloc(YYSIZE_T)
void xfree(void *)
const struct symbol_block_ops ada_function_alias_funcs
const struct symbol_computed_ops ada_imported_funcs
int code
Definition ada-lex.l:670
static struct @5 attributes[]
gdb_static_assert(sizeof(splay_tree_key) >=sizeof(CORE_ADDR *))
void * xcalloc(size_t number, size_t size)
Definition alloc.c:85
bool operator==(const T &lhs, const T &rhs)
struct blockranges * make_blockranges(struct objfile *objfile, const std::vector< blockrange > &rangevec)
Definition block.c:818
int blockvector_contains_pc(const struct blockvector *bv, CORE_ADDR pc)
Definition block.c:208
const struct bfd_build_id * build_id_bfd_get(bfd *abfd)
Definition build-id.c:34
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:727
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
@ CALL_SITE_PARAMETER_FB_OFFSET
Definition call-site.h:41
@ CALL_SITE_PARAMETER_DWARF_REG
Definition call-site.h:38
@ CALL_SITE_PARAMETER_PARAM_OFFSET
Definition call-site.h:44
abbrev_table * find(struct dwarf2_section_info *section, sect_offset offset)
void add(abbrev_table_up table)
std::unique_ptr< cooked_index_shard > release()
Definition read.c:4661
cutu_reader * preserve(std::unique_ptr< cutu_reader > reader)
Definition read.c:4635
DISABLE_COPY_AND_ASSIGN(cooked_index_storage)
static int eq_cutu_reader(const void *a, const void *b)
Definition read.c:4683
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:4650
addrmap_mutable * get_addrmap()
Definition read.c:4668
addrmap_mutable m_addrmap
Definition read.c:4698
static hashval_t hash_cutu_reader(const void *a)
Definition read.c:4676
htab_up m_reader_hash
Definition read.c:4693
abbrev_cache * get_abbrev_cache()
Definition read.c:4620
abbrev_cache m_abbrev_cache
Definition read.c:4691
std::unique_ptr< cooked_index_shard > m_index
Definition read.c:4695
cutu_reader * get_reader(dwarf2_per_cu_data *per_cu)
Definition read.c:4627
dwarf2_per_cu_data * lookup(CORE_ADDR addr)
void start_writing_index(dwarf2_per_bfd *per_bfd)
const cooked_index_entry * get_main() const
void wait() const
void dump(gdbarch *arch) const
quick_symbol_functions_up make_quick_functions() const override
Definition read.c:16973
range find(const std::string &name, bool completing) const
range all_entries() const
void check_bounds(cutu_reader *reader)
Definition read.c:16075
addrmap_mutable m_die_range_map
Definition read.c:4800
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:16123
cooked_indexer(cooked_index_storage *storage, dwarf2_per_cu_data *per_cu, enum language language)
Definition read.c:4707
enum language m_language
Definition read.c:4795
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:16172
const gdb_byte * recurse(cutu_reader *reader, const gdb_byte *info_ptr, const cooked_index_entry *parent_entry, bool fully)
Definition read.c:16467
DISABLE_COPY_AND_ASSIGN(cooked_indexer)
dwarf2_per_cu_data * m_per_cu
Definition read.c:4793
const gdb_byte * index_imported_unit(cutu_reader *reader, const gdb_byte *info_ptr, const abbrev_info *abbrev)
Definition read.c:16428
std::vector< deferred_entry > m_deferred_entries
Definition read.c:4819
CORE_ADDR form_addr(sect_offset offset, bool is_dwz)
Definition read.c:4725
void make_index(cutu_reader *reader)
Definition read.c:16645
const gdb_byte * index_dies(cutu_reader *reader, const gdb_byte *info_ptr, const cooked_index_entry *parent_entry, bool fully)
Definition read.c:16489
cooked_index_storage * m_index_storage
Definition read.c:4788
std::unique_ptr< dwarf2_cu > m_new_cu
Definition read.c:619
struct die_info * comp_unit_die
Definition read.c:599
struct dwarf2_per_cu_data * m_this_cu
Definition read.c:618
void keep()
Definition read.c:4398
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:4197
abbrev_table_up m_abbrev_table_holder
Definition read.c:622
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:4141
const gdb_byte * info_ptr
Definition read.c:598
cutu_reader(cutu_reader &&)=default
abbrev_table_up m_dwo_abbrev_table
Definition read.c:625
abbrev_table_up release_abbrev_table()
Definition read.c:608
bool dummy_p
Definition read.c:600
dwarf2_queue_guard(dwarf2_per_objfile *per_objfile)
Definition read.c:1090
dwarf2_per_objfile * m_per_objfile
Definition read.c:1110
DISABLE_COPY_AND_ASSIGN(dwarf2_queue_guard)
bool seen(const char *file)
free_cached_comp_units(dwarf2_per_objfile *per_objfile)
Definition read.c:1303
DISABLE_COPY_AND_ASSIGN(free_cached_comp_units)
dwarf2_per_objfile * m_per_objfile
Definition read.c:1317
gdb::array_view< const gdb_byte > lookup_gdb_index(const bfd_build_id *build_id, std::unique_ptr< index_cache_resource > *resource)
void handle_copy()
Definition read.c:18181
struct dwarf2_cu * m_cu
Definition read.c:18210
unsigned int m_discriminator
Definition read.c:18229
void handle_set_prologue_end()
Definition read.c:18195
unrelocated_addr m_last_address
Definition read.c:18240
lnp_state_machine(struct dwarf2_cu *cu, gdbarch *arch, line_header *lh)
Definition read.c:18505
bool m_line_has_non_zero_discriminator
Definition read.c:18255
unrelocated_addr m_address
Definition read.c:18227
bool m_stmt_at_address
Definition read.c:18246
file_name_index m_file
Definition read.c:18222
unsigned int m_line
Definition read.c:18223
unsigned int m_last_line
Definition read.c:18254
gdbarch * m_gdbarch
Definition read.c:18212
void check_line_address(struct dwarf2_cu *cu, const gdb_byte *line_ptr, unrelocated_addr unrelocated_lowpc, unrelocated_addr address)
Definition read.c:18522
bool m_currently_recording_lines
Definition read.c:18249
void handle_set_address(unrelocated_addr address)
Definition read.c:18139
void handle_advance_pc(CORE_ADDR adjust)
Definition read.c:18259
void handle_negate_stmt()
Definition read.c:18164
unsigned int m_last_file
Definition read.c:18235
void record_line(bool end_sequence)
Definition read.c:18421
linetable_entry_flags m_flags
Definition read.c:18228
void handle_set_discriminator(unsigned int discriminator)
Definition read.c:18132
void advance_line(int line_delta)
Definition read.c:18202
void handle_fixed_advance_pc(CORE_ADDR addr_adj)
Definition read.c:18173
struct subfile * m_last_subfile
Definition read.c:18237
void handle_special_opcode(unsigned char op_code)
Definition read.c:18271
unsigned char m_op_index
Definition read.c:18220
void handle_advance_line(int line_delta)
Definition read.c:18155
void handle_end_sequence()
Definition read.c:18189
line_header * m_line_header
Definition read.c:18215
void handle_set_file(file_name_index file)
Definition read.c:18292
file_entry * current_file()
Definition read.c:18114
void handle_const_add_pc()
Definition read.c:18308
std::vector< gdb::string_view > split_name(language lang) const
Definition symtab.h:295
const char * language_lookup_name(language lang) const
Definition symtab.h:276
symbol_name_match_type match_type() const
Definition symtab.h:239
lookup_name_info make_ignore_params() const
Definition symtab.h:256
bool completion_mode() const
Definition symtab.h:240
dwarf2_cu * m_cu
Definition read.c:6642
die_info * m_die
Definition read.c:6641
process_die_scope(die_info *die, dwarf2_cu *cu)
Definition read.c:6618
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:198
bool empty() const
Definition ui-file.h:224
type * new_type()
Definition gdbtypes.c:208
virtual void puts(const char *str)
Definition ui-file.h:76
struct cmd_list_element * showdebuglist
Definition cli-cmds.c:167
struct cmd_list_element * setdebuglist
Definition cli-cmds.c:165
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:809
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:405
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)
unsigned int cp_find_first_component(const char *name)
gdb::unique_xmalloc_ptr< char > cp_canonicalize_string(const char *string)
Definition cp-support.c:627
#define CP_ANONYMOUS_NAMESPACE_STR
Definition cp-support.h:43
std::string debug_file_directory
Definition symfile.c:1354
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition defs.h:515
#define O_BINARY
Definition defs.h:114
language
Definition defs.h:211
@ language_ada
Definition defs.h:225
@ language_m2
Definition defs.h:220
@ language_unknown
Definition defs.h:212
@ language_minimal
Definition defs.h:224
@ 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:215
@ language_c
Definition defs.h:213
@ language_d
Definition defs.h:217
@ nr_languages
Definition defs.h:226
@ language_objc
Definition defs.h:214
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
#define QUIT
Definition defs.h:187
struct dwz_file * dwarf2_get_dwz_file(dwarf2_per_bfd *per_bfd, bool require)
Definition dwz.c:193
void exception_print(struct ui_file *file, const struct gdb_exception &e)
Definition exceptions.c:106
const gdb_byte * safe_skip_leb128(const gdb_byte *buf, const gdb_byte *buf_end)
Definition expr.c:1281
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:1453
const gdb_byte * safe_read_uleb128(const gdb_byte *buf, const gdb_byte *buf_end, uint64_t *r)
Definition expr.c:1259
int dwarf_block_to_dwarf_reg(const gdb_byte *buf, const gdb_byte *buf_end)
Definition expr.c:1324
static const gdb_byte * gdb_read_uleb128(const gdb_byte *buf, const gdb_byte *buf_end, uint64_t *r)
Definition expr.h:281
const struct builtin_f_type * builtin_f_type(struct gdbarch *gdbarch)
Definition f-lang.c:1813
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
bool is_cplus_marker(int c)
int gdb_bfd_requires_relocations(bfd *abfd)
Definition gdb_bfd.c:1010
void gdb_bfd_record_inclusion(bfd *includer, bfd *includee)
Definition gdb_bfd.c:969
gdb_bfd_ref_ptr gdb_bfd_open(const char *name, const char *target, int fd, bool warn_if_slow)
Definition gdb_bfd.c:473
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
Definition gdb_bfd.h:79
static gdb_bfd_section_range gdb_bfd_sections(bfd *abfd)
Definition gdb_bfd.h:234
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
bool gdbarch_dwarf2_omit_typedef_p(struct gdbarch *gdbarch, struct type *target_type, const char *producer, const char *name)
Definition gdbarch.c:2644
bool gdbarch_address_class_type_flags_p(struct gdbarch *gdbarch)
Definition gdbarch.c:3581
bfd * obfd
const struct floatformat ** gdbarch_floatformat_for_type(struct gdbarch *gdbarch, const char *name, int length)
Definition gdbarch.c:1705
void gdbarch_make_symbol_special(struct gdbarch *gdbarch, struct symbol *sym, struct objfile *objfile)
Definition gdbarch.c:3496
CORE_ADDR gdbarch_adjust_dwarf2_line(struct gdbarch *gdbarch, CORE_ADDR addr, int rel)
Definition gdbarch.c:3530
CORE_ADDR gdbarch_adjust_dwarf2_addr(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition gdbarch.c:3513
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition gdbarch.c:3152
type_instance_flags gdbarch_address_class_type_flags(struct gdbarch *gdbarch, int byte_size, int dwarf2_addr_class)
Definition gdbarch.c:3588
void set_type_vptr_basetype(struct type *type, struct type *basetype)
Definition gdbtypes.c:1954
void set_type_vptr_fieldno(struct type *type, int fieldno)
Definition gdbtypes.c:1928
struct type * create_set_type(type_allocator &alloc, struct type *domain_type)
Definition gdbtypes.c:1439
struct type * make_restrict_type(struct type *type)
Definition gdbtypes.c:785
struct type * lookup_pointer_type(struct type *type)
Definition gdbtypes.c:430
struct type * init_character_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3374
struct type * init_integer_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3355
struct type * create_static_range_type(type_allocator &alloc, struct type *index_type, LONGEST low_bound, LONGEST high_bound)
Definition gdbtypes.c:1019
struct type * lookup_methodptr_type(struct type *to_type)
Definition gdbtypes.c:881
bool set_type_align(struct type *type, ULONGEST align)
Definition gdbtypes.c:3619
struct type * create_range_type(type_allocator &alloc, struct type *index_type, const struct dynamic_prop *low_bound, const struct dynamic_prop *high_bound, LONGEST bias)
Definition gdbtypes.c:936
struct type * init_fixed_point_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3502
struct type * init_decfloat_type(type_allocator &alloc, int bit, const char *name)
Definition gdbtypes.c:3431
struct type * make_cv_type(int cnst, int voltl, struct type *type, struct type **typeptr)
Definition gdbtypes.c:740
struct type * lookup_function_type(struct type *type)
Definition gdbtypes.c:567
struct type * create_string_type(type_allocator &alloc, struct type *string_char_type, struct type *range_type)
Definition gdbtypes.c:1415
struct type * create_range_type_with_stride(type_allocator &alloc, 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:998
struct type * init_pointer_type(type_allocator &alloc, int bit, const char *name, struct type *target_type)
Definition gdbtypes.c:3485
struct type * make_type_with_address_space(struct type *type, type_instance_flags space_flag)
Definition gdbtypes.c:715
struct type * lookup_reference_type(struct type *type, enum type_code refcode)
Definition gdbtypes.c:510
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:1603
struct type * init_float_type(type_allocator &alloc, int bit, const char *name, const struct floatformat **floatformats, enum bfd_endian byte_order)
Definition gdbtypes.c:3408
void smash_to_methodptr_type(struct type *type, struct type *to_type)
Definition gdbtypes.c:1586
struct type * lookup_memberptr_type(struct type *type, struct type *domain)
Definition gdbtypes.c:869
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition gdbtypes.c:6168
unsigned type_align(struct type *type)
Definition gdbtypes.c:3527
struct type * init_complex_type(const char *name, struct type *target_type)
Definition gdbtypes.c:3449
struct type * create_array_type_with_stride(type_allocator &alloc, struct type *element_type, struct type *range_type, struct dynamic_prop *byte_stride_prop, unsigned int bit_stride)
Definition gdbtypes.c:1339
struct type * init_boolean_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3389
struct type * make_atomic_type(struct type *type)
Definition gdbtypes.c:809
struct type * copy_type(const struct type *type)
Definition gdbtypes.c:5656
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:2966
void make_vector_type(struct type *array_type)
Definition gdbtypes.c:1468
@ TYPE_SPECIFIC_FIXED_POINT
Definition gdbtypes.h:509
@ TYPE_SPECIFIC_INT
Definition gdbtypes.h:508
#define TYPE_ZALLOC(t, size)
Definition gdbtypes.h:2224
#define TYPE_FN_FIELD_PHYSNAME(thisfn, n)
Definition gdbtypes.h:2001
#define TYPE_NFN_FIELDS(thistype)
Definition gdbtypes.h:1925
#define TYPE_CPLUS_DYNAMIC(thistype)
Definition gdbtypes.h:1952
#define TYPE_DESCRIPTIVE_TYPE(thistype)
Definition gdbtypes.h:1942
#define TYPE_FN_FIELDLIST(thistype, n)
Definition gdbtypes.h:1988
#define TYPE_TEMPLATE_ARGUMENTS(thistype)
Definition gdbtypes.h:1995
#define TYPE_NESTED_TYPES_COUNT(thistype)
Definition gdbtypes.h:2042
#define B_BYTES(x)
Definition gdbtypes.h:75
#define TYPE_FIELD_VIRTUAL_BITS(thistype)
Definition gdbtypes.h:1964
#define ALLOCATE_CPLUS_STRUCT_TYPE(type)
Definition gdbtypes.h:1824
#define TYPE_FIELD_PRIVATE_BITS(thistype)
Definition gdbtypes.h:1958
@ FIELD_LOC_KIND_BITPOS
Definition gdbtypes.h:481
@ FIELD_LOC_KIND_ENUMVAL
Definition gdbtypes.h:482
#define SET_TYPE_FIELD_PROTECTED(thistype, n)
Definition gdbtypes.h:1968
#define B_TYPE
Definition gdbtypes.h:74
#define TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
Definition gdbtypes.h:190
#define TYPE_MAIN_TYPE(thistype)
Definition gdbtypes.h:1866
#define TYPE_FN_FIELDLISTS(thistype)
Definition gdbtypes.h:1987
#define TYPE_NESTED_TYPES_FIELD(thistype, n)
Definition gdbtypes.h:2036
#define TYPE_FN_FIELD_VOLATILE(thisfn, n)
Definition gdbtypes.h:2005
#define ALLOCATE_GNAT_AUX_TYPE(type)
Definition gdbtypes.h:1841
#define TYPE_CALLING_CONVENTION(thistype)
Definition gdbtypes.h:1943
#define TYPE_CONST(t)
Definition gdbtypes.h:117
#define TYPE_VOLATILE(t)
Definition gdbtypes.h:122
#define VOFFSET_STATIC
Definition gdbtypes.h:1598
type_code
Definition gdbtypes.h:82
#define TYPE_FN_FIELDLIST_LENGTH(thistype, n)
Definition gdbtypes.h:1991
#define TYPE_N_TEMPLATE_ARGUMENTS(thistype)
Definition gdbtypes.h:1993
#define TYPE_VPTR_FIELDNO(thistype)
Definition gdbtypes.h:1922
#define TYPE_TAIL_CALL_LIST(thistype)
Definition gdbtypes.h:1945
#define TYPE_RAW_ALIGN(thistype)
Definition gdbtypes.h:1874
#define TYPE_SPECIFIC_FIELD(thistype)
Definition gdbtypes.h:1926
#define TYPE_NO_RETURN(thistype)
Definition gdbtypes.h:1944
#define TYPE_TEMPLATE_ARGUMENT(thistype, n)
Definition gdbtypes.h:1997
#define TYPE_TYPEDEF_FIELD(thistype, n)
Definition gdbtypes.h:2021
#define INIT_GNAT_SPECIFIC(type)
Definition gdbtypes.h:1838
#define INIT_CPLUS_SPECIFIC(type)
Definition gdbtypes.h:1819
#define TYPE_CPLUS_CALLING_CONVENTION(thistype)
Definition gdbtypes.h:1938
#define TYPE_TYPEDEF_FIELD_COUNT(thistype)
Definition gdbtypes.h:2027
#define TYPE_FN_FIELDLIST_NAME(thistype, n)
Definition gdbtypes.h:1990
#define TYPE_NESTED_TYPES_ARRAY(thistype)
Definition gdbtypes.h:2034
#define TYPE_FIELD_PROTECTED_BITS(thistype)
Definition gdbtypes.h:1960
#define TYPE_ALLOC(t, size)
Definition gdbtypes.h:2215
#define TYPE_TYPEDEF_FIELD_ARRAY(thistype)
Definition gdbtypes.h:2019
#define SET_TYPE_FIELD_PRIVATE(thistype, n)
Definition gdbtypes.h:1966
#define TYPE_N_BASECLASSES(thistype)
Definition gdbtypes.h:1947
@ DYN_PROP_VARIANT_PARTS
Definition gdbtypes.h:453
@ DYN_PROP_ASSOCIATED
Definition gdbtypes.h:447
@ DYN_PROP_RANK
Definition gdbtypes.h:457
@ DYN_PROP_BYTE_SIZE
Definition gdbtypes.h:460
@ DYN_PROP_DATA_LOCATION
Definition gdbtypes.h:439
@ DYN_PROP_ALLOCATED
Definition gdbtypes.h:443
#define HAVE_GNAT_AUX_INFO(type)
Definition gdbtypes.h:1844
#define TYPE_FN_FIELD_CONST(thisfn, n)
Definition gdbtypes.h:2004
#define SET_TYPE_FIELD_VIRTUAL(thistype, n)
Definition gdbtypes.h:1972
#define TYPE_FIELD_IGNORE_BITS(thistype)
Definition gdbtypes.h:1962
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:1861
gdb::unique_xmalloc_ptr< char > go_symbol_package_name(const struct symbol *sym)
Definition go-lang.c:411
unsigned dummy
Definition go32-nat.c:8
size_t size
Definition go32-nat.c:239
index_cache global_index_cache
Definition index-cache.c:48
uint32_t offset_type
const struct language_defn * language_def(enum language lang)
Definition language.c:439
struct type * language_string_char_type(const struct language_defn *la, struct gdbarch *gdbarch)
Definition language.c:868
@ 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:29
std::unique_ptr< line_header > line_header_up
int dir_index
Definition line-header.h:25
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:1564
const gdb_byte * dwarf2_find_location_expression(const dwarf2_loclist_baton *baton, size_t *locexpr_length, const CORE_ADDR pc)
Definition loc.c:365
const struct symbol_computed_ops dwarf2_loclist_funcs
Definition loc.c:4110
const struct symbol_computed_ops dwarf2_locexpr_funcs
Definition loc.c:3870
const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
Definition loc.c:539
const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
Definition loc.c:596
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, unsigned int decl_line, int copy_names, struct obstack *obstack)
Definition namespace.c:39
Definition aarch64.h:67
@ OBJF_READNEVER
@ OBJF_MAINLINE
@ OBJF_READNOW
void set_objfile_main_name(struct objfile *objfile, const char *name, enum language lang)
Definition objfiles.c:150
struct type * objfile_int_type(struct objfile *of, int size_in_bytes, bool unsigned_p)
Definition objfiles.c:1299
const char * objfile_name(const struct objfile *objfile)
Definition objfiles.c:1259
#define SECT_OFF_TEXT(objfile)
Definition objfiles.h:139
#define OBJSTAT(objfile, expr)
Definition objfiles.h:169
#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
int value
Definition py-param.c:79
static void set_type(type_object *obj, struct type *type)
Definition py-type.c:1201
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
bool dwarf2_read_debug_names(dwarf2_per_objfile *per_objfile)
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)
static struct dwo_unit * lookup_dwo_unit(dwarf2_cu *cu, die_info *comp_unit_die, const char *dwo_name)
Definition read.c:4099
static int eq_dwo_unit(const void *item_lhs, const void *item_rhs)
Definition read.c:7944
static void dwarf2_attach_fn_fields_to_type(struct field_info *, struct type *, struct dwarf2_cu *)
Definition read.c:12373
static const char * dwarf2_full_name(const char *name, struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:7110
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:8225
static void process_full_type_unit(dwarf2_cu *cu, enum language pretend_language)
Definition read.c:6506
static void queue_comp_unit(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, enum language pretend_language)
Definition read.c:5566
static void dw2_get_file_names_reader(const struct die_reader_specs *reader, struct die_info *comp_unit_die)
Definition read.c:2020
static bool is_ada_import_or_export(dwarf2_cu *cu, const char *name, const char *linkagename)
Definition read.c:18949
#define RUST_ENUM_PREFIX
static struct die_info * follow_die_ref(struct die_info *, const struct attribute *, struct dwarf2_cu **)
Definition read.c:20534
static int handle_member_location(struct die_info *die, struct dwarf2_cu *cu, LONGEST *offset)
Definition read.c:11512
static void dwarf2_build_psymtabs_hard(dwarf2_per_objfile *per_objfile)
Definition read.c:5091
static const registry< bfd >::key< dwarf2_per_bfd > dwarf2_per_bfd_bfd_data_key
Definition read.c:137
static void dwarf2_symbol_mark_computed(const struct attribute *attr, struct symbol *sym, struct dwarf2_cu *cu, int is_block)
Definition read.c:21483
static int queue_and_load_dwo_tu(void **slot, void *info)
Definition read.c:9800
static void compute_delayed_physnames(struct dwarf2_cu *cu)
Definition read.c:5802
static int eq_file_name_entry(const void *a, const void *b)
Definition read.c:1699
static struct using_direct ** using_directives(struct dwarf2_cu *cu)
Definition read.c:7289
static void process_structure_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:12979
static ULONGEST lookup_loclist_base(struct dwarf2_cu *cu)
Definition read.c:17010
static void process_die(struct die_info *, struct dwarf2_cu *)
Definition read.c:6648
static void dwarf2_invalid_attrib_class_complaint(const char *arg1, const char *arg2)
Definition read.c:1199
static const gdb_byte * read_full_die_1(const struct die_reader_specs *, struct die_info **, const gdb_byte *, int, bool)
Definition read.c:15971
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:9064
pc_bounds_kind
Definition read.c:884
@ PC_BOUNDS_RANGES
Definition read.c:893
@ PC_BOUNDS_INVALID
Definition read.c:890
@ PC_BOUNDS_NOT_PRESENT
Definition read.c:886
@ PC_BOUNDS_HIGH_LOW
Definition read.c:896
static bool ada_get_gnat_encoded_ratio(const char *encoding, int &offset, gdb_mpz *num, gdb_mpz *denom)
Definition read.c:14969
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:3675
static const char * read_dwo_str_index(const struct die_reader_specs *reader, ULONGEST str_index)
Definition read.c:17702
static void rust_union_quirks(struct dwarf2_cu *cu)
Definition read.c:6234
static void process_full_comp_unit(dwarf2_cu *cu, enum language pretend_language)
Definition read.c:6393
static hashval_t hash_dwo_file(const void *item)
Definition read.c:7877
static bool check_ada_pragma_import(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:10048
static bool producer_is_gcc_lt_4_3(struct dwarf2_cu *cu)
Definition read.c:7500
static struct type * get_die_type_at_offset(sect_offset, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:22006
static bool producer_is_icc(struct dwarf2_cu *cu)
Definition read.c:7487
htab_up create_quick_file_names_table(unsigned int nr_initial_entries)
Definition read.c:1710
static struct die_info * follow_die_offset(sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu **ref_cu)
Definition read.c:20463
static struct signatured_type * lookup_dwo_signatured_type(struct dwarf2_cu *cu, ULONGEST sig)
Definition read.c:3758
#define MAX_NR_V2_DWO_SECTIONS
Definition read.c:477
static void read_lexical_block_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:10292
static struct type * read_tag_atomic_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14469
static void dwarf2_add_member_fn(struct field_info *, struct die_info *, struct type *, struct dwarf2_cu *)
Definition read.c:12171
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:8725
static enum language dwarf_lang_to_enum_language(unsigned int lang)
Definition read.c:17800
static struct type * read_structure_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:12669
static gdb::array_view< const gdb_byte > get_gdb_index_contents_from_cache(objfile *obj, dwarf2_per_bfd *dwarf2_per_bfd)
Definition read.c:3356
static unsigned int read_decl_line(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:7303
static bool type_can_define_types(const struct die_info *die)
Definition read.c:11806
static struct type * read_tag_reference_type(struct die_info *die, struct dwarf2_cu *cu, enum type_code refcode)
Definition read.c:14349
static struct compunit_symtab * dw2_instantiate_symtab(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, bool skip_partial)
Definition read.c:1784
static void read_loclists_rnglists_header(struct loclists_rnglists_header *header, struct dwarf2_section_info *section, sect_offset header_offset)
Definition read.c:16985
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:19446
#define LOCLIST_HEADER_SIZE64
Definition read.c:154
static void dwarf2_const_value_length_mismatch_complaint(const char *arg1, int arg2, int arg3)
Definition read.c:1191
static struct dwo_unit * lookup_dwo_type_unit(dwarf2_cu *cu, const char *dwo_name, const char *comp_dir)
Definition read.c:9788
static gdb_bfd_ref_ptr open_dwp_file(dwarf2_per_objfile *per_objfile, const char *file_name)
Definition read.c:9500
static struct compunit_symtab * recursively_find_pc_sect_compunit_symtab(struct compunit_symtab *cust, CORE_ADDR pc)
Definition read.c:3155
static const char * determine_prefix(struct die_info *die, struct dwarf2_cu *)
Definition read.c:20013
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:5719
static struct type * set_die_type(struct die_info *, struct type *, struct dwarf2_cu *, bool=false)
Definition read.c:21920
static struct attribute * dw2_linkage_name_attr(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:6829
static unrelocated_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:17566
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:734
dwp_v2_section_ids
Definition read.c:329
@ DW_SECT_MIN
Definition read.c:330
static dwarf2_cu * load_cu(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, bool skip_partial)
Definition read.c:1722
static void maybe_set_alignment(struct dwarf2_cu *cu, struct die_info *die, struct type *type)
Definition read.c:12600
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:20681
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:5402
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:5201
static void dwarf2_add_field(struct field_info *, struct die_info *, struct dwarf2_cu *)
Definition read.c:11624
static hashval_t hash_dwp_loaded_cutus(const void *item)
Definition read.c:9463
static void dwarf2_locate_dwo_sections(struct objfile *objfile, bfd *abfd, asection *sectp, dwo_sections *dwo_sections)
Definition read.c:9248
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:8536
static sect_offset read_abbrev_offset(dwarf2_per_objfile *per_objfile, dwarf2_section_info *, sect_offset)
Definition read.c:3513
static struct type * die_containing_type(struct die_info *, struct dwarf2_cu *)
Definition read.c:19682
static struct type * read_module_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14169
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:2477
static void ** lookup_dwo_file_slot(dwarf2_per_objfile *per_objfile, const char *dwo_name, const char *comp_dir)
Definition read.c:7916
static struct type * get_die_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:22029
static void dwarf2_add_type_defn(struct field_info *fip, struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:11825
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:9144
static int line_header_eq_voidp(const void *item_lhs, const void *item_rhs)
Definition read.c:1247
static std::unique_ptr< type_unit_group > create_type_unit_group(struct dwarf2_cu *cu, sect_offset line_offset_struct)
Definition read.c:4536
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:9661
static void show_check_physname(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition read.c:22038
static void read_import_statement(struct die_info *die, struct dwarf2_cu *)
Definition read.c:7325
static std::string make_sort_after_prefix_name(const char *search_name)
Definition read.c:2256
static struct type * rust_containing_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:10711
static hashval_t hash_type_unit_group(const void *item)
Definition read.c:4497
static ULONGEST get_alignment(struct dwarf2_cu *cu, struct die_info *die)
Definition read.c:12549
static int leb128_size(const gdb_byte *buf)
Definition read.c:17786
static sect_offset read_rnglist_index(struct dwarf2_cu *cu, ULONGEST rnglist_index, dwarf_tag tag)
Definition read.c:17092
static int eq_type_unit_group(const void *item_lhs, const void *item_rhs)
Definition read.c:4506
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:20699
static void inherit_abstract_dies(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:9852
static struct type * read_type_die(struct die_info *, struct dwarf2_cu *)
Definition read.c:19798
static struct type * read_subroutine_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14629
static int dwarf2_loclist_index
Definition read.c:144
static bool producer_is_codewarrior(struct dwarf2_cu *cu)
Definition read.c:11456
#define MAX_NESTED_IMPORTED_DECLARATIONS
static void read_type_unit_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:7845
static void check_producer(struct dwarf2_cu *cu)
Definition read.c:11399
static void fixup_go_packaging(struct dwarf2_cu *cu)
Definition read.c:5855
bool producer_is_clang(struct dwarf2_cu *cu)
Definition read.c:7510
static struct attribute * dwarf2_attr(struct die_info *, unsigned int, struct dwarf2_cu *)
Definition read.c:17868
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:8683
static struct type * read_enumeration_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:13273
static struct die_info * follow_die_ref_or_sig(struct die_info *, const struct attribute *, struct dwarf2_cu **)
Definition read.c:20438
static void process_skeletonless_type_units(dwarf2_per_objfile *per_objfile, cooked_index_storage *storage)
Definition read.c:5072
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:1826
static void dwarf2_record_block_ranges(struct die_info *, struct block *, struct dwarf2_cu *)
Definition read.c:11341
static struct type * read_tag_restrict_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14451
static struct symbol * new_symbol(struct die_info *, struct type *, struct dwarf2_cu *, struct symbol *=NULL)
Definition read.c:18978
bool dwarf2_has_info(struct objfile *objfile, const struct dwarf2_debug_sections *names, bool can_copy)
Definition read.c:1360
static int dwarf2_locexpr_block_index
Definition read.c:146
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:12923
static void dwarf_finish_line(struct gdbarch *gdbarch, struct subfile *subfile, unrelocated_addr address, struct dwarf2_cu *cu)
Definition read.c:18403
static const char * dw2_get_real_path(dwarf2_per_objfile *per_objfile, struct quick_file_names *qfn, int index)
Definition read.c:2139
static void get_dwarf2_rational_constant(struct die_info *die, struct dwarf2_cu *cu, gdb_mpz *numerator, gdb_mpz *denominator)
Definition read.c:14871
static int dwarf2_locexpr_index
Definition read.c:143
static struct dwo_unit * lookup_dwo_comp_unit(dwarf2_cu *cu, const char *dwo_name, const char *comp_dir, ULONGEST signature)
Definition read.c:9776
static bool check_modifier(const char *physname, size_t &len, const char(&mod)[N])
Definition read.c:5784
static struct dwarf2_section_info * get_debug_line_section(struct dwarf2_cu *cu)
Definition read.c:17982
#define RNGLIST_HEADER_SIZE64
Definition read.c:160
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:14383
const char * read_indirect_string_at_offset(dwarf2_per_objfile *per_objfile, LONGEST str_offset)
Definition read.c:17514
static struct type * read_tag_ptr_to_member_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14313
static const char * anonymous_struct_prefix(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:19966
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:11972
static const char * dwarf2_dwo_name(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:17924
static struct type * dwarf2_init_float_type(struct dwarf2_cu *cu, int bits, const char *name, const char *name_hint, enum bfd_endian byte_order)
Definition read.c:15095
static int dwarf2_loclist_block_index
Definition read.c:147
static struct type * die_type(struct die_info *, struct dwarf2_cu *)
Definition read.c:19619
static enum dwarf_access_attribute dwarf2_access_attribute(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:11469
static int eq_signatured_type(const void *item_lhs, const void *item_rhs)
Definition read.c:3550
static void get_scope_pc_bounds(struct die_info *, unrelocated_addr *, unrelocated_addr *, struct dwarf2_cu *)
Definition read.c:11281
static struct type_unit_group * get_type_unit_group(struct dwarf2_cu *cu, const struct attribute *stmt_list)
Definition read.c:4550
static htab_up allocate_dwo_file_hash_table()
Definition read.c:7904
static unsigned int dwarf_die_debug
Definition read.c:117
static void build_type_psymtabs_reader(cutu_reader *reader, cooked_index_storage *storage)
Definition read.c:4859
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:5348
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:13426
static struct type * read_array_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:13674
#define LOCLIST_HEADER_SIZE32
Definition read.c:151
static const char * dwarf2_string_attr(struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
Definition read.c:17901
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:11953
static char * typename_concat(struct obstack *obs, const char *prefix, const char *suffix, int physname, struct dwarf2_cu *cu)
Definition read.c:20178
static int eq_dwo_file(const void *item_lhs, const void *item_rhs)
Definition read.c:7889
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:15464
void finalize_all_units(dwarf2_per_bfd *per_bfd)
Definition read.c:5271
static void store_in_ref_table(struct die_info *, struct dwarf2_cu *)
Definition read.c:20422
static struct type * get_signatured_type(struct die_info *, ULONGEST, struct dwarf2_cu *)
Definition read.c:20967
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:3055
static unsigned int peek_abbrev_code(bfd *, const gdb_byte *)
Definition read.c:5333
static void read_call_site_scope(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:10376
static void get_dwarf2_unsigned_rational_constant(struct die_info *die, struct dwarf2_cu *cu, gdb_mpz *numerator, gdb_mpz *denominator)
Definition read.c:14900
static const gdb_byte * skip_children(const struct die_reader_specs *reader, const gdb_byte *info_ptr)
Definition read.c:5377
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:20563
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:21630
static hashval_t line_header_hash_voidp(const void *item)
Definition read.c:1237
static void process_psymtab_comp_unit(dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile, cooked_index_storage *storage)
Definition read.c:4826
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:15871
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:15942
static struct type * read_subrange_index_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:15625
static void prepare_one_comp_unit(struct dwarf2_cu *cu, struct die_info *comp_unit_die, enum language pretend_language)
Definition read.c:21718
static bool dwarf2_rnglists_process(unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag, Callback &&callback)
Definition read.c:10780
static const char * dw2_linkage_name(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:6845
static int eq_dwp_loaded_cutus(const void *a, const void *b)
Definition read.c:9474
bool read_addrmap_from_aranges(dwarf2_per_objfile *per_objfile, dwarf2_section_info *section, addrmap *mutable_map)
Definition read.c:1842
#define MAX_SEP_LEN
Definition read.c:20175
#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:13915
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:18044
static const gdb::array_view< discriminant_range > convert_variant_range(struct obstack *obstack, const variant_field &variant, bool is_unsigned)
Definition read.c:11869
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:5938
static void process_cu_includes(dwarf2_per_objfile *per_objfile)
Definition read.c:6378
static const char * gnat_encoded_fixed_point_type_info(const char *name)
Definition read.c:15085
static htab_up allocate_type_unit_groups_table()
Definition read.c:4517
static struct die_info * dwarf2_extension(struct die_info *die, struct dwarf2_cu **)
Definition read.c:20410
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:17659
#define GNAT_FIXED_POINT_SUFFIX
Definition read.c:15078
static void get_mpz(struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr)
Definition read.c:14823
static void dwarf2_locate_v5_dwp_sections(struct objfile *objfile, bfd *abfd, asection *sectp, void *dwp_file_ptr)
Definition read.c:9423
#define dwarf_read_debug_printf_v(fmt,...)
Definition read.c:112
static void dwarf2_build_psymtabs(struct objfile *objfile)
Definition read.c:3452
#define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
Definition read.c:4530
static void finish_fixed_point_type(struct type *type, const char *suffix, struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14984
static struct die_info * die_specification(struct die_info *die, struct dwarf2_cu **)
Definition read.c:17965
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:20666
static void dwarf2_const_value(const struct attribute *, struct symbol *, struct dwarf2_cu *)
Definition read.c:19586
static void dwarf2_start_subfile(dwarf2_cu *cu, const file_entry &fe, const line_header &lh)
Definition read.c:18827
static void read_func_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:10070
#define RNGLIST_HEADER_SIZE32
Definition read.c:157
static struct type * dwarf2_init_integer_type(struct dwarf2_cu *cu, int bits, int unsigned_p, const char *name)
Definition read.c:15116
static void dwarf2_complex_location_expr_complaint(void)
Definition read.c:1185
static gdb::array_view< const gdb_byte > get_gdb_index_contents_from_cache_dwz(objfile *obj, dwz_file *dwz)
Definition read.c:3369
static bool ada_get_gnat_encoded_number(const char *encoding, int &k, gdb_mpz *result)
Definition read.c:14942
static quick_symbol_functions_up make_cooked_index_funcs()
Definition read.c:16967
static void quirk_ada_thick_pointer_struct(struct die_info *die, struct dwarf2_cu *cu, struct type *type)
Definition read.c:12513
static enum pc_bounds_kind dwarf2_get_pc_bounds(struct die_info *, unrelocated_addr *, unrelocated_addr *, struct dwarf2_cu *, addrmap *, void *)
Definition read.c:11160
void _initialize_dwarf2_read()
Definition read.c:22048
#define dwarf_read_debug_printf(fmt,...)
Definition read.c:106
static void process_imported_unit_die(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:6572
static const registry< objfile >::key< dwarf2_per_bfd > dwarf2_per_bfd_objfile_data_key
Definition read.c:139
static int ada_block_index
Definition read.c:148
static struct type * rewrite_array_type(struct type *type)
Definition read.c:12467
static void read_file_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:7647
static bool producer_is_gxx_lt_4_6(struct dwarf2_cu *cu)
Definition read.c:11443
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:8892
static const gdb_byte * read_attribute(const struct die_reader_specs *, struct attribute *, const struct attr_abbrev *, const gdb_byte *, bool allow_reprocess=true)
Definition read.c:17499
static unsigned int dwarf_read_debug
Definition read.c:102
static int dwarf2_ranges_read(unsigned offset, unrelocated_addr *low_return, unrelocated_addr *high_return, struct dwarf2_cu *cu, addrmap *map, void *datum, dwarf_tag tag)
Definition read.c:11084
static void dwarf2_ranges_read_low_addrs(unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag, std::vector< unrelocated_addr > &result)
Definition read.c:11144
static const char * dwarf2_physname(const char *name, struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:7123
static hashval_t hash_signatured_type(const void *item)
Definition read.c:3540
static bool producer_is_icc_lt_14(struct dwarf2_cu *cu)
Definition read.c:7474
static bool has_zero_over_zero_small_attribute(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:15144
static const char * dwarf2_compute_name(const char *name, struct die_info *die, struct dwarf2_cu *cu, int physname)
Definition read.c:6878
static struct type * read_tag_const_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14406
static void print_tu_stats(dwarf2_per_objfile *per_objfile)
Definition read.c:4991
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:15905
static int eq_stmt_list_entry(const struct stmt_list_hash *lhs, const struct stmt_list_hash *rhs)
Definition read.c:1673
static void create_all_units(dwarf2_per_objfile *per_objfile)
Definition read.c:5284
static void dwarf2_debug_line_missing_file_complaint(void)
Definition read.c:1172
static struct type * read_tag_volatile_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14427
static struct dwarf2_section_info * cu_debug_rnglists_section(struct dwarf2_cu *cu, dwarf_tag tag)
Definition read.c:21430
static void dwarf2_attach_fields_to_type(struct field_info *, struct type *, struct dwarf2_cu *)
Definition read.c:12055
static void queue_and_load_all_dwo_tus(dwarf2_cu *cu)
Definition read.c:9827
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:3574
static const char * unnamed_template_tag_name(die_info *die, dwarf2_cu *cu)
Definition read.c:20243
static struct dwp_file * get_dwp_file(dwarf2_per_objfile *per_objfile)
Definition read.c:9634
static void read_module(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14185
static void compute_compunit_symtab_includes(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:6334
static void quirk_rust_enum(struct type *type, struct objfile *objfile)
Definition read.c:6020
static void var_decode_location(struct attribute *attr, struct symbol *sym, struct dwarf2_cu *cu)
Definition read.c:18852
static const char * namespace_name(struct die_info *die, int *is_anonymous, struct dwarf2_cu *)
Definition read.c:14205
static htab_up allocate_dwo_unit_table()
Definition read.c:7960
static struct quick_file_names * dw2_get_file_names(dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:2119
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:3897
static struct type * read_namespace_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14082
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:5602
unrelocated_addr dwarf2_read_addr_index(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, unsigned int addr_index)
Definition read.c:17615
static hashval_t hash_dwo_unit(const void *item)
Definition read.c:7935
static int need_gnat_info(struct dwarf2_cu *)
Definition read.c:19639
static hashval_t hash_file_name_entry(const void *e)
Definition read.c:1688
static int locate_v1_virtual_dwo_sections(asection *sectp, struct virtual_v1_dwo_sections *sections)
Definition read.c:8459
static int bits_per_byte
Definition read.c:631
static hashval_t per_cu_offset_and_type_hash(const void *item)
Definition read.c:21879
static struct type * read_tag_string_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14490
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, bool allow_reprocess)
Definition read.c:17210
static int die_is_declaration(struct die_info *, struct dwarf2_cu *cu)
Definition read.c:17945
static const char * guess_full_die_structure_name(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:19903
static struct signatured_type * lookup_dwp_signatured_type(struct dwarf2_cu *cu, ULONGEST sig)
Definition read.c:3824
static gdb_bfd_ref_ptr open_dwo_file(dwarf2_per_objfile *per_objfile, const char *file_name, const char *comp_dir)
Definition read.c:9212
struct cmd_list_element * set_dwarf_cmdlist
Definition read.c:22034
static void dwarf2_debug_line_missing_end_sequence_complaint(void)
Definition read.c:1178
static const char * rust_fully_qualify(struct obstack *obstack, const char *p1, const char *p2)
Definition read.c:5920
static gdb::array_view< const gdb_byte > get_gdb_index_contents_from_section(objfile *obj, T *section_owner)
Definition read.c:3329
static int is_vtable_name(const char *name, struct dwarf2_cu *cu)
Definition read.c:12406
static bool read_alias(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:7210
static bool is_valid_DW_AT_calling_convention_for_subroutine(ULONGEST value)
Definition read.c:12635
static void dwarf2_locate_common_dwp_sections(struct objfile *objfile, bfd *abfd, asection *sectp, dwp_file *dwp_file)
Definition read.c:9344
static bool tag_can_have_linkage_name(enum dwarf_tag tag)
Definition read.c:16109
static void dwarf2_locate_v2_dwp_sections(struct objfile *objfile, bfd *abfd, asection *sectp, void *dwp_file_ptr)
Definition read.c:9378
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:6281
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:8007
static void update_enumeration_type_from_children(struct die_info *die, struct type *type, struct dwarf2_cu *cu)
Definition read.c:13206
static void build_type_psymtabs(dwarf2_per_objfile *per_objfile, cooked_index_storage *storage)
Definition read.c:4914
static void read_common_block(struct die_info *, struct dwarf2_cu *)
Definition read.c:13986
static void dwarf_decode_macros(struct dwarf2_cu *, unsigned int, int)
Definition read.c:21341
static void dwarf_record_line_1(struct gdbarch *gdbarch, struct subfile *subfile, unsigned int line, unrelocated_addr address, linetable_entry_flags flags, struct dwarf2_cu *cu)
Definition read.c:18376
static file_and_directory & find_file_and_directory(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:7519
static bool dwarf2_func_is_main_p(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:10035
static struct dwarf2_section_info * get_abbrev_section_for_cu(struct dwarf2_per_cu_data *this_cu)
Definition read.c:3497
static struct type * read_tag_pointer_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14237
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:18355
static gdb::optional< ULONGEST > lookup_dwo_id(struct dwarf2_cu *cu, struct die_info *comp_unit_die)
Definition read.c:4083
static const gdb_byte * read_toplevel_die(const struct die_reader_specs *, struct die_info **, const gdb_byte *, gdb::array_view< attribute * >={})
Definition read.c:16021
static struct dwo_file * open_and_init_dwo_file(dwarf2_cu *cu, const char *dwo_name, const char *comp_dir)
Definition read.c:9297
static struct type * read_subrange_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:15650
static void set_descriptive_type(struct type *, struct die_info *, struct dwarf2_cu *)
Definition read.c:19666
static struct type * read_set_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:13881
static int prototyped_function_p(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14590
static struct type * read_typedef(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:14768
static struct dwarf2_section_info * cu_debug_loc_section(struct dwarf2_cu *cu)
Definition read.c:21414
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:12867
static int dwarf_max_cache_age
Definition read.c:732
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:3032
static const char * dwarf2_name(struct die_info *die, struct dwarf2_cu *)
Definition read.c:20302
struct cmd_list_element * show_dwarf_cmdlist
Definition read.c:22035
static int ada_imported_index
Definition read.c:145
static struct signatured_type * add_type_unit(dwarf2_per_objfile *per_objfile, ULONGEST sig, void **slot)
Definition read.c:3690
static void add_variant_property(struct field_info *fip, struct type *type, struct dwarf2_cu *cu)
Definition read.c:12029
static bool decode_locdesc(struct dwarf_block *, struct dwarf2_cu *, CORE_ADDR *addr)
Definition read.c:21151
static bool is_valid_DW_AT_calling_convention_for_type(ULONGEST value)
Definition read.c:12614
static enum dwarf_array_dim_ordering read_array_order(struct die_info *, struct dwarf2_cu *)
Definition read.c:13841
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:17526
static struct type * build_error_marker_type(struct dwarf2_cu *cu, struct die_info *die)
Definition read.c:19698
static void fill_in_loclist_baton(struct dwarf2_cu *cu, struct dwarf2_loclist_baton *baton, const struct attribute *attr)
Definition read.c:21459
static struct type * get_DW_AT_signature_type(struct die_info *, const struct attribute *, struct dwarf2_cu *)
Definition read.c:21028
static void handle_DW_AT_stmt_list(struct die_info *die, struct dwarf2_cu *cu, const file_and_directory &fnd, unrelocated_addr lowpc, bool have_code)
Definition read.c:7548
static int dwarf2_is_constructor(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:12144
struct type * dwarf2_get_die_type(cu_offset die_offset, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:20863
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:1539
static int dwarf2_ranges_process(unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag, Callback &&callback)
Definition read.c:10983
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:12008
static void read_signatured_type(signatured_type *sig_type, dwarf2_per_objfile *per_objfile)
Definition read.c:21080
static line_header_up dwarf_decode_line_header(sect_offset sect_off, struct dwarf2_cu *cu, const char *comp_dir)
Definition read.c:18014
static struct type * dwarf2_init_complex_target_type(struct dwarf2_cu *cu, int bits, const char *name_hint, enum bfd_endian byte_order)
Definition read.c:15173
static void read_attribute_reprocess(const struct die_reader_specs *reader, struct attribute *attr, dwarf_tag tag=DW_TAG_padding)
Definition read.c:17158
static struct dwarf_block * dwarf_alloc_block(struct dwarf2_cu *)
Definition read.c:21328
static int process_skeletonless_type_unit(void **slot, void *info)
Definition read.c:5019
htab_up allocate_signatured_type_table()
Definition read.c:3561
static int process_dwo_file_for_skeletonless_type_units(void **slot, void *info)
Definition read.c:5056
static int die_needs_namespace(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:6770
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:3933
static sect_offset read_loclist_index(struct dwarf2_cu *cu, ULONGEST loclist_index)
Definition read.c:17034
static bool check_physname
Definition read.c:123
static struct die_info * follow_die_sig(struct die_info *, const struct attribute *, struct dwarf2_cu **)
Definition read.c:20930
static void dw2_do_instantiate_symtab(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, bool skip_partial)
Definition read.c:1743
static struct type * read_base_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:15232
static const char * read_stub_str_index(struct dwarf2_cu *cu, ULONGEST str_index)
Definition read.c:17763
static void dwarf_decode_lines_1(struct line_header *lh, struct dwarf2_cu *cu, unrelocated_addr lowpc)
Definition read.c:18553
static void quirk_gcc_member_function_pointer(struct type *type, struct objfile *objfile)
Definition read.c:12425
#define NO_STMT_LIST_TYPE_UNIT_PSYMTAB
Definition read.c:4529
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:5765
static struct type * read_type_die_1(struct die_info *, struct dwarf2_cu *)
Definition read.c:19813
static void read_variable(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:10734
static htab_up allocate_dwp_loaded_cutus_table()
Definition read.c:9485
static void process_queue(dwarf2_per_objfile *per_objfile)
Definition read.c:5649
static hashval_t hash_stmt_list_entry(const struct stmt_list_hash *stmt_list_hash)
Definition read.c:1660
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:3718
void dwarf2_initialize_objfile(struct objfile *objfile)
Definition read.c:3383
dwarf2_per_objfile * get_dwarf2_per_objfile(struct objfile *objfile)
Definition read.c:165
static unrelocated_addr read_addr_index_from_leb128(struct dwarf2_cu *, const gdb_byte *, unsigned int *)
Definition read.c:17603
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:20877
static struct type * quirk_ada_thick_pointer(struct die_info *die, struct dwarf2_cu *cu, struct type *type)
Definition read.c:13553
static int dwarf2_flag_true_p(struct die_info *die, unsigned name, struct dwarf2_cu *cu)
Definition read.c:17937
static const char * var_decl_name(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:15444
static void dwarf2_get_subprogram_pc_bounds(struct die_info *die, unrelocated_addr *lowpc, unrelocated_addr *highpc, struct dwarf2_cu *cu)
Definition read.c:11243
static const struct dwop_section_names dwop_section_names
static void load_full_type_unit(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:21058
static int per_cu_offset_and_type_eq(const void *item_lhs, const void *item_rhs)
Definition read.c:21890
unsigned int dwarf_line_debug
Definition read.c:120
static void process_enumeration_scope(struct die_info *, struct dwarf2_cu *)
Definition read.c:13366
static struct signatured_type * lookup_signatured_type(struct dwarf2_cu *cu, ULONGEST sig)
Definition read.c:3868
static struct type * read_unspecified_type(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:15846
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:20837
static void dwarf2_find_base_address(struct die_info *die, struct dwarf2_cu *cu)
Definition read.c:3476
static struct type * lookup_die_type(struct die_info *, const struct attribute *, struct dwarf2_cu *)
Definition read.c:19721
static hashval_t line_header_hash(const struct line_header *ofs)
Definition read.c:1229
const struct dwarf2_debug_sections dwarf2_elf_names
Definition read.c:175
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:19478
static const registry< objfile >::key< dwarf2_per_objfile > dwarf2_objfile_data_key
Definition read.c:127
std::unordered_map< sect_offset, int, gdb::hash_enum< sect_offset > > offset_map_type
Definition read.c:11861
#define MAX_NR_V5_DWO_SECTIONS
Definition read.c:492
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:12806
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:7973
static unrelocated_addr read_addr_index(struct dwarf2_cu *cu, unsigned int addr_index)
Definition read.c:17594
static void dwarf_decode_lines(struct line_header *, struct dwarf2_cu *, unrelocated_addr, int decode_mapping)
Definition read.c:18778
static const char * dwarf2_canonicalize_name(const char *, struct dwarf2_cu *, struct objfile *)
Definition read.c:20272
static std::unique_ptr< struct dwp_file > open_and_init_dwp_file(dwarf2_per_objfile *per_objfile)
Definition read.c:9534
std::unique_ptr< struct dwo_file > dwo_file_up
Definition read.c:1163
static void add_ada_export_symbol(struct symbol *orig, const char *new_name, const char *orig_name, struct dwarf2_cu *cu, struct pending **list_to_add)
Definition read.c:18931
static void read_namespace(struct die_info *die, struct dwarf2_cu *)
Definition read.c:14122
static struct type * die_descriptive_type(struct die_info *, struct dwarf2_cu *)
Definition read.c:19651
std::unique_ptr< signatured_type > signatured_type_up
Definition read.h:411
dwarf2_section_enum
Definition read.h:830
@ DWARF2_EH_FRAME
Definition read.h:832
@ DWARF2_DEBUG_FRAME
Definition read.h:831
std::unique_ptr< dwarf2_per_cu_data, dwarf2_per_cu_data_deleter > dwarf2_per_cu_data_up
Definition read.h:94
dwarf2_per_objfile * get_dwarf2_per_objfile(struct objfile *objfile)
Definition read.c:165
static struct ppc_variant variants[]
const char * rust_last_path_segment(const char *path)
Definition rust-lang.c:46
enum var_types type
Definition scm-param.c:142
int openp(const char *path, openp_flags opts, const char *string, int mode, gdb::unique_xmalloc_ptr< char > *filename_opened)
Definition source.c:772
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition source.c:1269
gdb::unique_xmalloc_ptr< char > find_source_or_rewrite(const char *filename, const char *dirname)
Definition source.c:1199
@ OPF_SEARCH_IN_PATH
Definition source.h:31
@ OPF_RETURN_REALPATH
Definition source.h:32
static struct pending * common_block
Definition stabsread.c:4233
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 set_empty(CORE_ADDR start, CORE_ADDR end_inclusive, void *obj) override
Definition addrmap.c:191
const void * find(CORE_ADDR addr) const
Definition addrmap.h:88
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
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
ULONGEST as_nonnegative() const
Definition attribute.h:108
const char * as_string() const
Definition attribute.c:83
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
unrelocated_addr as_address() const
Definition attribute.c:35
void set_address(unrelocated_addr addr)
Definition attribute.h:264
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
const struct block * static_block() const
Definition block.c:354
void set_scope(const char *scope, struct obstack *obstack)
Definition block.c:313
void set_ranges(blockranges *ranges)
Definition block.h:173
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:487
struct context_stack * get_current_context_stack()
Definition buildsym.h:280
struct compunit_symtab * end_compunit_symtab_from_static_block(struct block *static_block, int expandable)
Definition buildsym.c:1003
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:386
void record_line(struct subfile *subfile, int line, unrelocated_addr pc, linetable_entry_flags flags)
Definition buildsym.c:626
struct compunit_symtab * end_expandable_symtab(CORE_ADDR end_addr)
Definition buildsym.c:1058
bool outermost_context_p() const
Definition buildsym.h:275
struct block * end_compunit_symtab_get_static_block(CORE_ADDR end_addr, int expandable, int required)
Definition buildsym.c:760
void augment_type_symtab()
Definition buildsym.c:1092
struct pending ** get_file_symbols()
Definition buildsym.h:302
struct context_stack pop_context()
Definition buildsym.c:1156
struct pending ** get_global_symbols()
Definition buildsym.h:307
struct subfile * get_current_subfile()
Definition buildsym.h:292
void record_block_range(struct block *block, CORE_ADDR start, CORE_ADDR end_inclusive)
Definition buildsym.c:404
struct context_stack * push_context(int desc, CORE_ADDR valu)
Definition buildsym.c:1134
struct using_direct ** get_global_using_directives()
Definition buildsym.h:270
struct type * builtin_real
Definition f-lang.h:335
struct type * builtin_real_s8
Definition f-lang.h:336
struct type * builtin_real_s16
Definition f-lang.h:337
struct type * builtin_double
Definition gdbtypes.h:2090
struct type * builtin_long_double
Definition gdbtypes.h:2091
struct type * builtin_int
Definition gdbtypes.h:2080
struct type * builtin_void
Definition gdbtypes.h:2077
struct type * builtin_float
Definition gdbtypes.h:2089
__extension__ enum call_site_parameter_kind kind
Definition call-site.h:145
const gdb_byte * value
Definition call-site.h:151
union call_site_parameter_u u
Definition call-site.h:147
const gdb_byte * data_value
Definition call-site.h:157
unsigned parameter_count
Definition call-site.h:223
static hashval_t hash(const call_site *a)
Definition call-site.h:178
struct call_site_parameter parameter[]
Definition call-site.h:241
CORE_ADDR pc() const
Definition gdbtypes.c:6188
call_site(unrelocated_addr pc, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition call-site.h:166
static int eq(const call_site *a, const call_site *b)
Definition call-site.h:172
struct call_site * tail_call_next
Definition call-site.h:214
dwarf2_per_objfile *const per_objfile
Definition call-site.h:232
struct symbol * contents[1]
Definition f-lang.h:313
size_t n_entries
Definition f-lang.h:309
unsigned int get_length_with_initial() const
unsigned char addr_size
unsigned char version
unsigned int get_length_without_initial() const
cu_offset type_cu_offset_in_tu
cu_offset first_die_cu_offset
sect_offset abbrev_sect_off
bool offset_in_cu_p(sect_offset off) const
unsigned int initial_length_size
sect_offset sect_off
LONGEST read_offset(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read) const
unsigned int offset_size
unrelocated_addr read_address(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read) const
void set_epilogue_unwind_valid(bool epilogue_unwind_valid)
Definition symtab.h:1877
symtab * primary_filetab() const
Definition symtab.c:415
enum language language() const
Definition symtab.c:426
struct blockvector * blockvector()
Definition symtab.h:1847
struct compunit_symtab * user
Definition symtab.h:1981
void set_locations_valid(bool locations_valid)
Definition symtab.h:1867
void set_call_site_htab(htab_t call_site_htab)
Definition symtab.c:378
struct compunit_symtab ** includes
Definition symtab.h:1975
struct objfile * objfile() const
Definition symtab.h:1788
const char * dirname() const
Definition symtab.h:1837
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:16770
void dump(struct objfile *objfile) override
Definition read.c:16673
enum language lookup_global_symbol_language(struct objfile *objfile, const char *name, domain_enum domain, bool *symbol_found_p) override
Definition read.c:16715
void read_partial_symbols(struct objfile *objfile) override
Definition read.c:16709
dwarf2_per_cu_data * find_per_cu(dwarf2_per_bfd *per_bfd, CORE_ADDR adjusted_pc) override
Definition read.c:16757
bool can_lazily_read_symbols() override
Definition read.c:16704
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:16830
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:16792
Definition read.c:4804
sect_offset die_offset
Definition read.c:4805
cooked_index_flag flags
Definition read.c:4809
dwarf_tag tag
Definition read.c:4808
CORE_ADDR spec_offset
Definition read.c:4807
const char * name
Definition read.c:4806
const char * name
Definition gdbtypes.h:1607
unsigned int is_private
Definition gdbtypes.h:1617
struct type * type
Definition gdbtypes.h:1611
unsigned int is_protected
Definition gdbtypes.h:1614
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:28
struct die_info * child
Definition die.h:140
static die_info * allocate(struct obstack *obstack, int num_attrs)
Definition die.c:27
unsigned char building_fullname
Definition die.h:122
void dump(int max_level)
Definition die.c:218
unsigned char in_process
Definition die.h:125
struct attribute attrs[1]
Definition die.h:147
struct attribute * attr(dwarf_attribute name)
Definition die.h:51
ULONGEST gnu_ranges_base()
Definition die.h:82
unsigned int abbrev
Definition die.h:131
void error_dump()
Definition die.c:226
static int eq(const void *item_lhs, const void *item_rhs)
Definition die.c:52
unsigned char has_children
Definition die.h:128
sect_offset sect_off
Definition die.h:134
struct die_info * parent
Definition die.h:142
__extension__ enum dwarf_tag tag
Definition die.h:115
ULONGEST rnglists_base()
Definition die.h:99
struct die_info * sibling
Definition die.h:141
static hashval_t hash(const void *item)
Definition die.c:42
gdb::optional< ULONGEST > addr_base()
Definition die.h:62
unsigned char num_attrs
Definition die.h:118
struct dwarf2_cu * cu
Definition read.c:556
struct abbrev_table * abbrev_table
Definition read.c:572
struct dwarf2_section_info * die_section
Definition read.c:563
struct dwo_file * dwo_file
Definition read.c:559
const gdb_byte * buffer
Definition read.c:566
const gdb_byte * buffer_end
Definition read.c:569
void print_stats(struct objfile *objfile, bool print_bcache) override
Definition read.c:2209
struct symtab * find_last_source_symtab(struct objfile *objfile) override
Definition read.c:2163
void expand_all_symtabs(struct objfile *objfile) override
Definition read.c:2231
void map_symbol_filenames(struct objfile *objfile, gdb::function_view< symbol_filename_ftype > fun, bool need_fullname) override
Definition read.c:3224
void forget_cached_source_info(struct objfile *objfile) override
Definition read.c:2200
bool has_unexpanded_symtabs(struct objfile *objfile) override
Definition read.c:3307
bool has_symbols(struct objfile *objfile) override
Definition read.c:3299
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:3192
virtual dwarf2_per_cu_data * find_per_cu(dwarf2_per_bfd *per_bfd, CORE_ADDR adjusted_pc)
Definition read.c:3180
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:7719
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< 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
gdb::optional< unrelocated_addr > base_address
Definition cu.h:104
const char * producer
Definition cu.h:115
bool checked_producer
Definition cu.h:260
auto_obstack comp_unit_obstack
Definition cu.h:145
struct comp_unit_head header
Definition cu.h:101
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
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
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
unrelocated_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:1802
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
dwarf2_per_cu_data * get_cu(int index) const
Definition read.h:434
void map_info_sections(struct objfile *objfile)
Definition read.c:1578
void locate_sections(bfd *abfd, asection *sectp, const dwarf2_debug_sections &names)
Definition read.c:1412
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:1258
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:1813
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:1270
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:1127
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 reading_dwo_directly
Definition read.h:141
sect_offset sect_off
Definition read.h:120
packed< unsigned int, 1 > mark
Definition read.h:173
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:135
std::unique_ptr< file_and_directory > fnd
Definition read.h:215
int offset_size() const
Definition read.c:21575
struct quick_file_names * file_names
Definition read.h:220
const comp_unit_head * get_header() const
Definition read.c:21548
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
packed< bool, 1 > m_header_read_in
Definition read.h:169
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:159
comp_unit_head m_header
Definition read.h:209
void free_cached_file_names()
Definition read.c:2179
packed< bool, 1 > queued
Definition read.h:163
int addr_size() const
Definition read.c:21567
unsigned int is_debug_types
Definition read.h:132
int ref_addr_size() const
Definition read.c:21583
unsigned int tu_read
Definition read.h:151
packed< bool, 1 > files_read
Definition read.h:177
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:21871
struct objfile * objfile
Definition read.h:724
unrelocated_addr adjust(unrelocated_addr addr)
Definition read.c:1208
std::unordered_map< type_unit_group *, type_unit_group_unshareable_up > m_type_units
Definition read.h:756
std::unordered_map< signatured_type *, struct type * > m_type_map
Definition read.h:759
compunit_symtab * get_symtab(const dwarf2_per_cu_data *per_cu) const
Definition read.c:1333
CORE_ADDR relocate(unrelocated_addr addr)
Definition read.c:1219
type_unit_group_unshareable * get_type_unit_group_unshareable(type_unit_group *tu_group)
Definition read.c:6246
void remove_cu(dwarf2_per_cu_data *per_cu)
Definition read.c:21841
const char * read_line_string(const gdb_byte *buf, const struct comp_unit_head *cu_header, unsigned int *bytes_read_ptr)
Definition read.c:17551
void age_comp_units()
Definition read.c:21796
dwarf2_cu * sym_cu
Definition read.h:739
std::unique_ptr< type_unit_group_unshareable > type_unit_group_unshareable_up
Definition read.h:753
void set_type_for_signatured_type(signatured_type *sig_type, struct type *type)
Definition read.c:6270
void set_cu(dwarf2_per_cu_data *per_cu, std::unique_ptr< dwarf2_cu > cu)
Definition read.c:21785
struct type * get_type_for_signatured_type(signatured_type *sig_type) const
Definition read.c:6260
gdb::optional< std::queue< dwarf2_queue_item > > queue
Definition read.h:742
std::unordered_map< dwarf2_per_cu_data *, std::unique_ptr< dwarf2_cu > > m_dwarf2_cus
Definition read.h:764
htab_up die_type_hash
Definition read.h:733
void set_symtab(const dwarf2_per_cu_data *per_cu, compunit_symtab *symtab)
Definition read.c:1343
struct dwarf2_per_bfd * per_bfd
Definition read.h:728
void remove_all_cus()
Definition read.c:1289
htab_up line_header_hash
Definition read.h:736
bool symtab_set_p(const dwarf2_per_cu_data *per_cu) const
Definition read.c:1323
std::vector< compunit_symtab * > m_symtabs
Definition read.h:748
dwarf2_cu * get_cu(dwarf2_per_cu_data *per_cu)
Definition read.c:21773
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
bfd_size_type virtual_offset
Definition section.h:120
const char * get_name() const
Definition section.c:74
asection * get_bfd_section() const
Definition section.c:62
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
union dwarf2_section_info::@54 s
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:360
htab_up tus
Definition read.c:375
DISABLE_COPY_AND_ASSIGN(dwo_file)
const char * dwo_name
Definition read.c:353
const char * comp_dir
Definition read.c:356
dwo_file()=default
htab_up cus
Definition read.c:371
struct dwarf2_section_info rnglists
Definition read.c:293
std::vector< dwarf2_section_info > types
Definition read.c:298
struct dwarf2_section_info abbrev
Definition read.c:287
struct dwarf2_section_info str_offsets
Definition read.c:295
struct dwarf2_section_info loclists
Definition read.c:290
struct dwarf2_section_info macro
Definition read.c:292
struct dwarf2_section_info loc
Definition read.c:289
struct dwarf2_section_info info
Definition read.c:297
struct dwarf2_section_info macinfo
Definition read.c:291
struct dwarf2_section_info str
Definition read.c:294
struct dwarf2_section_info line
Definition read.c:288
ULONGEST signature
Definition read.c:311
sect_offset sect_off
Definition read.c:317
struct dwarf2_section_info * section
Definition read.c:314
cu_offset type_offset_in_tu
Definition read.c:321
struct dwo_file * dwo_file
Definition read.c:306
unsigned int length
Definition read.c:318
struct dwarf2_section_names str_dwo
Definition read.c:211
struct dwarf2_section_names types_dwo
Definition read.c:213
struct dwarf2_section_names loclists_dwo
Definition read.c:207
struct dwarf2_section_names str_offsets_dwo
Definition read.c:212
struct dwarf2_section_names line_dwo
Definition read.c:205
struct dwarf2_section_names cu_index
Definition read.c:214
struct dwarf2_section_names tu_index
Definition read.c:215
struct dwarf2_section_names macinfo_dwo
Definition read.c:208
struct dwarf2_section_names rnglists_dwo
Definition read.c:210
struct dwarf2_section_names info_dwo
Definition read.c:204
struct dwarf2_section_names macro_dwo
Definition read.c:209
struct dwarf2_section_names loc_dwo
Definition read.c:206
struct dwarf2_section_names abbrev_dwo
Definition read.c:203
int version
Definition read.c:521
unsigned int num_sections
Definition read.c:541
asection ** elf_sections
Definition read.c:542
htab_up loaded_tus
Definition read.c:537
const char * name
Definition read.c:518
gdb_bfd_ref_ptr dbfd
Definition read.c:524
htab_up loaded_cus
Definition read.c:536
const struct dwp_hash_table * tus
Definition read.c:533
const struct dwp_hash_table * cus
Definition read.c:530
dwp_file(const char *name_, gdb_bfd_ref_ptr &&abfd)
Definition read.c:511
int section_ids[MAX_NR_V2_DWO_SECTIONS]
Definition read.c:484
const gdb_byte * indices
Definition read.c:471
struct dwp_hash_table::@50::@52 v2
const gdb_byte * sizes
Definition read.c:486
const gdb_byte * unit_table
Definition read.c:466
const gdb_byte * hash_table
Definition read.c:466
uint32_t nr_units
Definition read.c:465
struct dwp_hash_table::@50::@53 v5
struct dwp_hash_table::@50::@51 v1
const gdb_byte * offsets
Definition read.c:485
uint32_t nr_slots
Definition read.c:465
uint32_t version
Definition read.c:464
union dwp_hash_table::@50 section_pool
uint32_t nr_columns
Definition read.c:464
struct dwarf2_section_info loc
Definition read.c:398
struct dwarf2_section_info cu_index
Definition read.c:384
struct dwarf2_section_info rnglists
Definition read.c:402
struct dwarf2_section_info str
Definition read.c:383
struct dwarf2_section_info line
Definition read.c:397
struct dwarf2_section_info info
Definition read.c:396
struct dwarf2_section_info macro
Definition read.c:401
struct dwarf2_section_info tu_index
Definition read.c:385
struct dwarf2_section_info str_offsets
Definition read.c:403
struct dwarf2_section_info macinfo
Definition read.c:400
struct dwarf2_section_info loclists
Definition read.c:399
struct dwarf2_section_info abbrev
Definition read.c:395
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:54
std::unique_ptr< index_cache_resource > index_cache_res
Definition dwz.h:58
const dwarf2_property_baton * baton() const
Definition gdbtypes.h:348
void set_loclist(const dwarf2_property_baton *baton)
Definition gdbtypes.h:363
LONGEST const_val() const
Definition gdbtypes.h:330
bool is_constant() const
Definition gdbtypes.h:345
void set_variable_name(const char *name)
Definition gdbtypes.h:411
void set_undefined()
Definition gdbtypes.h:325
void set_locexpr(const dwarf2_property_baton *baton)
Definition gdbtypes.h:357
void set_addr_offset(const dwarf2_property_baton *baton)
Definition gdbtypes.h:369
void set_variant_parts(gdb::array_view< variant_part > *variant_parts)
Definition gdbtypes.h:382
void set_const_val(LONGEST const_val)
Definition gdbtypes.h:337
std::vector< struct nextfield > fields
Definition read.c:694
std::vector< struct fnfieldlist > fnfieldlists
Definition read.c:703
std::vector< variant_part_builder > variant_parts
Definition read.c:718
bool non_public_fields
Definition read.c:698
std::vector< struct decl_field > typedef_field_list
Definition read.c:707
std::vector< struct decl_field > nested_types_list
Definition read.c:711
variant_part_builder * current_variant_part
Definition read.c:715
int nfields() const
Definition read.c:721
std::vector< struct nextfield > baseclasses
Definition read.c:695
void set_type(struct type *type)
Definition gdbtypes.h:552
void set_loc_bitpos(LONGEST bitpos)
Definition gdbtypes.h:617
LONGEST loc_bitpos() const
Definition gdbtypes.h:611
void set_is_artificial(bool is_artificial)
Definition gdbtypes.h:572
void set_loc_dwarf_block(dwarf2_locexpr_baton *dwarf_block)
Definition gdbtypes.h:665
void set_loc_physname(const char *physname)
Definition gdbtypes.h:653
bool is_artificial() const
Definition gdbtypes.h:567
void set_bitsize(unsigned int bitsize)
Definition gdbtypes.h:582
field_loc_kind loc_kind() const
Definition gdbtypes.h:606
LONGEST loc_enumval() const
Definition gdbtypes.h:623
void set_loc_enumval(LONGEST enumval)
Definition gdbtypes.h:629
void set_name(const char *name)
Definition gdbtypes.h:562
const char * name() const
Definition gdbtypes.h:557
unsigned int bitsize() const
Definition gdbtypes.h:577
struct type * type() const
Definition gdbtypes.h:547
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:34
dir_index d_index
Definition line-header.h:58
struct symtab * symtab
Definition line-header.h:65
const char * name
Definition line-header.h:52
const char * include_dir(const line_header *lh) const
unsigned int is_private
Definition gdbtypes.h:1567
unsigned int is_artificial
Definition gdbtypes.h:1569
__extension__ enum dwarf_defaulted_attribute defaulted
Definition gdbtypes.h:1587
struct type * type
Definition gdbtypes.h:1556
const char * physname
Definition gdbtypes.h:1548
unsigned int voffset
Definition gdbtypes.h:1596
struct type * fcontext
Definition gdbtypes.h:1561
unsigned int is_constructor
Definition gdbtypes.h:1578
unsigned int is_protected
Definition gdbtypes.h:1568
unsigned int is_deleted
Definition gdbtypes.h:1582
struct fn_field * fn_fields
Definition gdbtypes.h:1531
std::vector< struct fn_field > fnfields
Definition read.c:685
const char * name
Definition read.c:684
void negate()
Definition gmp-utils.h:168
static gdb_mpz pow(unsigned long base, unsigned long exp)
Definition gmp-utils.h:107
bool set(const char *str, int base)
Definition gmp-utils.h:101
void set_section_index(short idx)
Definition symtab.h:614
void set_demangled_name(const char *name, struct obstack *obstack)
Definition symtab.c:778
struct obstack * obstack
Definition symtab.h:585
const char * natural_name() const
Definition symtab.c:1056
const gdb_byte * bytes
Definition symtab.h:559
const char * print_name() const
Definition symtab.h:475
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:943
const char * search_name() const
Definition symtab.c:1106
enum language language() const
Definition symtab.h:502
void set_language(enum language language, struct obstack *obstack)
Definition symtab.c:803
short section_index() const
Definition symtab.h:621
const char * linkage_name() const
Definition symtab.h:460
void set_linkage_name(const char *linkage_name)
Definition symtab.h:494
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:666
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:640
virtual void printchar(int ch, struct type *chtype, struct ui_file *stream) const
Definition c-lang.c:158
virtual enum array_ordering array_ordering() const
Definition language.h:660
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
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:96
unsigned char opcode_base
int file_names_size() const
unsigned char addr_size
Definition read.c:250
unsigned char segment_collector_size
Definition read.c:254
unsigned int offset_entry_count
Definition read.c:257
unsigned int length
Definition read.c:243
struct dynamic_prop_list * dyn_prop_list
Definition gdbtypes.h:940
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:2328
void build_name_components(dwarf2_per_objfile *per_objfile)
Definition read.c:2401
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 name_offset
offset_type idx
int virtuality
Definition read.c:674
int accessibility
Definition read.c:673
sect_offset offset
Definition read.c:678
auto_obstack storage_obstack
Definition objfiles.h:256
const char * original_name
Definition objfiles.h:718
struct objfile * separate_debug_objfile_backlink
Definition objfiles.h:830
int sect_index_data
Definition objfiles.h:799
struct gdbarch * arch() const
Definition objfiles.h:507
struct objfile_per_bfd_storage * per_bfd
Definition objfiles.h:744
gdb_bfd_ref_ptr obfd
Definition objfiles.h:740
CORE_ADDR text_section_offset() const
Definition objfiles.h:482
const char * intern(const char *str)
Definition objfiles.h:494
objfile_flags flags
Definition objfiles.h:724
auto_obstack objfile_obstack
Definition objfiles.h:760
std::forward_list< quick_symbol_functions_up > qf
Definition objfiles.h:772
CORE_ADDR data_section_offset() const
Definition objfiles.h:487
struct symbol * template_symbols
Definition objfiles.h:846
::section_offsets section_offsets
Definition objfiles.h:786
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:1620
const char * comp_dir
Definition read.c:1612
unsigned int num_file_names
Definition read.c:1608
const char ** file_names
Definition read.c:1616
struct stmt_list_hash hash
Definition read.c:1605
struct dynamic_prop high
Definition gdbtypes.h:721
unsigned int flag_upper_bound_is_count
Definition gdbtypes.h:738
struct dynamic_prop low
Definition gdbtypes.h:717
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:1644
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:1635
void dump(struct objfile *objfile) override
Definition read.c:1630
struct type * concrete_type
Definition symtab.h:1586
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:5011
cooked_index_storage * storage
Definition read.c:5012
struct dwo_unit * dwo_unit
Definition read.c:266
sect_offset line_sect_off
Definition read.c:269
std::string name
Definition buildsym.h:57
std::string name_for_id
Definition buildsym.h:62
struct symtab * symtab
Definition buildsym.h:66
void set_line(unsigned int line)
Definition symtab.h:1346
address_class aclass() const
Definition symtab.h:1274
unsigned maybe_copied
Definition symtab.h:1491
struct type * type() const
Definition symtab.h:1331
void set_aclass_index(unsigned int aclass_index)
Definition symtab.h:1264
void set_is_artificial(bool artificial)
Definition symtab.h:1418
__extension__ enum symbol_subclass_kind subclass
Definition symtab.h:1495
void set_type(struct type *type)
Definition symtab.h:1336
void set_is_argument(bool is_argument)
Definition symtab.h:1311
void set_value_address(CORE_ADDR address)
Definition symtab.h:1369
CORE_ADDR value_address() const
Definition symtab.h:1361
void set_value_bytes(const gdb_byte *bytes)
Definition symtab.h:1379
struct symtab * symtab
Definition symtab.h:1457
void set_is_inlined(bool is_inlined)
Definition symtab.h:1321
void set_value_longest(LONGEST value)
Definition symtab.h:1356
struct symbol * hash_next
Definition symtab.h:1524
void set_domain(domain_enum domain)
Definition symtab.h:1291
void set_symtab(struct symtab *symtab)
Definition symtab.c:6510
void set_value_common_block(const common_block *common_block)
Definition symtab.h:1389
enum language language() const
Definition symtab.h:1697
void set_language(enum language language)
Definition symtab.h:1702
int n_template_arguments
Definition symtab.h:1573
struct symbol ** template_arguments
Definition symtab.h:1577
tu_abbrev_offset(signatured_type *sig_type_, sect_offset abbrev_offset_)
Definition read.c:4882
signatured_type * sig_type
Definition read.c:4892
sect_offset abbrev_offset
Definition read.c:4893
bool operator<(const tu_abbrev_offset &other) const
Definition read.c:4887
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:649
struct compunit_symtab * compunit_symtab
Definition read.h:635
struct type * target_type() const
Definition gdbtypes.h:1037
type_code code() const
Definition gdbtypes.h:956
void set_is_prototyped(bool is_prototyped)
Definition gdbtypes.h:1164
void copy_fields(struct type *src)
Definition gdbtypes.c:5920
void set_code(type_code code)
Definition gdbtypes.h:962
ULONGEST length() const
Definition gdbtypes.h:983
void set_is_multi_dimensional(bool value)
Definition gdbtypes.h:1298
bool has_varargs() const
Definition gdbtypes.h:1172
void set_endianity_is_not_default(bool endianity_is_not_default)
Definition gdbtypes.h:1255
struct field & field(int idx) const
Definition gdbtypes.h:1012
void set_has_no_signedness(bool has_no_signedness)
Definition gdbtypes.h:1119
void set_index_type(type *index_type)
Definition gdbtypes.h:1047
void set_target_type(struct type *target_type)
Definition gdbtypes.h:1042
bool is_unsigned() const
Definition gdbtypes.h:1100
struct main_type * main_type
Definition gdbtypes.h:1513
void set_is_unsigned(bool is_unsigned)
Definition gdbtypes.h:1105
void set_is_stub(bool is_stub)
Definition gdbtypes.h:1133
void set_is_declared_class(bool is_declared_class) const
Definition gdbtypes.h:1272
void set_has_varargs(bool has_varargs)
Definition gdbtypes.h:1177
void set_is_flag_enum(bool is_flag_enum)
Definition gdbtypes.h:1286
void set_bounds(range_bounds *bounds)
Definition gdbtypes.h:1083
bool is_declared_class() const
Definition gdbtypes.h:1267
bool is_stub() const
Definition gdbtypes.h:1128
bool has_no_signedness() const
Definition gdbtypes.h:1114
void add_dyn_prop(dynamic_prop_node_kind kind, dynamic_prop prop)
Definition gdbtypes.c:2891
void set_num_fields(unsigned int num_fields)
Definition gdbtypes.h:1000
unsigned int num_fields() const
Definition gdbtypes.h:994
void set_name(const char *name)
Definition gdbtypes.h:974
struct fixed_point_type_info & fixed_point_info() const
Definition gdbtypes.h:1306
void alloc_fields(unsigned int nfields, bool init=true)
Definition gdbtypes.c:5898
ULONGEST bit_stride() const
Definition gdbtypes.h:1090
void set_length(ULONGEST length)
Definition gdbtypes.h:988
struct field * fields() const
Definition gdbtypes.h:1006
range_bounds * bounds() const
Definition gdbtypes.h:1065
const char * name() const
Definition gdbtypes.h:968
type * index_type() const
Definition gdbtypes.h:1032
void set_stub_is_supported(bool stub_is_supported)
Definition gdbtypes.h:1206
unsigned short bit_offset() const
Definition gdbtypes.h:1424
void set_fields(struct field *fields)
Definition gdbtypes.h:1019
void set_target_is_stub(bool target_is_stub)
Definition gdbtypes.h:1149
Definition value.h:130
gdb::array_view< gdb_byte > contents_writeable()
Definition value.c:1271
static struct value * allocate(struct type *type)
Definition value.c:957
int last_field
Definition read.c:641
struct dwarf_block * discr_list_data
Definition read.c:654
std::vector< variant_part_builder > variant_parts
Definition read.c:644
ULONGEST discriminant_value
Definition read.c:651
int first_field
Definition read.c:640
bool default_branch
Definition read.c:648
bool processing_variant
Definition read.c:668
sect_offset discriminant_offset
Definition read.c:662
std::vector< variant_field > variants
Definition read.c:665
int discriminant_index
Definition gdbtypes.h:261
gdb::array_view< variant > variants
Definition gdbtypes.h:269
bool is_unsigned
Definition gdbtypes.h:265
int last_field
Definition gdbtypes.h:233
gdb::array_view< variant_part > parts
Definition gdbtypes.h:236
int first_field
Definition gdbtypes.h:232
gdb::array_view< discriminant_range > discriminants
Definition gdbtypes.h:226
struct dwarf2_section_info info_or_types
Definition read.c:420
struct dwarf2_section_info abbrev
Definition read.c:412
struct dwarf2_section_info macro
Definition read.c:416
struct dwarf2_section_info str_offsets
Definition read.c:417
struct dwarf2_section_info macinfo
Definition read.c:415
struct dwarf2_section_info line
Definition read.c:413
struct dwarf2_section_info loc
Definition read.c:414
bfd_size_type loc_offset
Definition read.c:436
bfd_size_type abbrev_offset
Definition read.c:430
bfd_size_type abbrev_size
Definition read.c:431
bfd_size_type macro_offset
Definition read.c:445
bfd_size_type str_offsets_offset
Definition read.c:451
bfd_size_type loclists_offset
Definition read.c:439
bfd_size_type rnglists_size
Definition read.c:449
bfd_size_type str_offsets_size
Definition read.c:452
bfd_size_type macinfo_offset
Definition read.c:442
bfd_size_type macinfo_size
Definition read.c:443
bfd_size_type line_size
Definition read.c:434
bfd_size_type rnglists_offset
Definition read.c:448
bfd_size_type loc_size
Definition read.c:437
bfd_size_type line_offset
Definition read.c:433
bfd_size_type info_or_types_size
Definition read.c:457
bfd_size_type info_or_types_offset
Definition read.c:456
bfd_size_type macro_size
Definition read.c:446
bfd_size_type loclists_size
Definition read.c:440
struct symtab * allocate_symtab(struct compunit_symtab *cust, const char *filename, const char *filename_for_id)
Definition symfile.c:2821
scoped_restore_tmpl< int > increment_reading_symtab(void)
Definition symfile.c:185
void fixup_symbol_section(struct symbol *sym, struct objfile *objfile)
Definition symtab.c:1723
int register_symbol_block_impl(enum address_class aclass, const struct symbol_block_ops *ops)
Definition symtab.c:6428
int register_symbol_computed_impl(enum address_class aclass, const struct symbol_computed_ops *ops)
Definition symtab.c:6402
bool producer_is_realview(const char *producer)
Definition symtab.c:6350
bool basenames_may_differ
Definition symtab.c:270
search_domain
Definition symtab.h:945
symbol_name_match_type
Definition symtab.h:63
@ LOC_STATIC
Definition symtab.h:979
@ LOC_BLOCK
Definition symtab.h:1028
@ LOC_LABEL
Definition symtab.h:1022
@ LOC_UNRESOLVED
Definition symtab.h:1057
@ LOC_CONST
Definition symtab.h:975
@ LOC_CONST_BYTES
Definition symtab.h:1033
@ LOC_OPTIMIZED_OUT
Definition symtab.h:1062
@ LOC_TYPEDEF
Definition symtab.h:1018
@ LOC_COMMON_BLOCK
Definition symtab.h:1070
@ LOC_COMPUTED
Definition symtab.h:1066
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:399
@ SYMBOL_RUST_VTABLE
Definition symtab.h:1224
@ SYMBOL_TEMPLATE
Definition symtab.h:1221
#define SYMBOL_COMPUTED_OPS(symbol)
Definition symtab.h:1543
domain_enum
Definition symtab.h:900
@ VAR_DOMAIN
Definition symtab.h:910
@ STRUCT_DOMAIN
Definition symtab.h:916
@ LABEL_DOMAIN
Definition symtab.h:924
@ COMMON_BLOCK_DOMAIN
Definition symtab.h:928
@ MODULE_DOMAIN
Definition symtab.h:920
#define SYMBOL_LOCATION_BATON(symbol)
Definition symtab.h:1546
const struct type_print_options type_print_raw_options
Definition typeprint.c:41
static char * sect_offset_str(sect_offset offset)
Definition types.h:35
std::string ldirname(const char *filename)
Definition utils.c:3306
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition utils.c:3166
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
#define gdb_stderr
Definition utils.h:187
#define gdb_stdlog
Definition utils.h:190
void get_formatted_print_options(struct value_print_options *opts, char format)
Definition valprint.c:152
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:1191
struct value * value_from_longest(struct type *type, LONGEST num)
Definition value.c:3438
value_ref_ptr release_value(struct value *val)
Definition value.c:1450
const char version[]
Definition version.c:2
#define nullptr
Definition x86-cpuid.h:28