1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 /* This is used to store the data that is always per objfile. */
109 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
111 /* These are used to store the dwarf2_per_bfd objects.
113 objfiles having the same BFD, which doesn't require relocations, are going to
114 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
116 Other objfiles are not going to share a dwarf2_per_bfd with any other
117 objfiles, so they'll have their own version kept in the _objfile_data_key
119 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
120 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
122 /* The "aclass" indices for various kinds of computed DWARF symbols. */
124 static int dwarf2_locexpr_index
;
125 static int dwarf2_loclist_index
;
126 static int dwarf2_locexpr_block_index
;
127 static int dwarf2_loclist_block_index
;
129 /* Size of .debug_loclists section header for 32-bit DWARF format. */
130 #define LOCLIST_HEADER_SIZE32 12
132 /* Size of .debug_loclists section header for 64-bit DWARF format. */
133 #define LOCLIST_HEADER_SIZE64 20
135 /* An index into a (C++) symbol name component in a symbol name as
136 recorded in the mapped_index's symbol table. For each C++ symbol
137 in the symbol table, we record one entry for the start of each
138 component in the symbol in a table of name components, and then
139 sort the table, in order to be able to binary search symbol names,
140 ignoring leading namespaces, both completion and regular look up.
141 For example, for symbol "A::B::C", we'll have an entry that points
142 to "A::B::C", another that points to "B::C", and another for "C".
143 Note that function symbols in GDB index have no parameter
144 information, just the function/method names. You can convert a
145 name_component to a "const char *" using the
146 'mapped_index::symbol_name_at(offset_type)' method. */
148 struct name_component
150 /* Offset in the symbol name where the component starts. Stored as
151 a (32-bit) offset instead of a pointer to save memory and improve
152 locality on 64-bit architectures. */
153 offset_type name_offset
;
155 /* The symbol's index in the symbol and constant pool tables of a
160 /* Base class containing bits shared by both .gdb_index and
161 .debug_name indexes. */
163 struct mapped_index_base
165 mapped_index_base () = default;
166 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
168 /* The name_component table (a sorted vector). See name_component's
169 description above. */
170 std::vector
<name_component
> name_components
;
172 /* How NAME_COMPONENTS is sorted. */
173 enum case_sensitivity name_components_casing
;
175 /* Return the number of names in the symbol table. */
176 virtual size_t symbol_name_count () const = 0;
178 /* Get the name of the symbol at IDX in the symbol table. */
179 virtual const char *symbol_name_at
180 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
182 /* Return whether the name at IDX in the symbol table should be
184 virtual bool symbol_name_slot_invalid (offset_type idx
) const
189 /* Build the symbol name component sorted vector, if we haven't
191 void build_name_components (dwarf2_per_objfile
*per_objfile
);
193 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
194 possible matches for LN_NO_PARAMS in the name component
196 std::pair
<std::vector
<name_component
>::const_iterator
,
197 std::vector
<name_component
>::const_iterator
>
198 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
200 dwarf2_per_objfile
*per_objfile
) const;
202 /* Prevent deleting/destroying via a base class pointer. */
204 ~mapped_index_base() = default;
207 /* A description of the mapped index. The file format is described in
208 a comment by the code that writes the index. */
209 struct mapped_index final
: public mapped_index_base
211 /* A slot/bucket in the symbol table hash. */
212 struct symbol_table_slot
214 const offset_type name
;
215 const offset_type vec
;
218 /* Index data format version. */
221 /* The address table data. */
222 gdb::array_view
<const gdb_byte
> address_table
;
224 /* The symbol table, implemented as a hash table. */
225 gdb::array_view
<symbol_table_slot
> symbol_table
;
227 /* A pointer to the constant pool. */
228 const char *constant_pool
= nullptr;
230 bool symbol_name_slot_invalid (offset_type idx
) const override
232 const auto &bucket
= this->symbol_table
[idx
];
233 return bucket
.name
== 0 && bucket
.vec
== 0;
236 /* Convenience method to get at the name of the symbol at IDX in the
238 const char *symbol_name_at
239 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
240 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
242 size_t symbol_name_count () const override
243 { return this->symbol_table
.size (); }
246 /* A description of the mapped .debug_names.
247 Uninitialized map has CU_COUNT 0. */
248 struct mapped_debug_names final
: public mapped_index_base
250 bfd_endian dwarf5_byte_order
;
251 bool dwarf5_is_dwarf64
;
252 bool augmentation_is_gdb
;
254 uint32_t cu_count
= 0;
255 uint32_t tu_count
, bucket_count
, name_count
;
256 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
257 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
258 const gdb_byte
*name_table_string_offs_reordered
;
259 const gdb_byte
*name_table_entry_offs_reordered
;
260 const gdb_byte
*entry_pool
;
267 /* Attribute name DW_IDX_*. */
270 /* Attribute form DW_FORM_*. */
273 /* Value if FORM is DW_FORM_implicit_const. */
274 LONGEST implicit_const
;
276 std::vector
<attr
> attr_vec
;
279 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
281 const char *namei_to_name
282 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
284 /* Implementation of the mapped_index_base virtual interface, for
285 the name_components cache. */
287 const char *symbol_name_at
288 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
289 { return namei_to_name (idx
, per_objfile
); }
291 size_t symbol_name_count () const override
292 { return this->name_count
; }
295 /* See dwarf2read.h. */
298 get_dwarf2_per_objfile (struct objfile
*objfile
)
300 return dwarf2_objfile_data_key
.get (objfile
);
303 /* Default names of the debugging sections. */
305 /* Note that if the debugging section has been compressed, it might
306 have a name like .zdebug_info. */
308 static const struct dwarf2_debug_sections dwarf2_elf_names
=
310 { ".debug_info", ".zdebug_info" },
311 { ".debug_abbrev", ".zdebug_abbrev" },
312 { ".debug_line", ".zdebug_line" },
313 { ".debug_loc", ".zdebug_loc" },
314 { ".debug_loclists", ".zdebug_loclists" },
315 { ".debug_macinfo", ".zdebug_macinfo" },
316 { ".debug_macro", ".zdebug_macro" },
317 { ".debug_str", ".zdebug_str" },
318 { ".debug_str_offsets", ".zdebug_str_offsets" },
319 { ".debug_line_str", ".zdebug_line_str" },
320 { ".debug_ranges", ".zdebug_ranges" },
321 { ".debug_rnglists", ".zdebug_rnglists" },
322 { ".debug_types", ".zdebug_types" },
323 { ".debug_addr", ".zdebug_addr" },
324 { ".debug_frame", ".zdebug_frame" },
325 { ".eh_frame", NULL
},
326 { ".gdb_index", ".zgdb_index" },
327 { ".debug_names", ".zdebug_names" },
328 { ".debug_aranges", ".zdebug_aranges" },
332 /* List of DWO/DWP sections. */
334 static const struct dwop_section_names
336 struct dwarf2_section_names abbrev_dwo
;
337 struct dwarf2_section_names info_dwo
;
338 struct dwarf2_section_names line_dwo
;
339 struct dwarf2_section_names loc_dwo
;
340 struct dwarf2_section_names loclists_dwo
;
341 struct dwarf2_section_names macinfo_dwo
;
342 struct dwarf2_section_names macro_dwo
;
343 struct dwarf2_section_names str_dwo
;
344 struct dwarf2_section_names str_offsets_dwo
;
345 struct dwarf2_section_names types_dwo
;
346 struct dwarf2_section_names cu_index
;
347 struct dwarf2_section_names tu_index
;
351 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
352 { ".debug_info.dwo", ".zdebug_info.dwo" },
353 { ".debug_line.dwo", ".zdebug_line.dwo" },
354 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
355 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
356 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
357 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
358 { ".debug_str.dwo", ".zdebug_str.dwo" },
359 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
360 { ".debug_types.dwo", ".zdebug_types.dwo" },
361 { ".debug_cu_index", ".zdebug_cu_index" },
362 { ".debug_tu_index", ".zdebug_tu_index" },
365 /* local data types */
367 /* The location list section (.debug_loclists) begins with a header,
368 which contains the following information. */
369 struct loclist_header
371 /* A 4-byte or 12-byte length containing the length of the
372 set of entries for this compilation unit, not including the
373 length field itself. */
376 /* A 2-byte version identifier. */
379 /* A 1-byte unsigned integer containing the size in bytes of an address on
380 the target system. */
381 unsigned char addr_size
;
383 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
384 on the target system. */
385 unsigned char segment_collector_size
;
387 /* A 4-byte count of the number of offsets that follow the header. */
388 unsigned int offset_entry_count
;
391 /* Type used for delaying computation of method physnames.
392 See comments for compute_delayed_physnames. */
393 struct delayed_method_info
395 /* The type to which the method is attached, i.e., its parent class. */
398 /* The index of the method in the type's function fieldlists. */
401 /* The index of the method in the fieldlist. */
404 /* The name of the DIE. */
407 /* The DIE associated with this method. */
408 struct die_info
*die
;
411 /* Internal state when decoding a particular compilation unit. */
414 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
415 dwarf2_per_objfile
*per_objfile
);
417 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
419 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
420 Create the set of symtabs used by this TU, or if this TU is sharing
421 symtabs with another TU and the symtabs have already been created
422 then restore those symtabs in the line header.
423 We don't need the pc/line-number mapping for type units. */
424 void setup_type_unit_groups (struct die_info
*die
);
426 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
427 buildsym_compunit constructor. */
428 struct compunit_symtab
*start_symtab (const char *name
,
429 const char *comp_dir
,
432 /* Reset the builder. */
433 void reset_builder () { m_builder
.reset (); }
435 /* Return a type that is a generic pointer type, the size of which
436 matches the address size given in the compilation unit header for
438 struct type
*addr_type () const;
440 /* Find an integer type the same size as the address size given in
441 the compilation unit header for this CU. UNSIGNED_P controls if
442 the integer is unsigned or not. */
443 struct type
*addr_sized_int_type (bool unsigned_p
) const;
445 /* The header of the compilation unit. */
446 struct comp_unit_head header
{};
448 /* Base address of this compilation unit. */
449 gdb::optional
<CORE_ADDR
> base_address
;
451 /* The language we are debugging. */
452 enum language language
= language_unknown
;
453 const struct language_defn
*language_defn
= nullptr;
455 const char *producer
= nullptr;
458 /* The symtab builder for this CU. This is only non-NULL when full
459 symbols are being read. */
460 std::unique_ptr
<buildsym_compunit
> m_builder
;
463 /* The generic symbol table building routines have separate lists for
464 file scope symbols and all all other scopes (local scopes). So
465 we need to select the right one to pass to add_symbol_to_list().
466 We do it by keeping a pointer to the correct list in list_in_scope.
468 FIXME: The original dwarf code just treated the file scope as the
469 first local scope, and all other local scopes as nested local
470 scopes, and worked fine. Check to see if we really need to
471 distinguish these in buildsym.c. */
472 struct pending
**list_in_scope
= nullptr;
474 /* Hash table holding all the loaded partial DIEs
475 with partial_die->offset.SECT_OFF as hash. */
476 htab_t partial_dies
= nullptr;
478 /* Storage for things with the same lifetime as this read-in compilation
479 unit, including partial DIEs. */
480 auto_obstack comp_unit_obstack
;
482 /* Backlink to our per_cu entry. */
483 struct dwarf2_per_cu_data
*per_cu
;
485 /* The dwarf2_per_objfile that owns this. */
486 dwarf2_per_objfile
*per_objfile
;
488 /* How many compilation units ago was this CU last referenced? */
491 /* A hash table of DIE cu_offset for following references with
492 die_info->offset.sect_off as hash. */
493 htab_t die_hash
= nullptr;
495 /* Full DIEs if read in. */
496 struct die_info
*dies
= nullptr;
498 /* A set of pointers to dwarf2_per_cu_data objects for compilation
499 units referenced by this one. Only set during full symbol processing;
500 partial symbol tables do not have dependencies. */
501 htab_t dependencies
= nullptr;
503 /* Header data from the line table, during full symbol processing. */
504 struct line_header
*line_header
= nullptr;
505 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
506 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
507 this is the DW_TAG_compile_unit die for this CU. We'll hold on
508 to the line header as long as this DIE is being processed. See
509 process_die_scope. */
510 die_info
*line_header_die_owner
= nullptr;
512 /* A list of methods which need to have physnames computed
513 after all type information has been read. */
514 std::vector
<delayed_method_info
> method_list
;
516 /* To be copied to symtab->call_site_htab. */
517 htab_t call_site_htab
= nullptr;
519 /* Non-NULL if this CU came from a DWO file.
520 There is an invariant here that is important to remember:
521 Except for attributes copied from the top level DIE in the "main"
522 (or "stub") file in preparation for reading the DWO file
523 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
524 Either there isn't a DWO file (in which case this is NULL and the point
525 is moot), or there is and either we're not going to read it (in which
526 case this is NULL) or there is and we are reading it (in which case this
528 struct dwo_unit
*dwo_unit
= nullptr;
530 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
531 Note this value comes from the Fission stub CU/TU's DIE. */
532 gdb::optional
<ULONGEST
> addr_base
;
534 /* The DW_AT_rnglists_base attribute if present.
535 Note this value comes from the Fission stub CU/TU's DIE.
536 Also note that the value is zero in the non-DWO case so this value can
537 be used without needing to know whether DWO files are in use or not.
538 N.B. This does not apply to DW_AT_ranges appearing in
539 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
540 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
541 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
542 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
543 ULONGEST ranges_base
= 0;
545 /* The DW_AT_loclists_base attribute if present. */
546 ULONGEST loclist_base
= 0;
548 /* When reading debug info generated by older versions of rustc, we
549 have to rewrite some union types to be struct types with a
550 variant part. This rewriting must be done after the CU is fully
551 read in, because otherwise at the point of rewriting some struct
552 type might not have been fully processed. So, we keep a list of
553 all such types here and process them after expansion. */
554 std::vector
<struct type
*> rust_unions
;
556 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
557 files, the value is implicitly zero. For DWARF 5 version DWO files, the
558 value is often implicit and is the size of the header of
559 .debug_str_offsets section (8 or 4, depending on the address size). */
560 gdb::optional
<ULONGEST
> str_offsets_base
;
562 /* Mark used when releasing cached dies. */
565 /* This CU references .debug_loc. See the symtab->locations_valid field.
566 This test is imperfect as there may exist optimized debug code not using
567 any location list and still facing inlining issues if handled as
568 unoptimized code. For a future better test see GCC PR other/32998. */
569 bool has_loclist
: 1;
571 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
572 if all the producer_is_* fields are valid. This information is cached
573 because profiling CU expansion showed excessive time spent in
574 producer_is_gxx_lt_4_6. */
575 bool checked_producer
: 1;
576 bool producer_is_gxx_lt_4_6
: 1;
577 bool producer_is_gcc_lt_4_3
: 1;
578 bool producer_is_icc
: 1;
579 bool producer_is_icc_lt_14
: 1;
580 bool producer_is_codewarrior
: 1;
582 /* When true, the file that we're processing is known to have
583 debugging info for C++ namespaces. GCC 3.3.x did not produce
584 this information, but later versions do. */
586 bool processing_has_namespace_info
: 1;
588 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
590 /* If this CU was inherited by another CU (via specification,
591 abstract_origin, etc), this is the ancestor CU. */
594 /* Get the buildsym_compunit for this CU. */
595 buildsym_compunit
*get_builder ()
597 /* If this CU has a builder associated with it, use that. */
598 if (m_builder
!= nullptr)
599 return m_builder
.get ();
601 /* Otherwise, search ancestors for a valid builder. */
602 if (ancestor
!= nullptr)
603 return ancestor
->get_builder ();
609 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
610 This includes type_unit_group and quick_file_names. */
612 struct stmt_list_hash
614 /* The DWO unit this table is from or NULL if there is none. */
615 struct dwo_unit
*dwo_unit
;
617 /* Offset in .debug_line or .debug_line.dwo. */
618 sect_offset line_sect_off
;
621 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
622 an object of this type. This contains elements of type unit groups
623 that can be shared across objfiles. The non-shareable parts are in
624 type_unit_group_unshareable. */
626 struct type_unit_group
628 /* dwarf2read.c's main "handle" on a TU symtab.
629 To simplify things we create an artificial CU that "includes" all the
630 type units using this stmt_list so that the rest of the code still has
631 a "per_cu" handle on the symtab. */
632 struct dwarf2_per_cu_data per_cu
;
634 /* The TUs that share this DW_AT_stmt_list entry.
635 This is added to while parsing type units to build partial symtabs,
636 and is deleted afterwards and not used again. */
637 std::vector
<signatured_type
*> *tus
;
639 /* The data used to construct the hash key. */
640 struct stmt_list_hash hash
;
643 /* These sections are what may appear in a (real or virtual) DWO file. */
647 struct dwarf2_section_info abbrev
;
648 struct dwarf2_section_info line
;
649 struct dwarf2_section_info loc
;
650 struct dwarf2_section_info loclists
;
651 struct dwarf2_section_info macinfo
;
652 struct dwarf2_section_info macro
;
653 struct dwarf2_section_info str
;
654 struct dwarf2_section_info str_offsets
;
655 /* In the case of a virtual DWO file, these two are unused. */
656 struct dwarf2_section_info info
;
657 std::vector
<dwarf2_section_info
> types
;
660 /* CUs/TUs in DWP/DWO files. */
664 /* Backlink to the containing struct dwo_file. */
665 struct dwo_file
*dwo_file
;
667 /* The "id" that distinguishes this CU/TU.
668 .debug_info calls this "dwo_id", .debug_types calls this "signature".
669 Since signatures came first, we stick with it for consistency. */
672 /* The section this CU/TU lives in, in the DWO file. */
673 struct dwarf2_section_info
*section
;
675 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
676 sect_offset sect_off
;
679 /* For types, offset in the type's DIE of the type defined by this TU. */
680 cu_offset type_offset_in_tu
;
683 /* include/dwarf2.h defines the DWP section codes.
684 It defines a max value but it doesn't define a min value, which we
685 use for error checking, so provide one. */
687 enum dwp_v2_section_ids
692 /* Data for one DWO file.
694 This includes virtual DWO files (a virtual DWO file is a DWO file as it
695 appears in a DWP file). DWP files don't really have DWO files per se -
696 comdat folding of types "loses" the DWO file they came from, and from
697 a high level view DWP files appear to contain a mass of random types.
698 However, to maintain consistency with the non-DWP case we pretend DWP
699 files contain virtual DWO files, and we assign each TU with one virtual
700 DWO file (generally based on the line and abbrev section offsets -
701 a heuristic that seems to work in practice). */
705 dwo_file () = default;
706 DISABLE_COPY_AND_ASSIGN (dwo_file
);
708 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
709 For virtual DWO files the name is constructed from the section offsets
710 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
711 from related CU+TUs. */
712 const char *dwo_name
= nullptr;
714 /* The DW_AT_comp_dir attribute. */
715 const char *comp_dir
= nullptr;
717 /* The bfd, when the file is open. Otherwise this is NULL.
718 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
719 gdb_bfd_ref_ptr dbfd
;
721 /* The sections that make up this DWO file.
722 Remember that for virtual DWO files in DWP V2, these are virtual
723 sections (for lack of a better name). */
724 struct dwo_sections sections
{};
726 /* The CUs in the file.
727 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
728 an extension to handle LLVM's Link Time Optimization output (where
729 multiple source files may be compiled into a single object/dwo pair). */
732 /* Table of TUs in the file.
733 Each element is a struct dwo_unit. */
737 /* These sections are what may appear in a DWP file. */
741 /* These are used by both DWP version 1 and 2. */
742 struct dwarf2_section_info str
;
743 struct dwarf2_section_info cu_index
;
744 struct dwarf2_section_info tu_index
;
746 /* These are only used by DWP version 2 files.
747 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
748 sections are referenced by section number, and are not recorded here.
749 In DWP version 2 there is at most one copy of all these sections, each
750 section being (effectively) comprised of the concatenation of all of the
751 individual sections that exist in the version 1 format.
752 To keep the code simple we treat each of these concatenated pieces as a
753 section itself (a virtual section?). */
754 struct dwarf2_section_info abbrev
;
755 struct dwarf2_section_info info
;
756 struct dwarf2_section_info line
;
757 struct dwarf2_section_info loc
;
758 struct dwarf2_section_info macinfo
;
759 struct dwarf2_section_info macro
;
760 struct dwarf2_section_info str_offsets
;
761 struct dwarf2_section_info types
;
764 /* These sections are what may appear in a virtual DWO file in DWP version 1.
765 A virtual DWO file is a DWO file as it appears in a DWP file. */
767 struct virtual_v1_dwo_sections
769 struct dwarf2_section_info abbrev
;
770 struct dwarf2_section_info line
;
771 struct dwarf2_section_info loc
;
772 struct dwarf2_section_info macinfo
;
773 struct dwarf2_section_info macro
;
774 struct dwarf2_section_info str_offsets
;
775 /* Each DWP hash table entry records one CU or one TU.
776 That is recorded here, and copied to dwo_unit.section. */
777 struct dwarf2_section_info info_or_types
;
780 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
781 In version 2, the sections of the DWO files are concatenated together
782 and stored in one section of that name. Thus each ELF section contains
783 several "virtual" sections. */
785 struct virtual_v2_dwo_sections
787 bfd_size_type abbrev_offset
;
788 bfd_size_type abbrev_size
;
790 bfd_size_type line_offset
;
791 bfd_size_type line_size
;
793 bfd_size_type loc_offset
;
794 bfd_size_type loc_size
;
796 bfd_size_type macinfo_offset
;
797 bfd_size_type macinfo_size
;
799 bfd_size_type macro_offset
;
800 bfd_size_type macro_size
;
802 bfd_size_type str_offsets_offset
;
803 bfd_size_type str_offsets_size
;
805 /* Each DWP hash table entry records one CU or one TU.
806 That is recorded here, and copied to dwo_unit.section. */
807 bfd_size_type info_or_types_offset
;
808 bfd_size_type info_or_types_size
;
811 /* Contents of DWP hash tables. */
813 struct dwp_hash_table
815 uint32_t version
, nr_columns
;
816 uint32_t nr_units
, nr_slots
;
817 const gdb_byte
*hash_table
, *unit_table
;
822 const gdb_byte
*indices
;
826 /* This is indexed by column number and gives the id of the section
828 #define MAX_NR_V2_DWO_SECTIONS \
829 (1 /* .debug_info or .debug_types */ \
830 + 1 /* .debug_abbrev */ \
831 + 1 /* .debug_line */ \
832 + 1 /* .debug_loc */ \
833 + 1 /* .debug_str_offsets */ \
834 + 1 /* .debug_macro or .debug_macinfo */)
835 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
836 const gdb_byte
*offsets
;
837 const gdb_byte
*sizes
;
842 /* Data for one DWP file. */
846 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
848 dbfd (std::move (abfd
))
852 /* Name of the file. */
855 /* File format version. */
859 gdb_bfd_ref_ptr dbfd
;
861 /* Section info for this file. */
862 struct dwp_sections sections
{};
864 /* Table of CUs in the file. */
865 const struct dwp_hash_table
*cus
= nullptr;
867 /* Table of TUs in the file. */
868 const struct dwp_hash_table
*tus
= nullptr;
870 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
874 /* Table to map ELF section numbers to their sections.
875 This is only needed for the DWP V1 file format. */
876 unsigned int num_sections
= 0;
877 asection
**elf_sections
= nullptr;
880 /* Struct used to pass misc. parameters to read_die_and_children, et
881 al. which are used for both .debug_info and .debug_types dies.
882 All parameters here are unchanging for the life of the call. This
883 struct exists to abstract away the constant parameters of die reading. */
885 struct die_reader_specs
887 /* The bfd of die_section. */
890 /* The CU of the DIE we are parsing. */
891 struct dwarf2_cu
*cu
;
893 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
894 struct dwo_file
*dwo_file
;
896 /* The section the die comes from.
897 This is either .debug_info or .debug_types, or the .dwo variants. */
898 struct dwarf2_section_info
*die_section
;
900 /* die_section->buffer. */
901 const gdb_byte
*buffer
;
903 /* The end of the buffer. */
904 const gdb_byte
*buffer_end
;
906 /* The abbreviation table to use when reading the DIEs. */
907 struct abbrev_table
*abbrev_table
;
910 /* A subclass of die_reader_specs that holds storage and has complex
911 constructor and destructor behavior. */
913 class cutu_reader
: public die_reader_specs
917 cutu_reader (dwarf2_per_cu_data
*this_cu
,
918 dwarf2_per_objfile
*per_objfile
,
919 struct abbrev_table
*abbrev_table
,
920 dwarf2_cu
*existing_cu
,
923 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
924 dwarf2_per_objfile
*per_objfile
,
925 struct dwarf2_cu
*parent_cu
= nullptr,
926 struct dwo_file
*dwo_file
= nullptr);
928 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
930 const gdb_byte
*info_ptr
= nullptr;
931 struct die_info
*comp_unit_die
= nullptr;
932 bool dummy_p
= false;
934 /* Release the new CU, putting it on the chain. This cannot be done
939 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
940 dwarf2_per_objfile
*per_objfile
,
941 dwarf2_cu
*existing_cu
);
943 struct dwarf2_per_cu_data
*m_this_cu
;
944 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
946 /* The ordinary abbreviation table. */
947 abbrev_table_up m_abbrev_table_holder
;
949 /* The DWO abbreviation table. */
950 abbrev_table_up m_dwo_abbrev_table
;
953 /* When we construct a partial symbol table entry we only
954 need this much information. */
955 struct partial_die_info
: public allocate_on_obstack
957 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
959 /* Disable assign but still keep copy ctor, which is needed
960 load_partial_dies. */
961 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
963 /* Adjust the partial die before generating a symbol for it. This
964 function may set the is_external flag or change the DIE's
966 void fixup (struct dwarf2_cu
*cu
);
968 /* Read a minimal amount of information into the minimal die
970 const gdb_byte
*read (const struct die_reader_specs
*reader
,
971 const struct abbrev_info
&abbrev
,
972 const gdb_byte
*info_ptr
);
974 /* Compute the name of this partial DIE. This memoizes the
975 result, so it is safe to call multiple times. */
976 const char *name (dwarf2_cu
*cu
);
978 /* Offset of this DIE. */
979 const sect_offset sect_off
;
981 /* DWARF-2 tag for this DIE. */
982 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
984 /* Assorted flags describing the data found in this DIE. */
985 const unsigned int has_children
: 1;
987 unsigned int is_external
: 1;
988 unsigned int is_declaration
: 1;
989 unsigned int has_type
: 1;
990 unsigned int has_specification
: 1;
991 unsigned int has_pc_info
: 1;
992 unsigned int may_be_inlined
: 1;
994 /* This DIE has been marked DW_AT_main_subprogram. */
995 unsigned int main_subprogram
: 1;
997 /* Flag set if the SCOPE field of this structure has been
999 unsigned int scope_set
: 1;
1001 /* Flag set if the DIE has a byte_size attribute. */
1002 unsigned int has_byte_size
: 1;
1004 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1005 unsigned int has_const_value
: 1;
1007 /* Flag set if any of the DIE's children are template arguments. */
1008 unsigned int has_template_arguments
: 1;
1010 /* Flag set if fixup has been called on this die. */
1011 unsigned int fixup_called
: 1;
1013 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1014 unsigned int is_dwz
: 1;
1016 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1017 unsigned int spec_is_dwz
: 1;
1019 unsigned int canonical_name
: 1;
1021 /* The name of this DIE. Normally the value of DW_AT_name, but
1022 sometimes a default name for unnamed DIEs. */
1023 const char *raw_name
= nullptr;
1025 /* The linkage name, if present. */
1026 const char *linkage_name
= nullptr;
1028 /* The scope to prepend to our children. This is generally
1029 allocated on the comp_unit_obstack, so will disappear
1030 when this compilation unit leaves the cache. */
1031 const char *scope
= nullptr;
1033 /* Some data associated with the partial DIE. The tag determines
1034 which field is live. */
1037 /* The location description associated with this DIE, if any. */
1038 struct dwarf_block
*locdesc
;
1039 /* The offset of an import, for DW_TAG_imported_unit. */
1040 sect_offset sect_off
;
1043 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1044 CORE_ADDR lowpc
= 0;
1045 CORE_ADDR highpc
= 0;
1047 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1048 DW_AT_sibling, if any. */
1049 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1050 could return DW_AT_sibling values to its caller load_partial_dies. */
1051 const gdb_byte
*sibling
= nullptr;
1053 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1054 DW_AT_specification (or DW_AT_abstract_origin or
1055 DW_AT_extension). */
1056 sect_offset spec_offset
{};
1058 /* Pointers to this DIE's parent, first child, and next sibling,
1060 struct partial_die_info
*die_parent
= nullptr;
1061 struct partial_die_info
*die_child
= nullptr;
1062 struct partial_die_info
*die_sibling
= nullptr;
1064 friend struct partial_die_info
*
1065 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1068 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1069 partial_die_info (sect_offset sect_off
)
1070 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1074 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1076 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1081 has_specification
= 0;
1084 main_subprogram
= 0;
1087 has_const_value
= 0;
1088 has_template_arguments
= 0;
1096 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1097 but this would require a corresponding change in unpack_field_as_long
1099 static int bits_per_byte
= 8;
1101 struct variant_part_builder
;
1103 /* When reading a variant, we track a bit more information about the
1104 field, and store it in an object of this type. */
1106 struct variant_field
1108 int first_field
= -1;
1109 int last_field
= -1;
1111 /* A variant can contain other variant parts. */
1112 std::vector
<variant_part_builder
> variant_parts
;
1114 /* If we see a DW_TAG_variant, then this will be set if this is the
1116 bool default_branch
= false;
1117 /* If we see a DW_AT_discr_value, then this will be the discriminant
1119 ULONGEST discriminant_value
= 0;
1120 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1122 struct dwarf_block
*discr_list_data
= nullptr;
1125 /* This represents a DW_TAG_variant_part. */
1127 struct variant_part_builder
1129 /* The offset of the discriminant field. */
1130 sect_offset discriminant_offset
{};
1132 /* Variants that are direct children of this variant part. */
1133 std::vector
<variant_field
> variants
;
1135 /* True if we're currently reading a variant. */
1136 bool processing_variant
= false;
1141 int accessibility
= 0;
1143 /* Variant parts need to find the discriminant, which is a DIE
1144 reference. We track the section offset of each field to make
1147 struct field field
{};
1152 const char *name
= nullptr;
1153 std::vector
<struct fn_field
> fnfields
;
1156 /* The routines that read and process dies for a C struct or C++ class
1157 pass lists of data member fields and lists of member function fields
1158 in an instance of a field_info structure, as defined below. */
1161 /* List of data member and baseclasses fields. */
1162 std::vector
<struct nextfield
> fields
;
1163 std::vector
<struct nextfield
> baseclasses
;
1165 /* Set if the accessibility of one of the fields is not public. */
1166 int non_public_fields
= 0;
1168 /* Member function fieldlist array, contains name of possibly overloaded
1169 member function, number of overloaded member functions and a pointer
1170 to the head of the member function field chain. */
1171 std::vector
<struct fnfieldlist
> fnfieldlists
;
1173 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1174 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1175 std::vector
<struct decl_field
> typedef_field_list
;
1177 /* Nested types defined by this class and the number of elements in this
1179 std::vector
<struct decl_field
> nested_types_list
;
1181 /* If non-null, this is the variant part we are currently
1183 variant_part_builder
*current_variant_part
= nullptr;
1184 /* This holds all the top-level variant parts attached to the type
1186 std::vector
<variant_part_builder
> variant_parts
;
1188 /* Return the total number of fields (including baseclasses). */
1189 int nfields () const
1191 return fields
.size () + baseclasses
.size ();
1195 /* Loaded secondary compilation units are kept in memory until they
1196 have not been referenced for the processing of this many
1197 compilation units. Set this to zero to disable caching. Cache
1198 sizes of up to at least twenty will improve startup time for
1199 typical inter-CU-reference binaries, at an obvious memory cost. */
1200 static int dwarf_max_cache_age
= 5;
1202 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1203 struct cmd_list_element
*c
, const char *value
)
1205 fprintf_filtered (file
, _("The upper bound on the age of cached "
1206 "DWARF compilation units is %s.\n"),
1210 /* local function prototypes */
1212 static void dwarf2_find_base_address (struct die_info
*die
,
1213 struct dwarf2_cu
*cu
);
1215 static dwarf2_psymtab
*create_partial_symtab
1216 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1219 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1220 const gdb_byte
*info_ptr
,
1221 struct die_info
*type_unit_die
);
1223 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1225 static void scan_partial_symbols (struct partial_die_info
*,
1226 CORE_ADDR
*, CORE_ADDR
*,
1227 int, struct dwarf2_cu
*);
1229 static void add_partial_symbol (struct partial_die_info
*,
1230 struct dwarf2_cu
*);
1232 static void add_partial_namespace (struct partial_die_info
*pdi
,
1233 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1234 int set_addrmap
, struct dwarf2_cu
*cu
);
1236 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1237 CORE_ADDR
*highpc
, int set_addrmap
,
1238 struct dwarf2_cu
*cu
);
1240 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1241 struct dwarf2_cu
*cu
);
1243 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1244 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1245 int need_pc
, struct dwarf2_cu
*cu
);
1247 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1249 static struct partial_die_info
*load_partial_dies
1250 (const struct die_reader_specs
*, const gdb_byte
*, int);
1252 /* A pair of partial_die_info and compilation unit. */
1253 struct cu_partial_die_info
1255 /* The compilation unit of the partial_die_info. */
1256 struct dwarf2_cu
*cu
;
1257 /* A partial_die_info. */
1258 struct partial_die_info
*pdi
;
1260 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1266 cu_partial_die_info () = delete;
1269 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1270 struct dwarf2_cu
*);
1272 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1273 struct attribute
*, struct attr_abbrev
*,
1274 const gdb_byte
*, bool *need_reprocess
);
1276 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1277 struct attribute
*attr
);
1279 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1281 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1282 dwarf2_section_info
*, sect_offset
);
1284 static const char *read_indirect_string
1285 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1286 const struct comp_unit_head
*, unsigned int *);
1288 static const char *read_indirect_string_at_offset
1289 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1291 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1295 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1296 ULONGEST str_index
);
1298 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1299 ULONGEST str_index
);
1301 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1303 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1304 struct dwarf2_cu
*);
1306 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1307 struct dwarf2_cu
*cu
);
1309 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1311 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1312 struct dwarf2_cu
*cu
);
1314 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1316 static struct die_info
*die_specification (struct die_info
*die
,
1317 struct dwarf2_cu
**);
1319 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1320 struct dwarf2_cu
*cu
);
1322 static void dwarf_decode_lines (struct line_header
*, const char *,
1323 struct dwarf2_cu
*, dwarf2_psymtab
*,
1324 CORE_ADDR
, int decode_mapping
);
1326 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1329 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1330 struct dwarf2_cu
*, struct symbol
* = NULL
);
1332 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1333 struct dwarf2_cu
*);
1335 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1338 struct obstack
*obstack
,
1339 struct dwarf2_cu
*cu
, LONGEST
*value
,
1340 const gdb_byte
**bytes
,
1341 struct dwarf2_locexpr_baton
**baton
);
1343 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1345 static int need_gnat_info (struct dwarf2_cu
*);
1347 static struct type
*die_descriptive_type (struct die_info
*,
1348 struct dwarf2_cu
*);
1350 static void set_descriptive_type (struct type
*, struct die_info
*,
1351 struct dwarf2_cu
*);
1353 static struct type
*die_containing_type (struct die_info
*,
1354 struct dwarf2_cu
*);
1356 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1357 struct dwarf2_cu
*);
1359 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1361 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1363 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1365 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1366 const char *suffix
, int physname
,
1367 struct dwarf2_cu
*cu
);
1369 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1371 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1373 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1375 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1377 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1379 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1381 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1382 struct dwarf2_cu
*, dwarf2_psymtab
*);
1384 /* Return the .debug_loclists section to use for cu. */
1385 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1387 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1388 values. Keep the items ordered with increasing constraints compliance. */
1391 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1392 PC_BOUNDS_NOT_PRESENT
,
1394 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1395 were present but they do not form a valid range of PC addresses. */
1398 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1401 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1405 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1406 CORE_ADDR
*, CORE_ADDR
*,
1410 static void get_scope_pc_bounds (struct die_info
*,
1411 CORE_ADDR
*, CORE_ADDR
*,
1412 struct dwarf2_cu
*);
1414 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1415 CORE_ADDR
, struct dwarf2_cu
*);
1417 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1418 struct dwarf2_cu
*);
1420 static void dwarf2_attach_fields_to_type (struct field_info
*,
1421 struct type
*, struct dwarf2_cu
*);
1423 static void dwarf2_add_member_fn (struct field_info
*,
1424 struct die_info
*, struct type
*,
1425 struct dwarf2_cu
*);
1427 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1429 struct dwarf2_cu
*);
1431 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1433 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1435 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1437 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1439 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1441 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1443 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1445 static struct type
*read_module_type (struct die_info
*die
,
1446 struct dwarf2_cu
*cu
);
1448 static const char *namespace_name (struct die_info
*die
,
1449 int *is_anonymous
, struct dwarf2_cu
*);
1451 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1453 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1456 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1457 struct dwarf2_cu
*);
1459 static struct die_info
*read_die_and_siblings_1
1460 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1463 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1464 const gdb_byte
*info_ptr
,
1465 const gdb_byte
**new_info_ptr
,
1466 struct die_info
*parent
);
1468 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1469 struct die_info
**, const gdb_byte
*,
1472 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1473 struct die_info
**, const gdb_byte
*);
1475 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1477 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1480 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1482 static const char *dwarf2_full_name (const char *name
,
1483 struct die_info
*die
,
1484 struct dwarf2_cu
*cu
);
1486 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1487 struct dwarf2_cu
*cu
);
1489 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1490 struct dwarf2_cu
**);
1492 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1494 static void dump_die_for_error (struct die_info
*);
1496 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1499 /*static*/ void dump_die (struct die_info
*, int max_level
);
1501 static void store_in_ref_table (struct die_info
*,
1502 struct dwarf2_cu
*);
1504 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1505 const struct attribute
*,
1506 struct dwarf2_cu
**);
1508 static struct die_info
*follow_die_ref (struct die_info
*,
1509 const struct attribute
*,
1510 struct dwarf2_cu
**);
1512 static struct die_info
*follow_die_sig (struct die_info
*,
1513 const struct attribute
*,
1514 struct dwarf2_cu
**);
1516 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1517 struct dwarf2_cu
*);
1519 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1520 const struct attribute
*,
1521 struct dwarf2_cu
*);
1523 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1524 dwarf2_per_objfile
*per_objfile
);
1526 static void read_signatured_type (signatured_type
*sig_type
,
1527 dwarf2_per_objfile
*per_objfile
);
1529 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1530 struct die_info
*die
, struct dwarf2_cu
*cu
,
1531 struct dynamic_prop
*prop
, struct type
*type
);
1533 /* memory allocation interface */
1535 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1537 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1539 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1541 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1542 struct dwarf2_loclist_baton
*baton
,
1543 const struct attribute
*attr
);
1545 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1547 struct dwarf2_cu
*cu
,
1550 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1551 const gdb_byte
*info_ptr
,
1552 struct abbrev_info
*abbrev
);
1554 static hashval_t
partial_die_hash (const void *item
);
1556 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1558 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1559 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1560 dwarf2_per_objfile
*per_objfile
);
1562 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1563 struct die_info
*comp_unit_die
,
1564 enum language pretend_language
);
1566 static struct type
*set_die_type (struct die_info
*, struct type
*,
1567 struct dwarf2_cu
*);
1569 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1571 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1573 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1574 dwarf2_per_objfile
*per_objfile
,
1576 enum language pretend_language
);
1578 static void process_full_comp_unit (dwarf2_cu
*cu
,
1579 enum language pretend_language
);
1581 static void process_full_type_unit (dwarf2_cu
*cu
,
1582 enum language pretend_language
);
1584 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1585 struct dwarf2_per_cu_data
*);
1587 static void dwarf2_mark (struct dwarf2_cu
*);
1589 static struct type
*get_die_type_at_offset (sect_offset
,
1590 dwarf2_per_cu_data
*per_cu
,
1591 dwarf2_per_objfile
*per_objfile
);
1593 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1595 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1596 dwarf2_per_objfile
*per_objfile
,
1597 enum language pretend_language
);
1599 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1601 /* Class, the destructor of which frees all allocated queue entries. This
1602 will only have work to do if an error was thrown while processing the
1603 dwarf. If no error was thrown then the queue entries should have all
1604 been processed, and freed, as we went along. */
1606 class dwarf2_queue_guard
1609 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1610 : m_per_objfile (per_objfile
)
1614 /* Free any entries remaining on the queue. There should only be
1615 entries left if we hit an error while processing the dwarf. */
1616 ~dwarf2_queue_guard ()
1618 /* Ensure that no memory is allocated by the queue. */
1619 std::queue
<dwarf2_queue_item
> empty
;
1620 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1623 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1626 dwarf2_per_objfile
*m_per_objfile
;
1629 dwarf2_queue_item::~dwarf2_queue_item ()
1631 /* Anything still marked queued is likely to be in an
1632 inconsistent state, so discard it. */
1635 per_objfile
->remove_cu (per_cu
);
1640 /* The return type of find_file_and_directory. Note, the enclosed
1641 string pointers are only valid while this object is valid. */
1643 struct file_and_directory
1645 /* The filename. This is never NULL. */
1648 /* The compilation directory. NULL if not known. If we needed to
1649 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1650 points directly to the DW_AT_comp_dir string attribute owned by
1651 the obstack that owns the DIE. */
1652 const char *comp_dir
;
1654 /* If we needed to build a new string for comp_dir, this is what
1655 owns the storage. */
1656 std::string comp_dir_storage
;
1659 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1660 struct dwarf2_cu
*cu
);
1662 static htab_up
allocate_signatured_type_table ();
1664 static htab_up
allocate_dwo_unit_table ();
1666 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1667 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1668 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1670 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1672 static struct dwo_unit
*lookup_dwo_comp_unit
1673 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1674 ULONGEST signature
);
1676 static struct dwo_unit
*lookup_dwo_type_unit
1677 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1679 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1681 /* A unique pointer to a dwo_file. */
1683 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1685 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1687 static void check_producer (struct dwarf2_cu
*cu
);
1689 static void free_line_header_voidp (void *arg
);
1691 /* Various complaints about symbol reading that don't abort the process. */
1694 dwarf2_debug_line_missing_file_complaint (void)
1696 complaint (_(".debug_line section has line data without a file"));
1700 dwarf2_debug_line_missing_end_sequence_complaint (void)
1702 complaint (_(".debug_line section has line "
1703 "program sequence without an end"));
1707 dwarf2_complex_location_expr_complaint (void)
1709 complaint (_("location expression too complex"));
1713 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1716 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1721 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1723 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1727 /* Hash function for line_header_hash. */
1730 line_header_hash (const struct line_header
*ofs
)
1732 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1735 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1738 line_header_hash_voidp (const void *item
)
1740 const struct line_header
*ofs
= (const struct line_header
*) item
;
1742 return line_header_hash (ofs
);
1745 /* Equality function for line_header_hash. */
1748 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1750 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1751 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1753 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1754 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1759 /* See declaration. */
1761 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1764 can_copy (can_copy_
)
1767 names
= &dwarf2_elf_names
;
1769 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1770 locate_sections (obfd
, sec
, *names
);
1773 dwarf2_per_bfd::~dwarf2_per_bfd ()
1775 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1776 per_cu
->imported_symtabs_free ();
1778 for (signatured_type
*sig_type
: all_type_units
)
1779 sig_type
->per_cu
.imported_symtabs_free ();
1781 /* Everything else should be on this->obstack. */
1787 dwarf2_per_objfile::remove_all_cus ()
1789 for (auto pair
: m_dwarf2_cus
)
1792 m_dwarf2_cus
.clear ();
1795 /* A helper class that calls free_cached_comp_units on
1798 class free_cached_comp_units
1802 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1803 : m_per_objfile (per_objfile
)
1807 ~free_cached_comp_units ()
1809 m_per_objfile
->remove_all_cus ();
1812 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1816 dwarf2_per_objfile
*m_per_objfile
;
1822 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1824 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1826 return this->m_symtabs
[per_cu
->index
] != nullptr;
1832 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1834 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1836 return this->m_symtabs
[per_cu
->index
];
1842 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1843 compunit_symtab
*symtab
)
1845 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1846 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1848 this->m_symtabs
[per_cu
->index
] = symtab
;
1851 /* Try to locate the sections we need for DWARF 2 debugging
1852 information and return true if we have enough to do something.
1853 NAMES points to the dwarf2 section names, or is NULL if the standard
1854 ELF names are used. CAN_COPY is true for formats where symbol
1855 interposition is possible and so symbol values must follow copy
1856 relocation rules. */
1859 dwarf2_has_info (struct objfile
*objfile
,
1860 const struct dwarf2_debug_sections
*names
,
1863 if (objfile
->flags
& OBJF_READNEVER
)
1866 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1868 if (per_objfile
== NULL
)
1870 dwarf2_per_bfd
*per_bfd
;
1872 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1873 doesn't require relocations and if there aren't partial symbols
1874 from some other reader. */
1875 if (!objfile_has_partial_symbols (objfile
)
1876 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1878 /* See if one has been created for this BFD yet. */
1879 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1881 if (per_bfd
== nullptr)
1883 /* No, create it now. */
1884 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1885 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1890 /* No sharing possible, create one specifically for this objfile. */
1891 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1892 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1895 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1898 return (!per_objfile
->per_bfd
->info
.is_virtual
1899 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1900 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1901 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1904 /* When loading sections, we look either for uncompressed section or for
1905 compressed section names. */
1908 section_is_p (const char *section_name
,
1909 const struct dwarf2_section_names
*names
)
1911 if (names
->normal
!= NULL
1912 && strcmp (section_name
, names
->normal
) == 0)
1914 if (names
->compressed
!= NULL
1915 && strcmp (section_name
, names
->compressed
) == 0)
1920 /* See declaration. */
1923 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1924 const dwarf2_debug_sections
&names
)
1926 flagword aflag
= bfd_section_flags (sectp
);
1928 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1931 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1932 > bfd_get_file_size (abfd
))
1934 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1935 warning (_("Discarding section %s which has a section size (%s"
1936 ") larger than the file size [in module %s]"),
1937 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1938 bfd_get_filename (abfd
));
1940 else if (section_is_p (sectp
->name
, &names
.info
))
1942 this->info
.s
.section
= sectp
;
1943 this->info
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1947 this->abbrev
.s
.section
= sectp
;
1948 this->abbrev
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.line
))
1952 this->line
.s
.section
= sectp
;
1953 this->line
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.loc
))
1957 this->loc
.s
.section
= sectp
;
1958 this->loc
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.loclists
))
1962 this->loclists
.s
.section
= sectp
;
1963 this->loclists
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1967 this->macinfo
.s
.section
= sectp
;
1968 this->macinfo
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.macro
))
1972 this->macro
.s
.section
= sectp
;
1973 this->macro
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.str
))
1977 this->str
.s
.section
= sectp
;
1978 this->str
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1982 this->str_offsets
.s
.section
= sectp
;
1983 this->str_offsets
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.line_str
))
1987 this->line_str
.s
.section
= sectp
;
1988 this->line_str
.size
= bfd_section_size (sectp
);
1990 else if (section_is_p (sectp
->name
, &names
.addr
))
1992 this->addr
.s
.section
= sectp
;
1993 this->addr
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.frame
))
1997 this->frame
.s
.section
= sectp
;
1998 this->frame
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2002 this->eh_frame
.s
.section
= sectp
;
2003 this->eh_frame
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.ranges
))
2007 this->ranges
.s
.section
= sectp
;
2008 this->ranges
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2012 this->rnglists
.s
.section
= sectp
;
2013 this->rnglists
.size
= bfd_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &names
.types
))
2017 struct dwarf2_section_info type_section
;
2019 memset (&type_section
, 0, sizeof (type_section
));
2020 type_section
.s
.section
= sectp
;
2021 type_section
.size
= bfd_section_size (sectp
);
2023 this->types
.push_back (type_section
);
2025 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2027 this->gdb_index
.s
.section
= sectp
;
2028 this->gdb_index
.size
= bfd_section_size (sectp
);
2030 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2032 this->debug_names
.s
.section
= sectp
;
2033 this->debug_names
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2037 this->debug_aranges
.s
.section
= sectp
;
2038 this->debug_aranges
.size
= bfd_section_size (sectp
);
2041 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2042 && bfd_section_vma (sectp
) == 0)
2043 this->has_section_at_zero
= true;
2046 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2050 dwarf2_get_section_info (struct objfile
*objfile
,
2051 enum dwarf2_section_enum sect
,
2052 asection
**sectp
, const gdb_byte
**bufp
,
2053 bfd_size_type
*sizep
)
2055 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2056 struct dwarf2_section_info
*info
;
2058 /* We may see an objfile without any DWARF, in which case we just
2060 if (per_objfile
== NULL
)
2069 case DWARF2_DEBUG_FRAME
:
2070 info
= &per_objfile
->per_bfd
->frame
;
2072 case DWARF2_EH_FRAME
:
2073 info
= &per_objfile
->per_bfd
->eh_frame
;
2076 gdb_assert_not_reached ("unexpected section");
2079 info
->read (objfile
);
2081 *sectp
= info
->get_bfd_section ();
2082 *bufp
= info
->buffer
;
2083 *sizep
= info
->size
;
2086 /* A helper function to find the sections for a .dwz file. */
2089 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2091 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2093 /* Note that we only support the standard ELF names, because .dwz
2094 is ELF-only (at the time of writing). */
2095 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2097 dwz_file
->abbrev
.s
.section
= sectp
;
2098 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2100 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2102 dwz_file
->info
.s
.section
= sectp
;
2103 dwz_file
->info
.size
= bfd_section_size (sectp
);
2105 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2107 dwz_file
->str
.s
.section
= sectp
;
2108 dwz_file
->str
.size
= bfd_section_size (sectp
);
2110 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2112 dwz_file
->line
.s
.section
= sectp
;
2113 dwz_file
->line
.size
= bfd_section_size (sectp
);
2115 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2117 dwz_file
->macro
.s
.section
= sectp
;
2118 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2120 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2122 dwz_file
->gdb_index
.s
.section
= sectp
;
2123 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2125 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2127 dwz_file
->debug_names
.s
.section
= sectp
;
2128 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2132 /* See dwarf2read.h. */
2135 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2137 const char *filename
;
2138 bfd_size_type buildid_len_arg
;
2142 if (per_bfd
->dwz_file
!= NULL
)
2143 return per_bfd
->dwz_file
.get ();
2145 bfd_set_error (bfd_error_no_error
);
2146 gdb::unique_xmalloc_ptr
<char> data
2147 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2148 &buildid_len_arg
, &buildid
));
2151 if (bfd_get_error () == bfd_error_no_error
)
2153 error (_("could not read '.gnu_debugaltlink' section: %s"),
2154 bfd_errmsg (bfd_get_error ()));
2157 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2159 buildid_len
= (size_t) buildid_len_arg
;
2161 filename
= data
.get ();
2163 std::string abs_storage
;
2164 if (!IS_ABSOLUTE_PATH (filename
))
2166 gdb::unique_xmalloc_ptr
<char> abs
2167 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2169 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2170 filename
= abs_storage
.c_str ();
2173 /* First try the file name given in the section. If that doesn't
2174 work, try to use the build-id instead. */
2175 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2176 if (dwz_bfd
!= NULL
)
2178 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2179 dwz_bfd
.reset (nullptr);
2182 if (dwz_bfd
== NULL
)
2183 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2185 if (dwz_bfd
== nullptr)
2187 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2188 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2190 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2197 /* File successfully retrieved from server. */
2198 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2200 if (dwz_bfd
== nullptr)
2201 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2202 alt_filename
.get ());
2203 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2204 dwz_bfd
.reset (nullptr);
2208 if (dwz_bfd
== NULL
)
2209 error (_("could not find '.gnu_debugaltlink' file for %s"),
2210 bfd_get_filename (per_bfd
->obfd
));
2212 std::unique_ptr
<struct dwz_file
> result
2213 (new struct dwz_file (std::move (dwz_bfd
)));
2215 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2218 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2219 per_bfd
->dwz_file
= std::move (result
);
2220 return per_bfd
->dwz_file
.get ();
2223 /* DWARF quick_symbols_functions support. */
2225 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2226 unique line tables, so we maintain a separate table of all .debug_line
2227 derived entries to support the sharing.
2228 All the quick functions need is the list of file names. We discard the
2229 line_header when we're done and don't need to record it here. */
2230 struct quick_file_names
2232 /* The data used to construct the hash key. */
2233 struct stmt_list_hash hash
;
2235 /* The number of entries in file_names, real_names. */
2236 unsigned int num_file_names
;
2238 /* The file names from the line table, after being run through
2240 const char **file_names
;
2242 /* The file names from the line table after being run through
2243 gdb_realpath. These are computed lazily. */
2244 const char **real_names
;
2247 /* When using the index (and thus not using psymtabs), each CU has an
2248 object of this type. This is used to hold information needed by
2249 the various "quick" methods. */
2250 struct dwarf2_per_cu_quick_data
2252 /* The file table. This can be NULL if there was no file table
2253 or it's currently not read in.
2254 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2255 struct quick_file_names
*file_names
;
2257 /* A temporary mark bit used when iterating over all CUs in
2258 expand_symtabs_matching. */
2259 unsigned int mark
: 1;
2261 /* True if we've tried to read the file table and found there isn't one.
2262 There will be no point in trying to read it again next time. */
2263 unsigned int no_file_data
: 1;
2266 /* Utility hash function for a stmt_list_hash. */
2269 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2273 if (stmt_list_hash
->dwo_unit
!= NULL
)
2274 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2275 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2279 /* Utility equality function for a stmt_list_hash. */
2282 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2283 const struct stmt_list_hash
*rhs
)
2285 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2287 if (lhs
->dwo_unit
!= NULL
2288 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2291 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2294 /* Hash function for a quick_file_names. */
2297 hash_file_name_entry (const void *e
)
2299 const struct quick_file_names
*file_data
2300 = (const struct quick_file_names
*) e
;
2302 return hash_stmt_list_entry (&file_data
->hash
);
2305 /* Equality function for a quick_file_names. */
2308 eq_file_name_entry (const void *a
, const void *b
)
2310 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2311 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2313 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2316 /* Delete function for a quick_file_names. */
2319 delete_file_name_entry (void *e
)
2321 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2324 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2326 xfree ((void*) file_data
->file_names
[i
]);
2327 if (file_data
->real_names
)
2328 xfree ((void*) file_data
->real_names
[i
]);
2331 /* The space for the struct itself lives on the obstack, so we don't
2335 /* Create a quick_file_names hash table. */
2338 create_quick_file_names_table (unsigned int nr_initial_entries
)
2340 return htab_up (htab_create_alloc (nr_initial_entries
,
2341 hash_file_name_entry
, eq_file_name_entry
,
2342 delete_file_name_entry
, xcalloc
, xfree
));
2345 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2346 function is unrelated to symtabs, symtab would have to be created afterwards.
2347 You should call age_cached_comp_units after processing the CU. */
2350 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2353 if (per_cu
->is_debug_types
)
2354 load_full_type_unit (per_cu
, per_objfile
);
2356 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2358 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2360 return nullptr; /* Dummy CU. */
2362 dwarf2_find_base_address (cu
->dies
, cu
);
2367 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2370 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2371 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2373 /* Skip type_unit_groups, reading the type units they contain
2374 is handled elsewhere. */
2375 if (per_cu
->type_unit_group_p ())
2378 /* The destructor of dwarf2_queue_guard frees any entries left on
2379 the queue. After this point we're guaranteed to leave this function
2380 with the dwarf queue empty. */
2381 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2383 if (!per_objfile
->symtab_set_p (per_cu
))
2385 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2386 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2388 /* If we just loaded a CU from a DWO, and we're working with an index
2389 that may badly handle TUs, load all the TUs in that DWO as well.
2390 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2391 if (!per_cu
->is_debug_types
2393 && cu
->dwo_unit
!= NULL
2394 && per_objfile
->per_bfd
->index_table
!= NULL
2395 && per_objfile
->per_bfd
->index_table
->version
<= 7
2396 /* DWP files aren't supported yet. */
2397 && get_dwp_file (per_objfile
) == NULL
)
2398 queue_and_load_all_dwo_tus (cu
);
2401 process_queue (per_objfile
);
2403 /* Age the cache, releasing compilation units that have not
2404 been used recently. */
2405 per_objfile
->age_comp_units ();
2408 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2409 the per-objfile for which this symtab is instantiated.
2411 Returns the resulting symbol table. */
2413 static struct compunit_symtab
*
2414 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2415 dwarf2_per_objfile
*per_objfile
,
2418 gdb_assert (per_objfile
->per_bfd
->using_index
);
2420 if (!per_objfile
->symtab_set_p (per_cu
))
2422 free_cached_comp_units
freer (per_objfile
);
2423 scoped_restore decrementer
= increment_reading_symtab ();
2424 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2425 process_cu_includes (per_objfile
);
2428 return per_objfile
->get_symtab (per_cu
);
2431 /* See declaration. */
2433 dwarf2_per_cu_data
*
2434 dwarf2_per_bfd::get_cutu (int index
)
2436 if (index
>= this->all_comp_units
.size ())
2438 index
-= this->all_comp_units
.size ();
2439 gdb_assert (index
< this->all_type_units
.size ());
2440 return &this->all_type_units
[index
]->per_cu
;
2443 return this->all_comp_units
[index
];
2446 /* See declaration. */
2448 dwarf2_per_cu_data
*
2449 dwarf2_per_bfd::get_cu (int index
)
2451 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2453 return this->all_comp_units
[index
];
2456 /* See declaration. */
2459 dwarf2_per_bfd::get_tu (int index
)
2461 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2463 return this->all_type_units
[index
];
2468 dwarf2_per_cu_data
*
2469 dwarf2_per_bfd::allocate_per_cu ()
2471 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2472 result
->per_bfd
= this;
2473 result
->index
= m_num_psymtabs
++;
2480 dwarf2_per_bfd::allocate_signatured_type ()
2482 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2483 result
->per_cu
.per_bfd
= this;
2484 result
->per_cu
.index
= m_num_psymtabs
++;
2488 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2489 obstack, and constructed with the specified field values. */
2491 static dwarf2_per_cu_data
*
2492 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2493 struct dwarf2_section_info
*section
,
2495 sect_offset sect_off
, ULONGEST length
)
2497 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2498 the_cu
->sect_off
= sect_off
;
2499 the_cu
->length
= length
;
2500 the_cu
->section
= section
;
2501 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2502 struct dwarf2_per_cu_quick_data
);
2503 the_cu
->is_dwz
= is_dwz
;
2507 /* A helper for create_cus_from_index that handles a given list of
2511 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2512 const gdb_byte
*cu_list
, offset_type n_elements
,
2513 struct dwarf2_section_info
*section
,
2516 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2518 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2520 sect_offset sect_off
2521 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2522 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2525 dwarf2_per_cu_data
*per_cu
2526 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2528 per_bfd
->all_comp_units
.push_back (per_cu
);
2532 /* Read the CU list from the mapped index, and use it to create all
2533 the CU objects for PER_BFD. */
2536 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2537 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2538 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2540 gdb_assert (per_bfd
->all_comp_units
.empty ());
2541 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2543 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2546 if (dwz_elements
== 0)
2549 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2550 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2554 /* Create the signatured type hash table from the index. */
2557 create_signatured_type_table_from_index
2558 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2559 const gdb_byte
*bytes
, offset_type elements
)
2561 gdb_assert (per_bfd
->all_type_units
.empty ());
2562 per_bfd
->all_type_units
.reserve (elements
/ 3);
2564 htab_up sig_types_hash
= allocate_signatured_type_table ();
2566 for (offset_type i
= 0; i
< elements
; i
+= 3)
2568 struct signatured_type
*sig_type
;
2571 cu_offset type_offset_in_tu
;
2573 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2574 sect_offset sect_off
2575 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2577 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2579 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2582 sig_type
= per_bfd
->allocate_signatured_type ();
2583 sig_type
->signature
= signature
;
2584 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2585 sig_type
->per_cu
.is_debug_types
= 1;
2586 sig_type
->per_cu
.section
= section
;
2587 sig_type
->per_cu
.sect_off
= sect_off
;
2588 sig_type
->per_cu
.v
.quick
2589 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2590 struct dwarf2_per_cu_quick_data
);
2592 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2595 per_bfd
->all_type_units
.push_back (sig_type
);
2598 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2601 /* Create the signatured type hash table from .debug_names. */
2604 create_signatured_type_table_from_debug_names
2605 (dwarf2_per_objfile
*per_objfile
,
2606 const mapped_debug_names
&map
,
2607 struct dwarf2_section_info
*section
,
2608 struct dwarf2_section_info
*abbrev_section
)
2610 struct objfile
*objfile
= per_objfile
->objfile
;
2612 section
->read (objfile
);
2613 abbrev_section
->read (objfile
);
2615 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2616 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2618 htab_up sig_types_hash
= allocate_signatured_type_table ();
2620 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2622 struct signatured_type
*sig_type
;
2625 sect_offset sect_off
2626 = (sect_offset
) (extract_unsigned_integer
2627 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2629 map
.dwarf5_byte_order
));
2631 comp_unit_head cu_header
;
2632 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2634 section
->buffer
+ to_underlying (sect_off
),
2637 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2638 sig_type
->signature
= cu_header
.signature
;
2639 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2640 sig_type
->per_cu
.is_debug_types
= 1;
2641 sig_type
->per_cu
.section
= section
;
2642 sig_type
->per_cu
.sect_off
= sect_off
;
2643 sig_type
->per_cu
.v
.quick
2644 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2645 struct dwarf2_per_cu_quick_data
);
2647 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2650 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2653 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2656 /* Read the address map data from the mapped index, and use it to
2657 populate the objfile's psymtabs_addrmap. */
2660 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2661 struct mapped_index
*index
)
2663 struct objfile
*objfile
= per_objfile
->objfile
;
2664 struct gdbarch
*gdbarch
= objfile
->arch ();
2665 const gdb_byte
*iter
, *end
;
2666 struct addrmap
*mutable_map
;
2669 auto_obstack temp_obstack
;
2671 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2673 iter
= index
->address_table
.data ();
2674 end
= iter
+ index
->address_table
.size ();
2676 baseaddr
= objfile
->text_section_offset ();
2680 ULONGEST hi
, lo
, cu_index
;
2681 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2683 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2685 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2690 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2691 hex_string (lo
), hex_string (hi
));
2695 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2697 complaint (_(".gdb_index address table has invalid CU number %u"),
2698 (unsigned) cu_index
);
2702 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2703 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2704 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2705 per_objfile
->per_bfd
->get_cu (cu_index
));
2708 objfile
->partial_symtabs
->psymtabs_addrmap
2709 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2712 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2713 populate the objfile's psymtabs_addrmap. */
2716 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2717 struct dwarf2_section_info
*section
)
2719 struct objfile
*objfile
= per_objfile
->objfile
;
2720 bfd
*abfd
= objfile
->obfd
;
2721 struct gdbarch
*gdbarch
= objfile
->arch ();
2722 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2724 auto_obstack temp_obstack
;
2725 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2727 std::unordered_map
<sect_offset
,
2728 dwarf2_per_cu_data
*,
2729 gdb::hash_enum
<sect_offset
>>
2730 debug_info_offset_to_per_cu
;
2731 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2733 const auto insertpair
2734 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2735 if (!insertpair
.second
)
2737 warning (_("Section .debug_aranges in %s has duplicate "
2738 "debug_info_offset %s, ignoring .debug_aranges."),
2739 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2744 section
->read (objfile
);
2746 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2748 const gdb_byte
*addr
= section
->buffer
;
2750 while (addr
< section
->buffer
+ section
->size
)
2752 const gdb_byte
*const entry_addr
= addr
;
2753 unsigned int bytes_read
;
2755 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2759 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2760 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2761 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2762 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2764 warning (_("Section .debug_aranges in %s entry at offset %s "
2765 "length %s exceeds section length %s, "
2766 "ignoring .debug_aranges."),
2767 objfile_name (objfile
),
2768 plongest (entry_addr
- section
->buffer
),
2769 plongest (bytes_read
+ entry_length
),
2770 pulongest (section
->size
));
2774 /* The version number. */
2775 const uint16_t version
= read_2_bytes (abfd
, addr
);
2779 warning (_("Section .debug_aranges in %s entry at offset %s "
2780 "has unsupported version %d, ignoring .debug_aranges."),
2781 objfile_name (objfile
),
2782 plongest (entry_addr
- section
->buffer
), version
);
2786 const uint64_t debug_info_offset
2787 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2788 addr
+= offset_size
;
2789 const auto per_cu_it
2790 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2791 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2793 warning (_("Section .debug_aranges in %s entry at offset %s "
2794 "debug_info_offset %s does not exists, "
2795 "ignoring .debug_aranges."),
2796 objfile_name (objfile
),
2797 plongest (entry_addr
- section
->buffer
),
2798 pulongest (debug_info_offset
));
2801 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2803 const uint8_t address_size
= *addr
++;
2804 if (address_size
< 1 || address_size
> 8)
2806 warning (_("Section .debug_aranges in %s entry at offset %s "
2807 "address_size %u is invalid, ignoring .debug_aranges."),
2808 objfile_name (objfile
),
2809 plongest (entry_addr
- section
->buffer
), address_size
);
2813 const uint8_t segment_selector_size
= *addr
++;
2814 if (segment_selector_size
!= 0)
2816 warning (_("Section .debug_aranges in %s entry at offset %s "
2817 "segment_selector_size %u is not supported, "
2818 "ignoring .debug_aranges."),
2819 objfile_name (objfile
),
2820 plongest (entry_addr
- section
->buffer
),
2821 segment_selector_size
);
2825 /* Must pad to an alignment boundary that is twice the address
2826 size. It is undocumented by the DWARF standard but GCC does
2828 for (size_t padding
= ((-(addr
- section
->buffer
))
2829 & (2 * address_size
- 1));
2830 padding
> 0; padding
--)
2833 warning (_("Section .debug_aranges in %s entry at offset %s "
2834 "padding is not zero, ignoring .debug_aranges."),
2835 objfile_name (objfile
),
2836 plongest (entry_addr
- section
->buffer
));
2842 if (addr
+ 2 * address_size
> entry_end
)
2844 warning (_("Section .debug_aranges in %s entry at offset %s "
2845 "address list is not properly terminated, "
2846 "ignoring .debug_aranges."),
2847 objfile_name (objfile
),
2848 plongest (entry_addr
- section
->buffer
));
2851 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2853 addr
+= address_size
;
2854 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2856 addr
+= address_size
;
2857 if (start
== 0 && length
== 0)
2859 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
2861 /* Symbol was eliminated due to a COMDAT group. */
2864 ULONGEST end
= start
+ length
;
2865 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2867 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2869 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2873 objfile
->partial_symtabs
->psymtabs_addrmap
2874 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2877 /* Find a slot in the mapped index INDEX for the object named NAME.
2878 If NAME is found, set *VEC_OUT to point to the CU vector in the
2879 constant pool and return true. If NAME cannot be found, return
2883 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2884 offset_type
**vec_out
)
2887 offset_type slot
, step
;
2888 int (*cmp
) (const char *, const char *);
2890 gdb::unique_xmalloc_ptr
<char> without_params
;
2891 if (current_language
->la_language
== language_cplus
2892 || current_language
->la_language
== language_fortran
2893 || current_language
->la_language
== language_d
)
2895 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2898 if (strchr (name
, '(') != NULL
)
2900 without_params
= cp_remove_params (name
);
2902 if (without_params
!= NULL
)
2903 name
= without_params
.get ();
2907 /* Index version 4 did not support case insensitive searches. But the
2908 indices for case insensitive languages are built in lowercase, therefore
2909 simulate our NAME being searched is also lowercased. */
2910 hash
= mapped_index_string_hash ((index
->version
== 4
2911 && case_sensitivity
== case_sensitive_off
2912 ? 5 : index
->version
),
2915 slot
= hash
& (index
->symbol_table
.size () - 1);
2916 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2917 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2923 const auto &bucket
= index
->symbol_table
[slot
];
2924 if (bucket
.name
== 0 && bucket
.vec
== 0)
2927 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2928 if (!cmp (name
, str
))
2930 *vec_out
= (offset_type
*) (index
->constant_pool
2931 + MAYBE_SWAP (bucket
.vec
));
2935 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2939 /* A helper function that reads the .gdb_index from BUFFER and fills
2940 in MAP. FILENAME is the name of the file containing the data;
2941 it is used for error reporting. DEPRECATED_OK is true if it is
2942 ok to use deprecated sections.
2944 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2945 out parameters that are filled in with information about the CU and
2946 TU lists in the section.
2948 Returns true if all went well, false otherwise. */
2951 read_gdb_index_from_buffer (const char *filename
,
2953 gdb::array_view
<const gdb_byte
> buffer
,
2954 struct mapped_index
*map
,
2955 const gdb_byte
**cu_list
,
2956 offset_type
*cu_list_elements
,
2957 const gdb_byte
**types_list
,
2958 offset_type
*types_list_elements
)
2960 const gdb_byte
*addr
= &buffer
[0];
2962 /* Version check. */
2963 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2964 /* Versions earlier than 3 emitted every copy of a psymbol. This
2965 causes the index to behave very poorly for certain requests. Version 3
2966 contained incomplete addrmap. So, it seems better to just ignore such
2970 static int warning_printed
= 0;
2971 if (!warning_printed
)
2973 warning (_("Skipping obsolete .gdb_index section in %s."),
2975 warning_printed
= 1;
2979 /* Index version 4 uses a different hash function than index version
2982 Versions earlier than 6 did not emit psymbols for inlined
2983 functions. Using these files will cause GDB not to be able to
2984 set breakpoints on inlined functions by name, so we ignore these
2985 indices unless the user has done
2986 "set use-deprecated-index-sections on". */
2987 if (version
< 6 && !deprecated_ok
)
2989 static int warning_printed
= 0;
2990 if (!warning_printed
)
2993 Skipping deprecated .gdb_index section in %s.\n\
2994 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2995 to use the section anyway."),
2997 warning_printed
= 1;
3001 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3002 of the TU (for symbols coming from TUs),
3003 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3004 Plus gold-generated indices can have duplicate entries for global symbols,
3005 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3006 These are just performance bugs, and we can't distinguish gdb-generated
3007 indices from gold-generated ones, so issue no warning here. */
3009 /* Indexes with higher version than the one supported by GDB may be no
3010 longer backward compatible. */
3014 map
->version
= version
;
3016 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3019 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3020 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3024 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3025 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3026 - MAYBE_SWAP (metadata
[i
]))
3030 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3031 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3033 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3036 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3037 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3039 = gdb::array_view
<mapped_index::symbol_table_slot
>
3040 ((mapped_index::symbol_table_slot
*) symbol_table
,
3041 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3044 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3049 /* Callback types for dwarf2_read_gdb_index. */
3051 typedef gdb::function_view
3052 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3053 get_gdb_index_contents_ftype
;
3054 typedef gdb::function_view
3055 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3056 get_gdb_index_contents_dwz_ftype
;
3058 /* Read .gdb_index. If everything went ok, initialize the "quick"
3059 elements of all the CUs and return 1. Otherwise, return 0. */
3062 dwarf2_read_gdb_index
3063 (dwarf2_per_objfile
*per_objfile
,
3064 get_gdb_index_contents_ftype get_gdb_index_contents
,
3065 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3067 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3068 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3069 struct dwz_file
*dwz
;
3070 struct objfile
*objfile
= per_objfile
->objfile
;
3071 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3073 gdb::array_view
<const gdb_byte
> main_index_contents
3074 = get_gdb_index_contents (objfile
, per_bfd
);
3076 if (main_index_contents
.empty ())
3079 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3080 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3081 use_deprecated_index_sections
,
3082 main_index_contents
, map
.get (), &cu_list
,
3083 &cu_list_elements
, &types_list
,
3084 &types_list_elements
))
3087 /* Don't use the index if it's empty. */
3088 if (map
->symbol_table
.empty ())
3091 /* If there is a .dwz file, read it so we can get its CU list as
3093 dwz
= dwarf2_get_dwz_file (per_bfd
);
3096 struct mapped_index dwz_map
;
3097 const gdb_byte
*dwz_types_ignore
;
3098 offset_type dwz_types_elements_ignore
;
3100 gdb::array_view
<const gdb_byte
> dwz_index_content
3101 = get_gdb_index_contents_dwz (objfile
, dwz
);
3103 if (dwz_index_content
.empty ())
3106 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3107 1, dwz_index_content
, &dwz_map
,
3108 &dwz_list
, &dwz_list_elements
,
3110 &dwz_types_elements_ignore
))
3112 warning (_("could not read '.gdb_index' section from %s; skipping"),
3113 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3118 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3121 if (types_list_elements
)
3123 /* We can only handle a single .debug_types when we have an
3125 if (per_bfd
->types
.size () != 1)
3128 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3130 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3131 types_list_elements
);
3134 create_addrmap_from_index (per_objfile
, map
.get ());
3136 per_bfd
->index_table
= std::move (map
);
3137 per_bfd
->using_index
= 1;
3138 per_bfd
->quick_file_names_table
=
3139 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3141 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3142 objfiles using the same BFD. */
3143 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3144 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3149 /* die_reader_func for dw2_get_file_names. */
3152 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3153 const gdb_byte
*info_ptr
,
3154 struct die_info
*comp_unit_die
)
3156 struct dwarf2_cu
*cu
= reader
->cu
;
3157 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3158 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3159 struct dwarf2_per_cu_data
*lh_cu
;
3160 struct attribute
*attr
;
3162 struct quick_file_names
*qfn
;
3164 gdb_assert (! this_cu
->is_debug_types
);
3166 /* Our callers never want to match partial units -- instead they
3167 will match the enclosing full CU. */
3168 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3170 this_cu
->v
.quick
->no_file_data
= 1;
3178 sect_offset line_offset
{};
3180 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3181 if (attr
!= nullptr)
3183 struct quick_file_names find_entry
;
3185 line_offset
= (sect_offset
) DW_UNSND (attr
);
3187 /* We may have already read in this line header (TU line header sharing).
3188 If we have we're done. */
3189 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3190 find_entry
.hash
.line_sect_off
= line_offset
;
3191 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3192 &find_entry
, INSERT
);
3195 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3199 lh
= dwarf_decode_line_header (line_offset
, cu
);
3203 lh_cu
->v
.quick
->no_file_data
= 1;
3207 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3208 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3209 qfn
->hash
.line_sect_off
= line_offset
;
3210 gdb_assert (slot
!= NULL
);
3213 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3216 if (strcmp (fnd
.name
, "<unknown>") != 0)
3219 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3221 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3222 qfn
->num_file_names
);
3224 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3225 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3226 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3227 fnd
.comp_dir
).release ();
3228 qfn
->real_names
= NULL
;
3230 lh_cu
->v
.quick
->file_names
= qfn
;
3233 /* A helper for the "quick" functions which attempts to read the line
3234 table for THIS_CU. */
3236 static struct quick_file_names
*
3237 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3238 dwarf2_per_objfile
*per_objfile
)
3240 /* This should never be called for TUs. */
3241 gdb_assert (! this_cu
->is_debug_types
);
3242 /* Nor type unit groups. */
3243 gdb_assert (! this_cu
->type_unit_group_p ());
3245 if (this_cu
->v
.quick
->file_names
!= NULL
)
3246 return this_cu
->v
.quick
->file_names
;
3247 /* If we know there is no line data, no point in looking again. */
3248 if (this_cu
->v
.quick
->no_file_data
)
3251 cutu_reader
reader (this_cu
, per_objfile
);
3252 if (!reader
.dummy_p
)
3253 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3255 if (this_cu
->v
.quick
->no_file_data
)
3257 return this_cu
->v
.quick
->file_names
;
3260 /* A helper for the "quick" functions which computes and caches the
3261 real path for a given file name from the line table. */
3264 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3265 struct quick_file_names
*qfn
, int index
)
3267 if (qfn
->real_names
== NULL
)
3268 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3269 qfn
->num_file_names
, const char *);
3271 if (qfn
->real_names
[index
] == NULL
)
3272 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3274 return qfn
->real_names
[index
];
3277 static struct symtab
*
3278 dw2_find_last_source_symtab (struct objfile
*objfile
)
3280 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3281 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3282 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3287 return compunit_primary_filetab (cust
);
3290 /* Traversal function for dw2_forget_cached_source_info. */
3293 dw2_free_cached_file_names (void **slot
, void *info
)
3295 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3297 if (file_data
->real_names
)
3301 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3303 xfree ((void*) file_data
->real_names
[i
]);
3304 file_data
->real_names
[i
] = NULL
;
3312 dw2_forget_cached_source_info (struct objfile
*objfile
)
3314 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3316 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3317 dw2_free_cached_file_names
, NULL
);
3320 /* Helper function for dw2_map_symtabs_matching_filename that expands
3321 the symtabs and calls the iterator. */
3324 dw2_map_expand_apply (struct objfile
*objfile
,
3325 struct dwarf2_per_cu_data
*per_cu
,
3326 const char *name
, const char *real_path
,
3327 gdb::function_view
<bool (symtab
*)> callback
)
3329 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3331 /* Don't visit already-expanded CUs. */
3332 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3333 if (per_objfile
->symtab_set_p (per_cu
))
3336 /* This may expand more than one symtab, and we want to iterate over
3338 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3340 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3341 last_made
, callback
);
3344 /* Implementation of the map_symtabs_matching_filename method. */
3347 dw2_map_symtabs_matching_filename
3348 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3349 gdb::function_view
<bool (symtab
*)> callback
)
3351 const char *name_basename
= lbasename (name
);
3352 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3354 /* The rule is CUs specify all the files, including those used by
3355 any TU, so there's no need to scan TUs here. */
3357 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3359 /* We only need to look at symtabs not already expanded. */
3360 if (per_objfile
->symtab_set_p (per_cu
))
3363 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3364 if (file_data
== NULL
)
3367 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3369 const char *this_name
= file_data
->file_names
[j
];
3370 const char *this_real_name
;
3372 if (compare_filenames_for_search (this_name
, name
))
3374 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3380 /* Before we invoke realpath, which can get expensive when many
3381 files are involved, do a quick comparison of the basenames. */
3382 if (! basenames_may_differ
3383 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3386 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3387 if (compare_filenames_for_search (this_real_name
, name
))
3389 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3395 if (real_path
!= NULL
)
3397 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3398 gdb_assert (IS_ABSOLUTE_PATH (name
));
3399 if (this_real_name
!= NULL
3400 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3402 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3414 /* Struct used to manage iterating over all CUs looking for a symbol. */
3416 struct dw2_symtab_iterator
3418 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3419 dwarf2_per_objfile
*per_objfile
;
3420 /* If set, only look for symbols that match that block. Valid values are
3421 GLOBAL_BLOCK and STATIC_BLOCK. */
3422 gdb::optional
<block_enum
> block_index
;
3423 /* The kind of symbol we're looking for. */
3425 /* The list of CUs from the index entry of the symbol,
3426 or NULL if not found. */
3428 /* The next element in VEC to look at. */
3430 /* The number of elements in VEC, or zero if there is no match. */
3432 /* Have we seen a global version of the symbol?
3433 If so we can ignore all further global instances.
3434 This is to work around gold/15646, inefficient gold-generated
3439 /* Initialize the index symtab iterator ITER, common part. */
3442 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3443 dwarf2_per_objfile
*per_objfile
,
3444 gdb::optional
<block_enum
> block_index
,
3447 iter
->per_objfile
= per_objfile
;
3448 iter
->block_index
= block_index
;
3449 iter
->domain
= domain
;
3451 iter
->global_seen
= 0;
3456 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3459 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3460 dwarf2_per_objfile
*per_objfile
,
3461 gdb::optional
<block_enum
> block_index
,
3465 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3467 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3468 /* index is NULL if OBJF_READNOW. */
3472 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3473 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3476 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3479 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3480 dwarf2_per_objfile
*per_objfile
,
3481 gdb::optional
<block_enum
> block_index
,
3482 domain_enum domain
, offset_type namei
)
3484 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3486 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3487 /* index is NULL if OBJF_READNOW. */
3491 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3492 const auto &bucket
= index
->symbol_table
[namei
];
3494 iter
->vec
= (offset_type
*) (index
->constant_pool
3495 + MAYBE_SWAP (bucket
.vec
));
3496 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3499 /* Return the next matching CU or NULL if there are no more. */
3501 static struct dwarf2_per_cu_data
*
3502 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3504 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3506 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3508 offset_type cu_index_and_attrs
=
3509 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3510 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3511 gdb_index_symbol_kind symbol_kind
=
3512 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3513 /* Only check the symbol attributes if they're present.
3514 Indices prior to version 7 don't record them,
3515 and indices >= 7 may elide them for certain symbols
3516 (gold does this). */
3518 (per_objfile
->per_bfd
->index_table
->version
>= 7
3519 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3521 /* Don't crash on bad data. */
3522 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3523 + per_objfile
->per_bfd
->all_type_units
.size ()))
3525 complaint (_(".gdb_index entry has bad CU index"
3526 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3530 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3532 /* Skip if already read in. */
3533 if (per_objfile
->symtab_set_p (per_cu
))
3536 /* Check static vs global. */
3539 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3541 if (iter
->block_index
.has_value ())
3543 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3545 if (is_static
!= want_static
)
3549 /* Work around gold/15646. */
3551 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3553 if (iter
->global_seen
)
3556 iter
->global_seen
= 1;
3560 /* Only check the symbol's kind if it has one. */
3563 switch (iter
->domain
)
3566 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3567 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3568 /* Some types are also in VAR_DOMAIN. */
3569 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3573 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3577 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3581 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3596 static struct compunit_symtab
*
3597 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3598 const char *name
, domain_enum domain
)
3600 struct compunit_symtab
*stab_best
= NULL
;
3601 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3603 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3605 struct dw2_symtab_iterator iter
;
3606 struct dwarf2_per_cu_data
*per_cu
;
3608 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3610 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3612 struct symbol
*sym
, *with_opaque
= NULL
;
3613 struct compunit_symtab
*stab
3614 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3615 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3616 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3618 sym
= block_find_symbol (block
, name
, domain
,
3619 block_find_non_opaque_type_preferred
,
3622 /* Some caution must be observed with overloaded functions
3623 and methods, since the index will not contain any overload
3624 information (but NAME might contain it). */
3627 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3629 if (with_opaque
!= NULL
3630 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3633 /* Keep looking through other CUs. */
3640 dw2_print_stats (struct objfile
*objfile
)
3642 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3643 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3644 + per_objfile
->per_bfd
->all_type_units
.size ());
3647 for (int i
= 0; i
< total
; ++i
)
3649 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3651 if (!per_objfile
->symtab_set_p (per_cu
))
3654 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3655 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3658 /* This dumps minimal information about the index.
3659 It is called via "mt print objfiles".
3660 One use is to verify .gdb_index has been loaded by the
3661 gdb.dwarf2/gdb-index.exp testcase. */
3664 dw2_dump (struct objfile
*objfile
)
3666 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3668 gdb_assert (per_objfile
->per_bfd
->using_index
);
3669 printf_filtered (".gdb_index:");
3670 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3672 printf_filtered (" version %d\n",
3673 per_objfile
->per_bfd
->index_table
->version
);
3676 printf_filtered (" faked for \"readnow\"\n");
3677 printf_filtered ("\n");
3681 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3682 const char *func_name
)
3684 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3686 struct dw2_symtab_iterator iter
;
3687 struct dwarf2_per_cu_data
*per_cu
;
3689 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3691 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3692 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3697 dw2_expand_all_symtabs (struct objfile
*objfile
)
3699 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3700 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3701 + per_objfile
->per_bfd
->all_type_units
.size ());
3703 for (int i
= 0; i
< total_units
; ++i
)
3705 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3707 /* We don't want to directly expand a partial CU, because if we
3708 read it with the wrong language, then assertion failures can
3709 be triggered later on. See PR symtab/23010. So, tell
3710 dw2_instantiate_symtab to skip partial CUs -- any important
3711 partial CU will be read via DW_TAG_imported_unit anyway. */
3712 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3717 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3718 const char *fullname
)
3720 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3722 /* We don't need to consider type units here.
3723 This is only called for examining code, e.g. expand_line_sal.
3724 There can be an order of magnitude (or more) more type units
3725 than comp units, and we avoid them if we can. */
3727 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3729 /* We only need to look at symtabs not already expanded. */
3730 if (per_objfile
->symtab_set_p (per_cu
))
3733 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3734 if (file_data
== NULL
)
3737 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3739 const char *this_fullname
= file_data
->file_names
[j
];
3741 if (filename_cmp (this_fullname
, fullname
) == 0)
3743 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3751 dw2_expand_symtabs_matching_symbol
3752 (mapped_index_base
&index
,
3753 const lookup_name_info
&lookup_name_in
,
3754 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3755 enum search_domain kind
,
3756 gdb::function_view
<bool (offset_type
)> match_callback
,
3757 dwarf2_per_objfile
*per_objfile
);
3760 dw2_expand_symtabs_matching_one
3761 (dwarf2_per_cu_data
*per_cu
,
3762 dwarf2_per_objfile
*per_objfile
,
3763 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3764 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3767 dw2_map_matching_symbols
3768 (struct objfile
*objfile
,
3769 const lookup_name_info
&name
, domain_enum domain
,
3771 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3772 symbol_compare_ftype
*ordered_compare
)
3775 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3777 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3779 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3781 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3783 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3784 auto matcher
= [&] (const char *symname
)
3786 if (ordered_compare
== nullptr)
3788 return ordered_compare (symname
, match_name
) == 0;
3791 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3792 [&] (offset_type namei
)
3794 struct dw2_symtab_iterator iter
;
3795 struct dwarf2_per_cu_data
*per_cu
;
3797 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3799 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3800 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3807 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3808 proceed assuming all symtabs have been read in. */
3811 for (compunit_symtab
*cust
: objfile
->compunits ())
3813 const struct block
*block
;
3817 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3818 if (!iterate_over_symbols_terminated (block
, name
,
3824 /* Starting from a search name, return the string that finds the upper
3825 bound of all strings that start with SEARCH_NAME in a sorted name
3826 list. Returns the empty string to indicate that the upper bound is
3827 the end of the list. */
3830 make_sort_after_prefix_name (const char *search_name
)
3832 /* When looking to complete "func", we find the upper bound of all
3833 symbols that start with "func" by looking for where we'd insert
3834 the closest string that would follow "func" in lexicographical
3835 order. Usually, that's "func"-with-last-character-incremented,
3836 i.e. "fund". Mind non-ASCII characters, though. Usually those
3837 will be UTF-8 multi-byte sequences, but we can't be certain.
3838 Especially mind the 0xff character, which is a valid character in
3839 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3840 rule out compilers allowing it in identifiers. Note that
3841 conveniently, strcmp/strcasecmp are specified to compare
3842 characters interpreted as unsigned char. So what we do is treat
3843 the whole string as a base 256 number composed of a sequence of
3844 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3845 to 0, and carries 1 to the following more-significant position.
3846 If the very first character in SEARCH_NAME ends up incremented
3847 and carries/overflows, then the upper bound is the end of the
3848 list. The string after the empty string is also the empty
3851 Some examples of this operation:
3853 SEARCH_NAME => "+1" RESULT
3857 "\xff" "a" "\xff" => "\xff" "b"
3862 Then, with these symbols for example:
3868 completing "func" looks for symbols between "func" and
3869 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3870 which finds "func" and "func1", but not "fund".
3874 funcÿ (Latin1 'ÿ' [0xff])
3878 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3879 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3883 ÿÿ (Latin1 'ÿ' [0xff])
3886 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3887 the end of the list.
3889 std::string after
= search_name
;
3890 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3892 if (!after
.empty ())
3893 after
.back () = (unsigned char) after
.back () + 1;
3897 /* See declaration. */
3899 std::pair
<std::vector
<name_component
>::const_iterator
,
3900 std::vector
<name_component
>::const_iterator
>
3901 mapped_index_base::find_name_components_bounds
3902 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3903 dwarf2_per_objfile
*per_objfile
) const
3906 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3908 const char *lang_name
3909 = lookup_name_without_params
.language_lookup_name (lang
);
3911 /* Comparison function object for lower_bound that matches against a
3912 given symbol name. */
3913 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3916 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3917 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3918 return name_cmp (elem_name
, name
) < 0;
3921 /* Comparison function object for upper_bound that matches against a
3922 given symbol name. */
3923 auto lookup_compare_upper
= [&] (const char *name
,
3924 const name_component
&elem
)
3926 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3927 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3928 return name_cmp (name
, elem_name
) < 0;
3931 auto begin
= this->name_components
.begin ();
3932 auto end
= this->name_components
.end ();
3934 /* Find the lower bound. */
3937 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3940 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3943 /* Find the upper bound. */
3946 if (lookup_name_without_params
.completion_mode ())
3948 /* In completion mode, we want UPPER to point past all
3949 symbols names that have the same prefix. I.e., with
3950 these symbols, and completing "func":
3952 function << lower bound
3954 other_function << upper bound
3956 We find the upper bound by looking for the insertion
3957 point of "func"-with-last-character-incremented,
3959 std::string after
= make_sort_after_prefix_name (lang_name
);
3962 return std::lower_bound (lower
, end
, after
.c_str (),
3963 lookup_compare_lower
);
3966 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3969 return {lower
, upper
};
3972 /* See declaration. */
3975 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3977 if (!this->name_components
.empty ())
3980 this->name_components_casing
= case_sensitivity
;
3982 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3984 /* The code below only knows how to break apart components of C++
3985 symbol names (and other languages that use '::' as
3986 namespace/module separator) and Ada symbol names. */
3987 auto count
= this->symbol_name_count ();
3988 for (offset_type idx
= 0; idx
< count
; idx
++)
3990 if (this->symbol_name_slot_invalid (idx
))
3993 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3995 /* Add each name component to the name component table. */
3996 unsigned int previous_len
= 0;
3998 if (strstr (name
, "::") != nullptr)
4000 for (unsigned int current_len
= cp_find_first_component (name
);
4001 name
[current_len
] != '\0';
4002 current_len
+= cp_find_first_component (name
+ current_len
))
4004 gdb_assert (name
[current_len
] == ':');
4005 this->name_components
.push_back ({previous_len
, idx
});
4006 /* Skip the '::'. */
4008 previous_len
= current_len
;
4013 /* Handle the Ada encoded (aka mangled) form here. */
4014 for (const char *iter
= strstr (name
, "__");
4016 iter
= strstr (iter
, "__"))
4018 this->name_components
.push_back ({previous_len
, idx
});
4020 previous_len
= iter
- name
;
4024 this->name_components
.push_back ({previous_len
, idx
});
4027 /* Sort name_components elements by name. */
4028 auto name_comp_compare
= [&] (const name_component
&left
,
4029 const name_component
&right
)
4031 const char *left_qualified
4032 = this->symbol_name_at (left
.idx
, per_objfile
);
4033 const char *right_qualified
4034 = this->symbol_name_at (right
.idx
, per_objfile
);
4036 const char *left_name
= left_qualified
+ left
.name_offset
;
4037 const char *right_name
= right_qualified
+ right
.name_offset
;
4039 return name_cmp (left_name
, right_name
) < 0;
4042 std::sort (this->name_components
.begin (),
4043 this->name_components
.end (),
4047 /* Helper for dw2_expand_symtabs_matching that works with a
4048 mapped_index_base instead of the containing objfile. This is split
4049 to a separate function in order to be able to unit test the
4050 name_components matching using a mock mapped_index_base. For each
4051 symbol name that matches, calls MATCH_CALLBACK, passing it the
4052 symbol's index in the mapped_index_base symbol table. */
4055 dw2_expand_symtabs_matching_symbol
4056 (mapped_index_base
&index
,
4057 const lookup_name_info
&lookup_name_in
,
4058 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4059 enum search_domain kind
,
4060 gdb::function_view
<bool (offset_type
)> match_callback
,
4061 dwarf2_per_objfile
*per_objfile
)
4063 lookup_name_info lookup_name_without_params
4064 = lookup_name_in
.make_ignore_params ();
4066 /* Build the symbol name component sorted vector, if we haven't
4068 index
.build_name_components (per_objfile
);
4070 /* The same symbol may appear more than once in the range though.
4071 E.g., if we're looking for symbols that complete "w", and we have
4072 a symbol named "w1::w2", we'll find the two name components for
4073 that same symbol in the range. To be sure we only call the
4074 callback once per symbol, we first collect the symbol name
4075 indexes that matched in a temporary vector and ignore
4077 std::vector
<offset_type
> matches
;
4079 struct name_and_matcher
4081 symbol_name_matcher_ftype
*matcher
;
4084 bool operator== (const name_and_matcher
&other
) const
4086 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4090 /* A vector holding all the different symbol name matchers, for all
4092 std::vector
<name_and_matcher
> matchers
;
4094 for (int i
= 0; i
< nr_languages
; i
++)
4096 enum language lang_e
= (enum language
) i
;
4098 const language_defn
*lang
= language_def (lang_e
);
4099 symbol_name_matcher_ftype
*name_matcher
4100 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4102 name_and_matcher key
{
4104 lookup_name_without_params
.language_lookup_name (lang_e
)
4107 /* Don't insert the same comparison routine more than once.
4108 Note that we do this linear walk. This is not a problem in
4109 practice because the number of supported languages is
4111 if (std::find (matchers
.begin (), matchers
.end (), key
)
4114 matchers
.push_back (std::move (key
));
4117 = index
.find_name_components_bounds (lookup_name_without_params
,
4118 lang_e
, per_objfile
);
4120 /* Now for each symbol name in range, check to see if we have a name
4121 match, and if so, call the MATCH_CALLBACK callback. */
4123 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4125 const char *qualified
4126 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4128 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4129 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4132 matches
.push_back (bounds
.first
->idx
);
4136 std::sort (matches
.begin (), matches
.end ());
4138 /* Finally call the callback, once per match. */
4140 for (offset_type idx
: matches
)
4144 if (!match_callback (idx
))
4150 /* Above we use a type wider than idx's for 'prev', since 0 and
4151 (offset_type)-1 are both possible values. */
4152 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4157 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4159 /* A mock .gdb_index/.debug_names-like name index table, enough to
4160 exercise dw2_expand_symtabs_matching_symbol, which works with the
4161 mapped_index_base interface. Builds an index from the symbol list
4162 passed as parameter to the constructor. */
4163 class mock_mapped_index
: public mapped_index_base
4166 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4167 : m_symbol_table (symbols
)
4170 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4172 /* Return the number of names in the symbol table. */
4173 size_t symbol_name_count () const override
4175 return m_symbol_table
.size ();
4178 /* Get the name of the symbol at IDX in the symbol table. */
4179 const char *symbol_name_at
4180 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4182 return m_symbol_table
[idx
];
4186 gdb::array_view
<const char *> m_symbol_table
;
4189 /* Convenience function that converts a NULL pointer to a "<null>"
4190 string, to pass to print routines. */
4193 string_or_null (const char *str
)
4195 return str
!= NULL
? str
: "<null>";
4198 /* Check if a lookup_name_info built from
4199 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4200 index. EXPECTED_LIST is the list of expected matches, in expected
4201 matching order. If no match expected, then an empty list is
4202 specified. Returns true on success. On failure prints a warning
4203 indicating the file:line that failed, and returns false. */
4206 check_match (const char *file
, int line
,
4207 mock_mapped_index
&mock_index
,
4208 const char *name
, symbol_name_match_type match_type
,
4209 bool completion_mode
,
4210 std::initializer_list
<const char *> expected_list
,
4211 dwarf2_per_objfile
*per_objfile
)
4213 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4215 bool matched
= true;
4217 auto mismatch
= [&] (const char *expected_str
,
4220 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4221 "expected=\"%s\", got=\"%s\"\n"),
4223 (match_type
== symbol_name_match_type::FULL
4225 name
, string_or_null (expected_str
), string_or_null (got
));
4229 auto expected_it
= expected_list
.begin ();
4230 auto expected_end
= expected_list
.end ();
4232 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4234 [&] (offset_type idx
)
4236 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4237 const char *expected_str
4238 = expected_it
== expected_end
? NULL
: *expected_it
++;
4240 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4241 mismatch (expected_str
, matched_name
);
4245 const char *expected_str
4246 = expected_it
== expected_end
? NULL
: *expected_it
++;
4247 if (expected_str
!= NULL
)
4248 mismatch (expected_str
, NULL
);
4253 /* The symbols added to the mock mapped_index for testing (in
4255 static const char *test_symbols
[] = {
4264 "ns2::tmpl<int>::foo2",
4265 "(anonymous namespace)::A::B::C",
4267 /* These are used to check that the increment-last-char in the
4268 matching algorithm for completion doesn't match "t1_fund" when
4269 completing "t1_func". */
4275 /* A UTF-8 name with multi-byte sequences to make sure that
4276 cp-name-parser understands this as a single identifier ("função"
4277 is "function" in PT). */
4280 /* \377 (0xff) is Latin1 'ÿ'. */
4283 /* \377 (0xff) is Latin1 'ÿ'. */
4287 /* A name with all sorts of complications. Starts with "z" to make
4288 it easier for the completion tests below. */
4289 #define Z_SYM_NAME \
4290 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4291 "::tuple<(anonymous namespace)::ui*, " \
4292 "std::default_delete<(anonymous namespace)::ui>, void>"
4297 /* Returns true if the mapped_index_base::find_name_component_bounds
4298 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4299 in completion mode. */
4302 check_find_bounds_finds (mapped_index_base
&index
,
4303 const char *search_name
,
4304 gdb::array_view
<const char *> expected_syms
,
4305 dwarf2_per_objfile
*per_objfile
)
4307 lookup_name_info
lookup_name (search_name
,
4308 symbol_name_match_type::FULL
, true);
4310 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4314 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4315 if (distance
!= expected_syms
.size ())
4318 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4320 auto nc_elem
= bounds
.first
+ exp_elem
;
4321 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4322 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4329 /* Test the lower-level mapped_index::find_name_component_bounds
4333 test_mapped_index_find_name_component_bounds ()
4335 mock_mapped_index
mock_index (test_symbols
);
4337 mock_index
.build_name_components (NULL
/* per_objfile */);
4339 /* Test the lower-level mapped_index::find_name_component_bounds
4340 method in completion mode. */
4342 static const char *expected_syms
[] = {
4347 SELF_CHECK (check_find_bounds_finds
4348 (mock_index
, "t1_func", expected_syms
,
4349 NULL
/* per_objfile */));
4352 /* Check that the increment-last-char in the name matching algorithm
4353 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4355 static const char *expected_syms1
[] = {
4359 SELF_CHECK (check_find_bounds_finds
4360 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4362 static const char *expected_syms2
[] = {
4365 SELF_CHECK (check_find_bounds_finds
4366 (mock_index
, "\377\377", expected_syms2
,
4367 NULL
/* per_objfile */));
4371 /* Test dw2_expand_symtabs_matching_symbol. */
4374 test_dw2_expand_symtabs_matching_symbol ()
4376 mock_mapped_index
mock_index (test_symbols
);
4378 /* We let all tests run until the end even if some fails, for debug
4380 bool any_mismatch
= false;
4382 /* Create the expected symbols list (an initializer_list). Needed
4383 because lists have commas, and we need to pass them to CHECK,
4384 which is a macro. */
4385 #define EXPECT(...) { __VA_ARGS__ }
4387 /* Wrapper for check_match that passes down the current
4388 __FILE__/__LINE__. */
4389 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4390 any_mismatch |= !check_match (__FILE__, __LINE__, \
4392 NAME, MATCH_TYPE, COMPLETION_MODE, \
4393 EXPECTED_LIST, NULL)
4395 /* Identity checks. */
4396 for (const char *sym
: test_symbols
)
4398 /* Should be able to match all existing symbols. */
4399 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4402 /* Should be able to match all existing symbols with
4404 std::string with_params
= std::string (sym
) + "(int)";
4405 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4408 /* Should be able to match all existing symbols with
4409 parameters and qualifiers. */
4410 with_params
= std::string (sym
) + " ( int ) const";
4411 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4414 /* This should really find sym, but cp-name-parser.y doesn't
4415 know about lvalue/rvalue qualifiers yet. */
4416 with_params
= std::string (sym
) + " ( int ) &&";
4417 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4421 /* Check that the name matching algorithm for completion doesn't get
4422 confused with Latin1 'ÿ' / 0xff. */
4424 static const char str
[] = "\377";
4425 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4426 EXPECT ("\377", "\377\377123"));
4429 /* Check that the increment-last-char in the matching algorithm for
4430 completion doesn't match "t1_fund" when completing "t1_func". */
4432 static const char str
[] = "t1_func";
4433 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4434 EXPECT ("t1_func", "t1_func1"));
4437 /* Check that completion mode works at each prefix of the expected
4440 static const char str
[] = "function(int)";
4441 size_t len
= strlen (str
);
4444 for (size_t i
= 1; i
< len
; i
++)
4446 lookup
.assign (str
, i
);
4447 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4448 EXPECT ("function"));
4452 /* While "w" is a prefix of both components, the match function
4453 should still only be called once. */
4455 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4457 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4461 /* Same, with a "complicated" symbol. */
4463 static const char str
[] = Z_SYM_NAME
;
4464 size_t len
= strlen (str
);
4467 for (size_t i
= 1; i
< len
; i
++)
4469 lookup
.assign (str
, i
);
4470 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4471 EXPECT (Z_SYM_NAME
));
4475 /* In FULL mode, an incomplete symbol doesn't match. */
4477 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4481 /* A complete symbol with parameters matches any overload, since the
4482 index has no overload info. */
4484 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4485 EXPECT ("std::zfunction", "std::zfunction2"));
4486 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4487 EXPECT ("std::zfunction", "std::zfunction2"));
4488 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4489 EXPECT ("std::zfunction", "std::zfunction2"));
4492 /* Check that whitespace is ignored appropriately. A symbol with a
4493 template argument list. */
4495 static const char expected
[] = "ns::foo<int>";
4496 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4498 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4502 /* Check that whitespace is ignored appropriately. A symbol with a
4503 template argument list that includes a pointer. */
4505 static const char expected
[] = "ns::foo<char*>";
4506 /* Try both completion and non-completion modes. */
4507 static const bool completion_mode
[2] = {false, true};
4508 for (size_t i
= 0; i
< 2; i
++)
4510 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4511 completion_mode
[i
], EXPECT (expected
));
4512 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4513 completion_mode
[i
], EXPECT (expected
));
4515 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4516 completion_mode
[i
], EXPECT (expected
));
4517 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4518 completion_mode
[i
], EXPECT (expected
));
4523 /* Check method qualifiers are ignored. */
4524 static const char expected
[] = "ns::foo<char*>";
4525 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4526 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4527 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4528 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4529 CHECK_MATCH ("foo < char * > ( int ) const",
4530 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4531 CHECK_MATCH ("foo < char * > ( int ) &&",
4532 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4535 /* Test lookup names that don't match anything. */
4537 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4540 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4544 /* Some wild matching tests, exercising "(anonymous namespace)",
4545 which should not be confused with a parameter list. */
4547 static const char *syms
[] = {
4551 "A :: B :: C ( int )",
4556 for (const char *s
: syms
)
4558 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4559 EXPECT ("(anonymous namespace)::A::B::C"));
4564 static const char expected
[] = "ns2::tmpl<int>::foo2";
4565 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4567 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4571 SELF_CHECK (!any_mismatch
);
4580 test_mapped_index_find_name_component_bounds ();
4581 test_dw2_expand_symtabs_matching_symbol ();
4584 }} // namespace selftests::dw2_expand_symtabs_matching
4586 #endif /* GDB_SELF_TEST */
4588 /* If FILE_MATCHER is NULL or if PER_CU has
4589 dwarf2_per_cu_quick_data::MARK set (see
4590 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4591 EXPANSION_NOTIFY on it. */
4594 dw2_expand_symtabs_matching_one
4595 (dwarf2_per_cu_data
*per_cu
,
4596 dwarf2_per_objfile
*per_objfile
,
4597 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4598 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4600 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4602 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4604 compunit_symtab
*symtab
4605 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4606 gdb_assert (symtab
!= nullptr);
4608 if (expansion_notify
!= NULL
&& symtab_was_null
)
4609 expansion_notify (symtab
);
4613 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4614 matched, to expand corresponding CUs that were marked. IDX is the
4615 index of the symbol name that matched. */
4618 dw2_expand_marked_cus
4619 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4620 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4621 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4624 offset_type
*vec
, vec_len
, vec_idx
;
4625 bool global_seen
= false;
4626 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4628 vec
= (offset_type
*) (index
.constant_pool
4629 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4630 vec_len
= MAYBE_SWAP (vec
[0]);
4631 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4633 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4634 /* This value is only valid for index versions >= 7. */
4635 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4636 gdb_index_symbol_kind symbol_kind
=
4637 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4638 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4639 /* Only check the symbol attributes if they're present.
4640 Indices prior to version 7 don't record them,
4641 and indices >= 7 may elide them for certain symbols
4642 (gold does this). */
4645 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4647 /* Work around gold/15646. */
4650 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4658 /* Only check the symbol's kind if it has one. */
4663 case VARIABLES_DOMAIN
:
4664 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4667 case FUNCTIONS_DOMAIN
:
4668 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4672 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4675 case MODULES_DOMAIN
:
4676 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4684 /* Don't crash on bad data. */
4685 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4686 + per_objfile
->per_bfd
->all_type_units
.size ()))
4688 complaint (_(".gdb_index entry has bad CU index"
4689 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4693 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4694 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4699 /* If FILE_MATCHER is non-NULL, set all the
4700 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4701 that match FILE_MATCHER. */
4704 dw_expand_symtabs_matching_file_matcher
4705 (dwarf2_per_objfile
*per_objfile
,
4706 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4708 if (file_matcher
== NULL
)
4711 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4713 NULL
, xcalloc
, xfree
));
4714 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4716 NULL
, xcalloc
, xfree
));
4718 /* The rule is CUs specify all the files, including those used by
4719 any TU, so there's no need to scan TUs here. */
4721 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4725 per_cu
->v
.quick
->mark
= 0;
4727 /* We only need to look at symtabs not already expanded. */
4728 if (per_objfile
->symtab_set_p (per_cu
))
4731 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4732 if (file_data
== NULL
)
4735 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4737 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4739 per_cu
->v
.quick
->mark
= 1;
4743 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4745 const char *this_real_name
;
4747 if (file_matcher (file_data
->file_names
[j
], false))
4749 per_cu
->v
.quick
->mark
= 1;
4753 /* Before we invoke realpath, which can get expensive when many
4754 files are involved, do a quick comparison of the basenames. */
4755 if (!basenames_may_differ
4756 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4760 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4761 if (file_matcher (this_real_name
, false))
4763 per_cu
->v
.quick
->mark
= 1;
4768 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4769 ? visited_found
.get ()
4770 : visited_not_found
.get (),
4777 dw2_expand_symtabs_matching
4778 (struct objfile
*objfile
,
4779 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4780 const lookup_name_info
*lookup_name
,
4781 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4782 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4783 enum search_domain kind
)
4785 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4787 /* index_table is NULL if OBJF_READNOW. */
4788 if (!per_objfile
->per_bfd
->index_table
)
4791 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4793 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4795 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4799 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4800 file_matcher
, expansion_notify
);
4805 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4807 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4809 kind
, [&] (offset_type idx
)
4811 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4817 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4820 static struct compunit_symtab
*
4821 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4826 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4827 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4830 if (cust
->includes
== NULL
)
4833 for (i
= 0; cust
->includes
[i
]; ++i
)
4835 struct compunit_symtab
*s
= cust
->includes
[i
];
4837 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4845 static struct compunit_symtab
*
4846 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4847 struct bound_minimal_symbol msymbol
,
4849 struct obj_section
*section
,
4852 struct dwarf2_per_cu_data
*data
;
4853 struct compunit_symtab
*result
;
4855 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4858 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4859 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4860 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4864 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4865 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4866 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4867 paddress (objfile
->arch (), pc
));
4869 result
= recursively_find_pc_sect_compunit_symtab
4870 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4872 gdb_assert (result
!= NULL
);
4877 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4878 void *data
, int need_fullname
)
4880 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4882 if (!per_objfile
->per_bfd
->filenames_cache
)
4884 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4886 htab_up
visited (htab_create_alloc (10,
4887 htab_hash_pointer
, htab_eq_pointer
,
4888 NULL
, xcalloc
, xfree
));
4890 /* The rule is CUs specify all the files, including those used
4891 by any TU, so there's no need to scan TUs here. We can
4892 ignore file names coming from already-expanded CUs. */
4894 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4896 if (per_objfile
->symtab_set_p (per_cu
))
4898 void **slot
= htab_find_slot (visited
.get (),
4899 per_cu
->v
.quick
->file_names
,
4902 *slot
= per_cu
->v
.quick
->file_names
;
4906 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4908 /* We only need to look at symtabs not already expanded. */
4909 if (per_objfile
->symtab_set_p (per_cu
))
4912 quick_file_names
*file_data
4913 = dw2_get_file_names (per_cu
, per_objfile
);
4914 if (file_data
== NULL
)
4917 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4920 /* Already visited. */
4925 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4927 const char *filename
= file_data
->file_names
[j
];
4928 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4933 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4935 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4938 this_real_name
= gdb_realpath (filename
);
4939 (*fun
) (filename
, this_real_name
.get (), data
);
4944 dw2_has_symbols (struct objfile
*objfile
)
4949 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4952 dw2_find_last_source_symtab
,
4953 dw2_forget_cached_source_info
,
4954 dw2_map_symtabs_matching_filename
,
4959 dw2_expand_symtabs_for_function
,
4960 dw2_expand_all_symtabs
,
4961 dw2_expand_symtabs_with_fullname
,
4962 dw2_map_matching_symbols
,
4963 dw2_expand_symtabs_matching
,
4964 dw2_find_pc_sect_compunit_symtab
,
4966 dw2_map_symbol_filenames
4969 /* DWARF-5 debug_names reader. */
4971 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4972 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4974 /* A helper function that reads the .debug_names section in SECTION
4975 and fills in MAP. FILENAME is the name of the file containing the
4976 section; it is used for error reporting.
4978 Returns true if all went well, false otherwise. */
4981 read_debug_names_from_section (struct objfile
*objfile
,
4982 const char *filename
,
4983 struct dwarf2_section_info
*section
,
4984 mapped_debug_names
&map
)
4986 if (section
->empty ())
4989 /* Older elfutils strip versions could keep the section in the main
4990 executable while splitting it for the separate debug info file. */
4991 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4994 section
->read (objfile
);
4996 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4998 const gdb_byte
*addr
= section
->buffer
;
5000 bfd
*const abfd
= section
->get_bfd_owner ();
5002 unsigned int bytes_read
;
5003 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5006 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5007 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5008 if (bytes_read
+ length
!= section
->size
)
5010 /* There may be multiple per-CU indices. */
5011 warning (_("Section .debug_names in %s length %s does not match "
5012 "section length %s, ignoring .debug_names."),
5013 filename
, plongest (bytes_read
+ length
),
5014 pulongest (section
->size
));
5018 /* The version number. */
5019 uint16_t version
= read_2_bytes (abfd
, addr
);
5023 warning (_("Section .debug_names in %s has unsupported version %d, "
5024 "ignoring .debug_names."),
5030 uint16_t padding
= read_2_bytes (abfd
, addr
);
5034 warning (_("Section .debug_names in %s has unsupported padding %d, "
5035 "ignoring .debug_names."),
5040 /* comp_unit_count - The number of CUs in the CU list. */
5041 map
.cu_count
= read_4_bytes (abfd
, addr
);
5044 /* local_type_unit_count - The number of TUs in the local TU
5046 map
.tu_count
= read_4_bytes (abfd
, addr
);
5049 /* foreign_type_unit_count - The number of TUs in the foreign TU
5051 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5053 if (foreign_tu_count
!= 0)
5055 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5056 "ignoring .debug_names."),
5057 filename
, static_cast<unsigned long> (foreign_tu_count
));
5061 /* bucket_count - The number of hash buckets in the hash lookup
5063 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5066 /* name_count - The number of unique names in the index. */
5067 map
.name_count
= read_4_bytes (abfd
, addr
);
5070 /* abbrev_table_size - The size in bytes of the abbreviations
5072 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5075 /* augmentation_string_size - The size in bytes of the augmentation
5076 string. This value is rounded up to a multiple of 4. */
5077 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5079 map
.augmentation_is_gdb
= ((augmentation_string_size
5080 == sizeof (dwarf5_augmentation
))
5081 && memcmp (addr
, dwarf5_augmentation
,
5082 sizeof (dwarf5_augmentation
)) == 0);
5083 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5084 addr
+= augmentation_string_size
;
5087 map
.cu_table_reordered
= addr
;
5088 addr
+= map
.cu_count
* map
.offset_size
;
5090 /* List of Local TUs */
5091 map
.tu_table_reordered
= addr
;
5092 addr
+= map
.tu_count
* map
.offset_size
;
5094 /* Hash Lookup Table */
5095 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5096 addr
+= map
.bucket_count
* 4;
5097 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5098 addr
+= map
.name_count
* 4;
5101 map
.name_table_string_offs_reordered
= addr
;
5102 addr
+= map
.name_count
* map
.offset_size
;
5103 map
.name_table_entry_offs_reordered
= addr
;
5104 addr
+= map
.name_count
* map
.offset_size
;
5106 const gdb_byte
*abbrev_table_start
= addr
;
5109 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5114 const auto insertpair
5115 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5116 if (!insertpair
.second
)
5118 warning (_("Section .debug_names in %s has duplicate index %s, "
5119 "ignoring .debug_names."),
5120 filename
, pulongest (index_num
));
5123 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5124 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5129 mapped_debug_names::index_val::attr attr
;
5130 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5132 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5134 if (attr
.form
== DW_FORM_implicit_const
)
5136 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5140 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5142 indexval
.attr_vec
.push_back (std::move (attr
));
5145 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5147 warning (_("Section .debug_names in %s has abbreviation_table "
5148 "of size %s vs. written as %u, ignoring .debug_names."),
5149 filename
, plongest (addr
- abbrev_table_start
),
5153 map
.entry_pool
= addr
;
5158 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5162 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5163 const mapped_debug_names
&map
,
5164 dwarf2_section_info
§ion
,
5167 if (!map
.augmentation_is_gdb
)
5169 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5171 sect_offset sect_off
5172 = (sect_offset
) (extract_unsigned_integer
5173 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5175 map
.dwarf5_byte_order
));
5176 /* We don't know the length of the CU, because the CU list in a
5177 .debug_names index can be incomplete, so we can't use the start of
5178 the next CU as end of this CU. We create the CUs here with length 0,
5179 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5180 dwarf2_per_cu_data
*per_cu
5181 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5182 per_bfd
->all_comp_units
.push_back (per_cu
);
5186 sect_offset sect_off_prev
;
5187 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5189 sect_offset sect_off_next
;
5190 if (i
< map
.cu_count
)
5193 = (sect_offset
) (extract_unsigned_integer
5194 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5196 map
.dwarf5_byte_order
));
5199 sect_off_next
= (sect_offset
) section
.size
;
5202 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5203 dwarf2_per_cu_data
*per_cu
5204 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5205 sect_off_prev
, length
);
5206 per_bfd
->all_comp_units
.push_back (per_cu
);
5208 sect_off_prev
= sect_off_next
;
5212 /* Read the CU list from the mapped index, and use it to create all
5213 the CU objects for this dwarf2_per_objfile. */
5216 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5217 const mapped_debug_names
&map
,
5218 const mapped_debug_names
&dwz_map
)
5220 gdb_assert (per_bfd
->all_comp_units
.empty ());
5221 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5223 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5224 false /* is_dwz */);
5226 if (dwz_map
.cu_count
== 0)
5229 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5230 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5234 /* Read .debug_names. If everything went ok, initialize the "quick"
5235 elements of all the CUs and return true. Otherwise, return false. */
5238 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5240 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5241 mapped_debug_names dwz_map
;
5242 struct objfile
*objfile
= per_objfile
->objfile
;
5243 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5245 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5246 &per_objfile
->per_bfd
->debug_names
, *map
))
5249 /* Don't use the index if it's empty. */
5250 if (map
->name_count
== 0)
5253 /* If there is a .dwz file, read it so we can get its CU list as
5255 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5258 if (!read_debug_names_from_section (objfile
,
5259 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5260 &dwz
->debug_names
, dwz_map
))
5262 warning (_("could not read '.debug_names' section from %s; skipping"),
5263 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5268 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5270 if (map
->tu_count
!= 0)
5272 /* We can only handle a single .debug_types when we have an
5274 if (per_bfd
->types
.size () != 1)
5277 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5279 create_signatured_type_table_from_debug_names
5280 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5283 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5285 per_bfd
->debug_names_table
= std::move (map
);
5286 per_bfd
->using_index
= 1;
5287 per_bfd
->quick_file_names_table
=
5288 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5290 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5291 objfiles using the same BFD. */
5292 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5293 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5298 /* Type used to manage iterating over all CUs looking for a symbol for
5301 class dw2_debug_names_iterator
5304 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5305 gdb::optional
<block_enum
> block_index
,
5307 const char *name
, dwarf2_per_objfile
*per_objfile
)
5308 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5309 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5310 m_per_objfile (per_objfile
)
5313 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5314 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5317 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5318 m_per_objfile (per_objfile
)
5321 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5322 block_enum block_index
, domain_enum domain
,
5323 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5324 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5325 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5326 m_per_objfile (per_objfile
)
5329 /* Return the next matching CU or NULL if there are no more. */
5330 dwarf2_per_cu_data
*next ();
5333 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5335 dwarf2_per_objfile
*per_objfile
);
5336 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5338 dwarf2_per_objfile
*per_objfile
);
5340 /* The internalized form of .debug_names. */
5341 const mapped_debug_names
&m_map
;
5343 /* If set, only look for symbols that match that block. Valid values are
5344 GLOBAL_BLOCK and STATIC_BLOCK. */
5345 const gdb::optional
<block_enum
> m_block_index
;
5347 /* The kind of symbol we're looking for. */
5348 const domain_enum m_domain
= UNDEF_DOMAIN
;
5349 const search_domain m_search
= ALL_DOMAIN
;
5351 /* The list of CUs from the index entry of the symbol, or NULL if
5353 const gdb_byte
*m_addr
;
5355 dwarf2_per_objfile
*m_per_objfile
;
5359 mapped_debug_names::namei_to_name
5360 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5362 const ULONGEST namei_string_offs
5363 = extract_unsigned_integer ((name_table_string_offs_reordered
5364 + namei
* offset_size
),
5367 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5370 /* Find a slot in .debug_names for the object named NAME. If NAME is
5371 found, return pointer to its pool data. If NAME cannot be found,
5375 dw2_debug_names_iterator::find_vec_in_debug_names
5376 (const mapped_debug_names
&map
, const char *name
,
5377 dwarf2_per_objfile
*per_objfile
)
5379 int (*cmp
) (const char *, const char *);
5381 gdb::unique_xmalloc_ptr
<char> without_params
;
5382 if (current_language
->la_language
== language_cplus
5383 || current_language
->la_language
== language_fortran
5384 || current_language
->la_language
== language_d
)
5386 /* NAME is already canonical. Drop any qualifiers as
5387 .debug_names does not contain any. */
5389 if (strchr (name
, '(') != NULL
)
5391 without_params
= cp_remove_params (name
);
5392 if (without_params
!= NULL
)
5393 name
= without_params
.get ();
5397 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5399 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5401 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5402 (map
.bucket_table_reordered
5403 + (full_hash
% map
.bucket_count
)), 4,
5404 map
.dwarf5_byte_order
);
5408 if (namei
>= map
.name_count
)
5410 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5412 namei
, map
.name_count
,
5413 objfile_name (per_objfile
->objfile
));
5419 const uint32_t namei_full_hash
5420 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5421 (map
.hash_table_reordered
+ namei
), 4,
5422 map
.dwarf5_byte_order
);
5423 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5426 if (full_hash
== namei_full_hash
)
5428 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5430 #if 0 /* An expensive sanity check. */
5431 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5433 complaint (_("Wrong .debug_names hash for string at index %u "
5435 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5440 if (cmp (namei_string
, name
) == 0)
5442 const ULONGEST namei_entry_offs
5443 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5444 + namei
* map
.offset_size
),
5445 map
.offset_size
, map
.dwarf5_byte_order
);
5446 return map
.entry_pool
+ namei_entry_offs
;
5451 if (namei
>= map
.name_count
)
5457 dw2_debug_names_iterator::find_vec_in_debug_names
5458 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5460 if (namei
>= map
.name_count
)
5462 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5464 namei
, map
.name_count
,
5465 objfile_name (per_objfile
->objfile
));
5469 const ULONGEST namei_entry_offs
5470 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5471 + namei
* map
.offset_size
),
5472 map
.offset_size
, map
.dwarf5_byte_order
);
5473 return map
.entry_pool
+ namei_entry_offs
;
5476 /* See dw2_debug_names_iterator. */
5478 dwarf2_per_cu_data
*
5479 dw2_debug_names_iterator::next ()
5484 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5485 struct objfile
*objfile
= m_per_objfile
->objfile
;
5486 bfd
*const abfd
= objfile
->obfd
;
5490 unsigned int bytes_read
;
5491 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5492 m_addr
+= bytes_read
;
5496 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5497 if (indexval_it
== m_map
.abbrev_map
.cend ())
5499 complaint (_("Wrong .debug_names undefined abbrev code %s "
5501 pulongest (abbrev
), objfile_name (objfile
));
5504 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5505 enum class symbol_linkage
{
5509 } symbol_linkage_
= symbol_linkage::unknown
;
5510 dwarf2_per_cu_data
*per_cu
= NULL
;
5511 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5516 case DW_FORM_implicit_const
:
5517 ull
= attr
.implicit_const
;
5519 case DW_FORM_flag_present
:
5523 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5524 m_addr
+= bytes_read
;
5527 ull
= read_4_bytes (abfd
, m_addr
);
5531 ull
= read_8_bytes (abfd
, m_addr
);
5534 case DW_FORM_ref_sig8
:
5535 ull
= read_8_bytes (abfd
, m_addr
);
5539 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5540 dwarf_form_name (attr
.form
),
5541 objfile_name (objfile
));
5544 switch (attr
.dw_idx
)
5546 case DW_IDX_compile_unit
:
5547 /* Don't crash on bad data. */
5548 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5550 complaint (_(".debug_names entry has bad CU index %s"
5553 objfile_name (objfile
));
5556 per_cu
= per_bfd
->get_cutu (ull
);
5558 case DW_IDX_type_unit
:
5559 /* Don't crash on bad data. */
5560 if (ull
>= per_bfd
->all_type_units
.size ())
5562 complaint (_(".debug_names entry has bad TU index %s"
5565 objfile_name (objfile
));
5568 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5570 case DW_IDX_die_offset
:
5571 /* In a per-CU index (as opposed to a per-module index), index
5572 entries without CU attribute implicitly refer to the single CU. */
5574 per_cu
= per_bfd
->get_cu (0);
5576 case DW_IDX_GNU_internal
:
5577 if (!m_map
.augmentation_is_gdb
)
5579 symbol_linkage_
= symbol_linkage::static_
;
5581 case DW_IDX_GNU_external
:
5582 if (!m_map
.augmentation_is_gdb
)
5584 symbol_linkage_
= symbol_linkage::extern_
;
5589 /* Skip if already read in. */
5590 if (m_per_objfile
->symtab_set_p (per_cu
))
5593 /* Check static vs global. */
5594 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5596 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5597 const bool symbol_is_static
=
5598 symbol_linkage_
== symbol_linkage::static_
;
5599 if (want_static
!= symbol_is_static
)
5603 /* Match dw2_symtab_iter_next, symbol_kind
5604 and debug_names::psymbol_tag. */
5608 switch (indexval
.dwarf_tag
)
5610 case DW_TAG_variable
:
5611 case DW_TAG_subprogram
:
5612 /* Some types are also in VAR_DOMAIN. */
5613 case DW_TAG_typedef
:
5614 case DW_TAG_structure_type
:
5621 switch (indexval
.dwarf_tag
)
5623 case DW_TAG_typedef
:
5624 case DW_TAG_structure_type
:
5631 switch (indexval
.dwarf_tag
)
5634 case DW_TAG_variable
:
5641 switch (indexval
.dwarf_tag
)
5653 /* Match dw2_expand_symtabs_matching, symbol_kind and
5654 debug_names::psymbol_tag. */
5657 case VARIABLES_DOMAIN
:
5658 switch (indexval
.dwarf_tag
)
5660 case DW_TAG_variable
:
5666 case FUNCTIONS_DOMAIN
:
5667 switch (indexval
.dwarf_tag
)
5669 case DW_TAG_subprogram
:
5676 switch (indexval
.dwarf_tag
)
5678 case DW_TAG_typedef
:
5679 case DW_TAG_structure_type
:
5685 case MODULES_DOMAIN
:
5686 switch (indexval
.dwarf_tag
)
5700 static struct compunit_symtab
*
5701 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5702 const char *name
, domain_enum domain
)
5704 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5706 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5709 /* index is NULL if OBJF_READNOW. */
5712 const auto &map
= *mapp
;
5714 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5716 struct compunit_symtab
*stab_best
= NULL
;
5717 struct dwarf2_per_cu_data
*per_cu
;
5718 while ((per_cu
= iter
.next ()) != NULL
)
5720 struct symbol
*sym
, *with_opaque
= NULL
;
5721 compunit_symtab
*stab
5722 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5723 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5724 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5726 sym
= block_find_symbol (block
, name
, domain
,
5727 block_find_non_opaque_type_preferred
,
5730 /* Some caution must be observed with overloaded functions and
5731 methods, since the index will not contain any overload
5732 information (but NAME might contain it). */
5735 && strcmp_iw (sym
->search_name (), name
) == 0)
5737 if (with_opaque
!= NULL
5738 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5741 /* Keep looking through other CUs. */
5747 /* This dumps minimal information about .debug_names. It is called
5748 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5749 uses this to verify that .debug_names has been loaded. */
5752 dw2_debug_names_dump (struct objfile
*objfile
)
5754 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5756 gdb_assert (per_objfile
->per_bfd
->using_index
);
5757 printf_filtered (".debug_names:");
5758 if (per_objfile
->per_bfd
->debug_names_table
)
5759 printf_filtered (" exists\n");
5761 printf_filtered (" faked for \"readnow\"\n");
5762 printf_filtered ("\n");
5766 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5767 const char *func_name
)
5769 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5771 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5772 if (per_objfile
->per_bfd
->debug_names_table
)
5774 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5776 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5779 struct dwarf2_per_cu_data
*per_cu
;
5780 while ((per_cu
= iter
.next ()) != NULL
)
5781 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5786 dw2_debug_names_map_matching_symbols
5787 (struct objfile
*objfile
,
5788 const lookup_name_info
&name
, domain_enum domain
,
5790 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5791 symbol_compare_ftype
*ordered_compare
)
5793 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5795 /* debug_names_table is NULL if OBJF_READNOW. */
5796 if (!per_objfile
->per_bfd
->debug_names_table
)
5799 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5800 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5802 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5803 auto matcher
= [&] (const char *symname
)
5805 if (ordered_compare
== nullptr)
5807 return ordered_compare (symname
, match_name
) == 0;
5810 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5811 [&] (offset_type namei
)
5813 /* The name was matched, now expand corresponding CUs that were
5815 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5818 struct dwarf2_per_cu_data
*per_cu
;
5819 while ((per_cu
= iter
.next ()) != NULL
)
5820 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5825 /* It's a shame we couldn't do this inside the
5826 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5827 that have already been expanded. Instead, this loop matches what
5828 the psymtab code does. */
5829 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5831 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5832 if (symtab
!= nullptr)
5834 const struct block
*block
5835 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5836 if (!iterate_over_symbols_terminated (block
, name
,
5844 dw2_debug_names_expand_symtabs_matching
5845 (struct objfile
*objfile
,
5846 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5847 const lookup_name_info
*lookup_name
,
5848 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5849 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5850 enum search_domain kind
)
5852 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5854 /* debug_names_table is NULL if OBJF_READNOW. */
5855 if (!per_objfile
->per_bfd
->debug_names_table
)
5858 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5860 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5862 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5866 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5872 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5874 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5876 kind
, [&] (offset_type namei
)
5878 /* The name was matched, now expand corresponding CUs that were
5880 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5882 struct dwarf2_per_cu_data
*per_cu
;
5883 while ((per_cu
= iter
.next ()) != NULL
)
5884 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5890 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5893 dw2_find_last_source_symtab
,
5894 dw2_forget_cached_source_info
,
5895 dw2_map_symtabs_matching_filename
,
5896 dw2_debug_names_lookup_symbol
,
5899 dw2_debug_names_dump
,
5900 dw2_debug_names_expand_symtabs_for_function
,
5901 dw2_expand_all_symtabs
,
5902 dw2_expand_symtabs_with_fullname
,
5903 dw2_debug_names_map_matching_symbols
,
5904 dw2_debug_names_expand_symtabs_matching
,
5905 dw2_find_pc_sect_compunit_symtab
,
5907 dw2_map_symbol_filenames
5910 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5911 to either a dwarf2_per_bfd or dwz_file object. */
5913 template <typename T
>
5914 static gdb::array_view
<const gdb_byte
>
5915 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5917 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5919 if (section
->empty ())
5922 /* Older elfutils strip versions could keep the section in the main
5923 executable while splitting it for the separate debug info file. */
5924 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5927 section
->read (obj
);
5929 /* dwarf2_section_info::size is a bfd_size_type, while
5930 gdb::array_view works with size_t. On 32-bit hosts, with
5931 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5932 is 32-bit. So we need an explicit narrowing conversion here.
5933 This is fine, because it's impossible to allocate or mmap an
5934 array/buffer larger than what size_t can represent. */
5935 return gdb::make_array_view (section
->buffer
, section
->size
);
5938 /* Lookup the index cache for the contents of the index associated to
5941 static gdb::array_view
<const gdb_byte
>
5942 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5944 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5945 if (build_id
== nullptr)
5948 return global_index_cache
.lookup_gdb_index (build_id
,
5949 &dwarf2_per_bfd
->index_cache_res
);
5952 /* Same as the above, but for DWZ. */
5954 static gdb::array_view
<const gdb_byte
>
5955 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5957 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5958 if (build_id
== nullptr)
5961 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5964 /* See symfile.h. */
5967 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5969 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5970 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5972 /* If we're about to read full symbols, don't bother with the
5973 indices. In this case we also don't care if some other debug
5974 format is making psymtabs, because they are all about to be
5976 if ((objfile
->flags
& OBJF_READNOW
))
5978 /* When using READNOW, the using_index flag (set below) indicates that
5979 PER_BFD was already initialized, when we loaded some other objfile. */
5980 if (per_bfd
->using_index
)
5982 *index_kind
= dw_index_kind::GDB_INDEX
;
5983 per_objfile
->resize_symtabs ();
5987 per_bfd
->using_index
= 1;
5988 create_all_comp_units (per_objfile
);
5989 create_all_type_units (per_objfile
);
5990 per_bfd
->quick_file_names_table
5991 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5992 per_objfile
->resize_symtabs ();
5994 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5995 + per_bfd
->all_type_units
.size ()); ++i
)
5997 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5999 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6000 struct dwarf2_per_cu_quick_data
);
6003 /* Return 1 so that gdb sees the "quick" functions. However,
6004 these functions will be no-ops because we will have expanded
6006 *index_kind
= dw_index_kind::GDB_INDEX
;
6010 /* Was a debug names index already read when we processed an objfile sharing
6012 if (per_bfd
->debug_names_table
!= nullptr)
6014 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6015 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6016 per_objfile
->resize_symtabs ();
6020 /* Was a GDB index already read when we processed an objfile sharing
6022 if (per_bfd
->index_table
!= nullptr)
6024 *index_kind
= dw_index_kind::GDB_INDEX
;
6025 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6026 per_objfile
->resize_symtabs ();
6030 /* There might already be partial symtabs built for this BFD. This happens
6031 when loading the same binary twice with the index-cache enabled. If so,
6032 don't try to read an index. The objfile / per_objfile initialization will
6033 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6035 if (per_bfd
->partial_symtabs
!= nullptr)
6038 if (dwarf2_read_debug_names (per_objfile
))
6040 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6041 per_objfile
->resize_symtabs ();
6045 if (dwarf2_read_gdb_index (per_objfile
,
6046 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6047 get_gdb_index_contents_from_section
<dwz_file
>))
6049 *index_kind
= dw_index_kind::GDB_INDEX
;
6050 per_objfile
->resize_symtabs ();
6054 /* ... otherwise, try to find the index in the index cache. */
6055 if (dwarf2_read_gdb_index (per_objfile
,
6056 get_gdb_index_contents_from_cache
,
6057 get_gdb_index_contents_from_cache_dwz
))
6059 global_index_cache
.hit ();
6060 *index_kind
= dw_index_kind::GDB_INDEX
;
6061 per_objfile
->resize_symtabs ();
6065 global_index_cache
.miss ();
6071 /* Build a partial symbol table. */
6074 dwarf2_build_psymtabs (struct objfile
*objfile
)
6076 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6077 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6079 if (per_bfd
->partial_symtabs
!= nullptr)
6081 /* Partial symbols were already read, so now we can simply
6083 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6084 per_objfile
->resize_symtabs ();
6088 init_psymbol_list (objfile
, 1024);
6092 /* This isn't really ideal: all the data we allocate on the
6093 objfile's obstack is still uselessly kept around. However,
6094 freeing it seems unsafe. */
6095 psymtab_discarder
psymtabs (objfile
);
6096 dwarf2_build_psymtabs_hard (per_objfile
);
6099 per_objfile
->resize_symtabs ();
6101 /* (maybe) store an index in the cache. */
6102 global_index_cache
.store (per_objfile
);
6104 catch (const gdb_exception_error
&except
)
6106 exception_print (gdb_stderr
, except
);
6109 /* Finish by setting the local reference to partial symtabs, so that
6110 we don't try to read them again if reading another objfile with the same
6111 BFD. If we can't in fact share, this won't make a difference anyway as
6112 the dwarf2_per_bfd object won't be shared. */
6113 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6116 /* Find the base address of the compilation unit for range lists and
6117 location lists. It will normally be specified by DW_AT_low_pc.
6118 In DWARF-3 draft 4, the base address could be overridden by
6119 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6120 compilation units with discontinuous ranges. */
6123 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6125 struct attribute
*attr
;
6127 cu
->base_address
.reset ();
6129 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6130 if (attr
!= nullptr)
6131 cu
->base_address
= attr
->value_as_address ();
6134 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6135 if (attr
!= nullptr)
6136 cu
->base_address
= attr
->value_as_address ();
6140 /* Helper function that returns the proper abbrev section for
6143 static struct dwarf2_section_info
*
6144 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6146 struct dwarf2_section_info
*abbrev
;
6147 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6149 if (this_cu
->is_dwz
)
6150 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6152 abbrev
= &per_bfd
->abbrev
;
6157 /* Fetch the abbreviation table offset from a comp or type unit header. */
6160 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6161 struct dwarf2_section_info
*section
,
6162 sect_offset sect_off
)
6164 bfd
*abfd
= section
->get_bfd_owner ();
6165 const gdb_byte
*info_ptr
;
6166 unsigned int initial_length_size
, offset_size
;
6169 section
->read (per_objfile
->objfile
);
6170 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6171 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6172 offset_size
= initial_length_size
== 4 ? 4 : 8;
6173 info_ptr
+= initial_length_size
;
6175 version
= read_2_bytes (abfd
, info_ptr
);
6179 /* Skip unit type and address size. */
6183 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6186 /* A partial symtab that is used only for include files. */
6187 struct dwarf2_include_psymtab
: public partial_symtab
6189 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6190 : partial_symtab (filename
, objfile
)
6194 void read_symtab (struct objfile
*objfile
) override
6196 /* It's an include file, no symbols to read for it.
6197 Everything is in the includer symtab. */
6199 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6200 expansion of the includer psymtab. We use the dependencies[0] field to
6201 model the includer. But if we go the regular route of calling
6202 expand_psymtab here, and having expand_psymtab call expand_dependencies
6203 to expand the includer, we'll only use expand_psymtab on the includer
6204 (making it a non-toplevel psymtab), while if we expand the includer via
6205 another path, we'll use read_symtab (making it a toplevel psymtab).
6206 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6207 psymtab, and trigger read_symtab on the includer here directly. */
6208 includer ()->read_symtab (objfile
);
6211 void expand_psymtab (struct objfile
*objfile
) override
6213 /* This is not called by read_symtab, and should not be called by any
6214 expand_dependencies. */
6218 bool readin_p (struct objfile
*objfile
) const override
6220 return includer ()->readin_p (objfile
);
6223 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6229 partial_symtab
*includer () const
6231 /* An include psymtab has exactly one dependency: the psymtab that
6233 gdb_assert (this->number_of_dependencies
== 1);
6234 return this->dependencies
[0];
6238 /* Allocate a new partial symtab for file named NAME and mark this new
6239 partial symtab as being an include of PST. */
6242 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6243 struct objfile
*objfile
)
6245 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6247 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6248 subpst
->dirname
= pst
->dirname
;
6250 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6251 subpst
->dependencies
[0] = pst
;
6252 subpst
->number_of_dependencies
= 1;
6255 /* Read the Line Number Program data and extract the list of files
6256 included by the source file represented by PST. Build an include
6257 partial symtab for each of these included files. */
6260 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6261 struct die_info
*die
,
6262 dwarf2_psymtab
*pst
)
6265 struct attribute
*attr
;
6267 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6268 if (attr
!= nullptr)
6269 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6271 return; /* No linetable, so no includes. */
6273 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6274 that we pass in the raw text_low here; that is ok because we're
6275 only decoding the line table to make include partial symtabs, and
6276 so the addresses aren't really used. */
6277 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6278 pst
->raw_text_low (), 1);
6282 hash_signatured_type (const void *item
)
6284 const struct signatured_type
*sig_type
6285 = (const struct signatured_type
*) item
;
6287 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6288 return sig_type
->signature
;
6292 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6294 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6295 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6297 return lhs
->signature
== rhs
->signature
;
6300 /* Allocate a hash table for signatured types. */
6303 allocate_signatured_type_table ()
6305 return htab_up (htab_create_alloc (41,
6306 hash_signatured_type
,
6308 NULL
, xcalloc
, xfree
));
6311 /* A helper function to add a signatured type CU to a table. */
6314 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6316 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6317 std::vector
<signatured_type
*> *all_type_units
6318 = (std::vector
<signatured_type
*> *) datum
;
6320 all_type_units
->push_back (sigt
);
6325 /* A helper for create_debug_types_hash_table. Read types from SECTION
6326 and fill them into TYPES_HTAB. It will process only type units,
6327 therefore DW_UT_type. */
6330 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6331 struct dwo_file
*dwo_file
,
6332 dwarf2_section_info
*section
, htab_up
&types_htab
,
6333 rcuh_kind section_kind
)
6335 struct objfile
*objfile
= per_objfile
->objfile
;
6336 struct dwarf2_section_info
*abbrev_section
;
6338 const gdb_byte
*info_ptr
, *end_ptr
;
6340 abbrev_section
= (dwo_file
!= NULL
6341 ? &dwo_file
->sections
.abbrev
6342 : &per_objfile
->per_bfd
->abbrev
);
6344 if (dwarf_read_debug
)
6345 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6346 section
->get_name (),
6347 abbrev_section
->get_file_name ());
6349 section
->read (objfile
);
6350 info_ptr
= section
->buffer
;
6352 if (info_ptr
== NULL
)
6355 /* We can't set abfd until now because the section may be empty or
6356 not present, in which case the bfd is unknown. */
6357 abfd
= section
->get_bfd_owner ();
6359 /* We don't use cutu_reader here because we don't need to read
6360 any dies: the signature is in the header. */
6362 end_ptr
= info_ptr
+ section
->size
;
6363 while (info_ptr
< end_ptr
)
6365 struct signatured_type
*sig_type
;
6366 struct dwo_unit
*dwo_tu
;
6368 const gdb_byte
*ptr
= info_ptr
;
6369 struct comp_unit_head header
;
6370 unsigned int length
;
6372 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6374 /* Initialize it due to a false compiler warning. */
6375 header
.signature
= -1;
6376 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6378 /* We need to read the type's signature in order to build the hash
6379 table, but we don't need anything else just yet. */
6381 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6382 abbrev_section
, ptr
, section_kind
);
6384 length
= header
.get_length ();
6386 /* Skip dummy type units. */
6387 if (ptr
>= info_ptr
+ length
6388 || peek_abbrev_code (abfd
, ptr
) == 0
6389 || header
.unit_type
!= DW_UT_type
)
6395 if (types_htab
== NULL
)
6398 types_htab
= allocate_dwo_unit_table ();
6400 types_htab
= allocate_signatured_type_table ();
6406 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6407 dwo_tu
->dwo_file
= dwo_file
;
6408 dwo_tu
->signature
= header
.signature
;
6409 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6410 dwo_tu
->section
= section
;
6411 dwo_tu
->sect_off
= sect_off
;
6412 dwo_tu
->length
= length
;
6416 /* N.B.: type_offset is not usable if this type uses a DWO file.
6417 The real type_offset is in the DWO file. */
6419 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6420 sig_type
->signature
= header
.signature
;
6421 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6422 sig_type
->per_cu
.is_debug_types
= 1;
6423 sig_type
->per_cu
.section
= section
;
6424 sig_type
->per_cu
.sect_off
= sect_off
;
6425 sig_type
->per_cu
.length
= length
;
6428 slot
= htab_find_slot (types_htab
.get (),
6429 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6431 gdb_assert (slot
!= NULL
);
6434 sect_offset dup_sect_off
;
6438 const struct dwo_unit
*dup_tu
6439 = (const struct dwo_unit
*) *slot
;
6441 dup_sect_off
= dup_tu
->sect_off
;
6445 const struct signatured_type
*dup_tu
6446 = (const struct signatured_type
*) *slot
;
6448 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6451 complaint (_("debug type entry at offset %s is duplicate to"
6452 " the entry at offset %s, signature %s"),
6453 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6454 hex_string (header
.signature
));
6456 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6458 if (dwarf_read_debug
> 1)
6459 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6460 sect_offset_str (sect_off
),
6461 hex_string (header
.signature
));
6467 /* Create the hash table of all entries in the .debug_types
6468 (or .debug_types.dwo) section(s).
6469 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6470 otherwise it is NULL.
6472 The result is a pointer to the hash table or NULL if there are no types.
6474 Note: This function processes DWO files only, not DWP files. */
6477 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6478 struct dwo_file
*dwo_file
,
6479 gdb::array_view
<dwarf2_section_info
> type_sections
,
6480 htab_up
&types_htab
)
6482 for (dwarf2_section_info
§ion
: type_sections
)
6483 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6487 /* Create the hash table of all entries in the .debug_types section,
6488 and initialize all_type_units.
6489 The result is zero if there is an error (e.g. missing .debug_types section),
6490 otherwise non-zero. */
6493 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6497 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6498 types_htab
, rcuh_kind::COMPILE
);
6499 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6501 if (types_htab
== NULL
)
6503 per_objfile
->per_bfd
->signatured_types
= NULL
;
6507 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6509 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6510 per_objfile
->per_bfd
->all_type_units
.reserve
6511 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6513 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6514 add_signatured_type_cu_to_table
,
6515 &per_objfile
->per_bfd
->all_type_units
);
6520 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6521 If SLOT is non-NULL, it is the entry to use in the hash table.
6522 Otherwise we find one. */
6524 static struct signatured_type
*
6525 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6527 if (per_objfile
->per_bfd
->all_type_units
.size ()
6528 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6529 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6531 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6533 per_objfile
->resize_symtabs ();
6535 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6536 sig_type
->signature
= sig
;
6537 sig_type
->per_cu
.is_debug_types
= 1;
6538 if (per_objfile
->per_bfd
->using_index
)
6540 sig_type
->per_cu
.v
.quick
=
6541 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6542 struct dwarf2_per_cu_quick_data
);
6547 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6550 gdb_assert (*slot
== NULL
);
6552 /* The rest of sig_type must be filled in by the caller. */
6556 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6557 Fill in SIG_ENTRY with DWO_ENTRY. */
6560 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6561 struct signatured_type
*sig_entry
,
6562 struct dwo_unit
*dwo_entry
)
6564 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6566 /* Make sure we're not clobbering something we don't expect to. */
6567 gdb_assert (! sig_entry
->per_cu
.queued
);
6568 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6569 if (per_bfd
->using_index
)
6571 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6572 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6575 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6576 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6577 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6578 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6579 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6581 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6582 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6583 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6584 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6585 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6586 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6587 sig_entry
->dwo_unit
= dwo_entry
;
6590 /* Subroutine of lookup_signatured_type.
6591 If we haven't read the TU yet, create the signatured_type data structure
6592 for a TU to be read in directly from a DWO file, bypassing the stub.
6593 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6594 using .gdb_index, then when reading a CU we want to stay in the DWO file
6595 containing that CU. Otherwise we could end up reading several other DWO
6596 files (due to comdat folding) to process the transitive closure of all the
6597 mentioned TUs, and that can be slow. The current DWO file will have every
6598 type signature that it needs.
6599 We only do this for .gdb_index because in the psymtab case we already have
6600 to read all the DWOs to build the type unit groups. */
6602 static struct signatured_type
*
6603 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6605 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6606 struct dwo_file
*dwo_file
;
6607 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6608 struct signatured_type find_sig_entry
, *sig_entry
;
6611 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6613 /* If TU skeletons have been removed then we may not have read in any
6615 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6616 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6618 /* We only ever need to read in one copy of a signatured type.
6619 Use the global signatured_types array to do our own comdat-folding
6620 of types. If this is the first time we're reading this TU, and
6621 the TU has an entry in .gdb_index, replace the recorded data from
6622 .gdb_index with this TU. */
6624 find_sig_entry
.signature
= sig
;
6625 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6626 &find_sig_entry
, INSERT
);
6627 sig_entry
= (struct signatured_type
*) *slot
;
6629 /* We can get here with the TU already read, *or* in the process of being
6630 read. Don't reassign the global entry to point to this DWO if that's
6631 the case. Also note that if the TU is already being read, it may not
6632 have come from a DWO, the program may be a mix of Fission-compiled
6633 code and non-Fission-compiled code. */
6635 /* Have we already tried to read this TU?
6636 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6637 needn't exist in the global table yet). */
6638 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6641 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6642 dwo_unit of the TU itself. */
6643 dwo_file
= cu
->dwo_unit
->dwo_file
;
6645 /* Ok, this is the first time we're reading this TU. */
6646 if (dwo_file
->tus
== NULL
)
6648 find_dwo_entry
.signature
= sig
;
6649 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6651 if (dwo_entry
== NULL
)
6654 /* If the global table doesn't have an entry for this TU, add one. */
6655 if (sig_entry
== NULL
)
6656 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6658 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6659 sig_entry
->per_cu
.tu_read
= 1;
6663 /* Subroutine of lookup_signatured_type.
6664 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6665 then try the DWP file. If the TU stub (skeleton) has been removed then
6666 it won't be in .gdb_index. */
6668 static struct signatured_type
*
6669 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6671 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6672 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6673 struct dwo_unit
*dwo_entry
;
6674 struct signatured_type find_sig_entry
, *sig_entry
;
6677 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6678 gdb_assert (dwp_file
!= NULL
);
6680 /* If TU skeletons have been removed then we may not have read in any
6682 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6683 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6685 find_sig_entry
.signature
= sig
;
6686 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6687 &find_sig_entry
, INSERT
);
6688 sig_entry
= (struct signatured_type
*) *slot
;
6690 /* Have we already tried to read this TU?
6691 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6692 needn't exist in the global table yet). */
6693 if (sig_entry
!= NULL
)
6696 if (dwp_file
->tus
== NULL
)
6698 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6699 1 /* is_debug_types */);
6700 if (dwo_entry
== NULL
)
6703 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6704 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6709 /* Lookup a signature based type for DW_FORM_ref_sig8.
6710 Returns NULL if signature SIG is not present in the table.
6711 It is up to the caller to complain about this. */
6713 static struct signatured_type
*
6714 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6716 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6718 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6720 /* We're in a DWO/DWP file, and we're using .gdb_index.
6721 These cases require special processing. */
6722 if (get_dwp_file (per_objfile
) == NULL
)
6723 return lookup_dwo_signatured_type (cu
, sig
);
6725 return lookup_dwp_signatured_type (cu
, sig
);
6729 struct signatured_type find_entry
, *entry
;
6731 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6733 find_entry
.signature
= sig
;
6734 entry
= ((struct signatured_type
*)
6735 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6741 /* Low level DIE reading support. */
6743 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6746 init_cu_die_reader (struct die_reader_specs
*reader
,
6747 struct dwarf2_cu
*cu
,
6748 struct dwarf2_section_info
*section
,
6749 struct dwo_file
*dwo_file
,
6750 struct abbrev_table
*abbrev_table
)
6752 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6753 reader
->abfd
= section
->get_bfd_owner ();
6755 reader
->dwo_file
= dwo_file
;
6756 reader
->die_section
= section
;
6757 reader
->buffer
= section
->buffer
;
6758 reader
->buffer_end
= section
->buffer
+ section
->size
;
6759 reader
->abbrev_table
= abbrev_table
;
6762 /* Subroutine of cutu_reader to simplify it.
6763 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6764 There's just a lot of work to do, and cutu_reader is big enough
6767 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6768 from it to the DIE in the DWO. If NULL we are skipping the stub.
6769 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6770 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6771 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6772 STUB_COMP_DIR may be non-NULL.
6773 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6774 are filled in with the info of the DIE from the DWO file.
6775 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6776 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6777 kept around for at least as long as *RESULT_READER.
6779 The result is non-zero if a valid (non-dummy) DIE was found. */
6782 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6783 struct dwo_unit
*dwo_unit
,
6784 struct die_info
*stub_comp_unit_die
,
6785 const char *stub_comp_dir
,
6786 struct die_reader_specs
*result_reader
,
6787 const gdb_byte
**result_info_ptr
,
6788 struct die_info
**result_comp_unit_die
,
6789 abbrev_table_up
*result_dwo_abbrev_table
)
6791 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6792 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6793 struct objfile
*objfile
= per_objfile
->objfile
;
6795 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6796 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6797 int i
,num_extra_attrs
;
6798 struct dwarf2_section_info
*dwo_abbrev_section
;
6799 struct die_info
*comp_unit_die
;
6801 /* At most one of these may be provided. */
6802 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6804 /* These attributes aren't processed until later:
6805 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6806 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6807 referenced later. However, these attributes are found in the stub
6808 which we won't have later. In order to not impose this complication
6809 on the rest of the code, we read them here and copy them to the
6818 if (stub_comp_unit_die
!= NULL
)
6820 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6822 if (!per_cu
->is_debug_types
)
6823 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6824 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6825 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6826 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6827 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6829 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6831 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6832 here (if needed). We need the value before we can process
6834 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6836 else if (stub_comp_dir
!= NULL
)
6838 /* Reconstruct the comp_dir attribute to simplify the code below. */
6839 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6840 comp_dir
->name
= DW_AT_comp_dir
;
6841 comp_dir
->form
= DW_FORM_string
;
6842 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6843 DW_STRING (comp_dir
) = stub_comp_dir
;
6846 /* Set up for reading the DWO CU/TU. */
6847 cu
->dwo_unit
= dwo_unit
;
6848 dwarf2_section_info
*section
= dwo_unit
->section
;
6849 section
->read (objfile
);
6850 abfd
= section
->get_bfd_owner ();
6851 begin_info_ptr
= info_ptr
= (section
->buffer
6852 + to_underlying (dwo_unit
->sect_off
));
6853 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6855 if (per_cu
->is_debug_types
)
6857 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6859 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6860 section
, dwo_abbrev_section
,
6861 info_ptr
, rcuh_kind::TYPE
);
6862 /* This is not an assert because it can be caused by bad debug info. */
6863 if (sig_type
->signature
!= cu
->header
.signature
)
6865 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6866 " TU at offset %s [in module %s]"),
6867 hex_string (sig_type
->signature
),
6868 hex_string (cu
->header
.signature
),
6869 sect_offset_str (dwo_unit
->sect_off
),
6870 bfd_get_filename (abfd
));
6872 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6873 /* For DWOs coming from DWP files, we don't know the CU length
6874 nor the type's offset in the TU until now. */
6875 dwo_unit
->length
= cu
->header
.get_length ();
6876 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6878 /* Establish the type offset that can be used to lookup the type.
6879 For DWO files, we don't know it until now. */
6880 sig_type
->type_offset_in_section
6881 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6885 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6886 section
, dwo_abbrev_section
,
6887 info_ptr
, rcuh_kind::COMPILE
);
6888 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6889 /* For DWOs coming from DWP files, we don't know the CU length
6891 dwo_unit
->length
= cu
->header
.get_length ();
6894 *result_dwo_abbrev_table
6895 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6896 cu
->header
.abbrev_sect_off
);
6897 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6898 result_dwo_abbrev_table
->get ());
6900 /* Read in the die, but leave space to copy over the attributes
6901 from the stub. This has the benefit of simplifying the rest of
6902 the code - all the work to maintain the illusion of a single
6903 DW_TAG_{compile,type}_unit DIE is done here. */
6904 num_extra_attrs
= ((stmt_list
!= NULL
)
6908 + (comp_dir
!= NULL
));
6909 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6912 /* Copy over the attributes from the stub to the DIE we just read in. */
6913 comp_unit_die
= *result_comp_unit_die
;
6914 i
= comp_unit_die
->num_attrs
;
6915 if (stmt_list
!= NULL
)
6916 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6918 comp_unit_die
->attrs
[i
++] = *low_pc
;
6919 if (high_pc
!= NULL
)
6920 comp_unit_die
->attrs
[i
++] = *high_pc
;
6922 comp_unit_die
->attrs
[i
++] = *ranges
;
6923 if (comp_dir
!= NULL
)
6924 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6925 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6927 if (dwarf_die_debug
)
6929 fprintf_unfiltered (gdb_stdlog
,
6930 "Read die from %s@0x%x of %s:\n",
6931 section
->get_name (),
6932 (unsigned) (begin_info_ptr
- section
->buffer
),
6933 bfd_get_filename (abfd
));
6934 dump_die (comp_unit_die
, dwarf_die_debug
);
6937 /* Skip dummy compilation units. */
6938 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6939 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6942 *result_info_ptr
= info_ptr
;
6946 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6947 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6948 signature is part of the header. */
6949 static gdb::optional
<ULONGEST
>
6950 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6952 if (cu
->header
.version
>= 5)
6953 return cu
->header
.signature
;
6954 struct attribute
*attr
;
6955 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6956 if (attr
== nullptr)
6957 return gdb::optional
<ULONGEST
> ();
6958 return DW_UNSND (attr
);
6961 /* Subroutine of cutu_reader to simplify it.
6962 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6963 Returns NULL if the specified DWO unit cannot be found. */
6965 static struct dwo_unit
*
6966 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6968 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6969 struct dwo_unit
*dwo_unit
;
6970 const char *comp_dir
;
6972 gdb_assert (cu
!= NULL
);
6974 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6975 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6976 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6978 if (per_cu
->is_debug_types
)
6979 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6982 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6984 if (!signature
.has_value ())
6985 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6987 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6989 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6995 /* Subroutine of cutu_reader to simplify it.
6996 See it for a description of the parameters.
6997 Read a TU directly from a DWO file, bypassing the stub. */
7000 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7001 dwarf2_per_objfile
*per_objfile
,
7002 dwarf2_cu
*existing_cu
)
7004 struct signatured_type
*sig_type
;
7006 /* Verify we can do the following downcast, and that we have the
7008 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7009 sig_type
= (struct signatured_type
*) this_cu
;
7010 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7014 if (existing_cu
!= nullptr)
7017 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7018 /* There's no need to do the rereading_dwo_cu handling that
7019 cutu_reader does since we don't read the stub. */
7023 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7024 in per_objfile yet. */
7025 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7026 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7027 cu
= m_new_cu
.get ();
7030 /* A future optimization, if needed, would be to use an existing
7031 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7032 could share abbrev tables. */
7034 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7035 NULL
/* stub_comp_unit_die */,
7036 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7039 &m_dwo_abbrev_table
) == 0)
7046 /* Initialize a CU (or TU) and read its DIEs.
7047 If the CU defers to a DWO file, read the DWO file as well.
7049 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7050 Otherwise the table specified in the comp unit header is read in and used.
7051 This is an optimization for when we already have the abbrev table.
7053 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7056 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7057 dwarf2_per_objfile
*per_objfile
,
7058 struct abbrev_table
*abbrev_table
,
7059 dwarf2_cu
*existing_cu
,
7061 : die_reader_specs
{},
7064 struct objfile
*objfile
= per_objfile
->objfile
;
7065 struct dwarf2_section_info
*section
= this_cu
->section
;
7066 bfd
*abfd
= section
->get_bfd_owner ();
7067 const gdb_byte
*begin_info_ptr
;
7068 struct signatured_type
*sig_type
= NULL
;
7069 struct dwarf2_section_info
*abbrev_section
;
7070 /* Non-zero if CU currently points to a DWO file and we need to
7071 reread it. When this happens we need to reread the skeleton die
7072 before we can reread the DWO file (this only applies to CUs, not TUs). */
7073 int rereading_dwo_cu
= 0;
7075 if (dwarf_die_debug
)
7076 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7077 this_cu
->is_debug_types
? "type" : "comp",
7078 sect_offset_str (this_cu
->sect_off
));
7080 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7081 file (instead of going through the stub), short-circuit all of this. */
7082 if (this_cu
->reading_dwo_directly
)
7084 /* Narrow down the scope of possibilities to have to understand. */
7085 gdb_assert (this_cu
->is_debug_types
);
7086 gdb_assert (abbrev_table
== NULL
);
7087 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7091 /* This is cheap if the section is already read in. */
7092 section
->read (objfile
);
7094 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7096 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7100 if (existing_cu
!= nullptr)
7103 /* If this CU is from a DWO file we need to start over, we need to
7104 refetch the attributes from the skeleton CU.
7105 This could be optimized by retrieving those attributes from when we
7106 were here the first time: the previous comp_unit_die was stored in
7107 comp_unit_obstack. But there's no data yet that we need this
7109 if (cu
->dwo_unit
!= NULL
)
7110 rereading_dwo_cu
= 1;
7114 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7115 in per_objfile yet. */
7116 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7117 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7118 cu
= m_new_cu
.get ();
7121 /* Get the header. */
7122 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7124 /* We already have the header, there's no need to read it in again. */
7125 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7129 if (this_cu
->is_debug_types
)
7131 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7132 section
, abbrev_section
,
7133 info_ptr
, rcuh_kind::TYPE
);
7135 /* Since per_cu is the first member of struct signatured_type,
7136 we can go from a pointer to one to a pointer to the other. */
7137 sig_type
= (struct signatured_type
*) this_cu
;
7138 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7139 gdb_assert (sig_type
->type_offset_in_tu
7140 == cu
->header
.type_cu_offset_in_tu
);
7141 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7143 /* LENGTH has not been set yet for type units if we're
7144 using .gdb_index. */
7145 this_cu
->length
= cu
->header
.get_length ();
7147 /* Establish the type offset that can be used to lookup the type. */
7148 sig_type
->type_offset_in_section
=
7149 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7151 this_cu
->dwarf_version
= cu
->header
.version
;
7155 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7156 section
, abbrev_section
,
7158 rcuh_kind::COMPILE
);
7160 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7161 if (this_cu
->length
== 0)
7162 this_cu
->length
= cu
->header
.get_length ();
7164 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7165 this_cu
->dwarf_version
= cu
->header
.version
;
7169 /* Skip dummy compilation units. */
7170 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7171 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7177 /* If we don't have them yet, read the abbrevs for this compilation unit.
7178 And if we need to read them now, make sure they're freed when we're
7180 if (abbrev_table
!= NULL
)
7181 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7184 m_abbrev_table_holder
7185 = abbrev_table::read (objfile
, abbrev_section
,
7186 cu
->header
.abbrev_sect_off
);
7187 abbrev_table
= m_abbrev_table_holder
.get ();
7190 /* Read the top level CU/TU die. */
7191 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7192 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7194 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7200 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7201 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7202 table from the DWO file and pass the ownership over to us. It will be
7203 referenced from READER, so we must make sure to free it after we're done
7206 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7207 DWO CU, that this test will fail (the attribute will not be present). */
7208 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7209 if (dwo_name
!= nullptr)
7211 struct dwo_unit
*dwo_unit
;
7212 struct die_info
*dwo_comp_unit_die
;
7214 if (comp_unit_die
->has_children
)
7216 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7217 " has children (offset %s) [in module %s]"),
7218 sect_offset_str (this_cu
->sect_off
),
7219 bfd_get_filename (abfd
));
7221 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7222 if (dwo_unit
!= NULL
)
7224 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7225 comp_unit_die
, NULL
,
7228 &m_dwo_abbrev_table
) == 0)
7234 comp_unit_die
= dwo_comp_unit_die
;
7238 /* Yikes, we couldn't find the rest of the DIE, we only have
7239 the stub. A complaint has already been logged. There's
7240 not much more we can do except pass on the stub DIE to
7241 die_reader_func. We don't want to throw an error on bad
7248 cutu_reader::keep ()
7250 /* Done, clean up. */
7251 gdb_assert (!dummy_p
);
7252 if (m_new_cu
!= NULL
)
7254 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7256 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7257 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7261 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7262 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7263 assumed to have already done the lookup to find the DWO file).
7265 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7266 THIS_CU->is_debug_types, but nothing else.
7268 We fill in THIS_CU->length.
7270 THIS_CU->cu is always freed when done.
7271 This is done in order to not leave THIS_CU->cu in a state where we have
7272 to care whether it refers to the "main" CU or the DWO CU.
7274 When parent_cu is passed, it is used to provide a default value for
7275 str_offsets_base and addr_base from the parent. */
7277 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7278 dwarf2_per_objfile
*per_objfile
,
7279 struct dwarf2_cu
*parent_cu
,
7280 struct dwo_file
*dwo_file
)
7281 : die_reader_specs
{},
7284 struct objfile
*objfile
= per_objfile
->objfile
;
7285 struct dwarf2_section_info
*section
= this_cu
->section
;
7286 bfd
*abfd
= section
->get_bfd_owner ();
7287 struct dwarf2_section_info
*abbrev_section
;
7288 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7290 if (dwarf_die_debug
)
7291 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7292 this_cu
->is_debug_types
? "type" : "comp",
7293 sect_offset_str (this_cu
->sect_off
));
7295 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7297 abbrev_section
= (dwo_file
!= NULL
7298 ? &dwo_file
->sections
.abbrev
7299 : get_abbrev_section_for_cu (this_cu
));
7301 /* This is cheap if the section is already read in. */
7302 section
->read (objfile
);
7304 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7306 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7307 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7308 section
, abbrev_section
, info_ptr
,
7309 (this_cu
->is_debug_types
7311 : rcuh_kind::COMPILE
));
7313 if (parent_cu
!= nullptr)
7315 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7316 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7318 this_cu
->length
= m_new_cu
->header
.get_length ();
7320 /* Skip dummy compilation units. */
7321 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7322 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7328 m_abbrev_table_holder
7329 = abbrev_table::read (objfile
, abbrev_section
,
7330 m_new_cu
->header
.abbrev_sect_off
);
7332 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7333 m_abbrev_table_holder
.get ());
7334 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7338 /* Type Unit Groups.
7340 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7341 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7342 so that all types coming from the same compilation (.o file) are grouped
7343 together. A future step could be to put the types in the same symtab as
7344 the CU the types ultimately came from. */
7347 hash_type_unit_group (const void *item
)
7349 const struct type_unit_group
*tu_group
7350 = (const struct type_unit_group
*) item
;
7352 return hash_stmt_list_entry (&tu_group
->hash
);
7356 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7358 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7359 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7361 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7364 /* Allocate a hash table for type unit groups. */
7367 allocate_type_unit_groups_table ()
7369 return htab_up (htab_create_alloc (3,
7370 hash_type_unit_group
,
7372 NULL
, xcalloc
, xfree
));
7375 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7376 partial symtabs. We combine several TUs per psymtab to not let the size
7377 of any one psymtab grow too big. */
7378 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7379 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7381 /* Helper routine for get_type_unit_group.
7382 Create the type_unit_group object used to hold one or more TUs. */
7384 static struct type_unit_group
*
7385 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7387 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7388 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7389 struct dwarf2_per_cu_data
*per_cu
;
7390 struct type_unit_group
*tu_group
;
7392 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7393 per_cu
= &tu_group
->per_cu
;
7394 per_cu
->per_bfd
= per_bfd
;
7396 if (per_bfd
->using_index
)
7398 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7399 struct dwarf2_per_cu_quick_data
);
7403 unsigned int line_offset
= to_underlying (line_offset_struct
);
7404 dwarf2_psymtab
*pst
;
7407 /* Give the symtab a useful name for debug purposes. */
7408 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7409 name
= string_printf ("<type_units_%d>",
7410 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7412 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7414 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7415 pst
->anonymous
= true;
7418 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7419 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7424 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7425 STMT_LIST is a DW_AT_stmt_list attribute. */
7427 static struct type_unit_group
*
7428 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7430 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7431 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7432 struct type_unit_group
*tu_group
;
7434 unsigned int line_offset
;
7435 struct type_unit_group type_unit_group_for_lookup
;
7437 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7438 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7440 /* Do we need to create a new group, or can we use an existing one? */
7444 line_offset
= DW_UNSND (stmt_list
);
7445 ++tu_stats
->nr_symtab_sharers
;
7449 /* Ugh, no stmt_list. Rare, but we have to handle it.
7450 We can do various things here like create one group per TU or
7451 spread them over multiple groups to split up the expansion work.
7452 To avoid worst case scenarios (too many groups or too large groups)
7453 we, umm, group them in bunches. */
7454 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7455 | (tu_stats
->nr_stmt_less_type_units
7456 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7457 ++tu_stats
->nr_stmt_less_type_units
;
7460 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7461 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7462 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7463 &type_unit_group_for_lookup
, INSERT
);
7466 tu_group
= (struct type_unit_group
*) *slot
;
7467 gdb_assert (tu_group
!= NULL
);
7471 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7472 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7474 ++tu_stats
->nr_symtabs
;
7480 /* Partial symbol tables. */
7482 /* Create a psymtab named NAME and assign it to PER_CU.
7484 The caller must fill in the following details:
7485 dirname, textlow, texthigh. */
7487 static dwarf2_psymtab
*
7488 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7489 dwarf2_per_objfile
*per_objfile
,
7492 struct objfile
*objfile
= per_objfile
->objfile
;
7493 dwarf2_psymtab
*pst
;
7495 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7497 pst
->psymtabs_addrmap_supported
= true;
7499 /* This is the glue that links PST into GDB's symbol API. */
7500 per_cu
->v
.psymtab
= pst
;
7505 /* DIE reader function for process_psymtab_comp_unit. */
7508 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7509 const gdb_byte
*info_ptr
,
7510 struct die_info
*comp_unit_die
,
7511 enum language pretend_language
)
7513 struct dwarf2_cu
*cu
= reader
->cu
;
7514 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7515 struct objfile
*objfile
= per_objfile
->objfile
;
7516 struct gdbarch
*gdbarch
= objfile
->arch ();
7517 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7519 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7520 dwarf2_psymtab
*pst
;
7521 enum pc_bounds_kind cu_bounds_kind
;
7522 const char *filename
;
7524 gdb_assert (! per_cu
->is_debug_types
);
7526 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7528 /* Allocate a new partial symbol table structure. */
7529 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7530 static const char artificial
[] = "<artificial>";
7531 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7532 if (filename
== NULL
)
7534 else if (strcmp (filename
, artificial
) == 0)
7536 debug_filename
.reset (concat (artificial
, "@",
7537 sect_offset_str (per_cu
->sect_off
),
7539 filename
= debug_filename
.get ();
7542 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7544 /* This must be done before calling dwarf2_build_include_psymtabs. */
7545 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7547 baseaddr
= objfile
->text_section_offset ();
7549 dwarf2_find_base_address (comp_unit_die
, cu
);
7551 /* Possibly set the default values of LOWPC and HIGHPC from
7553 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7554 &best_highpc
, cu
, pst
);
7555 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7558 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7561 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7563 /* Store the contiguous range if it is not empty; it can be
7564 empty for CUs with no code. */
7565 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7569 /* Check if comp unit has_children.
7570 If so, read the rest of the partial symbols from this comp unit.
7571 If not, there's no more debug_info for this comp unit. */
7572 if (comp_unit_die
->has_children
)
7574 struct partial_die_info
*first_die
;
7575 CORE_ADDR lowpc
, highpc
;
7577 lowpc
= ((CORE_ADDR
) -1);
7578 highpc
= ((CORE_ADDR
) 0);
7580 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7582 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7583 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7585 /* If we didn't find a lowpc, set it to highpc to avoid
7586 complaints from `maint check'. */
7587 if (lowpc
== ((CORE_ADDR
) -1))
7590 /* If the compilation unit didn't have an explicit address range,
7591 then use the information extracted from its child dies. */
7592 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7595 best_highpc
= highpc
;
7598 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7599 best_lowpc
+ baseaddr
)
7601 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7602 best_highpc
+ baseaddr
)
7605 end_psymtab_common (objfile
, pst
);
7607 if (!cu
->per_cu
->imported_symtabs_empty ())
7610 int len
= cu
->per_cu
->imported_symtabs_size ();
7612 /* Fill in 'dependencies' here; we fill in 'users' in a
7614 pst
->number_of_dependencies
= len
;
7616 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7617 for (i
= 0; i
< len
; ++i
)
7619 pst
->dependencies
[i
]
7620 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7623 cu
->per_cu
->imported_symtabs_free ();
7626 /* Get the list of files included in the current compilation unit,
7627 and build a psymtab for each of them. */
7628 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7630 if (dwarf_read_debug
)
7631 fprintf_unfiltered (gdb_stdlog
,
7632 "Psymtab for %s unit @%s: %s - %s"
7633 ", %d global, %d static syms\n",
7634 per_cu
->is_debug_types
? "type" : "comp",
7635 sect_offset_str (per_cu
->sect_off
),
7636 paddress (gdbarch
, pst
->text_low (objfile
)),
7637 paddress (gdbarch
, pst
->text_high (objfile
)),
7638 pst
->n_global_syms
, pst
->n_static_syms
);
7641 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7642 Process compilation unit THIS_CU for a psymtab. */
7645 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7646 dwarf2_per_objfile
*per_objfile
,
7647 bool want_partial_unit
,
7648 enum language pretend_language
)
7650 /* If this compilation unit was already read in, free the
7651 cached copy in order to read it in again. This is
7652 necessary because we skipped some symbols when we first
7653 read in the compilation unit (see load_partial_dies).
7654 This problem could be avoided, but the benefit is unclear. */
7655 per_objfile
->remove_cu (this_cu
);
7657 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7659 switch (reader
.comp_unit_die
->tag
)
7661 case DW_TAG_compile_unit
:
7662 this_cu
->unit_type
= DW_UT_compile
;
7664 case DW_TAG_partial_unit
:
7665 this_cu
->unit_type
= DW_UT_partial
;
7675 else if (this_cu
->is_debug_types
)
7676 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7677 reader
.comp_unit_die
);
7678 else if (want_partial_unit
7679 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7680 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7681 reader
.comp_unit_die
,
7684 this_cu
->lang
= reader
.cu
->language
;
7686 /* Age out any secondary CUs. */
7687 per_objfile
->age_comp_units ();
7690 /* Reader function for build_type_psymtabs. */
7693 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7694 const gdb_byte
*info_ptr
,
7695 struct die_info
*type_unit_die
)
7697 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7698 struct objfile
*objfile
= per_objfile
->objfile
;
7699 struct dwarf2_cu
*cu
= reader
->cu
;
7700 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7701 struct signatured_type
*sig_type
;
7702 struct type_unit_group
*tu_group
;
7703 struct attribute
*attr
;
7704 struct partial_die_info
*first_die
;
7705 CORE_ADDR lowpc
, highpc
;
7706 dwarf2_psymtab
*pst
;
7708 gdb_assert (per_cu
->is_debug_types
);
7709 sig_type
= (struct signatured_type
*) per_cu
;
7711 if (! type_unit_die
->has_children
)
7714 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7715 tu_group
= get_type_unit_group (cu
, attr
);
7717 if (tu_group
->tus
== nullptr)
7718 tu_group
->tus
= new std::vector
<signatured_type
*>;
7719 tu_group
->tus
->push_back (sig_type
);
7721 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7722 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7723 pst
->anonymous
= true;
7725 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7727 lowpc
= (CORE_ADDR
) -1;
7728 highpc
= (CORE_ADDR
) 0;
7729 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7731 end_psymtab_common (objfile
, pst
);
7734 /* Struct used to sort TUs by their abbreviation table offset. */
7736 struct tu_abbrev_offset
7738 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7739 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7742 signatured_type
*sig_type
;
7743 sect_offset abbrev_offset
;
7746 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7749 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7750 const struct tu_abbrev_offset
&b
)
7752 return a
.abbrev_offset
< b
.abbrev_offset
;
7755 /* Efficiently read all the type units.
7756 This does the bulk of the work for build_type_psymtabs.
7758 The efficiency is because we sort TUs by the abbrev table they use and
7759 only read each abbrev table once. In one program there are 200K TUs
7760 sharing 8K abbrev tables.
7762 The main purpose of this function is to support building the
7763 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7764 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7765 can collapse the search space by grouping them by stmt_list.
7766 The savings can be significant, in the same program from above the 200K TUs
7767 share 8K stmt_list tables.
7769 FUNC is expected to call get_type_unit_group, which will create the
7770 struct type_unit_group if necessary and add it to
7771 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7774 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7776 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7777 abbrev_table_up abbrev_table
;
7778 sect_offset abbrev_offset
;
7780 /* It's up to the caller to not call us multiple times. */
7781 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7783 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7786 /* TUs typically share abbrev tables, and there can be way more TUs than
7787 abbrev tables. Sort by abbrev table to reduce the number of times we
7788 read each abbrev table in.
7789 Alternatives are to punt or to maintain a cache of abbrev tables.
7790 This is simpler and efficient enough for now.
7792 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7793 symtab to use). Typically TUs with the same abbrev offset have the same
7794 stmt_list value too so in practice this should work well.
7796 The basic algorithm here is:
7798 sort TUs by abbrev table
7799 for each TU with same abbrev table:
7800 read abbrev table if first user
7801 read TU top level DIE
7802 [IWBN if DWO skeletons had DW_AT_stmt_list]
7805 if (dwarf_read_debug
)
7806 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7808 /* Sort in a separate table to maintain the order of all_type_units
7809 for .gdb_index: TU indices directly index all_type_units. */
7810 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7811 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7813 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7814 sorted_by_abbrev
.emplace_back
7815 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7816 sig_type
->per_cu
.sect_off
));
7818 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7819 sort_tu_by_abbrev_offset
);
7821 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7823 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7825 /* Switch to the next abbrev table if necessary. */
7826 if (abbrev_table
== NULL
7827 || tu
.abbrev_offset
!= abbrev_offset
)
7829 abbrev_offset
= tu
.abbrev_offset
;
7831 abbrev_table::read (per_objfile
->objfile
,
7832 &per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7833 ++tu_stats
->nr_uniq_abbrev_tables
;
7836 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7837 abbrev_table
.get (), nullptr, false);
7838 if (!reader
.dummy_p
)
7839 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7840 reader
.comp_unit_die
);
7844 /* Print collected type unit statistics. */
7847 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7849 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7851 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7852 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7853 per_objfile
->per_bfd
->all_type_units
.size ());
7854 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7855 tu_stats
->nr_uniq_abbrev_tables
);
7856 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7857 tu_stats
->nr_symtabs
);
7858 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7859 tu_stats
->nr_symtab_sharers
);
7860 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7861 tu_stats
->nr_stmt_less_type_units
);
7862 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7863 tu_stats
->nr_all_type_units_reallocs
);
7866 /* Traversal function for build_type_psymtabs. */
7869 build_type_psymtab_dependencies (void **slot
, void *info
)
7871 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7872 struct objfile
*objfile
= per_objfile
->objfile
;
7873 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7874 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7875 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7876 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7879 gdb_assert (len
> 0);
7880 gdb_assert (per_cu
->type_unit_group_p ());
7882 pst
->number_of_dependencies
= len
;
7883 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7884 for (i
= 0; i
< len
; ++i
)
7886 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7887 gdb_assert (iter
->per_cu
.is_debug_types
);
7888 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7889 iter
->type_unit_group
= tu_group
;
7892 delete tu_group
->tus
;
7893 tu_group
->tus
= nullptr;
7898 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7899 Build partial symbol tables for the .debug_types comp-units. */
7902 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7904 if (! create_all_type_units (per_objfile
))
7907 build_type_psymtabs_1 (per_objfile
);
7910 /* Traversal function for process_skeletonless_type_unit.
7911 Read a TU in a DWO file and build partial symbols for it. */
7914 process_skeletonless_type_unit (void **slot
, void *info
)
7916 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7917 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7918 struct signatured_type find_entry
, *entry
;
7920 /* If this TU doesn't exist in the global table, add it and read it in. */
7922 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7923 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7925 find_entry
.signature
= dwo_unit
->signature
;
7926 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7927 &find_entry
, INSERT
);
7928 /* If we've already seen this type there's nothing to do. What's happening
7929 is we're doing our own version of comdat-folding here. */
7933 /* This does the job that create_all_type_units would have done for
7935 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7936 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7939 /* This does the job that build_type_psymtabs_1 would have done. */
7940 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7941 if (!reader
.dummy_p
)
7942 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7943 reader
.comp_unit_die
);
7948 /* Traversal function for process_skeletonless_type_units. */
7951 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7953 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7955 if (dwo_file
->tus
!= NULL
)
7956 htab_traverse_noresize (dwo_file
->tus
.get (),
7957 process_skeletonless_type_unit
, info
);
7962 /* Scan all TUs of DWO files, verifying we've processed them.
7963 This is needed in case a TU was emitted without its skeleton.
7964 Note: This can't be done until we know what all the DWO files are. */
7967 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7969 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7970 if (get_dwp_file (per_objfile
) == NULL
7971 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7973 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7974 process_dwo_file_for_skeletonless_type_units
,
7979 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7982 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7984 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7986 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7991 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7993 /* Set the 'user' field only if it is not already set. */
7994 if (pst
->dependencies
[j
]->user
== NULL
)
7995 pst
->dependencies
[j
]->user
= pst
;
8000 /* Build the partial symbol table by doing a quick pass through the
8001 .debug_info and .debug_abbrev sections. */
8004 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8006 struct objfile
*objfile
= per_objfile
->objfile
;
8008 if (dwarf_read_debug
)
8010 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8011 objfile_name (objfile
));
8014 scoped_restore restore_reading_psyms
8015 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8018 per_objfile
->per_bfd
->info
.read (objfile
);
8020 /* Any cached compilation units will be linked by the per-objfile
8021 read_in_chain. Make sure to free them when we're done. */
8022 free_cached_comp_units
freer (per_objfile
);
8024 build_type_psymtabs (per_objfile
);
8026 create_all_comp_units (per_objfile
);
8028 /* Create a temporary address map on a temporary obstack. We later
8029 copy this to the final obstack. */
8030 auto_obstack temp_obstack
;
8032 scoped_restore save_psymtabs_addrmap
8033 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8034 addrmap_create_mutable (&temp_obstack
));
8036 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8038 if (per_cu
->v
.psymtab
!= NULL
)
8039 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8041 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8045 /* This has to wait until we read the CUs, we need the list of DWOs. */
8046 process_skeletonless_type_units (per_objfile
);
8048 /* Now that all TUs have been processed we can fill in the dependencies. */
8049 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8051 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8052 build_type_psymtab_dependencies
, per_objfile
);
8055 if (dwarf_read_debug
)
8056 print_tu_stats (per_objfile
);
8058 set_partial_user (per_objfile
);
8060 objfile
->partial_symtabs
->psymtabs_addrmap
8061 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8062 objfile
->partial_symtabs
->obstack ());
8063 /* At this point we want to keep the address map. */
8064 save_psymtabs_addrmap
.release ();
8066 if (dwarf_read_debug
)
8067 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8068 objfile_name (objfile
));
8071 /* Load the partial DIEs for a secondary CU into memory.
8072 This is also used when rereading a primary CU with load_all_dies. */
8075 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8076 dwarf2_per_objfile
*per_objfile
,
8077 dwarf2_cu
*existing_cu
)
8079 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8081 if (!reader
.dummy_p
)
8083 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8086 /* Check if comp unit has_children.
8087 If so, read the rest of the partial symbols from this comp unit.
8088 If not, there's no more debug_info for this comp unit. */
8089 if (reader
.comp_unit_die
->has_children
)
8090 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8097 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8098 struct dwarf2_section_info
*section
,
8099 struct dwarf2_section_info
*abbrev_section
,
8100 unsigned int is_dwz
)
8102 const gdb_byte
*info_ptr
;
8103 struct objfile
*objfile
= per_objfile
->objfile
;
8105 if (dwarf_read_debug
)
8106 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8107 section
->get_name (),
8108 section
->get_file_name ());
8110 section
->read (objfile
);
8112 info_ptr
= section
->buffer
;
8114 while (info_ptr
< section
->buffer
+ section
->size
)
8116 struct dwarf2_per_cu_data
*this_cu
;
8118 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8120 comp_unit_head cu_header
;
8121 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8122 abbrev_section
, info_ptr
,
8123 rcuh_kind::COMPILE
);
8125 /* Save the compilation unit for later lookup. */
8126 if (cu_header
.unit_type
!= DW_UT_type
)
8127 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8130 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8131 sig_type
->signature
= cu_header
.signature
;
8132 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8133 this_cu
= &sig_type
->per_cu
;
8135 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8136 this_cu
->sect_off
= sect_off
;
8137 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8138 this_cu
->is_dwz
= is_dwz
;
8139 this_cu
->section
= section
;
8141 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8143 info_ptr
= info_ptr
+ this_cu
->length
;
8147 /* Create a list of all compilation units in OBJFILE.
8148 This is only done for -readnow and building partial symtabs. */
8151 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8153 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8154 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8155 &per_objfile
->per_bfd
->abbrev
, 0);
8157 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8159 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8162 /* Process all loaded DIEs for compilation unit CU, starting at
8163 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8164 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8165 DW_AT_ranges). See the comments of add_partial_subprogram on how
8166 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8169 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8170 CORE_ADDR
*highpc
, int set_addrmap
,
8171 struct dwarf2_cu
*cu
)
8173 struct partial_die_info
*pdi
;
8175 /* Now, march along the PDI's, descending into ones which have
8176 interesting children but skipping the children of the other ones,
8177 until we reach the end of the compilation unit. */
8185 /* Anonymous namespaces or modules have no name but have interesting
8186 children, so we need to look at them. Ditto for anonymous
8189 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8190 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8191 || pdi
->tag
== DW_TAG_imported_unit
8192 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8196 case DW_TAG_subprogram
:
8197 case DW_TAG_inlined_subroutine
:
8198 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8199 if (cu
->language
== language_cplus
)
8200 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8203 case DW_TAG_constant
:
8204 case DW_TAG_variable
:
8205 case DW_TAG_typedef
:
8206 case DW_TAG_union_type
:
8207 if (!pdi
->is_declaration
8208 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8210 add_partial_symbol (pdi
, cu
);
8213 case DW_TAG_class_type
:
8214 case DW_TAG_interface_type
:
8215 case DW_TAG_structure_type
:
8216 if (!pdi
->is_declaration
)
8218 add_partial_symbol (pdi
, cu
);
8220 if ((cu
->language
== language_rust
8221 || cu
->language
== language_cplus
) && pdi
->has_children
)
8222 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8225 case DW_TAG_enumeration_type
:
8226 if (!pdi
->is_declaration
)
8227 add_partial_enumeration (pdi
, cu
);
8229 case DW_TAG_base_type
:
8230 case DW_TAG_subrange_type
:
8231 /* File scope base type definitions are added to the partial
8233 add_partial_symbol (pdi
, cu
);
8235 case DW_TAG_namespace
:
8236 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8239 if (!pdi
->is_declaration
)
8240 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8242 case DW_TAG_imported_unit
:
8244 struct dwarf2_per_cu_data
*per_cu
;
8246 /* For now we don't handle imported units in type units. */
8247 if (cu
->per_cu
->is_debug_types
)
8249 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8250 " supported in type units [in module %s]"),
8251 objfile_name (cu
->per_objfile
->objfile
));
8254 per_cu
= dwarf2_find_containing_comp_unit
8255 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8257 /* Go read the partial unit, if needed. */
8258 if (per_cu
->v
.psymtab
== NULL
)
8259 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8262 cu
->per_cu
->imported_symtabs_push (per_cu
);
8265 case DW_TAG_imported_declaration
:
8266 add_partial_symbol (pdi
, cu
);
8273 /* If the die has a sibling, skip to the sibling. */
8275 pdi
= pdi
->die_sibling
;
8279 /* Functions used to compute the fully scoped name of a partial DIE.
8281 Normally, this is simple. For C++, the parent DIE's fully scoped
8282 name is concatenated with "::" and the partial DIE's name.
8283 Enumerators are an exception; they use the scope of their parent
8284 enumeration type, i.e. the name of the enumeration type is not
8285 prepended to the enumerator.
8287 There are two complexities. One is DW_AT_specification; in this
8288 case "parent" means the parent of the target of the specification,
8289 instead of the direct parent of the DIE. The other is compilers
8290 which do not emit DW_TAG_namespace; in this case we try to guess
8291 the fully qualified name of structure types from their members'
8292 linkage names. This must be done using the DIE's children rather
8293 than the children of any DW_AT_specification target. We only need
8294 to do this for structures at the top level, i.e. if the target of
8295 any DW_AT_specification (if any; otherwise the DIE itself) does not
8298 /* Compute the scope prefix associated with PDI's parent, in
8299 compilation unit CU. The result will be allocated on CU's
8300 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8301 field. NULL is returned if no prefix is necessary. */
8303 partial_die_parent_scope (struct partial_die_info
*pdi
,
8304 struct dwarf2_cu
*cu
)
8306 const char *grandparent_scope
;
8307 struct partial_die_info
*parent
, *real_pdi
;
8309 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8310 then this means the parent of the specification DIE. */
8313 while (real_pdi
->has_specification
)
8315 auto res
= find_partial_die (real_pdi
->spec_offset
,
8316 real_pdi
->spec_is_dwz
, cu
);
8321 parent
= real_pdi
->die_parent
;
8325 if (parent
->scope_set
)
8326 return parent
->scope
;
8330 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8332 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8333 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8334 Work around this problem here. */
8335 if (cu
->language
== language_cplus
8336 && parent
->tag
== DW_TAG_namespace
8337 && strcmp (parent
->name (cu
), "::") == 0
8338 && grandparent_scope
== NULL
)
8340 parent
->scope
= NULL
;
8341 parent
->scope_set
= 1;
8345 /* Nested subroutines in Fortran get a prefix. */
8346 if (pdi
->tag
== DW_TAG_enumerator
)
8347 /* Enumerators should not get the name of the enumeration as a prefix. */
8348 parent
->scope
= grandparent_scope
;
8349 else if (parent
->tag
== DW_TAG_namespace
8350 || parent
->tag
== DW_TAG_module
8351 || parent
->tag
== DW_TAG_structure_type
8352 || parent
->tag
== DW_TAG_class_type
8353 || parent
->tag
== DW_TAG_interface_type
8354 || parent
->tag
== DW_TAG_union_type
8355 || parent
->tag
== DW_TAG_enumeration_type
8356 || (cu
->language
== language_fortran
8357 && parent
->tag
== DW_TAG_subprogram
8358 && pdi
->tag
== DW_TAG_subprogram
))
8360 if (grandparent_scope
== NULL
)
8361 parent
->scope
= parent
->name (cu
);
8363 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8365 parent
->name (cu
), 0, cu
);
8369 /* FIXME drow/2004-04-01: What should we be doing with
8370 function-local names? For partial symbols, we should probably be
8372 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8373 dwarf_tag_name (parent
->tag
),
8374 sect_offset_str (pdi
->sect_off
));
8375 parent
->scope
= grandparent_scope
;
8378 parent
->scope_set
= 1;
8379 return parent
->scope
;
8382 /* Return the fully scoped name associated with PDI, from compilation unit
8383 CU. The result will be allocated with malloc. */
8385 static gdb::unique_xmalloc_ptr
<char>
8386 partial_die_full_name (struct partial_die_info
*pdi
,
8387 struct dwarf2_cu
*cu
)
8389 const char *parent_scope
;
8391 /* If this is a template instantiation, we can not work out the
8392 template arguments from partial DIEs. So, unfortunately, we have
8393 to go through the full DIEs. At least any work we do building
8394 types here will be reused if full symbols are loaded later. */
8395 if (pdi
->has_template_arguments
)
8399 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8401 struct die_info
*die
;
8402 struct attribute attr
;
8403 struct dwarf2_cu
*ref_cu
= cu
;
8405 /* DW_FORM_ref_addr is using section offset. */
8406 attr
.name
= (enum dwarf_attribute
) 0;
8407 attr
.form
= DW_FORM_ref_addr
;
8408 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8409 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8411 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8415 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8416 if (parent_scope
== NULL
)
8419 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8425 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8427 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8428 struct objfile
*objfile
= per_objfile
->objfile
;
8429 struct gdbarch
*gdbarch
= objfile
->arch ();
8431 const char *actual_name
= NULL
;
8434 baseaddr
= objfile
->text_section_offset ();
8436 gdb::unique_xmalloc_ptr
<char> built_actual_name
8437 = partial_die_full_name (pdi
, cu
);
8438 if (built_actual_name
!= NULL
)
8439 actual_name
= built_actual_name
.get ();
8441 if (actual_name
== NULL
)
8442 actual_name
= pdi
->name (cu
);
8444 partial_symbol psymbol
;
8445 memset (&psymbol
, 0, sizeof (psymbol
));
8446 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8447 psymbol
.ginfo
.section
= -1;
8449 /* The code below indicates that the psymbol should be installed by
8451 gdb::optional
<psymbol_placement
> where
;
8455 case DW_TAG_inlined_subroutine
:
8456 case DW_TAG_subprogram
:
8457 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8459 if (pdi
->is_external
8460 || cu
->language
== language_ada
8461 || (cu
->language
== language_fortran
8462 && pdi
->die_parent
!= NULL
8463 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8465 /* Normally, only "external" DIEs are part of the global scope.
8466 But in Ada and Fortran, we want to be able to access nested
8467 procedures globally. So all Ada and Fortran subprograms are
8468 stored in the global scope. */
8469 where
= psymbol_placement::GLOBAL
;
8472 where
= psymbol_placement::STATIC
;
8474 psymbol
.domain
= VAR_DOMAIN
;
8475 psymbol
.aclass
= LOC_BLOCK
;
8476 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8477 psymbol
.ginfo
.value
.address
= addr
;
8479 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8480 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8482 case DW_TAG_constant
:
8483 psymbol
.domain
= VAR_DOMAIN
;
8484 psymbol
.aclass
= LOC_STATIC
;
8485 where
= (pdi
->is_external
8486 ? psymbol_placement::GLOBAL
8487 : psymbol_placement::STATIC
);
8489 case DW_TAG_variable
:
8491 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8495 && !per_objfile
->per_bfd
->has_section_at_zero
)
8497 /* A global or static variable may also have been stripped
8498 out by the linker if unused, in which case its address
8499 will be nullified; do not add such variables into partial
8500 symbol table then. */
8502 else if (pdi
->is_external
)
8505 Don't enter into the minimal symbol tables as there is
8506 a minimal symbol table entry from the ELF symbols already.
8507 Enter into partial symbol table if it has a location
8508 descriptor or a type.
8509 If the location descriptor is missing, new_symbol will create
8510 a LOC_UNRESOLVED symbol, the address of the variable will then
8511 be determined from the minimal symbol table whenever the variable
8513 The address for the partial symbol table entry is not
8514 used by GDB, but it comes in handy for debugging partial symbol
8517 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8519 psymbol
.domain
= VAR_DOMAIN
;
8520 psymbol
.aclass
= LOC_STATIC
;
8521 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8522 psymbol
.ginfo
.value
.address
= addr
;
8523 where
= psymbol_placement::GLOBAL
;
8528 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8530 /* Static Variable. Skip symbols whose value we cannot know (those
8531 without location descriptors or constant values). */
8532 if (!has_loc
&& !pdi
->has_const_value
)
8535 psymbol
.domain
= VAR_DOMAIN
;
8536 psymbol
.aclass
= LOC_STATIC
;
8537 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8539 psymbol
.ginfo
.value
.address
= addr
;
8540 where
= psymbol_placement::STATIC
;
8543 case DW_TAG_typedef
:
8544 case DW_TAG_base_type
:
8545 case DW_TAG_subrange_type
:
8546 psymbol
.domain
= VAR_DOMAIN
;
8547 psymbol
.aclass
= LOC_TYPEDEF
;
8548 where
= psymbol_placement::STATIC
;
8550 case DW_TAG_imported_declaration
:
8551 case DW_TAG_namespace
:
8552 psymbol
.domain
= VAR_DOMAIN
;
8553 psymbol
.aclass
= LOC_TYPEDEF
;
8554 where
= psymbol_placement::GLOBAL
;
8557 /* With Fortran 77 there might be a "BLOCK DATA" module
8558 available without any name. If so, we skip the module as it
8559 doesn't bring any value. */
8560 if (actual_name
!= nullptr)
8562 psymbol
.domain
= MODULE_DOMAIN
;
8563 psymbol
.aclass
= LOC_TYPEDEF
;
8564 where
= psymbol_placement::GLOBAL
;
8567 case DW_TAG_class_type
:
8568 case DW_TAG_interface_type
:
8569 case DW_TAG_structure_type
:
8570 case DW_TAG_union_type
:
8571 case DW_TAG_enumeration_type
:
8572 /* Skip external references. The DWARF standard says in the section
8573 about "Structure, Union, and Class Type Entries": "An incomplete
8574 structure, union or class type is represented by a structure,
8575 union or class entry that does not have a byte size attribute
8576 and that has a DW_AT_declaration attribute." */
8577 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8580 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8581 static vs. global. */
8582 psymbol
.domain
= STRUCT_DOMAIN
;
8583 psymbol
.aclass
= LOC_TYPEDEF
;
8584 where
= (cu
->language
== language_cplus
8585 ? psymbol_placement::GLOBAL
8586 : psymbol_placement::STATIC
);
8588 case DW_TAG_enumerator
:
8589 psymbol
.domain
= VAR_DOMAIN
;
8590 psymbol
.aclass
= LOC_CONST
;
8591 where
= (cu
->language
== language_cplus
8592 ? psymbol_placement::GLOBAL
8593 : psymbol_placement::STATIC
);
8599 if (where
.has_value ())
8601 if (built_actual_name
!= nullptr)
8602 actual_name
= objfile
->intern (actual_name
);
8603 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8604 psymbol
.ginfo
.set_linkage_name (actual_name
);
8607 psymbol
.ginfo
.set_demangled_name (actual_name
,
8608 &objfile
->objfile_obstack
);
8609 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8611 add_psymbol_to_list (psymbol
, *where
, objfile
);
8615 /* Read a partial die corresponding to a namespace; also, add a symbol
8616 corresponding to that namespace to the symbol table. NAMESPACE is
8617 the name of the enclosing namespace. */
8620 add_partial_namespace (struct partial_die_info
*pdi
,
8621 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8622 int set_addrmap
, struct dwarf2_cu
*cu
)
8624 /* Add a symbol for the namespace. */
8626 add_partial_symbol (pdi
, cu
);
8628 /* Now scan partial symbols in that namespace. */
8630 if (pdi
->has_children
)
8631 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8634 /* Read a partial die corresponding to a Fortran module. */
8637 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8638 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8640 /* Add a symbol for the namespace. */
8642 add_partial_symbol (pdi
, cu
);
8644 /* Now scan partial symbols in that module. */
8646 if (pdi
->has_children
)
8647 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8650 /* Read a partial die corresponding to a subprogram or an inlined
8651 subprogram and create a partial symbol for that subprogram.
8652 When the CU language allows it, this routine also defines a partial
8653 symbol for each nested subprogram that this subprogram contains.
8654 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8655 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8657 PDI may also be a lexical block, in which case we simply search
8658 recursively for subprograms defined inside that lexical block.
8659 Again, this is only performed when the CU language allows this
8660 type of definitions. */
8663 add_partial_subprogram (struct partial_die_info
*pdi
,
8664 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8665 int set_addrmap
, struct dwarf2_cu
*cu
)
8667 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8669 if (pdi
->has_pc_info
)
8671 if (pdi
->lowpc
< *lowpc
)
8672 *lowpc
= pdi
->lowpc
;
8673 if (pdi
->highpc
> *highpc
)
8674 *highpc
= pdi
->highpc
;
8677 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8678 struct gdbarch
*gdbarch
= objfile
->arch ();
8680 CORE_ADDR this_highpc
;
8681 CORE_ADDR this_lowpc
;
8683 baseaddr
= objfile
->text_section_offset ();
8685 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8686 pdi
->lowpc
+ baseaddr
)
8689 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8690 pdi
->highpc
+ baseaddr
)
8692 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8693 this_lowpc
, this_highpc
- 1,
8694 cu
->per_cu
->v
.psymtab
);
8698 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8700 if (!pdi
->is_declaration
)
8701 /* Ignore subprogram DIEs that do not have a name, they are
8702 illegal. Do not emit a complaint at this point, we will
8703 do so when we convert this psymtab into a symtab. */
8705 add_partial_symbol (pdi
, cu
);
8709 if (! pdi
->has_children
)
8712 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8714 pdi
= pdi
->die_child
;
8718 if (pdi
->tag
== DW_TAG_subprogram
8719 || pdi
->tag
== DW_TAG_inlined_subroutine
8720 || pdi
->tag
== DW_TAG_lexical_block
)
8721 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8722 pdi
= pdi
->die_sibling
;
8727 /* Read a partial die corresponding to an enumeration type. */
8730 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8731 struct dwarf2_cu
*cu
)
8733 struct partial_die_info
*pdi
;
8735 if (enum_pdi
->name (cu
) != NULL
)
8736 add_partial_symbol (enum_pdi
, cu
);
8738 pdi
= enum_pdi
->die_child
;
8741 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8742 complaint (_("malformed enumerator DIE ignored"));
8744 add_partial_symbol (pdi
, cu
);
8745 pdi
= pdi
->die_sibling
;
8749 /* Return the initial uleb128 in the die at INFO_PTR. */
8752 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8754 unsigned int bytes_read
;
8756 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8759 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8760 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8762 Return the corresponding abbrev, or NULL if the number is zero (indicating
8763 an empty DIE). In either case *BYTES_READ will be set to the length of
8764 the initial number. */
8766 static struct abbrev_info
*
8767 peek_die_abbrev (const die_reader_specs
&reader
,
8768 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8770 dwarf2_cu
*cu
= reader
.cu
;
8771 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8772 unsigned int abbrev_number
8773 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8775 if (abbrev_number
== 0)
8778 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8781 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8782 " at offset %s [in module %s]"),
8783 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8784 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8790 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8791 Returns a pointer to the end of a series of DIEs, terminated by an empty
8792 DIE. Any children of the skipped DIEs will also be skipped. */
8794 static const gdb_byte
*
8795 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8799 unsigned int bytes_read
;
8800 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8803 return info_ptr
+ bytes_read
;
8805 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8809 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8810 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8811 abbrev corresponding to that skipped uleb128 should be passed in
8812 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8815 static const gdb_byte
*
8816 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8817 struct abbrev_info
*abbrev
)
8819 unsigned int bytes_read
;
8820 struct attribute attr
;
8821 bfd
*abfd
= reader
->abfd
;
8822 struct dwarf2_cu
*cu
= reader
->cu
;
8823 const gdb_byte
*buffer
= reader
->buffer
;
8824 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8825 unsigned int form
, i
;
8827 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8829 /* The only abbrev we care about is DW_AT_sibling. */
8830 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8833 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8835 if (attr
.form
== DW_FORM_ref_addr
)
8836 complaint (_("ignoring absolute DW_AT_sibling"));
8839 sect_offset off
= attr
.get_ref_die_offset ();
8840 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8842 if (sibling_ptr
< info_ptr
)
8843 complaint (_("DW_AT_sibling points backwards"));
8844 else if (sibling_ptr
> reader
->buffer_end
)
8845 reader
->die_section
->overflow_complaint ();
8851 /* If it isn't DW_AT_sibling, skip this attribute. */
8852 form
= abbrev
->attrs
[i
].form
;
8856 case DW_FORM_ref_addr
:
8857 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8858 and later it is offset sized. */
8859 if (cu
->header
.version
== 2)
8860 info_ptr
+= cu
->header
.addr_size
;
8862 info_ptr
+= cu
->header
.offset_size
;
8864 case DW_FORM_GNU_ref_alt
:
8865 info_ptr
+= cu
->header
.offset_size
;
8868 info_ptr
+= cu
->header
.addr_size
;
8876 case DW_FORM_flag_present
:
8877 case DW_FORM_implicit_const
:
8894 case DW_FORM_ref_sig8
:
8897 case DW_FORM_data16
:
8900 case DW_FORM_string
:
8901 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8902 info_ptr
+= bytes_read
;
8904 case DW_FORM_sec_offset
:
8906 case DW_FORM_GNU_strp_alt
:
8907 info_ptr
+= cu
->header
.offset_size
;
8909 case DW_FORM_exprloc
:
8911 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8912 info_ptr
+= bytes_read
;
8914 case DW_FORM_block1
:
8915 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8917 case DW_FORM_block2
:
8918 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8920 case DW_FORM_block4
:
8921 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8927 case DW_FORM_ref_udata
:
8928 case DW_FORM_GNU_addr_index
:
8929 case DW_FORM_GNU_str_index
:
8930 case DW_FORM_rnglistx
:
8931 case DW_FORM_loclistx
:
8932 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8934 case DW_FORM_indirect
:
8935 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8936 info_ptr
+= bytes_read
;
8937 /* We need to continue parsing from here, so just go back to
8939 goto skip_attribute
;
8942 error (_("Dwarf Error: Cannot handle %s "
8943 "in DWARF reader [in module %s]"),
8944 dwarf_form_name (form
),
8945 bfd_get_filename (abfd
));
8949 if (abbrev
->has_children
)
8950 return skip_children (reader
, info_ptr
);
8955 /* Locate ORIG_PDI's sibling.
8956 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8958 static const gdb_byte
*
8959 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8960 struct partial_die_info
*orig_pdi
,
8961 const gdb_byte
*info_ptr
)
8963 /* Do we know the sibling already? */
8965 if (orig_pdi
->sibling
)
8966 return orig_pdi
->sibling
;
8968 /* Are there any children to deal with? */
8970 if (!orig_pdi
->has_children
)
8973 /* Skip the children the long way. */
8975 return skip_children (reader
, info_ptr
);
8978 /* Expand this partial symbol table into a full symbol table. SELF is
8982 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8984 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8986 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8988 /* If this psymtab is constructed from a debug-only objfile, the
8989 has_section_at_zero flag will not necessarily be correct. We
8990 can get the correct value for this flag by looking at the data
8991 associated with the (presumably stripped) associated objfile. */
8992 if (objfile
->separate_debug_objfile_backlink
)
8994 dwarf2_per_objfile
*per_objfile_backlink
8995 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8997 per_objfile
->per_bfd
->has_section_at_zero
8998 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9001 expand_psymtab (objfile
);
9003 process_cu_includes (per_objfile
);
9006 /* Reading in full CUs. */
9008 /* Add PER_CU to the queue. */
9011 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9012 dwarf2_per_objfile
*per_objfile
,
9013 enum language pretend_language
)
9016 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9019 /* If PER_CU is not yet queued, add it to the queue.
9020 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9022 The result is non-zero if PER_CU was queued, otherwise the result is zero
9023 meaning either PER_CU is already queued or it is already loaded.
9025 N.B. There is an invariant here that if a CU is queued then it is loaded.
9026 The caller is required to load PER_CU if we return non-zero. */
9029 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9030 dwarf2_per_cu_data
*per_cu
,
9031 dwarf2_per_objfile
*per_objfile
,
9032 enum language pretend_language
)
9034 /* We may arrive here during partial symbol reading, if we need full
9035 DIEs to process an unusual case (e.g. template arguments). Do
9036 not queue PER_CU, just tell our caller to load its DIEs. */
9037 if (per_cu
->per_bfd
->reading_partial_symbols
)
9039 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9041 if (cu
== NULL
|| cu
->dies
== NULL
)
9046 /* Mark the dependence relation so that we don't flush PER_CU
9048 if (dependent_cu
!= NULL
)
9049 dwarf2_add_dependence (dependent_cu
, per_cu
);
9051 /* If it's already on the queue, we have nothing to do. */
9055 /* If the compilation unit is already loaded, just mark it as
9057 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9064 /* Add it to the queue. */
9065 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9070 /* Process the queue. */
9073 process_queue (dwarf2_per_objfile
*per_objfile
)
9075 if (dwarf_read_debug
)
9077 fprintf_unfiltered (gdb_stdlog
,
9078 "Expanding one or more symtabs of objfile %s ...\n",
9079 objfile_name (per_objfile
->objfile
));
9082 /* The queue starts out with one item, but following a DIE reference
9083 may load a new CU, adding it to the end of the queue. */
9084 while (!per_objfile
->per_bfd
->queue
.empty ())
9086 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9087 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9089 if (!per_objfile
->symtab_set_p (per_cu
))
9091 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9093 /* Skip dummy CUs. */
9096 unsigned int debug_print_threshold
;
9099 if (per_cu
->is_debug_types
)
9101 struct signatured_type
*sig_type
=
9102 (struct signatured_type
*) per_cu
;
9104 sprintf (buf
, "TU %s at offset %s",
9105 hex_string (sig_type
->signature
),
9106 sect_offset_str (per_cu
->sect_off
));
9107 /* There can be 100s of TUs.
9108 Only print them in verbose mode. */
9109 debug_print_threshold
= 2;
9113 sprintf (buf
, "CU at offset %s",
9114 sect_offset_str (per_cu
->sect_off
));
9115 debug_print_threshold
= 1;
9118 if (dwarf_read_debug
>= debug_print_threshold
)
9119 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9121 if (per_cu
->is_debug_types
)
9122 process_full_type_unit (cu
, item
.pretend_language
);
9124 process_full_comp_unit (cu
, item
.pretend_language
);
9126 if (dwarf_read_debug
>= debug_print_threshold
)
9127 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9132 per_objfile
->per_bfd
->queue
.pop ();
9135 if (dwarf_read_debug
)
9137 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9138 objfile_name (per_objfile
->objfile
));
9142 /* Read in full symbols for PST, and anything it depends on. */
9145 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9147 gdb_assert (!readin_p (objfile
));
9149 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9150 free_cached_comp_units
freer (per_objfile
);
9151 expand_dependencies (objfile
);
9153 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9154 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9157 /* See psympriv.h. */
9160 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9162 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9163 return per_objfile
->symtab_set_p (per_cu_data
);
9166 /* See psympriv.h. */
9169 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9171 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9172 return per_objfile
->get_symtab (per_cu_data
);
9175 /* Trivial hash function for die_info: the hash value of a DIE
9176 is its offset in .debug_info for this objfile. */
9179 die_hash (const void *item
)
9181 const struct die_info
*die
= (const struct die_info
*) item
;
9183 return to_underlying (die
->sect_off
);
9186 /* Trivial comparison function for die_info structures: two DIEs
9187 are equal if they have the same offset. */
9190 die_eq (const void *item_lhs
, const void *item_rhs
)
9192 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9193 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9195 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9198 /* Load the DIEs associated with PER_CU into memory. */
9201 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9202 dwarf2_per_objfile
*per_objfile
,
9204 enum language pretend_language
)
9206 gdb_assert (! this_cu
->is_debug_types
);
9208 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9209 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9213 struct dwarf2_cu
*cu
= reader
.cu
;
9214 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9216 gdb_assert (cu
->die_hash
== NULL
);
9218 htab_create_alloc_ex (cu
->header
.length
/ 12,
9222 &cu
->comp_unit_obstack
,
9223 hashtab_obstack_allocate
,
9224 dummy_obstack_deallocate
);
9226 if (reader
.comp_unit_die
->has_children
)
9227 reader
.comp_unit_die
->child
9228 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9229 &info_ptr
, reader
.comp_unit_die
);
9230 cu
->dies
= reader
.comp_unit_die
;
9231 /* comp_unit_die is not stored in die_hash, no need. */
9233 /* We try not to read any attributes in this function, because not
9234 all CUs needed for references have been loaded yet, and symbol
9235 table processing isn't initialized. But we have to set the CU language,
9236 or we won't be able to build types correctly.
9237 Similarly, if we do not read the producer, we can not apply
9238 producer-specific interpretation. */
9239 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9244 /* Add a DIE to the delayed physname list. */
9247 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9248 const char *name
, struct die_info
*die
,
9249 struct dwarf2_cu
*cu
)
9251 struct delayed_method_info mi
;
9253 mi
.fnfield_index
= fnfield_index
;
9257 cu
->method_list
.push_back (mi
);
9260 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9261 "const" / "volatile". If so, decrements LEN by the length of the
9262 modifier and return true. Otherwise return false. */
9266 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9268 size_t mod_len
= sizeof (mod
) - 1;
9269 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9277 /* Compute the physnames of any methods on the CU's method list.
9279 The computation of method physnames is delayed in order to avoid the
9280 (bad) condition that one of the method's formal parameters is of an as yet
9284 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9286 /* Only C++ delays computing physnames. */
9287 if (cu
->method_list
.empty ())
9289 gdb_assert (cu
->language
== language_cplus
);
9291 for (const delayed_method_info
&mi
: cu
->method_list
)
9293 const char *physname
;
9294 struct fn_fieldlist
*fn_flp
9295 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9296 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9297 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9298 = physname
? physname
: "";
9300 /* Since there's no tag to indicate whether a method is a
9301 const/volatile overload, extract that information out of the
9303 if (physname
!= NULL
)
9305 size_t len
= strlen (physname
);
9309 if (physname
[len
] == ')') /* shortcut */
9311 else if (check_modifier (physname
, len
, " const"))
9312 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9313 else if (check_modifier (physname
, len
, " volatile"))
9314 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9321 /* The list is no longer needed. */
9322 cu
->method_list
.clear ();
9325 /* Go objects should be embedded in a DW_TAG_module DIE,
9326 and it's not clear if/how imported objects will appear.
9327 To keep Go support simple until that's worked out,
9328 go back through what we've read and create something usable.
9329 We could do this while processing each DIE, and feels kinda cleaner,
9330 but that way is more invasive.
9331 This is to, for example, allow the user to type "p var" or "b main"
9332 without having to specify the package name, and allow lookups
9333 of module.object to work in contexts that use the expression
9337 fixup_go_packaging (struct dwarf2_cu
*cu
)
9339 gdb::unique_xmalloc_ptr
<char> package_name
;
9340 struct pending
*list
;
9343 for (list
= *cu
->get_builder ()->get_global_symbols ();
9347 for (i
= 0; i
< list
->nsyms
; ++i
)
9349 struct symbol
*sym
= list
->symbol
[i
];
9351 if (sym
->language () == language_go
9352 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9354 gdb::unique_xmalloc_ptr
<char> this_package_name
9355 (go_symbol_package_name (sym
));
9357 if (this_package_name
== NULL
)
9359 if (package_name
== NULL
)
9360 package_name
= std::move (this_package_name
);
9363 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9364 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9365 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9366 (symbol_symtab (sym
) != NULL
9367 ? symtab_to_filename_for_display
9368 (symbol_symtab (sym
))
9369 : objfile_name (objfile
)),
9370 this_package_name
.get (), package_name
.get ());
9376 if (package_name
!= NULL
)
9378 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9379 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9380 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9381 saved_package_name
);
9384 sym
= new (&objfile
->objfile_obstack
) symbol
;
9385 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9386 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9387 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9388 e.g., "main" finds the "main" module and not C's main(). */
9389 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9390 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9391 SYMBOL_TYPE (sym
) = type
;
9393 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9397 /* Allocate a fully-qualified name consisting of the two parts on the
9401 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9403 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9406 /* A helper that allocates a variant part to attach to a Rust enum
9407 type. OBSTACK is where the results should be allocated. TYPE is
9408 the type we're processing. DISCRIMINANT_INDEX is the index of the
9409 discriminant. It must be the index of one of the fields of TYPE.
9410 DEFAULT_INDEX is the index of the default field; or -1 if there is
9411 no default. RANGES is indexed by "effective" field number (the
9412 field index, but omitting the discriminant and default fields) and
9413 must hold the discriminant values used by the variants. Note that
9414 RANGES must have a lifetime at least as long as OBSTACK -- either
9415 already allocated on it, or static. */
9418 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9419 int discriminant_index
, int default_index
,
9420 gdb::array_view
<discriminant_range
> ranges
)
9422 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9423 must be handled by the caller. */
9424 gdb_assert (discriminant_index
>= 0
9425 && discriminant_index
< type
->num_fields ());
9426 gdb_assert (default_index
== -1
9427 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9429 /* We have one variant for each non-discriminant field. */
9430 int n_variants
= type
->num_fields () - 1;
9432 variant
*variants
= new (obstack
) variant
[n_variants
];
9435 for (int i
= 0; i
< type
->num_fields (); ++i
)
9437 if (i
== discriminant_index
)
9440 variants
[var_idx
].first_field
= i
;
9441 variants
[var_idx
].last_field
= i
+ 1;
9443 /* The default field does not need a range, but other fields do.
9444 We skipped the discriminant above. */
9445 if (i
!= default_index
)
9447 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9454 gdb_assert (range_idx
== ranges
.size ());
9455 gdb_assert (var_idx
== n_variants
);
9457 variant_part
*part
= new (obstack
) variant_part
;
9458 part
->discriminant_index
= discriminant_index
;
9459 part
->is_unsigned
= TYPE_UNSIGNED (type
->field (discriminant_index
).type ());
9460 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9462 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9463 gdb::array_view
<variant_part
> *prop_value
9464 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9466 struct dynamic_prop prop
;
9467 prop
.kind
= PROP_VARIANT_PARTS
;
9468 prop
.data
.variant_parts
= prop_value
;
9470 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9473 /* Some versions of rustc emitted enums in an unusual way.
9475 Ordinary enums were emitted as unions. The first element of each
9476 structure in the union was named "RUST$ENUM$DISR". This element
9477 held the discriminant.
9479 These versions of Rust also implemented the "non-zero"
9480 optimization. When the enum had two values, and one is empty and
9481 the other holds a pointer that cannot be zero, the pointer is used
9482 as the discriminant, with a zero value meaning the empty variant.
9483 Here, the union's first member is of the form
9484 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9485 where the fieldnos are the indices of the fields that should be
9486 traversed in order to find the field (which may be several fields deep)
9487 and the variantname is the name of the variant of the case when the
9490 This function recognizes whether TYPE is of one of these forms,
9491 and, if so, smashes it to be a variant type. */
9494 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9496 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9498 /* We don't need to deal with empty enums. */
9499 if (type
->num_fields () == 0)
9502 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9503 if (type
->num_fields () == 1
9504 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9506 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9508 /* Decode the field name to find the offset of the
9510 ULONGEST bit_offset
= 0;
9511 struct type
*field_type
= type
->field (0).type ();
9512 while (name
[0] >= '0' && name
[0] <= '9')
9515 unsigned long index
= strtoul (name
, &tail
, 10);
9518 || index
>= field_type
->num_fields ()
9519 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9520 != FIELD_LOC_KIND_BITPOS
))
9522 complaint (_("Could not parse Rust enum encoding string \"%s\""
9524 TYPE_FIELD_NAME (type
, 0),
9525 objfile_name (objfile
));
9530 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9531 field_type
= field_type
->field (index
).type ();
9534 /* Smash this type to be a structure type. We have to do this
9535 because the type has already been recorded. */
9536 type
->set_code (TYPE_CODE_STRUCT
);
9537 type
->set_num_fields (3);
9538 /* Save the field we care about. */
9539 struct field saved_field
= type
->field (0);
9541 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9543 /* Put the discriminant at index 0. */
9544 type
->field (0).set_type (field_type
);
9545 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9546 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9547 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9549 /* The order of fields doesn't really matter, so put the real
9550 field at index 1 and the data-less field at index 2. */
9551 type
->field (1) = saved_field
;
9552 TYPE_FIELD_NAME (type
, 1)
9553 = rust_last_path_segment (type
->field (1).type ()->name ());
9554 type
->field (1).type ()->set_name
9555 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9556 TYPE_FIELD_NAME (type
, 1)));
9558 const char *dataless_name
9559 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9561 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9563 type
->field (2).set_type (dataless_type
);
9564 /* NAME points into the original discriminant name, which
9565 already has the correct lifetime. */
9566 TYPE_FIELD_NAME (type
, 2) = name
;
9567 SET_FIELD_BITPOS (type
->field (2), 0);
9569 /* Indicate that this is a variant type. */
9570 static discriminant_range ranges
[1] = { { 0, 0 } };
9571 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9573 /* A union with a single anonymous field is probably an old-style
9575 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9577 /* Smash this type to be a structure type. We have to do this
9578 because the type has already been recorded. */
9579 type
->set_code (TYPE_CODE_STRUCT
);
9581 struct type
*field_type
= type
->field (0).type ();
9582 const char *variant_name
9583 = rust_last_path_segment (field_type
->name ());
9584 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9585 field_type
->set_name
9586 (rust_fully_qualify (&objfile
->objfile_obstack
,
9587 type
->name (), variant_name
));
9591 struct type
*disr_type
= nullptr;
9592 for (int i
= 0; i
< type
->num_fields (); ++i
)
9594 disr_type
= type
->field (i
).type ();
9596 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9598 /* All fields of a true enum will be structs. */
9601 else if (disr_type
->num_fields () == 0)
9603 /* Could be data-less variant, so keep going. */
9604 disr_type
= nullptr;
9606 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9607 "RUST$ENUM$DISR") != 0)
9609 /* Not a Rust enum. */
9619 /* If we got here without a discriminant, then it's probably
9621 if (disr_type
== nullptr)
9624 /* Smash this type to be a structure type. We have to do this
9625 because the type has already been recorded. */
9626 type
->set_code (TYPE_CODE_STRUCT
);
9628 /* Make space for the discriminant field. */
9629 struct field
*disr_field
= &disr_type
->field (0);
9631 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9632 * sizeof (struct field
)));
9633 memcpy (new_fields
+ 1, type
->fields (),
9634 type
->num_fields () * sizeof (struct field
));
9635 type
->set_fields (new_fields
);
9636 type
->set_num_fields (type
->num_fields () + 1);
9638 /* Install the discriminant at index 0 in the union. */
9639 type
->field (0) = *disr_field
;
9640 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9641 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9643 /* We need a way to find the correct discriminant given a
9644 variant name. For convenience we build a map here. */
9645 struct type
*enum_type
= disr_field
->type ();
9646 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9647 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9649 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9652 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9653 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9657 int n_fields
= type
->num_fields ();
9658 /* We don't need a range entry for the discriminant, but we do
9659 need one for every other field, as there is no default
9661 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9664 /* Skip the discriminant here. */
9665 for (int i
= 1; i
< n_fields
; ++i
)
9667 /* Find the final word in the name of this variant's type.
9668 That name can be used to look up the correct
9670 const char *variant_name
9671 = rust_last_path_segment (type
->field (i
).type ()->name ());
9673 auto iter
= discriminant_map
.find (variant_name
);
9674 if (iter
!= discriminant_map
.end ())
9676 ranges
[i
].low
= iter
->second
;
9677 ranges
[i
].high
= iter
->second
;
9680 /* Remove the discriminant field, if it exists. */
9681 struct type
*sub_type
= type
->field (i
).type ();
9682 if (sub_type
->num_fields () > 0)
9684 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9685 sub_type
->set_fields (sub_type
->fields () + 1);
9687 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9689 (rust_fully_qualify (&objfile
->objfile_obstack
,
9690 type
->name (), variant_name
));
9693 /* Indicate that this is a variant type. */
9694 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9695 gdb::array_view
<discriminant_range
> (ranges
,
9700 /* Rewrite some Rust unions to be structures with variants parts. */
9703 rust_union_quirks (struct dwarf2_cu
*cu
)
9705 gdb_assert (cu
->language
== language_rust
);
9706 for (type
*type_
: cu
->rust_unions
)
9707 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9708 /* We don't need this any more. */
9709 cu
->rust_unions
.clear ();
9714 type_unit_group_unshareable
*
9715 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9717 auto iter
= this->m_type_units
.find (tu_group
);
9718 if (iter
!= this->m_type_units
.end ())
9719 return iter
->second
.get ();
9721 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9722 type_unit_group_unshareable
*result
= uniq
.get ();
9723 this->m_type_units
[tu_group
] = std::move (uniq
);
9728 dwarf2_per_objfile::get_type_for_signatured_type
9729 (signatured_type
*sig_type
) const
9731 auto iter
= this->m_type_map
.find (sig_type
);
9732 if (iter
== this->m_type_map
.end ())
9735 return iter
->second
;
9738 void dwarf2_per_objfile::set_type_for_signatured_type
9739 (signatured_type
*sig_type
, struct type
*type
)
9741 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9743 this->m_type_map
[sig_type
] = type
;
9746 /* A helper function for computing the list of all symbol tables
9747 included by PER_CU. */
9750 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9751 htab_t all_children
, htab_t all_type_symtabs
,
9752 dwarf2_per_cu_data
*per_cu
,
9753 dwarf2_per_objfile
*per_objfile
,
9754 struct compunit_symtab
*immediate_parent
)
9756 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9759 /* This inclusion and its children have been processed. */
9765 /* Only add a CU if it has a symbol table. */
9766 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9769 /* If this is a type unit only add its symbol table if we haven't
9770 seen it yet (type unit per_cu's can share symtabs). */
9771 if (per_cu
->is_debug_types
)
9773 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9777 result
->push_back (cust
);
9778 if (cust
->user
== NULL
)
9779 cust
->user
= immediate_parent
;
9784 result
->push_back (cust
);
9785 if (cust
->user
== NULL
)
9786 cust
->user
= immediate_parent
;
9790 if (!per_cu
->imported_symtabs_empty ())
9791 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9793 recursively_compute_inclusions (result
, all_children
,
9794 all_type_symtabs
, ptr
, per_objfile
,
9799 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9803 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9804 dwarf2_per_objfile
*per_objfile
)
9806 gdb_assert (! per_cu
->is_debug_types
);
9808 if (!per_cu
->imported_symtabs_empty ())
9811 std::vector
<compunit_symtab
*> result_symtabs
;
9812 htab_t all_children
, all_type_symtabs
;
9813 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9815 /* If we don't have a symtab, we can just skip this case. */
9819 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9820 NULL
, xcalloc
, xfree
);
9821 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9822 NULL
, xcalloc
, xfree
);
9824 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9826 recursively_compute_inclusions (&result_symtabs
, all_children
,
9827 all_type_symtabs
, ptr
, per_objfile
,
9831 /* Now we have a transitive closure of all the included symtabs. */
9832 len
= result_symtabs
.size ();
9834 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9835 struct compunit_symtab
*, len
+ 1);
9836 memcpy (cust
->includes
, result_symtabs
.data (),
9837 len
* sizeof (compunit_symtab
*));
9838 cust
->includes
[len
] = NULL
;
9840 htab_delete (all_children
);
9841 htab_delete (all_type_symtabs
);
9845 /* Compute the 'includes' field for the symtabs of all the CUs we just
9849 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9851 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9853 if (! iter
->is_debug_types
)
9854 compute_compunit_symtab_includes (iter
, per_objfile
);
9857 per_objfile
->per_bfd
->just_read_cus
.clear ();
9860 /* Generate full symbol information for CU, whose DIEs have
9861 already been loaded into memory. */
9864 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9866 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9867 struct objfile
*objfile
= per_objfile
->objfile
;
9868 struct gdbarch
*gdbarch
= objfile
->arch ();
9869 CORE_ADDR lowpc
, highpc
;
9870 struct compunit_symtab
*cust
;
9872 struct block
*static_block
;
9875 baseaddr
= objfile
->text_section_offset ();
9877 /* Clear the list here in case something was left over. */
9878 cu
->method_list
.clear ();
9880 cu
->language
= pretend_language
;
9881 cu
->language_defn
= language_def (cu
->language
);
9883 /* Do line number decoding in read_file_scope () */
9884 process_die (cu
->dies
, cu
);
9886 /* For now fudge the Go package. */
9887 if (cu
->language
== language_go
)
9888 fixup_go_packaging (cu
);
9890 /* Now that we have processed all the DIEs in the CU, all the types
9891 should be complete, and it should now be safe to compute all of the
9893 compute_delayed_physnames (cu
);
9895 if (cu
->language
== language_rust
)
9896 rust_union_quirks (cu
);
9898 /* Some compilers don't define a DW_AT_high_pc attribute for the
9899 compilation unit. If the DW_AT_high_pc is missing, synthesize
9900 it, by scanning the DIE's below the compilation unit. */
9901 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9903 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9904 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9906 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9907 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9908 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9909 addrmap to help ensure it has an accurate map of pc values belonging to
9911 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9913 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9914 SECT_OFF_TEXT (objfile
),
9919 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9921 /* Set symtab language to language from DW_AT_language. If the
9922 compilation is from a C file generated by language preprocessors, do
9923 not set the language if it was already deduced by start_subfile. */
9924 if (!(cu
->language
== language_c
9925 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9926 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9928 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9929 produce DW_AT_location with location lists but it can be possibly
9930 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9931 there were bugs in prologue debug info, fixed later in GCC-4.5
9932 by "unwind info for epilogues" patch (which is not directly related).
9934 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9935 needed, it would be wrong due to missing DW_AT_producer there.
9937 Still one can confuse GDB by using non-standard GCC compilation
9938 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9940 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9941 cust
->locations_valid
= 1;
9943 if (gcc_4_minor
>= 5)
9944 cust
->epilogue_unwind_valid
= 1;
9946 cust
->call_site_htab
= cu
->call_site_htab
;
9949 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9951 /* Push it for inclusion processing later. */
9952 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9954 /* Not needed any more. */
9955 cu
->reset_builder ();
9958 /* Generate full symbol information for type unit CU, whose DIEs have
9959 already been loaded into memory. */
9962 process_full_type_unit (dwarf2_cu
*cu
,
9963 enum language pretend_language
)
9965 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9966 struct objfile
*objfile
= per_objfile
->objfile
;
9967 struct compunit_symtab
*cust
;
9968 struct signatured_type
*sig_type
;
9970 gdb_assert (cu
->per_cu
->is_debug_types
);
9971 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9973 /* Clear the list here in case something was left over. */
9974 cu
->method_list
.clear ();
9976 cu
->language
= pretend_language
;
9977 cu
->language_defn
= language_def (cu
->language
);
9979 /* The symbol tables are set up in read_type_unit_scope. */
9980 process_die (cu
->dies
, cu
);
9982 /* For now fudge the Go package. */
9983 if (cu
->language
== language_go
)
9984 fixup_go_packaging (cu
);
9986 /* Now that we have processed all the DIEs in the CU, all the types
9987 should be complete, and it should now be safe to compute all of the
9989 compute_delayed_physnames (cu
);
9991 if (cu
->language
== language_rust
)
9992 rust_union_quirks (cu
);
9994 /* TUs share symbol tables.
9995 If this is the first TU to use this symtab, complete the construction
9996 of it with end_expandable_symtab. Otherwise, complete the addition of
9997 this TU's symbols to the existing symtab. */
9998 type_unit_group_unshareable
*tug_unshare
=
9999 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10000 if (tug_unshare
->compunit_symtab
== NULL
)
10002 buildsym_compunit
*builder
= cu
->get_builder ();
10003 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10004 tug_unshare
->compunit_symtab
= cust
;
10008 /* Set symtab language to language from DW_AT_language. If the
10009 compilation is from a C file generated by language preprocessors,
10010 do not set the language if it was already deduced by
10012 if (!(cu
->language
== language_c
10013 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10014 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10019 cu
->get_builder ()->augment_type_symtab ();
10020 cust
= tug_unshare
->compunit_symtab
;
10023 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10025 /* Not needed any more. */
10026 cu
->reset_builder ();
10029 /* Process an imported unit DIE. */
10032 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10034 struct attribute
*attr
;
10036 /* For now we don't handle imported units in type units. */
10037 if (cu
->per_cu
->is_debug_types
)
10039 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10040 " supported in type units [in module %s]"),
10041 objfile_name (cu
->per_objfile
->objfile
));
10044 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10047 sect_offset sect_off
= attr
->get_ref_die_offset ();
10048 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10049 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10050 dwarf2_per_cu_data
*per_cu
10051 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10053 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10054 into another compilation unit, at root level. Regard this as a hint,
10056 if (die
->parent
&& die
->parent
->parent
== NULL
10057 && per_cu
->unit_type
== DW_UT_compile
10058 && per_cu
->lang
== language_cplus
)
10061 /* If necessary, add it to the queue and load its DIEs. */
10062 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10063 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
10065 cu
->per_cu
->imported_symtabs_push (per_cu
);
10069 /* RAII object that represents a process_die scope: i.e.,
10070 starts/finishes processing a DIE. */
10071 class process_die_scope
10074 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10075 : m_die (die
), m_cu (cu
)
10077 /* We should only be processing DIEs not already in process. */
10078 gdb_assert (!m_die
->in_process
);
10079 m_die
->in_process
= true;
10082 ~process_die_scope ()
10084 m_die
->in_process
= false;
10086 /* If we're done processing the DIE for the CU that owns the line
10087 header, we don't need the line header anymore. */
10088 if (m_cu
->line_header_die_owner
== m_die
)
10090 delete m_cu
->line_header
;
10091 m_cu
->line_header
= NULL
;
10092 m_cu
->line_header_die_owner
= NULL
;
10101 /* Process a die and its children. */
10104 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10106 process_die_scope
scope (die
, cu
);
10110 case DW_TAG_padding
:
10112 case DW_TAG_compile_unit
:
10113 case DW_TAG_partial_unit
:
10114 read_file_scope (die
, cu
);
10116 case DW_TAG_type_unit
:
10117 read_type_unit_scope (die
, cu
);
10119 case DW_TAG_subprogram
:
10120 /* Nested subprograms in Fortran get a prefix. */
10121 if (cu
->language
== language_fortran
10122 && die
->parent
!= NULL
10123 && die
->parent
->tag
== DW_TAG_subprogram
)
10124 cu
->processing_has_namespace_info
= true;
10125 /* Fall through. */
10126 case DW_TAG_inlined_subroutine
:
10127 read_func_scope (die
, cu
);
10129 case DW_TAG_lexical_block
:
10130 case DW_TAG_try_block
:
10131 case DW_TAG_catch_block
:
10132 read_lexical_block_scope (die
, cu
);
10134 case DW_TAG_call_site
:
10135 case DW_TAG_GNU_call_site
:
10136 read_call_site_scope (die
, cu
);
10138 case DW_TAG_class_type
:
10139 case DW_TAG_interface_type
:
10140 case DW_TAG_structure_type
:
10141 case DW_TAG_union_type
:
10142 process_structure_scope (die
, cu
);
10144 case DW_TAG_enumeration_type
:
10145 process_enumeration_scope (die
, cu
);
10148 /* These dies have a type, but processing them does not create
10149 a symbol or recurse to process the children. Therefore we can
10150 read them on-demand through read_type_die. */
10151 case DW_TAG_subroutine_type
:
10152 case DW_TAG_set_type
:
10153 case DW_TAG_array_type
:
10154 case DW_TAG_pointer_type
:
10155 case DW_TAG_ptr_to_member_type
:
10156 case DW_TAG_reference_type
:
10157 case DW_TAG_rvalue_reference_type
:
10158 case DW_TAG_string_type
:
10161 case DW_TAG_base_type
:
10162 case DW_TAG_subrange_type
:
10163 case DW_TAG_typedef
:
10164 /* Add a typedef symbol for the type definition, if it has a
10166 new_symbol (die
, read_type_die (die
, cu
), cu
);
10168 case DW_TAG_common_block
:
10169 read_common_block (die
, cu
);
10171 case DW_TAG_common_inclusion
:
10173 case DW_TAG_namespace
:
10174 cu
->processing_has_namespace_info
= true;
10175 read_namespace (die
, cu
);
10177 case DW_TAG_module
:
10178 cu
->processing_has_namespace_info
= true;
10179 read_module (die
, cu
);
10181 case DW_TAG_imported_declaration
:
10182 cu
->processing_has_namespace_info
= true;
10183 if (read_namespace_alias (die
, cu
))
10185 /* The declaration is not a global namespace alias. */
10186 /* Fall through. */
10187 case DW_TAG_imported_module
:
10188 cu
->processing_has_namespace_info
= true;
10189 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10190 || cu
->language
!= language_fortran
))
10191 complaint (_("Tag '%s' has unexpected children"),
10192 dwarf_tag_name (die
->tag
));
10193 read_import_statement (die
, cu
);
10196 case DW_TAG_imported_unit
:
10197 process_imported_unit_die (die
, cu
);
10200 case DW_TAG_variable
:
10201 read_variable (die
, cu
);
10205 new_symbol (die
, NULL
, cu
);
10210 /* DWARF name computation. */
10212 /* A helper function for dwarf2_compute_name which determines whether DIE
10213 needs to have the name of the scope prepended to the name listed in the
10217 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10219 struct attribute
*attr
;
10223 case DW_TAG_namespace
:
10224 case DW_TAG_typedef
:
10225 case DW_TAG_class_type
:
10226 case DW_TAG_interface_type
:
10227 case DW_TAG_structure_type
:
10228 case DW_TAG_union_type
:
10229 case DW_TAG_enumeration_type
:
10230 case DW_TAG_enumerator
:
10231 case DW_TAG_subprogram
:
10232 case DW_TAG_inlined_subroutine
:
10233 case DW_TAG_member
:
10234 case DW_TAG_imported_declaration
:
10237 case DW_TAG_variable
:
10238 case DW_TAG_constant
:
10239 /* We only need to prefix "globally" visible variables. These include
10240 any variable marked with DW_AT_external or any variable that
10241 lives in a namespace. [Variables in anonymous namespaces
10242 require prefixing, but they are not DW_AT_external.] */
10244 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10246 struct dwarf2_cu
*spec_cu
= cu
;
10248 return die_needs_namespace (die_specification (die
, &spec_cu
),
10252 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10253 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10254 && die
->parent
->tag
!= DW_TAG_module
)
10256 /* A variable in a lexical block of some kind does not need a
10257 namespace, even though in C++ such variables may be external
10258 and have a mangled name. */
10259 if (die
->parent
->tag
== DW_TAG_lexical_block
10260 || die
->parent
->tag
== DW_TAG_try_block
10261 || die
->parent
->tag
== DW_TAG_catch_block
10262 || die
->parent
->tag
== DW_TAG_subprogram
)
10271 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10272 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10273 defined for the given DIE. */
10275 static struct attribute
*
10276 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10278 struct attribute
*attr
;
10280 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10282 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10287 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10288 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10289 defined for the given DIE. */
10291 static const char *
10292 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10294 const char *linkage_name
;
10296 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10297 if (linkage_name
== NULL
)
10298 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10300 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10301 See https://github.com/rust-lang/rust/issues/32925. */
10302 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10303 && strchr (linkage_name
, '{') != NULL
)
10304 linkage_name
= NULL
;
10306 return linkage_name
;
10309 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10310 compute the physname for the object, which include a method's:
10311 - formal parameters (C++),
10312 - receiver type (Go),
10314 The term "physname" is a bit confusing.
10315 For C++, for example, it is the demangled name.
10316 For Go, for example, it's the mangled name.
10318 For Ada, return the DIE's linkage name rather than the fully qualified
10319 name. PHYSNAME is ignored..
10321 The result is allocated on the objfile->per_bfd's obstack and
10324 static const char *
10325 dwarf2_compute_name (const char *name
,
10326 struct die_info
*die
, struct dwarf2_cu
*cu
,
10329 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10332 name
= dwarf2_name (die
, cu
);
10334 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10335 but otherwise compute it by typename_concat inside GDB.
10336 FIXME: Actually this is not really true, or at least not always true.
10337 It's all very confusing. compute_and_set_names doesn't try to demangle
10338 Fortran names because there is no mangling standard. So new_symbol
10339 will set the demangled name to the result of dwarf2_full_name, and it is
10340 the demangled name that GDB uses if it exists. */
10341 if (cu
->language
== language_ada
10342 || (cu
->language
== language_fortran
&& physname
))
10344 /* For Ada unit, we prefer the linkage name over the name, as
10345 the former contains the exported name, which the user expects
10346 to be able to reference. Ideally, we want the user to be able
10347 to reference this entity using either natural or linkage name,
10348 but we haven't started looking at this enhancement yet. */
10349 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10351 if (linkage_name
!= NULL
)
10352 return linkage_name
;
10355 /* These are the only languages we know how to qualify names in. */
10357 && (cu
->language
== language_cplus
10358 || cu
->language
== language_fortran
|| cu
->language
== language_d
10359 || cu
->language
== language_rust
))
10361 if (die_needs_namespace (die
, cu
))
10363 const char *prefix
;
10364 const char *canonical_name
= NULL
;
10368 prefix
= determine_prefix (die
, cu
);
10369 if (*prefix
!= '\0')
10371 gdb::unique_xmalloc_ptr
<char> prefixed_name
10372 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10374 buf
.puts (prefixed_name
.get ());
10379 /* Template parameters may be specified in the DIE's DW_AT_name, or
10380 as children with DW_TAG_template_type_param or
10381 DW_TAG_value_type_param. If the latter, add them to the name
10382 here. If the name already has template parameters, then
10383 skip this step; some versions of GCC emit both, and
10384 it is more efficient to use the pre-computed name.
10386 Something to keep in mind about this process: it is very
10387 unlikely, or in some cases downright impossible, to produce
10388 something that will match the mangled name of a function.
10389 If the definition of the function has the same debug info,
10390 we should be able to match up with it anyway. But fallbacks
10391 using the minimal symbol, for instance to find a method
10392 implemented in a stripped copy of libstdc++, will not work.
10393 If we do not have debug info for the definition, we will have to
10394 match them up some other way.
10396 When we do name matching there is a related problem with function
10397 templates; two instantiated function templates are allowed to
10398 differ only by their return types, which we do not add here. */
10400 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10402 struct attribute
*attr
;
10403 struct die_info
*child
;
10406 die
->building_fullname
= 1;
10408 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10412 const gdb_byte
*bytes
;
10413 struct dwarf2_locexpr_baton
*baton
;
10416 if (child
->tag
!= DW_TAG_template_type_param
10417 && child
->tag
!= DW_TAG_template_value_param
)
10428 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10431 complaint (_("template parameter missing DW_AT_type"));
10432 buf
.puts ("UNKNOWN_TYPE");
10435 type
= die_type (child
, cu
);
10437 if (child
->tag
== DW_TAG_template_type_param
)
10439 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10440 &type_print_raw_options
);
10444 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10447 complaint (_("template parameter missing "
10448 "DW_AT_const_value"));
10449 buf
.puts ("UNKNOWN_VALUE");
10453 dwarf2_const_value_attr (attr
, type
, name
,
10454 &cu
->comp_unit_obstack
, cu
,
10455 &value
, &bytes
, &baton
);
10457 if (TYPE_NOSIGN (type
))
10458 /* GDB prints characters as NUMBER 'CHAR'. If that's
10459 changed, this can use value_print instead. */
10460 c_printchar (value
, type
, &buf
);
10463 struct value_print_options opts
;
10466 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10470 baton
->per_objfile
);
10471 else if (bytes
!= NULL
)
10473 v
= allocate_value (type
);
10474 memcpy (value_contents_writeable (v
), bytes
,
10475 TYPE_LENGTH (type
));
10478 v
= value_from_longest (type
, value
);
10480 /* Specify decimal so that we do not depend on
10482 get_formatted_print_options (&opts
, 'd');
10484 value_print (v
, &buf
, &opts
);
10489 die
->building_fullname
= 0;
10493 /* Close the argument list, with a space if necessary
10494 (nested templates). */
10495 if (!buf
.empty () && buf
.string ().back () == '>')
10502 /* For C++ methods, append formal parameter type
10503 information, if PHYSNAME. */
10505 if (physname
&& die
->tag
== DW_TAG_subprogram
10506 && cu
->language
== language_cplus
)
10508 struct type
*type
= read_type_die (die
, cu
);
10510 c_type_print_args (type
, &buf
, 1, cu
->language
,
10511 &type_print_raw_options
);
10513 if (cu
->language
== language_cplus
)
10515 /* Assume that an artificial first parameter is
10516 "this", but do not crash if it is not. RealView
10517 marks unnamed (and thus unused) parameters as
10518 artificial; there is no way to differentiate
10520 if (type
->num_fields () > 0
10521 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10522 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10523 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10524 buf
.puts (" const");
10528 const std::string
&intermediate_name
= buf
.string ();
10530 if (cu
->language
== language_cplus
)
10532 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10535 /* If we only computed INTERMEDIATE_NAME, or if
10536 INTERMEDIATE_NAME is already canonical, then we need to
10538 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10539 name
= objfile
->intern (intermediate_name
);
10541 name
= canonical_name
;
10548 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10549 If scope qualifiers are appropriate they will be added. The result
10550 will be allocated on the storage_obstack, or NULL if the DIE does
10551 not have a name. NAME may either be from a previous call to
10552 dwarf2_name or NULL.
10554 The output string will be canonicalized (if C++). */
10556 static const char *
10557 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10559 return dwarf2_compute_name (name
, die
, cu
, 0);
10562 /* Construct a physname for the given DIE in CU. NAME may either be
10563 from a previous call to dwarf2_name or NULL. The result will be
10564 allocated on the objfile_objstack or NULL if the DIE does not have a
10567 The output string will be canonicalized (if C++). */
10569 static const char *
10570 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10572 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10573 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10576 /* In this case dwarf2_compute_name is just a shortcut not building anything
10578 if (!die_needs_namespace (die
, cu
))
10579 return dwarf2_compute_name (name
, die
, cu
, 1);
10581 if (cu
->language
!= language_rust
)
10582 mangled
= dw2_linkage_name (die
, cu
);
10584 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10586 gdb::unique_xmalloc_ptr
<char> demangled
;
10587 if (mangled
!= NULL
)
10590 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10592 /* Do nothing (do not demangle the symbol name). */
10594 else if (cu
->language
== language_go
)
10596 /* This is a lie, but we already lie to the caller new_symbol.
10597 new_symbol assumes we return the mangled name.
10598 This just undoes that lie until things are cleaned up. */
10602 /* Use DMGL_RET_DROP for C++ template functions to suppress
10603 their return type. It is easier for GDB users to search
10604 for such functions as `name(params)' than `long name(params)'.
10605 In such case the minimal symbol names do not match the full
10606 symbol names but for template functions there is never a need
10607 to look up their definition from their declaration so
10608 the only disadvantage remains the minimal symbol variant
10609 `long name(params)' does not have the proper inferior type. */
10610 demangled
.reset (gdb_demangle (mangled
,
10611 (DMGL_PARAMS
| DMGL_ANSI
10612 | DMGL_RET_DROP
)));
10615 canon
= demangled
.get ();
10623 if (canon
== NULL
|| check_physname
)
10625 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10627 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10629 /* It may not mean a bug in GDB. The compiler could also
10630 compute DW_AT_linkage_name incorrectly. But in such case
10631 GDB would need to be bug-to-bug compatible. */
10633 complaint (_("Computed physname <%s> does not match demangled <%s> "
10634 "(from linkage <%s>) - DIE at %s [in module %s]"),
10635 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10636 objfile_name (objfile
));
10638 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10639 is available here - over computed PHYSNAME. It is safer
10640 against both buggy GDB and buggy compilers. */
10654 retval
= objfile
->intern (retval
);
10659 /* Inspect DIE in CU for a namespace alias. If one exists, record
10660 a new symbol for it.
10662 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10665 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10667 struct attribute
*attr
;
10669 /* If the die does not have a name, this is not a namespace
10671 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10675 struct die_info
*d
= die
;
10676 struct dwarf2_cu
*imported_cu
= cu
;
10678 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10679 keep inspecting DIEs until we hit the underlying import. */
10680 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10681 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10683 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10687 d
= follow_die_ref (d
, attr
, &imported_cu
);
10688 if (d
->tag
!= DW_TAG_imported_declaration
)
10692 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10694 complaint (_("DIE at %s has too many recursively imported "
10695 "declarations"), sect_offset_str (d
->sect_off
));
10702 sect_offset sect_off
= attr
->get_ref_die_offset ();
10704 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10705 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10707 /* This declaration is a global namespace alias. Add
10708 a symbol for it whose type is the aliased namespace. */
10709 new_symbol (die
, type
, cu
);
10718 /* Return the using directives repository (global or local?) to use in the
10719 current context for CU.
10721 For Ada, imported declarations can materialize renamings, which *may* be
10722 global. However it is impossible (for now?) in DWARF to distinguish
10723 "external" imported declarations and "static" ones. As all imported
10724 declarations seem to be static in all other languages, make them all CU-wide
10725 global only in Ada. */
10727 static struct using_direct
**
10728 using_directives (struct dwarf2_cu
*cu
)
10730 if (cu
->language
== language_ada
10731 && cu
->get_builder ()->outermost_context_p ())
10732 return cu
->get_builder ()->get_global_using_directives ();
10734 return cu
->get_builder ()->get_local_using_directives ();
10737 /* Read the import statement specified by the given die and record it. */
10740 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10742 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10743 struct attribute
*import_attr
;
10744 struct die_info
*imported_die
, *child_die
;
10745 struct dwarf2_cu
*imported_cu
;
10746 const char *imported_name
;
10747 const char *imported_name_prefix
;
10748 const char *canonical_name
;
10749 const char *import_alias
;
10750 const char *imported_declaration
= NULL
;
10751 const char *import_prefix
;
10752 std::vector
<const char *> excludes
;
10754 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10755 if (import_attr
== NULL
)
10757 complaint (_("Tag '%s' has no DW_AT_import"),
10758 dwarf_tag_name (die
->tag
));
10763 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10764 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10765 if (imported_name
== NULL
)
10767 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10769 The import in the following code:
10783 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10784 <52> DW_AT_decl_file : 1
10785 <53> DW_AT_decl_line : 6
10786 <54> DW_AT_import : <0x75>
10787 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10788 <59> DW_AT_name : B
10789 <5b> DW_AT_decl_file : 1
10790 <5c> DW_AT_decl_line : 2
10791 <5d> DW_AT_type : <0x6e>
10793 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10794 <76> DW_AT_byte_size : 4
10795 <77> DW_AT_encoding : 5 (signed)
10797 imports the wrong die ( 0x75 instead of 0x58 ).
10798 This case will be ignored until the gcc bug is fixed. */
10802 /* Figure out the local name after import. */
10803 import_alias
= dwarf2_name (die
, cu
);
10805 /* Figure out where the statement is being imported to. */
10806 import_prefix
= determine_prefix (die
, cu
);
10808 /* Figure out what the scope of the imported die is and prepend it
10809 to the name of the imported die. */
10810 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10812 if (imported_die
->tag
!= DW_TAG_namespace
10813 && imported_die
->tag
!= DW_TAG_module
)
10815 imported_declaration
= imported_name
;
10816 canonical_name
= imported_name_prefix
;
10818 else if (strlen (imported_name_prefix
) > 0)
10819 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10820 imported_name_prefix
,
10821 (cu
->language
== language_d
? "." : "::"),
10822 imported_name
, (char *) NULL
);
10824 canonical_name
= imported_name
;
10826 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10827 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10828 child_die
= child_die
->sibling
)
10830 /* DWARF-4: A Fortran use statement with a “rename list” may be
10831 represented by an imported module entry with an import attribute
10832 referring to the module and owned entries corresponding to those
10833 entities that are renamed as part of being imported. */
10835 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10837 complaint (_("child DW_TAG_imported_declaration expected "
10838 "- DIE at %s [in module %s]"),
10839 sect_offset_str (child_die
->sect_off
),
10840 objfile_name (objfile
));
10844 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10845 if (import_attr
== NULL
)
10847 complaint (_("Tag '%s' has no DW_AT_import"),
10848 dwarf_tag_name (child_die
->tag
));
10853 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10855 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10856 if (imported_name
== NULL
)
10858 complaint (_("child DW_TAG_imported_declaration has unknown "
10859 "imported name - DIE at %s [in module %s]"),
10860 sect_offset_str (child_die
->sect_off
),
10861 objfile_name (objfile
));
10865 excludes
.push_back (imported_name
);
10867 process_die (child_die
, cu
);
10870 add_using_directive (using_directives (cu
),
10874 imported_declaration
,
10877 &objfile
->objfile_obstack
);
10880 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10881 types, but gives them a size of zero. Starting with version 14,
10882 ICC is compatible with GCC. */
10885 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10887 if (!cu
->checked_producer
)
10888 check_producer (cu
);
10890 return cu
->producer_is_icc_lt_14
;
10893 /* ICC generates a DW_AT_type for C void functions. This was observed on
10894 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10895 which says that void functions should not have a DW_AT_type. */
10898 producer_is_icc (struct dwarf2_cu
*cu
)
10900 if (!cu
->checked_producer
)
10901 check_producer (cu
);
10903 return cu
->producer_is_icc
;
10906 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10907 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10908 this, it was first present in GCC release 4.3.0. */
10911 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10913 if (!cu
->checked_producer
)
10914 check_producer (cu
);
10916 return cu
->producer_is_gcc_lt_4_3
;
10919 static file_and_directory
10920 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10922 file_and_directory res
;
10924 /* Find the filename. Do not use dwarf2_name here, since the filename
10925 is not a source language identifier. */
10926 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10927 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10929 if (res
.comp_dir
== NULL
10930 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10931 && IS_ABSOLUTE_PATH (res
.name
))
10933 res
.comp_dir_storage
= ldirname (res
.name
);
10934 if (!res
.comp_dir_storage
.empty ())
10935 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10937 if (res
.comp_dir
!= NULL
)
10939 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10940 directory, get rid of it. */
10941 const char *cp
= strchr (res
.comp_dir
, ':');
10943 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10944 res
.comp_dir
= cp
+ 1;
10947 if (res
.name
== NULL
)
10948 res
.name
= "<unknown>";
10953 /* Handle DW_AT_stmt_list for a compilation unit.
10954 DIE is the DW_TAG_compile_unit die for CU.
10955 COMP_DIR is the compilation directory. LOWPC is passed to
10956 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10959 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10960 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10962 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10963 struct attribute
*attr
;
10964 struct line_header line_header_local
;
10965 hashval_t line_header_local_hash
;
10967 int decode_mapping
;
10969 gdb_assert (! cu
->per_cu
->is_debug_types
);
10971 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10975 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10977 /* The line header hash table is only created if needed (it exists to
10978 prevent redundant reading of the line table for partial_units).
10979 If we're given a partial_unit, we'll need it. If we're given a
10980 compile_unit, then use the line header hash table if it's already
10981 created, but don't create one just yet. */
10983 if (per_objfile
->line_header_hash
== NULL
10984 && die
->tag
== DW_TAG_partial_unit
)
10986 per_objfile
->line_header_hash
10987 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10988 line_header_eq_voidp
,
10989 free_line_header_voidp
,
10993 line_header_local
.sect_off
= line_offset
;
10994 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10995 line_header_local_hash
= line_header_hash (&line_header_local
);
10996 if (per_objfile
->line_header_hash
!= NULL
)
10998 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10999 &line_header_local
,
11000 line_header_local_hash
, NO_INSERT
);
11002 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11003 is not present in *SLOT (since if there is something in *SLOT then
11004 it will be for a partial_unit). */
11005 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11007 gdb_assert (*slot
!= NULL
);
11008 cu
->line_header
= (struct line_header
*) *slot
;
11013 /* dwarf_decode_line_header does not yet provide sufficient information.
11014 We always have to call also dwarf_decode_lines for it. */
11015 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11019 cu
->line_header
= lh
.release ();
11020 cu
->line_header_die_owner
= die
;
11022 if (per_objfile
->line_header_hash
== NULL
)
11026 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11027 &line_header_local
,
11028 line_header_local_hash
, INSERT
);
11029 gdb_assert (slot
!= NULL
);
11031 if (slot
!= NULL
&& *slot
== NULL
)
11033 /* This newly decoded line number information unit will be owned
11034 by line_header_hash hash table. */
11035 *slot
= cu
->line_header
;
11036 cu
->line_header_die_owner
= NULL
;
11040 /* We cannot free any current entry in (*slot) as that struct line_header
11041 may be already used by multiple CUs. Create only temporary decoded
11042 line_header for this CU - it may happen at most once for each line
11043 number information unit. And if we're not using line_header_hash
11044 then this is what we want as well. */
11045 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11047 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11048 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11053 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11056 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11058 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11059 struct objfile
*objfile
= per_objfile
->objfile
;
11060 struct gdbarch
*gdbarch
= objfile
->arch ();
11061 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11062 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11063 struct attribute
*attr
;
11064 struct die_info
*child_die
;
11065 CORE_ADDR baseaddr
;
11067 prepare_one_comp_unit (cu
, die
, cu
->language
);
11068 baseaddr
= objfile
->text_section_offset ();
11070 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11072 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11073 from finish_block. */
11074 if (lowpc
== ((CORE_ADDR
) -1))
11076 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11078 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11080 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11081 standardised yet. As a workaround for the language detection we fall
11082 back to the DW_AT_producer string. */
11083 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11084 cu
->language
= language_opencl
;
11086 /* Similar hack for Go. */
11087 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11088 set_cu_language (DW_LANG_Go
, cu
);
11090 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11092 /* Decode line number information if present. We do this before
11093 processing child DIEs, so that the line header table is available
11094 for DW_AT_decl_file. */
11095 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11097 /* Process all dies in compilation unit. */
11098 if (die
->child
!= NULL
)
11100 child_die
= die
->child
;
11101 while (child_die
&& child_die
->tag
)
11103 process_die (child_die
, cu
);
11104 child_die
= child_die
->sibling
;
11108 /* Decode macro information, if present. Dwarf 2 macro information
11109 refers to information in the line number info statement program
11110 header, so we can only read it if we've read the header
11112 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11114 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11115 if (attr
&& cu
->line_header
)
11117 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11118 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11120 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11124 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11125 if (attr
&& cu
->line_header
)
11127 unsigned int macro_offset
= DW_UNSND (attr
);
11129 dwarf_decode_macros (cu
, macro_offset
, 0);
11135 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11137 struct type_unit_group
*tu_group
;
11139 struct attribute
*attr
;
11141 struct signatured_type
*sig_type
;
11143 gdb_assert (per_cu
->is_debug_types
);
11144 sig_type
= (struct signatured_type
*) per_cu
;
11146 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11148 /* If we're using .gdb_index (includes -readnow) then
11149 per_cu->type_unit_group may not have been set up yet. */
11150 if (sig_type
->type_unit_group
== NULL
)
11151 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11152 tu_group
= sig_type
->type_unit_group
;
11154 /* If we've already processed this stmt_list there's no real need to
11155 do it again, we could fake it and just recreate the part we need
11156 (file name,index -> symtab mapping). If data shows this optimization
11157 is useful we can do it then. */
11158 type_unit_group_unshareable
*tug_unshare
11159 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11160 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11162 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11167 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11168 lh
= dwarf_decode_line_header (line_offset
, this);
11173 start_symtab ("", NULL
, 0);
11176 gdb_assert (tug_unshare
->symtabs
== NULL
);
11177 gdb_assert (m_builder
== nullptr);
11178 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11179 m_builder
.reset (new struct buildsym_compunit
11180 (COMPUNIT_OBJFILE (cust
), "",
11181 COMPUNIT_DIRNAME (cust
),
11182 compunit_language (cust
),
11184 list_in_scope
= get_builder ()->get_file_symbols ();
11189 line_header
= lh
.release ();
11190 line_header_die_owner
= die
;
11194 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11196 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11197 still initializing it, and our caller (a few levels up)
11198 process_full_type_unit still needs to know if this is the first
11201 tug_unshare
->symtabs
11202 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11203 struct symtab
*, line_header
->file_names_size ());
11205 auto &file_names
= line_header
->file_names ();
11206 for (i
= 0; i
< file_names
.size (); ++i
)
11208 file_entry
&fe
= file_names
[i
];
11209 dwarf2_start_subfile (this, fe
.name
,
11210 fe
.include_dir (line_header
));
11211 buildsym_compunit
*b
= get_builder ();
11212 if (b
->get_current_subfile ()->symtab
== NULL
)
11214 /* NOTE: start_subfile will recognize when it's been
11215 passed a file it has already seen. So we can't
11216 assume there's a simple mapping from
11217 cu->line_header->file_names to subfiles, plus
11218 cu->line_header->file_names may contain dups. */
11219 b
->get_current_subfile ()->symtab
11220 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11223 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11224 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11229 gdb_assert (m_builder
== nullptr);
11230 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11231 m_builder
.reset (new struct buildsym_compunit
11232 (COMPUNIT_OBJFILE (cust
), "",
11233 COMPUNIT_DIRNAME (cust
),
11234 compunit_language (cust
),
11236 list_in_scope
= get_builder ()->get_file_symbols ();
11238 auto &file_names
= line_header
->file_names ();
11239 for (i
= 0; i
< file_names
.size (); ++i
)
11241 file_entry
&fe
= file_names
[i
];
11242 fe
.symtab
= tug_unshare
->symtabs
[i
];
11246 /* The main symtab is allocated last. Type units don't have DW_AT_name
11247 so they don't have a "real" (so to speak) symtab anyway.
11248 There is later code that will assign the main symtab to all symbols
11249 that don't have one. We need to handle the case of a symbol with a
11250 missing symtab (DW_AT_decl_file) anyway. */
11253 /* Process DW_TAG_type_unit.
11254 For TUs we want to skip the first top level sibling if it's not the
11255 actual type being defined by this TU. In this case the first top
11256 level sibling is there to provide context only. */
11259 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11261 struct die_info
*child_die
;
11263 prepare_one_comp_unit (cu
, die
, language_minimal
);
11265 /* Initialize (or reinitialize) the machinery for building symtabs.
11266 We do this before processing child DIEs, so that the line header table
11267 is available for DW_AT_decl_file. */
11268 cu
->setup_type_unit_groups (die
);
11270 if (die
->child
!= NULL
)
11272 child_die
= die
->child
;
11273 while (child_die
&& child_die
->tag
)
11275 process_die (child_die
, cu
);
11276 child_die
= child_die
->sibling
;
11283 http://gcc.gnu.org/wiki/DebugFission
11284 http://gcc.gnu.org/wiki/DebugFissionDWP
11286 To simplify handling of both DWO files ("object" files with the DWARF info)
11287 and DWP files (a file with the DWOs packaged up into one file), we treat
11288 DWP files as having a collection of virtual DWO files. */
11291 hash_dwo_file (const void *item
)
11293 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11296 hash
= htab_hash_string (dwo_file
->dwo_name
);
11297 if (dwo_file
->comp_dir
!= NULL
)
11298 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11303 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11305 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11306 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11308 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11310 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11311 return lhs
->comp_dir
== rhs
->comp_dir
;
11312 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11315 /* Allocate a hash table for DWO files. */
11318 allocate_dwo_file_hash_table ()
11320 auto delete_dwo_file
= [] (void *item
)
11322 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11327 return htab_up (htab_create_alloc (41,
11334 /* Lookup DWO file DWO_NAME. */
11337 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11338 const char *dwo_name
,
11339 const char *comp_dir
)
11341 struct dwo_file find_entry
;
11344 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11345 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11347 find_entry
.dwo_name
= dwo_name
;
11348 find_entry
.comp_dir
= comp_dir
;
11349 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11356 hash_dwo_unit (const void *item
)
11358 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11360 /* This drops the top 32 bits of the id, but is ok for a hash. */
11361 return dwo_unit
->signature
;
11365 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11367 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11368 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11370 /* The signature is assumed to be unique within the DWO file.
11371 So while object file CU dwo_id's always have the value zero,
11372 that's OK, assuming each object file DWO file has only one CU,
11373 and that's the rule for now. */
11374 return lhs
->signature
== rhs
->signature
;
11377 /* Allocate a hash table for DWO CUs,TUs.
11378 There is one of these tables for each of CUs,TUs for each DWO file. */
11381 allocate_dwo_unit_table ()
11383 /* Start out with a pretty small number.
11384 Generally DWO files contain only one CU and maybe some TUs. */
11385 return htab_up (htab_create_alloc (3,
11388 NULL
, xcalloc
, xfree
));
11391 /* die_reader_func for create_dwo_cu. */
11394 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11395 const gdb_byte
*info_ptr
,
11396 struct die_info
*comp_unit_die
,
11397 struct dwo_file
*dwo_file
,
11398 struct dwo_unit
*dwo_unit
)
11400 struct dwarf2_cu
*cu
= reader
->cu
;
11401 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11402 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11404 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11405 if (!signature
.has_value ())
11407 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11408 " its dwo_id [in module %s]"),
11409 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11413 dwo_unit
->dwo_file
= dwo_file
;
11414 dwo_unit
->signature
= *signature
;
11415 dwo_unit
->section
= section
;
11416 dwo_unit
->sect_off
= sect_off
;
11417 dwo_unit
->length
= cu
->per_cu
->length
;
11419 if (dwarf_read_debug
)
11420 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11421 sect_offset_str (sect_off
),
11422 hex_string (dwo_unit
->signature
));
11425 /* Create the dwo_units for the CUs in a DWO_FILE.
11426 Note: This function processes DWO files only, not DWP files. */
11429 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11430 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11431 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11433 struct objfile
*objfile
= per_objfile
->objfile
;
11434 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11435 const gdb_byte
*info_ptr
, *end_ptr
;
11437 section
.read (objfile
);
11438 info_ptr
= section
.buffer
;
11440 if (info_ptr
== NULL
)
11443 if (dwarf_read_debug
)
11445 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11446 section
.get_name (),
11447 section
.get_file_name ());
11450 end_ptr
= info_ptr
+ section
.size
;
11451 while (info_ptr
< end_ptr
)
11453 struct dwarf2_per_cu_data per_cu
;
11454 struct dwo_unit read_unit
{};
11455 struct dwo_unit
*dwo_unit
;
11457 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11459 memset (&per_cu
, 0, sizeof (per_cu
));
11460 per_cu
.per_bfd
= per_bfd
;
11461 per_cu
.is_debug_types
= 0;
11462 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11463 per_cu
.section
= §ion
;
11465 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11466 if (!reader
.dummy_p
)
11467 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11468 &dwo_file
, &read_unit
);
11469 info_ptr
+= per_cu
.length
;
11471 // If the unit could not be parsed, skip it.
11472 if (read_unit
.dwo_file
== NULL
)
11475 if (cus_htab
== NULL
)
11476 cus_htab
= allocate_dwo_unit_table ();
11478 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11480 *dwo_unit
= read_unit
;
11481 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11482 gdb_assert (slot
!= NULL
);
11485 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11486 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11488 complaint (_("debug cu entry at offset %s is duplicate to"
11489 " the entry at offset %s, signature %s"),
11490 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11491 hex_string (dwo_unit
->signature
));
11493 *slot
= (void *)dwo_unit
;
11497 /* DWP file .debug_{cu,tu}_index section format:
11498 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11502 Both index sections have the same format, and serve to map a 64-bit
11503 signature to a set of section numbers. Each section begins with a header,
11504 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11505 indexes, and a pool of 32-bit section numbers. The index sections will be
11506 aligned at 8-byte boundaries in the file.
11508 The index section header consists of:
11510 V, 32 bit version number
11512 N, 32 bit number of compilation units or type units in the index
11513 M, 32 bit number of slots in the hash table
11515 Numbers are recorded using the byte order of the application binary.
11517 The hash table begins at offset 16 in the section, and consists of an array
11518 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11519 order of the application binary). Unused slots in the hash table are 0.
11520 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11522 The parallel table begins immediately after the hash table
11523 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11524 array of 32-bit indexes (using the byte order of the application binary),
11525 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11526 table contains a 32-bit index into the pool of section numbers. For unused
11527 hash table slots, the corresponding entry in the parallel table will be 0.
11529 The pool of section numbers begins immediately following the hash table
11530 (at offset 16 + 12 * M from the beginning of the section). The pool of
11531 section numbers consists of an array of 32-bit words (using the byte order
11532 of the application binary). Each item in the array is indexed starting
11533 from 0. The hash table entry provides the index of the first section
11534 number in the set. Additional section numbers in the set follow, and the
11535 set is terminated by a 0 entry (section number 0 is not used in ELF).
11537 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11538 section must be the first entry in the set, and the .debug_abbrev.dwo must
11539 be the second entry. Other members of the set may follow in any order.
11545 DWP Version 2 combines all the .debug_info, etc. sections into one,
11546 and the entries in the index tables are now offsets into these sections.
11547 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11550 Index Section Contents:
11552 Hash Table of Signatures dwp_hash_table.hash_table
11553 Parallel Table of Indices dwp_hash_table.unit_table
11554 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11555 Table of Section Sizes dwp_hash_table.v2.sizes
11557 The index section header consists of:
11559 V, 32 bit version number
11560 L, 32 bit number of columns in the table of section offsets
11561 N, 32 bit number of compilation units or type units in the index
11562 M, 32 bit number of slots in the hash table
11564 Numbers are recorded using the byte order of the application binary.
11566 The hash table has the same format as version 1.
11567 The parallel table of indices has the same format as version 1,
11568 except that the entries are origin-1 indices into the table of sections
11569 offsets and the table of section sizes.
11571 The table of offsets begins immediately following the parallel table
11572 (at offset 16 + 12 * M from the beginning of the section). The table is
11573 a two-dimensional array of 32-bit words (using the byte order of the
11574 application binary), with L columns and N+1 rows, in row-major order.
11575 Each row in the array is indexed starting from 0. The first row provides
11576 a key to the remaining rows: each column in this row provides an identifier
11577 for a debug section, and the offsets in the same column of subsequent rows
11578 refer to that section. The section identifiers are:
11580 DW_SECT_INFO 1 .debug_info.dwo
11581 DW_SECT_TYPES 2 .debug_types.dwo
11582 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11583 DW_SECT_LINE 4 .debug_line.dwo
11584 DW_SECT_LOC 5 .debug_loc.dwo
11585 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11586 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11587 DW_SECT_MACRO 8 .debug_macro.dwo
11589 The offsets provided by the CU and TU index sections are the base offsets
11590 for the contributions made by each CU or TU to the corresponding section
11591 in the package file. Each CU and TU header contains an abbrev_offset
11592 field, used to find the abbreviations table for that CU or TU within the
11593 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11594 be interpreted as relative to the base offset given in the index section.
11595 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11596 should be interpreted as relative to the base offset for .debug_line.dwo,
11597 and offsets into other debug sections obtained from DWARF attributes should
11598 also be interpreted as relative to the corresponding base offset.
11600 The table of sizes begins immediately following the table of offsets.
11601 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11602 with L columns and N rows, in row-major order. Each row in the array is
11603 indexed starting from 1 (row 0 is shared by the two tables).
11607 Hash table lookup is handled the same in version 1 and 2:
11609 We assume that N and M will not exceed 2^32 - 1.
11610 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11612 Given a 64-bit compilation unit signature or a type signature S, an entry
11613 in the hash table is located as follows:
11615 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11616 the low-order k bits all set to 1.
11618 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11620 3) If the hash table entry at index H matches the signature, use that
11621 entry. If the hash table entry at index H is unused (all zeroes),
11622 terminate the search: the signature is not present in the table.
11624 4) Let H = (H + H') modulo M. Repeat at Step 3.
11626 Because M > N and H' and M are relatively prime, the search is guaranteed
11627 to stop at an unused slot or find the match. */
11629 /* Create a hash table to map DWO IDs to their CU/TU entry in
11630 .debug_{info,types}.dwo in DWP_FILE.
11631 Returns NULL if there isn't one.
11632 Note: This function processes DWP files only, not DWO files. */
11634 static struct dwp_hash_table
*
11635 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11636 struct dwp_file
*dwp_file
, int is_debug_types
)
11638 struct objfile
*objfile
= per_objfile
->objfile
;
11639 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11640 const gdb_byte
*index_ptr
, *index_end
;
11641 struct dwarf2_section_info
*index
;
11642 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11643 struct dwp_hash_table
*htab
;
11645 if (is_debug_types
)
11646 index
= &dwp_file
->sections
.tu_index
;
11648 index
= &dwp_file
->sections
.cu_index
;
11650 if (index
->empty ())
11652 index
->read (objfile
);
11654 index_ptr
= index
->buffer
;
11655 index_end
= index_ptr
+ index
->size
;
11657 version
= read_4_bytes (dbfd
, index_ptr
);
11660 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11664 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11666 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11669 if (version
!= 1 && version
!= 2)
11671 error (_("Dwarf Error: unsupported DWP file version (%s)"
11672 " [in module %s]"),
11673 pulongest (version
), dwp_file
->name
);
11675 if (nr_slots
!= (nr_slots
& -nr_slots
))
11677 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11678 " is not power of 2 [in module %s]"),
11679 pulongest (nr_slots
), dwp_file
->name
);
11682 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11683 htab
->version
= version
;
11684 htab
->nr_columns
= nr_columns
;
11685 htab
->nr_units
= nr_units
;
11686 htab
->nr_slots
= nr_slots
;
11687 htab
->hash_table
= index_ptr
;
11688 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11690 /* Exit early if the table is empty. */
11691 if (nr_slots
== 0 || nr_units
== 0
11692 || (version
== 2 && nr_columns
== 0))
11694 /* All must be zero. */
11695 if (nr_slots
!= 0 || nr_units
!= 0
11696 || (version
== 2 && nr_columns
!= 0))
11698 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11699 " all zero [in modules %s]"),
11707 htab
->section_pool
.v1
.indices
=
11708 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11709 /* It's harder to decide whether the section is too small in v1.
11710 V1 is deprecated anyway so we punt. */
11714 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11715 int *ids
= htab
->section_pool
.v2
.section_ids
;
11716 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11717 /* Reverse map for error checking. */
11718 int ids_seen
[DW_SECT_MAX
+ 1];
11721 if (nr_columns
< 2)
11723 error (_("Dwarf Error: bad DWP hash table, too few columns"
11724 " in section table [in module %s]"),
11727 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11729 error (_("Dwarf Error: bad DWP hash table, too many columns"
11730 " in section table [in module %s]"),
11733 memset (ids
, 255, sizeof_ids
);
11734 memset (ids_seen
, 255, sizeof (ids_seen
));
11735 for (i
= 0; i
< nr_columns
; ++i
)
11737 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11739 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11741 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11742 " in section table [in module %s]"),
11743 id
, dwp_file
->name
);
11745 if (ids_seen
[id
] != -1)
11747 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11748 " id %d in section table [in module %s]"),
11749 id
, dwp_file
->name
);
11754 /* Must have exactly one info or types section. */
11755 if (((ids_seen
[DW_SECT_INFO
] != -1)
11756 + (ids_seen
[DW_SECT_TYPES
] != -1))
11759 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11760 " DWO info/types section [in module %s]"),
11763 /* Must have an abbrev section. */
11764 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11766 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11767 " section [in module %s]"),
11770 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11771 htab
->section_pool
.v2
.sizes
=
11772 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11773 * nr_units
* nr_columns
);
11774 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11775 * nr_units
* nr_columns
))
11778 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11779 " [in module %s]"),
11787 /* Update SECTIONS with the data from SECTP.
11789 This function is like the other "locate" section routines that are
11790 passed to bfd_map_over_sections, but in this context the sections to
11791 read comes from the DWP V1 hash table, not the full ELF section table.
11793 The result is non-zero for success, or zero if an error was found. */
11796 locate_v1_virtual_dwo_sections (asection
*sectp
,
11797 struct virtual_v1_dwo_sections
*sections
)
11799 const struct dwop_section_names
*names
= &dwop_section_names
;
11801 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11803 /* There can be only one. */
11804 if (sections
->abbrev
.s
.section
!= NULL
)
11806 sections
->abbrev
.s
.section
= sectp
;
11807 sections
->abbrev
.size
= bfd_section_size (sectp
);
11809 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11810 || section_is_p (sectp
->name
, &names
->types_dwo
))
11812 /* There can be only one. */
11813 if (sections
->info_or_types
.s
.section
!= NULL
)
11815 sections
->info_or_types
.s
.section
= sectp
;
11816 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11818 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11820 /* There can be only one. */
11821 if (sections
->line
.s
.section
!= NULL
)
11823 sections
->line
.s
.section
= sectp
;
11824 sections
->line
.size
= bfd_section_size (sectp
);
11826 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11828 /* There can be only one. */
11829 if (sections
->loc
.s
.section
!= NULL
)
11831 sections
->loc
.s
.section
= sectp
;
11832 sections
->loc
.size
= bfd_section_size (sectp
);
11834 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11836 /* There can be only one. */
11837 if (sections
->macinfo
.s
.section
!= NULL
)
11839 sections
->macinfo
.s
.section
= sectp
;
11840 sections
->macinfo
.size
= bfd_section_size (sectp
);
11842 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11844 /* There can be only one. */
11845 if (sections
->macro
.s
.section
!= NULL
)
11847 sections
->macro
.s
.section
= sectp
;
11848 sections
->macro
.size
= bfd_section_size (sectp
);
11850 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11852 /* There can be only one. */
11853 if (sections
->str_offsets
.s
.section
!= NULL
)
11855 sections
->str_offsets
.s
.section
= sectp
;
11856 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11860 /* No other kind of section is valid. */
11867 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11868 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11869 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11870 This is for DWP version 1 files. */
11872 static struct dwo_unit
*
11873 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11874 struct dwp_file
*dwp_file
,
11875 uint32_t unit_index
,
11876 const char *comp_dir
,
11877 ULONGEST signature
, int is_debug_types
)
11879 const struct dwp_hash_table
*dwp_htab
=
11880 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11881 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11882 const char *kind
= is_debug_types
? "TU" : "CU";
11883 struct dwo_file
*dwo_file
;
11884 struct dwo_unit
*dwo_unit
;
11885 struct virtual_v1_dwo_sections sections
;
11886 void **dwo_file_slot
;
11889 gdb_assert (dwp_file
->version
== 1);
11891 if (dwarf_read_debug
)
11893 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11895 pulongest (unit_index
), hex_string (signature
),
11899 /* Fetch the sections of this DWO unit.
11900 Put a limit on the number of sections we look for so that bad data
11901 doesn't cause us to loop forever. */
11903 #define MAX_NR_V1_DWO_SECTIONS \
11904 (1 /* .debug_info or .debug_types */ \
11905 + 1 /* .debug_abbrev */ \
11906 + 1 /* .debug_line */ \
11907 + 1 /* .debug_loc */ \
11908 + 1 /* .debug_str_offsets */ \
11909 + 1 /* .debug_macro or .debug_macinfo */ \
11910 + 1 /* trailing zero */)
11912 memset (§ions
, 0, sizeof (sections
));
11914 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11917 uint32_t section_nr
=
11918 read_4_bytes (dbfd
,
11919 dwp_htab
->section_pool
.v1
.indices
11920 + (unit_index
+ i
) * sizeof (uint32_t));
11922 if (section_nr
== 0)
11924 if (section_nr
>= dwp_file
->num_sections
)
11926 error (_("Dwarf Error: bad DWP hash table, section number too large"
11927 " [in module %s]"),
11931 sectp
= dwp_file
->elf_sections
[section_nr
];
11932 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11934 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11935 " [in module %s]"),
11941 || sections
.info_or_types
.empty ()
11942 || sections
.abbrev
.empty ())
11944 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11945 " [in module %s]"),
11948 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11950 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11951 " [in module %s]"),
11955 /* It's easier for the rest of the code if we fake a struct dwo_file and
11956 have dwo_unit "live" in that. At least for now.
11958 The DWP file can be made up of a random collection of CUs and TUs.
11959 However, for each CU + set of TUs that came from the same original DWO
11960 file, we can combine them back into a virtual DWO file to save space
11961 (fewer struct dwo_file objects to allocate). Remember that for really
11962 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11964 std::string virtual_dwo_name
=
11965 string_printf ("virtual-dwo/%d-%d-%d-%d",
11966 sections
.abbrev
.get_id (),
11967 sections
.line
.get_id (),
11968 sections
.loc
.get_id (),
11969 sections
.str_offsets
.get_id ());
11970 /* Can we use an existing virtual DWO file? */
11971 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11973 /* Create one if necessary. */
11974 if (*dwo_file_slot
== NULL
)
11976 if (dwarf_read_debug
)
11978 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11979 virtual_dwo_name
.c_str ());
11981 dwo_file
= new struct dwo_file
;
11982 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11983 dwo_file
->comp_dir
= comp_dir
;
11984 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11985 dwo_file
->sections
.line
= sections
.line
;
11986 dwo_file
->sections
.loc
= sections
.loc
;
11987 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11988 dwo_file
->sections
.macro
= sections
.macro
;
11989 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11990 /* The "str" section is global to the entire DWP file. */
11991 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11992 /* The info or types section is assigned below to dwo_unit,
11993 there's no need to record it in dwo_file.
11994 Also, we can't simply record type sections in dwo_file because
11995 we record a pointer into the vector in dwo_unit. As we collect more
11996 types we'll grow the vector and eventually have to reallocate space
11997 for it, invalidating all copies of pointers into the previous
11999 *dwo_file_slot
= dwo_file
;
12003 if (dwarf_read_debug
)
12005 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12006 virtual_dwo_name
.c_str ());
12008 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12011 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12012 dwo_unit
->dwo_file
= dwo_file
;
12013 dwo_unit
->signature
= signature
;
12014 dwo_unit
->section
=
12015 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12016 *dwo_unit
->section
= sections
.info_or_types
;
12017 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12022 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12023 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12024 piece within that section used by a TU/CU, return a virtual section
12025 of just that piece. */
12027 static struct dwarf2_section_info
12028 create_dwp_v2_section (dwarf2_per_objfile
*per_objfile
,
12029 struct dwarf2_section_info
*section
,
12030 bfd_size_type offset
, bfd_size_type size
)
12032 struct dwarf2_section_info result
;
12035 gdb_assert (section
!= NULL
);
12036 gdb_assert (!section
->is_virtual
);
12038 memset (&result
, 0, sizeof (result
));
12039 result
.s
.containing_section
= section
;
12040 result
.is_virtual
= true;
12045 sectp
= section
->get_bfd_section ();
12047 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12048 bounds of the real section. This is a pretty-rare event, so just
12049 flag an error (easier) instead of a warning and trying to cope. */
12051 || offset
+ size
> bfd_section_size (sectp
))
12053 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12054 " in section %s [in module %s]"),
12055 sectp
? bfd_section_name (sectp
) : "<unknown>",
12056 objfile_name (per_objfile
->objfile
));
12059 result
.virtual_offset
= offset
;
12060 result
.size
= size
;
12064 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12065 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12066 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12067 This is for DWP version 2 files. */
12069 static struct dwo_unit
*
12070 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12071 struct dwp_file
*dwp_file
,
12072 uint32_t unit_index
,
12073 const char *comp_dir
,
12074 ULONGEST signature
, int is_debug_types
)
12076 const struct dwp_hash_table
*dwp_htab
=
12077 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12078 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12079 const char *kind
= is_debug_types
? "TU" : "CU";
12080 struct dwo_file
*dwo_file
;
12081 struct dwo_unit
*dwo_unit
;
12082 struct virtual_v2_dwo_sections sections
;
12083 void **dwo_file_slot
;
12086 gdb_assert (dwp_file
->version
== 2);
12088 if (dwarf_read_debug
)
12090 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12092 pulongest (unit_index
), hex_string (signature
),
12096 /* Fetch the section offsets of this DWO unit. */
12098 memset (§ions
, 0, sizeof (sections
));
12100 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12102 uint32_t offset
= read_4_bytes (dbfd
,
12103 dwp_htab
->section_pool
.v2
.offsets
12104 + (((unit_index
- 1) * dwp_htab
->nr_columns
12106 * sizeof (uint32_t)));
12107 uint32_t size
= read_4_bytes (dbfd
,
12108 dwp_htab
->section_pool
.v2
.sizes
12109 + (((unit_index
- 1) * dwp_htab
->nr_columns
12111 * sizeof (uint32_t)));
12113 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12116 case DW_SECT_TYPES
:
12117 sections
.info_or_types_offset
= offset
;
12118 sections
.info_or_types_size
= size
;
12120 case DW_SECT_ABBREV
:
12121 sections
.abbrev_offset
= offset
;
12122 sections
.abbrev_size
= size
;
12125 sections
.line_offset
= offset
;
12126 sections
.line_size
= size
;
12129 sections
.loc_offset
= offset
;
12130 sections
.loc_size
= size
;
12132 case DW_SECT_STR_OFFSETS
:
12133 sections
.str_offsets_offset
= offset
;
12134 sections
.str_offsets_size
= size
;
12136 case DW_SECT_MACINFO
:
12137 sections
.macinfo_offset
= offset
;
12138 sections
.macinfo_size
= size
;
12140 case DW_SECT_MACRO
:
12141 sections
.macro_offset
= offset
;
12142 sections
.macro_size
= size
;
12147 /* It's easier for the rest of the code if we fake a struct dwo_file and
12148 have dwo_unit "live" in that. At least for now.
12150 The DWP file can be made up of a random collection of CUs and TUs.
12151 However, for each CU + set of TUs that came from the same original DWO
12152 file, we can combine them back into a virtual DWO file to save space
12153 (fewer struct dwo_file objects to allocate). Remember that for really
12154 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12156 std::string virtual_dwo_name
=
12157 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12158 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12159 (long) (sections
.line_size
? sections
.line_offset
: 0),
12160 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12161 (long) (sections
.str_offsets_size
12162 ? sections
.str_offsets_offset
: 0));
12163 /* Can we use an existing virtual DWO file? */
12164 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12166 /* Create one if necessary. */
12167 if (*dwo_file_slot
== NULL
)
12169 if (dwarf_read_debug
)
12171 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12172 virtual_dwo_name
.c_str ());
12174 dwo_file
= new struct dwo_file
;
12175 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12176 dwo_file
->comp_dir
= comp_dir
;
12177 dwo_file
->sections
.abbrev
=
12178 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12179 sections
.abbrev_offset
, sections
.abbrev_size
);
12180 dwo_file
->sections
.line
=
12181 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.line
,
12182 sections
.line_offset
, sections
.line_size
);
12183 dwo_file
->sections
.loc
=
12184 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.loc
,
12185 sections
.loc_offset
, sections
.loc_size
);
12186 dwo_file
->sections
.macinfo
=
12187 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12188 sections
.macinfo_offset
, sections
.macinfo_size
);
12189 dwo_file
->sections
.macro
=
12190 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macro
,
12191 sections
.macro_offset
, sections
.macro_size
);
12192 dwo_file
->sections
.str_offsets
=
12193 create_dwp_v2_section (per_objfile
,
12194 &dwp_file
->sections
.str_offsets
,
12195 sections
.str_offsets_offset
,
12196 sections
.str_offsets_size
);
12197 /* The "str" section is global to the entire DWP file. */
12198 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12199 /* The info or types section is assigned below to dwo_unit,
12200 there's no need to record it in dwo_file.
12201 Also, we can't simply record type sections in dwo_file because
12202 we record a pointer into the vector in dwo_unit. As we collect more
12203 types we'll grow the vector and eventually have to reallocate space
12204 for it, invalidating all copies of pointers into the previous
12206 *dwo_file_slot
= dwo_file
;
12210 if (dwarf_read_debug
)
12212 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12213 virtual_dwo_name
.c_str ());
12215 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12218 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12219 dwo_unit
->dwo_file
= dwo_file
;
12220 dwo_unit
->signature
= signature
;
12221 dwo_unit
->section
=
12222 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12223 *dwo_unit
->section
= create_dwp_v2_section (per_objfile
,
12225 ? &dwp_file
->sections
.types
12226 : &dwp_file
->sections
.info
,
12227 sections
.info_or_types_offset
,
12228 sections
.info_or_types_size
);
12229 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12234 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12235 Returns NULL if the signature isn't found. */
12237 static struct dwo_unit
*
12238 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12239 struct dwp_file
*dwp_file
, const char *comp_dir
,
12240 ULONGEST signature
, int is_debug_types
)
12242 const struct dwp_hash_table
*dwp_htab
=
12243 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12244 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12245 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12246 uint32_t hash
= signature
& mask
;
12247 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12250 struct dwo_unit find_dwo_cu
;
12252 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12253 find_dwo_cu
.signature
= signature
;
12254 slot
= htab_find_slot (is_debug_types
12255 ? dwp_file
->loaded_tus
.get ()
12256 : dwp_file
->loaded_cus
.get (),
12257 &find_dwo_cu
, INSERT
);
12260 return (struct dwo_unit
*) *slot
;
12262 /* Use a for loop so that we don't loop forever on bad debug info. */
12263 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12265 ULONGEST signature_in_table
;
12267 signature_in_table
=
12268 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12269 if (signature_in_table
== signature
)
12271 uint32_t unit_index
=
12272 read_4_bytes (dbfd
,
12273 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12275 if (dwp_file
->version
== 1)
12277 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12278 unit_index
, comp_dir
,
12279 signature
, is_debug_types
);
12283 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12284 unit_index
, comp_dir
,
12285 signature
, is_debug_types
);
12287 return (struct dwo_unit
*) *slot
;
12289 if (signature_in_table
== 0)
12291 hash
= (hash
+ hash2
) & mask
;
12294 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12295 " [in module %s]"),
12299 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12300 Open the file specified by FILE_NAME and hand it off to BFD for
12301 preliminary analysis. Return a newly initialized bfd *, which
12302 includes a canonicalized copy of FILE_NAME.
12303 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12304 SEARCH_CWD is true if the current directory is to be searched.
12305 It will be searched before debug-file-directory.
12306 If successful, the file is added to the bfd include table of the
12307 objfile's bfd (see gdb_bfd_record_inclusion).
12308 If unable to find/open the file, return NULL.
12309 NOTE: This function is derived from symfile_bfd_open. */
12311 static gdb_bfd_ref_ptr
12312 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12313 const char *file_name
, int is_dwp
, int search_cwd
)
12316 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12317 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12318 to debug_file_directory. */
12319 const char *search_path
;
12320 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12322 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12325 if (*debug_file_directory
!= '\0')
12327 search_path_holder
.reset (concat (".", dirname_separator_string
,
12328 debug_file_directory
,
12330 search_path
= search_path_holder
.get ();
12336 search_path
= debug_file_directory
;
12338 openp_flags flags
= OPF_RETURN_REALPATH
;
12340 flags
|= OPF_SEARCH_IN_PATH
;
12342 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12343 desc
= openp (search_path
, flags
, file_name
,
12344 O_RDONLY
| O_BINARY
, &absolute_name
);
12348 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12350 if (sym_bfd
== NULL
)
12352 bfd_set_cacheable (sym_bfd
.get (), 1);
12354 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12357 /* Success. Record the bfd as having been included by the objfile's bfd.
12358 This is important because things like demangled_names_hash lives in the
12359 objfile's per_bfd space and may have references to things like symbol
12360 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12361 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12366 /* Try to open DWO file FILE_NAME.
12367 COMP_DIR is the DW_AT_comp_dir attribute.
12368 The result is the bfd handle of the file.
12369 If there is a problem finding or opening the file, return NULL.
12370 Upon success, the canonicalized path of the file is stored in the bfd,
12371 same as symfile_bfd_open. */
12373 static gdb_bfd_ref_ptr
12374 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12375 const char *file_name
, const char *comp_dir
)
12377 if (IS_ABSOLUTE_PATH (file_name
))
12378 return try_open_dwop_file (per_objfile
, file_name
,
12379 0 /*is_dwp*/, 0 /*search_cwd*/);
12381 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12383 if (comp_dir
!= NULL
)
12385 gdb::unique_xmalloc_ptr
<char> path_to_try
12386 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12388 /* NOTE: If comp_dir is a relative path, this will also try the
12389 search path, which seems useful. */
12390 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12392 1 /*search_cwd*/));
12397 /* That didn't work, try debug-file-directory, which, despite its name,
12398 is a list of paths. */
12400 if (*debug_file_directory
== '\0')
12403 return try_open_dwop_file (per_objfile
, file_name
,
12404 0 /*is_dwp*/, 1 /*search_cwd*/);
12407 /* This function is mapped across the sections and remembers the offset and
12408 size of each of the DWO debugging sections we are interested in. */
12411 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12413 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12414 const struct dwop_section_names
*names
= &dwop_section_names
;
12416 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12418 dwo_sections
->abbrev
.s
.section
= sectp
;
12419 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12421 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12423 dwo_sections
->info
.s
.section
= sectp
;
12424 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12426 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12428 dwo_sections
->line
.s
.section
= sectp
;
12429 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12431 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12433 dwo_sections
->loc
.s
.section
= sectp
;
12434 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12436 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12438 dwo_sections
->loclists
.s
.section
= sectp
;
12439 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12441 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12443 dwo_sections
->macinfo
.s
.section
= sectp
;
12444 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12446 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12448 dwo_sections
->macro
.s
.section
= sectp
;
12449 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12451 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12453 dwo_sections
->str
.s
.section
= sectp
;
12454 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12456 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12458 dwo_sections
->str_offsets
.s
.section
= sectp
;
12459 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12461 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12463 struct dwarf2_section_info type_section
;
12465 memset (&type_section
, 0, sizeof (type_section
));
12466 type_section
.s
.section
= sectp
;
12467 type_section
.size
= bfd_section_size (sectp
);
12468 dwo_sections
->types
.push_back (type_section
);
12472 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12473 by PER_CU. This is for the non-DWP case.
12474 The result is NULL if DWO_NAME can't be found. */
12476 static struct dwo_file
*
12477 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12478 const char *comp_dir
)
12480 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12482 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12485 if (dwarf_read_debug
)
12486 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12490 dwo_file_up
dwo_file (new struct dwo_file
);
12491 dwo_file
->dwo_name
= dwo_name
;
12492 dwo_file
->comp_dir
= comp_dir
;
12493 dwo_file
->dbfd
= std::move (dbfd
);
12495 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12496 &dwo_file
->sections
);
12498 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12501 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12502 dwo_file
->sections
.types
, dwo_file
->tus
);
12504 if (dwarf_read_debug
)
12505 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12507 return dwo_file
.release ();
12510 /* This function is mapped across the sections and remembers the offset and
12511 size of each of the DWP debugging sections common to version 1 and 2 that
12512 we are interested in. */
12515 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12516 void *dwp_file_ptr
)
12518 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12519 const struct dwop_section_names
*names
= &dwop_section_names
;
12520 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12522 /* Record the ELF section number for later lookup: this is what the
12523 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12524 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12525 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12527 /* Look for specific sections that we need. */
12528 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12530 dwp_file
->sections
.str
.s
.section
= sectp
;
12531 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12533 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12535 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12536 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12538 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12540 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12541 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12545 /* This function is mapped across the sections and remembers the offset and
12546 size of each of the DWP version 2 debugging sections that we are interested
12547 in. This is split into a separate function because we don't know if we
12548 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12551 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12553 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12554 const struct dwop_section_names
*names
= &dwop_section_names
;
12555 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12557 /* Record the ELF section number for later lookup: this is what the
12558 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12559 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12560 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12562 /* Look for specific sections that we need. */
12563 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12565 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12566 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12568 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12570 dwp_file
->sections
.info
.s
.section
= sectp
;
12571 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12573 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12575 dwp_file
->sections
.line
.s
.section
= sectp
;
12576 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12578 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12580 dwp_file
->sections
.loc
.s
.section
= sectp
;
12581 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12583 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12585 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12586 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12588 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12590 dwp_file
->sections
.macro
.s
.section
= sectp
;
12591 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12593 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12595 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12596 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12598 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12600 dwp_file
->sections
.types
.s
.section
= sectp
;
12601 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12605 /* Hash function for dwp_file loaded CUs/TUs. */
12608 hash_dwp_loaded_cutus (const void *item
)
12610 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12612 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12613 return dwo_unit
->signature
;
12616 /* Equality function for dwp_file loaded CUs/TUs. */
12619 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12621 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12622 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12624 return dua
->signature
== dub
->signature
;
12627 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12630 allocate_dwp_loaded_cutus_table ()
12632 return htab_up (htab_create_alloc (3,
12633 hash_dwp_loaded_cutus
,
12634 eq_dwp_loaded_cutus
,
12635 NULL
, xcalloc
, xfree
));
12638 /* Try to open DWP file FILE_NAME.
12639 The result is the bfd handle of the file.
12640 If there is a problem finding or opening the file, return NULL.
12641 Upon success, the canonicalized path of the file is stored in the bfd,
12642 same as symfile_bfd_open. */
12644 static gdb_bfd_ref_ptr
12645 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12647 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12649 1 /*search_cwd*/));
12653 /* Work around upstream bug 15652.
12654 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12655 [Whether that's a "bug" is debatable, but it is getting in our way.]
12656 We have no real idea where the dwp file is, because gdb's realpath-ing
12657 of the executable's path may have discarded the needed info.
12658 [IWBN if the dwp file name was recorded in the executable, akin to
12659 .gnu_debuglink, but that doesn't exist yet.]
12660 Strip the directory from FILE_NAME and search again. */
12661 if (*debug_file_directory
!= '\0')
12663 /* Don't implicitly search the current directory here.
12664 If the user wants to search "." to handle this case,
12665 it must be added to debug-file-directory. */
12666 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12674 /* Initialize the use of the DWP file for the current objfile.
12675 By convention the name of the DWP file is ${objfile}.dwp.
12676 The result is NULL if it can't be found. */
12678 static std::unique_ptr
<struct dwp_file
>
12679 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12681 struct objfile
*objfile
= per_objfile
->objfile
;
12683 /* Try to find first .dwp for the binary file before any symbolic links
12686 /* If the objfile is a debug file, find the name of the real binary
12687 file and get the name of dwp file from there. */
12688 std::string dwp_name
;
12689 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12691 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12692 const char *backlink_basename
= lbasename (backlink
->original_name
);
12694 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12697 dwp_name
= objfile
->original_name
;
12699 dwp_name
+= ".dwp";
12701 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12703 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12705 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12706 dwp_name
= objfile_name (objfile
);
12707 dwp_name
+= ".dwp";
12708 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12713 if (dwarf_read_debug
)
12714 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12715 return std::unique_ptr
<dwp_file
> ();
12718 const char *name
= bfd_get_filename (dbfd
.get ());
12719 std::unique_ptr
<struct dwp_file
> dwp_file
12720 (new struct dwp_file (name
, std::move (dbfd
)));
12722 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12723 dwp_file
->elf_sections
=
12724 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12725 dwp_file
->num_sections
, asection
*);
12727 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12728 dwarf2_locate_common_dwp_sections
,
12731 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12733 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12735 /* The DWP file version is stored in the hash table. Oh well. */
12736 if (dwp_file
->cus
&& dwp_file
->tus
12737 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12739 /* Technically speaking, we should try to limp along, but this is
12740 pretty bizarre. We use pulongest here because that's the established
12741 portability solution (e.g, we cannot use %u for uint32_t). */
12742 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12743 " TU version %s [in DWP file %s]"),
12744 pulongest (dwp_file
->cus
->version
),
12745 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12749 dwp_file
->version
= dwp_file
->cus
->version
;
12750 else if (dwp_file
->tus
)
12751 dwp_file
->version
= dwp_file
->tus
->version
;
12753 dwp_file
->version
= 2;
12755 if (dwp_file
->version
== 2)
12756 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12757 dwarf2_locate_v2_dwp_sections
,
12760 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12761 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12763 if (dwarf_read_debug
)
12765 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12766 fprintf_unfiltered (gdb_stdlog
,
12767 " %s CUs, %s TUs\n",
12768 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12769 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12775 /* Wrapper around open_and_init_dwp_file, only open it once. */
12777 static struct dwp_file
*
12778 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12780 if (!per_objfile
->per_bfd
->dwp_checked
)
12782 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12783 per_objfile
->per_bfd
->dwp_checked
= 1;
12785 return per_objfile
->per_bfd
->dwp_file
.get ();
12788 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12789 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12790 or in the DWP file for the objfile, referenced by THIS_UNIT.
12791 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12792 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12794 This is called, for example, when wanting to read a variable with a
12795 complex location. Therefore we don't want to do file i/o for every call.
12796 Therefore we don't want to look for a DWO file on every call.
12797 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12798 then we check if we've already seen DWO_NAME, and only THEN do we check
12801 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12802 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12804 static struct dwo_unit
*
12805 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12806 ULONGEST signature
, int is_debug_types
)
12808 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12809 struct objfile
*objfile
= per_objfile
->objfile
;
12810 const char *kind
= is_debug_types
? "TU" : "CU";
12811 void **dwo_file_slot
;
12812 struct dwo_file
*dwo_file
;
12813 struct dwp_file
*dwp_file
;
12815 /* First see if there's a DWP file.
12816 If we have a DWP file but didn't find the DWO inside it, don't
12817 look for the original DWO file. It makes gdb behave differently
12818 depending on whether one is debugging in the build tree. */
12820 dwp_file
= get_dwp_file (per_objfile
);
12821 if (dwp_file
!= NULL
)
12823 const struct dwp_hash_table
*dwp_htab
=
12824 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12826 if (dwp_htab
!= NULL
)
12828 struct dwo_unit
*dwo_cutu
=
12829 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12832 if (dwo_cutu
!= NULL
)
12834 if (dwarf_read_debug
)
12836 fprintf_unfiltered (gdb_stdlog
,
12837 "Virtual DWO %s %s found: @%s\n",
12838 kind
, hex_string (signature
),
12839 host_address_to_string (dwo_cutu
));
12847 /* No DWP file, look for the DWO file. */
12849 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12850 if (*dwo_file_slot
== NULL
)
12852 /* Read in the file and build a table of the CUs/TUs it contains. */
12853 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12855 /* NOTE: This will be NULL if unable to open the file. */
12856 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12858 if (dwo_file
!= NULL
)
12860 struct dwo_unit
*dwo_cutu
= NULL
;
12862 if (is_debug_types
&& dwo_file
->tus
)
12864 struct dwo_unit find_dwo_cutu
;
12866 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12867 find_dwo_cutu
.signature
= signature
;
12869 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12872 else if (!is_debug_types
&& dwo_file
->cus
)
12874 struct dwo_unit find_dwo_cutu
;
12876 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12877 find_dwo_cutu
.signature
= signature
;
12878 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12882 if (dwo_cutu
!= NULL
)
12884 if (dwarf_read_debug
)
12886 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12887 kind
, dwo_name
, hex_string (signature
),
12888 host_address_to_string (dwo_cutu
));
12895 /* We didn't find it. This could mean a dwo_id mismatch, or
12896 someone deleted the DWO/DWP file, or the search path isn't set up
12897 correctly to find the file. */
12899 if (dwarf_read_debug
)
12901 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12902 kind
, dwo_name
, hex_string (signature
));
12905 /* This is a warning and not a complaint because it can be caused by
12906 pilot error (e.g., user accidentally deleting the DWO). */
12908 /* Print the name of the DWP file if we looked there, helps the user
12909 better diagnose the problem. */
12910 std::string dwp_text
;
12912 if (dwp_file
!= NULL
)
12913 dwp_text
= string_printf (" [in DWP file %s]",
12914 lbasename (dwp_file
->name
));
12916 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12917 " [in module %s]"),
12918 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12919 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12924 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12925 See lookup_dwo_cutu_unit for details. */
12927 static struct dwo_unit
*
12928 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12929 ULONGEST signature
)
12931 gdb_assert (!cu
->per_cu
->is_debug_types
);
12933 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12936 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12937 See lookup_dwo_cutu_unit for details. */
12939 static struct dwo_unit
*
12940 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12942 gdb_assert (cu
->per_cu
->is_debug_types
);
12944 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12946 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12949 /* Traversal function for queue_and_load_all_dwo_tus. */
12952 queue_and_load_dwo_tu (void **slot
, void *info
)
12954 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12955 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12956 ULONGEST signature
= dwo_unit
->signature
;
12957 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12959 if (sig_type
!= NULL
)
12961 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12963 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12964 a real dependency of PER_CU on SIG_TYPE. That is detected later
12965 while processing PER_CU. */
12966 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12967 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12968 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12974 /* Queue all TUs contained in the DWO of CU to be read in.
12975 The DWO may have the only definition of the type, though it may not be
12976 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12977 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12980 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12982 struct dwo_unit
*dwo_unit
;
12983 struct dwo_file
*dwo_file
;
12985 gdb_assert (cu
!= nullptr);
12986 gdb_assert (!cu
->per_cu
->is_debug_types
);
12987 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12989 dwo_unit
= cu
->dwo_unit
;
12990 gdb_assert (dwo_unit
!= NULL
);
12992 dwo_file
= dwo_unit
->dwo_file
;
12993 if (dwo_file
->tus
!= NULL
)
12994 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12997 /* Read in various DIEs. */
12999 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13000 Inherit only the children of the DW_AT_abstract_origin DIE not being
13001 already referenced by DW_AT_abstract_origin from the children of the
13005 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13007 struct die_info
*child_die
;
13008 sect_offset
*offsetp
;
13009 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13010 struct die_info
*origin_die
;
13011 /* Iterator of the ORIGIN_DIE children. */
13012 struct die_info
*origin_child_die
;
13013 struct attribute
*attr
;
13014 struct dwarf2_cu
*origin_cu
;
13015 struct pending
**origin_previous_list_in_scope
;
13017 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13021 /* Note that following die references may follow to a die in a
13025 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13027 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13029 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13030 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13032 if (die
->tag
!= origin_die
->tag
13033 && !(die
->tag
== DW_TAG_inlined_subroutine
13034 && origin_die
->tag
== DW_TAG_subprogram
))
13035 complaint (_("DIE %s and its abstract origin %s have different tags"),
13036 sect_offset_str (die
->sect_off
),
13037 sect_offset_str (origin_die
->sect_off
));
13039 std::vector
<sect_offset
> offsets
;
13041 for (child_die
= die
->child
;
13042 child_die
&& child_die
->tag
;
13043 child_die
= child_die
->sibling
)
13045 struct die_info
*child_origin_die
;
13046 struct dwarf2_cu
*child_origin_cu
;
13048 /* We are trying to process concrete instance entries:
13049 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13050 it's not relevant to our analysis here. i.e. detecting DIEs that are
13051 present in the abstract instance but not referenced in the concrete
13053 if (child_die
->tag
== DW_TAG_call_site
13054 || child_die
->tag
== DW_TAG_GNU_call_site
)
13057 /* For each CHILD_DIE, find the corresponding child of
13058 ORIGIN_DIE. If there is more than one layer of
13059 DW_AT_abstract_origin, follow them all; there shouldn't be,
13060 but GCC versions at least through 4.4 generate this (GCC PR
13062 child_origin_die
= child_die
;
13063 child_origin_cu
= cu
;
13066 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13070 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13074 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13075 counterpart may exist. */
13076 if (child_origin_die
!= child_die
)
13078 if (child_die
->tag
!= child_origin_die
->tag
13079 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13080 && child_origin_die
->tag
== DW_TAG_subprogram
))
13081 complaint (_("Child DIE %s and its abstract origin %s have "
13083 sect_offset_str (child_die
->sect_off
),
13084 sect_offset_str (child_origin_die
->sect_off
));
13085 if (child_origin_die
->parent
!= origin_die
)
13086 complaint (_("Child DIE %s and its abstract origin %s have "
13087 "different parents"),
13088 sect_offset_str (child_die
->sect_off
),
13089 sect_offset_str (child_origin_die
->sect_off
));
13091 offsets
.push_back (child_origin_die
->sect_off
);
13094 std::sort (offsets
.begin (), offsets
.end ());
13095 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13096 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13097 if (offsetp
[-1] == *offsetp
)
13098 complaint (_("Multiple children of DIE %s refer "
13099 "to DIE %s as their abstract origin"),
13100 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13102 offsetp
= offsets
.data ();
13103 origin_child_die
= origin_die
->child
;
13104 while (origin_child_die
&& origin_child_die
->tag
)
13106 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13107 while (offsetp
< offsets_end
13108 && *offsetp
< origin_child_die
->sect_off
)
13110 if (offsetp
>= offsets_end
13111 || *offsetp
> origin_child_die
->sect_off
)
13113 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13114 Check whether we're already processing ORIGIN_CHILD_DIE.
13115 This can happen with mutually referenced abstract_origins.
13117 if (!origin_child_die
->in_process
)
13118 process_die (origin_child_die
, origin_cu
);
13120 origin_child_die
= origin_child_die
->sibling
;
13122 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13124 if (cu
!= origin_cu
)
13125 compute_delayed_physnames (origin_cu
);
13129 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13131 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13132 struct gdbarch
*gdbarch
= objfile
->arch ();
13133 struct context_stack
*newobj
;
13136 struct die_info
*child_die
;
13137 struct attribute
*attr
, *call_line
, *call_file
;
13139 CORE_ADDR baseaddr
;
13140 struct block
*block
;
13141 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13142 std::vector
<struct symbol
*> template_args
;
13143 struct template_symbol
*templ_func
= NULL
;
13147 /* If we do not have call site information, we can't show the
13148 caller of this inlined function. That's too confusing, so
13149 only use the scope for local variables. */
13150 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13151 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13152 if (call_line
== NULL
|| call_file
== NULL
)
13154 read_lexical_block_scope (die
, cu
);
13159 baseaddr
= objfile
->text_section_offset ();
13161 name
= dwarf2_name (die
, cu
);
13163 /* Ignore functions with missing or empty names. These are actually
13164 illegal according to the DWARF standard. */
13167 complaint (_("missing name for subprogram DIE at %s"),
13168 sect_offset_str (die
->sect_off
));
13172 /* Ignore functions with missing or invalid low and high pc attributes. */
13173 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13174 <= PC_BOUNDS_INVALID
)
13176 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13177 if (!attr
|| !DW_UNSND (attr
))
13178 complaint (_("cannot get low and high bounds "
13179 "for subprogram DIE at %s"),
13180 sect_offset_str (die
->sect_off
));
13184 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13185 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13187 /* If we have any template arguments, then we must allocate a
13188 different sort of symbol. */
13189 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13191 if (child_die
->tag
== DW_TAG_template_type_param
13192 || child_die
->tag
== DW_TAG_template_value_param
)
13194 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13195 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13200 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13201 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13202 (struct symbol
*) templ_func
);
13204 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13205 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13208 /* If there is a location expression for DW_AT_frame_base, record
13210 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13211 if (attr
!= nullptr)
13212 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13214 /* If there is a location for the static link, record it. */
13215 newobj
->static_link
= NULL
;
13216 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13217 if (attr
!= nullptr)
13219 newobj
->static_link
13220 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13221 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13225 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13227 if (die
->child
!= NULL
)
13229 child_die
= die
->child
;
13230 while (child_die
&& child_die
->tag
)
13232 if (child_die
->tag
== DW_TAG_template_type_param
13233 || child_die
->tag
== DW_TAG_template_value_param
)
13235 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13238 template_args
.push_back (arg
);
13241 process_die (child_die
, cu
);
13242 child_die
= child_die
->sibling
;
13246 inherit_abstract_dies (die
, cu
);
13248 /* If we have a DW_AT_specification, we might need to import using
13249 directives from the context of the specification DIE. See the
13250 comment in determine_prefix. */
13251 if (cu
->language
== language_cplus
13252 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13254 struct dwarf2_cu
*spec_cu
= cu
;
13255 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13259 child_die
= spec_die
->child
;
13260 while (child_die
&& child_die
->tag
)
13262 if (child_die
->tag
== DW_TAG_imported_module
)
13263 process_die (child_die
, spec_cu
);
13264 child_die
= child_die
->sibling
;
13267 /* In some cases, GCC generates specification DIEs that
13268 themselves contain DW_AT_specification attributes. */
13269 spec_die
= die_specification (spec_die
, &spec_cu
);
13273 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13274 /* Make a block for the local symbols within. */
13275 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13276 cstk
.static_link
, lowpc
, highpc
);
13278 /* For C++, set the block's scope. */
13279 if ((cu
->language
== language_cplus
13280 || cu
->language
== language_fortran
13281 || cu
->language
== language_d
13282 || cu
->language
== language_rust
)
13283 && cu
->processing_has_namespace_info
)
13284 block_set_scope (block
, determine_prefix (die
, cu
),
13285 &objfile
->objfile_obstack
);
13287 /* If we have address ranges, record them. */
13288 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13290 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13292 /* Attach template arguments to function. */
13293 if (!template_args
.empty ())
13295 gdb_assert (templ_func
!= NULL
);
13297 templ_func
->n_template_arguments
= template_args
.size ();
13298 templ_func
->template_arguments
13299 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13300 templ_func
->n_template_arguments
);
13301 memcpy (templ_func
->template_arguments
,
13302 template_args
.data (),
13303 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13305 /* Make sure that the symtab is set on the new symbols. Even
13306 though they don't appear in this symtab directly, other parts
13307 of gdb assume that symbols do, and this is reasonably
13309 for (symbol
*sym
: template_args
)
13310 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13313 /* In C++, we can have functions nested inside functions (e.g., when
13314 a function declares a class that has methods). This means that
13315 when we finish processing a function scope, we may need to go
13316 back to building a containing block's symbol lists. */
13317 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13318 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13320 /* If we've finished processing a top-level function, subsequent
13321 symbols go in the file symbol list. */
13322 if (cu
->get_builder ()->outermost_context_p ())
13323 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13326 /* Process all the DIES contained within a lexical block scope. Start
13327 a new scope, process the dies, and then close the scope. */
13330 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13332 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13333 struct gdbarch
*gdbarch
= objfile
->arch ();
13334 CORE_ADDR lowpc
, highpc
;
13335 struct die_info
*child_die
;
13336 CORE_ADDR baseaddr
;
13338 baseaddr
= objfile
->text_section_offset ();
13340 /* Ignore blocks with missing or invalid low and high pc attributes. */
13341 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13342 as multiple lexical blocks? Handling children in a sane way would
13343 be nasty. Might be easier to properly extend generic blocks to
13344 describe ranges. */
13345 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13347 case PC_BOUNDS_NOT_PRESENT
:
13348 /* DW_TAG_lexical_block has no attributes, process its children as if
13349 there was no wrapping by that DW_TAG_lexical_block.
13350 GCC does no longer produces such DWARF since GCC r224161. */
13351 for (child_die
= die
->child
;
13352 child_die
!= NULL
&& child_die
->tag
;
13353 child_die
= child_die
->sibling
)
13355 /* We might already be processing this DIE. This can happen
13356 in an unusual circumstance -- where a subroutine A
13357 appears lexically in another subroutine B, but A actually
13358 inlines B. The recursion is broken here, rather than in
13359 inherit_abstract_dies, because it seems better to simply
13360 drop concrete children here. */
13361 if (!child_die
->in_process
)
13362 process_die (child_die
, cu
);
13365 case PC_BOUNDS_INVALID
:
13368 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13369 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13371 cu
->get_builder ()->push_context (0, lowpc
);
13372 if (die
->child
!= NULL
)
13374 child_die
= die
->child
;
13375 while (child_die
&& child_die
->tag
)
13377 process_die (child_die
, cu
);
13378 child_die
= child_die
->sibling
;
13381 inherit_abstract_dies (die
, cu
);
13382 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13384 if (*cu
->get_builder ()->get_local_symbols () != NULL
13385 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13387 struct block
*block
13388 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13389 cstk
.start_addr
, highpc
);
13391 /* Note that recording ranges after traversing children, as we
13392 do here, means that recording a parent's ranges entails
13393 walking across all its children's ranges as they appear in
13394 the address map, which is quadratic behavior.
13396 It would be nicer to record the parent's ranges before
13397 traversing its children, simply overriding whatever you find
13398 there. But since we don't even decide whether to create a
13399 block until after we've traversed its children, that's hard
13401 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13403 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13404 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13407 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13410 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13412 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13413 struct objfile
*objfile
= per_objfile
->objfile
;
13414 struct gdbarch
*gdbarch
= objfile
->arch ();
13415 CORE_ADDR pc
, baseaddr
;
13416 struct attribute
*attr
;
13417 struct call_site
*call_site
, call_site_local
;
13420 struct die_info
*child_die
;
13422 baseaddr
= objfile
->text_section_offset ();
13424 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13427 /* This was a pre-DWARF-5 GNU extension alias
13428 for DW_AT_call_return_pc. */
13429 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13433 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13434 "DIE %s [in module %s]"),
13435 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13438 pc
= attr
->value_as_address () + baseaddr
;
13439 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13441 if (cu
->call_site_htab
== NULL
)
13442 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13443 NULL
, &objfile
->objfile_obstack
,
13444 hashtab_obstack_allocate
, NULL
);
13445 call_site_local
.pc
= pc
;
13446 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13449 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13450 "DIE %s [in module %s]"),
13451 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13452 objfile_name (objfile
));
13456 /* Count parameters at the caller. */
13459 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13460 child_die
= child_die
->sibling
)
13462 if (child_die
->tag
!= DW_TAG_call_site_parameter
13463 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13465 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13466 "DW_TAG_call_site child DIE %s [in module %s]"),
13467 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13468 objfile_name (objfile
));
13476 = ((struct call_site
*)
13477 obstack_alloc (&objfile
->objfile_obstack
,
13478 sizeof (*call_site
)
13479 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13481 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13482 call_site
->pc
= pc
;
13484 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13485 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13487 struct die_info
*func_die
;
13489 /* Skip also over DW_TAG_inlined_subroutine. */
13490 for (func_die
= die
->parent
;
13491 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13492 && func_die
->tag
!= DW_TAG_subroutine_type
;
13493 func_die
= func_die
->parent
);
13495 /* DW_AT_call_all_calls is a superset
13496 of DW_AT_call_all_tail_calls. */
13498 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13499 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13500 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13501 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13503 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13504 not complete. But keep CALL_SITE for look ups via call_site_htab,
13505 both the initial caller containing the real return address PC and
13506 the final callee containing the current PC of a chain of tail
13507 calls do not need to have the tail call list complete. But any
13508 function candidate for a virtual tail call frame searched via
13509 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13510 determined unambiguously. */
13514 struct type
*func_type
= NULL
;
13517 func_type
= get_die_type (func_die
, cu
);
13518 if (func_type
!= NULL
)
13520 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13522 /* Enlist this call site to the function. */
13523 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13524 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13527 complaint (_("Cannot find function owning DW_TAG_call_site "
13528 "DIE %s [in module %s]"),
13529 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13533 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13535 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13537 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13540 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13541 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13543 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13544 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13545 /* Keep NULL DWARF_BLOCK. */;
13546 else if (attr
->form_is_block ())
13548 struct dwarf2_locexpr_baton
*dlbaton
;
13550 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13551 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13552 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13553 dlbaton
->per_objfile
= per_objfile
;
13554 dlbaton
->per_cu
= cu
->per_cu
;
13556 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13558 else if (attr
->form_is_ref ())
13560 struct dwarf2_cu
*target_cu
= cu
;
13561 struct die_info
*target_die
;
13563 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13564 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13565 if (die_is_declaration (target_die
, target_cu
))
13567 const char *target_physname
;
13569 /* Prefer the mangled name; otherwise compute the demangled one. */
13570 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13571 if (target_physname
== NULL
)
13572 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13573 if (target_physname
== NULL
)
13574 complaint (_("DW_AT_call_target target DIE has invalid "
13575 "physname, for referencing DIE %s [in module %s]"),
13576 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13578 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13584 /* DW_AT_entry_pc should be preferred. */
13585 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13586 <= PC_BOUNDS_INVALID
)
13587 complaint (_("DW_AT_call_target target DIE has invalid "
13588 "low pc, for referencing DIE %s [in module %s]"),
13589 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13592 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13593 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13598 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13599 "block nor reference, for DIE %s [in module %s]"),
13600 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13602 call_site
->per_cu
= cu
->per_cu
;
13603 call_site
->per_objfile
= per_objfile
;
13605 for (child_die
= die
->child
;
13606 child_die
&& child_die
->tag
;
13607 child_die
= child_die
->sibling
)
13609 struct call_site_parameter
*parameter
;
13610 struct attribute
*loc
, *origin
;
13612 if (child_die
->tag
!= DW_TAG_call_site_parameter
13613 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13615 /* Already printed the complaint above. */
13619 gdb_assert (call_site
->parameter_count
< nparams
);
13620 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13622 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13623 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13624 register is contained in DW_AT_call_value. */
13626 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13627 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13628 if (origin
== NULL
)
13630 /* This was a pre-DWARF-5 GNU extension alias
13631 for DW_AT_call_parameter. */
13632 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13634 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13636 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13638 sect_offset sect_off
= origin
->get_ref_die_offset ();
13639 if (!cu
->header
.offset_in_cu_p (sect_off
))
13641 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13642 binding can be done only inside one CU. Such referenced DIE
13643 therefore cannot be even moved to DW_TAG_partial_unit. */
13644 complaint (_("DW_AT_call_parameter offset is not in CU for "
13645 "DW_TAG_call_site child DIE %s [in module %s]"),
13646 sect_offset_str (child_die
->sect_off
),
13647 objfile_name (objfile
));
13650 parameter
->u
.param_cu_off
13651 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13653 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13655 complaint (_("No DW_FORM_block* DW_AT_location for "
13656 "DW_TAG_call_site child DIE %s [in module %s]"),
13657 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13662 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13663 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13664 if (parameter
->u
.dwarf_reg
!= -1)
13665 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13666 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13667 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13668 ¶meter
->u
.fb_offset
))
13669 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13672 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13673 "for DW_FORM_block* DW_AT_location is supported for "
13674 "DW_TAG_call_site child DIE %s "
13676 sect_offset_str (child_die
->sect_off
),
13677 objfile_name (objfile
));
13682 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13684 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13685 if (attr
== NULL
|| !attr
->form_is_block ())
13687 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13688 "DW_TAG_call_site child DIE %s [in module %s]"),
13689 sect_offset_str (child_die
->sect_off
),
13690 objfile_name (objfile
));
13693 parameter
->value
= DW_BLOCK (attr
)->data
;
13694 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13696 /* Parameters are not pre-cleared by memset above. */
13697 parameter
->data_value
= NULL
;
13698 parameter
->data_value_size
= 0;
13699 call_site
->parameter_count
++;
13701 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13703 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13704 if (attr
!= nullptr)
13706 if (!attr
->form_is_block ())
13707 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13708 "DW_TAG_call_site child DIE %s [in module %s]"),
13709 sect_offset_str (child_die
->sect_off
),
13710 objfile_name (objfile
));
13713 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13714 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13720 /* Helper function for read_variable. If DIE represents a virtual
13721 table, then return the type of the concrete object that is
13722 associated with the virtual table. Otherwise, return NULL. */
13724 static struct type
*
13725 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13727 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13731 /* Find the type DIE. */
13732 struct die_info
*type_die
= NULL
;
13733 struct dwarf2_cu
*type_cu
= cu
;
13735 if (attr
->form_is_ref ())
13736 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13737 if (type_die
== NULL
)
13740 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13742 return die_containing_type (type_die
, type_cu
);
13745 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13748 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13750 struct rust_vtable_symbol
*storage
= NULL
;
13752 if (cu
->language
== language_rust
)
13754 struct type
*containing_type
= rust_containing_type (die
, cu
);
13756 if (containing_type
!= NULL
)
13758 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13760 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13761 storage
->concrete_type
= containing_type
;
13762 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13766 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13767 struct attribute
*abstract_origin
13768 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13769 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13770 if (res
== NULL
&& loc
&& abstract_origin
)
13772 /* We have a variable without a name, but with a location and an abstract
13773 origin. This may be a concrete instance of an abstract variable
13774 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13776 struct dwarf2_cu
*origin_cu
= cu
;
13777 struct die_info
*origin_die
13778 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13779 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13780 per_objfile
->per_bfd
->abstract_to_concrete
13781 [origin_die
->sect_off
].push_back (die
->sect_off
);
13785 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13786 reading .debug_rnglists.
13787 Callback's type should be:
13788 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13789 Return true if the attributes are present and valid, otherwise,
13792 template <typename Callback
>
13794 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13795 Callback
&&callback
)
13797 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13798 struct objfile
*objfile
= per_objfile
->objfile
;
13799 bfd
*obfd
= objfile
->obfd
;
13800 /* Base address selection entry. */
13801 gdb::optional
<CORE_ADDR
> base
;
13802 const gdb_byte
*buffer
;
13803 CORE_ADDR baseaddr
;
13804 bool overflow
= false;
13806 base
= cu
->base_address
;
13808 per_objfile
->per_bfd
->rnglists
.read (objfile
);
13809 if (offset
>= per_objfile
->per_bfd
->rnglists
.size
)
13811 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13815 buffer
= per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13817 baseaddr
= objfile
->text_section_offset ();
13821 /* Initialize it due to a false compiler warning. */
13822 CORE_ADDR range_beginning
= 0, range_end
= 0;
13823 const gdb_byte
*buf_end
= (per_objfile
->per_bfd
->rnglists
.buffer
13824 + per_objfile
->per_bfd
->rnglists
.size
);
13825 unsigned int bytes_read
;
13827 if (buffer
== buf_end
)
13832 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13835 case DW_RLE_end_of_list
:
13837 case DW_RLE_base_address
:
13838 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13843 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13844 buffer
+= bytes_read
;
13846 case DW_RLE_start_length
:
13847 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13852 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13854 buffer
+= bytes_read
;
13855 range_end
= (range_beginning
13856 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13857 buffer
+= bytes_read
;
13858 if (buffer
> buf_end
)
13864 case DW_RLE_offset_pair
:
13865 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13866 buffer
+= bytes_read
;
13867 if (buffer
> buf_end
)
13872 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13873 buffer
+= bytes_read
;
13874 if (buffer
> buf_end
)
13880 case DW_RLE_start_end
:
13881 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13886 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13888 buffer
+= bytes_read
;
13889 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13890 buffer
+= bytes_read
;
13893 complaint (_("Invalid .debug_rnglists data (no base address)"));
13896 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13898 if (rlet
== DW_RLE_base_address
)
13901 if (!base
.has_value ())
13903 /* We have no valid base address for the ranges
13905 complaint (_("Invalid .debug_rnglists data (no base address)"));
13909 if (range_beginning
> range_end
)
13911 /* Inverted range entries are invalid. */
13912 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13916 /* Empty range entries have no effect. */
13917 if (range_beginning
== range_end
)
13920 range_beginning
+= *base
;
13921 range_end
+= *base
;
13923 /* A not-uncommon case of bad debug info.
13924 Don't pollute the addrmap with bad data. */
13925 if (range_beginning
+ baseaddr
== 0
13926 && !per_objfile
->per_bfd
->has_section_at_zero
)
13928 complaint (_(".debug_rnglists entry has start address of zero"
13929 " [in module %s]"), objfile_name (objfile
));
13933 callback (range_beginning
, range_end
);
13938 complaint (_("Offset %d is not terminated "
13939 "for DW_AT_ranges attribute"),
13947 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13948 Callback's type should be:
13949 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13950 Return 1 if the attributes are present and valid, otherwise, return 0. */
13952 template <typename Callback
>
13954 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13955 Callback
&&callback
)
13957 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13958 struct objfile
*objfile
= per_objfile
->objfile
;
13959 struct comp_unit_head
*cu_header
= &cu
->header
;
13960 bfd
*obfd
= objfile
->obfd
;
13961 unsigned int addr_size
= cu_header
->addr_size
;
13962 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13963 /* Base address selection entry. */
13964 gdb::optional
<CORE_ADDR
> base
;
13965 unsigned int dummy
;
13966 const gdb_byte
*buffer
;
13967 CORE_ADDR baseaddr
;
13969 if (cu_header
->version
>= 5)
13970 return dwarf2_rnglists_process (offset
, cu
, callback
);
13972 base
= cu
->base_address
;
13974 per_objfile
->per_bfd
->ranges
.read (objfile
);
13975 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13977 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13981 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13983 baseaddr
= objfile
->text_section_offset ();
13987 CORE_ADDR range_beginning
, range_end
;
13989 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13990 buffer
+= addr_size
;
13991 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13992 buffer
+= addr_size
;
13993 offset
+= 2 * addr_size
;
13995 /* An end of list marker is a pair of zero addresses. */
13996 if (range_beginning
== 0 && range_end
== 0)
13997 /* Found the end of list entry. */
14000 /* Each base address selection entry is a pair of 2 values.
14001 The first is the largest possible address, the second is
14002 the base address. Check for a base address here. */
14003 if ((range_beginning
& mask
) == mask
)
14005 /* If we found the largest possible address, then we already
14006 have the base address in range_end. */
14011 if (!base
.has_value ())
14013 /* We have no valid base address for the ranges
14015 complaint (_("Invalid .debug_ranges data (no base address)"));
14019 if (range_beginning
> range_end
)
14021 /* Inverted range entries are invalid. */
14022 complaint (_("Invalid .debug_ranges data (inverted range)"));
14026 /* Empty range entries have no effect. */
14027 if (range_beginning
== range_end
)
14030 range_beginning
+= *base
;
14031 range_end
+= *base
;
14033 /* A not-uncommon case of bad debug info.
14034 Don't pollute the addrmap with bad data. */
14035 if (range_beginning
+ baseaddr
== 0
14036 && !per_objfile
->per_bfd
->has_section_at_zero
)
14038 complaint (_(".debug_ranges entry has start address of zero"
14039 " [in module %s]"), objfile_name (objfile
));
14043 callback (range_beginning
, range_end
);
14049 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14050 Return 1 if the attributes are present and valid, otherwise, return 0.
14051 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14054 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14055 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14056 dwarf2_psymtab
*ranges_pst
)
14058 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14059 struct gdbarch
*gdbarch
= objfile
->arch ();
14060 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14063 CORE_ADDR high
= 0;
14066 retval
= dwarf2_ranges_process (offset
, cu
,
14067 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14069 if (ranges_pst
!= NULL
)
14074 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14075 range_beginning
+ baseaddr
)
14077 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14078 range_end
+ baseaddr
)
14080 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14081 lowpc
, highpc
- 1, ranges_pst
);
14084 /* FIXME: This is recording everything as a low-high
14085 segment of consecutive addresses. We should have a
14086 data structure for discontiguous block ranges
14090 low
= range_beginning
;
14096 if (range_beginning
< low
)
14097 low
= range_beginning
;
14098 if (range_end
> high
)
14106 /* If the first entry is an end-of-list marker, the range
14107 describes an empty scope, i.e. no instructions. */
14113 *high_return
= high
;
14117 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14118 definition for the return value. *LOWPC and *HIGHPC are set iff
14119 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14121 static enum pc_bounds_kind
14122 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14123 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14124 dwarf2_psymtab
*pst
)
14126 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14127 struct attribute
*attr
;
14128 struct attribute
*attr_high
;
14130 CORE_ADDR high
= 0;
14131 enum pc_bounds_kind ret
;
14133 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14136 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14137 if (attr
!= nullptr)
14139 low
= attr
->value_as_address ();
14140 high
= attr_high
->value_as_address ();
14141 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14145 /* Found high w/o low attribute. */
14146 return PC_BOUNDS_INVALID
;
14148 /* Found consecutive range of addresses. */
14149 ret
= PC_BOUNDS_HIGH_LOW
;
14153 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14156 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14157 We take advantage of the fact that DW_AT_ranges does not appear
14158 in DW_TAG_compile_unit of DWO files. */
14159 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14160 unsigned int ranges_offset
= (DW_UNSND (attr
)
14161 + (need_ranges_base
14165 /* Value of the DW_AT_ranges attribute is the offset in the
14166 .debug_ranges section. */
14167 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14168 return PC_BOUNDS_INVALID
;
14169 /* Found discontinuous range of addresses. */
14170 ret
= PC_BOUNDS_RANGES
;
14173 return PC_BOUNDS_NOT_PRESENT
;
14176 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14178 return PC_BOUNDS_INVALID
;
14180 /* When using the GNU linker, .gnu.linkonce. sections are used to
14181 eliminate duplicate copies of functions and vtables and such.
14182 The linker will arbitrarily choose one and discard the others.
14183 The AT_*_pc values for such functions refer to local labels in
14184 these sections. If the section from that file was discarded, the
14185 labels are not in the output, so the relocs get a value of 0.
14186 If this is a discarded function, mark the pc bounds as invalid,
14187 so that GDB will ignore it. */
14188 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14189 return PC_BOUNDS_INVALID
;
14197 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14198 its low and high PC addresses. Do nothing if these addresses could not
14199 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14200 and HIGHPC to the high address if greater than HIGHPC. */
14203 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14204 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14205 struct dwarf2_cu
*cu
)
14207 CORE_ADDR low
, high
;
14208 struct die_info
*child
= die
->child
;
14210 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14212 *lowpc
= std::min (*lowpc
, low
);
14213 *highpc
= std::max (*highpc
, high
);
14216 /* If the language does not allow nested subprograms (either inside
14217 subprograms or lexical blocks), we're done. */
14218 if (cu
->language
!= language_ada
)
14221 /* Check all the children of the given DIE. If it contains nested
14222 subprograms, then check their pc bounds. Likewise, we need to
14223 check lexical blocks as well, as they may also contain subprogram
14225 while (child
&& child
->tag
)
14227 if (child
->tag
== DW_TAG_subprogram
14228 || child
->tag
== DW_TAG_lexical_block
)
14229 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14230 child
= child
->sibling
;
14234 /* Get the low and high pc's represented by the scope DIE, and store
14235 them in *LOWPC and *HIGHPC. If the correct values can't be
14236 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14239 get_scope_pc_bounds (struct die_info
*die
,
14240 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14241 struct dwarf2_cu
*cu
)
14243 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14244 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14245 CORE_ADDR current_low
, current_high
;
14247 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14248 >= PC_BOUNDS_RANGES
)
14250 best_low
= current_low
;
14251 best_high
= current_high
;
14255 struct die_info
*child
= die
->child
;
14257 while (child
&& child
->tag
)
14259 switch (child
->tag
) {
14260 case DW_TAG_subprogram
:
14261 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14263 case DW_TAG_namespace
:
14264 case DW_TAG_module
:
14265 /* FIXME: carlton/2004-01-16: Should we do this for
14266 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14267 that current GCC's always emit the DIEs corresponding
14268 to definitions of methods of classes as children of a
14269 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14270 the DIEs giving the declarations, which could be
14271 anywhere). But I don't see any reason why the
14272 standards says that they have to be there. */
14273 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14275 if (current_low
!= ((CORE_ADDR
) -1))
14277 best_low
= std::min (best_low
, current_low
);
14278 best_high
= std::max (best_high
, current_high
);
14286 child
= child
->sibling
;
14291 *highpc
= best_high
;
14294 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14298 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14299 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14301 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14302 struct gdbarch
*gdbarch
= objfile
->arch ();
14303 struct attribute
*attr
;
14304 struct attribute
*attr_high
;
14306 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14309 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14310 if (attr
!= nullptr)
14312 CORE_ADDR low
= attr
->value_as_address ();
14313 CORE_ADDR high
= attr_high
->value_as_address ();
14315 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14318 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14319 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14320 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14324 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14325 if (attr
!= nullptr)
14327 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14328 We take advantage of the fact that DW_AT_ranges does not appear
14329 in DW_TAG_compile_unit of DWO files. */
14330 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14332 /* The value of the DW_AT_ranges attribute is the offset of the
14333 address range list in the .debug_ranges section. */
14334 unsigned long offset
= (DW_UNSND (attr
)
14335 + (need_ranges_base
? cu
->ranges_base
: 0));
14337 std::vector
<blockrange
> blockvec
;
14338 dwarf2_ranges_process (offset
, cu
,
14339 [&] (CORE_ADDR start
, CORE_ADDR end
)
14343 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14344 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14345 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14346 blockvec
.emplace_back (start
, end
);
14349 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14353 /* Check whether the producer field indicates either of GCC < 4.6, or the
14354 Intel C/C++ compiler, and cache the result in CU. */
14357 check_producer (struct dwarf2_cu
*cu
)
14361 if (cu
->producer
== NULL
)
14363 /* For unknown compilers expect their behavior is DWARF version
14366 GCC started to support .debug_types sections by -gdwarf-4 since
14367 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14368 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14369 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14370 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14372 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14374 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14375 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14377 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14379 cu
->producer_is_icc
= true;
14380 cu
->producer_is_icc_lt_14
= major
< 14;
14382 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14383 cu
->producer_is_codewarrior
= true;
14386 /* For other non-GCC compilers, expect their behavior is DWARF version
14390 cu
->checked_producer
= true;
14393 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14394 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14395 during 4.6.0 experimental. */
14398 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14400 if (!cu
->checked_producer
)
14401 check_producer (cu
);
14403 return cu
->producer_is_gxx_lt_4_6
;
14407 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14408 with incorrect is_stmt attributes. */
14411 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14413 if (!cu
->checked_producer
)
14414 check_producer (cu
);
14416 return cu
->producer_is_codewarrior
;
14419 /* Return the default accessibility type if it is not overridden by
14420 DW_AT_accessibility. */
14422 static enum dwarf_access_attribute
14423 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14425 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14427 /* The default DWARF 2 accessibility for members is public, the default
14428 accessibility for inheritance is private. */
14430 if (die
->tag
!= DW_TAG_inheritance
)
14431 return DW_ACCESS_public
;
14433 return DW_ACCESS_private
;
14437 /* DWARF 3+ defines the default accessibility a different way. The same
14438 rules apply now for DW_TAG_inheritance as for the members and it only
14439 depends on the container kind. */
14441 if (die
->parent
->tag
== DW_TAG_class_type
)
14442 return DW_ACCESS_private
;
14444 return DW_ACCESS_public
;
14448 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14449 offset. If the attribute was not found return 0, otherwise return
14450 1. If it was found but could not properly be handled, set *OFFSET
14454 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14457 struct attribute
*attr
;
14459 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14464 /* Note that we do not check for a section offset first here.
14465 This is because DW_AT_data_member_location is new in DWARF 4,
14466 so if we see it, we can assume that a constant form is really
14467 a constant and not a section offset. */
14468 if (attr
->form_is_constant ())
14469 *offset
= attr
->constant_value (0);
14470 else if (attr
->form_is_section_offset ())
14471 dwarf2_complex_location_expr_complaint ();
14472 else if (attr
->form_is_block ())
14473 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14475 dwarf2_complex_location_expr_complaint ();
14483 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14486 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14487 struct field
*field
)
14489 struct attribute
*attr
;
14491 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14494 if (attr
->form_is_constant ())
14496 LONGEST offset
= attr
->constant_value (0);
14497 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14499 else if (attr
->form_is_section_offset ())
14500 dwarf2_complex_location_expr_complaint ();
14501 else if (attr
->form_is_block ())
14504 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14506 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14509 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14510 struct objfile
*objfile
= per_objfile
->objfile
;
14511 struct dwarf2_locexpr_baton
*dlbaton
14512 = XOBNEW (&objfile
->objfile_obstack
,
14513 struct dwarf2_locexpr_baton
);
14514 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14515 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14516 /* When using this baton, we want to compute the address
14517 of the field, not the value. This is why
14518 is_reference is set to false here. */
14519 dlbaton
->is_reference
= false;
14520 dlbaton
->per_objfile
= per_objfile
;
14521 dlbaton
->per_cu
= cu
->per_cu
;
14523 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14527 dwarf2_complex_location_expr_complaint ();
14531 /* Add an aggregate field to the field list. */
14534 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14535 struct dwarf2_cu
*cu
)
14537 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14538 struct gdbarch
*gdbarch
= objfile
->arch ();
14539 struct nextfield
*new_field
;
14540 struct attribute
*attr
;
14542 const char *fieldname
= "";
14544 if (die
->tag
== DW_TAG_inheritance
)
14546 fip
->baseclasses
.emplace_back ();
14547 new_field
= &fip
->baseclasses
.back ();
14551 fip
->fields
.emplace_back ();
14552 new_field
= &fip
->fields
.back ();
14555 new_field
->offset
= die
->sect_off
;
14557 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14558 if (attr
!= nullptr)
14559 new_field
->accessibility
= DW_UNSND (attr
);
14561 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14562 if (new_field
->accessibility
!= DW_ACCESS_public
)
14563 fip
->non_public_fields
= 1;
14565 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14566 if (attr
!= nullptr)
14567 new_field
->virtuality
= DW_UNSND (attr
);
14569 new_field
->virtuality
= DW_VIRTUALITY_none
;
14571 fp
= &new_field
->field
;
14573 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14575 /* Data member other than a C++ static data member. */
14577 /* Get type of field. */
14578 fp
->set_type (die_type (die
, cu
));
14580 SET_FIELD_BITPOS (*fp
, 0);
14582 /* Get bit size of field (zero if none). */
14583 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14584 if (attr
!= nullptr)
14586 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14590 FIELD_BITSIZE (*fp
) = 0;
14593 /* Get bit offset of field. */
14594 handle_data_member_location (die
, cu
, fp
);
14595 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14596 if (attr
!= nullptr)
14598 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14600 /* For big endian bits, the DW_AT_bit_offset gives the
14601 additional bit offset from the MSB of the containing
14602 anonymous object to the MSB of the field. We don't
14603 have to do anything special since we don't need to
14604 know the size of the anonymous object. */
14605 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14609 /* For little endian bits, compute the bit offset to the
14610 MSB of the anonymous object, subtract off the number of
14611 bits from the MSB of the field to the MSB of the
14612 object, and then subtract off the number of bits of
14613 the field itself. The result is the bit offset of
14614 the LSB of the field. */
14615 int anonymous_size
;
14616 int bit_offset
= DW_UNSND (attr
);
14618 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14619 if (attr
!= nullptr)
14621 /* The size of the anonymous object containing
14622 the bit field is explicit, so use the
14623 indicated size (in bytes). */
14624 anonymous_size
= DW_UNSND (attr
);
14628 /* The size of the anonymous object containing
14629 the bit field must be inferred from the type
14630 attribute of the data member containing the
14632 anonymous_size
= TYPE_LENGTH (fp
->type ());
14634 SET_FIELD_BITPOS (*fp
,
14635 (FIELD_BITPOS (*fp
)
14636 + anonymous_size
* bits_per_byte
14637 - bit_offset
- FIELD_BITSIZE (*fp
)));
14640 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14642 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14643 + attr
->constant_value (0)));
14645 /* Get name of field. */
14646 fieldname
= dwarf2_name (die
, cu
);
14647 if (fieldname
== NULL
)
14650 /* The name is already allocated along with this objfile, so we don't
14651 need to duplicate it for the type. */
14652 fp
->name
= fieldname
;
14654 /* Change accessibility for artificial fields (e.g. virtual table
14655 pointer or virtual base class pointer) to private. */
14656 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14658 FIELD_ARTIFICIAL (*fp
) = 1;
14659 new_field
->accessibility
= DW_ACCESS_private
;
14660 fip
->non_public_fields
= 1;
14663 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14665 /* C++ static member. */
14667 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14668 is a declaration, but all versions of G++ as of this writing
14669 (so through at least 3.2.1) incorrectly generate
14670 DW_TAG_variable tags. */
14672 const char *physname
;
14674 /* Get name of field. */
14675 fieldname
= dwarf2_name (die
, cu
);
14676 if (fieldname
== NULL
)
14679 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14681 /* Only create a symbol if this is an external value.
14682 new_symbol checks this and puts the value in the global symbol
14683 table, which we want. If it is not external, new_symbol
14684 will try to put the value in cu->list_in_scope which is wrong. */
14685 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14687 /* A static const member, not much different than an enum as far as
14688 we're concerned, except that we can support more types. */
14689 new_symbol (die
, NULL
, cu
);
14692 /* Get physical name. */
14693 physname
= dwarf2_physname (fieldname
, die
, cu
);
14695 /* The name is already allocated along with this objfile, so we don't
14696 need to duplicate it for the type. */
14697 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14698 fp
->set_type (die_type (die
, cu
));
14699 FIELD_NAME (*fp
) = fieldname
;
14701 else if (die
->tag
== DW_TAG_inheritance
)
14703 /* C++ base class field. */
14704 handle_data_member_location (die
, cu
, fp
);
14705 FIELD_BITSIZE (*fp
) = 0;
14706 fp
->set_type (die_type (die
, cu
));
14707 FIELD_NAME (*fp
) = fp
->type ()->name ();
14710 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14713 /* Can the type given by DIE define another type? */
14716 type_can_define_types (const struct die_info
*die
)
14720 case DW_TAG_typedef
:
14721 case DW_TAG_class_type
:
14722 case DW_TAG_structure_type
:
14723 case DW_TAG_union_type
:
14724 case DW_TAG_enumeration_type
:
14732 /* Add a type definition defined in the scope of the FIP's class. */
14735 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14736 struct dwarf2_cu
*cu
)
14738 struct decl_field fp
;
14739 memset (&fp
, 0, sizeof (fp
));
14741 gdb_assert (type_can_define_types (die
));
14743 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14744 fp
.name
= dwarf2_name (die
, cu
);
14745 fp
.type
= read_type_die (die
, cu
);
14747 /* Save accessibility. */
14748 enum dwarf_access_attribute accessibility
;
14749 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14751 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14753 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14754 switch (accessibility
)
14756 case DW_ACCESS_public
:
14757 /* The assumed value if neither private nor protected. */
14759 case DW_ACCESS_private
:
14762 case DW_ACCESS_protected
:
14763 fp
.is_protected
= 1;
14766 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14769 if (die
->tag
== DW_TAG_typedef
)
14770 fip
->typedef_field_list
.push_back (fp
);
14772 fip
->nested_types_list
.push_back (fp
);
14775 /* A convenience typedef that's used when finding the discriminant
14776 field for a variant part. */
14777 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14780 /* Compute the discriminant range for a given variant. OBSTACK is
14781 where the results will be stored. VARIANT is the variant to
14782 process. IS_UNSIGNED indicates whether the discriminant is signed
14785 static const gdb::array_view
<discriminant_range
>
14786 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14789 std::vector
<discriminant_range
> ranges
;
14791 if (variant
.default_branch
)
14794 if (variant
.discr_list_data
== nullptr)
14796 discriminant_range r
14797 = {variant
.discriminant_value
, variant
.discriminant_value
};
14798 ranges
.push_back (r
);
14802 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14803 variant
.discr_list_data
->size
);
14804 while (!data
.empty ())
14806 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14808 complaint (_("invalid discriminant marker: %d"), data
[0]);
14811 bool is_range
= data
[0] == DW_DSC_range
;
14812 data
= data
.slice (1);
14814 ULONGEST low
, high
;
14815 unsigned int bytes_read
;
14819 complaint (_("DW_AT_discr_list missing low value"));
14823 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14825 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14827 data
= data
.slice (bytes_read
);
14833 complaint (_("DW_AT_discr_list missing high value"));
14837 high
= read_unsigned_leb128 (nullptr, data
.data (),
14840 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14842 data
= data
.slice (bytes_read
);
14847 ranges
.push_back ({ low
, high
});
14851 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14853 std::copy (ranges
.begin (), ranges
.end (), result
);
14854 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14857 static const gdb::array_view
<variant_part
> create_variant_parts
14858 (struct obstack
*obstack
,
14859 const offset_map_type
&offset_map
,
14860 struct field_info
*fi
,
14861 const std::vector
<variant_part_builder
> &variant_parts
);
14863 /* Fill in a "struct variant" for a given variant field. RESULT is
14864 the variant to fill in. OBSTACK is where any needed allocations
14865 will be done. OFFSET_MAP holds the mapping from section offsets to
14866 fields for the type. FI describes the fields of the type we're
14867 processing. FIELD is the variant field we're converting. */
14870 create_one_variant (variant
&result
, struct obstack
*obstack
,
14871 const offset_map_type
&offset_map
,
14872 struct field_info
*fi
, const variant_field
&field
)
14874 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14875 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14876 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14877 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14878 field
.variant_parts
);
14881 /* Fill in a "struct variant_part" for a given variant part. RESULT
14882 is the variant part to fill in. OBSTACK is where any needed
14883 allocations will be done. OFFSET_MAP holds the mapping from
14884 section offsets to fields for the type. FI describes the fields of
14885 the type we're processing. BUILDER is the variant part to be
14889 create_one_variant_part (variant_part
&result
,
14890 struct obstack
*obstack
,
14891 const offset_map_type
&offset_map
,
14892 struct field_info
*fi
,
14893 const variant_part_builder
&builder
)
14895 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14896 if (iter
== offset_map
.end ())
14898 result
.discriminant_index
= -1;
14899 /* Doesn't matter. */
14900 result
.is_unsigned
= false;
14904 result
.discriminant_index
= iter
->second
;
14906 = TYPE_UNSIGNED (fi
->fields
[result
.discriminant_index
].field
.type ());
14909 size_t n
= builder
.variants
.size ();
14910 variant
*output
= new (obstack
) variant
[n
];
14911 for (size_t i
= 0; i
< n
; ++i
)
14912 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14913 builder
.variants
[i
]);
14915 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14918 /* Create a vector of variant parts that can be attached to a type.
14919 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14920 holds the mapping from section offsets to fields for the type. FI
14921 describes the fields of the type we're processing. VARIANT_PARTS
14922 is the vector to convert. */
14924 static const gdb::array_view
<variant_part
>
14925 create_variant_parts (struct obstack
*obstack
,
14926 const offset_map_type
&offset_map
,
14927 struct field_info
*fi
,
14928 const std::vector
<variant_part_builder
> &variant_parts
)
14930 if (variant_parts
.empty ())
14933 size_t n
= variant_parts
.size ();
14934 variant_part
*result
= new (obstack
) variant_part
[n
];
14935 for (size_t i
= 0; i
< n
; ++i
)
14936 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14939 return gdb::array_view
<variant_part
> (result
, n
);
14942 /* Compute the variant part vector for FIP, attaching it to TYPE when
14946 add_variant_property (struct field_info
*fip
, struct type
*type
,
14947 struct dwarf2_cu
*cu
)
14949 /* Map section offsets of fields to their field index. Note the
14950 field index here does not take the number of baseclasses into
14952 offset_map_type offset_map
;
14953 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14954 offset_map
[fip
->fields
[i
].offset
] = i
;
14956 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14957 gdb::array_view
<variant_part
> parts
14958 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14959 fip
->variant_parts
);
14961 struct dynamic_prop prop
;
14962 prop
.kind
= PROP_VARIANT_PARTS
;
14963 prop
.data
.variant_parts
14964 = ((gdb::array_view
<variant_part
> *)
14965 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14967 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14970 /* Create the vector of fields, and attach it to the type. */
14973 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14974 struct dwarf2_cu
*cu
)
14976 int nfields
= fip
->nfields ();
14978 /* Record the field count, allocate space for the array of fields,
14979 and create blank accessibility bitfields if necessary. */
14980 type
->set_num_fields (nfields
);
14982 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14984 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14986 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14988 TYPE_FIELD_PRIVATE_BITS (type
) =
14989 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14990 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14992 TYPE_FIELD_PROTECTED_BITS (type
) =
14993 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14994 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14996 TYPE_FIELD_IGNORE_BITS (type
) =
14997 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14998 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15001 /* If the type has baseclasses, allocate and clear a bit vector for
15002 TYPE_FIELD_VIRTUAL_BITS. */
15003 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15005 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15006 unsigned char *pointer
;
15008 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15009 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15010 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15011 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15012 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15015 if (!fip
->variant_parts
.empty ())
15016 add_variant_property (fip
, type
, cu
);
15018 /* Copy the saved-up fields into the field vector. */
15019 for (int i
= 0; i
< nfields
; ++i
)
15021 struct nextfield
&field
15022 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15023 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15025 type
->field (i
) = field
.field
;
15026 switch (field
.accessibility
)
15028 case DW_ACCESS_private
:
15029 if (cu
->language
!= language_ada
)
15030 SET_TYPE_FIELD_PRIVATE (type
, i
);
15033 case DW_ACCESS_protected
:
15034 if (cu
->language
!= language_ada
)
15035 SET_TYPE_FIELD_PROTECTED (type
, i
);
15038 case DW_ACCESS_public
:
15042 /* Unknown accessibility. Complain and treat it as public. */
15044 complaint (_("unsupported accessibility %d"),
15045 field
.accessibility
);
15049 if (i
< fip
->baseclasses
.size ())
15051 switch (field
.virtuality
)
15053 case DW_VIRTUALITY_virtual
:
15054 case DW_VIRTUALITY_pure_virtual
:
15055 if (cu
->language
== language_ada
)
15056 error (_("unexpected virtuality in component of Ada type"));
15057 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15064 /* Return true if this member function is a constructor, false
15068 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15070 const char *fieldname
;
15071 const char *type_name
;
15074 if (die
->parent
== NULL
)
15077 if (die
->parent
->tag
!= DW_TAG_structure_type
15078 && die
->parent
->tag
!= DW_TAG_union_type
15079 && die
->parent
->tag
!= DW_TAG_class_type
)
15082 fieldname
= dwarf2_name (die
, cu
);
15083 type_name
= dwarf2_name (die
->parent
, cu
);
15084 if (fieldname
== NULL
|| type_name
== NULL
)
15087 len
= strlen (fieldname
);
15088 return (strncmp (fieldname
, type_name
, len
) == 0
15089 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15092 /* Check if the given VALUE is a recognized enum
15093 dwarf_defaulted_attribute constant according to DWARF5 spec,
15097 is_valid_DW_AT_defaulted (ULONGEST value
)
15101 case DW_DEFAULTED_no
:
15102 case DW_DEFAULTED_in_class
:
15103 case DW_DEFAULTED_out_of_class
:
15107 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15111 /* Add a member function to the proper fieldlist. */
15114 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15115 struct type
*type
, struct dwarf2_cu
*cu
)
15117 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15118 struct attribute
*attr
;
15120 struct fnfieldlist
*flp
= nullptr;
15121 struct fn_field
*fnp
;
15122 const char *fieldname
;
15123 struct type
*this_type
;
15124 enum dwarf_access_attribute accessibility
;
15126 if (cu
->language
== language_ada
)
15127 error (_("unexpected member function in Ada type"));
15129 /* Get name of member function. */
15130 fieldname
= dwarf2_name (die
, cu
);
15131 if (fieldname
== NULL
)
15134 /* Look up member function name in fieldlist. */
15135 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15137 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15139 flp
= &fip
->fnfieldlists
[i
];
15144 /* Create a new fnfieldlist if necessary. */
15145 if (flp
== nullptr)
15147 fip
->fnfieldlists
.emplace_back ();
15148 flp
= &fip
->fnfieldlists
.back ();
15149 flp
->name
= fieldname
;
15150 i
= fip
->fnfieldlists
.size () - 1;
15153 /* Create a new member function field and add it to the vector of
15155 flp
->fnfields
.emplace_back ();
15156 fnp
= &flp
->fnfields
.back ();
15158 /* Delay processing of the physname until later. */
15159 if (cu
->language
== language_cplus
)
15160 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15164 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15165 fnp
->physname
= physname
? physname
: "";
15168 fnp
->type
= alloc_type (objfile
);
15169 this_type
= read_type_die (die
, cu
);
15170 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15172 int nparams
= this_type
->num_fields ();
15174 /* TYPE is the domain of this method, and THIS_TYPE is the type
15175 of the method itself (TYPE_CODE_METHOD). */
15176 smash_to_method_type (fnp
->type
, type
,
15177 TYPE_TARGET_TYPE (this_type
),
15178 this_type
->fields (),
15179 this_type
->num_fields (),
15180 TYPE_VARARGS (this_type
));
15182 /* Handle static member functions.
15183 Dwarf2 has no clean way to discern C++ static and non-static
15184 member functions. G++ helps GDB by marking the first
15185 parameter for non-static member functions (which is the this
15186 pointer) as artificial. We obtain this information from
15187 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15188 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15189 fnp
->voffset
= VOFFSET_STATIC
;
15192 complaint (_("member function type missing for '%s'"),
15193 dwarf2_full_name (fieldname
, die
, cu
));
15195 /* Get fcontext from DW_AT_containing_type if present. */
15196 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15197 fnp
->fcontext
= die_containing_type (die
, cu
);
15199 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15200 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15202 /* Get accessibility. */
15203 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15204 if (attr
!= nullptr)
15205 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15207 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15208 switch (accessibility
)
15210 case DW_ACCESS_private
:
15211 fnp
->is_private
= 1;
15213 case DW_ACCESS_protected
:
15214 fnp
->is_protected
= 1;
15218 /* Check for artificial methods. */
15219 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15220 if (attr
&& DW_UNSND (attr
) != 0)
15221 fnp
->is_artificial
= 1;
15223 /* Check for defaulted methods. */
15224 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15225 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15226 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15228 /* Check for deleted methods. */
15229 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15230 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15231 fnp
->is_deleted
= 1;
15233 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15235 /* Get index in virtual function table if it is a virtual member
15236 function. For older versions of GCC, this is an offset in the
15237 appropriate virtual table, as specified by DW_AT_containing_type.
15238 For everyone else, it is an expression to be evaluated relative
15239 to the object address. */
15241 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15242 if (attr
!= nullptr)
15244 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15246 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15248 /* Old-style GCC. */
15249 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15251 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15252 || (DW_BLOCK (attr
)->size
> 1
15253 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15254 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15256 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15257 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15258 dwarf2_complex_location_expr_complaint ();
15260 fnp
->voffset
/= cu
->header
.addr_size
;
15264 dwarf2_complex_location_expr_complaint ();
15266 if (!fnp
->fcontext
)
15268 /* If there is no `this' field and no DW_AT_containing_type,
15269 we cannot actually find a base class context for the
15271 if (this_type
->num_fields () == 0
15272 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15274 complaint (_("cannot determine context for virtual member "
15275 "function \"%s\" (offset %s)"),
15276 fieldname
, sect_offset_str (die
->sect_off
));
15281 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15285 else if (attr
->form_is_section_offset ())
15287 dwarf2_complex_location_expr_complaint ();
15291 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15297 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15298 if (attr
&& DW_UNSND (attr
))
15300 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15301 complaint (_("Member function \"%s\" (offset %s) is virtual "
15302 "but the vtable offset is not specified"),
15303 fieldname
, sect_offset_str (die
->sect_off
));
15304 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15305 TYPE_CPLUS_DYNAMIC (type
) = 1;
15310 /* Create the vector of member function fields, and attach it to the type. */
15313 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15314 struct dwarf2_cu
*cu
)
15316 if (cu
->language
== language_ada
)
15317 error (_("unexpected member functions in Ada type"));
15319 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15320 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15322 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15324 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15326 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15327 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15329 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15330 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15331 fn_flp
->fn_fields
= (struct fn_field
*)
15332 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15334 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15335 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15338 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15341 /* Returns non-zero if NAME is the name of a vtable member in CU's
15342 language, zero otherwise. */
15344 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15346 static const char vptr
[] = "_vptr";
15348 /* Look for the C++ form of the vtable. */
15349 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15355 /* GCC outputs unnamed structures that are really pointers to member
15356 functions, with the ABI-specified layout. If TYPE describes
15357 such a structure, smash it into a member function type.
15359 GCC shouldn't do this; it should just output pointer to member DIEs.
15360 This is GCC PR debug/28767. */
15363 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15365 struct type
*pfn_type
, *self_type
, *new_type
;
15367 /* Check for a structure with no name and two children. */
15368 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15371 /* Check for __pfn and __delta members. */
15372 if (TYPE_FIELD_NAME (type
, 0) == NULL
15373 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15374 || TYPE_FIELD_NAME (type
, 1) == NULL
15375 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15378 /* Find the type of the method. */
15379 pfn_type
= type
->field (0).type ();
15380 if (pfn_type
== NULL
15381 || pfn_type
->code () != TYPE_CODE_PTR
15382 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15385 /* Look for the "this" argument. */
15386 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15387 if (pfn_type
->num_fields () == 0
15388 /* || pfn_type->field (0).type () == NULL */
15389 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15392 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15393 new_type
= alloc_type (objfile
);
15394 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15395 pfn_type
->fields (), pfn_type
->num_fields (),
15396 TYPE_VARARGS (pfn_type
));
15397 smash_to_methodptr_type (type
, new_type
);
15400 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15401 appropriate error checking and issuing complaints if there is a
15405 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15407 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15409 if (attr
== nullptr)
15412 if (!attr
->form_is_constant ())
15414 complaint (_("DW_AT_alignment must have constant form"
15415 " - DIE at %s [in module %s]"),
15416 sect_offset_str (die
->sect_off
),
15417 objfile_name (cu
->per_objfile
->objfile
));
15422 if (attr
->form
== DW_FORM_sdata
)
15424 LONGEST val
= DW_SND (attr
);
15427 complaint (_("DW_AT_alignment value must not be negative"
15428 " - DIE at %s [in module %s]"),
15429 sect_offset_str (die
->sect_off
),
15430 objfile_name (cu
->per_objfile
->objfile
));
15436 align
= DW_UNSND (attr
);
15440 complaint (_("DW_AT_alignment value must not be zero"
15441 " - DIE at %s [in module %s]"),
15442 sect_offset_str (die
->sect_off
),
15443 objfile_name (cu
->per_objfile
->objfile
));
15446 if ((align
& (align
- 1)) != 0)
15448 complaint (_("DW_AT_alignment value must be a power of 2"
15449 " - DIE at %s [in module %s]"),
15450 sect_offset_str (die
->sect_off
),
15451 objfile_name (cu
->per_objfile
->objfile
));
15458 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15459 the alignment for TYPE. */
15462 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15465 if (!set_type_align (type
, get_alignment (cu
, die
)))
15466 complaint (_("DW_AT_alignment value too large"
15467 " - DIE at %s [in module %s]"),
15468 sect_offset_str (die
->sect_off
),
15469 objfile_name (cu
->per_objfile
->objfile
));
15472 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15473 constant for a type, according to DWARF5 spec, Table 5.5. */
15476 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15481 case DW_CC_pass_by_reference
:
15482 case DW_CC_pass_by_value
:
15486 complaint (_("unrecognized DW_AT_calling_convention value "
15487 "(%s) for a type"), pulongest (value
));
15492 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15493 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15494 also according to GNU-specific values (see include/dwarf2.h). */
15497 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15502 case DW_CC_program
:
15506 case DW_CC_GNU_renesas_sh
:
15507 case DW_CC_GNU_borland_fastcall_i386
:
15508 case DW_CC_GDB_IBM_OpenCL
:
15512 complaint (_("unrecognized DW_AT_calling_convention value "
15513 "(%s) for a subroutine"), pulongest (value
));
15518 /* Called when we find the DIE that starts a structure or union scope
15519 (definition) to create a type for the structure or union. Fill in
15520 the type's name and general properties; the members will not be
15521 processed until process_structure_scope. A symbol table entry for
15522 the type will also not be done until process_structure_scope (assuming
15523 the type has a name).
15525 NOTE: we need to call these functions regardless of whether or not the
15526 DIE has a DW_AT_name attribute, since it might be an anonymous
15527 structure or union. This gets the type entered into our set of
15528 user defined types. */
15530 static struct type
*
15531 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15533 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15535 struct attribute
*attr
;
15538 /* If the definition of this type lives in .debug_types, read that type.
15539 Don't follow DW_AT_specification though, that will take us back up
15540 the chain and we want to go down. */
15541 attr
= die
->attr (DW_AT_signature
);
15542 if (attr
!= nullptr)
15544 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15546 /* The type's CU may not be the same as CU.
15547 Ensure TYPE is recorded with CU in die_type_hash. */
15548 return set_die_type (die
, type
, cu
);
15551 type
= alloc_type (objfile
);
15552 INIT_CPLUS_SPECIFIC (type
);
15554 name
= dwarf2_name (die
, cu
);
15557 if (cu
->language
== language_cplus
15558 || cu
->language
== language_d
15559 || cu
->language
== language_rust
)
15561 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15563 /* dwarf2_full_name might have already finished building the DIE's
15564 type. If so, there is no need to continue. */
15565 if (get_die_type (die
, cu
) != NULL
)
15566 return get_die_type (die
, cu
);
15568 type
->set_name (full_name
);
15572 /* The name is already allocated along with this objfile, so
15573 we don't need to duplicate it for the type. */
15574 type
->set_name (name
);
15578 if (die
->tag
== DW_TAG_structure_type
)
15580 type
->set_code (TYPE_CODE_STRUCT
);
15582 else if (die
->tag
== DW_TAG_union_type
)
15584 type
->set_code (TYPE_CODE_UNION
);
15588 type
->set_code (TYPE_CODE_STRUCT
);
15591 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15592 TYPE_DECLARED_CLASS (type
) = 1;
15594 /* Store the calling convention in the type if it's available in
15595 the die. Otherwise the calling convention remains set to
15596 the default value DW_CC_normal. */
15597 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15598 if (attr
!= nullptr
15599 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15601 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15602 TYPE_CPLUS_CALLING_CONVENTION (type
)
15603 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15606 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15607 if (attr
!= nullptr)
15609 if (attr
->form_is_constant ())
15610 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15613 struct dynamic_prop prop
;
15614 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15615 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15616 TYPE_LENGTH (type
) = 0;
15621 TYPE_LENGTH (type
) = 0;
15624 maybe_set_alignment (cu
, die
, type
);
15626 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15628 /* ICC<14 does not output the required DW_AT_declaration on
15629 incomplete types, but gives them a size of zero. */
15630 TYPE_STUB (type
) = 1;
15633 TYPE_STUB_SUPPORTED (type
) = 1;
15635 if (die_is_declaration (die
, cu
))
15636 TYPE_STUB (type
) = 1;
15637 else if (attr
== NULL
&& die
->child
== NULL
15638 && producer_is_realview (cu
->producer
))
15639 /* RealView does not output the required DW_AT_declaration
15640 on incomplete types. */
15641 TYPE_STUB (type
) = 1;
15643 /* We need to add the type field to the die immediately so we don't
15644 infinitely recurse when dealing with pointers to the structure
15645 type within the structure itself. */
15646 set_die_type (die
, type
, cu
);
15648 /* set_die_type should be already done. */
15649 set_descriptive_type (type
, die
, cu
);
15654 static void handle_struct_member_die
15655 (struct die_info
*child_die
,
15657 struct field_info
*fi
,
15658 std::vector
<struct symbol
*> *template_args
,
15659 struct dwarf2_cu
*cu
);
15661 /* A helper for handle_struct_member_die that handles
15662 DW_TAG_variant_part. */
15665 handle_variant_part (struct die_info
*die
, struct type
*type
,
15666 struct field_info
*fi
,
15667 std::vector
<struct symbol
*> *template_args
,
15668 struct dwarf2_cu
*cu
)
15670 variant_part_builder
*new_part
;
15671 if (fi
->current_variant_part
== nullptr)
15673 fi
->variant_parts
.emplace_back ();
15674 new_part
= &fi
->variant_parts
.back ();
15676 else if (!fi
->current_variant_part
->processing_variant
)
15678 complaint (_("nested DW_TAG_variant_part seen "
15679 "- DIE at %s [in module %s]"),
15680 sect_offset_str (die
->sect_off
),
15681 objfile_name (cu
->per_objfile
->objfile
));
15686 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15687 current
.variant_parts
.emplace_back ();
15688 new_part
= ¤t
.variant_parts
.back ();
15691 /* When we recurse, we want callees to add to this new variant
15693 scoped_restore save_current_variant_part
15694 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15696 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15699 /* It's a univariant form, an extension we support. */
15701 else if (discr
->form_is_ref ())
15703 struct dwarf2_cu
*target_cu
= cu
;
15704 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15706 new_part
->discriminant_offset
= target_die
->sect_off
;
15710 complaint (_("DW_AT_discr does not have DIE reference form"
15711 " - DIE at %s [in module %s]"),
15712 sect_offset_str (die
->sect_off
),
15713 objfile_name (cu
->per_objfile
->objfile
));
15716 for (die_info
*child_die
= die
->child
;
15718 child_die
= child_die
->sibling
)
15719 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15722 /* A helper for handle_struct_member_die that handles
15726 handle_variant (struct die_info
*die
, struct type
*type
,
15727 struct field_info
*fi
,
15728 std::vector
<struct symbol
*> *template_args
,
15729 struct dwarf2_cu
*cu
)
15731 if (fi
->current_variant_part
== nullptr)
15733 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15734 "- DIE at %s [in module %s]"),
15735 sect_offset_str (die
->sect_off
),
15736 objfile_name (cu
->per_objfile
->objfile
));
15739 if (fi
->current_variant_part
->processing_variant
)
15741 complaint (_("nested DW_TAG_variant seen "
15742 "- DIE at %s [in module %s]"),
15743 sect_offset_str (die
->sect_off
),
15744 objfile_name (cu
->per_objfile
->objfile
));
15748 scoped_restore save_processing_variant
15749 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15752 fi
->current_variant_part
->variants
.emplace_back ();
15753 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15754 variant
.first_field
= fi
->fields
.size ();
15756 /* In a variant we want to get the discriminant and also add a
15757 field for our sole member child. */
15758 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15759 if (discr
== nullptr)
15761 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15762 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15763 variant
.default_branch
= true;
15765 variant
.discr_list_data
= DW_BLOCK (discr
);
15768 variant
.discriminant_value
= DW_UNSND (discr
);
15770 for (die_info
*variant_child
= die
->child
;
15771 variant_child
!= NULL
;
15772 variant_child
= variant_child
->sibling
)
15773 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15775 variant
.last_field
= fi
->fields
.size ();
15778 /* A helper for process_structure_scope that handles a single member
15782 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15783 struct field_info
*fi
,
15784 std::vector
<struct symbol
*> *template_args
,
15785 struct dwarf2_cu
*cu
)
15787 if (child_die
->tag
== DW_TAG_member
15788 || child_die
->tag
== DW_TAG_variable
)
15790 /* NOTE: carlton/2002-11-05: A C++ static data member
15791 should be a DW_TAG_member that is a declaration, but
15792 all versions of G++ as of this writing (so through at
15793 least 3.2.1) incorrectly generate DW_TAG_variable
15794 tags for them instead. */
15795 dwarf2_add_field (fi
, child_die
, cu
);
15797 else if (child_die
->tag
== DW_TAG_subprogram
)
15799 /* Rust doesn't have member functions in the C++ sense.
15800 However, it does emit ordinary functions as children
15801 of a struct DIE. */
15802 if (cu
->language
== language_rust
)
15803 read_func_scope (child_die
, cu
);
15806 /* C++ member function. */
15807 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15810 else if (child_die
->tag
== DW_TAG_inheritance
)
15812 /* C++ base class field. */
15813 dwarf2_add_field (fi
, child_die
, cu
);
15815 else if (type_can_define_types (child_die
))
15816 dwarf2_add_type_defn (fi
, child_die
, cu
);
15817 else if (child_die
->tag
== DW_TAG_template_type_param
15818 || child_die
->tag
== DW_TAG_template_value_param
)
15820 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15823 template_args
->push_back (arg
);
15825 else if (child_die
->tag
== DW_TAG_variant_part
)
15826 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15827 else if (child_die
->tag
== DW_TAG_variant
)
15828 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15831 /* Finish creating a structure or union type, including filling in
15832 its members and creating a symbol for it. */
15835 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15837 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15838 struct die_info
*child_die
;
15841 type
= get_die_type (die
, cu
);
15843 type
= read_structure_type (die
, cu
);
15845 bool has_template_parameters
= false;
15846 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15848 struct field_info fi
;
15849 std::vector
<struct symbol
*> template_args
;
15851 child_die
= die
->child
;
15853 while (child_die
&& child_die
->tag
)
15855 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15856 child_die
= child_die
->sibling
;
15859 /* Attach template arguments to type. */
15860 if (!template_args
.empty ())
15862 has_template_parameters
= true;
15863 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15864 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15865 TYPE_TEMPLATE_ARGUMENTS (type
)
15866 = XOBNEWVEC (&objfile
->objfile_obstack
,
15868 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15869 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15870 template_args
.data (),
15871 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15872 * sizeof (struct symbol
*)));
15875 /* Attach fields and member functions to the type. */
15876 if (fi
.nfields () > 0)
15877 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15878 if (!fi
.fnfieldlists
.empty ())
15880 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15882 /* Get the type which refers to the base class (possibly this
15883 class itself) which contains the vtable pointer for the current
15884 class from the DW_AT_containing_type attribute. This use of
15885 DW_AT_containing_type is a GNU extension. */
15887 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15889 struct type
*t
= die_containing_type (die
, cu
);
15891 set_type_vptr_basetype (type
, t
);
15896 /* Our own class provides vtbl ptr. */
15897 for (i
= t
->num_fields () - 1;
15898 i
>= TYPE_N_BASECLASSES (t
);
15901 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15903 if (is_vtable_name (fieldname
, cu
))
15905 set_type_vptr_fieldno (type
, i
);
15910 /* Complain if virtual function table field not found. */
15911 if (i
< TYPE_N_BASECLASSES (t
))
15912 complaint (_("virtual function table pointer "
15913 "not found when defining class '%s'"),
15914 type
->name () ? type
->name () : "");
15918 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15921 else if (cu
->producer
15922 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15924 /* The IBM XLC compiler does not provide direct indication
15925 of the containing type, but the vtable pointer is
15926 always named __vfp. */
15930 for (i
= type
->num_fields () - 1;
15931 i
>= TYPE_N_BASECLASSES (type
);
15934 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15936 set_type_vptr_fieldno (type
, i
);
15937 set_type_vptr_basetype (type
, type
);
15944 /* Copy fi.typedef_field_list linked list elements content into the
15945 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15946 if (!fi
.typedef_field_list
.empty ())
15948 int count
= fi
.typedef_field_list
.size ();
15950 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15951 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15952 = ((struct decl_field
*)
15954 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15955 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15957 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15958 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15961 /* Copy fi.nested_types_list linked list elements content into the
15962 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15963 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15965 int count
= fi
.nested_types_list
.size ();
15967 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15968 TYPE_NESTED_TYPES_ARRAY (type
)
15969 = ((struct decl_field
*)
15970 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15971 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15973 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15974 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15978 quirk_gcc_member_function_pointer (type
, objfile
);
15979 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15980 cu
->rust_unions
.push_back (type
);
15982 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15983 snapshots) has been known to create a die giving a declaration
15984 for a class that has, as a child, a die giving a definition for a
15985 nested class. So we have to process our children even if the
15986 current die is a declaration. Normally, of course, a declaration
15987 won't have any children at all. */
15989 child_die
= die
->child
;
15991 while (child_die
!= NULL
&& child_die
->tag
)
15993 if (child_die
->tag
== DW_TAG_member
15994 || child_die
->tag
== DW_TAG_variable
15995 || child_die
->tag
== DW_TAG_inheritance
15996 || child_die
->tag
== DW_TAG_template_value_param
15997 || child_die
->tag
== DW_TAG_template_type_param
)
16002 process_die (child_die
, cu
);
16004 child_die
= child_die
->sibling
;
16007 /* Do not consider external references. According to the DWARF standard,
16008 these DIEs are identified by the fact that they have no byte_size
16009 attribute, and a declaration attribute. */
16010 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16011 || !die_is_declaration (die
, cu
)
16012 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16014 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16016 if (has_template_parameters
)
16018 struct symtab
*symtab
;
16019 if (sym
!= nullptr)
16020 symtab
= symbol_symtab (sym
);
16021 else if (cu
->line_header
!= nullptr)
16023 /* Any related symtab will do. */
16025 = cu
->line_header
->file_names ()[0].symtab
;
16030 complaint (_("could not find suitable "
16031 "symtab for template parameter"
16032 " - DIE at %s [in module %s]"),
16033 sect_offset_str (die
->sect_off
),
16034 objfile_name (objfile
));
16037 if (symtab
!= nullptr)
16039 /* Make sure that the symtab is set on the new symbols.
16040 Even though they don't appear in this symtab directly,
16041 other parts of gdb assume that symbols do, and this is
16042 reasonably true. */
16043 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16044 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16050 /* Assuming DIE is an enumeration type, and TYPE is its associated
16051 type, update TYPE using some information only available in DIE's
16052 children. In particular, the fields are computed. */
16055 update_enumeration_type_from_children (struct die_info
*die
,
16057 struct dwarf2_cu
*cu
)
16059 struct die_info
*child_die
;
16060 int unsigned_enum
= 1;
16063 auto_obstack obstack
;
16064 std::vector
<struct field
> fields
;
16066 for (child_die
= die
->child
;
16067 child_die
!= NULL
&& child_die
->tag
;
16068 child_die
= child_die
->sibling
)
16070 struct attribute
*attr
;
16072 const gdb_byte
*bytes
;
16073 struct dwarf2_locexpr_baton
*baton
;
16076 if (child_die
->tag
!= DW_TAG_enumerator
)
16079 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16083 name
= dwarf2_name (child_die
, cu
);
16085 name
= "<anonymous enumerator>";
16087 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16088 &value
, &bytes
, &baton
);
16096 if (count_one_bits_ll (value
) >= 2)
16100 fields
.emplace_back ();
16101 struct field
&field
= fields
.back ();
16102 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16103 SET_FIELD_ENUMVAL (field
, value
);
16106 if (!fields
.empty ())
16108 type
->set_num_fields (fields
.size ());
16111 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16112 memcpy (type
->fields (), fields
.data (),
16113 sizeof (struct field
) * fields
.size ());
16117 TYPE_UNSIGNED (type
) = 1;
16119 TYPE_FLAG_ENUM (type
) = 1;
16122 /* Given a DW_AT_enumeration_type die, set its type. We do not
16123 complete the type's fields yet, or create any symbols. */
16125 static struct type
*
16126 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16128 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16130 struct attribute
*attr
;
16133 /* If the definition of this type lives in .debug_types, read that type.
16134 Don't follow DW_AT_specification though, that will take us back up
16135 the chain and we want to go down. */
16136 attr
= die
->attr (DW_AT_signature
);
16137 if (attr
!= nullptr)
16139 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16141 /* The type's CU may not be the same as CU.
16142 Ensure TYPE is recorded with CU in die_type_hash. */
16143 return set_die_type (die
, type
, cu
);
16146 type
= alloc_type (objfile
);
16148 type
->set_code (TYPE_CODE_ENUM
);
16149 name
= dwarf2_full_name (NULL
, die
, cu
);
16151 type
->set_name (name
);
16153 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16156 struct type
*underlying_type
= die_type (die
, cu
);
16158 TYPE_TARGET_TYPE (type
) = underlying_type
;
16161 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16162 if (attr
!= nullptr)
16164 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16168 TYPE_LENGTH (type
) = 0;
16171 maybe_set_alignment (cu
, die
, type
);
16173 /* The enumeration DIE can be incomplete. In Ada, any type can be
16174 declared as private in the package spec, and then defined only
16175 inside the package body. Such types are known as Taft Amendment
16176 Types. When another package uses such a type, an incomplete DIE
16177 may be generated by the compiler. */
16178 if (die_is_declaration (die
, cu
))
16179 TYPE_STUB (type
) = 1;
16181 /* If this type has an underlying type that is not a stub, then we
16182 may use its attributes. We always use the "unsigned" attribute
16183 in this situation, because ordinarily we guess whether the type
16184 is unsigned -- but the guess can be wrong and the underlying type
16185 can tell us the reality. However, we defer to a local size
16186 attribute if one exists, because this lets the compiler override
16187 the underlying type if needed. */
16188 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16190 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16191 underlying_type
= check_typedef (underlying_type
);
16192 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16193 if (TYPE_LENGTH (type
) == 0)
16194 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16195 if (TYPE_RAW_ALIGN (type
) == 0
16196 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16197 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16200 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16202 set_die_type (die
, type
, cu
);
16204 /* Finish the creation of this type by using the enum's children.
16205 Note that, as usual, this must come after set_die_type to avoid
16206 infinite recursion when trying to compute the names of the
16208 update_enumeration_type_from_children (die
, type
, cu
);
16213 /* Given a pointer to a die which begins an enumeration, process all
16214 the dies that define the members of the enumeration, and create the
16215 symbol for the enumeration type.
16217 NOTE: We reverse the order of the element list. */
16220 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16222 struct type
*this_type
;
16224 this_type
= get_die_type (die
, cu
);
16225 if (this_type
== NULL
)
16226 this_type
= read_enumeration_type (die
, cu
);
16228 if (die
->child
!= NULL
)
16230 struct die_info
*child_die
;
16233 child_die
= die
->child
;
16234 while (child_die
&& child_die
->tag
)
16236 if (child_die
->tag
!= DW_TAG_enumerator
)
16238 process_die (child_die
, cu
);
16242 name
= dwarf2_name (child_die
, cu
);
16244 new_symbol (child_die
, this_type
, cu
);
16247 child_die
= child_die
->sibling
;
16251 /* If we are reading an enum from a .debug_types unit, and the enum
16252 is a declaration, and the enum is not the signatured type in the
16253 unit, then we do not want to add a symbol for it. Adding a
16254 symbol would in some cases obscure the true definition of the
16255 enum, giving users an incomplete type when the definition is
16256 actually available. Note that we do not want to do this for all
16257 enums which are just declarations, because C++0x allows forward
16258 enum declarations. */
16259 if (cu
->per_cu
->is_debug_types
16260 && die_is_declaration (die
, cu
))
16262 struct signatured_type
*sig_type
;
16264 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16265 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16266 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16270 new_symbol (die
, this_type
, cu
);
16273 /* Extract all information from a DW_TAG_array_type DIE and put it in
16274 the DIE's type field. For now, this only handles one dimensional
16277 static struct type
*
16278 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16280 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16281 struct die_info
*child_die
;
16283 struct type
*element_type
, *range_type
, *index_type
;
16284 struct attribute
*attr
;
16286 struct dynamic_prop
*byte_stride_prop
= NULL
;
16287 unsigned int bit_stride
= 0;
16289 element_type
= die_type (die
, cu
);
16291 /* The die_type call above may have already set the type for this DIE. */
16292 type
= get_die_type (die
, cu
);
16296 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16300 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16303 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16304 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16308 complaint (_("unable to read array DW_AT_byte_stride "
16309 " - DIE at %s [in module %s]"),
16310 sect_offset_str (die
->sect_off
),
16311 objfile_name (cu
->per_objfile
->objfile
));
16312 /* Ignore this attribute. We will likely not be able to print
16313 arrays of this type correctly, but there is little we can do
16314 to help if we cannot read the attribute's value. */
16315 byte_stride_prop
= NULL
;
16319 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16321 bit_stride
= DW_UNSND (attr
);
16323 /* Irix 6.2 native cc creates array types without children for
16324 arrays with unspecified length. */
16325 if (die
->child
== NULL
)
16327 index_type
= objfile_type (objfile
)->builtin_int
;
16328 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16329 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16330 byte_stride_prop
, bit_stride
);
16331 return set_die_type (die
, type
, cu
);
16334 std::vector
<struct type
*> range_types
;
16335 child_die
= die
->child
;
16336 while (child_die
&& child_die
->tag
)
16338 if (child_die
->tag
== DW_TAG_subrange_type
)
16340 struct type
*child_type
= read_type_die (child_die
, cu
);
16342 if (child_type
!= NULL
)
16344 /* The range type was succesfully read. Save it for the
16345 array type creation. */
16346 range_types
.push_back (child_type
);
16349 child_die
= child_die
->sibling
;
16352 /* Dwarf2 dimensions are output from left to right, create the
16353 necessary array types in backwards order. */
16355 type
= element_type
;
16357 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16361 while (i
< range_types
.size ())
16362 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16363 byte_stride_prop
, bit_stride
);
16367 size_t ndim
= range_types
.size ();
16369 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16370 byte_stride_prop
, bit_stride
);
16373 /* Understand Dwarf2 support for vector types (like they occur on
16374 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16375 array type. This is not part of the Dwarf2/3 standard yet, but a
16376 custom vendor extension. The main difference between a regular
16377 array and the vector variant is that vectors are passed by value
16379 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16380 if (attr
!= nullptr)
16381 make_vector_type (type
);
16383 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16384 implementation may choose to implement triple vectors using this
16386 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16387 if (attr
!= nullptr)
16389 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16390 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16392 complaint (_("DW_AT_byte_size for array type smaller "
16393 "than the total size of elements"));
16396 name
= dwarf2_name (die
, cu
);
16398 type
->set_name (name
);
16400 maybe_set_alignment (cu
, die
, type
);
16402 /* Install the type in the die. */
16403 set_die_type (die
, type
, cu
);
16405 /* set_die_type should be already done. */
16406 set_descriptive_type (type
, die
, cu
);
16411 static enum dwarf_array_dim_ordering
16412 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16414 struct attribute
*attr
;
16416 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16418 if (attr
!= nullptr)
16419 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16421 /* GNU F77 is a special case, as at 08/2004 array type info is the
16422 opposite order to the dwarf2 specification, but data is still
16423 laid out as per normal fortran.
16425 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16426 version checking. */
16428 if (cu
->language
== language_fortran
16429 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16431 return DW_ORD_row_major
;
16434 switch (cu
->language_defn
->la_array_ordering
)
16436 case array_column_major
:
16437 return DW_ORD_col_major
;
16438 case array_row_major
:
16440 return DW_ORD_row_major
;
16444 /* Extract all information from a DW_TAG_set_type DIE and put it in
16445 the DIE's type field. */
16447 static struct type
*
16448 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16450 struct type
*domain_type
, *set_type
;
16451 struct attribute
*attr
;
16453 domain_type
= die_type (die
, cu
);
16455 /* The die_type call above may have already set the type for this DIE. */
16456 set_type
= get_die_type (die
, cu
);
16460 set_type
= create_set_type (NULL
, domain_type
);
16462 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16463 if (attr
!= nullptr)
16464 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16466 maybe_set_alignment (cu
, die
, set_type
);
16468 return set_die_type (die
, set_type
, cu
);
16471 /* A helper for read_common_block that creates a locexpr baton.
16472 SYM is the symbol which we are marking as computed.
16473 COMMON_DIE is the DIE for the common block.
16474 COMMON_LOC is the location expression attribute for the common
16476 MEMBER_LOC is the location expression attribute for the particular
16477 member of the common block that we are processing.
16478 CU is the CU from which the above come. */
16481 mark_common_block_symbol_computed (struct symbol
*sym
,
16482 struct die_info
*common_die
,
16483 struct attribute
*common_loc
,
16484 struct attribute
*member_loc
,
16485 struct dwarf2_cu
*cu
)
16487 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16488 struct objfile
*objfile
= per_objfile
->objfile
;
16489 struct dwarf2_locexpr_baton
*baton
;
16491 unsigned int cu_off
;
16492 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16493 LONGEST offset
= 0;
16495 gdb_assert (common_loc
&& member_loc
);
16496 gdb_assert (common_loc
->form_is_block ());
16497 gdb_assert (member_loc
->form_is_block ()
16498 || member_loc
->form_is_constant ());
16500 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16501 baton
->per_objfile
= per_objfile
;
16502 baton
->per_cu
= cu
->per_cu
;
16503 gdb_assert (baton
->per_cu
);
16505 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16507 if (member_loc
->form_is_constant ())
16509 offset
= member_loc
->constant_value (0);
16510 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16513 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16515 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16518 *ptr
++ = DW_OP_call4
;
16519 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16520 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16523 if (member_loc
->form_is_constant ())
16525 *ptr
++ = DW_OP_addr
;
16526 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16527 ptr
+= cu
->header
.addr_size
;
16531 /* We have to copy the data here, because DW_OP_call4 will only
16532 use a DW_AT_location attribute. */
16533 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16534 ptr
+= DW_BLOCK (member_loc
)->size
;
16537 *ptr
++ = DW_OP_plus
;
16538 gdb_assert (ptr
- baton
->data
== baton
->size
);
16540 SYMBOL_LOCATION_BATON (sym
) = baton
;
16541 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16544 /* Create appropriate locally-scoped variables for all the
16545 DW_TAG_common_block entries. Also create a struct common_block
16546 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16547 is used to separate the common blocks name namespace from regular
16551 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16553 struct attribute
*attr
;
16555 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16556 if (attr
!= nullptr)
16558 /* Support the .debug_loc offsets. */
16559 if (attr
->form_is_block ())
16563 else if (attr
->form_is_section_offset ())
16565 dwarf2_complex_location_expr_complaint ();
16570 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16571 "common block member");
16576 if (die
->child
!= NULL
)
16578 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16579 struct die_info
*child_die
;
16580 size_t n_entries
= 0, size
;
16581 struct common_block
*common_block
;
16582 struct symbol
*sym
;
16584 for (child_die
= die
->child
;
16585 child_die
&& child_die
->tag
;
16586 child_die
= child_die
->sibling
)
16589 size
= (sizeof (struct common_block
)
16590 + (n_entries
- 1) * sizeof (struct symbol
*));
16592 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16594 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16595 common_block
->n_entries
= 0;
16597 for (child_die
= die
->child
;
16598 child_die
&& child_die
->tag
;
16599 child_die
= child_die
->sibling
)
16601 /* Create the symbol in the DW_TAG_common_block block in the current
16603 sym
= new_symbol (child_die
, NULL
, cu
);
16606 struct attribute
*member_loc
;
16608 common_block
->contents
[common_block
->n_entries
++] = sym
;
16610 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16614 /* GDB has handled this for a long time, but it is
16615 not specified by DWARF. It seems to have been
16616 emitted by gfortran at least as recently as:
16617 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16618 complaint (_("Variable in common block has "
16619 "DW_AT_data_member_location "
16620 "- DIE at %s [in module %s]"),
16621 sect_offset_str (child_die
->sect_off
),
16622 objfile_name (objfile
));
16624 if (member_loc
->form_is_section_offset ())
16625 dwarf2_complex_location_expr_complaint ();
16626 else if (member_loc
->form_is_constant ()
16627 || member_loc
->form_is_block ())
16629 if (attr
!= nullptr)
16630 mark_common_block_symbol_computed (sym
, die
, attr
,
16634 dwarf2_complex_location_expr_complaint ();
16639 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16640 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16644 /* Create a type for a C++ namespace. */
16646 static struct type
*
16647 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16649 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16650 const char *previous_prefix
, *name
;
16654 /* For extensions, reuse the type of the original namespace. */
16655 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16657 struct die_info
*ext_die
;
16658 struct dwarf2_cu
*ext_cu
= cu
;
16660 ext_die
= dwarf2_extension (die
, &ext_cu
);
16661 type
= read_type_die (ext_die
, ext_cu
);
16663 /* EXT_CU may not be the same as CU.
16664 Ensure TYPE is recorded with CU in die_type_hash. */
16665 return set_die_type (die
, type
, cu
);
16668 name
= namespace_name (die
, &is_anonymous
, cu
);
16670 /* Now build the name of the current namespace. */
16672 previous_prefix
= determine_prefix (die
, cu
);
16673 if (previous_prefix
[0] != '\0')
16674 name
= typename_concat (&objfile
->objfile_obstack
,
16675 previous_prefix
, name
, 0, cu
);
16677 /* Create the type. */
16678 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16680 return set_die_type (die
, type
, cu
);
16683 /* Read a namespace scope. */
16686 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16688 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16691 /* Add a symbol associated to this if we haven't seen the namespace
16692 before. Also, add a using directive if it's an anonymous
16695 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16699 type
= read_type_die (die
, cu
);
16700 new_symbol (die
, type
, cu
);
16702 namespace_name (die
, &is_anonymous
, cu
);
16705 const char *previous_prefix
= determine_prefix (die
, cu
);
16707 std::vector
<const char *> excludes
;
16708 add_using_directive (using_directives (cu
),
16709 previous_prefix
, type
->name (), NULL
,
16710 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16714 if (die
->child
!= NULL
)
16716 struct die_info
*child_die
= die
->child
;
16718 while (child_die
&& child_die
->tag
)
16720 process_die (child_die
, cu
);
16721 child_die
= child_die
->sibling
;
16726 /* Read a Fortran module as type. This DIE can be only a declaration used for
16727 imported module. Still we need that type as local Fortran "use ... only"
16728 declaration imports depend on the created type in determine_prefix. */
16730 static struct type
*
16731 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16733 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16734 const char *module_name
;
16737 module_name
= dwarf2_name (die
, cu
);
16738 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16740 return set_die_type (die
, type
, cu
);
16743 /* Read a Fortran module. */
16746 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16748 struct die_info
*child_die
= die
->child
;
16751 type
= read_type_die (die
, cu
);
16752 new_symbol (die
, type
, cu
);
16754 while (child_die
&& child_die
->tag
)
16756 process_die (child_die
, cu
);
16757 child_die
= child_die
->sibling
;
16761 /* Return the name of the namespace represented by DIE. Set
16762 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16765 static const char *
16766 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16768 struct die_info
*current_die
;
16769 const char *name
= NULL
;
16771 /* Loop through the extensions until we find a name. */
16773 for (current_die
= die
;
16774 current_die
!= NULL
;
16775 current_die
= dwarf2_extension (die
, &cu
))
16777 /* We don't use dwarf2_name here so that we can detect the absence
16778 of a name -> anonymous namespace. */
16779 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16785 /* Is it an anonymous namespace? */
16787 *is_anonymous
= (name
== NULL
);
16789 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16794 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16795 the user defined type vector. */
16797 static struct type
*
16798 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16800 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16801 struct comp_unit_head
*cu_header
= &cu
->header
;
16803 struct attribute
*attr_byte_size
;
16804 struct attribute
*attr_address_class
;
16805 int byte_size
, addr_class
;
16806 struct type
*target_type
;
16808 target_type
= die_type (die
, cu
);
16810 /* The die_type call above may have already set the type for this DIE. */
16811 type
= get_die_type (die
, cu
);
16815 type
= lookup_pointer_type (target_type
);
16817 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16818 if (attr_byte_size
)
16819 byte_size
= DW_UNSND (attr_byte_size
);
16821 byte_size
= cu_header
->addr_size
;
16823 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16824 if (attr_address_class
)
16825 addr_class
= DW_UNSND (attr_address_class
);
16827 addr_class
= DW_ADDR_none
;
16829 ULONGEST alignment
= get_alignment (cu
, die
);
16831 /* If the pointer size, alignment, or address class is different
16832 than the default, create a type variant marked as such and set
16833 the length accordingly. */
16834 if (TYPE_LENGTH (type
) != byte_size
16835 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16836 && alignment
!= TYPE_RAW_ALIGN (type
))
16837 || addr_class
!= DW_ADDR_none
)
16839 if (gdbarch_address_class_type_flags_p (gdbarch
))
16843 type_flags
= gdbarch_address_class_type_flags
16844 (gdbarch
, byte_size
, addr_class
);
16845 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16847 type
= make_type_with_address_space (type
, type_flags
);
16849 else if (TYPE_LENGTH (type
) != byte_size
)
16851 complaint (_("invalid pointer size %d"), byte_size
);
16853 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16855 complaint (_("Invalid DW_AT_alignment"
16856 " - DIE at %s [in module %s]"),
16857 sect_offset_str (die
->sect_off
),
16858 objfile_name (cu
->per_objfile
->objfile
));
16862 /* Should we also complain about unhandled address classes? */
16866 TYPE_LENGTH (type
) = byte_size
;
16867 set_type_align (type
, alignment
);
16868 return set_die_type (die
, type
, cu
);
16871 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16872 the user defined type vector. */
16874 static struct type
*
16875 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16878 struct type
*to_type
;
16879 struct type
*domain
;
16881 to_type
= die_type (die
, cu
);
16882 domain
= die_containing_type (die
, cu
);
16884 /* The calls above may have already set the type for this DIE. */
16885 type
= get_die_type (die
, cu
);
16889 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16890 type
= lookup_methodptr_type (to_type
);
16891 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16893 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16895 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16896 to_type
->fields (), to_type
->num_fields (),
16897 TYPE_VARARGS (to_type
));
16898 type
= lookup_methodptr_type (new_type
);
16901 type
= lookup_memberptr_type (to_type
, domain
);
16903 return set_die_type (die
, type
, cu
);
16906 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16907 the user defined type vector. */
16909 static struct type
*
16910 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16911 enum type_code refcode
)
16913 struct comp_unit_head
*cu_header
= &cu
->header
;
16914 struct type
*type
, *target_type
;
16915 struct attribute
*attr
;
16917 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16919 target_type
= die_type (die
, cu
);
16921 /* The die_type call above may have already set the type for this DIE. */
16922 type
= get_die_type (die
, cu
);
16926 type
= lookup_reference_type (target_type
, refcode
);
16927 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16928 if (attr
!= nullptr)
16930 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16934 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16936 maybe_set_alignment (cu
, die
, type
);
16937 return set_die_type (die
, type
, cu
);
16940 /* Add the given cv-qualifiers to the element type of the array. GCC
16941 outputs DWARF type qualifiers that apply to an array, not the
16942 element type. But GDB relies on the array element type to carry
16943 the cv-qualifiers. This mimics section 6.7.3 of the C99
16946 static struct type
*
16947 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16948 struct type
*base_type
, int cnst
, int voltl
)
16950 struct type
*el_type
, *inner_array
;
16952 base_type
= copy_type (base_type
);
16953 inner_array
= base_type
;
16955 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16957 TYPE_TARGET_TYPE (inner_array
) =
16958 copy_type (TYPE_TARGET_TYPE (inner_array
));
16959 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16962 el_type
= TYPE_TARGET_TYPE (inner_array
);
16963 cnst
|= TYPE_CONST (el_type
);
16964 voltl
|= TYPE_VOLATILE (el_type
);
16965 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16967 return set_die_type (die
, base_type
, cu
);
16970 static struct type
*
16971 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16973 struct type
*base_type
, *cv_type
;
16975 base_type
= die_type (die
, cu
);
16977 /* The die_type call above may have already set the type for this DIE. */
16978 cv_type
= get_die_type (die
, cu
);
16982 /* In case the const qualifier is applied to an array type, the element type
16983 is so qualified, not the array type (section 6.7.3 of C99). */
16984 if (base_type
->code () == TYPE_CODE_ARRAY
)
16985 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16987 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16988 return set_die_type (die
, cv_type
, cu
);
16991 static struct type
*
16992 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16994 struct type
*base_type
, *cv_type
;
16996 base_type
= die_type (die
, cu
);
16998 /* The die_type call above may have already set the type for this DIE. */
16999 cv_type
= get_die_type (die
, cu
);
17003 /* In case the volatile qualifier is applied to an array type, the
17004 element type is so qualified, not the array type (section 6.7.3
17006 if (base_type
->code () == TYPE_CODE_ARRAY
)
17007 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17009 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17010 return set_die_type (die
, cv_type
, cu
);
17013 /* Handle DW_TAG_restrict_type. */
17015 static struct type
*
17016 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17018 struct type
*base_type
, *cv_type
;
17020 base_type
= die_type (die
, cu
);
17022 /* The die_type call above may have already set the type for this DIE. */
17023 cv_type
= get_die_type (die
, cu
);
17027 cv_type
= make_restrict_type (base_type
);
17028 return set_die_type (die
, cv_type
, cu
);
17031 /* Handle DW_TAG_atomic_type. */
17033 static struct type
*
17034 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17036 struct type
*base_type
, *cv_type
;
17038 base_type
= die_type (die
, cu
);
17040 /* The die_type call above may have already set the type for this DIE. */
17041 cv_type
= get_die_type (die
, cu
);
17045 cv_type
= make_atomic_type (base_type
);
17046 return set_die_type (die
, cv_type
, cu
);
17049 /* Extract all information from a DW_TAG_string_type DIE and add to
17050 the user defined type vector. It isn't really a user defined type,
17051 but it behaves like one, with other DIE's using an AT_user_def_type
17052 attribute to reference it. */
17054 static struct type
*
17055 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17057 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17058 struct gdbarch
*gdbarch
= objfile
->arch ();
17059 struct type
*type
, *range_type
, *index_type
, *char_type
;
17060 struct attribute
*attr
;
17061 struct dynamic_prop prop
;
17062 bool length_is_constant
= true;
17065 /* There are a couple of places where bit sizes might be made use of
17066 when parsing a DW_TAG_string_type, however, no producer that we know
17067 of make use of these. Handling bit sizes that are a multiple of the
17068 byte size is easy enough, but what about other bit sizes? Lets deal
17069 with that problem when we have to. Warn about these attributes being
17070 unsupported, then parse the type and ignore them like we always
17072 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17073 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17075 static bool warning_printed
= false;
17076 if (!warning_printed
)
17078 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17079 "currently supported on DW_TAG_string_type."));
17080 warning_printed
= true;
17084 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17085 if (attr
!= nullptr && !attr
->form_is_constant ())
17087 /* The string length describes the location at which the length of
17088 the string can be found. The size of the length field can be
17089 specified with one of the attributes below. */
17090 struct type
*prop_type
;
17091 struct attribute
*len
17092 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17093 if (len
== nullptr)
17094 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17095 if (len
!= nullptr && len
->form_is_constant ())
17097 /* Pass 0 as the default as we know this attribute is constant
17098 and the default value will not be returned. */
17099 LONGEST sz
= len
->constant_value (0);
17100 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17104 /* If the size is not specified then we assume it is the size of
17105 an address on this target. */
17106 prop_type
= cu
->addr_sized_int_type (true);
17109 /* Convert the attribute into a dynamic property. */
17110 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17113 length_is_constant
= false;
17115 else if (attr
!= nullptr)
17117 /* This DW_AT_string_length just contains the length with no
17118 indirection. There's no need to create a dynamic property in this
17119 case. Pass 0 for the default value as we know it will not be
17120 returned in this case. */
17121 length
= attr
->constant_value (0);
17123 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17125 /* We don't currently support non-constant byte sizes for strings. */
17126 length
= attr
->constant_value (1);
17130 /* Use 1 as a fallback length if we have nothing else. */
17134 index_type
= objfile_type (objfile
)->builtin_int
;
17135 if (length_is_constant
)
17136 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17139 struct dynamic_prop low_bound
;
17141 low_bound
.kind
= PROP_CONST
;
17142 low_bound
.data
.const_val
= 1;
17143 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17145 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17146 type
= create_string_type (NULL
, char_type
, range_type
);
17148 return set_die_type (die
, type
, cu
);
17151 /* Assuming that DIE corresponds to a function, returns nonzero
17152 if the function is prototyped. */
17155 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17157 struct attribute
*attr
;
17159 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17160 if (attr
&& (DW_UNSND (attr
) != 0))
17163 /* The DWARF standard implies that the DW_AT_prototyped attribute
17164 is only meaningful for C, but the concept also extends to other
17165 languages that allow unprototyped functions (Eg: Objective C).
17166 For all other languages, assume that functions are always
17168 if (cu
->language
!= language_c
17169 && cu
->language
!= language_objc
17170 && cu
->language
!= language_opencl
)
17173 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17174 prototyped and unprototyped functions; default to prototyped,
17175 since that is more common in modern code (and RealView warns
17176 about unprototyped functions). */
17177 if (producer_is_realview (cu
->producer
))
17183 /* Handle DIES due to C code like:
17187 int (*funcp)(int a, long l);
17191 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17193 static struct type
*
17194 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17196 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17197 struct type
*type
; /* Type that this function returns. */
17198 struct type
*ftype
; /* Function that returns above type. */
17199 struct attribute
*attr
;
17201 type
= die_type (die
, cu
);
17203 /* The die_type call above may have already set the type for this DIE. */
17204 ftype
= get_die_type (die
, cu
);
17208 ftype
= lookup_function_type (type
);
17210 if (prototyped_function_p (die
, cu
))
17211 TYPE_PROTOTYPED (ftype
) = 1;
17213 /* Store the calling convention in the type if it's available in
17214 the subroutine die. Otherwise set the calling convention to
17215 the default value DW_CC_normal. */
17216 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17217 if (attr
!= nullptr
17218 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17219 TYPE_CALLING_CONVENTION (ftype
)
17220 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17221 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17222 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17224 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17226 /* Record whether the function returns normally to its caller or not
17227 if the DWARF producer set that information. */
17228 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17229 if (attr
&& (DW_UNSND (attr
) != 0))
17230 TYPE_NO_RETURN (ftype
) = 1;
17232 /* We need to add the subroutine type to the die immediately so
17233 we don't infinitely recurse when dealing with parameters
17234 declared as the same subroutine type. */
17235 set_die_type (die
, ftype
, cu
);
17237 if (die
->child
!= NULL
)
17239 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17240 struct die_info
*child_die
;
17241 int nparams
, iparams
;
17243 /* Count the number of parameters.
17244 FIXME: GDB currently ignores vararg functions, but knows about
17245 vararg member functions. */
17247 child_die
= die
->child
;
17248 while (child_die
&& child_die
->tag
)
17250 if (child_die
->tag
== DW_TAG_formal_parameter
)
17252 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17253 TYPE_VARARGS (ftype
) = 1;
17254 child_die
= child_die
->sibling
;
17257 /* Allocate storage for parameters and fill them in. */
17258 ftype
->set_num_fields (nparams
);
17260 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17262 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17263 even if we error out during the parameters reading below. */
17264 for (iparams
= 0; iparams
< nparams
; iparams
++)
17265 ftype
->field (iparams
).set_type (void_type
);
17268 child_die
= die
->child
;
17269 while (child_die
&& child_die
->tag
)
17271 if (child_die
->tag
== DW_TAG_formal_parameter
)
17273 struct type
*arg_type
;
17275 /* DWARF version 2 has no clean way to discern C++
17276 static and non-static member functions. G++ helps
17277 GDB by marking the first parameter for non-static
17278 member functions (which is the this pointer) as
17279 artificial. We pass this information to
17280 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17282 DWARF version 3 added DW_AT_object_pointer, which GCC
17283 4.5 does not yet generate. */
17284 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17285 if (attr
!= nullptr)
17286 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17288 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17289 arg_type
= die_type (child_die
, cu
);
17291 /* RealView does not mark THIS as const, which the testsuite
17292 expects. GCC marks THIS as const in method definitions,
17293 but not in the class specifications (GCC PR 43053). */
17294 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17295 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17298 struct dwarf2_cu
*arg_cu
= cu
;
17299 const char *name
= dwarf2_name (child_die
, cu
);
17301 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17302 if (attr
!= nullptr)
17304 /* If the compiler emits this, use it. */
17305 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17308 else if (name
&& strcmp (name
, "this") == 0)
17309 /* Function definitions will have the argument names. */
17311 else if (name
== NULL
&& iparams
== 0)
17312 /* Declarations may not have the names, so like
17313 elsewhere in GDB, assume an artificial first
17314 argument is "this". */
17318 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17322 ftype
->field (iparams
).set_type (arg_type
);
17325 child_die
= child_die
->sibling
;
17332 static struct type
*
17333 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17335 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17336 const char *name
= NULL
;
17337 struct type
*this_type
, *target_type
;
17339 name
= dwarf2_full_name (NULL
, die
, cu
);
17340 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17341 TYPE_TARGET_STUB (this_type
) = 1;
17342 set_die_type (die
, this_type
, cu
);
17343 target_type
= die_type (die
, cu
);
17344 if (target_type
!= this_type
)
17345 TYPE_TARGET_TYPE (this_type
) = target_type
;
17348 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17349 spec and cause infinite loops in GDB. */
17350 complaint (_("Self-referential DW_TAG_typedef "
17351 "- DIE at %s [in module %s]"),
17352 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17353 TYPE_TARGET_TYPE (this_type
) = NULL
;
17357 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17358 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17359 Handle these by just returning the target type, rather than
17360 constructing an anonymous typedef type and trying to handle this
17362 set_die_type (die
, target_type
, cu
);
17363 return target_type
;
17368 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17369 (which may be different from NAME) to the architecture back-end to allow
17370 it to guess the correct format if necessary. */
17372 static struct type
*
17373 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17374 const char *name_hint
, enum bfd_endian byte_order
)
17376 struct gdbarch
*gdbarch
= objfile
->arch ();
17377 const struct floatformat
**format
;
17380 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17382 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17384 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17389 /* Allocate an integer type of size BITS and name NAME. */
17391 static struct type
*
17392 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17393 int bits
, int unsigned_p
, const char *name
)
17397 /* Versions of Intel's C Compiler generate an integer type called "void"
17398 instead of using DW_TAG_unspecified_type. This has been seen on
17399 at least versions 14, 17, and 18. */
17400 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17401 && strcmp (name
, "void") == 0)
17402 type
= objfile_type (objfile
)->builtin_void
;
17404 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17409 /* Initialise and return a floating point type of size BITS suitable for
17410 use as a component of a complex number. The NAME_HINT is passed through
17411 when initialising the floating point type and is the name of the complex
17414 As DWARF doesn't currently provide an explicit name for the components
17415 of a complex number, but it can be helpful to have these components
17416 named, we try to select a suitable name based on the size of the
17418 static struct type
*
17419 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17420 struct objfile
*objfile
,
17421 int bits
, const char *name_hint
,
17422 enum bfd_endian byte_order
)
17424 gdbarch
*gdbarch
= objfile
->arch ();
17425 struct type
*tt
= nullptr;
17427 /* Try to find a suitable floating point builtin type of size BITS.
17428 We're going to use the name of this type as the name for the complex
17429 target type that we are about to create. */
17430 switch (cu
->language
)
17432 case language_fortran
:
17436 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17439 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17441 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17443 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17451 tt
= builtin_type (gdbarch
)->builtin_float
;
17454 tt
= builtin_type (gdbarch
)->builtin_double
;
17456 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17458 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17464 /* If the type we found doesn't match the size we were looking for, then
17465 pretend we didn't find a type at all, the complex target type we
17466 create will then be nameless. */
17467 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17470 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17471 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17474 /* Find a representation of a given base type and install
17475 it in the TYPE field of the die. */
17477 static struct type
*
17478 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17480 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17482 struct attribute
*attr
;
17483 int encoding
= 0, bits
= 0;
17487 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17488 if (attr
!= nullptr)
17489 encoding
= DW_UNSND (attr
);
17490 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17491 if (attr
!= nullptr)
17492 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17493 name
= dwarf2_name (die
, cu
);
17495 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17497 arch
= objfile
->arch ();
17498 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17500 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17503 int endianity
= DW_UNSND (attr
);
17508 byte_order
= BFD_ENDIAN_BIG
;
17510 case DW_END_little
:
17511 byte_order
= BFD_ENDIAN_LITTLE
;
17514 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17521 case DW_ATE_address
:
17522 /* Turn DW_ATE_address into a void * pointer. */
17523 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17524 type
= init_pointer_type (objfile
, bits
, name
, type
);
17526 case DW_ATE_boolean
:
17527 type
= init_boolean_type (objfile
, bits
, 1, name
);
17529 case DW_ATE_complex_float
:
17530 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17532 if (type
->code () == TYPE_CODE_ERROR
)
17534 if (name
== nullptr)
17536 struct obstack
*obstack
17537 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17538 name
= obconcat (obstack
, "_Complex ", type
->name (),
17541 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17544 type
= init_complex_type (name
, type
);
17546 case DW_ATE_decimal_float
:
17547 type
= init_decfloat_type (objfile
, bits
, name
);
17550 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17552 case DW_ATE_signed
:
17553 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17555 case DW_ATE_unsigned
:
17556 if (cu
->language
== language_fortran
17558 && startswith (name
, "character("))
17559 type
= init_character_type (objfile
, bits
, 1, name
);
17561 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17563 case DW_ATE_signed_char
:
17564 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17565 || cu
->language
== language_pascal
17566 || cu
->language
== language_fortran
)
17567 type
= init_character_type (objfile
, bits
, 0, name
);
17569 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17571 case DW_ATE_unsigned_char
:
17572 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17573 || cu
->language
== language_pascal
17574 || cu
->language
== language_fortran
17575 || cu
->language
== language_rust
)
17576 type
= init_character_type (objfile
, bits
, 1, name
);
17578 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17583 type
= builtin_type (arch
)->builtin_char16
;
17584 else if (bits
== 32)
17585 type
= builtin_type (arch
)->builtin_char32
;
17588 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17590 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17592 return set_die_type (die
, type
, cu
);
17597 complaint (_("unsupported DW_AT_encoding: '%s'"),
17598 dwarf_type_encoding_name (encoding
));
17599 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17603 if (name
&& strcmp (name
, "char") == 0)
17604 TYPE_NOSIGN (type
) = 1;
17606 maybe_set_alignment (cu
, die
, type
);
17608 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17610 return set_die_type (die
, type
, cu
);
17613 /* Parse dwarf attribute if it's a block, reference or constant and put the
17614 resulting value of the attribute into struct bound_prop.
17615 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17618 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17619 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17620 struct type
*default_type
)
17622 struct dwarf2_property_baton
*baton
;
17623 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17624 struct objfile
*objfile
= per_objfile
->objfile
;
17625 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17627 gdb_assert (default_type
!= NULL
);
17629 if (attr
== NULL
|| prop
== NULL
)
17632 if (attr
->form_is_block ())
17634 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17635 baton
->property_type
= default_type
;
17636 baton
->locexpr
.per_cu
= cu
->per_cu
;
17637 baton
->locexpr
.per_objfile
= per_objfile
;
17638 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17639 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17640 switch (attr
->name
)
17642 case DW_AT_string_length
:
17643 baton
->locexpr
.is_reference
= true;
17646 baton
->locexpr
.is_reference
= false;
17649 prop
->data
.baton
= baton
;
17650 prop
->kind
= PROP_LOCEXPR
;
17651 gdb_assert (prop
->data
.baton
!= NULL
);
17653 else if (attr
->form_is_ref ())
17655 struct dwarf2_cu
*target_cu
= cu
;
17656 struct die_info
*target_die
;
17657 struct attribute
*target_attr
;
17659 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17660 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17661 if (target_attr
== NULL
)
17662 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17664 if (target_attr
== NULL
)
17667 switch (target_attr
->name
)
17669 case DW_AT_location
:
17670 if (target_attr
->form_is_section_offset ())
17672 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17673 baton
->property_type
= die_type (target_die
, target_cu
);
17674 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17675 prop
->data
.baton
= baton
;
17676 prop
->kind
= PROP_LOCLIST
;
17677 gdb_assert (prop
->data
.baton
!= NULL
);
17679 else if (target_attr
->form_is_block ())
17681 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17682 baton
->property_type
= die_type (target_die
, target_cu
);
17683 baton
->locexpr
.per_cu
= cu
->per_cu
;
17684 baton
->locexpr
.per_objfile
= per_objfile
;
17685 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17686 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17687 baton
->locexpr
.is_reference
= true;
17688 prop
->data
.baton
= baton
;
17689 prop
->kind
= PROP_LOCEXPR
;
17690 gdb_assert (prop
->data
.baton
!= NULL
);
17694 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17695 "dynamic property");
17699 case DW_AT_data_member_location
:
17703 if (!handle_data_member_location (target_die
, target_cu
,
17707 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17708 baton
->property_type
= read_type_die (target_die
->parent
,
17710 baton
->offset_info
.offset
= offset
;
17711 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17712 prop
->data
.baton
= baton
;
17713 prop
->kind
= PROP_ADDR_OFFSET
;
17718 else if (attr
->form_is_constant ())
17720 prop
->data
.const_val
= attr
->constant_value (0);
17721 prop
->kind
= PROP_CONST
;
17725 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17726 dwarf2_name (die
, cu
));
17736 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17738 struct type
*int_type
;
17740 /* Helper macro to examine the various builtin types. */
17741 #define TRY_TYPE(F) \
17742 int_type = (unsigned_p \
17743 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17744 : objfile_type (objfile)->builtin_ ## F); \
17745 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17752 TRY_TYPE (long_long
);
17756 gdb_assert_not_reached ("unable to find suitable integer type");
17762 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17764 int addr_size
= this->per_cu
->addr_size ();
17765 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17768 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17769 present (which is valid) then compute the default type based on the
17770 compilation units address size. */
17772 static struct type
*
17773 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17775 struct type
*index_type
= die_type (die
, cu
);
17777 /* Dwarf-2 specifications explicitly allows to create subrange types
17778 without specifying a base type.
17779 In that case, the base type must be set to the type of
17780 the lower bound, upper bound or count, in that order, if any of these
17781 three attributes references an object that has a type.
17782 If no base type is found, the Dwarf-2 specifications say that
17783 a signed integer type of size equal to the size of an address should
17785 For the following C code: `extern char gdb_int [];'
17786 GCC produces an empty range DIE.
17787 FIXME: muller/2010-05-28: Possible references to object for low bound,
17788 high bound or count are not yet handled by this code. */
17789 if (index_type
->code () == TYPE_CODE_VOID
)
17790 index_type
= cu
->addr_sized_int_type (false);
17795 /* Read the given DW_AT_subrange DIE. */
17797 static struct type
*
17798 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17800 struct type
*base_type
, *orig_base_type
;
17801 struct type
*range_type
;
17802 struct attribute
*attr
;
17803 struct dynamic_prop low
, high
;
17804 int low_default_is_valid
;
17805 int high_bound_is_count
= 0;
17807 ULONGEST negative_mask
;
17809 orig_base_type
= read_subrange_index_type (die
, cu
);
17811 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17812 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17813 creating the range type, but we use the result of check_typedef
17814 when examining properties of the type. */
17815 base_type
= check_typedef (orig_base_type
);
17817 /* The die_type call above may have already set the type for this DIE. */
17818 range_type
= get_die_type (die
, cu
);
17822 low
.kind
= PROP_CONST
;
17823 high
.kind
= PROP_CONST
;
17824 high
.data
.const_val
= 0;
17826 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17827 omitting DW_AT_lower_bound. */
17828 switch (cu
->language
)
17831 case language_cplus
:
17832 low
.data
.const_val
= 0;
17833 low_default_is_valid
= 1;
17835 case language_fortran
:
17836 low
.data
.const_val
= 1;
17837 low_default_is_valid
= 1;
17840 case language_objc
:
17841 case language_rust
:
17842 low
.data
.const_val
= 0;
17843 low_default_is_valid
= (cu
->header
.version
>= 4);
17847 case language_pascal
:
17848 low
.data
.const_val
= 1;
17849 low_default_is_valid
= (cu
->header
.version
>= 4);
17852 low
.data
.const_val
= 0;
17853 low_default_is_valid
= 0;
17857 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17858 if (attr
!= nullptr)
17859 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17860 else if (!low_default_is_valid
)
17861 complaint (_("Missing DW_AT_lower_bound "
17862 "- DIE at %s [in module %s]"),
17863 sect_offset_str (die
->sect_off
),
17864 objfile_name (cu
->per_objfile
->objfile
));
17866 struct attribute
*attr_ub
, *attr_count
;
17867 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17868 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17870 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17871 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17873 /* If bounds are constant do the final calculation here. */
17874 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17875 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17877 high_bound_is_count
= 1;
17881 if (attr_ub
!= NULL
)
17882 complaint (_("Unresolved DW_AT_upper_bound "
17883 "- DIE at %s [in module %s]"),
17884 sect_offset_str (die
->sect_off
),
17885 objfile_name (cu
->per_objfile
->objfile
));
17886 if (attr_count
!= NULL
)
17887 complaint (_("Unresolved DW_AT_count "
17888 "- DIE at %s [in module %s]"),
17889 sect_offset_str (die
->sect_off
),
17890 objfile_name (cu
->per_objfile
->objfile
));
17895 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17896 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17897 bias
= bias_attr
->constant_value (0);
17899 /* Normally, the DWARF producers are expected to use a signed
17900 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17901 But this is unfortunately not always the case, as witnessed
17902 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17903 is used instead. To work around that ambiguity, we treat
17904 the bounds as signed, and thus sign-extend their values, when
17905 the base type is signed. */
17907 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17908 if (low
.kind
== PROP_CONST
17909 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17910 low
.data
.const_val
|= negative_mask
;
17911 if (high
.kind
== PROP_CONST
17912 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17913 high
.data
.const_val
|= negative_mask
;
17915 /* Check for bit and byte strides. */
17916 struct dynamic_prop byte_stride_prop
;
17917 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17918 if (attr_byte_stride
!= nullptr)
17920 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17921 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17925 struct dynamic_prop bit_stride_prop
;
17926 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17927 if (attr_bit_stride
!= nullptr)
17929 /* It only makes sense to have either a bit or byte stride. */
17930 if (attr_byte_stride
!= nullptr)
17932 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17933 "- DIE at %s [in module %s]"),
17934 sect_offset_str (die
->sect_off
),
17935 objfile_name (cu
->per_objfile
->objfile
));
17936 attr_bit_stride
= nullptr;
17940 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17941 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17946 if (attr_byte_stride
!= nullptr
17947 || attr_bit_stride
!= nullptr)
17949 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17950 struct dynamic_prop
*stride
17951 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17954 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17955 &high
, bias
, stride
, byte_stride_p
);
17958 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17960 if (high_bound_is_count
)
17961 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17963 /* Ada expects an empty array on no boundary attributes. */
17964 if (attr
== NULL
&& cu
->language
!= language_ada
)
17965 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17967 name
= dwarf2_name (die
, cu
);
17969 range_type
->set_name (name
);
17971 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17972 if (attr
!= nullptr)
17973 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17975 maybe_set_alignment (cu
, die
, range_type
);
17977 set_die_type (die
, range_type
, cu
);
17979 /* set_die_type should be already done. */
17980 set_descriptive_type (range_type
, die
, cu
);
17985 static struct type
*
17986 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17990 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17991 type
->set_name (dwarf2_name (die
, cu
));
17993 /* In Ada, an unspecified type is typically used when the description
17994 of the type is deferred to a different unit. When encountering
17995 such a type, we treat it as a stub, and try to resolve it later on,
17997 if (cu
->language
== language_ada
)
17998 TYPE_STUB (type
) = 1;
18000 return set_die_type (die
, type
, cu
);
18003 /* Read a single die and all its descendents. Set the die's sibling
18004 field to NULL; set other fields in the die correctly, and set all
18005 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18006 location of the info_ptr after reading all of those dies. PARENT
18007 is the parent of the die in question. */
18009 static struct die_info
*
18010 read_die_and_children (const struct die_reader_specs
*reader
,
18011 const gdb_byte
*info_ptr
,
18012 const gdb_byte
**new_info_ptr
,
18013 struct die_info
*parent
)
18015 struct die_info
*die
;
18016 const gdb_byte
*cur_ptr
;
18018 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18021 *new_info_ptr
= cur_ptr
;
18024 store_in_ref_table (die
, reader
->cu
);
18026 if (die
->has_children
)
18027 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18031 *new_info_ptr
= cur_ptr
;
18034 die
->sibling
= NULL
;
18035 die
->parent
= parent
;
18039 /* Read a die, all of its descendents, and all of its siblings; set
18040 all of the fields of all of the dies correctly. Arguments are as
18041 in read_die_and_children. */
18043 static struct die_info
*
18044 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18045 const gdb_byte
*info_ptr
,
18046 const gdb_byte
**new_info_ptr
,
18047 struct die_info
*parent
)
18049 struct die_info
*first_die
, *last_sibling
;
18050 const gdb_byte
*cur_ptr
;
18052 cur_ptr
= info_ptr
;
18053 first_die
= last_sibling
= NULL
;
18057 struct die_info
*die
18058 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18062 *new_info_ptr
= cur_ptr
;
18069 last_sibling
->sibling
= die
;
18071 last_sibling
= die
;
18075 /* Read a die, all of its descendents, and all of its siblings; set
18076 all of the fields of all of the dies correctly. Arguments are as
18077 in read_die_and_children.
18078 This the main entry point for reading a DIE and all its children. */
18080 static struct die_info
*
18081 read_die_and_siblings (const struct die_reader_specs
*reader
,
18082 const gdb_byte
*info_ptr
,
18083 const gdb_byte
**new_info_ptr
,
18084 struct die_info
*parent
)
18086 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18087 new_info_ptr
, parent
);
18089 if (dwarf_die_debug
)
18091 fprintf_unfiltered (gdb_stdlog
,
18092 "Read die from %s@0x%x of %s:\n",
18093 reader
->die_section
->get_name (),
18094 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18095 bfd_get_filename (reader
->abfd
));
18096 dump_die (die
, dwarf_die_debug
);
18102 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18104 The caller is responsible for filling in the extra attributes
18105 and updating (*DIEP)->num_attrs.
18106 Set DIEP to point to a newly allocated die with its information,
18107 except for its child, sibling, and parent fields. */
18109 static const gdb_byte
*
18110 read_full_die_1 (const struct die_reader_specs
*reader
,
18111 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18112 int num_extra_attrs
)
18114 unsigned int abbrev_number
, bytes_read
, i
;
18115 struct abbrev_info
*abbrev
;
18116 struct die_info
*die
;
18117 struct dwarf2_cu
*cu
= reader
->cu
;
18118 bfd
*abfd
= reader
->abfd
;
18120 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18121 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18122 info_ptr
+= bytes_read
;
18123 if (!abbrev_number
)
18129 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18131 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18133 bfd_get_filename (abfd
));
18135 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18136 die
->sect_off
= sect_off
;
18137 die
->tag
= abbrev
->tag
;
18138 die
->abbrev
= abbrev_number
;
18139 die
->has_children
= abbrev
->has_children
;
18141 /* Make the result usable.
18142 The caller needs to update num_attrs after adding the extra
18144 die
->num_attrs
= abbrev
->num_attrs
;
18146 std::vector
<int> indexes_that_need_reprocess
;
18147 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18149 bool need_reprocess
;
18151 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18152 info_ptr
, &need_reprocess
);
18153 if (need_reprocess
)
18154 indexes_that_need_reprocess
.push_back (i
);
18157 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18158 if (attr
!= nullptr)
18159 cu
->str_offsets_base
= DW_UNSND (attr
);
18161 attr
= die
->attr (DW_AT_loclists_base
);
18162 if (attr
!= nullptr)
18163 cu
->loclist_base
= DW_UNSND (attr
);
18165 auto maybe_addr_base
= die
->addr_base ();
18166 if (maybe_addr_base
.has_value ())
18167 cu
->addr_base
= *maybe_addr_base
;
18168 for (int index
: indexes_that_need_reprocess
)
18169 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18174 /* Read a die and all its attributes.
18175 Set DIEP to point to a newly allocated die with its information,
18176 except for its child, sibling, and parent fields. */
18178 static const gdb_byte
*
18179 read_full_die (const struct die_reader_specs
*reader
,
18180 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18182 const gdb_byte
*result
;
18184 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18186 if (dwarf_die_debug
)
18188 fprintf_unfiltered (gdb_stdlog
,
18189 "Read die from %s@0x%x of %s:\n",
18190 reader
->die_section
->get_name (),
18191 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18192 bfd_get_filename (reader
->abfd
));
18193 dump_die (*diep
, dwarf_die_debug
);
18200 /* Returns nonzero if TAG represents a type that we might generate a partial
18204 is_type_tag_for_partial (int tag
)
18209 /* Some types that would be reasonable to generate partial symbols for,
18210 that we don't at present. */
18211 case DW_TAG_array_type
:
18212 case DW_TAG_file_type
:
18213 case DW_TAG_ptr_to_member_type
:
18214 case DW_TAG_set_type
:
18215 case DW_TAG_string_type
:
18216 case DW_TAG_subroutine_type
:
18218 case DW_TAG_base_type
:
18219 case DW_TAG_class_type
:
18220 case DW_TAG_interface_type
:
18221 case DW_TAG_enumeration_type
:
18222 case DW_TAG_structure_type
:
18223 case DW_TAG_subrange_type
:
18224 case DW_TAG_typedef
:
18225 case DW_TAG_union_type
:
18232 /* Load all DIEs that are interesting for partial symbols into memory. */
18234 static struct partial_die_info
*
18235 load_partial_dies (const struct die_reader_specs
*reader
,
18236 const gdb_byte
*info_ptr
, int building_psymtab
)
18238 struct dwarf2_cu
*cu
= reader
->cu
;
18239 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18240 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18241 unsigned int bytes_read
;
18242 unsigned int load_all
= 0;
18243 int nesting_level
= 1;
18248 gdb_assert (cu
->per_cu
!= NULL
);
18249 if (cu
->per_cu
->load_all_dies
)
18253 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18257 &cu
->comp_unit_obstack
,
18258 hashtab_obstack_allocate
,
18259 dummy_obstack_deallocate
);
18263 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18265 /* A NULL abbrev means the end of a series of children. */
18266 if (abbrev
== NULL
)
18268 if (--nesting_level
== 0)
18271 info_ptr
+= bytes_read
;
18272 last_die
= parent_die
;
18273 parent_die
= parent_die
->die_parent
;
18277 /* Check for template arguments. We never save these; if
18278 they're seen, we just mark the parent, and go on our way. */
18279 if (parent_die
!= NULL
18280 && cu
->language
== language_cplus
18281 && (abbrev
->tag
== DW_TAG_template_type_param
18282 || abbrev
->tag
== DW_TAG_template_value_param
))
18284 parent_die
->has_template_arguments
= 1;
18288 /* We don't need a partial DIE for the template argument. */
18289 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18294 /* We only recurse into c++ subprograms looking for template arguments.
18295 Skip their other children. */
18297 && cu
->language
== language_cplus
18298 && parent_die
!= NULL
18299 && parent_die
->tag
== DW_TAG_subprogram
18300 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18302 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18306 /* Check whether this DIE is interesting enough to save. Normally
18307 we would not be interested in members here, but there may be
18308 later variables referencing them via DW_AT_specification (for
18309 static members). */
18311 && !is_type_tag_for_partial (abbrev
->tag
)
18312 && abbrev
->tag
!= DW_TAG_constant
18313 && abbrev
->tag
!= DW_TAG_enumerator
18314 && abbrev
->tag
!= DW_TAG_subprogram
18315 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18316 && abbrev
->tag
!= DW_TAG_lexical_block
18317 && abbrev
->tag
!= DW_TAG_variable
18318 && abbrev
->tag
!= DW_TAG_namespace
18319 && abbrev
->tag
!= DW_TAG_module
18320 && abbrev
->tag
!= DW_TAG_member
18321 && abbrev
->tag
!= DW_TAG_imported_unit
18322 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18324 /* Otherwise we skip to the next sibling, if any. */
18325 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18329 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18332 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18334 /* This two-pass algorithm for processing partial symbols has a
18335 high cost in cache pressure. Thus, handle some simple cases
18336 here which cover the majority of C partial symbols. DIEs
18337 which neither have specification tags in them, nor could have
18338 specification tags elsewhere pointing at them, can simply be
18339 processed and discarded.
18341 This segment is also optional; scan_partial_symbols and
18342 add_partial_symbol will handle these DIEs if we chain
18343 them in normally. When compilers which do not emit large
18344 quantities of duplicate debug information are more common,
18345 this code can probably be removed. */
18347 /* Any complete simple types at the top level (pretty much all
18348 of them, for a language without namespaces), can be processed
18350 if (parent_die
== NULL
18351 && pdi
.has_specification
== 0
18352 && pdi
.is_declaration
== 0
18353 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18354 || pdi
.tag
== DW_TAG_base_type
18355 || pdi
.tag
== DW_TAG_subrange_type
))
18357 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18358 add_partial_symbol (&pdi
, cu
);
18360 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18364 /* The exception for DW_TAG_typedef with has_children above is
18365 a workaround of GCC PR debug/47510. In the case of this complaint
18366 type_name_or_error will error on such types later.
18368 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18369 it could not find the child DIEs referenced later, this is checked
18370 above. In correct DWARF DW_TAG_typedef should have no children. */
18372 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18373 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18374 "- DIE at %s [in module %s]"),
18375 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18377 /* If we're at the second level, and we're an enumerator, and
18378 our parent has no specification (meaning possibly lives in a
18379 namespace elsewhere), then we can add the partial symbol now
18380 instead of queueing it. */
18381 if (pdi
.tag
== DW_TAG_enumerator
18382 && parent_die
!= NULL
18383 && parent_die
->die_parent
== NULL
18384 && parent_die
->tag
== DW_TAG_enumeration_type
18385 && parent_die
->has_specification
== 0)
18387 if (pdi
.raw_name
== NULL
)
18388 complaint (_("malformed enumerator DIE ignored"));
18389 else if (building_psymtab
)
18390 add_partial_symbol (&pdi
, cu
);
18392 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18396 struct partial_die_info
*part_die
18397 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18399 /* We'll save this DIE so link it in. */
18400 part_die
->die_parent
= parent_die
;
18401 part_die
->die_sibling
= NULL
;
18402 part_die
->die_child
= NULL
;
18404 if (last_die
&& last_die
== parent_die
)
18405 last_die
->die_child
= part_die
;
18407 last_die
->die_sibling
= part_die
;
18409 last_die
= part_die
;
18411 if (first_die
== NULL
)
18412 first_die
= part_die
;
18414 /* Maybe add the DIE to the hash table. Not all DIEs that we
18415 find interesting need to be in the hash table, because we
18416 also have the parent/sibling/child chains; only those that we
18417 might refer to by offset later during partial symbol reading.
18419 For now this means things that might have be the target of a
18420 DW_AT_specification, DW_AT_abstract_origin, or
18421 DW_AT_extension. DW_AT_extension will refer only to
18422 namespaces; DW_AT_abstract_origin refers to functions (and
18423 many things under the function DIE, but we do not recurse
18424 into function DIEs during partial symbol reading) and
18425 possibly variables as well; DW_AT_specification refers to
18426 declarations. Declarations ought to have the DW_AT_declaration
18427 flag. It happens that GCC forgets to put it in sometimes, but
18428 only for functions, not for types.
18430 Adding more things than necessary to the hash table is harmless
18431 except for the performance cost. Adding too few will result in
18432 wasted time in find_partial_die, when we reread the compilation
18433 unit with load_all_dies set. */
18436 || abbrev
->tag
== DW_TAG_constant
18437 || abbrev
->tag
== DW_TAG_subprogram
18438 || abbrev
->tag
== DW_TAG_variable
18439 || abbrev
->tag
== DW_TAG_namespace
18440 || part_die
->is_declaration
)
18444 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18445 to_underlying (part_die
->sect_off
),
18450 /* For some DIEs we want to follow their children (if any). For C
18451 we have no reason to follow the children of structures; for other
18452 languages we have to, so that we can get at method physnames
18453 to infer fully qualified class names, for DW_AT_specification,
18454 and for C++ template arguments. For C++, we also look one level
18455 inside functions to find template arguments (if the name of the
18456 function does not already contain the template arguments).
18458 For Ada and Fortran, we need to scan the children of subprograms
18459 and lexical blocks as well because these languages allow the
18460 definition of nested entities that could be interesting for the
18461 debugger, such as nested subprograms for instance. */
18462 if (last_die
->has_children
18464 || last_die
->tag
== DW_TAG_namespace
18465 || last_die
->tag
== DW_TAG_module
18466 || last_die
->tag
== DW_TAG_enumeration_type
18467 || (cu
->language
== language_cplus
18468 && last_die
->tag
== DW_TAG_subprogram
18469 && (last_die
->raw_name
== NULL
18470 || strchr (last_die
->raw_name
, '<') == NULL
))
18471 || (cu
->language
!= language_c
18472 && (last_die
->tag
== DW_TAG_class_type
18473 || last_die
->tag
== DW_TAG_interface_type
18474 || last_die
->tag
== DW_TAG_structure_type
18475 || last_die
->tag
== DW_TAG_union_type
))
18476 || ((cu
->language
== language_ada
18477 || cu
->language
== language_fortran
)
18478 && (last_die
->tag
== DW_TAG_subprogram
18479 || last_die
->tag
== DW_TAG_lexical_block
))))
18482 parent_die
= last_die
;
18486 /* Otherwise we skip to the next sibling, if any. */
18487 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18489 /* Back to the top, do it again. */
18493 partial_die_info::partial_die_info (sect_offset sect_off_
,
18494 struct abbrev_info
*abbrev
)
18495 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18499 /* See class definition. */
18502 partial_die_info::name (dwarf2_cu
*cu
)
18504 if (!canonical_name
&& raw_name
!= nullptr)
18506 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18507 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
18508 canonical_name
= 1;
18514 /* Read a minimal amount of information into the minimal die structure.
18515 INFO_PTR should point just after the initial uleb128 of a DIE. */
18518 partial_die_info::read (const struct die_reader_specs
*reader
,
18519 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18521 struct dwarf2_cu
*cu
= reader
->cu
;
18522 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18524 int has_low_pc_attr
= 0;
18525 int has_high_pc_attr
= 0;
18526 int high_pc_relative
= 0;
18528 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18531 bool need_reprocess
;
18532 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18533 info_ptr
, &need_reprocess
);
18534 /* String and address offsets that need to do the reprocessing have
18535 already been read at this point, so there is no need to wait until
18536 the loop terminates to do the reprocessing. */
18537 if (need_reprocess
)
18538 read_attribute_reprocess (reader
, &attr
);
18539 /* Store the data if it is of an attribute we want to keep in a
18540 partial symbol table. */
18546 case DW_TAG_compile_unit
:
18547 case DW_TAG_partial_unit
:
18548 case DW_TAG_type_unit
:
18549 /* Compilation units have a DW_AT_name that is a filename, not
18550 a source language identifier. */
18551 case DW_TAG_enumeration_type
:
18552 case DW_TAG_enumerator
:
18553 /* These tags always have simple identifiers already; no need
18554 to canonicalize them. */
18555 canonical_name
= 1;
18556 raw_name
= DW_STRING (&attr
);
18559 canonical_name
= 0;
18560 raw_name
= DW_STRING (&attr
);
18564 case DW_AT_linkage_name
:
18565 case DW_AT_MIPS_linkage_name
:
18566 /* Note that both forms of linkage name might appear. We
18567 assume they will be the same, and we only store the last
18569 linkage_name
= attr
.value_as_string ();
18570 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18571 See https://github.com/rust-lang/rust/issues/32925. */
18572 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18573 && strchr (linkage_name
, '{') != NULL
)
18574 linkage_name
= NULL
;
18577 has_low_pc_attr
= 1;
18578 lowpc
= attr
.value_as_address ();
18580 case DW_AT_high_pc
:
18581 has_high_pc_attr
= 1;
18582 highpc
= attr
.value_as_address ();
18583 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18584 high_pc_relative
= 1;
18586 case DW_AT_location
:
18587 /* Support the .debug_loc offsets. */
18588 if (attr
.form_is_block ())
18590 d
.locdesc
= DW_BLOCK (&attr
);
18592 else if (attr
.form_is_section_offset ())
18594 dwarf2_complex_location_expr_complaint ();
18598 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18599 "partial symbol information");
18602 case DW_AT_external
:
18603 is_external
= DW_UNSND (&attr
);
18605 case DW_AT_declaration
:
18606 is_declaration
= DW_UNSND (&attr
);
18611 case DW_AT_abstract_origin
:
18612 case DW_AT_specification
:
18613 case DW_AT_extension
:
18614 has_specification
= 1;
18615 spec_offset
= attr
.get_ref_die_offset ();
18616 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18617 || cu
->per_cu
->is_dwz
);
18619 case DW_AT_sibling
:
18620 /* Ignore absolute siblings, they might point outside of
18621 the current compile unit. */
18622 if (attr
.form
== DW_FORM_ref_addr
)
18623 complaint (_("ignoring absolute DW_AT_sibling"));
18626 const gdb_byte
*buffer
= reader
->buffer
;
18627 sect_offset off
= attr
.get_ref_die_offset ();
18628 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18630 if (sibling_ptr
< info_ptr
)
18631 complaint (_("DW_AT_sibling points backwards"));
18632 else if (sibling_ptr
> reader
->buffer_end
)
18633 reader
->die_section
->overflow_complaint ();
18635 sibling
= sibling_ptr
;
18638 case DW_AT_byte_size
:
18641 case DW_AT_const_value
:
18642 has_const_value
= 1;
18644 case DW_AT_calling_convention
:
18645 /* DWARF doesn't provide a way to identify a program's source-level
18646 entry point. DW_AT_calling_convention attributes are only meant
18647 to describe functions' calling conventions.
18649 However, because it's a necessary piece of information in
18650 Fortran, and before DWARF 4 DW_CC_program was the only
18651 piece of debugging information whose definition refers to
18652 a 'main program' at all, several compilers marked Fortran
18653 main programs with DW_CC_program --- even when those
18654 functions use the standard calling conventions.
18656 Although DWARF now specifies a way to provide this
18657 information, we support this practice for backward
18659 if (DW_UNSND (&attr
) == DW_CC_program
18660 && cu
->language
== language_fortran
)
18661 main_subprogram
= 1;
18664 if (DW_UNSND (&attr
) == DW_INL_inlined
18665 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18666 may_be_inlined
= 1;
18670 if (tag
== DW_TAG_imported_unit
)
18672 d
.sect_off
= attr
.get_ref_die_offset ();
18673 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18674 || cu
->per_cu
->is_dwz
);
18678 case DW_AT_main_subprogram
:
18679 main_subprogram
= DW_UNSND (&attr
);
18684 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18685 but that requires a full DIE, so instead we just
18687 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18688 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18689 + (need_ranges_base
18693 /* Value of the DW_AT_ranges attribute is the offset in the
18694 .debug_ranges section. */
18695 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18706 /* For Ada, if both the name and the linkage name appear, we prefer
18707 the latter. This lets "catch exception" work better, regardless
18708 of the order in which the name and linkage name were emitted.
18709 Really, though, this is just a workaround for the fact that gdb
18710 doesn't store both the name and the linkage name. */
18711 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18712 raw_name
= linkage_name
;
18714 if (high_pc_relative
)
18717 if (has_low_pc_attr
&& has_high_pc_attr
)
18719 /* When using the GNU linker, .gnu.linkonce. sections are used to
18720 eliminate duplicate copies of functions and vtables and such.
18721 The linker will arbitrarily choose one and discard the others.
18722 The AT_*_pc values for such functions refer to local labels in
18723 these sections. If the section from that file was discarded, the
18724 labels are not in the output, so the relocs get a value of 0.
18725 If this is a discarded function, mark the pc bounds as invalid,
18726 so that GDB will ignore it. */
18727 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
18729 struct objfile
*objfile
= per_objfile
->objfile
;
18730 struct gdbarch
*gdbarch
= objfile
->arch ();
18732 complaint (_("DW_AT_low_pc %s is zero "
18733 "for DIE at %s [in module %s]"),
18734 paddress (gdbarch
, lowpc
),
18735 sect_offset_str (sect_off
),
18736 objfile_name (objfile
));
18738 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18739 else if (lowpc
>= highpc
)
18741 struct objfile
*objfile
= per_objfile
->objfile
;
18742 struct gdbarch
*gdbarch
= objfile
->arch ();
18744 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18745 "for DIE at %s [in module %s]"),
18746 paddress (gdbarch
, lowpc
),
18747 paddress (gdbarch
, highpc
),
18748 sect_offset_str (sect_off
),
18749 objfile_name (objfile
));
18758 /* Find a cached partial DIE at OFFSET in CU. */
18760 struct partial_die_info
*
18761 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18763 struct partial_die_info
*lookup_die
= NULL
;
18764 struct partial_die_info
part_die (sect_off
);
18766 lookup_die
= ((struct partial_die_info
*)
18767 htab_find_with_hash (partial_dies
, &part_die
,
18768 to_underlying (sect_off
)));
18773 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18774 except in the case of .debug_types DIEs which do not reference
18775 outside their CU (they do however referencing other types via
18776 DW_FORM_ref_sig8). */
18778 static const struct cu_partial_die_info
18779 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18781 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18782 struct objfile
*objfile
= per_objfile
->objfile
;
18783 struct partial_die_info
*pd
= NULL
;
18785 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18786 && cu
->header
.offset_in_cu_p (sect_off
))
18788 pd
= cu
->find_partial_die (sect_off
);
18791 /* We missed recording what we needed.
18792 Load all dies and try again. */
18796 /* TUs don't reference other CUs/TUs (except via type signatures). */
18797 if (cu
->per_cu
->is_debug_types
)
18799 error (_("Dwarf Error: Type Unit at offset %s contains"
18800 " external reference to offset %s [in module %s].\n"),
18801 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18802 bfd_get_filename (objfile
->obfd
));
18804 dwarf2_per_cu_data
*per_cu
18805 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18808 cu
= per_objfile
->get_cu (per_cu
);
18809 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
18810 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
18812 cu
= per_objfile
->get_cu (per_cu
);
18815 pd
= cu
->find_partial_die (sect_off
);
18818 /* If we didn't find it, and not all dies have been loaded,
18819 load them all and try again. */
18821 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
18823 cu
->per_cu
->load_all_dies
= 1;
18825 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18826 THIS_CU->cu may already be in use. So we can't just free it and
18827 replace its DIEs with the ones we read in. Instead, we leave those
18828 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18829 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18831 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
18833 pd
= cu
->find_partial_die (sect_off
);
18837 internal_error (__FILE__
, __LINE__
,
18838 _("could not find partial DIE %s "
18839 "in cache [from module %s]\n"),
18840 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18844 /* See if we can figure out if the class lives in a namespace. We do
18845 this by looking for a member function; its demangled name will
18846 contain namespace info, if there is any. */
18849 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18850 struct dwarf2_cu
*cu
)
18852 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18853 what template types look like, because the demangler
18854 frequently doesn't give the same name as the debug info. We
18855 could fix this by only using the demangled name to get the
18856 prefix (but see comment in read_structure_type). */
18858 struct partial_die_info
*real_pdi
;
18859 struct partial_die_info
*child_pdi
;
18861 /* If this DIE (this DIE's specification, if any) has a parent, then
18862 we should not do this. We'll prepend the parent's fully qualified
18863 name when we create the partial symbol. */
18865 real_pdi
= struct_pdi
;
18866 while (real_pdi
->has_specification
)
18868 auto res
= find_partial_die (real_pdi
->spec_offset
,
18869 real_pdi
->spec_is_dwz
, cu
);
18870 real_pdi
= res
.pdi
;
18874 if (real_pdi
->die_parent
!= NULL
)
18877 for (child_pdi
= struct_pdi
->die_child
;
18879 child_pdi
= child_pdi
->die_sibling
)
18881 if (child_pdi
->tag
== DW_TAG_subprogram
18882 && child_pdi
->linkage_name
!= NULL
)
18884 gdb::unique_xmalloc_ptr
<char> actual_class_name
18885 (cu
->language_defn
->class_name_from_physname
18886 (child_pdi
->linkage_name
));
18887 if (actual_class_name
!= NULL
)
18889 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18890 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
18891 struct_pdi
->canonical_name
= 1;
18898 /* Return true if a DIE with TAG may have the DW_AT_const_value
18902 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18906 case DW_TAG_constant
:
18907 case DW_TAG_enumerator
:
18908 case DW_TAG_formal_parameter
:
18909 case DW_TAG_template_value_param
:
18910 case DW_TAG_variable
:
18918 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18920 /* Once we've fixed up a die, there's no point in doing so again.
18921 This also avoids a memory leak if we were to call
18922 guess_partial_die_structure_name multiple times. */
18926 /* If we found a reference attribute and the DIE has no name, try
18927 to find a name in the referred to DIE. */
18929 if (raw_name
== NULL
&& has_specification
)
18931 struct partial_die_info
*spec_die
;
18933 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18934 spec_die
= res
.pdi
;
18937 spec_die
->fixup (cu
);
18939 if (spec_die
->raw_name
)
18941 raw_name
= spec_die
->raw_name
;
18942 canonical_name
= spec_die
->canonical_name
;
18944 /* Copy DW_AT_external attribute if it is set. */
18945 if (spec_die
->is_external
)
18946 is_external
= spec_die
->is_external
;
18950 if (!has_const_value
&& has_specification
18951 && can_have_DW_AT_const_value_p (tag
))
18953 struct partial_die_info
*spec_die
;
18955 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18956 spec_die
= res
.pdi
;
18959 spec_die
->fixup (cu
);
18961 if (spec_die
->has_const_value
)
18963 /* Copy DW_AT_const_value attribute if it is set. */
18964 has_const_value
= spec_die
->has_const_value
;
18968 /* Set default names for some unnamed DIEs. */
18970 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
18972 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
18973 canonical_name
= 1;
18976 /* If there is no parent die to provide a namespace, and there are
18977 children, see if we can determine the namespace from their linkage
18979 if (cu
->language
== language_cplus
18980 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18981 && die_parent
== NULL
18983 && (tag
== DW_TAG_class_type
18984 || tag
== DW_TAG_structure_type
18985 || tag
== DW_TAG_union_type
))
18986 guess_partial_die_structure_name (this, cu
);
18988 /* GCC might emit a nameless struct or union that has a linkage
18989 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18990 if (raw_name
== NULL
18991 && (tag
== DW_TAG_class_type
18992 || tag
== DW_TAG_interface_type
18993 || tag
== DW_TAG_structure_type
18994 || tag
== DW_TAG_union_type
)
18995 && linkage_name
!= NULL
)
18997 gdb::unique_xmalloc_ptr
<char> demangled
18998 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18999 if (demangled
!= nullptr)
19003 /* Strip any leading namespaces/classes, keep only the base name.
19004 DW_AT_name for named DIEs does not contain the prefixes. */
19005 base
= strrchr (demangled
.get (), ':');
19006 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19009 base
= demangled
.get ();
19011 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19012 raw_name
= objfile
->intern (base
);
19013 canonical_name
= 1;
19020 /* Read the .debug_loclists header contents from the given SECTION in the
19023 read_loclist_header (struct loclist_header
*header
,
19024 struct dwarf2_section_info
*section
)
19026 unsigned int bytes_read
;
19027 bfd
*abfd
= section
->get_bfd_owner ();
19028 const gdb_byte
*info_ptr
= section
->buffer
;
19029 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19030 info_ptr
+= bytes_read
;
19031 header
->version
= read_2_bytes (abfd
, info_ptr
);
19033 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19035 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19037 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19040 /* Return the DW_AT_loclists_base value for the CU. */
19042 lookup_loclist_base (struct dwarf2_cu
*cu
)
19044 /* For the .dwo unit, the loclist_base points to the first offset following
19045 the header. The header consists of the following entities-
19046 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19048 2. version (2 bytes)
19049 3. address size (1 byte)
19050 4. segment selector size (1 byte)
19051 5. offset entry count (4 bytes)
19052 These sizes are derived as per the DWARFv5 standard. */
19053 if (cu
->dwo_unit
!= nullptr)
19055 if (cu
->header
.initial_length_size
== 4)
19056 return LOCLIST_HEADER_SIZE32
;
19057 return LOCLIST_HEADER_SIZE64
;
19059 return cu
->loclist_base
;
19062 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19063 array of offsets in the .debug_loclists section. */
19065 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19067 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19068 struct objfile
*objfile
= per_objfile
->objfile
;
19069 bfd
*abfd
= objfile
->obfd
;
19070 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19071 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19073 section
->read (objfile
);
19074 if (section
->buffer
== NULL
)
19075 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19076 "section [in module %s]"), objfile_name (objfile
));
19077 struct loclist_header header
;
19078 read_loclist_header (&header
, section
);
19079 if (loclist_index
>= header
.offset_entry_count
)
19080 complaint (_("DW_FORM_loclistx pointing outside of "
19081 ".debug_loclists offset array [in module %s]"),
19082 objfile_name (objfile
));
19083 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19085 complaint (_("DW_FORM_loclistx pointing outside of "
19086 ".debug_loclists section [in module %s]"),
19087 objfile_name (objfile
));
19088 const gdb_byte
*info_ptr
19089 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19091 if (cu
->header
.offset_size
== 4)
19092 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19094 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19097 /* Process the attributes that had to be skipped in the first round. These
19098 attributes are the ones that need str_offsets_base or addr_base attributes.
19099 They could not have been processed in the first round, because at the time
19100 the values of str_offsets_base or addr_base may not have been known. */
19102 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19103 struct attribute
*attr
)
19105 struct dwarf2_cu
*cu
= reader
->cu
;
19106 switch (attr
->form
)
19108 case DW_FORM_addrx
:
19109 case DW_FORM_GNU_addr_index
:
19110 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19112 case DW_FORM_loclistx
:
19113 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19116 case DW_FORM_strx1
:
19117 case DW_FORM_strx2
:
19118 case DW_FORM_strx3
:
19119 case DW_FORM_strx4
:
19120 case DW_FORM_GNU_str_index
:
19122 unsigned int str_index
= DW_UNSND (attr
);
19123 if (reader
->dwo_file
!= NULL
)
19125 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19126 DW_STRING_IS_CANONICAL (attr
) = 0;
19130 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19131 DW_STRING_IS_CANONICAL (attr
) = 0;
19136 gdb_assert_not_reached (_("Unexpected DWARF form."));
19140 /* Read an attribute value described by an attribute form. */
19142 static const gdb_byte
*
19143 read_attribute_value (const struct die_reader_specs
*reader
,
19144 struct attribute
*attr
, unsigned form
,
19145 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19146 bool *need_reprocess
)
19148 struct dwarf2_cu
*cu
= reader
->cu
;
19149 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19150 struct objfile
*objfile
= per_objfile
->objfile
;
19151 bfd
*abfd
= reader
->abfd
;
19152 struct comp_unit_head
*cu_header
= &cu
->header
;
19153 unsigned int bytes_read
;
19154 struct dwarf_block
*blk
;
19155 *need_reprocess
= false;
19157 attr
->form
= (enum dwarf_form
) form
;
19160 case DW_FORM_ref_addr
:
19161 if (cu
->header
.version
== 2)
19162 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19165 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19167 info_ptr
+= bytes_read
;
19169 case DW_FORM_GNU_ref_alt
:
19170 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19171 info_ptr
+= bytes_read
;
19175 struct gdbarch
*gdbarch
= objfile
->arch ();
19176 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19177 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19178 info_ptr
+= bytes_read
;
19181 case DW_FORM_block2
:
19182 blk
= dwarf_alloc_block (cu
);
19183 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19185 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19186 info_ptr
+= blk
->size
;
19187 DW_BLOCK (attr
) = blk
;
19189 case DW_FORM_block4
:
19190 blk
= dwarf_alloc_block (cu
);
19191 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19193 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19194 info_ptr
+= blk
->size
;
19195 DW_BLOCK (attr
) = blk
;
19197 case DW_FORM_data2
:
19198 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19201 case DW_FORM_data4
:
19202 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19205 case DW_FORM_data8
:
19206 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19209 case DW_FORM_data16
:
19210 blk
= dwarf_alloc_block (cu
);
19212 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19214 DW_BLOCK (attr
) = blk
;
19216 case DW_FORM_sec_offset
:
19217 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19218 info_ptr
+= bytes_read
;
19220 case DW_FORM_loclistx
:
19222 *need_reprocess
= true;
19223 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19224 info_ptr
+= bytes_read
;
19227 case DW_FORM_string
:
19228 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19229 DW_STRING_IS_CANONICAL (attr
) = 0;
19230 info_ptr
+= bytes_read
;
19233 if (!cu
->per_cu
->is_dwz
)
19235 DW_STRING (attr
) = read_indirect_string (per_objfile
,
19236 abfd
, info_ptr
, cu_header
,
19238 DW_STRING_IS_CANONICAL (attr
) = 0;
19239 info_ptr
+= bytes_read
;
19243 case DW_FORM_line_strp
:
19244 if (!cu
->per_cu
->is_dwz
)
19246 DW_STRING (attr
) = per_objfile
->read_line_string (info_ptr
, cu_header
,
19248 DW_STRING_IS_CANONICAL (attr
) = 0;
19249 info_ptr
+= bytes_read
;
19253 case DW_FORM_GNU_strp_alt
:
19255 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19256 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19259 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19260 DW_STRING_IS_CANONICAL (attr
) = 0;
19261 info_ptr
+= bytes_read
;
19264 case DW_FORM_exprloc
:
19265 case DW_FORM_block
:
19266 blk
= dwarf_alloc_block (cu
);
19267 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19268 info_ptr
+= bytes_read
;
19269 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19270 info_ptr
+= blk
->size
;
19271 DW_BLOCK (attr
) = blk
;
19273 case DW_FORM_block1
:
19274 blk
= dwarf_alloc_block (cu
);
19275 blk
->size
= read_1_byte (abfd
, info_ptr
);
19277 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19278 info_ptr
+= blk
->size
;
19279 DW_BLOCK (attr
) = blk
;
19281 case DW_FORM_data1
:
19282 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19286 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19289 case DW_FORM_flag_present
:
19290 DW_UNSND (attr
) = 1;
19292 case DW_FORM_sdata
:
19293 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19294 info_ptr
+= bytes_read
;
19296 case DW_FORM_udata
:
19297 case DW_FORM_rnglistx
:
19298 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19299 info_ptr
+= bytes_read
;
19302 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19303 + read_1_byte (abfd
, info_ptr
));
19307 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19308 + read_2_bytes (abfd
, info_ptr
));
19312 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19313 + read_4_bytes (abfd
, info_ptr
));
19317 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19318 + read_8_bytes (abfd
, info_ptr
));
19321 case DW_FORM_ref_sig8
:
19322 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19325 case DW_FORM_ref_udata
:
19326 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19327 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19328 info_ptr
+= bytes_read
;
19330 case DW_FORM_indirect
:
19331 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19332 info_ptr
+= bytes_read
;
19333 if (form
== DW_FORM_implicit_const
)
19335 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19336 info_ptr
+= bytes_read
;
19338 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19339 info_ptr
, need_reprocess
);
19341 case DW_FORM_implicit_const
:
19342 DW_SND (attr
) = implicit_const
;
19344 case DW_FORM_addrx
:
19345 case DW_FORM_GNU_addr_index
:
19346 *need_reprocess
= true;
19347 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19348 info_ptr
+= bytes_read
;
19351 case DW_FORM_strx1
:
19352 case DW_FORM_strx2
:
19353 case DW_FORM_strx3
:
19354 case DW_FORM_strx4
:
19355 case DW_FORM_GNU_str_index
:
19357 ULONGEST str_index
;
19358 if (form
== DW_FORM_strx1
)
19360 str_index
= read_1_byte (abfd
, info_ptr
);
19363 else if (form
== DW_FORM_strx2
)
19365 str_index
= read_2_bytes (abfd
, info_ptr
);
19368 else if (form
== DW_FORM_strx3
)
19370 str_index
= read_3_bytes (abfd
, info_ptr
);
19373 else if (form
== DW_FORM_strx4
)
19375 str_index
= read_4_bytes (abfd
, info_ptr
);
19380 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19381 info_ptr
+= bytes_read
;
19383 *need_reprocess
= true;
19384 DW_UNSND (attr
) = str_index
;
19388 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19389 dwarf_form_name (form
),
19390 bfd_get_filename (abfd
));
19394 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19395 attr
->form
= DW_FORM_GNU_ref_alt
;
19397 /* We have seen instances where the compiler tried to emit a byte
19398 size attribute of -1 which ended up being encoded as an unsigned
19399 0xffffffff. Although 0xffffffff is technically a valid size value,
19400 an object of this size seems pretty unlikely so we can relatively
19401 safely treat these cases as if the size attribute was invalid and
19402 treat them as zero by default. */
19403 if (attr
->name
== DW_AT_byte_size
19404 && form
== DW_FORM_data4
19405 && DW_UNSND (attr
) >= 0xffffffff)
19408 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19409 hex_string (DW_UNSND (attr
)));
19410 DW_UNSND (attr
) = 0;
19416 /* Read an attribute described by an abbreviated attribute. */
19418 static const gdb_byte
*
19419 read_attribute (const struct die_reader_specs
*reader
,
19420 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19421 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19423 attr
->name
= abbrev
->name
;
19424 return read_attribute_value (reader
, attr
, abbrev
->form
,
19425 abbrev
->implicit_const
, info_ptr
,
19429 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19431 static const char *
19432 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
19433 LONGEST str_offset
)
19435 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
19436 str_offset
, "DW_FORM_strp");
19439 /* Return pointer to string at .debug_str offset as read from BUF.
19440 BUF is assumed to be in a compilation unit described by CU_HEADER.
19441 Return *BYTES_READ_PTR count of bytes read from BUF. */
19443 static const char *
19444 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
19445 const gdb_byte
*buf
,
19446 const struct comp_unit_head
*cu_header
,
19447 unsigned int *bytes_read_ptr
)
19449 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19451 return read_indirect_string_at_offset (per_objfile
, str_offset
);
19457 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19458 const struct comp_unit_head
*cu_header
,
19459 unsigned int *bytes_read_ptr
)
19461 bfd
*abfd
= objfile
->obfd
;
19462 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19464 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19467 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19468 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19469 ADDR_SIZE is the size of addresses from the CU header. */
19472 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
19473 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
19475 struct objfile
*objfile
= per_objfile
->objfile
;
19476 bfd
*abfd
= objfile
->obfd
;
19477 const gdb_byte
*info_ptr
;
19478 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19480 per_objfile
->per_bfd
->addr
.read (objfile
);
19481 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19482 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19483 objfile_name (objfile
));
19484 if (addr_base_or_zero
+ addr_index
* addr_size
19485 >= per_objfile
->per_bfd
->addr
.size
)
19486 error (_("DW_FORM_addr_index pointing outside of "
19487 ".debug_addr section [in module %s]"),
19488 objfile_name (objfile
));
19489 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
19490 + addr_index
* addr_size
);
19491 if (addr_size
== 4)
19492 return bfd_get_32 (abfd
, info_ptr
);
19494 return bfd_get_64 (abfd
, info_ptr
);
19497 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19500 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19502 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19503 cu
->addr_base
, cu
->header
.addr_size
);
19506 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19509 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19510 unsigned int *bytes_read
)
19512 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19513 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19515 return read_addr_index (cu
, addr_index
);
19521 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19522 dwarf2_per_objfile
*per_objfile
,
19523 unsigned int addr_index
)
19525 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
19526 gdb::optional
<ULONGEST
> addr_base
;
19529 /* We need addr_base and addr_size.
19530 If we don't have PER_CU->cu, we have to get it.
19531 Nasty, but the alternative is storing the needed info in PER_CU,
19532 which at this point doesn't seem justified: it's not clear how frequently
19533 it would get used and it would increase the size of every PER_CU.
19534 Entry points like dwarf2_per_cu_addr_size do a similar thing
19535 so we're not in uncharted territory here.
19536 Alas we need to be a bit more complicated as addr_base is contained
19539 We don't need to read the entire CU(/TU).
19540 We just need the header and top level die.
19542 IWBN to use the aging mechanism to let us lazily later discard the CU.
19543 For now we skip this optimization. */
19547 addr_base
= cu
->addr_base
;
19548 addr_size
= cu
->header
.addr_size
;
19552 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
19553 addr_base
= reader
.cu
->addr_base
;
19554 addr_size
= reader
.cu
->header
.addr_size
;
19557 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
19560 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19561 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19564 static const char *
19565 read_str_index (struct dwarf2_cu
*cu
,
19566 struct dwarf2_section_info
*str_section
,
19567 struct dwarf2_section_info
*str_offsets_section
,
19568 ULONGEST str_offsets_base
, ULONGEST str_index
)
19570 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19571 struct objfile
*objfile
= per_objfile
->objfile
;
19572 const char *objf_name
= objfile_name (objfile
);
19573 bfd
*abfd
= objfile
->obfd
;
19574 const gdb_byte
*info_ptr
;
19575 ULONGEST str_offset
;
19576 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19578 str_section
->read (objfile
);
19579 str_offsets_section
->read (objfile
);
19580 if (str_section
->buffer
== NULL
)
19581 error (_("%s used without %s section"
19582 " in CU at offset %s [in module %s]"),
19583 form_name
, str_section
->get_name (),
19584 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19585 if (str_offsets_section
->buffer
== NULL
)
19586 error (_("%s used without %s section"
19587 " in CU at offset %s [in module %s]"),
19588 form_name
, str_section
->get_name (),
19589 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19590 info_ptr
= (str_offsets_section
->buffer
19592 + str_index
* cu
->header
.offset_size
);
19593 if (cu
->header
.offset_size
== 4)
19594 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19596 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19597 if (str_offset
>= str_section
->size
)
19598 error (_("Offset from %s pointing outside of"
19599 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19600 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19601 return (const char *) (str_section
->buffer
+ str_offset
);
19604 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19606 static const char *
19607 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19609 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19610 ? reader
->cu
->header
.addr_size
: 0;
19611 return read_str_index (reader
->cu
,
19612 &reader
->dwo_file
->sections
.str
,
19613 &reader
->dwo_file
->sections
.str_offsets
,
19614 str_offsets_base
, str_index
);
19617 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19619 static const char *
19620 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19622 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19623 const char *objf_name
= objfile_name (objfile
);
19624 static const char form_name
[] = "DW_FORM_GNU_str_index";
19625 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19627 if (!cu
->str_offsets_base
.has_value ())
19628 error (_("%s used in Fission stub without %s"
19629 " in CU at offset 0x%lx [in module %s]"),
19630 form_name
, str_offsets_attr_name
,
19631 (long) cu
->header
.offset_size
, objf_name
);
19633 return read_str_index (cu
,
19634 &cu
->per_objfile
->per_bfd
->str
,
19635 &cu
->per_objfile
->per_bfd
->str_offsets
,
19636 *cu
->str_offsets_base
, str_index
);
19639 /* Return the length of an LEB128 number in BUF. */
19642 leb128_size (const gdb_byte
*buf
)
19644 const gdb_byte
*begin
= buf
;
19650 if ((byte
& 128) == 0)
19651 return buf
- begin
;
19656 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19665 cu
->language
= language_c
;
19668 case DW_LANG_C_plus_plus
:
19669 case DW_LANG_C_plus_plus_11
:
19670 case DW_LANG_C_plus_plus_14
:
19671 cu
->language
= language_cplus
;
19674 cu
->language
= language_d
;
19676 case DW_LANG_Fortran77
:
19677 case DW_LANG_Fortran90
:
19678 case DW_LANG_Fortran95
:
19679 case DW_LANG_Fortran03
:
19680 case DW_LANG_Fortran08
:
19681 cu
->language
= language_fortran
;
19684 cu
->language
= language_go
;
19686 case DW_LANG_Mips_Assembler
:
19687 cu
->language
= language_asm
;
19689 case DW_LANG_Ada83
:
19690 case DW_LANG_Ada95
:
19691 cu
->language
= language_ada
;
19693 case DW_LANG_Modula2
:
19694 cu
->language
= language_m2
;
19696 case DW_LANG_Pascal83
:
19697 cu
->language
= language_pascal
;
19700 cu
->language
= language_objc
;
19703 case DW_LANG_Rust_old
:
19704 cu
->language
= language_rust
;
19706 case DW_LANG_Cobol74
:
19707 case DW_LANG_Cobol85
:
19709 cu
->language
= language_minimal
;
19712 cu
->language_defn
= language_def (cu
->language
);
19715 /* Return the named attribute or NULL if not there. */
19717 static struct attribute
*
19718 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19723 struct attribute
*spec
= NULL
;
19725 for (i
= 0; i
< die
->num_attrs
; ++i
)
19727 if (die
->attrs
[i
].name
== name
)
19728 return &die
->attrs
[i
];
19729 if (die
->attrs
[i
].name
== DW_AT_specification
19730 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19731 spec
= &die
->attrs
[i
];
19737 die
= follow_die_ref (die
, spec
, &cu
);
19743 /* Return the string associated with a string-typed attribute, or NULL if it
19744 is either not found or is of an incorrect type. */
19746 static const char *
19747 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19749 struct attribute
*attr
;
19750 const char *str
= NULL
;
19752 attr
= dwarf2_attr (die
, name
, cu
);
19756 str
= attr
->value_as_string ();
19757 if (str
== nullptr)
19758 complaint (_("string type expected for attribute %s for "
19759 "DIE at %s in module %s"),
19760 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19761 objfile_name (cu
->per_objfile
->objfile
));
19767 /* Return the dwo name or NULL if not present. If present, it is in either
19768 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19769 static const char *
19770 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19772 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19773 if (dwo_name
== nullptr)
19774 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19778 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19779 and holds a non-zero value. This function should only be used for
19780 DW_FORM_flag or DW_FORM_flag_present attributes. */
19783 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19785 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19787 return (attr
&& DW_UNSND (attr
));
19791 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19793 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19794 which value is non-zero. However, we have to be careful with
19795 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19796 (via dwarf2_flag_true_p) follows this attribute. So we may
19797 end up accidently finding a declaration attribute that belongs
19798 to a different DIE referenced by the specification attribute,
19799 even though the given DIE does not have a declaration attribute. */
19800 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19801 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19804 /* Return the die giving the specification for DIE, if there is
19805 one. *SPEC_CU is the CU containing DIE on input, and the CU
19806 containing the return value on output. If there is no
19807 specification, but there is an abstract origin, that is
19810 static struct die_info
*
19811 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19813 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19816 if (spec_attr
== NULL
)
19817 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19819 if (spec_attr
== NULL
)
19822 return follow_die_ref (die
, spec_attr
, spec_cu
);
19825 /* Stub for free_line_header to match void * callback types. */
19828 free_line_header_voidp (void *arg
)
19830 struct line_header
*lh
= (struct line_header
*) arg
;
19835 /* A convenience function to find the proper .debug_line section for a CU. */
19837 static struct dwarf2_section_info
*
19838 get_debug_line_section (struct dwarf2_cu
*cu
)
19840 struct dwarf2_section_info
*section
;
19841 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19843 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19845 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19846 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19847 else if (cu
->per_cu
->is_dwz
)
19849 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19851 section
= &dwz
->line
;
19854 section
= &per_objfile
->per_bfd
->line
;
19859 /* Read the statement program header starting at OFFSET in
19860 .debug_line, or .debug_line.dwo. Return a pointer
19861 to a struct line_header, allocated using xmalloc.
19862 Returns NULL if there is a problem reading the header, e.g., if it
19863 has a version we don't understand.
19865 NOTE: the strings in the include directory and file name tables of
19866 the returned object point into the dwarf line section buffer,
19867 and must not be freed. */
19869 static line_header_up
19870 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19872 struct dwarf2_section_info
*section
;
19873 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19875 section
= get_debug_line_section (cu
);
19876 section
->read (per_objfile
->objfile
);
19877 if (section
->buffer
== NULL
)
19879 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19880 complaint (_("missing .debug_line.dwo section"));
19882 complaint (_("missing .debug_line section"));
19886 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19887 per_objfile
, section
, &cu
->header
);
19890 /* Subroutine of dwarf_decode_lines to simplify it.
19891 Return the file name of the psymtab for the given file_entry.
19892 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19893 If space for the result is malloc'd, *NAME_HOLDER will be set.
19894 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19896 static const char *
19897 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19898 const dwarf2_psymtab
*pst
,
19899 const char *comp_dir
,
19900 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19902 const char *include_name
= fe
.name
;
19903 const char *include_name_to_compare
= include_name
;
19904 const char *pst_filename
;
19907 const char *dir_name
= fe
.include_dir (lh
);
19909 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19910 if (!IS_ABSOLUTE_PATH (include_name
)
19911 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19913 /* Avoid creating a duplicate psymtab for PST.
19914 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19915 Before we do the comparison, however, we need to account
19916 for DIR_NAME and COMP_DIR.
19917 First prepend dir_name (if non-NULL). If we still don't
19918 have an absolute path prepend comp_dir (if non-NULL).
19919 However, the directory we record in the include-file's
19920 psymtab does not contain COMP_DIR (to match the
19921 corresponding symtab(s)).
19926 bash$ gcc -g ./hello.c
19927 include_name = "hello.c"
19929 DW_AT_comp_dir = comp_dir = "/tmp"
19930 DW_AT_name = "./hello.c"
19934 if (dir_name
!= NULL
)
19936 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19937 include_name
, (char *) NULL
));
19938 include_name
= name_holder
->get ();
19939 include_name_to_compare
= include_name
;
19941 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19943 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19944 include_name
, (char *) NULL
));
19945 include_name_to_compare
= hold_compare
.get ();
19949 pst_filename
= pst
->filename
;
19950 gdb::unique_xmalloc_ptr
<char> copied_name
;
19951 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19953 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19954 pst_filename
, (char *) NULL
));
19955 pst_filename
= copied_name
.get ();
19958 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19962 return include_name
;
19965 /* State machine to track the state of the line number program. */
19967 class lnp_state_machine
19970 /* Initialize a machine state for the start of a line number
19972 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19973 bool record_lines_p
);
19975 file_entry
*current_file ()
19977 /* lh->file_names is 0-based, but the file name numbers in the
19978 statement program are 1-based. */
19979 return m_line_header
->file_name_at (m_file
);
19982 /* Record the line in the state machine. END_SEQUENCE is true if
19983 we're processing the end of a sequence. */
19984 void record_line (bool end_sequence
);
19986 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19987 nop-out rest of the lines in this sequence. */
19988 void check_line_address (struct dwarf2_cu
*cu
,
19989 const gdb_byte
*line_ptr
,
19990 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19992 void handle_set_discriminator (unsigned int discriminator
)
19994 m_discriminator
= discriminator
;
19995 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19998 /* Handle DW_LNE_set_address. */
19999 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20002 address
+= baseaddr
;
20003 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20006 /* Handle DW_LNS_advance_pc. */
20007 void handle_advance_pc (CORE_ADDR adjust
);
20009 /* Handle a special opcode. */
20010 void handle_special_opcode (unsigned char op_code
);
20012 /* Handle DW_LNS_advance_line. */
20013 void handle_advance_line (int line_delta
)
20015 advance_line (line_delta
);
20018 /* Handle DW_LNS_set_file. */
20019 void handle_set_file (file_name_index file
);
20021 /* Handle DW_LNS_negate_stmt. */
20022 void handle_negate_stmt ()
20024 m_is_stmt
= !m_is_stmt
;
20027 /* Handle DW_LNS_const_add_pc. */
20028 void handle_const_add_pc ();
20030 /* Handle DW_LNS_fixed_advance_pc. */
20031 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20033 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20037 /* Handle DW_LNS_copy. */
20038 void handle_copy ()
20040 record_line (false);
20041 m_discriminator
= 0;
20044 /* Handle DW_LNE_end_sequence. */
20045 void handle_end_sequence ()
20047 m_currently_recording_lines
= true;
20051 /* Advance the line by LINE_DELTA. */
20052 void advance_line (int line_delta
)
20054 m_line
+= line_delta
;
20056 if (line_delta
!= 0)
20057 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20060 struct dwarf2_cu
*m_cu
;
20062 gdbarch
*m_gdbarch
;
20064 /* True if we're recording lines.
20065 Otherwise we're building partial symtabs and are just interested in
20066 finding include files mentioned by the line number program. */
20067 bool m_record_lines_p
;
20069 /* The line number header. */
20070 line_header
*m_line_header
;
20072 /* These are part of the standard DWARF line number state machine,
20073 and initialized according to the DWARF spec. */
20075 unsigned char m_op_index
= 0;
20076 /* The line table index of the current file. */
20077 file_name_index m_file
= 1;
20078 unsigned int m_line
= 1;
20080 /* These are initialized in the constructor. */
20082 CORE_ADDR m_address
;
20084 unsigned int m_discriminator
;
20086 /* Additional bits of state we need to track. */
20088 /* The last file that we called dwarf2_start_subfile for.
20089 This is only used for TLLs. */
20090 unsigned int m_last_file
= 0;
20091 /* The last file a line number was recorded for. */
20092 struct subfile
*m_last_subfile
= NULL
;
20094 /* The address of the last line entry. */
20095 CORE_ADDR m_last_address
;
20097 /* Set to true when a previous line at the same address (using
20098 m_last_address) had m_is_stmt true. This is reset to false when a
20099 line entry at a new address (m_address different to m_last_address) is
20101 bool m_stmt_at_address
= false;
20103 /* When true, record the lines we decode. */
20104 bool m_currently_recording_lines
= false;
20106 /* The last line number that was recorded, used to coalesce
20107 consecutive entries for the same line. This can happen, for
20108 example, when discriminators are present. PR 17276. */
20109 unsigned int m_last_line
= 0;
20110 bool m_line_has_non_zero_discriminator
= false;
20114 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20116 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20117 / m_line_header
->maximum_ops_per_instruction
)
20118 * m_line_header
->minimum_instruction_length
);
20119 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20120 m_op_index
= ((m_op_index
+ adjust
)
20121 % m_line_header
->maximum_ops_per_instruction
);
20125 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20127 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20128 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20129 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20130 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20131 / m_line_header
->maximum_ops_per_instruction
)
20132 * m_line_header
->minimum_instruction_length
);
20133 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20134 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20135 % m_line_header
->maximum_ops_per_instruction
);
20137 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20138 advance_line (line_delta
);
20139 record_line (false);
20140 m_discriminator
= 0;
20144 lnp_state_machine::handle_set_file (file_name_index file
)
20148 const file_entry
*fe
= current_file ();
20150 dwarf2_debug_line_missing_file_complaint ();
20151 else if (m_record_lines_p
)
20153 const char *dir
= fe
->include_dir (m_line_header
);
20155 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20156 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20157 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20162 lnp_state_machine::handle_const_add_pc ()
20165 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20168 = (((m_op_index
+ adjust
)
20169 / m_line_header
->maximum_ops_per_instruction
)
20170 * m_line_header
->minimum_instruction_length
);
20172 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20173 m_op_index
= ((m_op_index
+ adjust
)
20174 % m_line_header
->maximum_ops_per_instruction
);
20177 /* Return non-zero if we should add LINE to the line number table.
20178 LINE is the line to add, LAST_LINE is the last line that was added,
20179 LAST_SUBFILE is the subfile for LAST_LINE.
20180 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20181 had a non-zero discriminator.
20183 We have to be careful in the presence of discriminators.
20184 E.g., for this line:
20186 for (i = 0; i < 100000; i++);
20188 clang can emit four line number entries for that one line,
20189 each with a different discriminator.
20190 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20192 However, we want gdb to coalesce all four entries into one.
20193 Otherwise the user could stepi into the middle of the line and
20194 gdb would get confused about whether the pc really was in the
20195 middle of the line.
20197 Things are further complicated by the fact that two consecutive
20198 line number entries for the same line is a heuristic used by gcc
20199 to denote the end of the prologue. So we can't just discard duplicate
20200 entries, we have to be selective about it. The heuristic we use is
20201 that we only collapse consecutive entries for the same line if at least
20202 one of those entries has a non-zero discriminator. PR 17276.
20204 Note: Addresses in the line number state machine can never go backwards
20205 within one sequence, thus this coalescing is ok. */
20208 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20209 unsigned int line
, unsigned int last_line
,
20210 int line_has_non_zero_discriminator
,
20211 struct subfile
*last_subfile
)
20213 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20215 if (line
!= last_line
)
20217 /* Same line for the same file that we've seen already.
20218 As a last check, for pr 17276, only record the line if the line
20219 has never had a non-zero discriminator. */
20220 if (!line_has_non_zero_discriminator
)
20225 /* Use the CU's builder to record line number LINE beginning at
20226 address ADDRESS in the line table of subfile SUBFILE. */
20229 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20230 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20231 struct dwarf2_cu
*cu
)
20233 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20235 if (dwarf_line_debug
)
20237 fprintf_unfiltered (gdb_stdlog
,
20238 "Recording line %u, file %s, address %s\n",
20239 line
, lbasename (subfile
->name
),
20240 paddress (gdbarch
, address
));
20244 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20247 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20248 Mark the end of a set of line number records.
20249 The arguments are the same as for dwarf_record_line_1.
20250 If SUBFILE is NULL the request is ignored. */
20253 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20254 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20256 if (subfile
== NULL
)
20259 if (dwarf_line_debug
)
20261 fprintf_unfiltered (gdb_stdlog
,
20262 "Finishing current line, file %s, address %s\n",
20263 lbasename (subfile
->name
),
20264 paddress (gdbarch
, address
));
20267 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20271 lnp_state_machine::record_line (bool end_sequence
)
20273 if (dwarf_line_debug
)
20275 fprintf_unfiltered (gdb_stdlog
,
20276 "Processing actual line %u: file %u,"
20277 " address %s, is_stmt %u, discrim %u%s\n",
20279 paddress (m_gdbarch
, m_address
),
20280 m_is_stmt
, m_discriminator
,
20281 (end_sequence
? "\t(end sequence)" : ""));
20284 file_entry
*fe
= current_file ();
20287 dwarf2_debug_line_missing_file_complaint ();
20288 /* For now we ignore lines not starting on an instruction boundary.
20289 But not when processing end_sequence for compatibility with the
20290 previous version of the code. */
20291 else if (m_op_index
== 0 || end_sequence
)
20293 fe
->included_p
= 1;
20294 if (m_record_lines_p
)
20296 /* When we switch files we insert an end maker in the first file,
20297 switch to the second file and add a new line entry. The
20298 problem is that the end marker inserted in the first file will
20299 discard any previous line entries at the same address. If the
20300 line entries in the first file are marked as is-stmt, while
20301 the new line in the second file is non-stmt, then this means
20302 the end marker will discard is-stmt lines so we can have a
20303 non-stmt line. This means that there are less addresses at
20304 which the user can insert a breakpoint.
20306 To improve this we track the last address in m_last_address,
20307 and whether we have seen an is-stmt at this address. Then
20308 when switching files, if we have seen a stmt at the current
20309 address, and we are switching to create a non-stmt line, then
20310 discard the new line. */
20312 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
20313 bool ignore_this_line
20314 = (file_changed
&& !end_sequence
&& m_last_address
== m_address
20315 && !m_is_stmt
&& m_stmt_at_address
);
20317 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
20319 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20320 m_currently_recording_lines
? m_cu
: nullptr);
20323 if (!end_sequence
&& !ignore_this_line
)
20325 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20327 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20328 m_line_has_non_zero_discriminator
,
20331 buildsym_compunit
*builder
= m_cu
->get_builder ();
20332 dwarf_record_line_1 (m_gdbarch
,
20333 builder
->get_current_subfile (),
20334 m_line
, m_address
, is_stmt
,
20335 m_currently_recording_lines
? m_cu
: nullptr);
20337 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20338 m_last_line
= m_line
;
20343 /* Track whether we have seen any m_is_stmt true at m_address in case we
20344 have multiple line table entries all at m_address. */
20345 if (m_last_address
!= m_address
)
20347 m_stmt_at_address
= false;
20348 m_last_address
= m_address
;
20350 m_stmt_at_address
|= m_is_stmt
;
20353 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20354 line_header
*lh
, bool record_lines_p
)
20358 m_record_lines_p
= record_lines_p
;
20359 m_line_header
= lh
;
20361 m_currently_recording_lines
= true;
20363 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20364 was a line entry for it so that the backend has a chance to adjust it
20365 and also record it in case it needs it. This is currently used by MIPS
20366 code, cf. `mips_adjust_dwarf2_line'. */
20367 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20368 m_is_stmt
= lh
->default_is_stmt
;
20369 m_discriminator
= 0;
20371 m_last_address
= m_address
;
20372 m_stmt_at_address
= false;
20376 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20377 const gdb_byte
*line_ptr
,
20378 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20380 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20381 the pc range of the CU. However, we restrict the test to only ADDRESS
20382 values of zero to preserve GDB's previous behaviour which is to handle
20383 the specific case of a function being GC'd by the linker. */
20385 if (address
== 0 && address
< unrelocated_lowpc
)
20387 /* This line table is for a function which has been
20388 GCd by the linker. Ignore it. PR gdb/12528 */
20390 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20391 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20393 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20394 line_offset
, objfile_name (objfile
));
20395 m_currently_recording_lines
= false;
20396 /* Note: m_currently_recording_lines is left as false until we see
20397 DW_LNE_end_sequence. */
20401 /* Subroutine of dwarf_decode_lines to simplify it.
20402 Process the line number information in LH.
20403 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20404 program in order to set included_p for every referenced header. */
20407 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20408 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20410 const gdb_byte
*line_ptr
, *extended_end
;
20411 const gdb_byte
*line_end
;
20412 unsigned int bytes_read
, extended_len
;
20413 unsigned char op_code
, extended_op
;
20414 CORE_ADDR baseaddr
;
20415 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20416 bfd
*abfd
= objfile
->obfd
;
20417 struct gdbarch
*gdbarch
= objfile
->arch ();
20418 /* True if we're recording line info (as opposed to building partial
20419 symtabs and just interested in finding include files mentioned by
20420 the line number program). */
20421 bool record_lines_p
= !decode_for_pst_p
;
20423 baseaddr
= objfile
->text_section_offset ();
20425 line_ptr
= lh
->statement_program_start
;
20426 line_end
= lh
->statement_program_end
;
20428 /* Read the statement sequences until there's nothing left. */
20429 while (line_ptr
< line_end
)
20431 /* The DWARF line number program state machine. Reset the state
20432 machine at the start of each sequence. */
20433 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20434 bool end_sequence
= false;
20436 if (record_lines_p
)
20438 /* Start a subfile for the current file of the state
20440 const file_entry
*fe
= state_machine
.current_file ();
20443 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20446 /* Decode the table. */
20447 while (line_ptr
< line_end
&& !end_sequence
)
20449 op_code
= read_1_byte (abfd
, line_ptr
);
20452 if (op_code
>= lh
->opcode_base
)
20454 /* Special opcode. */
20455 state_machine
.handle_special_opcode (op_code
);
20457 else switch (op_code
)
20459 case DW_LNS_extended_op
:
20460 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20462 line_ptr
+= bytes_read
;
20463 extended_end
= line_ptr
+ extended_len
;
20464 extended_op
= read_1_byte (abfd
, line_ptr
);
20466 switch (extended_op
)
20468 case DW_LNE_end_sequence
:
20469 state_machine
.handle_end_sequence ();
20470 end_sequence
= true;
20472 case DW_LNE_set_address
:
20475 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20476 line_ptr
+= bytes_read
;
20478 state_machine
.check_line_address (cu
, line_ptr
,
20479 lowpc
- baseaddr
, address
);
20480 state_machine
.handle_set_address (baseaddr
, address
);
20483 case DW_LNE_define_file
:
20485 const char *cur_file
;
20486 unsigned int mod_time
, length
;
20489 cur_file
= read_direct_string (abfd
, line_ptr
,
20491 line_ptr
+= bytes_read
;
20492 dindex
= (dir_index
)
20493 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20494 line_ptr
+= bytes_read
;
20496 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20497 line_ptr
+= bytes_read
;
20499 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20500 line_ptr
+= bytes_read
;
20501 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20504 case DW_LNE_set_discriminator
:
20506 /* The discriminator is not interesting to the
20507 debugger; just ignore it. We still need to
20508 check its value though:
20509 if there are consecutive entries for the same
20510 (non-prologue) line we want to coalesce them.
20513 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20514 line_ptr
+= bytes_read
;
20516 state_machine
.handle_set_discriminator (discr
);
20520 complaint (_("mangled .debug_line section"));
20523 /* Make sure that we parsed the extended op correctly. If e.g.
20524 we expected a different address size than the producer used,
20525 we may have read the wrong number of bytes. */
20526 if (line_ptr
!= extended_end
)
20528 complaint (_("mangled .debug_line section"));
20533 state_machine
.handle_copy ();
20535 case DW_LNS_advance_pc
:
20538 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20539 line_ptr
+= bytes_read
;
20541 state_machine
.handle_advance_pc (adjust
);
20544 case DW_LNS_advance_line
:
20547 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20548 line_ptr
+= bytes_read
;
20550 state_machine
.handle_advance_line (line_delta
);
20553 case DW_LNS_set_file
:
20555 file_name_index file
20556 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20558 line_ptr
+= bytes_read
;
20560 state_machine
.handle_set_file (file
);
20563 case DW_LNS_set_column
:
20564 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20565 line_ptr
+= bytes_read
;
20567 case DW_LNS_negate_stmt
:
20568 state_machine
.handle_negate_stmt ();
20570 case DW_LNS_set_basic_block
:
20572 /* Add to the address register of the state machine the
20573 address increment value corresponding to special opcode
20574 255. I.e., this value is scaled by the minimum
20575 instruction length since special opcode 255 would have
20576 scaled the increment. */
20577 case DW_LNS_const_add_pc
:
20578 state_machine
.handle_const_add_pc ();
20580 case DW_LNS_fixed_advance_pc
:
20582 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20585 state_machine
.handle_fixed_advance_pc (addr_adj
);
20590 /* Unknown standard opcode, ignore it. */
20593 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20595 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20596 line_ptr
+= bytes_read
;
20603 dwarf2_debug_line_missing_end_sequence_complaint ();
20605 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20606 in which case we still finish recording the last line). */
20607 state_machine
.record_line (true);
20611 /* Decode the Line Number Program (LNP) for the given line_header
20612 structure and CU. The actual information extracted and the type
20613 of structures created from the LNP depends on the value of PST.
20615 1. If PST is NULL, then this procedure uses the data from the program
20616 to create all necessary symbol tables, and their linetables.
20618 2. If PST is not NULL, this procedure reads the program to determine
20619 the list of files included by the unit represented by PST, and
20620 builds all the associated partial symbol tables.
20622 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20623 It is used for relative paths in the line table.
20624 NOTE: When processing partial symtabs (pst != NULL),
20625 comp_dir == pst->dirname.
20627 NOTE: It is important that psymtabs have the same file name (via strcmp)
20628 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20629 symtab we don't use it in the name of the psymtabs we create.
20630 E.g. expand_line_sal requires this when finding psymtabs to expand.
20631 A good testcase for this is mb-inline.exp.
20633 LOWPC is the lowest address in CU (or 0 if not known).
20635 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20636 for its PC<->lines mapping information. Otherwise only the filename
20637 table is read in. */
20640 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20641 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20642 CORE_ADDR lowpc
, int decode_mapping
)
20644 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20645 const int decode_for_pst_p
= (pst
!= NULL
);
20647 if (decode_mapping
)
20648 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20650 if (decode_for_pst_p
)
20652 /* Now that we're done scanning the Line Header Program, we can
20653 create the psymtab of each included file. */
20654 for (auto &file_entry
: lh
->file_names ())
20655 if (file_entry
.included_p
== 1)
20657 gdb::unique_xmalloc_ptr
<char> name_holder
;
20658 const char *include_name
=
20659 psymtab_include_file_name (lh
, file_entry
, pst
,
20660 comp_dir
, &name_holder
);
20661 if (include_name
!= NULL
)
20662 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20667 /* Make sure a symtab is created for every file, even files
20668 which contain only variables (i.e. no code with associated
20670 buildsym_compunit
*builder
= cu
->get_builder ();
20671 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20673 for (auto &fe
: lh
->file_names ())
20675 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20676 if (builder
->get_current_subfile ()->symtab
== NULL
)
20678 builder
->get_current_subfile ()->symtab
20679 = allocate_symtab (cust
,
20680 builder
->get_current_subfile ()->name
);
20682 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20687 /* Start a subfile for DWARF. FILENAME is the name of the file and
20688 DIRNAME the name of the source directory which contains FILENAME
20689 or NULL if not known.
20690 This routine tries to keep line numbers from identical absolute and
20691 relative file names in a common subfile.
20693 Using the `list' example from the GDB testsuite, which resides in
20694 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20695 of /srcdir/list0.c yields the following debugging information for list0.c:
20697 DW_AT_name: /srcdir/list0.c
20698 DW_AT_comp_dir: /compdir
20699 files.files[0].name: list0.h
20700 files.files[0].dir: /srcdir
20701 files.files[1].name: list0.c
20702 files.files[1].dir: /srcdir
20704 The line number information for list0.c has to end up in a single
20705 subfile, so that `break /srcdir/list0.c:1' works as expected.
20706 start_subfile will ensure that this happens provided that we pass the
20707 concatenation of files.files[1].dir and files.files[1].name as the
20711 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20712 const char *dirname
)
20714 gdb::unique_xmalloc_ptr
<char> copy
;
20716 /* In order not to lose the line information directory,
20717 we concatenate it to the filename when it makes sense.
20718 Note that the Dwarf3 standard says (speaking of filenames in line
20719 information): ``The directory index is ignored for file names
20720 that represent full path names''. Thus ignoring dirname in the
20721 `else' branch below isn't an issue. */
20723 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20725 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20726 filename
= copy
.get ();
20729 cu
->get_builder ()->start_subfile (filename
);
20732 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20733 buildsym_compunit constructor. */
20735 struct compunit_symtab
*
20736 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20739 gdb_assert (m_builder
== nullptr);
20741 m_builder
.reset (new struct buildsym_compunit
20742 (this->per_objfile
->objfile
,
20743 name
, comp_dir
, language
, low_pc
));
20745 list_in_scope
= get_builder ()->get_file_symbols ();
20747 get_builder ()->record_debugformat ("DWARF 2");
20748 get_builder ()->record_producer (producer
);
20750 processing_has_namespace_info
= false;
20752 return get_builder ()->get_compunit_symtab ();
20756 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20757 struct dwarf2_cu
*cu
)
20759 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20760 struct comp_unit_head
*cu_header
= &cu
->header
;
20762 /* NOTE drow/2003-01-30: There used to be a comment and some special
20763 code here to turn a symbol with DW_AT_external and a
20764 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20765 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20766 with some versions of binutils) where shared libraries could have
20767 relocations against symbols in their debug information - the
20768 minimal symbol would have the right address, but the debug info
20769 would not. It's no longer necessary, because we will explicitly
20770 apply relocations when we read in the debug information now. */
20772 /* A DW_AT_location attribute with no contents indicates that a
20773 variable has been optimized away. */
20774 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20776 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20780 /* Handle one degenerate form of location expression specially, to
20781 preserve GDB's previous behavior when section offsets are
20782 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20783 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20785 if (attr
->form_is_block ()
20786 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20787 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20788 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20789 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20790 && (DW_BLOCK (attr
)->size
20791 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20793 unsigned int dummy
;
20795 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20796 SET_SYMBOL_VALUE_ADDRESS
20797 (sym
, cu
->header
.read_address (objfile
->obfd
,
20798 DW_BLOCK (attr
)->data
+ 1,
20801 SET_SYMBOL_VALUE_ADDRESS
20802 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20804 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20805 fixup_symbol_section (sym
, objfile
);
20806 SET_SYMBOL_VALUE_ADDRESS
20808 SYMBOL_VALUE_ADDRESS (sym
)
20809 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20813 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20814 expression evaluator, and use LOC_COMPUTED only when necessary
20815 (i.e. when the value of a register or memory location is
20816 referenced, or a thread-local block, etc.). Then again, it might
20817 not be worthwhile. I'm assuming that it isn't unless performance
20818 or memory numbers show me otherwise. */
20820 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20822 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20823 cu
->has_loclist
= true;
20826 /* Given a pointer to a DWARF information entry, figure out if we need
20827 to make a symbol table entry for it, and if so, create a new entry
20828 and return a pointer to it.
20829 If TYPE is NULL, determine symbol type from the die, otherwise
20830 used the passed type.
20831 If SPACE is not NULL, use it to hold the new symbol. If it is
20832 NULL, allocate a new symbol on the objfile's obstack. */
20834 static struct symbol
*
20835 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20836 struct symbol
*space
)
20838 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20839 struct objfile
*objfile
= per_objfile
->objfile
;
20840 struct gdbarch
*gdbarch
= objfile
->arch ();
20841 struct symbol
*sym
= NULL
;
20843 struct attribute
*attr
= NULL
;
20844 struct attribute
*attr2
= NULL
;
20845 CORE_ADDR baseaddr
;
20846 struct pending
**list_to_add
= NULL
;
20848 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20850 baseaddr
= objfile
->text_section_offset ();
20852 name
= dwarf2_name (die
, cu
);
20855 int suppress_add
= 0;
20860 sym
= new (&objfile
->objfile_obstack
) symbol
;
20861 OBJSTAT (objfile
, n_syms
++);
20863 /* Cache this symbol's name and the name's demangled form (if any). */
20864 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20865 /* Fortran does not have mangling standard and the mangling does differ
20866 between gfortran, iFort etc. */
20867 const char *physname
20868 = (cu
->language
== language_fortran
20869 ? dwarf2_full_name (name
, die
, cu
)
20870 : dwarf2_physname (name
, die
, cu
));
20871 const char *linkagename
= dw2_linkage_name (die
, cu
);
20873 if (linkagename
== nullptr || cu
->language
== language_ada
)
20874 sym
->set_linkage_name (physname
);
20877 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20878 sym
->set_linkage_name (linkagename
);
20881 /* Default assumptions.
20882 Use the passed type or decode it from the die. */
20883 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20884 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20886 SYMBOL_TYPE (sym
) = type
;
20888 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20889 attr
= dwarf2_attr (die
,
20890 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20892 if (attr
!= nullptr)
20894 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20897 attr
= dwarf2_attr (die
,
20898 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20900 if (attr
!= nullptr)
20902 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20903 struct file_entry
*fe
;
20905 if (cu
->line_header
!= NULL
)
20906 fe
= cu
->line_header
->file_name_at (file_index
);
20911 complaint (_("file index out of range"));
20913 symbol_set_symtab (sym
, fe
->symtab
);
20919 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20920 if (attr
!= nullptr)
20924 addr
= attr
->value_as_address ();
20925 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20926 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20928 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20929 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20930 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20931 add_symbol_to_list (sym
, cu
->list_in_scope
);
20933 case DW_TAG_subprogram
:
20934 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20936 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20937 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20938 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20939 || cu
->language
== language_ada
20940 || cu
->language
== language_fortran
)
20942 /* Subprograms marked external are stored as a global symbol.
20943 Ada and Fortran subprograms, whether marked external or
20944 not, are always stored as a global symbol, because we want
20945 to be able to access them globally. For instance, we want
20946 to be able to break on a nested subprogram without having
20947 to specify the context. */
20948 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20952 list_to_add
= cu
->list_in_scope
;
20955 case DW_TAG_inlined_subroutine
:
20956 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20958 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20959 SYMBOL_INLINED (sym
) = 1;
20960 list_to_add
= cu
->list_in_scope
;
20962 case DW_TAG_template_value_param
:
20964 /* Fall through. */
20965 case DW_TAG_constant
:
20966 case DW_TAG_variable
:
20967 case DW_TAG_member
:
20968 /* Compilation with minimal debug info may result in
20969 variables with missing type entries. Change the
20970 misleading `void' type to something sensible. */
20971 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20972 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20974 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20975 /* In the case of DW_TAG_member, we should only be called for
20976 static const members. */
20977 if (die
->tag
== DW_TAG_member
)
20979 /* dwarf2_add_field uses die_is_declaration,
20980 so we do the same. */
20981 gdb_assert (die_is_declaration (die
, cu
));
20984 if (attr
!= nullptr)
20986 dwarf2_const_value (attr
, sym
, cu
);
20987 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20990 if (attr2
&& (DW_UNSND (attr2
) != 0))
20991 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20993 list_to_add
= cu
->list_in_scope
;
20997 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20998 if (attr
!= nullptr)
21000 var_decode_location (attr
, sym
, cu
);
21001 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21003 /* Fortran explicitly imports any global symbols to the local
21004 scope by DW_TAG_common_block. */
21005 if (cu
->language
== language_fortran
&& die
->parent
21006 && die
->parent
->tag
== DW_TAG_common_block
)
21009 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21010 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21011 && !per_objfile
->per_bfd
->has_section_at_zero
)
21013 /* When a static variable is eliminated by the linker,
21014 the corresponding debug information is not stripped
21015 out, but the variable address is set to null;
21016 do not add such variables into symbol table. */
21018 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21020 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21021 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21022 && per_objfile
->per_bfd
->can_copy
)
21024 /* A global static variable might be subject to
21025 copy relocation. We first check for a local
21026 minsym, though, because maybe the symbol was
21027 marked hidden, in which case this would not
21029 bound_minimal_symbol found
21030 = (lookup_minimal_symbol_linkage
21031 (sym
->linkage_name (), objfile
));
21032 if (found
.minsym
!= nullptr)
21033 sym
->maybe_copied
= 1;
21036 /* A variable with DW_AT_external is never static,
21037 but it may be block-scoped. */
21039 = ((cu
->list_in_scope
21040 == cu
->get_builder ()->get_file_symbols ())
21041 ? cu
->get_builder ()->get_global_symbols ()
21042 : cu
->list_in_scope
);
21045 list_to_add
= cu
->list_in_scope
;
21049 /* We do not know the address of this symbol.
21050 If it is an external symbol and we have type information
21051 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21052 The address of the variable will then be determined from
21053 the minimal symbol table whenever the variable is
21055 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21057 /* Fortran explicitly imports any global symbols to the local
21058 scope by DW_TAG_common_block. */
21059 if (cu
->language
== language_fortran
&& die
->parent
21060 && die
->parent
->tag
== DW_TAG_common_block
)
21062 /* SYMBOL_CLASS doesn't matter here because
21063 read_common_block is going to reset it. */
21065 list_to_add
= cu
->list_in_scope
;
21067 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21068 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21070 /* A variable with DW_AT_external is never static, but it
21071 may be block-scoped. */
21073 = ((cu
->list_in_scope
21074 == cu
->get_builder ()->get_file_symbols ())
21075 ? cu
->get_builder ()->get_global_symbols ()
21076 : cu
->list_in_scope
);
21078 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21080 else if (!die_is_declaration (die
, cu
))
21082 /* Use the default LOC_OPTIMIZED_OUT class. */
21083 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21085 list_to_add
= cu
->list_in_scope
;
21089 case DW_TAG_formal_parameter
:
21091 /* If we are inside a function, mark this as an argument. If
21092 not, we might be looking at an argument to an inlined function
21093 when we do not have enough information to show inlined frames;
21094 pretend it's a local variable in that case so that the user can
21096 struct context_stack
*curr
21097 = cu
->get_builder ()->get_current_context_stack ();
21098 if (curr
!= nullptr && curr
->name
!= nullptr)
21099 SYMBOL_IS_ARGUMENT (sym
) = 1;
21100 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21101 if (attr
!= nullptr)
21103 var_decode_location (attr
, sym
, cu
);
21105 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21106 if (attr
!= nullptr)
21108 dwarf2_const_value (attr
, sym
, cu
);
21111 list_to_add
= cu
->list_in_scope
;
21114 case DW_TAG_unspecified_parameters
:
21115 /* From varargs functions; gdb doesn't seem to have any
21116 interest in this information, so just ignore it for now.
21119 case DW_TAG_template_type_param
:
21121 /* Fall through. */
21122 case DW_TAG_class_type
:
21123 case DW_TAG_interface_type
:
21124 case DW_TAG_structure_type
:
21125 case DW_TAG_union_type
:
21126 case DW_TAG_set_type
:
21127 case DW_TAG_enumeration_type
:
21128 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21129 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21132 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21133 really ever be static objects: otherwise, if you try
21134 to, say, break of a class's method and you're in a file
21135 which doesn't mention that class, it won't work unless
21136 the check for all static symbols in lookup_symbol_aux
21137 saves you. See the OtherFileClass tests in
21138 gdb.c++/namespace.exp. */
21142 buildsym_compunit
*builder
= cu
->get_builder ();
21144 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21145 && cu
->language
== language_cplus
21146 ? builder
->get_global_symbols ()
21147 : cu
->list_in_scope
);
21149 /* The semantics of C++ state that "struct foo {
21150 ... }" also defines a typedef for "foo". */
21151 if (cu
->language
== language_cplus
21152 || cu
->language
== language_ada
21153 || cu
->language
== language_d
21154 || cu
->language
== language_rust
)
21156 /* The symbol's name is already allocated along
21157 with this objfile, so we don't need to
21158 duplicate it for the type. */
21159 if (SYMBOL_TYPE (sym
)->name () == 0)
21160 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21165 case DW_TAG_typedef
:
21166 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21167 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21168 list_to_add
= cu
->list_in_scope
;
21170 case DW_TAG_base_type
:
21171 case DW_TAG_subrange_type
:
21172 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21173 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21174 list_to_add
= cu
->list_in_scope
;
21176 case DW_TAG_enumerator
:
21177 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21178 if (attr
!= nullptr)
21180 dwarf2_const_value (attr
, sym
, cu
);
21183 /* NOTE: carlton/2003-11-10: See comment above in the
21184 DW_TAG_class_type, etc. block. */
21187 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21188 && cu
->language
== language_cplus
21189 ? cu
->get_builder ()->get_global_symbols ()
21190 : cu
->list_in_scope
);
21193 case DW_TAG_imported_declaration
:
21194 case DW_TAG_namespace
:
21195 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21196 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21198 case DW_TAG_module
:
21199 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21200 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21201 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21203 case DW_TAG_common_block
:
21204 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21205 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21206 add_symbol_to_list (sym
, cu
->list_in_scope
);
21209 /* Not a tag we recognize. Hopefully we aren't processing
21210 trash data, but since we must specifically ignore things
21211 we don't recognize, there is nothing else we should do at
21213 complaint (_("unsupported tag: '%s'"),
21214 dwarf_tag_name (die
->tag
));
21220 sym
->hash_next
= objfile
->template_symbols
;
21221 objfile
->template_symbols
= sym
;
21222 list_to_add
= NULL
;
21225 if (list_to_add
!= NULL
)
21226 add_symbol_to_list (sym
, list_to_add
);
21228 /* For the benefit of old versions of GCC, check for anonymous
21229 namespaces based on the demangled name. */
21230 if (!cu
->processing_has_namespace_info
21231 && cu
->language
== language_cplus
)
21232 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21237 /* Given an attr with a DW_FORM_dataN value in host byte order,
21238 zero-extend it as appropriate for the symbol's type. The DWARF
21239 standard (v4) is not entirely clear about the meaning of using
21240 DW_FORM_dataN for a constant with a signed type, where the type is
21241 wider than the data. The conclusion of a discussion on the DWARF
21242 list was that this is unspecified. We choose to always zero-extend
21243 because that is the interpretation long in use by GCC. */
21246 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21247 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21249 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21250 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21251 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21252 LONGEST l
= DW_UNSND (attr
);
21254 if (bits
< sizeof (*value
) * 8)
21256 l
&= ((LONGEST
) 1 << bits
) - 1;
21259 else if (bits
== sizeof (*value
) * 8)
21263 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21264 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21271 /* Read a constant value from an attribute. Either set *VALUE, or if
21272 the value does not fit in *VALUE, set *BYTES - either already
21273 allocated on the objfile obstack, or newly allocated on OBSTACK,
21274 or, set *BATON, if we translated the constant to a location
21278 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21279 const char *name
, struct obstack
*obstack
,
21280 struct dwarf2_cu
*cu
,
21281 LONGEST
*value
, const gdb_byte
**bytes
,
21282 struct dwarf2_locexpr_baton
**baton
)
21284 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21285 struct objfile
*objfile
= per_objfile
->objfile
;
21286 struct comp_unit_head
*cu_header
= &cu
->header
;
21287 struct dwarf_block
*blk
;
21288 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21289 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21295 switch (attr
->form
)
21298 case DW_FORM_addrx
:
21299 case DW_FORM_GNU_addr_index
:
21303 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21304 dwarf2_const_value_length_mismatch_complaint (name
,
21305 cu_header
->addr_size
,
21306 TYPE_LENGTH (type
));
21307 /* Symbols of this form are reasonably rare, so we just
21308 piggyback on the existing location code rather than writing
21309 a new implementation of symbol_computed_ops. */
21310 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21311 (*baton
)->per_objfile
= per_objfile
;
21312 (*baton
)->per_cu
= cu
->per_cu
;
21313 gdb_assert ((*baton
)->per_cu
);
21315 (*baton
)->size
= 2 + cu_header
->addr_size
;
21316 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21317 (*baton
)->data
= data
;
21319 data
[0] = DW_OP_addr
;
21320 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21321 byte_order
, DW_ADDR (attr
));
21322 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21325 case DW_FORM_string
:
21328 case DW_FORM_GNU_str_index
:
21329 case DW_FORM_GNU_strp_alt
:
21330 /* DW_STRING is already allocated on the objfile obstack, point
21332 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21334 case DW_FORM_block1
:
21335 case DW_FORM_block2
:
21336 case DW_FORM_block4
:
21337 case DW_FORM_block
:
21338 case DW_FORM_exprloc
:
21339 case DW_FORM_data16
:
21340 blk
= DW_BLOCK (attr
);
21341 if (TYPE_LENGTH (type
) != blk
->size
)
21342 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21343 TYPE_LENGTH (type
));
21344 *bytes
= blk
->data
;
21347 /* The DW_AT_const_value attributes are supposed to carry the
21348 symbol's value "represented as it would be on the target
21349 architecture." By the time we get here, it's already been
21350 converted to host endianness, so we just need to sign- or
21351 zero-extend it as appropriate. */
21352 case DW_FORM_data1
:
21353 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21355 case DW_FORM_data2
:
21356 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21358 case DW_FORM_data4
:
21359 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21361 case DW_FORM_data8
:
21362 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21365 case DW_FORM_sdata
:
21366 case DW_FORM_implicit_const
:
21367 *value
= DW_SND (attr
);
21370 case DW_FORM_udata
:
21371 *value
= DW_UNSND (attr
);
21375 complaint (_("unsupported const value attribute form: '%s'"),
21376 dwarf_form_name (attr
->form
));
21383 /* Copy constant value from an attribute to a symbol. */
21386 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21387 struct dwarf2_cu
*cu
)
21389 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21391 const gdb_byte
*bytes
;
21392 struct dwarf2_locexpr_baton
*baton
;
21394 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21395 sym
->print_name (),
21396 &objfile
->objfile_obstack
, cu
,
21397 &value
, &bytes
, &baton
);
21401 SYMBOL_LOCATION_BATON (sym
) = baton
;
21402 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21404 else if (bytes
!= NULL
)
21406 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21407 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21411 SYMBOL_VALUE (sym
) = value
;
21412 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21416 /* Return the type of the die in question using its DW_AT_type attribute. */
21418 static struct type
*
21419 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21421 struct attribute
*type_attr
;
21423 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21426 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21427 /* A missing DW_AT_type represents a void type. */
21428 return objfile_type (objfile
)->builtin_void
;
21431 return lookup_die_type (die
, type_attr
, cu
);
21434 /* True iff CU's producer generates GNAT Ada auxiliary information
21435 that allows to find parallel types through that information instead
21436 of having to do expensive parallel lookups by type name. */
21439 need_gnat_info (struct dwarf2_cu
*cu
)
21441 /* Assume that the Ada compiler was GNAT, which always produces
21442 the auxiliary information. */
21443 return (cu
->language
== language_ada
);
21446 /* Return the auxiliary type of the die in question using its
21447 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21448 attribute is not present. */
21450 static struct type
*
21451 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21453 struct attribute
*type_attr
;
21455 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21459 return lookup_die_type (die
, type_attr
, cu
);
21462 /* If DIE has a descriptive_type attribute, then set the TYPE's
21463 descriptive type accordingly. */
21466 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21467 struct dwarf2_cu
*cu
)
21469 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21471 if (descriptive_type
)
21473 ALLOCATE_GNAT_AUX_TYPE (type
);
21474 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21478 /* Return the containing type of the die in question using its
21479 DW_AT_containing_type attribute. */
21481 static struct type
*
21482 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21484 struct attribute
*type_attr
;
21485 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21487 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21489 error (_("Dwarf Error: Problem turning containing type into gdb type "
21490 "[in module %s]"), objfile_name (objfile
));
21492 return lookup_die_type (die
, type_attr
, cu
);
21495 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21497 static struct type
*
21498 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21500 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21501 struct objfile
*objfile
= per_objfile
->objfile
;
21504 std::string message
21505 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21506 objfile_name (objfile
),
21507 sect_offset_str (cu
->header
.sect_off
),
21508 sect_offset_str (die
->sect_off
));
21509 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21511 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21514 /* Look up the type of DIE in CU using its type attribute ATTR.
21515 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21516 DW_AT_containing_type.
21517 If there is no type substitute an error marker. */
21519 static struct type
*
21520 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21521 struct dwarf2_cu
*cu
)
21523 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21524 struct objfile
*objfile
= per_objfile
->objfile
;
21525 struct type
*this_type
;
21527 gdb_assert (attr
->name
== DW_AT_type
21528 || attr
->name
== DW_AT_GNAT_descriptive_type
21529 || attr
->name
== DW_AT_containing_type
);
21531 /* First see if we have it cached. */
21533 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21535 struct dwarf2_per_cu_data
*per_cu
;
21536 sect_offset sect_off
= attr
->get_ref_die_offset ();
21538 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
21539 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
21541 else if (attr
->form_is_ref ())
21543 sect_offset sect_off
= attr
->get_ref_die_offset ();
21545 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
21547 else if (attr
->form
== DW_FORM_ref_sig8
)
21549 ULONGEST signature
= DW_SIGNATURE (attr
);
21551 return get_signatured_type (die
, signature
, cu
);
21555 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21556 " at %s [in module %s]"),
21557 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21558 objfile_name (objfile
));
21559 return build_error_marker_type (cu
, die
);
21562 /* If not cached we need to read it in. */
21564 if (this_type
== NULL
)
21566 struct die_info
*type_die
= NULL
;
21567 struct dwarf2_cu
*type_cu
= cu
;
21569 if (attr
->form_is_ref ())
21570 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21571 if (type_die
== NULL
)
21572 return build_error_marker_type (cu
, die
);
21573 /* If we find the type now, it's probably because the type came
21574 from an inter-CU reference and the type's CU got expanded before
21576 this_type
= read_type_die (type_die
, type_cu
);
21579 /* If we still don't have a type use an error marker. */
21581 if (this_type
== NULL
)
21582 return build_error_marker_type (cu
, die
);
21587 /* Return the type in DIE, CU.
21588 Returns NULL for invalid types.
21590 This first does a lookup in die_type_hash,
21591 and only reads the die in if necessary.
21593 NOTE: This can be called when reading in partial or full symbols. */
21595 static struct type
*
21596 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21598 struct type
*this_type
;
21600 this_type
= get_die_type (die
, cu
);
21604 return read_type_die_1 (die
, cu
);
21607 /* Read the type in DIE, CU.
21608 Returns NULL for invalid types. */
21610 static struct type
*
21611 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21613 struct type
*this_type
= NULL
;
21617 case DW_TAG_class_type
:
21618 case DW_TAG_interface_type
:
21619 case DW_TAG_structure_type
:
21620 case DW_TAG_union_type
:
21621 this_type
= read_structure_type (die
, cu
);
21623 case DW_TAG_enumeration_type
:
21624 this_type
= read_enumeration_type (die
, cu
);
21626 case DW_TAG_subprogram
:
21627 case DW_TAG_subroutine_type
:
21628 case DW_TAG_inlined_subroutine
:
21629 this_type
= read_subroutine_type (die
, cu
);
21631 case DW_TAG_array_type
:
21632 this_type
= read_array_type (die
, cu
);
21634 case DW_TAG_set_type
:
21635 this_type
= read_set_type (die
, cu
);
21637 case DW_TAG_pointer_type
:
21638 this_type
= read_tag_pointer_type (die
, cu
);
21640 case DW_TAG_ptr_to_member_type
:
21641 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21643 case DW_TAG_reference_type
:
21644 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21646 case DW_TAG_rvalue_reference_type
:
21647 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21649 case DW_TAG_const_type
:
21650 this_type
= read_tag_const_type (die
, cu
);
21652 case DW_TAG_volatile_type
:
21653 this_type
= read_tag_volatile_type (die
, cu
);
21655 case DW_TAG_restrict_type
:
21656 this_type
= read_tag_restrict_type (die
, cu
);
21658 case DW_TAG_string_type
:
21659 this_type
= read_tag_string_type (die
, cu
);
21661 case DW_TAG_typedef
:
21662 this_type
= read_typedef (die
, cu
);
21664 case DW_TAG_subrange_type
:
21665 this_type
= read_subrange_type (die
, cu
);
21667 case DW_TAG_base_type
:
21668 this_type
= read_base_type (die
, cu
);
21670 case DW_TAG_unspecified_type
:
21671 this_type
= read_unspecified_type (die
, cu
);
21673 case DW_TAG_namespace
:
21674 this_type
= read_namespace_type (die
, cu
);
21676 case DW_TAG_module
:
21677 this_type
= read_module_type (die
, cu
);
21679 case DW_TAG_atomic_type
:
21680 this_type
= read_tag_atomic_type (die
, cu
);
21683 complaint (_("unexpected tag in read_type_die: '%s'"),
21684 dwarf_tag_name (die
->tag
));
21691 /* See if we can figure out if the class lives in a namespace. We do
21692 this by looking for a member function; its demangled name will
21693 contain namespace info, if there is any.
21694 Return the computed name or NULL.
21695 Space for the result is allocated on the objfile's obstack.
21696 This is the full-die version of guess_partial_die_structure_name.
21697 In this case we know DIE has no useful parent. */
21699 static const char *
21700 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21702 struct die_info
*spec_die
;
21703 struct dwarf2_cu
*spec_cu
;
21704 struct die_info
*child
;
21705 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21708 spec_die
= die_specification (die
, &spec_cu
);
21709 if (spec_die
!= NULL
)
21715 for (child
= die
->child
;
21717 child
= child
->sibling
)
21719 if (child
->tag
== DW_TAG_subprogram
)
21721 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21723 if (linkage_name
!= NULL
)
21725 gdb::unique_xmalloc_ptr
<char> actual_name
21726 (cu
->language_defn
->class_name_from_physname (linkage_name
));
21727 const char *name
= NULL
;
21729 if (actual_name
!= NULL
)
21731 const char *die_name
= dwarf2_name (die
, cu
);
21733 if (die_name
!= NULL
21734 && strcmp (die_name
, actual_name
.get ()) != 0)
21736 /* Strip off the class name from the full name.
21737 We want the prefix. */
21738 int die_name_len
= strlen (die_name
);
21739 int actual_name_len
= strlen (actual_name
.get ());
21740 const char *ptr
= actual_name
.get ();
21742 /* Test for '::' as a sanity check. */
21743 if (actual_name_len
> die_name_len
+ 2
21744 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21745 name
= obstack_strndup (
21746 &objfile
->per_bfd
->storage_obstack
,
21747 ptr
, actual_name_len
- die_name_len
- 2);
21758 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21759 prefix part in such case. See
21760 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21762 static const char *
21763 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21765 struct attribute
*attr
;
21768 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21769 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21772 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21775 attr
= dw2_linkage_name_attr (die
, cu
);
21776 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21779 /* dwarf2_name had to be already called. */
21780 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21782 /* Strip the base name, keep any leading namespaces/classes. */
21783 base
= strrchr (DW_STRING (attr
), ':');
21784 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21787 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21788 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21790 &base
[-1] - DW_STRING (attr
));
21793 /* Return the name of the namespace/class that DIE is defined within,
21794 or "" if we can't tell. The caller should not xfree the result.
21796 For example, if we're within the method foo() in the following
21806 then determine_prefix on foo's die will return "N::C". */
21808 static const char *
21809 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21811 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21812 struct die_info
*parent
, *spec_die
;
21813 struct dwarf2_cu
*spec_cu
;
21814 struct type
*parent_type
;
21815 const char *retval
;
21817 if (cu
->language
!= language_cplus
21818 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21819 && cu
->language
!= language_rust
)
21822 retval
= anonymous_struct_prefix (die
, cu
);
21826 /* We have to be careful in the presence of DW_AT_specification.
21827 For example, with GCC 3.4, given the code
21831 // Definition of N::foo.
21835 then we'll have a tree of DIEs like this:
21837 1: DW_TAG_compile_unit
21838 2: DW_TAG_namespace // N
21839 3: DW_TAG_subprogram // declaration of N::foo
21840 4: DW_TAG_subprogram // definition of N::foo
21841 DW_AT_specification // refers to die #3
21843 Thus, when processing die #4, we have to pretend that we're in
21844 the context of its DW_AT_specification, namely the contex of die
21847 spec_die
= die_specification (die
, &spec_cu
);
21848 if (spec_die
== NULL
)
21849 parent
= die
->parent
;
21852 parent
= spec_die
->parent
;
21856 if (parent
== NULL
)
21858 else if (parent
->building_fullname
)
21861 const char *parent_name
;
21863 /* It has been seen on RealView 2.2 built binaries,
21864 DW_TAG_template_type_param types actually _defined_ as
21865 children of the parent class:
21868 template class <class Enum> Class{};
21869 Class<enum E> class_e;
21871 1: DW_TAG_class_type (Class)
21872 2: DW_TAG_enumeration_type (E)
21873 3: DW_TAG_enumerator (enum1:0)
21874 3: DW_TAG_enumerator (enum2:1)
21876 2: DW_TAG_template_type_param
21877 DW_AT_type DW_FORM_ref_udata (E)
21879 Besides being broken debug info, it can put GDB into an
21880 infinite loop. Consider:
21882 When we're building the full name for Class<E>, we'll start
21883 at Class, and go look over its template type parameters,
21884 finding E. We'll then try to build the full name of E, and
21885 reach here. We're now trying to build the full name of E,
21886 and look over the parent DIE for containing scope. In the
21887 broken case, if we followed the parent DIE of E, we'd again
21888 find Class, and once again go look at its template type
21889 arguments, etc., etc. Simply don't consider such parent die
21890 as source-level parent of this die (it can't be, the language
21891 doesn't allow it), and break the loop here. */
21892 name
= dwarf2_name (die
, cu
);
21893 parent_name
= dwarf2_name (parent
, cu
);
21894 complaint (_("template param type '%s' defined within parent '%s'"),
21895 name
? name
: "<unknown>",
21896 parent_name
? parent_name
: "<unknown>");
21900 switch (parent
->tag
)
21902 case DW_TAG_namespace
:
21903 parent_type
= read_type_die (parent
, cu
);
21904 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21905 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21906 Work around this problem here. */
21907 if (cu
->language
== language_cplus
21908 && strcmp (parent_type
->name (), "::") == 0)
21910 /* We give a name to even anonymous namespaces. */
21911 return parent_type
->name ();
21912 case DW_TAG_class_type
:
21913 case DW_TAG_interface_type
:
21914 case DW_TAG_structure_type
:
21915 case DW_TAG_union_type
:
21916 case DW_TAG_module
:
21917 parent_type
= read_type_die (parent
, cu
);
21918 if (parent_type
->name () != NULL
)
21919 return parent_type
->name ();
21921 /* An anonymous structure is only allowed non-static data
21922 members; no typedefs, no member functions, et cetera.
21923 So it does not need a prefix. */
21925 case DW_TAG_compile_unit
:
21926 case DW_TAG_partial_unit
:
21927 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21928 if (cu
->language
== language_cplus
21929 && !per_objfile
->per_bfd
->types
.empty ()
21930 && die
->child
!= NULL
21931 && (die
->tag
== DW_TAG_class_type
21932 || die
->tag
== DW_TAG_structure_type
21933 || die
->tag
== DW_TAG_union_type
))
21935 const char *name
= guess_full_die_structure_name (die
, cu
);
21940 case DW_TAG_subprogram
:
21941 /* Nested subroutines in Fortran get a prefix with the name
21942 of the parent's subroutine. */
21943 if (cu
->language
== language_fortran
)
21945 if ((die
->tag
== DW_TAG_subprogram
)
21946 && (dwarf2_name (parent
, cu
) != NULL
))
21947 return dwarf2_name (parent
, cu
);
21949 return determine_prefix (parent
, cu
);
21950 case DW_TAG_enumeration_type
:
21951 parent_type
= read_type_die (parent
, cu
);
21952 if (TYPE_DECLARED_CLASS (parent_type
))
21954 if (parent_type
->name () != NULL
)
21955 return parent_type
->name ();
21958 /* Fall through. */
21960 return determine_prefix (parent
, cu
);
21964 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21965 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21966 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21967 an obconcat, otherwise allocate storage for the result. The CU argument is
21968 used to determine the language and hence, the appropriate separator. */
21970 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21973 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21974 int physname
, struct dwarf2_cu
*cu
)
21976 const char *lead
= "";
21979 if (suffix
== NULL
|| suffix
[0] == '\0'
21980 || prefix
== NULL
|| prefix
[0] == '\0')
21982 else if (cu
->language
== language_d
)
21984 /* For D, the 'main' function could be defined in any module, but it
21985 should never be prefixed. */
21986 if (strcmp (suffix
, "D main") == 0)
21994 else if (cu
->language
== language_fortran
&& physname
)
21996 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21997 DW_AT_MIPS_linkage_name is preferred and used instead. */
22005 if (prefix
== NULL
)
22007 if (suffix
== NULL
)
22014 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22016 strcpy (retval
, lead
);
22017 strcat (retval
, prefix
);
22018 strcat (retval
, sep
);
22019 strcat (retval
, suffix
);
22024 /* We have an obstack. */
22025 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22029 /* Get name of a die, return NULL if not found. */
22031 static const char *
22032 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22033 struct objfile
*objfile
)
22035 if (name
&& cu
->language
== language_cplus
)
22037 gdb::unique_xmalloc_ptr
<char> canon_name
22038 = cp_canonicalize_string (name
);
22040 if (canon_name
!= nullptr)
22041 name
= objfile
->intern (canon_name
.get ());
22047 /* Get name of a die, return NULL if not found.
22048 Anonymous namespaces are converted to their magic string. */
22050 static const char *
22051 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22053 struct attribute
*attr
;
22054 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22056 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22057 if ((!attr
|| !DW_STRING (attr
))
22058 && die
->tag
!= DW_TAG_namespace
22059 && die
->tag
!= DW_TAG_class_type
22060 && die
->tag
!= DW_TAG_interface_type
22061 && die
->tag
!= DW_TAG_structure_type
22062 && die
->tag
!= DW_TAG_union_type
)
22067 case DW_TAG_compile_unit
:
22068 case DW_TAG_partial_unit
:
22069 /* Compilation units have a DW_AT_name that is a filename, not
22070 a source language identifier. */
22071 case DW_TAG_enumeration_type
:
22072 case DW_TAG_enumerator
:
22073 /* These tags always have simple identifiers already; no need
22074 to canonicalize them. */
22075 return DW_STRING (attr
);
22077 case DW_TAG_namespace
:
22078 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22079 return DW_STRING (attr
);
22080 return CP_ANONYMOUS_NAMESPACE_STR
;
22082 case DW_TAG_class_type
:
22083 case DW_TAG_interface_type
:
22084 case DW_TAG_structure_type
:
22085 case DW_TAG_union_type
:
22086 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22087 structures or unions. These were of the form "._%d" in GCC 4.1,
22088 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22089 and GCC 4.4. We work around this problem by ignoring these. */
22090 if (attr
&& DW_STRING (attr
)
22091 && (startswith (DW_STRING (attr
), "._")
22092 || startswith (DW_STRING (attr
), "<anonymous")))
22095 /* GCC might emit a nameless typedef that has a linkage name. See
22096 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22097 if (!attr
|| DW_STRING (attr
) == NULL
)
22099 attr
= dw2_linkage_name_attr (die
, cu
);
22100 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22103 /* Avoid demangling DW_STRING (attr) the second time on a second
22104 call for the same DIE. */
22105 if (!DW_STRING_IS_CANONICAL (attr
))
22107 gdb::unique_xmalloc_ptr
<char> demangled
22108 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22109 if (demangled
== nullptr)
22112 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
22113 DW_STRING_IS_CANONICAL (attr
) = 1;
22116 /* Strip any leading namespaces/classes, keep only the base name.
22117 DW_AT_name for named DIEs does not contain the prefixes. */
22118 const char *base
= strrchr (DW_STRING (attr
), ':');
22119 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22122 return DW_STRING (attr
);
22130 if (!DW_STRING_IS_CANONICAL (attr
))
22132 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22134 DW_STRING_IS_CANONICAL (attr
) = 1;
22136 return DW_STRING (attr
);
22139 /* Return the die that this die in an extension of, or NULL if there
22140 is none. *EXT_CU is the CU containing DIE on input, and the CU
22141 containing the return value on output. */
22143 static struct die_info
*
22144 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22146 struct attribute
*attr
;
22148 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22152 return follow_die_ref (die
, attr
, ext_cu
);
22156 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22160 print_spaces (indent
, f
);
22161 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22162 dwarf_tag_name (die
->tag
), die
->abbrev
,
22163 sect_offset_str (die
->sect_off
));
22165 if (die
->parent
!= NULL
)
22167 print_spaces (indent
, f
);
22168 fprintf_unfiltered (f
, " parent at offset: %s\n",
22169 sect_offset_str (die
->parent
->sect_off
));
22172 print_spaces (indent
, f
);
22173 fprintf_unfiltered (f
, " has children: %s\n",
22174 dwarf_bool_name (die
->child
!= NULL
));
22176 print_spaces (indent
, f
);
22177 fprintf_unfiltered (f
, " attributes:\n");
22179 for (i
= 0; i
< die
->num_attrs
; ++i
)
22181 print_spaces (indent
, f
);
22182 fprintf_unfiltered (f
, " %s (%s) ",
22183 dwarf_attr_name (die
->attrs
[i
].name
),
22184 dwarf_form_name (die
->attrs
[i
].form
));
22186 switch (die
->attrs
[i
].form
)
22189 case DW_FORM_addrx
:
22190 case DW_FORM_GNU_addr_index
:
22191 fprintf_unfiltered (f
, "address: ");
22192 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22194 case DW_FORM_block2
:
22195 case DW_FORM_block4
:
22196 case DW_FORM_block
:
22197 case DW_FORM_block1
:
22198 fprintf_unfiltered (f
, "block: size %s",
22199 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22201 case DW_FORM_exprloc
:
22202 fprintf_unfiltered (f
, "expression: size %s",
22203 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22205 case DW_FORM_data16
:
22206 fprintf_unfiltered (f
, "constant of 16 bytes");
22208 case DW_FORM_ref_addr
:
22209 fprintf_unfiltered (f
, "ref address: ");
22210 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22212 case DW_FORM_GNU_ref_alt
:
22213 fprintf_unfiltered (f
, "alt ref address: ");
22214 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22220 case DW_FORM_ref_udata
:
22221 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22222 (long) (DW_UNSND (&die
->attrs
[i
])));
22224 case DW_FORM_data1
:
22225 case DW_FORM_data2
:
22226 case DW_FORM_data4
:
22227 case DW_FORM_data8
:
22228 case DW_FORM_udata
:
22229 case DW_FORM_sdata
:
22230 fprintf_unfiltered (f
, "constant: %s",
22231 pulongest (DW_UNSND (&die
->attrs
[i
])));
22233 case DW_FORM_sec_offset
:
22234 fprintf_unfiltered (f
, "section offset: %s",
22235 pulongest (DW_UNSND (&die
->attrs
[i
])));
22237 case DW_FORM_ref_sig8
:
22238 fprintf_unfiltered (f
, "signature: %s",
22239 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22241 case DW_FORM_string
:
22243 case DW_FORM_line_strp
:
22245 case DW_FORM_GNU_str_index
:
22246 case DW_FORM_GNU_strp_alt
:
22247 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22248 DW_STRING (&die
->attrs
[i
])
22249 ? DW_STRING (&die
->attrs
[i
]) : "",
22250 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22253 if (DW_UNSND (&die
->attrs
[i
]))
22254 fprintf_unfiltered (f
, "flag: TRUE");
22256 fprintf_unfiltered (f
, "flag: FALSE");
22258 case DW_FORM_flag_present
:
22259 fprintf_unfiltered (f
, "flag: TRUE");
22261 case DW_FORM_indirect
:
22262 /* The reader will have reduced the indirect form to
22263 the "base form" so this form should not occur. */
22264 fprintf_unfiltered (f
,
22265 "unexpected attribute form: DW_FORM_indirect");
22267 case DW_FORM_implicit_const
:
22268 fprintf_unfiltered (f
, "constant: %s",
22269 plongest (DW_SND (&die
->attrs
[i
])));
22272 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22273 die
->attrs
[i
].form
);
22276 fprintf_unfiltered (f
, "\n");
22281 dump_die_for_error (struct die_info
*die
)
22283 dump_die_shallow (gdb_stderr
, 0, die
);
22287 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22289 int indent
= level
* 4;
22291 gdb_assert (die
!= NULL
);
22293 if (level
>= max_level
)
22296 dump_die_shallow (f
, indent
, die
);
22298 if (die
->child
!= NULL
)
22300 print_spaces (indent
, f
);
22301 fprintf_unfiltered (f
, " Children:");
22302 if (level
+ 1 < max_level
)
22304 fprintf_unfiltered (f
, "\n");
22305 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22309 fprintf_unfiltered (f
,
22310 " [not printed, max nesting level reached]\n");
22314 if (die
->sibling
!= NULL
&& level
> 0)
22316 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22320 /* This is called from the pdie macro in gdbinit.in.
22321 It's not static so gcc will keep a copy callable from gdb. */
22324 dump_die (struct die_info
*die
, int max_level
)
22326 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22330 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22334 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22335 to_underlying (die
->sect_off
),
22341 /* Follow reference or signature attribute ATTR of SRC_DIE.
22342 On entry *REF_CU is the CU of SRC_DIE.
22343 On exit *REF_CU is the CU of the result. */
22345 static struct die_info
*
22346 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22347 struct dwarf2_cu
**ref_cu
)
22349 struct die_info
*die
;
22351 if (attr
->form_is_ref ())
22352 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22353 else if (attr
->form
== DW_FORM_ref_sig8
)
22354 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22357 dump_die_for_error (src_die
);
22358 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22359 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22365 /* Follow reference OFFSET.
22366 On entry *REF_CU is the CU of the source die referencing OFFSET.
22367 On exit *REF_CU is the CU of the result.
22368 Returns NULL if OFFSET is invalid. */
22370 static struct die_info
*
22371 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22372 struct dwarf2_cu
**ref_cu
)
22374 struct die_info temp_die
;
22375 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22376 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22378 gdb_assert (cu
->per_cu
!= NULL
);
22382 if (cu
->per_cu
->is_debug_types
)
22384 /* .debug_types CUs cannot reference anything outside their CU.
22385 If they need to, they have to reference a signatured type via
22386 DW_FORM_ref_sig8. */
22387 if (!cu
->header
.offset_in_cu_p (sect_off
))
22390 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22391 || !cu
->header
.offset_in_cu_p (sect_off
))
22393 struct dwarf2_per_cu_data
*per_cu
;
22395 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22398 /* If necessary, add it to the queue and load its DIEs. */
22399 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
22400 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
22402 target_cu
= per_objfile
->get_cu (per_cu
);
22404 else if (cu
->dies
== NULL
)
22406 /* We're loading full DIEs during partial symbol reading. */
22407 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
22408 load_full_comp_unit (cu
->per_cu
, per_objfile
, false, language_minimal
);
22411 *ref_cu
= target_cu
;
22412 temp_die
.sect_off
= sect_off
;
22414 if (target_cu
!= cu
)
22415 target_cu
->ancestor
= cu
;
22417 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22419 to_underlying (sect_off
));
22422 /* Follow reference attribute ATTR of SRC_DIE.
22423 On entry *REF_CU is the CU of SRC_DIE.
22424 On exit *REF_CU is the CU of the result. */
22426 static struct die_info
*
22427 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22428 struct dwarf2_cu
**ref_cu
)
22430 sect_offset sect_off
= attr
->get_ref_die_offset ();
22431 struct dwarf2_cu
*cu
= *ref_cu
;
22432 struct die_info
*die
;
22434 die
= follow_die_offset (sect_off
,
22435 (attr
->form
== DW_FORM_GNU_ref_alt
22436 || cu
->per_cu
->is_dwz
),
22439 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22440 "at %s [in module %s]"),
22441 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22442 objfile_name (cu
->per_objfile
->objfile
));
22449 struct dwarf2_locexpr_baton
22450 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22451 dwarf2_per_cu_data
*per_cu
,
22452 dwarf2_per_objfile
*per_objfile
,
22453 CORE_ADDR (*get_frame_pc
) (void *baton
),
22454 void *baton
, bool resolve_abstract_p
)
22456 struct die_info
*die
;
22457 struct attribute
*attr
;
22458 struct dwarf2_locexpr_baton retval
;
22459 struct objfile
*objfile
= per_objfile
->objfile
;
22461 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22463 cu
= load_cu (per_cu
, per_objfile
, false);
22467 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22468 Instead just throw an error, not much else we can do. */
22469 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22470 sect_offset_str (sect_off
), objfile_name (objfile
));
22473 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22475 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22476 sect_offset_str (sect_off
), objfile_name (objfile
));
22478 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22479 if (!attr
&& resolve_abstract_p
22480 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22481 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22483 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22484 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22485 struct gdbarch
*gdbarch
= objfile
->arch ();
22487 for (const auto &cand_off
22488 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22490 struct dwarf2_cu
*cand_cu
= cu
;
22491 struct die_info
*cand
22492 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22495 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22498 CORE_ADDR pc_low
, pc_high
;
22499 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22500 if (pc_low
== ((CORE_ADDR
) -1))
22502 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22503 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22504 if (!(pc_low
<= pc
&& pc
< pc_high
))
22508 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22515 /* DWARF: "If there is no such attribute, then there is no effect.".
22516 DATA is ignored if SIZE is 0. */
22518 retval
.data
= NULL
;
22521 else if (attr
->form_is_section_offset ())
22523 struct dwarf2_loclist_baton loclist_baton
;
22524 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22527 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22529 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22531 retval
.size
= size
;
22535 if (!attr
->form_is_block ())
22536 error (_("Dwarf Error: DIE at %s referenced in module %s "
22537 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22538 sect_offset_str (sect_off
), objfile_name (objfile
));
22540 retval
.data
= DW_BLOCK (attr
)->data
;
22541 retval
.size
= DW_BLOCK (attr
)->size
;
22543 retval
.per_objfile
= per_objfile
;
22544 retval
.per_cu
= cu
->per_cu
;
22546 per_objfile
->age_comp_units ();
22553 struct dwarf2_locexpr_baton
22554 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22555 dwarf2_per_cu_data
*per_cu
,
22556 dwarf2_per_objfile
*per_objfile
,
22557 CORE_ADDR (*get_frame_pc
) (void *baton
),
22560 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22562 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22563 get_frame_pc
, baton
);
22566 /* Write a constant of a given type as target-ordered bytes into
22569 static const gdb_byte
*
22570 write_constant_as_bytes (struct obstack
*obstack
,
22571 enum bfd_endian byte_order
,
22578 *len
= TYPE_LENGTH (type
);
22579 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22580 store_unsigned_integer (result
, *len
, byte_order
, value
);
22588 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22589 dwarf2_per_cu_data
*per_cu
,
22590 dwarf2_per_objfile
*per_objfile
,
22594 struct die_info
*die
;
22595 struct attribute
*attr
;
22596 const gdb_byte
*result
= NULL
;
22599 enum bfd_endian byte_order
;
22600 struct objfile
*objfile
= per_objfile
->objfile
;
22602 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22604 cu
= load_cu (per_cu
, per_objfile
, false);
22608 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22609 Instead just throw an error, not much else we can do. */
22610 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22611 sect_offset_str (sect_off
), objfile_name (objfile
));
22614 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22616 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22617 sect_offset_str (sect_off
), objfile_name (objfile
));
22619 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22623 byte_order
= (bfd_big_endian (objfile
->obfd
)
22624 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22626 switch (attr
->form
)
22629 case DW_FORM_addrx
:
22630 case DW_FORM_GNU_addr_index
:
22634 *len
= cu
->header
.addr_size
;
22635 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22636 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22640 case DW_FORM_string
:
22643 case DW_FORM_GNU_str_index
:
22644 case DW_FORM_GNU_strp_alt
:
22645 /* DW_STRING is already allocated on the objfile obstack, point
22647 result
= (const gdb_byte
*) DW_STRING (attr
);
22648 *len
= strlen (DW_STRING (attr
));
22650 case DW_FORM_block1
:
22651 case DW_FORM_block2
:
22652 case DW_FORM_block4
:
22653 case DW_FORM_block
:
22654 case DW_FORM_exprloc
:
22655 case DW_FORM_data16
:
22656 result
= DW_BLOCK (attr
)->data
;
22657 *len
= DW_BLOCK (attr
)->size
;
22660 /* The DW_AT_const_value attributes are supposed to carry the
22661 symbol's value "represented as it would be on the target
22662 architecture." By the time we get here, it's already been
22663 converted to host endianness, so we just need to sign- or
22664 zero-extend it as appropriate. */
22665 case DW_FORM_data1
:
22666 type
= die_type (die
, cu
);
22667 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22668 if (result
== NULL
)
22669 result
= write_constant_as_bytes (obstack
, byte_order
,
22672 case DW_FORM_data2
:
22673 type
= die_type (die
, cu
);
22674 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22675 if (result
== NULL
)
22676 result
= write_constant_as_bytes (obstack
, byte_order
,
22679 case DW_FORM_data4
:
22680 type
= die_type (die
, cu
);
22681 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22682 if (result
== NULL
)
22683 result
= write_constant_as_bytes (obstack
, byte_order
,
22686 case DW_FORM_data8
:
22687 type
= die_type (die
, cu
);
22688 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22689 if (result
== NULL
)
22690 result
= write_constant_as_bytes (obstack
, byte_order
,
22694 case DW_FORM_sdata
:
22695 case DW_FORM_implicit_const
:
22696 type
= die_type (die
, cu
);
22697 result
= write_constant_as_bytes (obstack
, byte_order
,
22698 type
, DW_SND (attr
), len
);
22701 case DW_FORM_udata
:
22702 type
= die_type (die
, cu
);
22703 result
= write_constant_as_bytes (obstack
, byte_order
,
22704 type
, DW_UNSND (attr
), len
);
22708 complaint (_("unsupported const value attribute form: '%s'"),
22709 dwarf_form_name (attr
->form
));
22719 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22720 dwarf2_per_cu_data
*per_cu
,
22721 dwarf2_per_objfile
*per_objfile
)
22723 struct die_info
*die
;
22725 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22727 cu
= load_cu (per_cu
, per_objfile
, false);
22732 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22736 return die_type (die
, cu
);
22742 dwarf2_get_die_type (cu_offset die_offset
,
22743 dwarf2_per_cu_data
*per_cu
,
22744 dwarf2_per_objfile
*per_objfile
)
22746 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22747 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22750 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22751 On entry *REF_CU is the CU of SRC_DIE.
22752 On exit *REF_CU is the CU of the result.
22753 Returns NULL if the referenced DIE isn't found. */
22755 static struct die_info
*
22756 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22757 struct dwarf2_cu
**ref_cu
)
22759 struct die_info temp_die
;
22760 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22761 struct die_info
*die
;
22762 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
22765 /* While it might be nice to assert sig_type->type == NULL here,
22766 we can get here for DW_AT_imported_declaration where we need
22767 the DIE not the type. */
22769 /* If necessary, add it to the queue and load its DIEs. */
22771 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
22773 read_signatured_type (sig_type
, per_objfile
);
22775 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
22776 gdb_assert (sig_cu
!= NULL
);
22777 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22778 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22779 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22780 to_underlying (temp_die
.sect_off
));
22783 /* For .gdb_index version 7 keep track of included TUs.
22784 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22785 if (per_objfile
->per_bfd
->index_table
!= NULL
22786 && per_objfile
->per_bfd
->index_table
->version
<= 7)
22788 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22793 sig_cu
->ancestor
= cu
;
22801 /* Follow signatured type referenced by ATTR in SRC_DIE.
22802 On entry *REF_CU is the CU of SRC_DIE.
22803 On exit *REF_CU is the CU of the result.
22804 The result is the DIE of the type.
22805 If the referenced type cannot be found an error is thrown. */
22807 static struct die_info
*
22808 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22809 struct dwarf2_cu
**ref_cu
)
22811 ULONGEST signature
= DW_SIGNATURE (attr
);
22812 struct signatured_type
*sig_type
;
22813 struct die_info
*die
;
22815 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22817 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22818 /* sig_type will be NULL if the signatured type is missing from
22820 if (sig_type
== NULL
)
22822 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22823 " from DIE at %s [in module %s]"),
22824 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22825 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22828 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22831 dump_die_for_error (src_die
);
22832 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22833 " from DIE at %s [in module %s]"),
22834 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22835 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22841 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22842 reading in and processing the type unit if necessary. */
22844 static struct type
*
22845 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22846 struct dwarf2_cu
*cu
)
22848 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22849 struct signatured_type
*sig_type
;
22850 struct dwarf2_cu
*type_cu
;
22851 struct die_info
*type_die
;
22854 sig_type
= lookup_signatured_type (cu
, signature
);
22855 /* sig_type will be NULL if the signatured type is missing from
22857 if (sig_type
== NULL
)
22859 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22860 " from DIE at %s [in module %s]"),
22861 hex_string (signature
), sect_offset_str (die
->sect_off
),
22862 objfile_name (per_objfile
->objfile
));
22863 return build_error_marker_type (cu
, die
);
22866 /* If we already know the type we're done. */
22867 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
22868 if (type
!= nullptr)
22872 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22873 if (type_die
!= NULL
)
22875 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22876 is created. This is important, for example, because for c++ classes
22877 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22878 type
= read_type_die (type_die
, type_cu
);
22881 complaint (_("Dwarf Error: Cannot build signatured type %s"
22882 " referenced from DIE at %s [in module %s]"),
22883 hex_string (signature
), sect_offset_str (die
->sect_off
),
22884 objfile_name (per_objfile
->objfile
));
22885 type
= build_error_marker_type (cu
, die
);
22890 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22891 " from DIE at %s [in module %s]"),
22892 hex_string (signature
), sect_offset_str (die
->sect_off
),
22893 objfile_name (per_objfile
->objfile
));
22894 type
= build_error_marker_type (cu
, die
);
22897 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22902 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22903 reading in and processing the type unit if necessary. */
22905 static struct type
*
22906 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22907 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22909 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22910 if (attr
->form_is_ref ())
22912 struct dwarf2_cu
*type_cu
= cu
;
22913 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22915 return read_type_die (type_die
, type_cu
);
22917 else if (attr
->form
== DW_FORM_ref_sig8
)
22919 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22923 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22925 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22926 " at %s [in module %s]"),
22927 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22928 objfile_name (per_objfile
->objfile
));
22929 return build_error_marker_type (cu
, die
);
22933 /* Load the DIEs associated with type unit PER_CU into memory. */
22936 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22937 dwarf2_per_objfile
*per_objfile
)
22939 struct signatured_type
*sig_type
;
22941 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22942 gdb_assert (! per_cu
->type_unit_group_p ());
22944 /* We have the per_cu, but we need the signatured_type.
22945 Fortunately this is an easy translation. */
22946 gdb_assert (per_cu
->is_debug_types
);
22947 sig_type
= (struct signatured_type
*) per_cu
;
22949 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22951 read_signatured_type (sig_type
, per_objfile
);
22953 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22956 /* Read in a signatured type and build its CU and DIEs.
22957 If the type is a stub for the real type in a DWO file,
22958 read in the real type from the DWO file as well. */
22961 read_signatured_type (signatured_type
*sig_type
,
22962 dwarf2_per_objfile
*per_objfile
)
22964 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22966 gdb_assert (per_cu
->is_debug_types
);
22967 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22969 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
22971 if (!reader
.dummy_p
)
22973 struct dwarf2_cu
*cu
= reader
.cu
;
22974 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22976 gdb_assert (cu
->die_hash
== NULL
);
22978 htab_create_alloc_ex (cu
->header
.length
/ 12,
22982 &cu
->comp_unit_obstack
,
22983 hashtab_obstack_allocate
,
22984 dummy_obstack_deallocate
);
22986 if (reader
.comp_unit_die
->has_children
)
22987 reader
.comp_unit_die
->child
22988 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22989 reader
.comp_unit_die
);
22990 cu
->dies
= reader
.comp_unit_die
;
22991 /* comp_unit_die is not stored in die_hash, no need. */
22993 /* We try not to read any attributes in this function, because
22994 not all CUs needed for references have been loaded yet, and
22995 symbol table processing isn't initialized. But we have to
22996 set the CU language, or we won't be able to build types
22997 correctly. Similarly, if we do not read the producer, we can
22998 not apply producer-specific interpretation. */
22999 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23004 sig_type
->per_cu
.tu_read
= 1;
23007 /* Decode simple location descriptions.
23008 Given a pointer to a dwarf block that defines a location, compute
23009 the location and return the value. If COMPUTED is non-null, it is
23010 set to true to indicate that decoding was successful, and false
23011 otherwise. If COMPUTED is null, then this function may emit a
23015 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23017 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23019 size_t size
= blk
->size
;
23020 const gdb_byte
*data
= blk
->data
;
23021 CORE_ADDR stack
[64];
23023 unsigned int bytes_read
, unsnd
;
23026 if (computed
!= nullptr)
23032 stack
[++stacki
] = 0;
23071 stack
[++stacki
] = op
- DW_OP_lit0
;
23106 stack
[++stacki
] = op
- DW_OP_reg0
;
23109 if (computed
== nullptr)
23110 dwarf2_complex_location_expr_complaint ();
23117 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23119 stack
[++stacki
] = unsnd
;
23122 if (computed
== nullptr)
23123 dwarf2_complex_location_expr_complaint ();
23130 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23135 case DW_OP_const1u
:
23136 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23140 case DW_OP_const1s
:
23141 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23145 case DW_OP_const2u
:
23146 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23150 case DW_OP_const2s
:
23151 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23155 case DW_OP_const4u
:
23156 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23160 case DW_OP_const4s
:
23161 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23165 case DW_OP_const8u
:
23166 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23171 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23177 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23182 stack
[stacki
+ 1] = stack
[stacki
];
23187 stack
[stacki
- 1] += stack
[stacki
];
23191 case DW_OP_plus_uconst
:
23192 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23198 stack
[stacki
- 1] -= stack
[stacki
];
23203 /* If we're not the last op, then we definitely can't encode
23204 this using GDB's address_class enum. This is valid for partial
23205 global symbols, although the variable's address will be bogus
23209 if (computed
== nullptr)
23210 dwarf2_complex_location_expr_complaint ();
23216 case DW_OP_GNU_push_tls_address
:
23217 case DW_OP_form_tls_address
:
23218 /* The top of the stack has the offset from the beginning
23219 of the thread control block at which the variable is located. */
23220 /* Nothing should follow this operator, so the top of stack would
23222 /* This is valid for partial global symbols, but the variable's
23223 address will be bogus in the psymtab. Make it always at least
23224 non-zero to not look as a variable garbage collected by linker
23225 which have DW_OP_addr 0. */
23228 if (computed
== nullptr)
23229 dwarf2_complex_location_expr_complaint ();
23236 case DW_OP_GNU_uninit
:
23237 if (computed
!= nullptr)
23242 case DW_OP_GNU_addr_index
:
23243 case DW_OP_GNU_const_index
:
23244 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23250 if (computed
== nullptr)
23252 const char *name
= get_DW_OP_name (op
);
23255 complaint (_("unsupported stack op: '%s'"),
23258 complaint (_("unsupported stack op: '%02x'"),
23262 return (stack
[stacki
]);
23265 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23266 outside of the allocated space. Also enforce minimum>0. */
23267 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23269 if (computed
== nullptr)
23270 complaint (_("location description stack overflow"));
23276 if (computed
== nullptr)
23277 complaint (_("location description stack underflow"));
23282 if (computed
!= nullptr)
23284 return (stack
[stacki
]);
23287 /* memory allocation interface */
23289 static struct dwarf_block
*
23290 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23292 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23295 static struct die_info
*
23296 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23298 struct die_info
*die
;
23299 size_t size
= sizeof (struct die_info
);
23302 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23304 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23305 memset (die
, 0, sizeof (struct die_info
));
23311 /* Macro support. */
23313 /* An overload of dwarf_decode_macros that finds the correct section
23314 and ensures it is read in before calling the other overload. */
23317 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23318 int section_is_gnu
)
23320 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23321 struct objfile
*objfile
= per_objfile
->objfile
;
23322 const struct line_header
*lh
= cu
->line_header
;
23323 unsigned int offset_size
= cu
->header
.offset_size
;
23324 struct dwarf2_section_info
*section
;
23325 const char *section_name
;
23327 if (cu
->dwo_unit
!= nullptr)
23329 if (section_is_gnu
)
23331 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23332 section_name
= ".debug_macro.dwo";
23336 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23337 section_name
= ".debug_macinfo.dwo";
23342 if (section_is_gnu
)
23344 section
= &per_objfile
->per_bfd
->macro
;
23345 section_name
= ".debug_macro";
23349 section
= &per_objfile
->per_bfd
->macinfo
;
23350 section_name
= ".debug_macinfo";
23354 section
->read (objfile
);
23355 if (section
->buffer
== nullptr)
23357 complaint (_("missing %s section"), section_name
);
23361 buildsym_compunit
*builder
= cu
->get_builder ();
23363 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
23364 offset_size
, offset
, section_is_gnu
);
23367 /* Return the .debug_loc section to use for CU.
23368 For DWO files use .debug_loc.dwo. */
23370 static struct dwarf2_section_info
*
23371 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23373 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23377 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23379 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23381 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
23382 : &per_objfile
->per_bfd
->loc
);
23385 /* A helper function that fills in a dwarf2_loclist_baton. */
23388 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23389 struct dwarf2_loclist_baton
*baton
,
23390 const struct attribute
*attr
)
23392 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23393 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23395 section
->read (per_objfile
->objfile
);
23397 baton
->per_objfile
= per_objfile
;
23398 baton
->per_cu
= cu
->per_cu
;
23399 gdb_assert (baton
->per_cu
);
23400 /* We don't know how long the location list is, but make sure we
23401 don't run off the edge of the section. */
23402 baton
->size
= section
->size
- DW_UNSND (attr
);
23403 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23404 if (cu
->base_address
.has_value ())
23405 baton
->base_address
= *cu
->base_address
;
23407 baton
->base_address
= 0;
23408 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23412 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23413 struct dwarf2_cu
*cu
, int is_block
)
23415 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23416 struct objfile
*objfile
= per_objfile
->objfile
;
23417 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23419 if (attr
->form_is_section_offset ()
23420 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23421 the section. If so, fall through to the complaint in the
23423 && DW_UNSND (attr
) < section
->get_size (objfile
))
23425 struct dwarf2_loclist_baton
*baton
;
23427 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23429 fill_in_loclist_baton (cu
, baton
, attr
);
23431 if (!cu
->base_address
.has_value ())
23432 complaint (_("Location list used without "
23433 "specifying the CU base address."));
23435 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23436 ? dwarf2_loclist_block_index
23437 : dwarf2_loclist_index
);
23438 SYMBOL_LOCATION_BATON (sym
) = baton
;
23442 struct dwarf2_locexpr_baton
*baton
;
23444 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23445 baton
->per_objfile
= per_objfile
;
23446 baton
->per_cu
= cu
->per_cu
;
23447 gdb_assert (baton
->per_cu
);
23449 if (attr
->form_is_block ())
23451 /* Note that we're just copying the block's data pointer
23452 here, not the actual data. We're still pointing into the
23453 info_buffer for SYM's objfile; right now we never release
23454 that buffer, but when we do clean up properly this may
23456 baton
->size
= DW_BLOCK (attr
)->size
;
23457 baton
->data
= DW_BLOCK (attr
)->data
;
23461 dwarf2_invalid_attrib_class_complaint ("location description",
23462 sym
->natural_name ());
23466 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23467 ? dwarf2_locexpr_block_index
23468 : dwarf2_locexpr_index
);
23469 SYMBOL_LOCATION_BATON (sym
) = baton
;
23475 const comp_unit_head
*
23476 dwarf2_per_cu_data::get_header () const
23478 if (!m_header_read_in
)
23480 const gdb_byte
*info_ptr
23481 = this->section
->buffer
+ to_underlying (this->sect_off
);
23483 memset (&m_header
, 0, sizeof (m_header
));
23485 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23486 rcuh_kind::COMPILE
);
23495 dwarf2_per_cu_data::addr_size () const
23497 return this->get_header ()->addr_size
;
23503 dwarf2_per_cu_data::offset_size () const
23505 return this->get_header ()->offset_size
;
23511 dwarf2_per_cu_data::ref_addr_size () const
23513 const comp_unit_head
*header
= this->get_header ();
23515 if (header
->version
== 2)
23516 return header
->addr_size
;
23518 return header
->offset_size
;
23524 dwarf2_cu::addr_type () const
23526 struct objfile
*objfile
= this->per_objfile
->objfile
;
23527 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23528 struct type
*addr_type
= lookup_pointer_type (void_type
);
23529 int addr_size
= this->per_cu
->addr_size ();
23531 if (TYPE_LENGTH (addr_type
) == addr_size
)
23534 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23538 /* A helper function for dwarf2_find_containing_comp_unit that returns
23539 the index of the result, and that searches a vector. It will
23540 return a result even if the offset in question does not actually
23541 occur in any CU. This is separate so that it can be unit
23545 dwarf2_find_containing_comp_unit
23546 (sect_offset sect_off
,
23547 unsigned int offset_in_dwz
,
23548 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23553 high
= all_comp_units
.size () - 1;
23556 struct dwarf2_per_cu_data
*mid_cu
;
23557 int mid
= low
+ (high
- low
) / 2;
23559 mid_cu
= all_comp_units
[mid
];
23560 if (mid_cu
->is_dwz
> offset_in_dwz
23561 || (mid_cu
->is_dwz
== offset_in_dwz
23562 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23567 gdb_assert (low
== high
);
23571 /* Locate the .debug_info compilation unit from CU's objfile which contains
23572 the DIE at OFFSET. Raises an error on failure. */
23574 static struct dwarf2_per_cu_data
*
23575 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23576 unsigned int offset_in_dwz
,
23577 dwarf2_per_objfile
*per_objfile
)
23579 int low
= dwarf2_find_containing_comp_unit
23580 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
23581 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
23583 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23585 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23586 error (_("Dwarf Error: could not find partial DIE containing "
23587 "offset %s [in module %s]"),
23588 sect_offset_str (sect_off
),
23589 bfd_get_filename (per_objfile
->objfile
->obfd
));
23591 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23593 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
23597 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
23598 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23599 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23600 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23607 namespace selftests
{
23608 namespace find_containing_comp_unit
{
23613 struct dwarf2_per_cu_data one
{};
23614 struct dwarf2_per_cu_data two
{};
23615 struct dwarf2_per_cu_data three
{};
23616 struct dwarf2_per_cu_data four
{};
23619 two
.sect_off
= sect_offset (one
.length
);
23624 four
.sect_off
= sect_offset (three
.length
);
23628 std::vector
<dwarf2_per_cu_data
*> units
;
23629 units
.push_back (&one
);
23630 units
.push_back (&two
);
23631 units
.push_back (&three
);
23632 units
.push_back (&four
);
23636 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23637 SELF_CHECK (units
[result
] == &one
);
23638 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23639 SELF_CHECK (units
[result
] == &one
);
23640 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23641 SELF_CHECK (units
[result
] == &two
);
23643 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23644 SELF_CHECK (units
[result
] == &three
);
23645 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23646 SELF_CHECK (units
[result
] == &three
);
23647 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23648 SELF_CHECK (units
[result
] == &four
);
23654 #endif /* GDB_SELF_TEST */
23656 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23658 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23659 dwarf2_per_objfile
*per_objfile
)
23661 per_objfile (per_objfile
),
23663 has_loclist (false),
23664 checked_producer (false),
23665 producer_is_gxx_lt_4_6 (false),
23666 producer_is_gcc_lt_4_3 (false),
23667 producer_is_icc (false),
23668 producer_is_icc_lt_14 (false),
23669 producer_is_codewarrior (false),
23670 processing_has_namespace_info (false)
23674 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23677 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23678 enum language pretend_language
)
23680 struct attribute
*attr
;
23682 /* Set the language we're debugging. */
23683 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23684 if (attr
!= nullptr)
23685 set_cu_language (DW_UNSND (attr
), cu
);
23688 cu
->language
= pretend_language
;
23689 cu
->language_defn
= language_def (cu
->language
);
23692 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23698 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23700 auto it
= m_dwarf2_cus
.find (per_cu
);
23701 if (it
== m_dwarf2_cus
.end ())
23710 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
23712 gdb_assert (this->get_cu (per_cu
) == nullptr);
23714 m_dwarf2_cus
[per_cu
] = cu
;
23720 dwarf2_per_objfile::age_comp_units ()
23722 /* Start by clearing all marks. */
23723 for (auto pair
: m_dwarf2_cus
)
23724 pair
.second
->mark
= false;
23726 /* Traverse all CUs, mark them and their dependencies if used recently
23728 for (auto pair
: m_dwarf2_cus
)
23730 dwarf2_cu
*cu
= pair
.second
;
23733 if (cu
->last_used
<= dwarf_max_cache_age
)
23737 /* Delete all CUs still not marked. */
23738 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23740 dwarf2_cu
*cu
= it
->second
;
23745 it
= m_dwarf2_cus
.erase (it
);
23755 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23757 auto it
= m_dwarf2_cus
.find (per_cu
);
23758 if (it
== m_dwarf2_cus
.end ())
23763 m_dwarf2_cus
.erase (it
);
23766 dwarf2_per_objfile::~dwarf2_per_objfile ()
23771 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23772 We store these in a hash table separate from the DIEs, and preserve them
23773 when the DIEs are flushed out of cache.
23775 The CU "per_cu" pointer is needed because offset alone is not enough to
23776 uniquely identify the type. A file may have multiple .debug_types sections,
23777 or the type may come from a DWO file. Furthermore, while it's more logical
23778 to use per_cu->section+offset, with Fission the section with the data is in
23779 the DWO file but we don't know that section at the point we need it.
23780 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23781 because we can enter the lookup routine, get_die_type_at_offset, from
23782 outside this file, and thus won't necessarily have PER_CU->cu.
23783 Fortunately, PER_CU is stable for the life of the objfile. */
23785 struct dwarf2_per_cu_offset_and_type
23787 const struct dwarf2_per_cu_data
*per_cu
;
23788 sect_offset sect_off
;
23792 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23795 per_cu_offset_and_type_hash (const void *item
)
23797 const struct dwarf2_per_cu_offset_and_type
*ofs
23798 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23800 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23803 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23806 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23808 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23809 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23810 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23811 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23813 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23814 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23817 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23818 table if necessary. For convenience, return TYPE.
23820 The DIEs reading must have careful ordering to:
23821 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23822 reading current DIE.
23823 * Not trying to dereference contents of still incompletely read in types
23824 while reading in other DIEs.
23825 * Enable referencing still incompletely read in types just by a pointer to
23826 the type without accessing its fields.
23828 Therefore caller should follow these rules:
23829 * Try to fetch any prerequisite types we may need to build this DIE type
23830 before building the type and calling set_die_type.
23831 * After building type call set_die_type for current DIE as soon as
23832 possible before fetching more types to complete the current type.
23833 * Make the type as complete as possible before fetching more types. */
23835 static struct type
*
23836 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23838 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23839 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23840 struct objfile
*objfile
= per_objfile
->objfile
;
23841 struct attribute
*attr
;
23842 struct dynamic_prop prop
;
23844 /* For Ada types, make sure that the gnat-specific data is always
23845 initialized (if not already set). There are a few types where
23846 we should not be doing so, because the type-specific area is
23847 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23848 where the type-specific area is used to store the floatformat).
23849 But this is not a problem, because the gnat-specific information
23850 is actually not needed for these types. */
23851 if (need_gnat_info (cu
)
23852 && type
->code () != TYPE_CODE_FUNC
23853 && type
->code () != TYPE_CODE_FLT
23854 && type
->code () != TYPE_CODE_METHODPTR
23855 && type
->code () != TYPE_CODE_MEMBERPTR
23856 && type
->code () != TYPE_CODE_METHOD
23857 && !HAVE_GNAT_AUX_INFO (type
))
23858 INIT_GNAT_SPECIFIC (type
);
23860 /* Read DW_AT_allocated and set in type. */
23861 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23862 if (attr
!= NULL
&& attr
->form_is_block ())
23864 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23865 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23866 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23868 else if (attr
!= NULL
)
23870 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23871 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23872 sect_offset_str (die
->sect_off
));
23875 /* Read DW_AT_associated and set in type. */
23876 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23877 if (attr
!= NULL
&& attr
->form_is_block ())
23879 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23880 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23881 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23883 else if (attr
!= NULL
)
23885 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23886 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23887 sect_offset_str (die
->sect_off
));
23890 /* Read DW_AT_data_location and set in type. */
23891 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23892 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23893 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23895 if (per_objfile
->die_type_hash
== NULL
)
23896 per_objfile
->die_type_hash
23897 = htab_up (htab_create_alloc (127,
23898 per_cu_offset_and_type_hash
,
23899 per_cu_offset_and_type_eq
,
23900 NULL
, xcalloc
, xfree
));
23902 ofs
.per_cu
= cu
->per_cu
;
23903 ofs
.sect_off
= die
->sect_off
;
23905 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23906 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23908 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23909 sect_offset_str (die
->sect_off
));
23910 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23911 struct dwarf2_per_cu_offset_and_type
);
23916 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23917 or return NULL if the die does not have a saved type. */
23919 static struct type
*
23920 get_die_type_at_offset (sect_offset sect_off
,
23921 dwarf2_per_cu_data
*per_cu
,
23922 dwarf2_per_objfile
*per_objfile
)
23924 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23926 if (per_objfile
->die_type_hash
== NULL
)
23929 ofs
.per_cu
= per_cu
;
23930 ofs
.sect_off
= sect_off
;
23931 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23932 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
23939 /* Look up the type for DIE in CU in die_type_hash,
23940 or return NULL if DIE does not have a saved type. */
23942 static struct type
*
23943 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23945 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23948 /* Add a dependence relationship from CU to REF_PER_CU. */
23951 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23952 struct dwarf2_per_cu_data
*ref_per_cu
)
23956 if (cu
->dependencies
== NULL
)
23958 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23959 NULL
, &cu
->comp_unit_obstack
,
23960 hashtab_obstack_allocate
,
23961 dummy_obstack_deallocate
);
23963 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23965 *slot
= ref_per_cu
;
23968 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23969 Set the mark field in every compilation unit in the
23970 cache that we must keep because we are keeping CU.
23972 DATA is the dwarf2_per_objfile object in which to look up CUs. */
23975 dwarf2_mark_helper (void **slot
, void *data
)
23977 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
23978 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
23979 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23981 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23982 reading of the chain. As such dependencies remain valid it is not much
23983 useful to track and undo them during QUIT cleanups. */
23992 if (cu
->dependencies
!= nullptr)
23993 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
23998 /* Set the mark field in CU and in every other compilation unit in the
23999 cache that we must keep because we are keeping CU. */
24002 dwarf2_mark (struct dwarf2_cu
*cu
)
24009 if (cu
->dependencies
!= nullptr)
24010 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
24013 /* Trivial hash function for partial_die_info: the hash value of a DIE
24014 is its offset in .debug_info for this objfile. */
24017 partial_die_hash (const void *item
)
24019 const struct partial_die_info
*part_die
24020 = (const struct partial_die_info
*) item
;
24022 return to_underlying (part_die
->sect_off
);
24025 /* Trivial comparison function for partial_die_info structures: two DIEs
24026 are equal if they have the same offset. */
24029 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24031 const struct partial_die_info
*part_die_lhs
24032 = (const struct partial_die_info
*) item_lhs
;
24033 const struct partial_die_info
*part_die_rhs
24034 = (const struct partial_die_info
*) item_rhs
;
24036 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24039 struct cmd_list_element
*set_dwarf_cmdlist
;
24040 struct cmd_list_element
*show_dwarf_cmdlist
;
24043 show_check_physname (struct ui_file
*file
, int from_tty
,
24044 struct cmd_list_element
*c
, const char *value
)
24046 fprintf_filtered (file
,
24047 _("Whether to check \"physname\" is %s.\n"),
24051 void _initialize_dwarf2_read ();
24053 _initialize_dwarf2_read ()
24055 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24056 Set DWARF specific variables.\n\
24057 Configure DWARF variables such as the cache size."),
24058 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24059 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24061 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24062 Show DWARF specific variables.\n\
24063 Show DWARF variables such as the cache size."),
24064 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24065 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24067 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24068 &dwarf_max_cache_age
, _("\
24069 Set the upper bound on the age of cached DWARF compilation units."), _("\
24070 Show the upper bound on the age of cached DWARF compilation units."), _("\
24071 A higher limit means that cached compilation units will be stored\n\
24072 in memory longer, and more total memory will be used. Zero disables\n\
24073 caching, which can slow down startup."),
24075 show_dwarf_max_cache_age
,
24076 &set_dwarf_cmdlist
,
24077 &show_dwarf_cmdlist
);
24079 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24080 Set debugging of the DWARF reader."), _("\
24081 Show debugging of the DWARF reader."), _("\
24082 When enabled (non-zero), debugging messages are printed during DWARF\n\
24083 reading and symtab expansion. A value of 1 (one) provides basic\n\
24084 information. A value greater than 1 provides more verbose information."),
24087 &setdebuglist
, &showdebuglist
);
24089 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24090 Set debugging of the DWARF DIE reader."), _("\
24091 Show debugging of the DWARF DIE reader."), _("\
24092 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24093 The value is the maximum depth to print."),
24096 &setdebuglist
, &showdebuglist
);
24098 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24099 Set debugging of the dwarf line reader."), _("\
24100 Show debugging of the dwarf line reader."), _("\
24101 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24102 A value of 1 (one) provides basic information.\n\
24103 A value greater than 1 provides more verbose information."),
24106 &setdebuglist
, &showdebuglist
);
24108 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24109 Set cross-checking of \"physname\" code against demangler."), _("\
24110 Show cross-checking of \"physname\" code against demangler."), _("\
24111 When enabled, GDB's internal \"physname\" code is checked against\n\
24113 NULL
, show_check_physname
,
24114 &setdebuglist
, &showdebuglist
);
24116 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24117 no_class
, &use_deprecated_index_sections
, _("\
24118 Set whether to use deprecated gdb_index sections."), _("\
24119 Show whether to use deprecated gdb_index sections."), _("\
24120 When enabled, deprecated .gdb_index sections are used anyway.\n\
24121 Normally they are ignored either because of a missing feature or\n\
24122 performance issue.\n\
24123 Warning: This option must be enabled before gdb reads the file."),
24126 &setlist
, &showlist
);
24128 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24129 &dwarf2_locexpr_funcs
);
24130 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24131 &dwarf2_loclist_funcs
);
24133 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24134 &dwarf2_block_frame_base_locexpr_funcs
);
24135 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24136 &dwarf2_block_frame_base_loclist_funcs
);
24139 selftests::register_test ("dw2_expand_symtabs_matching",
24140 selftests::dw2_expand_symtabs_matching::run_test
);
24141 selftests::register_test ("dwarf2_find_containing_comp_unit",
24142 selftests::find_containing_comp_unit::run_test
);