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 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
110 /* The "aclass" indices for various kinds of computed DWARF symbols. */
112 static int dwarf2_locexpr_index
;
113 static int dwarf2_loclist_index
;
114 static int dwarf2_locexpr_block_index
;
115 static int dwarf2_loclist_block_index
;
117 /* Size of .debug_loclists section header for 32-bit DWARF format. */
118 #define LOCLIST_HEADER_SIZE32 12
120 /* Size of .debug_loclists section header for 64-bit DWARF format. */
121 #define LOCLIST_HEADER_SIZE64 20
123 /* An index into a (C++) symbol name component in a symbol name as
124 recorded in the mapped_index's symbol table. For each C++ symbol
125 in the symbol table, we record one entry for the start of each
126 component in the symbol in a table of name components, and then
127 sort the table, in order to be able to binary search symbol names,
128 ignoring leading namespaces, both completion and regular look up.
129 For example, for symbol "A::B::C", we'll have an entry that points
130 to "A::B::C", another that points to "B::C", and another for "C".
131 Note that function symbols in GDB index have no parameter
132 information, just the function/method names. You can convert a
133 name_component to a "const char *" using the
134 'mapped_index::symbol_name_at(offset_type)' method. */
136 struct name_component
138 /* Offset in the symbol name where the component starts. Stored as
139 a (32-bit) offset instead of a pointer to save memory and improve
140 locality on 64-bit architectures. */
141 offset_type name_offset
;
143 /* The symbol's index in the symbol and constant pool tables of a
148 /* Base class containing bits shared by both .gdb_index and
149 .debug_name indexes. */
151 struct mapped_index_base
153 mapped_index_base () = default;
154 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
156 /* The name_component table (a sorted vector). See name_component's
157 description above. */
158 std::vector
<name_component
> name_components
;
160 /* How NAME_COMPONENTS is sorted. */
161 enum case_sensitivity name_components_casing
;
163 /* Return the number of names in the symbol table. */
164 virtual size_t symbol_name_count () const = 0;
166 /* Get the name of the symbol at IDX in the symbol table. */
167 virtual const char *symbol_name_at (offset_type idx
) const = 0;
169 /* Return whether the name at IDX in the symbol table should be
171 virtual bool symbol_name_slot_invalid (offset_type idx
) const
176 /* Build the symbol name component sorted vector, if we haven't
178 void build_name_components ();
180 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
181 possible matches for LN_NO_PARAMS in the name component
183 std::pair
<std::vector
<name_component
>::const_iterator
,
184 std::vector
<name_component
>::const_iterator
>
185 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
186 enum language lang
) const;
188 /* Prevent deleting/destroying via a base class pointer. */
190 ~mapped_index_base() = default;
193 /* A description of the mapped index. The file format is described in
194 a comment by the code that writes the index. */
195 struct mapped_index final
: public mapped_index_base
197 /* A slot/bucket in the symbol table hash. */
198 struct symbol_table_slot
200 const offset_type name
;
201 const offset_type vec
;
204 /* Index data format version. */
207 /* The address table data. */
208 gdb::array_view
<const gdb_byte
> address_table
;
210 /* The symbol table, implemented as a hash table. */
211 gdb::array_view
<symbol_table_slot
> symbol_table
;
213 /* A pointer to the constant pool. */
214 const char *constant_pool
= nullptr;
216 bool symbol_name_slot_invalid (offset_type idx
) const override
218 const auto &bucket
= this->symbol_table
[idx
];
219 return bucket
.name
== 0 && bucket
.vec
== 0;
222 /* Convenience method to get at the name of the symbol at IDX in the
224 const char *symbol_name_at (offset_type idx
) const override
225 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
227 size_t symbol_name_count () const override
228 { return this->symbol_table
.size (); }
231 /* A description of the mapped .debug_names.
232 Uninitialized map has CU_COUNT 0. */
233 struct mapped_debug_names final
: public mapped_index_base
235 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
236 : dwarf2_per_objfile (dwarf2_per_objfile_
)
239 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
240 bfd_endian dwarf5_byte_order
;
241 bool dwarf5_is_dwarf64
;
242 bool augmentation_is_gdb
;
244 uint32_t cu_count
= 0;
245 uint32_t tu_count
, bucket_count
, name_count
;
246 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
247 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
248 const gdb_byte
*name_table_string_offs_reordered
;
249 const gdb_byte
*name_table_entry_offs_reordered
;
250 const gdb_byte
*entry_pool
;
257 /* Attribute name DW_IDX_*. */
260 /* Attribute form DW_FORM_*. */
263 /* Value if FORM is DW_FORM_implicit_const. */
264 LONGEST implicit_const
;
266 std::vector
<attr
> attr_vec
;
269 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
271 const char *namei_to_name (uint32_t namei
) const;
273 /* Implementation of the mapped_index_base virtual interface, for
274 the name_components cache. */
276 const char *symbol_name_at (offset_type idx
) const override
277 { return namei_to_name (idx
); }
279 size_t symbol_name_count () const override
280 { return this->name_count
; }
283 /* See dwarf2read.h. */
286 get_dwarf2_per_objfile (struct objfile
*objfile
)
288 return dwarf2_objfile_data_key
.get (objfile
);
291 /* Default names of the debugging sections. */
293 /* Note that if the debugging section has been compressed, it might
294 have a name like .zdebug_info. */
296 static const struct dwarf2_debug_sections dwarf2_elf_names
=
298 { ".debug_info", ".zdebug_info" },
299 { ".debug_abbrev", ".zdebug_abbrev" },
300 { ".debug_line", ".zdebug_line" },
301 { ".debug_loc", ".zdebug_loc" },
302 { ".debug_loclists", ".zdebug_loclists" },
303 { ".debug_macinfo", ".zdebug_macinfo" },
304 { ".debug_macro", ".zdebug_macro" },
305 { ".debug_str", ".zdebug_str" },
306 { ".debug_str_offsets", ".zdebug_str_offsets" },
307 { ".debug_line_str", ".zdebug_line_str" },
308 { ".debug_ranges", ".zdebug_ranges" },
309 { ".debug_rnglists", ".zdebug_rnglists" },
310 { ".debug_types", ".zdebug_types" },
311 { ".debug_addr", ".zdebug_addr" },
312 { ".debug_frame", ".zdebug_frame" },
313 { ".eh_frame", NULL
},
314 { ".gdb_index", ".zgdb_index" },
315 { ".debug_names", ".zdebug_names" },
316 { ".debug_aranges", ".zdebug_aranges" },
320 /* List of DWO/DWP sections. */
322 static const struct dwop_section_names
324 struct dwarf2_section_names abbrev_dwo
;
325 struct dwarf2_section_names info_dwo
;
326 struct dwarf2_section_names line_dwo
;
327 struct dwarf2_section_names loc_dwo
;
328 struct dwarf2_section_names loclists_dwo
;
329 struct dwarf2_section_names macinfo_dwo
;
330 struct dwarf2_section_names macro_dwo
;
331 struct dwarf2_section_names str_dwo
;
332 struct dwarf2_section_names str_offsets_dwo
;
333 struct dwarf2_section_names types_dwo
;
334 struct dwarf2_section_names cu_index
;
335 struct dwarf2_section_names tu_index
;
339 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
340 { ".debug_info.dwo", ".zdebug_info.dwo" },
341 { ".debug_line.dwo", ".zdebug_line.dwo" },
342 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
343 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
344 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
345 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
346 { ".debug_str.dwo", ".zdebug_str.dwo" },
347 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
348 { ".debug_types.dwo", ".zdebug_types.dwo" },
349 { ".debug_cu_index", ".zdebug_cu_index" },
350 { ".debug_tu_index", ".zdebug_tu_index" },
353 /* local data types */
355 /* The location list section (.debug_loclists) begins with a header,
356 which contains the following information. */
357 struct loclist_header
359 /* A 4-byte or 12-byte length containing the length of the
360 set of entries for this compilation unit, not including the
361 length field itself. */
364 /* A 2-byte version identifier. */
367 /* A 1-byte unsigned integer containing the size in bytes of an address on
368 the target system. */
369 unsigned char addr_size
;
371 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
372 on the target system. */
373 unsigned char segment_collector_size
;
375 /* A 4-byte count of the number of offsets that follow the header. */
376 unsigned int offset_entry_count
;
379 /* Type used for delaying computation of method physnames.
380 See comments for compute_delayed_physnames. */
381 struct delayed_method_info
383 /* The type to which the method is attached, i.e., its parent class. */
386 /* The index of the method in the type's function fieldlists. */
389 /* The index of the method in the fieldlist. */
392 /* The name of the DIE. */
395 /* The DIE associated with this method. */
396 struct die_info
*die
;
399 /* Internal state when decoding a particular compilation unit. */
402 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
403 dwarf2_per_objfile
*per_objfile
);
406 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
408 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
409 Create the set of symtabs used by this TU, or if this TU is sharing
410 symtabs with another TU and the symtabs have already been created
411 then restore those symtabs in the line header.
412 We don't need the pc/line-number mapping for type units. */
413 void setup_type_unit_groups (struct die_info
*die
);
415 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
416 buildsym_compunit constructor. */
417 struct compunit_symtab
*start_symtab (const char *name
,
418 const char *comp_dir
,
421 /* Reset the builder. */
422 void reset_builder () { m_builder
.reset (); }
424 /* Return a type that is a generic pointer type, the size of which
425 matches the address size given in the compilation unit header for
427 struct type
*addr_type () const;
429 /* Find an integer type the same size as the address size given in
430 the compilation unit header for this CU. UNSIGNED_P controls if
431 the integer is unsigned or not. */
432 struct type
*addr_sized_int_type (bool unsigned_p
) const;
434 /* The header of the compilation unit. */
435 struct comp_unit_head header
{};
437 /* Base address of this compilation unit. */
438 gdb::optional
<CORE_ADDR
> base_address
;
440 /* The language we are debugging. */
441 enum language language
= language_unknown
;
442 const struct language_defn
*language_defn
= nullptr;
444 const char *producer
= nullptr;
447 /* The symtab builder for this CU. This is only non-NULL when full
448 symbols are being read. */
449 std::unique_ptr
<buildsym_compunit
> m_builder
;
452 /* The generic symbol table building routines have separate lists for
453 file scope symbols and all all other scopes (local scopes). So
454 we need to select the right one to pass to add_symbol_to_list().
455 We do it by keeping a pointer to the correct list in list_in_scope.
457 FIXME: The original dwarf code just treated the file scope as the
458 first local scope, and all other local scopes as nested local
459 scopes, and worked fine. Check to see if we really need to
460 distinguish these in buildsym.c. */
461 struct pending
**list_in_scope
= nullptr;
463 /* Hash table holding all the loaded partial DIEs
464 with partial_die->offset.SECT_OFF as hash. */
465 htab_t partial_dies
= nullptr;
467 /* Storage for things with the same lifetime as this read-in compilation
468 unit, including partial DIEs. */
469 auto_obstack comp_unit_obstack
;
471 /* When multiple dwarf2_cu structures are living in memory, this field
472 chains them all together, so that they can be released efficiently.
473 We will probably also want a generation counter so that most-recently-used
474 compilation units are cached... */
475 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
477 /* Backlink to our per_cu entry. */
478 struct dwarf2_per_cu_data
*per_cu
;
480 /* The dwarf2_per_objfile that owns this. */
481 struct dwarf2_per_objfile
*per_objfile
;
483 /* How many compilation units ago was this CU last referenced? */
486 /* A hash table of DIE cu_offset for following references with
487 die_info->offset.sect_off as hash. */
488 htab_t die_hash
= nullptr;
490 /* Full DIEs if read in. */
491 struct die_info
*dies
= nullptr;
493 /* A set of pointers to dwarf2_per_cu_data objects for compilation
494 units referenced by this one. Only set during full symbol processing;
495 partial symbol tables do not have dependencies. */
496 htab_t dependencies
= nullptr;
498 /* Header data from the line table, during full symbol processing. */
499 struct line_header
*line_header
= nullptr;
500 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
501 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
502 this is the DW_TAG_compile_unit die for this CU. We'll hold on
503 to the line header as long as this DIE is being processed. See
504 process_die_scope. */
505 die_info
*line_header_die_owner
= nullptr;
507 /* A list of methods which need to have physnames computed
508 after all type information has been read. */
509 std::vector
<delayed_method_info
> method_list
;
511 /* To be copied to symtab->call_site_htab. */
512 htab_t call_site_htab
= nullptr;
514 /* Non-NULL if this CU came from a DWO file.
515 There is an invariant here that is important to remember:
516 Except for attributes copied from the top level DIE in the "main"
517 (or "stub") file in preparation for reading the DWO file
518 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
519 Either there isn't a DWO file (in which case this is NULL and the point
520 is moot), or there is and either we're not going to read it (in which
521 case this is NULL) or there is and we are reading it (in which case this
523 struct dwo_unit
*dwo_unit
= nullptr;
525 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
526 Note this value comes from the Fission stub CU/TU's DIE. */
527 gdb::optional
<ULONGEST
> addr_base
;
529 /* The DW_AT_rnglists_base attribute if present.
530 Note this value comes from the Fission stub CU/TU's DIE.
531 Also note that the value is zero in the non-DWO case so this value can
532 be used without needing to know whether DWO files are in use or not.
533 N.B. This does not apply to DW_AT_ranges appearing in
534 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
535 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
536 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
537 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
538 ULONGEST ranges_base
= 0;
540 /* The DW_AT_loclists_base attribute if present. */
541 ULONGEST loclist_base
= 0;
543 /* When reading debug info generated by older versions of rustc, we
544 have to rewrite some union types to be struct types with a
545 variant part. This rewriting must be done after the CU is fully
546 read in, because otherwise at the point of rewriting some struct
547 type might not have been fully processed. So, we keep a list of
548 all such types here and process them after expansion. */
549 std::vector
<struct type
*> rust_unions
;
551 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
552 files, the value is implicitly zero. For DWARF 5 version DWO files, the
553 value is often implicit and is the size of the header of
554 .debug_str_offsets section (8 or 4, depending on the address size). */
555 gdb::optional
<ULONGEST
> str_offsets_base
;
557 /* Mark used when releasing cached dies. */
560 /* This CU references .debug_loc. See the symtab->locations_valid field.
561 This test is imperfect as there may exist optimized debug code not using
562 any location list and still facing inlining issues if handled as
563 unoptimized code. For a future better test see GCC PR other/32998. */
564 bool has_loclist
: 1;
566 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
567 if all the producer_is_* fields are valid. This information is cached
568 because profiling CU expansion showed excessive time spent in
569 producer_is_gxx_lt_4_6. */
570 bool checked_producer
: 1;
571 bool producer_is_gxx_lt_4_6
: 1;
572 bool producer_is_gcc_lt_4_3
: 1;
573 bool producer_is_icc
: 1;
574 bool producer_is_icc_lt_14
: 1;
575 bool producer_is_codewarrior
: 1;
577 /* When true, the file that we're processing is known to have
578 debugging info for C++ namespaces. GCC 3.3.x did not produce
579 this information, but later versions do. */
581 bool processing_has_namespace_info
: 1;
583 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
585 /* If this CU was inherited by another CU (via specification,
586 abstract_origin, etc), this is the ancestor CU. */
589 /* Get the buildsym_compunit for this CU. */
590 buildsym_compunit
*get_builder ()
592 /* If this CU has a builder associated with it, use that. */
593 if (m_builder
!= nullptr)
594 return m_builder
.get ();
596 /* Otherwise, search ancestors for a valid builder. */
597 if (ancestor
!= nullptr)
598 return ancestor
->get_builder ();
604 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
605 This includes type_unit_group and quick_file_names. */
607 struct stmt_list_hash
609 /* The DWO unit this table is from or NULL if there is none. */
610 struct dwo_unit
*dwo_unit
;
612 /* Offset in .debug_line or .debug_line.dwo. */
613 sect_offset line_sect_off
;
616 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
617 an object of this type. */
619 struct type_unit_group
621 /* dwarf2read.c's main "handle" on a TU symtab.
622 To simplify things we create an artificial CU that "includes" all the
623 type units using this stmt_list so that the rest of the code still has
624 a "per_cu" handle on the symtab. */
625 struct dwarf2_per_cu_data per_cu
;
627 /* The TUs that share this DW_AT_stmt_list entry.
628 This is added to while parsing type units to build partial symtabs,
629 and is deleted afterwards and not used again. */
630 std::vector
<signatured_type
*> *tus
;
632 /* The compunit symtab.
633 Type units in a group needn't all be defined in the same source file,
634 so we create an essentially anonymous symtab as the compunit symtab. */
635 struct compunit_symtab
*compunit_symtab
;
637 /* The data used to construct the hash key. */
638 struct stmt_list_hash hash
;
640 /* The symbol tables for this TU (obtained from the files listed in
642 WARNING: The order of entries here must match the order of entries
643 in the line header. After the first TU using this type_unit_group, the
644 line header for the subsequent TUs is recreated from this. This is done
645 because we need to use the same symtabs for each TU using the same
646 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
647 there's no guarantee the line header doesn't have duplicate entries. */
648 struct symtab
**symtabs
;
651 /* These sections are what may appear in a (real or virtual) DWO file. */
655 struct dwarf2_section_info abbrev
;
656 struct dwarf2_section_info line
;
657 struct dwarf2_section_info loc
;
658 struct dwarf2_section_info loclists
;
659 struct dwarf2_section_info macinfo
;
660 struct dwarf2_section_info macro
;
661 struct dwarf2_section_info str
;
662 struct dwarf2_section_info str_offsets
;
663 /* In the case of a virtual DWO file, these two are unused. */
664 struct dwarf2_section_info info
;
665 std::vector
<dwarf2_section_info
> types
;
668 /* CUs/TUs in DWP/DWO files. */
672 /* Backlink to the containing struct dwo_file. */
673 struct dwo_file
*dwo_file
;
675 /* The "id" that distinguishes this CU/TU.
676 .debug_info calls this "dwo_id", .debug_types calls this "signature".
677 Since signatures came first, we stick with it for consistency. */
680 /* The section this CU/TU lives in, in the DWO file. */
681 struct dwarf2_section_info
*section
;
683 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
684 sect_offset sect_off
;
687 /* For types, offset in the type's DIE of the type defined by this TU. */
688 cu_offset type_offset_in_tu
;
691 /* include/dwarf2.h defines the DWP section codes.
692 It defines a max value but it doesn't define a min value, which we
693 use for error checking, so provide one. */
695 enum dwp_v2_section_ids
700 /* Data for one DWO file.
702 This includes virtual DWO files (a virtual DWO file is a DWO file as it
703 appears in a DWP file). DWP files don't really have DWO files per se -
704 comdat folding of types "loses" the DWO file they came from, and from
705 a high level view DWP files appear to contain a mass of random types.
706 However, to maintain consistency with the non-DWP case we pretend DWP
707 files contain virtual DWO files, and we assign each TU with one virtual
708 DWO file (generally based on the line and abbrev section offsets -
709 a heuristic that seems to work in practice). */
713 dwo_file () = default;
714 DISABLE_COPY_AND_ASSIGN (dwo_file
);
716 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
717 For virtual DWO files the name is constructed from the section offsets
718 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
719 from related CU+TUs. */
720 const char *dwo_name
= nullptr;
722 /* The DW_AT_comp_dir attribute. */
723 const char *comp_dir
= nullptr;
725 /* The bfd, when the file is open. Otherwise this is NULL.
726 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
727 gdb_bfd_ref_ptr dbfd
;
729 /* The sections that make up this DWO file.
730 Remember that for virtual DWO files in DWP V2, these are virtual
731 sections (for lack of a better name). */
732 struct dwo_sections sections
{};
734 /* The CUs in the file.
735 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
736 an extension to handle LLVM's Link Time Optimization output (where
737 multiple source files may be compiled into a single object/dwo pair). */
740 /* Table of TUs in the file.
741 Each element is a struct dwo_unit. */
745 /* These sections are what may appear in a DWP file. */
749 /* These are used by both DWP version 1 and 2. */
750 struct dwarf2_section_info str
;
751 struct dwarf2_section_info cu_index
;
752 struct dwarf2_section_info tu_index
;
754 /* These are only used by DWP version 2 files.
755 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
756 sections are referenced by section number, and are not recorded here.
757 In DWP version 2 there is at most one copy of all these sections, each
758 section being (effectively) comprised of the concatenation of all of the
759 individual sections that exist in the version 1 format.
760 To keep the code simple we treat each of these concatenated pieces as a
761 section itself (a virtual section?). */
762 struct dwarf2_section_info abbrev
;
763 struct dwarf2_section_info info
;
764 struct dwarf2_section_info line
;
765 struct dwarf2_section_info loc
;
766 struct dwarf2_section_info macinfo
;
767 struct dwarf2_section_info macro
;
768 struct dwarf2_section_info str_offsets
;
769 struct dwarf2_section_info types
;
772 /* These sections are what may appear in a virtual DWO file in DWP version 1.
773 A virtual DWO file is a DWO file as it appears in a DWP file. */
775 struct virtual_v1_dwo_sections
777 struct dwarf2_section_info abbrev
;
778 struct dwarf2_section_info line
;
779 struct dwarf2_section_info loc
;
780 struct dwarf2_section_info macinfo
;
781 struct dwarf2_section_info macro
;
782 struct dwarf2_section_info str_offsets
;
783 /* Each DWP hash table entry records one CU or one TU.
784 That is recorded here, and copied to dwo_unit.section. */
785 struct dwarf2_section_info info_or_types
;
788 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
789 In version 2, the sections of the DWO files are concatenated together
790 and stored in one section of that name. Thus each ELF section contains
791 several "virtual" sections. */
793 struct virtual_v2_dwo_sections
795 bfd_size_type abbrev_offset
;
796 bfd_size_type abbrev_size
;
798 bfd_size_type line_offset
;
799 bfd_size_type line_size
;
801 bfd_size_type loc_offset
;
802 bfd_size_type loc_size
;
804 bfd_size_type macinfo_offset
;
805 bfd_size_type macinfo_size
;
807 bfd_size_type macro_offset
;
808 bfd_size_type macro_size
;
810 bfd_size_type str_offsets_offset
;
811 bfd_size_type str_offsets_size
;
813 /* Each DWP hash table entry records one CU or one TU.
814 That is recorded here, and copied to dwo_unit.section. */
815 bfd_size_type info_or_types_offset
;
816 bfd_size_type info_or_types_size
;
819 /* Contents of DWP hash tables. */
821 struct dwp_hash_table
823 uint32_t version
, nr_columns
;
824 uint32_t nr_units
, nr_slots
;
825 const gdb_byte
*hash_table
, *unit_table
;
830 const gdb_byte
*indices
;
834 /* This is indexed by column number and gives the id of the section
836 #define MAX_NR_V2_DWO_SECTIONS \
837 (1 /* .debug_info or .debug_types */ \
838 + 1 /* .debug_abbrev */ \
839 + 1 /* .debug_line */ \
840 + 1 /* .debug_loc */ \
841 + 1 /* .debug_str_offsets */ \
842 + 1 /* .debug_macro or .debug_macinfo */)
843 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
844 const gdb_byte
*offsets
;
845 const gdb_byte
*sizes
;
850 /* Data for one DWP file. */
854 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
856 dbfd (std::move (abfd
))
860 /* Name of the file. */
863 /* File format version. */
867 gdb_bfd_ref_ptr dbfd
;
869 /* Section info for this file. */
870 struct dwp_sections sections
{};
872 /* Table of CUs in the file. */
873 const struct dwp_hash_table
*cus
= nullptr;
875 /* Table of TUs in the file. */
876 const struct dwp_hash_table
*tus
= nullptr;
878 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
882 /* Table to map ELF section numbers to their sections.
883 This is only needed for the DWP V1 file format. */
884 unsigned int num_sections
= 0;
885 asection
**elf_sections
= nullptr;
888 /* Struct used to pass misc. parameters to read_die_and_children, et
889 al. which are used for both .debug_info and .debug_types dies.
890 All parameters here are unchanging for the life of the call. This
891 struct exists to abstract away the constant parameters of die reading. */
893 struct die_reader_specs
895 /* The bfd of die_section. */
898 /* The CU of the DIE we are parsing. */
899 struct dwarf2_cu
*cu
;
901 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
902 struct dwo_file
*dwo_file
;
904 /* The section the die comes from.
905 This is either .debug_info or .debug_types, or the .dwo variants. */
906 struct dwarf2_section_info
*die_section
;
908 /* die_section->buffer. */
909 const gdb_byte
*buffer
;
911 /* The end of the buffer. */
912 const gdb_byte
*buffer_end
;
914 /* The abbreviation table to use when reading the DIEs. */
915 struct abbrev_table
*abbrev_table
;
918 /* A subclass of die_reader_specs that holds storage and has complex
919 constructor and destructor behavior. */
921 class cutu_reader
: public die_reader_specs
925 cutu_reader (dwarf2_per_cu_data
*this_cu
,
926 dwarf2_per_objfile
*per_objfile
,
927 struct abbrev_table
*abbrev_table
,
931 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
932 dwarf2_per_objfile
*per_objfile
,
933 struct dwarf2_cu
*parent_cu
= nullptr,
934 struct dwo_file
*dwo_file
= nullptr);
936 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
938 const gdb_byte
*info_ptr
= nullptr;
939 struct die_info
*comp_unit_die
= nullptr;
940 bool dummy_p
= false;
942 /* Release the new CU, putting it on the chain. This cannot be done
947 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
948 dwarf2_per_objfile
*per_objfile
,
949 int use_existing_cu
);
951 struct dwarf2_per_cu_data
*m_this_cu
;
952 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
954 /* The ordinary abbreviation table. */
955 abbrev_table_up m_abbrev_table_holder
;
957 /* The DWO abbreviation table. */
958 abbrev_table_up m_dwo_abbrev_table
;
961 /* When we construct a partial symbol table entry we only
962 need this much information. */
963 struct partial_die_info
: public allocate_on_obstack
965 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
967 /* Disable assign but still keep copy ctor, which is needed
968 load_partial_dies. */
969 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
971 /* Adjust the partial die before generating a symbol for it. This
972 function may set the is_external flag or change the DIE's
974 void fixup (struct dwarf2_cu
*cu
);
976 /* Read a minimal amount of information into the minimal die
978 const gdb_byte
*read (const struct die_reader_specs
*reader
,
979 const struct abbrev_info
&abbrev
,
980 const gdb_byte
*info_ptr
);
982 /* Offset of this DIE. */
983 const sect_offset sect_off
;
985 /* DWARF-2 tag for this DIE. */
986 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
988 /* Assorted flags describing the data found in this DIE. */
989 const unsigned int has_children
: 1;
991 unsigned int is_external
: 1;
992 unsigned int is_declaration
: 1;
993 unsigned int has_type
: 1;
994 unsigned int has_specification
: 1;
995 unsigned int has_pc_info
: 1;
996 unsigned int may_be_inlined
: 1;
998 /* This DIE has been marked DW_AT_main_subprogram. */
999 unsigned int main_subprogram
: 1;
1001 /* Flag set if the SCOPE field of this structure has been
1003 unsigned int scope_set
: 1;
1005 /* Flag set if the DIE has a byte_size attribute. */
1006 unsigned int has_byte_size
: 1;
1008 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1009 unsigned int has_const_value
: 1;
1011 /* Flag set if any of the DIE's children are template arguments. */
1012 unsigned int has_template_arguments
: 1;
1014 /* Flag set if fixup has been called on this die. */
1015 unsigned int fixup_called
: 1;
1017 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1018 unsigned int is_dwz
: 1;
1020 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1021 unsigned int spec_is_dwz
: 1;
1023 /* The name of this DIE. Normally the value of DW_AT_name, but
1024 sometimes a default name for unnamed DIEs. */
1025 const char *name
= nullptr;
1027 /* The linkage name, if present. */
1028 const char *linkage_name
= nullptr;
1030 /* The scope to prepend to our children. This is generally
1031 allocated on the comp_unit_obstack, so will disappear
1032 when this compilation unit leaves the cache. */
1033 const char *scope
= nullptr;
1035 /* Some data associated with the partial DIE. The tag determines
1036 which field is live. */
1039 /* The location description associated with this DIE, if any. */
1040 struct dwarf_block
*locdesc
;
1041 /* The offset of an import, for DW_TAG_imported_unit. */
1042 sect_offset sect_off
;
1045 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1046 CORE_ADDR lowpc
= 0;
1047 CORE_ADDR highpc
= 0;
1049 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1050 DW_AT_sibling, if any. */
1051 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1052 could return DW_AT_sibling values to its caller load_partial_dies. */
1053 const gdb_byte
*sibling
= nullptr;
1055 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1056 DW_AT_specification (or DW_AT_abstract_origin or
1057 DW_AT_extension). */
1058 sect_offset spec_offset
{};
1060 /* Pointers to this DIE's parent, first child, and next sibling,
1062 struct partial_die_info
*die_parent
= nullptr;
1063 struct partial_die_info
*die_child
= nullptr;
1064 struct partial_die_info
*die_sibling
= nullptr;
1066 friend struct partial_die_info
*
1067 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1070 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1071 partial_die_info (sect_offset sect_off
)
1072 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1076 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1078 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1083 has_specification
= 0;
1086 main_subprogram
= 0;
1089 has_const_value
= 0;
1090 has_template_arguments
= 0;
1097 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1098 but this would require a corresponding change in unpack_field_as_long
1100 static int bits_per_byte
= 8;
1102 struct variant_part_builder
;
1104 /* When reading a variant, we track a bit more information about the
1105 field, and store it in an object of this type. */
1107 struct variant_field
1109 int first_field
= -1;
1110 int last_field
= -1;
1112 /* A variant can contain other variant parts. */
1113 std::vector
<variant_part_builder
> variant_parts
;
1115 /* If we see a DW_TAG_variant, then this will be set if this is the
1117 bool default_branch
= false;
1118 /* If we see a DW_AT_discr_value, then this will be the discriminant
1120 ULONGEST discriminant_value
= 0;
1121 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1123 struct dwarf_block
*discr_list_data
= nullptr;
1126 /* This represents a DW_TAG_variant_part. */
1128 struct variant_part_builder
1130 /* The offset of the discriminant field. */
1131 sect_offset discriminant_offset
{};
1133 /* Variants that are direct children of this variant part. */
1134 std::vector
<variant_field
> variants
;
1136 /* True if we're currently reading a variant. */
1137 bool processing_variant
= false;
1142 int accessibility
= 0;
1144 /* Variant parts need to find the discriminant, which is a DIE
1145 reference. We track the section offset of each field to make
1148 struct field field
{};
1153 const char *name
= nullptr;
1154 std::vector
<struct fn_field
> fnfields
;
1157 /* The routines that read and process dies for a C struct or C++ class
1158 pass lists of data member fields and lists of member function fields
1159 in an instance of a field_info structure, as defined below. */
1162 /* List of data member and baseclasses fields. */
1163 std::vector
<struct nextfield
> fields
;
1164 std::vector
<struct nextfield
> baseclasses
;
1166 /* Set if the accessibility of one of the fields is not public. */
1167 int non_public_fields
= 0;
1169 /* Member function fieldlist array, contains name of possibly overloaded
1170 member function, number of overloaded member functions and a pointer
1171 to the head of the member function field chain. */
1172 std::vector
<struct fnfieldlist
> fnfieldlists
;
1174 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1175 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1176 std::vector
<struct decl_field
> typedef_field_list
;
1178 /* Nested types defined by this class and the number of elements in this
1180 std::vector
<struct decl_field
> nested_types_list
;
1182 /* If non-null, this is the variant part we are currently
1184 variant_part_builder
*current_variant_part
= nullptr;
1185 /* This holds all the top-level variant parts attached to the type
1187 std::vector
<variant_part_builder
> variant_parts
;
1189 /* Return the total number of fields (including baseclasses). */
1190 int nfields () const
1192 return fields
.size () + baseclasses
.size ();
1196 /* Loaded secondary compilation units are kept in memory until they
1197 have not been referenced for the processing of this many
1198 compilation units. Set this to zero to disable caching. Cache
1199 sizes of up to at least twenty will improve startup time for
1200 typical inter-CU-reference binaries, at an obvious memory cost. */
1201 static int dwarf_max_cache_age
= 5;
1203 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1204 struct cmd_list_element
*c
, const char *value
)
1206 fprintf_filtered (file
, _("The upper bound on the age of cached "
1207 "DWARF compilation units is %s.\n"),
1211 /* local function prototypes */
1213 static void dwarf2_find_base_address (struct die_info
*die
,
1214 struct dwarf2_cu
*cu
);
1216 static dwarf2_psymtab
*create_partial_symtab
1217 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1220 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1221 const gdb_byte
*info_ptr
,
1222 struct die_info
*type_unit_die
);
1224 static void dwarf2_build_psymtabs_hard
1225 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1227 static void scan_partial_symbols (struct partial_die_info
*,
1228 CORE_ADDR
*, CORE_ADDR
*,
1229 int, struct dwarf2_cu
*);
1231 static void add_partial_symbol (struct partial_die_info
*,
1232 struct dwarf2_cu
*);
1234 static void add_partial_namespace (struct partial_die_info
*pdi
,
1235 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1236 int set_addrmap
, struct dwarf2_cu
*cu
);
1238 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1239 CORE_ADDR
*highpc
, int set_addrmap
,
1240 struct dwarf2_cu
*cu
);
1242 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1243 struct dwarf2_cu
*cu
);
1245 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1246 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1247 int need_pc
, struct dwarf2_cu
*cu
);
1249 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1251 static struct partial_die_info
*load_partial_dies
1252 (const struct die_reader_specs
*, const gdb_byte
*, int);
1254 /* A pair of partial_die_info and compilation unit. */
1255 struct cu_partial_die_info
1257 /* The compilation unit of the partial_die_info. */
1258 struct dwarf2_cu
*cu
;
1259 /* A partial_die_info. */
1260 struct partial_die_info
*pdi
;
1262 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1268 cu_partial_die_info () = delete;
1271 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1272 struct dwarf2_cu
*);
1274 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1275 struct attribute
*, struct attr_abbrev
*,
1276 const gdb_byte
*, bool *need_reprocess
);
1278 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1279 struct attribute
*attr
);
1281 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1283 static sect_offset read_abbrev_offset
1284 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1285 struct dwarf2_section_info
*, sect_offset
);
1287 static const char *read_indirect_string
1288 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1289 const struct comp_unit_head
*, unsigned int *);
1291 static const char *read_indirect_string_at_offset
1292 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1294 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1298 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1299 ULONGEST str_index
);
1301 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1302 ULONGEST str_index
);
1304 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1306 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1307 struct dwarf2_cu
*);
1309 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1310 struct dwarf2_cu
*cu
);
1312 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1314 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1315 struct dwarf2_cu
*cu
);
1317 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1319 static struct die_info
*die_specification (struct die_info
*die
,
1320 struct dwarf2_cu
**);
1322 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1323 struct dwarf2_cu
*cu
);
1325 static void dwarf_decode_lines (struct line_header
*, const char *,
1326 struct dwarf2_cu
*, dwarf2_psymtab
*,
1327 CORE_ADDR
, int decode_mapping
);
1329 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1332 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1333 struct dwarf2_cu
*, struct symbol
* = NULL
);
1335 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1336 struct dwarf2_cu
*);
1338 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1341 struct obstack
*obstack
,
1342 struct dwarf2_cu
*cu
, LONGEST
*value
,
1343 const gdb_byte
**bytes
,
1344 struct dwarf2_locexpr_baton
**baton
);
1346 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1348 static int need_gnat_info (struct dwarf2_cu
*);
1350 static struct type
*die_descriptive_type (struct die_info
*,
1351 struct dwarf2_cu
*);
1353 static void set_descriptive_type (struct type
*, struct die_info
*,
1354 struct dwarf2_cu
*);
1356 static struct type
*die_containing_type (struct die_info
*,
1357 struct dwarf2_cu
*);
1359 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1360 struct dwarf2_cu
*);
1362 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1364 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1366 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1368 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1369 const char *suffix
, int physname
,
1370 struct dwarf2_cu
*cu
);
1372 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1374 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1376 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1378 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1380 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1382 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1384 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1385 struct dwarf2_cu
*, dwarf2_psymtab
*);
1387 /* Return the .debug_loclists section to use for cu. */
1388 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1390 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1391 values. Keep the items ordered with increasing constraints compliance. */
1394 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1395 PC_BOUNDS_NOT_PRESENT
,
1397 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1398 were present but they do not form a valid range of PC addresses. */
1401 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1404 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1408 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1409 CORE_ADDR
*, CORE_ADDR
*,
1413 static void get_scope_pc_bounds (struct die_info
*,
1414 CORE_ADDR
*, CORE_ADDR
*,
1415 struct dwarf2_cu
*);
1417 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1418 CORE_ADDR
, struct dwarf2_cu
*);
1420 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1421 struct dwarf2_cu
*);
1423 static void dwarf2_attach_fields_to_type (struct field_info
*,
1424 struct type
*, struct dwarf2_cu
*);
1426 static void dwarf2_add_member_fn (struct field_info
*,
1427 struct die_info
*, struct type
*,
1428 struct dwarf2_cu
*);
1430 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1432 struct dwarf2_cu
*);
1434 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1436 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1438 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1440 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1442 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1444 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1446 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1448 static struct type
*read_module_type (struct die_info
*die
,
1449 struct dwarf2_cu
*cu
);
1451 static const char *namespace_name (struct die_info
*die
,
1452 int *is_anonymous
, struct dwarf2_cu
*);
1454 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1456 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1459 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1460 struct dwarf2_cu
*);
1462 static struct die_info
*read_die_and_siblings_1
1463 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1466 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1467 const gdb_byte
*info_ptr
,
1468 const gdb_byte
**new_info_ptr
,
1469 struct die_info
*parent
);
1471 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1472 struct die_info
**, const gdb_byte
*,
1475 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1476 struct die_info
**, const gdb_byte
*);
1478 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1480 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1483 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1485 static const char *dwarf2_full_name (const char *name
,
1486 struct die_info
*die
,
1487 struct dwarf2_cu
*cu
);
1489 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1490 struct dwarf2_cu
*cu
);
1492 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1493 struct dwarf2_cu
**);
1495 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1497 static void dump_die_for_error (struct die_info
*);
1499 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1502 /*static*/ void dump_die (struct die_info
*, int max_level
);
1504 static void store_in_ref_table (struct die_info
*,
1505 struct dwarf2_cu
*);
1507 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1508 const struct attribute
*,
1509 struct dwarf2_cu
**);
1511 static struct die_info
*follow_die_ref (struct die_info
*,
1512 const struct attribute
*,
1513 struct dwarf2_cu
**);
1515 static struct die_info
*follow_die_sig (struct die_info
*,
1516 const struct attribute
*,
1517 struct dwarf2_cu
**);
1519 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1520 struct dwarf2_cu
*);
1522 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1523 const struct attribute
*,
1524 struct dwarf2_cu
*);
1526 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1527 dwarf2_per_objfile
*per_objfile
);
1529 static void read_signatured_type (signatured_type
*sig_type
,
1530 dwarf2_per_objfile
*per_objfile
);
1532 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1533 struct die_info
*die
, struct dwarf2_cu
*cu
,
1534 struct dynamic_prop
*prop
, struct type
*type
);
1536 /* memory allocation interface */
1538 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1540 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1542 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1544 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1545 struct dwarf2_loclist_baton
*baton
,
1546 const struct attribute
*attr
);
1548 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1550 struct dwarf2_cu
*cu
,
1553 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1554 const gdb_byte
*info_ptr
,
1555 struct abbrev_info
*abbrev
);
1557 static hashval_t
partial_die_hash (const void *item
);
1559 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1561 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1562 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1563 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1565 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1566 struct die_info
*comp_unit_die
,
1567 enum language pretend_language
);
1569 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1571 static void free_one_cached_comp_unit (dwarf2_per_cu_data
*target_per_cu
,
1572 dwarf2_per_objfile
*per_objfile
);
1574 static struct type
*set_die_type (struct die_info
*, struct type
*,
1575 struct dwarf2_cu
*);
1577 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1579 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1581 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1582 dwarf2_per_objfile
*per_objfile
,
1584 enum language pretend_language
);
1586 static void process_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1587 dwarf2_per_objfile
*per_objfile
,
1588 enum language pretend_language
);
1590 static void process_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1591 dwarf2_per_objfile
*per_objfile
,
1592 enum language pretend_language
);
1594 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1595 struct dwarf2_per_cu_data
*);
1597 static void dwarf2_mark (struct dwarf2_cu
*);
1599 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1601 static struct type
*get_die_type_at_offset (sect_offset
,
1602 struct dwarf2_per_cu_data
*);
1604 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1606 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1607 dwarf2_per_objfile
*per_objfile
,
1608 enum language pretend_language
);
1610 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1612 /* Class, the destructor of which frees all allocated queue entries. This
1613 will only have work to do if an error was thrown while processing the
1614 dwarf. If no error was thrown then the queue entries should have all
1615 been processed, and freed, as we went along. */
1617 class dwarf2_queue_guard
1620 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1621 : m_per_objfile (per_objfile
)
1625 /* Free any entries remaining on the queue. There should only be
1626 entries left if we hit an error while processing the dwarf. */
1627 ~dwarf2_queue_guard ()
1629 /* Ensure that no memory is allocated by the queue. */
1630 std::queue
<dwarf2_queue_item
> empty
;
1631 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1634 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1637 dwarf2_per_objfile
*m_per_objfile
;
1640 dwarf2_queue_item::~dwarf2_queue_item ()
1642 /* Anything still marked queued is likely to be in an
1643 inconsistent state, so discard it. */
1646 if (per_cu
->cu
!= NULL
)
1647 free_one_cached_comp_unit (per_cu
, per_objfile
);
1652 /* The return type of find_file_and_directory. Note, the enclosed
1653 string pointers are only valid while this object is valid. */
1655 struct file_and_directory
1657 /* The filename. This is never NULL. */
1660 /* The compilation directory. NULL if not known. If we needed to
1661 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1662 points directly to the DW_AT_comp_dir string attribute owned by
1663 the obstack that owns the DIE. */
1664 const char *comp_dir
;
1666 /* If we needed to build a new string for comp_dir, this is what
1667 owns the storage. */
1668 std::string comp_dir_storage
;
1671 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1672 struct dwarf2_cu
*cu
);
1674 static htab_up
allocate_signatured_type_table ();
1676 static htab_up
allocate_dwo_unit_table ();
1678 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1679 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1680 struct dwp_file
*dwp_file
, const char *comp_dir
,
1681 ULONGEST signature
, int is_debug_types
);
1683 static struct dwp_file
*get_dwp_file
1684 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1686 static struct dwo_unit
*lookup_dwo_comp_unit
1687 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1688 ULONGEST signature
);
1690 static struct dwo_unit
*lookup_dwo_type_unit
1691 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1693 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1695 /* A unique pointer to a dwo_file. */
1697 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1699 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1701 static void check_producer (struct dwarf2_cu
*cu
);
1703 static void free_line_header_voidp (void *arg
);
1705 /* Various complaints about symbol reading that don't abort the process. */
1708 dwarf2_debug_line_missing_file_complaint (void)
1710 complaint (_(".debug_line section has line data without a file"));
1714 dwarf2_debug_line_missing_end_sequence_complaint (void)
1716 complaint (_(".debug_line section has line "
1717 "program sequence without an end"));
1721 dwarf2_complex_location_expr_complaint (void)
1723 complaint (_("location expression too complex"));
1727 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1730 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1735 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1737 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1741 /* Hash function for line_header_hash. */
1744 line_header_hash (const struct line_header
*ofs
)
1746 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1749 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1752 line_header_hash_voidp (const void *item
)
1754 const struct line_header
*ofs
= (const struct line_header
*) item
;
1756 return line_header_hash (ofs
);
1759 /* Equality function for line_header_hash. */
1762 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1764 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1765 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1767 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1768 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1773 /* See declaration. */
1775 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1778 can_copy (can_copy_
)
1781 names
= &dwarf2_elf_names
;
1783 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1784 locate_sections (obfd
, sec
, *names
);
1787 dwarf2_per_bfd::~dwarf2_per_bfd ()
1789 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1790 free_cached_comp_units ();
1792 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1793 per_cu
->imported_symtabs_free ();
1795 for (signatured_type
*sig_type
: all_type_units
)
1796 sig_type
->per_cu
.imported_symtabs_free ();
1798 /* Everything else should be on this->obstack. */
1801 /* See declaration. */
1804 dwarf2_per_bfd::free_cached_comp_units ()
1806 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1807 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1808 while (per_cu
!= NULL
)
1810 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1813 *last_chain
= next_cu
;
1818 /* A helper class that calls free_cached_comp_units on
1821 class free_cached_comp_units
1825 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1826 : m_per_objfile (per_objfile
)
1830 ~free_cached_comp_units ()
1832 m_per_objfile
->per_bfd
->free_cached_comp_units ();
1835 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1839 dwarf2_per_objfile
*m_per_objfile
;
1845 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1847 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1849 return this->m_symtabs
[per_cu
->index
] != nullptr;
1855 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1857 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1859 return this->m_symtabs
[per_cu
->index
];
1865 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1866 compunit_symtab
*symtab
)
1868 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1869 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1871 this->m_symtabs
[per_cu
->index
] = symtab
;
1874 /* Try to locate the sections we need for DWARF 2 debugging
1875 information and return true if we have enough to do something.
1876 NAMES points to the dwarf2 section names, or is NULL if the standard
1877 ELF names are used. CAN_COPY is true for formats where symbol
1878 interposition is possible and so symbol values must follow copy
1879 relocation rules. */
1882 dwarf2_has_info (struct objfile
*objfile
,
1883 const struct dwarf2_debug_sections
*names
,
1886 if (objfile
->flags
& OBJF_READNEVER
)
1889 struct dwarf2_per_objfile
*dwarf2_per_objfile
1890 = get_dwarf2_per_objfile (objfile
);
1892 if (dwarf2_per_objfile
== NULL
)
1894 /* For now, each dwarf2_per_objfile owns its own dwarf2_per_bfd (no
1896 dwarf2_per_bfd
*per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1898 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1901 return (!dwarf2_per_objfile
->per_bfd
->info
.is_virtual
1902 && dwarf2_per_objfile
->per_bfd
->info
.s
.section
!= NULL
1903 && !dwarf2_per_objfile
->per_bfd
->abbrev
.is_virtual
1904 && dwarf2_per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1907 /* When loading sections, we look either for uncompressed section or for
1908 compressed section names. */
1911 section_is_p (const char *section_name
,
1912 const struct dwarf2_section_names
*names
)
1914 if (names
->normal
!= NULL
1915 && strcmp (section_name
, names
->normal
) == 0)
1917 if (names
->compressed
!= NULL
1918 && strcmp (section_name
, names
->compressed
) == 0)
1923 /* See declaration. */
1926 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1927 const dwarf2_debug_sections
&names
)
1929 flagword aflag
= bfd_section_flags (sectp
);
1931 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1934 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1935 > bfd_get_file_size (abfd
))
1937 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1938 warning (_("Discarding section %s which has a section size (%s"
1939 ") larger than the file size [in module %s]"),
1940 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1941 bfd_get_filename (abfd
));
1943 else if (section_is_p (sectp
->name
, &names
.info
))
1945 this->info
.s
.section
= sectp
;
1946 this->info
.size
= bfd_section_size (sectp
);
1948 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1950 this->abbrev
.s
.section
= sectp
;
1951 this->abbrev
.size
= bfd_section_size (sectp
);
1953 else if (section_is_p (sectp
->name
, &names
.line
))
1955 this->line
.s
.section
= sectp
;
1956 this->line
.size
= bfd_section_size (sectp
);
1958 else if (section_is_p (sectp
->name
, &names
.loc
))
1960 this->loc
.s
.section
= sectp
;
1961 this->loc
.size
= bfd_section_size (sectp
);
1963 else if (section_is_p (sectp
->name
, &names
.loclists
))
1965 this->loclists
.s
.section
= sectp
;
1966 this->loclists
.size
= bfd_section_size (sectp
);
1968 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1970 this->macinfo
.s
.section
= sectp
;
1971 this->macinfo
.size
= bfd_section_size (sectp
);
1973 else if (section_is_p (sectp
->name
, &names
.macro
))
1975 this->macro
.s
.section
= sectp
;
1976 this->macro
.size
= bfd_section_size (sectp
);
1978 else if (section_is_p (sectp
->name
, &names
.str
))
1980 this->str
.s
.section
= sectp
;
1981 this->str
.size
= bfd_section_size (sectp
);
1983 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1985 this->str_offsets
.s
.section
= sectp
;
1986 this->str_offsets
.size
= bfd_section_size (sectp
);
1988 else if (section_is_p (sectp
->name
, &names
.line_str
))
1990 this->line_str
.s
.section
= sectp
;
1991 this->line_str
.size
= bfd_section_size (sectp
);
1993 else if (section_is_p (sectp
->name
, &names
.addr
))
1995 this->addr
.s
.section
= sectp
;
1996 this->addr
.size
= bfd_section_size (sectp
);
1998 else if (section_is_p (sectp
->name
, &names
.frame
))
2000 this->frame
.s
.section
= sectp
;
2001 this->frame
.size
= bfd_section_size (sectp
);
2003 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2005 this->eh_frame
.s
.section
= sectp
;
2006 this->eh_frame
.size
= bfd_section_size (sectp
);
2008 else if (section_is_p (sectp
->name
, &names
.ranges
))
2010 this->ranges
.s
.section
= sectp
;
2011 this->ranges
.size
= bfd_section_size (sectp
);
2013 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2015 this->rnglists
.s
.section
= sectp
;
2016 this->rnglists
.size
= bfd_section_size (sectp
);
2018 else if (section_is_p (sectp
->name
, &names
.types
))
2020 struct dwarf2_section_info type_section
;
2022 memset (&type_section
, 0, sizeof (type_section
));
2023 type_section
.s
.section
= sectp
;
2024 type_section
.size
= bfd_section_size (sectp
);
2026 this->types
.push_back (type_section
);
2028 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2030 this->gdb_index
.s
.section
= sectp
;
2031 this->gdb_index
.size
= bfd_section_size (sectp
);
2033 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2035 this->debug_names
.s
.section
= sectp
;
2036 this->debug_names
.size
= bfd_section_size (sectp
);
2038 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2040 this->debug_aranges
.s
.section
= sectp
;
2041 this->debug_aranges
.size
= bfd_section_size (sectp
);
2044 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2045 && bfd_section_vma (sectp
) == 0)
2046 this->has_section_at_zero
= true;
2049 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2053 dwarf2_get_section_info (struct objfile
*objfile
,
2054 enum dwarf2_section_enum sect
,
2055 asection
**sectp
, const gdb_byte
**bufp
,
2056 bfd_size_type
*sizep
)
2058 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2059 struct dwarf2_section_info
*info
;
2061 /* We may see an objfile without any DWARF, in which case we just
2072 case DWARF2_DEBUG_FRAME
:
2073 info
= &data
->per_bfd
->frame
;
2075 case DWARF2_EH_FRAME
:
2076 info
= &data
->per_bfd
->eh_frame
;
2079 gdb_assert_not_reached ("unexpected section");
2082 info
->read (objfile
);
2084 *sectp
= info
->get_bfd_section ();
2085 *bufp
= info
->buffer
;
2086 *sizep
= info
->size
;
2089 /* A helper function to find the sections for a .dwz file. */
2092 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2094 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2096 /* Note that we only support the standard ELF names, because .dwz
2097 is ELF-only (at the time of writing). */
2098 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2100 dwz_file
->abbrev
.s
.section
= sectp
;
2101 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2103 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2105 dwz_file
->info
.s
.section
= sectp
;
2106 dwz_file
->info
.size
= bfd_section_size (sectp
);
2108 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2110 dwz_file
->str
.s
.section
= sectp
;
2111 dwz_file
->str
.size
= bfd_section_size (sectp
);
2113 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2115 dwz_file
->line
.s
.section
= sectp
;
2116 dwz_file
->line
.size
= bfd_section_size (sectp
);
2118 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2120 dwz_file
->macro
.s
.section
= sectp
;
2121 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2123 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2125 dwz_file
->gdb_index
.s
.section
= sectp
;
2126 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2128 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2130 dwz_file
->debug_names
.s
.section
= sectp
;
2131 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2135 /* See dwarf2read.h. */
2138 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2140 const char *filename
;
2141 bfd_size_type buildid_len_arg
;
2145 if (per_bfd
->dwz_file
!= NULL
)
2146 return per_bfd
->dwz_file
.get ();
2148 bfd_set_error (bfd_error_no_error
);
2149 gdb::unique_xmalloc_ptr
<char> data
2150 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2151 &buildid_len_arg
, &buildid
));
2154 if (bfd_get_error () == bfd_error_no_error
)
2156 error (_("could not read '.gnu_debugaltlink' section: %s"),
2157 bfd_errmsg (bfd_get_error ()));
2160 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2162 buildid_len
= (size_t) buildid_len_arg
;
2164 filename
= data
.get ();
2166 std::string abs_storage
;
2167 if (!IS_ABSOLUTE_PATH (filename
))
2169 gdb::unique_xmalloc_ptr
<char> abs
2170 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2172 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2173 filename
= abs_storage
.c_str ();
2176 /* First try the file name given in the section. If that doesn't
2177 work, try to use the build-id instead. */
2178 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2179 if (dwz_bfd
!= NULL
)
2181 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2182 dwz_bfd
.reset (nullptr);
2185 if (dwz_bfd
== NULL
)
2186 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2188 if (dwz_bfd
== nullptr)
2190 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2191 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2193 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2200 /* File successfully retrieved from server. */
2201 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2203 if (dwz_bfd
== nullptr)
2204 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2205 alt_filename
.get ());
2206 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2207 dwz_bfd
.reset (nullptr);
2211 if (dwz_bfd
== NULL
)
2212 error (_("could not find '.gnu_debugaltlink' file for %s"),
2213 bfd_get_filename (per_bfd
->obfd
));
2215 std::unique_ptr
<struct dwz_file
> result
2216 (new struct dwz_file (std::move (dwz_bfd
)));
2218 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2221 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2222 per_bfd
->dwz_file
= std::move (result
);
2223 return per_bfd
->dwz_file
.get ();
2226 /* DWARF quick_symbols_functions support. */
2228 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2229 unique line tables, so we maintain a separate table of all .debug_line
2230 derived entries to support the sharing.
2231 All the quick functions need is the list of file names. We discard the
2232 line_header when we're done and don't need to record it here. */
2233 struct quick_file_names
2235 /* The data used to construct the hash key. */
2236 struct stmt_list_hash hash
;
2238 /* The number of entries in file_names, real_names. */
2239 unsigned int num_file_names
;
2241 /* The file names from the line table, after being run through
2243 const char **file_names
;
2245 /* The file names from the line table after being run through
2246 gdb_realpath. These are computed lazily. */
2247 const char **real_names
;
2250 /* When using the index (and thus not using psymtabs), each CU has an
2251 object of this type. This is used to hold information needed by
2252 the various "quick" methods. */
2253 struct dwarf2_per_cu_quick_data
2255 /* The file table. This can be NULL if there was no file table
2256 or it's currently not read in.
2257 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2258 struct quick_file_names
*file_names
;
2260 /* A temporary mark bit used when iterating over all CUs in
2261 expand_symtabs_matching. */
2262 unsigned int mark
: 1;
2264 /* True if we've tried to read the file table and found there isn't one.
2265 There will be no point in trying to read it again next time. */
2266 unsigned int no_file_data
: 1;
2269 /* Utility hash function for a stmt_list_hash. */
2272 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2276 if (stmt_list_hash
->dwo_unit
!= NULL
)
2277 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2278 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2282 /* Utility equality function for a stmt_list_hash. */
2285 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2286 const struct stmt_list_hash
*rhs
)
2288 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2290 if (lhs
->dwo_unit
!= NULL
2291 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2294 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2297 /* Hash function for a quick_file_names. */
2300 hash_file_name_entry (const void *e
)
2302 const struct quick_file_names
*file_data
2303 = (const struct quick_file_names
*) e
;
2305 return hash_stmt_list_entry (&file_data
->hash
);
2308 /* Equality function for a quick_file_names. */
2311 eq_file_name_entry (const void *a
, const void *b
)
2313 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2314 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2316 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2319 /* Delete function for a quick_file_names. */
2322 delete_file_name_entry (void *e
)
2324 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2327 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2329 xfree ((void*) file_data
->file_names
[i
]);
2330 if (file_data
->real_names
)
2331 xfree ((void*) file_data
->real_names
[i
]);
2334 /* The space for the struct itself lives on the obstack, so we don't
2338 /* Create a quick_file_names hash table. */
2341 create_quick_file_names_table (unsigned int nr_initial_entries
)
2343 return htab_up (htab_create_alloc (nr_initial_entries
,
2344 hash_file_name_entry
, eq_file_name_entry
,
2345 delete_file_name_entry
, xcalloc
, xfree
));
2348 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2349 function is unrelated to symtabs, symtab would have to be created afterwards.
2350 You should call age_cached_comp_units after processing the CU. */
2353 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2356 if (per_cu
->is_debug_types
)
2357 load_full_type_unit (per_cu
, per_objfile
);
2359 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2361 if (per_cu
->cu
== NULL
)
2362 return; /* Dummy CU. */
2364 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->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
*dwarf2_per_objfile
,
2374 /* Skip type_unit_groups, reading the type units they contain
2375 is handled elsewhere. */
2376 if (per_cu
->type_unit_group_p ())
2379 /* The destructor of dwarf2_queue_guard frees any entries left on
2380 the queue. After this point we're guaranteed to leave this function
2381 with the dwarf queue empty. */
2382 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2384 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2386 queue_comp_unit (per_cu
, dwarf2_per_objfile
, language_minimal
);
2387 load_cu (per_cu
, dwarf2_per_objfile
, skip_partial
);
2389 /* If we just loaded a CU from a DWO, and we're working with an index
2390 that may badly handle TUs, load all the TUs in that DWO as well.
2391 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2392 if (!per_cu
->is_debug_types
2393 && per_cu
->cu
!= NULL
2394 && per_cu
->cu
->dwo_unit
!= NULL
2395 && dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
2396 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7
2397 /* DWP files aren't supported yet. */
2398 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2399 queue_and_load_all_dwo_tus (per_cu
);
2402 process_queue (dwarf2_per_objfile
);
2404 /* Age the cache, releasing compilation units that have not
2405 been used recently. */
2406 age_cached_comp_units (dwarf2_per_objfile
);
2409 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2410 the per-objfile for which this symtab is instantiated.
2412 Returns the resulting symbol table. */
2414 static struct compunit_symtab
*
2415 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2416 dwarf2_per_objfile
*dwarf2_per_objfile
,
2419 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
2421 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2423 free_cached_comp_units
freer (dwarf2_per_objfile
);
2424 scoped_restore decrementer
= increment_reading_symtab ();
2425 dw2_do_instantiate_symtab (per_cu
, dwarf2_per_objfile
, skip_partial
);
2426 process_cu_includes (dwarf2_per_objfile
);
2429 return dwarf2_per_objfile
->get_symtab (per_cu
);
2432 /* See declaration. */
2434 dwarf2_per_cu_data
*
2435 dwarf2_per_bfd::get_cutu (int index
)
2437 if (index
>= this->all_comp_units
.size ())
2439 index
-= this->all_comp_units
.size ();
2440 gdb_assert (index
< this->all_type_units
.size ());
2441 return &this->all_type_units
[index
]->per_cu
;
2444 return this->all_comp_units
[index
];
2447 /* See declaration. */
2449 dwarf2_per_cu_data
*
2450 dwarf2_per_bfd::get_cu (int index
)
2452 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2454 return this->all_comp_units
[index
];
2457 /* See declaration. */
2460 dwarf2_per_bfd::get_tu (int index
)
2462 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2464 return this->all_type_units
[index
];
2469 dwarf2_per_cu_data
*
2470 dwarf2_per_bfd::allocate_per_cu ()
2472 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2473 result
->per_bfd
= this;
2474 result
->index
= m_num_psymtabs
++;
2481 dwarf2_per_bfd::allocate_signatured_type ()
2483 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2484 result
->per_cu
.per_bfd
= this;
2485 result
->per_cu
.index
= m_num_psymtabs
++;
2489 /* Return a new dwarf2_per_cu_data allocated on the dwarf2_per_objfile
2490 obstack, and constructed with the specified field values. */
2492 static dwarf2_per_cu_data
*
2493 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2494 struct dwarf2_section_info
*section
,
2496 sect_offset sect_off
, ULONGEST length
)
2498 dwarf2_per_cu_data
*the_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
2499 the_cu
->sect_off
= sect_off
;
2500 the_cu
->length
= length
;
2501 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2502 the_cu
->section
= section
;
2503 the_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2504 struct dwarf2_per_cu_quick_data
);
2505 the_cu
->is_dwz
= is_dwz
;
2509 /* A helper for create_cus_from_index that handles a given list of
2513 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2514 const gdb_byte
*cu_list
, offset_type n_elements
,
2515 struct dwarf2_section_info
*section
,
2518 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2520 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2522 sect_offset sect_off
2523 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2524 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2527 dwarf2_per_cu_data
*per_cu
2528 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2530 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
2534 /* Read the CU list from the mapped index, and use it to create all
2535 the CU objects for this objfile. */
2538 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2539 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2540 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2542 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
2543 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve
2544 ((cu_list_elements
+ dwz_elements
) / 2);
2546 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2547 &dwarf2_per_objfile
->per_bfd
->info
, 0);
2549 if (dwz_elements
== 0)
2552 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
2553 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2557 /* Create the signatured type hash table from the index. */
2560 create_signatured_type_table_from_index
2561 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2562 struct dwarf2_section_info
*section
,
2563 const gdb_byte
*bytes
,
2564 offset_type elements
)
2566 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2567 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (elements
/ 3);
2569 htab_up sig_types_hash
= allocate_signatured_type_table ();
2571 for (offset_type i
= 0; i
< elements
; i
+= 3)
2573 struct signatured_type
*sig_type
;
2576 cu_offset type_offset_in_tu
;
2578 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2579 sect_offset sect_off
2580 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2582 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2584 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2587 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2588 sig_type
->signature
= signature
;
2589 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2590 sig_type
->per_cu
.is_debug_types
= 1;
2591 sig_type
->per_cu
.section
= section
;
2592 sig_type
->per_cu
.sect_off
= sect_off
;
2593 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2594 sig_type
->per_cu
.v
.quick
2595 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2596 struct dwarf2_per_cu_quick_data
);
2598 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2601 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2604 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2607 /* Create the signatured type hash table from .debug_names. */
2610 create_signatured_type_table_from_debug_names
2611 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2612 const mapped_debug_names
&map
,
2613 struct dwarf2_section_info
*section
,
2614 struct dwarf2_section_info
*abbrev_section
)
2616 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2618 section
->read (objfile
);
2619 abbrev_section
->read (objfile
);
2621 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2622 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2624 htab_up sig_types_hash
= allocate_signatured_type_table ();
2626 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2628 struct signatured_type
*sig_type
;
2631 sect_offset sect_off
2632 = (sect_offset
) (extract_unsigned_integer
2633 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2635 map
.dwarf5_byte_order
));
2637 comp_unit_head cu_header
;
2638 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2640 section
->buffer
+ to_underlying (sect_off
),
2643 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2644 sig_type
->signature
= cu_header
.signature
;
2645 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2646 sig_type
->per_cu
.is_debug_types
= 1;
2647 sig_type
->per_cu
.section
= section
;
2648 sig_type
->per_cu
.sect_off
= sect_off
;
2649 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2650 sig_type
->per_cu
.v
.quick
2651 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2652 struct dwarf2_per_cu_quick_data
);
2654 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2657 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2660 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2663 /* Read the address map data from the mapped index, and use it to
2664 populate the objfile's psymtabs_addrmap. */
2667 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2668 struct mapped_index
*index
)
2670 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2671 struct gdbarch
*gdbarch
= objfile
->arch ();
2672 const gdb_byte
*iter
, *end
;
2673 struct addrmap
*mutable_map
;
2676 auto_obstack temp_obstack
;
2678 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2680 iter
= index
->address_table
.data ();
2681 end
= iter
+ index
->address_table
.size ();
2683 baseaddr
= objfile
->text_section_offset ();
2687 ULONGEST hi
, lo
, cu_index
;
2688 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2690 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2692 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2697 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2698 hex_string (lo
), hex_string (hi
));
2702 if (cu_index
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
2704 complaint (_(".gdb_index address table has invalid CU number %u"),
2705 (unsigned) cu_index
);
2709 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2710 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2711 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2712 dwarf2_per_objfile
->per_bfd
->get_cu (cu_index
));
2715 objfile
->partial_symtabs
->psymtabs_addrmap
2716 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2719 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2720 populate the objfile's psymtabs_addrmap. */
2723 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2724 struct dwarf2_section_info
*section
)
2726 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2727 bfd
*abfd
= objfile
->obfd
;
2728 struct gdbarch
*gdbarch
= objfile
->arch ();
2729 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2731 auto_obstack temp_obstack
;
2732 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2734 std::unordered_map
<sect_offset
,
2735 dwarf2_per_cu_data
*,
2736 gdb::hash_enum
<sect_offset
>>
2737 debug_info_offset_to_per_cu
;
2738 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
2740 const auto insertpair
2741 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2742 if (!insertpair
.second
)
2744 warning (_("Section .debug_aranges in %s has duplicate "
2745 "debug_info_offset %s, ignoring .debug_aranges."),
2746 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2751 section
->read (objfile
);
2753 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2755 const gdb_byte
*addr
= section
->buffer
;
2757 while (addr
< section
->buffer
+ section
->size
)
2759 const gdb_byte
*const entry_addr
= addr
;
2760 unsigned int bytes_read
;
2762 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2766 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2767 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2768 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2769 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2771 warning (_("Section .debug_aranges in %s entry at offset %s "
2772 "length %s exceeds section length %s, "
2773 "ignoring .debug_aranges."),
2774 objfile_name (objfile
),
2775 plongest (entry_addr
- section
->buffer
),
2776 plongest (bytes_read
+ entry_length
),
2777 pulongest (section
->size
));
2781 /* The version number. */
2782 const uint16_t version
= read_2_bytes (abfd
, addr
);
2786 warning (_("Section .debug_aranges in %s entry at offset %s "
2787 "has unsupported version %d, ignoring .debug_aranges."),
2788 objfile_name (objfile
),
2789 plongest (entry_addr
- section
->buffer
), version
);
2793 const uint64_t debug_info_offset
2794 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2795 addr
+= offset_size
;
2796 const auto per_cu_it
2797 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2798 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2800 warning (_("Section .debug_aranges in %s entry at offset %s "
2801 "debug_info_offset %s does not exists, "
2802 "ignoring .debug_aranges."),
2803 objfile_name (objfile
),
2804 plongest (entry_addr
- section
->buffer
),
2805 pulongest (debug_info_offset
));
2808 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2810 const uint8_t address_size
= *addr
++;
2811 if (address_size
< 1 || address_size
> 8)
2813 warning (_("Section .debug_aranges in %s entry at offset %s "
2814 "address_size %u is invalid, ignoring .debug_aranges."),
2815 objfile_name (objfile
),
2816 plongest (entry_addr
- section
->buffer
), address_size
);
2820 const uint8_t segment_selector_size
= *addr
++;
2821 if (segment_selector_size
!= 0)
2823 warning (_("Section .debug_aranges in %s entry at offset %s "
2824 "segment_selector_size %u is not supported, "
2825 "ignoring .debug_aranges."),
2826 objfile_name (objfile
),
2827 plongest (entry_addr
- section
->buffer
),
2828 segment_selector_size
);
2832 /* Must pad to an alignment boundary that is twice the address
2833 size. It is undocumented by the DWARF standard but GCC does
2835 for (size_t padding
= ((-(addr
- section
->buffer
))
2836 & (2 * address_size
- 1));
2837 padding
> 0; padding
--)
2840 warning (_("Section .debug_aranges in %s entry at offset %s "
2841 "padding is not zero, ignoring .debug_aranges."),
2842 objfile_name (objfile
),
2843 plongest (entry_addr
- section
->buffer
));
2849 if (addr
+ 2 * address_size
> entry_end
)
2851 warning (_("Section .debug_aranges in %s entry at offset %s "
2852 "address list is not properly terminated, "
2853 "ignoring .debug_aranges."),
2854 objfile_name (objfile
),
2855 plongest (entry_addr
- section
->buffer
));
2858 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2860 addr
+= address_size
;
2861 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2863 addr
+= address_size
;
2864 if (start
== 0 && length
== 0)
2866 if (start
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
2868 /* Symbol was eliminated due to a COMDAT group. */
2871 ULONGEST end
= start
+ length
;
2872 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2874 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2876 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2880 objfile
->partial_symtabs
->psymtabs_addrmap
2881 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2884 /* Find a slot in the mapped index INDEX for the object named NAME.
2885 If NAME is found, set *VEC_OUT to point to the CU vector in the
2886 constant pool and return true. If NAME cannot be found, return
2890 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2891 offset_type
**vec_out
)
2894 offset_type slot
, step
;
2895 int (*cmp
) (const char *, const char *);
2897 gdb::unique_xmalloc_ptr
<char> without_params
;
2898 if (current_language
->la_language
== language_cplus
2899 || current_language
->la_language
== language_fortran
2900 || current_language
->la_language
== language_d
)
2902 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2905 if (strchr (name
, '(') != NULL
)
2907 without_params
= cp_remove_params (name
);
2909 if (without_params
!= NULL
)
2910 name
= without_params
.get ();
2914 /* Index version 4 did not support case insensitive searches. But the
2915 indices for case insensitive languages are built in lowercase, therefore
2916 simulate our NAME being searched is also lowercased. */
2917 hash
= mapped_index_string_hash ((index
->version
== 4
2918 && case_sensitivity
== case_sensitive_off
2919 ? 5 : index
->version
),
2922 slot
= hash
& (index
->symbol_table
.size () - 1);
2923 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2924 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2930 const auto &bucket
= index
->symbol_table
[slot
];
2931 if (bucket
.name
== 0 && bucket
.vec
== 0)
2934 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2935 if (!cmp (name
, str
))
2937 *vec_out
= (offset_type
*) (index
->constant_pool
2938 + MAYBE_SWAP (bucket
.vec
));
2942 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2946 /* A helper function that reads the .gdb_index from BUFFER and fills
2947 in MAP. FILENAME is the name of the file containing the data;
2948 it is used for error reporting. DEPRECATED_OK is true if it is
2949 ok to use deprecated sections.
2951 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2952 out parameters that are filled in with information about the CU and
2953 TU lists in the section.
2955 Returns true if all went well, false otherwise. */
2958 read_gdb_index_from_buffer (const char *filename
,
2960 gdb::array_view
<const gdb_byte
> buffer
,
2961 struct mapped_index
*map
,
2962 const gdb_byte
**cu_list
,
2963 offset_type
*cu_list_elements
,
2964 const gdb_byte
**types_list
,
2965 offset_type
*types_list_elements
)
2967 const gdb_byte
*addr
= &buffer
[0];
2969 /* Version check. */
2970 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2971 /* Versions earlier than 3 emitted every copy of a psymbol. This
2972 causes the index to behave very poorly for certain requests. Version 3
2973 contained incomplete addrmap. So, it seems better to just ignore such
2977 static int warning_printed
= 0;
2978 if (!warning_printed
)
2980 warning (_("Skipping obsolete .gdb_index section in %s."),
2982 warning_printed
= 1;
2986 /* Index version 4 uses a different hash function than index version
2989 Versions earlier than 6 did not emit psymbols for inlined
2990 functions. Using these files will cause GDB not to be able to
2991 set breakpoints on inlined functions by name, so we ignore these
2992 indices unless the user has done
2993 "set use-deprecated-index-sections on". */
2994 if (version
< 6 && !deprecated_ok
)
2996 static int warning_printed
= 0;
2997 if (!warning_printed
)
3000 Skipping deprecated .gdb_index section in %s.\n\
3001 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3002 to use the section anyway."),
3004 warning_printed
= 1;
3008 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3009 of the TU (for symbols coming from TUs),
3010 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3011 Plus gold-generated indices can have duplicate entries for global symbols,
3012 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3013 These are just performance bugs, and we can't distinguish gdb-generated
3014 indices from gold-generated ones, so issue no warning here. */
3016 /* Indexes with higher version than the one supported by GDB may be no
3017 longer backward compatible. */
3021 map
->version
= version
;
3023 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3026 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3027 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3031 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3032 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3033 - MAYBE_SWAP (metadata
[i
]))
3037 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3038 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3040 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3043 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3044 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3046 = gdb::array_view
<mapped_index::symbol_table_slot
>
3047 ((mapped_index::symbol_table_slot
*) symbol_table
,
3048 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3051 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3056 /* Callback types for dwarf2_read_gdb_index. */
3058 typedef gdb::function_view
3059 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3060 get_gdb_index_contents_ftype
;
3061 typedef gdb::function_view
3062 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3063 get_gdb_index_contents_dwz_ftype
;
3065 /* Read .gdb_index. If everything went ok, initialize the "quick"
3066 elements of all the CUs and return 1. Otherwise, return 0. */
3069 dwarf2_read_gdb_index
3070 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3071 get_gdb_index_contents_ftype get_gdb_index_contents
,
3072 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3074 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3075 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3076 struct dwz_file
*dwz
;
3077 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3079 gdb::array_view
<const gdb_byte
> main_index_contents
3080 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
->per_bfd
);
3082 if (main_index_contents
.empty ())
3085 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3086 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3087 use_deprecated_index_sections
,
3088 main_index_contents
, map
.get (), &cu_list
,
3089 &cu_list_elements
, &types_list
,
3090 &types_list_elements
))
3093 /* Don't use the index if it's empty. */
3094 if (map
->symbol_table
.empty ())
3097 /* If there is a .dwz file, read it so we can get its CU list as
3099 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
3102 struct mapped_index dwz_map
;
3103 const gdb_byte
*dwz_types_ignore
;
3104 offset_type dwz_types_elements_ignore
;
3106 gdb::array_view
<const gdb_byte
> dwz_index_content
3107 = get_gdb_index_contents_dwz (objfile
, dwz
);
3109 if (dwz_index_content
.empty ())
3112 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3113 1, dwz_index_content
, &dwz_map
,
3114 &dwz_list
, &dwz_list_elements
,
3116 &dwz_types_elements_ignore
))
3118 warning (_("could not read '.gdb_index' section from %s; skipping"),
3119 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3124 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3125 dwz_list
, dwz_list_elements
);
3127 if (types_list_elements
)
3129 /* We can only handle a single .debug_types when we have an
3131 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
3134 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
3136 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3137 types_list
, types_list_elements
);
3140 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3142 dwarf2_per_objfile
->per_bfd
->index_table
= std::move (map
);
3143 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
3144 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
3145 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
3150 /* die_reader_func for dw2_get_file_names. */
3153 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3154 const gdb_byte
*info_ptr
,
3155 struct die_info
*comp_unit_die
)
3157 struct dwarf2_cu
*cu
= reader
->cu
;
3158 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3159 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
3160 struct dwarf2_per_cu_data
*lh_cu
;
3161 struct attribute
*attr
;
3163 struct quick_file_names
*qfn
;
3165 gdb_assert (! this_cu
->is_debug_types
);
3167 /* Our callers never want to match partial units -- instead they
3168 will match the enclosing full CU. */
3169 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3171 this_cu
->v
.quick
->no_file_data
= 1;
3179 sect_offset line_offset
{};
3181 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3182 if (attr
!= nullptr)
3184 struct quick_file_names find_entry
;
3186 line_offset
= (sect_offset
) DW_UNSND (attr
);
3188 /* We may have already read in this line header (TU line header sharing).
3189 If we have we're done. */
3190 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3191 find_entry
.hash
.line_sect_off
= line_offset
;
3192 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3193 &find_entry
, INSERT
);
3196 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3200 lh
= dwarf_decode_line_header (line_offset
, cu
);
3204 lh_cu
->v
.quick
->no_file_data
= 1;
3208 qfn
= XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3209 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3210 qfn
->hash
.line_sect_off
= line_offset
;
3211 gdb_assert (slot
!= NULL
);
3214 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3217 if (strcmp (fnd
.name
, "<unknown>") != 0)
3220 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3222 XOBNEWVEC (&dwarf2_per_objfile
->per_bfd
->obstack
, const char *,
3223 qfn
->num_file_names
);
3225 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3226 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3227 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3228 fnd
.comp_dir
).release ();
3229 qfn
->real_names
= NULL
;
3231 lh_cu
->v
.quick
->file_names
= qfn
;
3234 /* A helper for the "quick" functions which attempts to read the line
3235 table for THIS_CU. */
3237 static struct quick_file_names
*
3238 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3239 dwarf2_per_objfile
*per_objfile
)
3241 /* This should never be called for TUs. */
3242 gdb_assert (! this_cu
->is_debug_types
);
3243 /* Nor type unit groups. */
3244 gdb_assert (! this_cu
->type_unit_group_p ());
3246 if (this_cu
->v
.quick
->file_names
!= NULL
)
3247 return this_cu
->v
.quick
->file_names
;
3248 /* If we know there is no line data, no point in looking again. */
3249 if (this_cu
->v
.quick
->no_file_data
)
3252 cutu_reader
reader (this_cu
, per_objfile
);
3253 if (!reader
.dummy_p
)
3254 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3256 if (this_cu
->v
.quick
->no_file_data
)
3258 return this_cu
->v
.quick
->file_names
;
3261 /* A helper for the "quick" functions which computes and caches the
3262 real path for a given file name from the line table. */
3265 dw2_get_real_path (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3266 struct quick_file_names
*qfn
, int index
)
3268 if (qfn
->real_names
== NULL
)
3269 qfn
->real_names
= OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
3270 qfn
->num_file_names
, const char *);
3272 if (qfn
->real_names
[index
] == NULL
)
3273 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3275 return qfn
->real_names
[index
];
3278 static struct symtab
*
3279 dw2_find_last_source_symtab (struct objfile
*objfile
)
3281 struct dwarf2_per_objfile
*dwarf2_per_objfile
3282 = get_dwarf2_per_objfile (objfile
);
3283 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->per_bfd
->all_comp_units
.back ();
3284 compunit_symtab
*cust
3285 = dw2_instantiate_symtab (dwarf_cu
, dwarf2_per_objfile
, false);
3290 return compunit_primary_filetab (cust
);
3293 /* Traversal function for dw2_forget_cached_source_info. */
3296 dw2_free_cached_file_names (void **slot
, void *info
)
3298 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3300 if (file_data
->real_names
)
3304 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3306 xfree ((void*) file_data
->real_names
[i
]);
3307 file_data
->real_names
[i
] = NULL
;
3315 dw2_forget_cached_source_info (struct objfile
*objfile
)
3317 struct dwarf2_per_objfile
*dwarf2_per_objfile
3318 = get_dwarf2_per_objfile (objfile
);
3320 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3321 dw2_free_cached_file_names
, NULL
);
3324 /* Helper function for dw2_map_symtabs_matching_filename that expands
3325 the symtabs and calls the iterator. */
3328 dw2_map_expand_apply (struct objfile
*objfile
,
3329 struct dwarf2_per_cu_data
*per_cu
,
3330 const char *name
, const char *real_path
,
3331 gdb::function_view
<bool (symtab
*)> callback
)
3333 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3335 /* Don't visit already-expanded CUs. */
3336 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3337 if (per_objfile
->symtab_set_p (per_cu
))
3340 /* This may expand more than one symtab, and we want to iterate over
3342 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3344 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3345 last_made
, callback
);
3348 /* Implementation of the map_symtabs_matching_filename method. */
3351 dw2_map_symtabs_matching_filename
3352 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3353 gdb::function_view
<bool (symtab
*)> callback
)
3355 const char *name_basename
= lbasename (name
);
3356 struct dwarf2_per_objfile
*dwarf2_per_objfile
3357 = get_dwarf2_per_objfile (objfile
);
3359 /* The rule is CUs specify all the files, including those used by
3360 any TU, so there's no need to scan TUs here. */
3362 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3364 /* We only need to look at symtabs not already expanded. */
3365 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3368 quick_file_names
*file_data
3369 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3370 if (file_data
== NULL
)
3373 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3375 const char *this_name
= file_data
->file_names
[j
];
3376 const char *this_real_name
;
3378 if (compare_filenames_for_search (this_name
, name
))
3380 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3386 /* Before we invoke realpath, which can get expensive when many
3387 files are involved, do a quick comparison of the basenames. */
3388 if (! basenames_may_differ
3389 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3392 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
3394 if (compare_filenames_for_search (this_real_name
, name
))
3396 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3402 if (real_path
!= NULL
)
3404 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3405 gdb_assert (IS_ABSOLUTE_PATH (name
));
3406 if (this_real_name
!= NULL
3407 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3409 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3421 /* Struct used to manage iterating over all CUs looking for a symbol. */
3423 struct dw2_symtab_iterator
3425 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3426 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3427 /* If set, only look for symbols that match that block. Valid values are
3428 GLOBAL_BLOCK and STATIC_BLOCK. */
3429 gdb::optional
<block_enum
> block_index
;
3430 /* The kind of symbol we're looking for. */
3432 /* The list of CUs from the index entry of the symbol,
3433 or NULL if not found. */
3435 /* The next element in VEC to look at. */
3437 /* The number of elements in VEC, or zero if there is no match. */
3439 /* Have we seen a global version of the symbol?
3440 If so we can ignore all further global instances.
3441 This is to work around gold/15646, inefficient gold-generated
3446 /* Initialize the index symtab iterator ITER. */
3449 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3450 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3451 gdb::optional
<block_enum
> block_index
,
3455 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3456 iter
->block_index
= block_index
;
3457 iter
->domain
= domain
;
3459 iter
->global_seen
= 0;
3461 mapped_index
*index
= dwarf2_per_objfile
->per_bfd
->index_table
.get ();
3463 /* index is NULL if OBJF_READNOW. */
3464 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3465 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3473 /* Return the next matching CU or NULL if there are no more. */
3475 static struct dwarf2_per_cu_data
*
3476 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3478 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3480 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3482 offset_type cu_index_and_attrs
=
3483 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3484 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3485 gdb_index_symbol_kind symbol_kind
=
3486 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3487 /* Only check the symbol attributes if they're present.
3488 Indices prior to version 7 don't record them,
3489 and indices >= 7 may elide them for certain symbols
3490 (gold does this). */
3492 (dwarf2_per_objfile
->per_bfd
->index_table
->version
>= 7
3493 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3495 /* Don't crash on bad data. */
3496 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3497 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
3499 complaint (_(".gdb_index entry has bad CU index"
3501 objfile_name (dwarf2_per_objfile
->objfile
));
3505 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
3507 /* Skip if already read in. */
3508 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3511 /* Check static vs global. */
3514 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3516 if (iter
->block_index
.has_value ())
3518 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3520 if (is_static
!= want_static
)
3524 /* Work around gold/15646. */
3525 if (!is_static
&& iter
->global_seen
)
3528 iter
->global_seen
= 1;
3531 /* Only check the symbol's kind if it has one. */
3534 switch (iter
->domain
)
3537 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3538 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3539 /* Some types are also in VAR_DOMAIN. */
3540 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3544 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3548 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3552 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3567 static struct compunit_symtab
*
3568 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3569 const char *name
, domain_enum domain
)
3571 struct compunit_symtab
*stab_best
= NULL
;
3572 struct dwarf2_per_objfile
*dwarf2_per_objfile
3573 = get_dwarf2_per_objfile (objfile
);
3575 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3577 struct dw2_symtab_iterator iter
;
3578 struct dwarf2_per_cu_data
*per_cu
;
3580 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3582 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3584 struct symbol
*sym
, *with_opaque
= NULL
;
3585 struct compunit_symtab
*stab
3586 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3587 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3588 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3590 sym
= block_find_symbol (block
, name
, domain
,
3591 block_find_non_opaque_type_preferred
,
3594 /* Some caution must be observed with overloaded functions
3595 and methods, since the index will not contain any overload
3596 information (but NAME might contain it). */
3599 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3601 if (with_opaque
!= NULL
3602 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3605 /* Keep looking through other CUs. */
3612 dw2_print_stats (struct objfile
*objfile
)
3614 struct dwarf2_per_objfile
*dwarf2_per_objfile
3615 = get_dwarf2_per_objfile (objfile
);
3616 int total
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3617 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3620 for (int i
= 0; i
< total
; ++i
)
3622 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3624 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
3627 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3628 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3631 /* This dumps minimal information about the index.
3632 It is called via "mt print objfiles".
3633 One use is to verify .gdb_index has been loaded by the
3634 gdb.dwarf2/gdb-index.exp testcase. */
3637 dw2_dump (struct objfile
*objfile
)
3639 struct dwarf2_per_objfile
*dwarf2_per_objfile
3640 = get_dwarf2_per_objfile (objfile
);
3642 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
3643 printf_filtered (".gdb_index:");
3644 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
)
3646 printf_filtered (" version %d\n",
3647 dwarf2_per_objfile
->per_bfd
->index_table
->version
);
3650 printf_filtered (" faked for \"readnow\"\n");
3651 printf_filtered ("\n");
3655 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3656 const char *func_name
)
3658 struct dwarf2_per_objfile
*dwarf2_per_objfile
3659 = get_dwarf2_per_objfile (objfile
);
3661 struct dw2_symtab_iterator iter
;
3662 struct dwarf2_per_cu_data
*per_cu
;
3664 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3666 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3667 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3672 dw2_expand_all_symtabs (struct objfile
*objfile
)
3674 struct dwarf2_per_objfile
*dwarf2_per_objfile
3675 = get_dwarf2_per_objfile (objfile
);
3676 int total_units
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3677 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3679 for (int i
= 0; i
< total_units
; ++i
)
3681 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3683 /* We don't want to directly expand a partial CU, because if we
3684 read it with the wrong language, then assertion failures can
3685 be triggered later on. See PR symtab/23010. So, tell
3686 dw2_instantiate_symtab to skip partial CUs -- any important
3687 partial CU will be read via DW_TAG_imported_unit anyway. */
3688 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, true);
3693 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3694 const char *fullname
)
3696 struct dwarf2_per_objfile
*dwarf2_per_objfile
3697 = get_dwarf2_per_objfile (objfile
);
3699 /* We don't need to consider type units here.
3700 This is only called for examining code, e.g. expand_line_sal.
3701 There can be an order of magnitude (or more) more type units
3702 than comp units, and we avoid them if we can. */
3704 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3706 /* We only need to look at symtabs not already expanded. */
3707 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3710 quick_file_names
*file_data
3711 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3712 if (file_data
== NULL
)
3715 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3717 const char *this_fullname
= file_data
->file_names
[j
];
3719 if (filename_cmp (this_fullname
, fullname
) == 0)
3721 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3729 dw2_expand_symtabs_matching_symbol
3730 (mapped_index_base
&index
,
3731 const lookup_name_info
&lookup_name_in
,
3732 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3733 enum search_domain kind
,
3734 gdb::function_view
<bool (offset_type
)> match_callback
);
3737 dw2_expand_symtabs_matching_one
3738 (dwarf2_per_cu_data
*per_cu
,
3739 dwarf2_per_objfile
*per_objfile
,
3740 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3741 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3744 dw2_map_matching_symbols
3745 (struct objfile
*objfile
,
3746 const lookup_name_info
&name
, domain_enum domain
,
3748 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3749 symbol_compare_ftype
*ordered_compare
)
3752 struct dwarf2_per_objfile
*dwarf2_per_objfile
3753 = get_dwarf2_per_objfile (objfile
);
3755 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3757 if (dwarf2_per_objfile
->per_bfd
->index_table
!= nullptr)
3759 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3760 here though if the current language is Ada for a non-Ada objfile
3762 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
3764 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3765 auto matcher
= [&] (const char *symname
)
3767 if (ordered_compare
== nullptr)
3769 return ordered_compare (symname
, match_name
) == 0;
3772 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3773 [&] (offset_type namei
)
3775 struct dw2_symtab_iterator iter
;
3776 struct dwarf2_per_cu_data
*per_cu
;
3778 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3780 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3781 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
3788 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3789 proceed assuming all symtabs have been read in. */
3792 for (compunit_symtab
*cust
: objfile
->compunits ())
3794 const struct block
*block
;
3798 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3799 if (!iterate_over_symbols_terminated (block
, name
,
3805 /* Starting from a search name, return the string that finds the upper
3806 bound of all strings that start with SEARCH_NAME in a sorted name
3807 list. Returns the empty string to indicate that the upper bound is
3808 the end of the list. */
3811 make_sort_after_prefix_name (const char *search_name
)
3813 /* When looking to complete "func", we find the upper bound of all
3814 symbols that start with "func" by looking for where we'd insert
3815 the closest string that would follow "func" in lexicographical
3816 order. Usually, that's "func"-with-last-character-incremented,
3817 i.e. "fund". Mind non-ASCII characters, though. Usually those
3818 will be UTF-8 multi-byte sequences, but we can't be certain.
3819 Especially mind the 0xff character, which is a valid character in
3820 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3821 rule out compilers allowing it in identifiers. Note that
3822 conveniently, strcmp/strcasecmp are specified to compare
3823 characters interpreted as unsigned char. So what we do is treat
3824 the whole string as a base 256 number composed of a sequence of
3825 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3826 to 0, and carries 1 to the following more-significant position.
3827 If the very first character in SEARCH_NAME ends up incremented
3828 and carries/overflows, then the upper bound is the end of the
3829 list. The string after the empty string is also the empty
3832 Some examples of this operation:
3834 SEARCH_NAME => "+1" RESULT
3838 "\xff" "a" "\xff" => "\xff" "b"
3843 Then, with these symbols for example:
3849 completing "func" looks for symbols between "func" and
3850 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3851 which finds "func" and "func1", but not "fund".
3855 funcÿ (Latin1 'ÿ' [0xff])
3859 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3860 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3864 ÿÿ (Latin1 'ÿ' [0xff])
3867 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3868 the end of the list.
3870 std::string after
= search_name
;
3871 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3873 if (!after
.empty ())
3874 after
.back () = (unsigned char) after
.back () + 1;
3878 /* See declaration. */
3880 std::pair
<std::vector
<name_component
>::const_iterator
,
3881 std::vector
<name_component
>::const_iterator
>
3882 mapped_index_base::find_name_components_bounds
3883 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3886 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3888 const char *lang_name
3889 = lookup_name_without_params
.language_lookup_name (lang
);
3891 /* Comparison function object for lower_bound that matches against a
3892 given symbol name. */
3893 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3896 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3897 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3898 return name_cmp (elem_name
, name
) < 0;
3901 /* Comparison function object for upper_bound that matches against a
3902 given symbol name. */
3903 auto lookup_compare_upper
= [&] (const char *name
,
3904 const name_component
&elem
)
3906 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3907 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3908 return name_cmp (name
, elem_name
) < 0;
3911 auto begin
= this->name_components
.begin ();
3912 auto end
= this->name_components
.end ();
3914 /* Find the lower bound. */
3917 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3920 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3923 /* Find the upper bound. */
3926 if (lookup_name_without_params
.completion_mode ())
3928 /* In completion mode, we want UPPER to point past all
3929 symbols names that have the same prefix. I.e., with
3930 these symbols, and completing "func":
3932 function << lower bound
3934 other_function << upper bound
3936 We find the upper bound by looking for the insertion
3937 point of "func"-with-last-character-incremented,
3939 std::string after
= make_sort_after_prefix_name (lang_name
);
3942 return std::lower_bound (lower
, end
, after
.c_str (),
3943 lookup_compare_lower
);
3946 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3949 return {lower
, upper
};
3952 /* See declaration. */
3955 mapped_index_base::build_name_components ()
3957 if (!this->name_components
.empty ())
3960 this->name_components_casing
= case_sensitivity
;
3962 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3964 /* The code below only knows how to break apart components of C++
3965 symbol names (and other languages that use '::' as
3966 namespace/module separator) and Ada symbol names. */
3967 auto count
= this->symbol_name_count ();
3968 for (offset_type idx
= 0; idx
< count
; idx
++)
3970 if (this->symbol_name_slot_invalid (idx
))
3973 const char *name
= this->symbol_name_at (idx
);
3975 /* Add each name component to the name component table. */
3976 unsigned int previous_len
= 0;
3978 if (strstr (name
, "::") != nullptr)
3980 for (unsigned int current_len
= cp_find_first_component (name
);
3981 name
[current_len
] != '\0';
3982 current_len
+= cp_find_first_component (name
+ current_len
))
3984 gdb_assert (name
[current_len
] == ':');
3985 this->name_components
.push_back ({previous_len
, idx
});
3986 /* Skip the '::'. */
3988 previous_len
= current_len
;
3993 /* Handle the Ada encoded (aka mangled) form here. */
3994 for (const char *iter
= strstr (name
, "__");
3996 iter
= strstr (iter
, "__"))
3998 this->name_components
.push_back ({previous_len
, idx
});
4000 previous_len
= iter
- name
;
4004 this->name_components
.push_back ({previous_len
, idx
});
4007 /* Sort name_components elements by name. */
4008 auto name_comp_compare
= [&] (const name_component
&left
,
4009 const name_component
&right
)
4011 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4012 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4014 const char *left_name
= left_qualified
+ left
.name_offset
;
4015 const char *right_name
= right_qualified
+ right
.name_offset
;
4017 return name_cmp (left_name
, right_name
) < 0;
4020 std::sort (this->name_components
.begin (),
4021 this->name_components
.end (),
4025 /* Helper for dw2_expand_symtabs_matching that works with a
4026 mapped_index_base instead of the containing objfile. This is split
4027 to a separate function in order to be able to unit test the
4028 name_components matching using a mock mapped_index_base. For each
4029 symbol name that matches, calls MATCH_CALLBACK, passing it the
4030 symbol's index in the mapped_index_base symbol table. */
4033 dw2_expand_symtabs_matching_symbol
4034 (mapped_index_base
&index
,
4035 const lookup_name_info
&lookup_name_in
,
4036 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4037 enum search_domain kind
,
4038 gdb::function_view
<bool (offset_type
)> match_callback
)
4040 lookup_name_info lookup_name_without_params
4041 = lookup_name_in
.make_ignore_params ();
4043 /* Build the symbol name component sorted vector, if we haven't
4045 index
.build_name_components ();
4047 /* The same symbol may appear more than once in the range though.
4048 E.g., if we're looking for symbols that complete "w", and we have
4049 a symbol named "w1::w2", we'll find the two name components for
4050 that same symbol in the range. To be sure we only call the
4051 callback once per symbol, we first collect the symbol name
4052 indexes that matched in a temporary vector and ignore
4054 std::vector
<offset_type
> matches
;
4056 struct name_and_matcher
4058 symbol_name_matcher_ftype
*matcher
;
4061 bool operator== (const name_and_matcher
&other
) const
4063 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4067 /* A vector holding all the different symbol name matchers, for all
4069 std::vector
<name_and_matcher
> matchers
;
4071 for (int i
= 0; i
< nr_languages
; i
++)
4073 enum language lang_e
= (enum language
) i
;
4075 const language_defn
*lang
= language_def (lang_e
);
4076 symbol_name_matcher_ftype
*name_matcher
4077 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4079 name_and_matcher key
{
4081 lookup_name_without_params
.language_lookup_name (lang_e
)
4084 /* Don't insert the same comparison routine more than once.
4085 Note that we do this linear walk. This is not a problem in
4086 practice because the number of supported languages is
4088 if (std::find (matchers
.begin (), matchers
.end (), key
)
4091 matchers
.push_back (std::move (key
));
4094 = index
.find_name_components_bounds (lookup_name_without_params
,
4097 /* Now for each symbol name in range, check to see if we have a name
4098 match, and if so, call the MATCH_CALLBACK callback. */
4100 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4102 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4104 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4105 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4108 matches
.push_back (bounds
.first
->idx
);
4112 std::sort (matches
.begin (), matches
.end ());
4114 /* Finally call the callback, once per match. */
4116 for (offset_type idx
: matches
)
4120 if (!match_callback (idx
))
4126 /* Above we use a type wider than idx's for 'prev', since 0 and
4127 (offset_type)-1 are both possible values. */
4128 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4133 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4135 /* A mock .gdb_index/.debug_names-like name index table, enough to
4136 exercise dw2_expand_symtabs_matching_symbol, which works with the
4137 mapped_index_base interface. Builds an index from the symbol list
4138 passed as parameter to the constructor. */
4139 class mock_mapped_index
: public mapped_index_base
4142 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4143 : m_symbol_table (symbols
)
4146 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4148 /* Return the number of names in the symbol table. */
4149 size_t symbol_name_count () const override
4151 return m_symbol_table
.size ();
4154 /* Get the name of the symbol at IDX in the symbol table. */
4155 const char *symbol_name_at (offset_type idx
) const override
4157 return m_symbol_table
[idx
];
4161 gdb::array_view
<const char *> m_symbol_table
;
4164 /* Convenience function that converts a NULL pointer to a "<null>"
4165 string, to pass to print routines. */
4168 string_or_null (const char *str
)
4170 return str
!= NULL
? str
: "<null>";
4173 /* Check if a lookup_name_info built from
4174 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4175 index. EXPECTED_LIST is the list of expected matches, in expected
4176 matching order. If no match expected, then an empty list is
4177 specified. Returns true on success. On failure prints a warning
4178 indicating the file:line that failed, and returns false. */
4181 check_match (const char *file
, int line
,
4182 mock_mapped_index
&mock_index
,
4183 const char *name
, symbol_name_match_type match_type
,
4184 bool completion_mode
,
4185 std::initializer_list
<const char *> expected_list
)
4187 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4189 bool matched
= true;
4191 auto mismatch
= [&] (const char *expected_str
,
4194 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4195 "expected=\"%s\", got=\"%s\"\n"),
4197 (match_type
== symbol_name_match_type::FULL
4199 name
, string_or_null (expected_str
), string_or_null (got
));
4203 auto expected_it
= expected_list
.begin ();
4204 auto expected_end
= expected_list
.end ();
4206 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4208 [&] (offset_type idx
)
4210 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4211 const char *expected_str
4212 = expected_it
== expected_end
? NULL
: *expected_it
++;
4214 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4215 mismatch (expected_str
, matched_name
);
4219 const char *expected_str
4220 = expected_it
== expected_end
? NULL
: *expected_it
++;
4221 if (expected_str
!= NULL
)
4222 mismatch (expected_str
, NULL
);
4227 /* The symbols added to the mock mapped_index for testing (in
4229 static const char *test_symbols
[] = {
4238 "ns2::tmpl<int>::foo2",
4239 "(anonymous namespace)::A::B::C",
4241 /* These are used to check that the increment-last-char in the
4242 matching algorithm for completion doesn't match "t1_fund" when
4243 completing "t1_func". */
4249 /* A UTF-8 name with multi-byte sequences to make sure that
4250 cp-name-parser understands this as a single identifier ("função"
4251 is "function" in PT). */
4254 /* \377 (0xff) is Latin1 'ÿ'. */
4257 /* \377 (0xff) is Latin1 'ÿ'. */
4261 /* A name with all sorts of complications. Starts with "z" to make
4262 it easier for the completion tests below. */
4263 #define Z_SYM_NAME \
4264 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4265 "::tuple<(anonymous namespace)::ui*, " \
4266 "std::default_delete<(anonymous namespace)::ui>, void>"
4271 /* Returns true if the mapped_index_base::find_name_component_bounds
4272 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4273 in completion mode. */
4276 check_find_bounds_finds (mapped_index_base
&index
,
4277 const char *search_name
,
4278 gdb::array_view
<const char *> expected_syms
)
4280 lookup_name_info
lookup_name (search_name
,
4281 symbol_name_match_type::FULL
, true);
4283 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4286 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4287 if (distance
!= expected_syms
.size ())
4290 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4292 auto nc_elem
= bounds
.first
+ exp_elem
;
4293 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4294 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4301 /* Test the lower-level mapped_index::find_name_component_bounds
4305 test_mapped_index_find_name_component_bounds ()
4307 mock_mapped_index
mock_index (test_symbols
);
4309 mock_index
.build_name_components ();
4311 /* Test the lower-level mapped_index::find_name_component_bounds
4312 method in completion mode. */
4314 static const char *expected_syms
[] = {
4319 SELF_CHECK (check_find_bounds_finds (mock_index
,
4320 "t1_func", expected_syms
));
4323 /* Check that the increment-last-char in the name matching algorithm
4324 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4326 static const char *expected_syms1
[] = {
4330 SELF_CHECK (check_find_bounds_finds (mock_index
,
4331 "\377", expected_syms1
));
4333 static const char *expected_syms2
[] = {
4336 SELF_CHECK (check_find_bounds_finds (mock_index
,
4337 "\377\377", expected_syms2
));
4341 /* Test dw2_expand_symtabs_matching_symbol. */
4344 test_dw2_expand_symtabs_matching_symbol ()
4346 mock_mapped_index
mock_index (test_symbols
);
4348 /* We let all tests run until the end even if some fails, for debug
4350 bool any_mismatch
= false;
4352 /* Create the expected symbols list (an initializer_list). Needed
4353 because lists have commas, and we need to pass them to CHECK,
4354 which is a macro. */
4355 #define EXPECT(...) { __VA_ARGS__ }
4357 /* Wrapper for check_match that passes down the current
4358 __FILE__/__LINE__. */
4359 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4360 any_mismatch |= !check_match (__FILE__, __LINE__, \
4362 NAME, MATCH_TYPE, COMPLETION_MODE, \
4365 /* Identity checks. */
4366 for (const char *sym
: test_symbols
)
4368 /* Should be able to match all existing symbols. */
4369 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4372 /* Should be able to match all existing symbols with
4374 std::string with_params
= std::string (sym
) + "(int)";
4375 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4378 /* Should be able to match all existing symbols with
4379 parameters and qualifiers. */
4380 with_params
= std::string (sym
) + " ( int ) const";
4381 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4384 /* This should really find sym, but cp-name-parser.y doesn't
4385 know about lvalue/rvalue qualifiers yet. */
4386 with_params
= std::string (sym
) + " ( int ) &&";
4387 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4391 /* Check that the name matching algorithm for completion doesn't get
4392 confused with Latin1 'ÿ' / 0xff. */
4394 static const char str
[] = "\377";
4395 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4396 EXPECT ("\377", "\377\377123"));
4399 /* Check that the increment-last-char in the matching algorithm for
4400 completion doesn't match "t1_fund" when completing "t1_func". */
4402 static const char str
[] = "t1_func";
4403 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4404 EXPECT ("t1_func", "t1_func1"));
4407 /* Check that completion mode works at each prefix of the expected
4410 static const char str
[] = "function(int)";
4411 size_t len
= strlen (str
);
4414 for (size_t i
= 1; i
< len
; i
++)
4416 lookup
.assign (str
, i
);
4417 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4418 EXPECT ("function"));
4422 /* While "w" is a prefix of both components, the match function
4423 should still only be called once. */
4425 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4427 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4431 /* Same, with a "complicated" symbol. */
4433 static const char str
[] = Z_SYM_NAME
;
4434 size_t len
= strlen (str
);
4437 for (size_t i
= 1; i
< len
; i
++)
4439 lookup
.assign (str
, i
);
4440 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4441 EXPECT (Z_SYM_NAME
));
4445 /* In FULL mode, an incomplete symbol doesn't match. */
4447 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4451 /* A complete symbol with parameters matches any overload, since the
4452 index has no overload info. */
4454 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4455 EXPECT ("std::zfunction", "std::zfunction2"));
4456 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4457 EXPECT ("std::zfunction", "std::zfunction2"));
4458 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4459 EXPECT ("std::zfunction", "std::zfunction2"));
4462 /* Check that whitespace is ignored appropriately. A symbol with a
4463 template argument list. */
4465 static const char expected
[] = "ns::foo<int>";
4466 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4468 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4472 /* Check that whitespace is ignored appropriately. A symbol with a
4473 template argument list that includes a pointer. */
4475 static const char expected
[] = "ns::foo<char*>";
4476 /* Try both completion and non-completion modes. */
4477 static const bool completion_mode
[2] = {false, true};
4478 for (size_t i
= 0; i
< 2; i
++)
4480 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4481 completion_mode
[i
], EXPECT (expected
));
4482 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4483 completion_mode
[i
], EXPECT (expected
));
4485 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4486 completion_mode
[i
], EXPECT (expected
));
4487 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4488 completion_mode
[i
], EXPECT (expected
));
4493 /* Check method qualifiers are ignored. */
4494 static const char expected
[] = "ns::foo<char*>";
4495 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4496 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4497 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4498 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4499 CHECK_MATCH ("foo < char * > ( int ) const",
4500 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4501 CHECK_MATCH ("foo < char * > ( int ) &&",
4502 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4505 /* Test lookup names that don't match anything. */
4507 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4510 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4514 /* Some wild matching tests, exercising "(anonymous namespace)",
4515 which should not be confused with a parameter list. */
4517 static const char *syms
[] = {
4521 "A :: B :: C ( int )",
4526 for (const char *s
: syms
)
4528 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4529 EXPECT ("(anonymous namespace)::A::B::C"));
4534 static const char expected
[] = "ns2::tmpl<int>::foo2";
4535 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4537 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4541 SELF_CHECK (!any_mismatch
);
4550 test_mapped_index_find_name_component_bounds ();
4551 test_dw2_expand_symtabs_matching_symbol ();
4554 }} // namespace selftests::dw2_expand_symtabs_matching
4556 #endif /* GDB_SELF_TEST */
4558 /* If FILE_MATCHER is NULL or if PER_CU has
4559 dwarf2_per_cu_quick_data::MARK set (see
4560 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4561 EXPANSION_NOTIFY on it. */
4564 dw2_expand_symtabs_matching_one
4565 (dwarf2_per_cu_data
*per_cu
,
4566 dwarf2_per_objfile
*per_objfile
,
4567 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4568 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4570 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4572 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4574 compunit_symtab
*symtab
4575 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4576 gdb_assert (symtab
!= nullptr);
4578 if (expansion_notify
!= NULL
&& symtab_was_null
)
4579 expansion_notify (symtab
);
4583 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4584 matched, to expand corresponding CUs that were marked. IDX is the
4585 index of the symbol name that matched. */
4588 dw2_expand_marked_cus
4589 (dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4590 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4591 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4594 offset_type
*vec
, vec_len
, vec_idx
;
4595 bool global_seen
= false;
4596 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4598 vec
= (offset_type
*) (index
.constant_pool
4599 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4600 vec_len
= MAYBE_SWAP (vec
[0]);
4601 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4603 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4604 /* This value is only valid for index versions >= 7. */
4605 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4606 gdb_index_symbol_kind symbol_kind
=
4607 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4608 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4609 /* Only check the symbol attributes if they're present.
4610 Indices prior to version 7 don't record them,
4611 and indices >= 7 may elide them for certain symbols
4612 (gold does this). */
4615 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4617 /* Work around gold/15646. */
4620 if (!is_static
&& global_seen
)
4626 /* Only check the symbol's kind if it has one. */
4631 case VARIABLES_DOMAIN
:
4632 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4635 case FUNCTIONS_DOMAIN
:
4636 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4640 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4643 case MODULES_DOMAIN
:
4644 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4652 /* Don't crash on bad data. */
4653 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
4654 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
4656 complaint (_(".gdb_index entry has bad CU index"
4658 objfile_name (dwarf2_per_objfile
->objfile
));
4662 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
4663 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, file_matcher
,
4668 /* If FILE_MATCHER is non-NULL, set all the
4669 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4670 that match FILE_MATCHER. */
4673 dw_expand_symtabs_matching_file_matcher
4674 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4675 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4677 if (file_matcher
== NULL
)
4680 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4682 NULL
, xcalloc
, xfree
));
4683 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4685 NULL
, xcalloc
, xfree
));
4687 /* The rule is CUs specify all the files, including those used by
4688 any TU, so there's no need to scan TUs here. */
4690 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4694 per_cu
->v
.quick
->mark
= 0;
4696 /* We only need to look at symtabs not already expanded. */
4697 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4700 quick_file_names
*file_data
4701 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4702 if (file_data
== NULL
)
4705 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4707 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4709 per_cu
->v
.quick
->mark
= 1;
4713 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4715 const char *this_real_name
;
4717 if (file_matcher (file_data
->file_names
[j
], false))
4719 per_cu
->v
.quick
->mark
= 1;
4723 /* Before we invoke realpath, which can get expensive when many
4724 files are involved, do a quick comparison of the basenames. */
4725 if (!basenames_may_differ
4726 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4730 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
4732 if (file_matcher (this_real_name
, false))
4734 per_cu
->v
.quick
->mark
= 1;
4739 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4740 ? visited_found
.get ()
4741 : visited_not_found
.get (),
4748 dw2_expand_symtabs_matching
4749 (struct objfile
*objfile
,
4750 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4751 const lookup_name_info
*lookup_name
,
4752 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4753 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4754 enum search_domain kind
)
4756 struct dwarf2_per_objfile
*dwarf2_per_objfile
4757 = get_dwarf2_per_objfile (objfile
);
4759 /* index_table is NULL if OBJF_READNOW. */
4760 if (!dwarf2_per_objfile
->per_bfd
->index_table
)
4763 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4765 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4767 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4771 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
4772 file_matcher
, expansion_notify
);
4777 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4779 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4781 kind
, [&] (offset_type idx
)
4783 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4784 expansion_notify
, kind
);
4789 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4792 static struct compunit_symtab
*
4793 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4798 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4799 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4802 if (cust
->includes
== NULL
)
4805 for (i
= 0; cust
->includes
[i
]; ++i
)
4807 struct compunit_symtab
*s
= cust
->includes
[i
];
4809 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4817 static struct compunit_symtab
*
4818 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4819 struct bound_minimal_symbol msymbol
,
4821 struct obj_section
*section
,
4824 struct dwarf2_per_cu_data
*data
;
4825 struct compunit_symtab
*result
;
4827 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4830 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4831 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4832 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4836 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4837 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4838 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4839 paddress (objfile
->arch (), pc
));
4841 result
= recursively_find_pc_sect_compunit_symtab
4842 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4844 gdb_assert (result
!= NULL
);
4849 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4850 void *data
, int need_fullname
)
4852 struct dwarf2_per_objfile
*dwarf2_per_objfile
4853 = get_dwarf2_per_objfile (objfile
);
4855 if (!dwarf2_per_objfile
->per_bfd
->filenames_cache
)
4857 dwarf2_per_objfile
->per_bfd
->filenames_cache
.emplace ();
4859 htab_up
visited (htab_create_alloc (10,
4860 htab_hash_pointer
, htab_eq_pointer
,
4861 NULL
, xcalloc
, xfree
));
4863 /* The rule is CUs specify all the files, including those used
4864 by any TU, so there's no need to scan TUs here. We can
4865 ignore file names coming from already-expanded CUs. */
4867 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4869 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4871 void **slot
= htab_find_slot (visited
.get (),
4872 per_cu
->v
.quick
->file_names
,
4875 *slot
= per_cu
->v
.quick
->file_names
;
4879 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4881 /* We only need to look at symtabs not already expanded. */
4882 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4885 quick_file_names
*file_data
4886 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4887 if (file_data
== NULL
)
4890 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4893 /* Already visited. */
4898 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4900 const char *filename
= file_data
->file_names
[j
];
4901 dwarf2_per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4906 dwarf2_per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4908 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4911 this_real_name
= gdb_realpath (filename
);
4912 (*fun
) (filename
, this_real_name
.get (), data
);
4917 dw2_has_symbols (struct objfile
*objfile
)
4922 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4925 dw2_find_last_source_symtab
,
4926 dw2_forget_cached_source_info
,
4927 dw2_map_symtabs_matching_filename
,
4932 dw2_expand_symtabs_for_function
,
4933 dw2_expand_all_symtabs
,
4934 dw2_expand_symtabs_with_fullname
,
4935 dw2_map_matching_symbols
,
4936 dw2_expand_symtabs_matching
,
4937 dw2_find_pc_sect_compunit_symtab
,
4939 dw2_map_symbol_filenames
4942 /* DWARF-5 debug_names reader. */
4944 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4945 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4947 /* A helper function that reads the .debug_names section in SECTION
4948 and fills in MAP. FILENAME is the name of the file containing the
4949 section; it is used for error reporting.
4951 Returns true if all went well, false otherwise. */
4954 read_debug_names_from_section (struct objfile
*objfile
,
4955 const char *filename
,
4956 struct dwarf2_section_info
*section
,
4957 mapped_debug_names
&map
)
4959 if (section
->empty ())
4962 /* Older elfutils strip versions could keep the section in the main
4963 executable while splitting it for the separate debug info file. */
4964 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4967 section
->read (objfile
);
4969 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4971 const gdb_byte
*addr
= section
->buffer
;
4973 bfd
*const abfd
= section
->get_bfd_owner ();
4975 unsigned int bytes_read
;
4976 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4979 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4980 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4981 if (bytes_read
+ length
!= section
->size
)
4983 /* There may be multiple per-CU indices. */
4984 warning (_("Section .debug_names in %s length %s does not match "
4985 "section length %s, ignoring .debug_names."),
4986 filename
, plongest (bytes_read
+ length
),
4987 pulongest (section
->size
));
4991 /* The version number. */
4992 uint16_t version
= read_2_bytes (abfd
, addr
);
4996 warning (_("Section .debug_names in %s has unsupported version %d, "
4997 "ignoring .debug_names."),
5003 uint16_t padding
= read_2_bytes (abfd
, addr
);
5007 warning (_("Section .debug_names in %s has unsupported padding %d, "
5008 "ignoring .debug_names."),
5013 /* comp_unit_count - The number of CUs in the CU list. */
5014 map
.cu_count
= read_4_bytes (abfd
, addr
);
5017 /* local_type_unit_count - The number of TUs in the local TU
5019 map
.tu_count
= read_4_bytes (abfd
, addr
);
5022 /* foreign_type_unit_count - The number of TUs in the foreign TU
5024 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5026 if (foreign_tu_count
!= 0)
5028 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5029 "ignoring .debug_names."),
5030 filename
, static_cast<unsigned long> (foreign_tu_count
));
5034 /* bucket_count - The number of hash buckets in the hash lookup
5036 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5039 /* name_count - The number of unique names in the index. */
5040 map
.name_count
= read_4_bytes (abfd
, addr
);
5043 /* abbrev_table_size - The size in bytes of the abbreviations
5045 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5048 /* augmentation_string_size - The size in bytes of the augmentation
5049 string. This value is rounded up to a multiple of 4. */
5050 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5052 map
.augmentation_is_gdb
= ((augmentation_string_size
5053 == sizeof (dwarf5_augmentation
))
5054 && memcmp (addr
, dwarf5_augmentation
,
5055 sizeof (dwarf5_augmentation
)) == 0);
5056 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5057 addr
+= augmentation_string_size
;
5060 map
.cu_table_reordered
= addr
;
5061 addr
+= map
.cu_count
* map
.offset_size
;
5063 /* List of Local TUs */
5064 map
.tu_table_reordered
= addr
;
5065 addr
+= map
.tu_count
* map
.offset_size
;
5067 /* Hash Lookup Table */
5068 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5069 addr
+= map
.bucket_count
* 4;
5070 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5071 addr
+= map
.name_count
* 4;
5074 map
.name_table_string_offs_reordered
= addr
;
5075 addr
+= map
.name_count
* map
.offset_size
;
5076 map
.name_table_entry_offs_reordered
= addr
;
5077 addr
+= map
.name_count
* map
.offset_size
;
5079 const gdb_byte
*abbrev_table_start
= addr
;
5082 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5087 const auto insertpair
5088 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5089 if (!insertpair
.second
)
5091 warning (_("Section .debug_names in %s has duplicate index %s, "
5092 "ignoring .debug_names."),
5093 filename
, pulongest (index_num
));
5096 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5097 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5102 mapped_debug_names::index_val::attr attr
;
5103 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5105 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5107 if (attr
.form
== DW_FORM_implicit_const
)
5109 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5113 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5115 indexval
.attr_vec
.push_back (std::move (attr
));
5118 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5120 warning (_("Section .debug_names in %s has abbreviation_table "
5121 "of size %s vs. written as %u, ignoring .debug_names."),
5122 filename
, plongest (addr
- abbrev_table_start
),
5126 map
.entry_pool
= addr
;
5131 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5135 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5136 const mapped_debug_names
&map
,
5137 dwarf2_section_info
§ion
,
5140 if (!map
.augmentation_is_gdb
)
5142 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5144 sect_offset sect_off
5145 = (sect_offset
) (extract_unsigned_integer
5146 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5148 map
.dwarf5_byte_order
));
5149 /* We don't know the length of the CU, because the CU list in a
5150 .debug_names index can be incomplete, so we can't use the start of
5151 the next CU as end of this CU. We create the CUs here with length 0,
5152 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5153 dwarf2_per_cu_data
*per_cu
5154 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5156 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5160 sect_offset sect_off_prev
;
5161 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5163 sect_offset sect_off_next
;
5164 if (i
< map
.cu_count
)
5167 = (sect_offset
) (extract_unsigned_integer
5168 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5170 map
.dwarf5_byte_order
));
5173 sect_off_next
= (sect_offset
) section
.size
;
5176 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5177 dwarf2_per_cu_data
*per_cu
5178 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5179 sect_off_prev
, length
);
5180 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5182 sect_off_prev
= sect_off_next
;
5186 /* Read the CU list from the mapped index, and use it to create all
5187 the CU objects for this dwarf2_per_objfile. */
5190 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5191 const mapped_debug_names
&map
,
5192 const mapped_debug_names
&dwz_map
)
5194 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
5195 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5197 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5198 dwarf2_per_objfile
->per_bfd
->info
,
5199 false /* is_dwz */);
5201 if (dwz_map
.cu_count
== 0)
5204 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5205 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5209 /* Read .debug_names. If everything went ok, initialize the "quick"
5210 elements of all the CUs and return true. Otherwise, return false. */
5213 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5215 std::unique_ptr
<mapped_debug_names
> map
5216 (new mapped_debug_names (dwarf2_per_objfile
));
5217 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5218 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5220 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5221 &dwarf2_per_objfile
->per_bfd
->debug_names
,
5225 /* Don't use the index if it's empty. */
5226 if (map
->name_count
== 0)
5229 /* If there is a .dwz file, read it so we can get its CU list as
5231 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5234 if (!read_debug_names_from_section (objfile
,
5235 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5236 &dwz
->debug_names
, dwz_map
))
5238 warning (_("could not read '.debug_names' section from %s; skipping"),
5239 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5244 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5246 if (map
->tu_count
!= 0)
5248 /* We can only handle a single .debug_types when we have an
5250 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
5253 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
5255 create_signatured_type_table_from_debug_names
5256 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->per_bfd
->abbrev
);
5259 create_addrmap_from_aranges (dwarf2_per_objfile
,
5260 &dwarf2_per_objfile
->per_bfd
->debug_aranges
);
5262 dwarf2_per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5263 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5264 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
5265 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5270 /* Type used to manage iterating over all CUs looking for a symbol for
5273 class dw2_debug_names_iterator
5276 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5277 gdb::optional
<block_enum
> block_index
,
5280 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5281 m_addr (find_vec_in_debug_names (map
, name
))
5284 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5285 search_domain search
, uint32_t namei
)
5288 m_addr (find_vec_in_debug_names (map
, namei
))
5291 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5292 block_enum block_index
, domain_enum domain
,
5294 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5295 m_addr (find_vec_in_debug_names (map
, namei
))
5298 /* Return the next matching CU or NULL if there are no more. */
5299 dwarf2_per_cu_data
*next ();
5302 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5304 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5307 /* The internalized form of .debug_names. */
5308 const mapped_debug_names
&m_map
;
5310 /* If set, only look for symbols that match that block. Valid values are
5311 GLOBAL_BLOCK and STATIC_BLOCK. */
5312 const gdb::optional
<block_enum
> m_block_index
;
5314 /* The kind of symbol we're looking for. */
5315 const domain_enum m_domain
= UNDEF_DOMAIN
;
5316 const search_domain m_search
= ALL_DOMAIN
;
5318 /* The list of CUs from the index entry of the symbol, or NULL if
5320 const gdb_byte
*m_addr
;
5324 mapped_debug_names::namei_to_name (uint32_t namei
) const
5326 const ULONGEST namei_string_offs
5327 = extract_unsigned_integer ((name_table_string_offs_reordered
5328 + namei
* offset_size
),
5331 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5335 /* Find a slot in .debug_names for the object named NAME. If NAME is
5336 found, return pointer to its pool data. If NAME cannot be found,
5340 dw2_debug_names_iterator::find_vec_in_debug_names
5341 (const mapped_debug_names
&map
, const char *name
)
5343 int (*cmp
) (const char *, const char *);
5345 gdb::unique_xmalloc_ptr
<char> without_params
;
5346 if (current_language
->la_language
== language_cplus
5347 || current_language
->la_language
== language_fortran
5348 || current_language
->la_language
== language_d
)
5350 /* NAME is already canonical. Drop any qualifiers as
5351 .debug_names does not contain any. */
5353 if (strchr (name
, '(') != NULL
)
5355 without_params
= cp_remove_params (name
);
5356 if (without_params
!= NULL
)
5357 name
= without_params
.get ();
5361 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5363 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5365 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5366 (map
.bucket_table_reordered
5367 + (full_hash
% map
.bucket_count
)), 4,
5368 map
.dwarf5_byte_order
);
5372 if (namei
>= map
.name_count
)
5374 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5376 namei
, map
.name_count
,
5377 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5383 const uint32_t namei_full_hash
5384 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5385 (map
.hash_table_reordered
+ namei
), 4,
5386 map
.dwarf5_byte_order
);
5387 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5390 if (full_hash
== namei_full_hash
)
5392 const char *const namei_string
= map
.namei_to_name (namei
);
5394 #if 0 /* An expensive sanity check. */
5395 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5397 complaint (_("Wrong .debug_names hash for string at index %u "
5399 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5404 if (cmp (namei_string
, name
) == 0)
5406 const ULONGEST namei_entry_offs
5407 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5408 + namei
* map
.offset_size
),
5409 map
.offset_size
, map
.dwarf5_byte_order
);
5410 return map
.entry_pool
+ namei_entry_offs
;
5415 if (namei
>= map
.name_count
)
5421 dw2_debug_names_iterator::find_vec_in_debug_names
5422 (const mapped_debug_names
&map
, uint32_t namei
)
5424 if (namei
>= map
.name_count
)
5426 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5428 namei
, map
.name_count
,
5429 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5433 const ULONGEST namei_entry_offs
5434 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5435 + namei
* map
.offset_size
),
5436 map
.offset_size
, map
.dwarf5_byte_order
);
5437 return map
.entry_pool
+ namei_entry_offs
;
5440 /* See dw2_debug_names_iterator. */
5442 dwarf2_per_cu_data
*
5443 dw2_debug_names_iterator::next ()
5448 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5449 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5450 bfd
*const abfd
= objfile
->obfd
;
5454 unsigned int bytes_read
;
5455 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5456 m_addr
+= bytes_read
;
5460 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5461 if (indexval_it
== m_map
.abbrev_map
.cend ())
5463 complaint (_("Wrong .debug_names undefined abbrev code %s "
5465 pulongest (abbrev
), objfile_name (objfile
));
5468 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5469 enum class symbol_linkage
{
5473 } symbol_linkage_
= symbol_linkage::unknown
;
5474 dwarf2_per_cu_data
*per_cu
= NULL
;
5475 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5480 case DW_FORM_implicit_const
:
5481 ull
= attr
.implicit_const
;
5483 case DW_FORM_flag_present
:
5487 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5488 m_addr
+= bytes_read
;
5491 ull
= read_4_bytes (abfd
, m_addr
);
5495 ull
= read_8_bytes (abfd
, m_addr
);
5498 case DW_FORM_ref_sig8
:
5499 ull
= read_8_bytes (abfd
, m_addr
);
5503 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5504 dwarf_form_name (attr
.form
),
5505 objfile_name (objfile
));
5508 switch (attr
.dw_idx
)
5510 case DW_IDX_compile_unit
:
5511 /* Don't crash on bad data. */
5512 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
5514 complaint (_(".debug_names entry has bad CU index %s"
5517 objfile_name (dwarf2_per_objfile
->objfile
));
5520 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (ull
);
5522 case DW_IDX_type_unit
:
5523 /* Don't crash on bad data. */
5524 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_type_units
.size ())
5526 complaint (_(".debug_names entry has bad TU index %s"
5529 objfile_name (dwarf2_per_objfile
->objfile
));
5532 per_cu
= &dwarf2_per_objfile
->per_bfd
->get_tu (ull
)->per_cu
;
5534 case DW_IDX_die_offset
:
5535 /* In a per-CU index (as opposed to a per-module index), index
5536 entries without CU attribute implicitly refer to the single CU. */
5538 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cu (0);
5540 case DW_IDX_GNU_internal
:
5541 if (!m_map
.augmentation_is_gdb
)
5543 symbol_linkage_
= symbol_linkage::static_
;
5545 case DW_IDX_GNU_external
:
5546 if (!m_map
.augmentation_is_gdb
)
5548 symbol_linkage_
= symbol_linkage::extern_
;
5553 /* Skip if already read in. */
5554 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
5557 /* Check static vs global. */
5558 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5560 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5561 const bool symbol_is_static
=
5562 symbol_linkage_
== symbol_linkage::static_
;
5563 if (want_static
!= symbol_is_static
)
5567 /* Match dw2_symtab_iter_next, symbol_kind
5568 and debug_names::psymbol_tag. */
5572 switch (indexval
.dwarf_tag
)
5574 case DW_TAG_variable
:
5575 case DW_TAG_subprogram
:
5576 /* Some types are also in VAR_DOMAIN. */
5577 case DW_TAG_typedef
:
5578 case DW_TAG_structure_type
:
5585 switch (indexval
.dwarf_tag
)
5587 case DW_TAG_typedef
:
5588 case DW_TAG_structure_type
:
5595 switch (indexval
.dwarf_tag
)
5598 case DW_TAG_variable
:
5605 switch (indexval
.dwarf_tag
)
5617 /* Match dw2_expand_symtabs_matching, symbol_kind and
5618 debug_names::psymbol_tag. */
5621 case VARIABLES_DOMAIN
:
5622 switch (indexval
.dwarf_tag
)
5624 case DW_TAG_variable
:
5630 case FUNCTIONS_DOMAIN
:
5631 switch (indexval
.dwarf_tag
)
5633 case DW_TAG_subprogram
:
5640 switch (indexval
.dwarf_tag
)
5642 case DW_TAG_typedef
:
5643 case DW_TAG_structure_type
:
5649 case MODULES_DOMAIN
:
5650 switch (indexval
.dwarf_tag
)
5664 static struct compunit_symtab
*
5665 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5666 const char *name
, domain_enum domain
)
5668 struct dwarf2_per_objfile
*dwarf2_per_objfile
5669 = get_dwarf2_per_objfile (objfile
);
5671 const auto &mapp
= dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5674 /* index is NULL if OBJF_READNOW. */
5677 const auto &map
= *mapp
;
5679 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5681 struct compunit_symtab
*stab_best
= NULL
;
5682 struct dwarf2_per_cu_data
*per_cu
;
5683 while ((per_cu
= iter
.next ()) != NULL
)
5685 struct symbol
*sym
, *with_opaque
= NULL
;
5686 compunit_symtab
*stab
5687 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5688 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5689 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5691 sym
= block_find_symbol (block
, name
, domain
,
5692 block_find_non_opaque_type_preferred
,
5695 /* Some caution must be observed with overloaded functions and
5696 methods, since the index will not contain any overload
5697 information (but NAME might contain it). */
5700 && strcmp_iw (sym
->search_name (), name
) == 0)
5702 if (with_opaque
!= NULL
5703 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5706 /* Keep looking through other CUs. */
5712 /* This dumps minimal information about .debug_names. It is called
5713 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5714 uses this to verify that .debug_names has been loaded. */
5717 dw2_debug_names_dump (struct objfile
*objfile
)
5719 struct dwarf2_per_objfile
*dwarf2_per_objfile
5720 = get_dwarf2_per_objfile (objfile
);
5722 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
5723 printf_filtered (".debug_names:");
5724 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5725 printf_filtered (" exists\n");
5727 printf_filtered (" faked for \"readnow\"\n");
5728 printf_filtered ("\n");
5732 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5733 const char *func_name
)
5735 struct dwarf2_per_objfile
*dwarf2_per_objfile
5736 = get_dwarf2_per_objfile (objfile
);
5738 /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5739 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5741 const mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5743 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5745 struct dwarf2_per_cu_data
*per_cu
;
5746 while ((per_cu
= iter
.next ()) != NULL
)
5747 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5752 dw2_debug_names_map_matching_symbols
5753 (struct objfile
*objfile
,
5754 const lookup_name_info
&name
, domain_enum domain
,
5756 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5757 symbol_compare_ftype
*ordered_compare
)
5759 struct dwarf2_per_objfile
*dwarf2_per_objfile
5760 = get_dwarf2_per_objfile (objfile
);
5762 /* debug_names_table is NULL if OBJF_READNOW. */
5763 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5766 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5767 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5769 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5770 auto matcher
= [&] (const char *symname
)
5772 if (ordered_compare
== nullptr)
5774 return ordered_compare (symname
, match_name
) == 0;
5777 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5778 [&] (offset_type namei
)
5780 /* The name was matched, now expand corresponding CUs that were
5782 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5784 struct dwarf2_per_cu_data
*per_cu
;
5785 while ((per_cu
= iter
.next ()) != NULL
)
5786 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
5791 /* It's a shame we couldn't do this inside the
5792 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5793 that have already been expanded. Instead, this loop matches what
5794 the psymtab code does. */
5795 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5797 compunit_symtab
*symtab
= dwarf2_per_objfile
->get_symtab (per_cu
);
5798 if (symtab
!= nullptr)
5800 const struct block
*block
5801 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5802 if (!iterate_over_symbols_terminated (block
, name
,
5810 dw2_debug_names_expand_symtabs_matching
5811 (struct objfile
*objfile
,
5812 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5813 const lookup_name_info
*lookup_name
,
5814 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5815 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5816 enum search_domain kind
)
5818 struct dwarf2_per_objfile
*dwarf2_per_objfile
5819 = get_dwarf2_per_objfile (objfile
);
5821 /* debug_names_table is NULL if OBJF_READNOW. */
5822 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5825 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5827 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5829 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5833 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5834 file_matcher
, expansion_notify
);
5839 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5841 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5843 kind
, [&] (offset_type namei
)
5845 /* The name was matched, now expand corresponding CUs that were
5847 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5849 struct dwarf2_per_cu_data
*per_cu
;
5850 while ((per_cu
= iter
.next ()) != NULL
)
5851 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5852 file_matcher
, expansion_notify
);
5857 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5860 dw2_find_last_source_symtab
,
5861 dw2_forget_cached_source_info
,
5862 dw2_map_symtabs_matching_filename
,
5863 dw2_debug_names_lookup_symbol
,
5866 dw2_debug_names_dump
,
5867 dw2_debug_names_expand_symtabs_for_function
,
5868 dw2_expand_all_symtabs
,
5869 dw2_expand_symtabs_with_fullname
,
5870 dw2_debug_names_map_matching_symbols
,
5871 dw2_debug_names_expand_symtabs_matching
,
5872 dw2_find_pc_sect_compunit_symtab
,
5874 dw2_map_symbol_filenames
5877 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5878 to either a dwarf2_per_bfd or dwz_file object. */
5880 template <typename T
>
5881 static gdb::array_view
<const gdb_byte
>
5882 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5884 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5886 if (section
->empty ())
5889 /* Older elfutils strip versions could keep the section in the main
5890 executable while splitting it for the separate debug info file. */
5891 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5894 section
->read (obj
);
5896 /* dwarf2_section_info::size is a bfd_size_type, while
5897 gdb::array_view works with size_t. On 32-bit hosts, with
5898 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5899 is 32-bit. So we need an explicit narrowing conversion here.
5900 This is fine, because it's impossible to allocate or mmap an
5901 array/buffer larger than what size_t can represent. */
5902 return gdb::make_array_view (section
->buffer
, section
->size
);
5905 /* Lookup the index cache for the contents of the index associated to
5908 static gdb::array_view
<const gdb_byte
>
5909 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5911 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5912 if (build_id
== nullptr)
5915 return global_index_cache
.lookup_gdb_index (build_id
,
5916 &dwarf2_per_bfd
->index_cache_res
);
5919 /* Same as the above, but for DWZ. */
5921 static gdb::array_view
<const gdb_byte
>
5922 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5924 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5925 if (build_id
== nullptr)
5928 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5931 /* See symfile.h. */
5934 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5936 struct dwarf2_per_objfile
*dwarf2_per_objfile
5937 = get_dwarf2_per_objfile (objfile
);
5939 /* If we're about to read full symbols, don't bother with the
5940 indices. In this case we also don't care if some other debug
5941 format is making psymtabs, because they are all about to be
5943 if ((objfile
->flags
& OBJF_READNOW
))
5945 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5946 create_all_comp_units (dwarf2_per_objfile
);
5947 create_all_type_units (dwarf2_per_objfile
);
5948 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
5949 = create_quick_file_names_table
5950 (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5951 dwarf2_per_objfile
->resize_symtabs ();
5953 for (int i
= 0; i
< (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
5954 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()); ++i
)
5956 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
5958 per_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
5959 struct dwarf2_per_cu_quick_data
);
5962 /* Return 1 so that gdb sees the "quick" functions. However,
5963 these functions will be no-ops because we will have expanded
5965 *index_kind
= dw_index_kind::GDB_INDEX
;
5969 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5971 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5972 dwarf2_per_objfile
->resize_symtabs ();
5976 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5977 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5978 get_gdb_index_contents_from_section
<dwz_file
>))
5980 *index_kind
= dw_index_kind::GDB_INDEX
;
5981 dwarf2_per_objfile
->resize_symtabs ();
5985 /* ... otherwise, try to find the index in the index cache. */
5986 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5987 get_gdb_index_contents_from_cache
,
5988 get_gdb_index_contents_from_cache_dwz
))
5990 global_index_cache
.hit ();
5991 *index_kind
= dw_index_kind::GDB_INDEX
;
5992 dwarf2_per_objfile
->resize_symtabs ();
5996 global_index_cache
.miss ();
6002 /* Build a partial symbol table. */
6005 dwarf2_build_psymtabs (struct objfile
*objfile
)
6007 struct dwarf2_per_objfile
*dwarf2_per_objfile
6008 = get_dwarf2_per_objfile (objfile
);
6010 init_psymbol_list (objfile
, 1024);
6014 /* This isn't really ideal: all the data we allocate on the
6015 objfile's obstack is still uselessly kept around. However,
6016 freeing it seems unsafe. */
6017 psymtab_discarder
psymtabs (objfile
);
6018 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6021 dwarf2_per_objfile
->resize_symtabs ();
6023 /* (maybe) store an index in the cache. */
6024 global_index_cache
.store (dwarf2_per_objfile
);
6026 catch (const gdb_exception_error
&except
)
6028 exception_print (gdb_stderr
, except
);
6032 /* Find the base address of the compilation unit for range lists and
6033 location lists. It will normally be specified by DW_AT_low_pc.
6034 In DWARF-3 draft 4, the base address could be overridden by
6035 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6036 compilation units with discontinuous ranges. */
6039 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6041 struct attribute
*attr
;
6043 cu
->base_address
.reset ();
6045 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6046 if (attr
!= nullptr)
6047 cu
->base_address
= attr
->value_as_address ();
6050 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6051 if (attr
!= nullptr)
6052 cu
->base_address
= attr
->value_as_address ();
6056 /* Helper function that returns the proper abbrev section for
6059 static struct dwarf2_section_info
*
6060 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6062 struct dwarf2_section_info
*abbrev
;
6063 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6065 if (this_cu
->is_dwz
)
6066 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6068 abbrev
= &per_bfd
->abbrev
;
6073 /* Fetch the abbreviation table offset from a comp or type unit header. */
6076 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6077 struct dwarf2_section_info
*section
,
6078 sect_offset sect_off
)
6080 bfd
*abfd
= section
->get_bfd_owner ();
6081 const gdb_byte
*info_ptr
;
6082 unsigned int initial_length_size
, offset_size
;
6085 section
->read (dwarf2_per_objfile
->objfile
);
6086 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6087 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6088 offset_size
= initial_length_size
== 4 ? 4 : 8;
6089 info_ptr
+= initial_length_size
;
6091 version
= read_2_bytes (abfd
, info_ptr
);
6095 /* Skip unit type and address size. */
6099 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6102 /* A partial symtab that is used only for include files. */
6103 struct dwarf2_include_psymtab
: public partial_symtab
6105 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6106 : partial_symtab (filename
, objfile
)
6110 void read_symtab (struct objfile
*objfile
) override
6112 /* It's an include file, no symbols to read for it.
6113 Everything is in the includer symtab. */
6115 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6116 expansion of the includer psymtab. We use the dependencies[0] field to
6117 model the includer. But if we go the regular route of calling
6118 expand_psymtab here, and having expand_psymtab call expand_dependencies
6119 to expand the includer, we'll only use expand_psymtab on the includer
6120 (making it a non-toplevel psymtab), while if we expand the includer via
6121 another path, we'll use read_symtab (making it a toplevel psymtab).
6122 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6123 psymtab, and trigger read_symtab on the includer here directly. */
6124 includer ()->read_symtab (objfile
);
6127 void expand_psymtab (struct objfile
*objfile
) override
6129 /* This is not called by read_symtab, and should not be called by any
6130 expand_dependencies. */
6134 bool readin_p (struct objfile
*objfile
) const override
6136 return includer ()->readin_p (objfile
);
6139 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6145 partial_symtab
*includer () const
6147 /* An include psymtab has exactly one dependency: the psymtab that
6149 gdb_assert (this->number_of_dependencies
== 1);
6150 return this->dependencies
[0];
6154 /* Allocate a new partial symtab for file named NAME and mark this new
6155 partial symtab as being an include of PST. */
6158 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6159 struct objfile
*objfile
)
6161 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6163 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6164 subpst
->dirname
= pst
->dirname
;
6166 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6167 subpst
->dependencies
[0] = pst
;
6168 subpst
->number_of_dependencies
= 1;
6171 /* Read the Line Number Program data and extract the list of files
6172 included by the source file represented by PST. Build an include
6173 partial symtab for each of these included files. */
6176 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6177 struct die_info
*die
,
6178 dwarf2_psymtab
*pst
)
6181 struct attribute
*attr
;
6183 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6184 if (attr
!= nullptr)
6185 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6187 return; /* No linetable, so no includes. */
6189 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6190 that we pass in the raw text_low here; that is ok because we're
6191 only decoding the line table to make include partial symtabs, and
6192 so the addresses aren't really used. */
6193 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6194 pst
->raw_text_low (), 1);
6198 hash_signatured_type (const void *item
)
6200 const struct signatured_type
*sig_type
6201 = (const struct signatured_type
*) item
;
6203 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6204 return sig_type
->signature
;
6208 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6210 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6211 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6213 return lhs
->signature
== rhs
->signature
;
6216 /* Allocate a hash table for signatured types. */
6219 allocate_signatured_type_table ()
6221 return htab_up (htab_create_alloc (41,
6222 hash_signatured_type
,
6224 NULL
, xcalloc
, xfree
));
6227 /* A helper function to add a signatured type CU to a table. */
6230 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6232 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6233 std::vector
<signatured_type
*> *all_type_units
6234 = (std::vector
<signatured_type
*> *) datum
;
6236 all_type_units
->push_back (sigt
);
6241 /* A helper for create_debug_types_hash_table. Read types from SECTION
6242 and fill them into TYPES_HTAB. It will process only type units,
6243 therefore DW_UT_type. */
6246 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6247 struct dwo_file
*dwo_file
,
6248 dwarf2_section_info
*section
, htab_up
&types_htab
,
6249 rcuh_kind section_kind
)
6251 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6252 struct dwarf2_section_info
*abbrev_section
;
6254 const gdb_byte
*info_ptr
, *end_ptr
;
6256 abbrev_section
= (dwo_file
!= NULL
6257 ? &dwo_file
->sections
.abbrev
6258 : &dwarf2_per_objfile
->per_bfd
->abbrev
);
6260 if (dwarf_read_debug
)
6261 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6262 section
->get_name (),
6263 abbrev_section
->get_file_name ());
6265 section
->read (objfile
);
6266 info_ptr
= section
->buffer
;
6268 if (info_ptr
== NULL
)
6271 /* We can't set abfd until now because the section may be empty or
6272 not present, in which case the bfd is unknown. */
6273 abfd
= section
->get_bfd_owner ();
6275 /* We don't use cutu_reader here because we don't need to read
6276 any dies: the signature is in the header. */
6278 end_ptr
= info_ptr
+ section
->size
;
6279 while (info_ptr
< end_ptr
)
6281 struct signatured_type
*sig_type
;
6282 struct dwo_unit
*dwo_tu
;
6284 const gdb_byte
*ptr
= info_ptr
;
6285 struct comp_unit_head header
;
6286 unsigned int length
;
6288 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6290 /* Initialize it due to a false compiler warning. */
6291 header
.signature
= -1;
6292 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6294 /* We need to read the type's signature in order to build the hash
6295 table, but we don't need anything else just yet. */
6297 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6298 abbrev_section
, ptr
, section_kind
);
6300 length
= header
.get_length ();
6302 /* Skip dummy type units. */
6303 if (ptr
>= info_ptr
+ length
6304 || peek_abbrev_code (abfd
, ptr
) == 0
6305 || header
.unit_type
!= DW_UT_type
)
6311 if (types_htab
== NULL
)
6314 types_htab
= allocate_dwo_unit_table ();
6316 types_htab
= allocate_signatured_type_table ();
6322 dwo_tu
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6324 dwo_tu
->dwo_file
= dwo_file
;
6325 dwo_tu
->signature
= header
.signature
;
6326 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6327 dwo_tu
->section
= section
;
6328 dwo_tu
->sect_off
= sect_off
;
6329 dwo_tu
->length
= length
;
6333 /* N.B.: type_offset is not usable if this type uses a DWO file.
6334 The real type_offset is in the DWO file. */
6336 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6337 sig_type
->signature
= header
.signature
;
6338 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6339 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6340 sig_type
->per_cu
.is_debug_types
= 1;
6341 sig_type
->per_cu
.section
= section
;
6342 sig_type
->per_cu
.sect_off
= sect_off
;
6343 sig_type
->per_cu
.length
= length
;
6346 slot
= htab_find_slot (types_htab
.get (),
6347 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6349 gdb_assert (slot
!= NULL
);
6352 sect_offset dup_sect_off
;
6356 const struct dwo_unit
*dup_tu
6357 = (const struct dwo_unit
*) *slot
;
6359 dup_sect_off
= dup_tu
->sect_off
;
6363 const struct signatured_type
*dup_tu
6364 = (const struct signatured_type
*) *slot
;
6366 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6369 complaint (_("debug type entry at offset %s is duplicate to"
6370 " the entry at offset %s, signature %s"),
6371 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6372 hex_string (header
.signature
));
6374 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6376 if (dwarf_read_debug
> 1)
6377 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6378 sect_offset_str (sect_off
),
6379 hex_string (header
.signature
));
6385 /* Create the hash table of all entries in the .debug_types
6386 (or .debug_types.dwo) section(s).
6387 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6388 otherwise it is NULL.
6390 The result is a pointer to the hash table or NULL if there are no types.
6392 Note: This function processes DWO files only, not DWP files. */
6395 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6396 struct dwo_file
*dwo_file
,
6397 gdb::array_view
<dwarf2_section_info
> type_sections
,
6398 htab_up
&types_htab
)
6400 for (dwarf2_section_info
§ion
: type_sections
)
6401 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6402 types_htab
, rcuh_kind::TYPE
);
6405 /* Create the hash table of all entries in the .debug_types section,
6406 and initialize all_type_units.
6407 The result is zero if there is an error (e.g. missing .debug_types section),
6408 otherwise non-zero. */
6411 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6415 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6416 &dwarf2_per_objfile
->per_bfd
->info
, types_htab
,
6417 rcuh_kind::COMPILE
);
6418 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6419 dwarf2_per_objfile
->per_bfd
->types
, types_htab
);
6420 if (types_htab
== NULL
)
6422 dwarf2_per_objfile
->per_bfd
->signatured_types
= NULL
;
6426 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6428 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
6429 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve
6430 (htab_elements (dwarf2_per_objfile
->per_bfd
->signatured_types
.get ()));
6432 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6433 add_signatured_type_cu_to_table
,
6434 &dwarf2_per_objfile
->per_bfd
->all_type_units
);
6439 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6440 If SLOT is non-NULL, it is the entry to use in the hash table.
6441 Otherwise we find one. */
6443 static struct signatured_type
*
6444 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6447 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()
6448 == dwarf2_per_objfile
->per_bfd
->all_type_units
.capacity ())
6449 ++dwarf2_per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6451 signatured_type
*sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6453 dwarf2_per_objfile
->resize_symtabs ();
6455 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6456 sig_type
->signature
= sig
;
6457 sig_type
->per_cu
.is_debug_types
= 1;
6458 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6460 sig_type
->per_cu
.v
.quick
=
6461 OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6462 struct dwarf2_per_cu_quick_data
);
6467 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6470 gdb_assert (*slot
== NULL
);
6472 /* The rest of sig_type must be filled in by the caller. */
6476 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6477 Fill in SIG_ENTRY with DWO_ENTRY. */
6480 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6481 struct signatured_type
*sig_entry
,
6482 struct dwo_unit
*dwo_entry
)
6484 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
6486 /* Make sure we're not clobbering something we don't expect to. */
6487 gdb_assert (! sig_entry
->per_cu
.queued
);
6488 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6489 if (per_bfd
->using_index
)
6491 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6492 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6495 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6496 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6497 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6498 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6499 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6501 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6502 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6503 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6504 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6505 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6506 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6507 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6508 sig_entry
->dwo_unit
= dwo_entry
;
6511 /* Subroutine of lookup_signatured_type.
6512 If we haven't read the TU yet, create the signatured_type data structure
6513 for a TU to be read in directly from a DWO file, bypassing the stub.
6514 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6515 using .gdb_index, then when reading a CU we want to stay in the DWO file
6516 containing that CU. Otherwise we could end up reading several other DWO
6517 files (due to comdat folding) to process the transitive closure of all the
6518 mentioned TUs, and that can be slow. The current DWO file will have every
6519 type signature that it needs.
6520 We only do this for .gdb_index because in the psymtab case we already have
6521 to read all the DWOs to build the type unit groups. */
6523 static struct signatured_type
*
6524 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6526 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6527 struct dwo_file
*dwo_file
;
6528 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6529 struct signatured_type find_sig_entry
, *sig_entry
;
6532 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6534 /* If TU skeletons have been removed then we may not have read in any
6536 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6537 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6539 /* We only ever need to read in one copy of a signatured type.
6540 Use the global signatured_types array to do our own comdat-folding
6541 of types. If this is the first time we're reading this TU, and
6542 the TU has an entry in .gdb_index, replace the recorded data from
6543 .gdb_index with this TU. */
6545 find_sig_entry
.signature
= sig
;
6546 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6547 &find_sig_entry
, INSERT
);
6548 sig_entry
= (struct signatured_type
*) *slot
;
6550 /* We can get here with the TU already read, *or* in the process of being
6551 read. Don't reassign the global entry to point to this DWO if that's
6552 the case. Also note that if the TU is already being read, it may not
6553 have come from a DWO, the program may be a mix of Fission-compiled
6554 code and non-Fission-compiled code. */
6556 /* Have we already tried to read this TU?
6557 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6558 needn't exist in the global table yet). */
6559 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6562 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6563 dwo_unit of the TU itself. */
6564 dwo_file
= cu
->dwo_unit
->dwo_file
;
6566 /* Ok, this is the first time we're reading this TU. */
6567 if (dwo_file
->tus
== NULL
)
6569 find_dwo_entry
.signature
= sig
;
6570 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6572 if (dwo_entry
== NULL
)
6575 /* If the global table doesn't have an entry for this TU, add one. */
6576 if (sig_entry
== NULL
)
6577 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6579 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6580 sig_entry
->per_cu
.tu_read
= 1;
6584 /* Subroutine of lookup_signatured_type.
6585 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6586 then try the DWP file. If the TU stub (skeleton) has been removed then
6587 it won't be in .gdb_index. */
6589 static struct signatured_type
*
6590 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6592 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6593 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6594 struct dwo_unit
*dwo_entry
;
6595 struct signatured_type find_sig_entry
, *sig_entry
;
6598 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6599 gdb_assert (dwp_file
!= NULL
);
6601 /* If TU skeletons have been removed then we may not have read in any
6603 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6604 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6606 find_sig_entry
.signature
= sig
;
6607 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6608 &find_sig_entry
, INSERT
);
6609 sig_entry
= (struct signatured_type
*) *slot
;
6611 /* Have we already tried to read this TU?
6612 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6613 needn't exist in the global table yet). */
6614 if (sig_entry
!= NULL
)
6617 if (dwp_file
->tus
== NULL
)
6619 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6620 sig
, 1 /* is_debug_types */);
6621 if (dwo_entry
== NULL
)
6624 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6625 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6630 /* Lookup a signature based type for DW_FORM_ref_sig8.
6631 Returns NULL if signature SIG is not present in the table.
6632 It is up to the caller to complain about this. */
6634 static struct signatured_type
*
6635 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6637 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6640 && dwarf2_per_objfile
->per_bfd
->using_index
)
6642 /* We're in a DWO/DWP file, and we're using .gdb_index.
6643 These cases require special processing. */
6644 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6645 return lookup_dwo_signatured_type (cu
, sig
);
6647 return lookup_dwp_signatured_type (cu
, sig
);
6651 struct signatured_type find_entry
, *entry
;
6653 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6655 find_entry
.signature
= sig
;
6656 entry
= ((struct signatured_type
*)
6657 htab_find (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6663 /* Low level DIE reading support. */
6665 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6668 init_cu_die_reader (struct die_reader_specs
*reader
,
6669 struct dwarf2_cu
*cu
,
6670 struct dwarf2_section_info
*section
,
6671 struct dwo_file
*dwo_file
,
6672 struct abbrev_table
*abbrev_table
)
6674 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6675 reader
->abfd
= section
->get_bfd_owner ();
6677 reader
->dwo_file
= dwo_file
;
6678 reader
->die_section
= section
;
6679 reader
->buffer
= section
->buffer
;
6680 reader
->buffer_end
= section
->buffer
+ section
->size
;
6681 reader
->abbrev_table
= abbrev_table
;
6684 /* Subroutine of cutu_reader to simplify it.
6685 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6686 There's just a lot of work to do, and cutu_reader is big enough
6689 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6690 from it to the DIE in the DWO. If NULL we are skipping the stub.
6691 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6692 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6693 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6694 STUB_COMP_DIR may be non-NULL.
6695 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6696 are filled in with the info of the DIE from the DWO file.
6697 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6698 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6699 kept around for at least as long as *RESULT_READER.
6701 The result is non-zero if a valid (non-dummy) DIE was found. */
6704 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6705 struct dwo_unit
*dwo_unit
,
6706 struct die_info
*stub_comp_unit_die
,
6707 const char *stub_comp_dir
,
6708 struct die_reader_specs
*result_reader
,
6709 const gdb_byte
**result_info_ptr
,
6710 struct die_info
**result_comp_unit_die
,
6711 abbrev_table_up
*result_dwo_abbrev_table
)
6713 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6714 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6715 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6717 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6718 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6719 int i
,num_extra_attrs
;
6720 struct dwarf2_section_info
*dwo_abbrev_section
;
6721 struct die_info
*comp_unit_die
;
6723 /* At most one of these may be provided. */
6724 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6726 /* These attributes aren't processed until later:
6727 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6728 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6729 referenced later. However, these attributes are found in the stub
6730 which we won't have later. In order to not impose this complication
6731 on the rest of the code, we read them here and copy them to the
6740 if (stub_comp_unit_die
!= NULL
)
6742 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6744 if (!per_cu
->is_debug_types
)
6745 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6746 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6747 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6748 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6749 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6751 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6753 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6754 here (if needed). We need the value before we can process
6756 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6758 else if (stub_comp_dir
!= NULL
)
6760 /* Reconstruct the comp_dir attribute to simplify the code below. */
6761 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6762 comp_dir
->name
= DW_AT_comp_dir
;
6763 comp_dir
->form
= DW_FORM_string
;
6764 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6765 DW_STRING (comp_dir
) = stub_comp_dir
;
6768 /* Set up for reading the DWO CU/TU. */
6769 cu
->dwo_unit
= dwo_unit
;
6770 dwarf2_section_info
*section
= dwo_unit
->section
;
6771 section
->read (objfile
);
6772 abfd
= section
->get_bfd_owner ();
6773 begin_info_ptr
= info_ptr
= (section
->buffer
6774 + to_underlying (dwo_unit
->sect_off
));
6775 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6777 if (per_cu
->is_debug_types
)
6779 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6781 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6782 &cu
->header
, section
,
6784 info_ptr
, rcuh_kind::TYPE
);
6785 /* This is not an assert because it can be caused by bad debug info. */
6786 if (sig_type
->signature
!= cu
->header
.signature
)
6788 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6789 " TU at offset %s [in module %s]"),
6790 hex_string (sig_type
->signature
),
6791 hex_string (cu
->header
.signature
),
6792 sect_offset_str (dwo_unit
->sect_off
),
6793 bfd_get_filename (abfd
));
6795 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6796 /* For DWOs coming from DWP files, we don't know the CU length
6797 nor the type's offset in the TU until now. */
6798 dwo_unit
->length
= cu
->header
.get_length ();
6799 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6801 /* Establish the type offset that can be used to lookup the type.
6802 For DWO files, we don't know it until now. */
6803 sig_type
->type_offset_in_section
6804 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6808 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6809 &cu
->header
, section
,
6811 info_ptr
, rcuh_kind::COMPILE
);
6812 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6813 /* For DWOs coming from DWP files, we don't know the CU length
6815 dwo_unit
->length
= cu
->header
.get_length ();
6818 *result_dwo_abbrev_table
6819 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6820 cu
->header
.abbrev_sect_off
);
6821 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6822 result_dwo_abbrev_table
->get ());
6824 /* Read in the die, but leave space to copy over the attributes
6825 from the stub. This has the benefit of simplifying the rest of
6826 the code - all the work to maintain the illusion of a single
6827 DW_TAG_{compile,type}_unit DIE is done here. */
6828 num_extra_attrs
= ((stmt_list
!= NULL
)
6832 + (comp_dir
!= NULL
));
6833 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6836 /* Copy over the attributes from the stub to the DIE we just read in. */
6837 comp_unit_die
= *result_comp_unit_die
;
6838 i
= comp_unit_die
->num_attrs
;
6839 if (stmt_list
!= NULL
)
6840 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6842 comp_unit_die
->attrs
[i
++] = *low_pc
;
6843 if (high_pc
!= NULL
)
6844 comp_unit_die
->attrs
[i
++] = *high_pc
;
6846 comp_unit_die
->attrs
[i
++] = *ranges
;
6847 if (comp_dir
!= NULL
)
6848 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6849 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6851 if (dwarf_die_debug
)
6853 fprintf_unfiltered (gdb_stdlog
,
6854 "Read die from %s@0x%x of %s:\n",
6855 section
->get_name (),
6856 (unsigned) (begin_info_ptr
- section
->buffer
),
6857 bfd_get_filename (abfd
));
6858 dump_die (comp_unit_die
, dwarf_die_debug
);
6861 /* Skip dummy compilation units. */
6862 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6863 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6866 *result_info_ptr
= info_ptr
;
6870 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6871 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6872 signature is part of the header. */
6873 static gdb::optional
<ULONGEST
>
6874 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6876 if (cu
->header
.version
>= 5)
6877 return cu
->header
.signature
;
6878 struct attribute
*attr
;
6879 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6880 if (attr
== nullptr)
6881 return gdb::optional
<ULONGEST
> ();
6882 return DW_UNSND (attr
);
6885 /* Subroutine of cutu_reader to simplify it.
6886 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6887 Returns NULL if the specified DWO unit cannot be found. */
6889 static struct dwo_unit
*
6890 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6892 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6893 struct dwo_unit
*dwo_unit
;
6894 const char *comp_dir
;
6896 gdb_assert (cu
!= NULL
);
6898 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6899 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6900 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6902 if (per_cu
->is_debug_types
)
6903 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6906 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6908 if (!signature
.has_value ())
6909 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6911 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6913 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6919 /* Subroutine of cutu_reader to simplify it.
6920 See it for a description of the parameters.
6921 Read a TU directly from a DWO file, bypassing the stub. */
6924 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6925 dwarf2_per_objfile
*per_objfile
,
6926 int use_existing_cu
)
6928 struct signatured_type
*sig_type
;
6930 /* Verify we can do the following downcast, and that we have the
6932 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6933 sig_type
= (struct signatured_type
*) this_cu
;
6934 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6936 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6938 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6939 /* There's no need to do the rereading_dwo_cu handling that
6940 cutu_reader does since we don't read the stub. */
6944 /* If !use_existing_cu, this_cu->cu must be NULL. */
6945 gdb_assert (this_cu
->cu
== NULL
);
6946 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6949 /* A future optimization, if needed, would be to use an existing
6950 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6951 could share abbrev tables. */
6953 if (read_cutu_die_from_dwo (this_cu
->cu
, sig_type
->dwo_unit
,
6954 NULL
/* stub_comp_unit_die */,
6955 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6958 &m_dwo_abbrev_table
) == 0)
6965 /* Initialize a CU (or TU) and read its DIEs.
6966 If the CU defers to a DWO file, read the DWO file as well.
6968 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6969 Otherwise the table specified in the comp unit header is read in and used.
6970 This is an optimization for when we already have the abbrev table.
6972 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6973 Otherwise, a new CU is allocated with xmalloc. */
6975 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6976 dwarf2_per_objfile
*dwarf2_per_objfile
,
6977 struct abbrev_table
*abbrev_table
,
6978 int use_existing_cu
,
6980 : die_reader_specs
{},
6983 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6984 struct dwarf2_section_info
*section
= this_cu
->section
;
6985 bfd
*abfd
= section
->get_bfd_owner ();
6986 struct dwarf2_cu
*cu
;
6987 const gdb_byte
*begin_info_ptr
;
6988 struct signatured_type
*sig_type
= NULL
;
6989 struct dwarf2_section_info
*abbrev_section
;
6990 /* Non-zero if CU currently points to a DWO file and we need to
6991 reread it. When this happens we need to reread the skeleton die
6992 before we can reread the DWO file (this only applies to CUs, not TUs). */
6993 int rereading_dwo_cu
= 0;
6995 if (dwarf_die_debug
)
6996 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6997 this_cu
->is_debug_types
? "type" : "comp",
6998 sect_offset_str (this_cu
->sect_off
));
7000 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7001 file (instead of going through the stub), short-circuit all of this. */
7002 if (this_cu
->reading_dwo_directly
)
7004 /* Narrow down the scope of possibilities to have to understand. */
7005 gdb_assert (this_cu
->is_debug_types
);
7006 gdb_assert (abbrev_table
== NULL
);
7007 init_tu_and_read_dwo_dies (this_cu
, dwarf2_per_objfile
, use_existing_cu
);
7011 /* This is cheap if the section is already read in. */
7012 section
->read (objfile
);
7014 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7016 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7018 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7021 /* If this CU is from a DWO file we need to start over, we need to
7022 refetch the attributes from the skeleton CU.
7023 This could be optimized by retrieving those attributes from when we
7024 were here the first time: the previous comp_unit_die was stored in
7025 comp_unit_obstack. But there's no data yet that we need this
7027 if (cu
->dwo_unit
!= NULL
)
7028 rereading_dwo_cu
= 1;
7032 /* If !use_existing_cu, this_cu->cu must be NULL. */
7033 gdb_assert (this_cu
->cu
== NULL
);
7034 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7035 cu
= m_new_cu
.get ();
7038 /* Get the header. */
7039 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7041 /* We already have the header, there's no need to read it in again. */
7042 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7046 if (this_cu
->is_debug_types
)
7048 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7049 &cu
->header
, section
,
7050 abbrev_section
, info_ptr
,
7053 /* Since per_cu is the first member of struct signatured_type,
7054 we can go from a pointer to one to a pointer to the other. */
7055 sig_type
= (struct signatured_type
*) this_cu
;
7056 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7057 gdb_assert (sig_type
->type_offset_in_tu
7058 == cu
->header
.type_cu_offset_in_tu
);
7059 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7061 /* LENGTH has not been set yet for type units if we're
7062 using .gdb_index. */
7063 this_cu
->length
= cu
->header
.get_length ();
7065 /* Establish the type offset that can be used to lookup the type. */
7066 sig_type
->type_offset_in_section
=
7067 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7069 this_cu
->dwarf_version
= cu
->header
.version
;
7073 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7074 &cu
->header
, section
,
7077 rcuh_kind::COMPILE
);
7079 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7080 if (this_cu
->length
== 0)
7081 this_cu
->length
= cu
->header
.get_length ();
7083 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7084 this_cu
->dwarf_version
= cu
->header
.version
;
7088 /* Skip dummy compilation units. */
7089 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7090 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7096 /* If we don't have them yet, read the abbrevs for this compilation unit.
7097 And if we need to read them now, make sure they're freed when we're
7099 if (abbrev_table
!= NULL
)
7100 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7103 m_abbrev_table_holder
7104 = abbrev_table::read (objfile
, abbrev_section
,
7105 cu
->header
.abbrev_sect_off
);
7106 abbrev_table
= m_abbrev_table_holder
.get ();
7109 /* Read the top level CU/TU die. */
7110 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7111 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7113 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7119 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7120 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7121 table from the DWO file and pass the ownership over to us. It will be
7122 referenced from READER, so we must make sure to free it after we're done
7125 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7126 DWO CU, that this test will fail (the attribute will not be present). */
7127 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7128 if (dwo_name
!= nullptr)
7130 struct dwo_unit
*dwo_unit
;
7131 struct die_info
*dwo_comp_unit_die
;
7133 if (comp_unit_die
->has_children
)
7135 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7136 " has children (offset %s) [in module %s]"),
7137 sect_offset_str (this_cu
->sect_off
),
7138 bfd_get_filename (abfd
));
7140 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7141 if (dwo_unit
!= NULL
)
7143 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7144 comp_unit_die
, NULL
,
7147 &m_dwo_abbrev_table
) == 0)
7153 comp_unit_die
= dwo_comp_unit_die
;
7157 /* Yikes, we couldn't find the rest of the DIE, we only have
7158 the stub. A complaint has already been logged. There's
7159 not much more we can do except pass on the stub DIE to
7160 die_reader_func. We don't want to throw an error on bad
7167 cutu_reader::keep ()
7169 /* Done, clean up. */
7170 gdb_assert (!dummy_p
);
7171 if (m_new_cu
!= NULL
)
7173 /* We know that m_this_cu->cu is set, since we are in the process of
7175 gdb_assert (m_this_cu
->cu
!= nullptr);
7176 dwarf2_per_objfile
*dwarf2_per_objfile
= m_this_cu
->cu
->per_objfile
;
7178 /* Link this CU into read_in_chain. */
7179 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
7180 dwarf2_per_objfile
->per_bfd
->read_in_chain
= m_this_cu
;
7181 /* The chain owns it now. */
7182 m_new_cu
.release ();
7186 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7187 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7188 assumed to have already done the lookup to find the DWO file).
7190 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7191 THIS_CU->is_debug_types, but nothing else.
7193 We fill in THIS_CU->length.
7195 THIS_CU->cu is always freed when done.
7196 This is done in order to not leave THIS_CU->cu in a state where we have
7197 to care whether it refers to the "main" CU or the DWO CU.
7199 When parent_cu is passed, it is used to provide a default value for
7200 str_offsets_base and addr_base from the parent. */
7202 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7203 dwarf2_per_objfile
*dwarf2_per_objfile
,
7204 struct dwarf2_cu
*parent_cu
,
7205 struct dwo_file
*dwo_file
)
7206 : die_reader_specs
{},
7209 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7210 struct dwarf2_section_info
*section
= this_cu
->section
;
7211 bfd
*abfd
= section
->get_bfd_owner ();
7212 struct dwarf2_section_info
*abbrev_section
;
7213 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7215 if (dwarf_die_debug
)
7216 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7217 this_cu
->is_debug_types
? "type" : "comp",
7218 sect_offset_str (this_cu
->sect_off
));
7220 gdb_assert (this_cu
->cu
== NULL
);
7222 abbrev_section
= (dwo_file
!= NULL
7223 ? &dwo_file
->sections
.abbrev
7224 : get_abbrev_section_for_cu (this_cu
));
7226 /* This is cheap if the section is already read in. */
7227 section
->read (objfile
);
7229 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7231 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7232 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7233 &m_new_cu
->header
, section
,
7234 abbrev_section
, info_ptr
,
7235 (this_cu
->is_debug_types
7237 : rcuh_kind::COMPILE
));
7239 if (parent_cu
!= nullptr)
7241 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7242 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7244 this_cu
->length
= m_new_cu
->header
.get_length ();
7246 /* Skip dummy compilation units. */
7247 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7248 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7254 m_abbrev_table_holder
7255 = abbrev_table::read (objfile
, abbrev_section
,
7256 m_new_cu
->header
.abbrev_sect_off
);
7258 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7259 m_abbrev_table_holder
.get ());
7260 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7264 /* Type Unit Groups.
7266 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7267 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7268 so that all types coming from the same compilation (.o file) are grouped
7269 together. A future step could be to put the types in the same symtab as
7270 the CU the types ultimately came from. */
7273 hash_type_unit_group (const void *item
)
7275 const struct type_unit_group
*tu_group
7276 = (const struct type_unit_group
*) item
;
7278 return hash_stmt_list_entry (&tu_group
->hash
);
7282 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7284 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7285 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7287 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7290 /* Allocate a hash table for type unit groups. */
7293 allocate_type_unit_groups_table ()
7295 return htab_up (htab_create_alloc (3,
7296 hash_type_unit_group
,
7298 NULL
, xcalloc
, xfree
));
7301 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7302 partial symtabs. We combine several TUs per psymtab to not let the size
7303 of any one psymtab grow too big. */
7304 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7305 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7307 /* Helper routine for get_type_unit_group.
7308 Create the type_unit_group object used to hold one or more TUs. */
7310 static struct type_unit_group
*
7311 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7313 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7314 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
7315 struct dwarf2_per_cu_data
*per_cu
;
7316 struct type_unit_group
*tu_group
;
7318 tu_group
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7319 struct type_unit_group
);
7320 per_cu
= &tu_group
->per_cu
;
7321 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7322 per_cu
->per_bfd
= per_bfd
;
7324 if (per_bfd
->using_index
)
7326 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7327 struct dwarf2_per_cu_quick_data
);
7331 unsigned int line_offset
= to_underlying (line_offset_struct
);
7332 dwarf2_psymtab
*pst
;
7335 /* Give the symtab a useful name for debug purposes. */
7336 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7337 name
= string_printf ("<type_units_%d>",
7338 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7340 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7342 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, name
.c_str ());
7343 pst
->anonymous
= true;
7346 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7347 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7352 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7353 STMT_LIST is a DW_AT_stmt_list attribute. */
7355 static struct type_unit_group
*
7356 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7358 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7359 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7360 struct type_unit_group
*tu_group
;
7362 unsigned int line_offset
;
7363 struct type_unit_group type_unit_group_for_lookup
;
7365 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7366 dwarf2_per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7368 /* Do we need to create a new group, or can we use an existing one? */
7372 line_offset
= DW_UNSND (stmt_list
);
7373 ++tu_stats
->nr_symtab_sharers
;
7377 /* Ugh, no stmt_list. Rare, but we have to handle it.
7378 We can do various things here like create one group per TU or
7379 spread them over multiple groups to split up the expansion work.
7380 To avoid worst case scenarios (too many groups or too large groups)
7381 we, umm, group them in bunches. */
7382 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7383 | (tu_stats
->nr_stmt_less_type_units
7384 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7385 ++tu_stats
->nr_stmt_less_type_units
;
7388 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7389 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7390 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7391 &type_unit_group_for_lookup
, INSERT
);
7394 tu_group
= (struct type_unit_group
*) *slot
;
7395 gdb_assert (tu_group
!= NULL
);
7399 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7400 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7402 ++tu_stats
->nr_symtabs
;
7408 /* Partial symbol tables. */
7410 /* Create a psymtab named NAME and assign it to PER_CU.
7412 The caller must fill in the following details:
7413 dirname, textlow, texthigh. */
7415 static dwarf2_psymtab
*
7416 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7417 dwarf2_per_objfile
*per_objfile
,
7420 struct objfile
*objfile
= per_objfile
->objfile
;
7421 dwarf2_psymtab
*pst
;
7423 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7425 pst
->psymtabs_addrmap_supported
= true;
7427 /* This is the glue that links PST into GDB's symbol API. */
7428 per_cu
->v
.psymtab
= pst
;
7433 /* DIE reader function for process_psymtab_comp_unit. */
7436 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7437 const gdb_byte
*info_ptr
,
7438 struct die_info
*comp_unit_die
,
7439 enum language pretend_language
)
7441 struct dwarf2_cu
*cu
= reader
->cu
;
7442 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7443 struct objfile
*objfile
= per_objfile
->objfile
;
7444 struct gdbarch
*gdbarch
= objfile
->arch ();
7445 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7447 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7448 dwarf2_psymtab
*pst
;
7449 enum pc_bounds_kind cu_bounds_kind
;
7450 const char *filename
;
7452 gdb_assert (! per_cu
->is_debug_types
);
7454 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7456 /* Allocate a new partial symbol table structure. */
7457 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7458 static const char artificial
[] = "<artificial>";
7459 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7460 if (filename
== NULL
)
7462 else if (strcmp (filename
, artificial
) == 0)
7464 debug_filename
.reset (concat (artificial
, "@",
7465 sect_offset_str (per_cu
->sect_off
),
7467 filename
= debug_filename
.get ();
7470 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7472 /* This must be done before calling dwarf2_build_include_psymtabs. */
7473 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7475 baseaddr
= objfile
->text_section_offset ();
7477 dwarf2_find_base_address (comp_unit_die
, cu
);
7479 /* Possibly set the default values of LOWPC and HIGHPC from
7481 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7482 &best_highpc
, cu
, pst
);
7483 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7486 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7489 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7491 /* Store the contiguous range if it is not empty; it can be
7492 empty for CUs with no code. */
7493 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7497 /* Check if comp unit has_children.
7498 If so, read the rest of the partial symbols from this comp unit.
7499 If not, there's no more debug_info for this comp unit. */
7500 if (comp_unit_die
->has_children
)
7502 struct partial_die_info
*first_die
;
7503 CORE_ADDR lowpc
, highpc
;
7505 lowpc
= ((CORE_ADDR
) -1);
7506 highpc
= ((CORE_ADDR
) 0);
7508 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7510 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7511 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7513 /* If we didn't find a lowpc, set it to highpc to avoid
7514 complaints from `maint check'. */
7515 if (lowpc
== ((CORE_ADDR
) -1))
7518 /* If the compilation unit didn't have an explicit address range,
7519 then use the information extracted from its child dies. */
7520 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7523 best_highpc
= highpc
;
7526 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7527 best_lowpc
+ baseaddr
)
7529 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7530 best_highpc
+ baseaddr
)
7533 end_psymtab_common (objfile
, pst
);
7535 if (!cu
->per_cu
->imported_symtabs_empty ())
7538 int len
= cu
->per_cu
->imported_symtabs_size ();
7540 /* Fill in 'dependencies' here; we fill in 'users' in a
7542 pst
->number_of_dependencies
= len
;
7544 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7545 for (i
= 0; i
< len
; ++i
)
7547 pst
->dependencies
[i
]
7548 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7551 cu
->per_cu
->imported_symtabs_free ();
7554 /* Get the list of files included in the current compilation unit,
7555 and build a psymtab for each of them. */
7556 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7558 if (dwarf_read_debug
)
7559 fprintf_unfiltered (gdb_stdlog
,
7560 "Psymtab for %s unit @%s: %s - %s"
7561 ", %d global, %d static syms\n",
7562 per_cu
->is_debug_types
? "type" : "comp",
7563 sect_offset_str (per_cu
->sect_off
),
7564 paddress (gdbarch
, pst
->text_low (objfile
)),
7565 paddress (gdbarch
, pst
->text_high (objfile
)),
7566 pst
->n_global_syms
, pst
->n_static_syms
);
7569 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7570 Process compilation unit THIS_CU for a psymtab. */
7573 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7574 dwarf2_per_objfile
*per_objfile
,
7575 bool want_partial_unit
,
7576 enum language pretend_language
)
7578 /* If this compilation unit was already read in, free the
7579 cached copy in order to read it in again. This is
7580 necessary because we skipped some symbols when we first
7581 read in the compilation unit (see load_partial_dies).
7582 This problem could be avoided, but the benefit is unclear. */
7583 if (this_cu
->cu
!= NULL
)
7584 free_one_cached_comp_unit (this_cu
, per_objfile
);
7586 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 0, false);
7588 switch (reader
.comp_unit_die
->tag
)
7590 case DW_TAG_compile_unit
:
7591 this_cu
->unit_type
= DW_UT_compile
;
7593 case DW_TAG_partial_unit
:
7594 this_cu
->unit_type
= DW_UT_partial
;
7604 else if (this_cu
->is_debug_types
)
7605 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7606 reader
.comp_unit_die
);
7607 else if (want_partial_unit
7608 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7609 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7610 reader
.comp_unit_die
,
7613 this_cu
->lang
= this_cu
->cu
->language
;
7615 /* Age out any secondary CUs. */
7616 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7619 /* Reader function for build_type_psymtabs. */
7622 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7623 const gdb_byte
*info_ptr
,
7624 struct die_info
*type_unit_die
)
7626 struct dwarf2_per_objfile
*dwarf2_per_objfile
= reader
->cu
->per_objfile
;
7627 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7628 struct dwarf2_cu
*cu
= reader
->cu
;
7629 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7630 struct signatured_type
*sig_type
;
7631 struct type_unit_group
*tu_group
;
7632 struct attribute
*attr
;
7633 struct partial_die_info
*first_die
;
7634 CORE_ADDR lowpc
, highpc
;
7635 dwarf2_psymtab
*pst
;
7637 gdb_assert (per_cu
->is_debug_types
);
7638 sig_type
= (struct signatured_type
*) per_cu
;
7640 if (! type_unit_die
->has_children
)
7643 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7644 tu_group
= get_type_unit_group (cu
, attr
);
7646 if (tu_group
->tus
== nullptr)
7647 tu_group
->tus
= new std::vector
<signatured_type
*>;
7648 tu_group
->tus
->push_back (sig_type
);
7650 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7651 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, "");
7652 pst
->anonymous
= true;
7654 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7656 lowpc
= (CORE_ADDR
) -1;
7657 highpc
= (CORE_ADDR
) 0;
7658 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7660 end_psymtab_common (objfile
, pst
);
7663 /* Struct used to sort TUs by their abbreviation table offset. */
7665 struct tu_abbrev_offset
7667 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7668 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7671 signatured_type
*sig_type
;
7672 sect_offset abbrev_offset
;
7675 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7678 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7679 const struct tu_abbrev_offset
&b
)
7681 return a
.abbrev_offset
< b
.abbrev_offset
;
7684 /* Efficiently read all the type units.
7685 This does the bulk of the work for build_type_psymtabs.
7687 The efficiency is because we sort TUs by the abbrev table they use and
7688 only read each abbrev table once. In one program there are 200K TUs
7689 sharing 8K abbrev tables.
7691 The main purpose of this function is to support building the
7692 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7693 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7694 can collapse the search space by grouping them by stmt_list.
7695 The savings can be significant, in the same program from above the 200K TUs
7696 share 8K stmt_list tables.
7698 FUNC is expected to call get_type_unit_group, which will create the
7699 struct type_unit_group if necessary and add it to
7700 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7703 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7705 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7706 abbrev_table_up abbrev_table
;
7707 sect_offset abbrev_offset
;
7709 /* It's up to the caller to not call us multiple times. */
7710 gdb_assert (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7712 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ())
7715 /* TUs typically share abbrev tables, and there can be way more TUs than
7716 abbrev tables. Sort by abbrev table to reduce the number of times we
7717 read each abbrev table in.
7718 Alternatives are to punt or to maintain a cache of abbrev tables.
7719 This is simpler and efficient enough for now.
7721 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7722 symtab to use). Typically TUs with the same abbrev offset have the same
7723 stmt_list value too so in practice this should work well.
7725 The basic algorithm here is:
7727 sort TUs by abbrev table
7728 for each TU with same abbrev table:
7729 read abbrev table if first user
7730 read TU top level DIE
7731 [IWBN if DWO skeletons had DW_AT_stmt_list]
7734 if (dwarf_read_debug
)
7735 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7737 /* Sort in a separate table to maintain the order of all_type_units
7738 for .gdb_index: TU indices directly index all_type_units. */
7739 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7740 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7742 for (signatured_type
*sig_type
: dwarf2_per_objfile
->per_bfd
->all_type_units
)
7743 sorted_by_abbrev
.emplace_back
7744 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7745 sig_type
->per_cu
.section
,
7746 sig_type
->per_cu
.sect_off
));
7748 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7749 sort_tu_by_abbrev_offset
);
7751 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7753 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7755 /* Switch to the next abbrev table if necessary. */
7756 if (abbrev_table
== NULL
7757 || tu
.abbrev_offset
!= abbrev_offset
)
7759 abbrev_offset
= tu
.abbrev_offset
;
7761 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7762 &dwarf2_per_objfile
->per_bfd
->abbrev
,
7764 ++tu_stats
->nr_uniq_abbrev_tables
;
7767 cutu_reader
reader (&tu
.sig_type
->per_cu
, dwarf2_per_objfile
,
7768 abbrev_table
.get (), 0, false);
7769 if (!reader
.dummy_p
)
7770 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7771 reader
.comp_unit_die
);
7775 /* Print collected type unit statistics. */
7778 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7780 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7782 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7783 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7784 dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7785 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7786 tu_stats
->nr_uniq_abbrev_tables
);
7787 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7788 tu_stats
->nr_symtabs
);
7789 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7790 tu_stats
->nr_symtab_sharers
);
7791 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7792 tu_stats
->nr_stmt_less_type_units
);
7793 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7794 tu_stats
->nr_all_type_units_reallocs
);
7797 /* Traversal function for build_type_psymtabs. */
7800 build_type_psymtab_dependencies (void **slot
, void *info
)
7802 struct dwarf2_per_objfile
*dwarf2_per_objfile
7803 = (struct dwarf2_per_objfile
*) info
;
7804 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7805 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7806 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7807 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7808 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7811 gdb_assert (len
> 0);
7812 gdb_assert (per_cu
->type_unit_group_p ());
7814 pst
->number_of_dependencies
= len
;
7815 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7816 for (i
= 0; i
< len
; ++i
)
7818 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7819 gdb_assert (iter
->per_cu
.is_debug_types
);
7820 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7821 iter
->type_unit_group
= tu_group
;
7824 delete tu_group
->tus
;
7825 tu_group
->tus
= nullptr;
7830 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7831 Build partial symbol tables for the .debug_types comp-units. */
7834 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7836 if (! create_all_type_units (dwarf2_per_objfile
))
7839 build_type_psymtabs_1 (dwarf2_per_objfile
);
7842 /* Traversal function for process_skeletonless_type_unit.
7843 Read a TU in a DWO file and build partial symbols for it. */
7846 process_skeletonless_type_unit (void **slot
, void *info
)
7848 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7849 struct dwarf2_per_objfile
*dwarf2_per_objfile
7850 = (struct dwarf2_per_objfile
*) info
;
7851 struct signatured_type find_entry
, *entry
;
7853 /* If this TU doesn't exist in the global table, add it and read it in. */
7855 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
7856 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7858 find_entry
.signature
= dwo_unit
->signature
;
7859 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
7860 &find_entry
, INSERT
);
7861 /* If we've already seen this type there's nothing to do. What's happening
7862 is we're doing our own version of comdat-folding here. */
7866 /* This does the job that create_all_type_units would have done for
7868 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7869 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7872 /* This does the job that build_type_psymtabs_1 would have done. */
7873 cutu_reader
reader (&entry
->per_cu
, dwarf2_per_objfile
, NULL
, 0, false);
7874 if (!reader
.dummy_p
)
7875 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7876 reader
.comp_unit_die
);
7881 /* Traversal function for process_skeletonless_type_units. */
7884 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7886 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7888 if (dwo_file
->tus
!= NULL
)
7889 htab_traverse_noresize (dwo_file
->tus
.get (),
7890 process_skeletonless_type_unit
, info
);
7895 /* Scan all TUs of DWO files, verifying we've processed them.
7896 This is needed in case a TU was emitted without its skeleton.
7897 Note: This can't be done until we know what all the DWO files are. */
7900 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7902 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7903 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7904 && dwarf2_per_objfile
->per_bfd
->dwo_files
!= NULL
)
7906 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (),
7907 process_dwo_file_for_skeletonless_type_units
,
7908 dwarf2_per_objfile
);
7912 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7915 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7917 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7919 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7924 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7926 /* Set the 'user' field only if it is not already set. */
7927 if (pst
->dependencies
[j
]->user
== NULL
)
7928 pst
->dependencies
[j
]->user
= pst
;
7933 /* Build the partial symbol table by doing a quick pass through the
7934 .debug_info and .debug_abbrev sections. */
7937 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7939 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7941 if (dwarf_read_debug
)
7943 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7944 objfile_name (objfile
));
7947 scoped_restore restore_reading_psyms
7948 = make_scoped_restore (&dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
,
7951 dwarf2_per_objfile
->per_bfd
->info
.read (objfile
);
7953 /* Any cached compilation units will be linked by the per-objfile
7954 read_in_chain. Make sure to free them when we're done. */
7955 free_cached_comp_units
freer (dwarf2_per_objfile
);
7957 build_type_psymtabs (dwarf2_per_objfile
);
7959 create_all_comp_units (dwarf2_per_objfile
);
7961 /* Create a temporary address map on a temporary obstack. We later
7962 copy this to the final obstack. */
7963 auto_obstack temp_obstack
;
7965 scoped_restore save_psymtabs_addrmap
7966 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7967 addrmap_create_mutable (&temp_obstack
));
7969 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7971 if (per_cu
->v
.psymtab
!= NULL
)
7972 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7974 process_psymtab_comp_unit (per_cu
, dwarf2_per_objfile
, false,
7978 /* This has to wait until we read the CUs, we need the list of DWOs. */
7979 process_skeletonless_type_units (dwarf2_per_objfile
);
7981 /* Now that all TUs have been processed we can fill in the dependencies. */
7982 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
7984 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7985 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7988 if (dwarf_read_debug
)
7989 print_tu_stats (dwarf2_per_objfile
);
7991 set_partial_user (dwarf2_per_objfile
);
7993 objfile
->partial_symtabs
->psymtabs_addrmap
7994 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7995 objfile
->partial_symtabs
->obstack ());
7996 /* At this point we want to keep the address map. */
7997 save_psymtabs_addrmap
.release ();
7999 if (dwarf_read_debug
)
8000 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8001 objfile_name (objfile
));
8004 /* Load the partial DIEs for a secondary CU into memory.
8005 This is also used when rereading a primary CU with load_all_dies. */
8008 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8009 dwarf2_per_objfile
*per_objfile
)
8011 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 1, false);
8013 if (!reader
.dummy_p
)
8015 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8018 /* Check if comp unit has_children.
8019 If so, read the rest of the partial symbols from this comp unit.
8020 If not, there's no more debug_info for this comp unit. */
8021 if (reader
.comp_unit_die
->has_children
)
8022 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8029 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8030 struct dwarf2_section_info
*section
,
8031 struct dwarf2_section_info
*abbrev_section
,
8032 unsigned int is_dwz
)
8034 const gdb_byte
*info_ptr
;
8035 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8037 if (dwarf_read_debug
)
8038 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8039 section
->get_name (),
8040 section
->get_file_name ());
8042 section
->read (objfile
);
8044 info_ptr
= section
->buffer
;
8046 while (info_ptr
< section
->buffer
+ section
->size
)
8048 struct dwarf2_per_cu_data
*this_cu
;
8050 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8052 comp_unit_head cu_header
;
8053 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8054 abbrev_section
, info_ptr
,
8055 rcuh_kind::COMPILE
);
8057 /* Save the compilation unit for later lookup. */
8058 if (cu_header
.unit_type
!= DW_UT_type
)
8059 this_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
8062 auto sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
8063 sig_type
->signature
= cu_header
.signature
;
8064 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8065 this_cu
= &sig_type
->per_cu
;
8067 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8068 this_cu
->sect_off
= sect_off
;
8069 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8070 this_cu
->is_dwz
= is_dwz
;
8071 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8072 this_cu
->section
= section
;
8074 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8076 info_ptr
= info_ptr
+ this_cu
->length
;
8080 /* Create a list of all compilation units in OBJFILE.
8081 This is only done for -readnow and building partial symtabs. */
8084 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8086 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
8087 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->per_bfd
->info
,
8088 &dwarf2_per_objfile
->per_bfd
->abbrev
, 0);
8090 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
8092 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8096 /* Process all loaded DIEs for compilation unit CU, starting at
8097 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8098 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8099 DW_AT_ranges). See the comments of add_partial_subprogram on how
8100 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8103 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8104 CORE_ADDR
*highpc
, int set_addrmap
,
8105 struct dwarf2_cu
*cu
)
8107 struct partial_die_info
*pdi
;
8109 /* Now, march along the PDI's, descending into ones which have
8110 interesting children but skipping the children of the other ones,
8111 until we reach the end of the compilation unit. */
8119 /* Anonymous namespaces or modules have no name but have interesting
8120 children, so we need to look at them. Ditto for anonymous
8123 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8124 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8125 || pdi
->tag
== DW_TAG_imported_unit
8126 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8130 case DW_TAG_subprogram
:
8131 case DW_TAG_inlined_subroutine
:
8132 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8134 case DW_TAG_constant
:
8135 case DW_TAG_variable
:
8136 case DW_TAG_typedef
:
8137 case DW_TAG_union_type
:
8138 if (!pdi
->is_declaration
8139 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8141 add_partial_symbol (pdi
, cu
);
8144 case DW_TAG_class_type
:
8145 case DW_TAG_interface_type
:
8146 case DW_TAG_structure_type
:
8147 if (!pdi
->is_declaration
)
8149 add_partial_symbol (pdi
, cu
);
8151 if ((cu
->language
== language_rust
8152 || cu
->language
== language_cplus
) && pdi
->has_children
)
8153 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8156 case DW_TAG_enumeration_type
:
8157 if (!pdi
->is_declaration
)
8158 add_partial_enumeration (pdi
, cu
);
8160 case DW_TAG_base_type
:
8161 case DW_TAG_subrange_type
:
8162 /* File scope base type definitions are added to the partial
8164 add_partial_symbol (pdi
, cu
);
8166 case DW_TAG_namespace
:
8167 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8170 if (!pdi
->is_declaration
)
8171 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8173 case DW_TAG_imported_unit
:
8175 struct dwarf2_per_cu_data
*per_cu
;
8177 /* For now we don't handle imported units in type units. */
8178 if (cu
->per_cu
->is_debug_types
)
8180 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8181 " supported in type units [in module %s]"),
8182 objfile_name (cu
->per_objfile
->objfile
));
8185 per_cu
= dwarf2_find_containing_comp_unit
8186 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8188 /* Go read the partial unit, if needed. */
8189 if (per_cu
->v
.psymtab
== NULL
)
8190 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8193 cu
->per_cu
->imported_symtabs_push (per_cu
);
8196 case DW_TAG_imported_declaration
:
8197 add_partial_symbol (pdi
, cu
);
8204 /* If the die has a sibling, skip to the sibling. */
8206 pdi
= pdi
->die_sibling
;
8210 /* Functions used to compute the fully scoped name of a partial DIE.
8212 Normally, this is simple. For C++, the parent DIE's fully scoped
8213 name is concatenated with "::" and the partial DIE's name.
8214 Enumerators are an exception; they use the scope of their parent
8215 enumeration type, i.e. the name of the enumeration type is not
8216 prepended to the enumerator.
8218 There are two complexities. One is DW_AT_specification; in this
8219 case "parent" means the parent of the target of the specification,
8220 instead of the direct parent of the DIE. The other is compilers
8221 which do not emit DW_TAG_namespace; in this case we try to guess
8222 the fully qualified name of structure types from their members'
8223 linkage names. This must be done using the DIE's children rather
8224 than the children of any DW_AT_specification target. We only need
8225 to do this for structures at the top level, i.e. if the target of
8226 any DW_AT_specification (if any; otherwise the DIE itself) does not
8229 /* Compute the scope prefix associated with PDI's parent, in
8230 compilation unit CU. The result will be allocated on CU's
8231 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8232 field. NULL is returned if no prefix is necessary. */
8234 partial_die_parent_scope (struct partial_die_info
*pdi
,
8235 struct dwarf2_cu
*cu
)
8237 const char *grandparent_scope
;
8238 struct partial_die_info
*parent
, *real_pdi
;
8240 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8241 then this means the parent of the specification DIE. */
8244 while (real_pdi
->has_specification
)
8246 auto res
= find_partial_die (real_pdi
->spec_offset
,
8247 real_pdi
->spec_is_dwz
, cu
);
8252 parent
= real_pdi
->die_parent
;
8256 if (parent
->scope_set
)
8257 return parent
->scope
;
8261 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8263 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8264 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8265 Work around this problem here. */
8266 if (cu
->language
== language_cplus
8267 && parent
->tag
== DW_TAG_namespace
8268 && strcmp (parent
->name
, "::") == 0
8269 && grandparent_scope
== NULL
)
8271 parent
->scope
= NULL
;
8272 parent
->scope_set
= 1;
8276 /* Nested subroutines in Fortran get a prefix. */
8277 if (pdi
->tag
== DW_TAG_enumerator
)
8278 /* Enumerators should not get the name of the enumeration as a prefix. */
8279 parent
->scope
= grandparent_scope
;
8280 else if (parent
->tag
== DW_TAG_namespace
8281 || parent
->tag
== DW_TAG_module
8282 || parent
->tag
== DW_TAG_structure_type
8283 || parent
->tag
== DW_TAG_class_type
8284 || parent
->tag
== DW_TAG_interface_type
8285 || parent
->tag
== DW_TAG_union_type
8286 || parent
->tag
== DW_TAG_enumeration_type
8287 || (cu
->language
== language_fortran
8288 && parent
->tag
== DW_TAG_subprogram
8289 && pdi
->tag
== DW_TAG_subprogram
))
8291 if (grandparent_scope
== NULL
)
8292 parent
->scope
= parent
->name
;
8294 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8296 parent
->name
, 0, cu
);
8300 /* FIXME drow/2004-04-01: What should we be doing with
8301 function-local names? For partial symbols, we should probably be
8303 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8304 dwarf_tag_name (parent
->tag
),
8305 sect_offset_str (pdi
->sect_off
));
8306 parent
->scope
= grandparent_scope
;
8309 parent
->scope_set
= 1;
8310 return parent
->scope
;
8313 /* Return the fully scoped name associated with PDI, from compilation unit
8314 CU. The result will be allocated with malloc. */
8316 static gdb::unique_xmalloc_ptr
<char>
8317 partial_die_full_name (struct partial_die_info
*pdi
,
8318 struct dwarf2_cu
*cu
)
8320 const char *parent_scope
;
8322 /* If this is a template instantiation, we can not work out the
8323 template arguments from partial DIEs. So, unfortunately, we have
8324 to go through the full DIEs. At least any work we do building
8325 types here will be reused if full symbols are loaded later. */
8326 if (pdi
->has_template_arguments
)
8330 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8332 struct die_info
*die
;
8333 struct attribute attr
;
8334 struct dwarf2_cu
*ref_cu
= cu
;
8336 /* DW_FORM_ref_addr is using section offset. */
8337 attr
.name
= (enum dwarf_attribute
) 0;
8338 attr
.form
= DW_FORM_ref_addr
;
8339 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8340 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8342 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8346 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8347 if (parent_scope
== NULL
)
8350 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8355 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8357 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
8358 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8359 struct gdbarch
*gdbarch
= objfile
->arch ();
8361 const char *actual_name
= NULL
;
8364 baseaddr
= objfile
->text_section_offset ();
8366 gdb::unique_xmalloc_ptr
<char> built_actual_name
8367 = partial_die_full_name (pdi
, cu
);
8368 if (built_actual_name
!= NULL
)
8369 actual_name
= built_actual_name
.get ();
8371 if (actual_name
== NULL
)
8372 actual_name
= pdi
->name
;
8374 partial_symbol psymbol
;
8375 memset (&psymbol
, 0, sizeof (psymbol
));
8376 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8377 psymbol
.ginfo
.section
= -1;
8379 /* The code below indicates that the psymbol should be installed by
8381 gdb::optional
<psymbol_placement
> where
;
8385 case DW_TAG_inlined_subroutine
:
8386 case DW_TAG_subprogram
:
8387 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8389 if (pdi
->is_external
8390 || cu
->language
== language_ada
8391 || (cu
->language
== language_fortran
8392 && pdi
->die_parent
!= NULL
8393 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8395 /* Normally, only "external" DIEs are part of the global scope.
8396 But in Ada and Fortran, we want to be able to access nested
8397 procedures globally. So all Ada and Fortran subprograms are
8398 stored in the global scope. */
8399 where
= psymbol_placement::GLOBAL
;
8402 where
= psymbol_placement::STATIC
;
8404 psymbol
.domain
= VAR_DOMAIN
;
8405 psymbol
.aclass
= LOC_BLOCK
;
8406 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8407 psymbol
.ginfo
.value
.address
= addr
;
8409 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8410 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8412 case DW_TAG_constant
:
8413 psymbol
.domain
= VAR_DOMAIN
;
8414 psymbol
.aclass
= LOC_STATIC
;
8415 where
= (pdi
->is_external
8416 ? psymbol_placement::GLOBAL
8417 : psymbol_placement::STATIC
);
8419 case DW_TAG_variable
:
8421 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8425 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
8427 /* A global or static variable may also have been stripped
8428 out by the linker if unused, in which case its address
8429 will be nullified; do not add such variables into partial
8430 symbol table then. */
8432 else if (pdi
->is_external
)
8435 Don't enter into the minimal symbol tables as there is
8436 a minimal symbol table entry from the ELF symbols already.
8437 Enter into partial symbol table if it has a location
8438 descriptor or a type.
8439 If the location descriptor is missing, new_symbol will create
8440 a LOC_UNRESOLVED symbol, the address of the variable will then
8441 be determined from the minimal symbol table whenever the variable
8443 The address for the partial symbol table entry is not
8444 used by GDB, but it comes in handy for debugging partial symbol
8447 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8449 psymbol
.domain
= VAR_DOMAIN
;
8450 psymbol
.aclass
= LOC_STATIC
;
8451 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8452 psymbol
.ginfo
.value
.address
= addr
;
8453 where
= psymbol_placement::GLOBAL
;
8458 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8460 /* Static Variable. Skip symbols whose value we cannot know (those
8461 without location descriptors or constant values). */
8462 if (!has_loc
&& !pdi
->has_const_value
)
8465 psymbol
.domain
= VAR_DOMAIN
;
8466 psymbol
.aclass
= LOC_STATIC
;
8467 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8469 psymbol
.ginfo
.value
.address
= addr
;
8470 where
= psymbol_placement::STATIC
;
8473 case DW_TAG_typedef
:
8474 case DW_TAG_base_type
:
8475 case DW_TAG_subrange_type
:
8476 psymbol
.domain
= VAR_DOMAIN
;
8477 psymbol
.aclass
= LOC_TYPEDEF
;
8478 where
= psymbol_placement::STATIC
;
8480 case DW_TAG_imported_declaration
:
8481 case DW_TAG_namespace
:
8482 psymbol
.domain
= VAR_DOMAIN
;
8483 psymbol
.aclass
= LOC_TYPEDEF
;
8484 where
= psymbol_placement::GLOBAL
;
8487 /* With Fortran 77 there might be a "BLOCK DATA" module
8488 available without any name. If so, we skip the module as it
8489 doesn't bring any value. */
8490 if (actual_name
!= nullptr)
8492 psymbol
.domain
= MODULE_DOMAIN
;
8493 psymbol
.aclass
= LOC_TYPEDEF
;
8494 where
= psymbol_placement::GLOBAL
;
8497 case DW_TAG_class_type
:
8498 case DW_TAG_interface_type
:
8499 case DW_TAG_structure_type
:
8500 case DW_TAG_union_type
:
8501 case DW_TAG_enumeration_type
:
8502 /* Skip external references. The DWARF standard says in the section
8503 about "Structure, Union, and Class Type Entries": "An incomplete
8504 structure, union or class type is represented by a structure,
8505 union or class entry that does not have a byte size attribute
8506 and that has a DW_AT_declaration attribute." */
8507 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8510 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8511 static vs. global. */
8512 psymbol
.domain
= STRUCT_DOMAIN
;
8513 psymbol
.aclass
= LOC_TYPEDEF
;
8514 where
= (cu
->language
== language_cplus
8515 ? psymbol_placement::GLOBAL
8516 : psymbol_placement::STATIC
);
8518 case DW_TAG_enumerator
:
8519 psymbol
.domain
= VAR_DOMAIN
;
8520 psymbol
.aclass
= LOC_CONST
;
8521 where
= (cu
->language
== language_cplus
8522 ? psymbol_placement::GLOBAL
8523 : psymbol_placement::STATIC
);
8529 if (where
.has_value ())
8531 if (built_actual_name
!= nullptr)
8532 actual_name
= objfile
->intern (actual_name
);
8533 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8534 psymbol
.ginfo
.set_linkage_name (actual_name
);
8537 psymbol
.ginfo
.set_demangled_name (actual_name
,
8538 &objfile
->objfile_obstack
);
8539 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8541 add_psymbol_to_list (psymbol
, *where
, objfile
);
8545 /* Read a partial die corresponding to a namespace; also, add a symbol
8546 corresponding to that namespace to the symbol table. NAMESPACE is
8547 the name of the enclosing namespace. */
8550 add_partial_namespace (struct partial_die_info
*pdi
,
8551 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8552 int set_addrmap
, struct dwarf2_cu
*cu
)
8554 /* Add a symbol for the namespace. */
8556 add_partial_symbol (pdi
, cu
);
8558 /* Now scan partial symbols in that namespace. */
8560 if (pdi
->has_children
)
8561 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8564 /* Read a partial die corresponding to a Fortran module. */
8567 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8568 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8570 /* Add a symbol for the namespace. */
8572 add_partial_symbol (pdi
, cu
);
8574 /* Now scan partial symbols in that module. */
8576 if (pdi
->has_children
)
8577 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8580 /* Read a partial die corresponding to a subprogram or an inlined
8581 subprogram and create a partial symbol for that subprogram.
8582 When the CU language allows it, this routine also defines a partial
8583 symbol for each nested subprogram that this subprogram contains.
8584 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8585 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8587 PDI may also be a lexical block, in which case we simply search
8588 recursively for subprograms defined inside that lexical block.
8589 Again, this is only performed when the CU language allows this
8590 type of definitions. */
8593 add_partial_subprogram (struct partial_die_info
*pdi
,
8594 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8595 int set_addrmap
, struct dwarf2_cu
*cu
)
8597 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8599 if (pdi
->has_pc_info
)
8601 if (pdi
->lowpc
< *lowpc
)
8602 *lowpc
= pdi
->lowpc
;
8603 if (pdi
->highpc
> *highpc
)
8604 *highpc
= pdi
->highpc
;
8607 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8608 struct gdbarch
*gdbarch
= objfile
->arch ();
8610 CORE_ADDR this_highpc
;
8611 CORE_ADDR this_lowpc
;
8613 baseaddr
= objfile
->text_section_offset ();
8615 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8616 pdi
->lowpc
+ baseaddr
)
8619 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8620 pdi
->highpc
+ baseaddr
)
8622 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8623 this_lowpc
, this_highpc
- 1,
8624 cu
->per_cu
->v
.psymtab
);
8628 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8630 if (!pdi
->is_declaration
)
8631 /* Ignore subprogram DIEs that do not have a name, they are
8632 illegal. Do not emit a complaint at this point, we will
8633 do so when we convert this psymtab into a symtab. */
8635 add_partial_symbol (pdi
, cu
);
8639 if (! pdi
->has_children
)
8642 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8644 pdi
= pdi
->die_child
;
8648 if (pdi
->tag
== DW_TAG_subprogram
8649 || pdi
->tag
== DW_TAG_inlined_subroutine
8650 || pdi
->tag
== DW_TAG_lexical_block
)
8651 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8652 pdi
= pdi
->die_sibling
;
8657 /* Read a partial die corresponding to an enumeration type. */
8660 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8661 struct dwarf2_cu
*cu
)
8663 struct partial_die_info
*pdi
;
8665 if (enum_pdi
->name
!= NULL
)
8666 add_partial_symbol (enum_pdi
, cu
);
8668 pdi
= enum_pdi
->die_child
;
8671 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8672 complaint (_("malformed enumerator DIE ignored"));
8674 add_partial_symbol (pdi
, cu
);
8675 pdi
= pdi
->die_sibling
;
8679 /* Return the initial uleb128 in the die at INFO_PTR. */
8682 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8684 unsigned int bytes_read
;
8686 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8689 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8690 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8692 Return the corresponding abbrev, or NULL if the number is zero (indicating
8693 an empty DIE). In either case *BYTES_READ will be set to the length of
8694 the initial number. */
8696 static struct abbrev_info
*
8697 peek_die_abbrev (const die_reader_specs
&reader
,
8698 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8700 dwarf2_cu
*cu
= reader
.cu
;
8701 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8702 unsigned int abbrev_number
8703 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8705 if (abbrev_number
== 0)
8708 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8711 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8712 " at offset %s [in module %s]"),
8713 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8714 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8720 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8721 Returns a pointer to the end of a series of DIEs, terminated by an empty
8722 DIE. Any children of the skipped DIEs will also be skipped. */
8724 static const gdb_byte
*
8725 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8729 unsigned int bytes_read
;
8730 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8733 return info_ptr
+ bytes_read
;
8735 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8739 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8740 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8741 abbrev corresponding to that skipped uleb128 should be passed in
8742 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8745 static const gdb_byte
*
8746 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8747 struct abbrev_info
*abbrev
)
8749 unsigned int bytes_read
;
8750 struct attribute attr
;
8751 bfd
*abfd
= reader
->abfd
;
8752 struct dwarf2_cu
*cu
= reader
->cu
;
8753 const gdb_byte
*buffer
= reader
->buffer
;
8754 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8755 unsigned int form
, i
;
8757 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8759 /* The only abbrev we care about is DW_AT_sibling. */
8760 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8763 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8765 if (attr
.form
== DW_FORM_ref_addr
)
8766 complaint (_("ignoring absolute DW_AT_sibling"));
8769 sect_offset off
= attr
.get_ref_die_offset ();
8770 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8772 if (sibling_ptr
< info_ptr
)
8773 complaint (_("DW_AT_sibling points backwards"));
8774 else if (sibling_ptr
> reader
->buffer_end
)
8775 reader
->die_section
->overflow_complaint ();
8781 /* If it isn't DW_AT_sibling, skip this attribute. */
8782 form
= abbrev
->attrs
[i
].form
;
8786 case DW_FORM_ref_addr
:
8787 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8788 and later it is offset sized. */
8789 if (cu
->header
.version
== 2)
8790 info_ptr
+= cu
->header
.addr_size
;
8792 info_ptr
+= cu
->header
.offset_size
;
8794 case DW_FORM_GNU_ref_alt
:
8795 info_ptr
+= cu
->header
.offset_size
;
8798 info_ptr
+= cu
->header
.addr_size
;
8806 case DW_FORM_flag_present
:
8807 case DW_FORM_implicit_const
:
8824 case DW_FORM_ref_sig8
:
8827 case DW_FORM_data16
:
8830 case DW_FORM_string
:
8831 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8832 info_ptr
+= bytes_read
;
8834 case DW_FORM_sec_offset
:
8836 case DW_FORM_GNU_strp_alt
:
8837 info_ptr
+= cu
->header
.offset_size
;
8839 case DW_FORM_exprloc
:
8841 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8842 info_ptr
+= bytes_read
;
8844 case DW_FORM_block1
:
8845 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8847 case DW_FORM_block2
:
8848 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8850 case DW_FORM_block4
:
8851 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8857 case DW_FORM_ref_udata
:
8858 case DW_FORM_GNU_addr_index
:
8859 case DW_FORM_GNU_str_index
:
8860 case DW_FORM_rnglistx
:
8861 case DW_FORM_loclistx
:
8862 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8864 case DW_FORM_indirect
:
8865 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8866 info_ptr
+= bytes_read
;
8867 /* We need to continue parsing from here, so just go back to
8869 goto skip_attribute
;
8872 error (_("Dwarf Error: Cannot handle %s "
8873 "in DWARF reader [in module %s]"),
8874 dwarf_form_name (form
),
8875 bfd_get_filename (abfd
));
8879 if (abbrev
->has_children
)
8880 return skip_children (reader
, info_ptr
);
8885 /* Locate ORIG_PDI's sibling.
8886 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8888 static const gdb_byte
*
8889 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8890 struct partial_die_info
*orig_pdi
,
8891 const gdb_byte
*info_ptr
)
8893 /* Do we know the sibling already? */
8895 if (orig_pdi
->sibling
)
8896 return orig_pdi
->sibling
;
8898 /* Are there any children to deal with? */
8900 if (!orig_pdi
->has_children
)
8903 /* Skip the children the long way. */
8905 return skip_children (reader
, info_ptr
);
8908 /* Expand this partial symbol table into a full symbol table. SELF is
8912 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8914 struct dwarf2_per_objfile
*dwarf2_per_objfile
8915 = get_dwarf2_per_objfile (objfile
);
8917 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (per_cu_data
));
8919 /* If this psymtab is constructed from a debug-only objfile, the
8920 has_section_at_zero flag will not necessarily be correct. We
8921 can get the correct value for this flag by looking at the data
8922 associated with the (presumably stripped) associated objfile. */
8923 if (objfile
->separate_debug_objfile_backlink
)
8925 struct dwarf2_per_objfile
*dpo_backlink
8926 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8928 dwarf2_per_objfile
->per_bfd
->has_section_at_zero
8929 = dpo_backlink
->per_bfd
->has_section_at_zero
;
8932 expand_psymtab (objfile
);
8934 process_cu_includes (dwarf2_per_objfile
);
8937 /* Reading in full CUs. */
8939 /* Add PER_CU to the queue. */
8942 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8943 dwarf2_per_objfile
*per_objfile
,
8944 enum language pretend_language
)
8947 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
8950 /* If PER_CU is not yet queued, add it to the queue.
8951 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8953 The result is non-zero if PER_CU was queued, otherwise the result is zero
8954 meaning either PER_CU is already queued or it is already loaded.
8956 N.B. There is an invariant here that if a CU is queued then it is loaded.
8957 The caller is required to load PER_CU if we return non-zero. */
8960 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8961 dwarf2_per_cu_data
*per_cu
,
8962 dwarf2_per_objfile
*per_objfile
,
8963 enum language pretend_language
)
8965 /* We may arrive here during partial symbol reading, if we need full
8966 DIEs to process an unusual case (e.g. template arguments). Do
8967 not queue PER_CU, just tell our caller to load its DIEs. */
8968 if (per_cu
->per_bfd
->reading_partial_symbols
)
8970 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8975 /* Mark the dependence relation so that we don't flush PER_CU
8977 if (dependent_cu
!= NULL
)
8978 dwarf2_add_dependence (dependent_cu
, per_cu
);
8980 /* If it's already on the queue, we have nothing to do. */
8984 /* If the compilation unit is already loaded, just mark it as
8986 if (per_cu
->cu
!= NULL
)
8988 per_cu
->cu
->last_used
= 0;
8992 /* Add it to the queue. */
8993 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8998 /* Process the queue. */
9001 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9003 if (dwarf_read_debug
)
9005 fprintf_unfiltered (gdb_stdlog
,
9006 "Expanding one or more symtabs of objfile %s ...\n",
9007 objfile_name (dwarf2_per_objfile
->objfile
));
9010 /* The queue starts out with one item, but following a DIE reference
9011 may load a new CU, adding it to the end of the queue. */
9012 while (!dwarf2_per_objfile
->per_bfd
->queue
.empty ())
9014 dwarf2_queue_item
&item
= dwarf2_per_objfile
->per_bfd
->queue
.front ();
9016 if (!dwarf2_per_objfile
->symtab_set_p (item
.per_cu
)
9017 /* Skip dummy CUs. */
9018 && item
.per_cu
->cu
!= NULL
)
9020 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9021 unsigned int debug_print_threshold
;
9024 if (per_cu
->is_debug_types
)
9026 struct signatured_type
*sig_type
=
9027 (struct signatured_type
*) per_cu
;
9029 sprintf (buf
, "TU %s at offset %s",
9030 hex_string (sig_type
->signature
),
9031 sect_offset_str (per_cu
->sect_off
));
9032 /* There can be 100s of TUs.
9033 Only print them in verbose mode. */
9034 debug_print_threshold
= 2;
9038 sprintf (buf
, "CU at offset %s",
9039 sect_offset_str (per_cu
->sect_off
));
9040 debug_print_threshold
= 1;
9043 if (dwarf_read_debug
>= debug_print_threshold
)
9044 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9046 if (per_cu
->is_debug_types
)
9047 process_full_type_unit (per_cu
, dwarf2_per_objfile
,
9048 item
.pretend_language
);
9050 process_full_comp_unit (per_cu
, dwarf2_per_objfile
,
9051 item
.pretend_language
);
9053 if (dwarf_read_debug
>= debug_print_threshold
)
9054 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9057 item
.per_cu
->queued
= 0;
9058 dwarf2_per_objfile
->per_bfd
->queue
.pop ();
9061 if (dwarf_read_debug
)
9063 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9064 objfile_name (dwarf2_per_objfile
->objfile
));
9068 /* Read in full symbols for PST, and anything it depends on. */
9071 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9073 gdb_assert (!readin_p (objfile
));
9075 expand_dependencies (objfile
);
9077 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9078 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9079 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9082 /* See psympriv.h. */
9085 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9087 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9088 return per_objfile
->symtab_set_p (per_cu_data
);
9091 /* See psympriv.h. */
9094 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9096 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9097 return per_objfile
->get_symtab (per_cu_data
);
9100 /* Trivial hash function for die_info: the hash value of a DIE
9101 is its offset in .debug_info for this objfile. */
9104 die_hash (const void *item
)
9106 const struct die_info
*die
= (const struct die_info
*) item
;
9108 return to_underlying (die
->sect_off
);
9111 /* Trivial comparison function for die_info structures: two DIEs
9112 are equal if they have the same offset. */
9115 die_eq (const void *item_lhs
, const void *item_rhs
)
9117 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9118 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9120 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9123 /* Load the DIEs associated with PER_CU into memory. */
9126 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9127 dwarf2_per_objfile
*per_objfile
,
9129 enum language pretend_language
)
9131 gdb_assert (! this_cu
->is_debug_types
);
9133 cutu_reader
reader (this_cu
, per_objfile
, NULL
, 1, skip_partial
);
9137 struct dwarf2_cu
*cu
= reader
.cu
;
9138 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9140 gdb_assert (cu
->die_hash
== NULL
);
9142 htab_create_alloc_ex (cu
->header
.length
/ 12,
9146 &cu
->comp_unit_obstack
,
9147 hashtab_obstack_allocate
,
9148 dummy_obstack_deallocate
);
9150 if (reader
.comp_unit_die
->has_children
)
9151 reader
.comp_unit_die
->child
9152 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9153 &info_ptr
, reader
.comp_unit_die
);
9154 cu
->dies
= reader
.comp_unit_die
;
9155 /* comp_unit_die is not stored in die_hash, no need. */
9157 /* We try not to read any attributes in this function, because not
9158 all CUs needed for references have been loaded yet, and symbol
9159 table processing isn't initialized. But we have to set the CU language,
9160 or we won't be able to build types correctly.
9161 Similarly, if we do not read the producer, we can not apply
9162 producer-specific interpretation. */
9163 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9168 /* Add a DIE to the delayed physname list. */
9171 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9172 const char *name
, struct die_info
*die
,
9173 struct dwarf2_cu
*cu
)
9175 struct delayed_method_info mi
;
9177 mi
.fnfield_index
= fnfield_index
;
9181 cu
->method_list
.push_back (mi
);
9184 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9185 "const" / "volatile". If so, decrements LEN by the length of the
9186 modifier and return true. Otherwise return false. */
9190 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9192 size_t mod_len
= sizeof (mod
) - 1;
9193 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9201 /* Compute the physnames of any methods on the CU's method list.
9203 The computation of method physnames is delayed in order to avoid the
9204 (bad) condition that one of the method's formal parameters is of an as yet
9208 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9210 /* Only C++ delays computing physnames. */
9211 if (cu
->method_list
.empty ())
9213 gdb_assert (cu
->language
== language_cplus
);
9215 for (const delayed_method_info
&mi
: cu
->method_list
)
9217 const char *physname
;
9218 struct fn_fieldlist
*fn_flp
9219 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9220 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9221 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9222 = physname
? physname
: "";
9224 /* Since there's no tag to indicate whether a method is a
9225 const/volatile overload, extract that information out of the
9227 if (physname
!= NULL
)
9229 size_t len
= strlen (physname
);
9233 if (physname
[len
] == ')') /* shortcut */
9235 else if (check_modifier (physname
, len
, " const"))
9236 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9237 else if (check_modifier (physname
, len
, " volatile"))
9238 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9245 /* The list is no longer needed. */
9246 cu
->method_list
.clear ();
9249 /* Go objects should be embedded in a DW_TAG_module DIE,
9250 and it's not clear if/how imported objects will appear.
9251 To keep Go support simple until that's worked out,
9252 go back through what we've read and create something usable.
9253 We could do this while processing each DIE, and feels kinda cleaner,
9254 but that way is more invasive.
9255 This is to, for example, allow the user to type "p var" or "b main"
9256 without having to specify the package name, and allow lookups
9257 of module.object to work in contexts that use the expression
9261 fixup_go_packaging (struct dwarf2_cu
*cu
)
9263 gdb::unique_xmalloc_ptr
<char> package_name
;
9264 struct pending
*list
;
9267 for (list
= *cu
->get_builder ()->get_global_symbols ();
9271 for (i
= 0; i
< list
->nsyms
; ++i
)
9273 struct symbol
*sym
= list
->symbol
[i
];
9275 if (sym
->language () == language_go
9276 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9278 gdb::unique_xmalloc_ptr
<char> this_package_name
9279 (go_symbol_package_name (sym
));
9281 if (this_package_name
== NULL
)
9283 if (package_name
== NULL
)
9284 package_name
= std::move (this_package_name
);
9287 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9288 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9289 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9290 (symbol_symtab (sym
) != NULL
9291 ? symtab_to_filename_for_display
9292 (symbol_symtab (sym
))
9293 : objfile_name (objfile
)),
9294 this_package_name
.get (), package_name
.get ());
9300 if (package_name
!= NULL
)
9302 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9303 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9304 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9305 saved_package_name
);
9308 sym
= new (&objfile
->objfile_obstack
) symbol
;
9309 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9310 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9311 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9312 e.g., "main" finds the "main" module and not C's main(). */
9313 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9314 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9315 SYMBOL_TYPE (sym
) = type
;
9317 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9321 /* Allocate a fully-qualified name consisting of the two parts on the
9325 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9327 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9330 /* A helper that allocates a variant part to attach to a Rust enum
9331 type. OBSTACK is where the results should be allocated. TYPE is
9332 the type we're processing. DISCRIMINANT_INDEX is the index of the
9333 discriminant. It must be the index of one of the fields of TYPE.
9334 DEFAULT_INDEX is the index of the default field; or -1 if there is
9335 no default. RANGES is indexed by "effective" field number (the
9336 field index, but omitting the discriminant and default fields) and
9337 must hold the discriminant values used by the variants. Note that
9338 RANGES must have a lifetime at least as long as OBSTACK -- either
9339 already allocated on it, or static. */
9342 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9343 int discriminant_index
, int default_index
,
9344 gdb::array_view
<discriminant_range
> ranges
)
9346 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9347 must be handled by the caller. */
9348 gdb_assert (discriminant_index
>= 0
9349 && discriminant_index
< type
->num_fields ());
9350 gdb_assert (default_index
== -1
9351 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9353 /* We have one variant for each non-discriminant field. */
9354 int n_variants
= type
->num_fields () - 1;
9356 variant
*variants
= new (obstack
) variant
[n_variants
];
9359 for (int i
= 0; i
< type
->num_fields (); ++i
)
9361 if (i
== discriminant_index
)
9364 variants
[var_idx
].first_field
= i
;
9365 variants
[var_idx
].last_field
= i
+ 1;
9367 /* The default field does not need a range, but other fields do.
9368 We skipped the discriminant above. */
9369 if (i
!= default_index
)
9371 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9378 gdb_assert (range_idx
== ranges
.size ());
9379 gdb_assert (var_idx
== n_variants
);
9381 variant_part
*part
= new (obstack
) variant_part
;
9382 part
->discriminant_index
= discriminant_index
;
9383 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9384 discriminant_index
));
9385 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9387 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9388 gdb::array_view
<variant_part
> *prop_value
9389 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9391 struct dynamic_prop prop
;
9392 prop
.kind
= PROP_VARIANT_PARTS
;
9393 prop
.data
.variant_parts
= prop_value
;
9395 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9398 /* Some versions of rustc emitted enums in an unusual way.
9400 Ordinary enums were emitted as unions. The first element of each
9401 structure in the union was named "RUST$ENUM$DISR". This element
9402 held the discriminant.
9404 These versions of Rust also implemented the "non-zero"
9405 optimization. When the enum had two values, and one is empty and
9406 the other holds a pointer that cannot be zero, the pointer is used
9407 as the discriminant, with a zero value meaning the empty variant.
9408 Here, the union's first member is of the form
9409 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9410 where the fieldnos are the indices of the fields that should be
9411 traversed in order to find the field (which may be several fields deep)
9412 and the variantname is the name of the variant of the case when the
9415 This function recognizes whether TYPE is of one of these forms,
9416 and, if so, smashes it to be a variant type. */
9419 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9421 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9423 /* We don't need to deal with empty enums. */
9424 if (type
->num_fields () == 0)
9427 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9428 if (type
->num_fields () == 1
9429 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9431 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9433 /* Decode the field name to find the offset of the
9435 ULONGEST bit_offset
= 0;
9436 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9437 while (name
[0] >= '0' && name
[0] <= '9')
9440 unsigned long index
= strtoul (name
, &tail
, 10);
9443 || index
>= field_type
->num_fields ()
9444 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9445 != FIELD_LOC_KIND_BITPOS
))
9447 complaint (_("Could not parse Rust enum encoding string \"%s\""
9449 TYPE_FIELD_NAME (type
, 0),
9450 objfile_name (objfile
));
9455 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9456 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9459 /* Smash this type to be a structure type. We have to do this
9460 because the type has already been recorded. */
9461 type
->set_code (TYPE_CODE_STRUCT
);
9462 type
->set_num_fields (3);
9463 /* Save the field we care about. */
9464 struct field saved_field
= type
->field (0);
9466 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9468 /* Put the discriminant at index 0. */
9469 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9470 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9471 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9472 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9474 /* The order of fields doesn't really matter, so put the real
9475 field at index 1 and the data-less field at index 2. */
9476 type
->field (1) = saved_field
;
9477 TYPE_FIELD_NAME (type
, 1)
9478 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9479 TYPE_FIELD_TYPE (type
, 1)->set_name
9480 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9481 TYPE_FIELD_NAME (type
, 1)));
9483 const char *dataless_name
9484 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9486 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9488 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9489 /* NAME points into the original discriminant name, which
9490 already has the correct lifetime. */
9491 TYPE_FIELD_NAME (type
, 2) = name
;
9492 SET_FIELD_BITPOS (type
->field (2), 0);
9494 /* Indicate that this is a variant type. */
9495 static discriminant_range ranges
[1] = { { 0, 0 } };
9496 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9498 /* A union with a single anonymous field is probably an old-style
9500 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9502 /* Smash this type to be a structure type. We have to do this
9503 because the type has already been recorded. */
9504 type
->set_code (TYPE_CODE_STRUCT
);
9506 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9507 const char *variant_name
9508 = rust_last_path_segment (field_type
->name ());
9509 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9510 field_type
->set_name
9511 (rust_fully_qualify (&objfile
->objfile_obstack
,
9512 type
->name (), variant_name
));
9516 struct type
*disr_type
= nullptr;
9517 for (int i
= 0; i
< type
->num_fields (); ++i
)
9519 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9521 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9523 /* All fields of a true enum will be structs. */
9526 else if (disr_type
->num_fields () == 0)
9528 /* Could be data-less variant, so keep going. */
9529 disr_type
= nullptr;
9531 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9532 "RUST$ENUM$DISR") != 0)
9534 /* Not a Rust enum. */
9544 /* If we got here without a discriminant, then it's probably
9546 if (disr_type
== nullptr)
9549 /* Smash this type to be a structure type. We have to do this
9550 because the type has already been recorded. */
9551 type
->set_code (TYPE_CODE_STRUCT
);
9553 /* Make space for the discriminant field. */
9554 struct field
*disr_field
= &disr_type
->field (0);
9556 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9557 * sizeof (struct field
)));
9558 memcpy (new_fields
+ 1, type
->fields (),
9559 type
->num_fields () * sizeof (struct field
));
9560 type
->set_fields (new_fields
);
9561 type
->set_num_fields (type
->num_fields () + 1);
9563 /* Install the discriminant at index 0 in the union. */
9564 type
->field (0) = *disr_field
;
9565 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9566 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9568 /* We need a way to find the correct discriminant given a
9569 variant name. For convenience we build a map here. */
9570 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9571 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9572 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9574 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9577 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9578 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9582 int n_fields
= type
->num_fields ();
9583 /* We don't need a range entry for the discriminant, but we do
9584 need one for every other field, as there is no default
9586 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9589 /* Skip the discriminant here. */
9590 for (int i
= 1; i
< n_fields
; ++i
)
9592 /* Find the final word in the name of this variant's type.
9593 That name can be used to look up the correct
9595 const char *variant_name
9596 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9598 auto iter
= discriminant_map
.find (variant_name
);
9599 if (iter
!= discriminant_map
.end ())
9601 ranges
[i
].low
= iter
->second
;
9602 ranges
[i
].high
= iter
->second
;
9605 /* Remove the discriminant field, if it exists. */
9606 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9607 if (sub_type
->num_fields () > 0)
9609 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9610 sub_type
->set_fields (sub_type
->fields () + 1);
9612 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9614 (rust_fully_qualify (&objfile
->objfile_obstack
,
9615 type
->name (), variant_name
));
9618 /* Indicate that this is a variant type. */
9619 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9620 gdb::array_view
<discriminant_range
> (ranges
,
9625 /* Rewrite some Rust unions to be structures with variants parts. */
9628 rust_union_quirks (struct dwarf2_cu
*cu
)
9630 gdb_assert (cu
->language
== language_rust
);
9631 for (type
*type_
: cu
->rust_unions
)
9632 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9633 /* We don't need this any more. */
9634 cu
->rust_unions
.clear ();
9637 /* A helper function for computing the list of all symbol tables
9638 included by PER_CU. */
9641 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9642 htab_t all_children
, htab_t all_type_symtabs
,
9643 dwarf2_per_cu_data
*per_cu
,
9644 dwarf2_per_objfile
*per_objfile
,
9645 struct compunit_symtab
*immediate_parent
)
9647 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9650 /* This inclusion and its children have been processed. */
9656 /* Only add a CU if it has a symbol table. */
9657 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9660 /* If this is a type unit only add its symbol table if we haven't
9661 seen it yet (type unit per_cu's can share symtabs). */
9662 if (per_cu
->is_debug_types
)
9664 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9668 result
->push_back (cust
);
9669 if (cust
->user
== NULL
)
9670 cust
->user
= immediate_parent
;
9675 result
->push_back (cust
);
9676 if (cust
->user
== NULL
)
9677 cust
->user
= immediate_parent
;
9681 if (!per_cu
->imported_symtabs_empty ())
9682 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9684 recursively_compute_inclusions (result
, all_children
,
9685 all_type_symtabs
, ptr
, per_objfile
,
9690 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9694 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9695 dwarf2_per_objfile
*per_objfile
)
9697 gdb_assert (! per_cu
->is_debug_types
);
9699 if (!per_cu
->imported_symtabs_empty ())
9702 std::vector
<compunit_symtab
*> result_symtabs
;
9703 htab_t all_children
, all_type_symtabs
;
9704 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9706 /* If we don't have a symtab, we can just skip this case. */
9710 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9711 NULL
, xcalloc
, xfree
);
9712 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9713 NULL
, xcalloc
, xfree
);
9715 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9717 recursively_compute_inclusions (&result_symtabs
, all_children
,
9718 all_type_symtabs
, ptr
, per_objfile
,
9722 /* Now we have a transitive closure of all the included symtabs. */
9723 len
= result_symtabs
.size ();
9725 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9726 struct compunit_symtab
*, len
+ 1);
9727 memcpy (cust
->includes
, result_symtabs
.data (),
9728 len
* sizeof (compunit_symtab
*));
9729 cust
->includes
[len
] = NULL
;
9731 htab_delete (all_children
);
9732 htab_delete (all_type_symtabs
);
9736 /* Compute the 'includes' field for the symtabs of all the CUs we just
9740 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9742 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->per_bfd
->just_read_cus
)
9744 if (! iter
->is_debug_types
)
9745 compute_compunit_symtab_includes (iter
, dwarf2_per_objfile
);
9748 dwarf2_per_objfile
->per_bfd
->just_read_cus
.clear ();
9751 /* Generate full symbol information for PER_CU, whose DIEs have
9752 already been loaded into memory. */
9755 process_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
9756 dwarf2_per_objfile
*dwarf2_per_objfile
,
9757 enum language pretend_language
)
9759 struct dwarf2_cu
*cu
= per_cu
->cu
;
9760 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9761 struct gdbarch
*gdbarch
= objfile
->arch ();
9762 CORE_ADDR lowpc
, highpc
;
9763 struct compunit_symtab
*cust
;
9765 struct block
*static_block
;
9768 baseaddr
= objfile
->text_section_offset ();
9770 /* Clear the list here in case something was left over. */
9771 cu
->method_list
.clear ();
9773 cu
->language
= pretend_language
;
9774 cu
->language_defn
= language_def (cu
->language
);
9776 /* Do line number decoding in read_file_scope () */
9777 process_die (cu
->dies
, cu
);
9779 /* For now fudge the Go package. */
9780 if (cu
->language
== language_go
)
9781 fixup_go_packaging (cu
);
9783 /* Now that we have processed all the DIEs in the CU, all the types
9784 should be complete, and it should now be safe to compute all of the
9786 compute_delayed_physnames (cu
);
9788 if (cu
->language
== language_rust
)
9789 rust_union_quirks (cu
);
9791 /* Some compilers don't define a DW_AT_high_pc attribute for the
9792 compilation unit. If the DW_AT_high_pc is missing, synthesize
9793 it, by scanning the DIE's below the compilation unit. */
9794 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9796 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9797 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9799 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9800 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9801 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9802 addrmap to help ensure it has an accurate map of pc values belonging to
9804 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9806 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9807 SECT_OFF_TEXT (objfile
),
9812 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9814 /* Set symtab language to language from DW_AT_language. If the
9815 compilation is from a C file generated by language preprocessors, do
9816 not set the language if it was already deduced by start_subfile. */
9817 if (!(cu
->language
== language_c
9818 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9819 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9821 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9822 produce DW_AT_location with location lists but it can be possibly
9823 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9824 there were bugs in prologue debug info, fixed later in GCC-4.5
9825 by "unwind info for epilogues" patch (which is not directly related).
9827 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9828 needed, it would be wrong due to missing DW_AT_producer there.
9830 Still one can confuse GDB by using non-standard GCC compilation
9831 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9833 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9834 cust
->locations_valid
= 1;
9836 if (gcc_4_minor
>= 5)
9837 cust
->epilogue_unwind_valid
= 1;
9839 cust
->call_site_htab
= cu
->call_site_htab
;
9842 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9844 /* Push it for inclusion processing later. */
9845 dwarf2_per_objfile
->per_bfd
->just_read_cus
.push_back (per_cu
);
9847 /* Not needed any more. */
9848 cu
->reset_builder ();
9851 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9852 already been loaded into memory. */
9855 process_full_type_unit (dwarf2_per_cu_data
*per_cu
,
9856 dwarf2_per_objfile
*dwarf2_per_objfile
,
9857 enum language pretend_language
)
9859 struct dwarf2_cu
*cu
= per_cu
->cu
;
9860 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9861 struct compunit_symtab
*cust
;
9862 struct signatured_type
*sig_type
;
9864 gdb_assert (per_cu
->is_debug_types
);
9865 sig_type
= (struct signatured_type
*) per_cu
;
9867 /* Clear the list here in case something was left over. */
9868 cu
->method_list
.clear ();
9870 cu
->language
= pretend_language
;
9871 cu
->language_defn
= language_def (cu
->language
);
9873 /* The symbol tables are set up in read_type_unit_scope. */
9874 process_die (cu
->dies
, cu
);
9876 /* For now fudge the Go package. */
9877 if (cu
->language
== language_go
)
9878 fixup_go_packaging (cu
);
9880 /* Now that we have processed all the DIEs in the CU, all the types
9881 should be complete, and it should now be safe to compute all of the
9883 compute_delayed_physnames (cu
);
9885 if (cu
->language
== language_rust
)
9886 rust_union_quirks (cu
);
9888 /* TUs share symbol tables.
9889 If this is the first TU to use this symtab, complete the construction
9890 of it with end_expandable_symtab. Otherwise, complete the addition of
9891 this TU's symbols to the existing symtab. */
9892 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9894 buildsym_compunit
*builder
= cu
->get_builder ();
9895 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9896 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9900 /* Set symtab language to language from DW_AT_language. If the
9901 compilation is from a C file generated by language preprocessors,
9902 do not set the language if it was already deduced by
9904 if (!(cu
->language
== language_c
9905 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9906 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9911 cu
->get_builder ()->augment_type_symtab ();
9912 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9915 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9917 /* Not needed any more. */
9918 cu
->reset_builder ();
9921 /* Process an imported unit DIE. */
9924 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9926 struct attribute
*attr
;
9928 /* For now we don't handle imported units in type units. */
9929 if (cu
->per_cu
->is_debug_types
)
9931 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9932 " supported in type units [in module %s]"),
9933 objfile_name (cu
->per_objfile
->objfile
));
9936 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9939 sect_offset sect_off
= attr
->get_ref_die_offset ();
9940 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9941 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9942 dwarf2_per_cu_data
*per_cu
9943 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9945 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9946 into another compilation unit, at root level. Regard this as a hint,
9948 if (die
->parent
&& die
->parent
->parent
== NULL
9949 && per_cu
->unit_type
== DW_UT_compile
9950 && per_cu
->lang
== language_cplus
)
9953 /* If necessary, add it to the queue and load its DIEs. */
9954 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
9955 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
9957 cu
->per_cu
->imported_symtabs_push (per_cu
);
9961 /* RAII object that represents a process_die scope: i.e.,
9962 starts/finishes processing a DIE. */
9963 class process_die_scope
9966 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9967 : m_die (die
), m_cu (cu
)
9969 /* We should only be processing DIEs not already in process. */
9970 gdb_assert (!m_die
->in_process
);
9971 m_die
->in_process
= true;
9974 ~process_die_scope ()
9976 m_die
->in_process
= false;
9978 /* If we're done processing the DIE for the CU that owns the line
9979 header, we don't need the line header anymore. */
9980 if (m_cu
->line_header_die_owner
== m_die
)
9982 delete m_cu
->line_header
;
9983 m_cu
->line_header
= NULL
;
9984 m_cu
->line_header_die_owner
= NULL
;
9993 /* Process a die and its children. */
9996 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9998 process_die_scope
scope (die
, cu
);
10002 case DW_TAG_padding
:
10004 case DW_TAG_compile_unit
:
10005 case DW_TAG_partial_unit
:
10006 read_file_scope (die
, cu
);
10008 case DW_TAG_type_unit
:
10009 read_type_unit_scope (die
, cu
);
10011 case DW_TAG_subprogram
:
10012 /* Nested subprograms in Fortran get a prefix. */
10013 if (cu
->language
== language_fortran
10014 && die
->parent
!= NULL
10015 && die
->parent
->tag
== DW_TAG_subprogram
)
10016 cu
->processing_has_namespace_info
= true;
10017 /* Fall through. */
10018 case DW_TAG_inlined_subroutine
:
10019 read_func_scope (die
, cu
);
10021 case DW_TAG_lexical_block
:
10022 case DW_TAG_try_block
:
10023 case DW_TAG_catch_block
:
10024 read_lexical_block_scope (die
, cu
);
10026 case DW_TAG_call_site
:
10027 case DW_TAG_GNU_call_site
:
10028 read_call_site_scope (die
, cu
);
10030 case DW_TAG_class_type
:
10031 case DW_TAG_interface_type
:
10032 case DW_TAG_structure_type
:
10033 case DW_TAG_union_type
:
10034 process_structure_scope (die
, cu
);
10036 case DW_TAG_enumeration_type
:
10037 process_enumeration_scope (die
, cu
);
10040 /* These dies have a type, but processing them does not create
10041 a symbol or recurse to process the children. Therefore we can
10042 read them on-demand through read_type_die. */
10043 case DW_TAG_subroutine_type
:
10044 case DW_TAG_set_type
:
10045 case DW_TAG_array_type
:
10046 case DW_TAG_pointer_type
:
10047 case DW_TAG_ptr_to_member_type
:
10048 case DW_TAG_reference_type
:
10049 case DW_TAG_rvalue_reference_type
:
10050 case DW_TAG_string_type
:
10053 case DW_TAG_base_type
:
10054 case DW_TAG_subrange_type
:
10055 case DW_TAG_typedef
:
10056 /* Add a typedef symbol for the type definition, if it has a
10058 new_symbol (die
, read_type_die (die
, cu
), cu
);
10060 case DW_TAG_common_block
:
10061 read_common_block (die
, cu
);
10063 case DW_TAG_common_inclusion
:
10065 case DW_TAG_namespace
:
10066 cu
->processing_has_namespace_info
= true;
10067 read_namespace (die
, cu
);
10069 case DW_TAG_module
:
10070 cu
->processing_has_namespace_info
= true;
10071 read_module (die
, cu
);
10073 case DW_TAG_imported_declaration
:
10074 cu
->processing_has_namespace_info
= true;
10075 if (read_namespace_alias (die
, cu
))
10077 /* The declaration is not a global namespace alias. */
10078 /* Fall through. */
10079 case DW_TAG_imported_module
:
10080 cu
->processing_has_namespace_info
= true;
10081 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10082 || cu
->language
!= language_fortran
))
10083 complaint (_("Tag '%s' has unexpected children"),
10084 dwarf_tag_name (die
->tag
));
10085 read_import_statement (die
, cu
);
10088 case DW_TAG_imported_unit
:
10089 process_imported_unit_die (die
, cu
);
10092 case DW_TAG_variable
:
10093 read_variable (die
, cu
);
10097 new_symbol (die
, NULL
, cu
);
10102 /* DWARF name computation. */
10104 /* A helper function for dwarf2_compute_name which determines whether DIE
10105 needs to have the name of the scope prepended to the name listed in the
10109 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10111 struct attribute
*attr
;
10115 case DW_TAG_namespace
:
10116 case DW_TAG_typedef
:
10117 case DW_TAG_class_type
:
10118 case DW_TAG_interface_type
:
10119 case DW_TAG_structure_type
:
10120 case DW_TAG_union_type
:
10121 case DW_TAG_enumeration_type
:
10122 case DW_TAG_enumerator
:
10123 case DW_TAG_subprogram
:
10124 case DW_TAG_inlined_subroutine
:
10125 case DW_TAG_member
:
10126 case DW_TAG_imported_declaration
:
10129 case DW_TAG_variable
:
10130 case DW_TAG_constant
:
10131 /* We only need to prefix "globally" visible variables. These include
10132 any variable marked with DW_AT_external or any variable that
10133 lives in a namespace. [Variables in anonymous namespaces
10134 require prefixing, but they are not DW_AT_external.] */
10136 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10138 struct dwarf2_cu
*spec_cu
= cu
;
10140 return die_needs_namespace (die_specification (die
, &spec_cu
),
10144 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10145 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10146 && die
->parent
->tag
!= DW_TAG_module
)
10148 /* A variable in a lexical block of some kind does not need a
10149 namespace, even though in C++ such variables may be external
10150 and have a mangled name. */
10151 if (die
->parent
->tag
== DW_TAG_lexical_block
10152 || die
->parent
->tag
== DW_TAG_try_block
10153 || die
->parent
->tag
== DW_TAG_catch_block
10154 || die
->parent
->tag
== DW_TAG_subprogram
)
10163 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10164 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10165 defined for the given DIE. */
10167 static struct attribute
*
10168 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10170 struct attribute
*attr
;
10172 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10174 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10179 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10180 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10181 defined for the given DIE. */
10183 static const char *
10184 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10186 const char *linkage_name
;
10188 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10189 if (linkage_name
== NULL
)
10190 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10192 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10193 See https://github.com/rust-lang/rust/issues/32925. */
10194 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10195 && strchr (linkage_name
, '{') != NULL
)
10196 linkage_name
= NULL
;
10198 return linkage_name
;
10201 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10202 compute the physname for the object, which include a method's:
10203 - formal parameters (C++),
10204 - receiver type (Go),
10206 The term "physname" is a bit confusing.
10207 For C++, for example, it is the demangled name.
10208 For Go, for example, it's the mangled name.
10210 For Ada, return the DIE's linkage name rather than the fully qualified
10211 name. PHYSNAME is ignored..
10213 The result is allocated on the objfile->per_bfd's obstack and
10216 static const char *
10217 dwarf2_compute_name (const char *name
,
10218 struct die_info
*die
, struct dwarf2_cu
*cu
,
10221 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10224 name
= dwarf2_name (die
, cu
);
10226 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10227 but otherwise compute it by typename_concat inside GDB.
10228 FIXME: Actually this is not really true, or at least not always true.
10229 It's all very confusing. compute_and_set_names doesn't try to demangle
10230 Fortran names because there is no mangling standard. So new_symbol
10231 will set the demangled name to the result of dwarf2_full_name, and it is
10232 the demangled name that GDB uses if it exists. */
10233 if (cu
->language
== language_ada
10234 || (cu
->language
== language_fortran
&& physname
))
10236 /* For Ada unit, we prefer the linkage name over the name, as
10237 the former contains the exported name, which the user expects
10238 to be able to reference. Ideally, we want the user to be able
10239 to reference this entity using either natural or linkage name,
10240 but we haven't started looking at this enhancement yet. */
10241 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10243 if (linkage_name
!= NULL
)
10244 return linkage_name
;
10247 /* These are the only languages we know how to qualify names in. */
10249 && (cu
->language
== language_cplus
10250 || cu
->language
== language_fortran
|| cu
->language
== language_d
10251 || cu
->language
== language_rust
))
10253 if (die_needs_namespace (die
, cu
))
10255 const char *prefix
;
10256 const char *canonical_name
= NULL
;
10260 prefix
= determine_prefix (die
, cu
);
10261 if (*prefix
!= '\0')
10263 gdb::unique_xmalloc_ptr
<char> prefixed_name
10264 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10266 buf
.puts (prefixed_name
.get ());
10271 /* Template parameters may be specified in the DIE's DW_AT_name, or
10272 as children with DW_TAG_template_type_param or
10273 DW_TAG_value_type_param. If the latter, add them to the name
10274 here. If the name already has template parameters, then
10275 skip this step; some versions of GCC emit both, and
10276 it is more efficient to use the pre-computed name.
10278 Something to keep in mind about this process: it is very
10279 unlikely, or in some cases downright impossible, to produce
10280 something that will match the mangled name of a function.
10281 If the definition of the function has the same debug info,
10282 we should be able to match up with it anyway. But fallbacks
10283 using the minimal symbol, for instance to find a method
10284 implemented in a stripped copy of libstdc++, will not work.
10285 If we do not have debug info for the definition, we will have to
10286 match them up some other way.
10288 When we do name matching there is a related problem with function
10289 templates; two instantiated function templates are allowed to
10290 differ only by their return types, which we do not add here. */
10292 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10294 struct attribute
*attr
;
10295 struct die_info
*child
;
10298 die
->building_fullname
= 1;
10300 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10304 const gdb_byte
*bytes
;
10305 struct dwarf2_locexpr_baton
*baton
;
10308 if (child
->tag
!= DW_TAG_template_type_param
10309 && child
->tag
!= DW_TAG_template_value_param
)
10320 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10323 complaint (_("template parameter missing DW_AT_type"));
10324 buf
.puts ("UNKNOWN_TYPE");
10327 type
= die_type (child
, cu
);
10329 if (child
->tag
== DW_TAG_template_type_param
)
10331 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10332 &type_print_raw_options
);
10336 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10339 complaint (_("template parameter missing "
10340 "DW_AT_const_value"));
10341 buf
.puts ("UNKNOWN_VALUE");
10345 dwarf2_const_value_attr (attr
, type
, name
,
10346 &cu
->comp_unit_obstack
, cu
,
10347 &value
, &bytes
, &baton
);
10349 if (TYPE_NOSIGN (type
))
10350 /* GDB prints characters as NUMBER 'CHAR'. If that's
10351 changed, this can use value_print instead. */
10352 c_printchar (value
, type
, &buf
);
10355 struct value_print_options opts
;
10358 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10362 baton
->per_objfile
);
10363 else if (bytes
!= NULL
)
10365 v
= allocate_value (type
);
10366 memcpy (value_contents_writeable (v
), bytes
,
10367 TYPE_LENGTH (type
));
10370 v
= value_from_longest (type
, value
);
10372 /* Specify decimal so that we do not depend on
10374 get_formatted_print_options (&opts
, 'd');
10376 value_print (v
, &buf
, &opts
);
10381 die
->building_fullname
= 0;
10385 /* Close the argument list, with a space if necessary
10386 (nested templates). */
10387 if (!buf
.empty () && buf
.string ().back () == '>')
10394 /* For C++ methods, append formal parameter type
10395 information, if PHYSNAME. */
10397 if (physname
&& die
->tag
== DW_TAG_subprogram
10398 && cu
->language
== language_cplus
)
10400 struct type
*type
= read_type_die (die
, cu
);
10402 c_type_print_args (type
, &buf
, 1, cu
->language
,
10403 &type_print_raw_options
);
10405 if (cu
->language
== language_cplus
)
10407 /* Assume that an artificial first parameter is
10408 "this", but do not crash if it is not. RealView
10409 marks unnamed (and thus unused) parameters as
10410 artificial; there is no way to differentiate
10412 if (type
->num_fields () > 0
10413 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10414 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10415 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10417 buf
.puts (" const");
10421 const std::string
&intermediate_name
= buf
.string ();
10423 if (cu
->language
== language_cplus
)
10425 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10428 /* If we only computed INTERMEDIATE_NAME, or if
10429 INTERMEDIATE_NAME is already canonical, then we need to
10431 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10432 name
= objfile
->intern (intermediate_name
);
10434 name
= canonical_name
;
10441 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10442 If scope qualifiers are appropriate they will be added. The result
10443 will be allocated on the storage_obstack, or NULL if the DIE does
10444 not have a name. NAME may either be from a previous call to
10445 dwarf2_name or NULL.
10447 The output string will be canonicalized (if C++). */
10449 static const char *
10450 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10452 return dwarf2_compute_name (name
, die
, cu
, 0);
10455 /* Construct a physname for the given DIE in CU. NAME may either be
10456 from a previous call to dwarf2_name or NULL. The result will be
10457 allocated on the objfile_objstack or NULL if the DIE does not have a
10460 The output string will be canonicalized (if C++). */
10462 static const char *
10463 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10465 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10466 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10469 /* In this case dwarf2_compute_name is just a shortcut not building anything
10471 if (!die_needs_namespace (die
, cu
))
10472 return dwarf2_compute_name (name
, die
, cu
, 1);
10474 if (cu
->language
!= language_rust
)
10475 mangled
= dw2_linkage_name (die
, cu
);
10477 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10479 gdb::unique_xmalloc_ptr
<char> demangled
;
10480 if (mangled
!= NULL
)
10483 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10485 /* Do nothing (do not demangle the symbol name). */
10487 else if (cu
->language
== language_go
)
10489 /* This is a lie, but we already lie to the caller new_symbol.
10490 new_symbol assumes we return the mangled name.
10491 This just undoes that lie until things are cleaned up. */
10495 /* Use DMGL_RET_DROP for C++ template functions to suppress
10496 their return type. It is easier for GDB users to search
10497 for such functions as `name(params)' than `long name(params)'.
10498 In such case the minimal symbol names do not match the full
10499 symbol names but for template functions there is never a need
10500 to look up their definition from their declaration so
10501 the only disadvantage remains the minimal symbol variant
10502 `long name(params)' does not have the proper inferior type. */
10503 demangled
.reset (gdb_demangle (mangled
,
10504 (DMGL_PARAMS
| DMGL_ANSI
10505 | DMGL_RET_DROP
)));
10508 canon
= demangled
.get ();
10516 if (canon
== NULL
|| check_physname
)
10518 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10520 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10522 /* It may not mean a bug in GDB. The compiler could also
10523 compute DW_AT_linkage_name incorrectly. But in such case
10524 GDB would need to be bug-to-bug compatible. */
10526 complaint (_("Computed physname <%s> does not match demangled <%s> "
10527 "(from linkage <%s>) - DIE at %s [in module %s]"),
10528 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10529 objfile_name (objfile
));
10531 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10532 is available here - over computed PHYSNAME. It is safer
10533 against both buggy GDB and buggy compilers. */
10547 retval
= objfile
->intern (retval
);
10552 /* Inspect DIE in CU for a namespace alias. If one exists, record
10553 a new symbol for it.
10555 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10558 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10560 struct attribute
*attr
;
10562 /* If the die does not have a name, this is not a namespace
10564 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10568 struct die_info
*d
= die
;
10569 struct dwarf2_cu
*imported_cu
= cu
;
10571 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10572 keep inspecting DIEs until we hit the underlying import. */
10573 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10574 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10576 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10580 d
= follow_die_ref (d
, attr
, &imported_cu
);
10581 if (d
->tag
!= DW_TAG_imported_declaration
)
10585 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10587 complaint (_("DIE at %s has too many recursively imported "
10588 "declarations"), sect_offset_str (d
->sect_off
));
10595 sect_offset sect_off
= attr
->get_ref_die_offset ();
10597 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10598 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10600 /* This declaration is a global namespace alias. Add
10601 a symbol for it whose type is the aliased namespace. */
10602 new_symbol (die
, type
, cu
);
10611 /* Return the using directives repository (global or local?) to use in the
10612 current context for CU.
10614 For Ada, imported declarations can materialize renamings, which *may* be
10615 global. However it is impossible (for now?) in DWARF to distinguish
10616 "external" imported declarations and "static" ones. As all imported
10617 declarations seem to be static in all other languages, make them all CU-wide
10618 global only in Ada. */
10620 static struct using_direct
**
10621 using_directives (struct dwarf2_cu
*cu
)
10623 if (cu
->language
== language_ada
10624 && cu
->get_builder ()->outermost_context_p ())
10625 return cu
->get_builder ()->get_global_using_directives ();
10627 return cu
->get_builder ()->get_local_using_directives ();
10630 /* Read the import statement specified by the given die and record it. */
10633 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10635 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10636 struct attribute
*import_attr
;
10637 struct die_info
*imported_die
, *child_die
;
10638 struct dwarf2_cu
*imported_cu
;
10639 const char *imported_name
;
10640 const char *imported_name_prefix
;
10641 const char *canonical_name
;
10642 const char *import_alias
;
10643 const char *imported_declaration
= NULL
;
10644 const char *import_prefix
;
10645 std::vector
<const char *> excludes
;
10647 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10648 if (import_attr
== NULL
)
10650 complaint (_("Tag '%s' has no DW_AT_import"),
10651 dwarf_tag_name (die
->tag
));
10656 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10657 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10658 if (imported_name
== NULL
)
10660 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10662 The import in the following code:
10676 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10677 <52> DW_AT_decl_file : 1
10678 <53> DW_AT_decl_line : 6
10679 <54> DW_AT_import : <0x75>
10680 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10681 <59> DW_AT_name : B
10682 <5b> DW_AT_decl_file : 1
10683 <5c> DW_AT_decl_line : 2
10684 <5d> DW_AT_type : <0x6e>
10686 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10687 <76> DW_AT_byte_size : 4
10688 <77> DW_AT_encoding : 5 (signed)
10690 imports the wrong die ( 0x75 instead of 0x58 ).
10691 This case will be ignored until the gcc bug is fixed. */
10695 /* Figure out the local name after import. */
10696 import_alias
= dwarf2_name (die
, cu
);
10698 /* Figure out where the statement is being imported to. */
10699 import_prefix
= determine_prefix (die
, cu
);
10701 /* Figure out what the scope of the imported die is and prepend it
10702 to the name of the imported die. */
10703 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10705 if (imported_die
->tag
!= DW_TAG_namespace
10706 && imported_die
->tag
!= DW_TAG_module
)
10708 imported_declaration
= imported_name
;
10709 canonical_name
= imported_name_prefix
;
10711 else if (strlen (imported_name_prefix
) > 0)
10712 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10713 imported_name_prefix
,
10714 (cu
->language
== language_d
? "." : "::"),
10715 imported_name
, (char *) NULL
);
10717 canonical_name
= imported_name
;
10719 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10720 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10721 child_die
= child_die
->sibling
)
10723 /* DWARF-4: A Fortran use statement with a “rename list” may be
10724 represented by an imported module entry with an import attribute
10725 referring to the module and owned entries corresponding to those
10726 entities that are renamed as part of being imported. */
10728 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10730 complaint (_("child DW_TAG_imported_declaration expected "
10731 "- DIE at %s [in module %s]"),
10732 sect_offset_str (child_die
->sect_off
),
10733 objfile_name (objfile
));
10737 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10738 if (import_attr
== NULL
)
10740 complaint (_("Tag '%s' has no DW_AT_import"),
10741 dwarf_tag_name (child_die
->tag
));
10746 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10748 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10749 if (imported_name
== NULL
)
10751 complaint (_("child DW_TAG_imported_declaration has unknown "
10752 "imported name - DIE at %s [in module %s]"),
10753 sect_offset_str (child_die
->sect_off
),
10754 objfile_name (objfile
));
10758 excludes
.push_back (imported_name
);
10760 process_die (child_die
, cu
);
10763 add_using_directive (using_directives (cu
),
10767 imported_declaration
,
10770 &objfile
->objfile_obstack
);
10773 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10774 types, but gives them a size of zero. Starting with version 14,
10775 ICC is compatible with GCC. */
10778 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10780 if (!cu
->checked_producer
)
10781 check_producer (cu
);
10783 return cu
->producer_is_icc_lt_14
;
10786 /* ICC generates a DW_AT_type for C void functions. This was observed on
10787 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10788 which says that void functions should not have a DW_AT_type. */
10791 producer_is_icc (struct dwarf2_cu
*cu
)
10793 if (!cu
->checked_producer
)
10794 check_producer (cu
);
10796 return cu
->producer_is_icc
;
10799 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10800 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10801 this, it was first present in GCC release 4.3.0. */
10804 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10806 if (!cu
->checked_producer
)
10807 check_producer (cu
);
10809 return cu
->producer_is_gcc_lt_4_3
;
10812 static file_and_directory
10813 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10815 file_and_directory res
;
10817 /* Find the filename. Do not use dwarf2_name here, since the filename
10818 is not a source language identifier. */
10819 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10820 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10822 if (res
.comp_dir
== NULL
10823 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10824 && IS_ABSOLUTE_PATH (res
.name
))
10826 res
.comp_dir_storage
= ldirname (res
.name
);
10827 if (!res
.comp_dir_storage
.empty ())
10828 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10830 if (res
.comp_dir
!= NULL
)
10832 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10833 directory, get rid of it. */
10834 const char *cp
= strchr (res
.comp_dir
, ':');
10836 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10837 res
.comp_dir
= cp
+ 1;
10840 if (res
.name
== NULL
)
10841 res
.name
= "<unknown>";
10846 /* Handle DW_AT_stmt_list for a compilation unit.
10847 DIE is the DW_TAG_compile_unit die for CU.
10848 COMP_DIR is the compilation directory. LOWPC is passed to
10849 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10852 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10853 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10855 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10856 struct attribute
*attr
;
10857 struct line_header line_header_local
;
10858 hashval_t line_header_local_hash
;
10860 int decode_mapping
;
10862 gdb_assert (! cu
->per_cu
->is_debug_types
);
10864 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10868 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10870 /* The line header hash table is only created if needed (it exists to
10871 prevent redundant reading of the line table for partial_units).
10872 If we're given a partial_unit, we'll need it. If we're given a
10873 compile_unit, then use the line header hash table if it's already
10874 created, but don't create one just yet. */
10876 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
10877 && die
->tag
== DW_TAG_partial_unit
)
10879 dwarf2_per_objfile
->per_bfd
->line_header_hash
10880 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10881 line_header_eq_voidp
,
10882 free_line_header_voidp
,
10886 line_header_local
.sect_off
= line_offset
;
10887 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10888 line_header_local_hash
= line_header_hash (&line_header_local
);
10889 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
!= NULL
)
10891 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10892 &line_header_local
,
10893 line_header_local_hash
, NO_INSERT
);
10895 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10896 is not present in *SLOT (since if there is something in *SLOT then
10897 it will be for a partial_unit). */
10898 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10900 gdb_assert (*slot
!= NULL
);
10901 cu
->line_header
= (struct line_header
*) *slot
;
10906 /* dwarf_decode_line_header does not yet provide sufficient information.
10907 We always have to call also dwarf_decode_lines for it. */
10908 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10912 cu
->line_header
= lh
.release ();
10913 cu
->line_header_die_owner
= die
;
10915 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
)
10919 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10920 &line_header_local
,
10921 line_header_local_hash
, INSERT
);
10922 gdb_assert (slot
!= NULL
);
10924 if (slot
!= NULL
&& *slot
== NULL
)
10926 /* This newly decoded line number information unit will be owned
10927 by line_header_hash hash table. */
10928 *slot
= cu
->line_header
;
10929 cu
->line_header_die_owner
= NULL
;
10933 /* We cannot free any current entry in (*slot) as that struct line_header
10934 may be already used by multiple CUs. Create only temporary decoded
10935 line_header for this CU - it may happen at most once for each line
10936 number information unit. And if we're not using line_header_hash
10937 then this is what we want as well. */
10938 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10940 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10941 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10946 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10949 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10951 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10952 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10953 struct gdbarch
*gdbarch
= objfile
->arch ();
10954 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10955 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10956 struct attribute
*attr
;
10957 struct die_info
*child_die
;
10958 CORE_ADDR baseaddr
;
10960 prepare_one_comp_unit (cu
, die
, cu
->language
);
10961 baseaddr
= objfile
->text_section_offset ();
10963 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10965 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10966 from finish_block. */
10967 if (lowpc
== ((CORE_ADDR
) -1))
10969 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10971 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10973 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10974 standardised yet. As a workaround for the language detection we fall
10975 back to the DW_AT_producer string. */
10976 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10977 cu
->language
= language_opencl
;
10979 /* Similar hack for Go. */
10980 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10981 set_cu_language (DW_LANG_Go
, cu
);
10983 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10985 /* Decode line number information if present. We do this before
10986 processing child DIEs, so that the line header table is available
10987 for DW_AT_decl_file. */
10988 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10990 /* Process all dies in compilation unit. */
10991 if (die
->child
!= NULL
)
10993 child_die
= die
->child
;
10994 while (child_die
&& child_die
->tag
)
10996 process_die (child_die
, cu
);
10997 child_die
= child_die
->sibling
;
11001 /* Decode macro information, if present. Dwarf 2 macro information
11002 refers to information in the line number info statement program
11003 header, so we can only read it if we've read the header
11005 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11007 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11008 if (attr
&& cu
->line_header
)
11010 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11011 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11013 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11017 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11018 if (attr
&& cu
->line_header
)
11020 unsigned int macro_offset
= DW_UNSND (attr
);
11022 dwarf_decode_macros (cu
, macro_offset
, 0);
11028 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11030 struct type_unit_group
*tu_group
;
11032 struct attribute
*attr
;
11034 struct signatured_type
*sig_type
;
11036 gdb_assert (per_cu
->is_debug_types
);
11037 sig_type
= (struct signatured_type
*) per_cu
;
11039 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11041 /* If we're using .gdb_index (includes -readnow) then
11042 per_cu->type_unit_group may not have been set up yet. */
11043 if (sig_type
->type_unit_group
== NULL
)
11044 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11045 tu_group
= sig_type
->type_unit_group
;
11047 /* If we've already processed this stmt_list there's no real need to
11048 do it again, we could fake it and just recreate the part we need
11049 (file name,index -> symtab mapping). If data shows this optimization
11050 is useful we can do it then. */
11051 first_time
= tu_group
->compunit_symtab
== NULL
;
11053 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11058 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11059 lh
= dwarf_decode_line_header (line_offset
, this);
11064 start_symtab ("", NULL
, 0);
11067 gdb_assert (tu_group
->symtabs
== NULL
);
11068 gdb_assert (m_builder
== nullptr);
11069 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11070 m_builder
.reset (new struct buildsym_compunit
11071 (COMPUNIT_OBJFILE (cust
), "",
11072 COMPUNIT_DIRNAME (cust
),
11073 compunit_language (cust
),
11075 list_in_scope
= get_builder ()->get_file_symbols ();
11080 line_header
= lh
.release ();
11081 line_header_die_owner
= die
;
11085 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11087 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11088 still initializing it, and our caller (a few levels up)
11089 process_full_type_unit still needs to know if this is the first
11093 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11094 struct symtab
*, line_header
->file_names_size ());
11096 auto &file_names
= line_header
->file_names ();
11097 for (i
= 0; i
< file_names
.size (); ++i
)
11099 file_entry
&fe
= file_names
[i
];
11100 dwarf2_start_subfile (this, fe
.name
,
11101 fe
.include_dir (line_header
));
11102 buildsym_compunit
*b
= get_builder ();
11103 if (b
->get_current_subfile ()->symtab
== NULL
)
11105 /* NOTE: start_subfile will recognize when it's been
11106 passed a file it has already seen. So we can't
11107 assume there's a simple mapping from
11108 cu->line_header->file_names to subfiles, plus
11109 cu->line_header->file_names may contain dups. */
11110 b
->get_current_subfile ()->symtab
11111 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11114 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11115 tu_group
->symtabs
[i
] = fe
.symtab
;
11120 gdb_assert (m_builder
== nullptr);
11121 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11122 m_builder
.reset (new struct buildsym_compunit
11123 (COMPUNIT_OBJFILE (cust
), "",
11124 COMPUNIT_DIRNAME (cust
),
11125 compunit_language (cust
),
11127 list_in_scope
= get_builder ()->get_file_symbols ();
11129 auto &file_names
= line_header
->file_names ();
11130 for (i
= 0; i
< file_names
.size (); ++i
)
11132 file_entry
&fe
= file_names
[i
];
11133 fe
.symtab
= tu_group
->symtabs
[i
];
11137 /* The main symtab is allocated last. Type units don't have DW_AT_name
11138 so they don't have a "real" (so to speak) symtab anyway.
11139 There is later code that will assign the main symtab to all symbols
11140 that don't have one. We need to handle the case of a symbol with a
11141 missing symtab (DW_AT_decl_file) anyway. */
11144 /* Process DW_TAG_type_unit.
11145 For TUs we want to skip the first top level sibling if it's not the
11146 actual type being defined by this TU. In this case the first top
11147 level sibling is there to provide context only. */
11150 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11152 struct die_info
*child_die
;
11154 prepare_one_comp_unit (cu
, die
, language_minimal
);
11156 /* Initialize (or reinitialize) the machinery for building symtabs.
11157 We do this before processing child DIEs, so that the line header table
11158 is available for DW_AT_decl_file. */
11159 cu
->setup_type_unit_groups (die
);
11161 if (die
->child
!= NULL
)
11163 child_die
= die
->child
;
11164 while (child_die
&& child_die
->tag
)
11166 process_die (child_die
, cu
);
11167 child_die
= child_die
->sibling
;
11174 http://gcc.gnu.org/wiki/DebugFission
11175 http://gcc.gnu.org/wiki/DebugFissionDWP
11177 To simplify handling of both DWO files ("object" files with the DWARF info)
11178 and DWP files (a file with the DWOs packaged up into one file), we treat
11179 DWP files as having a collection of virtual DWO files. */
11182 hash_dwo_file (const void *item
)
11184 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11187 hash
= htab_hash_string (dwo_file
->dwo_name
);
11188 if (dwo_file
->comp_dir
!= NULL
)
11189 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11194 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11196 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11197 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11199 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11201 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11202 return lhs
->comp_dir
== rhs
->comp_dir
;
11203 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11206 /* Allocate a hash table for DWO files. */
11209 allocate_dwo_file_hash_table ()
11211 auto delete_dwo_file
= [] (void *item
)
11213 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11218 return htab_up (htab_create_alloc (41,
11225 /* Lookup DWO file DWO_NAME. */
11228 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11229 const char *dwo_name
,
11230 const char *comp_dir
)
11232 struct dwo_file find_entry
;
11235 if (dwarf2_per_objfile
->per_bfd
->dwo_files
== NULL
)
11236 dwarf2_per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11238 find_entry
.dwo_name
= dwo_name
;
11239 find_entry
.comp_dir
= comp_dir
;
11240 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11247 hash_dwo_unit (const void *item
)
11249 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11251 /* This drops the top 32 bits of the id, but is ok for a hash. */
11252 return dwo_unit
->signature
;
11256 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11258 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11259 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11261 /* The signature is assumed to be unique within the DWO file.
11262 So while object file CU dwo_id's always have the value zero,
11263 that's OK, assuming each object file DWO file has only one CU,
11264 and that's the rule for now. */
11265 return lhs
->signature
== rhs
->signature
;
11268 /* Allocate a hash table for DWO CUs,TUs.
11269 There is one of these tables for each of CUs,TUs for each DWO file. */
11272 allocate_dwo_unit_table ()
11274 /* Start out with a pretty small number.
11275 Generally DWO files contain only one CU and maybe some TUs. */
11276 return htab_up (htab_create_alloc (3,
11279 NULL
, xcalloc
, xfree
));
11282 /* die_reader_func for create_dwo_cu. */
11285 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11286 const gdb_byte
*info_ptr
,
11287 struct die_info
*comp_unit_die
,
11288 struct dwo_file
*dwo_file
,
11289 struct dwo_unit
*dwo_unit
)
11291 struct dwarf2_cu
*cu
= reader
->cu
;
11292 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11293 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11295 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11296 if (!signature
.has_value ())
11298 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11299 " its dwo_id [in module %s]"),
11300 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11304 dwo_unit
->dwo_file
= dwo_file
;
11305 dwo_unit
->signature
= *signature
;
11306 dwo_unit
->section
= section
;
11307 dwo_unit
->sect_off
= sect_off
;
11308 dwo_unit
->length
= cu
->per_cu
->length
;
11310 if (dwarf_read_debug
)
11311 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11312 sect_offset_str (sect_off
),
11313 hex_string (dwo_unit
->signature
));
11316 /* Create the dwo_units for the CUs in a DWO_FILE.
11317 Note: This function processes DWO files only, not DWP files. */
11320 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11321 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11322 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11324 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11325 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
11326 const gdb_byte
*info_ptr
, *end_ptr
;
11328 section
.read (objfile
);
11329 info_ptr
= section
.buffer
;
11331 if (info_ptr
== NULL
)
11334 if (dwarf_read_debug
)
11336 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11337 section
.get_name (),
11338 section
.get_file_name ());
11341 end_ptr
= info_ptr
+ section
.size
;
11342 while (info_ptr
< end_ptr
)
11344 struct dwarf2_per_cu_data per_cu
;
11345 struct dwo_unit read_unit
{};
11346 struct dwo_unit
*dwo_unit
;
11348 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11350 memset (&per_cu
, 0, sizeof (per_cu
));
11351 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11352 per_cu
.per_bfd
= per_bfd
;
11353 per_cu
.is_debug_types
= 0;
11354 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11355 per_cu
.section
= §ion
;
11357 cutu_reader
reader (&per_cu
, dwarf2_per_objfile
, cu
, &dwo_file
);
11358 if (!reader
.dummy_p
)
11359 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11360 &dwo_file
, &read_unit
);
11361 info_ptr
+= per_cu
.length
;
11363 // If the unit could not be parsed, skip it.
11364 if (read_unit
.dwo_file
== NULL
)
11367 if (cus_htab
== NULL
)
11368 cus_htab
= allocate_dwo_unit_table ();
11370 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11372 *dwo_unit
= read_unit
;
11373 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11374 gdb_assert (slot
!= NULL
);
11377 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11378 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11380 complaint (_("debug cu entry at offset %s is duplicate to"
11381 " the entry at offset %s, signature %s"),
11382 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11383 hex_string (dwo_unit
->signature
));
11385 *slot
= (void *)dwo_unit
;
11389 /* DWP file .debug_{cu,tu}_index section format:
11390 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11394 Both index sections have the same format, and serve to map a 64-bit
11395 signature to a set of section numbers. Each section begins with a header,
11396 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11397 indexes, and a pool of 32-bit section numbers. The index sections will be
11398 aligned at 8-byte boundaries in the file.
11400 The index section header consists of:
11402 V, 32 bit version number
11404 N, 32 bit number of compilation units or type units in the index
11405 M, 32 bit number of slots in the hash table
11407 Numbers are recorded using the byte order of the application binary.
11409 The hash table begins at offset 16 in the section, and consists of an array
11410 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11411 order of the application binary). Unused slots in the hash table are 0.
11412 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11414 The parallel table begins immediately after the hash table
11415 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11416 array of 32-bit indexes (using the byte order of the application binary),
11417 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11418 table contains a 32-bit index into the pool of section numbers. For unused
11419 hash table slots, the corresponding entry in the parallel table will be 0.
11421 The pool of section numbers begins immediately following the hash table
11422 (at offset 16 + 12 * M from the beginning of the section). The pool of
11423 section numbers consists of an array of 32-bit words (using the byte order
11424 of the application binary). Each item in the array is indexed starting
11425 from 0. The hash table entry provides the index of the first section
11426 number in the set. Additional section numbers in the set follow, and the
11427 set is terminated by a 0 entry (section number 0 is not used in ELF).
11429 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11430 section must be the first entry in the set, and the .debug_abbrev.dwo must
11431 be the second entry. Other members of the set may follow in any order.
11437 DWP Version 2 combines all the .debug_info, etc. sections into one,
11438 and the entries in the index tables are now offsets into these sections.
11439 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11442 Index Section Contents:
11444 Hash Table of Signatures dwp_hash_table.hash_table
11445 Parallel Table of Indices dwp_hash_table.unit_table
11446 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11447 Table of Section Sizes dwp_hash_table.v2.sizes
11449 The index section header consists of:
11451 V, 32 bit version number
11452 L, 32 bit number of columns in the table of section offsets
11453 N, 32 bit number of compilation units or type units in the index
11454 M, 32 bit number of slots in the hash table
11456 Numbers are recorded using the byte order of the application binary.
11458 The hash table has the same format as version 1.
11459 The parallel table of indices has the same format as version 1,
11460 except that the entries are origin-1 indices into the table of sections
11461 offsets and the table of section sizes.
11463 The table of offsets begins immediately following the parallel table
11464 (at offset 16 + 12 * M from the beginning of the section). The table is
11465 a two-dimensional array of 32-bit words (using the byte order of the
11466 application binary), with L columns and N+1 rows, in row-major order.
11467 Each row in the array is indexed starting from 0. The first row provides
11468 a key to the remaining rows: each column in this row provides an identifier
11469 for a debug section, and the offsets in the same column of subsequent rows
11470 refer to that section. The section identifiers are:
11472 DW_SECT_INFO 1 .debug_info.dwo
11473 DW_SECT_TYPES 2 .debug_types.dwo
11474 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11475 DW_SECT_LINE 4 .debug_line.dwo
11476 DW_SECT_LOC 5 .debug_loc.dwo
11477 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11478 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11479 DW_SECT_MACRO 8 .debug_macro.dwo
11481 The offsets provided by the CU and TU index sections are the base offsets
11482 for the contributions made by each CU or TU to the corresponding section
11483 in the package file. Each CU and TU header contains an abbrev_offset
11484 field, used to find the abbreviations table for that CU or TU within the
11485 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11486 be interpreted as relative to the base offset given in the index section.
11487 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11488 should be interpreted as relative to the base offset for .debug_line.dwo,
11489 and offsets into other debug sections obtained from DWARF attributes should
11490 also be interpreted as relative to the corresponding base offset.
11492 The table of sizes begins immediately following the table of offsets.
11493 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11494 with L columns and N rows, in row-major order. Each row in the array is
11495 indexed starting from 1 (row 0 is shared by the two tables).
11499 Hash table lookup is handled the same in version 1 and 2:
11501 We assume that N and M will not exceed 2^32 - 1.
11502 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11504 Given a 64-bit compilation unit signature or a type signature S, an entry
11505 in the hash table is located as follows:
11507 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11508 the low-order k bits all set to 1.
11510 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11512 3) If the hash table entry at index H matches the signature, use that
11513 entry. If the hash table entry at index H is unused (all zeroes),
11514 terminate the search: the signature is not present in the table.
11516 4) Let H = (H + H') modulo M. Repeat at Step 3.
11518 Because M > N and H' and M are relatively prime, the search is guaranteed
11519 to stop at an unused slot or find the match. */
11521 /* Create a hash table to map DWO IDs to their CU/TU entry in
11522 .debug_{info,types}.dwo in DWP_FILE.
11523 Returns NULL if there isn't one.
11524 Note: This function processes DWP files only, not DWO files. */
11526 static struct dwp_hash_table
*
11527 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11528 struct dwp_file
*dwp_file
, int is_debug_types
)
11530 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11531 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11532 const gdb_byte
*index_ptr
, *index_end
;
11533 struct dwarf2_section_info
*index
;
11534 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11535 struct dwp_hash_table
*htab
;
11537 if (is_debug_types
)
11538 index
= &dwp_file
->sections
.tu_index
;
11540 index
= &dwp_file
->sections
.cu_index
;
11542 if (index
->empty ())
11544 index
->read (objfile
);
11546 index_ptr
= index
->buffer
;
11547 index_end
= index_ptr
+ index
->size
;
11549 version
= read_4_bytes (dbfd
, index_ptr
);
11552 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11556 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11558 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11561 if (version
!= 1 && version
!= 2)
11563 error (_("Dwarf Error: unsupported DWP file version (%s)"
11564 " [in module %s]"),
11565 pulongest (version
), dwp_file
->name
);
11567 if (nr_slots
!= (nr_slots
& -nr_slots
))
11569 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11570 " is not power of 2 [in module %s]"),
11571 pulongest (nr_slots
), dwp_file
->name
);
11574 htab
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11575 htab
->version
= version
;
11576 htab
->nr_columns
= nr_columns
;
11577 htab
->nr_units
= nr_units
;
11578 htab
->nr_slots
= nr_slots
;
11579 htab
->hash_table
= index_ptr
;
11580 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11582 /* Exit early if the table is empty. */
11583 if (nr_slots
== 0 || nr_units
== 0
11584 || (version
== 2 && nr_columns
== 0))
11586 /* All must be zero. */
11587 if (nr_slots
!= 0 || nr_units
!= 0
11588 || (version
== 2 && nr_columns
!= 0))
11590 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11591 " all zero [in modules %s]"),
11599 htab
->section_pool
.v1
.indices
=
11600 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11601 /* It's harder to decide whether the section is too small in v1.
11602 V1 is deprecated anyway so we punt. */
11606 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11607 int *ids
= htab
->section_pool
.v2
.section_ids
;
11608 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11609 /* Reverse map for error checking. */
11610 int ids_seen
[DW_SECT_MAX
+ 1];
11613 if (nr_columns
< 2)
11615 error (_("Dwarf Error: bad DWP hash table, too few columns"
11616 " in section table [in module %s]"),
11619 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11621 error (_("Dwarf Error: bad DWP hash table, too many columns"
11622 " in section table [in module %s]"),
11625 memset (ids
, 255, sizeof_ids
);
11626 memset (ids_seen
, 255, sizeof (ids_seen
));
11627 for (i
= 0; i
< nr_columns
; ++i
)
11629 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11631 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11633 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11634 " in section table [in module %s]"),
11635 id
, dwp_file
->name
);
11637 if (ids_seen
[id
] != -1)
11639 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11640 " id %d in section table [in module %s]"),
11641 id
, dwp_file
->name
);
11646 /* Must have exactly one info or types section. */
11647 if (((ids_seen
[DW_SECT_INFO
] != -1)
11648 + (ids_seen
[DW_SECT_TYPES
] != -1))
11651 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11652 " DWO info/types section [in module %s]"),
11655 /* Must have an abbrev section. */
11656 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11658 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11659 " section [in module %s]"),
11662 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11663 htab
->section_pool
.v2
.sizes
=
11664 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11665 * nr_units
* nr_columns
);
11666 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11667 * nr_units
* nr_columns
))
11670 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11671 " [in module %s]"),
11679 /* Update SECTIONS with the data from SECTP.
11681 This function is like the other "locate" section routines that are
11682 passed to bfd_map_over_sections, but in this context the sections to
11683 read comes from the DWP V1 hash table, not the full ELF section table.
11685 The result is non-zero for success, or zero if an error was found. */
11688 locate_v1_virtual_dwo_sections (asection
*sectp
,
11689 struct virtual_v1_dwo_sections
*sections
)
11691 const struct dwop_section_names
*names
= &dwop_section_names
;
11693 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11695 /* There can be only one. */
11696 if (sections
->abbrev
.s
.section
!= NULL
)
11698 sections
->abbrev
.s
.section
= sectp
;
11699 sections
->abbrev
.size
= bfd_section_size (sectp
);
11701 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11702 || section_is_p (sectp
->name
, &names
->types_dwo
))
11704 /* There can be only one. */
11705 if (sections
->info_or_types
.s
.section
!= NULL
)
11707 sections
->info_or_types
.s
.section
= sectp
;
11708 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11710 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11712 /* There can be only one. */
11713 if (sections
->line
.s
.section
!= NULL
)
11715 sections
->line
.s
.section
= sectp
;
11716 sections
->line
.size
= bfd_section_size (sectp
);
11718 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11720 /* There can be only one. */
11721 if (sections
->loc
.s
.section
!= NULL
)
11723 sections
->loc
.s
.section
= sectp
;
11724 sections
->loc
.size
= bfd_section_size (sectp
);
11726 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11728 /* There can be only one. */
11729 if (sections
->macinfo
.s
.section
!= NULL
)
11731 sections
->macinfo
.s
.section
= sectp
;
11732 sections
->macinfo
.size
= bfd_section_size (sectp
);
11734 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11736 /* There can be only one. */
11737 if (sections
->macro
.s
.section
!= NULL
)
11739 sections
->macro
.s
.section
= sectp
;
11740 sections
->macro
.size
= bfd_section_size (sectp
);
11742 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11744 /* There can be only one. */
11745 if (sections
->str_offsets
.s
.section
!= NULL
)
11747 sections
->str_offsets
.s
.section
= sectp
;
11748 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11752 /* No other kind of section is valid. */
11759 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11760 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11761 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11762 This is for DWP version 1 files. */
11764 static struct dwo_unit
*
11765 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11766 struct dwp_file
*dwp_file
,
11767 uint32_t unit_index
,
11768 const char *comp_dir
,
11769 ULONGEST signature
, int is_debug_types
)
11771 const struct dwp_hash_table
*dwp_htab
=
11772 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11773 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11774 const char *kind
= is_debug_types
? "TU" : "CU";
11775 struct dwo_file
*dwo_file
;
11776 struct dwo_unit
*dwo_unit
;
11777 struct virtual_v1_dwo_sections sections
;
11778 void **dwo_file_slot
;
11781 gdb_assert (dwp_file
->version
== 1);
11783 if (dwarf_read_debug
)
11785 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11787 pulongest (unit_index
), hex_string (signature
),
11791 /* Fetch the sections of this DWO unit.
11792 Put a limit on the number of sections we look for so that bad data
11793 doesn't cause us to loop forever. */
11795 #define MAX_NR_V1_DWO_SECTIONS \
11796 (1 /* .debug_info or .debug_types */ \
11797 + 1 /* .debug_abbrev */ \
11798 + 1 /* .debug_line */ \
11799 + 1 /* .debug_loc */ \
11800 + 1 /* .debug_str_offsets */ \
11801 + 1 /* .debug_macro or .debug_macinfo */ \
11802 + 1 /* trailing zero */)
11804 memset (§ions
, 0, sizeof (sections
));
11806 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11809 uint32_t section_nr
=
11810 read_4_bytes (dbfd
,
11811 dwp_htab
->section_pool
.v1
.indices
11812 + (unit_index
+ i
) * sizeof (uint32_t));
11814 if (section_nr
== 0)
11816 if (section_nr
>= dwp_file
->num_sections
)
11818 error (_("Dwarf Error: bad DWP hash table, section number too large"
11819 " [in module %s]"),
11823 sectp
= dwp_file
->elf_sections
[section_nr
];
11824 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11826 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11827 " [in module %s]"),
11833 || sections
.info_or_types
.empty ()
11834 || sections
.abbrev
.empty ())
11836 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11837 " [in module %s]"),
11840 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11842 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11843 " [in module %s]"),
11847 /* It's easier for the rest of the code if we fake a struct dwo_file and
11848 have dwo_unit "live" in that. At least for now.
11850 The DWP file can be made up of a random collection of CUs and TUs.
11851 However, for each CU + set of TUs that came from the same original DWO
11852 file, we can combine them back into a virtual DWO file to save space
11853 (fewer struct dwo_file objects to allocate). Remember that for really
11854 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11856 std::string virtual_dwo_name
=
11857 string_printf ("virtual-dwo/%d-%d-%d-%d",
11858 sections
.abbrev
.get_id (),
11859 sections
.line
.get_id (),
11860 sections
.loc
.get_id (),
11861 sections
.str_offsets
.get_id ());
11862 /* Can we use an existing virtual DWO file? */
11863 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11864 virtual_dwo_name
.c_str (),
11866 /* Create one if necessary. */
11867 if (*dwo_file_slot
== NULL
)
11869 if (dwarf_read_debug
)
11871 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11872 virtual_dwo_name
.c_str ());
11874 dwo_file
= new struct dwo_file
;
11875 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
11876 dwo_file
->comp_dir
= comp_dir
;
11877 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11878 dwo_file
->sections
.line
= sections
.line
;
11879 dwo_file
->sections
.loc
= sections
.loc
;
11880 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11881 dwo_file
->sections
.macro
= sections
.macro
;
11882 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11883 /* The "str" section is global to the entire DWP file. */
11884 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11885 /* The info or types section is assigned below to dwo_unit,
11886 there's no need to record it in dwo_file.
11887 Also, we can't simply record type sections in dwo_file because
11888 we record a pointer into the vector in dwo_unit. As we collect more
11889 types we'll grow the vector and eventually have to reallocate space
11890 for it, invalidating all copies of pointers into the previous
11892 *dwo_file_slot
= dwo_file
;
11896 if (dwarf_read_debug
)
11898 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11899 virtual_dwo_name
.c_str ());
11901 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11904 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11905 dwo_unit
->dwo_file
= dwo_file
;
11906 dwo_unit
->signature
= signature
;
11907 dwo_unit
->section
=
11908 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11909 *dwo_unit
->section
= sections
.info_or_types
;
11910 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11915 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11916 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11917 piece within that section used by a TU/CU, return a virtual section
11918 of just that piece. */
11920 static struct dwarf2_section_info
11921 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11922 struct dwarf2_section_info
*section
,
11923 bfd_size_type offset
, bfd_size_type size
)
11925 struct dwarf2_section_info result
;
11928 gdb_assert (section
!= NULL
);
11929 gdb_assert (!section
->is_virtual
);
11931 memset (&result
, 0, sizeof (result
));
11932 result
.s
.containing_section
= section
;
11933 result
.is_virtual
= true;
11938 sectp
= section
->get_bfd_section ();
11940 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11941 bounds of the real section. This is a pretty-rare event, so just
11942 flag an error (easier) instead of a warning and trying to cope. */
11944 || offset
+ size
> bfd_section_size (sectp
))
11946 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11947 " in section %s [in module %s]"),
11948 sectp
? bfd_section_name (sectp
) : "<unknown>",
11949 objfile_name (dwarf2_per_objfile
->objfile
));
11952 result
.virtual_offset
= offset
;
11953 result
.size
= size
;
11957 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11958 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11959 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11960 This is for DWP version 2 files. */
11962 static struct dwo_unit
*
11963 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11964 struct dwp_file
*dwp_file
,
11965 uint32_t unit_index
,
11966 const char *comp_dir
,
11967 ULONGEST signature
, int is_debug_types
)
11969 const struct dwp_hash_table
*dwp_htab
=
11970 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11971 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11972 const char *kind
= is_debug_types
? "TU" : "CU";
11973 struct dwo_file
*dwo_file
;
11974 struct dwo_unit
*dwo_unit
;
11975 struct virtual_v2_dwo_sections sections
;
11976 void **dwo_file_slot
;
11979 gdb_assert (dwp_file
->version
== 2);
11981 if (dwarf_read_debug
)
11983 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11985 pulongest (unit_index
), hex_string (signature
),
11989 /* Fetch the section offsets of this DWO unit. */
11991 memset (§ions
, 0, sizeof (sections
));
11993 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11995 uint32_t offset
= read_4_bytes (dbfd
,
11996 dwp_htab
->section_pool
.v2
.offsets
11997 + (((unit_index
- 1) * dwp_htab
->nr_columns
11999 * sizeof (uint32_t)));
12000 uint32_t size
= read_4_bytes (dbfd
,
12001 dwp_htab
->section_pool
.v2
.sizes
12002 + (((unit_index
- 1) * dwp_htab
->nr_columns
12004 * sizeof (uint32_t)));
12006 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12009 case DW_SECT_TYPES
:
12010 sections
.info_or_types_offset
= offset
;
12011 sections
.info_or_types_size
= size
;
12013 case DW_SECT_ABBREV
:
12014 sections
.abbrev_offset
= offset
;
12015 sections
.abbrev_size
= size
;
12018 sections
.line_offset
= offset
;
12019 sections
.line_size
= size
;
12022 sections
.loc_offset
= offset
;
12023 sections
.loc_size
= size
;
12025 case DW_SECT_STR_OFFSETS
:
12026 sections
.str_offsets_offset
= offset
;
12027 sections
.str_offsets_size
= size
;
12029 case DW_SECT_MACINFO
:
12030 sections
.macinfo_offset
= offset
;
12031 sections
.macinfo_size
= size
;
12033 case DW_SECT_MACRO
:
12034 sections
.macro_offset
= offset
;
12035 sections
.macro_size
= size
;
12040 /* It's easier for the rest of the code if we fake a struct dwo_file and
12041 have dwo_unit "live" in that. At least for now.
12043 The DWP file can be made up of a random collection of CUs and TUs.
12044 However, for each CU + set of TUs that came from the same original DWO
12045 file, we can combine them back into a virtual DWO file to save space
12046 (fewer struct dwo_file objects to allocate). Remember that for really
12047 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12049 std::string virtual_dwo_name
=
12050 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12051 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12052 (long) (sections
.line_size
? sections
.line_offset
: 0),
12053 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12054 (long) (sections
.str_offsets_size
12055 ? sections
.str_offsets_offset
: 0));
12056 /* Can we use an existing virtual DWO file? */
12057 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12058 virtual_dwo_name
.c_str (),
12060 /* Create one if necessary. */
12061 if (*dwo_file_slot
== NULL
)
12063 if (dwarf_read_debug
)
12065 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12066 virtual_dwo_name
.c_str ());
12068 dwo_file
= new struct dwo_file
;
12069 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
12070 dwo_file
->comp_dir
= comp_dir
;
12071 dwo_file
->sections
.abbrev
=
12072 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12073 sections
.abbrev_offset
, sections
.abbrev_size
);
12074 dwo_file
->sections
.line
=
12075 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12076 sections
.line_offset
, sections
.line_size
);
12077 dwo_file
->sections
.loc
=
12078 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12079 sections
.loc_offset
, sections
.loc_size
);
12080 dwo_file
->sections
.macinfo
=
12081 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12082 sections
.macinfo_offset
, sections
.macinfo_size
);
12083 dwo_file
->sections
.macro
=
12084 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12085 sections
.macro_offset
, sections
.macro_size
);
12086 dwo_file
->sections
.str_offsets
=
12087 create_dwp_v2_section (dwarf2_per_objfile
,
12088 &dwp_file
->sections
.str_offsets
,
12089 sections
.str_offsets_offset
,
12090 sections
.str_offsets_size
);
12091 /* The "str" section is global to the entire DWP file. */
12092 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12093 /* The info or types section is assigned below to dwo_unit,
12094 there's no need to record it in dwo_file.
12095 Also, we can't simply record type sections in dwo_file because
12096 we record a pointer into the vector in dwo_unit. As we collect more
12097 types we'll grow the vector and eventually have to reallocate space
12098 for it, invalidating all copies of pointers into the previous
12100 *dwo_file_slot
= dwo_file
;
12104 if (dwarf_read_debug
)
12106 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12107 virtual_dwo_name
.c_str ());
12109 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12112 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12113 dwo_unit
->dwo_file
= dwo_file
;
12114 dwo_unit
->signature
= signature
;
12115 dwo_unit
->section
=
12116 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12117 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12119 ? &dwp_file
->sections
.types
12120 : &dwp_file
->sections
.info
,
12121 sections
.info_or_types_offset
,
12122 sections
.info_or_types_size
);
12123 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12128 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12129 Returns NULL if the signature isn't found. */
12131 static struct dwo_unit
*
12132 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12133 struct dwp_file
*dwp_file
, const char *comp_dir
,
12134 ULONGEST signature
, int is_debug_types
)
12136 const struct dwp_hash_table
*dwp_htab
=
12137 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12138 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12139 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12140 uint32_t hash
= signature
& mask
;
12141 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12144 struct dwo_unit find_dwo_cu
;
12146 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12147 find_dwo_cu
.signature
= signature
;
12148 slot
= htab_find_slot (is_debug_types
12149 ? dwp_file
->loaded_tus
.get ()
12150 : dwp_file
->loaded_cus
.get (),
12151 &find_dwo_cu
, INSERT
);
12154 return (struct dwo_unit
*) *slot
;
12156 /* Use a for loop so that we don't loop forever on bad debug info. */
12157 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12159 ULONGEST signature_in_table
;
12161 signature_in_table
=
12162 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12163 if (signature_in_table
== signature
)
12165 uint32_t unit_index
=
12166 read_4_bytes (dbfd
,
12167 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12169 if (dwp_file
->version
== 1)
12171 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12172 dwp_file
, unit_index
,
12173 comp_dir
, signature
,
12178 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12179 dwp_file
, unit_index
,
12180 comp_dir
, signature
,
12183 return (struct dwo_unit
*) *slot
;
12185 if (signature_in_table
== 0)
12187 hash
= (hash
+ hash2
) & mask
;
12190 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12191 " [in module %s]"),
12195 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12196 Open the file specified by FILE_NAME and hand it off to BFD for
12197 preliminary analysis. Return a newly initialized bfd *, which
12198 includes a canonicalized copy of FILE_NAME.
12199 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12200 SEARCH_CWD is true if the current directory is to be searched.
12201 It will be searched before debug-file-directory.
12202 If successful, the file is added to the bfd include table of the
12203 objfile's bfd (see gdb_bfd_record_inclusion).
12204 If unable to find/open the file, return NULL.
12205 NOTE: This function is derived from symfile_bfd_open. */
12207 static gdb_bfd_ref_ptr
12208 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12209 const char *file_name
, int is_dwp
, int search_cwd
)
12212 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12213 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12214 to debug_file_directory. */
12215 const char *search_path
;
12216 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12218 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12221 if (*debug_file_directory
!= '\0')
12223 search_path_holder
.reset (concat (".", dirname_separator_string
,
12224 debug_file_directory
,
12226 search_path
= search_path_holder
.get ();
12232 search_path
= debug_file_directory
;
12234 openp_flags flags
= OPF_RETURN_REALPATH
;
12236 flags
|= OPF_SEARCH_IN_PATH
;
12238 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12239 desc
= openp (search_path
, flags
, file_name
,
12240 O_RDONLY
| O_BINARY
, &absolute_name
);
12244 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12246 if (sym_bfd
== NULL
)
12248 bfd_set_cacheable (sym_bfd
.get (), 1);
12250 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12253 /* Success. Record the bfd as having been included by the objfile's bfd.
12254 This is important because things like demangled_names_hash lives in the
12255 objfile's per_bfd space and may have references to things like symbol
12256 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12257 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12262 /* Try to open DWO file FILE_NAME.
12263 COMP_DIR is the DW_AT_comp_dir attribute.
12264 The result is the bfd handle of the file.
12265 If there is a problem finding or opening the file, return NULL.
12266 Upon success, the canonicalized path of the file is stored in the bfd,
12267 same as symfile_bfd_open. */
12269 static gdb_bfd_ref_ptr
12270 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12271 const char *file_name
, const char *comp_dir
)
12273 if (IS_ABSOLUTE_PATH (file_name
))
12274 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12275 0 /*is_dwp*/, 0 /*search_cwd*/);
12277 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12279 if (comp_dir
!= NULL
)
12281 gdb::unique_xmalloc_ptr
<char> path_to_try
12282 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12284 /* NOTE: If comp_dir is a relative path, this will also try the
12285 search path, which seems useful. */
12286 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12287 path_to_try
.get (),
12289 1 /*search_cwd*/));
12294 /* That didn't work, try debug-file-directory, which, despite its name,
12295 is a list of paths. */
12297 if (*debug_file_directory
== '\0')
12300 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12301 0 /*is_dwp*/, 1 /*search_cwd*/);
12304 /* This function is mapped across the sections and remembers the offset and
12305 size of each of the DWO debugging sections we are interested in. */
12308 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12310 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12311 const struct dwop_section_names
*names
= &dwop_section_names
;
12313 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12315 dwo_sections
->abbrev
.s
.section
= sectp
;
12316 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12318 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12320 dwo_sections
->info
.s
.section
= sectp
;
12321 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12323 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12325 dwo_sections
->line
.s
.section
= sectp
;
12326 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12328 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12330 dwo_sections
->loc
.s
.section
= sectp
;
12331 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12333 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12335 dwo_sections
->loclists
.s
.section
= sectp
;
12336 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12338 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12340 dwo_sections
->macinfo
.s
.section
= sectp
;
12341 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12343 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12345 dwo_sections
->macro
.s
.section
= sectp
;
12346 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12348 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12350 dwo_sections
->str
.s
.section
= sectp
;
12351 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12353 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12355 dwo_sections
->str_offsets
.s
.section
= sectp
;
12356 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12358 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12360 struct dwarf2_section_info type_section
;
12362 memset (&type_section
, 0, sizeof (type_section
));
12363 type_section
.s
.section
= sectp
;
12364 type_section
.size
= bfd_section_size (sectp
);
12365 dwo_sections
->types
.push_back (type_section
);
12369 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12370 by PER_CU. This is for the non-DWP case.
12371 The result is NULL if DWO_NAME can't be found. */
12373 static struct dwo_file
*
12374 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12375 const char *comp_dir
)
12377 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12379 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12382 if (dwarf_read_debug
)
12383 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12387 dwo_file_up
dwo_file (new struct dwo_file
);
12388 dwo_file
->dwo_name
= dwo_name
;
12389 dwo_file
->comp_dir
= comp_dir
;
12390 dwo_file
->dbfd
= std::move (dbfd
);
12392 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12393 &dwo_file
->sections
);
12395 create_cus_hash_table (dwarf2_per_objfile
, cu
, *dwo_file
,
12396 dwo_file
->sections
.info
, dwo_file
->cus
);
12398 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12399 dwo_file
->sections
.types
, dwo_file
->tus
);
12401 if (dwarf_read_debug
)
12402 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12404 return dwo_file
.release ();
12407 /* This function is mapped across the sections and remembers the offset and
12408 size of each of the DWP debugging sections common to version 1 and 2 that
12409 we are interested in. */
12412 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12413 void *dwp_file_ptr
)
12415 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12416 const struct dwop_section_names
*names
= &dwop_section_names
;
12417 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12419 /* Record the ELF section number for later lookup: this is what the
12420 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12421 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12422 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12424 /* Look for specific sections that we need. */
12425 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12427 dwp_file
->sections
.str
.s
.section
= sectp
;
12428 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12430 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12432 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12433 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12435 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12437 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12438 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12442 /* This function is mapped across the sections and remembers the offset and
12443 size of each of the DWP version 2 debugging sections that we are interested
12444 in. This is split into a separate function because we don't know if we
12445 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12448 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12450 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12451 const struct dwop_section_names
*names
= &dwop_section_names
;
12452 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12454 /* Record the ELF section number for later lookup: this is what the
12455 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12456 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12457 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12459 /* Look for specific sections that we need. */
12460 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12462 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12463 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12465 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12467 dwp_file
->sections
.info
.s
.section
= sectp
;
12468 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12470 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12472 dwp_file
->sections
.line
.s
.section
= sectp
;
12473 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12475 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12477 dwp_file
->sections
.loc
.s
.section
= sectp
;
12478 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12480 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12482 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12483 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12485 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12487 dwp_file
->sections
.macro
.s
.section
= sectp
;
12488 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12490 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12492 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12493 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12495 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12497 dwp_file
->sections
.types
.s
.section
= sectp
;
12498 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12502 /* Hash function for dwp_file loaded CUs/TUs. */
12505 hash_dwp_loaded_cutus (const void *item
)
12507 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12509 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12510 return dwo_unit
->signature
;
12513 /* Equality function for dwp_file loaded CUs/TUs. */
12516 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12518 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12519 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12521 return dua
->signature
== dub
->signature
;
12524 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12527 allocate_dwp_loaded_cutus_table ()
12529 return htab_up (htab_create_alloc (3,
12530 hash_dwp_loaded_cutus
,
12531 eq_dwp_loaded_cutus
,
12532 NULL
, xcalloc
, xfree
));
12535 /* Try to open DWP file FILE_NAME.
12536 The result is the bfd handle of the file.
12537 If there is a problem finding or opening the file, return NULL.
12538 Upon success, the canonicalized path of the file is stored in the bfd,
12539 same as symfile_bfd_open. */
12541 static gdb_bfd_ref_ptr
12542 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12543 const char *file_name
)
12545 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12547 1 /*search_cwd*/));
12551 /* Work around upstream bug 15652.
12552 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12553 [Whether that's a "bug" is debatable, but it is getting in our way.]
12554 We have no real idea where the dwp file is, because gdb's realpath-ing
12555 of the executable's path may have discarded the needed info.
12556 [IWBN if the dwp file name was recorded in the executable, akin to
12557 .gnu_debuglink, but that doesn't exist yet.]
12558 Strip the directory from FILE_NAME and search again. */
12559 if (*debug_file_directory
!= '\0')
12561 /* Don't implicitly search the current directory here.
12562 If the user wants to search "." to handle this case,
12563 it must be added to debug-file-directory. */
12564 return try_open_dwop_file (dwarf2_per_objfile
,
12565 lbasename (file_name
), 1 /*is_dwp*/,
12572 /* Initialize the use of the DWP file for the current objfile.
12573 By convention the name of the DWP file is ${objfile}.dwp.
12574 The result is NULL if it can't be found. */
12576 static std::unique_ptr
<struct dwp_file
>
12577 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12579 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12581 /* Try to find first .dwp for the binary file before any symbolic links
12584 /* If the objfile is a debug file, find the name of the real binary
12585 file and get the name of dwp file from there. */
12586 std::string dwp_name
;
12587 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12589 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12590 const char *backlink_basename
= lbasename (backlink
->original_name
);
12592 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12595 dwp_name
= objfile
->original_name
;
12597 dwp_name
+= ".dwp";
12599 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12601 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12603 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12604 dwp_name
= objfile_name (objfile
);
12605 dwp_name
+= ".dwp";
12606 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12611 if (dwarf_read_debug
)
12612 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12613 return std::unique_ptr
<dwp_file
> ();
12616 const char *name
= bfd_get_filename (dbfd
.get ());
12617 std::unique_ptr
<struct dwp_file
> dwp_file
12618 (new struct dwp_file (name
, std::move (dbfd
)));
12620 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12621 dwp_file
->elf_sections
=
12622 OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
12623 dwp_file
->num_sections
, asection
*);
12625 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12626 dwarf2_locate_common_dwp_sections
,
12629 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12632 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12635 /* The DWP file version is stored in the hash table. Oh well. */
12636 if (dwp_file
->cus
&& dwp_file
->tus
12637 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12639 /* Technically speaking, we should try to limp along, but this is
12640 pretty bizarre. We use pulongest here because that's the established
12641 portability solution (e.g, we cannot use %u for uint32_t). */
12642 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12643 " TU version %s [in DWP file %s]"),
12644 pulongest (dwp_file
->cus
->version
),
12645 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12649 dwp_file
->version
= dwp_file
->cus
->version
;
12650 else if (dwp_file
->tus
)
12651 dwp_file
->version
= dwp_file
->tus
->version
;
12653 dwp_file
->version
= 2;
12655 if (dwp_file
->version
== 2)
12656 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12657 dwarf2_locate_v2_dwp_sections
,
12660 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12661 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12663 if (dwarf_read_debug
)
12665 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12666 fprintf_unfiltered (gdb_stdlog
,
12667 " %s CUs, %s TUs\n",
12668 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12669 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12675 /* Wrapper around open_and_init_dwp_file, only open it once. */
12677 static struct dwp_file
*
12678 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12680 if (! dwarf2_per_objfile
->per_bfd
->dwp_checked
)
12682 dwarf2_per_objfile
->per_bfd
->dwp_file
12683 = open_and_init_dwp_file (dwarf2_per_objfile
);
12684 dwarf2_per_objfile
->per_bfd
->dwp_checked
= 1;
12686 return dwarf2_per_objfile
->per_bfd
->dwp_file
.get ();
12689 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12690 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12691 or in the DWP file for the objfile, referenced by THIS_UNIT.
12692 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12693 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12695 This is called, for example, when wanting to read a variable with a
12696 complex location. Therefore we don't want to do file i/o for every call.
12697 Therefore we don't want to look for a DWO file on every call.
12698 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12699 then we check if we've already seen DWO_NAME, and only THEN do we check
12702 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12703 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12705 static struct dwo_unit
*
12706 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12707 ULONGEST signature
, int is_debug_types
)
12709 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12710 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12711 const char *kind
= is_debug_types
? "TU" : "CU";
12712 void **dwo_file_slot
;
12713 struct dwo_file
*dwo_file
;
12714 struct dwp_file
*dwp_file
;
12716 /* First see if there's a DWP file.
12717 If we have a DWP file but didn't find the DWO inside it, don't
12718 look for the original DWO file. It makes gdb behave differently
12719 depending on whether one is debugging in the build tree. */
12721 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12722 if (dwp_file
!= NULL
)
12724 const struct dwp_hash_table
*dwp_htab
=
12725 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12727 if (dwp_htab
!= NULL
)
12729 struct dwo_unit
*dwo_cutu
=
12730 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12731 signature
, is_debug_types
);
12733 if (dwo_cutu
!= NULL
)
12735 if (dwarf_read_debug
)
12737 fprintf_unfiltered (gdb_stdlog
,
12738 "Virtual DWO %s %s found: @%s\n",
12739 kind
, hex_string (signature
),
12740 host_address_to_string (dwo_cutu
));
12748 /* No DWP file, look for the DWO file. */
12750 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12751 dwo_name
, comp_dir
);
12752 if (*dwo_file_slot
== NULL
)
12754 /* Read in the file and build a table of the CUs/TUs it contains. */
12755 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12757 /* NOTE: This will be NULL if unable to open the file. */
12758 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12760 if (dwo_file
!= NULL
)
12762 struct dwo_unit
*dwo_cutu
= NULL
;
12764 if (is_debug_types
&& dwo_file
->tus
)
12766 struct dwo_unit find_dwo_cutu
;
12768 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12769 find_dwo_cutu
.signature
= signature
;
12771 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12774 else if (!is_debug_types
&& dwo_file
->cus
)
12776 struct dwo_unit find_dwo_cutu
;
12778 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12779 find_dwo_cutu
.signature
= signature
;
12780 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12784 if (dwo_cutu
!= NULL
)
12786 if (dwarf_read_debug
)
12788 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12789 kind
, dwo_name
, hex_string (signature
),
12790 host_address_to_string (dwo_cutu
));
12797 /* We didn't find it. This could mean a dwo_id mismatch, or
12798 someone deleted the DWO/DWP file, or the search path isn't set up
12799 correctly to find the file. */
12801 if (dwarf_read_debug
)
12803 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12804 kind
, dwo_name
, hex_string (signature
));
12807 /* This is a warning and not a complaint because it can be caused by
12808 pilot error (e.g., user accidentally deleting the DWO). */
12810 /* Print the name of the DWP file if we looked there, helps the user
12811 better diagnose the problem. */
12812 std::string dwp_text
;
12814 if (dwp_file
!= NULL
)
12815 dwp_text
= string_printf (" [in DWP file %s]",
12816 lbasename (dwp_file
->name
));
12818 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12819 " [in module %s]"),
12820 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12821 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12826 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12827 See lookup_dwo_cutu_unit for details. */
12829 static struct dwo_unit
*
12830 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12831 ULONGEST signature
)
12833 gdb_assert (!cu
->per_cu
->is_debug_types
);
12835 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12838 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12839 See lookup_dwo_cutu_unit for details. */
12841 static struct dwo_unit
*
12842 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12844 gdb_assert (cu
->per_cu
->is_debug_types
);
12846 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12848 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12851 /* Traversal function for queue_and_load_all_dwo_tus. */
12854 queue_and_load_dwo_tu (void **slot
, void *info
)
12856 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12857 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12858 ULONGEST signature
= dwo_unit
->signature
;
12859 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12861 if (sig_type
!= NULL
)
12863 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12865 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12866 a real dependency of PER_CU on SIG_TYPE. That is detected later
12867 while processing PER_CU. */
12868 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12869 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12870 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12876 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12877 The DWO may have the only definition of the type, though it may not be
12878 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12879 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12882 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12884 struct dwo_unit
*dwo_unit
;
12885 struct dwo_file
*dwo_file
;
12887 gdb_assert (!per_cu
->is_debug_types
);
12888 gdb_assert (per_cu
->cu
!= NULL
);
12889 gdb_assert (get_dwp_file (per_cu
->cu
->per_objfile
) == NULL
);
12891 dwo_unit
= per_cu
->cu
->dwo_unit
;
12892 gdb_assert (dwo_unit
!= NULL
);
12894 dwo_file
= dwo_unit
->dwo_file
;
12895 if (dwo_file
->tus
!= NULL
)
12896 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12900 /* Read in various DIEs. */
12902 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12903 Inherit only the children of the DW_AT_abstract_origin DIE not being
12904 already referenced by DW_AT_abstract_origin from the children of the
12908 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12910 struct die_info
*child_die
;
12911 sect_offset
*offsetp
;
12912 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12913 struct die_info
*origin_die
;
12914 /* Iterator of the ORIGIN_DIE children. */
12915 struct die_info
*origin_child_die
;
12916 struct attribute
*attr
;
12917 struct dwarf2_cu
*origin_cu
;
12918 struct pending
**origin_previous_list_in_scope
;
12920 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12924 /* Note that following die references may follow to a die in a
12928 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12930 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12932 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12933 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12935 if (die
->tag
!= origin_die
->tag
12936 && !(die
->tag
== DW_TAG_inlined_subroutine
12937 && origin_die
->tag
== DW_TAG_subprogram
))
12938 complaint (_("DIE %s and its abstract origin %s have different tags"),
12939 sect_offset_str (die
->sect_off
),
12940 sect_offset_str (origin_die
->sect_off
));
12942 std::vector
<sect_offset
> offsets
;
12944 for (child_die
= die
->child
;
12945 child_die
&& child_die
->tag
;
12946 child_die
= child_die
->sibling
)
12948 struct die_info
*child_origin_die
;
12949 struct dwarf2_cu
*child_origin_cu
;
12951 /* We are trying to process concrete instance entries:
12952 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12953 it's not relevant to our analysis here. i.e. detecting DIEs that are
12954 present in the abstract instance but not referenced in the concrete
12956 if (child_die
->tag
== DW_TAG_call_site
12957 || child_die
->tag
== DW_TAG_GNU_call_site
)
12960 /* For each CHILD_DIE, find the corresponding child of
12961 ORIGIN_DIE. If there is more than one layer of
12962 DW_AT_abstract_origin, follow them all; there shouldn't be,
12963 but GCC versions at least through 4.4 generate this (GCC PR
12965 child_origin_die
= child_die
;
12966 child_origin_cu
= cu
;
12969 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12973 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12977 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12978 counterpart may exist. */
12979 if (child_origin_die
!= child_die
)
12981 if (child_die
->tag
!= child_origin_die
->tag
12982 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12983 && child_origin_die
->tag
== DW_TAG_subprogram
))
12984 complaint (_("Child DIE %s and its abstract origin %s have "
12986 sect_offset_str (child_die
->sect_off
),
12987 sect_offset_str (child_origin_die
->sect_off
));
12988 if (child_origin_die
->parent
!= origin_die
)
12989 complaint (_("Child DIE %s and its abstract origin %s have "
12990 "different parents"),
12991 sect_offset_str (child_die
->sect_off
),
12992 sect_offset_str (child_origin_die
->sect_off
));
12994 offsets
.push_back (child_origin_die
->sect_off
);
12997 std::sort (offsets
.begin (), offsets
.end ());
12998 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12999 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13000 if (offsetp
[-1] == *offsetp
)
13001 complaint (_("Multiple children of DIE %s refer "
13002 "to DIE %s as their abstract origin"),
13003 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13005 offsetp
= offsets
.data ();
13006 origin_child_die
= origin_die
->child
;
13007 while (origin_child_die
&& origin_child_die
->tag
)
13009 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13010 while (offsetp
< offsets_end
13011 && *offsetp
< origin_child_die
->sect_off
)
13013 if (offsetp
>= offsets_end
13014 || *offsetp
> origin_child_die
->sect_off
)
13016 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13017 Check whether we're already processing ORIGIN_CHILD_DIE.
13018 This can happen with mutually referenced abstract_origins.
13020 if (!origin_child_die
->in_process
)
13021 process_die (origin_child_die
, origin_cu
);
13023 origin_child_die
= origin_child_die
->sibling
;
13025 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13027 if (cu
!= origin_cu
)
13028 compute_delayed_physnames (origin_cu
);
13032 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13034 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13035 struct gdbarch
*gdbarch
= objfile
->arch ();
13036 struct context_stack
*newobj
;
13039 struct die_info
*child_die
;
13040 struct attribute
*attr
, *call_line
, *call_file
;
13042 CORE_ADDR baseaddr
;
13043 struct block
*block
;
13044 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13045 std::vector
<struct symbol
*> template_args
;
13046 struct template_symbol
*templ_func
= NULL
;
13050 /* If we do not have call site information, we can't show the
13051 caller of this inlined function. That's too confusing, so
13052 only use the scope for local variables. */
13053 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13054 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13055 if (call_line
== NULL
|| call_file
== NULL
)
13057 read_lexical_block_scope (die
, cu
);
13062 baseaddr
= objfile
->text_section_offset ();
13064 name
= dwarf2_name (die
, cu
);
13066 /* Ignore functions with missing or empty names. These are actually
13067 illegal according to the DWARF standard. */
13070 complaint (_("missing name for subprogram DIE at %s"),
13071 sect_offset_str (die
->sect_off
));
13075 /* Ignore functions with missing or invalid low and high pc attributes. */
13076 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13077 <= PC_BOUNDS_INVALID
)
13079 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13080 if (!attr
|| !DW_UNSND (attr
))
13081 complaint (_("cannot get low and high bounds "
13082 "for subprogram DIE at %s"),
13083 sect_offset_str (die
->sect_off
));
13087 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13088 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13090 /* If we have any template arguments, then we must allocate a
13091 different sort of symbol. */
13092 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13094 if (child_die
->tag
== DW_TAG_template_type_param
13095 || child_die
->tag
== DW_TAG_template_value_param
)
13097 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13098 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13103 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13104 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13105 (struct symbol
*) templ_func
);
13107 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13108 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13111 /* If there is a location expression for DW_AT_frame_base, record
13113 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13114 if (attr
!= nullptr)
13115 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13117 /* If there is a location for the static link, record it. */
13118 newobj
->static_link
= NULL
;
13119 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13120 if (attr
!= nullptr)
13122 newobj
->static_link
13123 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13124 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13128 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13130 if (die
->child
!= NULL
)
13132 child_die
= die
->child
;
13133 while (child_die
&& child_die
->tag
)
13135 if (child_die
->tag
== DW_TAG_template_type_param
13136 || child_die
->tag
== DW_TAG_template_value_param
)
13138 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13141 template_args
.push_back (arg
);
13144 process_die (child_die
, cu
);
13145 child_die
= child_die
->sibling
;
13149 inherit_abstract_dies (die
, cu
);
13151 /* If we have a DW_AT_specification, we might need to import using
13152 directives from the context of the specification DIE. See the
13153 comment in determine_prefix. */
13154 if (cu
->language
== language_cplus
13155 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13157 struct dwarf2_cu
*spec_cu
= cu
;
13158 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13162 child_die
= spec_die
->child
;
13163 while (child_die
&& child_die
->tag
)
13165 if (child_die
->tag
== DW_TAG_imported_module
)
13166 process_die (child_die
, spec_cu
);
13167 child_die
= child_die
->sibling
;
13170 /* In some cases, GCC generates specification DIEs that
13171 themselves contain DW_AT_specification attributes. */
13172 spec_die
= die_specification (spec_die
, &spec_cu
);
13176 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13177 /* Make a block for the local symbols within. */
13178 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13179 cstk
.static_link
, lowpc
, highpc
);
13181 /* For C++, set the block's scope. */
13182 if ((cu
->language
== language_cplus
13183 || cu
->language
== language_fortran
13184 || cu
->language
== language_d
13185 || cu
->language
== language_rust
)
13186 && cu
->processing_has_namespace_info
)
13187 block_set_scope (block
, determine_prefix (die
, cu
),
13188 &objfile
->objfile_obstack
);
13190 /* If we have address ranges, record them. */
13191 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13193 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13195 /* Attach template arguments to function. */
13196 if (!template_args
.empty ())
13198 gdb_assert (templ_func
!= NULL
);
13200 templ_func
->n_template_arguments
= template_args
.size ();
13201 templ_func
->template_arguments
13202 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13203 templ_func
->n_template_arguments
);
13204 memcpy (templ_func
->template_arguments
,
13205 template_args
.data (),
13206 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13208 /* Make sure that the symtab is set on the new symbols. Even
13209 though they don't appear in this symtab directly, other parts
13210 of gdb assume that symbols do, and this is reasonably
13212 for (symbol
*sym
: template_args
)
13213 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13216 /* In C++, we can have functions nested inside functions (e.g., when
13217 a function declares a class that has methods). This means that
13218 when we finish processing a function scope, we may need to go
13219 back to building a containing block's symbol lists. */
13220 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13221 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13223 /* If we've finished processing a top-level function, subsequent
13224 symbols go in the file symbol list. */
13225 if (cu
->get_builder ()->outermost_context_p ())
13226 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13229 /* Process all the DIES contained within a lexical block scope. Start
13230 a new scope, process the dies, and then close the scope. */
13233 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13235 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13236 struct gdbarch
*gdbarch
= objfile
->arch ();
13237 CORE_ADDR lowpc
, highpc
;
13238 struct die_info
*child_die
;
13239 CORE_ADDR baseaddr
;
13241 baseaddr
= objfile
->text_section_offset ();
13243 /* Ignore blocks with missing or invalid low and high pc attributes. */
13244 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13245 as multiple lexical blocks? Handling children in a sane way would
13246 be nasty. Might be easier to properly extend generic blocks to
13247 describe ranges. */
13248 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13250 case PC_BOUNDS_NOT_PRESENT
:
13251 /* DW_TAG_lexical_block has no attributes, process its children as if
13252 there was no wrapping by that DW_TAG_lexical_block.
13253 GCC does no longer produces such DWARF since GCC r224161. */
13254 for (child_die
= die
->child
;
13255 child_die
!= NULL
&& child_die
->tag
;
13256 child_die
= child_die
->sibling
)
13258 /* We might already be processing this DIE. This can happen
13259 in an unusual circumstance -- where a subroutine A
13260 appears lexically in another subroutine B, but A actually
13261 inlines B. The recursion is broken here, rather than in
13262 inherit_abstract_dies, because it seems better to simply
13263 drop concrete children here. */
13264 if (!child_die
->in_process
)
13265 process_die (child_die
, cu
);
13268 case PC_BOUNDS_INVALID
:
13271 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13272 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13274 cu
->get_builder ()->push_context (0, lowpc
);
13275 if (die
->child
!= NULL
)
13277 child_die
= die
->child
;
13278 while (child_die
&& child_die
->tag
)
13280 process_die (child_die
, cu
);
13281 child_die
= child_die
->sibling
;
13284 inherit_abstract_dies (die
, cu
);
13285 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13287 if (*cu
->get_builder ()->get_local_symbols () != NULL
13288 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13290 struct block
*block
13291 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13292 cstk
.start_addr
, highpc
);
13294 /* Note that recording ranges after traversing children, as we
13295 do here, means that recording a parent's ranges entails
13296 walking across all its children's ranges as they appear in
13297 the address map, which is quadratic behavior.
13299 It would be nicer to record the parent's ranges before
13300 traversing its children, simply overriding whatever you find
13301 there. But since we don't even decide whether to create a
13302 block until after we've traversed its children, that's hard
13304 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13306 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13307 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13310 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13313 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13315 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13316 struct objfile
*objfile
= per_objfile
->objfile
;
13317 struct gdbarch
*gdbarch
= objfile
->arch ();
13318 CORE_ADDR pc
, baseaddr
;
13319 struct attribute
*attr
;
13320 struct call_site
*call_site
, call_site_local
;
13323 struct die_info
*child_die
;
13325 baseaddr
= objfile
->text_section_offset ();
13327 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13330 /* This was a pre-DWARF-5 GNU extension alias
13331 for DW_AT_call_return_pc. */
13332 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13336 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13337 "DIE %s [in module %s]"),
13338 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13341 pc
= attr
->value_as_address () + baseaddr
;
13342 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13344 if (cu
->call_site_htab
== NULL
)
13345 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13346 NULL
, &objfile
->objfile_obstack
,
13347 hashtab_obstack_allocate
, NULL
);
13348 call_site_local
.pc
= pc
;
13349 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13352 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13353 "DIE %s [in module %s]"),
13354 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13355 objfile_name (objfile
));
13359 /* Count parameters at the caller. */
13362 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13363 child_die
= child_die
->sibling
)
13365 if (child_die
->tag
!= DW_TAG_call_site_parameter
13366 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13368 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13369 "DW_TAG_call_site child DIE %s [in module %s]"),
13370 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13371 objfile_name (objfile
));
13379 = ((struct call_site
*)
13380 obstack_alloc (&objfile
->objfile_obstack
,
13381 sizeof (*call_site
)
13382 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13384 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13385 call_site
->pc
= pc
;
13387 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13388 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13390 struct die_info
*func_die
;
13392 /* Skip also over DW_TAG_inlined_subroutine. */
13393 for (func_die
= die
->parent
;
13394 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13395 && func_die
->tag
!= DW_TAG_subroutine_type
;
13396 func_die
= func_die
->parent
);
13398 /* DW_AT_call_all_calls is a superset
13399 of DW_AT_call_all_tail_calls. */
13401 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13402 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13403 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13404 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13406 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13407 not complete. But keep CALL_SITE for look ups via call_site_htab,
13408 both the initial caller containing the real return address PC and
13409 the final callee containing the current PC of a chain of tail
13410 calls do not need to have the tail call list complete. But any
13411 function candidate for a virtual tail call frame searched via
13412 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13413 determined unambiguously. */
13417 struct type
*func_type
= NULL
;
13420 func_type
= get_die_type (func_die
, cu
);
13421 if (func_type
!= NULL
)
13423 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13425 /* Enlist this call site to the function. */
13426 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13427 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13430 complaint (_("Cannot find function owning DW_TAG_call_site "
13431 "DIE %s [in module %s]"),
13432 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13436 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13438 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13440 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13443 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13444 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13446 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13447 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13448 /* Keep NULL DWARF_BLOCK. */;
13449 else if (attr
->form_is_block ())
13451 struct dwarf2_locexpr_baton
*dlbaton
;
13453 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13454 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13455 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13456 dlbaton
->per_objfile
= per_objfile
;
13457 dlbaton
->per_cu
= cu
->per_cu
;
13459 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13461 else if (attr
->form_is_ref ())
13463 struct dwarf2_cu
*target_cu
= cu
;
13464 struct die_info
*target_die
;
13466 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13467 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13468 if (die_is_declaration (target_die
, target_cu
))
13470 const char *target_physname
;
13472 /* Prefer the mangled name; otherwise compute the demangled one. */
13473 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13474 if (target_physname
== NULL
)
13475 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13476 if (target_physname
== NULL
)
13477 complaint (_("DW_AT_call_target target DIE has invalid "
13478 "physname, for referencing DIE %s [in module %s]"),
13479 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13481 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13487 /* DW_AT_entry_pc should be preferred. */
13488 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13489 <= PC_BOUNDS_INVALID
)
13490 complaint (_("DW_AT_call_target target DIE has invalid "
13491 "low pc, for referencing DIE %s [in module %s]"),
13492 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13495 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13496 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13501 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13502 "block nor reference, for DIE %s [in module %s]"),
13503 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13505 call_site
->per_cu
= cu
->per_cu
;
13506 call_site
->per_objfile
= per_objfile
;
13508 for (child_die
= die
->child
;
13509 child_die
&& child_die
->tag
;
13510 child_die
= child_die
->sibling
)
13512 struct call_site_parameter
*parameter
;
13513 struct attribute
*loc
, *origin
;
13515 if (child_die
->tag
!= DW_TAG_call_site_parameter
13516 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13518 /* Already printed the complaint above. */
13522 gdb_assert (call_site
->parameter_count
< nparams
);
13523 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13525 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13526 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13527 register is contained in DW_AT_call_value. */
13529 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13530 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13531 if (origin
== NULL
)
13533 /* This was a pre-DWARF-5 GNU extension alias
13534 for DW_AT_call_parameter. */
13535 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13537 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13539 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13541 sect_offset sect_off
= origin
->get_ref_die_offset ();
13542 if (!cu
->header
.offset_in_cu_p (sect_off
))
13544 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13545 binding can be done only inside one CU. Such referenced DIE
13546 therefore cannot be even moved to DW_TAG_partial_unit. */
13547 complaint (_("DW_AT_call_parameter offset is not in CU for "
13548 "DW_TAG_call_site child DIE %s [in module %s]"),
13549 sect_offset_str (child_die
->sect_off
),
13550 objfile_name (objfile
));
13553 parameter
->u
.param_cu_off
13554 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13556 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13558 complaint (_("No DW_FORM_block* DW_AT_location for "
13559 "DW_TAG_call_site child DIE %s [in module %s]"),
13560 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13565 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13566 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13567 if (parameter
->u
.dwarf_reg
!= -1)
13568 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13569 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13570 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13571 ¶meter
->u
.fb_offset
))
13572 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13575 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13576 "for DW_FORM_block* DW_AT_location is supported for "
13577 "DW_TAG_call_site child DIE %s "
13579 sect_offset_str (child_die
->sect_off
),
13580 objfile_name (objfile
));
13585 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13587 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13588 if (attr
== NULL
|| !attr
->form_is_block ())
13590 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13591 "DW_TAG_call_site child DIE %s [in module %s]"),
13592 sect_offset_str (child_die
->sect_off
),
13593 objfile_name (objfile
));
13596 parameter
->value
= DW_BLOCK (attr
)->data
;
13597 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13599 /* Parameters are not pre-cleared by memset above. */
13600 parameter
->data_value
= NULL
;
13601 parameter
->data_value_size
= 0;
13602 call_site
->parameter_count
++;
13604 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13606 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13607 if (attr
!= nullptr)
13609 if (!attr
->form_is_block ())
13610 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13611 "DW_TAG_call_site child DIE %s [in module %s]"),
13612 sect_offset_str (child_die
->sect_off
),
13613 objfile_name (objfile
));
13616 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13617 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13623 /* Helper function for read_variable. If DIE represents a virtual
13624 table, then return the type of the concrete object that is
13625 associated with the virtual table. Otherwise, return NULL. */
13627 static struct type
*
13628 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13630 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13634 /* Find the type DIE. */
13635 struct die_info
*type_die
= NULL
;
13636 struct dwarf2_cu
*type_cu
= cu
;
13638 if (attr
->form_is_ref ())
13639 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13640 if (type_die
== NULL
)
13643 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13645 return die_containing_type (type_die
, type_cu
);
13648 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13651 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13653 struct rust_vtable_symbol
*storage
= NULL
;
13655 if (cu
->language
== language_rust
)
13657 struct type
*containing_type
= rust_containing_type (die
, cu
);
13659 if (containing_type
!= NULL
)
13661 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13663 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13664 storage
->concrete_type
= containing_type
;
13665 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13669 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13670 struct attribute
*abstract_origin
13671 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13672 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13673 if (res
== NULL
&& loc
&& abstract_origin
)
13675 /* We have a variable without a name, but with a location and an abstract
13676 origin. This may be a concrete instance of an abstract variable
13677 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13679 struct dwarf2_cu
*origin_cu
= cu
;
13680 struct die_info
*origin_die
13681 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13682 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13683 per_objfile
->per_bfd
->abstract_to_concrete
13684 [origin_die
->sect_off
].push_back (die
->sect_off
);
13688 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13689 reading .debug_rnglists.
13690 Callback's type should be:
13691 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13692 Return true if the attributes are present and valid, otherwise,
13695 template <typename Callback
>
13697 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13698 Callback
&&callback
)
13700 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
13701 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13702 bfd
*obfd
= objfile
->obfd
;
13703 /* Base address selection entry. */
13704 gdb::optional
<CORE_ADDR
> base
;
13705 const gdb_byte
*buffer
;
13706 CORE_ADDR baseaddr
;
13707 bool overflow
= false;
13709 base
= cu
->base_address
;
13711 dwarf2_per_objfile
->per_bfd
->rnglists
.read (objfile
);
13712 if (offset
>= dwarf2_per_objfile
->per_bfd
->rnglists
.size
)
13714 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13718 buffer
= dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13720 baseaddr
= objfile
->text_section_offset ();
13724 /* Initialize it due to a false compiler warning. */
13725 CORE_ADDR range_beginning
= 0, range_end
= 0;
13726 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
13727 + dwarf2_per_objfile
->per_bfd
->rnglists
.size
);
13728 unsigned int bytes_read
;
13730 if (buffer
== buf_end
)
13735 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13738 case DW_RLE_end_of_list
:
13740 case DW_RLE_base_address
:
13741 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13746 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13747 buffer
+= bytes_read
;
13749 case DW_RLE_start_length
:
13750 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13755 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13757 buffer
+= bytes_read
;
13758 range_end
= (range_beginning
13759 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13760 buffer
+= bytes_read
;
13761 if (buffer
> buf_end
)
13767 case DW_RLE_offset_pair
:
13768 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13769 buffer
+= bytes_read
;
13770 if (buffer
> buf_end
)
13775 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13776 buffer
+= bytes_read
;
13777 if (buffer
> buf_end
)
13783 case DW_RLE_start_end
:
13784 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13789 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13791 buffer
+= bytes_read
;
13792 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13793 buffer
+= bytes_read
;
13796 complaint (_("Invalid .debug_rnglists data (no base address)"));
13799 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13801 if (rlet
== DW_RLE_base_address
)
13804 if (!base
.has_value ())
13806 /* We have no valid base address for the ranges
13808 complaint (_("Invalid .debug_rnglists data (no base address)"));
13812 if (range_beginning
> range_end
)
13814 /* Inverted range entries are invalid. */
13815 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13819 /* Empty range entries have no effect. */
13820 if (range_beginning
== range_end
)
13823 range_beginning
+= *base
;
13824 range_end
+= *base
;
13826 /* A not-uncommon case of bad debug info.
13827 Don't pollute the addrmap with bad data. */
13828 if (range_beginning
+ baseaddr
== 0
13829 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13831 complaint (_(".debug_rnglists entry has start address of zero"
13832 " [in module %s]"), objfile_name (objfile
));
13836 callback (range_beginning
, range_end
);
13841 complaint (_("Offset %d is not terminated "
13842 "for DW_AT_ranges attribute"),
13850 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13851 Callback's type should be:
13852 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13853 Return 1 if the attributes are present and valid, otherwise, return 0. */
13855 template <typename Callback
>
13857 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13858 Callback
&&callback
)
13860 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13861 struct objfile
*objfile
= per_objfile
->objfile
;
13862 struct comp_unit_head
*cu_header
= &cu
->header
;
13863 bfd
*obfd
= objfile
->obfd
;
13864 unsigned int addr_size
= cu_header
->addr_size
;
13865 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13866 /* Base address selection entry. */
13867 gdb::optional
<CORE_ADDR
> base
;
13868 unsigned int dummy
;
13869 const gdb_byte
*buffer
;
13870 CORE_ADDR baseaddr
;
13872 if (cu_header
->version
>= 5)
13873 return dwarf2_rnglists_process (offset
, cu
, callback
);
13875 base
= cu
->base_address
;
13877 per_objfile
->per_bfd
->ranges
.read (objfile
);
13878 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13880 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13884 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13886 baseaddr
= objfile
->text_section_offset ();
13890 CORE_ADDR range_beginning
, range_end
;
13892 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13893 buffer
+= addr_size
;
13894 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13895 buffer
+= addr_size
;
13896 offset
+= 2 * addr_size
;
13898 /* An end of list marker is a pair of zero addresses. */
13899 if (range_beginning
== 0 && range_end
== 0)
13900 /* Found the end of list entry. */
13903 /* Each base address selection entry is a pair of 2 values.
13904 The first is the largest possible address, the second is
13905 the base address. Check for a base address here. */
13906 if ((range_beginning
& mask
) == mask
)
13908 /* If we found the largest possible address, then we already
13909 have the base address in range_end. */
13914 if (!base
.has_value ())
13916 /* We have no valid base address for the ranges
13918 complaint (_("Invalid .debug_ranges data (no base address)"));
13922 if (range_beginning
> range_end
)
13924 /* Inverted range entries are invalid. */
13925 complaint (_("Invalid .debug_ranges data (inverted range)"));
13929 /* Empty range entries have no effect. */
13930 if (range_beginning
== range_end
)
13933 range_beginning
+= *base
;
13934 range_end
+= *base
;
13936 /* A not-uncommon case of bad debug info.
13937 Don't pollute the addrmap with bad data. */
13938 if (range_beginning
+ baseaddr
== 0
13939 && !per_objfile
->per_bfd
->has_section_at_zero
)
13941 complaint (_(".debug_ranges entry has start address of zero"
13942 " [in module %s]"), objfile_name (objfile
));
13946 callback (range_beginning
, range_end
);
13952 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13953 Return 1 if the attributes are present and valid, otherwise, return 0.
13954 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13957 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13958 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13959 dwarf2_psymtab
*ranges_pst
)
13961 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13962 struct gdbarch
*gdbarch
= objfile
->arch ();
13963 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13966 CORE_ADDR high
= 0;
13969 retval
= dwarf2_ranges_process (offset
, cu
,
13970 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13972 if (ranges_pst
!= NULL
)
13977 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13978 range_beginning
+ baseaddr
)
13980 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13981 range_end
+ baseaddr
)
13983 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13984 lowpc
, highpc
- 1, ranges_pst
);
13987 /* FIXME: This is recording everything as a low-high
13988 segment of consecutive addresses. We should have a
13989 data structure for discontiguous block ranges
13993 low
= range_beginning
;
13999 if (range_beginning
< low
)
14000 low
= range_beginning
;
14001 if (range_end
> high
)
14009 /* If the first entry is an end-of-list marker, the range
14010 describes an empty scope, i.e. no instructions. */
14016 *high_return
= high
;
14020 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14021 definition for the return value. *LOWPC and *HIGHPC are set iff
14022 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14024 static enum pc_bounds_kind
14025 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14026 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14027 dwarf2_psymtab
*pst
)
14029 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
14030 struct attribute
*attr
;
14031 struct attribute
*attr_high
;
14033 CORE_ADDR high
= 0;
14034 enum pc_bounds_kind ret
;
14036 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14039 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14040 if (attr
!= nullptr)
14042 low
= attr
->value_as_address ();
14043 high
= attr_high
->value_as_address ();
14044 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14048 /* Found high w/o low attribute. */
14049 return PC_BOUNDS_INVALID
;
14051 /* Found consecutive range of addresses. */
14052 ret
= PC_BOUNDS_HIGH_LOW
;
14056 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14059 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14060 We take advantage of the fact that DW_AT_ranges does not appear
14061 in DW_TAG_compile_unit of DWO files. */
14062 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14063 unsigned int ranges_offset
= (DW_UNSND (attr
)
14064 + (need_ranges_base
14068 /* Value of the DW_AT_ranges attribute is the offset in the
14069 .debug_ranges section. */
14070 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14071 return PC_BOUNDS_INVALID
;
14072 /* Found discontinuous range of addresses. */
14073 ret
= PC_BOUNDS_RANGES
;
14076 return PC_BOUNDS_NOT_PRESENT
;
14079 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14081 return PC_BOUNDS_INVALID
;
14083 /* When using the GNU linker, .gnu.linkonce. sections are used to
14084 eliminate duplicate copies of functions and vtables and such.
14085 The linker will arbitrarily choose one and discard the others.
14086 The AT_*_pc values for such functions refer to local labels in
14087 these sections. If the section from that file was discarded, the
14088 labels are not in the output, so the relocs get a value of 0.
14089 If this is a discarded function, mark the pc bounds as invalid,
14090 so that GDB will ignore it. */
14091 if (low
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
14092 return PC_BOUNDS_INVALID
;
14100 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14101 its low and high PC addresses. Do nothing if these addresses could not
14102 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14103 and HIGHPC to the high address if greater than HIGHPC. */
14106 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14107 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14108 struct dwarf2_cu
*cu
)
14110 CORE_ADDR low
, high
;
14111 struct die_info
*child
= die
->child
;
14113 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14115 *lowpc
= std::min (*lowpc
, low
);
14116 *highpc
= std::max (*highpc
, high
);
14119 /* If the language does not allow nested subprograms (either inside
14120 subprograms or lexical blocks), we're done. */
14121 if (cu
->language
!= language_ada
)
14124 /* Check all the children of the given DIE. If it contains nested
14125 subprograms, then check their pc bounds. Likewise, we need to
14126 check lexical blocks as well, as they may also contain subprogram
14128 while (child
&& child
->tag
)
14130 if (child
->tag
== DW_TAG_subprogram
14131 || child
->tag
== DW_TAG_lexical_block
)
14132 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14133 child
= child
->sibling
;
14137 /* Get the low and high pc's represented by the scope DIE, and store
14138 them in *LOWPC and *HIGHPC. If the correct values can't be
14139 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14142 get_scope_pc_bounds (struct die_info
*die
,
14143 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14144 struct dwarf2_cu
*cu
)
14146 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14147 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14148 CORE_ADDR current_low
, current_high
;
14150 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14151 >= PC_BOUNDS_RANGES
)
14153 best_low
= current_low
;
14154 best_high
= current_high
;
14158 struct die_info
*child
= die
->child
;
14160 while (child
&& child
->tag
)
14162 switch (child
->tag
) {
14163 case DW_TAG_subprogram
:
14164 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14166 case DW_TAG_namespace
:
14167 case DW_TAG_module
:
14168 /* FIXME: carlton/2004-01-16: Should we do this for
14169 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14170 that current GCC's always emit the DIEs corresponding
14171 to definitions of methods of classes as children of a
14172 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14173 the DIEs giving the declarations, which could be
14174 anywhere). But I don't see any reason why the
14175 standards says that they have to be there. */
14176 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14178 if (current_low
!= ((CORE_ADDR
) -1))
14180 best_low
= std::min (best_low
, current_low
);
14181 best_high
= std::max (best_high
, current_high
);
14189 child
= child
->sibling
;
14194 *highpc
= best_high
;
14197 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14201 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14202 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14204 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14205 struct gdbarch
*gdbarch
= objfile
->arch ();
14206 struct attribute
*attr
;
14207 struct attribute
*attr_high
;
14209 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14212 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14213 if (attr
!= nullptr)
14215 CORE_ADDR low
= attr
->value_as_address ();
14216 CORE_ADDR high
= attr_high
->value_as_address ();
14218 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14221 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14222 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14223 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14227 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14228 if (attr
!= nullptr)
14230 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14231 We take advantage of the fact that DW_AT_ranges does not appear
14232 in DW_TAG_compile_unit of DWO files. */
14233 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14235 /* The value of the DW_AT_ranges attribute is the offset of the
14236 address range list in the .debug_ranges section. */
14237 unsigned long offset
= (DW_UNSND (attr
)
14238 + (need_ranges_base
? cu
->ranges_base
: 0));
14240 std::vector
<blockrange
> blockvec
;
14241 dwarf2_ranges_process (offset
, cu
,
14242 [&] (CORE_ADDR start
, CORE_ADDR end
)
14246 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14247 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14248 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14249 blockvec
.emplace_back (start
, end
);
14252 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14256 /* Check whether the producer field indicates either of GCC < 4.6, or the
14257 Intel C/C++ compiler, and cache the result in CU. */
14260 check_producer (struct dwarf2_cu
*cu
)
14264 if (cu
->producer
== NULL
)
14266 /* For unknown compilers expect their behavior is DWARF version
14269 GCC started to support .debug_types sections by -gdwarf-4 since
14270 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14271 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14272 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14273 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14275 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14277 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14278 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14280 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14282 cu
->producer_is_icc
= true;
14283 cu
->producer_is_icc_lt_14
= major
< 14;
14285 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14286 cu
->producer_is_codewarrior
= true;
14289 /* For other non-GCC compilers, expect their behavior is DWARF version
14293 cu
->checked_producer
= true;
14296 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14297 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14298 during 4.6.0 experimental. */
14301 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14303 if (!cu
->checked_producer
)
14304 check_producer (cu
);
14306 return cu
->producer_is_gxx_lt_4_6
;
14310 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14311 with incorrect is_stmt attributes. */
14314 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14316 if (!cu
->checked_producer
)
14317 check_producer (cu
);
14319 return cu
->producer_is_codewarrior
;
14322 /* Return the default accessibility type if it is not overridden by
14323 DW_AT_accessibility. */
14325 static enum dwarf_access_attribute
14326 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14328 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14330 /* The default DWARF 2 accessibility for members is public, the default
14331 accessibility for inheritance is private. */
14333 if (die
->tag
!= DW_TAG_inheritance
)
14334 return DW_ACCESS_public
;
14336 return DW_ACCESS_private
;
14340 /* DWARF 3+ defines the default accessibility a different way. The same
14341 rules apply now for DW_TAG_inheritance as for the members and it only
14342 depends on the container kind. */
14344 if (die
->parent
->tag
== DW_TAG_class_type
)
14345 return DW_ACCESS_private
;
14347 return DW_ACCESS_public
;
14351 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14352 offset. If the attribute was not found return 0, otherwise return
14353 1. If it was found but could not properly be handled, set *OFFSET
14357 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14360 struct attribute
*attr
;
14362 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14367 /* Note that we do not check for a section offset first here.
14368 This is because DW_AT_data_member_location is new in DWARF 4,
14369 so if we see it, we can assume that a constant form is really
14370 a constant and not a section offset. */
14371 if (attr
->form_is_constant ())
14372 *offset
= attr
->constant_value (0);
14373 else if (attr
->form_is_section_offset ())
14374 dwarf2_complex_location_expr_complaint ();
14375 else if (attr
->form_is_block ())
14376 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14378 dwarf2_complex_location_expr_complaint ();
14386 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14389 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14390 struct field
*field
)
14392 struct attribute
*attr
;
14394 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14397 if (attr
->form_is_constant ())
14399 LONGEST offset
= attr
->constant_value (0);
14400 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14402 else if (attr
->form_is_section_offset ())
14403 dwarf2_complex_location_expr_complaint ();
14404 else if (attr
->form_is_block ())
14407 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14409 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14412 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14413 struct objfile
*objfile
= per_objfile
->objfile
;
14414 struct dwarf2_locexpr_baton
*dlbaton
14415 = XOBNEW (&objfile
->objfile_obstack
,
14416 struct dwarf2_locexpr_baton
);
14417 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14418 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14419 /* When using this baton, we want to compute the address
14420 of the field, not the value. This is why
14421 is_reference is set to false here. */
14422 dlbaton
->is_reference
= false;
14423 dlbaton
->per_objfile
= per_objfile
;
14424 dlbaton
->per_cu
= cu
->per_cu
;
14426 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14430 dwarf2_complex_location_expr_complaint ();
14434 /* Add an aggregate field to the field list. */
14437 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14438 struct dwarf2_cu
*cu
)
14440 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14441 struct gdbarch
*gdbarch
= objfile
->arch ();
14442 struct nextfield
*new_field
;
14443 struct attribute
*attr
;
14445 const char *fieldname
= "";
14447 if (die
->tag
== DW_TAG_inheritance
)
14449 fip
->baseclasses
.emplace_back ();
14450 new_field
= &fip
->baseclasses
.back ();
14454 fip
->fields
.emplace_back ();
14455 new_field
= &fip
->fields
.back ();
14458 new_field
->offset
= die
->sect_off
;
14460 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14461 if (attr
!= nullptr)
14462 new_field
->accessibility
= DW_UNSND (attr
);
14464 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14465 if (new_field
->accessibility
!= DW_ACCESS_public
)
14466 fip
->non_public_fields
= 1;
14468 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14469 if (attr
!= nullptr)
14470 new_field
->virtuality
= DW_UNSND (attr
);
14472 new_field
->virtuality
= DW_VIRTUALITY_none
;
14474 fp
= &new_field
->field
;
14476 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14478 /* Data member other than a C++ static data member. */
14480 /* Get type of field. */
14481 fp
->type
= die_type (die
, cu
);
14483 SET_FIELD_BITPOS (*fp
, 0);
14485 /* Get bit size of field (zero if none). */
14486 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14487 if (attr
!= nullptr)
14489 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14493 FIELD_BITSIZE (*fp
) = 0;
14496 /* Get bit offset of field. */
14497 handle_data_member_location (die
, cu
, fp
);
14498 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14499 if (attr
!= nullptr)
14501 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14503 /* For big endian bits, the DW_AT_bit_offset gives the
14504 additional bit offset from the MSB of the containing
14505 anonymous object to the MSB of the field. We don't
14506 have to do anything special since we don't need to
14507 know the size of the anonymous object. */
14508 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14512 /* For little endian bits, compute the bit offset to the
14513 MSB of the anonymous object, subtract off the number of
14514 bits from the MSB of the field to the MSB of the
14515 object, and then subtract off the number of bits of
14516 the field itself. The result is the bit offset of
14517 the LSB of the field. */
14518 int anonymous_size
;
14519 int bit_offset
= DW_UNSND (attr
);
14521 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14522 if (attr
!= nullptr)
14524 /* The size of the anonymous object containing
14525 the bit field is explicit, so use the
14526 indicated size (in bytes). */
14527 anonymous_size
= DW_UNSND (attr
);
14531 /* The size of the anonymous object containing
14532 the bit field must be inferred from the type
14533 attribute of the data member containing the
14535 anonymous_size
= TYPE_LENGTH (fp
->type
);
14537 SET_FIELD_BITPOS (*fp
,
14538 (FIELD_BITPOS (*fp
)
14539 + anonymous_size
* bits_per_byte
14540 - bit_offset
- FIELD_BITSIZE (*fp
)));
14543 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14545 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14546 + attr
->constant_value (0)));
14548 /* Get name of field. */
14549 fieldname
= dwarf2_name (die
, cu
);
14550 if (fieldname
== NULL
)
14553 /* The name is already allocated along with this objfile, so we don't
14554 need to duplicate it for the type. */
14555 fp
->name
= fieldname
;
14557 /* Change accessibility for artificial fields (e.g. virtual table
14558 pointer or virtual base class pointer) to private. */
14559 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14561 FIELD_ARTIFICIAL (*fp
) = 1;
14562 new_field
->accessibility
= DW_ACCESS_private
;
14563 fip
->non_public_fields
= 1;
14566 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14568 /* C++ static member. */
14570 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14571 is a declaration, but all versions of G++ as of this writing
14572 (so through at least 3.2.1) incorrectly generate
14573 DW_TAG_variable tags. */
14575 const char *physname
;
14577 /* Get name of field. */
14578 fieldname
= dwarf2_name (die
, cu
);
14579 if (fieldname
== NULL
)
14582 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14584 /* Only create a symbol if this is an external value.
14585 new_symbol checks this and puts the value in the global symbol
14586 table, which we want. If it is not external, new_symbol
14587 will try to put the value in cu->list_in_scope which is wrong. */
14588 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14590 /* A static const member, not much different than an enum as far as
14591 we're concerned, except that we can support more types. */
14592 new_symbol (die
, NULL
, cu
);
14595 /* Get physical name. */
14596 physname
= dwarf2_physname (fieldname
, die
, cu
);
14598 /* The name is already allocated along with this objfile, so we don't
14599 need to duplicate it for the type. */
14600 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14601 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14602 FIELD_NAME (*fp
) = fieldname
;
14604 else if (die
->tag
== DW_TAG_inheritance
)
14606 /* C++ base class field. */
14607 handle_data_member_location (die
, cu
, fp
);
14608 FIELD_BITSIZE (*fp
) = 0;
14609 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14610 FIELD_NAME (*fp
) = fp
->type
->name ();
14613 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14616 /* Can the type given by DIE define another type? */
14619 type_can_define_types (const struct die_info
*die
)
14623 case DW_TAG_typedef
:
14624 case DW_TAG_class_type
:
14625 case DW_TAG_structure_type
:
14626 case DW_TAG_union_type
:
14627 case DW_TAG_enumeration_type
:
14635 /* Add a type definition defined in the scope of the FIP's class. */
14638 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14639 struct dwarf2_cu
*cu
)
14641 struct decl_field fp
;
14642 memset (&fp
, 0, sizeof (fp
));
14644 gdb_assert (type_can_define_types (die
));
14646 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14647 fp
.name
= dwarf2_name (die
, cu
);
14648 fp
.type
= read_type_die (die
, cu
);
14650 /* Save accessibility. */
14651 enum dwarf_access_attribute accessibility
;
14652 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14654 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14656 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14657 switch (accessibility
)
14659 case DW_ACCESS_public
:
14660 /* The assumed value if neither private nor protected. */
14662 case DW_ACCESS_private
:
14665 case DW_ACCESS_protected
:
14666 fp
.is_protected
= 1;
14669 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14672 if (die
->tag
== DW_TAG_typedef
)
14673 fip
->typedef_field_list
.push_back (fp
);
14675 fip
->nested_types_list
.push_back (fp
);
14678 /* A convenience typedef that's used when finding the discriminant
14679 field for a variant part. */
14680 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14683 /* Compute the discriminant range for a given variant. OBSTACK is
14684 where the results will be stored. VARIANT is the variant to
14685 process. IS_UNSIGNED indicates whether the discriminant is signed
14688 static const gdb::array_view
<discriminant_range
>
14689 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14692 std::vector
<discriminant_range
> ranges
;
14694 if (variant
.default_branch
)
14697 if (variant
.discr_list_data
== nullptr)
14699 discriminant_range r
14700 = {variant
.discriminant_value
, variant
.discriminant_value
};
14701 ranges
.push_back (r
);
14705 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14706 variant
.discr_list_data
->size
);
14707 while (!data
.empty ())
14709 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14711 complaint (_("invalid discriminant marker: %d"), data
[0]);
14714 bool is_range
= data
[0] == DW_DSC_range
;
14715 data
= data
.slice (1);
14717 ULONGEST low
, high
;
14718 unsigned int bytes_read
;
14722 complaint (_("DW_AT_discr_list missing low value"));
14726 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14728 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14730 data
= data
.slice (bytes_read
);
14736 complaint (_("DW_AT_discr_list missing high value"));
14740 high
= read_unsigned_leb128 (nullptr, data
.data (),
14743 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14745 data
= data
.slice (bytes_read
);
14750 ranges
.push_back ({ low
, high
});
14754 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14756 std::copy (ranges
.begin (), ranges
.end (), result
);
14757 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14760 static const gdb::array_view
<variant_part
> create_variant_parts
14761 (struct obstack
*obstack
,
14762 const offset_map_type
&offset_map
,
14763 struct field_info
*fi
,
14764 const std::vector
<variant_part_builder
> &variant_parts
);
14766 /* Fill in a "struct variant" for a given variant field. RESULT is
14767 the variant to fill in. OBSTACK is where any needed allocations
14768 will be done. OFFSET_MAP holds the mapping from section offsets to
14769 fields for the type. FI describes the fields of the type we're
14770 processing. FIELD is the variant field we're converting. */
14773 create_one_variant (variant
&result
, struct obstack
*obstack
,
14774 const offset_map_type
&offset_map
,
14775 struct field_info
*fi
, const variant_field
&field
)
14777 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14778 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14779 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14780 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14781 field
.variant_parts
);
14784 /* Fill in a "struct variant_part" for a given variant part. RESULT
14785 is the variant part to fill in. OBSTACK is where any needed
14786 allocations will be done. OFFSET_MAP holds the mapping from
14787 section offsets to fields for the type. FI describes the fields of
14788 the type we're processing. BUILDER is the variant part to be
14792 create_one_variant_part (variant_part
&result
,
14793 struct obstack
*obstack
,
14794 const offset_map_type
&offset_map
,
14795 struct field_info
*fi
,
14796 const variant_part_builder
&builder
)
14798 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14799 if (iter
== offset_map
.end ())
14801 result
.discriminant_index
= -1;
14802 /* Doesn't matter. */
14803 result
.is_unsigned
= false;
14807 result
.discriminant_index
= iter
->second
;
14809 = TYPE_UNSIGNED (FIELD_TYPE
14810 (fi
->fields
[result
.discriminant_index
].field
));
14813 size_t n
= builder
.variants
.size ();
14814 variant
*output
= new (obstack
) variant
[n
];
14815 for (size_t i
= 0; i
< n
; ++i
)
14816 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14817 builder
.variants
[i
]);
14819 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14822 /* Create a vector of variant parts that can be attached to a type.
14823 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14824 holds the mapping from section offsets to fields for the type. FI
14825 describes the fields of the type we're processing. VARIANT_PARTS
14826 is the vector to convert. */
14828 static const gdb::array_view
<variant_part
>
14829 create_variant_parts (struct obstack
*obstack
,
14830 const offset_map_type
&offset_map
,
14831 struct field_info
*fi
,
14832 const std::vector
<variant_part_builder
> &variant_parts
)
14834 if (variant_parts
.empty ())
14837 size_t n
= variant_parts
.size ();
14838 variant_part
*result
= new (obstack
) variant_part
[n
];
14839 for (size_t i
= 0; i
< n
; ++i
)
14840 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14843 return gdb::array_view
<variant_part
> (result
, n
);
14846 /* Compute the variant part vector for FIP, attaching it to TYPE when
14850 add_variant_property (struct field_info
*fip
, struct type
*type
,
14851 struct dwarf2_cu
*cu
)
14853 /* Map section offsets of fields to their field index. Note the
14854 field index here does not take the number of baseclasses into
14856 offset_map_type offset_map
;
14857 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14858 offset_map
[fip
->fields
[i
].offset
] = i
;
14860 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14861 gdb::array_view
<variant_part
> parts
14862 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14863 fip
->variant_parts
);
14865 struct dynamic_prop prop
;
14866 prop
.kind
= PROP_VARIANT_PARTS
;
14867 prop
.data
.variant_parts
14868 = ((gdb::array_view
<variant_part
> *)
14869 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14871 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14874 /* Create the vector of fields, and attach it to the type. */
14877 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14878 struct dwarf2_cu
*cu
)
14880 int nfields
= fip
->nfields ();
14882 /* Record the field count, allocate space for the array of fields,
14883 and create blank accessibility bitfields if necessary. */
14884 type
->set_num_fields (nfields
);
14886 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14888 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14890 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14892 TYPE_FIELD_PRIVATE_BITS (type
) =
14893 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14894 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14896 TYPE_FIELD_PROTECTED_BITS (type
) =
14897 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14898 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14900 TYPE_FIELD_IGNORE_BITS (type
) =
14901 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14902 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14905 /* If the type has baseclasses, allocate and clear a bit vector for
14906 TYPE_FIELD_VIRTUAL_BITS. */
14907 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14909 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14910 unsigned char *pointer
;
14912 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14913 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14914 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14915 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14916 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14919 if (!fip
->variant_parts
.empty ())
14920 add_variant_property (fip
, type
, cu
);
14922 /* Copy the saved-up fields into the field vector. */
14923 for (int i
= 0; i
< nfields
; ++i
)
14925 struct nextfield
&field
14926 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14927 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14929 type
->field (i
) = field
.field
;
14930 switch (field
.accessibility
)
14932 case DW_ACCESS_private
:
14933 if (cu
->language
!= language_ada
)
14934 SET_TYPE_FIELD_PRIVATE (type
, i
);
14937 case DW_ACCESS_protected
:
14938 if (cu
->language
!= language_ada
)
14939 SET_TYPE_FIELD_PROTECTED (type
, i
);
14942 case DW_ACCESS_public
:
14946 /* Unknown accessibility. Complain and treat it as public. */
14948 complaint (_("unsupported accessibility %d"),
14949 field
.accessibility
);
14953 if (i
< fip
->baseclasses
.size ())
14955 switch (field
.virtuality
)
14957 case DW_VIRTUALITY_virtual
:
14958 case DW_VIRTUALITY_pure_virtual
:
14959 if (cu
->language
== language_ada
)
14960 error (_("unexpected virtuality in component of Ada type"));
14961 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14968 /* Return true if this member function is a constructor, false
14972 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14974 const char *fieldname
;
14975 const char *type_name
;
14978 if (die
->parent
== NULL
)
14981 if (die
->parent
->tag
!= DW_TAG_structure_type
14982 && die
->parent
->tag
!= DW_TAG_union_type
14983 && die
->parent
->tag
!= DW_TAG_class_type
)
14986 fieldname
= dwarf2_name (die
, cu
);
14987 type_name
= dwarf2_name (die
->parent
, cu
);
14988 if (fieldname
== NULL
|| type_name
== NULL
)
14991 len
= strlen (fieldname
);
14992 return (strncmp (fieldname
, type_name
, len
) == 0
14993 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14996 /* Check if the given VALUE is a recognized enum
14997 dwarf_defaulted_attribute constant according to DWARF5 spec,
15001 is_valid_DW_AT_defaulted (ULONGEST value
)
15005 case DW_DEFAULTED_no
:
15006 case DW_DEFAULTED_in_class
:
15007 case DW_DEFAULTED_out_of_class
:
15011 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15015 /* Add a member function to the proper fieldlist. */
15018 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15019 struct type
*type
, struct dwarf2_cu
*cu
)
15021 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15022 struct attribute
*attr
;
15024 struct fnfieldlist
*flp
= nullptr;
15025 struct fn_field
*fnp
;
15026 const char *fieldname
;
15027 struct type
*this_type
;
15028 enum dwarf_access_attribute accessibility
;
15030 if (cu
->language
== language_ada
)
15031 error (_("unexpected member function in Ada type"));
15033 /* Get name of member function. */
15034 fieldname
= dwarf2_name (die
, cu
);
15035 if (fieldname
== NULL
)
15038 /* Look up member function name in fieldlist. */
15039 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15041 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15043 flp
= &fip
->fnfieldlists
[i
];
15048 /* Create a new fnfieldlist if necessary. */
15049 if (flp
== nullptr)
15051 fip
->fnfieldlists
.emplace_back ();
15052 flp
= &fip
->fnfieldlists
.back ();
15053 flp
->name
= fieldname
;
15054 i
= fip
->fnfieldlists
.size () - 1;
15057 /* Create a new member function field and add it to the vector of
15059 flp
->fnfields
.emplace_back ();
15060 fnp
= &flp
->fnfields
.back ();
15062 /* Delay processing of the physname until later. */
15063 if (cu
->language
== language_cplus
)
15064 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15068 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15069 fnp
->physname
= physname
? physname
: "";
15072 fnp
->type
= alloc_type (objfile
);
15073 this_type
= read_type_die (die
, cu
);
15074 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15076 int nparams
= this_type
->num_fields ();
15078 /* TYPE is the domain of this method, and THIS_TYPE is the type
15079 of the method itself (TYPE_CODE_METHOD). */
15080 smash_to_method_type (fnp
->type
, type
,
15081 TYPE_TARGET_TYPE (this_type
),
15082 this_type
->fields (),
15083 this_type
->num_fields (),
15084 TYPE_VARARGS (this_type
));
15086 /* Handle static member functions.
15087 Dwarf2 has no clean way to discern C++ static and non-static
15088 member functions. G++ helps GDB by marking the first
15089 parameter for non-static member functions (which is the this
15090 pointer) as artificial. We obtain this information from
15091 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15092 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15093 fnp
->voffset
= VOFFSET_STATIC
;
15096 complaint (_("member function type missing for '%s'"),
15097 dwarf2_full_name (fieldname
, die
, cu
));
15099 /* Get fcontext from DW_AT_containing_type if present. */
15100 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15101 fnp
->fcontext
= die_containing_type (die
, cu
);
15103 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15104 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15106 /* Get accessibility. */
15107 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15108 if (attr
!= nullptr)
15109 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15111 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15112 switch (accessibility
)
15114 case DW_ACCESS_private
:
15115 fnp
->is_private
= 1;
15117 case DW_ACCESS_protected
:
15118 fnp
->is_protected
= 1;
15122 /* Check for artificial methods. */
15123 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15124 if (attr
&& DW_UNSND (attr
) != 0)
15125 fnp
->is_artificial
= 1;
15127 /* Check for defaulted methods. */
15128 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15129 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15130 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15132 /* Check for deleted methods. */
15133 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15134 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15135 fnp
->is_deleted
= 1;
15137 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15139 /* Get index in virtual function table if it is a virtual member
15140 function. For older versions of GCC, this is an offset in the
15141 appropriate virtual table, as specified by DW_AT_containing_type.
15142 For everyone else, it is an expression to be evaluated relative
15143 to the object address. */
15145 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15146 if (attr
!= nullptr)
15148 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15150 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15152 /* Old-style GCC. */
15153 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15155 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15156 || (DW_BLOCK (attr
)->size
> 1
15157 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15158 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15160 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15161 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15162 dwarf2_complex_location_expr_complaint ();
15164 fnp
->voffset
/= cu
->header
.addr_size
;
15168 dwarf2_complex_location_expr_complaint ();
15170 if (!fnp
->fcontext
)
15172 /* If there is no `this' field and no DW_AT_containing_type,
15173 we cannot actually find a base class context for the
15175 if (this_type
->num_fields () == 0
15176 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15178 complaint (_("cannot determine context for virtual member "
15179 "function \"%s\" (offset %s)"),
15180 fieldname
, sect_offset_str (die
->sect_off
));
15185 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15189 else if (attr
->form_is_section_offset ())
15191 dwarf2_complex_location_expr_complaint ();
15195 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15201 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15202 if (attr
&& DW_UNSND (attr
))
15204 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15205 complaint (_("Member function \"%s\" (offset %s) is virtual "
15206 "but the vtable offset is not specified"),
15207 fieldname
, sect_offset_str (die
->sect_off
));
15208 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15209 TYPE_CPLUS_DYNAMIC (type
) = 1;
15214 /* Create the vector of member function fields, and attach it to the type. */
15217 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15218 struct dwarf2_cu
*cu
)
15220 if (cu
->language
== language_ada
)
15221 error (_("unexpected member functions in Ada type"));
15223 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15224 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15226 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15228 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15230 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15231 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15233 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15234 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15235 fn_flp
->fn_fields
= (struct fn_field
*)
15236 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15238 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15239 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15242 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15245 /* Returns non-zero if NAME is the name of a vtable member in CU's
15246 language, zero otherwise. */
15248 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15250 static const char vptr
[] = "_vptr";
15252 /* Look for the C++ form of the vtable. */
15253 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15259 /* GCC outputs unnamed structures that are really pointers to member
15260 functions, with the ABI-specified layout. If TYPE describes
15261 such a structure, smash it into a member function type.
15263 GCC shouldn't do this; it should just output pointer to member DIEs.
15264 This is GCC PR debug/28767. */
15267 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15269 struct type
*pfn_type
, *self_type
, *new_type
;
15271 /* Check for a structure with no name and two children. */
15272 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15275 /* Check for __pfn and __delta members. */
15276 if (TYPE_FIELD_NAME (type
, 0) == NULL
15277 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15278 || TYPE_FIELD_NAME (type
, 1) == NULL
15279 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15282 /* Find the type of the method. */
15283 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15284 if (pfn_type
== NULL
15285 || pfn_type
->code () != TYPE_CODE_PTR
15286 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15289 /* Look for the "this" argument. */
15290 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15291 if (pfn_type
->num_fields () == 0
15292 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15293 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15296 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15297 new_type
= alloc_type (objfile
);
15298 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15299 pfn_type
->fields (), pfn_type
->num_fields (),
15300 TYPE_VARARGS (pfn_type
));
15301 smash_to_methodptr_type (type
, new_type
);
15304 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15305 appropriate error checking and issuing complaints if there is a
15309 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15311 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15313 if (attr
== nullptr)
15316 if (!attr
->form_is_constant ())
15318 complaint (_("DW_AT_alignment must have constant form"
15319 " - DIE at %s [in module %s]"),
15320 sect_offset_str (die
->sect_off
),
15321 objfile_name (cu
->per_objfile
->objfile
));
15326 if (attr
->form
== DW_FORM_sdata
)
15328 LONGEST val
= DW_SND (attr
);
15331 complaint (_("DW_AT_alignment value must not be negative"
15332 " - DIE at %s [in module %s]"),
15333 sect_offset_str (die
->sect_off
),
15334 objfile_name (cu
->per_objfile
->objfile
));
15340 align
= DW_UNSND (attr
);
15344 complaint (_("DW_AT_alignment value must not be zero"
15345 " - DIE at %s [in module %s]"),
15346 sect_offset_str (die
->sect_off
),
15347 objfile_name (cu
->per_objfile
->objfile
));
15350 if ((align
& (align
- 1)) != 0)
15352 complaint (_("DW_AT_alignment value must be a power of 2"
15353 " - DIE at %s [in module %s]"),
15354 sect_offset_str (die
->sect_off
),
15355 objfile_name (cu
->per_objfile
->objfile
));
15362 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15363 the alignment for TYPE. */
15366 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15369 if (!set_type_align (type
, get_alignment (cu
, die
)))
15370 complaint (_("DW_AT_alignment value too large"
15371 " - DIE at %s [in module %s]"),
15372 sect_offset_str (die
->sect_off
),
15373 objfile_name (cu
->per_objfile
->objfile
));
15376 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15377 constant for a type, according to DWARF5 spec, Table 5.5. */
15380 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15385 case DW_CC_pass_by_reference
:
15386 case DW_CC_pass_by_value
:
15390 complaint (_("unrecognized DW_AT_calling_convention value "
15391 "(%s) for a type"), pulongest (value
));
15396 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15397 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15398 also according to GNU-specific values (see include/dwarf2.h). */
15401 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15406 case DW_CC_program
:
15410 case DW_CC_GNU_renesas_sh
:
15411 case DW_CC_GNU_borland_fastcall_i386
:
15412 case DW_CC_GDB_IBM_OpenCL
:
15416 complaint (_("unrecognized DW_AT_calling_convention value "
15417 "(%s) for a subroutine"), pulongest (value
));
15422 /* Called when we find the DIE that starts a structure or union scope
15423 (definition) to create a type for the structure or union. Fill in
15424 the type's name and general properties; the members will not be
15425 processed until process_structure_scope. A symbol table entry for
15426 the type will also not be done until process_structure_scope (assuming
15427 the type has a name).
15429 NOTE: we need to call these functions regardless of whether or not the
15430 DIE has a DW_AT_name attribute, since it might be an anonymous
15431 structure or union. This gets the type entered into our set of
15432 user defined types. */
15434 static struct type
*
15435 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15437 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15439 struct attribute
*attr
;
15442 /* If the definition of this type lives in .debug_types, read that type.
15443 Don't follow DW_AT_specification though, that will take us back up
15444 the chain and we want to go down. */
15445 attr
= die
->attr (DW_AT_signature
);
15446 if (attr
!= nullptr)
15448 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15450 /* The type's CU may not be the same as CU.
15451 Ensure TYPE is recorded with CU in die_type_hash. */
15452 return set_die_type (die
, type
, cu
);
15455 type
= alloc_type (objfile
);
15456 INIT_CPLUS_SPECIFIC (type
);
15458 name
= dwarf2_name (die
, cu
);
15461 if (cu
->language
== language_cplus
15462 || cu
->language
== language_d
15463 || cu
->language
== language_rust
)
15465 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15467 /* dwarf2_full_name might have already finished building the DIE's
15468 type. If so, there is no need to continue. */
15469 if (get_die_type (die
, cu
) != NULL
)
15470 return get_die_type (die
, cu
);
15472 type
->set_name (full_name
);
15476 /* The name is already allocated along with this objfile, so
15477 we don't need to duplicate it for the type. */
15478 type
->set_name (name
);
15482 if (die
->tag
== DW_TAG_structure_type
)
15484 type
->set_code (TYPE_CODE_STRUCT
);
15486 else if (die
->tag
== DW_TAG_union_type
)
15488 type
->set_code (TYPE_CODE_UNION
);
15492 type
->set_code (TYPE_CODE_STRUCT
);
15495 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15496 TYPE_DECLARED_CLASS (type
) = 1;
15498 /* Store the calling convention in the type if it's available in
15499 the die. Otherwise the calling convention remains set to
15500 the default value DW_CC_normal. */
15501 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15502 if (attr
!= nullptr
15503 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15505 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15506 TYPE_CPLUS_CALLING_CONVENTION (type
)
15507 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15510 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15511 if (attr
!= nullptr)
15513 if (attr
->form_is_constant ())
15514 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15517 struct dynamic_prop prop
;
15518 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15519 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15520 TYPE_LENGTH (type
) = 0;
15525 TYPE_LENGTH (type
) = 0;
15528 maybe_set_alignment (cu
, die
, type
);
15530 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15532 /* ICC<14 does not output the required DW_AT_declaration on
15533 incomplete types, but gives them a size of zero. */
15534 TYPE_STUB (type
) = 1;
15537 TYPE_STUB_SUPPORTED (type
) = 1;
15539 if (die_is_declaration (die
, cu
))
15540 TYPE_STUB (type
) = 1;
15541 else if (attr
== NULL
&& die
->child
== NULL
15542 && producer_is_realview (cu
->producer
))
15543 /* RealView does not output the required DW_AT_declaration
15544 on incomplete types. */
15545 TYPE_STUB (type
) = 1;
15547 /* We need to add the type field to the die immediately so we don't
15548 infinitely recurse when dealing with pointers to the structure
15549 type within the structure itself. */
15550 set_die_type (die
, type
, cu
);
15552 /* set_die_type should be already done. */
15553 set_descriptive_type (type
, die
, cu
);
15558 static void handle_struct_member_die
15559 (struct die_info
*child_die
,
15561 struct field_info
*fi
,
15562 std::vector
<struct symbol
*> *template_args
,
15563 struct dwarf2_cu
*cu
);
15565 /* A helper for handle_struct_member_die that handles
15566 DW_TAG_variant_part. */
15569 handle_variant_part (struct die_info
*die
, struct type
*type
,
15570 struct field_info
*fi
,
15571 std::vector
<struct symbol
*> *template_args
,
15572 struct dwarf2_cu
*cu
)
15574 variant_part_builder
*new_part
;
15575 if (fi
->current_variant_part
== nullptr)
15577 fi
->variant_parts
.emplace_back ();
15578 new_part
= &fi
->variant_parts
.back ();
15580 else if (!fi
->current_variant_part
->processing_variant
)
15582 complaint (_("nested DW_TAG_variant_part seen "
15583 "- DIE at %s [in module %s]"),
15584 sect_offset_str (die
->sect_off
),
15585 objfile_name (cu
->per_objfile
->objfile
));
15590 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15591 current
.variant_parts
.emplace_back ();
15592 new_part
= ¤t
.variant_parts
.back ();
15595 /* When we recurse, we want callees to add to this new variant
15597 scoped_restore save_current_variant_part
15598 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15600 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15603 /* It's a univariant form, an extension we support. */
15605 else if (discr
->form_is_ref ())
15607 struct dwarf2_cu
*target_cu
= cu
;
15608 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15610 new_part
->discriminant_offset
= target_die
->sect_off
;
15614 complaint (_("DW_AT_discr does not have DIE reference form"
15615 " - DIE at %s [in module %s]"),
15616 sect_offset_str (die
->sect_off
),
15617 objfile_name (cu
->per_objfile
->objfile
));
15620 for (die_info
*child_die
= die
->child
;
15622 child_die
= child_die
->sibling
)
15623 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15626 /* A helper for handle_struct_member_die that handles
15630 handle_variant (struct die_info
*die
, struct type
*type
,
15631 struct field_info
*fi
,
15632 std::vector
<struct symbol
*> *template_args
,
15633 struct dwarf2_cu
*cu
)
15635 if (fi
->current_variant_part
== nullptr)
15637 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15638 "- DIE at %s [in module %s]"),
15639 sect_offset_str (die
->sect_off
),
15640 objfile_name (cu
->per_objfile
->objfile
));
15643 if (fi
->current_variant_part
->processing_variant
)
15645 complaint (_("nested DW_TAG_variant seen "
15646 "- DIE at %s [in module %s]"),
15647 sect_offset_str (die
->sect_off
),
15648 objfile_name (cu
->per_objfile
->objfile
));
15652 scoped_restore save_processing_variant
15653 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15656 fi
->current_variant_part
->variants
.emplace_back ();
15657 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15658 variant
.first_field
= fi
->fields
.size ();
15660 /* In a variant we want to get the discriminant and also add a
15661 field for our sole member child. */
15662 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15663 if (discr
== nullptr)
15665 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15666 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15667 variant
.default_branch
= true;
15669 variant
.discr_list_data
= DW_BLOCK (discr
);
15672 variant
.discriminant_value
= DW_UNSND (discr
);
15674 for (die_info
*variant_child
= die
->child
;
15675 variant_child
!= NULL
;
15676 variant_child
= variant_child
->sibling
)
15677 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15679 variant
.last_field
= fi
->fields
.size ();
15682 /* A helper for process_structure_scope that handles a single member
15686 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15687 struct field_info
*fi
,
15688 std::vector
<struct symbol
*> *template_args
,
15689 struct dwarf2_cu
*cu
)
15691 if (child_die
->tag
== DW_TAG_member
15692 || child_die
->tag
== DW_TAG_variable
)
15694 /* NOTE: carlton/2002-11-05: A C++ static data member
15695 should be a DW_TAG_member that is a declaration, but
15696 all versions of G++ as of this writing (so through at
15697 least 3.2.1) incorrectly generate DW_TAG_variable
15698 tags for them instead. */
15699 dwarf2_add_field (fi
, child_die
, cu
);
15701 else if (child_die
->tag
== DW_TAG_subprogram
)
15703 /* Rust doesn't have member functions in the C++ sense.
15704 However, it does emit ordinary functions as children
15705 of a struct DIE. */
15706 if (cu
->language
== language_rust
)
15707 read_func_scope (child_die
, cu
);
15710 /* C++ member function. */
15711 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15714 else if (child_die
->tag
== DW_TAG_inheritance
)
15716 /* C++ base class field. */
15717 dwarf2_add_field (fi
, child_die
, cu
);
15719 else if (type_can_define_types (child_die
))
15720 dwarf2_add_type_defn (fi
, child_die
, cu
);
15721 else if (child_die
->tag
== DW_TAG_template_type_param
15722 || child_die
->tag
== DW_TAG_template_value_param
)
15724 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15727 template_args
->push_back (arg
);
15729 else if (child_die
->tag
== DW_TAG_variant_part
)
15730 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15731 else if (child_die
->tag
== DW_TAG_variant
)
15732 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15735 /* Finish creating a structure or union type, including filling in
15736 its members and creating a symbol for it. */
15739 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15741 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15742 struct die_info
*child_die
;
15745 type
= get_die_type (die
, cu
);
15747 type
= read_structure_type (die
, cu
);
15749 bool has_template_parameters
= false;
15750 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15752 struct field_info fi
;
15753 std::vector
<struct symbol
*> template_args
;
15755 child_die
= die
->child
;
15757 while (child_die
&& child_die
->tag
)
15759 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15760 child_die
= child_die
->sibling
;
15763 /* Attach template arguments to type. */
15764 if (!template_args
.empty ())
15766 has_template_parameters
= true;
15767 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15768 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15769 TYPE_TEMPLATE_ARGUMENTS (type
)
15770 = XOBNEWVEC (&objfile
->objfile_obstack
,
15772 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15773 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15774 template_args
.data (),
15775 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15776 * sizeof (struct symbol
*)));
15779 /* Attach fields and member functions to the type. */
15780 if (fi
.nfields () > 0)
15781 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15782 if (!fi
.fnfieldlists
.empty ())
15784 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15786 /* Get the type which refers to the base class (possibly this
15787 class itself) which contains the vtable pointer for the current
15788 class from the DW_AT_containing_type attribute. This use of
15789 DW_AT_containing_type is a GNU extension. */
15791 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15793 struct type
*t
= die_containing_type (die
, cu
);
15795 set_type_vptr_basetype (type
, t
);
15800 /* Our own class provides vtbl ptr. */
15801 for (i
= t
->num_fields () - 1;
15802 i
>= TYPE_N_BASECLASSES (t
);
15805 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15807 if (is_vtable_name (fieldname
, cu
))
15809 set_type_vptr_fieldno (type
, i
);
15814 /* Complain if virtual function table field not found. */
15815 if (i
< TYPE_N_BASECLASSES (t
))
15816 complaint (_("virtual function table pointer "
15817 "not found when defining class '%s'"),
15818 type
->name () ? type
->name () : "");
15822 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15825 else if (cu
->producer
15826 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15828 /* The IBM XLC compiler does not provide direct indication
15829 of the containing type, but the vtable pointer is
15830 always named __vfp. */
15834 for (i
= type
->num_fields () - 1;
15835 i
>= TYPE_N_BASECLASSES (type
);
15838 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15840 set_type_vptr_fieldno (type
, i
);
15841 set_type_vptr_basetype (type
, type
);
15848 /* Copy fi.typedef_field_list linked list elements content into the
15849 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15850 if (!fi
.typedef_field_list
.empty ())
15852 int count
= fi
.typedef_field_list
.size ();
15854 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15855 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15856 = ((struct decl_field
*)
15858 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15859 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15861 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15862 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15865 /* Copy fi.nested_types_list linked list elements content into the
15866 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15867 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15869 int count
= fi
.nested_types_list
.size ();
15871 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15872 TYPE_NESTED_TYPES_ARRAY (type
)
15873 = ((struct decl_field
*)
15874 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15875 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15877 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15878 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15882 quirk_gcc_member_function_pointer (type
, objfile
);
15883 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15884 cu
->rust_unions
.push_back (type
);
15886 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15887 snapshots) has been known to create a die giving a declaration
15888 for a class that has, as a child, a die giving a definition for a
15889 nested class. So we have to process our children even if the
15890 current die is a declaration. Normally, of course, a declaration
15891 won't have any children at all. */
15893 child_die
= die
->child
;
15895 while (child_die
!= NULL
&& child_die
->tag
)
15897 if (child_die
->tag
== DW_TAG_member
15898 || child_die
->tag
== DW_TAG_variable
15899 || child_die
->tag
== DW_TAG_inheritance
15900 || child_die
->tag
== DW_TAG_template_value_param
15901 || child_die
->tag
== DW_TAG_template_type_param
)
15906 process_die (child_die
, cu
);
15908 child_die
= child_die
->sibling
;
15911 /* Do not consider external references. According to the DWARF standard,
15912 these DIEs are identified by the fact that they have no byte_size
15913 attribute, and a declaration attribute. */
15914 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15915 || !die_is_declaration (die
, cu
)
15916 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15918 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15920 if (has_template_parameters
)
15922 struct symtab
*symtab
;
15923 if (sym
!= nullptr)
15924 symtab
= symbol_symtab (sym
);
15925 else if (cu
->line_header
!= nullptr)
15927 /* Any related symtab will do. */
15929 = cu
->line_header
->file_names ()[0].symtab
;
15934 complaint (_("could not find suitable "
15935 "symtab for template parameter"
15936 " - DIE at %s [in module %s]"),
15937 sect_offset_str (die
->sect_off
),
15938 objfile_name (objfile
));
15941 if (symtab
!= nullptr)
15943 /* Make sure that the symtab is set on the new symbols.
15944 Even though they don't appear in this symtab directly,
15945 other parts of gdb assume that symbols do, and this is
15946 reasonably true. */
15947 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15948 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15954 /* Assuming DIE is an enumeration type, and TYPE is its associated
15955 type, update TYPE using some information only available in DIE's
15956 children. In particular, the fields are computed. */
15959 update_enumeration_type_from_children (struct die_info
*die
,
15961 struct dwarf2_cu
*cu
)
15963 struct die_info
*child_die
;
15964 int unsigned_enum
= 1;
15967 auto_obstack obstack
;
15968 std::vector
<struct field
> fields
;
15970 for (child_die
= die
->child
;
15971 child_die
!= NULL
&& child_die
->tag
;
15972 child_die
= child_die
->sibling
)
15974 struct attribute
*attr
;
15976 const gdb_byte
*bytes
;
15977 struct dwarf2_locexpr_baton
*baton
;
15980 if (child_die
->tag
!= DW_TAG_enumerator
)
15983 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15987 name
= dwarf2_name (child_die
, cu
);
15989 name
= "<anonymous enumerator>";
15991 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15992 &value
, &bytes
, &baton
);
16000 if (count_one_bits_ll (value
) >= 2)
16004 fields
.emplace_back ();
16005 struct field
&field
= fields
.back ();
16006 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16007 SET_FIELD_ENUMVAL (field
, value
);
16010 if (!fields
.empty ())
16012 type
->set_num_fields (fields
.size ());
16015 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16016 memcpy (type
->fields (), fields
.data (),
16017 sizeof (struct field
) * fields
.size ());
16021 TYPE_UNSIGNED (type
) = 1;
16023 TYPE_FLAG_ENUM (type
) = 1;
16026 /* Given a DW_AT_enumeration_type die, set its type. We do not
16027 complete the type's fields yet, or create any symbols. */
16029 static struct type
*
16030 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16032 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16034 struct attribute
*attr
;
16037 /* If the definition of this type lives in .debug_types, read that type.
16038 Don't follow DW_AT_specification though, that will take us back up
16039 the chain and we want to go down. */
16040 attr
= die
->attr (DW_AT_signature
);
16041 if (attr
!= nullptr)
16043 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16045 /* The type's CU may not be the same as CU.
16046 Ensure TYPE is recorded with CU in die_type_hash. */
16047 return set_die_type (die
, type
, cu
);
16050 type
= alloc_type (objfile
);
16052 type
->set_code (TYPE_CODE_ENUM
);
16053 name
= dwarf2_full_name (NULL
, die
, cu
);
16055 type
->set_name (name
);
16057 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16060 struct type
*underlying_type
= die_type (die
, cu
);
16062 TYPE_TARGET_TYPE (type
) = underlying_type
;
16065 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16066 if (attr
!= nullptr)
16068 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16072 TYPE_LENGTH (type
) = 0;
16075 maybe_set_alignment (cu
, die
, type
);
16077 /* The enumeration DIE can be incomplete. In Ada, any type can be
16078 declared as private in the package spec, and then defined only
16079 inside the package body. Such types are known as Taft Amendment
16080 Types. When another package uses such a type, an incomplete DIE
16081 may be generated by the compiler. */
16082 if (die_is_declaration (die
, cu
))
16083 TYPE_STUB (type
) = 1;
16085 /* If this type has an underlying type that is not a stub, then we
16086 may use its attributes. We always use the "unsigned" attribute
16087 in this situation, because ordinarily we guess whether the type
16088 is unsigned -- but the guess can be wrong and the underlying type
16089 can tell us the reality. However, we defer to a local size
16090 attribute if one exists, because this lets the compiler override
16091 the underlying type if needed. */
16092 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16094 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16095 underlying_type
= check_typedef (underlying_type
);
16096 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16097 if (TYPE_LENGTH (type
) == 0)
16098 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16099 if (TYPE_RAW_ALIGN (type
) == 0
16100 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16101 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16104 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16106 set_die_type (die
, type
, cu
);
16108 /* Finish the creation of this type by using the enum's children.
16109 Note that, as usual, this must come after set_die_type to avoid
16110 infinite recursion when trying to compute the names of the
16112 update_enumeration_type_from_children (die
, type
, cu
);
16117 /* Given a pointer to a die which begins an enumeration, process all
16118 the dies that define the members of the enumeration, and create the
16119 symbol for the enumeration type.
16121 NOTE: We reverse the order of the element list. */
16124 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16126 struct type
*this_type
;
16128 this_type
= get_die_type (die
, cu
);
16129 if (this_type
== NULL
)
16130 this_type
= read_enumeration_type (die
, cu
);
16132 if (die
->child
!= NULL
)
16134 struct die_info
*child_die
;
16137 child_die
= die
->child
;
16138 while (child_die
&& child_die
->tag
)
16140 if (child_die
->tag
!= DW_TAG_enumerator
)
16142 process_die (child_die
, cu
);
16146 name
= dwarf2_name (child_die
, cu
);
16148 new_symbol (child_die
, this_type
, cu
);
16151 child_die
= child_die
->sibling
;
16155 /* If we are reading an enum from a .debug_types unit, and the enum
16156 is a declaration, and the enum is not the signatured type in the
16157 unit, then we do not want to add a symbol for it. Adding a
16158 symbol would in some cases obscure the true definition of the
16159 enum, giving users an incomplete type when the definition is
16160 actually available. Note that we do not want to do this for all
16161 enums which are just declarations, because C++0x allows forward
16162 enum declarations. */
16163 if (cu
->per_cu
->is_debug_types
16164 && die_is_declaration (die
, cu
))
16166 struct signatured_type
*sig_type
;
16168 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16169 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16170 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16174 new_symbol (die
, this_type
, cu
);
16177 /* Extract all information from a DW_TAG_array_type DIE and put it in
16178 the DIE's type field. For now, this only handles one dimensional
16181 static struct type
*
16182 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16184 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16185 struct die_info
*child_die
;
16187 struct type
*element_type
, *range_type
, *index_type
;
16188 struct attribute
*attr
;
16190 struct dynamic_prop
*byte_stride_prop
= NULL
;
16191 unsigned int bit_stride
= 0;
16193 element_type
= die_type (die
, cu
);
16195 /* The die_type call above may have already set the type for this DIE. */
16196 type
= get_die_type (die
, cu
);
16200 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16204 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16207 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16208 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16212 complaint (_("unable to read array DW_AT_byte_stride "
16213 " - DIE at %s [in module %s]"),
16214 sect_offset_str (die
->sect_off
),
16215 objfile_name (cu
->per_objfile
->objfile
));
16216 /* Ignore this attribute. We will likely not be able to print
16217 arrays of this type correctly, but there is little we can do
16218 to help if we cannot read the attribute's value. */
16219 byte_stride_prop
= NULL
;
16223 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16225 bit_stride
= DW_UNSND (attr
);
16227 /* Irix 6.2 native cc creates array types without children for
16228 arrays with unspecified length. */
16229 if (die
->child
== NULL
)
16231 index_type
= objfile_type (objfile
)->builtin_int
;
16232 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16233 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16234 byte_stride_prop
, bit_stride
);
16235 return set_die_type (die
, type
, cu
);
16238 std::vector
<struct type
*> range_types
;
16239 child_die
= die
->child
;
16240 while (child_die
&& child_die
->tag
)
16242 if (child_die
->tag
== DW_TAG_subrange_type
)
16244 struct type
*child_type
= read_type_die (child_die
, cu
);
16246 if (child_type
!= NULL
)
16248 /* The range type was succesfully read. Save it for the
16249 array type creation. */
16250 range_types
.push_back (child_type
);
16253 child_die
= child_die
->sibling
;
16256 /* Dwarf2 dimensions are output from left to right, create the
16257 necessary array types in backwards order. */
16259 type
= element_type
;
16261 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16265 while (i
< range_types
.size ())
16266 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16267 byte_stride_prop
, bit_stride
);
16271 size_t ndim
= range_types
.size ();
16273 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16274 byte_stride_prop
, bit_stride
);
16277 /* Understand Dwarf2 support for vector types (like they occur on
16278 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16279 array type. This is not part of the Dwarf2/3 standard yet, but a
16280 custom vendor extension. The main difference between a regular
16281 array and the vector variant is that vectors are passed by value
16283 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16284 if (attr
!= nullptr)
16285 make_vector_type (type
);
16287 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16288 implementation may choose to implement triple vectors using this
16290 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16291 if (attr
!= nullptr)
16293 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16294 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16296 complaint (_("DW_AT_byte_size for array type smaller "
16297 "than the total size of elements"));
16300 name
= dwarf2_name (die
, cu
);
16302 type
->set_name (name
);
16304 maybe_set_alignment (cu
, die
, type
);
16306 /* Install the type in the die. */
16307 set_die_type (die
, type
, cu
);
16309 /* set_die_type should be already done. */
16310 set_descriptive_type (type
, die
, cu
);
16315 static enum dwarf_array_dim_ordering
16316 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16318 struct attribute
*attr
;
16320 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16322 if (attr
!= nullptr)
16323 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16325 /* GNU F77 is a special case, as at 08/2004 array type info is the
16326 opposite order to the dwarf2 specification, but data is still
16327 laid out as per normal fortran.
16329 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16330 version checking. */
16332 if (cu
->language
== language_fortran
16333 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16335 return DW_ORD_row_major
;
16338 switch (cu
->language_defn
->la_array_ordering
)
16340 case array_column_major
:
16341 return DW_ORD_col_major
;
16342 case array_row_major
:
16344 return DW_ORD_row_major
;
16348 /* Extract all information from a DW_TAG_set_type DIE and put it in
16349 the DIE's type field. */
16351 static struct type
*
16352 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16354 struct type
*domain_type
, *set_type
;
16355 struct attribute
*attr
;
16357 domain_type
= die_type (die
, cu
);
16359 /* The die_type call above may have already set the type for this DIE. */
16360 set_type
= get_die_type (die
, cu
);
16364 set_type
= create_set_type (NULL
, domain_type
);
16366 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16367 if (attr
!= nullptr)
16368 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16370 maybe_set_alignment (cu
, die
, set_type
);
16372 return set_die_type (die
, set_type
, cu
);
16375 /* A helper for read_common_block that creates a locexpr baton.
16376 SYM is the symbol which we are marking as computed.
16377 COMMON_DIE is the DIE for the common block.
16378 COMMON_LOC is the location expression attribute for the common
16380 MEMBER_LOC is the location expression attribute for the particular
16381 member of the common block that we are processing.
16382 CU is the CU from which the above come. */
16385 mark_common_block_symbol_computed (struct symbol
*sym
,
16386 struct die_info
*common_die
,
16387 struct attribute
*common_loc
,
16388 struct attribute
*member_loc
,
16389 struct dwarf2_cu
*cu
)
16391 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16392 struct objfile
*objfile
= per_objfile
->objfile
;
16393 struct dwarf2_locexpr_baton
*baton
;
16395 unsigned int cu_off
;
16396 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16397 LONGEST offset
= 0;
16399 gdb_assert (common_loc
&& member_loc
);
16400 gdb_assert (common_loc
->form_is_block ());
16401 gdb_assert (member_loc
->form_is_block ()
16402 || member_loc
->form_is_constant ());
16404 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16405 baton
->per_objfile
= per_objfile
;
16406 baton
->per_cu
= cu
->per_cu
;
16407 gdb_assert (baton
->per_cu
);
16409 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16411 if (member_loc
->form_is_constant ())
16413 offset
= member_loc
->constant_value (0);
16414 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16417 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16419 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16422 *ptr
++ = DW_OP_call4
;
16423 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16424 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16427 if (member_loc
->form_is_constant ())
16429 *ptr
++ = DW_OP_addr
;
16430 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16431 ptr
+= cu
->header
.addr_size
;
16435 /* We have to copy the data here, because DW_OP_call4 will only
16436 use a DW_AT_location attribute. */
16437 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16438 ptr
+= DW_BLOCK (member_loc
)->size
;
16441 *ptr
++ = DW_OP_plus
;
16442 gdb_assert (ptr
- baton
->data
== baton
->size
);
16444 SYMBOL_LOCATION_BATON (sym
) = baton
;
16445 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16448 /* Create appropriate locally-scoped variables for all the
16449 DW_TAG_common_block entries. Also create a struct common_block
16450 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16451 is used to separate the common blocks name namespace from regular
16455 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16457 struct attribute
*attr
;
16459 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16460 if (attr
!= nullptr)
16462 /* Support the .debug_loc offsets. */
16463 if (attr
->form_is_block ())
16467 else if (attr
->form_is_section_offset ())
16469 dwarf2_complex_location_expr_complaint ();
16474 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16475 "common block member");
16480 if (die
->child
!= NULL
)
16482 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16483 struct die_info
*child_die
;
16484 size_t n_entries
= 0, size
;
16485 struct common_block
*common_block
;
16486 struct symbol
*sym
;
16488 for (child_die
= die
->child
;
16489 child_die
&& child_die
->tag
;
16490 child_die
= child_die
->sibling
)
16493 size
= (sizeof (struct common_block
)
16494 + (n_entries
- 1) * sizeof (struct symbol
*));
16496 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16498 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16499 common_block
->n_entries
= 0;
16501 for (child_die
= die
->child
;
16502 child_die
&& child_die
->tag
;
16503 child_die
= child_die
->sibling
)
16505 /* Create the symbol in the DW_TAG_common_block block in the current
16507 sym
= new_symbol (child_die
, NULL
, cu
);
16510 struct attribute
*member_loc
;
16512 common_block
->contents
[common_block
->n_entries
++] = sym
;
16514 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16518 /* GDB has handled this for a long time, but it is
16519 not specified by DWARF. It seems to have been
16520 emitted by gfortran at least as recently as:
16521 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16522 complaint (_("Variable in common block has "
16523 "DW_AT_data_member_location "
16524 "- DIE at %s [in module %s]"),
16525 sect_offset_str (child_die
->sect_off
),
16526 objfile_name (objfile
));
16528 if (member_loc
->form_is_section_offset ())
16529 dwarf2_complex_location_expr_complaint ();
16530 else if (member_loc
->form_is_constant ()
16531 || member_loc
->form_is_block ())
16533 if (attr
!= nullptr)
16534 mark_common_block_symbol_computed (sym
, die
, attr
,
16538 dwarf2_complex_location_expr_complaint ();
16543 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16544 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16548 /* Create a type for a C++ namespace. */
16550 static struct type
*
16551 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16553 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16554 const char *previous_prefix
, *name
;
16558 /* For extensions, reuse the type of the original namespace. */
16559 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16561 struct die_info
*ext_die
;
16562 struct dwarf2_cu
*ext_cu
= cu
;
16564 ext_die
= dwarf2_extension (die
, &ext_cu
);
16565 type
= read_type_die (ext_die
, ext_cu
);
16567 /* EXT_CU may not be the same as CU.
16568 Ensure TYPE is recorded with CU in die_type_hash. */
16569 return set_die_type (die
, type
, cu
);
16572 name
= namespace_name (die
, &is_anonymous
, cu
);
16574 /* Now build the name of the current namespace. */
16576 previous_prefix
= determine_prefix (die
, cu
);
16577 if (previous_prefix
[0] != '\0')
16578 name
= typename_concat (&objfile
->objfile_obstack
,
16579 previous_prefix
, name
, 0, cu
);
16581 /* Create the type. */
16582 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16584 return set_die_type (die
, type
, cu
);
16587 /* Read a namespace scope. */
16590 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16592 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16595 /* Add a symbol associated to this if we haven't seen the namespace
16596 before. Also, add a using directive if it's an anonymous
16599 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16603 type
= read_type_die (die
, cu
);
16604 new_symbol (die
, type
, cu
);
16606 namespace_name (die
, &is_anonymous
, cu
);
16609 const char *previous_prefix
= determine_prefix (die
, cu
);
16611 std::vector
<const char *> excludes
;
16612 add_using_directive (using_directives (cu
),
16613 previous_prefix
, type
->name (), NULL
,
16614 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16618 if (die
->child
!= NULL
)
16620 struct die_info
*child_die
= die
->child
;
16622 while (child_die
&& child_die
->tag
)
16624 process_die (child_die
, cu
);
16625 child_die
= child_die
->sibling
;
16630 /* Read a Fortran module as type. This DIE can be only a declaration used for
16631 imported module. Still we need that type as local Fortran "use ... only"
16632 declaration imports depend on the created type in determine_prefix. */
16634 static struct type
*
16635 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16637 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16638 const char *module_name
;
16641 module_name
= dwarf2_name (die
, cu
);
16642 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16644 return set_die_type (die
, type
, cu
);
16647 /* Read a Fortran module. */
16650 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16652 struct die_info
*child_die
= die
->child
;
16655 type
= read_type_die (die
, cu
);
16656 new_symbol (die
, type
, cu
);
16658 while (child_die
&& child_die
->tag
)
16660 process_die (child_die
, cu
);
16661 child_die
= child_die
->sibling
;
16665 /* Return the name of the namespace represented by DIE. Set
16666 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16669 static const char *
16670 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16672 struct die_info
*current_die
;
16673 const char *name
= NULL
;
16675 /* Loop through the extensions until we find a name. */
16677 for (current_die
= die
;
16678 current_die
!= NULL
;
16679 current_die
= dwarf2_extension (die
, &cu
))
16681 /* We don't use dwarf2_name here so that we can detect the absence
16682 of a name -> anonymous namespace. */
16683 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16689 /* Is it an anonymous namespace? */
16691 *is_anonymous
= (name
== NULL
);
16693 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16698 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16699 the user defined type vector. */
16701 static struct type
*
16702 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16704 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16705 struct comp_unit_head
*cu_header
= &cu
->header
;
16707 struct attribute
*attr_byte_size
;
16708 struct attribute
*attr_address_class
;
16709 int byte_size
, addr_class
;
16710 struct type
*target_type
;
16712 target_type
= die_type (die
, cu
);
16714 /* The die_type call above may have already set the type for this DIE. */
16715 type
= get_die_type (die
, cu
);
16719 type
= lookup_pointer_type (target_type
);
16721 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16722 if (attr_byte_size
)
16723 byte_size
= DW_UNSND (attr_byte_size
);
16725 byte_size
= cu_header
->addr_size
;
16727 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16728 if (attr_address_class
)
16729 addr_class
= DW_UNSND (attr_address_class
);
16731 addr_class
= DW_ADDR_none
;
16733 ULONGEST alignment
= get_alignment (cu
, die
);
16735 /* If the pointer size, alignment, or address class is different
16736 than the default, create a type variant marked as such and set
16737 the length accordingly. */
16738 if (TYPE_LENGTH (type
) != byte_size
16739 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16740 && alignment
!= TYPE_RAW_ALIGN (type
))
16741 || addr_class
!= DW_ADDR_none
)
16743 if (gdbarch_address_class_type_flags_p (gdbarch
))
16747 type_flags
= gdbarch_address_class_type_flags
16748 (gdbarch
, byte_size
, addr_class
);
16749 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16751 type
= make_type_with_address_space (type
, type_flags
);
16753 else if (TYPE_LENGTH (type
) != byte_size
)
16755 complaint (_("invalid pointer size %d"), byte_size
);
16757 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16759 complaint (_("Invalid DW_AT_alignment"
16760 " - DIE at %s [in module %s]"),
16761 sect_offset_str (die
->sect_off
),
16762 objfile_name (cu
->per_objfile
->objfile
));
16766 /* Should we also complain about unhandled address classes? */
16770 TYPE_LENGTH (type
) = byte_size
;
16771 set_type_align (type
, alignment
);
16772 return set_die_type (die
, type
, cu
);
16775 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16776 the user defined type vector. */
16778 static struct type
*
16779 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16782 struct type
*to_type
;
16783 struct type
*domain
;
16785 to_type
= die_type (die
, cu
);
16786 domain
= die_containing_type (die
, cu
);
16788 /* The calls above may have already set the type for this DIE. */
16789 type
= get_die_type (die
, cu
);
16793 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16794 type
= lookup_methodptr_type (to_type
);
16795 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16797 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16799 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16800 to_type
->fields (), to_type
->num_fields (),
16801 TYPE_VARARGS (to_type
));
16802 type
= lookup_methodptr_type (new_type
);
16805 type
= lookup_memberptr_type (to_type
, domain
);
16807 return set_die_type (die
, type
, cu
);
16810 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16811 the user defined type vector. */
16813 static struct type
*
16814 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16815 enum type_code refcode
)
16817 struct comp_unit_head
*cu_header
= &cu
->header
;
16818 struct type
*type
, *target_type
;
16819 struct attribute
*attr
;
16821 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16823 target_type
= die_type (die
, cu
);
16825 /* The die_type call above may have already set the type for this DIE. */
16826 type
= get_die_type (die
, cu
);
16830 type
= lookup_reference_type (target_type
, refcode
);
16831 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16832 if (attr
!= nullptr)
16834 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16838 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16840 maybe_set_alignment (cu
, die
, type
);
16841 return set_die_type (die
, type
, cu
);
16844 /* Add the given cv-qualifiers to the element type of the array. GCC
16845 outputs DWARF type qualifiers that apply to an array, not the
16846 element type. But GDB relies on the array element type to carry
16847 the cv-qualifiers. This mimics section 6.7.3 of the C99
16850 static struct type
*
16851 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16852 struct type
*base_type
, int cnst
, int voltl
)
16854 struct type
*el_type
, *inner_array
;
16856 base_type
= copy_type (base_type
);
16857 inner_array
= base_type
;
16859 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16861 TYPE_TARGET_TYPE (inner_array
) =
16862 copy_type (TYPE_TARGET_TYPE (inner_array
));
16863 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16866 el_type
= TYPE_TARGET_TYPE (inner_array
);
16867 cnst
|= TYPE_CONST (el_type
);
16868 voltl
|= TYPE_VOLATILE (el_type
);
16869 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16871 return set_die_type (die
, base_type
, cu
);
16874 static struct type
*
16875 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16877 struct type
*base_type
, *cv_type
;
16879 base_type
= die_type (die
, cu
);
16881 /* The die_type call above may have already set the type for this DIE. */
16882 cv_type
= get_die_type (die
, cu
);
16886 /* In case the const qualifier is applied to an array type, the element type
16887 is so qualified, not the array type (section 6.7.3 of C99). */
16888 if (base_type
->code () == TYPE_CODE_ARRAY
)
16889 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16891 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16892 return set_die_type (die
, cv_type
, cu
);
16895 static struct type
*
16896 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16898 struct type
*base_type
, *cv_type
;
16900 base_type
= die_type (die
, cu
);
16902 /* The die_type call above may have already set the type for this DIE. */
16903 cv_type
= get_die_type (die
, cu
);
16907 /* In case the volatile qualifier is applied to an array type, the
16908 element type is so qualified, not the array type (section 6.7.3
16910 if (base_type
->code () == TYPE_CODE_ARRAY
)
16911 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16913 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16914 return set_die_type (die
, cv_type
, cu
);
16917 /* Handle DW_TAG_restrict_type. */
16919 static struct type
*
16920 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16922 struct type
*base_type
, *cv_type
;
16924 base_type
= die_type (die
, cu
);
16926 /* The die_type call above may have already set the type for this DIE. */
16927 cv_type
= get_die_type (die
, cu
);
16931 cv_type
= make_restrict_type (base_type
);
16932 return set_die_type (die
, cv_type
, cu
);
16935 /* Handle DW_TAG_atomic_type. */
16937 static struct type
*
16938 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16940 struct type
*base_type
, *cv_type
;
16942 base_type
= die_type (die
, cu
);
16944 /* The die_type call above may have already set the type for this DIE. */
16945 cv_type
= get_die_type (die
, cu
);
16949 cv_type
= make_atomic_type (base_type
);
16950 return set_die_type (die
, cv_type
, cu
);
16953 /* Extract all information from a DW_TAG_string_type DIE and add to
16954 the user defined type vector. It isn't really a user defined type,
16955 but it behaves like one, with other DIE's using an AT_user_def_type
16956 attribute to reference it. */
16958 static struct type
*
16959 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16961 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16962 struct gdbarch
*gdbarch
= objfile
->arch ();
16963 struct type
*type
, *range_type
, *index_type
, *char_type
;
16964 struct attribute
*attr
;
16965 struct dynamic_prop prop
;
16966 bool length_is_constant
= true;
16969 /* There are a couple of places where bit sizes might be made use of
16970 when parsing a DW_TAG_string_type, however, no producer that we know
16971 of make use of these. Handling bit sizes that are a multiple of the
16972 byte size is easy enough, but what about other bit sizes? Lets deal
16973 with that problem when we have to. Warn about these attributes being
16974 unsupported, then parse the type and ignore them like we always
16976 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16977 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16979 static bool warning_printed
= false;
16980 if (!warning_printed
)
16982 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16983 "currently supported on DW_TAG_string_type."));
16984 warning_printed
= true;
16988 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16989 if (attr
!= nullptr && !attr
->form_is_constant ())
16991 /* The string length describes the location at which the length of
16992 the string can be found. The size of the length field can be
16993 specified with one of the attributes below. */
16994 struct type
*prop_type
;
16995 struct attribute
*len
16996 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16997 if (len
== nullptr)
16998 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16999 if (len
!= nullptr && len
->form_is_constant ())
17001 /* Pass 0 as the default as we know this attribute is constant
17002 and the default value will not be returned. */
17003 LONGEST sz
= len
->constant_value (0);
17004 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17008 /* If the size is not specified then we assume it is the size of
17009 an address on this target. */
17010 prop_type
= cu
->addr_sized_int_type (true);
17013 /* Convert the attribute into a dynamic property. */
17014 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17017 length_is_constant
= false;
17019 else if (attr
!= nullptr)
17021 /* This DW_AT_string_length just contains the length with no
17022 indirection. There's no need to create a dynamic property in this
17023 case. Pass 0 for the default value as we know it will not be
17024 returned in this case. */
17025 length
= attr
->constant_value (0);
17027 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17029 /* We don't currently support non-constant byte sizes for strings. */
17030 length
= attr
->constant_value (1);
17034 /* Use 1 as a fallback length if we have nothing else. */
17038 index_type
= objfile_type (objfile
)->builtin_int
;
17039 if (length_is_constant
)
17040 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17043 struct dynamic_prop low_bound
;
17045 low_bound
.kind
= PROP_CONST
;
17046 low_bound
.data
.const_val
= 1;
17047 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17049 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17050 type
= create_string_type (NULL
, char_type
, range_type
);
17052 return set_die_type (die
, type
, cu
);
17055 /* Assuming that DIE corresponds to a function, returns nonzero
17056 if the function is prototyped. */
17059 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17061 struct attribute
*attr
;
17063 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17064 if (attr
&& (DW_UNSND (attr
) != 0))
17067 /* The DWARF standard implies that the DW_AT_prototyped attribute
17068 is only meaningful for C, but the concept also extends to other
17069 languages that allow unprototyped functions (Eg: Objective C).
17070 For all other languages, assume that functions are always
17072 if (cu
->language
!= language_c
17073 && cu
->language
!= language_objc
17074 && cu
->language
!= language_opencl
)
17077 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17078 prototyped and unprototyped functions; default to prototyped,
17079 since that is more common in modern code (and RealView warns
17080 about unprototyped functions). */
17081 if (producer_is_realview (cu
->producer
))
17087 /* Handle DIES due to C code like:
17091 int (*funcp)(int a, long l);
17095 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17097 static struct type
*
17098 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17100 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17101 struct type
*type
; /* Type that this function returns. */
17102 struct type
*ftype
; /* Function that returns above type. */
17103 struct attribute
*attr
;
17105 type
= die_type (die
, cu
);
17107 /* The die_type call above may have already set the type for this DIE. */
17108 ftype
= get_die_type (die
, cu
);
17112 ftype
= lookup_function_type (type
);
17114 if (prototyped_function_p (die
, cu
))
17115 TYPE_PROTOTYPED (ftype
) = 1;
17117 /* Store the calling convention in the type if it's available in
17118 the subroutine die. Otherwise set the calling convention to
17119 the default value DW_CC_normal. */
17120 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17121 if (attr
!= nullptr
17122 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17123 TYPE_CALLING_CONVENTION (ftype
)
17124 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17125 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17126 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17128 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17130 /* Record whether the function returns normally to its caller or not
17131 if the DWARF producer set that information. */
17132 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17133 if (attr
&& (DW_UNSND (attr
) != 0))
17134 TYPE_NO_RETURN (ftype
) = 1;
17136 /* We need to add the subroutine type to the die immediately so
17137 we don't infinitely recurse when dealing with parameters
17138 declared as the same subroutine type. */
17139 set_die_type (die
, ftype
, cu
);
17141 if (die
->child
!= NULL
)
17143 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17144 struct die_info
*child_die
;
17145 int nparams
, iparams
;
17147 /* Count the number of parameters.
17148 FIXME: GDB currently ignores vararg functions, but knows about
17149 vararg member functions. */
17151 child_die
= die
->child
;
17152 while (child_die
&& child_die
->tag
)
17154 if (child_die
->tag
== DW_TAG_formal_parameter
)
17156 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17157 TYPE_VARARGS (ftype
) = 1;
17158 child_die
= child_die
->sibling
;
17161 /* Allocate storage for parameters and fill them in. */
17162 ftype
->set_num_fields (nparams
);
17164 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17166 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17167 even if we error out during the parameters reading below. */
17168 for (iparams
= 0; iparams
< nparams
; iparams
++)
17169 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17172 child_die
= die
->child
;
17173 while (child_die
&& child_die
->tag
)
17175 if (child_die
->tag
== DW_TAG_formal_parameter
)
17177 struct type
*arg_type
;
17179 /* DWARF version 2 has no clean way to discern C++
17180 static and non-static member functions. G++ helps
17181 GDB by marking the first parameter for non-static
17182 member functions (which is the this pointer) as
17183 artificial. We pass this information to
17184 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17186 DWARF version 3 added DW_AT_object_pointer, which GCC
17187 4.5 does not yet generate. */
17188 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17189 if (attr
!= nullptr)
17190 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17192 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17193 arg_type
= die_type (child_die
, cu
);
17195 /* RealView does not mark THIS as const, which the testsuite
17196 expects. GCC marks THIS as const in method definitions,
17197 but not in the class specifications (GCC PR 43053). */
17198 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17199 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17202 struct dwarf2_cu
*arg_cu
= cu
;
17203 const char *name
= dwarf2_name (child_die
, cu
);
17205 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17206 if (attr
!= nullptr)
17208 /* If the compiler emits this, use it. */
17209 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17212 else if (name
&& strcmp (name
, "this") == 0)
17213 /* Function definitions will have the argument names. */
17215 else if (name
== NULL
&& iparams
== 0)
17216 /* Declarations may not have the names, so like
17217 elsewhere in GDB, assume an artificial first
17218 argument is "this". */
17222 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17226 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17229 child_die
= child_die
->sibling
;
17236 static struct type
*
17237 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17239 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17240 const char *name
= NULL
;
17241 struct type
*this_type
, *target_type
;
17243 name
= dwarf2_full_name (NULL
, die
, cu
);
17244 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17245 TYPE_TARGET_STUB (this_type
) = 1;
17246 set_die_type (die
, this_type
, cu
);
17247 target_type
= die_type (die
, cu
);
17248 if (target_type
!= this_type
)
17249 TYPE_TARGET_TYPE (this_type
) = target_type
;
17252 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17253 spec and cause infinite loops in GDB. */
17254 complaint (_("Self-referential DW_TAG_typedef "
17255 "- DIE at %s [in module %s]"),
17256 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17257 TYPE_TARGET_TYPE (this_type
) = NULL
;
17261 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17262 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17263 Handle these by just returning the target type, rather than
17264 constructing an anonymous typedef type and trying to handle this
17266 set_die_type (die
, target_type
, cu
);
17267 return target_type
;
17272 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17273 (which may be different from NAME) to the architecture back-end to allow
17274 it to guess the correct format if necessary. */
17276 static struct type
*
17277 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17278 const char *name_hint
, enum bfd_endian byte_order
)
17280 struct gdbarch
*gdbarch
= objfile
->arch ();
17281 const struct floatformat
**format
;
17284 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17286 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17288 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17293 /* Allocate an integer type of size BITS and name NAME. */
17295 static struct type
*
17296 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17297 int bits
, int unsigned_p
, const char *name
)
17301 /* Versions of Intel's C Compiler generate an integer type called "void"
17302 instead of using DW_TAG_unspecified_type. This has been seen on
17303 at least versions 14, 17, and 18. */
17304 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17305 && strcmp (name
, "void") == 0)
17306 type
= objfile_type (objfile
)->builtin_void
;
17308 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17313 /* Initialise and return a floating point type of size BITS suitable for
17314 use as a component of a complex number. The NAME_HINT is passed through
17315 when initialising the floating point type and is the name of the complex
17318 As DWARF doesn't currently provide an explicit name for the components
17319 of a complex number, but it can be helpful to have these components
17320 named, we try to select a suitable name based on the size of the
17322 static struct type
*
17323 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17324 struct objfile
*objfile
,
17325 int bits
, const char *name_hint
,
17326 enum bfd_endian byte_order
)
17328 gdbarch
*gdbarch
= objfile
->arch ();
17329 struct type
*tt
= nullptr;
17331 /* Try to find a suitable floating point builtin type of size BITS.
17332 We're going to use the name of this type as the name for the complex
17333 target type that we are about to create. */
17334 switch (cu
->language
)
17336 case language_fortran
:
17340 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17343 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17345 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17347 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17355 tt
= builtin_type (gdbarch
)->builtin_float
;
17358 tt
= builtin_type (gdbarch
)->builtin_double
;
17360 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17362 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17368 /* If the type we found doesn't match the size we were looking for, then
17369 pretend we didn't find a type at all, the complex target type we
17370 create will then be nameless. */
17371 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17374 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17375 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17378 /* Find a representation of a given base type and install
17379 it in the TYPE field of the die. */
17381 static struct type
*
17382 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17384 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17386 struct attribute
*attr
;
17387 int encoding
= 0, bits
= 0;
17391 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17392 if (attr
!= nullptr)
17393 encoding
= DW_UNSND (attr
);
17394 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17395 if (attr
!= nullptr)
17396 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17397 name
= dwarf2_name (die
, cu
);
17399 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17401 arch
= objfile
->arch ();
17402 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17404 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17407 int endianity
= DW_UNSND (attr
);
17412 byte_order
= BFD_ENDIAN_BIG
;
17414 case DW_END_little
:
17415 byte_order
= BFD_ENDIAN_LITTLE
;
17418 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17425 case DW_ATE_address
:
17426 /* Turn DW_ATE_address into a void * pointer. */
17427 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17428 type
= init_pointer_type (objfile
, bits
, name
, type
);
17430 case DW_ATE_boolean
:
17431 type
= init_boolean_type (objfile
, bits
, 1, name
);
17433 case DW_ATE_complex_float
:
17434 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17436 if (type
->code () == TYPE_CODE_ERROR
)
17438 if (name
== nullptr)
17440 struct obstack
*obstack
17441 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17442 name
= obconcat (obstack
, "_Complex ", type
->name (),
17445 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17448 type
= init_complex_type (name
, type
);
17450 case DW_ATE_decimal_float
:
17451 type
= init_decfloat_type (objfile
, bits
, name
);
17454 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17456 case DW_ATE_signed
:
17457 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17459 case DW_ATE_unsigned
:
17460 if (cu
->language
== language_fortran
17462 && startswith (name
, "character("))
17463 type
= init_character_type (objfile
, bits
, 1, name
);
17465 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17467 case DW_ATE_signed_char
:
17468 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17469 || cu
->language
== language_pascal
17470 || cu
->language
== language_fortran
)
17471 type
= init_character_type (objfile
, bits
, 0, name
);
17473 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17475 case DW_ATE_unsigned_char
:
17476 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17477 || cu
->language
== language_pascal
17478 || cu
->language
== language_fortran
17479 || cu
->language
== language_rust
)
17480 type
= init_character_type (objfile
, bits
, 1, name
);
17482 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17487 type
= builtin_type (arch
)->builtin_char16
;
17488 else if (bits
== 32)
17489 type
= builtin_type (arch
)->builtin_char32
;
17492 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17494 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17496 return set_die_type (die
, type
, cu
);
17501 complaint (_("unsupported DW_AT_encoding: '%s'"),
17502 dwarf_type_encoding_name (encoding
));
17503 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17507 if (name
&& strcmp (name
, "char") == 0)
17508 TYPE_NOSIGN (type
) = 1;
17510 maybe_set_alignment (cu
, die
, type
);
17512 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17514 return set_die_type (die
, type
, cu
);
17517 /* Parse dwarf attribute if it's a block, reference or constant and put the
17518 resulting value of the attribute into struct bound_prop.
17519 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17522 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17523 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17524 struct type
*default_type
)
17526 struct dwarf2_property_baton
*baton
;
17527 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17528 struct objfile
*objfile
= per_objfile
->objfile
;
17529 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17531 gdb_assert (default_type
!= NULL
);
17533 if (attr
== NULL
|| prop
== NULL
)
17536 if (attr
->form_is_block ())
17538 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17539 baton
->property_type
= default_type
;
17540 baton
->locexpr
.per_cu
= cu
->per_cu
;
17541 baton
->locexpr
.per_objfile
= per_objfile
;
17542 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17543 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17544 switch (attr
->name
)
17546 case DW_AT_string_length
:
17547 baton
->locexpr
.is_reference
= true;
17550 baton
->locexpr
.is_reference
= false;
17553 prop
->data
.baton
= baton
;
17554 prop
->kind
= PROP_LOCEXPR
;
17555 gdb_assert (prop
->data
.baton
!= NULL
);
17557 else if (attr
->form_is_ref ())
17559 struct dwarf2_cu
*target_cu
= cu
;
17560 struct die_info
*target_die
;
17561 struct attribute
*target_attr
;
17563 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17564 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17565 if (target_attr
== NULL
)
17566 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17568 if (target_attr
== NULL
)
17571 switch (target_attr
->name
)
17573 case DW_AT_location
:
17574 if (target_attr
->form_is_section_offset ())
17576 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17577 baton
->property_type
= die_type (target_die
, target_cu
);
17578 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17579 prop
->data
.baton
= baton
;
17580 prop
->kind
= PROP_LOCLIST
;
17581 gdb_assert (prop
->data
.baton
!= NULL
);
17583 else if (target_attr
->form_is_block ())
17585 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17586 baton
->property_type
= die_type (target_die
, target_cu
);
17587 baton
->locexpr
.per_cu
= cu
->per_cu
;
17588 baton
->locexpr
.per_objfile
= per_objfile
;
17589 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17590 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17591 baton
->locexpr
.is_reference
= true;
17592 prop
->data
.baton
= baton
;
17593 prop
->kind
= PROP_LOCEXPR
;
17594 gdb_assert (prop
->data
.baton
!= NULL
);
17598 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17599 "dynamic property");
17603 case DW_AT_data_member_location
:
17607 if (!handle_data_member_location (target_die
, target_cu
,
17611 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17612 baton
->property_type
= read_type_die (target_die
->parent
,
17614 baton
->offset_info
.offset
= offset
;
17615 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17616 prop
->data
.baton
= baton
;
17617 prop
->kind
= PROP_ADDR_OFFSET
;
17622 else if (attr
->form_is_constant ())
17624 prop
->data
.const_val
= attr
->constant_value (0);
17625 prop
->kind
= PROP_CONST
;
17629 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17630 dwarf2_name (die
, cu
));
17640 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17642 struct type
*int_type
;
17644 /* Helper macro to examine the various builtin types. */
17645 #define TRY_TYPE(F) \
17646 int_type = (unsigned_p \
17647 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17648 : objfile_type (objfile)->builtin_ ## F); \
17649 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17656 TRY_TYPE (long_long
);
17660 gdb_assert_not_reached ("unable to find suitable integer type");
17666 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17668 int addr_size
= this->per_cu
->addr_size ();
17669 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17672 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17673 present (which is valid) then compute the default type based on the
17674 compilation units address size. */
17676 static struct type
*
17677 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17679 struct type
*index_type
= die_type (die
, cu
);
17681 /* Dwarf-2 specifications explicitly allows to create subrange types
17682 without specifying a base type.
17683 In that case, the base type must be set to the type of
17684 the lower bound, upper bound or count, in that order, if any of these
17685 three attributes references an object that has a type.
17686 If no base type is found, the Dwarf-2 specifications say that
17687 a signed integer type of size equal to the size of an address should
17689 For the following C code: `extern char gdb_int [];'
17690 GCC produces an empty range DIE.
17691 FIXME: muller/2010-05-28: Possible references to object for low bound,
17692 high bound or count are not yet handled by this code. */
17693 if (index_type
->code () == TYPE_CODE_VOID
)
17694 index_type
= cu
->addr_sized_int_type (false);
17699 /* Read the given DW_AT_subrange DIE. */
17701 static struct type
*
17702 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17704 struct type
*base_type
, *orig_base_type
;
17705 struct type
*range_type
;
17706 struct attribute
*attr
;
17707 struct dynamic_prop low
, high
;
17708 int low_default_is_valid
;
17709 int high_bound_is_count
= 0;
17711 ULONGEST negative_mask
;
17713 orig_base_type
= read_subrange_index_type (die
, cu
);
17715 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17716 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17717 creating the range type, but we use the result of check_typedef
17718 when examining properties of the type. */
17719 base_type
= check_typedef (orig_base_type
);
17721 /* The die_type call above may have already set the type for this DIE. */
17722 range_type
= get_die_type (die
, cu
);
17726 low
.kind
= PROP_CONST
;
17727 high
.kind
= PROP_CONST
;
17728 high
.data
.const_val
= 0;
17730 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17731 omitting DW_AT_lower_bound. */
17732 switch (cu
->language
)
17735 case language_cplus
:
17736 low
.data
.const_val
= 0;
17737 low_default_is_valid
= 1;
17739 case language_fortran
:
17740 low
.data
.const_val
= 1;
17741 low_default_is_valid
= 1;
17744 case language_objc
:
17745 case language_rust
:
17746 low
.data
.const_val
= 0;
17747 low_default_is_valid
= (cu
->header
.version
>= 4);
17751 case language_pascal
:
17752 low
.data
.const_val
= 1;
17753 low_default_is_valid
= (cu
->header
.version
>= 4);
17756 low
.data
.const_val
= 0;
17757 low_default_is_valid
= 0;
17761 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17762 if (attr
!= nullptr)
17763 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17764 else if (!low_default_is_valid
)
17765 complaint (_("Missing DW_AT_lower_bound "
17766 "- DIE at %s [in module %s]"),
17767 sect_offset_str (die
->sect_off
),
17768 objfile_name (cu
->per_objfile
->objfile
));
17770 struct attribute
*attr_ub
, *attr_count
;
17771 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17772 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17774 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17775 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17777 /* If bounds are constant do the final calculation here. */
17778 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17779 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17781 high_bound_is_count
= 1;
17785 if (attr_ub
!= NULL
)
17786 complaint (_("Unresolved DW_AT_upper_bound "
17787 "- DIE at %s [in module %s]"),
17788 sect_offset_str (die
->sect_off
),
17789 objfile_name (cu
->per_objfile
->objfile
));
17790 if (attr_count
!= NULL
)
17791 complaint (_("Unresolved DW_AT_count "
17792 "- DIE at %s [in module %s]"),
17793 sect_offset_str (die
->sect_off
),
17794 objfile_name (cu
->per_objfile
->objfile
));
17799 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17800 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17801 bias
= bias_attr
->constant_value (0);
17803 /* Normally, the DWARF producers are expected to use a signed
17804 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17805 But this is unfortunately not always the case, as witnessed
17806 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17807 is used instead. To work around that ambiguity, we treat
17808 the bounds as signed, and thus sign-extend their values, when
17809 the base type is signed. */
17811 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17812 if (low
.kind
== PROP_CONST
17813 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17814 low
.data
.const_val
|= negative_mask
;
17815 if (high
.kind
== PROP_CONST
17816 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17817 high
.data
.const_val
|= negative_mask
;
17819 /* Check for bit and byte strides. */
17820 struct dynamic_prop byte_stride_prop
;
17821 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17822 if (attr_byte_stride
!= nullptr)
17824 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17825 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17829 struct dynamic_prop bit_stride_prop
;
17830 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17831 if (attr_bit_stride
!= nullptr)
17833 /* It only makes sense to have either a bit or byte stride. */
17834 if (attr_byte_stride
!= nullptr)
17836 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17837 "- DIE at %s [in module %s]"),
17838 sect_offset_str (die
->sect_off
),
17839 objfile_name (cu
->per_objfile
->objfile
));
17840 attr_bit_stride
= nullptr;
17844 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17845 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17850 if (attr_byte_stride
!= nullptr
17851 || attr_bit_stride
!= nullptr)
17853 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17854 struct dynamic_prop
*stride
17855 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17858 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17859 &high
, bias
, stride
, byte_stride_p
);
17862 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17864 if (high_bound_is_count
)
17865 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17867 /* Ada expects an empty array on no boundary attributes. */
17868 if (attr
== NULL
&& cu
->language
!= language_ada
)
17869 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17871 name
= dwarf2_name (die
, cu
);
17873 range_type
->set_name (name
);
17875 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17876 if (attr
!= nullptr)
17877 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17879 maybe_set_alignment (cu
, die
, range_type
);
17881 set_die_type (die
, range_type
, cu
);
17883 /* set_die_type should be already done. */
17884 set_descriptive_type (range_type
, die
, cu
);
17889 static struct type
*
17890 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17894 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17895 type
->set_name (dwarf2_name (die
, cu
));
17897 /* In Ada, an unspecified type is typically used when the description
17898 of the type is deferred to a different unit. When encountering
17899 such a type, we treat it as a stub, and try to resolve it later on,
17901 if (cu
->language
== language_ada
)
17902 TYPE_STUB (type
) = 1;
17904 return set_die_type (die
, type
, cu
);
17907 /* Read a single die and all its descendents. Set the die's sibling
17908 field to NULL; set other fields in the die correctly, and set all
17909 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17910 location of the info_ptr after reading all of those dies. PARENT
17911 is the parent of the die in question. */
17913 static struct die_info
*
17914 read_die_and_children (const struct die_reader_specs
*reader
,
17915 const gdb_byte
*info_ptr
,
17916 const gdb_byte
**new_info_ptr
,
17917 struct die_info
*parent
)
17919 struct die_info
*die
;
17920 const gdb_byte
*cur_ptr
;
17922 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17925 *new_info_ptr
= cur_ptr
;
17928 store_in_ref_table (die
, reader
->cu
);
17930 if (die
->has_children
)
17931 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17935 *new_info_ptr
= cur_ptr
;
17938 die
->sibling
= NULL
;
17939 die
->parent
= parent
;
17943 /* Read a die, all of its descendents, and all of its siblings; set
17944 all of the fields of all of the dies correctly. Arguments are as
17945 in read_die_and_children. */
17947 static struct die_info
*
17948 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17949 const gdb_byte
*info_ptr
,
17950 const gdb_byte
**new_info_ptr
,
17951 struct die_info
*parent
)
17953 struct die_info
*first_die
, *last_sibling
;
17954 const gdb_byte
*cur_ptr
;
17956 cur_ptr
= info_ptr
;
17957 first_die
= last_sibling
= NULL
;
17961 struct die_info
*die
17962 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17966 *new_info_ptr
= cur_ptr
;
17973 last_sibling
->sibling
= die
;
17975 last_sibling
= die
;
17979 /* Read a die, all of its descendents, and all of its siblings; set
17980 all of the fields of all of the dies correctly. Arguments are as
17981 in read_die_and_children.
17982 This the main entry point for reading a DIE and all its children. */
17984 static struct die_info
*
17985 read_die_and_siblings (const struct die_reader_specs
*reader
,
17986 const gdb_byte
*info_ptr
,
17987 const gdb_byte
**new_info_ptr
,
17988 struct die_info
*parent
)
17990 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17991 new_info_ptr
, parent
);
17993 if (dwarf_die_debug
)
17995 fprintf_unfiltered (gdb_stdlog
,
17996 "Read die from %s@0x%x of %s:\n",
17997 reader
->die_section
->get_name (),
17998 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17999 bfd_get_filename (reader
->abfd
));
18000 dump_die (die
, dwarf_die_debug
);
18006 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18008 The caller is responsible for filling in the extra attributes
18009 and updating (*DIEP)->num_attrs.
18010 Set DIEP to point to a newly allocated die with its information,
18011 except for its child, sibling, and parent fields. */
18013 static const gdb_byte
*
18014 read_full_die_1 (const struct die_reader_specs
*reader
,
18015 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18016 int num_extra_attrs
)
18018 unsigned int abbrev_number
, bytes_read
, i
;
18019 struct abbrev_info
*abbrev
;
18020 struct die_info
*die
;
18021 struct dwarf2_cu
*cu
= reader
->cu
;
18022 bfd
*abfd
= reader
->abfd
;
18024 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18025 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18026 info_ptr
+= bytes_read
;
18027 if (!abbrev_number
)
18033 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18035 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18037 bfd_get_filename (abfd
));
18039 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18040 die
->sect_off
= sect_off
;
18041 die
->tag
= abbrev
->tag
;
18042 die
->abbrev
= abbrev_number
;
18043 die
->has_children
= abbrev
->has_children
;
18045 /* Make the result usable.
18046 The caller needs to update num_attrs after adding the extra
18048 die
->num_attrs
= abbrev
->num_attrs
;
18050 std::vector
<int> indexes_that_need_reprocess
;
18051 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18053 bool need_reprocess
;
18055 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18056 info_ptr
, &need_reprocess
);
18057 if (need_reprocess
)
18058 indexes_that_need_reprocess
.push_back (i
);
18061 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18062 if (attr
!= nullptr)
18063 cu
->str_offsets_base
= DW_UNSND (attr
);
18065 attr
= die
->attr (DW_AT_loclists_base
);
18066 if (attr
!= nullptr)
18067 cu
->loclist_base
= DW_UNSND (attr
);
18069 auto maybe_addr_base
= die
->addr_base ();
18070 if (maybe_addr_base
.has_value ())
18071 cu
->addr_base
= *maybe_addr_base
;
18072 for (int index
: indexes_that_need_reprocess
)
18073 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18078 /* Read a die and all its attributes.
18079 Set DIEP to point to a newly allocated die with its information,
18080 except for its child, sibling, and parent fields. */
18082 static const gdb_byte
*
18083 read_full_die (const struct die_reader_specs
*reader
,
18084 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18086 const gdb_byte
*result
;
18088 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18090 if (dwarf_die_debug
)
18092 fprintf_unfiltered (gdb_stdlog
,
18093 "Read die from %s@0x%x of %s:\n",
18094 reader
->die_section
->get_name (),
18095 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18096 bfd_get_filename (reader
->abfd
));
18097 dump_die (*diep
, dwarf_die_debug
);
18104 /* Returns nonzero if TAG represents a type that we might generate a partial
18108 is_type_tag_for_partial (int tag
)
18113 /* Some types that would be reasonable to generate partial symbols for,
18114 that we don't at present. */
18115 case DW_TAG_array_type
:
18116 case DW_TAG_file_type
:
18117 case DW_TAG_ptr_to_member_type
:
18118 case DW_TAG_set_type
:
18119 case DW_TAG_string_type
:
18120 case DW_TAG_subroutine_type
:
18122 case DW_TAG_base_type
:
18123 case DW_TAG_class_type
:
18124 case DW_TAG_interface_type
:
18125 case DW_TAG_enumeration_type
:
18126 case DW_TAG_structure_type
:
18127 case DW_TAG_subrange_type
:
18128 case DW_TAG_typedef
:
18129 case DW_TAG_union_type
:
18136 /* Load all DIEs that are interesting for partial symbols into memory. */
18138 static struct partial_die_info
*
18139 load_partial_dies (const struct die_reader_specs
*reader
,
18140 const gdb_byte
*info_ptr
, int building_psymtab
)
18142 struct dwarf2_cu
*cu
= reader
->cu
;
18143 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18144 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18145 unsigned int bytes_read
;
18146 unsigned int load_all
= 0;
18147 int nesting_level
= 1;
18152 gdb_assert (cu
->per_cu
!= NULL
);
18153 if (cu
->per_cu
->load_all_dies
)
18157 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18161 &cu
->comp_unit_obstack
,
18162 hashtab_obstack_allocate
,
18163 dummy_obstack_deallocate
);
18167 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18169 /* A NULL abbrev means the end of a series of children. */
18170 if (abbrev
== NULL
)
18172 if (--nesting_level
== 0)
18175 info_ptr
+= bytes_read
;
18176 last_die
= parent_die
;
18177 parent_die
= parent_die
->die_parent
;
18181 /* Check for template arguments. We never save these; if
18182 they're seen, we just mark the parent, and go on our way. */
18183 if (parent_die
!= NULL
18184 && cu
->language
== language_cplus
18185 && (abbrev
->tag
== DW_TAG_template_type_param
18186 || abbrev
->tag
== DW_TAG_template_value_param
))
18188 parent_die
->has_template_arguments
= 1;
18192 /* We don't need a partial DIE for the template argument. */
18193 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18198 /* We only recurse into c++ subprograms looking for template arguments.
18199 Skip their other children. */
18201 && cu
->language
== language_cplus
18202 && parent_die
!= NULL
18203 && parent_die
->tag
== DW_TAG_subprogram
)
18205 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18209 /* Check whether this DIE is interesting enough to save. Normally
18210 we would not be interested in members here, but there may be
18211 later variables referencing them via DW_AT_specification (for
18212 static members). */
18214 && !is_type_tag_for_partial (abbrev
->tag
)
18215 && abbrev
->tag
!= DW_TAG_constant
18216 && abbrev
->tag
!= DW_TAG_enumerator
18217 && abbrev
->tag
!= DW_TAG_subprogram
18218 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18219 && abbrev
->tag
!= DW_TAG_lexical_block
18220 && abbrev
->tag
!= DW_TAG_variable
18221 && abbrev
->tag
!= DW_TAG_namespace
18222 && abbrev
->tag
!= DW_TAG_module
18223 && abbrev
->tag
!= DW_TAG_member
18224 && abbrev
->tag
!= DW_TAG_imported_unit
18225 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18227 /* Otherwise we skip to the next sibling, if any. */
18228 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18232 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18235 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18237 /* This two-pass algorithm for processing partial symbols has a
18238 high cost in cache pressure. Thus, handle some simple cases
18239 here which cover the majority of C partial symbols. DIEs
18240 which neither have specification tags in them, nor could have
18241 specification tags elsewhere pointing at them, can simply be
18242 processed and discarded.
18244 This segment is also optional; scan_partial_symbols and
18245 add_partial_symbol will handle these DIEs if we chain
18246 them in normally. When compilers which do not emit large
18247 quantities of duplicate debug information are more common,
18248 this code can probably be removed. */
18250 /* Any complete simple types at the top level (pretty much all
18251 of them, for a language without namespaces), can be processed
18253 if (parent_die
== NULL
18254 && pdi
.has_specification
== 0
18255 && pdi
.is_declaration
== 0
18256 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18257 || pdi
.tag
== DW_TAG_base_type
18258 || pdi
.tag
== DW_TAG_subrange_type
))
18260 if (building_psymtab
&& pdi
.name
!= NULL
)
18261 add_psymbol_to_list (pdi
.name
, false,
18262 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18263 psymbol_placement::STATIC
,
18264 0, cu
->language
, objfile
);
18265 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18269 /* The exception for DW_TAG_typedef with has_children above is
18270 a workaround of GCC PR debug/47510. In the case of this complaint
18271 type_name_or_error will error on such types later.
18273 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18274 it could not find the child DIEs referenced later, this is checked
18275 above. In correct DWARF DW_TAG_typedef should have no children. */
18277 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18278 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18279 "- DIE at %s [in module %s]"),
18280 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18282 /* If we're at the second level, and we're an enumerator, and
18283 our parent has no specification (meaning possibly lives in a
18284 namespace elsewhere), then we can add the partial symbol now
18285 instead of queueing it. */
18286 if (pdi
.tag
== DW_TAG_enumerator
18287 && parent_die
!= NULL
18288 && parent_die
->die_parent
== NULL
18289 && parent_die
->tag
== DW_TAG_enumeration_type
18290 && parent_die
->has_specification
== 0)
18292 if (pdi
.name
== NULL
)
18293 complaint (_("malformed enumerator DIE ignored"));
18294 else if (building_psymtab
)
18295 add_psymbol_to_list (pdi
.name
, false,
18296 VAR_DOMAIN
, LOC_CONST
, -1,
18297 cu
->language
== language_cplus
18298 ? psymbol_placement::GLOBAL
18299 : psymbol_placement::STATIC
,
18300 0, cu
->language
, objfile
);
18302 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18306 struct partial_die_info
*part_die
18307 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18309 /* We'll save this DIE so link it in. */
18310 part_die
->die_parent
= parent_die
;
18311 part_die
->die_sibling
= NULL
;
18312 part_die
->die_child
= NULL
;
18314 if (last_die
&& last_die
== parent_die
)
18315 last_die
->die_child
= part_die
;
18317 last_die
->die_sibling
= part_die
;
18319 last_die
= part_die
;
18321 if (first_die
== NULL
)
18322 first_die
= part_die
;
18324 /* Maybe add the DIE to the hash table. Not all DIEs that we
18325 find interesting need to be in the hash table, because we
18326 also have the parent/sibling/child chains; only those that we
18327 might refer to by offset later during partial symbol reading.
18329 For now this means things that might have be the target of a
18330 DW_AT_specification, DW_AT_abstract_origin, or
18331 DW_AT_extension. DW_AT_extension will refer only to
18332 namespaces; DW_AT_abstract_origin refers to functions (and
18333 many things under the function DIE, but we do not recurse
18334 into function DIEs during partial symbol reading) and
18335 possibly variables as well; DW_AT_specification refers to
18336 declarations. Declarations ought to have the DW_AT_declaration
18337 flag. It happens that GCC forgets to put it in sometimes, but
18338 only for functions, not for types.
18340 Adding more things than necessary to the hash table is harmless
18341 except for the performance cost. Adding too few will result in
18342 wasted time in find_partial_die, when we reread the compilation
18343 unit with load_all_dies set. */
18346 || abbrev
->tag
== DW_TAG_constant
18347 || abbrev
->tag
== DW_TAG_subprogram
18348 || abbrev
->tag
== DW_TAG_variable
18349 || abbrev
->tag
== DW_TAG_namespace
18350 || part_die
->is_declaration
)
18354 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18355 to_underlying (part_die
->sect_off
),
18360 /* For some DIEs we want to follow their children (if any). For C
18361 we have no reason to follow the children of structures; for other
18362 languages we have to, so that we can get at method physnames
18363 to infer fully qualified class names, for DW_AT_specification,
18364 and for C++ template arguments. For C++, we also look one level
18365 inside functions to find template arguments (if the name of the
18366 function does not already contain the template arguments).
18368 For Ada and Fortran, we need to scan the children of subprograms
18369 and lexical blocks as well because these languages allow the
18370 definition of nested entities that could be interesting for the
18371 debugger, such as nested subprograms for instance. */
18372 if (last_die
->has_children
18374 || last_die
->tag
== DW_TAG_namespace
18375 || last_die
->tag
== DW_TAG_module
18376 || last_die
->tag
== DW_TAG_enumeration_type
18377 || (cu
->language
== language_cplus
18378 && last_die
->tag
== DW_TAG_subprogram
18379 && (last_die
->name
== NULL
18380 || strchr (last_die
->name
, '<') == NULL
))
18381 || (cu
->language
!= language_c
18382 && (last_die
->tag
== DW_TAG_class_type
18383 || last_die
->tag
== DW_TAG_interface_type
18384 || last_die
->tag
== DW_TAG_structure_type
18385 || last_die
->tag
== DW_TAG_union_type
))
18386 || ((cu
->language
== language_ada
18387 || cu
->language
== language_fortran
)
18388 && (last_die
->tag
== DW_TAG_subprogram
18389 || last_die
->tag
== DW_TAG_lexical_block
))))
18392 parent_die
= last_die
;
18396 /* Otherwise we skip to the next sibling, if any. */
18397 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18399 /* Back to the top, do it again. */
18403 partial_die_info::partial_die_info (sect_offset sect_off_
,
18404 struct abbrev_info
*abbrev
)
18405 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18409 /* Read a minimal amount of information into the minimal die structure.
18410 INFO_PTR should point just after the initial uleb128 of a DIE. */
18413 partial_die_info::read (const struct die_reader_specs
*reader
,
18414 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18416 struct dwarf2_cu
*cu
= reader
->cu
;
18417 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18419 int has_low_pc_attr
= 0;
18420 int has_high_pc_attr
= 0;
18421 int high_pc_relative
= 0;
18423 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18426 bool need_reprocess
;
18427 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18428 info_ptr
, &need_reprocess
);
18429 /* String and address offsets that need to do the reprocessing have
18430 already been read at this point, so there is no need to wait until
18431 the loop terminates to do the reprocessing. */
18432 if (need_reprocess
)
18433 read_attribute_reprocess (reader
, &attr
);
18434 /* Store the data if it is of an attribute we want to keep in a
18435 partial symbol table. */
18441 case DW_TAG_compile_unit
:
18442 case DW_TAG_partial_unit
:
18443 case DW_TAG_type_unit
:
18444 /* Compilation units have a DW_AT_name that is a filename, not
18445 a source language identifier. */
18446 case DW_TAG_enumeration_type
:
18447 case DW_TAG_enumerator
:
18448 /* These tags always have simple identifiers already; no need
18449 to canonicalize them. */
18450 name
= DW_STRING (&attr
);
18454 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18457 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18462 case DW_AT_linkage_name
:
18463 case DW_AT_MIPS_linkage_name
:
18464 /* Note that both forms of linkage name might appear. We
18465 assume they will be the same, and we only store the last
18467 linkage_name
= attr
.value_as_string ();
18468 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18469 See https://github.com/rust-lang/rust/issues/32925. */
18470 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18471 && strchr (linkage_name
, '{') != NULL
)
18472 linkage_name
= NULL
;
18475 has_low_pc_attr
= 1;
18476 lowpc
= attr
.value_as_address ();
18478 case DW_AT_high_pc
:
18479 has_high_pc_attr
= 1;
18480 highpc
= attr
.value_as_address ();
18481 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18482 high_pc_relative
= 1;
18484 case DW_AT_location
:
18485 /* Support the .debug_loc offsets. */
18486 if (attr
.form_is_block ())
18488 d
.locdesc
= DW_BLOCK (&attr
);
18490 else if (attr
.form_is_section_offset ())
18492 dwarf2_complex_location_expr_complaint ();
18496 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18497 "partial symbol information");
18500 case DW_AT_external
:
18501 is_external
= DW_UNSND (&attr
);
18503 case DW_AT_declaration
:
18504 is_declaration
= DW_UNSND (&attr
);
18509 case DW_AT_abstract_origin
:
18510 case DW_AT_specification
:
18511 case DW_AT_extension
:
18512 has_specification
= 1;
18513 spec_offset
= attr
.get_ref_die_offset ();
18514 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18515 || cu
->per_cu
->is_dwz
);
18517 case DW_AT_sibling
:
18518 /* Ignore absolute siblings, they might point outside of
18519 the current compile unit. */
18520 if (attr
.form
== DW_FORM_ref_addr
)
18521 complaint (_("ignoring absolute DW_AT_sibling"));
18524 const gdb_byte
*buffer
= reader
->buffer
;
18525 sect_offset off
= attr
.get_ref_die_offset ();
18526 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18528 if (sibling_ptr
< info_ptr
)
18529 complaint (_("DW_AT_sibling points backwards"));
18530 else if (sibling_ptr
> reader
->buffer_end
)
18531 reader
->die_section
->overflow_complaint ();
18533 sibling
= sibling_ptr
;
18536 case DW_AT_byte_size
:
18539 case DW_AT_const_value
:
18540 has_const_value
= 1;
18542 case DW_AT_calling_convention
:
18543 /* DWARF doesn't provide a way to identify a program's source-level
18544 entry point. DW_AT_calling_convention attributes are only meant
18545 to describe functions' calling conventions.
18547 However, because it's a necessary piece of information in
18548 Fortran, and before DWARF 4 DW_CC_program was the only
18549 piece of debugging information whose definition refers to
18550 a 'main program' at all, several compilers marked Fortran
18551 main programs with DW_CC_program --- even when those
18552 functions use the standard calling conventions.
18554 Although DWARF now specifies a way to provide this
18555 information, we support this practice for backward
18557 if (DW_UNSND (&attr
) == DW_CC_program
18558 && cu
->language
== language_fortran
)
18559 main_subprogram
= 1;
18562 if (DW_UNSND (&attr
) == DW_INL_inlined
18563 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18564 may_be_inlined
= 1;
18568 if (tag
== DW_TAG_imported_unit
)
18570 d
.sect_off
= attr
.get_ref_die_offset ();
18571 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18572 || cu
->per_cu
->is_dwz
);
18576 case DW_AT_main_subprogram
:
18577 main_subprogram
= DW_UNSND (&attr
);
18582 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18583 but that requires a full DIE, so instead we just
18585 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18586 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18587 + (need_ranges_base
18591 /* Value of the DW_AT_ranges attribute is the offset in the
18592 .debug_ranges section. */
18593 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18604 /* For Ada, if both the name and the linkage name appear, we prefer
18605 the latter. This lets "catch exception" work better, regardless
18606 of the order in which the name and linkage name were emitted.
18607 Really, though, this is just a workaround for the fact that gdb
18608 doesn't store both the name and the linkage name. */
18609 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18610 name
= linkage_name
;
18612 if (high_pc_relative
)
18615 if (has_low_pc_attr
&& has_high_pc_attr
)
18617 /* When using the GNU linker, .gnu.linkonce. sections are used to
18618 eliminate duplicate copies of functions and vtables and such.
18619 The linker will arbitrarily choose one and discard the others.
18620 The AT_*_pc values for such functions refer to local labels in
18621 these sections. If the section from that file was discarded, the
18622 labels are not in the output, so the relocs get a value of 0.
18623 If this is a discarded function, mark the pc bounds as invalid,
18624 so that GDB will ignore it. */
18625 if (lowpc
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
18627 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18628 struct gdbarch
*gdbarch
= objfile
->arch ();
18630 complaint (_("DW_AT_low_pc %s is zero "
18631 "for DIE at %s [in module %s]"),
18632 paddress (gdbarch
, lowpc
),
18633 sect_offset_str (sect_off
),
18634 objfile_name (objfile
));
18636 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18637 else if (lowpc
>= highpc
)
18639 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18640 struct gdbarch
*gdbarch
= objfile
->arch ();
18642 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18643 "for DIE at %s [in module %s]"),
18644 paddress (gdbarch
, lowpc
),
18645 paddress (gdbarch
, highpc
),
18646 sect_offset_str (sect_off
),
18647 objfile_name (objfile
));
18656 /* Find a cached partial DIE at OFFSET in CU. */
18658 struct partial_die_info
*
18659 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18661 struct partial_die_info
*lookup_die
= NULL
;
18662 struct partial_die_info
part_die (sect_off
);
18664 lookup_die
= ((struct partial_die_info
*)
18665 htab_find_with_hash (partial_dies
, &part_die
,
18666 to_underlying (sect_off
)));
18671 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18672 except in the case of .debug_types DIEs which do not reference
18673 outside their CU (they do however referencing other types via
18674 DW_FORM_ref_sig8). */
18676 static const struct cu_partial_die_info
18677 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18679 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18680 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18681 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18682 struct partial_die_info
*pd
= NULL
;
18684 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18685 && cu
->header
.offset_in_cu_p (sect_off
))
18687 pd
= cu
->find_partial_die (sect_off
);
18690 /* We missed recording what we needed.
18691 Load all dies and try again. */
18692 per_cu
= cu
->per_cu
;
18696 /* TUs don't reference other CUs/TUs (except via type signatures). */
18697 if (cu
->per_cu
->is_debug_types
)
18699 error (_("Dwarf Error: Type Unit at offset %s contains"
18700 " external reference to offset %s [in module %s].\n"),
18701 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18702 bfd_get_filename (objfile
->obfd
));
18704 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18705 dwarf2_per_objfile
);
18707 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18708 load_partial_comp_unit (per_cu
, cu
->per_objfile
);
18710 per_cu
->cu
->last_used
= 0;
18711 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18714 /* If we didn't find it, and not all dies have been loaded,
18715 load them all and try again. */
18717 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18719 per_cu
->load_all_dies
= 1;
18721 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18722 THIS_CU->cu may already be in use. So we can't just free it and
18723 replace its DIEs with the ones we read in. Instead, we leave those
18724 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18725 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18727 load_partial_comp_unit (per_cu
, cu
->per_objfile
);
18729 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18733 internal_error (__FILE__
, __LINE__
,
18734 _("could not find partial DIE %s "
18735 "in cache [from module %s]\n"),
18736 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18737 return { per_cu
->cu
, pd
};
18740 /* See if we can figure out if the class lives in a namespace. We do
18741 this by looking for a member function; its demangled name will
18742 contain namespace info, if there is any. */
18745 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18746 struct dwarf2_cu
*cu
)
18748 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18749 what template types look like, because the demangler
18750 frequently doesn't give the same name as the debug info. We
18751 could fix this by only using the demangled name to get the
18752 prefix (but see comment in read_structure_type). */
18754 struct partial_die_info
*real_pdi
;
18755 struct partial_die_info
*child_pdi
;
18757 /* If this DIE (this DIE's specification, if any) has a parent, then
18758 we should not do this. We'll prepend the parent's fully qualified
18759 name when we create the partial symbol. */
18761 real_pdi
= struct_pdi
;
18762 while (real_pdi
->has_specification
)
18764 auto res
= find_partial_die (real_pdi
->spec_offset
,
18765 real_pdi
->spec_is_dwz
, cu
);
18766 real_pdi
= res
.pdi
;
18770 if (real_pdi
->die_parent
!= NULL
)
18773 for (child_pdi
= struct_pdi
->die_child
;
18775 child_pdi
= child_pdi
->die_sibling
)
18777 if (child_pdi
->tag
== DW_TAG_subprogram
18778 && child_pdi
->linkage_name
!= NULL
)
18780 gdb::unique_xmalloc_ptr
<char> actual_class_name
18781 (language_class_name_from_physname (cu
->language_defn
,
18782 child_pdi
->linkage_name
));
18783 if (actual_class_name
!= NULL
)
18785 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18786 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18793 /* Return true if a DIE with TAG may have the DW_AT_const_value
18797 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18801 case DW_TAG_constant
:
18802 case DW_TAG_enumerator
:
18803 case DW_TAG_formal_parameter
:
18804 case DW_TAG_template_value_param
:
18805 case DW_TAG_variable
:
18813 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18815 /* Once we've fixed up a die, there's no point in doing so again.
18816 This also avoids a memory leak if we were to call
18817 guess_partial_die_structure_name multiple times. */
18821 /* If we found a reference attribute and the DIE has no name, try
18822 to find a name in the referred to DIE. */
18824 if (name
== NULL
&& has_specification
)
18826 struct partial_die_info
*spec_die
;
18828 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18829 spec_die
= res
.pdi
;
18832 spec_die
->fixup (cu
);
18834 if (spec_die
->name
)
18836 name
= spec_die
->name
;
18838 /* Copy DW_AT_external attribute if it is set. */
18839 if (spec_die
->is_external
)
18840 is_external
= spec_die
->is_external
;
18844 if (!has_const_value
&& has_specification
18845 && can_have_DW_AT_const_value_p (tag
))
18847 struct partial_die_info
*spec_die
;
18849 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18850 spec_die
= res
.pdi
;
18853 spec_die
->fixup (cu
);
18855 if (spec_die
->has_const_value
)
18857 /* Copy DW_AT_const_value attribute if it is set. */
18858 has_const_value
= spec_die
->has_const_value
;
18862 /* Set default names for some unnamed DIEs. */
18864 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18865 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18867 /* If there is no parent die to provide a namespace, and there are
18868 children, see if we can determine the namespace from their linkage
18870 if (cu
->language
== language_cplus
18871 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18872 && die_parent
== NULL
18874 && (tag
== DW_TAG_class_type
18875 || tag
== DW_TAG_structure_type
18876 || tag
== DW_TAG_union_type
))
18877 guess_partial_die_structure_name (this, cu
);
18879 /* GCC might emit a nameless struct or union that has a linkage
18880 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18882 && (tag
== DW_TAG_class_type
18883 || tag
== DW_TAG_interface_type
18884 || tag
== DW_TAG_structure_type
18885 || tag
== DW_TAG_union_type
)
18886 && linkage_name
!= NULL
)
18888 gdb::unique_xmalloc_ptr
<char> demangled
18889 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18890 if (demangled
!= nullptr)
18894 /* Strip any leading namespaces/classes, keep only the base name.
18895 DW_AT_name for named DIEs does not contain the prefixes. */
18896 base
= strrchr (demangled
.get (), ':');
18897 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18900 base
= demangled
.get ();
18902 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18903 name
= objfile
->intern (base
);
18910 /* Read the .debug_loclists header contents from the given SECTION in the
18913 read_loclist_header (struct loclist_header
*header
,
18914 struct dwarf2_section_info
*section
)
18916 unsigned int bytes_read
;
18917 bfd
*abfd
= section
->get_bfd_owner ();
18918 const gdb_byte
*info_ptr
= section
->buffer
;
18919 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18920 info_ptr
+= bytes_read
;
18921 header
->version
= read_2_bytes (abfd
, info_ptr
);
18923 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18925 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18927 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18930 /* Return the DW_AT_loclists_base value for the CU. */
18932 lookup_loclist_base (struct dwarf2_cu
*cu
)
18934 /* For the .dwo unit, the loclist_base points to the first offset following
18935 the header. The header consists of the following entities-
18936 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18938 2. version (2 bytes)
18939 3. address size (1 byte)
18940 4. segment selector size (1 byte)
18941 5. offset entry count (4 bytes)
18942 These sizes are derived as per the DWARFv5 standard. */
18943 if (cu
->dwo_unit
!= nullptr)
18945 if (cu
->header
.initial_length_size
== 4)
18946 return LOCLIST_HEADER_SIZE32
;
18947 return LOCLIST_HEADER_SIZE64
;
18949 return cu
->loclist_base
;
18952 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18953 array of offsets in the .debug_loclists section. */
18955 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18957 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18958 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18959 bfd
*abfd
= objfile
->obfd
;
18960 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18961 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18963 section
->read (objfile
);
18964 if (section
->buffer
== NULL
)
18965 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18966 "section [in module %s]"), objfile_name (objfile
));
18967 struct loclist_header header
;
18968 read_loclist_header (&header
, section
);
18969 if (loclist_index
>= header
.offset_entry_count
)
18970 complaint (_("DW_FORM_loclistx pointing outside of "
18971 ".debug_loclists offset array [in module %s]"),
18972 objfile_name (objfile
));
18973 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18975 complaint (_("DW_FORM_loclistx pointing outside of "
18976 ".debug_loclists section [in module %s]"),
18977 objfile_name (objfile
));
18978 const gdb_byte
*info_ptr
18979 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18981 if (cu
->header
.offset_size
== 4)
18982 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18984 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18987 /* Process the attributes that had to be skipped in the first round. These
18988 attributes are the ones that need str_offsets_base or addr_base attributes.
18989 They could not have been processed in the first round, because at the time
18990 the values of str_offsets_base or addr_base may not have been known. */
18992 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18993 struct attribute
*attr
)
18995 struct dwarf2_cu
*cu
= reader
->cu
;
18996 switch (attr
->form
)
18998 case DW_FORM_addrx
:
18999 case DW_FORM_GNU_addr_index
:
19000 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19002 case DW_FORM_loclistx
:
19003 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19006 case DW_FORM_strx1
:
19007 case DW_FORM_strx2
:
19008 case DW_FORM_strx3
:
19009 case DW_FORM_strx4
:
19010 case DW_FORM_GNU_str_index
:
19012 unsigned int str_index
= DW_UNSND (attr
);
19013 if (reader
->dwo_file
!= NULL
)
19015 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19016 DW_STRING_IS_CANONICAL (attr
) = 0;
19020 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19021 DW_STRING_IS_CANONICAL (attr
) = 0;
19026 gdb_assert_not_reached (_("Unexpected DWARF form."));
19030 /* Read an attribute value described by an attribute form. */
19032 static const gdb_byte
*
19033 read_attribute_value (const struct die_reader_specs
*reader
,
19034 struct attribute
*attr
, unsigned form
,
19035 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19036 bool *need_reprocess
)
19038 struct dwarf2_cu
*cu
= reader
->cu
;
19039 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19040 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19041 bfd
*abfd
= reader
->abfd
;
19042 struct comp_unit_head
*cu_header
= &cu
->header
;
19043 unsigned int bytes_read
;
19044 struct dwarf_block
*blk
;
19045 *need_reprocess
= false;
19047 attr
->form
= (enum dwarf_form
) form
;
19050 case DW_FORM_ref_addr
:
19051 if (cu
->header
.version
== 2)
19052 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19055 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19057 info_ptr
+= bytes_read
;
19059 case DW_FORM_GNU_ref_alt
:
19060 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19061 info_ptr
+= bytes_read
;
19065 struct gdbarch
*gdbarch
= objfile
->arch ();
19066 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19067 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19068 info_ptr
+= bytes_read
;
19071 case DW_FORM_block2
:
19072 blk
= dwarf_alloc_block (cu
);
19073 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19075 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19076 info_ptr
+= blk
->size
;
19077 DW_BLOCK (attr
) = blk
;
19079 case DW_FORM_block4
:
19080 blk
= dwarf_alloc_block (cu
);
19081 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19083 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19084 info_ptr
+= blk
->size
;
19085 DW_BLOCK (attr
) = blk
;
19087 case DW_FORM_data2
:
19088 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19091 case DW_FORM_data4
:
19092 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19095 case DW_FORM_data8
:
19096 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19099 case DW_FORM_data16
:
19100 blk
= dwarf_alloc_block (cu
);
19102 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19104 DW_BLOCK (attr
) = blk
;
19106 case DW_FORM_sec_offset
:
19107 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19108 info_ptr
+= bytes_read
;
19110 case DW_FORM_loclistx
:
19112 *need_reprocess
= true;
19113 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19114 info_ptr
+= bytes_read
;
19117 case DW_FORM_string
:
19118 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19119 DW_STRING_IS_CANONICAL (attr
) = 0;
19120 info_ptr
+= bytes_read
;
19123 if (!cu
->per_cu
->is_dwz
)
19125 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19126 abfd
, info_ptr
, cu_header
,
19128 DW_STRING_IS_CANONICAL (attr
) = 0;
19129 info_ptr
+= bytes_read
;
19133 case DW_FORM_line_strp
:
19134 if (!cu
->per_cu
->is_dwz
)
19137 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19139 DW_STRING_IS_CANONICAL (attr
) = 0;
19140 info_ptr
+= bytes_read
;
19144 case DW_FORM_GNU_strp_alt
:
19146 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19147 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19150 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19151 DW_STRING_IS_CANONICAL (attr
) = 0;
19152 info_ptr
+= bytes_read
;
19155 case DW_FORM_exprloc
:
19156 case DW_FORM_block
:
19157 blk
= dwarf_alloc_block (cu
);
19158 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19159 info_ptr
+= bytes_read
;
19160 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19161 info_ptr
+= blk
->size
;
19162 DW_BLOCK (attr
) = blk
;
19164 case DW_FORM_block1
:
19165 blk
= dwarf_alloc_block (cu
);
19166 blk
->size
= read_1_byte (abfd
, info_ptr
);
19168 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19169 info_ptr
+= blk
->size
;
19170 DW_BLOCK (attr
) = blk
;
19172 case DW_FORM_data1
:
19173 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19177 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19180 case DW_FORM_flag_present
:
19181 DW_UNSND (attr
) = 1;
19183 case DW_FORM_sdata
:
19184 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19185 info_ptr
+= bytes_read
;
19187 case DW_FORM_udata
:
19188 case DW_FORM_rnglistx
:
19189 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19190 info_ptr
+= bytes_read
;
19193 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19194 + read_1_byte (abfd
, info_ptr
));
19198 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19199 + read_2_bytes (abfd
, info_ptr
));
19203 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19204 + read_4_bytes (abfd
, info_ptr
));
19208 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19209 + read_8_bytes (abfd
, info_ptr
));
19212 case DW_FORM_ref_sig8
:
19213 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19216 case DW_FORM_ref_udata
:
19217 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19218 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19219 info_ptr
+= bytes_read
;
19221 case DW_FORM_indirect
:
19222 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19223 info_ptr
+= bytes_read
;
19224 if (form
== DW_FORM_implicit_const
)
19226 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19227 info_ptr
+= bytes_read
;
19229 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19230 info_ptr
, need_reprocess
);
19232 case DW_FORM_implicit_const
:
19233 DW_SND (attr
) = implicit_const
;
19235 case DW_FORM_addrx
:
19236 case DW_FORM_GNU_addr_index
:
19237 *need_reprocess
= true;
19238 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19239 info_ptr
+= bytes_read
;
19242 case DW_FORM_strx1
:
19243 case DW_FORM_strx2
:
19244 case DW_FORM_strx3
:
19245 case DW_FORM_strx4
:
19246 case DW_FORM_GNU_str_index
:
19248 ULONGEST str_index
;
19249 if (form
== DW_FORM_strx1
)
19251 str_index
= read_1_byte (abfd
, info_ptr
);
19254 else if (form
== DW_FORM_strx2
)
19256 str_index
= read_2_bytes (abfd
, info_ptr
);
19259 else if (form
== DW_FORM_strx3
)
19261 str_index
= read_3_bytes (abfd
, info_ptr
);
19264 else if (form
== DW_FORM_strx4
)
19266 str_index
= read_4_bytes (abfd
, info_ptr
);
19271 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19272 info_ptr
+= bytes_read
;
19274 *need_reprocess
= true;
19275 DW_UNSND (attr
) = str_index
;
19279 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19280 dwarf_form_name (form
),
19281 bfd_get_filename (abfd
));
19285 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19286 attr
->form
= DW_FORM_GNU_ref_alt
;
19288 /* We have seen instances where the compiler tried to emit a byte
19289 size attribute of -1 which ended up being encoded as an unsigned
19290 0xffffffff. Although 0xffffffff is technically a valid size value,
19291 an object of this size seems pretty unlikely so we can relatively
19292 safely treat these cases as if the size attribute was invalid and
19293 treat them as zero by default. */
19294 if (attr
->name
== DW_AT_byte_size
19295 && form
== DW_FORM_data4
19296 && DW_UNSND (attr
) >= 0xffffffff)
19299 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19300 hex_string (DW_UNSND (attr
)));
19301 DW_UNSND (attr
) = 0;
19307 /* Read an attribute described by an abbreviated attribute. */
19309 static const gdb_byte
*
19310 read_attribute (const struct die_reader_specs
*reader
,
19311 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19312 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19314 attr
->name
= abbrev
->name
;
19315 return read_attribute_value (reader
, attr
, abbrev
->form
,
19316 abbrev
->implicit_const
, info_ptr
,
19320 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19322 static const char *
19323 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19324 LONGEST str_offset
)
19326 return dwarf2_per_objfile
->per_bfd
->str
.read_string
19327 (dwarf2_per_objfile
->objfile
, str_offset
, "DW_FORM_strp");
19330 /* Return pointer to string at .debug_str offset as read from BUF.
19331 BUF is assumed to be in a compilation unit described by CU_HEADER.
19332 Return *BYTES_READ_PTR count of bytes read from BUF. */
19334 static const char *
19335 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19336 const gdb_byte
*buf
,
19337 const struct comp_unit_head
*cu_header
,
19338 unsigned int *bytes_read_ptr
)
19340 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19342 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19348 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19349 const struct comp_unit_head
*cu_header
,
19350 unsigned int *bytes_read_ptr
)
19352 bfd
*abfd
= objfile
->obfd
;
19353 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19355 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19358 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19359 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19360 ADDR_SIZE is the size of addresses from the CU header. */
19363 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19364 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19367 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19368 bfd
*abfd
= objfile
->obfd
;
19369 const gdb_byte
*info_ptr
;
19370 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19372 dwarf2_per_objfile
->per_bfd
->addr
.read (objfile
);
19373 if (dwarf2_per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19374 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19375 objfile_name (objfile
));
19376 if (addr_base_or_zero
+ addr_index
* addr_size
19377 >= dwarf2_per_objfile
->per_bfd
->addr
.size
)
19378 error (_("DW_FORM_addr_index pointing outside of "
19379 ".debug_addr section [in module %s]"),
19380 objfile_name (objfile
));
19381 info_ptr
= (dwarf2_per_objfile
->per_bfd
->addr
.buffer
19382 + addr_base_or_zero
+ addr_index
* addr_size
);
19383 if (addr_size
== 4)
19384 return bfd_get_32 (abfd
, info_ptr
);
19386 return bfd_get_64 (abfd
, info_ptr
);
19389 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19392 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19394 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19395 cu
->addr_base
, cu
->header
.addr_size
);
19398 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19401 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19402 unsigned int *bytes_read
)
19404 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19405 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19407 return read_addr_index (cu
, addr_index
);
19413 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19414 dwarf2_per_objfile
*dwarf2_per_objfile
,
19415 unsigned int addr_index
)
19417 struct dwarf2_cu
*cu
= per_cu
->cu
;
19418 gdb::optional
<ULONGEST
> addr_base
;
19421 /* We need addr_base and addr_size.
19422 If we don't have PER_CU->cu, we have to get it.
19423 Nasty, but the alternative is storing the needed info in PER_CU,
19424 which at this point doesn't seem justified: it's not clear how frequently
19425 it would get used and it would increase the size of every PER_CU.
19426 Entry points like dwarf2_per_cu_addr_size do a similar thing
19427 so we're not in uncharted territory here.
19428 Alas we need to be a bit more complicated as addr_base is contained
19431 We don't need to read the entire CU(/TU).
19432 We just need the header and top level die.
19434 IWBN to use the aging mechanism to let us lazily later discard the CU.
19435 For now we skip this optimization. */
19439 addr_base
= cu
->addr_base
;
19440 addr_size
= cu
->header
.addr_size
;
19444 cutu_reader
reader (per_cu
, dwarf2_per_objfile
, NULL
, 0, false);
19445 addr_base
= reader
.cu
->addr_base
;
19446 addr_size
= reader
.cu
->header
.addr_size
;
19449 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19453 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19454 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19457 static const char *
19458 read_str_index (struct dwarf2_cu
*cu
,
19459 struct dwarf2_section_info
*str_section
,
19460 struct dwarf2_section_info
*str_offsets_section
,
19461 ULONGEST str_offsets_base
, ULONGEST str_index
)
19463 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19464 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19465 const char *objf_name
= objfile_name (objfile
);
19466 bfd
*abfd
= objfile
->obfd
;
19467 const gdb_byte
*info_ptr
;
19468 ULONGEST str_offset
;
19469 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19471 str_section
->read (objfile
);
19472 str_offsets_section
->read (objfile
);
19473 if (str_section
->buffer
== NULL
)
19474 error (_("%s used without %s section"
19475 " in CU at offset %s [in module %s]"),
19476 form_name
, str_section
->get_name (),
19477 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19478 if (str_offsets_section
->buffer
== NULL
)
19479 error (_("%s used without %s section"
19480 " in CU at offset %s [in module %s]"),
19481 form_name
, str_section
->get_name (),
19482 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19483 info_ptr
= (str_offsets_section
->buffer
19485 + str_index
* cu
->header
.offset_size
);
19486 if (cu
->header
.offset_size
== 4)
19487 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19489 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19490 if (str_offset
>= str_section
->size
)
19491 error (_("Offset from %s pointing outside of"
19492 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19493 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19494 return (const char *) (str_section
->buffer
+ str_offset
);
19497 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19499 static const char *
19500 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19502 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19503 ? reader
->cu
->header
.addr_size
: 0;
19504 return read_str_index (reader
->cu
,
19505 &reader
->dwo_file
->sections
.str
,
19506 &reader
->dwo_file
->sections
.str_offsets
,
19507 str_offsets_base
, str_index
);
19510 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19512 static const char *
19513 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19515 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19516 const char *objf_name
= objfile_name (objfile
);
19517 static const char form_name
[] = "DW_FORM_GNU_str_index";
19518 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19520 if (!cu
->str_offsets_base
.has_value ())
19521 error (_("%s used in Fission stub without %s"
19522 " in CU at offset 0x%lx [in module %s]"),
19523 form_name
, str_offsets_attr_name
,
19524 (long) cu
->header
.offset_size
, objf_name
);
19526 return read_str_index (cu
,
19527 &cu
->per_objfile
->per_bfd
->str
,
19528 &cu
->per_objfile
->per_bfd
->str_offsets
,
19529 *cu
->str_offsets_base
, str_index
);
19532 /* Return the length of an LEB128 number in BUF. */
19535 leb128_size (const gdb_byte
*buf
)
19537 const gdb_byte
*begin
= buf
;
19543 if ((byte
& 128) == 0)
19544 return buf
- begin
;
19549 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19558 cu
->language
= language_c
;
19561 case DW_LANG_C_plus_plus
:
19562 case DW_LANG_C_plus_plus_11
:
19563 case DW_LANG_C_plus_plus_14
:
19564 cu
->language
= language_cplus
;
19567 cu
->language
= language_d
;
19569 case DW_LANG_Fortran77
:
19570 case DW_LANG_Fortran90
:
19571 case DW_LANG_Fortran95
:
19572 case DW_LANG_Fortran03
:
19573 case DW_LANG_Fortran08
:
19574 cu
->language
= language_fortran
;
19577 cu
->language
= language_go
;
19579 case DW_LANG_Mips_Assembler
:
19580 cu
->language
= language_asm
;
19582 case DW_LANG_Ada83
:
19583 case DW_LANG_Ada95
:
19584 cu
->language
= language_ada
;
19586 case DW_LANG_Modula2
:
19587 cu
->language
= language_m2
;
19589 case DW_LANG_Pascal83
:
19590 cu
->language
= language_pascal
;
19593 cu
->language
= language_objc
;
19596 case DW_LANG_Rust_old
:
19597 cu
->language
= language_rust
;
19599 case DW_LANG_Cobol74
:
19600 case DW_LANG_Cobol85
:
19602 cu
->language
= language_minimal
;
19605 cu
->language_defn
= language_def (cu
->language
);
19608 /* Return the named attribute or NULL if not there. */
19610 static struct attribute
*
19611 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19616 struct attribute
*spec
= NULL
;
19618 for (i
= 0; i
< die
->num_attrs
; ++i
)
19620 if (die
->attrs
[i
].name
== name
)
19621 return &die
->attrs
[i
];
19622 if (die
->attrs
[i
].name
== DW_AT_specification
19623 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19624 spec
= &die
->attrs
[i
];
19630 die
= follow_die_ref (die
, spec
, &cu
);
19636 /* Return the string associated with a string-typed attribute, or NULL if it
19637 is either not found or is of an incorrect type. */
19639 static const char *
19640 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19642 struct attribute
*attr
;
19643 const char *str
= NULL
;
19645 attr
= dwarf2_attr (die
, name
, cu
);
19649 str
= attr
->value_as_string ();
19650 if (str
== nullptr)
19651 complaint (_("string type expected for attribute %s for "
19652 "DIE at %s in module %s"),
19653 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19654 objfile_name (cu
->per_objfile
->objfile
));
19660 /* Return the dwo name or NULL if not present. If present, it is in either
19661 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19662 static const char *
19663 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19665 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19666 if (dwo_name
== nullptr)
19667 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19671 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19672 and holds a non-zero value. This function should only be used for
19673 DW_FORM_flag or DW_FORM_flag_present attributes. */
19676 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19678 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19680 return (attr
&& DW_UNSND (attr
));
19684 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19686 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19687 which value is non-zero. However, we have to be careful with
19688 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19689 (via dwarf2_flag_true_p) follows this attribute. So we may
19690 end up accidently finding a declaration attribute that belongs
19691 to a different DIE referenced by the specification attribute,
19692 even though the given DIE does not have a declaration attribute. */
19693 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19694 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19697 /* Return the die giving the specification for DIE, if there is
19698 one. *SPEC_CU is the CU containing DIE on input, and the CU
19699 containing the return value on output. If there is no
19700 specification, but there is an abstract origin, that is
19703 static struct die_info
*
19704 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19706 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19709 if (spec_attr
== NULL
)
19710 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19712 if (spec_attr
== NULL
)
19715 return follow_die_ref (die
, spec_attr
, spec_cu
);
19718 /* Stub for free_line_header to match void * callback types. */
19721 free_line_header_voidp (void *arg
)
19723 struct line_header
*lh
= (struct line_header
*) arg
;
19728 /* A convenience function to find the proper .debug_line section for a CU. */
19730 static struct dwarf2_section_info
*
19731 get_debug_line_section (struct dwarf2_cu
*cu
)
19733 struct dwarf2_section_info
*section
;
19734 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19736 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19738 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19739 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19740 else if (cu
->per_cu
->is_dwz
)
19742 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19744 section
= &dwz
->line
;
19747 section
= &dwarf2_per_objfile
->per_bfd
->line
;
19752 /* Read the statement program header starting at OFFSET in
19753 .debug_line, or .debug_line.dwo. Return a pointer
19754 to a struct line_header, allocated using xmalloc.
19755 Returns NULL if there is a problem reading the header, e.g., if it
19756 has a version we don't understand.
19758 NOTE: the strings in the include directory and file name tables of
19759 the returned object point into the dwarf line section buffer,
19760 and must not be freed. */
19762 static line_header_up
19763 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19765 struct dwarf2_section_info
*section
;
19766 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19768 section
= get_debug_line_section (cu
);
19769 section
->read (dwarf2_per_objfile
->objfile
);
19770 if (section
->buffer
== NULL
)
19772 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19773 complaint (_("missing .debug_line.dwo section"));
19775 complaint (_("missing .debug_line section"));
19779 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19780 dwarf2_per_objfile
, section
,
19784 /* Subroutine of dwarf_decode_lines to simplify it.
19785 Return the file name of the psymtab for the given file_entry.
19786 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19787 If space for the result is malloc'd, *NAME_HOLDER will be set.
19788 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19790 static const char *
19791 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19792 const dwarf2_psymtab
*pst
,
19793 const char *comp_dir
,
19794 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19796 const char *include_name
= fe
.name
;
19797 const char *include_name_to_compare
= include_name
;
19798 const char *pst_filename
;
19801 const char *dir_name
= fe
.include_dir (lh
);
19803 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19804 if (!IS_ABSOLUTE_PATH (include_name
)
19805 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19807 /* Avoid creating a duplicate psymtab for PST.
19808 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19809 Before we do the comparison, however, we need to account
19810 for DIR_NAME and COMP_DIR.
19811 First prepend dir_name (if non-NULL). If we still don't
19812 have an absolute path prepend comp_dir (if non-NULL).
19813 However, the directory we record in the include-file's
19814 psymtab does not contain COMP_DIR (to match the
19815 corresponding symtab(s)).
19820 bash$ gcc -g ./hello.c
19821 include_name = "hello.c"
19823 DW_AT_comp_dir = comp_dir = "/tmp"
19824 DW_AT_name = "./hello.c"
19828 if (dir_name
!= NULL
)
19830 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19831 include_name
, (char *) NULL
));
19832 include_name
= name_holder
->get ();
19833 include_name_to_compare
= include_name
;
19835 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19837 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19838 include_name
, (char *) NULL
));
19839 include_name_to_compare
= hold_compare
.get ();
19843 pst_filename
= pst
->filename
;
19844 gdb::unique_xmalloc_ptr
<char> copied_name
;
19845 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19847 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19848 pst_filename
, (char *) NULL
));
19849 pst_filename
= copied_name
.get ();
19852 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19856 return include_name
;
19859 /* State machine to track the state of the line number program. */
19861 class lnp_state_machine
19864 /* Initialize a machine state for the start of a line number
19866 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19867 bool record_lines_p
);
19869 file_entry
*current_file ()
19871 /* lh->file_names is 0-based, but the file name numbers in the
19872 statement program are 1-based. */
19873 return m_line_header
->file_name_at (m_file
);
19876 /* Record the line in the state machine. END_SEQUENCE is true if
19877 we're processing the end of a sequence. */
19878 void record_line (bool end_sequence
);
19880 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19881 nop-out rest of the lines in this sequence. */
19882 void check_line_address (struct dwarf2_cu
*cu
,
19883 const gdb_byte
*line_ptr
,
19884 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19886 void handle_set_discriminator (unsigned int discriminator
)
19888 m_discriminator
= discriminator
;
19889 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19892 /* Handle DW_LNE_set_address. */
19893 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19896 address
+= baseaddr
;
19897 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19900 /* Handle DW_LNS_advance_pc. */
19901 void handle_advance_pc (CORE_ADDR adjust
);
19903 /* Handle a special opcode. */
19904 void handle_special_opcode (unsigned char op_code
);
19906 /* Handle DW_LNS_advance_line. */
19907 void handle_advance_line (int line_delta
)
19909 advance_line (line_delta
);
19912 /* Handle DW_LNS_set_file. */
19913 void handle_set_file (file_name_index file
);
19915 /* Handle DW_LNS_negate_stmt. */
19916 void handle_negate_stmt ()
19918 m_is_stmt
= !m_is_stmt
;
19921 /* Handle DW_LNS_const_add_pc. */
19922 void handle_const_add_pc ();
19924 /* Handle DW_LNS_fixed_advance_pc. */
19925 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19927 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19931 /* Handle DW_LNS_copy. */
19932 void handle_copy ()
19934 record_line (false);
19935 m_discriminator
= 0;
19938 /* Handle DW_LNE_end_sequence. */
19939 void handle_end_sequence ()
19941 m_currently_recording_lines
= true;
19945 /* Advance the line by LINE_DELTA. */
19946 void advance_line (int line_delta
)
19948 m_line
+= line_delta
;
19950 if (line_delta
!= 0)
19951 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19954 struct dwarf2_cu
*m_cu
;
19956 gdbarch
*m_gdbarch
;
19958 /* True if we're recording lines.
19959 Otherwise we're building partial symtabs and are just interested in
19960 finding include files mentioned by the line number program. */
19961 bool m_record_lines_p
;
19963 /* The line number header. */
19964 line_header
*m_line_header
;
19966 /* These are part of the standard DWARF line number state machine,
19967 and initialized according to the DWARF spec. */
19969 unsigned char m_op_index
= 0;
19970 /* The line table index of the current file. */
19971 file_name_index m_file
= 1;
19972 unsigned int m_line
= 1;
19974 /* These are initialized in the constructor. */
19976 CORE_ADDR m_address
;
19978 unsigned int m_discriminator
;
19980 /* Additional bits of state we need to track. */
19982 /* The last file that we called dwarf2_start_subfile for.
19983 This is only used for TLLs. */
19984 unsigned int m_last_file
= 0;
19985 /* The last file a line number was recorded for. */
19986 struct subfile
*m_last_subfile
= NULL
;
19988 /* When true, record the lines we decode. */
19989 bool m_currently_recording_lines
= false;
19991 /* The last line number that was recorded, used to coalesce
19992 consecutive entries for the same line. This can happen, for
19993 example, when discriminators are present. PR 17276. */
19994 unsigned int m_last_line
= 0;
19995 bool m_line_has_non_zero_discriminator
= false;
19999 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20001 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20002 / m_line_header
->maximum_ops_per_instruction
)
20003 * m_line_header
->minimum_instruction_length
);
20004 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20005 m_op_index
= ((m_op_index
+ adjust
)
20006 % m_line_header
->maximum_ops_per_instruction
);
20010 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20012 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20013 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20014 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20015 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20016 / m_line_header
->maximum_ops_per_instruction
)
20017 * m_line_header
->minimum_instruction_length
);
20018 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20019 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20020 % m_line_header
->maximum_ops_per_instruction
);
20022 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20023 advance_line (line_delta
);
20024 record_line (false);
20025 m_discriminator
= 0;
20029 lnp_state_machine::handle_set_file (file_name_index file
)
20033 const file_entry
*fe
= current_file ();
20035 dwarf2_debug_line_missing_file_complaint ();
20036 else if (m_record_lines_p
)
20038 const char *dir
= fe
->include_dir (m_line_header
);
20040 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20041 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20042 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20047 lnp_state_machine::handle_const_add_pc ()
20050 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20053 = (((m_op_index
+ adjust
)
20054 / m_line_header
->maximum_ops_per_instruction
)
20055 * m_line_header
->minimum_instruction_length
);
20057 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20058 m_op_index
= ((m_op_index
+ adjust
)
20059 % m_line_header
->maximum_ops_per_instruction
);
20062 /* Return non-zero if we should add LINE to the line number table.
20063 LINE is the line to add, LAST_LINE is the last line that was added,
20064 LAST_SUBFILE is the subfile for LAST_LINE.
20065 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20066 had a non-zero discriminator.
20068 We have to be careful in the presence of discriminators.
20069 E.g., for this line:
20071 for (i = 0; i < 100000; i++);
20073 clang can emit four line number entries for that one line,
20074 each with a different discriminator.
20075 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20077 However, we want gdb to coalesce all four entries into one.
20078 Otherwise the user could stepi into the middle of the line and
20079 gdb would get confused about whether the pc really was in the
20080 middle of the line.
20082 Things are further complicated by the fact that two consecutive
20083 line number entries for the same line is a heuristic used by gcc
20084 to denote the end of the prologue. So we can't just discard duplicate
20085 entries, we have to be selective about it. The heuristic we use is
20086 that we only collapse consecutive entries for the same line if at least
20087 one of those entries has a non-zero discriminator. PR 17276.
20089 Note: Addresses in the line number state machine can never go backwards
20090 within one sequence, thus this coalescing is ok. */
20093 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20094 unsigned int line
, unsigned int last_line
,
20095 int line_has_non_zero_discriminator
,
20096 struct subfile
*last_subfile
)
20098 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20100 if (line
!= last_line
)
20102 /* Same line for the same file that we've seen already.
20103 As a last check, for pr 17276, only record the line if the line
20104 has never had a non-zero discriminator. */
20105 if (!line_has_non_zero_discriminator
)
20110 /* Use the CU's builder to record line number LINE beginning at
20111 address ADDRESS in the line table of subfile SUBFILE. */
20114 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20115 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20116 struct dwarf2_cu
*cu
)
20118 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20120 if (dwarf_line_debug
)
20122 fprintf_unfiltered (gdb_stdlog
,
20123 "Recording line %u, file %s, address %s\n",
20124 line
, lbasename (subfile
->name
),
20125 paddress (gdbarch
, address
));
20129 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20132 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20133 Mark the end of a set of line number records.
20134 The arguments are the same as for dwarf_record_line_1.
20135 If SUBFILE is NULL the request is ignored. */
20138 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20139 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20141 if (subfile
== NULL
)
20144 if (dwarf_line_debug
)
20146 fprintf_unfiltered (gdb_stdlog
,
20147 "Finishing current line, file %s, address %s\n",
20148 lbasename (subfile
->name
),
20149 paddress (gdbarch
, address
));
20152 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20156 lnp_state_machine::record_line (bool end_sequence
)
20158 if (dwarf_line_debug
)
20160 fprintf_unfiltered (gdb_stdlog
,
20161 "Processing actual line %u: file %u,"
20162 " address %s, is_stmt %u, discrim %u%s\n",
20164 paddress (m_gdbarch
, m_address
),
20165 m_is_stmt
, m_discriminator
,
20166 (end_sequence
? "\t(end sequence)" : ""));
20169 file_entry
*fe
= current_file ();
20172 dwarf2_debug_line_missing_file_complaint ();
20173 /* For now we ignore lines not starting on an instruction boundary.
20174 But not when processing end_sequence for compatibility with the
20175 previous version of the code. */
20176 else if (m_op_index
== 0 || end_sequence
)
20178 fe
->included_p
= 1;
20179 if (m_record_lines_p
)
20181 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20184 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20185 m_currently_recording_lines
? m_cu
: nullptr);
20190 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20192 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20193 m_line_has_non_zero_discriminator
,
20196 buildsym_compunit
*builder
= m_cu
->get_builder ();
20197 dwarf_record_line_1 (m_gdbarch
,
20198 builder
->get_current_subfile (),
20199 m_line
, m_address
, is_stmt
,
20200 m_currently_recording_lines
? m_cu
: nullptr);
20202 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20203 m_last_line
= m_line
;
20209 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20210 line_header
*lh
, bool record_lines_p
)
20214 m_record_lines_p
= record_lines_p
;
20215 m_line_header
= lh
;
20217 m_currently_recording_lines
= true;
20219 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20220 was a line entry for it so that the backend has a chance to adjust it
20221 and also record it in case it needs it. This is currently used by MIPS
20222 code, cf. `mips_adjust_dwarf2_line'. */
20223 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20224 m_is_stmt
= lh
->default_is_stmt
;
20225 m_discriminator
= 0;
20229 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20230 const gdb_byte
*line_ptr
,
20231 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20233 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20234 the pc range of the CU. However, we restrict the test to only ADDRESS
20235 values of zero to preserve GDB's previous behaviour which is to handle
20236 the specific case of a function being GC'd by the linker. */
20238 if (address
== 0 && address
< unrelocated_lowpc
)
20240 /* This line table is for a function which has been
20241 GCd by the linker. Ignore it. PR gdb/12528 */
20243 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20244 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20246 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20247 line_offset
, objfile_name (objfile
));
20248 m_currently_recording_lines
= false;
20249 /* Note: m_currently_recording_lines is left as false until we see
20250 DW_LNE_end_sequence. */
20254 /* Subroutine of dwarf_decode_lines to simplify it.
20255 Process the line number information in LH.
20256 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20257 program in order to set included_p for every referenced header. */
20260 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20261 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20263 const gdb_byte
*line_ptr
, *extended_end
;
20264 const gdb_byte
*line_end
;
20265 unsigned int bytes_read
, extended_len
;
20266 unsigned char op_code
, extended_op
;
20267 CORE_ADDR baseaddr
;
20268 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20269 bfd
*abfd
= objfile
->obfd
;
20270 struct gdbarch
*gdbarch
= objfile
->arch ();
20271 /* True if we're recording line info (as opposed to building partial
20272 symtabs and just interested in finding include files mentioned by
20273 the line number program). */
20274 bool record_lines_p
= !decode_for_pst_p
;
20276 baseaddr
= objfile
->text_section_offset ();
20278 line_ptr
= lh
->statement_program_start
;
20279 line_end
= lh
->statement_program_end
;
20281 /* Read the statement sequences until there's nothing left. */
20282 while (line_ptr
< line_end
)
20284 /* The DWARF line number program state machine. Reset the state
20285 machine at the start of each sequence. */
20286 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20287 bool end_sequence
= false;
20289 if (record_lines_p
)
20291 /* Start a subfile for the current file of the state
20293 const file_entry
*fe
= state_machine
.current_file ();
20296 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20299 /* Decode the table. */
20300 while (line_ptr
< line_end
&& !end_sequence
)
20302 op_code
= read_1_byte (abfd
, line_ptr
);
20305 if (op_code
>= lh
->opcode_base
)
20307 /* Special opcode. */
20308 state_machine
.handle_special_opcode (op_code
);
20310 else switch (op_code
)
20312 case DW_LNS_extended_op
:
20313 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20315 line_ptr
+= bytes_read
;
20316 extended_end
= line_ptr
+ extended_len
;
20317 extended_op
= read_1_byte (abfd
, line_ptr
);
20319 switch (extended_op
)
20321 case DW_LNE_end_sequence
:
20322 state_machine
.handle_end_sequence ();
20323 end_sequence
= true;
20325 case DW_LNE_set_address
:
20328 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20329 line_ptr
+= bytes_read
;
20331 state_machine
.check_line_address (cu
, line_ptr
,
20332 lowpc
- baseaddr
, address
);
20333 state_machine
.handle_set_address (baseaddr
, address
);
20336 case DW_LNE_define_file
:
20338 const char *cur_file
;
20339 unsigned int mod_time
, length
;
20342 cur_file
= read_direct_string (abfd
, line_ptr
,
20344 line_ptr
+= bytes_read
;
20345 dindex
= (dir_index
)
20346 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20347 line_ptr
+= bytes_read
;
20349 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20350 line_ptr
+= bytes_read
;
20352 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20353 line_ptr
+= bytes_read
;
20354 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20357 case DW_LNE_set_discriminator
:
20359 /* The discriminator is not interesting to the
20360 debugger; just ignore it. We still need to
20361 check its value though:
20362 if there are consecutive entries for the same
20363 (non-prologue) line we want to coalesce them.
20366 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20367 line_ptr
+= bytes_read
;
20369 state_machine
.handle_set_discriminator (discr
);
20373 complaint (_("mangled .debug_line section"));
20376 /* Make sure that we parsed the extended op correctly. If e.g.
20377 we expected a different address size than the producer used,
20378 we may have read the wrong number of bytes. */
20379 if (line_ptr
!= extended_end
)
20381 complaint (_("mangled .debug_line section"));
20386 state_machine
.handle_copy ();
20388 case DW_LNS_advance_pc
:
20391 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20392 line_ptr
+= bytes_read
;
20394 state_machine
.handle_advance_pc (adjust
);
20397 case DW_LNS_advance_line
:
20400 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20401 line_ptr
+= bytes_read
;
20403 state_machine
.handle_advance_line (line_delta
);
20406 case DW_LNS_set_file
:
20408 file_name_index file
20409 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20411 line_ptr
+= bytes_read
;
20413 state_machine
.handle_set_file (file
);
20416 case DW_LNS_set_column
:
20417 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20418 line_ptr
+= bytes_read
;
20420 case DW_LNS_negate_stmt
:
20421 state_machine
.handle_negate_stmt ();
20423 case DW_LNS_set_basic_block
:
20425 /* Add to the address register of the state machine the
20426 address increment value corresponding to special opcode
20427 255. I.e., this value is scaled by the minimum
20428 instruction length since special opcode 255 would have
20429 scaled the increment. */
20430 case DW_LNS_const_add_pc
:
20431 state_machine
.handle_const_add_pc ();
20433 case DW_LNS_fixed_advance_pc
:
20435 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20438 state_machine
.handle_fixed_advance_pc (addr_adj
);
20443 /* Unknown standard opcode, ignore it. */
20446 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20448 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20449 line_ptr
+= bytes_read
;
20456 dwarf2_debug_line_missing_end_sequence_complaint ();
20458 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20459 in which case we still finish recording the last line). */
20460 state_machine
.record_line (true);
20464 /* Decode the Line Number Program (LNP) for the given line_header
20465 structure and CU. The actual information extracted and the type
20466 of structures created from the LNP depends on the value of PST.
20468 1. If PST is NULL, then this procedure uses the data from the program
20469 to create all necessary symbol tables, and their linetables.
20471 2. If PST is not NULL, this procedure reads the program to determine
20472 the list of files included by the unit represented by PST, and
20473 builds all the associated partial symbol tables.
20475 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20476 It is used for relative paths in the line table.
20477 NOTE: When processing partial symtabs (pst != NULL),
20478 comp_dir == pst->dirname.
20480 NOTE: It is important that psymtabs have the same file name (via strcmp)
20481 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20482 symtab we don't use it in the name of the psymtabs we create.
20483 E.g. expand_line_sal requires this when finding psymtabs to expand.
20484 A good testcase for this is mb-inline.exp.
20486 LOWPC is the lowest address in CU (or 0 if not known).
20488 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20489 for its PC<->lines mapping information. Otherwise only the filename
20490 table is read in. */
20493 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20494 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20495 CORE_ADDR lowpc
, int decode_mapping
)
20497 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20498 const int decode_for_pst_p
= (pst
!= NULL
);
20500 if (decode_mapping
)
20501 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20503 if (decode_for_pst_p
)
20505 /* Now that we're done scanning the Line Header Program, we can
20506 create the psymtab of each included file. */
20507 for (auto &file_entry
: lh
->file_names ())
20508 if (file_entry
.included_p
== 1)
20510 gdb::unique_xmalloc_ptr
<char> name_holder
;
20511 const char *include_name
=
20512 psymtab_include_file_name (lh
, file_entry
, pst
,
20513 comp_dir
, &name_holder
);
20514 if (include_name
!= NULL
)
20515 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20520 /* Make sure a symtab is created for every file, even files
20521 which contain only variables (i.e. no code with associated
20523 buildsym_compunit
*builder
= cu
->get_builder ();
20524 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20526 for (auto &fe
: lh
->file_names ())
20528 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20529 if (builder
->get_current_subfile ()->symtab
== NULL
)
20531 builder
->get_current_subfile ()->symtab
20532 = allocate_symtab (cust
,
20533 builder
->get_current_subfile ()->name
);
20535 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20540 /* Start a subfile for DWARF. FILENAME is the name of the file and
20541 DIRNAME the name of the source directory which contains FILENAME
20542 or NULL if not known.
20543 This routine tries to keep line numbers from identical absolute and
20544 relative file names in a common subfile.
20546 Using the `list' example from the GDB testsuite, which resides in
20547 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20548 of /srcdir/list0.c yields the following debugging information for list0.c:
20550 DW_AT_name: /srcdir/list0.c
20551 DW_AT_comp_dir: /compdir
20552 files.files[0].name: list0.h
20553 files.files[0].dir: /srcdir
20554 files.files[1].name: list0.c
20555 files.files[1].dir: /srcdir
20557 The line number information for list0.c has to end up in a single
20558 subfile, so that `break /srcdir/list0.c:1' works as expected.
20559 start_subfile will ensure that this happens provided that we pass the
20560 concatenation of files.files[1].dir and files.files[1].name as the
20564 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20565 const char *dirname
)
20567 gdb::unique_xmalloc_ptr
<char> copy
;
20569 /* In order not to lose the line information directory,
20570 we concatenate it to the filename when it makes sense.
20571 Note that the Dwarf3 standard says (speaking of filenames in line
20572 information): ``The directory index is ignored for file names
20573 that represent full path names''. Thus ignoring dirname in the
20574 `else' branch below isn't an issue. */
20576 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20578 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20579 filename
= copy
.get ();
20582 cu
->get_builder ()->start_subfile (filename
);
20585 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20586 buildsym_compunit constructor. */
20588 struct compunit_symtab
*
20589 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20592 gdb_assert (m_builder
== nullptr);
20594 m_builder
.reset (new struct buildsym_compunit
20595 (per_cu
->dwarf2_per_objfile
->objfile
,
20596 name
, comp_dir
, language
, low_pc
));
20598 list_in_scope
= get_builder ()->get_file_symbols ();
20600 get_builder ()->record_debugformat ("DWARF 2");
20601 get_builder ()->record_producer (producer
);
20603 processing_has_namespace_info
= false;
20605 return get_builder ()->get_compunit_symtab ();
20609 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20610 struct dwarf2_cu
*cu
)
20612 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20613 struct comp_unit_head
*cu_header
= &cu
->header
;
20615 /* NOTE drow/2003-01-30: There used to be a comment and some special
20616 code here to turn a symbol with DW_AT_external and a
20617 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20618 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20619 with some versions of binutils) where shared libraries could have
20620 relocations against symbols in their debug information - the
20621 minimal symbol would have the right address, but the debug info
20622 would not. It's no longer necessary, because we will explicitly
20623 apply relocations when we read in the debug information now. */
20625 /* A DW_AT_location attribute with no contents indicates that a
20626 variable has been optimized away. */
20627 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20629 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20633 /* Handle one degenerate form of location expression specially, to
20634 preserve GDB's previous behavior when section offsets are
20635 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20636 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20638 if (attr
->form_is_block ()
20639 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20640 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20641 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20642 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20643 && (DW_BLOCK (attr
)->size
20644 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20646 unsigned int dummy
;
20648 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20649 SET_SYMBOL_VALUE_ADDRESS
20650 (sym
, cu
->header
.read_address (objfile
->obfd
,
20651 DW_BLOCK (attr
)->data
+ 1,
20654 SET_SYMBOL_VALUE_ADDRESS
20655 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20657 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20658 fixup_symbol_section (sym
, objfile
);
20659 SET_SYMBOL_VALUE_ADDRESS
20661 SYMBOL_VALUE_ADDRESS (sym
)
20662 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20666 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20667 expression evaluator, and use LOC_COMPUTED only when necessary
20668 (i.e. when the value of a register or memory location is
20669 referenced, or a thread-local block, etc.). Then again, it might
20670 not be worthwhile. I'm assuming that it isn't unless performance
20671 or memory numbers show me otherwise. */
20673 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20675 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20676 cu
->has_loclist
= true;
20679 /* Given a pointer to a DWARF information entry, figure out if we need
20680 to make a symbol table entry for it, and if so, create a new entry
20681 and return a pointer to it.
20682 If TYPE is NULL, determine symbol type from the die, otherwise
20683 used the passed type.
20684 If SPACE is not NULL, use it to hold the new symbol. If it is
20685 NULL, allocate a new symbol on the objfile's obstack. */
20687 static struct symbol
*
20688 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20689 struct symbol
*space
)
20691 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20692 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20693 struct gdbarch
*gdbarch
= objfile
->arch ();
20694 struct symbol
*sym
= NULL
;
20696 struct attribute
*attr
= NULL
;
20697 struct attribute
*attr2
= NULL
;
20698 CORE_ADDR baseaddr
;
20699 struct pending
**list_to_add
= NULL
;
20701 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20703 baseaddr
= objfile
->text_section_offset ();
20705 name
= dwarf2_name (die
, cu
);
20708 int suppress_add
= 0;
20713 sym
= new (&objfile
->objfile_obstack
) symbol
;
20714 OBJSTAT (objfile
, n_syms
++);
20716 /* Cache this symbol's name and the name's demangled form (if any). */
20717 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20718 /* Fortran does not have mangling standard and the mangling does differ
20719 between gfortran, iFort etc. */
20720 const char *physname
20721 = (cu
->language
== language_fortran
20722 ? dwarf2_full_name (name
, die
, cu
)
20723 : dwarf2_physname (name
, die
, cu
));
20724 const char *linkagename
= dw2_linkage_name (die
, cu
);
20726 if (linkagename
== nullptr || cu
->language
== language_ada
)
20727 sym
->set_linkage_name (physname
);
20730 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20731 sym
->set_linkage_name (linkagename
);
20734 /* Default assumptions.
20735 Use the passed type or decode it from the die. */
20736 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20737 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20739 SYMBOL_TYPE (sym
) = type
;
20741 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20742 attr
= dwarf2_attr (die
,
20743 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20745 if (attr
!= nullptr)
20747 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20750 attr
= dwarf2_attr (die
,
20751 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20753 if (attr
!= nullptr)
20755 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20756 struct file_entry
*fe
;
20758 if (cu
->line_header
!= NULL
)
20759 fe
= cu
->line_header
->file_name_at (file_index
);
20764 complaint (_("file index out of range"));
20766 symbol_set_symtab (sym
, fe
->symtab
);
20772 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20773 if (attr
!= nullptr)
20777 addr
= attr
->value_as_address ();
20778 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20779 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20781 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20782 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20783 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20784 add_symbol_to_list (sym
, cu
->list_in_scope
);
20786 case DW_TAG_subprogram
:
20787 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20789 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20790 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20791 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20792 || cu
->language
== language_ada
20793 || cu
->language
== language_fortran
)
20795 /* Subprograms marked external are stored as a global symbol.
20796 Ada and Fortran subprograms, whether marked external or
20797 not, are always stored as a global symbol, because we want
20798 to be able to access them globally. For instance, we want
20799 to be able to break on a nested subprogram without having
20800 to specify the context. */
20801 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20805 list_to_add
= cu
->list_in_scope
;
20808 case DW_TAG_inlined_subroutine
:
20809 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20811 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20812 SYMBOL_INLINED (sym
) = 1;
20813 list_to_add
= cu
->list_in_scope
;
20815 case DW_TAG_template_value_param
:
20817 /* Fall through. */
20818 case DW_TAG_constant
:
20819 case DW_TAG_variable
:
20820 case DW_TAG_member
:
20821 /* Compilation with minimal debug info may result in
20822 variables with missing type entries. Change the
20823 misleading `void' type to something sensible. */
20824 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20825 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20827 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20828 /* In the case of DW_TAG_member, we should only be called for
20829 static const members. */
20830 if (die
->tag
== DW_TAG_member
)
20832 /* dwarf2_add_field uses die_is_declaration,
20833 so we do the same. */
20834 gdb_assert (die_is_declaration (die
, cu
));
20837 if (attr
!= nullptr)
20839 dwarf2_const_value (attr
, sym
, cu
);
20840 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20843 if (attr2
&& (DW_UNSND (attr2
) != 0))
20844 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20846 list_to_add
= cu
->list_in_scope
;
20850 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20851 if (attr
!= nullptr)
20853 var_decode_location (attr
, sym
, cu
);
20854 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20856 /* Fortran explicitly imports any global symbols to the local
20857 scope by DW_TAG_common_block. */
20858 if (cu
->language
== language_fortran
&& die
->parent
20859 && die
->parent
->tag
== DW_TAG_common_block
)
20862 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20863 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20864 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
20866 /* When a static variable is eliminated by the linker,
20867 the corresponding debug information is not stripped
20868 out, but the variable address is set to null;
20869 do not add such variables into symbol table. */
20871 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20873 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20874 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20875 && dwarf2_per_objfile
->per_bfd
->can_copy
)
20877 /* A global static variable might be subject to
20878 copy relocation. We first check for a local
20879 minsym, though, because maybe the symbol was
20880 marked hidden, in which case this would not
20882 bound_minimal_symbol found
20883 = (lookup_minimal_symbol_linkage
20884 (sym
->linkage_name (), objfile
));
20885 if (found
.minsym
!= nullptr)
20886 sym
->maybe_copied
= 1;
20889 /* A variable with DW_AT_external is never static,
20890 but it may be block-scoped. */
20892 = ((cu
->list_in_scope
20893 == cu
->get_builder ()->get_file_symbols ())
20894 ? cu
->get_builder ()->get_global_symbols ()
20895 : cu
->list_in_scope
);
20898 list_to_add
= cu
->list_in_scope
;
20902 /* We do not know the address of this symbol.
20903 If it is an external symbol and we have type information
20904 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20905 The address of the variable will then be determined from
20906 the minimal symbol table whenever the variable is
20908 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20910 /* Fortran explicitly imports any global symbols to the local
20911 scope by DW_TAG_common_block. */
20912 if (cu
->language
== language_fortran
&& die
->parent
20913 && die
->parent
->tag
== DW_TAG_common_block
)
20915 /* SYMBOL_CLASS doesn't matter here because
20916 read_common_block is going to reset it. */
20918 list_to_add
= cu
->list_in_scope
;
20920 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20921 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20923 /* A variable with DW_AT_external is never static, but it
20924 may be block-scoped. */
20926 = ((cu
->list_in_scope
20927 == cu
->get_builder ()->get_file_symbols ())
20928 ? cu
->get_builder ()->get_global_symbols ()
20929 : cu
->list_in_scope
);
20931 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20933 else if (!die_is_declaration (die
, cu
))
20935 /* Use the default LOC_OPTIMIZED_OUT class. */
20936 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20938 list_to_add
= cu
->list_in_scope
;
20942 case DW_TAG_formal_parameter
:
20944 /* If we are inside a function, mark this as an argument. If
20945 not, we might be looking at an argument to an inlined function
20946 when we do not have enough information to show inlined frames;
20947 pretend it's a local variable in that case so that the user can
20949 struct context_stack
*curr
20950 = cu
->get_builder ()->get_current_context_stack ();
20951 if (curr
!= nullptr && curr
->name
!= nullptr)
20952 SYMBOL_IS_ARGUMENT (sym
) = 1;
20953 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20954 if (attr
!= nullptr)
20956 var_decode_location (attr
, sym
, cu
);
20958 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20959 if (attr
!= nullptr)
20961 dwarf2_const_value (attr
, sym
, cu
);
20964 list_to_add
= cu
->list_in_scope
;
20967 case DW_TAG_unspecified_parameters
:
20968 /* From varargs functions; gdb doesn't seem to have any
20969 interest in this information, so just ignore it for now.
20972 case DW_TAG_template_type_param
:
20974 /* Fall through. */
20975 case DW_TAG_class_type
:
20976 case DW_TAG_interface_type
:
20977 case DW_TAG_structure_type
:
20978 case DW_TAG_union_type
:
20979 case DW_TAG_set_type
:
20980 case DW_TAG_enumeration_type
:
20981 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20982 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20985 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20986 really ever be static objects: otherwise, if you try
20987 to, say, break of a class's method and you're in a file
20988 which doesn't mention that class, it won't work unless
20989 the check for all static symbols in lookup_symbol_aux
20990 saves you. See the OtherFileClass tests in
20991 gdb.c++/namespace.exp. */
20995 buildsym_compunit
*builder
= cu
->get_builder ();
20997 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20998 && cu
->language
== language_cplus
20999 ? builder
->get_global_symbols ()
21000 : cu
->list_in_scope
);
21002 /* The semantics of C++ state that "struct foo {
21003 ... }" also defines a typedef for "foo". */
21004 if (cu
->language
== language_cplus
21005 || cu
->language
== language_ada
21006 || cu
->language
== language_d
21007 || cu
->language
== language_rust
)
21009 /* The symbol's name is already allocated along
21010 with this objfile, so we don't need to
21011 duplicate it for the type. */
21012 if (SYMBOL_TYPE (sym
)->name () == 0)
21013 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21018 case DW_TAG_typedef
:
21019 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21020 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21021 list_to_add
= cu
->list_in_scope
;
21023 case DW_TAG_base_type
:
21024 case DW_TAG_subrange_type
:
21025 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21026 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21027 list_to_add
= cu
->list_in_scope
;
21029 case DW_TAG_enumerator
:
21030 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21031 if (attr
!= nullptr)
21033 dwarf2_const_value (attr
, sym
, cu
);
21036 /* NOTE: carlton/2003-11-10: See comment above in the
21037 DW_TAG_class_type, etc. block. */
21040 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21041 && cu
->language
== language_cplus
21042 ? cu
->get_builder ()->get_global_symbols ()
21043 : cu
->list_in_scope
);
21046 case DW_TAG_imported_declaration
:
21047 case DW_TAG_namespace
:
21048 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21049 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21051 case DW_TAG_module
:
21052 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21053 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21054 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21056 case DW_TAG_common_block
:
21057 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21058 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21059 add_symbol_to_list (sym
, cu
->list_in_scope
);
21062 /* Not a tag we recognize. Hopefully we aren't processing
21063 trash data, but since we must specifically ignore things
21064 we don't recognize, there is nothing else we should do at
21066 complaint (_("unsupported tag: '%s'"),
21067 dwarf_tag_name (die
->tag
));
21073 sym
->hash_next
= objfile
->template_symbols
;
21074 objfile
->template_symbols
= sym
;
21075 list_to_add
= NULL
;
21078 if (list_to_add
!= NULL
)
21079 add_symbol_to_list (sym
, list_to_add
);
21081 /* For the benefit of old versions of GCC, check for anonymous
21082 namespaces based on the demangled name. */
21083 if (!cu
->processing_has_namespace_info
21084 && cu
->language
== language_cplus
)
21085 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21090 /* Given an attr with a DW_FORM_dataN value in host byte order,
21091 zero-extend it as appropriate for the symbol's type. The DWARF
21092 standard (v4) is not entirely clear about the meaning of using
21093 DW_FORM_dataN for a constant with a signed type, where the type is
21094 wider than the data. The conclusion of a discussion on the DWARF
21095 list was that this is unspecified. We choose to always zero-extend
21096 because that is the interpretation long in use by GCC. */
21099 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21100 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21102 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21103 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21104 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21105 LONGEST l
= DW_UNSND (attr
);
21107 if (bits
< sizeof (*value
) * 8)
21109 l
&= ((LONGEST
) 1 << bits
) - 1;
21112 else if (bits
== sizeof (*value
) * 8)
21116 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21117 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21124 /* Read a constant value from an attribute. Either set *VALUE, or if
21125 the value does not fit in *VALUE, set *BYTES - either already
21126 allocated on the objfile obstack, or newly allocated on OBSTACK,
21127 or, set *BATON, if we translated the constant to a location
21131 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21132 const char *name
, struct obstack
*obstack
,
21133 struct dwarf2_cu
*cu
,
21134 LONGEST
*value
, const gdb_byte
**bytes
,
21135 struct dwarf2_locexpr_baton
**baton
)
21137 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21138 struct objfile
*objfile
= per_objfile
->objfile
;
21139 struct comp_unit_head
*cu_header
= &cu
->header
;
21140 struct dwarf_block
*blk
;
21141 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21142 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21148 switch (attr
->form
)
21151 case DW_FORM_addrx
:
21152 case DW_FORM_GNU_addr_index
:
21156 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21157 dwarf2_const_value_length_mismatch_complaint (name
,
21158 cu_header
->addr_size
,
21159 TYPE_LENGTH (type
));
21160 /* Symbols of this form are reasonably rare, so we just
21161 piggyback on the existing location code rather than writing
21162 a new implementation of symbol_computed_ops. */
21163 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21164 (*baton
)->per_objfile
= per_objfile
;
21165 (*baton
)->per_cu
= cu
->per_cu
;
21166 gdb_assert ((*baton
)->per_cu
);
21168 (*baton
)->size
= 2 + cu_header
->addr_size
;
21169 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21170 (*baton
)->data
= data
;
21172 data
[0] = DW_OP_addr
;
21173 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21174 byte_order
, DW_ADDR (attr
));
21175 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21178 case DW_FORM_string
:
21181 case DW_FORM_GNU_str_index
:
21182 case DW_FORM_GNU_strp_alt
:
21183 /* DW_STRING is already allocated on the objfile obstack, point
21185 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21187 case DW_FORM_block1
:
21188 case DW_FORM_block2
:
21189 case DW_FORM_block4
:
21190 case DW_FORM_block
:
21191 case DW_FORM_exprloc
:
21192 case DW_FORM_data16
:
21193 blk
= DW_BLOCK (attr
);
21194 if (TYPE_LENGTH (type
) != blk
->size
)
21195 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21196 TYPE_LENGTH (type
));
21197 *bytes
= blk
->data
;
21200 /* The DW_AT_const_value attributes are supposed to carry the
21201 symbol's value "represented as it would be on the target
21202 architecture." By the time we get here, it's already been
21203 converted to host endianness, so we just need to sign- or
21204 zero-extend it as appropriate. */
21205 case DW_FORM_data1
:
21206 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21208 case DW_FORM_data2
:
21209 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21211 case DW_FORM_data4
:
21212 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21214 case DW_FORM_data8
:
21215 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21218 case DW_FORM_sdata
:
21219 case DW_FORM_implicit_const
:
21220 *value
= DW_SND (attr
);
21223 case DW_FORM_udata
:
21224 *value
= DW_UNSND (attr
);
21228 complaint (_("unsupported const value attribute form: '%s'"),
21229 dwarf_form_name (attr
->form
));
21236 /* Copy constant value from an attribute to a symbol. */
21239 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21240 struct dwarf2_cu
*cu
)
21242 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21244 const gdb_byte
*bytes
;
21245 struct dwarf2_locexpr_baton
*baton
;
21247 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21248 sym
->print_name (),
21249 &objfile
->objfile_obstack
, cu
,
21250 &value
, &bytes
, &baton
);
21254 SYMBOL_LOCATION_BATON (sym
) = baton
;
21255 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21257 else if (bytes
!= NULL
)
21259 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21260 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21264 SYMBOL_VALUE (sym
) = value
;
21265 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21269 /* Return the type of the die in question using its DW_AT_type attribute. */
21271 static struct type
*
21272 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21274 struct attribute
*type_attr
;
21276 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21279 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21280 /* A missing DW_AT_type represents a void type. */
21281 return objfile_type (objfile
)->builtin_void
;
21284 return lookup_die_type (die
, type_attr
, cu
);
21287 /* True iff CU's producer generates GNAT Ada auxiliary information
21288 that allows to find parallel types through that information instead
21289 of having to do expensive parallel lookups by type name. */
21292 need_gnat_info (struct dwarf2_cu
*cu
)
21294 /* Assume that the Ada compiler was GNAT, which always produces
21295 the auxiliary information. */
21296 return (cu
->language
== language_ada
);
21299 /* Return the auxiliary type of the die in question using its
21300 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21301 attribute is not present. */
21303 static struct type
*
21304 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21306 struct attribute
*type_attr
;
21308 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21312 return lookup_die_type (die
, type_attr
, cu
);
21315 /* If DIE has a descriptive_type attribute, then set the TYPE's
21316 descriptive type accordingly. */
21319 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21320 struct dwarf2_cu
*cu
)
21322 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21324 if (descriptive_type
)
21326 ALLOCATE_GNAT_AUX_TYPE (type
);
21327 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21331 /* Return the containing type of the die in question using its
21332 DW_AT_containing_type attribute. */
21334 static struct type
*
21335 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21337 struct attribute
*type_attr
;
21338 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21340 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21342 error (_("Dwarf Error: Problem turning containing type into gdb type "
21343 "[in module %s]"), objfile_name (objfile
));
21345 return lookup_die_type (die
, type_attr
, cu
);
21348 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21350 static struct type
*
21351 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21353 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21354 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21357 std::string message
21358 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21359 objfile_name (objfile
),
21360 sect_offset_str (cu
->header
.sect_off
),
21361 sect_offset_str (die
->sect_off
));
21362 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21364 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21367 /* Look up the type of DIE in CU using its type attribute ATTR.
21368 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21369 DW_AT_containing_type.
21370 If there is no type substitute an error marker. */
21372 static struct type
*
21373 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21374 struct dwarf2_cu
*cu
)
21376 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21377 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21378 struct type
*this_type
;
21380 gdb_assert (attr
->name
== DW_AT_type
21381 || attr
->name
== DW_AT_GNAT_descriptive_type
21382 || attr
->name
== DW_AT_containing_type
);
21384 /* First see if we have it cached. */
21386 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21388 struct dwarf2_per_cu_data
*per_cu
;
21389 sect_offset sect_off
= attr
->get_ref_die_offset ();
21391 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21392 dwarf2_per_objfile
);
21393 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21395 else if (attr
->form_is_ref ())
21397 sect_offset sect_off
= attr
->get_ref_die_offset ();
21399 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21401 else if (attr
->form
== DW_FORM_ref_sig8
)
21403 ULONGEST signature
= DW_SIGNATURE (attr
);
21405 return get_signatured_type (die
, signature
, cu
);
21409 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21410 " at %s [in module %s]"),
21411 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21412 objfile_name (objfile
));
21413 return build_error_marker_type (cu
, die
);
21416 /* If not cached we need to read it in. */
21418 if (this_type
== NULL
)
21420 struct die_info
*type_die
= NULL
;
21421 struct dwarf2_cu
*type_cu
= cu
;
21423 if (attr
->form_is_ref ())
21424 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21425 if (type_die
== NULL
)
21426 return build_error_marker_type (cu
, die
);
21427 /* If we find the type now, it's probably because the type came
21428 from an inter-CU reference and the type's CU got expanded before
21430 this_type
= read_type_die (type_die
, type_cu
);
21433 /* If we still don't have a type use an error marker. */
21435 if (this_type
== NULL
)
21436 return build_error_marker_type (cu
, die
);
21441 /* Return the type in DIE, CU.
21442 Returns NULL for invalid types.
21444 This first does a lookup in die_type_hash,
21445 and only reads the die in if necessary.
21447 NOTE: This can be called when reading in partial or full symbols. */
21449 static struct type
*
21450 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21452 struct type
*this_type
;
21454 this_type
= get_die_type (die
, cu
);
21458 return read_type_die_1 (die
, cu
);
21461 /* Read the type in DIE, CU.
21462 Returns NULL for invalid types. */
21464 static struct type
*
21465 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21467 struct type
*this_type
= NULL
;
21471 case DW_TAG_class_type
:
21472 case DW_TAG_interface_type
:
21473 case DW_TAG_structure_type
:
21474 case DW_TAG_union_type
:
21475 this_type
= read_structure_type (die
, cu
);
21477 case DW_TAG_enumeration_type
:
21478 this_type
= read_enumeration_type (die
, cu
);
21480 case DW_TAG_subprogram
:
21481 case DW_TAG_subroutine_type
:
21482 case DW_TAG_inlined_subroutine
:
21483 this_type
= read_subroutine_type (die
, cu
);
21485 case DW_TAG_array_type
:
21486 this_type
= read_array_type (die
, cu
);
21488 case DW_TAG_set_type
:
21489 this_type
= read_set_type (die
, cu
);
21491 case DW_TAG_pointer_type
:
21492 this_type
= read_tag_pointer_type (die
, cu
);
21494 case DW_TAG_ptr_to_member_type
:
21495 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21497 case DW_TAG_reference_type
:
21498 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21500 case DW_TAG_rvalue_reference_type
:
21501 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21503 case DW_TAG_const_type
:
21504 this_type
= read_tag_const_type (die
, cu
);
21506 case DW_TAG_volatile_type
:
21507 this_type
= read_tag_volatile_type (die
, cu
);
21509 case DW_TAG_restrict_type
:
21510 this_type
= read_tag_restrict_type (die
, cu
);
21512 case DW_TAG_string_type
:
21513 this_type
= read_tag_string_type (die
, cu
);
21515 case DW_TAG_typedef
:
21516 this_type
= read_typedef (die
, cu
);
21518 case DW_TAG_subrange_type
:
21519 this_type
= read_subrange_type (die
, cu
);
21521 case DW_TAG_base_type
:
21522 this_type
= read_base_type (die
, cu
);
21524 case DW_TAG_unspecified_type
:
21525 this_type
= read_unspecified_type (die
, cu
);
21527 case DW_TAG_namespace
:
21528 this_type
= read_namespace_type (die
, cu
);
21530 case DW_TAG_module
:
21531 this_type
= read_module_type (die
, cu
);
21533 case DW_TAG_atomic_type
:
21534 this_type
= read_tag_atomic_type (die
, cu
);
21537 complaint (_("unexpected tag in read_type_die: '%s'"),
21538 dwarf_tag_name (die
->tag
));
21545 /* See if we can figure out if the class lives in a namespace. We do
21546 this by looking for a member function; its demangled name will
21547 contain namespace info, if there is any.
21548 Return the computed name or NULL.
21549 Space for the result is allocated on the objfile's obstack.
21550 This is the full-die version of guess_partial_die_structure_name.
21551 In this case we know DIE has no useful parent. */
21553 static const char *
21554 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21556 struct die_info
*spec_die
;
21557 struct dwarf2_cu
*spec_cu
;
21558 struct die_info
*child
;
21559 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21562 spec_die
= die_specification (die
, &spec_cu
);
21563 if (spec_die
!= NULL
)
21569 for (child
= die
->child
;
21571 child
= child
->sibling
)
21573 if (child
->tag
== DW_TAG_subprogram
)
21575 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21577 if (linkage_name
!= NULL
)
21579 gdb::unique_xmalloc_ptr
<char> actual_name
21580 (language_class_name_from_physname (cu
->language_defn
,
21582 const char *name
= NULL
;
21584 if (actual_name
!= NULL
)
21586 const char *die_name
= dwarf2_name (die
, cu
);
21588 if (die_name
!= NULL
21589 && strcmp (die_name
, actual_name
.get ()) != 0)
21591 /* Strip off the class name from the full name.
21592 We want the prefix. */
21593 int die_name_len
= strlen (die_name
);
21594 int actual_name_len
= strlen (actual_name
.get ());
21595 const char *ptr
= actual_name
.get ();
21597 /* Test for '::' as a sanity check. */
21598 if (actual_name_len
> die_name_len
+ 2
21599 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21600 name
= obstack_strndup (
21601 &objfile
->per_bfd
->storage_obstack
,
21602 ptr
, actual_name_len
- die_name_len
- 2);
21613 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21614 prefix part in such case. See
21615 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21617 static const char *
21618 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21620 struct attribute
*attr
;
21623 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21624 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21627 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21630 attr
= dw2_linkage_name_attr (die
, cu
);
21631 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21634 /* dwarf2_name had to be already called. */
21635 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21637 /* Strip the base name, keep any leading namespaces/classes. */
21638 base
= strrchr (DW_STRING (attr
), ':');
21639 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21642 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21643 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21645 &base
[-1] - DW_STRING (attr
));
21648 /* Return the name of the namespace/class that DIE is defined within,
21649 or "" if we can't tell. The caller should not xfree the result.
21651 For example, if we're within the method foo() in the following
21661 then determine_prefix on foo's die will return "N::C". */
21663 static const char *
21664 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21666 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21667 struct die_info
*parent
, *spec_die
;
21668 struct dwarf2_cu
*spec_cu
;
21669 struct type
*parent_type
;
21670 const char *retval
;
21672 if (cu
->language
!= language_cplus
21673 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21674 && cu
->language
!= language_rust
)
21677 retval
= anonymous_struct_prefix (die
, cu
);
21681 /* We have to be careful in the presence of DW_AT_specification.
21682 For example, with GCC 3.4, given the code
21686 // Definition of N::foo.
21690 then we'll have a tree of DIEs like this:
21692 1: DW_TAG_compile_unit
21693 2: DW_TAG_namespace // N
21694 3: DW_TAG_subprogram // declaration of N::foo
21695 4: DW_TAG_subprogram // definition of N::foo
21696 DW_AT_specification // refers to die #3
21698 Thus, when processing die #4, we have to pretend that we're in
21699 the context of its DW_AT_specification, namely the contex of die
21702 spec_die
= die_specification (die
, &spec_cu
);
21703 if (spec_die
== NULL
)
21704 parent
= die
->parent
;
21707 parent
= spec_die
->parent
;
21711 if (parent
== NULL
)
21713 else if (parent
->building_fullname
)
21716 const char *parent_name
;
21718 /* It has been seen on RealView 2.2 built binaries,
21719 DW_TAG_template_type_param types actually _defined_ as
21720 children of the parent class:
21723 template class <class Enum> Class{};
21724 Class<enum E> class_e;
21726 1: DW_TAG_class_type (Class)
21727 2: DW_TAG_enumeration_type (E)
21728 3: DW_TAG_enumerator (enum1:0)
21729 3: DW_TAG_enumerator (enum2:1)
21731 2: DW_TAG_template_type_param
21732 DW_AT_type DW_FORM_ref_udata (E)
21734 Besides being broken debug info, it can put GDB into an
21735 infinite loop. Consider:
21737 When we're building the full name for Class<E>, we'll start
21738 at Class, and go look over its template type parameters,
21739 finding E. We'll then try to build the full name of E, and
21740 reach here. We're now trying to build the full name of E,
21741 and look over the parent DIE for containing scope. In the
21742 broken case, if we followed the parent DIE of E, we'd again
21743 find Class, and once again go look at its template type
21744 arguments, etc., etc. Simply don't consider such parent die
21745 as source-level parent of this die (it can't be, the language
21746 doesn't allow it), and break the loop here. */
21747 name
= dwarf2_name (die
, cu
);
21748 parent_name
= dwarf2_name (parent
, cu
);
21749 complaint (_("template param type '%s' defined within parent '%s'"),
21750 name
? name
: "<unknown>",
21751 parent_name
? parent_name
: "<unknown>");
21755 switch (parent
->tag
)
21757 case DW_TAG_namespace
:
21758 parent_type
= read_type_die (parent
, cu
);
21759 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21760 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21761 Work around this problem here. */
21762 if (cu
->language
== language_cplus
21763 && strcmp (parent_type
->name (), "::") == 0)
21765 /* We give a name to even anonymous namespaces. */
21766 return parent_type
->name ();
21767 case DW_TAG_class_type
:
21768 case DW_TAG_interface_type
:
21769 case DW_TAG_structure_type
:
21770 case DW_TAG_union_type
:
21771 case DW_TAG_module
:
21772 parent_type
= read_type_die (parent
, cu
);
21773 if (parent_type
->name () != NULL
)
21774 return parent_type
->name ();
21776 /* An anonymous structure is only allowed non-static data
21777 members; no typedefs, no member functions, et cetera.
21778 So it does not need a prefix. */
21780 case DW_TAG_compile_unit
:
21781 case DW_TAG_partial_unit
:
21782 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21783 if (cu
->language
== language_cplus
21784 && !dwarf2_per_objfile
->per_bfd
->types
.empty ()
21785 && die
->child
!= NULL
21786 && (die
->tag
== DW_TAG_class_type
21787 || die
->tag
== DW_TAG_structure_type
21788 || die
->tag
== DW_TAG_union_type
))
21790 const char *name
= guess_full_die_structure_name (die
, cu
);
21795 case DW_TAG_subprogram
:
21796 /* Nested subroutines in Fortran get a prefix with the name
21797 of the parent's subroutine. */
21798 if (cu
->language
== language_fortran
)
21800 if ((die
->tag
== DW_TAG_subprogram
)
21801 && (dwarf2_name (parent
, cu
) != NULL
))
21802 return dwarf2_name (parent
, cu
);
21804 return determine_prefix (parent
, cu
);
21805 case DW_TAG_enumeration_type
:
21806 parent_type
= read_type_die (parent
, cu
);
21807 if (TYPE_DECLARED_CLASS (parent_type
))
21809 if (parent_type
->name () != NULL
)
21810 return parent_type
->name ();
21813 /* Fall through. */
21815 return determine_prefix (parent
, cu
);
21819 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21820 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21821 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21822 an obconcat, otherwise allocate storage for the result. The CU argument is
21823 used to determine the language and hence, the appropriate separator. */
21825 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21828 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21829 int physname
, struct dwarf2_cu
*cu
)
21831 const char *lead
= "";
21834 if (suffix
== NULL
|| suffix
[0] == '\0'
21835 || prefix
== NULL
|| prefix
[0] == '\0')
21837 else if (cu
->language
== language_d
)
21839 /* For D, the 'main' function could be defined in any module, but it
21840 should never be prefixed. */
21841 if (strcmp (suffix
, "D main") == 0)
21849 else if (cu
->language
== language_fortran
&& physname
)
21851 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21852 DW_AT_MIPS_linkage_name is preferred and used instead. */
21860 if (prefix
== NULL
)
21862 if (suffix
== NULL
)
21869 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21871 strcpy (retval
, lead
);
21872 strcat (retval
, prefix
);
21873 strcat (retval
, sep
);
21874 strcat (retval
, suffix
);
21879 /* We have an obstack. */
21880 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21884 /* Get name of a die, return NULL if not found. */
21886 static const char *
21887 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21888 struct objfile
*objfile
)
21890 if (name
&& cu
->language
== language_cplus
)
21892 gdb::unique_xmalloc_ptr
<char> canon_name
21893 = cp_canonicalize_string (name
);
21895 if (canon_name
!= nullptr)
21896 name
= objfile
->intern (canon_name
.get ());
21902 /* Get name of a die, return NULL if not found.
21903 Anonymous namespaces are converted to their magic string. */
21905 static const char *
21906 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21908 struct attribute
*attr
;
21909 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21911 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21912 if ((!attr
|| !DW_STRING (attr
))
21913 && die
->tag
!= DW_TAG_namespace
21914 && die
->tag
!= DW_TAG_class_type
21915 && die
->tag
!= DW_TAG_interface_type
21916 && die
->tag
!= DW_TAG_structure_type
21917 && die
->tag
!= DW_TAG_union_type
)
21922 case DW_TAG_compile_unit
:
21923 case DW_TAG_partial_unit
:
21924 /* Compilation units have a DW_AT_name that is a filename, not
21925 a source language identifier. */
21926 case DW_TAG_enumeration_type
:
21927 case DW_TAG_enumerator
:
21928 /* These tags always have simple identifiers already; no need
21929 to canonicalize them. */
21930 return DW_STRING (attr
);
21932 case DW_TAG_namespace
:
21933 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21934 return DW_STRING (attr
);
21935 return CP_ANONYMOUS_NAMESPACE_STR
;
21937 case DW_TAG_class_type
:
21938 case DW_TAG_interface_type
:
21939 case DW_TAG_structure_type
:
21940 case DW_TAG_union_type
:
21941 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21942 structures or unions. These were of the form "._%d" in GCC 4.1,
21943 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21944 and GCC 4.4. We work around this problem by ignoring these. */
21945 if (attr
&& DW_STRING (attr
)
21946 && (startswith (DW_STRING (attr
), "._")
21947 || startswith (DW_STRING (attr
), "<anonymous")))
21950 /* GCC might emit a nameless typedef that has a linkage name. See
21951 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21952 if (!attr
|| DW_STRING (attr
) == NULL
)
21954 attr
= dw2_linkage_name_attr (die
, cu
);
21955 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21958 /* Avoid demangling DW_STRING (attr) the second time on a second
21959 call for the same DIE. */
21960 if (!DW_STRING_IS_CANONICAL (attr
))
21962 gdb::unique_xmalloc_ptr
<char> demangled
21963 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21964 if (demangled
== nullptr)
21967 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21968 DW_STRING_IS_CANONICAL (attr
) = 1;
21971 /* Strip any leading namespaces/classes, keep only the base name.
21972 DW_AT_name for named DIEs does not contain the prefixes. */
21973 const char *base
= strrchr (DW_STRING (attr
), ':');
21974 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21977 return DW_STRING (attr
);
21985 if (!DW_STRING_IS_CANONICAL (attr
))
21987 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21989 DW_STRING_IS_CANONICAL (attr
) = 1;
21991 return DW_STRING (attr
);
21994 /* Return the die that this die in an extension of, or NULL if there
21995 is none. *EXT_CU is the CU containing DIE on input, and the CU
21996 containing the return value on output. */
21998 static struct die_info
*
21999 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22001 struct attribute
*attr
;
22003 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22007 return follow_die_ref (die
, attr
, ext_cu
);
22011 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22015 print_spaces (indent
, f
);
22016 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22017 dwarf_tag_name (die
->tag
), die
->abbrev
,
22018 sect_offset_str (die
->sect_off
));
22020 if (die
->parent
!= NULL
)
22022 print_spaces (indent
, f
);
22023 fprintf_unfiltered (f
, " parent at offset: %s\n",
22024 sect_offset_str (die
->parent
->sect_off
));
22027 print_spaces (indent
, f
);
22028 fprintf_unfiltered (f
, " has children: %s\n",
22029 dwarf_bool_name (die
->child
!= NULL
));
22031 print_spaces (indent
, f
);
22032 fprintf_unfiltered (f
, " attributes:\n");
22034 for (i
= 0; i
< die
->num_attrs
; ++i
)
22036 print_spaces (indent
, f
);
22037 fprintf_unfiltered (f
, " %s (%s) ",
22038 dwarf_attr_name (die
->attrs
[i
].name
),
22039 dwarf_form_name (die
->attrs
[i
].form
));
22041 switch (die
->attrs
[i
].form
)
22044 case DW_FORM_addrx
:
22045 case DW_FORM_GNU_addr_index
:
22046 fprintf_unfiltered (f
, "address: ");
22047 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22049 case DW_FORM_block2
:
22050 case DW_FORM_block4
:
22051 case DW_FORM_block
:
22052 case DW_FORM_block1
:
22053 fprintf_unfiltered (f
, "block: size %s",
22054 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22056 case DW_FORM_exprloc
:
22057 fprintf_unfiltered (f
, "expression: size %s",
22058 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22060 case DW_FORM_data16
:
22061 fprintf_unfiltered (f
, "constant of 16 bytes");
22063 case DW_FORM_ref_addr
:
22064 fprintf_unfiltered (f
, "ref address: ");
22065 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22067 case DW_FORM_GNU_ref_alt
:
22068 fprintf_unfiltered (f
, "alt ref address: ");
22069 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22075 case DW_FORM_ref_udata
:
22076 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22077 (long) (DW_UNSND (&die
->attrs
[i
])));
22079 case DW_FORM_data1
:
22080 case DW_FORM_data2
:
22081 case DW_FORM_data4
:
22082 case DW_FORM_data8
:
22083 case DW_FORM_udata
:
22084 case DW_FORM_sdata
:
22085 fprintf_unfiltered (f
, "constant: %s",
22086 pulongest (DW_UNSND (&die
->attrs
[i
])));
22088 case DW_FORM_sec_offset
:
22089 fprintf_unfiltered (f
, "section offset: %s",
22090 pulongest (DW_UNSND (&die
->attrs
[i
])));
22092 case DW_FORM_ref_sig8
:
22093 fprintf_unfiltered (f
, "signature: %s",
22094 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22096 case DW_FORM_string
:
22098 case DW_FORM_line_strp
:
22100 case DW_FORM_GNU_str_index
:
22101 case DW_FORM_GNU_strp_alt
:
22102 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22103 DW_STRING (&die
->attrs
[i
])
22104 ? DW_STRING (&die
->attrs
[i
]) : "",
22105 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22108 if (DW_UNSND (&die
->attrs
[i
]))
22109 fprintf_unfiltered (f
, "flag: TRUE");
22111 fprintf_unfiltered (f
, "flag: FALSE");
22113 case DW_FORM_flag_present
:
22114 fprintf_unfiltered (f
, "flag: TRUE");
22116 case DW_FORM_indirect
:
22117 /* The reader will have reduced the indirect form to
22118 the "base form" so this form should not occur. */
22119 fprintf_unfiltered (f
,
22120 "unexpected attribute form: DW_FORM_indirect");
22122 case DW_FORM_implicit_const
:
22123 fprintf_unfiltered (f
, "constant: %s",
22124 plongest (DW_SND (&die
->attrs
[i
])));
22127 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22128 die
->attrs
[i
].form
);
22131 fprintf_unfiltered (f
, "\n");
22136 dump_die_for_error (struct die_info
*die
)
22138 dump_die_shallow (gdb_stderr
, 0, die
);
22142 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22144 int indent
= level
* 4;
22146 gdb_assert (die
!= NULL
);
22148 if (level
>= max_level
)
22151 dump_die_shallow (f
, indent
, die
);
22153 if (die
->child
!= NULL
)
22155 print_spaces (indent
, f
);
22156 fprintf_unfiltered (f
, " Children:");
22157 if (level
+ 1 < max_level
)
22159 fprintf_unfiltered (f
, "\n");
22160 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22164 fprintf_unfiltered (f
,
22165 " [not printed, max nesting level reached]\n");
22169 if (die
->sibling
!= NULL
&& level
> 0)
22171 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22175 /* This is called from the pdie macro in gdbinit.in.
22176 It's not static so gcc will keep a copy callable from gdb. */
22179 dump_die (struct die_info
*die
, int max_level
)
22181 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22185 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22189 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22190 to_underlying (die
->sect_off
),
22196 /* Follow reference or signature attribute ATTR of SRC_DIE.
22197 On entry *REF_CU is the CU of SRC_DIE.
22198 On exit *REF_CU is the CU of the result. */
22200 static struct die_info
*
22201 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22202 struct dwarf2_cu
**ref_cu
)
22204 struct die_info
*die
;
22206 if (attr
->form_is_ref ())
22207 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22208 else if (attr
->form
== DW_FORM_ref_sig8
)
22209 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22212 dump_die_for_error (src_die
);
22213 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22214 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22220 /* Follow reference OFFSET.
22221 On entry *REF_CU is the CU of the source die referencing OFFSET.
22222 On exit *REF_CU is the CU of the result.
22223 Returns NULL if OFFSET is invalid. */
22225 static struct die_info
*
22226 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22227 struct dwarf2_cu
**ref_cu
)
22229 struct die_info temp_die
;
22230 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22231 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22233 gdb_assert (cu
->per_cu
!= NULL
);
22237 if (cu
->per_cu
->is_debug_types
)
22239 /* .debug_types CUs cannot reference anything outside their CU.
22240 If they need to, they have to reference a signatured type via
22241 DW_FORM_ref_sig8. */
22242 if (!cu
->header
.offset_in_cu_p (sect_off
))
22245 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22246 || !cu
->header
.offset_in_cu_p (sect_off
))
22248 struct dwarf2_per_cu_data
*per_cu
;
22250 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22251 dwarf2_per_objfile
);
22253 /* If necessary, add it to the queue and load its DIEs. */
22254 if (maybe_queue_comp_unit (cu
, per_cu
, dwarf2_per_objfile
, cu
->language
))
22255 load_full_comp_unit (per_cu
, dwarf2_per_objfile
, false, cu
->language
);
22257 target_cu
= per_cu
->cu
;
22259 else if (cu
->dies
== NULL
)
22261 /* We're loading full DIEs during partial symbol reading. */
22262 gdb_assert (dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
);
22263 load_full_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, false,
22267 *ref_cu
= target_cu
;
22268 temp_die
.sect_off
= sect_off
;
22270 if (target_cu
!= cu
)
22271 target_cu
->ancestor
= cu
;
22273 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22275 to_underlying (sect_off
));
22278 /* Follow reference attribute ATTR of SRC_DIE.
22279 On entry *REF_CU is the CU of SRC_DIE.
22280 On exit *REF_CU is the CU of the result. */
22282 static struct die_info
*
22283 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22284 struct dwarf2_cu
**ref_cu
)
22286 sect_offset sect_off
= attr
->get_ref_die_offset ();
22287 struct dwarf2_cu
*cu
= *ref_cu
;
22288 struct die_info
*die
;
22290 die
= follow_die_offset (sect_off
,
22291 (attr
->form
== DW_FORM_GNU_ref_alt
22292 || cu
->per_cu
->is_dwz
),
22295 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22296 "at %s [in module %s]"),
22297 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22298 objfile_name (cu
->per_objfile
->objfile
));
22305 struct dwarf2_locexpr_baton
22306 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22307 dwarf2_per_cu_data
*per_cu
,
22308 dwarf2_per_objfile
*dwarf2_per_objfile
,
22309 CORE_ADDR (*get_frame_pc
) (void *baton
),
22310 void *baton
, bool resolve_abstract_p
)
22312 struct dwarf2_cu
*cu
;
22313 struct die_info
*die
;
22314 struct attribute
*attr
;
22315 struct dwarf2_locexpr_baton retval
;
22316 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22318 if (per_cu
->cu
== NULL
)
22319 load_cu (per_cu
, dwarf2_per_objfile
, false);
22323 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22324 Instead just throw an error, not much else we can do. */
22325 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22326 sect_offset_str (sect_off
), objfile_name (objfile
));
22329 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22331 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22332 sect_offset_str (sect_off
), objfile_name (objfile
));
22334 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22335 if (!attr
&& resolve_abstract_p
22336 && (dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22337 != dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22339 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22340 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22341 struct gdbarch
*gdbarch
= objfile
->arch ();
22343 for (const auto &cand_off
22344 : dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22346 struct dwarf2_cu
*cand_cu
= cu
;
22347 struct die_info
*cand
22348 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22351 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22354 CORE_ADDR pc_low
, pc_high
;
22355 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22356 if (pc_low
== ((CORE_ADDR
) -1))
22358 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22359 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22360 if (!(pc_low
<= pc
&& pc
< pc_high
))
22364 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22371 /* DWARF: "If there is no such attribute, then there is no effect.".
22372 DATA is ignored if SIZE is 0. */
22374 retval
.data
= NULL
;
22377 else if (attr
->form_is_section_offset ())
22379 struct dwarf2_loclist_baton loclist_baton
;
22380 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22383 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22385 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22387 retval
.size
= size
;
22391 if (!attr
->form_is_block ())
22392 error (_("Dwarf Error: DIE at %s referenced in module %s "
22393 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22394 sect_offset_str (sect_off
), objfile_name (objfile
));
22396 retval
.data
= DW_BLOCK (attr
)->data
;
22397 retval
.size
= DW_BLOCK (attr
)->size
;
22399 retval
.per_objfile
= dwarf2_per_objfile
;
22400 retval
.per_cu
= cu
->per_cu
;
22402 age_cached_comp_units (dwarf2_per_objfile
);
22409 struct dwarf2_locexpr_baton
22410 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22411 dwarf2_per_cu_data
*per_cu
,
22412 dwarf2_per_objfile
*per_objfile
,
22413 CORE_ADDR (*get_frame_pc
) (void *baton
),
22416 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22418 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22419 get_frame_pc
, baton
);
22422 /* Write a constant of a given type as target-ordered bytes into
22425 static const gdb_byte
*
22426 write_constant_as_bytes (struct obstack
*obstack
,
22427 enum bfd_endian byte_order
,
22434 *len
= TYPE_LENGTH (type
);
22435 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22436 store_unsigned_integer (result
, *len
, byte_order
, value
);
22444 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22445 dwarf2_per_cu_data
*per_cu
,
22446 dwarf2_per_objfile
*per_objfile
,
22450 struct dwarf2_cu
*cu
;
22451 struct die_info
*die
;
22452 struct attribute
*attr
;
22453 const gdb_byte
*result
= NULL
;
22456 enum bfd_endian byte_order
;
22457 struct objfile
*objfile
= per_objfile
->objfile
;
22459 if (per_cu
->cu
== NULL
)
22460 load_cu (per_cu
, per_objfile
, false);
22464 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22465 Instead just throw an error, not much else we can do. */
22466 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22467 sect_offset_str (sect_off
), objfile_name (objfile
));
22470 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22472 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22473 sect_offset_str (sect_off
), objfile_name (objfile
));
22475 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22479 byte_order
= (bfd_big_endian (objfile
->obfd
)
22480 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22482 switch (attr
->form
)
22485 case DW_FORM_addrx
:
22486 case DW_FORM_GNU_addr_index
:
22490 *len
= cu
->header
.addr_size
;
22491 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22492 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22496 case DW_FORM_string
:
22499 case DW_FORM_GNU_str_index
:
22500 case DW_FORM_GNU_strp_alt
:
22501 /* DW_STRING is already allocated on the objfile obstack, point
22503 result
= (const gdb_byte
*) DW_STRING (attr
);
22504 *len
= strlen (DW_STRING (attr
));
22506 case DW_FORM_block1
:
22507 case DW_FORM_block2
:
22508 case DW_FORM_block4
:
22509 case DW_FORM_block
:
22510 case DW_FORM_exprloc
:
22511 case DW_FORM_data16
:
22512 result
= DW_BLOCK (attr
)->data
;
22513 *len
= DW_BLOCK (attr
)->size
;
22516 /* The DW_AT_const_value attributes are supposed to carry the
22517 symbol's value "represented as it would be on the target
22518 architecture." By the time we get here, it's already been
22519 converted to host endianness, so we just need to sign- or
22520 zero-extend it as appropriate. */
22521 case DW_FORM_data1
:
22522 type
= die_type (die
, cu
);
22523 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22524 if (result
== NULL
)
22525 result
= write_constant_as_bytes (obstack
, byte_order
,
22528 case DW_FORM_data2
:
22529 type
= die_type (die
, cu
);
22530 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22531 if (result
== NULL
)
22532 result
= write_constant_as_bytes (obstack
, byte_order
,
22535 case DW_FORM_data4
:
22536 type
= die_type (die
, cu
);
22537 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22538 if (result
== NULL
)
22539 result
= write_constant_as_bytes (obstack
, byte_order
,
22542 case DW_FORM_data8
:
22543 type
= die_type (die
, cu
);
22544 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22545 if (result
== NULL
)
22546 result
= write_constant_as_bytes (obstack
, byte_order
,
22550 case DW_FORM_sdata
:
22551 case DW_FORM_implicit_const
:
22552 type
= die_type (die
, cu
);
22553 result
= write_constant_as_bytes (obstack
, byte_order
,
22554 type
, DW_SND (attr
), len
);
22557 case DW_FORM_udata
:
22558 type
= die_type (die
, cu
);
22559 result
= write_constant_as_bytes (obstack
, byte_order
,
22560 type
, DW_UNSND (attr
), len
);
22564 complaint (_("unsupported const value attribute form: '%s'"),
22565 dwarf_form_name (attr
->form
));
22575 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22576 dwarf2_per_cu_data
*per_cu
,
22577 dwarf2_per_objfile
*per_objfile
)
22579 struct dwarf2_cu
*cu
;
22580 struct die_info
*die
;
22582 if (per_cu
->cu
== NULL
)
22583 load_cu (per_cu
, per_objfile
, false);
22588 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22592 return die_type (die
, cu
);
22598 dwarf2_get_die_type (cu_offset die_offset
,
22599 struct dwarf2_per_cu_data
*per_cu
)
22601 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22602 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22605 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22606 On entry *REF_CU is the CU of SRC_DIE.
22607 On exit *REF_CU is the CU of the result.
22608 Returns NULL if the referenced DIE isn't found. */
22610 static struct die_info
*
22611 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22612 struct dwarf2_cu
**ref_cu
)
22614 struct die_info temp_die
;
22615 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22616 struct die_info
*die
;
22617 dwarf2_per_objfile
*dwarf2_per_objfile
= (*ref_cu
)->per_objfile
;
22620 /* While it might be nice to assert sig_type->type == NULL here,
22621 we can get here for DW_AT_imported_declaration where we need
22622 the DIE not the type. */
22624 /* If necessary, add it to the queue and load its DIEs. */
22626 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, dwarf2_per_objfile
,
22628 read_signatured_type (sig_type
, dwarf2_per_objfile
);
22630 sig_cu
= sig_type
->per_cu
.cu
;
22631 gdb_assert (sig_cu
!= NULL
);
22632 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22633 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22634 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22635 to_underlying (temp_die
.sect_off
));
22638 /* For .gdb_index version 7 keep track of included TUs.
22639 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22640 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
22641 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7)
22643 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22648 sig_cu
->ancestor
= cu
;
22656 /* Follow signatured type referenced by ATTR in SRC_DIE.
22657 On entry *REF_CU is the CU of SRC_DIE.
22658 On exit *REF_CU is the CU of the result.
22659 The result is the DIE of the type.
22660 If the referenced type cannot be found an error is thrown. */
22662 static struct die_info
*
22663 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22664 struct dwarf2_cu
**ref_cu
)
22666 ULONGEST signature
= DW_SIGNATURE (attr
);
22667 struct signatured_type
*sig_type
;
22668 struct die_info
*die
;
22670 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22672 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22673 /* sig_type will be NULL if the signatured type is missing from
22675 if (sig_type
== NULL
)
22677 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22678 " from DIE at %s [in module %s]"),
22679 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22680 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22683 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22686 dump_die_for_error (src_die
);
22687 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22688 " from DIE at %s [in module %s]"),
22689 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22690 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22696 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22697 reading in and processing the type unit if necessary. */
22699 static struct type
*
22700 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22701 struct dwarf2_cu
*cu
)
22703 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22704 struct signatured_type
*sig_type
;
22705 struct dwarf2_cu
*type_cu
;
22706 struct die_info
*type_die
;
22709 sig_type
= lookup_signatured_type (cu
, signature
);
22710 /* sig_type will be NULL if the signatured type is missing from
22712 if (sig_type
== NULL
)
22714 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22715 " from DIE at %s [in module %s]"),
22716 hex_string (signature
), sect_offset_str (die
->sect_off
),
22717 objfile_name (dwarf2_per_objfile
->objfile
));
22718 return build_error_marker_type (cu
, die
);
22721 /* If we already know the type we're done. */
22722 if (sig_type
->type
!= NULL
)
22723 return sig_type
->type
;
22726 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22727 if (type_die
!= NULL
)
22729 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22730 is created. This is important, for example, because for c++ classes
22731 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22732 type
= read_type_die (type_die
, type_cu
);
22735 complaint (_("Dwarf Error: Cannot build signatured type %s"
22736 " referenced from DIE at %s [in module %s]"),
22737 hex_string (signature
), sect_offset_str (die
->sect_off
),
22738 objfile_name (dwarf2_per_objfile
->objfile
));
22739 type
= build_error_marker_type (cu
, die
);
22744 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22745 " from DIE at %s [in module %s]"),
22746 hex_string (signature
), sect_offset_str (die
->sect_off
),
22747 objfile_name (dwarf2_per_objfile
->objfile
));
22748 type
= build_error_marker_type (cu
, die
);
22750 sig_type
->type
= type
;
22755 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22756 reading in and processing the type unit if necessary. */
22758 static struct type
*
22759 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22760 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22762 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22763 if (attr
->form_is_ref ())
22765 struct dwarf2_cu
*type_cu
= cu
;
22766 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22768 return read_type_die (type_die
, type_cu
);
22770 else if (attr
->form
== DW_FORM_ref_sig8
)
22772 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22776 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22778 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22779 " at %s [in module %s]"),
22780 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22781 objfile_name (dwarf2_per_objfile
->objfile
));
22782 return build_error_marker_type (cu
, die
);
22786 /* Load the DIEs associated with type unit PER_CU into memory. */
22789 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22790 dwarf2_per_objfile
*per_objfile
)
22792 struct signatured_type
*sig_type
;
22794 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22795 gdb_assert (! per_cu
->type_unit_group_p ());
22797 /* We have the per_cu, but we need the signatured_type.
22798 Fortunately this is an easy translation. */
22799 gdb_assert (per_cu
->is_debug_types
);
22800 sig_type
= (struct signatured_type
*) per_cu
;
22802 gdb_assert (per_cu
->cu
== NULL
);
22804 read_signatured_type (sig_type
, per_objfile
);
22806 gdb_assert (per_cu
->cu
!= NULL
);
22809 /* Read in a signatured type and build its CU and DIEs.
22810 If the type is a stub for the real type in a DWO file,
22811 read in the real type from the DWO file as well. */
22814 read_signatured_type (signatured_type
*sig_type
,
22815 dwarf2_per_objfile
*per_objfile
)
22817 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22819 gdb_assert (per_cu
->is_debug_types
);
22820 gdb_assert (per_cu
->cu
== NULL
);
22822 cutu_reader
reader (per_cu
, per_objfile
, NULL
, 0, false);
22824 if (!reader
.dummy_p
)
22826 struct dwarf2_cu
*cu
= reader
.cu
;
22827 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22829 gdb_assert (cu
->die_hash
== NULL
);
22831 htab_create_alloc_ex (cu
->header
.length
/ 12,
22835 &cu
->comp_unit_obstack
,
22836 hashtab_obstack_allocate
,
22837 dummy_obstack_deallocate
);
22839 if (reader
.comp_unit_die
->has_children
)
22840 reader
.comp_unit_die
->child
22841 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22842 reader
.comp_unit_die
);
22843 cu
->dies
= reader
.comp_unit_die
;
22844 /* comp_unit_die is not stored in die_hash, no need. */
22846 /* We try not to read any attributes in this function, because
22847 not all CUs needed for references have been loaded yet, and
22848 symbol table processing isn't initialized. But we have to
22849 set the CU language, or we won't be able to build types
22850 correctly. Similarly, if we do not read the producer, we can
22851 not apply producer-specific interpretation. */
22852 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22857 sig_type
->per_cu
.tu_read
= 1;
22860 /* Decode simple location descriptions.
22861 Given a pointer to a dwarf block that defines a location, compute
22862 the location and return the value. If COMPUTED is non-null, it is
22863 set to true to indicate that decoding was successful, and false
22864 otherwise. If COMPUTED is null, then this function may emit a
22868 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22870 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22872 size_t size
= blk
->size
;
22873 const gdb_byte
*data
= blk
->data
;
22874 CORE_ADDR stack
[64];
22876 unsigned int bytes_read
, unsnd
;
22879 if (computed
!= nullptr)
22885 stack
[++stacki
] = 0;
22924 stack
[++stacki
] = op
- DW_OP_lit0
;
22959 stack
[++stacki
] = op
- DW_OP_reg0
;
22962 if (computed
== nullptr)
22963 dwarf2_complex_location_expr_complaint ();
22970 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22972 stack
[++stacki
] = unsnd
;
22975 if (computed
== nullptr)
22976 dwarf2_complex_location_expr_complaint ();
22983 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22988 case DW_OP_const1u
:
22989 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22993 case DW_OP_const1s
:
22994 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22998 case DW_OP_const2u
:
22999 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23003 case DW_OP_const2s
:
23004 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23008 case DW_OP_const4u
:
23009 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23013 case DW_OP_const4s
:
23014 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23018 case DW_OP_const8u
:
23019 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23024 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23030 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23035 stack
[stacki
+ 1] = stack
[stacki
];
23040 stack
[stacki
- 1] += stack
[stacki
];
23044 case DW_OP_plus_uconst
:
23045 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23051 stack
[stacki
- 1] -= stack
[stacki
];
23056 /* If we're not the last op, then we definitely can't encode
23057 this using GDB's address_class enum. This is valid for partial
23058 global symbols, although the variable's address will be bogus
23062 if (computed
== nullptr)
23063 dwarf2_complex_location_expr_complaint ();
23069 case DW_OP_GNU_push_tls_address
:
23070 case DW_OP_form_tls_address
:
23071 /* The top of the stack has the offset from the beginning
23072 of the thread control block at which the variable is located. */
23073 /* Nothing should follow this operator, so the top of stack would
23075 /* This is valid for partial global symbols, but the variable's
23076 address will be bogus in the psymtab. Make it always at least
23077 non-zero to not look as a variable garbage collected by linker
23078 which have DW_OP_addr 0. */
23081 if (computed
== nullptr)
23082 dwarf2_complex_location_expr_complaint ();
23089 case DW_OP_GNU_uninit
:
23090 if (computed
!= nullptr)
23095 case DW_OP_GNU_addr_index
:
23096 case DW_OP_GNU_const_index
:
23097 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23103 if (computed
== nullptr)
23105 const char *name
= get_DW_OP_name (op
);
23108 complaint (_("unsupported stack op: '%s'"),
23111 complaint (_("unsupported stack op: '%02x'"),
23115 return (stack
[stacki
]);
23118 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23119 outside of the allocated space. Also enforce minimum>0. */
23120 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23122 if (computed
== nullptr)
23123 complaint (_("location description stack overflow"));
23129 if (computed
== nullptr)
23130 complaint (_("location description stack underflow"));
23135 if (computed
!= nullptr)
23137 return (stack
[stacki
]);
23140 /* memory allocation interface */
23142 static struct dwarf_block
*
23143 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23145 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23148 static struct die_info
*
23149 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23151 struct die_info
*die
;
23152 size_t size
= sizeof (struct die_info
);
23155 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23157 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23158 memset (die
, 0, sizeof (struct die_info
));
23164 /* Macro support. */
23166 /* An overload of dwarf_decode_macros that finds the correct section
23167 and ensures it is read in before calling the other overload. */
23170 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23171 int section_is_gnu
)
23173 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23174 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23175 const struct line_header
*lh
= cu
->line_header
;
23176 unsigned int offset_size
= cu
->header
.offset_size
;
23177 struct dwarf2_section_info
*section
;
23178 const char *section_name
;
23180 if (cu
->dwo_unit
!= nullptr)
23182 if (section_is_gnu
)
23184 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23185 section_name
= ".debug_macro.dwo";
23189 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23190 section_name
= ".debug_macinfo.dwo";
23195 if (section_is_gnu
)
23197 section
= &dwarf2_per_objfile
->per_bfd
->macro
;
23198 section_name
= ".debug_macro";
23202 section
= &dwarf2_per_objfile
->per_bfd
->macinfo
;
23203 section_name
= ".debug_macinfo";
23207 section
->read (objfile
);
23208 if (section
->buffer
== nullptr)
23210 complaint (_("missing %s section"), section_name
);
23214 buildsym_compunit
*builder
= cu
->get_builder ();
23216 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23217 offset_size
, offset
, section_is_gnu
);
23220 /* Return the .debug_loc section to use for CU.
23221 For DWO files use .debug_loc.dwo. */
23223 static struct dwarf2_section_info
*
23224 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23226 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23230 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23232 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23234 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->per_bfd
->loclists
23235 : &dwarf2_per_objfile
->per_bfd
->loc
);
23238 /* A helper function that fills in a dwarf2_loclist_baton. */
23241 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23242 struct dwarf2_loclist_baton
*baton
,
23243 const struct attribute
*attr
)
23245 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23246 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23248 section
->read (dwarf2_per_objfile
->objfile
);
23250 baton
->per_objfile
= dwarf2_per_objfile
;
23251 baton
->per_cu
= cu
->per_cu
;
23252 gdb_assert (baton
->per_cu
);
23253 /* We don't know how long the location list is, but make sure we
23254 don't run off the edge of the section. */
23255 baton
->size
= section
->size
- DW_UNSND (attr
);
23256 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23257 if (cu
->base_address
.has_value ())
23258 baton
->base_address
= *cu
->base_address
;
23260 baton
->base_address
= 0;
23261 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23265 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23266 struct dwarf2_cu
*cu
, int is_block
)
23268 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23269 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23270 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23272 if (attr
->form_is_section_offset ()
23273 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23274 the section. If so, fall through to the complaint in the
23276 && DW_UNSND (attr
) < section
->get_size (objfile
))
23278 struct dwarf2_loclist_baton
*baton
;
23280 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23282 fill_in_loclist_baton (cu
, baton
, attr
);
23284 if (!cu
->base_address
.has_value ())
23285 complaint (_("Location list used without "
23286 "specifying the CU base address."));
23288 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23289 ? dwarf2_loclist_block_index
23290 : dwarf2_loclist_index
);
23291 SYMBOL_LOCATION_BATON (sym
) = baton
;
23295 struct dwarf2_locexpr_baton
*baton
;
23297 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23298 baton
->per_objfile
= dwarf2_per_objfile
;
23299 baton
->per_cu
= cu
->per_cu
;
23300 gdb_assert (baton
->per_cu
);
23302 if (attr
->form_is_block ())
23304 /* Note that we're just copying the block's data pointer
23305 here, not the actual data. We're still pointing into the
23306 info_buffer for SYM's objfile; right now we never release
23307 that buffer, but when we do clean up properly this may
23309 baton
->size
= DW_BLOCK (attr
)->size
;
23310 baton
->data
= DW_BLOCK (attr
)->data
;
23314 dwarf2_invalid_attrib_class_complaint ("location description",
23315 sym
->natural_name ());
23319 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23320 ? dwarf2_locexpr_block_index
23321 : dwarf2_locexpr_index
);
23322 SYMBOL_LOCATION_BATON (sym
) = baton
;
23326 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23327 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23328 CU_HEADERP first. */
23330 static const struct comp_unit_head
*
23331 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23332 const struct dwarf2_per_cu_data
*per_cu
)
23334 const gdb_byte
*info_ptr
;
23337 return &per_cu
->cu
->header
;
23339 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23341 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23342 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23343 rcuh_kind::COMPILE
);
23351 dwarf2_per_cu_data::addr_size () const
23353 struct comp_unit_head cu_header_local
;
23354 const struct comp_unit_head
*cu_headerp
;
23356 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23358 return cu_headerp
->addr_size
;
23364 dwarf2_per_cu_data::offset_size () const
23366 struct comp_unit_head cu_header_local
;
23367 const struct comp_unit_head
*cu_headerp
;
23369 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23371 return cu_headerp
->offset_size
;
23377 dwarf2_per_cu_data::ref_addr_size () const
23379 struct comp_unit_head cu_header_local
;
23380 const struct comp_unit_head
*cu_headerp
;
23382 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23384 if (cu_headerp
->version
== 2)
23385 return cu_headerp
->addr_size
;
23387 return cu_headerp
->offset_size
;
23393 dwarf2_cu::addr_type () const
23395 struct objfile
*objfile
= this->per_objfile
->objfile
;
23396 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23397 struct type
*addr_type
= lookup_pointer_type (void_type
);
23398 int addr_size
= this->per_cu
->addr_size ();
23400 if (TYPE_LENGTH (addr_type
) == addr_size
)
23403 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23407 /* A helper function for dwarf2_find_containing_comp_unit that returns
23408 the index of the result, and that searches a vector. It will
23409 return a result even if the offset in question does not actually
23410 occur in any CU. This is separate so that it can be unit
23414 dwarf2_find_containing_comp_unit
23415 (sect_offset sect_off
,
23416 unsigned int offset_in_dwz
,
23417 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23422 high
= all_comp_units
.size () - 1;
23425 struct dwarf2_per_cu_data
*mid_cu
;
23426 int mid
= low
+ (high
- low
) / 2;
23428 mid_cu
= all_comp_units
[mid
];
23429 if (mid_cu
->is_dwz
> offset_in_dwz
23430 || (mid_cu
->is_dwz
== offset_in_dwz
23431 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23436 gdb_assert (low
== high
);
23440 /* Locate the .debug_info compilation unit from CU's objfile which contains
23441 the DIE at OFFSET. Raises an error on failure. */
23443 static struct dwarf2_per_cu_data
*
23444 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23445 unsigned int offset_in_dwz
,
23446 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23449 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23450 dwarf2_per_objfile
->per_bfd
->all_comp_units
);
23451 struct dwarf2_per_cu_data
*this_cu
23452 = dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
];
23454 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23456 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23457 error (_("Dwarf Error: could not find partial DIE containing "
23458 "offset %s [in module %s]"),
23459 sect_offset_str (sect_off
),
23460 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23462 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23464 return dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1];
23468 if (low
== dwarf2_per_objfile
->per_bfd
->all_comp_units
.size () - 1
23469 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23470 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23471 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23478 namespace selftests
{
23479 namespace find_containing_comp_unit
{
23484 struct dwarf2_per_cu_data one
{};
23485 struct dwarf2_per_cu_data two
{};
23486 struct dwarf2_per_cu_data three
{};
23487 struct dwarf2_per_cu_data four
{};
23490 two
.sect_off
= sect_offset (one
.length
);
23495 four
.sect_off
= sect_offset (three
.length
);
23499 std::vector
<dwarf2_per_cu_data
*> units
;
23500 units
.push_back (&one
);
23501 units
.push_back (&two
);
23502 units
.push_back (&three
);
23503 units
.push_back (&four
);
23507 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23508 SELF_CHECK (units
[result
] == &one
);
23509 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23510 SELF_CHECK (units
[result
] == &one
);
23511 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23512 SELF_CHECK (units
[result
] == &two
);
23514 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23515 SELF_CHECK (units
[result
] == &three
);
23516 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23517 SELF_CHECK (units
[result
] == &three
);
23518 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23519 SELF_CHECK (units
[result
] == &four
);
23525 #endif /* GDB_SELF_TEST */
23527 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23529 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23530 dwarf2_per_objfile
*per_objfile
)
23532 per_objfile (per_objfile
),
23534 has_loclist (false),
23535 checked_producer (false),
23536 producer_is_gxx_lt_4_6 (false),
23537 producer_is_gcc_lt_4_3 (false),
23538 producer_is_icc (false),
23539 producer_is_icc_lt_14 (false),
23540 producer_is_codewarrior (false),
23541 processing_has_namespace_info (false)
23546 /* Destroy a dwarf2_cu. */
23548 dwarf2_cu::~dwarf2_cu ()
23553 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23556 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23557 enum language pretend_language
)
23559 struct attribute
*attr
;
23561 /* Set the language we're debugging. */
23562 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23563 if (attr
!= nullptr)
23564 set_cu_language (DW_UNSND (attr
), cu
);
23567 cu
->language
= pretend_language
;
23568 cu
->language_defn
= language_def (cu
->language
);
23571 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23574 /* Increase the age counter on each cached compilation unit, and free
23575 any that are too old. */
23578 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23580 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23582 dwarf2_clear_marks (dwarf2_per_objfile
->per_bfd
->read_in_chain
);
23583 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23584 while (per_cu
!= NULL
)
23586 per_cu
->cu
->last_used
++;
23587 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23588 dwarf2_mark (per_cu
->cu
);
23589 per_cu
= per_cu
->cu
->read_in_chain
;
23592 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23593 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23594 while (per_cu
!= NULL
)
23596 struct dwarf2_per_cu_data
*next_cu
;
23598 next_cu
= per_cu
->cu
->read_in_chain
;
23600 if (!per_cu
->cu
->mark
)
23603 *last_chain
= next_cu
;
23606 last_chain
= &per_cu
->cu
->read_in_chain
;
23612 /* Remove a single compilation unit from the cache. */
23615 free_one_cached_comp_unit (dwarf2_per_cu_data
*target_per_cu
,
23616 dwarf2_per_objfile
*dwarf2_per_objfile
)
23618 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23620 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23621 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23622 while (per_cu
!= NULL
)
23624 struct dwarf2_per_cu_data
*next_cu
;
23626 next_cu
= per_cu
->cu
->read_in_chain
;
23628 if (per_cu
== target_per_cu
)
23632 *last_chain
= next_cu
;
23636 last_chain
= &per_cu
->cu
->read_in_chain
;
23642 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23643 We store these in a hash table separate from the DIEs, and preserve them
23644 when the DIEs are flushed out of cache.
23646 The CU "per_cu" pointer is needed because offset alone is not enough to
23647 uniquely identify the type. A file may have multiple .debug_types sections,
23648 or the type may come from a DWO file. Furthermore, while it's more logical
23649 to use per_cu->section+offset, with Fission the section with the data is in
23650 the DWO file but we don't know that section at the point we need it.
23651 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23652 because we can enter the lookup routine, get_die_type_at_offset, from
23653 outside this file, and thus won't necessarily have PER_CU->cu.
23654 Fortunately, PER_CU is stable for the life of the objfile. */
23656 struct dwarf2_per_cu_offset_and_type
23658 const struct dwarf2_per_cu_data
*per_cu
;
23659 sect_offset sect_off
;
23663 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23666 per_cu_offset_and_type_hash (const void *item
)
23668 const struct dwarf2_per_cu_offset_and_type
*ofs
23669 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23671 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23674 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23677 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23679 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23680 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23681 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23682 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23684 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23685 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23688 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23689 table if necessary. For convenience, return TYPE.
23691 The DIEs reading must have careful ordering to:
23692 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23693 reading current DIE.
23694 * Not trying to dereference contents of still incompletely read in types
23695 while reading in other DIEs.
23696 * Enable referencing still incompletely read in types just by a pointer to
23697 the type without accessing its fields.
23699 Therefore caller should follow these rules:
23700 * Try to fetch any prerequisite types we may need to build this DIE type
23701 before building the type and calling set_die_type.
23702 * After building type call set_die_type for current DIE as soon as
23703 possible before fetching more types to complete the current type.
23704 * Make the type as complete as possible before fetching more types. */
23706 static struct type
*
23707 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23709 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23710 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23711 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23712 struct attribute
*attr
;
23713 struct dynamic_prop prop
;
23715 /* For Ada types, make sure that the gnat-specific data is always
23716 initialized (if not already set). There are a few types where
23717 we should not be doing so, because the type-specific area is
23718 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23719 where the type-specific area is used to store the floatformat).
23720 But this is not a problem, because the gnat-specific information
23721 is actually not needed for these types. */
23722 if (need_gnat_info (cu
)
23723 && type
->code () != TYPE_CODE_FUNC
23724 && type
->code () != TYPE_CODE_FLT
23725 && type
->code () != TYPE_CODE_METHODPTR
23726 && type
->code () != TYPE_CODE_MEMBERPTR
23727 && type
->code () != TYPE_CODE_METHOD
23728 && !HAVE_GNAT_AUX_INFO (type
))
23729 INIT_GNAT_SPECIFIC (type
);
23731 /* Read DW_AT_allocated and set in type. */
23732 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23733 if (attr
!= NULL
&& attr
->form_is_block ())
23735 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23736 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23737 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23739 else if (attr
!= NULL
)
23741 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23742 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23743 sect_offset_str (die
->sect_off
));
23746 /* Read DW_AT_associated and set in type. */
23747 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23748 if (attr
!= NULL
&& attr
->form_is_block ())
23750 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23751 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23752 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23754 else if (attr
!= NULL
)
23756 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23757 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23758 sect_offset_str (die
->sect_off
));
23761 /* Read DW_AT_data_location and set in type. */
23762 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23763 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23764 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23766 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23767 dwarf2_per_objfile
->die_type_hash
23768 = htab_up (htab_create_alloc (127,
23769 per_cu_offset_and_type_hash
,
23770 per_cu_offset_and_type_eq
,
23771 NULL
, xcalloc
, xfree
));
23773 ofs
.per_cu
= cu
->per_cu
;
23774 ofs
.sect_off
= die
->sect_off
;
23776 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23777 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23779 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23780 sect_offset_str (die
->sect_off
));
23781 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23782 struct dwarf2_per_cu_offset_and_type
);
23787 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23788 or return NULL if the die does not have a saved type. */
23790 static struct type
*
23791 get_die_type_at_offset (sect_offset sect_off
,
23792 struct dwarf2_per_cu_data
*per_cu
)
23794 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23795 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23797 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23800 ofs
.per_cu
= per_cu
;
23801 ofs
.sect_off
= sect_off
;
23802 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23803 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23810 /* Look up the type for DIE in CU in die_type_hash,
23811 or return NULL if DIE does not have a saved type. */
23813 static struct type
*
23814 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23816 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23819 /* Add a dependence relationship from CU to REF_PER_CU. */
23822 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23823 struct dwarf2_per_cu_data
*ref_per_cu
)
23827 if (cu
->dependencies
== NULL
)
23829 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23830 NULL
, &cu
->comp_unit_obstack
,
23831 hashtab_obstack_allocate
,
23832 dummy_obstack_deallocate
);
23834 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23836 *slot
= ref_per_cu
;
23839 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23840 Set the mark field in every compilation unit in the
23841 cache that we must keep because we are keeping CU. */
23844 dwarf2_mark_helper (void **slot
, void *data
)
23846 struct dwarf2_per_cu_data
*per_cu
;
23848 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23850 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23851 reading of the chain. As such dependencies remain valid it is not much
23852 useful to track and undo them during QUIT cleanups. */
23853 if (per_cu
->cu
== NULL
)
23856 if (per_cu
->cu
->mark
)
23858 per_cu
->cu
->mark
= true;
23860 if (per_cu
->cu
->dependencies
!= NULL
)
23861 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23866 /* Set the mark field in CU and in every other compilation unit in the
23867 cache that we must keep because we are keeping CU. */
23870 dwarf2_mark (struct dwarf2_cu
*cu
)
23875 if (cu
->dependencies
!= NULL
)
23876 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23880 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23884 per_cu
->cu
->mark
= false;
23885 per_cu
= per_cu
->cu
->read_in_chain
;
23889 /* Trivial hash function for partial_die_info: the hash value of a DIE
23890 is its offset in .debug_info for this objfile. */
23893 partial_die_hash (const void *item
)
23895 const struct partial_die_info
*part_die
23896 = (const struct partial_die_info
*) item
;
23898 return to_underlying (part_die
->sect_off
);
23901 /* Trivial comparison function for partial_die_info structures: two DIEs
23902 are equal if they have the same offset. */
23905 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23907 const struct partial_die_info
*part_die_lhs
23908 = (const struct partial_die_info
*) item_lhs
;
23909 const struct partial_die_info
*part_die_rhs
23910 = (const struct partial_die_info
*) item_rhs
;
23912 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23915 struct cmd_list_element
*set_dwarf_cmdlist
;
23916 struct cmd_list_element
*show_dwarf_cmdlist
;
23919 show_check_physname (struct ui_file
*file
, int from_tty
,
23920 struct cmd_list_element
*c
, const char *value
)
23922 fprintf_filtered (file
,
23923 _("Whether to check \"physname\" is %s.\n"),
23927 void _initialize_dwarf2_read ();
23929 _initialize_dwarf2_read ()
23931 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23932 Set DWARF specific variables.\n\
23933 Configure DWARF variables such as the cache size."),
23934 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23935 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23937 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23938 Show DWARF specific variables.\n\
23939 Show DWARF variables such as the cache size."),
23940 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23941 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23943 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23944 &dwarf_max_cache_age
, _("\
23945 Set the upper bound on the age of cached DWARF compilation units."), _("\
23946 Show the upper bound on the age of cached DWARF compilation units."), _("\
23947 A higher limit means that cached compilation units will be stored\n\
23948 in memory longer, and more total memory will be used. Zero disables\n\
23949 caching, which can slow down startup."),
23951 show_dwarf_max_cache_age
,
23952 &set_dwarf_cmdlist
,
23953 &show_dwarf_cmdlist
);
23955 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23956 Set debugging of the DWARF reader."), _("\
23957 Show debugging of the DWARF reader."), _("\
23958 When enabled (non-zero), debugging messages are printed during DWARF\n\
23959 reading and symtab expansion. A value of 1 (one) provides basic\n\
23960 information. A value greater than 1 provides more verbose information."),
23963 &setdebuglist
, &showdebuglist
);
23965 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23966 Set debugging of the DWARF DIE reader."), _("\
23967 Show debugging of the DWARF DIE reader."), _("\
23968 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23969 The value is the maximum depth to print."),
23972 &setdebuglist
, &showdebuglist
);
23974 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23975 Set debugging of the dwarf line reader."), _("\
23976 Show debugging of the dwarf line reader."), _("\
23977 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23978 A value of 1 (one) provides basic information.\n\
23979 A value greater than 1 provides more verbose information."),
23982 &setdebuglist
, &showdebuglist
);
23984 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23985 Set cross-checking of \"physname\" code against demangler."), _("\
23986 Show cross-checking of \"physname\" code against demangler."), _("\
23987 When enabled, GDB's internal \"physname\" code is checked against\n\
23989 NULL
, show_check_physname
,
23990 &setdebuglist
, &showdebuglist
);
23992 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23993 no_class
, &use_deprecated_index_sections
, _("\
23994 Set whether to use deprecated gdb_index sections."), _("\
23995 Show whether to use deprecated gdb_index sections."), _("\
23996 When enabled, deprecated .gdb_index sections are used anyway.\n\
23997 Normally they are ignored either because of a missing feature or\n\
23998 performance issue.\n\
23999 Warning: This option must be enabled before gdb reads the file."),
24002 &setlist
, &showlist
);
24004 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24005 &dwarf2_locexpr_funcs
);
24006 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24007 &dwarf2_loclist_funcs
);
24009 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24010 &dwarf2_block_frame_base_locexpr_funcs
);
24011 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24012 &dwarf2_block_frame_base_loclist_funcs
);
24015 selftests::register_test ("dw2_expand_symtabs_matching",
24016 selftests::dw2_expand_symtabs_matching::run_test
);
24017 selftests::register_test ("dwarf2_find_containing_comp_unit",
24018 selftests::find_containing_comp_unit::run_test
);